fork download
  1. # your code goes here
  2. from itertools import permutations
  3. t = int(input())
  4. l = []
  5. ans = []
  6. for i in range(t):
  7. s = input()
  8. l.append(s)
  9. res = list(permutations(l))
  10. for x in res:
  11. i = 0
  12. j = i+1
  13. c = 0
  14. for k in range(len(x)):
  15. if j < len(x):
  16. first_set = set(x[i])
  17. second_set = set(x[j])
  18. overlap = first_set.intersection(second_set)
  19. c += len(overlap)
  20. # print(x[i],x[j],c)
  21. i += 1
  22. j += 1
  23. ans.append(c)
  24. print(min(ans))
  25.  
Success #stdin #stdout 0.03s 9184KB
stdin
4
XYZ
XYZ
ABYZ
Z
stdout
4