integer N
character(5000) S
integer maxlen
integer ans,preans
read*,N
read*,S
ans=0
do i=1,N-1
  do j=i+1,N
    if(S(i:i)==S(j:j))then
      maxlen=min(N-j+1,j-i)
      if(maxlen<=ans)cycle
      preans=1
      do ii=1,maxlen-1
        if(S(i+ii:i+ii)/=S(j+ii:j+ii))exit
        preans=preans+1
      end do
      ans=max(ans,preans)
    endif
  end do
end do
print"(I0)",ans
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"

@_QFEs = internal global [5000 x i8] undef
@_QQcl.33f84ce28d17d6781df25c8e1711f9d3 = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_3266/source.f\00"
@_QQcl.28493029 = linkonce constant [4 x i8] c"(I0)"
@_QQEnvironmentDefaults = local_unnamed_addr constant ptr null

define void @_QQmain() local_unnamed_addr {
  %1 = alloca i32, align 4
  %2 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.33f84ce28d17d6781df25c8e1711f9d3, i32 5)
  %3 = call i1 @_FortranAioInputInteger(ptr %2, ptr nonnull %1, i32 4)
  %4 = call i32 @_FortranAioEndIoStatement(ptr %2)
  %5 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.33f84ce28d17d6781df25c8e1711f9d3, i32 6)
  %6 = call i1 @_FortranAioInputAscii(ptr %5, ptr nonnull @_QFEs, i64 5000)
  %7 = call i32 @_FortranAioEndIoStatement(ptr %5)
  %8 = load i32, ptr %1, align 4, !tbaa !3
  %.02946 = add i32 %8, -1
  %9 = icmp sgt i32 %.02946, 0
  br i1 %9, label %.lr.ph51, label %._crit_edge52

.loopexit:                                        ; preds = %43, %.lr.ph51
  %.1.lcssa = phi i32 [ %.02847, %.lr.ph51 ], [ %.2, %43 ]
  %exitcond54.not = icmp eq i32 %10, %8
  br i1 %exitcond54.not, label %._crit_edge52, label %.lr.ph51

.lr.ph51:                                         ; preds = %0, %.loopexit
  %.02748 = phi i32 [ %10, %.loopexit ], [ 1, %0 ]
  %.02847 = phi i32 [ %.1.lcssa, %.loopexit ], [ 0, %0 ]
  %10 = add nuw i32 %.02748, 1
  %11 = load i32, ptr %1, align 4, !tbaa !3
  %12 = sub i32 %11, %.02748
  %13 = icmp sgt i32 %12, 0
  br i1 %13, label %.lr.ph44, label %.loopexit

.lr.ph44:                                         ; preds = %.lr.ph51
  %14 = sext i32 %.02748 to i64
  %15 = add nsw i64 %14, -1
  %16 = getelementptr [5000 x [1 x i8]], ptr @_QFEs, i64 0, i64 %15
  br label %17

17:                                               ; preds = %.lr.ph44, %43
  %.02541 = phi i32 [ %10, %.lr.ph44 ], [ %44, %43 ]
  %.140 = phi i32 [ %.02847, %.lr.ph44 ], [ %.2, %43 ]
  %18 = sext i32 %.02541 to i64
  %19 = add nsw i64 %18, -1
  %20 = getelementptr [5000 x [1 x i8]], ptr @_QFEs, i64 0, i64 %19
  %21 = call i32 @_FortranACharacterCompareScalar1(ptr %16, ptr %20, i64 1, i64 1)
  %22 = icmp eq i32 %21, 0
  br i1 %22, label %23, label %43

23:                                               ; preds = %17
  %24 = load i32, ptr %1, align 4, !tbaa !3
  %25 = sub i32 1, %.02541
  %26 = add i32 %25, %24
  %27 = sub i32 %.02541, %.02748
  %28 = call i32 @llvm.smin.i32(i32 %26, i32 %27)
  %.not = icmp sgt i32 %28, %.140
  br i1 %.not, label %.preheader, label %43

.preheader:                                       ; preds = %23
  %29 = icmp sgt i32 %28, 1
  br i1 %29, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %.preheader
  %.02433 = add nsw i32 %28, -1
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %39
  %.02436 = phi i32 [ %.024, %39 ], [ %.02433, %.lr.ph.preheader ]
  %.035 = phi i32 [ %40, %39 ], [ 1, %.lr.ph.preheader ]
  %30 = add i32 %.035, %.02748
  %31 = sext i32 %30 to i64
  %32 = add nsw i64 %31, -1
  %33 = getelementptr [5000 x [1 x i8]], ptr @_QFEs, i64 0, i64 %32
  %34 = add i32 %.035, %.02541
  %35 = sext i32 %34 to i64
  %36 = add nsw i64 %35, -1
  %37 = getelementptr [5000 x [1 x i8]], ptr @_QFEs, i64 0, i64 %36
  %38 = call i32 @_FortranACharacterCompareScalar1(ptr %33, ptr %37, i64 1, i64 1)
  %.not32 = icmp eq i32 %38, 0
  br i1 %.not32, label %39, label %._crit_edge

39:                                               ; preds = %.lr.ph
  %40 = add nuw i32 %.035, 1
  %.024 = add i32 %.02436, -1
  %41 = icmp sgt i32 %.024, 0
  br i1 %41, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %39, %.lr.ph, %.preheader
  %.0.lcssa = phi i32 [ 1, %.preheader ], [ %.035, %.lr.ph ], [ %40, %39 ]
  %42 = call i32 @llvm.smax.i32(i32 %.140, i32 %.0.lcssa)
  br label %43

43:                                               ; preds = %._crit_edge, %23, %17
  %.2 = phi i32 [ %.140, %23 ], [ %42, %._crit_edge ], [ %.140, %17 ]
  %44 = add i32 %.02541, 1
  %exitcond.not = icmp eq i32 %.02541, %11
  br i1 %exitcond.not, label %.loopexit, label %17

._crit_edge52:                                    ; preds = %.loopexit, %0
  %.028.lcssa = phi i32 [ 0, %0 ], [ %.1.lcssa, %.loopexit ]
  %45 = call ptr @_FortranAioBeginExternalFormattedOutput(ptr nonnull @_QQcl.28493029, i64 4, ptr null, i32 -1, ptr nonnull @_QQcl.33f84ce28d17d6781df25c8e1711f9d3, i32 22)
  %46 = call i1 @_FortranAioOutputInteger32(ptr %45, i32 %.028.lcssa)
  %47 = call i32 @_FortranAioEndIoStatement(ptr %45)
  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 i32 @llvm.smin.i32(i32, i32) #0

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

attributes #0 = { nocallback nofree nosync nounwind speculatable 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"}
