P14482 A Stairway Dream
Background
[ドリームレス・ドリームス (Acoustic Arrange)](https://music.163.com/#/song?id=529391584&uct2=U2FsdGVkX1+ckL1JzohOyzor5KJV7Qawv87o4pAhuNE=).
Description
> You obtained a legacy cipher machine and restored its principle using pseudocode.
$s$ is a sequence of length $n$. Also define a positive integer $m$. There are three permutations $f_1,f_2,f_3$ of $0\sim m-1$.
The encryption function `encode` takes $s,k_1,k_2,k_3,f_1,f_2,f_3$. Its definition is as follows:
```cpp
function rotate(f[], k, x)
m = length(f)
return (f[(x + m - k) mod m] + k) mod m
function encode(s[], k1, k2, k3, f1[], f2[], f3[])
t = []
n = length(s)
m = length(f1)
for i = 1 ... n
t[i] = rotate(f3, k3, rotate(f2, k2, rotate(f1, k1, s[i])))
k1 = (k1 + 1) mod m
if (i mod m) = 0
k2 = (k2 + 1) mod m
if (i mod (m * m)) = 0
k3 = (k3 + 1) mod m
return t
```
Where $0\le k_1,k_2,k_3
Input Format
The first line contains two numbers: $n,m$.
The second line contains $n$ numbers, where the $i$-th number represents $s_i$.
The third line contains $n$ numbers, where the $i$-th number represents $t_i$.
The fourth line contains $m$ numbers, where the $i$-th number represents $f_{1,i-1}$.
The fifth line contains $m$ numbers, where the $i$-th number represents $f_{2,i-1}$.
The sixth line contains $m$ numbers, where the $i$-th number represents $f_{3,i-1}$.
Output Format
Output several lines, each containing three integers $k1_i,k2_i,k3_i$, representing one solution.
Output all solutions in lexicographical order of $(k1,k2,k3)$.
Explanation/Hint
This problem uses bundled testing. The bundling details are as follows:
|Sub|Constraints|Score|
| :----------: | :----------: | :----:|
|1|$n\leq100,m \leq26$|$3$|
|2|$n\leq100,m\leq100$|$13$|
|3|$n\leq1000,m\leq300$|$23$|
|4|$n\leq10^6,m\le 200$|$27$|
|5|$n\leq5000,m\le1000$|$10$|
|6|$n\leq2\times 10^5,m\le1000$|$10$|
|7|$n\leq10^6,m\le1000$|$7$|
|8|$n\le 20,m\le 1000$|$7$|
For all data, it's guaranteed that $1\le n\le 10^6,1\le m\le 1000,0\le s_i,t_i,f_{1,i},f_{2,i},f_{3,i}