output_description: Print `YES` or `NO`.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      A B C
attempt: N, W = list(map(int, input().split()))
  v = [[], [], [], []]
  kosu = [0, 0, 0, 0]
  kr = list(map(int, input().split()))
  v[0].append(kr[1])
  w0 = kr[0]
  for i in range(1, N):
      kr = list(map(int, input().split()))
      v[kr[0] - w0].append(kr[1])
  for i in range(4):
      v[i].sort()
      v[i].reverse()
  kos = [len(v[0]), len(v[1]), len(v[2]), len(v[3])]
  kk = [-1] * ((kos[0] + 1) * (kos[1] + 1) * (kos[2] + 1) * (kos[3] + 1))
  
  
  def toru(a, b, c, d, nw):
      global kk
      if kk[a + (kos[0] + 1) * (b + ((kos[1] + 1) * (c + (kos[2] + 1) * d)))] != -1:
          return kk[a + (kos[0] + 1) * (b + ((kos[1] + 1) * (c + (kos[2] + 1) * d)))]
      max = 0
      if a < kos[0] and W >= nw + w0 and max < toru(a + 1, b, c, d, nw + w0) + v[0][a]:
          max = toru(a + 1, b, c, d, nw + w0) + v[0][a]
      if (
          b < kos[1]
          and W >= nw + w0 + 1
          and max < toru(a, b + 1, c, d, nw + w0 + 1) + v[1][b]
      ):
          max = toru(a, b + 1, c, d, nw + w0 + 1) + v[1][b]
      if (
          c < kos[2]
          and W >= nw + w0 + 2
          and max < toru(a, b, c + 1, d, nw + w0 + 2) + v[2][c]
      ):
          max = toru(a, b, c + 1, d, nw + w0 + 2) + v[2][c]
      if (
          d < kos[3]
          and W >= nw + w0 + 3
          and max < toru(a, b, c, d + 1, nw + w0 + 3) + v[3][d]
      ):
          max = toru(a + 1, b, c, d + 1, nw + w0 + 3) + v[3][d]
      kk[a + (kos[0] + 1) * (b + ((kos[1] + 1) * (c + (kos[2] + 1) * d)))] = max
      return max
  
  
  maxv = toru(0, 0, 0, 0, 0)
  
  print(maxv)
  
problem_description: Statement
  
  You are given three strings A, B and C. Check whether they form a _word
  chain_.
  
  More formally, determine whether both of the following are true:
  
    * The last character in A and the initial character in B are the same.
    * The last character in B and the initial character in C are the same.
  
  If both are true, print `YES`. Otherwise, print `NO`.
samples: [{"input": "rng gorilla apple", "output": "YES\n    \n\nThey form a word chain.\n\n* * *"}, {"input": "yakiniku unagi sushi", "output": "NO\n    \n\nA and B form a word chain, but B and C do not.\n\n* * *"}, {"input": "a a a", "output": "YES\n    \n\n* * *"}, {"input": "aaaaaaaaab aaaaaaaaaa aaaaaaaaab", "output": "NO"}]