QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 1024 MB Total points: 100 Hackable ✓

#17930. 3-Layer Chocolate Ice Cream

Statistics

Coco likes to stack chocolate ice cream to eat. A chocolate ice cream tower can be represented as a string consisting of uppercase English letters. For example, stacking Belgian, Mint, and Original flavors in order can be written as BMO.

Coco decided to define a "2-tier ice cream" as follows:

  • Given an ice cream string $S$ of length $n$, consider the prefix $S'$ of $S$ with length $\left\lceil \frac{n}{2} \right\rceil$. $\left\lceil x \right\rceil$ is the smallest integer greater than or equal to $x$.
  • $S$ is a 2-tier ice cream if it satisfies $S = S' + \operatorname{rev}(S')$ or $S = S' + \operatorname{tail}(\operatorname{rev}(S'))$. Here, $S_1+S_2$ denotes the concatenation of two strings, $\operatorname{rev}(S)$ denotes the string $S$ with its characters in reverse order, and $\operatorname{tail}(S)$ denotes the string $S$ with its first character removed.

However, disappointed that this definition is the same as the standard definition of a palindrome, Coco went a step further and defined a "3-tier ice cream":

  • Given an ice cream string $S$ of length $n$, consider the prefix $S'$ of $S$ with length $\left\lceil \frac{n}{3} \right\rceil$.
  • $S$ is a 3-tier ice cream if it satisfies at least one of the following:
    • $S = S' + \operatorname{rev}(S') + S'$
    • $S = S' + \operatorname{tail}(\operatorname{rev}(S')) + S'$
    • $S = S' + \operatorname{rev}(S') + \operatorname{tail}(S')$
    • $S = S' + \operatorname{tail}(\operatorname{rev}(S')) + \operatorname{tail}(S')$

For example, DOTTODOT is a 3-tier ice cream because DOTTODOT = DOT + TOD + OT.

Determine whether each string is a 3-tier ice cream string.

Input

The first line contains the number of test cases $T$ ($1 \le T \le 1000$).

Each of the next $T$ lines contains a string consisting of uppercase English letters. The length of the string is between $6$ and $30$, inclusive.

Output

For each test case, output 1 if the given string is a 3-tier ice cream string, and 0 otherwise.

Examples

Input 1

8
XYYXXY
BANABAN
DOTTODOT
DADADADADA
RANDOM
HOTSHOT
CHOCOLATE
DADADADADADA

Output 1

1
1
1
1
0
0
0
0

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.