eolymp
bolt
Try our new interface for solving problems
Problems

The Bermuda Triangle

The Bermuda Triangle

People in the hidden region of the Bermuda Triangle make everything they need in triangular shapes. One day, someone decided to break the rule and bake a hexagonally shaped cake. But as usual, he has to serve the cake in triangular pieces. The pieces are equilateral triangles but in different sizes for different people. He can use as many triangles as needed to cut the cake into pieces, such that nothing remains from the cake. For example, the following figure shows one way that a hexagon with side \textbf{9} can be cut into triangles with side \textbf{2} and \textbf{3}. (The cake is cut along the thick lines, thin lines are drawn to show the sizes). \includegraphics{https://static.e-olymp.com/content/43/43710606faf5dab27a5e2be629b78d073a428c50.jpg} Input is a hexagon and triangle types (specified by the length of their sides) and the goal is to decide if the hexagon can be completely divided by the given triangle types. \InputFile The first line of the input file contains a single integer \textbf{t} (\textbf{1} ≤ \textbf{t} ≤ \textbf{10}), the number of test cases, followed by the input data for each test case. Each test case consists of a single line, containing \textbf{s} (\textbf{1} ≤ \textbf{s} ≤ \textbf{25}), the length of the hexagon's side, followed by \textbf{n}, the number of triangle types (\textbf{1} ≤ \textbf{n} ≤ \textbf{10}), followed by \textbf{n} integers representing the length of each triangle type's side (between \textbf{1} and \textbf{25}, inclusive). \OutputFile There should be one output line per test case containing either \textbf{YES} or \textbf{NO} depending on whether the hexagon can be completely divided by the given triangle types.
Time limit 10 seconds
Memory limit 64 MiB
Input example #1
3
5 2 2 3
7 2 3 2
13 2 2 3
Output example #1
NO
NO
YES
Source 2001 Asia Regional Teheran