#include <limits.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define ABS(a) ((a) < 0 ? (-(a)) : (a))
#define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++)
#define reps(i, n) for (int i = 1, i##_len = (int)(n); i <= i##_len; i++)

typedef long long Int;
typedef long double Double;

int asc(const void *a, const void *b) {
    Int d = *(Int *)a - *(Int *)b;
    return (d > 0) ? 1 : (d < 0) ? -1 : 0;
}

int desc(const void *a, const void *b) {
    Int d = *(Int *)b - *(Int *)a;
    return (d > 0) ? 1 : (d < 0) ? -1 : 0;
}

// 昇順に並んだ values の中で searchValue を 左から探したときに初めて上回る(order>0) / 右から探したときに初めて下回る(order<0) ような index を探す（ない場合は -1 を返す）
int binary_search(Int searchValue, Int *values, int minIndex, int maxIndex, int order) {
    int midIndex = (minIndex + maxIndex) / 2;
    Int midValue = values[midIndex];
    Int maxValue = values[maxIndex];
    if (minIndex == midIndex) { // 区間の長さが2になったとき
        if (order > 0) {
            if (searchValue < midValue) { // 左がサーチ値を上回るなら左
                return midIndex;
            }
            if (searchValue < maxValue) { // 左がサーチ値以下かつ右がサーチ値を上回るなら右
                return maxIndex;
            }
        } else {
            if (searchValue > maxValue) { // 右がサーチ値を下回るなら右
                return maxIndex;
            }
            if (searchValue > midValue) { // 右がサーチ値以上かつ左がサーチ値を下回るなら左
                return midIndex;
            }
        }
        return -1; // 区間の長さが2のとき両端とも条件を満たさないなら存在しない
    }
    if (order > 0) {
        if (midValue <= searchValue) { // 中央での値がまだ上回っていないなら右半分
            return binary_search(searchValue, values, midIndex, maxIndex, order);
        } else {
            return binary_search(searchValue, values, minIndex, midIndex, order);
        }
    } else {
        if (midValue >= searchValue) { // 中央での値がまだ下回っていないなら左半分
            return binary_search(searchValue, values, minIndex, midIndex, order);
        } else {
            return binary_search(searchValue, values, midIndex, maxIndex, order);
        }
    }
}
int main() {
    Int n;
    scanf("%lld", &n);
    Int *a = (Int *)malloc(sizeof(Int) * n);
    rep(i, n) scanf("%lld", a + i);
    qsort(a, n, sizeof(Int), asc);
    Int m = a[n - 1];
    int index = binary_search(m / 2, a, 0, n - 1, 1);
    Double mm = ((Double)m) / 2.0;
    Int ans;
    if (index == 0) {
        ans = a[0];
    } else {
        Double candidate1 = a[index];
        Double candidate2 = a[index - 1];
        ans = (ABS(candidate1 - mm) < ABS(candidate2 - mm)) ? candidate1 : candidate2;
    }
    printf("%lld %lld\n", m, ans);
}

; ModuleID = '/data/TheStack_IR/OJ_Samples/Collated/ObjectiveC/Source_561/source.m'
source_filename = "/data/TheStack_IR/OJ_Samples/Collated/ObjectiveC/Source_561/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 [5 x i8] c"%lld\00", align 1
@.str.1 = private unnamed_addr constant [11 x i8] c"%lld %lld\0A\00", align 1

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) uwtable
define dso_local i32 @asc(ptr nocapture noundef readonly %a, ptr nocapture noundef readonly %b) #0 {
entry:
  %0 = load i64, ptr %a, align 8, !tbaa !5
  %1 = load i64, ptr %b, align 8, !tbaa !5
  %cmp = icmp sgt i64 %0, %1
  %cmp1.not = icmp ne i64 %0, %1
  %cond = sext i1 %cmp1.not to i32
  %cond2 = select i1 %cmp, i32 1, i32 %cond
  ret i32 %cond2
}

; 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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) uwtable
define dso_local i32 @desc(ptr nocapture noundef readonly %a, ptr nocapture noundef readonly %b) local_unnamed_addr #0 {
entry:
  %0 = load i64, ptr %b, align 8, !tbaa !5
  %1 = load i64, ptr %a, align 8, !tbaa !5
  %cmp = icmp sgt i64 %0, %1
  %cmp1.not = icmp ne i64 %0, %1
  %cond = sext i1 %cmp1.not to i32
  %cond2 = select i1 %cmp, i32 1, i32 %cond
  ret i32 %cond2
}

; Function Attrs: nofree norecurse nosync nounwind memory(argmem: read) uwtable
define dso_local i32 @binary_search(i64 noundef %searchValue, ptr nocapture noundef readonly %values, i32 noundef %minIndex, i32 noundef %maxIndex, i32 noundef %order) local_unnamed_addr #2 {
entry:
  %add72 = add nsw i32 %maxIndex, %minIndex
  %div73 = sdiv i32 %add72, 2
  %idxprom74 = sext i32 %div73 to i64
  %arrayidx75 = getelementptr inbounds i64, ptr %values, i64 %idxprom74
  %0 = load i64, ptr %arrayidx75, align 8, !tbaa !5
  %cmp76 = icmp eq i32 %div73, %minIndex
  br i1 %cmp76, label %if.then, label %if.end17.lr.ph

if.end17.lr.ph:                                   ; preds = %entry
  %cmp18 = icmp sgt i32 %order, 0
  br i1 %cmp18, label %if.end17.us, label %if.end17

if.end17.us:                                      ; preds = %if.end17.lr.ph, %if.end17.us
  %1 = phi i64 [ %2, %if.end17.us ], [ %0, %if.end17.lr.ph ]
  %div79.us = phi i32 [ %div.us, %if.end17.us ], [ %div73, %if.end17.lr.ph ]
  %maxIndex.tr78.us = phi i32 [ %div.maxIndex.tr.us, %if.end17.us ], [ %maxIndex, %if.end17.lr.ph ]
  %minIndex.tr77.us = phi i32 [ %minIndex.tr.div.us, %if.end17.us ], [ %minIndex, %if.end17.lr.ph ]
  %cmp20.not.us = icmp sgt i64 %1, %searchValue
  %minIndex.tr.div.us = select i1 %cmp20.not.us, i32 %minIndex.tr77.us, i32 %div79.us
  %div.maxIndex.tr.us = select i1 %cmp20.not.us, i32 %div79.us, i32 %maxIndex.tr78.us
  %add.us = add nsw i32 %div.maxIndex.tr.us, %minIndex.tr.div.us
  %div.us = sdiv i32 %add.us, 2
  %idxprom.us = sext i32 %div.us to i64
  %arrayidx.us = getelementptr inbounds i64, ptr %values, i64 %idxprom.us
  %2 = load i64, ptr %arrayidx.us, align 8, !tbaa !5
  %cmp.us = icmp eq i32 %div.us, %minIndex.tr.div.us
  br i1 %cmp.us, label %if.then, label %if.end17.us

if.then:                                          ; preds = %if.end17, %if.end17.us, %entry
  %maxIndex.tr.lcssa71 = phi i32 [ %maxIndex, %entry ], [ %div.maxIndex.tr.us, %if.end17.us ], [ %maxIndex.tr.div, %if.end17 ]
  %div.lcssa = phi i32 [ %minIndex, %entry ], [ %minIndex.tr.div.us, %if.end17.us ], [ %div.minIndex.tr, %if.end17 ]
  %.lcssa70 = phi i64 [ %0, %entry ], [ %2, %if.end17.us ], [ %5, %if.end17 ]
  %idxprom1.le = sext i32 %maxIndex.tr.lcssa71 to i64
  %arrayidx2.le = getelementptr inbounds i64, ptr %values, i64 %idxprom1.le
  %3 = load i64, ptr %arrayidx2.le, align 8, !tbaa !5
  %cmp3 = icmp sgt i32 %order, 0
  br i1 %cmp3, label %if.then4, label %if.else

if.then4:                                         ; preds = %if.then
  %cmp5 = icmp sgt i64 %.lcssa70, %searchValue
  br i1 %cmp5, label %cleanup, label %if.end

if.end:                                           ; preds = %if.then4
  %cmp7 = icmp sgt i64 %3, %searchValue
  br i1 %cmp7, label %cleanup, label %if.end16

if.else:                                          ; preds = %if.then
  %cmp10 = icmp slt i64 %3, %searchValue
  br i1 %cmp10, label %cleanup, label %if.end12

if.end12:                                         ; preds = %if.else
  %cmp13 = icmp slt i64 %.lcssa70, %searchValue
  br i1 %cmp13, label %cleanup, label %if.end16

if.end16:                                         ; preds = %if.end12, %if.end
  br label %cleanup

if.end17:                                         ; preds = %if.end17.lr.ph, %if.end17
  %4 = phi i64 [ %5, %if.end17 ], [ %0, %if.end17.lr.ph ]
  %div79 = phi i32 [ %div, %if.end17 ], [ %div73, %if.end17.lr.ph ]
  %maxIndex.tr78 = phi i32 [ %maxIndex.tr.div, %if.end17 ], [ %maxIndex, %if.end17.lr.ph ]
  %minIndex.tr77 = phi i32 [ %div.minIndex.tr, %if.end17 ], [ %minIndex, %if.end17.lr.ph ]
  %cmp25.not = icmp slt i64 %4, %searchValue
  %div.minIndex.tr = select i1 %cmp25.not, i32 %div79, i32 %minIndex.tr77
  %maxIndex.tr.div = select i1 %cmp25.not, i32 %maxIndex.tr78, i32 %div79
  %add = add nsw i32 %maxIndex.tr.div, %div.minIndex.tr
  %div = sdiv i32 %add, 2
  %idxprom = sext i32 %div to i64
  %arrayidx = getelementptr inbounds i64, ptr %values, i64 %idxprom
  %5 = load i64, ptr %arrayidx, align 8, !tbaa !5
  %cmp = icmp eq i32 %div, %div.minIndex.tr
  br i1 %cmp, label %if.then, label %if.end17

cleanup:                                          ; preds = %if.end12, %if.else, %if.end, %if.then4, %if.end16
  %retval.0 = phi i32 [ -1, %if.end16 ], [ %div.lcssa, %if.then4 ], [ %maxIndex.tr.lcssa71, %if.end ], [ %maxIndex.tr.lcssa71, %if.else ], [ %div.lcssa, %if.end12 ]
  ret i32 %retval.0
}

; Function Attrs: nofree nounwind uwtable
define dso_local i32 @main() local_unnamed_addr #3 {
entry:
  %n = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %n) #7
  %call = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %n)
  %0 = load i64, ptr %n, align 8, !tbaa !5
  %mul = shl i64 %0, 3
  %call1 = call noalias ptr @malloc(i64 noundef %mul) #8
  %conv = trunc i64 %0 to i32
  %cmp70 = icmp sgt i32 %conv, 0
  br i1 %cmp70, label %for.body.preheader, label %for.cond.cleanup

for.body.preheader:                               ; preds = %entry
  %wide.trip.count = and i64 %0, 4294967295
  br label %for.body

for.cond.cleanup.loopexit:                        ; preds = %for.body
  %.pre = load i64, ptr %n, align 8, !tbaa !5
  br label %for.cond.cleanup

for.cond.cleanup:                                 ; preds = %for.cond.cleanup.loopexit, %entry
  %1 = phi i64 [ %.pre, %for.cond.cleanup.loopexit ], [ %0, %entry ]
  call void @qsort(ptr noundef %call1, i64 noundef %1, i64 noundef 8, ptr noundef nonnull @asc) #7
  %2 = load i64, ptr %n, align 8, !tbaa !5
  %sub = add nsw i64 %2, -1
  %arrayidx = getelementptr inbounds i64, ptr %call1, i64 %sub
  %3 = load i64, ptr %arrayidx, align 8, !tbaa !5
  %div = sdiv i64 %3, 2
  %conv5 = trunc i64 %sub to i32
  %div73.i = sdiv i32 %conv5, 2
  %idxprom74.i = sext i32 %div73.i to i64
  %arrayidx75.i = getelementptr inbounds i64, ptr %call1, i64 %idxprom74.i
  %4 = load i64, ptr %arrayidx75.i, align 8, !tbaa !5
  %conv5.off = add i32 %conv5, 1
  %cmp76.i = icmp ult i32 %conv5.off, 3
  br i1 %cmp76.i, label %if.then.i, label %if.end17.us.i

if.end17.us.i:                                    ; preds = %for.cond.cleanup, %if.end17.us.i
  %5 = phi i64 [ %6, %if.end17.us.i ], [ %4, %for.cond.cleanup ]
  %div79.us.i = phi i32 [ %div.us.i, %if.end17.us.i ], [ %div73.i, %for.cond.cleanup ]
  %maxIndex.tr78.us.i = phi i32 [ %div.maxIndex.tr.us.i, %if.end17.us.i ], [ %conv5, %for.cond.cleanup ]
  %minIndex.tr77.us.i = phi i32 [ %minIndex.tr.div.us.i, %if.end17.us.i ], [ 0, %for.cond.cleanup ]
  %cmp20.not.us.i = icmp sgt i64 %5, %div
  %minIndex.tr.div.us.i = select i1 %cmp20.not.us.i, i32 %minIndex.tr77.us.i, i32 %div79.us.i
  %div.maxIndex.tr.us.i = select i1 %cmp20.not.us.i, i32 %div79.us.i, i32 %maxIndex.tr78.us.i
  %add.us.i = add nsw i32 %minIndex.tr.div.us.i, %div.maxIndex.tr.us.i
  %div.us.i = sdiv i32 %add.us.i, 2
  %idxprom.us.i = sext i32 %div.us.i to i64
  %arrayidx.us.i = getelementptr inbounds i64, ptr %call1, i64 %idxprom.us.i
  %6 = load i64, ptr %arrayidx.us.i, align 8, !tbaa !5
  %cmp.us.i = icmp eq i32 %div.us.i, %minIndex.tr.div.us.i
  br i1 %cmp.us.i, label %if.then.i, label %if.end17.us.i

if.then.i:                                        ; preds = %if.end17.us.i, %for.cond.cleanup
  %maxIndex.tr.lcssa71.i = phi i32 [ %conv5, %for.cond.cleanup ], [ %div.maxIndex.tr.us.i, %if.end17.us.i ]
  %div.lcssa.i = phi i32 [ 0, %for.cond.cleanup ], [ %minIndex.tr.div.us.i, %if.end17.us.i ]
  %.lcssa70.i = phi i64 [ %4, %for.cond.cleanup ], [ %6, %if.end17.us.i ]
  %cmp5.i = icmp sgt i64 %.lcssa70.i, %div
  br i1 %cmp5.i, label %binary_search.exit, label %if.end.i

if.end.i:                                         ; preds = %if.then.i
  %idxprom1.le.i = sext i32 %maxIndex.tr.lcssa71.i to i64
  %arrayidx2.le.i = getelementptr inbounds i64, ptr %call1, i64 %idxprom1.le.i
  %7 = load i64, ptr %arrayidx2.le.i, align 8, !tbaa !5
  %cmp7.i = icmp sgt i64 %7, %div
  br i1 %cmp7.i, label %binary_search.exit, label %if.else

binary_search.exit:                               ; preds = %if.then.i, %if.end.i
  %retval.0.i = phi i32 [ %div.lcssa.i, %if.then.i ], [ %maxIndex.tr.lcssa71.i, %if.end.i ]
  %cmp9 = icmp eq i32 %retval.0.i, 0
  br i1 %cmp9, label %if.then, label %if.else

for.body:                                         ; preds = %for.body.preheader, %for.body
  %indvars.iv = phi i64 [ 0, %for.body.preheader ], [ %indvars.iv.next, %for.body ]
  %add.ptr = getelementptr inbounds i64, ptr %call1, i64 %indvars.iv
  %call3 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef %add.ptr)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %for.cond.cleanup.loopexit, label %for.body

if.then:                                          ; preds = %binary_search.exit
  %8 = load i64, ptr %call1, align 8, !tbaa !5
  br label %if.end

if.else:                                          ; preds = %if.end.i, %binary_search.exit
  %retval.0.i68 = phi i32 [ %retval.0.i, %binary_search.exit ], [ -1, %if.end.i ]
  %div869.in = sitofp i64 %3 to x86_fp80
  %div869 = fmul x86_fp80 %div869.in, 0xK3FFE8000000000000000
  %idxprom = sext i32 %retval.0.i68 to i64
  %arrayidx12 = getelementptr inbounds i64, ptr %call1, i64 %idxprom
  %9 = load i64, ptr %arrayidx12, align 8, !tbaa !5
  %conv13 = sitofp i64 %9 to x86_fp80
  %sub14 = add nsw i32 %retval.0.i68, -1
  %idxprom15 = sext i32 %sub14 to i64
  %arrayidx16 = getelementptr inbounds i64, ptr %call1, i64 %idxprom15
  %10 = load i64, ptr %arrayidx16, align 8, !tbaa !5
  %conv17 = sitofp i64 %10 to x86_fp80
  %sub18 = fsub x86_fp80 %conv13, %div869
  %cmp19 = fcmp olt x86_fp80 %sub18, 0xK00000000000000000000
  %fneg = fneg x86_fp80 %sub18
  %cond = select i1 %cmp19, x86_fp80 %fneg, x86_fp80 %sub18
  %sub23 = fsub x86_fp80 %conv17, %div869
  %cmp24 = fcmp olt x86_fp80 %sub23, 0xK00000000000000000000
  %fneg28 = fneg x86_fp80 %sub23
  %cond32 = select i1 %cmp24, x86_fp80 %fneg28, x86_fp80 %sub23
  %cmp33 = fcmp olt x86_fp80 %cond, %cond32
  %cond38 = select i1 %cmp33, x86_fp80 %conv13, x86_fp80 %conv17
  %conv39 = fptosi x86_fp80 %cond38 to i64
  br label %if.end

if.end:                                           ; preds = %if.else, %if.then
  %ans.0 = phi i64 [ %8, %if.then ], [ %conv39, %if.else ]
  %call40 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i64 noundef %3, i64 noundef %ans.0)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %n) #7
  ret i32 0
}

; Function Attrs: nofree nounwind
declare noundef i32 @__isoc99_scanf(ptr nocapture noundef readonly, ...) local_unnamed_addr #4

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #5

; Function Attrs: nofree
declare void @qsort(ptr noundef, i64 noundef, i64 noundef, ptr nocapture noundef) local_unnamed_addr #6

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

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) 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 = { nofree norecurse nosync nounwind memory(argmem: read) 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 #3 = { nofree nounwind 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 #4 = { nofree nounwind "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 #5 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 #6 = { nofree "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 #7 = { nounwind }
attributes #8 = { nounwind allocsize(0) }

!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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
