#P10534. [Opoi 2024] 简谐振动

[Opoi 2024] 简谐振动

Background

You are right, but simple harmonic motion is very beautiful.

pic

cip

jzp

However, we are not going to the sea under polygons, so you do not need to maintain the simple harmonic motion of a particle.

Problem Description

Given a digit string SS, determine whether there exists an integer sequence AiA_i of length nn where nn is odd, such that the values of $A_1 + A_2, A_2 + A_3, \dots, A_{n-1} + A_n, A_n + A_1$, when concatenated in this order, can form SS.

In particular, if there is a solution such that, during concatenation, inserting [0,)[0,\infty) zeros as separators between two adjacent terms can still produce SS, then this solution is also considered valid. All testdata guarantee that SS has no leading 00.

Input Format

The first line contains an integer TT, the number of test cases.

For each test case:

The first line contains an integer nn.

The second line contains a string SS.

Output Format

For each test case, if a solution exists, output Yes; otherwise output No. Print each answer on its own line.

3
3
131011
1
5
3
2011

Yes
No
Yes

Hint

Sample Explanation

Explanation for the first sample:

$\begin{matrix} 7&6&4\cr +&+&+\cr 6&4&7\cr ||&||&||\cr 13&10&11\end{matrix}$

Of course, you can also say:

$\begin{matrix} 71&60&-60\cr +&+&+\cr 60&-60&71\cr ||&||&||\cr 131&0&11\end{matrix}$

The construction is not unique.

Explanation for the second sample:

If there is a solution, then A1=2.5A_1 = 2.5. But the problem states that AA is an integer sequence, so there is no solution.

Explanation for the third sample:

$\begin{matrix} 1&&1&0\cr +&&+&+\cr 1&&0&1\cr ||&&||&||\cr 2&0&1&1\end{matrix}$

In this solution, there are 1[0,)1 \in [0,\infty) zeros used as separators in the middle, which meets the requirement, so output Yes.


Constraints

For 50%50\% of the testdata: 1T101 \le T \le 10, 1S101 \le |S| \le 10, 1n31 \le n \le 3.

For 100%100\% of the testdata: 1T1001 \le T \le 100. It is guaranteed that n106\sum n \le 10^6 and S106\sum |S| \le 10^6, 0Si9{\tt 0} \le S_i \le {\tt 9}, and nn is odd.

Translated by ChatGPT 5