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 copy
  
  n, m = map(int, input().rstrip().split())
  number_list = list(map(int, input().rstrip().split()))
  number_list.sort()
  match = [2, 5, 5, 4, 5, 6, 3, 7, 6]
  new_match = []
  answer = []
  
  for i in number_list:
      new_match.append(match[i - 1])
  
  
  for index in range(m):
      value = new_match[index]
      new_match_tmp = copy.copy(new_match)
      new_match_tmp.remove(value)
      maximum = max(new_match_tmp)
      # 商と余りを計算
      quotient = int(n / value)
      remainder = n % value
      answer_tmp = [number_list[index]] * quotient
      # 余りがあるなら余りをなくすように組み合わせを考える
      if remainder != 0:
          while True:
              quotient -= 1
              remainder += value
              answer_tmp.pop(0)
              if remainder in new_match:
                  answer_tmp.append(number_list[new_match.index(remainder)])
                  break
              elif remainder > maximum:
                  try:
                      minimum = min(new_match_tmp)
                      remainder -= minimum
                      answer_tmp.append(number_list[new_match.index(minimum)])
                  except:
                      answer_tmp = []
                      break
              if remainder == n:
                  answer_tmp = []
                  break
  
      if len(answer_tmp) != 0:
          answer.append(answer_tmp)
  
  answer.sort(key=lambda x: len(x), reverse=True)
  ans = reversed(answer[0])
  
  print(*ans, sep="")
  print()
  
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."}]