output_description: Print the maximum total number of ingredients that Snuke's N servings of
  Skewer Meal can hold.
  
  * * *
input_description: The input is given from Standard Input in the following format:
  
      
      
      N
      L_1 L_2 ... L_{2N}
attempt: # 座標平面に落とし込んで再帰関数で無理やり計算
  # import numpy as np
  import sys
  
  sys.setrecursionlimit(10**5)
  N, X = map(int, input().split())
  if 2 * X > N:  # 対称性
      X = N - X
  
  # 座標の作成
  dp = [[-1] * (N + 3)]
  for i in range(N + 1):
      tmp = [-1]
      for j in range(N + 1):
          if i <= j:
              tmp.append(0)  # 到達していないマス
          else:
              tmp.append(-1)  # 壁(範囲外)
      tmp.append(-1)
      tmp.reverse()
      dp.append(tmp)
  dp.append([-1] * (N + 3))
  # print (np.array(dp))
  
  
  # m: 0:右へ, 1:左下へ, 2:左上へ
  def moving(x, y, total, m):
      if x == X and y == 1 and dp[x][y] == 1:  # 一周回ってもとの座標に戻ってきた時
          # print ('D')
          return total
      if m == 0:  # 右に動く時
          tmp = 0
          while dp[x - 1][y + 1] == 0:  # 右に進める時
              dp[x - 1][y + 1] = 1  # 右進んだマスを到達したことにする
              tmp += 1
              x -= 1
              y += 1
          if dp[x - 1][y + 1] == -1:  # 右側が壁の時-->左下に進む
              # print ('1-B')
              return moving(x, y, total + tmp, 1)
          if dp[x - 1][y + 1] == 1:  # 右側が光の線の時-->左上へ進む
              tmp += 1
              # print ('1-C')
              return moving(x - 1, y + 1, total + tmp, 2)
  
      if m == 1:  # 左下へ動く時
          tmp = 0
          while dp[x + 1][y] == 0:  # 左下に進める時
              dp[x + 1][y] = 1
              tmp += 1
              x += 1
          if dp[x + 1][y] == -1:  # 左下が壁の時-->左上に進む
              # print ('2-C')
              return moving(x, y, total + tmp, 2)
          if dp[x + 1][y] == 1:  # 左下が光の線の時-->左上に進む
              tmp += 1
              # print ('2-C')
              return moving(x + 1, y, total + tmp, 2)
  
      if m == 2:  # 左上に動く時
          tmp = 0
          while dp[x][y - 1] == 0:  # 左上に進める時
              dp[x][y - 1] = 1
              tmp += 1
              y -= 1
          if dp[x][y - 1] == -1:  # 左上が壁の時-->右に進む
              # print ('3-A')
              return moving(x, y, total + tmp, 0)
          if dp[x][y - 1] == 1:  # 左上が光の線の時-->左下に進む
              tmp += 1
              # print ('3-B')
              return moving(x, y - 1, total + tmp, 1)
  
  
  X += 1
  print(moving(X, 1, 0, 0))
  # print (np.array(dp))
  
problem_description: Statement
  
  Snuke is having a barbeque party.
  
  At the party, he will make N servings of _Skewer Meal_.
  
  ![](https://agc001.contest.atcoder.jp/img/agc/001/Gg9pvPKw/abbq.png)
  
  Example of a serving of Skewer Meal
  
  He has a stock of 2N skewers, all of which will be used in Skewer Meal. The
  length of the i-th skewer is L_i. Also, he has an infinite supply of
  ingredients.
  
  To make a serving of Skewer Meal, he picks 2 skewers and threads ingredients
  onto those skewers. Let the length of the shorter skewer be x, then the
  serving can hold the maximum of x ingredients.
  
  What is the maximum total number of ingredients that his N servings of Skewer
  Meal can hold, if he uses the skewers optimally?
samples: [{"input": "2\n    1 3 1 2", "output": "3\n    \n\nIf he makes a serving using the first and third skewers, and another using the\nsecond and fourth skewers, each serving will hold 1 and 2 ingredients, for the\ntotal of 3.\n\n* * *"}, {"input": "5\n    100 1 2 3 14 15 58 58 58 29", "output": "135"}]