Add the first n terms of a geometric sequence with first term a and ratio r, then print the sum modulo mod.
A geometric sequence has first term aaa and common ratio rrr. Add its first nnn terms and find the remainder of that total divided by mod\text{mod}mod.
That is, print a+ar+ar2+⋯+arn−1a + ar + ar^2 + \cdots + ar^{n-1}a+ar+ar2+⋯+arn−1 modulo mod\text{mod}mod.
The first line contains aaa, rrr, nnn, and mod\text{mod}mod, separated by spaces. All four are natural numbers greater than or equal to 111 and less than or equal to 10910^9109.
On the first line, print the remainder of the sequence sum divided by mod\text{mod}mod.