PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#TP0000066. Hai chuỗi (Two strings)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Hai chuỗi (Two strings)

Two strings

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

You are given two nonempty strings aa and bb consisting of lowercase English letters. You may remove at most one contiguous substring from bb. The removed substring may be empty (remove nothing) or may consist of all of bb.

The remaining string must be a subsequence of aa: it can be obtained by removing zero or more characters from aa without changing the order of the remaining characters. Remove as few characters from bb as possible and output any resulting string of maximum length. If no character can remain, output -.

Input

The first line contains aa.

The second line contains bb.

Output

Print any maximum-length remaining string, obtained by deleting one contiguous substring of bb, that is also a subsequence of aa. Print - if the result must be empty.

Subtasks

  • Subtask 1 (20 points): 1≤∣a∣,∣b∣≤1051\le |a|,|b|\le 10^5; ∣a∣+∣b∣≤24|a|+|b|\le 24; every character of a,ba,b is a lowercase English letter.
  • Subtask 2 (30 points): 1≤∣a∣,∣b∣≤1051\le |a|,|b|\le 10^5; ∣a∣+∣b∣≤4000|a|+|b|\le 4000; every character of a,ba,b is a lowercase English letter.
  • Subtask 3 (50 points): 1≤∣a∣,∣b∣≤1051\le |a|,|b|\le 10^5; ∣a∣+∣b∣≤200000|a|+|b|\le 200000; every character of a,ba,b is a lowercase English letter.

Examples

Input

abca
accepted

Output

ac

Explanation

The string b=acceptedb=\texttt{accepted} has eight characters. Removing the six-character suffix cepted (positions 33 through 88) leaves ac, which occurs at positions 11 and 33 of a=abcaa=\texttt{abca}. Removing a shorter contiguous substring cannot leave three characters forming a subsequence of aa. Therefore the two-character result is optimal.