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

~/algor $ cat problems/ikki-korsatkich-eng-qisqa-qamrov

Minimum window substring

Medium 1000 ms 128 MB 66%
Share

Two strings $s$ and $t$ are given. Find the shortest segment of consecutive letters of $s$ in which every letter of $t$ occurs at least as many times as in $t$ (for example, for $t$ = aab the segment must contain at least two a and one b). If there are several such segments, print the leftmost one; if there are none, print $-1$.

Letters of the string: the shortest window containing all letters of t is highlighted

Input

The first line contains $s$, the second line contains $t$.

Output

The found substring, or $-1$.

Note

$1 \le |t| \le |s| \le 10^{5}$
the strings consist of lowercase Latin letters

Examples

Input #1
adobecodebanc
abc
Output #1
banc
Input #2
aab
abb
Output #2
-1

Sign in to submit a solution

Signing up is free and takes a minute.