#import <stdio.h>

int main(){
    char a[20] = {'\0'};
    int N=0;
    char c = getchar();
    while(c>='0' && c<='9'){
        a[N]=c;
        N++;
        c = getchar();
    }
    for(int i=0;i<N;i++){
        if (a[i] == '9') {
            continue;
        } else if (a[i] == '0' || i>0) {
            a[i-1]--;
            for (int j=i;j<N;j++){
                a[j] = '9';
            }
        } else if (i<N-1) {
            int nineOnly = 1;
            for(int j=i+1;j<N;j++){
                if(a[j] !=
                   '9'){
                    nineOnly = 0;
                    a[j] = '9';
                }
            }
            if(!nineOnly){
                a[i]--;
            }
        } else if (N>1) {
            a[i] = '9';
            a[i-1]--;
        }
    }
    int sum = 0;
    for(int i=0;i<N;i++){
        sum += a[i] - '0';
    }
    printf("%d", sum);
}

; ModuleID = '/data/TheStack_IR/OJ_Samples/Collated/ObjectiveC/Source_591/source.m'
source_filename = "/data/TheStack_IR/OJ_Samples/Collated/ObjectiveC/Source_591/source.m"
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"

@.str = private unnamed_addr constant [3 x i8] c"%d\00", align 1

; Function Attrs: minsize nofree nounwind optsize uwtable
define dso_local i32 @main() local_unnamed_addr #0 {
entry:
  %a = alloca [20 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 20, ptr nonnull %a) #4
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(20) %a, i8 0, i64 20, i1 false)
  %call = tail call i32 @getchar() #5
  br label %while.cond

while.cond:                                       ; preds = %while.body, %entry
  %indvars.iv131 = phi i32 [ %indvars.iv.next132, %while.body ], [ 0, %entry ]
  %indvars.iv124 = phi i32 [ %indvars.iv.next125, %while.body ], [ -1, %entry ]
  %indvars.iv = phi i64 [ %indvars.iv.next, %while.body ], [ 0, %entry ]
  %c.0.in = phi i32 [ %call6, %while.body ], [ %call, %entry ]
  %sext = shl i32 %c.0.in, 24
  %0 = add i32 %sext, -788529153
  %1 = icmp ult i32 %0, 184549375
  br i1 %1, label %while.body, label %for.cond.preheader

for.cond.preheader:                               ; preds = %while.cond
  %2 = and i64 %indvars.iv, 4294967294
  %cmp61.not = icmp eq i64 %2, 0
  %arrayidx68 = getelementptr inbounds [20 x i8], ptr %a, i64 0, i64 -1
  %sub34 = shl i64 %indvars.iv, 32
  %sext146 = add i64 %sub34, -4294967296
  %wide.trip.count138 = zext i32 %indvars.iv131 to i64
  %cmp35 = icmp sgt i64 %sext146, 0
  %wide.trip.count = zext i32 %indvars.iv124 to i64
  br label %for.cond

while.body:                                       ; preds = %while.cond
  %c.0 = trunc i32 %c.0.in to i8
  %arrayidx = getelementptr inbounds [20 x i8], ptr %a, i64 0, i64 %indvars.iv
  store i8 %c.0, ptr %arrayidx, align 1, !tbaa !5
  %indvars.iv.next = add nuw i64 %indvars.iv, 1
  %call6 = tail call i32 @getchar() #5
  %indvars.iv.next125 = add nsw i32 %indvars.iv124, 1
  %indvars.iv.next132 = add nuw i32 %indvars.iv131, 1
  br label %while.cond

for.cond:                                         ; preds = %for.cond.preheader, %for.inc74
  %indvars.iv126 = phi i64 [ 0, %for.cond.preheader ], [ %indvars.iv.next127, %for.inc74 ]
  %exitcond139.not = icmp eq i64 %indvars.iv126, %wide.trip.count138
  br i1 %exitcond139.not, label %for.cond78, label %for.body

for.body:                                         ; preds = %for.cond
  %arrayidx11 = getelementptr inbounds [20 x i8], ptr %a, i64 0, i64 %indvars.iv126
  %3 = load i8, ptr %arrayidx11, align 1, !tbaa !5
  %cmp13 = icmp eq i8 %3, 57
  br i1 %cmp13, label %for.inc74, label %if.else

if.else:                                          ; preds = %for.body
  %cmp18 = icmp eq i8 %3, 48
  %cmp20 = icmp ne i64 %indvars.iv126, 0
  %or.cond = or i1 %cmp20, %cmp18
  br i1 %or.cond, label %if.then22, label %if.else33

if.then22:                                        ; preds = %if.else
  %4 = add nsw i64 %indvars.iv126, -1
  %arrayidx24 = getelementptr inbounds [20 x i8], ptr %a, i64 0, i64 %4
  %5 = load i8, ptr %arrayidx24, align 1, !tbaa !5
  %dec = add i8 %5, -1
  store i8 %dec, ptr %arrayidx24, align 1, !tbaa !5
  br label %for.cond25

for.cond25:                                       ; preds = %for.body29, %if.then22
  %indvars.iv128 = phi i64 [ %indvars.iv.next129, %for.body29 ], [ %indvars.iv126, %if.then22 ]
  %exitcond134.not = icmp eq i64 %indvars.iv128, %wide.trip.count138
  br i1 %exitcond134.not, label %for.inc74, label %for.body29

for.body29:                                       ; preds = %for.cond25
  %arrayidx31 = getelementptr inbounds [20 x i8], ptr %a, i64 0, i64 %indvars.iv128
  store i8 57, ptr %arrayidx31, align 1, !tbaa !5
  %indvars.iv.next129 = add nuw nsw i64 %indvars.iv128, 1
  br label %for.cond25

if.else33:                                        ; preds = %if.else
  br i1 %cmp35, label %for.cond39, label %if.else60

for.cond39:                                       ; preds = %if.else33, %for.body43
  %indvars.iv121 = phi i64 [ %indvars.iv.next122, %for.body43 ], [ 0, %if.else33 ]
  %nineOnly.0 = phi i32 [ %spec.select, %for.body43 ], [ 1, %if.else33 ]
  %exitcond.not = icmp eq i64 %indvars.iv121, %wide.trip.count
  br i1 %exitcond.not, label %for.cond.cleanup42, label %for.body43

for.cond.cleanup42:                               ; preds = %for.cond39
  %tobool.not = icmp eq i32 %nineOnly.0, 0
  br i1 %tobool.not, label %for.inc74.sink.split, label %for.inc74

for.body43:                                       ; preds = %for.cond39
  %indvars.iv.next122 = add nuw nsw i64 %indvars.iv121, 1
  %arrayidx45 = getelementptr inbounds [20 x i8], ptr %a, i64 0, i64 %indvars.iv.next122
  %6 = load i8, ptr %arrayidx45, align 1, !tbaa !5
  %cmp47.not = icmp eq i8 %6, 57
  store i8 57, ptr %arrayidx45, align 1
  %spec.select = select i1 %cmp47.not, i32 %nineOnly.0, i32 0
  br label %for.cond39

if.else60:                                        ; preds = %if.else33
  br i1 %cmp61.not, label %for.inc74, label %if.then63

if.then63:                                        ; preds = %if.else60
  store i8 57, ptr %arrayidx11, align 1, !tbaa !5
  br label %for.inc74.sink.split

for.inc74.sink.split:                             ; preds = %for.cond.cleanup42, %if.then63
  %arrayidx11.sink147 = phi ptr [ %arrayidx68, %if.then63 ], [ %arrayidx11, %for.cond.cleanup42 ]
  %7 = load i8, ptr %arrayidx11.sink147, align 1, !tbaa !5
  %dec58 = add i8 %7, -1
  store i8 %dec58, ptr %arrayidx11.sink147, align 1, !tbaa !5
  br label %for.inc74

for.inc74:                                        ; preds = %for.cond25, %for.inc74.sink.split, %for.cond.cleanup42, %if.else60, %for.body
  %indvars.iv.next127 = add nuw nsw i64 %indvars.iv126, 1
  br label %for.cond

for.cond78:                                       ; preds = %for.cond, %for.body82
  %indvars.iv140 = phi i64 [ %indvars.iv.next141, %for.body82 ], [ 0, %for.cond ]
  %sum.0 = phi i32 [ %add87, %for.body82 ], [ 0, %for.cond ]
  %exitcond145.not = icmp eq i64 %indvars.iv140, %wide.trip.count138
  br i1 %exitcond145.not, label %for.cond.cleanup81, label %for.body82

for.cond.cleanup81:                               ; preds = %for.cond78
  %call91 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %sum.0) #5
  call void @llvm.lifetime.end.p0(i64 20, ptr nonnull %a) #4
  ret i32 0

for.body82:                                       ; preds = %for.cond78
  %arrayidx84 = getelementptr inbounds [20 x i8], ptr %a, i64 0, i64 %indvars.iv140
  %8 = load i8, ptr %arrayidx84, align 1, !tbaa !5
  %conv85 = sext i8 %8 to i32
  %sub86 = add i32 %sum.0, -48
  %add87 = add i32 %sub86, %conv85
  %indvars.iv.next141 = add nuw nsw i64 %indvars.iv140, 1
  br label %for.cond78
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

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

; Function Attrs: minsize nofree nounwind optsize
declare noundef i32 @getchar() local_unnamed_addr #3

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: minsize nofree nounwind optsize
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #3

attributes #0 = { minsize nofree nounwind optsize uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { minsize nofree nounwind optsize "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #4 = { nounwind }
attributes #5 = { minsize optsize }

!llvm.linker.options = !{}
!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"Ubuntu clang version 18.0.0 (++20231007042255+8abb2ace888b-1~exp1~20231007042414.1230)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
