output_description: Print the minimum possible value of Z, where Z is the largest ugliness of the
  N pairs.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N M
      a_1 a_2 \cdots a_{2N}
attempt: N, M = map(int, input().split())
  A = map(int, input().split())
  size = 2 * A
  
  MOD_A = []
  for a in A:
      MOD_A.append(a % M)
  
  ans = 0
  MOD_A.sort(reverse=True)
  while len(MOD_A) > 0:
      ma = MOD_A.pop(0)
      diff = M - ma
      lb = 0
      rb = len(MOD_A) - 1
      while rb - lb > 1:
          mid = (lb + rb) / 2
          if MOD_A[mid] > diff:
              rb = mid
          else:
              lb = mid
      ans += (ma + MOD_A[lb]) % M
      MOD_A.pop(lb)
  print(ans)
  
problem_description: Statement
  
  Let M be a positive integer.
  
  You are given 2 N integers a_1, a_2, \ldots, a_{2 N}, where 0 \leq a_i < M for
  each i.
  
  Consider dividing the 2 N integers into N pairs. Here, each integer must
  belong to exactly one pair.
  
  We define the _ugliness_ of a pair (x, y) as (x + y) \mod M. Let Z be the
  largest ugliness of the N pairs. Find the minimum possible value of Z.
samples: [{"input": "3 10\n    0 2 3 4 5 9", "output": "5\n    \n\nOne solution is to form pairs (0, 5), (2, 3) and (4, 9), with ugliness 5, 5\nand 3, respectively.\n\n* * *"}, {"input": "2 10\n    1 9 1 9", "output": "0\n    \n\nPairs (1, 9) and (1, 9) should be formed, with ugliness both 0."}]