#P2671. Special Triplets on a Paper Tape
Special Triplets on a Paper Tape
Special Triplets on a Paper Tape
You are given a narrow paper tape divided into n cells numbered from 1 to n. Each cell is colored with an integer in the range \( [1, m] \) and has an associated number written on it.
A special triplet is defined as a triple \((x, y, z)\) satisfying the following conditions:
- \( x, y, z \) are integers such that \( x < y < z \) and \( y - x = z - y \).
- \( color_x = color_z \).
The score of a valid triplet \((x, y, z)\) is defined as:
\[ (x + z) \times (number_x + number_z) \]The total score of the paper tape is the sum of the scores of all valid triplets. Since the total score may be very large, output the remainder when the total score is divided by \(10007\).
inputFormat
The first line contains two integers n and m — the number of cells and the number of possible colors.
The second line contains n integers, where the \(i\)-th integer represents the color of the \(i\)-th cell.
The third line contains n integers, where the \(i\)-th integer is the number written on the \(i\)-th cell.
outputFormat
Output a single integer — the total score of the paper tape modulo \(10007\).
sample
6 2
1 1 2 2 1 2
5 5 3 2 2 2
82