program hrn;
 var
  b:array[0..101,0..101]of char;
  a:array[1..100,1..100]of longint;
  i,j,m,n,x:longint;s:string;
 begin
  read(m,n);readln;
  for i:=1 to m do  begin
   for j:=1 to n do
    read(b[i,j]);
   readln;end;
  for i:=1 to m do
   for j:=1 to n do
    if b[i,j]='.' then begin
     if b[i,j-1]='#'  then x:=x+1;
     if b[i,j+1]='#'  then x:=x+1;
     if b[i+1,j]='#'  then x:=x+1;
     if b[i-1,j]='#'  then x:=x+1;
     if b[i-1,j-1]='#'then x:=x+1;
     if b[i+1,j-1]='#'then x:=x+1;
     if b[i-1,j+1]='#'then x:=x+1;
     if b[i+1,j+1]='#'then x:=x+1;
     a[i,j]:=x;x:=0;
    end;
  for i:=1 to m do  begin
   for j:=1 to n do
    if b[i,j]='#' then write('#')
                  else write(a[i,j]);
   writeln;
  end;
 end.


program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils;
var
  h,w,i,j,count,x,y:Integer;
  s:array of string;
begin
  try
    { TODO -oUser -cConsole Main : ここにコードを記述してください }
    Read(h);
    Readln(w);
    SetLength(s,h+2);

    //0行目とh+1行目
    for j := 0 to h+1 do
      for i := 0 to w+1 do
        s[j]:=s[j]+'.';

    for j := 1 to h do
      Readln(s[j]);

    for j := 1 to h do begin
      for i := 1 to w do begin
        count:=0;
        for y := j-1 to j+1 do begin
          for x := i-1 to i+1 do begin
            if (s[y][x]='#')and((x<>i)or(y<>j)) then
              inc(count);
          end;
        end;
        if s[j][i]='.' then
          s[j][i]:=IntToStr(count)[1];
      end;
    end;

    for j := 1 to h do
      Writeln(s[j]);

    Readln;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.

Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.

Score : 200 points

Problem Statement

You are given an H × W grid.

The squares in the grid are described by H strings, S_1,...,S_H.

The j-th character in the string S_i corresponds to the square at the i-th row from the top and j-th column from the left (1 \leq i \leq H,1 \leq j \leq W).

. stands for an empty square, and # stands for a square containing a bomb.

Dolphin is interested in how many bomb squares are horizontally, vertically or diagonally adjacent to each empty square.

(Below, we will simply say "adjacent" for this meaning. For each square, there are at most eight adjacent squares.)

He decides to replace each . in our H strings with a digit that represents the number of bomb squares adjacent to the corresponding empty square.

Print the strings after the process.

Constraints

1 \leq H,W \leq 50

S_i is a string of length W consisting of # and ..

Input

Input is given from Standard Input in the following format:

H W
S_1
:
S_H

Output

Print the H strings after the process.

The i-th line should contain a string T_i of length W, where the j-th character in T_i corresponds to the square at the i-th row from the top and j-th row from the left in the grid (1 \leq i \leq H, 1 \leq j \leq W).

Sample Input 1

3 5
.....
.#.#.
.....

Sample Output 1

11211
1#2#1
11211

For example, let us observe the empty square at the first row from the top and first column from the left.

There is one bomb square adjacent to this empty square: the square at the second row and second column.

Thus, the . corresponding to this empty square is replaced with 1.

Sample Input 2

3 5
#####
#####
#####

Sample Output 2

#####
#####
#####

It is possible that there is no empty square.

Sample Input 3

6 6
#####.
#.#.##
####.#
.#..#.
#.##..
#.#...

Sample Output 3

#####3
#8#7##
####5#
4#65#2
#5##21
#4#310

Submitted source-code file size, in bytes.

Execution CPU time reported by official Project CodeNet metadata, in milliseconds.

Peak memory usage reported by official Project CodeNet metadata, in kilobytes.


var n,m,i,j,ans,k,l,num:longint;
var cc:char;
var c:array[0..100] of ansistring;
begin
  readln(n,m);
  for i:=1 to n do readln(c[i]);
  for i:=1 to n do
  begin
    for j:=1 to m do
    begin
      if c[i,j]='.' then
      begin
        ans:=0;
        for k:=-1 to 1 do
          for l:=-1 to 1 do
          if (i+k>0) and (i+k<=n) and (j+l>0) and (j+l<=m) then
          if c[i+k,j+l]='#' then inc(ans);
          write(ans);
      end else write(c[i,j]);
    end;
    writeln;
  end;
end.


var n,l,r,ans,i:longint;
begin
  readln(n);
  for i:=1 to n do
  begin
    readln(l,r);
    inc(ans,r-l+1);
  end;
  writeln(ans);
end.

Score : 200 points

Problem Statement

Joisino is working as a receptionist at a theater.

The theater has 100000 seats, numbered from 1 to 100000.

According to her memo, N groups of audiences have come so far, and the i-th group occupies the consecutive seats from Seat l_i to Seat r_i (inclusive).

How many people are sitting at the theater now?

Constraints

1≤N≤1000

1≤l_i≤r_i≤100000

No seat is occupied by more than one person.

All input values are integers.

Input

Input is given from Standard Input in the following format:

N
l_1 r_1
:
l_N r_N

Output

Print the number of people sitting at the theater.

Sample Input 1

1
24 30

Sample Output 1

7

There are 7 people, sitting at Seat 24,25,26,27,28,29 and 30.

Sample Input 2

2
6 8
3 3

Sample Output 2

4


var
  n,i,s,l,r:longint;
begin
  readln(n);
  for i:=1 to n do begin read(l,r);s:=s+r-l+1; end;
  writeln(s);
end.


var
n,i,l,r,s:longint;
begin
readln(n);
for i:=1 to n do
  begin
    readln(l,r);
    s:=s+r-l+1;
  end;
write(s);
end.


var
  n,i,s,l,r:longint;
begin
  readln(n);
  for i:=1 to n do
   begin
     readln(l,r);
     s:=s+(r-l+1);
   end;
  writeln(s);
end.


var i,j,n,m,a,b:longint;
begin
readln(n);
for i:=1 to n do
begin
  readln(a,b);
  m:=m+(b-a)+1;
end;
write(m);
writeln;
end.


var
  n,i,ans,x,y:longint;
begin
  readln(n);
  for i:=1 to n do
  begin
    readln(x,y);
    inc(ans,y-x+1);
  end;
  writeln(ans);
end.


var
    n,l,r,i:longint;
    s:int64;
begin
    read(n);
    s:=0;
    for i:=1 to n do
    begin
        read(l,r);
        s:=s+r-l+1;
    end;
    writeln(s);
end.


var sum,n,i,a,b:longint;
begin
 readln(n);
 for i:=1 to n do
  begin
   readln(a,b);
   inc(sum,b+1-a);
  end;
 writeln(sum);
end.


var
  n,i,ans:longint;
  a,b:array[1..1000] of longint;
begin
  readln(n);
  for i:=1 to n do
    begin
      readln(a[i],b[i]);
      inc(ans,b[i]-a[i]+1);
    end;
    writeln(ans);
end.


var
  k,i,n,l,r:longint;
begin
  readln(n);
  for i:=1 to n do
  begin
    readln(l,r);
    inc(k,r-l+1);
  end;
  writeln(k);
end.


var
 x,y,n,i,s:longint;
begin
 readln(n);
 for i:=1 to n do
  begin
   readln(x,y);
   s:=s+y-x+1;
  end;
  writeln(s);
 end.


var
 n,i,l,r,sum:longint;
begin
 readln(n);
 for i:=1 to n do
  begin
   readln(l,r);
   sum:=sum+(r-l+1);
  end;
 writeln(sum);
end.


var s,n,i,a,b:Longint;
begin
read(n);
for i:=1 to n do begin
read(a,b);
s:=s+b-a+1;
end;
write(s)end.


var
 n,i,r,l,sum:longint;
begin
 readln(n);
 for i:=1 to n do
  begin
   readln(l,r);
   sum:=sum+(r-l+1);
  end;
 writeln(sum);
end.


var n,i,ans:longint;
    a,b:array[1..1000]of longint;
begin
    readln(n);
    for i:=1 to n do
    begin
        readln(a[i],b[i]);
        inc(ans,b[i]-a[i]+1);
    end;
    writeln(ans);
end.


var
    n,i,ans:longint;
    a,b:array[1..1000]of longint;
begin
    readln(n);
    for i:=1 to n do
    begin
        readln(a[i],b[i]);
        inc(ans,b[i]-a[i]+1);//相加
    end;
    writeln(ans);
end.


var
i,j,c,d,n,e,b:longint;
s:qword;
begin
readln(n);
for i:=1 to n do
begin
read(c,d);
s:=s+(d-c)+1;
end;
write(s);
end.


var
 s:int64;
 n,i,x,y:longint;
begin
 readln(n);
 for i:=1 to n do begin readln(x,y);s:=s+(y-x+1);end;
 writeln(s);
end.


var
 s:int64;
 n,i,x,y:longint;
begin
 readln(n);
 for i:=1 to n do begin readln(x,y);s:=s+(x-y+1);end;
 writeln(s);
end.


var
    n,i,ans:longint;
    a,b:array[1..1000]of longint;
begin
    readln(n);
    for i:=1 to n do
    begin
        readln(a[i],b[i]);
        inc(ans,b[i]-a[i]+1);
    end;
    writeln(ans);
end.


var
    l,r,i,n,s:longint;
begin
    readln(n);
    s:=0;
    for i:=1 to n do
    begin
        read(l,r);
        s:=s+r-l+1;
    end;
    writeln(s);
end.


var
    i,l,n,r:longint;
    ans:longint;
begin
    readln(n);
    for i:=1 to n do
        begin
            readln(l,r);
            ans:=ans+r-l;
        end;
    writeln(ans+n);
end.


var
    i,l,n,r:longint;
    ans:int64;
begin
    readln(n);
    for i:=1 to n do
        begin
            readln(l,r);
            ans:=r-l;
        end;
    writeln(ans+n);
end.


var
    i,l,n,r,ans:longint;
begin
    readln(n);
    for i:=1 to n do
        begin
            readln(l,r);
            ans:=r-l;
        end;
    writeln(ans+n);
end.


var n,x,a,b,i:1..100000;
 begin
  readln(n);
  for i:=1 to n do
  begin
   readln(a,b);
   x:=x+(b-a+1);
  end;
  writeln(x);
 end.


var n,x,a,b,i:longint;
 begin
  readln(n);
  for i:=1 to n do
  begin
   readln(a,b);
   x:=x+(b-a+1);
  end;
  writeln(x);
 end.


program hrn;
 var
  n,x,a,b,i:longint;
 begin
  read(n);
  for i:=1 to n do begin
   read(a,b);
   inc(x,b-a+1);
  end;
  writeln(x);
 end.


var n,i,j,x,y,max:longint;
begin
readln(n);
for i:=1 to n do
begin
readln(x,y);
max:=max+y-x+1;
end;
write(max);
end.


program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils;
var
  l,r,a,h,w,i,j,count,x,y,sw,m,n,b,c,soeji,sum,max,k,t:Integer;
  //l:array of Integer;
  s,s123,s1,s2,s3:string;
  tf:Boolean;
  //nyu:TStringList;
begin
  try
    { TODO -oUser -cConsole Main : ここにコードを記述してください }
    Readln(n);

    sum:=0;
    for i := 0 to n - 1 do begin
      Read(l);
      Readln(r);
      sum:=sum+r-l+1;
    end;
    Writeln(sum);
    Readln;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.


var
 i,n,l,r,k:longint;
begin
 readln(n);
 k:=0;
 for i:=1 to n do
   begin
    readln(l,r);
    inc(k,r-l+1);
   end;
  writeln(k);
end.


var i,j,k,n,ans:longint;
begin
	readln(n);
	for i:=1 to n do begin
		readln(j,k);
		inc(ans,k-j+1);
	end;
	writeln(ans);
end.


var l,r:longint;
    n,i:longint;
    sum:longint;
begin
  read(n);
  for i:=1 to n do
  begin
    read(l,r);
    inc(sum,r-l+1);
  end;
  writeln(sum);
end.


var n,i,x,y,ans:longint;
begin
  read(n);for i:=1 to n do begin read(x,y);inc(ans,y-x+1);end;writeln(ans);end.


var
a:array[0..26] of 0..1;
s:ansistring;
i,x:longint;
begin
read(s);
for i:=1 to length(s) do a[ord(s[i])-96]:=1;
for i:=26 downto 1 do
  begin
    x:=x+a[i];
    if a[i]=0 then s:=chr(96+i);
  end;
if x=26 then writeln('None')
        else writeln(s);
end.

Score : 200 points

Problem Statement

You are given a string S consisting of lowercase English letters.
Find the lexicographically (alphabetically) smallest lowercase English letter that does not occur in S.
If every lowercase English letter occurs in S, print None instead.

Constraints

1 \leq |S| \leq 10^5 (|S| is the length of string S.)

S consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

S

Output

Print the lexicographically smallest lowercase English letter that does not occur in S.
If every lowercase English letter occurs in S, print None instead.

Sample Input 1

atcoderregularcontest

Sample Output 1

b

The string atcoderregularcontest contains a, but does not contain b.

Sample Input 2

abcdefghijklmnopqrstuvwxyz

Sample Output 2

None

This string contains every lowercase English letter.

Sample Input 3

fajsonlslfepbjtsaayxbymeskptcumtwrmkkinjxnnucagfrg

Sample Output 3

d


var
  n:string;
  a:array['a'..'z'] of 0..1;
  s,i:longint;
  ch:char;
begin
  readln(n);
  for i:=1 to length(n) do a[n[i]]:=1;
  for ch:='a' to 'z' do s:=s+a[ch];
  if s=26 then begin writeln('None');exit;end;
  for ch:='a' to 'z' do if a[ch]=0 then begin writeln(ch);exit;end;
end.


var
  n:string;
  a:array['a'..'z'] of 0..1;
  s,i:longint;
  ch:char;
begin
  readln(n);
  for i:=1 to length(n) do a[n[i]]:=1;
  for ch:='a' to 'z' do s:=s+a[ch];
  if s=26 then begin writeln('None');exit;end;
  for ch:='a' to 'z' do if a[ch]=1 then begin writeln(ch);exit;end;
end.


var    ch:char;
       a:array['a'..'z'] of longint;
begin
   while not eoln do
     begin
      read(ch);
        inc(a[ch]);
      end;
   for ch:='a' to 'z' do
    if a[ch]=0 then begin writeln(ch);exit;end;
        writeln('None');
end.


var
 s:string;
 i,k:longint;
 j:char;
 a:array['a'..'z'] of longint;
begin
 readln(s);
 for i:=1 to length(s) do
  if s[i] in ['a'..'z'] then inc(a[s[i]]);
 for j:='a' to 'z' do
  if a[j]=0 then begin writeln(j); halt; end;
 writeln('None');
end.


var
 s:ansistring;
 i,j,k:longint;
 a:array['a'..'z'] of 0..1;
begin
 readln(s);
 for i:=1 to length(s) do a[s[i]]:=1;
 for i:=1 to 26 do begin if a[chr(i+96)]=0 then begin writeln(chr(i+96));halt;end;if a[chr(i+96)]<>0 then inc(k);end;
 if k=26 then writeln('None');
end.


var
 i:longint;
 s:ansistring;
 j:char;
 a:array['a'..'z'] of longint;
begin
 readln(s);
 for i:=1 to length(s) do
  inc(a[s[i]]);
 for j:='a' to 'z' do
  if a[j]=0 then begin writeln(j); halt; end;
 writeln('None');
end.


var s:String;i:Longint;f:boolean;
begin
	readln(s);
	f:=false;
	for i:=1 to length(s) do begin
		if s[i]='a' then begin
			f:=true;
			break;
		end;
	end;
	if not f then begin
		writeln('a');
		exit;
	end;
	f:=false;
	for i:=1 to length(s) do begin
		if s[i]='b' then begin
			f:=true;
			break;
		end;
	end;
	if not f then begin
		writeln('b');
		exit;
	end;
	f:=false;
	for i:=1 to length(s) do begin
		if s[i]='d' then begin
			f:=true;
			break;
		end;
	end;
	if not f then begin
		writeln('d');
		exit;
	end;
	f:=false;
	for i:=1 to length(s) do begin
		if s[i]='f' then begin
			f:=true;
			break;
		end;
	end;
	if not f then begin
		writeln('f');
		exit;
	end;
	f:=false;
	for i:=1 to length(s) do begin
		if s[i]='i' then begin
			f:=true;
			break;
		end;
	end;
	if not f then begin
		writeln('i');
		exit;
	end;
	f:=false;
	for i:=1 to length(s) do begin
		if s[i]='p' then begin
			f:=true;
			break;
		end;
	end;
	if not f then begin
		writeln('p');
		exit;
	end;
	f:=false;
	for i:=1 to length(s) do begin
		if s[i]='y' then begin
			f:=true;
			break;
		end;
	end;
	if not f then begin
		writeln('y');
		exit;
	end;
	f:=false;
	for i:=1 to length(s) do begin
		if s[i]='z' then begin
			f:=true;
			break;
		end;
	end;
	if not f then begin
		writeln('z');
		exit;
	end;
	writeln('None');
end.


var s:String;i,j:Longint;f:boolean;a:array[0..7]of char=('a','b','d','f','i','p','y','z');
begin
	readln(s);
	for j:=0 to 7 do begin
		f:=false;
		for i:=1 to length(s) do begin
			if s[i]=a[j] then begin
				f:=true;
				break;
			end;
		end;
		if not f then begin
			writeln(a[j]);
			exit;
		end;
	end;
	writeln('None');
end.


var s:String;i:Longint;a:array[97..122]of boolean;
begin
	setlength(s,100000);
	readln(s);
	for i:=1 to length(s) do begin
		a[ord(s[i])]:=true;
	end;
	for i:=97 to 122 do begin
		if not a[i] then begin
			writeln(chr(i));
			exit;
		end;
	end;
	writeln('None');
end.


var s:String;i:Longint;a:array[97..122]of boolean;
begin
	readln(s);
	for i:=1 to length(s) do begin
		a[ord(s[i])]:=true;
	end;
	for i:=97 to 122 do begin
		if not a[i] then begin
			writeln(chr(i));
			exit;
		end;
	end;
	writeln('None');
end.


var s:String;i:Longint;a:array[97..122]of boolean;
begin
	readln(s);
	for i:=1 to length(s) do begin
		inc(a[ord(s[i])]);
	end;
	for i:=97 to 122 do begin
		if not a[i] then begin
			writeln(chr(i));
			exit;
		end;
	end;
	writeln('None');
end.


var s:String;i:Longint;c:char;f:boolean;
begin
	readln(s);
	for c:='a' to 'z' do begin
		f:=false;
		for i:=1 to length(s) do begin
			f:=f or(s[i]=c);
		end;
		if not f then begin
			writeln(c);
			exit;
		end;
	end;
	writeln('None');
end.


var
s,s1,s2,s3:string;
x:array[1..1000] of longint;
a:array['a'..'z'] of longint;
i,c,d,e:longint;
j,min:char;
begin
min:='z';
read(s);
for i:=1 to length(s) do
inc(a[s[i]]);
for j:='a' to 'z' do
if a[j]=0 then begin e:=1; if ord(j)<ord(min) then min:=j;end;
if e=0 then writeln('None')
else
writeln(min);
end.


var
 s:ansistring;
 i,j,k:longint;
 a:array['a'..'z'] of 0..1;
begin
 readln(s);
 for i:=1 to length(s) do a[s[i]]:=1;
 for i:=1 to 26 do if a[chr(i+96)]<>0 then begin inc(k);if j=0 then j:=i;end;
 if k=26 then writeln('None')
         else writeln(chr(j+96));
end.


program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils;
var
  a,h,w,i,j,count,x,y,sw,m,n,b,c,soeji,sum,max,k:Integer;
  l:array of Integer;
  s,s123,s1,s2,s3:string;
  tf:Boolean;
  //nyu:TStringList;
begin
  try
    { TODO -oUser -cConsole Main : ここにコードを記述してください }
    Readln(s);
    s2:='abcdefghijklmnopqrstuvwxyz';

    for j := 1 to Length(s2) do
      for i := 1 to Length(s) do begin
        if s[i]=s2[j] then
          break;
        if i=Length(s) then begin
          Writeln(s2[j]);
          Readln;
          exit;
        end;
      end;

    Writeln('None');
    Readln;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.


var
  s: array[0..100000] of char;
  alpha: array[0..128] of boolean;
  i: integer;
  ok: boolean;
begin
  read(s);
  for i := 0 to length(s) do
  begin
    alpha[ord(s[i])] := True;
  end;

  ok := False;
  for i := 97 to 122 do
  begin
    if alpha[i] = False then
    begin
      write(chr(i));
      ok := True;
      break;
    end;
  end;

  if ok = False then
  begin
    write('None');
  end;
end.


var
  s: array[0..100000] of char;
  alpha: array[0..128] of byte;
  i: integer;
  ok: boolean;
begin
  read(s);
  for i := 0 to 100000 do
  begin
    alpha[ord(s[i])] := 1;
  end;

  ok := False;
  for i := 97 to 122 do
  begin
    if alpha[i] = 0 then
    begin
      write(chr(i));
      ok := True;
      break;
    end;
  end;

  if ok = False then
  begin
    write('None');
  end;
end.


var
  s: array[0..100000] of char;
  alpha: array[97..122] of integer;
  i: integer;
  ok: boolean;
begin
  readln(s);
  for i := 0 to 100000 do
  begin
    alpha[ord(s[i])] := 1;
  end;

  ok := False;
  for i := 97 to 122 do
  begin
    if alpha[i] = 0 then
    begin
      writeln(chr(i));
      ok := True;
      break;
    end;
  end;

  if ok = False then
  begin
    writeln('None');
  end;
end.


var
  s: array[0..100000] of char;
  alpha: array[0..26] of int64;
  i: int64;
  ok: boolean;
begin
  readln(s);
  for i := 0 to 100000 do
  begin
    alpha[ord(s[i]) - 96] := 1;
  end;

  ok := False;
  for i := 1 to 26 do
  begin
    if alpha[i] = 0 then
    begin
      writeln(chr(i + 96));
      ok := True;
      break;
    end;
  end;

  if ok = False then
  begin
    writeln('None');
  end;
end.


var
  s: array[0..100005] of char;
  alpha: array[0..26] of int64;
  i: int64;
  ok: boolean;
begin
  readln(s);
  for i := 1 to 100005 do
  begin
    alpha[ord(s[i]) - ord('a') + 1] := 1;
  end;

  ok := False;
  for i := 1 to 26 do
  begin
    if alpha[i] = 0 then
    begin
      writeln(chr(i + ord('a') - 1));
      ok := True;
      break;
    end;
  end;

  if ok = False then
  begin
    writeln('None');
  end;
end.


var
  s: string;
  alpha: array[1..26] of int64;
  i: int64;
  ok: boolean;
begin
  readln(s);
  for i := 1 to length(s) do
  begin
    alpha[ord(s[i]) - ord('a') + 1] := 1;
  end;

  ok := False;
  for i := 1 to 26 do
  begin
    if alpha[i] = 0 then
    begin
      writeln(chr(i + ord('a') - 1));
      ok := True;
      break;
    end;
  end;

  if ok = False then
  begin
    writeln('None');
  end;
end.


var
  s: string;
  alpha: array[1..26] of int64;
  i: int64;
  ok: boolean;
begin
  readln(s);
  for i := 1 to length(s) do
  begin
    alpha[ord(s[i]) - ord('a')] := 1;
  end;

  ok := False;
  for i := 1 to 26 do
  begin
    if alpha[i] = 0 then
    begin
      writeln(chr(i + ord('a')));
      ok := True;
      break;
    end;
  end;

  if ok = False then
  begin
    writeln('None');
  end;
end.


var
  x,i:longint;
  s:ansistring;
begin
  read(s);
  x:=97;
  for i:=1 to length(s) do
    if ord(s[i])=x then x:=x+1;
    if x>=123 then write('None')else
  write(chr(x));
end.


var
  x,j,i:longint;
  s:ansistring;t:char;
begin
  read(s);
  x:=97;
  //for j:=1 to length(s)-1 do
    //for i:=1 to length(s)-j do
    //if ord(s[i]) > ord(s[i+1]) then
    //begin t:=s[i];s[i]:=s[i+1];s[i+1]:=t;end;
  for i:=1 to length(s) do
    if ord(s[i])=x then x:=x+1;
    if x=123 then write('None')else
  write(chr(x));
end.


var
  x,j,i:longint;
  s:string;t:char;
begin
  read(s);
  x:=97;
  for j:=1 to length(s)-1 do
    for i:=1 to length(s)-j do
    if ord(s[i]) > ord(s[i+1]) then
    begin t:=s[i];s[i]:=s[i+1];s[i+1]:=t;end;
  for i:=1 to length(s) do
    if ord(s[i])=x then x:=x+1;
    if x=123 then write('None')else
  write(chr(x));
end.


var s:ansistring;
var r:array['a'..'z'] of boolean;
var i:longint;
var r1:boolean;
var c:char;
begin
  readln(s);
  for i:=1 to length(s) do r[s[i]]:=true;
  for c:='a' to 'z' do if not r[c] then begin writeln(c);r1:=true;break;end;
  if not r1 then writeln('None');
end.


var s:ansistring;
    v:array[char(0)..char(255)]of boolean;
    c:char;
    i:longint;
begin
  readln(s);
  for i:=1 to length(s) do
  v[s[i]]:=true;
  for c:='a' to 'z' do
  if not v[c] then
  begin
    writeln(c);
    exit;
  end;
  writeln('None');
end.


program ec12;
var
	a,j,t,s:array[1..100001] of longint;
	n,m,i,tot1,tot2,tot3:longint;
begin
	readln(n);
	tot1:=0;
	tot2:=0;
	tot3:=0;
	for i:=1 to n do
	begin
		read(a[i]);
		if a[i] mod 2=1 then
		inc(tot1)
		else
		begin
			if a[i] mod 4=0 then
			inc(tot3)
			else
			inc(tot2);
		end;
	end;
	if tot3<tot1-1 then
	begin
		writeln('No');
		halt;
	end;
	if (tot3=tot1-1) and (tot2>0) then
	begin
		writeln('No');
		halt;
	end;
	writeln('Yes');
end.

Score : 400 points

Problem Statement

We have a sequence of length N, a = (a_1, a_2, ..., a_N).
Each a_i is a positive integer.

Snuke's objective is to permute the element in a so that the following condition is satisfied:

For each 1 ≤ i ≤ N - 1, the product of a_i and a_{i + 1} is a multiple of 4.

Determine whether Snuke can achieve his objective.

Constraints

2 ≤ N ≤ 10^5

a_i is an integer.

1 ≤ a_i ≤ 10^9

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 ... a_N

Output

If Snuke can achieve his objective, print Yes; otherwise, print No.

Sample Input 1

3
1 10 100

Sample Output 1

Yes

One solution is (1, 100, 10).

Sample Input 2

4
1 2 3 4

Sample Output 2

No

It is impossible to permute a so that the condition is satisfied.

Sample Input 3

3
1 4 1

Sample Output 3

Yes

The condition is already satisfied initially.

Sample Input 4

2
1 1

Sample Output 4

No

Sample Input 5

6
2 7 1 8 2 8

Sample Output 5

Yes


program V1003;
 var
  a:array[1..3] of longint;
  i,n,x:longint;
 begin
  readln(n);
  fillchar(a,sizeof(a),0);
  for i:=1 to n do
   begin
    read(x);
    if x mod 4=0 then inc(a[3])
                 else if x mod 2=0 then inc(a[2])
                                   else inc(a[1]);
   end;
  readln;
  if a[2]>0 then a[2]:=1;
  if a[2]+a[1]>a[3]+1 then writeln('No')
                      else writeln('Yes');
 end.


{AT2379}
var
n,a,b,t:longint;
begin
read(n,a,b);
if n=1 then
writeln(0)
else
writeln((b-a)*(n-2)+1);
end.

Score : 200 points

Problem Statement

Snuke has N integers. Among them, the smallest is A, and the largest is B.
We are interested in the sum of those N integers. How many different possible sums there are?

Constraints

1 ≤ N,A,B ≤ 10^9

A and B are integers.

Input

Input is given from Standard Input in the following format:

N A B

Output

Print the number of the different possible sums.

Sample Input 1

4 4 6

Sample Output 1

5

There are five possible sums: 18=4+4+4+6, 19=4+4+5+6, 20=4+5+5+6, 21=4+5+6+6 and 22=4+6+6+6.

Sample Input 2

5 4 3

Sample Output 2

0

Sample Input 3

1 7 10

Sample Output 3

0

Sample Input 4

1 3 3

Sample Output 4

1


Var s:ansistring;
      x,y:int64;
Function downPos(ch:char;s:ansistring):int64;
Var i:longint;
  Begin
     for i:=length(s) downto 1 do
     if ch=s[i] then exit(i);
  End;
Begin
    readln(s);
     x:=pos('A',s);
     y:=downPos('Z',s);
    writeln(y-x+1);
End.

Score : 200 points

Problem Statement

Snuke has decided to construct a string that starts with A and ends with Z, by taking out a substring of a string s (that is, a consecutive part of s).

Find the greatest length of the string Snuke can construct. Here, the test set guarantees that there always exists a substring of s that starts with A and ends with Z.

Constraints

1 ≦ |s| ≦ 200{,}000

s consists of uppercase English letters.

There exists a substring of s that starts with A and ends with Z.

Input

The input is given from Standard Input in the following format:

s

Output

Print the answer.

Sample Input 1

QWERTYASDFZXCV

Sample Output 1

5

By taking out the seventh through eleventh characters, it is possible to construct ASDFZ, which starts with A and ends with Z.

Sample Input 2

ZABCZ

Sample Output 2

4

Sample Input 3

HASFJGHOGAKZZFEGA

Sample Output 3

12


var
i,j:longint;
s:string;
begin
read(s);
for i:=1 to length(s) do
  if s[i]='A' then break;
for j:=length(s) downto 1 do
  if s[j]='Z' then break;
writeln(j-i+1);
end.


var i:longint;
    s:ansistring;
begin
  readln(s);
  for i:=length(s) downto 1 do
    if s[i]='Z' then
      break;
  writeln(i-pos('A',s)+1);
end.


var
	a,z,i:Longint;
	s:String;
begin
	readln(s);
	for i:=1 to length(s) do begin
		if (a=0)and(s[i]='A')then a:=i;
		if s[i]='Z' then z:=i;
	end;
	write(z-a+1)
end.


var
   s:string;
   l,a,b,i:longint;
begin
   read(s);
   l:=length(s);
   for i:=1 to l do if s[i]='Z'then b:=i;
   for i:=l downto 1 do if s[i]='A'then a:=i;
   writeln(b-a+1);
end.


var
    i,j,n:longint;
    ch:array[1..200000]of char;
begin
    while not eoln do
        begin
            inc(n);
            read(ch[n]);
        end;
    for i:=1 to n do if ch[i]='A' then break;
    for j:=n downto 1 do if ch[j]='Z' then break;
    writeln(j-i+1);
end.


var
    i,j,n:longint;
    ch:array[1..200000]of char;
begin
    while not eof do
        begin
            inc(n);
            read(ch[n]);
        end;
    for i:=1 to n do if ch[i]='A' then break;
    for j:=n downto 1 do if ch[j]='Z' then break;
    writeln(j-i+1);
end.


var
    ans:longint;
    ch:char;
    cancount:boolean;
begin
    while not eof do
        begin
            read(ch);
            if ch='A' then cancount:=true;
            if ch='Z' then begin writeln(ans+1); halt; end;
            if cancount then inc(ans);
        end;
end.


var a:array[1..200000] of char;
i,j,k,l:longint;
begin
while not eoln do
  begin
  k:=k+1;
  read(a[k]);

  end;

for i:=1 to k do if a[i]='A' then begin j:=i; break; end;
for i:=k downto 1 do if a[i]='Z' then begin k:=i;break;end;
writeln(abs(k-j)+1);

end.


var a:array[1..200000] of char;
i,j,k,l:longint;
begin
while not eoln do
  begin
  k:=k+1;
  read(a[k]);

  end;

for i:=1 to k do if a[i]='A' then j:=i;
for i:=k downto 1 do if a[i]='Z' then k:=i;
writeln(abs(k-j)+1);

end.


var a:string;
i,j,k,l:longint;
begin
readln(a);

l:=pos('A',a);
k:=pos('Z',a);
k:=length(a);

for i:=1 to k do if a[i]='A' then j:=i;
for i:=k downto 1 do if a[i]='Z' then k:=i;
writeln(abs(k-j)+1);

end.


var a:ansistring;
i,j,k,l:longint;
begin
readln(a);

l:=pos('A',a);
k:=pos('Z',a);
k:=length(a);

for i:=1 to k do if a[i]='A' then j:=i;
for i:=k downto 1 do if a[i]='Z' then k:=i;
writeln(k-j+1);

end.


var a:ansistring;
i,j,k,l:longint;
begin
readln(a);

l:=pos('A',a);
k:=pos('Z',a);

for i:=1 to length(a) do if a[i]='A' then j:=i;
for i:=length(a) downto 1 do if a[i]='Z' then k:=i;
writeln(k-j+1);

end.


var a:string;
i,j,k,l:longint;
begin
readln(a);

l:=pos('A',a);
k:=pos('Z',a);

for i:=1 to length(a) do if a[i]='A' then j:=i;
for i:=length(a) downto 1 do if a[i]='Z' then k:=i;
writeln(k-j+1);

end.


var s:ansistring;
    a,b,i:longint;
 begin
  readln(s);
  for i:=1 to length(s) do
   if s[i]='Z'then b:=i;
  for i:=length(s) downto 1 do
   if s[i]='A'then a:=i;
  writeln((b-a)+1);
 end.


var s:ansistring;
    a,b,i:longint;
 begin
  readln(s);
  for i:=1 to length(s) do
   if s[i]='A'then a:=i;
  for i:=length(s) downto 1 do
   if s[i]='Z'then b:=i;
  writeln((b-a)+1);
 end.


var
  s:string;
  a,b,i:longint;
begin
  read(s);
  for i:=1 to length(s) do
    if s[i]='Z'then b:=i;
  for i:=length(s) downto 1 do
    if s[i]='A'then a:=i;
  writeln(b-a+1);
 end.


program hrn;
 var
  s:string;
  l,a,b,i:longint;
 begin
  read(s);
  l:=length(s);
  for i:=1 to l do if s[i]='Z'then b:=i;
  for i:=l downto 1 do if s[i]='A'then a:=i;
  writeln(b-a+1);
 end.


program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils;
var
  a,z:Integer;
  s:string;
begin
  try
    { TODO -oUser -cConsole Main : ここにコードを記述してください }
    Readln(s);

    for a := 1 to  Length(s) do
      if s[a]='A' then
        Break;

    for z := Length(s) downto 1 do
      if s[z]='Z' then
        Break;

    Writeln(z-a+1);
    Readln;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.


program vjudge149349B;
var s:ansistring;
    i,t1,t2:longint;
begin
  readln(s);
  for i:=1 to length(s) do if s[i]='Z' then t2:=i;
  for i:=length(s) downto 1 do if s[i]='A' then t1:=i;
  writeln(t2-t1+1);
end.


var ch:array[0..200007] of char;
    n,lx,rx:longint;
begin
  n:=0;
  while not(eoln) do
  begin
    inc(n);
    read(ch[n]);
  end;
  readln;
  lx:=1;rx:=n;
  while (ch[lx]<>'A') do inc(lx);
  while (ch[rx]<>'Z') do dec(rx);
  writeln(rx-lx+1);
end.


Score : 200 points

Problem Statement

You are given two integers K and S.

Three variable X, Y and Z takes integer values satisfying 0≤X,Y,Z≤K.

How many different assignments of values to X, Y and Z are there such that X + Y + Z = S?

Constraints

2≤K≤2500

0≤S≤3K

K and S are integers.

Input

The input is given from Standard Input in the following format:

K S

Output

Print the number of the triples of X, Y and Z that satisfy the condition.

Sample Input 1

2 2

Sample Output 1

6

There are six triples of X, Y and Z that satisfy the condition:

X = 0, Y = 0, Z = 2

X = 0, Y = 2, Z = 0

X = 2, Y = 0, Z = 0

X = 0, Y = 1, Z = 1

X = 1, Y = 0, Z = 1

X = 1, Y = 1, Z = 0

Sample Input 2

5 15

Sample Output 2

1

The maximum value of X + Y + Z is 15, achieved by one triple of X, Y and Z.


program taskf;
var k, x, y, z,s, ans : longint;
begin
    readln(k, s);
    ans := 0;

    for x := 1 to k do
    begin
        for y := 1 to k do
        begin
            for z := 1 to k do
            begin
                ans := x + y + z;
            end;
        end;
    end;

    while x + y + z = s do
    begin
        inc(ans);
    end;

    writeln(ans);
end.


var
    k,s,cnt,i,j,b,z : longint;
begin
    readln(k,s);
    if (s / k = 3) or (s = 0 ) then
    begin
        writeln('1');
        halt;
    end;
    cnt := 0;
    if k>s then k := s
    else if (s mod 3 = 0) and ((s=k) and (s>2)) then
        writeln(k*3+(s-3)*3+1)
    else if (s mod 3 = 0)  then
        writeln(k*3+1)
    else if (s=k) and (s>2) then
        writeln(k*3+(s-3)*3)
    else writeln(k*3);
    {else if k = s then
    begin
        k := s-1;
        z := z + 1;
    end;
    for i := 0 to k do
        for j := 0 to k do
            for b := 0 to k do
                if (i+j+b) = s then
                    cnt := cnt + 1;
    if z = 1 then
        writeln(cnt+3)
    else
    writeln(cnt);}

end.


var
    k,s,cnt,i,j,b,z : longint;
begin
    readln(k,s);
    if (s / k = 3) or (s = 0 ) then
    begin
        writeln('1');
        halt;
    end;
    cnt := 0;
    if k>s then k := s
    else if (s mod 3 = 0)  then
        writeln(k*3+1)
    else writeln(k*3);
    {else if k = s then
    begin
        k := s-1;
        z := z + 1;
    end;
    for i := 0 to k do
        for j := 0 to k do
            for b := 0 to k do
                if (i+j+b) = s then
                    cnt := cnt + 1;
    if z = 1 then
        writeln(cnt+3)
    else
    writeln(cnt);}

end.


var x,y,z,s,k,n,i,ct:longint;
begin
  ct:=0;
  readln(k,s);
  y:=s-k;
  z:=k-y;
  for x:=0 to k do begin
  while z>=0 do begin
         ct:=ct+1;
         y:=y+1;
         z:=z-1;
   end;
   if k=s then
     y:=0
   else if k-x-1<=s then
     y:=0
   else y:=s-k-x-1;
   z:=s-x-y-1;
   end;
   if s=(k*3) then
    writeln(1)
   else writeln(ct);
end.


program taskF;
var
    k, s, x, y, z : longint;
    ans : longint;

begin
    read(k,s);
    ans := 0;
    for x := 0 to k do
    begin
        for y := 0 to k do
        begin
            for z := 0 to k do
            begin
                if (x + y + z = s) then
                begin
                    ans := ans + 1;
                end;
            end;
        end;
    end;
    writeln(ans);
end.


var
  cnt,k,s,x,y,z:longint;
begin
  readln(k,s);
  if (s=3*k) then begin
    writeln('1');
    exit;
  end;
  cnt:=0;
  if (s<k) then begin
      for x:=0 to s do
        for y:=0 to s do
          for z:=0 to s do
            if (x+y+z=s) then
              inc(cnt);
      writeln(cnt);
  end
  else begin
    writeln(k*3);
  end;
end.


var
    k,s,cnt,i,j,b,z : longint;
begin
    readln(k,s);
    if (s / k = 3) or (s = 0 ) then
    begin
        writeln('1');
        halt;
    end;
    cnt := 0;
    if k>s then k := s;
    writeln(k*3);
    {else if k = s then
    begin
        k := s-1;
        z := z + 1;
    end;
    for i := 0 to k do
        for j := 0 to k do
            for b := 0 to k do
                if (i+j+b) = s then
                    cnt := cnt + 1;
    if z = 1 then
        writeln(cnt+3)
    else
    writeln(cnt);}

end.


var
    k,s,cnt,i,j,b,z : longint;
begin
    readln(k,s);
    if (s / k = 3) and (s = 0 ) then
    begin
        writeln('1');
        halt;
    end;
    if k>s then k := s
    else if k = s then
    begin
        k := s-1;
        z := z + 1;
    end;
    for i := 0 to k do
        for j := 0 to k do
            for b := 0 to k do
                if (i+j+b) = s then
                    cnt := cnt + 1;
    if z = 1 then
        writeln(cnt+3)
    else
    writeln(cnt);
end.


var
    k,s,cnt,i,j,b : longint;
begin
    readln(k,s);
    if (s / k = 3) and (s = 0 ) then
    begin
        writeln('1');
        halt;
    end;
    if k>s then k := s;
    for i := 0 to k do
        for j := 0 to k do
            for b := 0 to k do
                if (i+j+b) = s then
                    cnt := cnt + 1;
    writeln(cnt);
end.


var

  S : ansistring;

begin

  readln(S);

    while pos('dreameraser', S) <> 0 do
      delete(S, pos('dreameraser', S), 11);

    while pos('dreamerase', S) <> 0 do
      delete(S, pos('dreamerase', S), 10);

    while pos('dreamererase', S) <> 0 do
      delete(S, pos('dreamererase', S), 12);

    while pos('dreamereraser', S) <> 0 do
      delete(S, pos('dreamereraser', S), 13);

    while pos('dreamer', S) <> 0 do
      delete(S, pos('dreamer', S), 7);

    while pos('dream', S) <> 0 do
      delete(S, pos('dream', S), 5);

    while pos('eraser', S) <> 0 do
      delete(S, pos('eraser', S), 6);

    while pos('erase', S) <> 0 do
      delete(S, pos('erase', S), 5);

    if length(S) = 0 then
      writeln('YES')
    else
      writeln('NO');

end.


var
    k,s,cnt,i,j,b : longint;
begin
    readln(k,s);
    if (s / k = 3) and (s = 0 ) then
    begin
        writeln('1');
        halt;
    end;
    if k>s then k := s;
    for i := 0 to k-1 do
        for j := 0 to k-1 do
            for b := 0 to k-1 do
                if (i+j+b) = s then
                    cnt := cnt + 1;
    writeln(cnt+3);
end.


var

  k, s, x, y, z, cnt : longint;

begin

  readln(k, s);
  cnt := 0;

  for x := 0 to k do
    for y := 0 to x do
      for z := 0 to y do
        if x + y + z = s then
          inc(cnt);

  if 3*k = S then
    writeln(1)
  else
    writeln(cnt*3);

end.


var

  k, s, x, y, z, cnt : longint;

begin

  readln(k, s);
  cnt := 0;

  for x := 0 to k do
    for y := 0 to x do
      for z := 0 to y do
        if x + y + z = s then
          inc(cnt);

  writeln(cnt*3);

end.


program taskF;
var
    k, s, x, y, z : longint;
    ans : longint;

begin
    readln(k,s);
    ans := 0;
    for x := 0 to k do
    begin
        for y := 0 to k do
        begin
            for z := 0 to k do
            begin
                if (x + y + z = s) then
                begin
                    ans := ans + 1;
                end;
            end;
        end;
    end;
    writeln(ans);
end.


var
    k,s,cnt,i,j,b : longint;
begin
    readln(k,s);
    for i := 0 to k-1 do
        for j := 0 to k-1 do
            for b := 0 to k-1 do
                if (i+j+b) = s then
                    cnt := cnt + 1;
    if (s / k = 3) then writeln('1')
    else
        writeln(cnt+3);
end.


var
    k,s,cnt,i,j,b : longint;
begin
    readln(k,s);
    for i := 0 to k do
        for j := 0 to k do
            for b := 0 to k do
                if (i+j+b) = s then
                    cnt := cnt + 1;
    writeln(cnt);
end.


var k,s,x,y,z,total,sum,i,j:longint;
begin
    total:=0;
    sum:=0;
    readln(k,s);
    for i:=0 to k do
    begin
        if s<i then
            break;
        for j:=0 to k do
        begin
            total:=i+j;
            if (total > s) then
                break;
            if (s-total<=k) then
                inc(sum);
        end;

    end;
    writeln(sum);
end.


var
  cnt,k,s,x,y,z:longint;
begin
  readln(k,s);
  if (s=3*k) then begin
    writeln('1');
    exit;
  end;
  cnt:=0;
  if (s<k) then begin
      for x:=0 to s do
        for y:=0 to s do
          for z:=0 to s do
            if (x+y+z=s) then
              inc(cnt);
  end
  else begin
    for x:=0 to k do
        for y:=0 to k do
          for z:=0 to k do
            if (x+y+z=s) then
              inc(cnt);
  end;
  writeln(cnt);
end.


//uses crt;
var x,y,z,s,k,n,i,ct:longint;
begin
  ct:=0;
  y:=0;
  readln(k,s);
  z:=k;
  for x:=0 to k do begin
  while z>=0 do begin
         ct:=ct+1;
         y:=y+1;
         z:=z-1;
   end;
   y:=0;
   z:=s-x-y-1;
   end;
   if s=(k*3) then
    writeln(1)
   else writeln(ct);
end.


var
  cnt,k,s,x,y,z:longint;
begin
  readln(k,s);
  cnt:=0;
  if (s<k) then begin
      for x:=0 to s do
        for y:=0 to s do
          for z:=0 to s do
            if (x+y+z=s) then
              inc(cnt);
  end
  else begin
    for x:=0 to k do
        for y:=0 to k do
          for z:=0 to k do
            if (x+y+z=s) then
              inc(cnt);
  end;
  writeln(cnt);
end.


var max,sum,ans,x,y,z:longint;

begin
   readln(max,sum);
   ans:=0;
   for x := 0 to max do begin
      for y := 0 to x do begin
	     for z := 0 to y do begin
		    if x+y+z=sum then
			 begin
			    if (x=y) and (y=z) then inc(ans)
				 else if (x=y) or (y=z) or (x=z) then inc(ans,3)
				 else inc(ans,6);
		     end;
		  end;
	   end;
	end;
	writeln(ans);
end.


var

  k, s, x, y, z, cnt : longint;

begin

  readln(k, s);
  cnt := 0;

  for x := 0 to k do
    for y := 0 to k do
      for z := 0 to k do
        if x + y + z = s then
          inc(cnt);

  writeln(cnt);

end.


var
  cnt,k,s,x,y,z:longint;
begin
  readln(k,s);
  cnt:=0;
  for x:=0 to k do
    for y:=0 to k do
      for z:=0 to k do
        if (x+y+z=s) then
          inc(cnt);
  writeln(cnt);
end.


var max,sum,ans,x,y,z:longint;

begin
   readln(max,sum);
   ans:=0;
   for x := 0 to max do begin
      for y := 0 to x do begin
	     for z := 0 to y do begin
		    if x+y+z=sum then
			 begin
			    inc(ans);
				 if x<>y then inc(ans);
				 if z<>y then inc(ans);
				 if x<>z then inc(ans);
		     end;
		  end;
	   end;
	end;
	writeln(ans);
end.


var max,sum,ans,x,y,z:longint;

begin
   readln(max,sum);
   ans:=0;
   for x := 0 to max do begin
      for y := 0 to x do begin
	     for z := 0 to y do begin
		    if x+y+z=sum then inc(ans);
		  end;
	   end;
	end;
	writeln(ans);
end.


var max,sum,ans,x,y,z:longint;

begin
   readln(max,sum);
   ans:=0;
   for x := 0 to max do begin
      for y := 0 to max do begin
	     for z := 0 to max do begin
		    if x+y+z=sum then inc(ans);
		  end;
	   end;
	end;
	writeln(ans);
end.


uses math;
var x,y,a,n,k,z:longint;
begin
  readln(k,n);
  for x:=0 to k do
    for y:=max(n-x-k,0) to min(n-x,k) do
      inc(a);
  writeln(a);
end.


Var s,k,ans,x,y,z:longint;
Begin
  readln(k,s);
  for x:=0 to k do
   for y:=0 to k do
      if(s-x-y>=0)and(s-x-y<=k) then inc(ans);
      writeln(ans);
End.


Var s,k,ans,x,y,z:longint;
Begin
  readln(k,s);
  for x:=0 to k do
   for y:=0 to k do
    for z:=0 to k do
      if(x+y+z=s) then inc(ans);
      writeln(ans);
End.


uses math;
var
 i1,i2,s,n,k,z:longint;
begin
 readln(k,n);
 for i1:=0 to k do
  for i2:=max(n-i1-k,0) to min(n-i1,k) do
   inc(s);
 writeln(s);
end.


var
  a,b,i,j,k,s:longint;
begin
  readln(a,b);
  for i:=0 to a do
    for j:=0 to a do
      begin
        k:=b-i-j;
        if (k>=0)and(k<=a) then inc(s);
      end;
  writeln(s);
end.


var
  a,b,i,j,k,s:longint;
begin
  readln(a,b);
  for i:=0 to a do
    for j:=0 to a do
      begin
        k:=b-i-j;
        if k in [0..a] then inc(s);
      end;
  writeln(s);
end.


uses math;
var x,y,a,n,k,z:longint;
begin
  readln(k,n);
  for x:=0 to k do
    for y:=max(n-x-k,0) to min(n-x,k) do
    begin{
      writeln(x,' ',y,' ',n-x-y);}
      inc(a);
    end;
  writeln(a);
end.


var x,y,z,n,k,a:longint;
begin
  readln(k,n);
  for x:=0 to k do
    for y:=0 to k do
    begin
      z:=n-x-y;
      if (z>=0) and (z<=k) then
        inc(a);
    end;
  writeln(a);
end.


var x,y,z,n,k,a:longint;
begin
  readln(k,n);
  for x:=0 to k do
    for y:=0 to k do
      for z:=0 to k do
        if x+y+z=n then
          inc(a);
  writeln(a);
end.


var x,y,z,n,k,a:longint;
begin
  readln(n,k);
  for x:=0 to k do
    for y:=0 to k do
      for z:=0 to k do
        if x+y+z=n then
          inc(a);
  writeln(a);
end.


var x,y,z,n,k,a:longint;
begin
  readln(n,k);
  for x:=1 to k do
    for y:=1 to k do
      for z:=1 to k do
        if x+y+z=n then
          inc(a);
  writeln(a);
end.


var
  k,s,x,y,i:longint;
begin
  readln(k,s);
  for x:=0 to k do
   for y:=0 to k do
    if (s-x-y<=k) and (s-x-y>=0) then i:=i+1;
  writeln(i);
end.


var k,s,i,j,ans:longint;
begin
    read(k,s);
    for i:=0 to k do
      for j:=0 to k do
       if(s-i-j>=0)and(s-i-j<=k) then inc(ans);
    write(ans);
end.


var k,s,i,j,ans:longint;
begin
    read(k,s);
    for i:=0 to k do
      for j:=0 to k-i do
       if(s-i-j>=0)and(s-i-j<=k) then inc(ans);
    write(ans);
end.


var k,s,i,j,k2,ans:longint;
begin
    read(k,s);
    for i:=0 to k do
      for j:=0 to k-i do
        begin
            k2:=k-i-j;
            if i+j+k2=s then inc(ans);
        end;
    write(ans);
end.


var n,m,i,j,q:longint;
begin
readln(n,m);
for i:=0 to n do
  for j:=0 to n do
    if (m-i-j<=n) and (m-i-j>=0) then q:=q+1;
writeln(q);
end.


var
  k,s,i,j,x,sum:longint;
begin
  readln(k,s);
  for i:=0 to k do
    for j:=0 to k do
    begin
      x:=s-i-j;
      if (i+j+x=s) and (x>=0) and (x<=k) then inc(sum);
    end;
  writeln(sum);
end.


var
  n,m,i,j,k:longint;
begin
  read(m,n);
  for i:=0 to m do
   for j:=0 to m do
     begin
      if (n-i-j>=0) and (n-i-j<=m) then inc(k);
end;
write(k);
end.


var
  n,m,i,j,k:longint;
begin
  read(m,n);
  for i:=0 to m do
   for j:=0 to m do
     begin
      if (i+j+(m-i-j)=m) and (i+j<=m) then inc(k);
end;
write(k);
end.


var
  i,j,k,l,s,ans:longint;
begin
  readln(k,s);
  for i:=0 to k do
  for j:=0 to k do
    if(s-i-j>=0)and(s-i-j<=k)then inc(ans);
  writeln(ans);
end.


var
  i,j,k,l,s,ans:longint;
begin
  readln(k,s);
  for i:=0 to k do
  for j:=0 to k do
  for l:=0 to k do
    if i+j+l=s then
    inc(ans);
  writeln(ans);
end.


var
 k,s,x,y,sum:longint;
begin
 readln(k,s);
 for x:=0 to k do
  for y:=0 to k do
   if (s-x-y<=k) and (s-x-y>=0) then inc(sum);
 writeln(sum);
end.


var
 x,y,z,k,s,ans:longint;
begin
 read(k,s);
 for x:=0 to k do
     for y:=0 to k do
         if (s-x-y>=0) and (s-x-y<=k) then inc(ans);

  writeln(ans);
end.


var
 x,y,z,k,s,ans:longint;
begin
 read(k,s);
 for x:=0 to k do
     for y:=0 to k do
         for z:=0 to k do
            if x+y+z=s then begin inc(ans);break;end;

  writeln(ans);
end.


var
 x,y,z,k,s,ans:longint;
begin
 read(k,s);
 for x:=0 to k do
     for y:=0 to k do
         for z:=0 to k do
            if x+y+z=s then inc(ans);
  writeln(ans);
end.


var
 x,y,z,k,s,ans:longint;
begin
 read(k,s);
 for x:=1 to k do
     for y:=1 to k do
         for z:=1 to k do
            if x+y+z=s then inc(ans);
  writeln(ans);
end.


var
  k,s,x,y,iii:longint;
begin
  readln(k,s);
  for x:=0 to k do
   for y:=0 to k do
    if (s-x-y<=k) and (s-x-y>=0) then iii:=iii+1;
  writeln(iii);
end.


var k,s,i,j,p,o:longint;
begin
readln(k,s);
for i:=0 to k do
  for j:=0 to k do
    if(i+j>s)then break
    else if(s-i-j<=k)then inc(p);write(p);
end.


var
 i,j,k,x,y,s:longint;
begin
 readln(x,y);
 for i:=0 to x do
  for j:=0 to x do
   begin
    if (y-i-j>=0) and (y-i-j<=x) then
     inc(s);
   end;
 writeln(s);
end.


var
 i,j,k,x,y,ans:longint;
begin
 read(x,y);
 for i:=0 to x do
  for j:=0 to x do
   begin
    if (y-i-j>=0) and (y-i-j<=x) then inc(ans);
   end;
 writeln(ans);
end.


var
 i,j,k,x,y,ans:longint;
begin
 read(x,y);
 for i:=0 to x do
  for j:=0 to x do
   for k:=0 to y-i-j do
    if i+j+k=y then inc(ans);
 writeln(ans);
end.


program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils;
var
  k,s,x,y,z,sum:Integer;
begin
  try
    { TODO -oUser -cConsole Main : ここにコードを記述してください }
    Read(k);
    Readln(s);

    sum:=0;

    for z := 0 to k do begin
      for y := 0 to k do begin
        for x := z to k do begin
          if x+y+z=s then begin
            if x=z then
              Inc(sum)
            else
              sum:=sum+2;
            Break;
          end;
        end;
      end;
    end;

    Writeln(sum);
    Readln;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.


var a,b,c,d,e,f,g,h,j,k,s,sum : longint ;
begin
 readln(k,s);
 for a:=0 to k do
  for b:=0 to k do
   begin
    if a+b=s then
     c:=0
    else if a+b<s then
     c:=s-a-b;
    if (c<=k)and(a+b+c=s) then
     begin
      sum:=sum+1;
     end;
   end;
 writeln(sum);
end.


program taskH;
var k,s,sum,x,y,z,temp:longint;
begin
readln(k,s);
for x:=0 to k do
begin
  y:=s-x;
  temp:=k*2;
  if y>temp then
  continue;
  if y=temp then
    begin
    sum:=sum+1;
    end;
  if y<temp then
  begin
    for y:=0 to k-x do
    begin
      if y+k<s then
      break
      else
      sum:=sum+1;
    end;
  end;
end;
writeln(sum);
end.


var k,s,a,b,c,d,e,f,sum : longint ;
begin
 readln(k,s);
 for a:=0 to k do
  for b:=a to k do
   for c:=b to k do
    begin
     if a+b+c=s then
      begin
      if (a<>b)and(a<>c)and(c<>b) then
       sum:=sum+6
      else if (a=b)and(a<>c)  then
       sum:=sum+3
      else if (b=c)and(b<>a) then
       sum:=sum+3
      else if (a=c) and (a<>c) then
       sum:=sum+3
      else
       sum:=sum+1;
 //      writeln(a,b:2,c:2,sum:2);
     end;
    end;
 writeln(sum);
end.


var
m,n,i,j,k,x,y,z,s:longint;
q:int64;
begin
    readln(k,s);
    q:=0;
    for i:=0 to k do
        for x:=0 to k do
        for j:=0 to k do
        if i+j+x=s then
        inc(q);
    writeln(q);
end.


var k,s,i,j,z,ans:longint;
begin
    readln(k,s);
    for i:=0 to k do
    begin
        for j:=0 to k do
        begin
            if (s-i-j<=k)and(s-i-j>=0) then ans:=ans+1;
            if j>s then break;
        end;
    end;
    writeln(ans);
end.


var k,s,a,b,c,d,e,f,sum : longint ;
begin
 readln(k,s);
 for a:=0 to k do
  for b:=a to k do
   for c:=b to k do
    begin
     if a+b+c=s then
      if (a<>b)or(a<>c)or(c<>b) then
       sum:=sum+3
      else
       sum:=sum+1;
    end;
 writeln(sum);
end.


var k,s,a,b,c,d,e,f,sum : longint ;
begin
 readln(k,s);
 for a:=0 to k do
  for b:=0 to k do
   for c:=0 to k do
    begin
     if a+b+c=s then
      sum:=sum+1;
    end;
 writeln(sum);
end.


var k,s,i,j,z,ans:longint;
begin
    readln(k,s);
    for i:=0 to k do
    begin
        for j:=0 to k do
        begin
            for z:=0 to k do
            begin
                if i+j+z=s then
                begin
                    ans:=ans+1;
                    if i+j+z>s then break;
                end;
            end;
            if i+j>s then break;
        end;
        if i>s then break;
    end;
    writeln(ans);
end.


program taskH;
var k,s,sum,x,y,z:longint;
begin
readln(k,s);
for x:=0 to k do
begin
for y:=0 to k do
begin
z:=s-x-y;
if (z<=k) and (z>=0) then
sum:=sum+1;
end;
end;
writeln(sum);
end.


var
k,s,o,i,j:longint;
begin
readln(k,s);
for i := 0 to k do
begin
for j := 0 to k do
begin
if (s-i-j<=k) and (s-i-j>=0) then o:=o+1;
end;
end;
writeln(o);
end.


var
s:ansistring;
begin
read(s);
if (pos('dream',s)<>0)and(pos('dream',s)+4=length(s)) then writeln('YES')
  else if (pos('dreamer',s)<>0)and(pos('dreamer',s)+6=length(s)) then writeln('YES')
    else if (pos('erase',s)<>0)and(pos('erase',s)+4=length(s)) then writeln('YES')
      else if (pos('eraser',s)<>0)and(pos('eraser',s)+5=length(s)) then writeln('YES')
                                                                   else writeln('NO');
end.

Score : 300 points

Problem Statement

You are given a string S consisting of lowercase English letters.
Another string T is initially empty.
Determine whether it is possible to obtain S = T by performing the following operation an arbitrary number of times:

Append one of the following at the end of T: dream, dreamer, erase and eraser.

Constraints

1≦|S|≦10^5

S consists of lowercase English letters.

Input

The input is given from Standard Input in the following format:

S

Output

If it is possible to obtain S = T, print YES. Otherwise, print NO.

Sample Input 1

erasedream

Sample Output 1

YES

Append erase and dream at the end of T in this order, to obtain S = T.

Sample Input 2

dreameraser

Sample Output 2

YES

Append dream and eraser at the end of T in this order, to obtain S = T.

Sample Input 3

dreamerer

Sample Output 3

NO


var
  n:string;
 function pd(n:string):boolean;
  var
    l:longint;
  begin
    l:=length(n);
    if(n[l]='m')and(n[l-1]='a')and(n[l-2]='e')and(n[l-3]='r')and(n[l-4]='d')then exit(true);
    if(n[l]='r')and(n[l-1]='e')and(n[l-2]='m')and(n[l-3]='a')and(n[l-4]='e')and(n[l-5]='r')and(n[l-6]='d')then exit(true);
    if(n[l]='e')and(n[l-1]='s')and(n[l-2]='a')and(n[l-3]='r')and(n[l-4]='e')then exit(true);
    if(n[l]='r')and(n[l-1]='e')and(n[l-2]='s')and(n[l-3]='a')and(n[l-4]='r')and(n[l-5]='e')then exit(true);
    exit(false);
  end;
begin
  readln(n);
  if pd(n) then writeln('YES') else writeln('NO');
end.


const a:array[0..3]of string=('eraser','erase','dreamer','dream');
var s:ansistring;
    i,t,x:longint;
begin
  readln(s);
  for i:=0 to 3 do
  begin
    t:=pos(a[i],s);
    x:=length(a[i]);
    while t<>0 do
    begin
      delete(s,t,x);
      t:=pos(a[i],s);
    end;
  end;
  if length(s)<>0 then
    writeln('NO')
  else
    writeln('YES');
end.


const a:array[0..3]of string=('eraser','erase','dreamer','dream');
var s:ansistring;
    i:longint;
begin
  readln(s);
  for i:=0 to 3 do
    while pos(a[i],s)<>0 do
      delete(s,pos(a[i],s),length(a[i]));
  if length(s)<>0 then
    writeln('NO')
  else
    writeln('YES');
end.


var
 n:ansistring;
procedure dfs(s:string);
begin
 if s='' then begin writeln('YES'); halt; end;
 if not((copy(s,1,5)='dream') or (copy(s,1,5)='erase')
    or (copy(s,1,7)='dreamer') or (copy(s,1,6)='eraser'))
     then exit;
 if copy(s,1,5)='dream' then dfs(copy(s,6,length(s)));
 if copy(s,1,5)='erase' then dfs(copy(s,6,length(s)));
 if copy(s,1,6)='eraser' then dfs(copy(s,7,length(s)));
 if copy(s,1,7)='dreamer' then dfs(copy(s,8,length(s)));
end;
begin
 readln(n);
 dfs(n);
 writeln('NO');
end.


var
  s:ansistring;
  l:longint;
begin
  readln(s);
  if length(s)<5 then begin writeln('NO');exit;end;
  l:=length(s);
  if (s[l]='m') and (s[l-1]='a') and (s[l-2]='e') and (s[l-3]='r') and (s[l-4]='d') then begin writeln('YES');exit;end;
  if (s[l]='r') and (s[l-1]='e') and (s[l-2]='m') and (s[l-3]='a') and (s[l-4]='e') and (s[l-5]='r') and (s[l-6]='d') then begin writeln('YES');exit;end;
  if (s[l]='e') and (s[l-1]='s') and (s[l-2]='a') and (s[l-3]='r') and (s[l-4]='e') then begin writeln('YES');exit;end;
  if (s[l]='r') and (s[l-1]='e') and (s[l-2]='s') and (s[l-3]='a') and (s[l-4]='r') and (s[l-5]='e') then begin writeln('YES');exit;end;
  writeln('NO');
end.


var
  s:ansistring;
  l:longint;
begin
  readln(s);
  if length(s)<5 then begin writeln('NO');exit;end;
  l:=length(s);
  if (s[l]='m') and (s[l-1]='a') and (s[l-2]='a') and (s[l-3]='r') and (s[l-4]='d') then begin writeln('YES');exit;end;
  if (s[l]='r') and (s[l-1]='e') and (s[l-2]='m') and (s[l-3]='a') and (s[l-4]='e') and (s[l-5]='r') and (s[l-6]='d') then begin writeln('YES');exit;end;
  if (s[l]='e') and (s[l-1]='s') and (s[l-2]='a') and (s[l-3]='r') and (s[l-4]='e') then begin writeln('YES');exit;end;
  if (s[l]='r') and (s[l-1]='e') and (s[l-2]='s') and (s[l-3]='a') and (s[l-4]='r') and (s[l-5]='e') then begin writeln('YES');exit;end;
  writeln('NO');
end.


program ABC049C;
uses StrUtils;
var
	T: array[0..3] of string = ('dream','dreamer','erase','eraser');
	s: string;
	i,c,l,k: integer;
begin
	for i:=0 to 3 do begin
		T[i]:=ReverseString(T[i]);
	end;
	readln(s);
	s:=ReverseString(s);
	c:=0;
	l:=Length(s);
	while c<l do begin
		k:=-1;
		for i:=0 to 3 do begin
			if copy(s,c+1,Length(T[i]))=T[i] then begin
				k:=Length(T[i]);
			end;
		end;
		if k<0 then begin
			writeln('NO');
			exit;
		end;
		c:=c+k;
	end;
	writeln('YES');
end.


program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils;
var
  s:string;
  i:Integer;
begin
  try
    { TODO -oUser -cConsole Main : ここにコードを記述してください }
    Readln(s);

    while True do
      if (Copy(s,length(s)-6,7)='dreamer') then
        Delete(s,length(s)-6,7)
      else if (Copy(s,length(s)-5,6)='eraser') then
        Delete(s,length(s)-5,6)
      else if (Copy(s,length(s)-4,5)='dream')or(Copy(s,length(s)-4,5)='erase') then
        Delete(s,length(s)-4,5)
      else if s='' then begin
        Writeln('YES');
        break;
      end else begin
        Writeln('NO');
        break;
      end;

    Readln;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.


var
m,n,i,j,k,x,y,z:longint;
s,t:ansistring;
begin
    readln(s);
    while true do
    begin

        m:=pos('eraser',s);
        if m=0 then break else
        delete(s,m,6);
    end;
while true do
    begin

        m:=pos('erase',s);
        if m=-0 then break else
        delete(s,m,5);
    end;
    while true do
    begin

        m:=pos('dreamer',s);
        if m=0 then break else
        delete(s,m,7);
    end;
    while true do
    begin

        m:=pos('dream',s);
        if m=-0 then break else
        delete(s,m,6);
    end;
    if length(s)=0 then writeln('YES') else writeln('NO');
end.


var
m,n,i,j,k,x,y,z:longint;
s,t:ansistring;
begin
    readln(s);
    while true do
    begin

        m:=pos('eraser',s);
        if m=0 then break else
        delete(s,m,6);
    end;
    while true do
    begin

        m:=pos('dreamer',s);
        if m=0 then break else
        delete(s,m,7);
    end;
    while true do
    begin

        m:=pos('dream',s);
        if m=-0 then break else
        delete(s,m,6);
    end;
    while true do
    begin

        m:=pos('erase',s);
        if m=-0 then break else
        delete(s,m,5);
    end;
    if length(s)=0 then writeln('YES') else writeln('NO');
end.


var a,b,c:ansistring;
i,j,p,l,x,y:longint;
begin
    readln(a);
    l:=length(a);
    while l>=5 do
    begin
        begin
       // writeln(a);
            b:=copy(a,1,6);
            if b='eraser'then delete(a,1,6)
            else
            begin
                b:=copy(a,1,7);
                if b='dreamer'then
                begin
                   x:=length(a);
                  //writeln(x);
                   if x>=10 then
                   begin
                       c:=copy(a,6,5);
                     //  writeln(c);
                       if c='erase'then
                       begin
                     //  writeln(c);
                         delete(a,1,5);
                       end
                       else delete(a,1,7);
                   end
                   else delete(a,1,7);
                end
                else
                begin
                    b:=copy(a,1,5);
                    if b='erase' then delete(a,1,5)
                    else
                    begin
                       b:=copy(a,1,5);
                       if (b='dream') then
                       begin
                          delete(a,1,5);
                       end
                       else
                       begin
                         writeln('NO');
                         halt;
                       end;
                   end;
                end;
            end;
        end;
        l:=length(a);
        if l=0 then
        begin
            writeln('YES');
            halt;
        end;
    end;
    writeln('NO');
end.


var s,t:ansistring;
ii,k,l,m,n,x,y,z:longint;
a,b,c,d,e,f,g,h,i,j:string;
begin
        readln(s);
        n:=length(s);
        s:=s+' ';
        a:='dream';
        b:='dreamer';
        c:='erase';
        d:='eraser';

        e:='dreamerdream';
        f:='dreamerase';
        g:='dreameraser';
        h:='dreamererase';
        i:='dreamereraser';
        j:='erasererase';

        for ii:=1 to n do
        begin
                t:=t+s[ii];
                if ii=n then
                begin
                        if(t=a) or (t=b) or (t=c) or (t=d) or (t=e) or (t=f) or (t=g) or (t=h) or (t=i) or (t=j) then
                        break;
                end;
                if (t=g) or (t=i) or (t=j) or (t=e) then t:=''
                else if ((t=f) or (t=h)) and ((s[ii+1]<>'r') and (s[ii+1]<>'d') and (s[ii+1]<>'e') and (ii<n)) then
		begin
			writeln('NO');
			halt;
		end else
                if ((pos(a,t)=0) and (pos(t,a)=0) and (pos(b,t)=0) and (pos(t,b)=0) and (pos(c,t)=0) and (pos(t,c)=0) and (pos(d,t)=0) and (pos(t,d)=0)) then
                begin
                        writeln('NO');
                        halt;
                end
                else if ((t=f) or (t=h)) and (s[ii+1] <> 'r') then t:='';
        end;
        writeln('YES');
end.


var a,b,c:ansistring;
i,j,p,l,x,y:longint;
begin
    readln(a);
    l:=length(a);
    while l>=5 do
    begin
        begin
            b:=copy(a,1,6);
            if b='eraser'then delete(a,1,6)
            else
            begin
                b:=copy(a,1,7);
                if b='dreamer'then
                begin
                   x:=length(a);
                  //writeln(x);
                   if x>=10 then
                   begin
                       c:=copy(a,6,5);
                       if c='erase'then
                       begin
                     //  writeln(c);
                         delete(a,1,5);
                       end;
                   end
                   else delete(a,1,7)
                end
                else
                begin
                    b:=copy(a,1,5);
                    if b='erase' then delete(a,1,5)
                    else
                    begin
                       b:=copy(a,1,5);
                       if (b='dream') then
                       begin
                          delete(a,1,5);
                       end
                       else
                       begin
                         writeln('NO');
                         halt;
                       end;
                   end;
                end;
            end;
        end;
        l:=length(a);
        if l=0 then
        begin
            writeln('YES');
            halt;
        end;
    end;
    writeln('NO');
end.


var
m,n,i,j,k,x,y,z:longint;
s,t:ansistring;
begin
    readln(s);
    while true do
    begin

        m:=pos('dreamer',s);
        if m=0 then break else
        delete(s,m,7);
    end;
    while true do
    begin

        m:=pos('eraser',s);
        if m=0 then break else
        delete(s,m,6);
    end;
    while true do
    begin

        m:=pos('dream',s);
        if m=-0 then break else
        delete(s,m,6);
    end;
    while true do
    begin

        m:=pos('erase',s);
        if m=-0 then break else
        delete(s,m,5);
    end;
    if length(s)=0 then writeln('YES') else writeln('NO');
end.


program taskd;
var s,s5,s6,s7,s10:string;
    process,i,j,len:longint;
begin
readln(s);
process:=1;
len:=Length(s);
while process<len do
begin
  s5:=Copy(s,process,5);
  s6:=Copy(s,process,6);
  s7:=Copy(s,process,7);
  s10:=Copy(s,process,10);
  if (s7='dreamer') and (s10<>'dreamerase') then
  process:=process+7
  else if s6='eraser' then
  process:=process+6
  else if (s5='dream') or (s5='erase') then
  process:=process+5
  else
  break;
end;
if process<=len then
writeln('NO')
else
writeln('YES');
end.


var s,t:ansistring;
i,j,k,l,m,n:longint;
begin
        readln(s);
        n:=length(s);
        for i:=1 to n do
        begin
                t:=t+s[i];
                if (t='dream') then t:=''
                else if (t='dreamer') then t:=''
                else if (t='erase') then t:=''
                else if (t='eraser') then t:=''
                else if (length(t)>=7) or (i=n) then
                begin
                        writeln('NO');
                        halt;
                end;
        end;
        writeln('YES');
end.


var s,s2:ansistring;
pos1,pos2,pos3,pos4,cnt,i:longint;
begin
  readln(s);
  for i:=length(s) downto 1 do
    s2:=s2+s[i];
  cnt:=1;
  pos1:=0;
  pos2:=0;
  pos3:=0;
  pos4:=0;
  while (true) do
    begin
      pos1:=pos('maerd',s2);
      pos2:=pos('remaerd',s2);
      pos3:=pos('esare',s2);
      pos4:=pos('resare',s2);
      //writeln(s2);
      if (length(s2)=0) then break
      else if (pos1=0) and (pos2=0) and (pos3=0) and (pos4=0) then
        begin
          writeln('NO');
          halt;
        end
      else if (pos1=1) and ((pos2=0) or (pos1<pos2)) and ((pos3=0) or (pos1<pos3)) and ((pos4=0) or (pos1<pos4)) then
        begin
          delete(s2,1,5);
          //writeln('1');
        end
        else if (pos2=1) and ((pos1=0) or (pos2<pos1)) and ((pos3=0) or (pos2<pos3)) and ((pos4=0) or (pos2<pos4)) then
        begin
          delete(s2,1,7);
          //writeln('2');
        end
        else if (pos3=1) and ((pos1=0) or (pos3<pos1)) and ((pos2=0) or (pos3<pos2)) and ((pos4=0) or (pos3<pos4)) then
        begin
          delete(s2,1,5);
          //writeln('3');
        end
        else if (pos4=1) and ((pos1=0) or (pos4<pos1)) and ((pos2=0) or (pos4<pos2)) and ((pos3=0) or (pos4<pos3)) then
        begin
          delete(s2,1,6);
          //writeln('4');
        end
        else begin
        if length(s2)=0 then break;
          writeln('NO');
          halt;
        end;
    end;
    writeln('YES');
end.


var cc,so: ansistring ;
    a,b,c,d,e,f,g,gg,yo : longint ;
begin
 readln(cc);
 a:=length(cc);
 while (gg=0)and(yo=0) do
  begin
   so:='';
   for b:=a-4 to a do
    so:=so+cc[b];
//   writeln(so);
   a:=a-5;
   if so='dream' then
    a:=a
   else if so='erase' then
    a:=a
   else if so='raser' then
    begin
     if a>=1 then
      begin
       if (cc[a]='e')then
        a:=a-1
       else
        gg:=1;
      end
     else
      gg:=1;
    end
   else if so='eamer'then
    begin
     if a>=2 then
      begin
       if (cc[a]='r')and(cc[a-1]='d') then
        a:=a-2
       else
        gg:=1;
      end
     else
      gg:=1;
    end
   else
    gg:=1;
   if a=0 then
    yo:=1
   else if a<5 then
    gg:=1

//   writeln(cc[a-1],a:2);
  end;
 if yo=1 then
 writeln('YES')
 else if gg=1 then
  writeln('NO');

end.


var s,t:ansistring;
i,j,k,l,m,n:longint;
begin
        readln(s);
        n:=length(s);
        for i:=1 to n do
        begin
                t:=t+s[i];
                if (t='dream') then t:=''
                else if (t='dreamer') then t:=''
                else if (t='erase') then t:=''
                else if (t='eraser') then t:=''
                else if (length(t)>7) or (i=n) then
                begin
                        writeln('NO');
                        halt;
                end;
        end;
        writeln('YES');
end.


var s,s2:ansistring;
pos1,pos2,pos3,pos4,cnt,i:longint;
begin
  readln(s);
  for i:=length(s) downto 1 do
    s2:=s2+s[i];
  cnt:=1;
  pos1:=0;
  pos2:=0;
  pos3:=0;
  pos4:=0;
  while (true) do
    begin
      pos1:=pos('maerd',s2);
      pos2:=pos('remaerd',s2);
      pos3:=pos('esare',s2);
      pos4:=pos('resare',s2);
      //writeln(s2);
      if (length(s2)=0) then break
      else if (pos1=0) and (pos2=0) and (pos3=0) and (pos4=0) then
        begin
          writeln('NO');
          halt;
        end
      else if (pos1<>0) and ((pos2=0) or (pos1<pos2)) and ((pos3=0) or (pos1<pos3)) and ((pos4=0) or (pos1<pos4)) then
        begin
          delete(s2,1,5);
          //writeln('1');
        end
        else if (pos2<>0) and ((pos1=0) or (pos2<pos1)) and ((pos3=0) or (pos2<pos3)) and ((pos4=0) or (pos2<pos4)) then
        begin
          delete(s2,1,7);
          //writeln('2');
        end
        else if (pos3<>0) and ((pos1=0) or (pos3<pos1)) and ((pos2=0) or (pos3<pos2)) and ((pos4=0) or (pos3<pos4)) then
        begin
          delete(s2,1,5);
          //writeln('3');
        end
        else if (pos4<>0) and ((pos1=0) or (pos4<pos1)) and ((pos2=0) or (pos4<pos2)) and ((pos3=0) or (pos4<pos3)) then
        begin
          delete(s2,1,6);
          //writeln('4');
        end
        else begin
        if length(s2)=0 then break;
          writeln('NO');
          halt;
        end;
    end;
    writeln('YES');
end.


var s,s2:ansistring;
pos1,pos2,pos3,pos4,cnt,i:longint;
begin
  readln(s);
  for i:=length(s) downto 1 do
    s2:=s2+s[i];
  cnt:=1;
  pos1:=0;
  pos2:=0;
  pos3:=0;
  pos4:=0;
  while (true) do
    begin
      pos1:=pos('maerd',s2);
      pos2:=pos('remaerd',s2);
      pos3:=pos('esare',s2);
      pos4:=pos('resare',s2);
      //writeln(s2);
      if (length(s2)=0) then break
      else if (pos1=0) and (pos2=0) and (pos3=0) and (pos4=0) then
        begin
          writeln('NO');
          halt;
        end
      else if ((pos2=0) or (pos1<pos2)) and ((pos3=0) or (pos1<pos3)) and ((pos4=0) or (pos1<pos4)) then
        begin
          delete(s2,1,5);
        end
        else if ((pos1=0) or (pos2<pos1)) and ((pos3=0) or (pos2<pos3)) and ((pos4=0) or (pos2<pos4)) then
        begin
          delete(s2,1,7);
        end
        else if ((pos1=0) or (pos3<pos1)) and ((pos2=0) or (pos3<pos2)) and ((pos4=0) or (pos3<pos4)) then
        begin
          delete(s2,1,5);
        end
        else if ((pos1=0) or (pos4<pos1)) and ((pos2=0) or (pos4<pos2)) and ((pos3=0) or (pos4<pos3)) then
        begin
          delete(s2,1,6);
        end
        else begin
        if length(s2)=0 then break;
          writeln('NO');
          halt;
        end;
    end;
    writeln('YES');
end.


var n,i,j,k:longint;
s,c:ansistring;
begin
  readln(s);
  j:=length(s);
  i:=j;
  while ((i>=1) and (j-i<7)) do
    begin
      c:='';
      for k:=i to j do c:=c+s[k];
      if c='dream' then
        begin
          j:=i-1;
          i:=j;
        end
      else if c='erase' then
        begin
          j:=i-1;
          i:=j;
        end
      else if c='dreamer' then
        begin
          j:=i-1;
          i:=j;
        end
      else if c='eraser' then
        begin
          j:=i-1;
          i:=j;
        end
      else dec(i);
    end;
  if j=0 then writeln('YES') else writeln('NO');
end.


var n,i,j,k:longint;
s,c:ansistring;
begin
  readln(s);
  j:=length(s);
  i:=j;
  while (i>=1) do
    begin
      c:='';
      for k:=i to j do c:=c+s[k];
      if c='dream' then
        begin
          j:=i-1;
          i:=j;
        end
      else if c='erase' then
        begin
          j:=i-1;
          i:=j;
        end
      else if c='dreamer' then
        begin
          j:=i-1;
          i:=j;
        end
      else if c='eraser' then
        begin
          j:=i-1;
          i:=j;
        end
      else dec(i);
    end;
  if j=0 then writeln('YES') else writeln('NO');
end.


program taskd;
var s,s5,s6,s7,s10:string;
    process,i,j,len:longint;
begin
readln(s);
process:=1;
len:=Length(s);
while process<len do
begin
  s5:=Copy(s,process,5);
  s6:=Copy(s,process,6);
  s7:=Copy(s,process,7);
  s10:=Copy(s,process,10);
  if (s7='dreamer') and (s10<>'dreamerase') then
  process:=process+7
  else if s6='eraser' then
  process:=process+6
  else if (s5='dream') or (s5='erase') then
  process:=process+5
  else
  break;
end;
if process<=len then
writeln('No')
else
writeln('Yes');
end.


program taskd;
var s,s5,s6,s7,s10:string;
    process,i,j,len:longint;
begin
readln(s);
process:=1;
len:=Length(s);
while process<len do
begin
  s5:=Copy(s,process,5);
  s6:=Copy(s,process,6);
  s7:=Copy(s,process,7);
  s10:=Copy(s,process,10);
  if (s7='dreamer') and (s10<>'dreamerase') then
  process:=process+7
  else if s6='eraser' then
  process:=process+6
  else if (s5='dream') or (s5='erase') then
  process:=process+5
  else
  break;
end;
if process<len then
writeln('No')
else
writeln('Yes');
end.


var
s:string;
i:longint;
begin
readln(s);
while i<length(s) do
begin
if copy(s,i+1,11)='dreameraser' then i:=i+11
else if copy(s,i+1,10)='dreamerase' then i:=i+10
else if copy(s,i+1,6)='eraser' then i:=i+6
else if copy(s,i+1,5)='erase' then i:=i+5
else if copy(s,i+1,7)='dreamer' then i:=i+7
else if copy(s,i+1,5)='dream' then i:=i+5
else begin writeln('NO'); halt; end;
end;
writeln('YES');
end.


var s:string;
begin
readln(s);
while (length(s)<>0) and (pos('eraser',s)<>0) do delete(s,pos('eraser',s),6);
while (length(s)<>0) and (pos('dreamer',s)<>0) do delete(s,pos('dreamer',s),7);
while (length(s)<>0) and (pos('erase',s)<>0) do delete(s,pos('erase',s),5);
while (length(s)<>0) and (pos('dream',s)<>0) do delete(s,pos('dream',s),5);
if length(s)>0 then writeln('NO')
else writeln('YES'); end.


var s:ansistring;
begin
readln(s);
while (length(s)<>0) and (pos('eraser',s)<>0) do delete(s,pos('eraser',s),6);
while (length(s)<>0) and (pos('dreamer',s)<>0) do delete(s,pos('dreamer',s),7);
while (length(s)<>0) and (pos('erase',s)<>0) do delete(s,pos('erase',s),5);
while (length(s)<>0) and (pos('dream',s)<>0) do delete(s,pos('dream',s),5);
if length(s)>0 then writeln('NO')
else writeln('YES'); end.


var s:ansistring;
begin
readln(s);
while (pos('eraser',s)<>0) do delete(s,pos('eraser',s),6);
while pos('dreamer',s)<>0 do delete(s,pos('dreamer',s),7);
while pos('erase',s)<>0 do delete(s,pos('erase',s),5);
while pos('dream',s)<>0 do delete(s,pos('dream',s),5);
if length(s)>0 then writeln('NO')
else writeln('YES'); end.


uses sysutils;
var s, tmp:ansistring;
    p:longint;
begin
    readln(s);
    p:=pos('dreameraser',s);
    writeln(p);
    while p<>0 do
    begin
        delete(s,p,11);
        p:=pos('dreameraser',s);
    end;
    p:=pos('dreamerase',s);
    writeln(p);
    while p<>0 do
    begin
        delete(s,p,10);
        p:=pos('dreamerase',s);
    end;
    p:=pos('dreamer',s);
    writeln(p);
    while p<>0 do
    begin
        delete(s,p,7);
        p:=pos('dreamer',s);
    end;
    p:=pos('eraser',s);
    writeln(p);
    while p<>0 do
    begin
        delete(s,p,6);
        p:=pos('eraser',s);
    end;
    p:=pos('erase',s);
    writeln(p);
    while p<>0 do
    begin
        delete(s,p,5);
        p:=pos('erase',s);
    end;
    p:=pos('dream',s);
    while p<>0 do
    begin
        delete(s,p,5);
        p:=pos('dream',s);
    end;
    if s='' then
        writeln('YES')
    else
        writeln('NO');
end.


program taskC;
var
    s, t, c, a : ansistring;
    i : longint;
    pre : boolean;

begin
    readln(s);
    a := s;
    t := '';
    pre := true;
    while (pre = true) do
    begin
        pre := false;
        c := copy(a,1,5);
        if (c = 'dream') and (pre = false) and ((length(a) = 5) or (((a[6] = 'e') and (a[8] = 'a')) or (a[6] = 'd'))) then
        begin
            pre := true;
            t := t + c;
            delete(a,1,5);
        end;
         c := copy(a,1,5);
        if (c = 'erase') and (pre = false) and ((length(a) = 5) or (((a[6] = 'e') and (a[8] = 'a')) or (a[6] = 'd'))) then
        begin
            pre := true;
            t := t + c;
            delete(a,1,5);
        end;
        c := copy(a,1,6);
        if (c = 'eraser') and (pre = false) and ((length(a) = 6) or (((a[7] = 'e') and (a[9] = 'a')) or (a[7] = 'd')))then
        begin
            pre := true;
            t := t + c;
            delete(a,1,6);
        end;
        c := copy(a,1,7);
        if (c = 'dreamer') and (pre = false) and ((length(a) = 7) or (((a[8] = 'e') and (a[10] = 'a')) or (a[8] = 'd'))) then
        begin
            pre := true;
            t := t + c;
            delete(a,1,7);
        end;
    end;
    if s = t then
    begin
        writeln('YES')
    end
    else
    begin
        writeln('NO');
    end;
end.


program taskC;
var
    s, t, c, a : ansistring;
    i : longint;
    pre : boolean;

begin
    readln(s);
    a := s;
    t := '';
    pre := true;
    while (pre = true) do
    begin
        writeln(a);
        pre := false;
        c := copy(a,1,5);
        if (c = 'dream') and (pre = false) and ((length(a) = 5) or (((a[6] = 'e') and (a[8] = 'a')) or (a[6] = 'd'))) then
        begin
            pre := true;
            t := t + c;
            delete(a,1,5);
        end;
         c := copy(a,1,5);
        if (c = 'erase') and (pre = false) and ((length(a) = 5) or (((a[6] = 'e') and (a[8] = 'a')) or (a[6] = 'd'))) then
        begin
            pre := true;
            t := t + c;
            delete(a,1,5);
        end;
        c := copy(a,1,6);
        if (c = 'eraser') and (pre = false) and ((length(a) = 6) or (((a[7] = 'e') and (a[9] = 'a')) or (a[7] = 'd')))then
        begin
            pre := true;
            t := t + c;
            delete(a,1,6);
        end;
        c := copy(a,1,7);
        if (c = 'dreamer') and (pre = false) and ((length(a) = 7) or (((a[8] = 'e') and (a[10] = 'a')) or (a[8] = 'd'))) then
        begin
            pre := true;
            t := t + c;
            delete(a,1,7);
        end;
    end;
    //writeln(t);
    if s = t then
    begin
        writeln('YES')
    end
    else
    begin
        writeln('NO');
    end;
end.


var s,t,v,w1,w2:ansistring;
    a:array[1..4] of ansistring=('dreamer','eraser','dream','erase');
    i,j,k:longint;
begin
  readln(s);
  t:='';
  v:=s;

  while (length(s)<>0) do begin
  w1:=s;
  w2:=s;
  //writeln(s);

      if (pos('dreamer',s)=1) then begin
        delete(w1,pos(a[1],w1),length(a[1]));
        delete(w2,pos(a[3],w2),length(a[3]));
        if (pos(a[2],w2)=1) or (pos(a[4],w2)=1) then begin
          t:=t+a[3];
          delete(s,1,length(a[3]));
        end
        else begin
          t:=t+a[1];
          delete(s,1,length(a[1]));
        end;
      end
      else if (pos('eraser',s)=1) then begin
        t:=t+a[2];
        delete(s,1,length(a[2]));
      end
      else if (pos('dream',s)=1) then begin
        t:=t+a[3];
        delete(s,1,length(a[3]));
      end
      else if (pos('erase',s)=1) then begin
        t:=t+a[4];
        delete(s,1,length(a[4]));
      end
      else begin
        writeln('NO');
        exit;
      end;

  end;
  if (v<>t) then writeln('NO')
  else writeln('YES');
end.


var s,t,v,w1,w2:ansistring;
    a:array[1..4] of ansistring=('dreamer','eraser','dream','erase');
    i,j,k:longint;
begin
  readln(s);
  t:='';
  v:=s;
  w1:=s;
  w2:=s;
  while (length(s)<>0) do begin

      if (pos('dreamer',s)=1) then begin
        delete(w1,pos(a[1],w1),length(a[1]));
        delete(w2,pos(a[3],w2),length(a[3]));
        if (pos(a[2],w2)=1) or (pos(a[4],w2)=1) then begin
          t:=t+a[3];
          delete(s,1,length(a[3]));
        end
        else begin
          t:=t+a[1];
          delete(s,1,length(a[1]));
        end;
      end
      else if (pos('eraser',s)=1) then begin
        t:=t+a[2];
        delete(s,1,length(a[2]));
      end
      else if (pos('dream',s)=1) then begin
        t:=t+a[3];
        delete(s,1,length(a[3]));
      end
      else if (pos('erase',s)=1) then begin
        t:=t+a[4];
        delete(s,1,length(a[4]));
      end
      else begin
        writeln('NO');
        exit;
      end;

  end;
  if (v<>t) then writeln('NO')
  else writeln('YES');
end.


program taskC;
var
    s, t, c, a : ansistring;
    i : longint;
    pre : boolean;

begin
    read(s);
    a := s;
    t := '';
    pre := true;
    while (pre) do
    begin
        pre := false;
        c := copy(a,1,5);
        if (a = 'dream') and (pre = false) and ((length(a) = 5) or (((a[6] = 'e') and (a[8] = 'a')) or (a[6] = 'd'))) then
        begin
            pre := true;
            t := t + c;
            delete(a,1,5);
        end;
         c := copy(a,1,5);
        if (a = 'erase') and (pre = false) and ((length(a) = 5) or (((a[6] = 'e') and (a[8] = 'a')) or (a[6] = 'd'))) then
        begin
            pre := true;
            t := t + c;
            delete(a,1,5);
        end;
        c := copy(a,1,6);
        if (c = 'eraser') and (pre = false) and ((length(a) = 6) or (((a[7] = 'e') and (a[9] = 'a')) or (a[7] = 'd')))then
        begin
            pre := true;
            t := t + c;
            delete(a,1,6);
        end;
        c := copy(a,1,7);
        if (c = 'dreamer') and (pre = false) and ((length(a) = 7) or (((a[8] = 'e') and (a[10] = 'a')) or (a[8] = 'd'))) then
        begin
            pre := true;
            t := t + c;
            delete(a,1,7);
        end;
    end;
    if s = t then
    begin
        writeln('YES')
    end
    else
    begin
        writeln('NO');
    end;
end.


var s,t,v,w1,w2:ansistring;
    a:array[1..4] of ansistring=('dreamer','eraser','dream','erase');
    i,j,k:longint;
begin
  readln(s);
  t:='';
  v:='';
  w1:=s;
  w2:=s;
  while (length(s)<>0) do begin

      if (pos('dreamer',s)=1) then begin
        delete(w1,pos(a[1],w1),length(a[1]));
        delete(w2,pos(a[3],w2),length(a[3]));
        if (pos(a[2],w2)=1) or (pos(a[4],w2)=1) then begin
          t:=t+a[3];
          delete(s,1,length(a[3]));
        end
        else begin
          t:=t+a[1];
          delete(s,1,length(a[1]));
        end;
      end
      else if (pos('eraser',s)=1) then begin
        t:=t+a[2];
        delete(s,1,length(a[2]));
      end
      else if (pos('dream',s)=1) then begin
        t:=t+a[3];
        delete(s,1,length(a[3]));
      end
      else if (pos('erase',s)=1) then begin
        t:=t+a[4];
        delete(s,1,length(a[4]));
      end
      else begin
        writeln('NO');
        exit;
      end;

  end;
  if (s<>t) and (v<>s) then writeln('NO')
  else writeln('YES');
end.


var s,t:ansistring;
begin
    read(s);
    if (s='dreamerase') or (s='dreameraser') or (s='dreamdreamer') or (s='dreamerdream') or (s='dreamererase') or (s='dreamereraser') or (s='erasedream') or (s='erasedreamer') or (s='eraseeraser') or (s='eraserdream') or (s='eraserdreamer') or (s='erasererase') then
        writeln('YES')
    else
        writeln('NO');
end.


var s,t,v,w1,w2:ansistring;
    a:array[1..4] of ansistring=('dreamer','eraser','dream','erase');
    i,j,k:longint;
begin
  readln(s);
  t:='';
  v:='';
  w1:=s;
  w2:=s;
  while (length(s)<>0) do begin

      if (pos('dreamer',s)=1) then begin
        delete(w1,pos(a[1],w1),length(a[1]));
        delete(w2,pos(a[3],w2),length(a[3]));
        if (pos(a[2],w2)=1) or (pos(a[4],w2)=1) then begin
          t:=t+a[3];
          delete(s,1,length(a[3]));
        end
        else begin
          t:=t+a[1];
          delete(s,1,length(a[1]));
        end;
      end
      else if (pos('eraser',s)=1) then begin
        delete(w1,pos(a[2],w1),length(a[2]));
        delete(w2,pos(a[4],w2),length(a[4]));
        if (pos(a[2],w2)=1) or (pos(a[4],w2)=1) then begin
          t:=t+a[4];
          delete(s,1,length(a[4]));
        end
        else begin
          t:=t+a[2];
          delete(s,1,length(a[2]));
        end;
      end
      else if (pos('dream',s)=1) then begin
        t:=t+a[3];
        delete(s,1,length(a[3]));
      end
      else if (pos('erase',s)=1) then begin
        t:=t+a[4];
        delete(s,1,length(a[4]));
      end
      else begin
        writeln('NO');
        exit;
      end;

  end;
  if (s<>t) and (v<>s) then writeln('NO')
  else writeln('YES');
end.


var

  S : ansistring;

begin

  readln(S);

  while s <> '' do

    if (pos('dreamereraser',s)=1) then
      delete(s,1,13)
    else if (pos('dreamererase',s)=1) then
      delete(s,1,12)
    else if (pos('dreameraser',s)=1) then
      delete(s,1,11)
    else if (pos('dreamerase',s)=1) then
      delete(s,1,10)
    else if (pos('dreamer',s)=1) then
      delete(s,1,7)
    else if (pos('eraser',s)=1) then
      delete(s,1,6)
    else if (pos('dream',s)=1) then
      delete(s,1,5)
    else if (pos('erase',s)=1) then
      delete(s,1,5)
    else
    begin
      writeln('NO');
      halt;
    end;

    writeln('YES');

end.


var

  S : ansistring;

begin

  readln(S);

    while pos('dreamererase', S) <> 0 do
      delete(S, pos('dreamererase', S), 12);

    while pos('dreamereraser', S) <> 0 do
      delete(S, pos('dreamereraser', S), 13);

    while pos('dreameraser', S) <> 0 do
      delete(S, pos('dreameraser', S), 11);

    while pos('dreamerase', S) <> 0 do
      delete(S, pos('dreamerase', S), 10);

    while pos('dreamer', S) <> 0 do
      delete(S, pos('dreamer', S), 7);

    while pos('dream', S) <> 0 do
      delete(S, pos('dream', S), 5);

    while pos('eraser', S) <> 0 do
      delete(S, pos('eraser', S), 6);

    while pos('erase', S) <> 0 do
      delete(S, pos('erase', S), 5);

    if length(S) = 0 then
      writeln('YES')
    else
      writeln('NO');

end.


var

  S : ansistring;

begin

  readln(S);

    while pos('dreameraser', S) <> 0 do
      delete(S, pos('dreameraser', S), 11);

    while pos('dreamerase', S) <> 0 do
      delete(S, pos('dreamerase', S), 10);

    while pos('dreamererase', S) <> 0 do
      delete(S, pos('dreamererase', S), 12);

    while pos('dreamereraser', S) <> 0 do
      delete(S, pos('dreamereraser', S), 13);

    while pos('dreamer', S) <> 0 do
      delete(S, pos('dreamer', S), 7);

    while pos('dream', S) <> 0 do
      delete(S, pos('dream', S), 5);

    while pos('eraser', S) <> 0 do
      delete(S, pos('eraser', S), 6);

    while pos('erase', S) <> 0 do
      delete(S, pos('erase', S), 5);

    if length(S) = 0 then
      writeln('YES')
    else
      writeln('NO');

end.


var

  S : ansistring;

begin

  readln(S);

    while pos('dreameraser', S) <> 0 do
      delete(S, pos('dreameraser', S), 11);

    while pos('dreamerase', S) <> 0 do
      delete(S, pos('dreamerase', S), 10);

    while pos('eraseeraser', S) <> 0 do
      delete(S, pos('eraseeraser', S), 11);

    while pos('erasererase', S) <> 0 do
      delete(S, pos('erasererase', S), 10);

    while pos('erasedreamer', S) <> 0 do
      delete(S, pos('erasedreamer', S), 12);

    while pos('dreamererase', S) <> 0 do
      delete(S, pos('dreamererase', S), 12);

    while pos('dreamereraser', S) <> 0 do
      delete(S, pos('dreamereraser', S), 13);

    while pos('eraserdreamer', S) <> 0 do
      delete(S, pos('eraserdreamer', S), 13);

    while pos('dreamer', S) <> 0 do
      delete(S, pos('dreamer', S), 7);

    while pos('dream', S) <> 0 do
      delete(S, pos('dream', S), 5);

    while pos('eraser', S) <> 0 do
      delete(S, pos('eraser', S), 6);

    while pos('erase', S) <> 0 do
      delete(S, pos('erase', S), 5);

    if length(S) = 0 then
      writeln('YES')
    else
      writeln('NO');

end.


var

  S : ansistring;

begin

  readln(S);

    while pos('dreameraser', S) <> 0 do
      delete(S, pos('dreameraser', S), 11);

    while pos('dreamerase', S) <> 0 do
      delete(S, pos('dreamerase', S), 10);

    while pos('eraseeraser', S) <> 0 do
      delete(S, pos('eraseeraser', S), 11);

    while pos('erasererase', S) <> 0 do
      delete(S, pos('erasererase', S), 10);

    while pos('erasedreamer', S) <> 0 do
      delete(S, pos('erasedreamer', S), 12);

    while pos('dreamererase', S) <> 0 do
      delete(S, pos('dreamererase', S), 12);

    while pos('dreamereraser', S) <> 0 do
      delete(S, pos('dreamereraser', S), 13);

    while pos('eraserdreamer', S) <> 0 do
      delete(S, pos('eraserdreamer', S), 13);

    while pos('dreamer', S) <> 0 do
      delete(S, pos('dreamer', S), 7);

    while pos('dream', S) <> 0 do
      delete(S, pos('dream', S), 5);

    while pos('eraser', S) <> 0 do
      delete(S, pos('eraser', S), 6);

    while pos('erase', S) <> 0 do
      delete(S, pos('erase', S), 5);

    writeln(S);

    if length(S) = 0 then
      writeln('YES')
    else
      writeln('NO');

end.


var
  s:ansistring;
begin
  readln(s);
  while (s<>'') do begin
    if (pos('dreamereraser',s)=1) then
      delete(s,1,13)
    else if (pos('dreamererase',s)=1) then
      delete(s,1,12)
    else if (pos('dreameraser',s)=1) then
      delete(s,1,11)
    else if (pos('dreamerase',s)=1) then
      delete(s,1,10)
    else if (pos('dreamer',s)=1) then
      delete(s,1,7)
    else if (pos('eraser',s)=1) then
      delete(s,1,6)
    else if (pos('dream',s)=1) then
      delete(s,1,5)
    else if (pos('erase',s)=1) then
      delete(s,1,5)
    else begin
      writeln('NO');
      exit;
    end;
  end;
  writeln('YES');
end.


var
  s,t:ansistring;
begin
  readln(s);
  t:='';
  while (s<>'') do begin
    if (pos('dreameraser',s)=1) then
      delete(s,1,11)
     else if (pos('dreamer',s)=1) then
      delete(s,1,7)
    else if (pos('eraser',s)=1) then
      delete(s,1,6)
    else if (pos('dream',s)=1) then
      delete(s,1,5)
      else if (pos('erase',s)=1) then
      delete(s,1,5)
    else begin
      writeln('NO');
      exit;
    end;
  end;
  writeln('YES');
end.


var

  S : ansistring;

begin

  readln(S);

    while pos('dreameraser', S) <> 0 do
      delete(S, pos('dreameraser', S), 11);

    while pos('dreamerase', S) <> 0 do
      delete(S, pos('dreamerase', S), 10);

    while pos('dreamer', S) <> 0 do
      delete(S, pos('dreamer', S), 7);

    while pos('dream', S) <> 0 do
      delete(S, pos('dream', S), 5);

    while pos('eraser', S) <> 0 do
      delete(S, pos('eraser', S), 6);

    while pos('erase', S) <> 0 do
      delete(S, pos('erase', S), 5);

    if length(S) = 0 then
      writeln('YES')
    else
      writeln('NO');

end.


program taskC;
var
    s, t, c, a : ansistring;
    i : longint;
    pre : boolean;

begin
    readln(s);
    a := s;
    t := '';
    pre := true;
    while (pre) do
    begin
        pre := false;
        c := copy(a,1,5);
        if (a = 'dream') and (pre = false) and ((length(a) = 5) or (((a[6] = 'e') and (a[8] = 'a')) or (a[6] = 'd'))) then
        begin
            pre := true;
            t := t + c;
            delete(a,1,5);
        end;
         c := copy(a,1,5);
        if (a = 'erase') and (pre = false) and ((length(a) = 5) or (((a[6] = 'e') and (a[8] = 'a')) or (a[6] = 'd'))) then
        begin
            pre := true;
            t := t + c;
            delete(a,1,5);
        end;
        c := copy(a,1,6);
        if (c = 'eraser') and (pre = false) and ((length(a) = 6) or (((a[7] = 'e') and (a[9] = 'a')) or (a[7] = 'd')))then
        begin
            pre := true;
            t := t + c;
            delete(a,1,6);
        end;
        c := copy(a,1,7);
        if (c = 'dreamer') and (pre = false) and ((length(a) = 7) or (((a[8] = 'e') and (a[10] = 'a')) or (a[8] = 'd'))) then
        begin
            pre := true;
            t := t + c;
            delete(a,1,7);
        end;
    end;
    if s = t then
    begin
        writeln('YES')
    end
    else
    begin
        writeln('NO');
    end;
end.


var s,t,v,w:ansistring;
    a:array[1..4] of ansistring=('dreamer','eraser','dream','erase');
    i,j,k:longint;
begin
  readln(s);
  t:='';
  v:=s;
  for i:=1 to 4 do begin

    //writeln(s,' ',v,' ',w,' ',a[i]);
    if (pos(a[i],s)<>0) then begin
      for j:=1 to length(s) do
        delete(s,pos(a[i],s),length(a[i]));
        if (i=1) or (i=2) then delete(v,pos(a[i+2],v),length(a[i+2]));
        w:=v;
        for k:=1 to 4 do begin
          if (pos(a[k],w)<>0) then delete(w,pos(a[k],w),length(a[k]));
        end;
        if (w=t) then begin
          writeln('YES');
          exit;
        end;
    end;
  end;
  if (s<>t) and (v<>t) then writeln('NO')
  else writeln('YES');
end.


program taskC;
var
    s, t, c, a : ansistring;
    i : longint;
    pre : boolean;

begin
    readln(s);
    a := s;
    t := '';
    pre := true;
    while (pre) do
    begin
        pre := false;
        c := copy(a,1,5);
        if (c = 'dream') and (pre = false) then
        begin
            pre := true;
            t := t + c;
            delete(a,1,5);
        end;
         c := copy(a,1,5);
        if (a = 'erase') and (pre = false) then
        begin
            pre := true;
            t := t + c;
            delete(a,1,5);
        end;
        c := copy(a,1,6);
        if (c = 'eraser') and (pre = false) then
        begin
            pre := true;
            t := t + c;
            delete(a,1,6);
        end;
        c := copy(a,1,7);
        if (c = 'dreamer') and (pre = false) then
        begin
            pre := true;
            t := t + c;
            delete(a,1,7);
        end;
    end;
    if s = t then
    begin
        writeln('YES')
    end
    else
    begin
        writeln('NO');
    end;
end.


uses sysutils;
var s:ansistring;
begin
    readln(s);
    s:= StringReplace(s, 'dreameraser', '',
                          [rfReplaceAll, rfIgnoreCase]);
    s:= StringReplace(s, 'dreamerase', '',
                          [rfReplaceAll, rfIgnoreCase]);
    s:= StringReplace(s, 'dreamer', '',
                          [rfReplaceAll, rfIgnoreCase]);
    s:= StringReplace(s, 'eraser', '',
                          [rfReplaceAll, rfIgnoreCase]);
    s:= StringReplace(s, 'dream', '',
                          [rfReplaceAll, rfIgnoreCase]);
    s:= StringReplace(s, 'erase', '',
                          [rfReplaceAll, rfIgnoreCase]);
    if s= '' then
        writeln('YES')
    else
        writeln('NO');
end.


var

  S : ansistring;
  i : longint;
  b : boolean;

begin

  readln(S);
  b := true;

    while pos('dreamer', S) <> 0 do
      delete(S, pos('dreamer', S), 7);

    while pos('dream', S) <> 0 do
      delete(S, pos('dream', S), 5);

    while pos('eraser', S) <> 0 do
      delete(S, pos('eraser', S), 6);

    while pos('erase', S) <> 0 do
      delete(S, pos('erase', S), 5);

    if length(S) = 0 then
      writeln('YES')
    else
      writeln('NO');

end.


var s,t,v:ansistring;
    a:array[1..4] of ansistring=('dreamer','eraser','dream','erase');
    i,j:longint;
begin
  readln(s);
  t:='';
  for i:=1 to 4 do begin
    //writeln(s);
    if (pos(a[i],s)<>0) then begin
      for j:=1 to length(s) do
        delete(s,pos(a[i],s),length(a[i]));
    end;

  end;
  if (s<>t) then writeln('NO')
  else writeln('YES');
end.


var

  S : ansistring;
  i : longint;
  b : boolean;

begin

  readln(S);
  b := true;

    while pos('dream', S) <> 0 do
      delete(S, pos('dream', S), 5);

    while pos('dreamer', S) <> 0 do
      delete(S, pos('dreamer', S), 7);

    while pos('erase', S) <> 0 do
      delete(S, pos('erase', S), 5);

    while pos('eraser', S) <> 0 do
      delete(S, pos('eraser', S), 6);

    if length(S) = 0 then
      writeln('YES')
    else
      writeln('NO');

end.


var s,t,v:ansistring;
    a:array[1..4] of ansistring=('dream','dreamer','erase','eraser');
    i,j:longint;
begin
  readln(s);
  t:='';
  for i:=1 to 4 do begin
    if (pos(a[i],s)<>0) then begin
      for j:=1 to length(s) do
        delete(s,pos(a[i],s),length(a[i]));
    end;

  end;
  if (s<>t) then writeln('NO')
  else writeln('YES');
end.


var

  S : ansistring;

begin

  readln(S);
  delete(S, 1, length(S)-7);
  if (pos('dream', S) = length(S)-5+1) or (pos('dreamer', S) = length(S)-7+1) or (pos('erase', S) = length(S)-5+1) or (pos('eraser', S) = length(S)-6+1) then
    writeln('YES')
  else
    writeln('NO');

end.


var

  S : ansistring;

begin

  readln(S);
  if (pos('dream', S) = length(S)-5+1) or (pos('dreamer', S) = length(S)-7+1) or (pos('erase', S) = length(S)-5+1) or (pos('eraser', S) = length(S)-6+1) then
    writeln('YES')
    else
      writeln('NO');

end.


var s,t,v:ansistring;
    a:array[1..4] of ansistring=('dream','dreamer','erase','eraser');
    i,j:longint;
begin
  readln(s);
  t:='';
  for i:=1 to 4 do begin
    for j:=1 to 4 do begin
      t:=a[i]+a[j];
      if (t=s) then begin
        writeln('YES');
        exit;
      end;
    end;
  end;
  writeln('NO');
end.


var
	S:String;
	id:Longint;
begin
	readln(S);
	id:=length(S);
	while id>0 do begin
		if(id>=5)and(copy(S,id-4,5)='dream')then dec(id,5)else if(id>=7)and(copy(S,id-6,7)='dreamer')then dec(id,7)else if(id>=5)and(copy(S,id-4,5)='erase')then dec(id,5)else if(id>=6)and(copy(S,id-5,6)='eraser')then dec(id,6)else begin writeln('NO');exit;end;
	end;
	writeln('YES');
end.


program task_C;
    const A='dream';
    const B='dreamer';
    const C='erase';
    const D='eraser';
    var S:Ansistring;
    function delete(_:Ansistring;_l:longint):boolean;
    begin
        if _l=0 then exit(true);
        if Copy(_,_l-4,5)=A then exit(delete(_,_l-5));
        if Copy(_,_l-4,5)=C then exit(delete(_,_l-5));
        if Copy(_,_l-5,6)=D then exit(delete(_,_l-6));
        if Copy(_,_l-6,7)=B then exit(delete(_,_l-7));
        exit(false);
    end;
begin
    readln(S);
    if delete(S,length(S))=true then writeln('YES') else writeln('NO');
end.


program task_C;
    const A='dream';
    const B='dreamer';
    const C='erase';
    const D='eraser';
    var S:Ansistring;
    function delete(_:Ansistring;_l:longint):boolean;
    begin
        if _l=0 then exit(true);
        if (_l>=5) then if Copy(_,_l-4,5)=A then exit(delete(Copy(_,1,_l-5),_l-5));
        if (_l>=5) then if Copy(_,_l-4,5)=C then exit(delete(Copy(_,1,_l-5),_l-5));
        if (_l>=6) then if Copy(_,_l-5,6)=D then exit(delete(Copy(_,1,_l-6),_l-6));
        if (_l>=7) then if Copy(_,_l-6,7)=B then exit(delete(Copy(_,1,_l-7),_l-7));
        exit(false);
    end;
begin
    readln(S);
    if delete(S,length(S))=true then writeln('YES') else writeln('NO');
end.


program task_C;
    const A='dream';
    const B='dreamer';
    const C='erase';
    const D='eraser';
    var S:Ansistring;
    function delete(_:Ansistring;_l:longint):boolean;
    begin
        if _l=0 then exit(true);
        if Copy(_,_l-4,5)=A then delete:=delete(Copy(_,1,_l-5),_l-5)
        else if Copy(_,_l-6,7)=B then delete:=delete(Copy(_,1,_l-7),_l-7)
        else if Copy(_,_l-4,5)=C then delete:=delete(Copy(_,1,_l-5),_l-5)
        else if Copy(_,_l-5,6)=D then delete:=delete(Copy(_,1,_l-6),_l-6)
        else exit(false);
    end;
begin
    readln(S);
    if delete(S,length(S))=true then writeln('YES') else writeln('NO');
end.


program task_C;
    const A='dream';
    const B='dreamer';
    const C='erase';
    const D='eraser';
    var S:string;
    function delete(_:string;_l:integer):boolean;
    begin
        if _l=0 then exit(true);
        if Copy(_,_l-4,5)=A then delete:=delete(Copy(_,1,_l-5),_l-5)
        else if Copy(_,_l-6,7)=B then delete:=delete(Copy(_,1,_l-7),_l-7)
        else if Copy(_,_l-4,5)=C then delete:=delete(Copy(_,1,_l-5),_l-5)
        else if Copy(_,_l-5,6)=D then delete:=delete(Copy(_,1,_l-6),_l-6)
        else exit(false);
    end;
begin
    readln(S);
    if delete(S,length(S))=true then writeln('YES') else writeln('NO');
end.


program task_C;
    const A='dream';
    const B='dreamer';
    const C='erase';
    const D='eraser';
    var S:Ansistring;
    function delete(_:Ansistring;_l:longint):boolean;
    begin
        if _l=0 then exit(true);
        if Copy(_,_l-4,5)=A then delete:=delete(Copy(_,1,_l-5),_l-5)
        else if Copy(_,_l-5,6)=B then delete:=delete(Copy(_,1,_l-6),_l-6)
        else if Copy(_,_l-4,5)=C then delete:=delete(Copy(_,1,_l-5),_l-5)
        else if Copy(_,_l-5,6)=D then delete:=delete(Copy(_,1,_l-6),_l-6)
        else exit(false);
    end;
begin
    readln(S);
    if delete(S,length(S))=true then writeln('YES') else writeln('NO');
end.


program task_C;
    const A='dream';
    const B='dreamer';
    const C='erase';
    const D='eraser';
    var S:string;
    function delete(_:string;_l:longint):boolean;
    begin
        if _l=0 then exit(true);
        if Copy(_,_l-4,5)=A then delete:=delete(Copy(_,1,_l-5),_l-5)
        else if Copy(_,_l-5,6)=B then delete:=delete(Copy(_,1,_l-6),_l-6)
        else if Copy(_,_l-4,5)=C then delete:=delete(Copy(_,1,_l-5),_l-5)
        else if Copy(_,_l-5,6)=D then delete:=delete(Copy(_,1,_l-6),_l-6)
        else exit(false);
    end;
begin
    readln(S);
    if delete(S,length(S))=true then writeln('YES') else writeln('NO');
end.


program task_C;
    const A='dream';
    const B='dreamer';
    const C='erase';
    const D='eraser';
    var S:string;
    function delete(_:string;_l:integer):boolean;
    begin
        if _l=0 then exit(true);
        if Copy(_,_l-4,5)=A then delete:=delete(Copy(_,1,_l-5),_l-5)
        else if Copy(_,_l-5,6)=B then delete:=delete(Copy(_,1,_l-6),_l-6)
        else if Copy(_,_l-4,5)=C then delete:=delete(Copy(_,1,_l-5),_l-5)
        else if Copy(_,_l-5,6)=D then delete:=delete(Copy(_,1,_l-6),_l-6)
        else exit(false);
    end;
begin
    readln(S);
    if delete(S,length(S))=true then writeln('YES') else writeln('NO');
end.


var c1,c2:char;c:longint;
begin
  read(c1);
  while not eoln do
  begin
    read(c2);
    if c1<>c2 then
      inc(c);
    c1:=c2;
  end;
  writeln(c);
end.

Score : 300 points

Problem Statement

Two foxes Jiro and Saburo are playing a game called 1D Reversi. This game is played on a board, using black and white stones. On the board, stones are placed in a row, and each player places a new stone to either end of the row. Similarly to the original game of Reversi, when a white stone is placed, all black stones between the new white stone and another white stone, turn into white stones, and vice versa.

In the middle of a game, something came up and Saburo has to leave the game. The state of the board at this point is described by a string S. There are |S| (the length of S) stones on the board, and each character in S represents the color of the i-th (1 ≦ i ≦ |S|) stone from the left. If the i-th character in S is B, it means that the color of the corresponding stone on the board is black. Similarly, if the i-th character in S is W, it means that the color of the corresponding stone is white.

Jiro wants all stones on the board to be of the same color. For this purpose, he will place new stones on the board according to the rules. Find the minimum number of new stones that he needs to place.

Constraints

1 ≦ |S| ≦ 10^5

Each character in S is B or W.

Input

The input is given from Standard Input in the following format:

S

Output

Print the minimum number of new stones that Jiro needs to place for his purpose.

Sample Input 1

BBBWW

Sample Output 1

1

By placing a new black stone to the right end of the row of stones, all white stones will become black. Also, by placing a new white stone to the left end of the row of stones, all black stones will become white.

In either way, Jiro's purpose can be achieved by placing one stone.

Sample Input 2

WWWWWW

Sample Output 2

0

If all stones are already of the same color, no new stone is necessary.

Sample Input 3

WBWBWBWBWB

Sample Output 3

9


var
 st:ansistring;
 i,s:longint;
begin
 readln(st);
 for i:=1 to length(st)-1 do
  if st[i]<>st[i+1] then inc(s);
 writeln(s);
end.