text: It is guaranteed that the first circle doesn't contain a hieroglyph, which occurs twice.The second circle also has this property.Output Print a single number — the maximum length of the common substring and subsequence.If at any way of breaking the circles it does not exist, print 0.Examples Input 5 4 1 2 3 4 5 1 3 5 6 Output 2 Input 4 6 1 3 5 2 1 2 3 4 5 6 Output 3 Input 3 3 1 2 3 3 2 1 Output 2 Note In the first test Polycarpus picks a string that consists of hieroglyphs 5 and 1, and in the second sample — from hieroglyphs 1, 3 and 5.# Solution #include <bits/stdc++.h> using namespace std; int lenA, lenB; int A[1000004]; int B[1000004]; int idxB[1000004]; int main() { scanf("%d %d", &lenA, &lenB); for (int i = 0, _n = (lenA); i < _n; ++i) scanf("%d", A + i); memset(idxB, -1, sizeof(idxB)); for (int j = 0, _n = (lenB); j < _n; ++j) { scanf("%d", B + j); idxB[B[j]] = j; } int idxV = 0; vector<long long> V; long long offset = 0; int res = 0; for (int k = 0, _n = (lenA * 2); k < _n; ++k) { long long p = idxB[A[k % lenA]]; if (p < 0) { V.clear(); idxV = 0; continue; } p += offset; if (!V.empty() && V.back() >= p) { p += lenB; offset += lenB; } V.push_back(p); idxV = (lower_bound(V.begin() + idxV, V.end(), p - lenB + 1) - V.begin()); int len = int((V).size()) - idxV; res = max(res, len); } printf("%d\n", res); return 0; }