eolymp
bolt
Try our new interface for solving problems
Problems

Lamps of the Mind

Lamps of the Mind

The great mathematician Arnold spent hours staring at his exciting Abat-Jour. Lamps in it formed a regular polygon. Some of them, with the red light, interested him a lot, other with the blue light less, and some of them didn't interest him at all. His mind chased them, made triangles out of them, memorized and compared those triangles, and after a while triangles forced out of his mind all the rest. You were hired by a researcher to help unlift the veil over Arnolds genius. It is known that John preferred some colors over others, so there were restrictions on the number of lamps of each color that can be in the considered triangles. Moreover only the geometric form (triangles with the same set length of sides have the same form), but not the position or color of the lamps, was memorized by Arnold. As the first task you have to calculate the number of triangles in the mind of the great mathematician. \InputFile The first line of the input contains two integers \textbf{N} and \textbf{K} (\textbf{3} ≤ \textbf{N} ≤ \textbf{3000}, \textbf{1} ≤ \textbf{K} ≤ \textbf{N}), separated by single space, the number of lamps forming the regular polygon and the number of their colors respectively. The second line contains \textbf{N} integers \textbf{c_i} (\textbf{1} ≤ \textbf{c_i} ≤ \textbf{K}) separated by single space - colors of the lamps. The third line contains \textbf{K} integers \textbf{l_i} (\textbf{0} ≤ \textbf{l_i} ≤ \textbf{3}). They mean that the triangles that have more than \textbf{l_i} lamps of \textbf{i}-th color are not considered by the great mathematician. \OutputFile Output should contain one integer - the number of geometrically different triangles in the mind of the great mathematician.
Time limit 3 seconds
Memory limit 256 MiB
Input example #1
5 3
1 2 2 1 3
2 1 0
Output example #1
1