fork download
  1. def min_beads(a, b, c, k):
  2. return (k + 2) // 2 if k <= a + b + c - k else (a + b + c + 1) // 2
  3.  
  4. a, b, c, k = map(int, input().split())
  5. print(min_beads(a, b, c, k))
  6.  
Success #stdin #stdout 0.03s 9804KB
stdin
2 4 6 3
stdout
2