output_description: If A is a divisor of B, print A + B; otherwise, print B - A.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      A B
attempt: import numpy as np
  
  # initialization
  nmatch = np.array([0, 2, 5, 5, 4, 5, 6, 3, 7, 6])
  N, M = map(int, input().split())
  dp = [-1] * (N + 1)  # contains the number of digits it can make
  dp[0] = 0
  ff = np.array(list(map(int, input().split()))).reshape(-1, 1)
  fg = nmatch[ff].reshape(-1, 1)
  Atemp = np.concatenate([ff, fg], axis=1)
  index0 = np.argsort(Atemp[:, 0])
  index1 = np.argsort(Atemp[:, 1])
  A = Atemp[index1]  # sorted by the number of matches: ascending
  B = Atemp[index0]
  B = B[::-1]  # sorted by the number: descending
  for i in range(1, N + 1):
      for k in range(M):
          j = A[k, 1]
          i_old = i - j  # available matches
          if (i - j) < 0:
              break
          if (i - j) == 0 and dp[i] == -1:
              dp[i] = 1
          if dp[i_old] != -1 and dp[i_old] + 1 > dp[i]:
              dp[i] = dp[i_old] + 1
  # print(dp)
  ndigits = dp[N]
  j = N
  final_number = ""
  for l in range(ndigits, 0, -1):
      index = 0
      while True:
          temp_j = j - B[index, 1]
          if temp_j < 0:
              index += 1
              continue
          if dp[temp_j] + 1 == dp[j]:
              final_number += str(B[index, 0])
              j = temp_j
              break
          else:
              index += 1
          if index > M:
              break
  print(int(final_number))
  
problem_description: Statement
  
  You are given positive integers A and B.
  
  If A is a divisor of B, print A + B; otherwise, print B - A.
samples: [{"input": "4 12", "output": "16\n    \n\nAs 4 is a divisor of 12, 4 + 12 = 16 should be printed.\n\n* * *"}, {"input": "8 20", "output": "12\n    \n\n* * *"}, {"input": "1 1", "output": "2\n    \n\n1 is a divisor of 1."}]