program A819B
    implicit none
    integer(8)::i,j,ans,Nlen,calc
    character(17)::N
    integer(8),allocatable,dimension(:)::A
    read*,N
    Nlen=len_trim(N)
    ans=0
    allocate(A(Nlen))
    do i=1,Nlen
        A(i)=ichar(N(i:i))-48
        ans=ans+A(i)
    end do

    do i=1,Nlen
        calc=0
        do j=1,Nlen
            if(j<i)calc=calc+A(j)
            if(j==i)calc=calc+A(j)-1
            if(j>i)calc=calc+9
        end do
        ans=max(ans,calc)
    end do

    print'(i0)',ans
end program A819B
; 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 = internal unnamed_addr global { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] } { ptr null, i64 ptrtoint (ptr getelementptr (i64, ptr null, i32 1) to i64), i32 20180515, i8 1, i8 10, i8 2, i8 0, [1 x [3 x i64]] [[3 x i64] [i64 1, i64 0, i64 ptrtoint (ptr getelementptr (i64, ptr null, i32 1) to i64)]] }
@_QQcl.ab7741aa5cf44a6a155f6f23bdb46361 = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_6228/source.f\00"
@_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 [17 x i8], align 1
  %2 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.ab7741aa5cf44a6a155f6f23bdb46361, i32 6)
  %3 = call i1 @_FortranAioInputAscii(ptr %2, ptr nonnull %1, i64 17)
  %4 = call i32 @_FortranAioEndIoStatement(ptr %2)
  br label %5

5:                                                ; preds = %0, %5
  %6 = phi i64 [ 16, %0 ], [ %10, %5 ]
  %7 = getelementptr [17 x [1 x i8]], ptr %1, i64 0, i64 %6
  %8 = load i8, ptr %7, align 1, !tbaa !3
  %9 = icmp eq i8 %8, 32
  %10 = add nsw i64 %6, -1
  %11 = icmp ne i64 %6, 0
  %12 = and i1 %9, %11
  br i1 %12, label %5, label %13

13:                                               ; preds = %5
  %14 = shl i64 %6, 32
  %sext = add i64 %14, 4294967296
  %15 = ashr exact i64 %sext, 32
  %16 = select i1 %9, i64 0, i64 %15
  %17 = call i64 @llvm.smax.i64(i64 %16, i64 0)
  %18 = shl nuw nsw i64 %17, 3
  %19 = call ptr @malloc(i64 %18)
  store ptr %19, ptr @_QFEa, align 16, !tbaa !7
  store i64 8, ptr getelementptr inbounds ({ ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr @_QFEa, i64 0, i32 1), align 8, !tbaa !7
  store i32 20180515, ptr getelementptr inbounds ({ ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr @_QFEa, i64 0, i32 2), align 16, !tbaa !7
  store i8 1, ptr getelementptr inbounds ({ ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr @_QFEa, i64 0, i32 3), align 4, !tbaa !7
  store i8 10, ptr getelementptr inbounds ({ ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr @_QFEa, i64 0, i32 4), align 1, !tbaa !7
  store i8 2, ptr getelementptr inbounds ({ ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr @_QFEa, i64 0, i32 5), align 2, !tbaa !7
  store i8 0, ptr getelementptr inbounds ({ ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr @_QFEa, i64 0, i32 6), align 1, !tbaa !7
  store i64 1, ptr getelementptr inbounds ({ ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr @_QFEa, i64 0, i32 7), align 8, !tbaa !7
  store i64 %17, ptr getelementptr inbounds ({ ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr @_QFEa, i64 0, i32 7, i64 0, i64 1), align 16, !tbaa !7
  store i64 8, ptr getelementptr inbounds ({ ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr @_QFEa, i64 0, i32 7, i64 0, i64 2), align 8, !tbaa !7
  %20 = icmp sgt i64 %16, 0
  br i1 %20, label %.lr.ph.preheader, label %._crit_edge189

.lr.ph.preheader:                                 ; preds = %13
  %min.iters.check = icmp ult i64 %16, 4
  br i1 %min.iters.check, label %.lr.ph.preheader205, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph.preheader
  %n.vec = and i64 %16, -4
  %ind.end = or i64 %n.vec, 1
  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> [ zeroinitializer, %vector.ph ], [ %29, %vector.body ]
  %vec.phi203 = phi <2 x i64> [ zeroinitializer, %vector.ph ], [ %30, %vector.body ]
  %21 = getelementptr [17 x [1 x i8]], ptr %1, i64 0, i64 %index
  %wide.load = load <2 x i8>, ptr %21, align 1, !tbaa !3
  %22 = getelementptr i8, ptr %21, i64 2
  %wide.load204 = load <2 x i8>, ptr %22, align 1, !tbaa !3
  %23 = zext <2 x i8> %wide.load to <2 x i64>
  %24 = zext <2 x i8> %wide.load204 to <2 x i64>
  %25 = add nsw <2 x i64> %23, <i64 -48, i64 -48>
  %26 = add nsw <2 x i64> %24, <i64 -48, i64 -48>
  %27 = getelementptr i64, ptr %19, i64 %index
  store <2 x i64> %25, ptr %27, align 8, !tbaa !3
  %28 = getelementptr i64, ptr %27, i64 2
  store <2 x i64> %26, ptr %28, align 8, !tbaa !3
  %29 = add <2 x i64> %25, %vec.phi
  %30 = add <2 x i64> %26, %vec.phi203
  %index.next = add nuw i64 %index, 4
  %31 = icmp eq i64 %index.next, %n.vec
  br i1 %31, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %vector.body
  %bin.rdx = add <2 x i64> %30, %29
  %32 = call i64 @llvm.vector.reduce.add.v2i64(<2 x i64> %bin.rdx)
  %cmp.n = icmp eq i64 %16, %n.vec
  br i1 %cmp.n, label %.preheader182, label %.lr.ph.preheader205

.lr.ph.preheader205:                              ; preds = %.lr.ph.preheader, %middle.block
  %.ph = phi i64 [ 1, %.lr.ph.preheader ], [ %ind.end, %middle.block ]
  %.0184.ph = phi i64 [ 0, %.lr.ph.preheader ], [ %32, %middle.block ]
  br label %.lr.ph

.preheader182:                                    ; preds = %.lr.ph, %middle.block
  %.lcssa200 = phi i64 [ %32, %middle.block ], [ %62, %.lr.ph ]
  br i1 %20, label %.preheader.us, label %._crit_edge189

.preheader.us:                                    ; preds = %.preheader182, %._crit_edge.us
  %33 = phi i64 [ %55, %._crit_edge.us ], [ 1, %.preheader182 ]
  %.1188.us = phi i64 [ %54, %._crit_edge.us ], [ %.lcssa200, %.preheader182 ]
  %34 = add nsw i64 %33, -1
  %35 = getelementptr i64, ptr %19, i64 %34
  br label %36

36:                                               ; preds = %.preheader.us, %50
  %37 = phi i64 [ 1, %.preheader.us ], [ %53, %50 ]
  %.0118185.us = phi i64 [ 0, %.preheader.us ], [ %spec.select.us, %50 ]
  %38 = icmp ult i64 %37, %33
  br i1 %38, label %39, label %44

39:                                               ; preds = %36
  %40 = add nsw i64 %37, -1
  %41 = getelementptr i64, ptr %19, i64 %40
  %42 = load i64, ptr %41, align 8, !tbaa !3
  %43 = add i64 %42, %.0118185.us
  br label %44

44:                                               ; preds = %39, %36
  %.1119.us = phi i64 [ %43, %39 ], [ %.0118185.us, %36 ]
  %45 = icmp eq i64 %37, %33
  br i1 %45, label %46, label %50

46:                                               ; preds = %44
  %47 = load i64, ptr %35, align 8, !tbaa !3
  %48 = add i64 %.1119.us, -1
  %49 = add i64 %48, %47
  br label %50

50:                                               ; preds = %46, %44
  %.2.us = phi i64 [ %49, %46 ], [ %.1119.us, %44 ]
  %51 = icmp ugt i64 %37, %33
  %52 = add i64 %.2.us, 9
  %spec.select.us = select i1 %51, i64 %52, i64 %.2.us
  %53 = add nuw nsw i64 %37, 1
  %exitcond194.not = icmp eq i64 %37, %16
  br i1 %exitcond194.not, label %._crit_edge.us, label %36

._crit_edge.us:                                   ; preds = %50
  %54 = call i64 @llvm.smax.i64(i64 %.1188.us, i64 %spec.select.us)
  %55 = add nuw nsw i64 %33, 1
  %exitcond195.not = icmp eq i64 %33, %16
  br i1 %exitcond195.not, label %._crit_edge189, label %.preheader.us

.lr.ph:                                           ; preds = %.lr.ph.preheader205, %.lr.ph
  %56 = phi i64 [ %63, %.lr.ph ], [ %.ph, %.lr.ph.preheader205 ]
  %.0184 = phi i64 [ %62, %.lr.ph ], [ %.0184.ph, %.lr.ph.preheader205 ]
  %57 = add nsw i64 %56, -1
  %58 = getelementptr [17 x [1 x i8]], ptr %1, i64 0, i64 %57
  %.fca.0.load = load i8, ptr %58, align 1, !tbaa !3
  %59 = zext i8 %.fca.0.load to i64
  %60 = add nsw i64 %59, -48
  %61 = getelementptr i64, ptr %19, i64 %57
  store i64 %60, ptr %61, align 8, !tbaa !3
  %62 = add i64 %60, %.0184
  %63 = add nuw nsw i64 %56, 1
  %exitcond.not = icmp eq i64 %56, %16
  br i1 %exitcond.not, label %.preheader182, label %.lr.ph, !llvm.loop !12

._crit_edge189:                                   ; preds = %._crit_edge.us, %13, %.preheader182
  %.1.lcssa = phi i64 [ %.lcssa200, %.preheader182 ], [ 0, %13 ], [ %54, %._crit_edge.us ]
  %64 = call ptr @_FortranAioBeginExternalFormattedOutput(ptr nonnull @_QQcl.28693029, i64 4, ptr null, i32 -1, ptr nonnull @_QQcl.ab7741aa5cf44a6a155f6f23bdb46361, i32 25)
  %65 = call i1 @_FortranAioOutputInteger64(ptr %64, i64 %.1.lcssa)
  %66 = call i32 @_FortranAioEndIoStatement(ptr %64)
  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 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 nosync nounwind willreturn memory(none)
declare i64 @llvm.vector.reduce.add.v2i64(<2 x i64>) #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 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}
