题目链接:http://codeforces.com/contest/475/problem/B

Imagine a city with n horizontal streets crossing m vertical streets, forming an (n - 1) × (m - 1) grid. In order to increase the traffic flow, mayor of the city has decided to make each street one way. This means in each horizontal street, the traffic moves only from west to east or only from east to west. Also, traffic moves only from north to south or only from south to north in each vertical street. It is possible to enter a horizontal street from a vertical street, or vice versa, at their intersection.

The mayor has received some street direction patterns. Your task is to check whether it is possible to reach any junction from any other junction in the proposed street direction pattern.

Input

The first line of input contains two integers n and m, (2 ≤ n, m ≤ 20), denoting the number of horizontal streets and the number of vertical streets.

The second line contains a string of length n, made of characters '<' and '>', denoting direction of each horizontal street. If the i-th character is equal to '<', the street is directed from east to west otherwise, the street is directed from west to east. Streets are listed in order from north to south.

The third line contains a string of length m, made of characters '^' and 'v', denoting direction of each vertical street. If the i-th character is equal to '^', the street is directed from south to north, otherwise the street is directed from north to south. Streets are listed in order from west to east.

Output

If the given pattern meets the mayor's criteria, print a single line containing "YES", otherwise print a single line containing "NO".

Examples

Input

3 3
><>
v^v

Output

NO

Input

4 6
<><>
v^v^v^

Output

YES

Note

The figure above shows street directions in the second sample test case.

此题解法颇多:

1.裸tarjan,【表示不会,回头学学】https://blog.csdn.net/qq_34374664/article/details/77488976

2.能够环绕一周的即可【智商做法,此题正解】https://blog.csdn.net/creat2012/article/details/40185517

3.大暴搜https://blog.csdn.net/gaoxiang36999/article/details/39942553

纯暴力搜索,判断每个点是否都能到达其他点

难点:存图

#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
using namespace std;
int n,m,k;
int G[405][405];
vector<int> v[405];
char s[25];
bool vis[405];
bool bfs(int x) {
	memset(vis,0,sizeof(vis));
	queue<int> q;
	q.push(x);
	vis[x]=true;
	while(!q.empty()) {
		int u=q.front();
		q.pop();
		for(int i=1; i<=n*m; i++) {
			if(G[u][i]&&!vis[i]) {
				q.push(i);
				vis[i]=true;
				v[x].push_back(i);
			}
		}
	}
	if(v[x].size()==n*m-1) {
		return true;
	} else {
		return false;
	}
}
int main() {
	scanf("%d%d",&n,&m);
	scanf("%s",s);
	for(int i=0; i<n; i++) {
		k=i*m;
		if(s[i]=='>') {
			for(int j=1; j<m; j++)
				G[k+j][k+j+1]=1;
		} else {
			for(int j=1; j<m; j++)
				G[k+j+1][k+j]=1;
		}
	}
	scanf("%s",s);
	for(int i=0; i<m; i++) {
		if(s[i]=='v') {
			for(int j=1; j+m<=n*m; j+=m)
				G[i+j][i+j+m]=1;
		} else {
			for(int j=1; j+m<=n*m; j+=m)
				G[i+j+m][i+j]=1;
		}
	}
	bool flag=true;
	for(int i=1; i<=n*m; i++) {
		flag=bfs(i);
		if(flag==false) {
			break;
		}
	}
	if(flag) printf("YES\n");
	else printf("NO\n");
	return 0;
}