Problem:


Score : 700 points

Problem Statement

Aoki loves numerical sequences and trees.

One day, Takahashi gave him an integer sequence of length N, a_1, a_2, ..., a_N, which made him want to construct a tree.

Aoki wants to construct a tree with N vertices numbered 1 through N, such that for each i = 1,2,...,N, the distance between vertex i and the farthest vertex from it is a_i, assuming that the length of each edge is 1.

Determine whether such a tree exists.

Constraints

2 ≦ N ≦ 100

1 ≦ a_i ≦ N-1

Input

The input is given from Standard Input in the following format:

N
a_1 a_2 ... a_N

Output

If there exists a tree that satisfies the condition, print Possible. Otherwise, print Impossible.

Sample Input 1

5
3 2 2 3 3

Sample Output 1

Possible

The diagram above shows an example of a tree that satisfies the conditions. The red arrows show paths from each vertex to the farthest vertex from it.

Sample Input 2

3
1 1 2

Sample Output 2

Impossible

Sample Input 3

10
1 2 2 2 2 2 2 2 2 2

Sample Output 3

Possible

Sample Input 4

10
1 1 2 2 2 2 2 2 2 2

Sample Output 4

Impossible

Sample Input 5

6
1 1 1 1 1 5

Sample Output 5

Impossible

Sample Input 6

5
4 3 2 3 4

Sample Output 6

Possible



Sample input:
5
3 2 2 3 3


Sample output:
Possible

Submission status: Wrong Answer

Solution code:
from collections import Counter as C
n=int(input())
a=sorted(C(list(map(int,input().split()))).items())
d=0
if a[-1][0]%2==0:
    d=1
q=1
for i in range(len(a)-1,-1,-1):
    if d:
        if a[i][0]==a[-1][0]//2:
            if a[i][1]!=1:
                q=0
                break
        elif a[i][0]<a[-1][0]//2:
            q=0
            break
        elif a[i][0]!=a[-1][0]+i-len(a)+1:
            q=0
            break
        elif a[i][1]<2:
            q=0
            break
    else:
        if a[i][0]<a[-1][0]//2:
            q=0
            break
        elif a[i][0]!=a[-1][0]+i-len(a)+1:
            q=0
            break
        elif a[i][1]<2:
            q=0
            break
if q:
    print("Possible")
else:
    print("Impossible")

Submission status: Wrong Answer

Solution code:

N = int(input())

a = list(map(int,input().split()))
maxi = max(a)

dic = {}

for i in range(N):

    if a[i] not in dic:
        dic[a[i]] = 1
    else:
        dic[a[i]] += 1

flag = True

if maxi % 2 == 0:

    for i in range(maxi + 1):

        if i < maxi // 2 and i in dic:
            flag = False

        if i == maxi // 2 and (i not in dic or dic[i] != 1):
            flag = False

        if i > maxi // 2 and (i not in dic or dic[i] < 2):
            flag = False

else:

    for i in range(maxi + 1):

        if i <= maxi // 2 and i in dic:
            flag = False

        if i > maxi // 2 and (i not in dic or dic[i] < 2):
            flag = False

if flag:
    print ("Possible")
else:
    print ("Impossible")

Submission status: Wrong Answer

Solution code:

N = int(input())

a = list(map(int,input().split()))
maxi = max(a)

dic = {}

for i in range(N):

    if a[i] not in dic:
        dic[a[i]] = 1
    else:
        dic[a[i]] += 1

flag = True

for i in range(maxi+1):

    if i < maxi // 2 and i in dic:
        flag = False

    elif i * 2 == maxi and (i not in dic or dic[i] != 1):
        flag = False

    elif i > maxi // 2 and (i not in dic or dic[i] < 2):
        flag = False

if flag:
    print ("Possible")
else:
    print ("Impossible")

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7 # 998244353
input=lambda:sys.stdin.readline().rstrip()
from collections import defaultdict
def resolve():
    n=int(input())
    A=list(map(int,input().split()))
    D=defaultdict(int)
    for a in A: D[a]+=1

    m=max(A)
    B=list(range(m//2+1,m+1))*2
    if(m&1==0): B.append(m//2)

    for b in B:
        if(D[b]==0):
            print("Impossible")
            return
        D[b]-=1

    for key,val in D.items():
        if(val==0): continue
        if(not (m//2+1<=key<=m)):
            print("Impossible")
            return

    print("Possible")
resolve()

Submission status: Wrong Answer

Solution code:
n=int(input())
A=[int(i) for i in input().split()]+[0]
m=max(A)
import collections
C=collections.Counter(A)
chk=True
if m%2==0:
  for i in range(m//2,m+1):
    if i==m//2:
      if C[i]!=1:
        chk=False
    elif i==m:
      if C[i]==1:
        chk=False
    else:
      if C[i]<2:
        chk=False
else:
  for i in range((m+1)//2,m+1):
    if i==m:
      if C[i]==1:
        chk=False
    else:
      if C[i]<2:
        chk=False
print("Possible" if chk else "Impossible")

Submission status: Wrong Answer

Solution code:
n=int(input())
A=[int(i) for i in input().split()]+[0]
m=max(A)
import collections
C=collections.Counter(A)
chk=True
if m%2==0:
  for i in range(m//2,m+1):
    if i==m//2:
      if C[i]!=1:
        chk=False
    elif i==m:
      if C[i]==1:
        chk=False
    else:
      if C[i]!=2:
        chk=False
else:
  for i in range((m+1)//2,m+1):
    if i==m:
      if C[i]==1:
        chk=False
    else:
      if C[i]!=2:
        chk=False
print("Possible" if chk else "Impossible")

Submission status: Wrong Answer

Solution code:
def main():
    from collections import Counter as ct
    n = int(input())
    a = list(map(int, input().split()))
    c = ct(a)
    min_a = min(a)
    max_a = max(a)
    if c[min_a] == 1 and (max_a+c[min_a])//2 > min_a:
        print("Impossible")
        return 0
    if c[min_a] > 2:
        print("Impossible")
        return 0
    for i in range(min_a+1, max_a+1):
        if c[i] < 2:
            print("Impossible")
            return 0
    print("Possible")


main()

Submission status: Wrong Answer

Solution code:
def main():
    from collections import Counter as ct
    n = int(input())
    a = list(map(int, input().split()))
    c = ct(a)
    min_a = min(a)
    max_a = max(a)
    if min_a == 1:
        if c[min_a] == 1:
            pass
        elif a == [1, 1]:
            print("Possible")
            return 0
        else:
            print("Impossible")
            return 0
    if c[min_a] == 1 and (max_a+1)//2 > min_a:
        print("Impossible")
        return 0
    if c[min_a] == 2 and (max_a+2)//2 > min_a:
        print("Impossible")
        return 0
    if c[min_a] > 2:
        print("Impossible")
        return 0
    for i in range(min_a+1, max_a+1):
        if c[i] < 2:
            print("Impossible")
            return 0
    print("Possible")

Submission status: Wrong Answer

Solution code:
def main():
    from collections import Counter as ct
    n = int(input())
    a = list(map(int, input().split()))
    c = ct(a)
    min_a = min(a)
    max_a = max(a)
    if min_a == 1:
        if c[min_a] == 1:
            pass
        elif a == [1, 1]:
            print("Possible")
            return 0
        else:
            print("Impossible")
            return 0
    if (max_a+1)//2 > min_a:
        print("Impossible")
        return 0
    if c[min_a] > 2:
        print("Impossible")
        return 0
    for i in range(min_a+1, max_a+1):
        if c[i] < 2:
            print("Impossible")
            return 0
    print("Possible")


main()

Submission status: Wrong Answer

Solution code:
def main():
    from collections import Counter as ct
    n = int(input())
    a = list(map(int, input().split()))
    c = ct(a)
    min_a = min(a)
    max_a = max(a)
    if min_a == 1:
        if c[min_a] == 1:
            pass
        elif a == [1, 1]:
            print("Possible")
            return 0
        else:
            print("Impossible")
            return 0
    if c[min_a] > 2:
        print("Impossible")
        return 0
    for i in range(min_a+1, max_a+1):
        if c[i] < 2:
            print("Impossible")
            return 0
    print("Possible")


main()

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

def solve() :
    cnt = list(Counter(a).items())
    cnt.sort()
    
    if cnt[0][1] == 1 and cnt[-1][0] != 2 * cnt[0][0] :
        return 'Impossible'
    if cnt[0][1] >= 2 and cnt[-1][0] != 2 * cnt[0][0] - 1 :
        return 'Impossible'

    for i in range(1, len(cnt)) :
        if cnt[i][0] != cnt[i-1][0] + 1 :
            return 'Impossible'
        if cnt[i][1] < 2 :
            return 'Impossible'
            
    return 'Possible'
    
print(solve())

Submission status: Wrong Answer

Solution code:
import numpy as np

def checker(n ,da):
    mx = max(da)
    mi = min(da)
    if mx < 2 or n <= mx: return False
    arr = np.zeros(mx + 1, dtype=int)
    for i in range(n):
        arr[da[i]] += 1
    if mx % 2:
        if arr[mi] > 2 or (mx + 1) // 2 != mi:
            return False
    else:
        if arr[mi] > 1 or mx // 2 != mi:
            return False
    for i in range(mi , mx):
        if arr[i + 1] < 2:
            return False
    return True

    

def main():
    n = int(input())
    da = list(map(int,input().split()))
    print('Possible') if checker(n, da) else print('Impossible')
    return

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter


def solve(n, aaa):
    count = Counter(aaa)
    min_a = min(count)
    max_a = max(count)
    # 最大値（直径）が所定の範囲内か
    if not 2 <= max_a <= n - 1:
        return False
    # 最小値は半径以下にはならない & 直径パス上の中点として半径である点が必要
    if min_a != (max_a + 1) // 2:
        return False
    # 中点は直径が偶数なら1個、奇数なら2個しかあり得ない
    if count[min_a] != max_a % 2 + 1:
        return False
    # 直径パス上の点として半径+1～直径の各距離が2点ずつ必要
    if any(count[a] < 2 for a in range(min_a + 1, max_a + 1)):
        return False
    # 後の頂点は直径パスの適当な箇所に接続すれば任意の距離に出来る
    return True


n = int(input())
aaa = list(map(int, input().split()))
print('Possible' if solve(n, aaa) else 'Impossible')

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N = int(input())
	D = defaultdict(int)
	a = sorted(getlist())
	if N == 2:
		if a[0] != 1 or a[1] != 1:
			print("Impossible")
		else:
			print("Possible")
	else:
		for i in range(N):
			D[a[i]] += 1
		if a[-1] % 2 != 0:
			if a[0] * 2 - 1 != a[-1]:
				print("Impossible")
			else:
				judge = "Possible"
				for i in range(a[0], a[-1] + 1):
					if D[i] < 2:
						judge = "Impossible"
						break
				print(judge)
		else:
			judge = "Possible"
			if a[0] * 2 != a[-1]:
				print("Impossible")
			else:
				judge = "Possible"
				if D[a[0]] != 1:
					judge = "Impossible"
				for i in range(a[0] + 1, a[-1] + 1):
					if D[i] < 2:
						judge = "Impossible"
						break
				print(judge)

if __name__ == '__main__':
	main()

Submission status: Wrong Answer

Solution code:
print("Possible")

Submission status: Wrong Answer

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

a.sort()
if a[0] != (a[-1]+1)//2:
    print("Impossible")
    exit()
# 一番小さい数字が何個か？
minnum = 0
for i in a:
    if i == a[0]:
        minnum += 1
if (max(a)) % 2 +1 != minnum:
    print("Impossible")
    exit()
num = [1]
for i in range(1,N):
    if a[i] == a[i-1]:
        num[-1] += 1
    elif abs(a[i-1] - a[i]) > 1:
        print("Impossible")
        exit()
    else:
        num.append(1)
for i in a[1:]:
    if i <= 1:
        print("Impossible")
        exit()

print("Possible")

Submission status: Wrong Answer

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

a.sort()
if a[0] != a[-1]//2:
    print("Impossible")
    exit()
# 一番小さい数字が何個か？
minnum = 0
for i in a:
    if i == a[0]:
        minnum += 1
if (max(a)) % 2 +1 != minnum:
    print("Impossible")
    exit()
num = [1]
for i in range(1,N):
    if a[i] == a[i-1]:
        num[-1] += 1
    elif abs(a[i-1] - a[i]) > 1:
        print("Impossible")
        exit()
    else:
        num.append(1)
for i in a[1:]:
    if i <= 1:
        print("Impossible")
        exit()

print("Possible")

Submission status: Wrong Answer

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

a.sort()
# 一番小さい数字が何個か？
minnum = 0
for i in a:
    if i == a[0]:
        minnum += 1
if (max(a)) % 2 +1 != minnum:
    print("Impossible")
    exit()
num = [1]
for i in range(1,N):
    if a[i] == a[i-1]:
        num[-1] += 1
    elif abs(a[i-1] - a[i]) > 1:
        print("Impossible")
        exit()
    else:
        num.append(1)
for i in a[1:]:
    if i <= 1:
        print("Impossible")
        exit()

print("Possible")

Submission status: Wrong Answer

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

a.sort()
# 一番小さい数字が何個か？
minnum = 0
for i in a:
    if i == a[0]:
        minnum += 1
if (max(a)+1) % 2 != minnum:
    print("Impossible")
    exit()
num = [1]
for i in range(1,N):
    if a[i] == a[i-1]:
        num[-1] += 1
    elif abs(a[i-1] - a[i]) > 1:
        print("Impossible")
        exit()
    else:
        num.append(1)
for i in a[1:]:
    if i <= 1:
        print("Impossible")
        exit()

print("Possible")

Submission status: Wrong Answer

Solution code:
from collections import Counter


def check(N, A):
    d = max(A)
    if d >= N:
        return False
    c = Counter(A)
    cnt = 0
    if d % 2 == 0:
        if c[d//2] != 1:
            return False
        cnt += 1
        mn = d//2+1
    else:
        if c[d//2+1] != 2:
            return False
        cnt += 2
        mn = d//2+2
    for i in range(mn, d+1):
        cnt += c[i]
    return cnt == len(A)


def main():
    N = int(input())
    A = list(map(int, input().split()))
    if check(N, A):
        print("Possible")
    else:
        print("Impossible")


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
cntA = Counter(A)
valA= list(set(A))
valA.sort()

if valA[-1] % 2 == 1:
    if valA[0] != -(-valA[-1] // 2):
        print('Impossible')
        exit()

    for a in range(valA[0], valA[-1] + 1):
        if cntA[a] < 2:
            print('Impossible')
            exit()
else:
    if valA[0] != valA[-1] // 2 or cntA[valA[0]] != 1:
        print('Impossible')
        exit()

    for a in range(valA[0] + 1, valA[-1] + 1):
        if cntA[a] < 2:
            print('Impossible')
            exit()

print('Possible')

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
N = int(input())
A = [int(x) for x in input().split()]
D = defaultdict(int)
for a in A:
  D[a] += 1
if D[1] > 2:
  print('Impossible')
elif D[1] == 2 and N > 2:
  print('Impossible')
elif D[min(A)] > 2:
  print('Impossible')
elif -(-max(A) // 2) != min(A):
  print('Impossible')
else:
  for a in range(min(A) + 1, max(A) + 1):
    if D[a] < 2:
      print('Impossible')
      break
  else:
    print('Possible')

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
N = int(input())
A = [int(x) for x in input().split()]
D = defaultdict(int)
for a in A:
  D[a] += 1
if D[1] > 2:
  print('Impossible')
elif D[1] == 2 and N > 2:
  print('Impossible')
elif D[min(A)] > 2:
  print('Impossible')
else:
  for a in range(min(A) + 1, max(A) + 1):
    if D[a] < 2:
      print('Impossible')
      break
  else:
    print('Possible')

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
N = int(input())
A = [int(x) for x in input().split()]
D = defaultdict(int)
for a in A:
  D[a] += 1
if D[min(A)] > 2:
  print('Impossible')
else:
  for a in range(min(A) + 1, max(A) + 1):
    if D[a] < 2:
      print('Impossible')
      break
  else:
    print('Possible')

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

c = Counter(a)
m = max(a)



flag = True

for i in range(1, m+1):
    if i<m//2:
        if c[i]!=0:
            flag = False
    elif i==m//2:
        if m%2 == 0:
            if c[i]!=1:
                flag = False
                break
        else:
            if c[i]!=0:
                flag = False
                break
    elif i == m//2+1:
        if m%2 == 0:
            if c[i]<2:
                flag = False
                break
        else:
            if c[i]!=2:
                flag = False
                break
    else:
        if c[i]<2:
            flag = False
        break

print('Possible' if flag else 'Impossible')

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

c = Counter(a)
m = max(a)



flag = True

for i in range(1, m+1):
    if i<m//2:
        if c[i]!=0:
            flag = False
    elif i==m//2:
        if m%2 == 0:
            if c[i]!=1:
                flag = False
                break
        else:
            if c[i]!=0:
                flag = False
                break
    elif i == m//2+1:
        if m%2 == 0:
            if c[i]<2:
                flag = False
                break
        else:
            if c[i]!=0:
                flag = False
                break
    else:
        if c[i]<2:
            flag = False
        break
if n ==2 and a==[1,1]:
    flag = True

print('Possible' if flag else 'Impossible')

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

c = Counter(a)
m = max(a)

flag = True

for i in range(1, m+1):
    if i<m//2:
        if c[i]!=0:
            flag = False
    elif i==m//2:
        if m%2 == 0:
            if c[i]!=1:
                flag = False
                break
        else:
            if c[i]!=0:
                flag = False
                break
    else:
        if c[i]<2:
            flag = False
        break

print('Possible' if flag else 'Impossible')

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

c = Counter(a)
m = max(a)

flag = True

for i in range(1, m+1):
    if i<=m//2:
        if c[i]>1:
            flag = False
    else:
        if c[i]<2:
            flag = False
        break
if m%2==0 and c[m//2]!=1:
    flag = False
print('Possible' if flag else 'Impossible')

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

c = Counter(a)
m = max(a)

flag = True

for i in range(m//2+1, m+1):
    if c[i]<2:
        flag = False
        break
if m%2==0 and c[m//2]!=1:
    flag = False
print('Possible' if flag else 'Impossible')

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

c = Counter(a)
m = max(a)

if m %2 == 1:
    for x in c:
        if c[x]<2:
            print('Impossible')
            exit()
else:
    for x in c:
        if x==m//2:
            if c[x]!=1:
                print('Impossible')
                exit()
        else:
            if c[x]<2:
                print('Impossible')
                exit()

print('Possible')

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
N=int(input())
A=list(map(int,input().split()))
def solve(N,A):
    dic=defaultdict(lambda: 0)
    for a in A:
        dic[a]+=1
    m=max(A)
    for i in range((m+1)//2,m+1):
        if m%2==0 and i==m//2:
            dic[i]-=1
        else:
            dic[i]-=2
    return not any([cnt<0 or (n<m//2+1 and cnt>0) for n,cnt in dic.items()])

print("Possible" if solve(N,A) else "Impossible")

Submission status: Wrong Answer

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

cnt = [0] * 100
for item in a:
    cnt[item] += 1

maxa = max(a)
mina = (maxa + 1) // 2

ans = True
for i in range(100):
    if i < mina:
        if(cnt[i] > 0):
            ans = False
    elif i == mina:
        if i == 1 and cnt[i] != 1:
            ans = False
        if i > 1 and not (cnt[i] == 1 or cnt[i] == 2):
            ans = False
    elif i > mina and i <= maxa: 
        if cnt[i] < 2:
            ans = False

if ans:
    print("Possible")
else:
    print("Impossible")

Submission status: Wrong Answer

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

from collections import deque, defaultdict
import itertools as ite
import sys
import math

sys.setrecursionlimit(1000000)

INF = 10 ** 18
MOD = 10 ** 9 + 7

N = input()
a = map(int, raw_input().split())

L = max(a)
m = defaultdict(int)
for num in a:
    if num < (L + 1) / 2:
        print "Impossible"
        exit()
    m[num] += 1
for num in range(L / 2 + 1, L + 1):
    if not num in m or m[num] < 2:
        print "Impossible"
        exit()
if L % 2 == 0 and (not L / 2 in m or m[L / 2] >= 2):
    print "Impossible"
    exit()
print "Possible"

Submission status: Wrong Answer

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

from collections import deque, defaultdict
import itertools as ite
import sys
import math

sys.setrecursionlimit(1000000)

INF = 10 ** 18
MOD = 10 ** 9 + 7

N = input()
a = map(int, raw_input().split())

L = max(a)
m = defaultdict(int)
for num in a:
    if num < (L + 1) / 2:
        print "Impossible"
        exit()
    m[num] += 1
for num in range(L / 2 + 1, L + 1):
    if not num in m or m[num] < 2:
        print "Impossible"
        exit()
if L % 2 == 0 and not L / 2 in m or m[L / 2] >= 2:
    print "Impossible"
    exit()
print "Possible"

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

maxA = max(As)
minA = (maxA+1) // 2
cnt = Counter(As)

for A, num in cnt.items():
    if A < minA:
        print('Impossible')
        break
    elif A == minA:
        if (maxA % 2 and num != 2) or (maxA % 2 == 0 and num != 1):
            print('Impossible')
            break
    elif num < 2:
        print('Impossible')
        break
else:
        print('Possible')

Submission status: Wrong Answer

Solution code:
N=int(input())
A=[int(i) for i in input().split()]
D=max(A)
L=[0]*(D+1)
for i in range(N):
  L[A[i]]+=1
if D==1:
  if N>2:
    print("Impossible")
    exit()
elif D%2==0:
  for i in range(D+1):
    if i<D//2 and L[i]>0:
      print("Impossible")
      exit()
    elif i==D//2 and L[i]!=1:
      print("Impossible")
      exit()
    elif i>D//2 and L[i]<2:
      print("Impossible")
      exit()
elif D%2==1:
  for i in range(D+1):
    if i<D//2 and L[i]>0:
      print("Impossible")
      exit()
    elif i>D//2 and L[i]<2:
      print("Impossible")
      exit()
print("Possible")

Submission status: Wrong Answer

Solution code:
N=int(input())
A=[int(i) for i in input().split()]
D=max(A)
L=[0]*(D+1)
for i in range(N):
  L[A[i]]+=1
if D%2==0:
  for i in range(D+1):
    if i<D//2 and L[i]>0:
      print("Impossible")
      exit()
    elif i==D//2 and L[i]!=1:
      print("Impossible")
      exit()
    elif i>D//2 and L[i]<2:
      print("Impossible")
      exit()
if D%2==1:
  for i in range(D+1):
    if i<D//2 and L[i]>0:
      print("Impossible")
      exit()
    elif i>D//2 and L[i]<2:
      print("Impossible")
      exit()
print("Possible")

Submission status: Wrong Answer

Solution code:
from collections import Counter as C
N = int(input())
A = [int(a) for a in input().split()]
B = C(A)
ma = max(B)
mi = min(B)

if ma==mi*2 and B[ma]>=2 and B[mi]==1:
    print("Possible")
    
elif ma==mi*2-1 and B[ma]>=2 and B[mi]==2:
    print("Possible")
    
else:
    print("Impossible")

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
m,s = a[-1],a[0]
if m!=a[-2] or (m+1)//2!=s or (m%2 and s-a[1]) or ((not m%2) and s==a[1]) or any(a.count(i)<2 for i in range(s+1,m)): print("Impossible")
else: print("Possible")

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
m,s = a[-1],a[0]
if m!=a[-2] or (m+1)//2!=s or (m%2 and s-a[1]) or ((not m%2) and s==a[1]) or any(a.count(i)==0 for i in range(s+1,m)): print("Impossible")
else: print("Possible")

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
ok = True

d_max = max(a)
if d_max > n - 1:
	ok = False
if n > 2 and d_max == 1:
	ok = False
if c[d_max] == 1:
	ok = False
else:
	if d_max % 2 == 0:
		d_min = d_max // 2
		if min(a) < d_min:
			ok = False
		if c[d_min] != 1:
			ok = False
		for d in range(d_min + 1, d_max):
			if c[d] < 2:
				ok = False

	else:
		d_min = (d_max + 1) // 2
		if min(a) < d_min:
			ok = False
		for d in range(d_min, d_max):
			if c[d] < 2:
				ok = False

if ok:
	print("Possible")
else:
	print("Impossible")

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
ok = True

d_max = max(a)
if n > 2 and d_max == 1:
	ok = False
if c[d_max] == 1:
	ok = False
else:
	if d_max % 2 == 0:
		d_min = d_max // 2
		if min(a) < d_min:
			ok = False
		if c[d_min] != 1:
			ok = False
		for d in range(d_min + 1, d_max):
			if c[d] < 2:
				ok = False

	else:
		d_min = (d_max + 1) // 2
		if min(a) < d_min:
			ok = False
		for d in range(d_min, d_max):
			if c[d] < 2:
				ok = False

if ok:
	print("Possible")
else:
	print("Impossible")

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
ok = True

d_max = max(a)
if n > 2 and d_max == 1:
	ok = False
if c[d_max] == 1:
	ok = False
else:
	if d_max % 2 == 0:
		d_min = d_max // 2
		if c[d_min] != 1:
			ok = False
		for d in range(d_min + 1, d_max):
			if c[d] < 2:
				ok = False

	else:
		d_min = (d_max + 1) // 2
		for d in range(d_min, d_max):
			if c[d] < 2:
				ok = False

if ok:
	print("Possible")
else:
	print("Impossible")

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
ok = True

d_max = max(a)
if c[d_max] == 1:
	ok = False
else:
	if d_max % 2 == 0:
		d_min = d_max // 2
		if c[d_min] != 1:
			ok = False
		for d in range(d_min + 1, d_max):
			if c[d] < 2:
				ok = False

	else:
		d_min = (d_max + 1) // 2
		for d in range(d_min, d_max):
			if c[d] < 2:
				ok = False

if ok:
	print("Possible")
else:
	print("Impossible")

Submission status: Wrong Answer

Solution code:
p = "Possible"
imp = "Impossible"

n = int(raw_input())
a = map(int, raw_input().split())
mx = max(a)
mn = min(a)
if mx == 1 and  mn == 1:
    if n == 2:
        print p
        exit()
    else:
        print imp
        exit()
cnt=[0] * 100
for i in xrange(n):
    cnt[a[i]] += 1
if mx % 2 == 0:
    if mx / 2 != mn:
        print imp
        exit()
    if cnt[mn] != 1:
        print imp
        exit()
    for i in xrange(mn + 1, mx + 1):
        if cnt[i] < 2:
            print imp
            exit()

else:
    if mx / 2 + 1 != mn:
        print imp
        exit()
    if cnt[mn] == 1:
        print imp
        exit()
    for i in xrange(mn + 1, mx + 1):
        if cnt[i] < 2:
            print imp
            exit()
print p

Submission status: Wrong Answer

Solution code:
p = "Possible"
imp = "Impossible"

n = int(raw_input())
a = map(int, raw_input().split())
mx = max(a)
mn = min(a)
if mx == mn:
    if n == 2:
        print p
        exit()
    else:
        print imp
        exit()
cnt=[0] * 100
for i in xrange(n):
    cnt[a[i]] += 1
if mx % 2 == 0:
    if mx / 2 != mn:
        print imp
        exit()
    if cnt[mn] != 1:
        print imp
        exit()
    for i in xrange(mn + 1, mx + 1):
        if cnt[i] < 2:
            print imp
            exit()

else:
    if mx / 2 + 1 != mn:
        print imp
        exit()
    if cnt[mn] == 1:
        print imp
        exit()
    for i in xrange(mn + 1, mx + 1):
        if cnt[i] < 2:
            print imp
            exit()
print p

Submission status: Wrong Answer

Solution code:
p = "Possible"
imp = "Impossible"

n = int(raw_input())
a = map(int, raw_input().split())
mx = max(a)
mn = min(a)
cnt=[0]*100
for i in xrange(n):
    cnt[a[i]] += 1
if mx % 2 == 0:
    if mx / 2 != mn:
        print imp
        exit()
    if cnt[mn] != 1:
        print imp
        exit()
    for i in xrange(mn+1, mx+1):
        if cnt[i] < 2:
            print imp
            exit()

else:
    if mx / 2 + 1 != mn:
        print imp
        exit()
    if cnt[mn] == 1:
        print imp
        exit()
    for i in xrange(mn+1, mx+1):
        if cnt[i] < 2:
            print imp
            exit()
print p

Submission status: Wrong Answer

Solution code:
def solve():
    n=int(input())
    a=list(map(int,input().split()))
    a.sort()
    mina=a[0]
    maxa=a[-1]
    if (a[-1]+1) // 2 != mina:
        return False

    b=[0]*n
    for v in a:
        b[v] += 1
    if (maxa & 1) > 0:
        if b[mina] < 2:
            return False
    elif b[mina] > 1:
        return False

    for v in range(mina+1, maxa+1):
        if b[v] < 2:
            return False
    return True

print('Possible' if solve() else 'Impossible')

Submission status: Wrong Answer

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

def resolve(a):
    if a == [1, 1]:
        return True

    if a.count(1) >= 2:
        return False

    max_num = max(a)
    min_num = min(a)

    if a.count(max_num) < 2:
        return False

    if max_num / 2 > min_num:
        return False

    if max_num & 1:
        # 奇数
        if a.count(min_num) > 2:
            return False
    else:
        # 偶数
        if a.count(min_num) > 1:
            return False
    return True

print("Possible" if resolve(a) else "Impossible")

Submission status: Wrong Answer

Solution code:
n=int(raw_input())
a=map(int,raw_input().split())
maxa=max(a)
cmaxa=a.count(maxa)
ca=[0]*(maxa+1)
for i in xrange(n):
    ca[a[i]]+=1
if maxa%2==1:
    l=maxa/2+1
    if a.count(l)==2:
        for i in xrange(n):
            if a[i]<l or ca[a[i]]<2:
                print("Impossible")
                exit()
        print("Possible")
    else:
        print("Impossible")
else:
    l=maxa/2
    if a.count(l)==1:
        for i in xrange(n):
            if a[i]<l:
                print("Impossible")
                exit()
            if a[i]!=l and ca[a[i]]<2:
                print("Impossible")
                exit()
        print("Possible")
    else:
        print("Impossible")

Submission status: Wrong Answer

Solution code:
n=int(raw_input())
a=map(int,raw_input().split())
maxa=max(a)
cmaxa=a.count(maxa)
ca=[0]*(maxa+1)
for i in xrange(n):
    ca[a[i]]+=1
if maxa%2==1:
    l=maxa/2+1
    if a.count(l)==2:
        for i in xrange(n):
            if a[i]<l or ca[a[i]]<2:
                print("Impossible")
                exit()
        print("Possible")
    else:
        print("Impossible")
else:
    l=maxa/2
    if a.count(l)==1:
        for i in xrange(n):
            if a[i]<l or ca[a[i]]<2:
                print("Impossible")
                exit()
            if a[i]!=l and ca[a[i]]<2:
                print("Impossible")
                exit()
        print("Possible")
    else:
        print("Impossible")

Submission status: Wrong Answer

Solution code:
n=int(raw_input())
a=map(int,raw_input().split())
maxa=max(a)
cmaxa=a.count(maxa)
ca=[0]*(maxa+1)
for i in xrange(n):
    ca[a[i]]+=1
if cmaxa==1:
    print("Impossible")
    exit()
if maxa%2==1:
    l=maxa/2+1
    if a.count(l)==2:
        for i in xrange(n):
            if a[i]<l or ca[a[i]]<2:
                print("Impossible")
                exit()
        print("Possible")
    else:
        print("Impossible")
else:
    l=maxa/2
    if a.count(l)==1:
        for i in xrange(n):
            if a[i]<l or ca[a[i]]<2:
                print("Impossible")
                exit()
        print("Possible")
    else:
        print("Impossible")