#include using namespace std; using ll = long long; using ld = long double; using vll = vector; using pll = pair; #define rep(i,n) for(int i=0;i<(n);i++) #define rrep(i,n) for(int i=(n)-1;0<=i;i--) #define REP(i,n) for(int i=1;i<=n;i++) #define RREP(i,n) for(int i=(n);1<=i;i--) #define all(a) a.begin(),a.end() #define sort(a) sort(all(a)) #define rev(a) reverse(all(a)) char el='\n'; void YN(bool f){cout<<(f?"Yes":"No")<<"\n";} template bool chmin(T& x,T y){if(x>y){x=y;return true;}return false;} template bool chmax(T& x,T y){if(x istream &operator>>(istream &is, vector &v){ for(T &in : v) is >> in; return is;} template ostream &operator<<(ostream &os, vector &v){ rep(i,v.size()) os << v[i] << (i+1==v.size()?"":" "); return os;} int main(){ int n, m; cin >> n >> m; vll a(n), b(m); cin >> a >> b; vector lcs(n+1, vll(m+1)); REP(i,n) REP(j,m){ chmax(lcs[i][j], lcs[i-1][j]); chmax(lcs[i][j], lcs[i][j-1]); if(a[i-1]==b[j-1]) chmax(lcs[i][j], lcs[i-1][j-1]+1); } vector> dp(n+1, vector(m+1,false)); dp[n][m] = true; RREP(i,n) RREP(j,m) if(dp[i][j]){ if(lcs[i-1][j]==lcs[i][j]) dp[i-1][j] = true; if(lcs[i][j-1]==lcs[i][j]) dp[i][j-1] = true; if(a[i-1]==b[j-1]) dp[i-1][j-1] = true; } int x = 0, y = 0; vll ans; while(ans.size()=m){ ans.push_back(a[x]); x++; continue; } bool flag = (a[x]==b[y]); // a[x] を飛ばすかどうか if(dp[x+2][y+1]==false) flag = false; if(a[x]