fork download
  1. def happiness(A, B, n):
  2. return sum(x in n for x in A) - sum(x in n for x in B)
  3.  
  4. def get_data(prompt=""):
  5. return [int(x) for x in input(prompt).split()]
  6.  
  7. def test(A, B, n, expected):
  8. print(f"A={A} B={B} n={n}")
  9. r = happiness(A, B, n)
  10. success = "SUCCESS" if r == expected else "FAILURE"
  11. print(f"{success}: r={r} expected={expected}")
  12.  
  13. test([1, 2, 4], [1, 3, 5], [3], -1)
  14. test([1, 2, 4], [1, 3, 5], [2], 1)
  15. test([1, 2, 4], [1, 3, 5], [1, 2, 4, 5], 1)
  16.  
  17. print("------")
  18. print(happiness(get_data(), get_data(), get_data()))
  19.  
Success #stdin #stdout 0.02s 9236KB
stdin
1 2 4
1 3 5
1 2 4 5
stdout
A=[1, 2, 4] B=[1, 3, 5] n=[3]
SUCCESS: r=-1 expected=-1
A=[1, 2, 4] B=[1, 3, 5] n=[2]
SUCCESS: r=1 expected=1
A=[1, 2, 4] B=[1, 3, 5] n=[1, 2, 4, 5]
SUCCESS: r=1 expected=1
------
1