The bear has a string s = s_1s_2... s_{|}s| (record |s| is the string's length), consisting of lowercase English letters. The bear wants to count the number of such pairs of indices i, j (1 ≤ i ≤ j ≤ |s|), that string x(i, j) = s_{i}s_{i} + 1... s_{j} contains at least one string "bear" as a substring.

String x(i, j) contains string "bear", if there is such index k (i ≤ k ≤ j - 3), that s_{k} = b, s_{k} + 1 = e, s_{k} + 2 = a, s_{k} + 3 = r.

Help the bear cope with the given problem.


-----Input-----

The first line contains a non-empty string s (1 ≤ |s| ≤ 5000). It is guaranteed that the string only consists of lowercase English letters.


-----Output-----

Print a single number — the answer to the problem.


-----Examples-----
Input
bearbtear

Output
6

Input
bearaabearc

Output
20



-----Note-----

In the first sample, the following pairs (i, j) match: (1, 4), (1, 5), (1, 6), (1, 7), (1, 8), (1, 9).

In the second sample, the following pairs (i, j) match: (1,  4), (1,  5), (1,  6), (1,  7), (1,  8), (1,  9), (1,  10), (1,  11), (2,  10), (2,  11), (3,  10), (3,  11), (4,  10), (4,  11), (5,  10), (5,  11), (6,  10), (6,  11), (7,  10), (7,  11).

Difficulty: interview

Starter code:

Solutions:
s=input()

if(len(s)<=3):
    print(0)

else:
    n=len(s)
    ans=0
    A=0
    for i in range(3,n):
        if(s[i-3]+s[i-2]+s[i-1]+s[i]=='bear'):
            ans+=((i-3)-A+1)*(n-i)
            A=i-2
    print(ans)


s = input()
ans = 0
li = []
for i in range(len(s)):
    if s[i:i+4] == 'bear':
        li.append(i)
if len(li) == 0:
    print(0)
else:
    k = 0
    start = li[k]
    b = 0
    for i in range(len(s)):
        while i > start:
            try:
                k += 1
                start = li[k]
            except:
                b = 1
                break
        if b:
            break
        ans += len(s)-start-3
        
    print(ans)


s = input()
n = len(s)
ans = 0
lb = -1
for i in range(n - 3):
    if s[i:i + 4] == 'bear':
        left = i-lb
        right = n - 3 - i
        ans += left * right
        lb = i
print(ans)


S = input().strip()
Words = S.split('bear')
N = len(S)
Amount = (N * (N + 1)) // 2
if len(Words) > 1:
    K = len(Words[0]) + 3
    Amount -= (K * (K + 1)) // 2
    K = len(Words[-1]) + 3
    Amount -= (K * (K + 1)) // 2
    for i in range(1, len(Words) - 1):
        K = len(Words[i]) + 6
        Amount -= (K * (K + 1)) // 2
    Amount += 3 * (len(Words) - 1)
    print(Amount)
else:
    print(0)


def get_max_s(s):
    n = len(s)
    i = 0
    l = 0
    count = 0

    while i < n:
        if s[i:i+4] == 'bear':
            count += (n - (i + 4) + 1) * (i - l + 1)
            l = i + 1
            i += 4
            continue
        i += 1

    return count


def __starting_point():
    s = input().strip()
    max_s = get_max_s(s)
    print(max_s)

import unittest

class TestFoo(unittest.TestCase):
    def test_world(self):
        got = get_max_s('bearbtear')
        self.assertEqual(got, 6)

        got = get_max_s('bearaabearc')
        self.assertEqual(got, 20)


__starting_point()

s=input().strip()
n=len(s)
x=[]
for i in range(n-3):
    if s[i:i+4]=='bear':
        x.append(i)
i=0
j=0
ans=0
m=len(x)
while i<m:
    ans+=max(0,n-x[i]-3)
    j+=1
    if j>x[i]:
        i+=1
print(ans)

string = input()

i = 0
last = 0
total = 0
while i < len(string)-3:
    if string[i]=='b' and string[i+1]=='e' and string[i+2]=='a' and string[i+3]=='r':
        total += (i+1) * (len(string)-i-3)
        string = string[i+1:]
        i = 0

    i += 1

print(total)


word = input()
points = 0

for i in range(len(word)):
    part = word[i:]
    if "bear" in part :
        points += len(part)-(part.index("bear")+3)

print(points)


s = input()
k = 0
l = 0
sstr = -2
count = 0
while sstr != -1:
    sstr = s.find("bear")
    if sstr == -1 :
        break
    else :
        if sstr == 0 or sstr == len(s) - 1:
            k += (len(s) - 3)   
        else:
            z = ((sstr + 1) * (len(s) - sstr - 3))  
            k += z
    s = s[(sstr + 1):len(s)]
print(k)

import sys, math, heapq, random, collections, bisect

def main():
    # sys.stdin = open('input.txt', 'r')
    # sys.stdout = open('output.txt', 'w')

    st = input()
    count = 0

    while st.find('bear') != -1:
        idx = st.find('bear')
        count = ((idx+1) * (len(st)-(3+idx))) + count
        st = st[idx+1:]

    print(count)
    # sys.stdin.close()
    # sys.stdout.close()

def __starting_point():
    main()

__starting_point()

from sys import stdin
debug = False

try :
  import os
  if os.environ['COMPUTERNAME'] == 'KRUEGER-PC':
    debug = True
except KeyError:
  pass  

def debug_print(*foo):
  if debug:
    print (foo)

debug_print("debug active")    

def print_array(res, size):
  if size:
    print(len(res))
  print(" ".join(map(str, res)))

def input_int_tuple():
  return tuple([ x for x in map(int, stdin.readline().split())])

def input_int_array(size=True):
  if size:
    #read 
    values = stdin.readline().split()
    assert(len(values) == 1)
  return [x for x in map(int, stdin.readline().split())]

def input_string():
  return stdin.readline().strip()



def problem():
  import re
  bear = "bear"
  s  = input_string()

  diffs = []
  prev = 0
  cnt = 0
  for m in re.finditer( bear, s ):
      cnt +=1
      diffs.append(m.start() - prev )
      prev = m.end()

  if cnt >0:
    diffs.append(len(s) - prev)
  else:
    return 0
    


  res = 0
  for i,v in enumerate(diffs):
    if i > 0 :
      v += 3
    if i < len(diffs) -1 :
      v += 3

    res += (v*v -v) // 2 +v
  
  cor = (len(diffs)-1)*3
  res = res - cor
  n = len(s)
  return (n*n-n) // 2 + n -  res 


 


print(problem()) 


#print_array(problem(), False)

#xx = input_string()


s = str(input())
n = len(s)
d = 0
dprec = -1
tot = 0
while d < n-3:
    if s[d:d+4] == 'bear':
        tot += (d-dprec)*(n-3-d)
        dprec = d
        d += 4
    else:
        d+= 1
print(tot)

s = input()
l = len(s)

import re
total = 0
prev=-1
for m in re.finditer('bear',s):
	total += (m.start()-prev)*(l-(m.start()+3))
	prev=m.start()
print(total)


s = input()
n = len(s)

idx = [-1]
curIdx = s.find('bear', 0)
cnt = 1
while curIdx > -1:
    idx.append(curIdx)
    cnt = cnt + 1
    curIdx = s.find('bear', curIdx + 1)
    
ret = 0
for i in range(cnt - 1):
    ret = ret + (idx[i + 1] - idx[i]) * (n - idx[i + 1] - 3)

print(ret)


s = input()

answer = 0
last = s.find("bear") + 1
answer += last * (len(s) - last - 2)
s = s[: last - 1] + "####" + s[last + 3 :]
last += 1
while "bear" in s:
    i = s.find("bear") + 1
    answer += (i - last + 1) * (len(s) - i - 2)
    s = s[: i - 1] + "####" + s[i + 3 :]
    last = i + 1

print(answer)


s = input().strip()
ans = 0
last = 2
for i in range(3, len(s)):
    if s[i - 3: i + 1] == "bear":
        last = i
    ans += last - 2
print(ans)


#!/usr/bin/env python3

def main():
    s = input()
    n = len(s)
    pos = [-1]
    p = 0
    while True:
        p = s.find("bear", p)
        if p == -1:
            break
        pos.append(p)
        p += 4
    ret = 0
    m = len(pos)
    for i in range(1, m):
        ret += (pos[i] - pos[i - 1]) * (n - pos[i] - 3)
    print(ret)


def __starting_point():
    main()

__starting_point()

# input part
string = input()

# solution
result = 0

pos = string.find("bear")
while pos >= 0:
    result += len(string) - (pos + 3)
    string = string[1:]
    pos = string.find("bear")

print(result)

p = input()
n, t = len(p), [len(i) + 6 for i in p.split('bear')]
t[0] -= 3
t[-1] -= 3
print(3 * (len(t) - 1) + (n * (n + 1) - sum(i * (i + 1) for i in t)) // 2)

word = input()
points = 0
x=0
for i in range(len(word)):
    part = word[i:]
    if "bear" in part :
        points += len(part)-(part.index("bear")+3)

print(points)

word = input()
points = 0
y=0
for i in range(len(word)):
    part = word[i:]
    if "bear" in part :
        points += len(part)-(part.index("bear")+3)

print(points)

s = input().strip()
ans = 0
last = 2
for i in range(3, len(s)):
    if s[i-3 : i+1] == "bear":
        last = i
    ans += last - 2
print(ans)


s = input()
a = list(map(len, s.split("bear")))
n = len(a)
for i in range(n):
  if 0 < i < n - 1:
    a[i] += 4
  else:
    a[i] += 1
k = r = 0
for i in range(n - 1):
  k += a[i]
  r += a[i] * (len(s) - k - 2)
print(r)

s=input()
n=len(s)

kol=0
posl_i=0
tek_i=s.find("bear",0,n)
while(tek_i!=-1):
    kol+=(tek_i-posl_i+1)*(n-tek_i-3)
    posl_i=tek_i+1
    tek_i=s.find("bear",tek_i+1,n)

print(kol)

def main():
    s = input()
    l, i = [], s.find('bear')
    while i >= 0:
        l.append(i)
        i = s.find('bear', i + 4)
    res = []
    for shift in range(min(len(l), 2)):
        res.append(sum((i + 1) * (len(s) - j - 3) for i, j in zip(l, l[shift:])))
    res.append(0)
    res.append(0)
    print(res[0] - res[1])


def __starting_point():
    main()
__starting_point()