Problem Of The Week 6: Beautiful String Pairs

Problem Statement

Given a string $t$ of length $m$, consisting of lowercase English letters, it is desired to split $t$ into parts. A pair of strings $(x, y)$ is defined as beautiful with respect to $t$ if and only if there exists a sequence of strings $a_1, a_2, \ldots, a_k$ such that:

\[t = a_1 + a_2 + \cdots + a_k\]

where $+$ denotes string concatenation. For each $1 \leq i \leq k$, at least one of the following conditions must hold:

\[a_i = x \quad \text{or} \quad a_i = y\]

You are given another string $s$ of length $n$, consisting of lowercase English letters. For each $1 \leq i < n$, determine whether the pair of strings

\[(x, y) = (s_1 s_2 \cdots s_i, s_{i+1} s_{i+2} \cdots s_n)\]

is beautiful with respect to $t$. (The string $s$ is made up of the strings $s_i$, where $i$ goes from $1$ to $n$, and each $s_i$ contains one lowercase English letter.)


Input Format


Output Format

For each $1 \leq i < n$, output “YES” if the pair

\[(x, y) = (s_1 s_2 \cdots s_i, s_{i+1} s_{i+2} \cdots s_n)\]

is beautiful with respect to $t$; otherwise, output “NO”.


Constraints


Example

Input:

t = “ababab” s = “abab”

Output:

NO YES NO


Explanation

\[t = ab + ab + ab\]

where each part matches $x$ or $y$.


Objective

Write a program to determine for each $1 \leq i < n$ whether the pair

\[(x, y) = (s_1 s_2 \cdots s_i, s_{i+1} s_{i+2} \cdots s_n)\]

is beautiful with respect to $t$.


Good luck and happy coding!