output_description: Print the maximum possible total value of the selected items.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N W
      w_1 v_1
      w_2 v_2
      :
      w_N v_N
attempt: N, W = map(int, input().split())
  WV = [list(map(int, input().split())) for _ in range(N)]
  
  Wdic = {}
  for w in WV:
      if w[0] not in Wdic:
          Wdic[w[0]] = [w]
      else:
          Wdic[w[0]].append(w)
  
  Wcount = [[0 for _ in range(2)] for _ in range(4)]
  idx = 0
  for k in Wdic.keys():
      Wcount[idx] = [k, len(Wdic[k])]
      idx += 1
  # print(Wcount)
  
  Wsum = {}
  for k, v in Wdic.items():
      v.sort(key=lambda x: x[1], reverse=True)
      Wsum[k] = [v[0][1]]
      for i in range(1, len(v)):
          Wsum[k].append(Wsum[k][-1] + v[i][1])
  # print(Wsum)
  
  
  def check(i, j, k, l):
      ret = 0
      w = 0
      if i > 0 and Wcount[0][0] > 0:
          ret += Wsum[Wcount[0][0]][i - 1]
          w += Wcount[0][0] * i
      if j > 0 and Wcount[1][0] > 0:
          ret += Wsum[Wcount[1][0]][j - 1]
          w += Wcount[1][0] * j
      if k > 0 and Wcount[2][0] > 0:
          ret += Wsum[Wcount[2][0]][k - 1]
          w += Wcount[2][0] * j
      if l > 0 and Wcount[3][0] > 0:
          ret += Wsum[Wcount[3][0]][l - 1]
          w += Wcount[3][0] * l
      if w > W:
          ret = 0
      return ret
  
  
  value = 0
  for i in range(Wcount[0][1] + 1):
      for j in range(Wcount[1][1] + 1):
          for k in range(Wcount[2][1] + 1):
              for l in range(Wcount[3][1] + 1):
                  value = max(value, check(i, j, k, l))
  print(value)
  
problem_description: Statement
  
  You have N items and a bag of strength W. The i-th item has a weight of w_i
  and a value of v_i.
  
  You will select some of the items and put them in the bag. Here, the total
  weight of the selected items needs to be at most W.
  
  Your objective is to maximize the total value of the selected items.
samples: [{"input": "4 6\n    2 1\n    3 4\n    4 10\n    3 4", "output": "11\n    \n\nThe first and third items should be selected.\n\n* * *"}, {"input": "4 6\n    2 1\n    3 7\n    4 10\n    3 6", "output": "13\n    \n\nThe second and fourth items should be selected.\n\n* * *"}, {"input": "4 10\n    1 100\n    1 100\n    1 100\n    1 100", "output": "400\n    \n\nYou can take everything.\n\n* * *"}, {"input": "4 1\n    10 100\n    10 100\n    10 100\n    10 100", "output": "0\n    \n\nYou can take nothing."}]