program prob5
    implicit none
    integer(8) i, L, m, change, up, down, j, ans
    integer(8), allocatable::s(:)
    character(len=5*10**5) N
    read(*,*) N
    L = len_trim(N)
    allocate(s(L+1))
    s = 0
    change = 0
    up = 0
    down = 0
    ans = 0

    do i = 1, L
        if(N(i:i) .eq. ">")then
            down = down + 1
            ans = ans + down
            s(i+1) = 0
            if((N(i+1:i+1) .eq. "<") .or. i == L)then
                if(s(i - down + 1) >= down)then
                    ans = ans - down
                else
                    ans = ans - up
                end if
                up = 0
            end if
        else
            up = up + 1
            ans = ans + up
            s(i+1) = s(i) + 1
            if(N(i+1:i+1) .eq. ">")then
                down = 0
            end if
        end if

    end do
    write(*,*) ans

    deallocate(s)

    stop
end program prob5
; 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"

@_QFEn = internal global [500000 x i8] undef
@_QFEs.0 = internal unnamed_addr global ptr null
@_QFEs.7 = internal unnamed_addr global i64 1
@_QQcl.0f1098a85ee4d6b14d4c583a27150d46 = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_3031/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.3E = linkonce constant [1 x i8] c">"
@_QQcl.3C = linkonce constant [1 x i8] c"<"
@_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

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #1

; Function Attrs: noreturn
define void @_QQmain() local_unnamed_addr #2 {
  %1 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.0f1098a85ee4d6b14d4c583a27150d46, i32 6)
  %2 = tail call i1 @_FortranAioInputAscii(ptr %1, ptr nonnull @_QFEn, i64 500000)
  %3 = tail call i32 @_FortranAioEndIoStatement(ptr %1)
  br label %4

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

12:                                               ; preds = %4
  %13 = shl i64 %5, 32
  %sext = add i64 %13, 4294967296
  %14 = ashr exact i64 %sext, 32
  %15 = select i1 %8, i64 0, i64 %14
  %16 = tail call i64 @llvm.smax.i64(i64 %15, i64 -1)
  %17 = add nsw i64 %16, 1
  %18 = shl nuw nsw i64 %17, 3
  %19 = tail call ptr @malloc(i64 %18)
  store ptr %19, ptr @_QFEs.0, align 8, !tbaa !7
  store i64 1, ptr @_QFEs.7, align 8, !tbaa !7
  %.not = icmp eq ptr %19, null
  br i1 %.not, label %24, label %.preheader

.preheader:                                       ; preds = %12
  %20 = icmp sgt i64 %15, -1
  br i1 %20, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %.preheader
  %21 = add nsw i64 %16, 2
  %smin = tail call i64 @llvm.smin.i64(i64 %17, i64 1)
  %22 = sub nuw nsw i64 %21, %smin
  %23 = shl nuw nsw i64 %22, 3
  tail call void @llvm.memset.p0.i64(ptr nonnull align 8 %19, i8 0, i64 %23, i1 false), !tbaa !3
  br label %.loopexit

24:                                               ; preds = %12
  %25 = tail call {} @_FortranAReportFatalUserError(ptr nonnull @_QQcl.16373402fa3425c6e46827601abb88fa, ptr nonnull @_QQcl.0f1098a85ee4d6b14d4c583a27150d46, i32 9)
  %.unpack291.unpack.unpack = load i64, ptr @_QFEs.7, align 8, !tbaa !7
  %26 = icmp eq i64 %17, 0
  %27 = select i1 %26, i64 1, i64 %.unpack291.unpack.unpack
  store ptr null, ptr @_QFEs.0, align 8, !tbaa !7
  store i64 %27, ptr @_QFEs.7, align 8, !tbaa !7
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph.preheader, %24
  %28 = icmp sgt i64 %15, 0
  br i1 %28, label %.lr.ph310.preheader, label %._crit_edge

.lr.ph310.preheader:                              ; preds = %.loopexit
  %29 = add nuw nsw i64 %15, 1
  br label %.lr.ph310

.lr.ph310:                                        ; preds = %.lr.ph310.preheader, %65
  %30 = phi i64 [ %.pre-phi, %65 ], [ 1, %.lr.ph310.preheader ]
  %.0309 = phi i64 [ %.1, %65 ], [ 0, %.lr.ph310.preheader ]
  %.0220308 = phi i64 [ %.2, %65 ], [ 0, %.lr.ph310.preheader ]
  %.0222307 = phi i64 [ %.1223, %65 ], [ 0, %.lr.ph310.preheader ]
  %31 = add nsw i64 %30, -1
  %32 = getelementptr [500000 x [1 x i8]], ptr @_QFEn, i64 0, i64 %31
  %33 = tail call i32 @_FortranACharacterCompareScalar1(ptr %32, ptr nonnull @_QQcl.3E, i64 1, i64 1)
  %34 = icmp eq i32 %33, 0
  %.unpack259 = load ptr, ptr @_QFEs.0, align 8, !tbaa !7
  %.unpack266.unpack.unpack = load i64, ptr @_QFEs.7, align 8, !tbaa !7
  br i1 %34, label %35, label %52

35:                                               ; preds = %.lr.ph310
  %36 = add i64 %.0222307, 1
  %37 = add i64 %.0220308, %36
  %38 = add nuw nsw i64 %30, 1
  %39 = sub i64 %38, %.unpack266.unpack.unpack
  %40 = getelementptr i64, ptr %.unpack259, i64 %39
  store i64 0, ptr %40, align 8, !tbaa !3
  %41 = getelementptr [500000 x [1 x i8]], ptr @_QFEn, i64 0, i64 %30
  %42 = tail call i32 @_FortranACharacterCompareScalar1(ptr %41, ptr nonnull @_QQcl.3C, i64 1, i64 1)
  %43 = icmp eq i32 %42, 0
  %44 = icmp eq i64 %30, %15
  %45 = or i1 %44, %43
  br i1 %45, label %46, label %65

46:                                               ; preds = %35
  %.unpack271 = load ptr, ptr @_QFEs.0, align 8, !tbaa !7
  %.unpack278.unpack.unpack = load i64, ptr @_QFEs.7, align 8, !tbaa !7
  %47 = add i64 %.0222307, %.unpack278.unpack.unpack
  %48 = sub i64 %30, %47
  %49 = getelementptr i64, ptr %.unpack271, i64 %48
  %50 = load i64, ptr %49, align 8, !tbaa !3
  %.not283 = icmp slt i64 %50, %36
  %51 = sub i64 %37, %.0309
  %.1221 = select i1 %.not283, i64 %51, i64 %.0220308
  br label %65

52:                                               ; preds = %.lr.ph310
  %53 = add i64 %.0309, 1
  %54 = add i64 %53, %.0220308
  %55 = sub i64 %30, %.unpack266.unpack.unpack
  %56 = getelementptr i64, ptr %.unpack259, i64 %55
  %57 = load i64, ptr %56, align 8, !tbaa !3
  %58 = add i64 %57, 1
  %59 = add nuw nsw i64 %30, 1
  %60 = sub i64 %59, %.unpack266.unpack.unpack
  %61 = getelementptr i64, ptr %.unpack259, i64 %60
  store i64 %58, ptr %61, align 8, !tbaa !3
  %62 = getelementptr [500000 x [1 x i8]], ptr @_QFEn, i64 0, i64 %30
  %63 = tail call i32 @_FortranACharacterCompareScalar1(ptr %62, ptr nonnull @_QQcl.3E, i64 1, i64 1)
  %64 = icmp eq i32 %63, 0
  %spec.select = select i1 %64, i64 0, i64 %.0222307
  br label %65

65:                                               ; preds = %52, %46, %35
  %.pre-phi = phi i64 [ %59, %52 ], [ %38, %46 ], [ %38, %35 ]
  %.1223 = phi i64 [ %spec.select, %52 ], [ %36, %46 ], [ %36, %35 ]
  %.2 = phi i64 [ %54, %52 ], [ %.1221, %46 ], [ %37, %35 ]
  %.1 = phi i64 [ %53, %52 ], [ 0, %46 ], [ %.0309, %35 ]
  %exitcond.not = icmp eq i64 %.pre-phi, %29
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph310

._crit_edge:                                      ; preds = %65, %.preheader, %.loopexit
  %.0220.lcssa = phi i64 [ 0, %.loopexit ], [ 0, %.preheader ], [ %.2, %65 ]
  %66 = tail call ptr @_FortranAioBeginExternalListOutput(i32 -1, ptr nonnull @_QQcl.0f1098a85ee4d6b14d4c583a27150d46, i32 38)
  %67 = tail call i1 @_FortranAioOutputInteger64(ptr %66, i64 %.0220.lcssa)
  %68 = tail call i32 @_FortranAioEndIoStatement(ptr %66)
  %.unpack = load ptr, ptr @_QFEs.0, align 8, !tbaa !7
  tail call void @free(ptr %.unpack)
  store ptr null, ptr @_QFEs.0, align 8, !tbaa !7
  store i64 1, ptr @_QFEs.7, align 8, !tbaa !7
  %69 = tail call {} @_FortranAStopStatement(i32 0, i1 false, i1 false)
  unreachable
}

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 {} @_FortranAReportFatalUserError(ptr, ptr, i32) local_unnamed_addr

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

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

declare i1 @_FortranAioOutputInteger64(ptr, i64) local_unnamed_addr

declare {} @_FortranAStopStatement(i32, i1, i1) local_unnamed_addr

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

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

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

attributes #0 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" }
attributes #1 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" }
attributes #2 = { noreturn }
attributes #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { 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}
