Problem:


Score : 400 points

Problem Statement

Let {\rm comb}(n,r) be the number of ways to choose r objects from among n objects, disregarding order.
From n non-negative integers a_1, a_2, ..., a_n, select two numbers a_i > a_j so that {\rm comb}(a_i,a_j) is maximized.
If there are multiple pairs that maximize the value, any of them is accepted.

Constraints

2 \leq n \leq 10^5

0 \leq a_i \leq 10^9

a_1,a_2,...,a_n are pairwise distinct.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

n
a_1 a_2 ... a_n

Output

Print a_i and a_j that you selected, with a space in between.

Sample Input 1

5
6 9 4 2 11

Sample Output 1

11 6

\rm{comb}(a_i,a_j) for each possible selection is as follows:

\rm{comb}(4,2)=6 

\rm{comb}(6,2)=15 

\rm{comb}(6,4)=15 

\rm{comb}(9,2)=36 

\rm{comb}(9,4)=126 

\rm{comb}(9,6)=84 

\rm{comb}(11,2)=55 

\rm{comb}(11,4)=330 

\rm{comb}(11,6)=462 

\rm{comb}(11,9)=55

Thus, we should print 11 and 6.

Sample Input 2

2
100 0

Sample Output 2

100 0



Sample input:
5
6 9 4 2 11


Sample output:
11 6

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline
from collections import defaultdict
from heapq import heappop, heappush

from decimal import *

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

##### 累乗 #####
# pow(x, y, z) -> x**y % z

##### 割り算の切り上げ #####
# tmp = -(-4 // 3)

##### dict の for文 #####
# for k, v in d.items():
#     print(k, v)

##### 進数の変換 #####
# bin_str = bin(i)[2:]
# oct_str = oct(i)
# hex_str = hex(i)

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
def inputStr(): return input()[:-1]

inf = float('inf')
mod = 1000000007

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

def main():
	N = inputInt()
	A = inputList()
	A.sort()
	AA = A[::-1]

	ans1 = AA[0]
	ans2 = AA[-1]
	mmm = combination(ans1, ans2)
	for i,val in enumerate(AA):
		ans11 = val
		tmp = val // 2
		ind = bisect_left(A, tmp)
		tmp = A[ind]

		if tmp == val:
			continue

		#ans = combination(val, tmp)

		#print("{} {} {}".format(ans11, tmp, ans))
		ans1 = ans11
		ans2 = tmp
		break

	print("{} {}".format(ans1,ans2))



#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# 2分検索のリバース
def bisect_left_reverse(a, x):
    if a[0] <= x:
        return 0
    if x < a[-1]:
        return len(a)
    # 二分探索
    ok = len(a) - 1
    ng = 0
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if a[mid] <= x:
            ok = mid
        else:
            ng = mid
    return ok

def bisect_right_reverse(a, x):
    if a[0] < x:
        return 0
    if x <= a[-1]:
        return len(a)
    # 二分探索
    ok = len(a) - 1
    ng = 0
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if a[mid] < x:
            ok = mid
        else:
            ng = mid
    return ok

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# 2分検索
# 存在しない場合: None 存在する場合: その値
def binary_search(list, item):
    low = 0
    high = len(list) - 1

    while low <= high:
        mid = (low + high) //2
        guess = list[mid]
        if guess == item:
            return mid
        if guess > item:
            high = mid -1
        else:
            low = mid + 1
    return None

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# N 個のボールを K グループに分ける場合のパターン数
def sunuke(N, K, mod=10**9+7):
	if N < K or K-1 < 0:
		return 0
	else:
		return combination(N-1, K-1, mod)

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# nCr mod m
# rがn/2に近いと非常に重くなる
def combination(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res

# mを法とするaの乗法的逆元
def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

def egcd(a, b):
    if a == 0:
        return b, 0, 1
    else:
        g, y, x = egcd(b % a, a)
        return g, x - (b // a) * y, y

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# nHr mod m
# 問題によって、combination()を切り替えること
def H(n, r, mod=10**9+7):
	# comb = Combination(n+r-1, mod)
	# return comb(n+r-1, r)
    return combination(n+r-1, r, mod)


class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000)
    print(comb(5, 3))  # 10
    """
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# dfs のサンプル
def dfs(graph,parent,counter,edge):
    stk = []
    stk.append(edge)
    while len(stk) > 0:
        p = stk.pop()
        for e in graph[p]:
            if parent[p] == e:
                continue
            else:
                parent[e] = p
                counter[e] += counter[p]
                stk.append(e)

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
import math
import bisect
from queue import Queue
from collections import deque

n = int(input())
a = [int(i) for i in input().split()]

a.sort()

b = a[n-1]
c = bisect.bisect_left(a,b//2)
d = max(c-1,0)

if(abs(b//2 - a[c]) < abs(b//2 - a[d])):
    print(b,a[c])
else:
    print(b,a[d])

Submission status: Wrong Answer

Solution code:
import math
import bisect
from queue import Queue
from collections import deque

n = int(input())
a = [int(i) for i in input().split()]

a.sort()

b = a[n-1]
c = bisect.bisect_left(a,b//2)
d = min(c-1,0)

if(abs(b//2 - a[c]) < abs(b//2 - a[d])):
    print(b,a[c])
else:
    print(b,a[d])

Submission status: Wrong Answer

Solution code:
from scipy.misc import comb
#from scipy.special import comb

n = int(input())
A = sorted(list(map(int, input().split())))
ans = 0
out = []
if n % 2 == 1:
    middle = A[n // 2]
    last = A[-1]
    print(last, middle)
    # ans = comb(last, middle, exact=True)
    # print(ans)
elif n == 2:
    print(*A[::-1])
else:
    cand = [A[n // 2 - 1], A[n // 2]]
    last = A[-1]
    for i in range(2):
        middle = cand[i]
        comb_last_middle = comb(last, middle)
        if ans < comb_last_middle:
            out.append([last, middle])
            ans = comb_last_middle
    print(*out[-1])

Submission status: Wrong Answer

Solution code:
from scipy.misc import comb
#from scipy.special import comb

n = int(input())
A = sorted(list(map(int, input().split())))
ans = 0
out = []
if n % 2 == 1:
    middle = A[n // 2]
    last = A[-1]
    print(last, middle)
    # ans = comb(last, middle, exact=True)
    # print(ans)
elif n == 2:
    print(*A[::-1])
else:
    cand = [A[n // 2 - 1], A[n // 2]]
    last = A[-1]
    for i in range(2):
        middle = cand[i]
        comb_last_middle = comb(last, middle)
        if ans < comb_last_middle:
            out.append([last, middle])
            ans = comb_last_middle
    print(last, middle)

Submission status: Wrong Answer

Solution code:
import bisect

N = 5
ARR = [6, 9, 4, 2, 11]


N = 2
ARR = [100, 0]

N = int(input())
ARR = list(map(int, input().split()))


def calculate(n, arr):
    arr = sorted(arr)

    mid = arr[n - 1] / 2

    a1 = bisect.bisect_left(arr, mid)

    return arr[n - 1],arr[a1]



n, a = calculate(N, ARR)
print(n, a)

Submission status: Wrong Answer

Solution code:
import bisect

N = 5
ARR = [6, 9, 4, 2, 11]


# N = 2
# ARR = [100, 0]
#
N = int(input())
ARR = list(map(int, input().split()))


def calculate(n, arr):
    arr = sorted(arr)

    if arr[n-1] % 2 == 0:
        mid = arr[n - 1] // 2
        index = bisect.bisect_left(arr, mid)

        return arr[n - 1], arr[index]
    if arr[n-1] % 2 == 1:
        mid1 = arr[n - 1] // 2
        mid2 = arr[n - 1] // 2 + 1

        a1 = bisect.bisect_left(arr, mid1)
        a2 = bisect.bisect_left(arr, mid2)
        if abs(arr[a1] - mid1) > abs(arr[a2] - mid2):
            return arr[n - 1], arr[a2]
        else:
            return arr[n - 1], arr[a1]



n,a = calculate(N,ARR)
print(n,a)

Submission status: Wrong Answer

Solution code:
import bisect
N = 5
ARR = [6, 9, 4, 2, 11]

# N = 2
# ARR = [100, 0]
#
N = int(input())
ARR = list(map(int, input().split()))


def calculate(n, arr):

    arr = sorted(arr)

    if n % 2 == 0:
        mid = arr[n-1] // 2
        index = bisect.bisect_left(arr,mid)

        return arr[n-1],arr[index]
    if n % 2 == 1:
        mid1 = arr[n - 1] // 2
        mid2 = arr[n - 1] // 2 + 1

        a1 = bisect.bisect_left(arr,mid1)
        a2 = bisect.bisect_right(arr,mid2)
        if abs(arr[a1] - mid1) > abs(arr[a2] - mid2):
            return arr[n-1],arr[a2]
        else:
            return arr[n - 1], arr[a1]


n,a = calculate(N,ARR)
print(n,a)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left
n = int(input())
a_list = sorted([int(x) for x in input().split()])
base = a_list[-1] // 2
i = bisect_left(a_list, base)
if i > 0:
    i -= 1
ans = [a_list[-1], a_list[i], abs(a_list[i] - base)]
for i in range(i + 1, n):
    temp = abs(a_list[i] - base)
    if temp >= ans[2]:
        break
    ans[1] = a_list[i]
    ans[2] = temp
print(ans[0], ans[1])

Submission status: Wrong Answer

Solution code:
from math import factorial as f
n=int(input())
a=list(map(int,input().split()))

def comb(n,r):
    return int(f(n)/(f(r)*f(n-r)))

m=max(a)
r=0
for i in range(n):
    if abs(m/2-a[i])<abs(m/2-r):
        r=a[i]

print(comb(m,r))

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left, bisect_right

n = int(input())
a = list(map(int, input().split()))
a.sort()

m = a[-1]
left = a[bisect_left(a, m//2)]
right = a[bisect_right(a, m//2)]

if min(m-left, left) > min(m-right, right):
    print(m, left)
else:
    print(m, right)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = [int(a) for a in input().split()]

max_val = max(A)
mid_val = max_val - max_val//2

# print("max_val: {}, mid_val: {}".format(max_val, mid_val))

m = 0
for a in A:
    if abs(a - mid_val) > abs(m - mid_val):
        m = a
    # print("m: {}".format(m))

print("{} {}".format(max_val, m))

Submission status: Wrong Answer

Solution code:
import bisect
import copy
n = int(input())
a = list(map(int, input().split()))
a.sort()
b = copy.copy(a)
b.pop()
if len(b) == 1:
    idx = 0
else:
    if abs(a[-1]/2 - b[bisect.bisect_left(b, a[-1]/2)]) < abs(a[-1]/2 - b[bisect.bisect_right(b, a[-1]/2)]):
        idx = bisect.bisect_left(b, a[-1]/2)
    else:
        idx = bisect.bisect_right(b, a[-1]/2)
print(a[-1], b[idx])

Submission status: Wrong Answer

Solution code:
import bisect
n = int(input())
a = list(map(int, input().split()))
a.sort()
if abs(a[-1]/2 - a[bisect.bisect_left(a, a[-1]/2)]) < abs(a[-1]/2 - a[bisect.bisect_right(a, a[-1]/2)]):
    idx = bisect.bisect_left(a, a[-1]/2)
else:
    idx = bisect.bisect_right(a, a[-1]/2)
print(a[-1], a[idx])

Submission status: Wrong Answer

Solution code:
import bisect
n = int(input())
a = list(map(int, input().split()))
a.sort()
if abs(a[-1]/2 - a[bisect.bisect_left(a, a[-1])//2]) <= abs(a[-1]/2 - a[bisect.bisect_right(a, a[-1])//2]):
    idx = bisect.bisect_left(a, a[-1])//2
else:
    idx = bisect.bisect_right(a, a[-1])//2
print(a[-1], a[idx])

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
a = list(map(int,input().split()))

a = sorted(a, reverse = True)
mid = a[0]//2
diff = abs(mid - a[0])

if n == 2:
    print(max(a[0],a[1]),min(a[0],a[1]))
else:
    for i in range(n):
        if abs(a[i] - mid) <= diff:
            diff = abs(a[i] - mid)
            ans = i
    print(a[0], a[ans])

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
a = list(map(int,input().split()))
a = sorted(a, reverse = True)
f = 1
m = 0

syutu = 0
i = 1

while f  == 1 and  i < n :
    if a[0]//2 == a[i] or a[0]//2 +1 == a[i] :
        f = 0
        m = a[i]
    else:
        i += 1

if f == 1:
    hikaku = -1
    for i in range(1, n):
        answer = 1
        syutu = a[i]
        answer = int(math.factorial(a[0]) / (math.factorial(a[i ]) * math.factorial(a[0] - m + 1)))
        if hikaku <= answer:     
            hikaku = answer
            m = syutu
        
        
print(a[0], m)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    
    n=int(input())
    A=list(map(int,input().split()))
    val=max(A)
    minabs=10**18
    for i in range(n):
        if abs(A[i]-(val//2))<minabs:
            minabs=abs(A[i]-(val//2))
            val2=A[i]
    print(val,val2)    



    
resolve()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    
    n=int(input())
    A=list(map(int,input().split()))
    val=max(A)
    val2=0
    minabs=10**10
    for i in range(n):
        if abs(A[i]-(val//2))<minabs:
            minabs=abs(A[i]-(val//2))
            val2=A[i]
    print(val,val2)    



    
resolve()

Submission status: Wrong Answer

Solution code:
import sys
from bisect import bisect_left

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    N = int(input())
    A = list(map(int, input().split()))
    A.sort()
    MAX = max(A)
    A = A[:-1]
    target = MAX // 2
    idx = bisect_left(A, target)

    if idx == N - 1:
        print(MAX, A[-1])
    else:
        if abs(target - A[idx]) < abs(target - A[idx + 1]):
            print(MAX, A[idx])
        else:
            print(MAX, A[idx + 1])


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys

n=int(input())
A=list(map(int,input().split()))
A.sort()

if n==2:
    print(A[1],A[0])
    sys.exit()

p=A[-1]
h=p/2
for i in range(n-1):
    if A[i]>=p:
        break
if abs(A[i-1]-h)<=abs(A[i]-h):
    q=A[i-1]
else:
    q=A[i]
print(p,q)

Submission status: Wrong Answer

Solution code:
import bisect
def main():
    N = int(input())
    A = sorted([int(_) for _ in input().split()])
    r = A[-1]//2
    B = A[:-1]
    x = bisect.bisect_left(B, r)
    if x == 0:
        return A[-1], B[x]
    elif x == N-1:
        return A[-1], B[x-1]
    else:
        if abs(B[x]-r) <= abs(B[x-1]-r): return A[-1], B[x]
        else: return A[-1], B[-1]
if __name__ == '__main__':
    print(*main())

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))

ai = max(a)
aj = min(a)

for i in a:
    if aj < min(i, ai - i):
        aj = i
    
print(ai, aj)

Submission status: Wrong Answer

Solution code:
def pow(x, n , mod):
    res = 1
    while n > 0:
        if  bin(n & 1) == bin(1) :
            res = res * x % mod
        x = x*x % mod
        n = n >>1
    return res   

def combination(n,a):
    x = 1
    for i in range(a):
        x = x * (n-i) % mod
    y = 1
    for i in range(a):
        y = y * (a-i) % mod
    y = pow(y, mod-2, mod)
    return (x*y % mod)

n = int(input())
a = list(map(int, input().split()))
mod =1

m = max(a)
a = sorted(a)

ans = 0

for i in a:
    if abs(m//2-i) < abs(m//2-ans):
        ans = i

print(m, ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
ai = a[-1]
aj = ai
for i in a:
    if abs(ai/2-i) < abs(ai/2-aj):
        aj = i
print(ai, aj)

Submission status: Wrong Answer

Solution code:
import sys
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from fractions import gcd
from math import factorial, sqrt, ceil
from functools import lru_cache, reduce
INF = 1 << 60
MOD = 1000000007
sys.setrecursionlimit(10 ** 7)

# UnionFind
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

def is_prime(n):
    if n == 1:
        return False
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            return False
    return True


# ワーシャルフロイド (任意の2頂点の対に対して最短経路を求める)
# 計算量n^3 (nは頂点の数)
def warshall_floyd(d, n):
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d


# ダイクストラ
def dijkstra_heap(s, edge, n):
    #始点sから各頂点への最短距離
    d = [10**20] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d

# 素因数分解
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

# 2数の最小公倍数
def lcm(x, y):
    return (x * y) // gcd(x, y)

# リストの要素の最小公倍数
def lcm_list(numbers):
    return reduce(lcm, numbers, 1)

# リストの要素の最大公約数
def gcd_list(numbers):
    return reduce(gcd, numbers)

# 素数判定



# limit以下の素数を列挙
def eratosthenes(limit):
    A = [i for i in range(2, limit+1)]
    P = []

    while True:
        prime = min(A)
        
        if prime > sqrt(limit):
            break
            
        P.append(prime)
            
        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1
            
    for a in A:
        P.append(a)
            
    return P

# 同じものを含む順列
def permutation_with_duplicates(L):

    if L == []:
        return [[]]

    else:
        ret = []

        # set（集合）型で重複を削除、ソート
        S = sorted(set(L))

        for i in S:

            data = L[:]
            data.remove(i)

            for j in permutation_with_duplicates(data):
                ret.append([i] + j)

        return ret


# ここから書き始める
n = int(input())
a = list(map(int, input().split()))
ai = max(a)
if ai % 2 == 0:
    d = INF
    aj = 0
    for i in a:
        if abs(i - ai // 2) < d:
            aj = i
            d = abs(i - ai // 2)
    print(ai, aj)
else:
    d = INF
    aj = 0
    for i in a:
        if min(abs(i - ai // 2), abs(i - ai // 2 - 1)) < d:
            aj = i
            d = min(abs(i - ai // 2), abs(i - ai // 2 - 1))
    print(ai, aj)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
ai = a[-1]
aj = a[0]
center = ai // 2
diff = 10**10
# print("-----------")
# print(center)

for i in range(n-1):
    if abs(center - a[i]) < diff and center <= a[i]:
        diff = abs(center - a[i])
        aj = a[i]
        # print(diff)
        # print(aj)
        # print("----")


print(str(ai) + " " + str(aj))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)

max_a = max(a)
da = [abs(ai - max_a / 2) for ai in a]
med_i = da.index(min(da))

print("%d %d" % (max_a, a[med_i]))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

def main():
    N = int(input())
    A = list(map(int, input().split()))
    A_sorted = sorted(A)
    A_max = A_sorted[-1]
    A = A_sorted[:-1]
    tansaku = (A_max + 1) / 2
    ok = 0
    ng = len(A) - 1
    if A[ok] > tansaku:
        print(A_max, A[ok])
        exit()
    if A[ng] <= tansaku:
        print(A_max, A[ng])
        exit()
    while ok + 1 < ng:
        center = (ok + ng) // 2
        if A[center] <= tansaku:
            ok = center
        else:
            ng = center
    print(A_max, A[ok])

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

N = int(input())
A = list(map(int, input().split()))

def main():
    A_sorted = sorted(A)
    A_max = A_sorted[-1]
    tansaku = (A_max + 1) / 2
    ok = 0
    ng = N - 1
    if A_sorted[ok] > tansaku:
        print(A_max, A_sorted[ok])
        exit()
    if A_sorted[ng] <= tansaku:
        print(A_max, A_sorted[ng - 1])
        exit()
    while ok + 1 < ng:
        center = (ok + ng) // 2
        if A_sorted[center] <= tansaku:
            ok = center
        else:
            ng = center
    print(A_max, A_sorted[ok])

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

N = int(input())
A = list(map(int, input().split()))

def main():
    A_sorted = sorted(A)
    A_max = A_sorted[-1]
    tansaku = (A_max + 1) / 2
    ok = 0
    ng = N - 1
    if A_sorted[ok] > tansaku:
        print(A_max, A_sorted[ok])
        exit()
    if A_sorted[ng] <= tansaku:
        print(A_max, A_sorted[ng])
        exit()
    while ok + 1 < ng:
        center = (ok + ng) // 2
        if A_sorted[center] <= tansaku:
            ok = center
        else:
            ng = center
    print(A_max, A_sorted[ok])

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from bisect import bisect_left, bisect_right

n, *a = map(int, read().split())
a.sort()
index1 = min(bisect_left(a, a[-1] / 2), n - 2)
index2 = min(bisect_right(a, a[-1] / 2), n - 2)
if abs(a[-1] / 2 - a[index1]) > abs(a[-1] / 2 - a[index2]):
    ans = index2
else:
    ans = index1
print(a[-1], a[ans])

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from bisect import bisect_left

n, *a = map(int, read().split())
a.sort()
index = bisect_left(a, a[-1] / 2)
if index == (n - 1):
    index -= 1
print(a[-1], a[index])

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from bisect import bisect_left

n, *a = map(int, read().split())
a.sort()
print(a[-1], a[bisect_left(a, a[-1] / 2)])

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left


def main():
    n = int(input())
    a = [int(x) for x in input().split()]
    a.sort()
    if n > 2:
        index = bisect_left(a, a[-1] // 2)
        if index == n - 1:
            index -= 1
        elif index > 0 and a[-1] - a[index] < a[index - 1]:
            index -= 1
        print(a[-1], a[index])
    else:
        print(a[0], a[1])


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left


def main():
    n = int(input())
    a = [int(x) for x in input().split()]
    a.sort()
    index = bisect_left(a, a[-1] // 2)
    if index == n - 1:
        index -= 1
    print(a[-1], a[index])


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))

import bisect
a.sort()

# cand = []
# for i, ai in enumerate(a):
#     targ = ai // 2
#     idx = bisect.bisect_right(a, targ)
#     if idx < N and a[idx] < targ: cand.append((ai, a[idx]))
#     if idx + 1 < N and a[idx + 1] < targ: cand.append((ai, a[idx + 1]))


cand = []

targ = a[-1] // 2
idx = bisect.bisect_right(a, targ)

if idx < len(a) and a[idx] < a[-1]:
    cand.append(a[idx])
if idx + 1 < len(a) and a[idx + 1] < a[-1]:
    cand.append(a[idx + 1])

ans = 0
ans_tmp = 0
for i, candi in enumerate(cand):
    tmp = min(candi, a[-1] - candi)
    if ans_tmp < tmp:
        ans = candi
        ans_tmp = max(ans_tmp, tmp)
        
print(a[-1], ans)

Submission status: Wrong Answer

Solution code:
import sys
def main():
    input = sys.stdin.readline
    n=int(input())
    *A,=map(int, input().split())
    #mCr
    m,r=max(A),0
    maxd=0
    for a in A:
        if a>=m: continue
        d = min(a,m+1-a)
        if maxd<d:
            maxd=d
            r=a
    print(m,r)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math
import bisect


def cmb(n, r):
    if n - r < r:
        r = n - r
    if r == 0:
        return 1
    if r == 1:
        return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result


n = int(input())

a = list(map(int, input().split()))
a.sort()

ncr = 0
ans = [0, 0]

id = bisect.bisect_left(a[:n-1], a[n-1]//2)
ncr = cmb(a[n-1], a[id])
ans = [a[n-1], a[id]]
if id != n-1 and cmb(a[n-1], a[id+1]) > ncr:
    ans = [a[n-1], a[id+1]]
print(*ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
sai=max(a)
b=sai//2
hantei=10**9
suuji=0
for i in a:
  if abs(b-i)<hantei:
    hantei=abs(b-i)
    suuji=i
print(sai,suuji)

Submission status: Wrong Answer

Solution code:
import math
import bisect


def cmb(n, r):
    if n - r < r:
        r = n - r
    if r == 0:
        return 1
    if r == 1:
        return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result


n = int(input())

a = list(map(int, input().split()))
a.sort()

ncr = 0
ans = [0, 0]
for i in range(1, n):
    id = bisect.bisect_left(a[:i], a[i]//2)
    tmp = cmb(a[i], a[id])
    if id != i:
        tmp = max(tmp, cmb(a[i], a[id+1]))
    if tmp > ncr:
        ncr = tmp
        ans = [a[i], a[id]]
print(*ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort()

n = A.pop()
A.sort(key=lambda a: abs(a - n // 2))
r = A[0]
print(n, r)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))

n = max(A)
A.sort(key=lambda a: abs(a - n // 2))
r = A[0]
print(n, r)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))

a.sort()
m = a[-1]
import bisect
j = bisect.bisect_left(a,m//2-1)
if j==n-1:
    j-=1
print(m,a[j])

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))

a.sort()
m = a[-1]
import bisect
j = bisect.bisect_left(a,m//2)
if j==n-1:
    j-=1
print(m,a[j])

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))

a.sort()
m = a[-1]
import bisect
j = bisect.bisect_left(a,m//2)
if j==n-1:
    j-=1
print(m,a[j])

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))

a.sort()
m = a[-1]
import bisect
j = bisect.bisect_left(a,m/2)
if j==n-1:
    j-=1
print(m,a[j])

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
a = sorted(a, reverse = True)

ai = a[0] // 2
aj = 0
comb = 10 ** 10
for i in range(n):
    temp = abs(a[i] - ai)
    if comb >= temp:
        comb = temp
        aj = a[i]
print(a[0], aj)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left
N = int(input())
A = list(map(int,input().split()))
A.sort()
n = A.pop()
index = bisect_left(A, n//2)
if index == 0:
    r = A[0]
elif index == N-1:
    r = A[N-2]
else:
    if abs(n//2-A[index]) < abs(n//2-A[index-1]):
        r = A[index]
    else:
        r = A[index - 1]
print(*[n,r])

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left
N = int(input())
A = list(map(int,input().split()))
A.sort()
n = A.pop()
index = bisect_left(A, n//2+1)
if index == 0:
    r = A[0]
elif index == N-1:
    r = A[N-2]
else:
    if abs(n//2+1-A[index]) < abs(n//2+1-A[index-1]):
        r = A[index]
    else:
        r = A[index - 1]
print(*[n,r])