A, B, C, D, E = map(int, input().split()) n = B - C if n == 0: print(0) exit() if n == 1: print(D) exit() acc = D x = D for i in range(1, n): if i%10 != 0: acc += x elif i%10 == 0 and x > E: x -= E acc += x elif i%10 == 0 and x < E: acc += x print(acc)