Exit Song

아직 제출이 없습니다시간 제한2초메모리 제한512 MB

문제

Your favorite singer is giving a farewell concert soon, and you just can't miss this.

The concert will be held in a hall which has nn rows, numbered from 0 to n1n - 1, with mm seats in each row, consecutively numbered from 0 to m1m - 1.

Unfortunately, kk seats are already unavailable for reservation. These seats are given by pairs (r_1,s_1)(r\_1, s\_1), (r_2,s_2)(r\_2, s\_2), ......, (r_k,s_k)(r\_k, s\_k). For every ii from 1 to kk, the ticket for seat s_is\_i in row r_ir\_i is gone.

You are definitely coming to the concert, but you have no idea if any of your friends would like to join. You are considering all options to buy tickets for several (at least one) consecutive seats in the same row. How many such options do you have?

입력

The first line of the input contains three integers nn, mm and kk (1n,m1051 \le n, m \le 10^5; 1knm1 \le k \le n \cdot m) --- the dimensions of the concert hall and the number of reserved seats, respectively.

The second line of the input contains three integers r_1r\_1, a_ra\_r and b_rb\_r (0r_1,a_r,b_r<n0 \le r\_1, a\_r, b\_r < n).

The third line of the input contains three integers s_1s\_1, a_sa\_s and b_sb\_s (0s_1,a_s,b_s<m0 \le s\_1, a\_s, b\_s < m).

As the input could be quite large, it's encoded in the following way: the values of r_1r\_1 and s_1s\_1 are given, and for every ii from 2 to kk the values of r_ir\_i and s_is\_i can be found using the following formulae:

r_i=(r_i1a_r+b_r)modnr\_i = (r\_{i-1} \cdot a\_r + b\_r) \bmod n;

s_i=(s_i1a_s+b_s)modms\_i = (s\_{i-1} \cdot a\_s + b\_s) \bmod m.

All pairs (r_i,s_i)(r\_i, s\_i) are distinct.

출력

Output a single integer --- the number of options to buy tickets for several consecutive seats in the same row.

힌트

In the first example test case, seats (1,2)(1, 2), (2,0)(2, 0) and (1,1)(1, 1) are occupied. There are 10 options to buy tickets in row 0, 2 options in row 1 and 6 options in row 2. The sum is 10+2+6=1810 + 2 + 6 = 18.