아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Exit Song

시간 제한2초메모리 제한512 MB

요약
등차점화식으로 생성되는 k개의 예약 좌석이 주어질 때, 같은 행에서 연속한 한 좌석 이상을 예매하는 경우의 수를 센다.
난이도

보통10점 중 7점

유형
조합론, 정렬, 수학, 구현
정답자
아직 제출이 없습니다

문제

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 n−1n - 1, with mm seats in each row, consecutively numbered from 0 to m−1m - 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 (1≤n,m≤1051 \le n, m \le 10^5; 1≤k≤n⋅m1 \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 (0≤r_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 (0≤s_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_i−1⋅a_r+b_r) mod nr\_i = (r\_{i-1} \cdot a\_r + b\_r) \bmod n;

s_i=(s_i−1⋅a_s+b_s) mod ms\_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.

예제2

  1. 예제 1

    입력
    3 4 3
    1 2 0
    2 1 1
    
    예상 출력
    18
    
  2. 예제 2

    입력
    22 13 41
    7 12 14
    5 8 1
    
    예상 출력
    1195