Under construction

Still being built. Things may change

Three-Tier Chocolate Ice Cream

Interview

Time limit1sMemory limit1024 MB

Summary
Given uppercase strings, decide whether each one matches one of four three-part patterns built from a prefix of length ceil(n/3) and its reverse.
Level

Easy2 of 10

Topics
Implementation, String, Brute force
Solved
No attempts yet

Problem

Coco likes to stack chocolate ice cream scoops and eat them. A stack of chocolate ice cream can be written as a string of uppercase English letters. For example, a stack of Belgian, mint, and original flavors, from bottom to top, can be written as BMO.

Coco defined a "two-tier ice cream" as follows.

  • Given an ice cream string SS of length nn, consider the prefix S′S' of SS with length ⌈n2⌉\left\lceil \frac{n}{2} \right\rceil. ⌈x⌉\left\lceil x \right\rceil is the smallest integer greater than or equal to xx.
  • SS is a two-tier ice cream if S=S′+rev⁡(S′)S=S'+\operatorname{rev}(S') or S=S′+tail⁡(rev⁡(S′))S=S'+\operatorname{tail}(\operatorname{rev}(S')). Here S_1+S_2S\_1+S\_2 is the concatenation of S_1S\_1 and S_2S\_2 in that order, rev⁡(S)\operatorname{rev}(S) is SS with its characters in reverse order, and tail⁡(S)\operatorname{tail}(S) is SS with its first character removed.

Disappointed that this definition is the same as the ordinary definition of a palindrome, Coco defined a further step, the "three-tier ice cream."

  • Given an ice cream string SS of length nn, consider the prefix S′S' of SS with length ⌈n3⌉\left\lceil \frac{n}{3} \right\rceil.
  • SS is a three-tier ice cream if at least one of the following holds.
    • S=S′+rev⁡(S′)+S′S=S'+\operatorname{rev}(S') +S'
    • S=S′+tail⁡(rev⁡(S′))+S′S=S'+\operatorname{tail}(\operatorname{rev}(S')) +S'
    • S=S′+rev⁡(S′)+tail⁡(S′)S=S'+\operatorname{rev}(S') +\operatorname{tail}(S')
    • S=S′+tail⁡(rev⁡(S′))+tail⁡(S′)S=S'+\operatorname{tail}(\operatorname{rev}(S')) +\operatorname{tail}(S')

For example, DOTTODOT = DOT + TOD + OT, so it is a three-tier ice cream.

Determine whether each given string is a three-tier ice cream string.

Input

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

Each of the next TT lines contains a string of uppercase English letters. The length of each string is at least 66 and at most 3030.

Output

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

Examples1

  1. Example 1

    Input
    8
    XYYXXY
    BANABAN
    DOTTODOT
    DADADADADA
    RANDOM
    HOTSHOT
    CHOCOLATE
    DADADADADADA
    
    Expected output
    1
    1
    1
    1
    0
    0
    0
    0