public static void main ( String [ ] args ) throws IOException {
  BufferedReader reader = new BufferedReader ( new InputStreamReader ( System . in ) ) ;
  String s = reader . readLine ( ) ;
  long count = 0 ;
  int left = 1 , right = 1 ;
  int n = s . length ( ) ;
  boolean flag = true ;
  for ( int i = 0 ;
  i < n - 3 ;
  i ++ ) {
    if ( s . substring ( i , i + 4 ) . compareTo ( "bear" ) == 0 ) {
      if ( flag ) {
        flag = false ;
      }
      else {
        count += left * ( right + 3 ) ;
        left = i + 1 ;
        right = 1 ;
      }
      if ( i > n - 7 ) {
        count += left * ( right + n - i - 4 ) ;
      }
      i += 3 ;
      continue ;
    }
    else if ( i == n - 4 ) {
      count += left * ( right + 4 ) ;
    }
    if ( flag ) left ++ ;
    else right ++ ;
  }
  if ( flag ) count = 0 ;
  System . out . println ( count ) ;
}

public static void main ( String [ ] args ) throws IOException { BufferedReader reader = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String s = reader . readLine ( ) ; long count = 0 ; int left = 1 , right = 1 ; int n = s . length ( ) ; boolean flag = true ; for ( int i = 0 ; i < n - 3 ; i ++ ) { if ( s . substring ( i , i + 4 ) . compareTo ( " bear " ) == 0 ) { if ( flag ) { flag = false ; } else { count += left * ( right + 3 ) ; left = i + 1 ; right = 1 ; } if ( i > n - 7 ) { count += left * ( right + n - i - 4 ) ; } i += 3 ; continue ; } else if ( i == n - 4 ) { count += left * ( right + 4 ) ; } if ( flag ) left ++ ; else right ++ ; } if ( flag ) count = 0 ; System . out . println ( count ) ; }
(method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (array_type element: (type_identifier) dimensions: (dimensions)) name: (identifier))) (throws (type_identifier)) body: (block (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (type_identifier) arguments: (argument_list (object_creation_expression type: (type_identifier) arguments: (argument_list (field_access object: (identifier) field: (identifier)))))))) (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal)) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (local_variable_declaration type: (boolean_type) declarator: (variable_declarator name: (identifier) value: (true))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (binary_expression left: (identifier) right: (decimal_integer_literal))) update: (update_expression (identifier)) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (method_invocation object: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (binary_expression left: (identifier) right: (decimal_integer_literal)))) name: (identifier) arguments: (argument_list (string_literal))) right: (decimal_integer_literal))) consequence: (block (if_statement condition: (parenthesized_expression (identifier)) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (false)))) alternative: (block (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (identifier) right: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal)))))) (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (identifier) right: (decimal_integer_literal)))) (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal))))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (binary_expression left: (identifier) right: (decimal_integer_literal)))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (identifier) right: (parenthesized_expression (binary_expression left: (binary_expression left: (binary_expression left: (identifier) right: (identifier)) right: (identifier)) right: (decimal_integer_literal)))))))) (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal))) (continue_statement)) alternative: (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (binary_expression left: (identifier) right: (decimal_integer_literal)))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (identifier) right: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))))))))) (if_statement condition: (parenthesized_expression (identifier)) consequence: (expression_statement (update_expression (identifier))) alternative: (expression_statement (update_expression (identifier)))))) (if_statement condition: (parenthesized_expression (identifier)) consequence: (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal)))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (identifier))))))