program ABC174D
    implicit none
    integer(8)::N,i,Wc(0:200000),Rc(0:200000),ans=2000000
    character(200000)::C
    read*,N,C
    Wc(0)=0
    Rc(0)=0
    do i=1,N
        if(C(i:i)=="R")then
            Rc(i)=Rc(i-1)+1
            Wc(i)=Wc(i-1)
        else
            Rc(i)=Rc(i-1)
            Wc(i)=Wc(i-1)+1
        end if
    end do

    do i=0,N
        ans=min(ans,max(Wc(i)-Wc(0),Rc(N)-Rc(i+1)))
    end do
    print'(i0)',ans
end program ABC174D
; 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"

@_QFEans = internal unnamed_addr global i64 2000000
@_QFEc = internal global [200000 x i8] undef
@_QFErc = internal unnamed_addr global [200001 x i64] undef
@_QFEwc = internal unnamed_addr global [200001 x i64] undef
@_QQcl.078c896ba6deb9cd97c24fcf4196e6ae = linkonce constant [72 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_874/source.f\00"
@_QQcl.52 = linkonce constant [1 x i8] c"R"
@_QQcl.28693029 = linkonce constant [4 x i8] c"(i0)"
@_QQEnvironmentDefaults = local_unnamed_addr constant ptr null

define void @_QQmain() local_unnamed_addr {
  %1 = alloca i64, align 8
  %2 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.078c896ba6deb9cd97c24fcf4196e6ae, i32 5)
  %3 = call i1 @_FortranAioInputInteger(ptr %2, ptr nonnull %1, i32 8)
  %4 = call i1 @_FortranAioInputAscii(ptr %2, ptr nonnull @_QFEc, i64 200000)
  %5 = call i32 @_FortranAioEndIoStatement(ptr %2)
  store i64 0, ptr @_QFEwc, align 16, !tbaa !3
  store i64 0, ptr @_QFErc, align 16, !tbaa !3
  %6 = load i64, ptr %1, align 8, !tbaa !3
  %7 = icmp sgt i64 %6, 0
  br i1 %7, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %0, %23
  %8 = phi i64 [ %26, %23 ], [ 1, %0 ]
  %9 = add nsw i64 %8, -1
  %10 = getelementptr [200000 x [1 x i8]], ptr @_QFEc, i64 0, i64 %9
  %11 = call i32 @_FortranACharacterCompareScalar1(ptr %10, ptr nonnull @_QQcl.52, i64 1, i64 1)
  %12 = icmp eq i32 %11, 0
  %13 = getelementptr [200001 x i64], ptr @_QFErc, i64 0, i64 %9
  %14 = load i64, ptr %13, align 8, !tbaa !3
  br i1 %12, label %15, label %19

15:                                               ; preds = %.lr.ph
  %16 = add i64 %14, 1
  %17 = getelementptr [200001 x i64], ptr @_QFEwc, i64 0, i64 %9
  %18 = load i64, ptr %17, align 8, !tbaa !3
  br label %23

19:                                               ; preds = %.lr.ph
  %20 = getelementptr [200001 x i64], ptr @_QFEwc, i64 0, i64 %9
  %21 = load i64, ptr %20, align 8, !tbaa !3
  %22 = add i64 %21, 1
  br label %23

23:                                               ; preds = %15, %19
  %.sink12 = phi i64 [ %16, %15 ], [ %14, %19 ]
  %.sink = phi i64 [ %18, %15 ], [ %22, %19 ]
  %24 = getelementptr [200001 x i64], ptr @_QFErc, i64 0, i64 %8
  store i64 %.sink12, ptr %24, align 8
  %25 = getelementptr [200001 x i64], ptr @_QFEwc, i64 0, i64 %8
  store i64 %.sink, ptr %25, align 8
  %26 = add nuw i64 %8, 1
  %exitcond.not = icmp eq i64 %8, %6
  br i1 %exitcond.not, label %._crit_edge.loopexit, label %.lr.ph

._crit_edge.loopexit:                             ; preds = %23
  %.pre = load i64, ptr %1, align 8, !tbaa !3
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %0
  %27 = phi i64 [ %.pre, %._crit_edge.loopexit ], [ %6, %0 ]
  %28 = icmp ult i64 %27, 9223372036854775807
  br i1 %28, label %.lr.ph10, label %65

.lr.ph10:                                         ; preds = %._crit_edge
  %29 = add i64 %27, 1
  %_QFEans.promoted = load i64, ptr @_QFEans, align 8, !tbaa !3
  %30 = load i64, ptr @_QFEwc, align 16, !tbaa !3
  %31 = getelementptr [200001 x i64], ptr @_QFErc, i64 0, i64 %27
  %32 = load i64, ptr %31, align 8, !tbaa !3
  %33 = add i64 %27, 2
  %34 = icmp ne i64 %29, 0
  %umin.neg = sext i1 %34 to i64
  %35 = add i64 %33, %umin.neg
  %min.iters.check = icmp ult i64 %35, 4
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph10
  %n.vec = and i64 %35, -4
  %ind.end = sub i64 %29, %n.vec
  %minmax.ident.splatinsert = insertelement <2 x i64> poison, i64 %_QFEans.promoted, i64 0
  %minmax.ident.splat = shufflevector <2 x i64> %minmax.ident.splatinsert, <2 x i64> poison, <2 x i32> zeroinitializer
  %broadcast.splatinsert = insertelement <2 x i64> poison, i64 %30, i64 0
  %broadcast.splat = shufflevector <2 x i64> %broadcast.splatinsert, <2 x i64> poison, <2 x i32> zeroinitializer
  %broadcast.splatinsert16 = insertelement <2 x i64> poison, i64 %30, i64 0
  %broadcast.splat17 = shufflevector <2 x i64> %broadcast.splatinsert16, <2 x i64> poison, <2 x i32> zeroinitializer
  %broadcast.splatinsert20 = insertelement <2 x i64> poison, i64 %32, i64 0
  %broadcast.splat21 = shufflevector <2 x i64> %broadcast.splatinsert20, <2 x i64> poison, <2 x i32> zeroinitializer
  %broadcast.splatinsert22 = insertelement <2 x i64> poison, i64 %32, i64 0
  %broadcast.splat23 = shufflevector <2 x i64> %broadcast.splatinsert22, <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.phi = phi <2 x i64> [ %minmax.ident.splat, %vector.ph ], [ %47, %vector.body ]
  %vec.phi14 = phi <2 x i64> [ %minmax.ident.splat, %vector.ph ], [ %48, %vector.body ]
  %36 = getelementptr [200001 x i64], ptr @_QFEwc, i64 0, i64 %index
  %wide.load = load <2 x i64>, ptr %36, align 16, !tbaa !3
  %37 = getelementptr i64, ptr %36, i64 2
  %wide.load15 = load <2 x i64>, ptr %37, align 16, !tbaa !3
  %38 = sub <2 x i64> %wide.load, %broadcast.splat
  %39 = sub <2 x i64> %wide.load15, %broadcast.splat17
  %40 = or i64 %index, 1
  %41 = getelementptr [200001 x i64], ptr @_QFErc, i64 0, i64 %40
  %wide.load18 = load <2 x i64>, ptr %41, align 8, !tbaa !3
  %42 = getelementptr i64, ptr %41, i64 2
  %wide.load19 = load <2 x i64>, ptr %42, align 8, !tbaa !3
  %43 = sub <2 x i64> %broadcast.splat21, %wide.load18
  %44 = sub <2 x i64> %broadcast.splat23, %wide.load19
  %45 = call <2 x i64> @llvm.smax.v2i64(<2 x i64> %38, <2 x i64> %43)
  %46 = call <2 x i64> @llvm.smax.v2i64(<2 x i64> %39, <2 x i64> %44)
  %47 = call <2 x i64> @llvm.smin.v2i64(<2 x i64> %vec.phi, <2 x i64> %45)
  %48 = call <2 x i64> @llvm.smin.v2i64(<2 x i64> %vec.phi14, <2 x i64> %46)
  %index.next = add nuw i64 %index, 4
  %49 = icmp eq i64 %index.next, %n.vec
  br i1 %49, label %middle.block, label %vector.body, !llvm.loop !7

middle.block:                                     ; preds = %vector.body
  %rdx.minmax.select = call <2 x i64> @llvm.smin.v2i64(<2 x i64> %47, <2 x i64> %48)
  %50 = call i64 @llvm.vector.reduce.smin.v2i64(<2 x i64> %rdx.minmax.select)
  %cmp.n = icmp eq i64 %35, %n.vec
  br i1 %cmp.n, label %._crit_edge11, label %scalar.ph.preheader

scalar.ph.preheader:                              ; preds = %.lr.ph10, %middle.block
  %.ph = phi i64 [ %29, %.lr.ph10 ], [ %ind.end, %middle.block ]
  %.ph24 = phi i64 [ 0, %.lr.ph10 ], [ %n.vec, %middle.block ]
  %.ph25 = phi i64 [ %_QFEans.promoted, %.lr.ph10 ], [ %50, %middle.block ]
  br label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %51 = phi i64 [ %63, %scalar.ph ], [ %.ph, %scalar.ph.preheader ]
  %52 = phi i64 [ %57, %scalar.ph ], [ %.ph24, %scalar.ph.preheader ]
  %53 = phi i64 [ %62, %scalar.ph ], [ %.ph25, %scalar.ph.preheader ]
  %54 = getelementptr [200001 x i64], ptr @_QFEwc, i64 0, i64 %52
  %55 = load i64, ptr %54, align 8, !tbaa !3
  %56 = sub i64 %55, %30
  %57 = add nuw nsw i64 %52, 1
  %58 = getelementptr [200001 x i64], ptr @_QFErc, i64 0, i64 %57
  %59 = load i64, ptr %58, align 8, !tbaa !3
  %60 = sub i64 %32, %59
  %61 = call i64 @llvm.smax.i64(i64 %56, i64 %60)
  %62 = call i64 @llvm.smin.i64(i64 %53, i64 %61)
  %63 = add nsw i64 %51, -1
  %64 = icmp ugt i64 %51, 1
  br i1 %64, label %scalar.ph, label %._crit_edge11, !llvm.loop !10

._crit_edge11:                                    ; preds = %scalar.ph, %middle.block
  %.lcssa = phi i64 [ %50, %middle.block ], [ %62, %scalar.ph ]
  store i64 %.lcssa, ptr @_QFEans, align 8, !tbaa !3
  br label %65

65:                                               ; preds = %._crit_edge11, %._crit_edge
  %66 = call ptr @_FortranAioBeginExternalFormattedOutput(ptr nonnull @_QQcl.28693029, i64 4, ptr null, i32 -1, ptr nonnull @_QQcl.078c896ba6deb9cd97c24fcf4196e6ae, i32 21)
  %67 = load i64, ptr @_QFEans, align 8, !tbaa !3
  %68 = call i1 @_FortranAioOutputInteger64(ptr %66, i64 %67)
  %69 = call i32 @_FortranAioEndIoStatement(ptr %66)
  ret void
}

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

declare i1 @_FortranAioInputInteger(ptr, 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

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

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

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <2 x i64> @llvm.smin.v2i64(<2 x i64>, <2 x i64>) #0

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

attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { 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 = distinct !{!7, !8, !9}
!8 = !{!"llvm.loop.isvectorized", i32 1}
!9 = !{!"llvm.loop.unroll.runtime.disable"}
!10 = distinct !{!10, !9, !8}
