program main
   implicit none
   integer(8) ::i,j,k,le
   character*200000 s
   integer(8) ::counter=0,acount=0,dummy
!   integer,allocatable,dimension(:)::
   read(*,*)s
   le=len_trim(s)
   do i=1,le
      if(s(i:i)=="B")then
         acount=acount+i
      else
         counter=counter+1
      endif
   enddo
   write(*,*)(le-counter)*(le+counter+1)/2-acount
end program main

; ModuleID = 'FIRModule'
source_filename = "FIRModule"
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-linux-gnu"

@_QFEacount = internal unnamed_addr global i64 0
@_QFEcounter = internal unnamed_addr global i64 0
@_QFEs = internal global [200000 x i8] undef
@_QQcl.9a4e8d8650d50388b050909e9958ffd3 = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_5263/source.f\00"
@_QQcl.42 = linkonce constant [1 x i8] c"B"
@_QQEnvironmentDefaults = local_unnamed_addr constant ptr null

define void @_QQmain() local_unnamed_addr {
  %1 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.9a4e8d8650d50388b050909e9958ffd3, i32 7)
  %2 = tail call i1 @_FortranAioInputAscii(ptr %1, ptr nonnull @_QFEs, i64 200000)
  %3 = tail call i32 @_FortranAioEndIoStatement(ptr %1)
  br label %4

4:                                                ; preds = %0, %4
  %5 = phi i64 [ 199999, %0 ], [ %9, %4 ]
  %6 = getelementptr [200000 x [1 x i8]], ptr @_QFEs, i64 0, i64 %5
  %7 = load i8, ptr %6, align 1, !tbaa !3
  %8 = icmp eq i8 %7, 32
  %9 = add nsw i64 %5, -1
  %10 = icmp ne i64 %5, 0
  %11 = and i1 %8, %10
  br i1 %11, label %4, label %12

12:                                               ; preds = %4
  %13 = shl i64 %5, 32
  %sext = add i64 %13, 4294967296
  %14 = ashr exact i64 %sext, 32
  %15 = select i1 %8, i64 0, i64 %14
  %16 = icmp sgt i64 %15, 0
  br i1 %16, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %12, %.lr.ph
  %17 = phi i64 [ %24, %.lr.ph ], [ 1, %12 ]
  %18 = add nsw i64 %17, -1
  %19 = getelementptr [200000 x [1 x i8]], ptr @_QFEs, i64 0, i64 %18
  %20 = tail call i32 @_FortranACharacterCompareScalar1(ptr %19, ptr nonnull @_QQcl.42, i64 1, i64 1)
  %21 = icmp eq i32 %20, 0
  %_QFEacount._QFEcounter = select i1 %21, ptr @_QFEacount, ptr @_QFEcounter
  %. = select i1 %21, i64 %17, i64 1
  %22 = load i64, ptr %_QFEacount._QFEcounter, align 8, !tbaa !3
  %23 = add i64 %22, %.
  store i64 %23, ptr %_QFEacount._QFEcounter, align 8, !tbaa !3
  %24 = add nuw nsw i64 %17, 1
  %exitcond.not = icmp eq i64 %17, %15
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %12
  %.pre-phi = add nsw i64 %15, 1
  %25 = tail call ptr @_FortranAioBeginExternalListOutput(i32 -1, ptr nonnull @_QQcl.9a4e8d8650d50388b050909e9958ffd3, i32 16)
  %26 = load i64, ptr @_QFEcounter, align 8, !tbaa !3
  %27 = sub i64 %15, %26
  %28 = add i64 %.pre-phi, %26
  %29 = mul i64 %27, %28
  %30 = sdiv i64 %29, 2
  %31 = load i64, ptr @_QFEacount, align 8, !tbaa !3
  %32 = sub i64 %30, %31
  %33 = tail call i1 @_FortranAioOutputInteger64(ptr %25, i64 %32)
  %34 = tail call i32 @_FortranAioEndIoStatement(ptr %25)
  ret void
}

declare ptr @_FortranAioBeginExternalListInput(i32, ptr, i32) local_unnamed_addr

declare i1 @_FortranAioInputAscii(ptr, ptr, i64) local_unnamed_addr

declare i32 @_FortranAioEndIoStatement(ptr) local_unnamed_addr

declare i32 @_FortranACharacterCompareScalar1(ptr, ptr, i64, i64) local_unnamed_addr

declare ptr @_FortranAioBeginExternalListOutput(i32, ptr, i32) local_unnamed_addr

declare i1 @_FortranAioOutputInteger64(ptr, i64) local_unnamed_addr

!llvm.module.flags = !{!0, !1, !2}

!0 = !{i32 2, !"Debug Info Version", i32 3}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{!4, !4, i64 0}
!4 = !{!"any data access", !5, i64 0}
!5 = !{!"any access", !6, i64 0}
!6 = !{!"Flang Type TBAA Root"}
