program main
  implicit none
  character(len=100000) :: s
  integer :: n, q, i, j, k, l, r
  integer, allocatable :: a(:), ans(:)

  read *, n, q
  read *, s

  allocate (a(n), ans(q))
  ans(:) = 0
  a(:) = 0

  do i = 1, len_trim(s) - 1
    if (s(i:i+1) == 'AC') then
      a(i+1:) = a(i+1:) + 1
    end if
  end do 

  do k = 1, q
    read *, l, r
    ans(k) = a(r) - a(l)
  end do

  do k = 1, q
    print '(i0)', ans(k)
  end do

end
; 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.8 = internal unnamed_addr global i64 0
@_QFEans.0 = internal unnamed_addr global ptr null
@_QFEs = internal global [100000 x i8] undef
@_QQcl.8d4cded5c1cf70bdbdc1e356f6df5759 = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_4672/source.f\00"
@_QQcl.4143 = linkonce constant [2 x i8] c"AC"
@_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 i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.8d4cded5c1cf70bdbdc1e356f6df5759, i32 7)
  %6 = call i1 @_FortranAioInputInteger(ptr %5, ptr nonnull %2, i32 4)
  %7 = call i1 @_FortranAioInputInteger(ptr %5, ptr nonnull %3, i32 4)
  %8 = call i32 @_FortranAioEndIoStatement(ptr %5)
  %9 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.8d4cded5c1cf70bdbdc1e356f6df5759, i32 8)
  %10 = call i1 @_FortranAioInputAscii(ptr %9, ptr nonnull @_QFEs, i64 100000)
  %11 = call i32 @_FortranAioEndIoStatement(ptr %9)
  %12 = load i32, ptr %2, align 4, !tbaa !3
  %13 = call i32 @llvm.smax.i32(i32 %12, i32 0)
  %14 = zext i32 %13 to i64
  %15 = shl nuw nsw i64 %14, 2
  %16 = call ptr @malloc(i64 %15)
  store ptr %16, ptr @_QFEa.0, align 8, !tbaa !7
  store i64 %14, ptr @_QFEa.8, align 8, !tbaa !7
  %17 = load i32, ptr %3, align 4, !tbaa !3
  %18 = call i32 @llvm.smax.i32(i32 %17, i32 0)
  %19 = zext i32 %18 to i64
  %20 = shl nuw nsw i64 %19, 2
  %21 = call ptr @malloc(i64 %20)
  store ptr %21, ptr @_QFEans.0, align 8, !tbaa !7
  %.not = icmp slt i32 %17, 1
  br i1 %.not, label %.preheader259, label %select.unfold.preheader

select.unfold.preheader:                          ; preds = %0
  %22 = shl nuw nsw i64 %19, 2
  call void @llvm.memset.p0.i64(ptr align 4 %21, i8 0, i64 %22, i1 false), !tbaa !3
  br label %.preheader259

.preheader259:                                    ; preds = %select.unfold.preheader, %0
  %.not269 = icmp slt i32 %12, 1
  br i1 %.not269, label %.preheader.preheader, label %.lr.ph261.preheader

.lr.ph261.preheader:                              ; preds = %.preheader259
  %23 = call i64 @llvm.smax.i64(i64 %14, i64 1)
  %24 = shl nuw nsw i64 %23, 2
  call void @llvm.memset.p0.i64(ptr align 4 %16, i8 0, i64 %24, i1 false), !tbaa !3
  br label %.preheader.preheader

.preheader.preheader:                             ; preds = %.lr.ph261.preheader, %.preheader259
  br label %.preheader

.preheader:                                       ; preds = %.preheader.preheader, %.preheader
  %25 = phi i64 [ %29, %.preheader ], [ 99999, %.preheader.preheader ]
  %26 = getelementptr [100000 x [1 x i8]], ptr @_QFEs, i64 0, i64 %25
  %27 = load i8, ptr %26, align 1, !tbaa !3
  %28 = icmp eq i8 %27, 32
  %29 = add nsw i64 %25, -1
  %30 = icmp ne i64 %25, 0
  %31 = and i1 %28, %30
  br i1 %31, label %.preheader, label %32

32:                                               ; preds = %.preheader
  %sext = shl i64 %25, 32
  %33 = ashr exact i64 %sext, 32
  %spec.select258 = select i1 %28, i64 -1, i64 %33
  %34 = icmp sgt i64 %spec.select258, 0
  br i1 %34, label %.lr.ph263, label %select.unfold257._crit_edge

.lr.ph263:                                        ; preds = %32, %select.unfold257
  %indvars.iv = phi i64 [ %indvars.iv.next, %select.unfold257 ], [ 1, %32 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %sext284 = shl i64 %indvars.iv.next, 32
  %35 = ashr exact i64 %sext284, 32
  %36 = add nsw i64 %indvars.iv, -1
  %37 = getelementptr [100000 x [1 x i8]], ptr @_QFEs, i64 0, i64 %36
  %38 = sub nsw i64 %35, %indvars.iv
  %39 = call i64 @llvm.smax.i64(i64 %38, i64 -1)
  %40 = add nsw i64 %39, 1
  %41 = call i32 @_FortranACharacterCompareScalar1(ptr %37, ptr nonnull @_QQcl.4143, i64 %40, i64 2)
  %42 = icmp eq i32 %41, 0
  br i1 %42, label %43, label %select.unfold257

43:                                               ; preds = %.lr.ph263
  %.unpack245 = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  %.unpack252.unpack.unpack254 = load i64, ptr @_QFEa.8, align 8, !tbaa !7
  %44 = sub nsw i64 1, %35
  %45 = add i64 %44, %.unpack252.unpack.unpack254
  %.not270 = icmp slt i64 %45, 1
  br i1 %.not270, label %select.unfold257, label %.lr.ph262

.lr.ph262:                                        ; preds = %43
  %46 = add nsw i64 %35, -1
  %min.iters.check = icmp ult i64 %45, 8
  br i1 %min.iters.check, label %scalar.ph, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph262
  %n.vec = and i64 %45, -8
  %ind.end = and i64 %45, 7
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %47 = add i64 %46, %index
  %48 = getelementptr i32, ptr %.unpack245, i64 %47
  %wide.load = load <4 x i32>, ptr %48, align 4, !tbaa !3
  %49 = getelementptr i32, ptr %48, i64 4
  %wide.load289 = load <4 x i32>, ptr %49, align 4, !tbaa !3
  %50 = add <4 x i32> %wide.load, <i32 1, i32 1, i32 1, i32 1>
  %51 = add <4 x i32> %wide.load289, <i32 1, i32 1, i32 1, i32 1>
  store <4 x i32> %50, ptr %48, align 4, !tbaa !3
  store <4 x i32> %51, ptr %49, align 4, !tbaa !3
  %index.next = add nuw i64 %index, 8
  %52 = icmp eq i64 %index.next, %n.vec
  br i1 %52, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %45, %n.vec
  br i1 %cmp.n, label %select.unfold257, label %scalar.ph

scalar.ph:                                        ; preds = %middle.block, %.lr.ph262
  %.ph = phi i64 [ %45, %.lr.ph262 ], [ %ind.end, %middle.block ]
  %.ph290 = phi i64 [ 0, %.lr.ph262 ], [ %n.vec, %middle.block ]
  %53 = add i64 %46, %.ph290
  %54 = getelementptr i32, ptr %.unpack245, i64 %53
  %55 = load i32, ptr %54, align 4, !tbaa !3
  %56 = add i32 %55, 1
  store i32 %56, ptr %54, align 4, !tbaa !3
  %57 = icmp ugt i64 %.ph, 1
  br i1 %57, label %scalar.ph.1, label %select.unfold257, !llvm.loop !12

scalar.ph.1:                                      ; preds = %scalar.ph
  %58 = or i64 %.ph290, 1
  %59 = add i64 %46, %58
  %60 = getelementptr i32, ptr %.unpack245, i64 %59
  %61 = load i32, ptr %60, align 4, !tbaa !3
  %62 = add i32 %61, 1
  store i32 %62, ptr %60, align 4, !tbaa !3
  %63 = add nsw i64 %.ph, -3
  %64 = icmp ult i64 %63, -2
  br i1 %64, label %scalar.ph.2, label %select.unfold257, !llvm.loop !12

scalar.ph.2:                                      ; preds = %scalar.ph.1
  %65 = or i64 %.ph290, 2
  %66 = add i64 %46, %65
  %67 = getelementptr i32, ptr %.unpack245, i64 %66
  %68 = load i32, ptr %67, align 4, !tbaa !3
  %69 = add i32 %68, 1
  store i32 %69, ptr %67, align 4, !tbaa !3
  %70 = and i64 %.ph, 6
  %.not292 = icmp eq i64 %70, 2
  br i1 %.not292, label %select.unfold257, label %scalar.ph.3, !llvm.loop !12

scalar.ph.3:                                      ; preds = %scalar.ph.2
  %71 = or i64 %.ph290, 3
  %72 = add i64 %46, %71
  %73 = getelementptr i32, ptr %.unpack245, i64 %72
  %74 = load i32, ptr %73, align 4, !tbaa !3
  %75 = add i32 %74, 1
  store i32 %75, ptr %73, align 4, !tbaa !3
  %76 = add nsw i64 %.ph, -5
  %77 = icmp ult i64 %76, -2
  br i1 %77, label %scalar.ph.4, label %select.unfold257, !llvm.loop !12

scalar.ph.4:                                      ; preds = %scalar.ph.3
  %78 = or i64 %.ph290, 4
  %79 = add i64 %46, %78
  %80 = getelementptr i32, ptr %.unpack245, i64 %79
  %81 = load i32, ptr %80, align 4, !tbaa !3
  %82 = add i32 %81, 1
  store i32 %82, ptr %80, align 4, !tbaa !3
  %83 = and i64 %.ph, 6
  %.not293 = icmp eq i64 %83, 4
  br i1 %.not293, label %select.unfold257, label %scalar.ph.5, !llvm.loop !12

scalar.ph.5:                                      ; preds = %scalar.ph.4
  %84 = or i64 %.ph290, 5
  %85 = add i64 %46, %84
  %86 = getelementptr i32, ptr %.unpack245, i64 %85
  %87 = load i32, ptr %86, align 4, !tbaa !3
  %88 = add i32 %87, 1
  store i32 %88, ptr %86, align 4, !tbaa !3
  %89 = add nsw i64 %.ph, -7
  %90 = icmp ult i64 %89, -2
  br i1 %90, label %scalar.ph.6, label %select.unfold257, !llvm.loop !12

scalar.ph.6:                                      ; preds = %scalar.ph.5
  %91 = or i64 %.ph290, 6
  %92 = add i64 %46, %91
  %93 = getelementptr i32, ptr %.unpack245, i64 %92
  %94 = load i32, ptr %93, align 4, !tbaa !3
  %95 = add i32 %94, 1
  store i32 %95, ptr %93, align 4, !tbaa !3
  br label %select.unfold257

select.unfold257:                                 ; preds = %scalar.ph, %scalar.ph.1, %scalar.ph.2, %scalar.ph.3, %scalar.ph.4, %scalar.ph.5, %scalar.ph.6, %middle.block, %43, %.lr.ph263
  %exitcond.not = icmp eq i64 %indvars.iv, %spec.select258
  br i1 %exitcond.not, label %select.unfold257._crit_edge.loopexit, label %.lr.ph263

select.unfold257._crit_edge.loopexit:             ; preds = %select.unfold257
  %.pre = load i32, ptr %3, align 4, !tbaa !3
  br label %select.unfold257._crit_edge

select.unfold257._crit_edge:                      ; preds = %select.unfold257._crit_edge.loopexit, %32
  %96 = phi i32 [ %.pre, %select.unfold257._crit_edge.loopexit ], [ %17, %32 ]
  %97 = sext i32 %96 to i64
  %98 = icmp sgt i32 %96, 0
  br i1 %98, label %.lr.ph264, label %._crit_edge267

.lr.ph264:                                        ; preds = %select.unfold257._crit_edge, %.lr.ph264
  %indvars.iv273 = phi i64 [ %indvars.iv.next274, %.lr.ph264 ], [ 1, %select.unfold257._crit_edge ]
  %99 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.8d4cded5c1cf70bdbdc1e356f6df5759, i32 21)
  %100 = call i1 @_FortranAioInputInteger(ptr %99, ptr nonnull %1, i32 4)
  %101 = call i1 @_FortranAioInputInteger(ptr %99, ptr nonnull %4, i32 4)
  %102 = call i32 @_FortranAioEndIoStatement(ptr %99)
  %.unpack221 = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  %103 = load i32, ptr %4, align 4, !tbaa !3
  %104 = sext i32 %103 to i64
  %105 = add nsw i64 %104, -1
  %106 = getelementptr i32, ptr %.unpack221, i64 %105
  %107 = load i32, ptr %106, align 4, !tbaa !3
  %108 = load i32, ptr %1, align 4, !tbaa !3
  %109 = sext i32 %108 to i64
  %110 = add nsw i64 %109, -1
  %111 = getelementptr i32, ptr %.unpack221, i64 %110
  %112 = load i32, ptr %111, align 4, !tbaa !3
  %113 = sub i32 %107, %112
  %.unpack233 = load ptr, ptr @_QFEans.0, align 8, !tbaa !7
  %114 = add nsw i64 %indvars.iv273, -1
  %115 = getelementptr i32, ptr %.unpack233, i64 %114
  store i32 %113, ptr %115, align 4, !tbaa !3
  %indvars.iv.next274 = add nuw nsw i64 %indvars.iv273, 1
  %exitcond276.not = icmp eq i64 %indvars.iv273, %97
  br i1 %exitcond276.not, label %._crit_edge, label %.lr.ph264

._crit_edge:                                      ; preds = %.lr.ph264
  %.pre281 = load i32, ptr %3, align 4, !tbaa !3
  %.pre282 = sext i32 %.pre281 to i64
  %116 = icmp sgt i32 %.pre281, 0
  br i1 %116, label %.lr.ph266, label %._crit_edge267

.lr.ph266:                                        ; preds = %._crit_edge, %.lr.ph266
  %indvars.iv277 = phi i64 [ %indvars.iv.next278, %.lr.ph266 ], [ 1, %._crit_edge ]
  %117 = call ptr @_FortranAioBeginExternalFormattedOutput(ptr nonnull @_QQcl.28693029, i64 4, ptr null, i32 -1, ptr nonnull @_QQcl.8d4cded5c1cf70bdbdc1e356f6df5759, i32 26)
  %.unpack209 = load ptr, ptr @_QFEans.0, align 8, !tbaa !7
  %118 = add nsw i64 %indvars.iv277, -1
  %119 = getelementptr i32, ptr %.unpack209, i64 %118
  %120 = load i32, ptr %119, align 4, !tbaa !3
  %121 = call i1 @_FortranAioOutputInteger32(ptr %117, i32 %120)
  %122 = call i32 @_FortranAioEndIoStatement(ptr %117)
  %indvars.iv.next278 = add nuw nsw i64 %indvars.iv277, 1
  %exitcond280.not = icmp eq i64 %indvars.iv277, %.pre282
  br i1 %exitcond280.not, label %._crit_edge267, label %.lr.ph266

._crit_edge267:                                   ; preds = %.lr.ph266, %select.unfold257._crit_edge, %._crit_edge
  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 i32 @_FortranACharacterCompareScalar1(ptr, ptr, i64, i64) local_unnamed_addr

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

declare i1 @_FortranAioOutputInteger32(ptr, i32) 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 nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #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, !11}
!10 = !{!"llvm.loop.isvectorized", i32 1}
!11 = !{!"llvm.loop.unroll.runtime.disable"}
!12 = distinct !{!12, !11, !10}
