#include using namespace std; using ll = long long; using ld = long double; using ull = unsigned long long; #define rep(i,n) for(ll i=0;i T div_floor(T a, T b) { return a / b - ((a ^ b) < 0 && a % b); } template T div_ceil(T a, T b) { return a / b + ((a ^ b) > 0 && a % b); } template inline bool chmin(T &x, U y) { return (y < x) ? (x = y, true) : false; } template inline bool chmax(T &x, U y) { return (x < y) ? (x = y, true) : false; } template ostream &operator<<(ostream &os, const vector &a){ if (a.empty()) return os; os << a.front(); for (auto e : a | views::drop(1)){ os << ' ' << e; } return os; } void dump(auto ...vs){ ((cout << vs << ' '), ...) << endl; } void solve() { ll N,M; cin>>N>>M; vector A(2*N+1); rep(i,2*N+1){ cin>>A[i]; } vector S(M); rep(i,M)cin>>S[i]; vector used(N+1,false); queue qu; rep(i,M){ used[S[i]]=true; qu.push(S[i]); } while (qu.size()>0){ ll cp=qu.front();qu.pop(); for (ll sp:S){ ll np=A[cp+sp]; if (!used[np]){ used[np]=true; qu.push(np); } } } cout<sync_with_stdio(0); ll T=1; while (T--){ solve(); } return 0; }