#include #include #include #include using namespace std; void solving(string x, string y, int lx, int ly){ vector res; vector > mark(lx, vector (ly)); int max = 0; for(int i = 0; i < lx; i++){ for(int j = 0; j < ly; j++){ if(x[i] != y[j]){ mark[i][j] = 0; continue; } if(i == 0 || j == 0){ mark[i][j] = 1; }else{ mark[i][j] = mark[i - 1][j - 1] + 1; } if(mark[i][j] > max){ max = mark[i][j]; res.clear(); res.push_back(x.substr(i + 1 - max, (i + 1) - (i + 1 - max))); }else if(mark[i][j] == max){ res.push_back(x.substr(i + 1 - max, (i + 1) - (i + 1 - max))); } } } sort(res.begin(), res.end()); cout << res[0] << endl; } string evolve(string temp){ string a = temp; a.erase(remove_if(a.begin(), a.end(), [](char c){ return c == ',' || c == '.' || c == '!' || c == '?'; }), a.end()); transform(a.begin(), a.end(), a.begin(), ::toupper); return a; } int main(){ string x, y; cin >> x >> y; string X = evolve(x); string Y = evolve(y); int m = x.length(); int n = y.length(); solving(X, Y, m, n); return 0; }