QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 256 MB Total points: 100

#355. Number Theory

Statistics

Given positive integers $P, Q, T$, a set of integers $A$ of size $n$, and a set of integers $B$ of size $m$, calculate:

$$ \sum_{i=0}^{T-1} [(i\in A \pmod P)\ \land\ (i \in B \pmod Q)] $$

In other words, find the number of non-negative integers $x < T$ such that the remainder of $x$ divided by $P$ is in $A$ and the remainder of $x$ divided by $Q$ is in $B$.

Input

The first line contains five space-separated integers $P, Q, n, m, T$.

The second line contains $n$ space-separated integers representing the set $A=\{A_1, A_2, \dots, A_n\}$. It is guaranteed that all $A_i$ are distinct and $0 \le A_i < P$.

The third line contains $m$ space-separated integers representing the set $B=\{B_1, B_2, \dots, B_m\}$. It is guaranteed that all $B_i$ are distinct and $0 \le B_i < Q$.

Output

Output a single integer representing the answer.

Examples

Input 1

4 6 3 3 14
0 1 3
2 4 5

Output 1

4

Subtasks

For all data, $1 \le n, m \le 10^6$, $1 \le P, Q \le 10^6$, $1 \le T \le 10^{18}$.

  • For $10\%$ of the data, $T \le 10^6$.
  • For another $20\%$ of the data, $P, Q \le 1000$.
  • For another $10\%$ of the data, $T$ is a common multiple of $P$ and $Q$.
  • For another $10\%$ of the data, $P$ and $Q$ are coprime, and $P, Q \le 10^5$.
  • For another $10\%$ of the data, $P$ and $Q$ are coprime.
  • For another $10\%$ of the data, $P, Q \le 10^5$.
  • For the remaining $30\%$ of the data, there are no special restrictions.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.