SP33773 ADAHLIA - Ada and Dahlia

Description

As you might already know, Ada the Ladybug is a farmer. Beside fruit and vegetable, Ada grows flowers. At the moment she plans to go to a competition with her dahlias. The evaluation of bunch of dahlias is simple: Jury sorts all dahlias by the diameters of blooms and takes the maximal difference between any two adjacent dahlias. This will be the score. The problems is that Ada's flowers are not in sorted order and she wants to know what score she would get if the passes all flowers to jury. To make job easier for you (or at least Ada hopes so), she created a formula which will give you the diameters of blooms (0 to N-1) in actual order: **A $ _{i+1} $ =(a\*A $ _{i} $ +b)%c**.

Input Format

The first and the only line contains five integers (**N,a,b,c,A $ _{0} $** ): **2 , the number of flowers, and **0 , **1 , 0******

Output Format

Output the maximum difference of elements (if they would be sorted).