The main characters have been omitted to be short.

You are given a directed unweighted graph without loops with n vertexes and a path in it (that path is not necessary simple) given by a sequence p1,p2,…,pm of m vertexes; for each 1≤i<m there is an arc from pi to pi+1.

Define the sequence v1,v2,…,vk of k vertexes as good, if v is a subsequence of p, v1=p1, vk=pm, and p is one of the shortest paths passing through the vertexes v1, …, vk in that order.

A sequence a is a subsequence of a sequence b if a can be obtained from b by deletion of several (possibly, zero or all) elements. It is obvious that the sequence p is good but your task is to find the shortest good subsequence.

If there are multiple shortest good subsequences, output any of them.

Input

The first line contains a single integer n (2≤n≤100) — the number of vertexes in a graph.

The next n lines define the graph by an adjacency matrix: the j-th character in the i-st line is equal to 1 if there is an arc from vertex i to the vertex j else it is equal to 0. It is guaranteed that the graph doesn’t contain loops.

The next line contains a single integer m (2≤m≤106) — the number of vertexes in the path.

The next line contains m integers p1,p2,…,pm (1≤pi≤n) — the sequence of vertexes in the path. It is guaranteed that for any 1≤i<m there is an arc from pi to pi+1.

Output

In the first line output a single integer k (2≤k≤m) — the length of the shortest good subsequence. In the second line output k integers v1, …, vk (1≤vi≤n) — the vertexes in the subsequence. If there are multiple shortest subsequences, print any. Any two consecutive numbers should be distinct.

#include<iostream>
#include<cstdio>
using namespace std;
const int inf = 0x7f7f7f7f;
char a[210][210];
int g[210][210];
int p[1000010];
bool f[1000010];
int n;
void floyd()
{
for(int k = 1 ; k <= n ; k++)
{
for(int i = 1 ; i <= n ; i++)
{
for(int j = 1 ; j <= n ; j++)
{
if(g[i][k] < inf && g[k][j] < inf)
g[i][j] = min(g[i][k] + g[k][j] , g[i][j]);
}
}
}
}
int main()
{
scanf("%d",&n);
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= n; j++)
{
char c;
scanf(" %c",&c);
g[i][j] = c - '0';
if(!g[i][j])
g[i][j] = inf;
}

}
floyd();
int m;
scanf("%d",&m);
for(int i = 1; i <= m; i++)
{
scanf("%d",&p[i]);
}
int cnt = p[1], t = m;
for(int i = 2 ; i < m ; i++)
{
if(g[cnt][p[i]] + g[p[i]][p[i + 1]] <= g[cnt][p[i + 1]] && cnt != p[i+1])
{
f[i] = 1;
t--;
}
else cnt = p[i];
}
printf("%d\n",t);
for(int i = 1 ; i <= m ; i++)
{
if(f[i])
continue;
printf("%d ",p[i]);
}
printf("\n");
}