program main
  implicit none

  integer :: n, i, cnt
  integer(16) :: ans
  integer(16), allocatable :: a(:)

  read(*,*) n
  allocate(a(n))
  
  ans = 0
  cnt = 0
  read(*,*) a
  call quicksort(a, 1, n)
  do i = n, 2, -1
     if(a(i) == a(i-1)) then
        ans = a(i)
        cnt = i
        exit
     end if
  end do

  do i = cnt-2, 2, -1
     if(a(i) == a(i-1)) then
        ans = ans * a(i)
        exit
     end if
     if(i == 2) then
        ans = 0
     end if
     
  end do

  write(*,*) ans

  stop
  
contains
  recursive subroutine quicksort(a, first, last)
    implicit none
    integer(16) ::  a(*)
    integer :: first, last
    integer :: i, j
    integer ::  x, t
    
    x = a( (first+last) / 2 )
    i = first
    j = last
    do
       do while (a(i) < x)
          i=i+1
       end do
       do while (x < a(j))
          j=j-1
       end do
       if (i >= j) exit
       t = a(i);  a(i) = a(j);  a(j) = t
       i=i+1
       j=j-1
    end do
    if (first < i - 1) call quicksort(a, first, i - 1)
    if (j + 1 < last)  call quicksort(a, j + 1, last)
  end subroutine quicksort

end program main

  

; 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
@_QQcl.814fa9f113dffdb9ad8f41163304ef1d = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_7001/source.f\00"
@_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: noreturn
define void @_QQmain() local_unnamed_addr #1 {
  %1 = alloca { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, align 8
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.814fa9f113dffdb9ad8f41163304ef1d, i32 8)
  %5 = call i1 @_FortranAioInputInteger(ptr %4, ptr nonnull %3, i32 4)
  %6 = call i32 @_FortranAioEndIoStatement(ptr %4)
  %7 = load i32, ptr %3, align 4, !tbaa !3
  %8 = call i32 @llvm.smax.i32(i32 %7, i32 0)
  %9 = zext i32 %8 to i64
  %10 = shl nuw nsw i64 %9, 4
  %11 = call ptr @malloc(i64 %10)
  store ptr %11, ptr @_QFEa.0, align 8, !tbaa !7
  store i64 %9, ptr @_QFEa.8, align 8, !tbaa !7
  %12 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.814fa9f113dffdb9ad8f41163304ef1d, i32 13)
  %.unpack = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  %.unpack223.unpack.unpack225 = load i64, ptr @_QFEa.8, align 8, !tbaa !7
  store ptr %.unpack, ptr %1, align 8, !tbaa !7
  %.fca.1.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 1
  store i64 16, ptr %.fca.1.gep, align 8, !tbaa !7
  %.fca.2.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 2
  store i32 20180515, ptr %.fca.2.gep, align 8, !tbaa !7
  %.fca.3.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 3
  store i8 1, ptr %.fca.3.gep, align 4, !tbaa !7
  %.fca.4.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 4
  store i8 11, ptr %.fca.4.gep, align 1, !tbaa !7
  %.fca.5.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 5
  store i8 0, ptr %.fca.5.gep, align 2, !tbaa !7
  %.fca.6.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 6
  store i8 0, ptr %.fca.6.gep, align 1, !tbaa !7
  %.fca.7.0.0.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 7, i64 0, i64 0
  store i64 1, ptr %.fca.7.0.0.gep, align 8, !tbaa !7
  %.fca.7.0.1.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 7, i64 0, i64 1
  store i64 %.unpack223.unpack.unpack225, ptr %.fca.7.0.1.gep, align 8, !tbaa !7
  %.fca.7.0.2.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 7, i64 0, i64 2
  store i64 16, ptr %.fca.7.0.2.gep, align 8, !tbaa !7
  %13 = call i1 @_FortranAioInputDescriptor(ptr %12, ptr nonnull %1)
  %14 = call i32 @_FortranAioEndIoStatement(ptr %12)
  %.unpack228 = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  store i32 1, ptr %2, align 4, !tbaa !3
  call void @_QFPquicksort(ptr %.unpack228, ptr nonnull %2, ptr nonnull %3)
  %15 = load i32, ptr %3, align 4, !tbaa !3
  br label %16

16:                                               ; preds = %18, %0
  %.0204.in = phi i32 [ %15, %0 ], [ %.0204, %18 ]
  %.0204 = add i32 %.0204.in, -1
  %17 = icmp sgt i32 %.0204, 0
  br i1 %17, label %18, label %.loopexit

18:                                               ; preds = %16
  %19 = sext i32 %.0204.in to i64
  %20 = add nsw i64 %19, -1
  %21 = getelementptr i128, ptr %.unpack228, i64 %20
  %22 = load i128, ptr %21, align 8, !tbaa !3
  %23 = zext i32 %.0204 to i64
  %24 = add nsw i64 %23, -1
  %25 = getelementptr i128, ptr %.unpack228, i64 %24
  %26 = load i128, ptr %25, align 8, !tbaa !3
  %27 = icmp eq i128 %22, %26
  br i1 %27, label %28, label %16

28:                                               ; preds = %18
  %.neg240 = add i32 %.0204.in, -3
  %29 = icmp sgt i32 %.neg240, 0
  br i1 %29, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %28
  %30 = add i32 %.0204.in, -2
  br label %31

31:                                               ; preds = %.lr.ph, %44
  %.1268 = phi i32 [ %30, %.lr.ph ], [ %36, %44 ]
  %.1203267 = phi i128 [ %22, %.lr.ph ], [ %spec.select, %44 ]
  %.0205266 = phi i32 [ %.neg240, %.lr.ph ], [ %46, %44 ]
  %32 = sext i32 %.1268 to i64
  %33 = add nsw i64 %32, -1
  %34 = getelementptr i128, ptr %.unpack228, i64 %33
  %35 = load i128, ptr %34, align 8, !tbaa !3
  %36 = add i32 %.1268, -1
  %37 = sext i32 %36 to i64
  %38 = add nsw i64 %37, -1
  %39 = getelementptr i128, ptr %.unpack228, i64 %38
  %40 = load i128, ptr %39, align 8, !tbaa !3
  %41 = icmp eq i128 %35, %40
  br i1 %41, label %42, label %44

42:                                               ; preds = %31
  %43 = mul i128 %35, %.1203267
  br label %.loopexit

44:                                               ; preds = %31
  %45 = icmp eq i32 %.1268, 2
  %spec.select = select i1 %45, i128 0, i128 %.1203267
  %46 = add nsw i32 %.0205266, -1
  %47 = icmp sgt i32 %.0205266, 1
  br i1 %47, label %31, label %.loopexit

.loopexit:                                        ; preds = %16, %44, %28, %42
  %.3 = phi i128 [ %43, %42 ], [ %22, %28 ], [ %spec.select, %44 ], [ 0, %16 ]
  %48 = call ptr @_FortranAioBeginExternalListOutput(i32 -1, ptr nonnull @_QQcl.814fa9f113dffdb9ad8f41163304ef1d, i32 34)
  %49 = call i1 @_FortranAioOutputInteger128(ptr %48, i128 %.3)
  %50 = call i32 @_FortranAioEndIoStatement(ptr %48)
  %51 = call {} @_FortranAStopStatement(i32 0, i1 false, i1 false)
  unreachable
}

; Function Attrs: nofree nosync nounwind memory(argmem: readwrite)
define void @_QFPquicksort(ptr %0, ptr nocapture readonly %1, ptr nocapture readonly %2) local_unnamed_addr #2 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = load i32, ptr %1, align 4, !tbaa !3
  %7 = load i32, ptr %2, align 4, !tbaa !3
  %8 = add i32 %7, %6
  %9 = sdiv i32 %8, 2
  %narrow = add nsw i32 %9, -1
  %10 = sext i32 %narrow to i64
  %11 = getelementptr i128, ptr %0, i64 %10
  %12 = load i128, ptr %11, align 8, !tbaa !3
  %13 = shl i128 %12, 96
  %14 = ashr exact i128 %13, 96
  br label %.outer

.outer:                                           ; preds = %40, %3
  %.019.ph = phi i32 [ %27, %40 ], [ %7, %3 ]
  %.0.ph = phi i32 [ %21, %40 ], [ %6, %3 ]
  br label %15

15:                                               ; preds = %15, %.outer
  %.0 = phi i32 [ %21, %15 ], [ %.0.ph, %.outer ]
  %16 = sext i32 %.0 to i64
  %17 = add nsw i64 %16, -1
  %18 = getelementptr i128, ptr %0, i64 %17
  %19 = load i128, ptr %18, align 8, !tbaa !3
  %20 = icmp slt i128 %19, %14
  %21 = add i32 %.0, 1
  br i1 %20, label %15, label %.preheader

.preheader:                                       ; preds = %15, %.preheader
  %.1 = phi i32 [ %27, %.preheader ], [ %.019.ph, %15 ]
  %22 = sext i32 %.1 to i64
  %23 = add nsw i64 %22, -1
  %24 = getelementptr i128, ptr %0, i64 %23
  %25 = load i128, ptr %24, align 8, !tbaa !3
  %26 = icmp slt i128 %14, %25
  %27 = add i32 %.1, -1
  br i1 %26, label %.preheader, label %28

28:                                               ; preds = %.preheader
  %.not = icmp slt i32 %.0, %.1
  br i1 %.not, label %40, label %29

29:                                               ; preds = %28
  %30 = load i32, ptr %1, align 4, !tbaa !3
  %31 = add i32 %.0, -1
  %32 = icmp slt i32 %30, %31
  br i1 %32, label %33, label %34

33:                                               ; preds = %29
  store i32 %31, ptr %5, align 4, !tbaa !3
  call void @_QFPquicksort(ptr nonnull %0, ptr nonnull %1, ptr nonnull %5)
  br label %34

34:                                               ; preds = %33, %29
  %35 = add i32 %.1, 1
  %36 = load i32, ptr %2, align 4, !tbaa !3
  %37 = icmp slt i32 %35, %36
  br i1 %37, label %38, label %39

38:                                               ; preds = %34
  store i32 %35, ptr %4, align 4, !tbaa !3
  call void @_QFPquicksort(ptr nonnull %0, ptr nonnull %4, ptr nonnull %2)
  br label %39

39:                                               ; preds = %38, %34
  ret void

40:                                               ; preds = %28
  store i128 %25, ptr %18, align 8, !tbaa !3
  %41 = shl i128 %19, 96
  %42 = ashr exact i128 %41, 96
  store i128 %42, ptr %24, align 8, !tbaa !3
  br label %.outer
}

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 @_FortranAioInputDescriptor(ptr, ptr) local_unnamed_addr

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

declare i1 @_FortranAioOutputInteger128(ptr, i128) local_unnamed_addr

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

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

attributes #0 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" }
attributes #1 = { noreturn }
attributes #2 = { nofree nosync nounwind memory(argmem: readwrite) }
attributes #3 = { 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"}
!7 = !{!8, !8, i64 0}
!8 = !{!"descriptor member", !5, i64 0}
