program main
implicit None
	character(len = 100000)::s
	integer(8)::n,q,i
	integer(8),allocatable::l(:),r(:),a(:)
	
	read*,n,q
	read*,s
	
	allocate(l(q),r(q),a(n))
	
	a =0
	do i = 2,n
		if(s(i:i) == "C")then
			if(s(i-1:i-1) == "A")then
				a(i) = 1
			endif
		endif
	enddo
	
	do i = 2,n
		a(i) = a(i-1)+a(i)
	enddo
	
	do i = 1,q
		read*,l(i),r(i)
	enddo
	
	do i = 1,q
		print"(i0)",a(r(i))-a(l(i))
	enddo
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
@_QFEa.7 = internal unnamed_addr global i64 1
@_QFEl.0 = internal unnamed_addr global ptr null
@_QFEr.0 = internal unnamed_addr global ptr null
@_QFEs = internal global [100000 x i8] undef
@_QQcl.e569b75b5a82ccfad5b2a67322571350 = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_4671/source.f\00"
@_QQcl.16373402fa3425c6e46827601abb88fa = linkonce constant [76 x i8] c"array left hand side must be allocated when the right hand side is a scalar\00"
@_QQcl.43 = linkonce constant [1 x i8] c"C"
@_QQcl.41 = linkonce constant [1 x i8] c"A"
@_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

define void @_QQmain() local_unnamed_addr {
  %1 = alloca i64, align 8
  %2 = alloca i64, align 8
  %3 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.e569b75b5a82ccfad5b2a67322571350, i32 7)
  %4 = call i1 @_FortranAioInputInteger(ptr %3, ptr nonnull %1, i32 8)
  %5 = call i1 @_FortranAioInputInteger(ptr %3, ptr nonnull %2, i32 8)
  %6 = call i32 @_FortranAioEndIoStatement(ptr %3)
  %7 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.e569b75b5a82ccfad5b2a67322571350, i32 8)
  %8 = call i1 @_FortranAioInputAscii(ptr %7, ptr nonnull @_QFEs, i64 100000)
  %9 = call i32 @_FortranAioEndIoStatement(ptr %7)
  %10 = load i64, ptr %2, align 8, !tbaa !3
  %11 = call i64 @llvm.smax.i64(i64 %10, i64 0)
  %12 = shl i64 %11, 3
  %13 = call ptr @malloc(i64 %12)
  store ptr %13, ptr @_QFEl.0, align 8, !tbaa !7
  %14 = call ptr @malloc(i64 %12)
  store ptr %14, ptr @_QFEr.0, align 8, !tbaa !7
  %15 = load i64, ptr %1, align 8, !tbaa !3
  %16 = call i64 @llvm.smax.i64(i64 %15, i64 0)
  %17 = shl i64 %16, 3
  %18 = call ptr @malloc(i64 %17)
  store ptr %18, ptr @_QFEa.0, align 8, !tbaa !7
  store i64 1, ptr @_QFEa.7, align 8, !tbaa !7
  %.not = icmp eq ptr %18, null
  br i1 %.not, label %19, label %.preheader

.preheader:                                       ; preds = %0
  %.not464 = icmp slt i64 %15, 1
  br i1 %.not464, label %.loopexit, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %.preheader
  call void @llvm.memset.p0.i64(ptr nonnull align 8 %18, i8 0, i64 %17, i1 false), !tbaa !3
  br label %.loopexit

19:                                               ; preds = %0
  %20 = call {} @_FortranAReportFatalUserError(ptr nonnull @_QQcl.16373402fa3425c6e46827601abb88fa, ptr nonnull @_QQcl.e569b75b5a82ccfad5b2a67322571350, i32 12)
  %.unpack440.unpack.unpack = load i64, ptr @_QFEa.7, align 8, !tbaa !7
  %21 = icmp slt i64 %15, 1
  %22 = select i1 %21, i64 1, i64 %.unpack440.unpack.unpack
  store ptr null, ptr @_QFEa.0, align 8, !tbaa !7
  store i64 %22, ptr @_QFEa.7, align 8, !tbaa !7
  %.pre = load i64, ptr %1, align 8, !tbaa !3
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph.preheader, %.preheader, %19
  %23 = phi i64 [ %15, %.lr.ph.preheader ], [ %15, %.preheader ], [ %.pre, %19 ]
  %24 = add i64 %23, -1
  %25 = icmp sgt i64 %24, 0
  br i1 %25, label %.lr.ph454, label %._crit_edge457

.lr.ph454:                                        ; preds = %.loopexit, %39
  %26 = phi i64 [ %40, %39 ], [ 2, %.loopexit ]
  %27 = add i64 %26, -1
  %28 = getelementptr [100000 x [1 x i8]], ptr @_QFEs, i64 0, i64 %27
  %29 = call i32 @_FortranACharacterCompareScalar1(ptr %28, ptr nonnull @_QQcl.43, i64 1, i64 1)
  %30 = icmp eq i32 %29, 0
  br i1 %30, label %31, label %39

31:                                               ; preds = %.lr.ph454
  %32 = add i64 %26, -2
  %33 = getelementptr [100000 x [1 x i8]], ptr @_QFEs, i64 0, i64 %32
  %34 = call i32 @_FortranACharacterCompareScalar1(ptr %33, ptr nonnull @_QQcl.41, i64 1, i64 1)
  %35 = icmp eq i32 %34, 0
  br i1 %35, label %36, label %39

36:                                               ; preds = %31
  %.unpack421 = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  %.unpack428.unpack.unpack = load i64, ptr @_QFEa.7, align 8, !tbaa !7
  %37 = sub i64 %26, %.unpack428.unpack.unpack
  %38 = getelementptr i64, ptr %.unpack421, i64 %37
  store i64 1, ptr %38, align 8, !tbaa !3
  br label %39

39:                                               ; preds = %36, %31, %.lr.ph454
  %40 = add nuw i64 %26, 1
  %exitcond.not = icmp eq i64 %26, %23
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph454

._crit_edge:                                      ; preds = %39
  %.pre468 = load i64, ptr %1, align 8, !tbaa !3
  %.pre470 = add i64 %.pre468, -1
  %41 = icmp sgt i64 %.pre470, 0
  br i1 %41, label %.lr.ph456, label %._crit_edge457

.lr.ph456:                                        ; preds = %._crit_edge
  %.unpack408 = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  %.unpack415.unpack.unpack = load i64, ptr @_QFEa.7, align 8, !tbaa !7
  %42 = shl i64 %.unpack415.unpack.unpack, 3
  %43 = sub i64 8, %42
  %uglygep = getelementptr i8, ptr %.unpack408, i64 %43
  %load_initial = load i64, ptr %uglygep, align 8
  %44 = add i64 %.pre468, -2
  %xtraiter = and i64 %.pre470, 3
  %45 = icmp ult i64 %44, 3
  br i1 %45, label %._crit_edge457.loopexit.unr-lcssa, label %.lr.ph456.new

.lr.ph456.new:                                    ; preds = %.lr.ph456
  %unroll_iter = and i64 %.pre470, -4
  br label %46

46:                                               ; preds = %46, %.lr.ph456.new
  %store_forwarded = phi i64 [ %load_initial, %.lr.ph456.new ], [ %66, %46 ]
  %47 = phi i64 [ 2, %.lr.ph456.new ], [ %67, %46 ]
  %niter = phi i64 [ 0, %.lr.ph456.new ], [ %niter.next.3, %46 ]
  %48 = sub i64 %47, %.unpack415.unpack.unpack
  %49 = getelementptr i64, ptr %.unpack408, i64 %48
  %50 = load i64, ptr %49, align 8, !tbaa !3
  %51 = add i64 %50, %store_forwarded
  store i64 %51, ptr %49, align 8, !tbaa !3
  %52 = or i64 %47, 1
  %53 = sub i64 %52, %.unpack415.unpack.unpack
  %54 = getelementptr i64, ptr %.unpack408, i64 %53
  %55 = load i64, ptr %54, align 8, !tbaa !3
  %56 = add i64 %55, %51
  store i64 %56, ptr %54, align 8, !tbaa !3
  %57 = add nuw i64 %47, 2
  %58 = sub i64 %57, %.unpack415.unpack.unpack
  %59 = getelementptr i64, ptr %.unpack408, i64 %58
  %60 = load i64, ptr %59, align 8, !tbaa !3
  %61 = add i64 %60, %56
  store i64 %61, ptr %59, align 8, !tbaa !3
  %62 = add nuw i64 %47, 3
  %63 = sub i64 %62, %.unpack415.unpack.unpack
  %64 = getelementptr i64, ptr %.unpack408, i64 %63
  %65 = load i64, ptr %64, align 8, !tbaa !3
  %66 = add i64 %65, %61
  store i64 %66, ptr %64, align 8, !tbaa !3
  %67 = add nuw i64 %47, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %._crit_edge457.loopexit.unr-lcssa, label %46

._crit_edge457.loopexit.unr-lcssa:                ; preds = %46, %.lr.ph456
  %store_forwarded.unr = phi i64 [ %load_initial, %.lr.ph456 ], [ %66, %46 ]
  %.unr = phi i64 [ 2, %.lr.ph456 ], [ %67, %46 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge457, label %.epil.preheader

.epil.preheader:                                  ; preds = %._crit_edge457.loopexit.unr-lcssa, %.epil.preheader
  %store_forwarded.epil = phi i64 [ %72, %.epil.preheader ], [ %store_forwarded.unr, %._crit_edge457.loopexit.unr-lcssa ]
  %68 = phi i64 [ %73, %.epil.preheader ], [ %.unr, %._crit_edge457.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.epil.preheader ], [ 0, %._crit_edge457.loopexit.unr-lcssa ]
  %69 = sub i64 %68, %.unpack415.unpack.unpack
  %70 = getelementptr i64, ptr %.unpack408, i64 %69
  %71 = load i64, ptr %70, align 8, !tbaa !3
  %72 = add i64 %71, %store_forwarded.epil
  store i64 %72, ptr %70, align 8, !tbaa !3
  %73 = add nuw i64 %68, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge457, label %.epil.preheader, !llvm.loop !9

._crit_edge457:                                   ; preds = %._crit_edge457.loopexit.unr-lcssa, %.epil.preheader, %.loopexit, %._crit_edge
  %74 = load i64, ptr %2, align 8, !tbaa !3
  %75 = icmp sgt i64 %74, 0
  br i1 %75, label %.lr.ph459, label %._crit_edge463

.lr.ph459:                                        ; preds = %._crit_edge457, %.lr.ph459
  %76 = phi i64 [ %85, %.lr.ph459 ], [ 1, %._crit_edge457 ]
  %77 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.e569b75b5a82ccfad5b2a67322571350, i32 26)
  %.unpack384 = load ptr, ptr @_QFEl.0, align 8, !tbaa !7
  %78 = add i64 %76, -1
  %79 = getelementptr i64, ptr %.unpack384, i64 %78
  %80 = call i1 @_FortranAioInputInteger(ptr %77, ptr %79, i32 8)
  %.unpack396 = load ptr, ptr @_QFEr.0, align 8, !tbaa !7
  %81 = add i64 %76, -1
  %82 = getelementptr i64, ptr %.unpack396, i64 %81
  %83 = call i1 @_FortranAioInputInteger(ptr %77, ptr %82, i32 8)
  %84 = call i32 @_FortranAioEndIoStatement(ptr %77)
  %85 = add nuw i64 %76, 1
  %exitcond466.not = icmp eq i64 %76, %74
  br i1 %exitcond466.not, label %._crit_edge460, label %.lr.ph459

._crit_edge460:                                   ; preds = %.lr.ph459
  %.pre469 = load i64, ptr %2, align 8, !tbaa !3
  %86 = icmp sgt i64 %.pre469, 0
  br i1 %86, label %.lr.ph462, label %._crit_edge463

.lr.ph462:                                        ; preds = %._crit_edge460, %.lr.ph462
  %87 = phi i64 [ %104, %.lr.ph462 ], [ 1, %._crit_edge460 ]
  %88 = call ptr @_FortranAioBeginExternalFormattedOutput(ptr nonnull @_QQcl.28693029, i64 4, ptr null, i32 -1, ptr nonnull @_QQcl.e569b75b5a82ccfad5b2a67322571350, i32 30)
  %.unpack = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  %.unpack355.unpack.unpack = load i64, ptr @_QFEa.7, align 8, !tbaa !7
  %.unpack360 = load ptr, ptr @_QFEr.0, align 8, !tbaa !7
  %89 = add i64 %87, -1
  %90 = getelementptr i64, ptr %.unpack360, i64 %89
  %91 = load i64, ptr %90, align 8, !tbaa !3
  %92 = sub i64 %91, %.unpack355.unpack.unpack
  %93 = getelementptr i64, ptr %.unpack, i64 %92
  %94 = load i64, ptr %93, align 8, !tbaa !3
  %.unpack372 = load ptr, ptr @_QFEl.0, align 8, !tbaa !7
  %95 = add i64 %87, -1
  %96 = getelementptr i64, ptr %.unpack372, i64 %95
  %97 = load i64, ptr %96, align 8, !tbaa !3
  %98 = sub i64 %97, %.unpack355.unpack.unpack
  %99 = getelementptr i64, ptr %.unpack, i64 %98
  %100 = load i64, ptr %99, align 8, !tbaa !3
  %101 = sub i64 %94, %100
  %102 = call i1 @_FortranAioOutputInteger64(ptr %88, i64 %101)
  %103 = call i32 @_FortranAioEndIoStatement(ptr %88)
  %104 = add nuw i64 %87, 1
  %exitcond467.not = icmp eq i64 %87, %.pre469
  br i1 %exitcond467.not, label %._crit_edge463, label %.lr.ph462

._crit_edge463:                                   ; preds = %.lr.ph462, %._crit_edge457, %._crit_edge460
  ret void
}

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

declare i1 @_FortranAioInputInteger(ptr, ptr, i32) local_unnamed_addr

declare i32 @_FortranAioEndIoStatement(ptr) local_unnamed_addr

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

declare {} @_FortranAReportFatalUserError(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 nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.smax.i64(i64, i64) #1

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

attributes #0 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { 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 = !{!"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}
!10 = !{!"llvm.loop.unroll.disable"}
