The bear has a string *s* = *s*<sub class="lower-index">1</sub>*s*<sub class="lower-index">2</sub>... *s*<sub class="lower-index">|*s*|</sub> (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*<sub class="lower-index">*i*</sub>*s*<sub class="lower-index">*i* + 1</sub>... *s*<sub class="lower-index">*j*</sub> 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*<sub class="lower-index">*k*</sub> = *b*, *s*<sub class="lower-index">*k* + 1</sub> = *e*, *s*<sub class="lower-index">*k* + 2</sub> = *a*, *s*<sub class="lower-index">*k* + 3</sub> = *r*.

Help the bear cope with the given problem.
The first line contains a non-empty string *s* (1 ≤ |*s*| ≤ 5000). It is guaranteed that the string only consists of lowercase English letters.
import math

class Bear():
    def __init__(self, s):
        self.s = s
        self.count = 0

    def kmp_algo(self):
        bear = "bear"
        bear = "1" + bear
        table = [0, 0]
        is_started = False
        for i in range(1, len(bear)):
            if not is_started:
                if bear[i] == bear[0]:
                    internal_counter = 1
                    index = 1
                    table.append(internal_counter)
                    is_started = True
                else:
                    table.append(0)
            else:
                if bear[i] == bear[index]:
                    internal_counter += 1
                    index += 1
                    table.append(internal_counter)
                elif bear[i] == bear[0]:
                    internal_counter = 1
                    index = 1
                    table.append(internal_counter)
                    is_started = True
                else:
                    is_started = False
                    table.append(0)
        #print(table)
        current_index = 0
        collector = []
        for i in range(len(self.s)):
            #print(i, current_index)
            if self.s[i] == bear[current_index + 1]:
                current_index += 1
                if current_index == len(bear) - 1:
                    collector.append(i)
                    current_index = 0
            else:
                while current_index != 0 and self.s[i] !=  bear[current_index  + 1]:
                    current_index = table[current_index]
                    if current_index != 0:
                        current_index += 1
        prev_item = 0
        counter = 0
        first_passed = False
        for j in range(len(collector)):
            i = collector[j]
            i += 1
            start = i - 3 - prev_item
            end = len(self.s) - i + 1
            prev_item = collector[j] + 1 - 3
            counter += start * end
            #print(start * end, "s")
            #print(start, end)
        print(counter)
       # print(len(self.s))




















    def calculate_count(self):
        pass





def main():
    s = input()
    new_bear = Bear(s)
    new_bear.kmp_algo()











main()
