Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!

~/algor $ cat problems/qavslar-balansi

Balanced brackets

Medium 1000 ms 64 MB 45%
Share

A string $s$ consisting only of the characters (, ), [, ], {, } is given. Are the brackets placed correctly? The brackets are placed correctly if every opening bracket is closed by a closing bracket of the matching type in the correct order. For example, ([]{}) is correct, and ([)] is not.

A string of brackets: each opening bracket is joined by an arc to its matching closing bracket

Input

One line with the string $s$.

Output

HA if the brackets are placed correctly, otherwise YOQ.

Note

$1 \le |s| \le 2 * 10^{5}$
$s$ consists only of the characters (, ), [, ], {, }

Examples

Input #1
([]{})
Output #1
HA
Input #2
([)]
Output #2
YOQ

Sign in to submit a solution

Signing up is free and takes a minute.