CF1382A Common Subsequence

Description

You are given two arrays of integers $ a_1,\ldots,a_n $ and $ b_1,\ldots,b_m $ . Your task is to find a non-empty array $ c_1,\ldots,c_k $ that is a subsequence of $ a_1,\ldots,a_n $ , and also a subsequence of $ b_1,\ldots,b_m $ . If there are multiple answers, find one of the smallest possible length. If there are still multiple of the smallest possible length, find any. If there are no such arrays, you should report about it. A sequence $ a $ is a subsequence of a sequence $ b $ if $ a $ can be obtained from $ b $ by deletion of several (possibly, zero) elements. For example, $ [3,1] $ is a subsequence of $ [3,2,1] $ and $ [4,3,1] $ , but not a subsequence of $ [1,3,3,7] $ and $ [3,10,4] $ .

Input Format

N/A

Output Format

N/A

Explanation/Hint

In the first test case, $ [4] $ is a subsequence of $ [10, 8, 6, 4] $ and $ [1, 2, 3, 4, 5] $ . This array has length $ 1 $ , it is the smallest possible length of a subsequence of both $ a $ and $ b $ . In the third test case, no non-empty subsequences of both $ [3] $ and $ [2] $ exist, so the answer is "NO".