fork download
  1. import sys
  2. input = sys.stdin.readline
  3.  
  4. N = int(input())
  5. SS = input().strip()
  6. SK = input().strip()
  7. SH = input().strip()
  8.  
  9. ans = []
  10. scoreS = scoreK = scoreH = 0
  11.  
  12. for i in range(N):
  13. s, k, h = SS[i], SK[i], SH[i]
  14.  
  15. if s == k == h:
  16. # 셋 다 같으면 -> 제3문자 (아무도 점수 안 받음)
  17. c = 'z' if s != 'z' else 'y'
  18.  
  19. elif s == k and s != h:
  20. # 숭=고, 한 다름
  21. # 숭>고 관계 유지가 힘듦 -> 제3문자로 점수 안 줌
  22. c = 'z' if s != 'z' else 'y'
  23.  
  24. elif s == h and s != k:
  25. # 숭=한, 고 다름
  26. # 여기서 고를 선택해 주면 고 점수만 +1 가능
  27. c = k
  28. scoreK += 1
  29.  
  30. elif k == h and s != k:
  31. # 고=한, 숭 다름
  32. # 숭 선택 -> 숭만 점수
  33. c = s
  34. scoreS += 1
  35.  
  36. else:
  37. # 셋 다 다름
  38. # 숭 선택 -> 숭 점수만
  39. c = s
  40. scoreS += 1
  41.  
  42. ans.append(c)
  43.  
  44. # 최종 점수 계산
  45. scoreS = sum(1 for i in range(N) if ans[i] == SS[i])
  46. scoreK = sum(1 for i in range(N) if ans[i] == SK[i])
  47. scoreH = sum(1 for i in range(N) if ans[i] == SH[i])
  48.  
  49. if scoreS > scoreK > scoreH:
  50. print("".join(ans))
  51. else:
  52. print(-1)
Success #stdin #stdout 0.1s 14092KB
stdin
5
abcde
efgtb
abgte
stdout
-1