program main
  implicit none
  integer(8) :: n, i, blacks, res
  character(200000) :: s
  read (*, *) s
  n = len(trim(s))
  res = 0
  blacks = 0
  do i = 1, n
    if (s(i:i) == "B") then
      blacks = blacks + 1
    else
      res = res + blacks
    end if
  end do
  write (*, "(i0)") res
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"

@_QFEs = internal global [200000 x i8] undef
@_QQcl.37e2df25bd33f131a2107d9f19ba96f4 = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_5258/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 nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #0

define void @_QQmain() local_unnamed_addr {
  %1 = alloca { ptr, i64, i32, i8, i8, i8, i8 }, align 8
  %2 = alloca { ptr, i64, i32, i8, i8, i8, i8 }, align 8
  %3 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.37e2df25bd33f131a2107d9f19ba96f4, i32 5)
  %4 = tail call i1 @_FortranAioInputAscii(ptr %3, ptr nonnull @_QFEs, i64 200000)
  %5 = tail call i32 @_FortranAioEndIoStatement(ptr %3)
  store ptr @_QFEs, ptr %1, align 8, !tbaa !3
  %.fca.1.gep15 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8 }, ptr %1, i64 0, i32 1
  store i64 200000, ptr %.fca.1.gep15, align 8, !tbaa !3
  %.fca.2.gep16 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8 }, ptr %1, i64 0, i32 2
  store i32 20180515, ptr %.fca.2.gep16, align 8, !tbaa !3
  %.fca.3.gep17 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8 }, ptr %1, i64 0, i32 3
  store i8 0, ptr %.fca.3.gep17, align 4, !tbaa !3
  %.fca.4.gep18 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8 }, ptr %1, i64 0, i32 4
  store i8 40, ptr %.fca.4.gep18, align 1, !tbaa !3
  %.fca.5.gep19 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8 }, ptr %1, i64 0, i32 5
  store i8 0, ptr %.fca.5.gep19, align 2, !tbaa !3
  %.fca.6.gep20 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8 }, ptr %1, i64 0, i32 6
  store i8 0, ptr %.fca.6.gep20, align 1, !tbaa !3
  %.fca.1.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8 }, ptr %2, i64 0, i32 1
  %.fca.2.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8 }, ptr %2, i64 0, i32 2
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %2, i8 0, i64 16, i1 false)
  store i32 20180515, ptr %.fca.2.gep, align 8, !tbaa !3
  %.fca.3.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8 }, ptr %2, i64 0, i32 3
  store i8 0, ptr %.fca.3.gep, align 4, !tbaa !3
  %.fca.4.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8 }, ptr %2, i64 0, i32 4
  store i8 40, ptr %.fca.4.gep, align 1, !tbaa !3
  %.fca.5.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8 }, ptr %2, i64 0, i32 5
  store i8 2, ptr %.fca.5.gep, align 2, !tbaa !3
  %.fca.6.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8 }, ptr %2, i64 0, i32 6
  store i8 0, ptr %.fca.6.gep, align 1, !tbaa !3
  %6 = call {} @_FortranATrim(ptr nonnull %2, ptr nonnull %1, ptr nonnull @_QQcl.37e2df25bd33f131a2107d9f19ba96f4, i32 6)
  %.fca.0.load = load ptr, ptr %2, align 8, !tbaa !3
  %.fca.1.load = load i64, ptr %.fca.1.gep, align 8, !tbaa !3
  call void @free(ptr %.fca.0.load)
  %7 = trunc i64 %.fca.1.load to i32
  %8 = icmp sgt i32 %7, 0
  br i1 %8, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %0
  %9 = and i64 %.fca.1.load, 4294967295
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %10 = phi i64 [ %19, %.lr.ph ], [ %9, %.lr.ph.preheader ]
  %11 = phi i64 [ %18, %.lr.ph ], [ 1, %.lr.ph.preheader ]
  %.058 = phi i64 [ %.1, %.lr.ph ], [ 0, %.lr.ph.preheader ]
  %.05457 = phi i64 [ %.155, %.lr.ph ], [ 0, %.lr.ph.preheader ]
  %12 = add nsw i64 %11, -1
  %13 = getelementptr [200000 x [1 x i8]], ptr @_QFEs, i64 0, i64 %12
  %14 = call i32 @_FortranACharacterCompareScalar1(ptr %13, ptr nonnull @_QQcl.42, i64 1, i64 1)
  %15 = icmp eq i32 %14, 0
  %16 = zext i1 %15 to i64
  %.155 = add i64 %.05457, %16
  %17 = select i1 %15, i64 0, i64 %.05457
  %.1 = add i64 %17, %.058
  %18 = add nuw nsw i64 %11, 1
  %19 = add nsw i64 %10, -1
  %20 = icmp ugt i64 %10, 1
  br i1 %20, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %0
  %.0.lcssa = phi i64 [ 0, %0 ], [ %.1, %.lr.ph ]
  %21 = call ptr @_FortranAioBeginExternalFormattedOutput(ptr nonnull @_QQcl.28693029, i64 4, ptr null, i32 -1, ptr nonnull @_QQcl.37e2df25bd33f131a2107d9f19ba96f4, i32 16)
  %22 = call i1 @_FortranAioOutputInteger64(ptr %21, i64 %.0.lcssa)
  %23 = call i32 @_FortranAioEndIoStatement(ptr %21)
  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 {} @_FortranATrim(ptr, ptr, ptr, i32) 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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

attributes #0 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: write) }

!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 = !{!"descriptor member", !5, i64 0}
!5 = !{!"any access", !6, i64 0}
!6 = !{!"Flang Type TBAA Root"}
