# RabbitLunch

Time Limit : 8 sec, Memory Limit : 65536 KB

## Problem F: RabbitLunch

͒Hɂɂ񂶂ƃLEC1 Hׂ. ͂ƂĂIȂ̂, Hׂɂ񂶂̎ނLEC̎ނł悤, قȂ2 Ĉ݂Ă͂ȂȂ.

ɂ񂶂 $M$ ނ. $i$ ޖڂ̂ɂ񂶂 $m_i$ . LEC $N$ ނ. $i$ ޖڂ̃LEC $n_i$ . ő剽ĈHƂ邩߂.

$m_i$ $n_i$ ͎̑QpĐ.

• $m_0 = m0$
• $m_{i+1} = (m_i * 58 + md )$ mod $(N + 1)$
• $n_0 = n0$
• $n_{i+1} = (n_i * 58 + nd )$ mod $(M + 1)$

### Constraints

• $M$ will be between 1 and 2,500,000, inclusive.
• $N$ will be between 1 and 2,500,000, inclusive.
• $m0$ and $md$ will be between 0 and $N$, inclusive.
• $n0$ and $nd$ will be between 0 and $M$, inclusive.

### Input

͈͂ȉ̌ŗ^:

$M$ $N$ $m0$ $md$ $n0$ $nd$

### Output

HƂ邤̕C̍ől\ 1 sɏo͂.

### Sample Input 1

2 3 1 3 1 0

### Sample Output 1

2

### Sample Input 2

5 8 1 2 3 4

### Sample Output 2

19`

Source: ACM-ICPC Japan Alumni Group Winter Camp 2011 , Day 3, Tokyo, Japan, 2011-02-20
http://acm-icpc.aitea.net/