program main
implicit None
character*200000::s
integer(8)::k,t,i,n
integer(8),allocatable::a(:)

read *,s
k = len_trim(s)
t = 0

do i = k,1,-1
	if(s(i:i) == "B")then
	t = t + 1
	endif
enddo

if(t == 0)then
	print 101,t
	stop
endif

allocate(a(t))

n = 1
do i = k,1,-1
	if(s(i:i) == "B")then
		a(n) = i
		n = n + 1
	endif
enddo

n = 0
do i = 1,t
	n  = n + k - (a(i)) -(i -1)
enddo

print 101,n
deallocate(a)

101 format(i0)
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"

@_QFEa.0 = internal unnamed_addr global ptr null
@_QFEs = internal global [200000 x i8] undef
@_QQcl.997126fe205d41d7c982ee786b4e119b = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_5266/source.f\00"
@_QQcl.42 = linkonce constant [1 x i8] c"B"
@_QQcl.28693029 = linkonce constant [4 x i8] c"(i0)"
@_QQEnvironmentDefaults = local_unnamed_addr constant ptr null

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #1

define void @_QQmain() local_unnamed_addr {
  %1 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.997126fe205d41d7c982ee786b4e119b, 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.thread

.lr.ph:                                           ; preds = %12, %.lr.ph
  %17 = phi i64 [ %18, %.lr.ph ], [ %14, %12 ]
  %.0169 = phi i64 [ %spec.select, %.lr.ph ], [ 0, %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
  %22 = zext i1 %21 to i64
  %spec.select = add i64 %.0169, %22
  %23 = icmp ugt i64 %17, 1
  br i1 %23, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph
  %24 = icmp eq i64 %spec.select, 0
  br i1 %24, label %._crit_edge.thread, label %29

._crit_edge.thread:                               ; preds = %12, %._crit_edge
  %25 = tail call ptr @_FortranAioBeginExternalFormattedOutput(ptr nonnull @_QQcl.28693029, i64 4, ptr null, i32 -1, ptr nonnull @_QQcl.997126fe205d41d7c982ee786b4e119b, i32 18)
  %26 = tail call i1 @_FortranAioOutputInteger64(ptr %25, i64 0)
  %27 = tail call i32 @_FortranAioEndIoStatement(ptr %25)
  %28 = tail call {} @_FortranAStopStatement(i32 0, i1 false, i1 false)
  unreachable

29:                                               ; preds = %._crit_edge
  %30 = tail call i64 @llvm.smax.i64(i64 %spec.select, i64 0)
  %31 = shl i64 %30, 3
  %32 = tail call ptr @malloc(i64 %31)
  store ptr %32, ptr @_QFEa.0, align 8, !tbaa !7
  br i1 %16, label %.lr.ph172, label %.preheader

.preheader:                                       ; preds = %53, %29
  %33 = icmp sgt i64 %spec.select, 0
  br i1 %33, label %.lr.ph174, label %._crit_edge175

.lr.ph174:                                        ; preds = %.preheader
  %.unpack141 = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  %.neg165 = add nsw i64 %15, 1
  %min.iters.check = icmp ult i64 %spec.select, 4
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph174
  %n.vec = and i64 %spec.select, -4
  %ind.end = or i64 %n.vec, 1
  %broadcast.splatinsert = insertelement <2 x i64> poison, i64 %.neg165, i64 0
  %broadcast.splat = shufflevector <2 x i64> %broadcast.splatinsert, <2 x i64> poison, <2 x i32> zeroinitializer
  %broadcast.splatinsert187 = insertelement <2 x i64> poison, i64 %.neg165, i64 0
  %broadcast.splat188 = shufflevector <2 x i64> %broadcast.splatinsert187, <2 x i64> poison, <2 x i32> zeroinitializer
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vec.ind = phi <2 x i64> [ <i64 1, i64 2>, %vector.ph ], [ %vec.ind.next, %vector.body ]
  %vec.phi = phi <2 x i64> [ zeroinitializer, %vector.ph ], [ %40, %vector.body ]
  %vec.phi185 = phi <2 x i64> [ zeroinitializer, %vector.ph ], [ %41, %vector.body ]
  %step.add = add <2 x i64> %vec.ind, <i64 2, i64 2>
  %34 = getelementptr i64, ptr %.unpack141, i64 %index
  %wide.load = load <2 x i64>, ptr %34, align 8, !tbaa !3
  %35 = getelementptr i64, ptr %34, i64 2
  %wide.load186 = load <2 x i64>, ptr %35, align 8, !tbaa !3
  %36 = add <2 x i64> %broadcast.splat, %vec.phi
  %37 = add <2 x i64> %broadcast.splat188, %vec.phi185
  %38 = add <2 x i64> %vec.ind, %wide.load
  %39 = add <2 x i64> %step.add, %wide.load186
  %40 = sub <2 x i64> %36, %38
  %41 = sub <2 x i64> %37, %39
  %index.next = add nuw i64 %index, 4
  %vec.ind.next = add <2 x i64> %vec.ind, <i64 4, i64 4>
  %42 = icmp eq i64 %index.next, %n.vec
  br i1 %42, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %vector.body
  %bin.rdx = add <2 x i64> %41, %40
  %43 = tail call i64 @llvm.vector.reduce.add.v2i64(<2 x i64> %bin.rdx)
  %cmp.n = icmp eq i64 %spec.select, %n.vec
  br i1 %cmp.n, label %._crit_edge175, label %scalar.ph.preheader

scalar.ph.preheader:                              ; preds = %.lr.ph174, %middle.block
  %.ph = phi i64 [ 1, %.lr.ph174 ], [ %ind.end, %middle.block ]
  %.2173.ph = phi i64 [ 0, %.lr.ph174 ], [ %43, %middle.block ]
  br label %scalar.ph

.lr.ph172:                                        ; preds = %29, %53
  %44 = phi i64 [ %45, %53 ], [ %14, %29 ]
  %.0115170 = phi i64 [ %.1116, %53 ], [ 1, %29 ]
  %45 = add nsw i64 %44, -1
  %46 = getelementptr [200000 x [1 x i8]], ptr @_QFEs, i64 0, i64 %45
  %47 = tail call i32 @_FortranACharacterCompareScalar1(ptr %46, ptr nonnull @_QQcl.42, i64 1, i64 1)
  %48 = icmp eq i32 %47, 0
  br i1 %48, label %49, label %53

49:                                               ; preds = %.lr.ph172
  %.unpack153 = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  %50 = add i64 %.0115170, -1
  %51 = getelementptr i64, ptr %.unpack153, i64 %50
  store i64 %44, ptr %51, align 8, !tbaa !3
  %52 = add i64 %.0115170, 1
  br label %53

53:                                               ; preds = %49, %.lr.ph172
  %.1116 = phi i64 [ %52, %49 ], [ %.0115170, %.lr.ph172 ]
  %54 = icmp ugt i64 %44, 1
  br i1 %54, label %.lr.ph172, label %.preheader

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %55 = phi i64 [ %61, %scalar.ph ], [ %.ph, %scalar.ph.preheader ]
  %.2173 = phi i64 [ %60, %scalar.ph ], [ %.2173.ph, %scalar.ph.preheader ]
  %56 = add i64 %55, -1
  %57 = getelementptr i64, ptr %.unpack141, i64 %56
  %58 = load i64, ptr %57, align 8, !tbaa !3
  %.neg167 = add i64 %.neg165, %.2173
  %59 = add i64 %55, %58
  %60 = sub i64 %.neg167, %59
  %61 = add nuw i64 %55, 1
  %exitcond.not = icmp eq i64 %55, %spec.select
  br i1 %exitcond.not, label %._crit_edge175, label %scalar.ph, !llvm.loop !12

._crit_edge175:                                   ; preds = %scalar.ph, %middle.block, %.preheader
  %.2.lcssa = phi i64 [ 0, %.preheader ], [ %43, %middle.block ], [ %60, %scalar.ph ]
  %62 = tail call ptr @_FortranAioBeginExternalFormattedOutput(ptr nonnull @_QQcl.28693029, i64 4, ptr null, i32 -1, ptr nonnull @_QQcl.997126fe205d41d7c982ee786b4e119b, i32 37)
  %63 = tail call i1 @_FortranAioOutputInteger64(ptr %62, i64 %.2.lcssa)
  %64 = tail call i32 @_FortranAioEndIoStatement(ptr %62)
  %.unpack = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  tail call void @free(ptr %.unpack)
  store ptr null, ptr @_QFEa.0, align 8, !tbaa !7
  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 @_FortranAioBeginExternalFormattedOutput(ptr, i64, ptr, i32, ptr, i32) local_unnamed_addr

declare i1 @_FortranAioOutputInteger64(ptr, i64) local_unnamed_addr

declare {} @_FortranAStopStatement(i32, i1, i1) local_unnamed_addr

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.smax.i64(i64, i64) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(none)
declare i64 @llvm.vector.reduce.add.v2i64(<2 x i64>) #3

attributes #0 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" }
attributes #1 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { nocallback nofree nosync nounwind willreturn memory(none) }

!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"}
!7 = !{!8, !8, i64 0}
!8 = !{!"descriptor member", !5, i64 0}
!9 = distinct !{!9, !10, !11}
!10 = !{!"llvm.loop.isvectorized", i32 1}
!11 = !{!"llvm.loop.unroll.runtime.disable"}
!12 = distinct !{!12, !11, !10}
