new_contents: import sys
  import math
  
  # Auto-generated code below aims at helping you parse
  # the standard input according to the problem statement.
  
  n = int(input())
  words = []
  for i in range(n):
      w = input()
      words.append(w)
  letters = input()
  letters = list(letters)
  
  most = 0
  out = ""
  value = {'e':1,'a':1,'i':1,'o':1,'n':1,'r':1,'t':1,'l':1,'s':1,'u':1,'d':2,'g':2,'b':3,'c':3,'m':3,'p':3,'f':4,'h':4,'v':4,'w':4,'y':4,'k':5,'j':8,'x':8,'q':10,'z':10}
  
  for word in words:
      temp = list(letters)
      fail = 0
      total = 0
      for char in word:
          if char in temp:
              temp.remove(char)
              total += value[char]
          else:
              fail = 1
              break
      if (fail == 0 and total > most):
          most = total
          out = word
  
  # Write an action using print
  # To debug: print("Debug messages...", file=sys.stderr)
  
  print(out)
  
subject: Create scrabble.py