def lscan; gets.split.map(&:to_i); end a,b,c,d,k = lscan p (a*b+c-d)%k