import strutils, sequtils let v = stdin.readLine.split.map(parseInt) (a, b, c, d, m) = (v[0], v[1], v[2], v[3], v[4]) var ans = 0 for x in countup(a, b): for y in countup(c, d): ans = max(ans, (x + y) mod m) echo ans