Diversity
Time limit2sMemory limit1024 MB
Given two periodic integer sequences with periods n and m, compute the sum of a_i XOR b_i over the first k indices, modulo 1e9+7.
- Level
Medium7 of 10
- Topics
- Math, Number theory, Bit manipulation
- Solved
- No attempts yet
Problem
Two infinite periodic integer sequences and are given. Their periods have lengths and . That is, the natural numbers and are given, along with and , where and hold for every natural number .
A natural number is also given. The diversity of the two sequences is the sum of for . Here is the bitwise exclusive OR, which sets a bit to 1 wherever the binary digits of the two numbers differ. For example, .
Calculate the diversity of the given sequences.
Input
The first line contains , , and (, ).
The second line contains integers ().
The third line contains integers ().
Output
Print the diversity modulo on a single line.