In Chef's house there are N apples lying in a row on the floor. These apples are numbered from 1 (left most one) to N (right most one). The types of apples are also numbered by positive integers, and the type of apple i is Ti.
Chef has recently brought two trained dogs. Both of the dogs are too intelligent to know the smell of each type of apple. If Chef gives a dog an integer x, and releases it at one end of the row of apples, then the dog smells each apple one by one. Once the dog find an apple of type x, the dog picks the apple and back to Chef's room immidiately. If there is no apple of type x, then the dog will back without any apples.
Now Chef wants to eat two apples as soon as possible. Here the apples must have distinct types, and the sum of the types must be equal to K. Chef can release the dogs from either of the ends, namely, he can leave (both at left end) or (both at right end) or (one at left end and one at right end) and he can release them at the same time. The dogs take one second to smell each apple. However the dogs can run rapidly, so the time for moving can be ignored. What is the minimum time (in seconds) to get the desired apples from his dogs?

-----Input-----
The first line of input contains two space-separated integers N and K, denoting the number of apples and the required sum respectively. Then the next line contains N space-separated integers T1, T2, ..., TN, denoting the types of the apples.

-----Output-----
Print one integer describing the minimum number of seconds that Chef needs to wait till he gets the desired apples. If Chef cannot get the desired apples, then output "-1" without quotes.

-----Constraints-----
- 2 ≤ N ≤ 500000 (5 × 105)
- 1 ≤ K ≤ 1000000 (106)
- 1 ≤ Ti ≤ 1000000 (106)

-----Example-----
Sample Input 1:
5 5
2 4 3 2 1

Sample Output 1:
2

Sample Input 2:
5 5
2 4 9 2 5

Sample Output 2:
-1

-----Explanation-----
In the first example, if Chef leaves the first dog from left and gives it integer 4, and the second dog from right and gives it integer 1, then the first dog takes 2 seconds and the second dog takes 1 second to get the apples. Thus Chef needs to wait 2 seconds. In any other way, Chef can't get the desired apples in less than 2 seconds.
In the second example, Chef cannot get two apples such that the sum of their types is 5 so the answer is "-1".

Difficulty: interview

Starter code:

Solutions:
def main():
 N, K = list(map(int, input().split()))
 
 Apples = [int(x) for x in input().split()]
 
 time = 0 # answer
 # Apples_encountered = [None]  # Binary Search Tree 
 
 distinct_apples_condition = None if K & 1 else K >> 1 
 
 already_found = [False] * K 
 
 for i in range((N >> 1) + 1):
  time += 1 
  for k in (Apples[i], Apples[N - i - 1]):
   if k < K and k != distinct_apples_condition:
    if already_found[K - k - 1]:
     # print(K, k)
     # print(already_found)
     return time 
    already_found[k - 1] = True
  
 
 return -1 


print(main())
 
 
 
 
 


def main():
 N, K = list(map(int, input().split()))
 
 Apples = [int(x) for x in input().split()]
 
 time = 0 # answer
 # Apples_encountered = [None]  # Binary Search Tree 
 
 distinct_apples_condition = None if K & 1 else K >> 1 
 
 already_found = [False] * K 
 
 for i in range((N >> 1) + 1):
  time += 1 
  for k in (Apples[i], Apples[N - i - 1]):
   if k < K and k != distinct_apples_condition:
    if already_found[K - k - 1]:
     # print(K, k)
     # print(already_found)
     return time 
    already_found[k - 1] = True
  
 
 return -1 


print(main())
 
 
 
 
 




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

la = list(map(int,input().split()))

# l = []
#
# for i in range(len(la)):
#        l.append([la[i],i])
# l.sort()
mini = 10**18
# i = 0
# j = len(l)-1
# # print(l)
# while i<j:
#     if l[i][0]+l[j][0]<k:
#         i+=1
#     elif l[i][0]+l[j][0]>k:
#         j-=1
#     else:
#         if l[i][0]+l[j][0]==k:
#
#             z1,z2 = max(l[i][1],l[j][1]),min(l[i][1],l[j][1])
#             ans1 = max(z1,z2)+1
#             ans2 = max(n-z1,n-z2)
#             ans3 = max(n-z1,z2+1)
#             ans4 = max(z1+1,n-z2)
#             # print(l[i][0],l[j][0])
#             if l[i][0]!=l[j][0]:
#              mini = min(mini,ans1,ans2,ans3,ans4)
#             j-=1
#             i+=1
#
# if mini == 10**18:
#     print(-1)
# else:
#     print(mini)

#
# from collections import defaultdict
# INF = float("inf")
#
# n,k = map(int,input().split())
# t = list(map(int,input().split()))
# d = defaultdict(int)
# for i in range(n):
#     x = i+1 if i<n/2 else n-i
#     if d[t[i]]:
#         d[t[i]] = min(d[t[i]],x)
#     else:
#         d[t[i]] = x
# ans = INF
# for i in range(n):
#     if d[k-t[i]] and t[i] != k-t[i]:
#         ans = min(ans,max(d[k-t[i]],d[t[i]]))
# print(-1 if ans == INF else ans)
#
#
#
from collections import defaultdict

hash = defaultdict(int)

for i in range(len(la)):
 z1 = i+1
 z2 = n-i
 z = min(z1,z2)
 if la[i] in hash:
  hash[la[i]] = min(z,hash[la[i]])
 else:
  hash[la[i]] = z

for i in range(len(la)):
 z = k-la[i]
 if z in hash and z!=la[i]:
  ans = max(hash[z],hash[la[i]])
  mini = min(mini,ans)





if mini == 10**18:
 print(-1)
else:
 print(mini)