This page is still under construction.

Parts of this page are still being built. What you see may change.

Bacteria

Time limit1sMemory limit1024 MB

Summary
Each adult produces one young per second while young mature into adults; find the total population after T seconds modulo K, given initial counts.
Level

Medium6 of 10

Topics
Math, Combinatorics, Dynamic programming, Number theory
Solved
No attempts yet

Problem

Juku forgot to brush his teeth in the evening, and bacteria began multiplying in his mouth. Each bacterium is either young or adult. Every second, each adult produces one new young bacterium, and a newly born young bacterium becomes an adult during the next second. No bacterium ever dies.

If there are initially NN young and VV adult bacteria, find how many bacteria (young and adult combined) are in Juku's mouth after TT seconds. Instead of the actual count, output the remainder when it is divided by the given number KK.

Input

A single line contains four space-separated integers NN, VV, TT, and KK (0≤N≤1090 \le N \le 10^9, 0≤V≤1090 \le V \le 10^9, 0≤T≤10180 \le T \le 10^{18}, 0<K≤1090 < K \le 10^9).

Output

Output the value (X mod K)(X \bmod K) on a single line, where XX is the total number of bacteria in Juku's mouth after TT seconds and " mod \bmod" denotes the remainder of the division.

Examples2

  1. Example 1

    Input
    1 3 2 100
    
    Expected output
    11
    
  2. Example 2

    Input
    0 10 1 20
    
    Expected output
    0