Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review  — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the dishes are different, because Mr. Apple doesn't like to eat the same food. For each pair of dishes from different days he remembers exactly which was better, or that they were of the same quality. After this the gourmet evaluates each dish with a positive integer.

Once, during a revision of a restaurant of Celtic medieval cuisine named «Poisson», that serves chestnut soup with fir, warm soda bread, spicy lemon pie and other folk food, Mr. Apple was very pleasantly surprised the gourmet with its variety of menu, and hence ordered too much. Now he's confused about evaluating dishes.

The gourmet tasted a set of $n$ dishes on the first day and a set of $m$ dishes on the second day. He made a table $a$ of size $n \times m$, in which he described his impressions. If, according to the expert, dish $i$ from the first set was better than dish $j$ from the second set, then $a_{ij}$ is equal to ">", in the opposite case $a_{ij}$ is equal to "<". Dishes also may be equally good, in this case $a_{ij}$ is "=".

Now Mr. Apple wants you to help him to evaluate every dish. Since Mr. Apple is very strict, he will evaluate the dishes so that the maximal number used is as small as possible. But Mr. Apple also is very fair, so he never evaluates the dishes so that it goes against his feelings. In other words, if $a_{ij}$ is "<", then the number assigned to dish $i$ from the first set should be less than the number of dish $j$ from the second set, if $a_{ij}$ is ">", then it should be greater, and finally if $a_{ij}$ is "=", then the numbers should be the same.

Help Mr. Apple to evaluate each dish from both sets so that it is consistent with his feelings, or determine that this is impossible.


-----Input-----

The first line contains integers $n$ and $m$ ($1 \leq n, m \leq 1000$) — the number of dishes in both days.

Each of the next $n$ lines contains a string of $m$ symbols. The $j$-th symbol on $i$-th line is $a_{ij}$. All strings consist only of "<", ">" and "=".


-----Output-----

The first line of output should contain "Yes", if it's possible to do a correct evaluation for all the dishes, or "No" otherwise.

If case an answer exist, on the second line print $n$ integers — evaluations of dishes from the first set, and on the third line print $m$ integers — evaluations of dishes from the second set.


-----Examples-----
Input
3 4
>>>>
>>>>
>>>>

Output
Yes
2 2 2 
1 1 1 1 

Input
3 3
>>>
<<<
>>>

Output
Yes
3 1 3 
2 2 2 

Input
3 2
==
=<
==

Output
No



-----Note-----

In the first sample, all dishes of the first day are better than dishes of the second day. So, the highest score will be $2$, for all dishes of the first day.

In the third sample, the table is contradictory — there is no possible evaluation of the dishes that satisfies it.

Source: codeforces | Difficulty: HARD
Tags: Graph algorithms

Graph traversal

Greedy algorithms

Dynamic programming

Spanning trees


Solutions:
import time
debug = False
(n1, m2) = list(map(int, input().split()))
tests = []
for i in range(n1):
	tests.append(list(input()))
if debug:
	print(tests)
begin = time.time()
if debug:
	print('---')
marks1 = []
result1 = []
for i in range(n1):
	marks1.append([i, 0.0])
	result1.append(0)
marks2 = []
result2 = []
for j in range(m2):
	marks2.append([j, 0.0])
	result2.append(0)
for i in range(n1):
	for j in range(m2):
		test = tests[i][j]
		if test == '>':
			marks1[i][1] += 1.0
		elif test == '<':
			marks2[j][1] += 1.0
		else:
			marks1[i][1] += 0.0001
			marks2[j][1] += 0.0001
marks1.sort(key=lambda val: val[1])
marks2.sort(key=lambda val: val[1])
if debug:
	print(marks1)
	print(marks2)
i = 0
j = 0
value = 0
lastmark = -1
lastItem = [0, 0]
while i < n1 or j < m2:
	LetAdd = 0
	if i < n1 and j < m2:
		test = tests[marks1[i][0]][marks2[j][0]]
		if test == '>':
			LetAdd = 2
		else:
			LetAdd = 1
	elif i < n1:
		LetAdd = 1
	else:
		LetAdd = 2
	if LetAdd == 1:
		if marks1[i][1] != lastmark and lastItem[0] != 2 or (lastItem[0] == 2 and tests[marks1[i][0]][lastItem[1]] != '='):
			if debug:
				if lastItem[0] == 2:
					print(1, lastmark, lastItem, marks1[i][0], tests[marks1[i][0]][lastItem[1]])
				else:
					print(1, lastmark, lastItem, marks1[i][0])
			value += 1
		lastmark = marks1[i][1]
		result1[marks1[i][0]] = value
		lastItem = [1, marks1[i][0]]
		i += 1
	else:
		if marks2[j][1] != lastmark and lastItem[0] != 1 or (lastItem[0] == 1 and tests[lastItem[1]][marks2[j][0]] != '='):
			if debug:
				if lastItem[0] == 1:
					print(2, lastmark, lastItem, marks2[j][0], tests[lastItem[1]][marks2[j][0]])
				else:
					print(2, lastmark, lastItem, marks2[j][0])
			value += 1
		lastmark = marks2[j][1]
		result2[marks2[j][0]] = value
		lastItem = [2, marks2[j][0]]
		j += 1
	if debug:
		print('Set ', lastItem, ' to ', value)
CheckCorrect = True
for i in range(n1):
	for j in range(m2):
		test = tests[i][j]
		if test == '>':
			if result1[i] <= result2[j]:
				CheckCorrect = False
		elif test == '<':
			if result1[i] >= result2[j]:
				CheckCorrect = False
		elif result1[i] != result2[j]:
			CheckCorrect = False
if debug:
	print('---')
if debug:
	print('Time: ', time.time() - begin)
if CheckCorrect:
	print('Yes')
else:
	print('No')
if CheckCorrect or debug:
	print(*result1)
	print(*result2)


import os
from io import BytesIO
from itertools import product

class CYCLE(Exception):
	...
debug_print = lambda *args: None

def solve(n, m, gs):

	def union(u, v):
		(p, q) = (find(u), find(v))
		if p == q:
			return
		if rank[p] < rank[q]:
			(p, q) = (q, p)
		if rank[p] == rank[q]:
			rank[p] += 1
		parent[q] = p

	def find(u):
		if parent[u] == u:
			return u
		else:
			p = find(parent[u])
			parent[u] = p
			return p
	rank = [0] * (n + m)
	parent = list(range(n + m))
	for (i, j) in product(range(n), range(m)):
		if gs[i][j] == '=':
			union(i, n + j)
	vertices = set(parent)
	v_sz = len(vertices)
	g = [set() for _ in range(n + m)]
	for (i, j) in product(range(n), range(m)):
		c = gs[i][j]
		(i, j) = (parent[i], parent[n + j])
		if c == '<':
			g[i].add(j)
		elif c == '>':
			g[j].add(i)
	debug_print(vertices, g)
	(NIL, VISITED, FINAL) = (0, 1, 2)
	state = [NIL] * (n + m)
	toposort_stack = []

	def visit(v):
		debug_print(v)
		if state[v] == VISITED:
			raise CYCLE
		state[v] = VISITED
		for u in g[v]:
			if state[u] != FINAL:
				visit(u)
		state[v] = FINAL
		toposort_stack.append(v)
	try:
		for v in vertices:
			if state[v] == FINAL:
				continue
			visit(v)
	except CYCLE:
		print('No')
		return
	debug_print(toposort_stack)
	layer = [1] * (n + m)
	while toposort_stack:
		v = toposort_stack.pop()
		for u in g[v]:
			layer[u] = max(layer[u], layer[v] + 1)
	print('Yes')
	out = []
	for i in range(n):
		out.append(str(layer[parent[i]]))
	print(' '.join(out))
	out = []
	for j in range(m):
		out.append(str(layer[parent[n + j]]))
	print(' '.join(out))

def solve_from_stdin():
	(n, m) = map(int, input().split())
	gs = []
	for _ in range(n):
		gs.append(input())
	solve(n, m, gs)
solve_from_stdin()


import sys
from collections import deque
sys.setrecursionlimit(10 ** 6)
readline = sys.stdin.readline
(N, M) = map(int, readline().split())
L = [readline().strip() for i in range(N)]

def root(x):
	if x == p[x]:
		return x
	p[x] = y = root(p[x])
	return y

def unite(x, y):
	px = root(x)
	py = root(y)
	if px < py:
		p[py] = px
	else:
		p[px] = py
(*p,) = range(N + M)
for i in range(N):
	for (j, c) in enumerate(L[i]):
		if c == '=':
			unite(i, N + j)
G = [[] for i in range(N + M)]
RG = [[] for i in range(N + M)]
deg = [0] * (N + M)
for i in range(N):
	x = root(i)
	for (j, c) in enumerate(L[i]):
		y = root(N + j)
		if c == '<':
			G[x].append(y)
			RG[y].append(x)
			deg[y] += 1
		elif c == '>':
			G[y].append(x)
			RG[x].append(y)
			deg[x] += 1
A = [-1] * (N + M)
que = deque()
for i in range(N + M):
	if root(i) == i and deg[i] == 0:
		que.append(i)
while que:
	v = que.popleft()
	lb = 0
	for w in RG[v]:
		lb = max(lb, A[w])
	A[v] = lb + 1
	for w in G[v]:
		deg[w] -= 1
		if deg[w] == 0:
			que.append(w)
if any((root(i) == i and A[i] == -1 for i in range(N + M))):
	print('No')
else:
	for i in range(N + M):
		A[i] = A[root(i)]
	print('Yes')
	print(*A[:N])
	print(*A[N:])


class UnionFind:

	def __init__(self, n):
		self.follow = [-1] * (n + 1)
		self.num_follower = [1] * (n + 1)

	def root_index_of(self, a):
		r = a
		while self.follow[r] > -1:
			r = self.follow[r]
		return r

	def connected(self, a, b):
		return self.root_index_of(a) == self.root_index_of(b)

	def connect(self, a, b):
		ra = self.root_index_of(a)
		rb = self.root_index_of(b)
		if ra == rb:
			return
		if self.num_follower[ra] < self.num_follower[rb]:
			self.follow[ra] = rb
			self.follow[a] = rb
			self.num_follower[rb] += self.num_follower[ra]
		else:
			self.follow[rb] = ra
			self.follow[b] = ra
			self.num_follower[ra] += self.num_follower[rb]
import sys
from collections import deque
input = sys.stdin.readline
(n, m) = map(int, input().split())
s = [input() for _ in range(n)]
uf = UnionFind(n + m)
v = [[] for _ in range(n + m)]
c = [0] * (n + m)
for i in range(n):
	for j in range(m):
		if s[i][j] == '=':
			uf.connect(i, j + n)
for i in range(n):
	for j in range(m):
		if s[i][j] == '<':
			v[uf.root_index_of(i)].append(uf.root_index_of(n + j))
			c[uf.root_index_of(n + j)] += 1
		elif s[i][j] == '>':
			v[uf.root_index_of(n + j)].append(uf.root_index_of(i))
			c[uf.root_index_of(i)] += 1
ans = [0] * (n + m)
used = [0] * (n + m)
que = deque([])
for i in range(n + m):
	if c[i] == 0:
		ans[i] = 1
		used[i] = 1
		que.append(i)
while que:
	x = que.popleft()
	for i in v[x]:
		if used[i]:
			continue
		ans[i] = max(ans[x] + 1, ans[i])
		c[i] -= 1
		if c[i] == 0:
			used[i] = 1
			que.append(i)
for i in range(n + m):
	if used[i] == 0:
		print('No')
		exit()
for i in range(n):
	for j in range(m):
		if s[i][j] == '=':
			if ans[uf.root_index_of(i)] != ans[uf.root_index_of(n + j)]:
				print('No')
				exit()
for i in range(n):
	for j in range(m):
		if s[i][j] == '<':
			if ans[uf.root_index_of(i)] >= ans[uf.root_index_of(n + j)]:
				print('No')
				exit()
for i in range(n):
	for j in range(m):
		if s[i][j] == '>':
			if ans[uf.root_index_of(i)] <= ans[uf.root_index_of(n + j)]:
				print('No')
				exit()
print('Yes')
for i in range(n):
	print(ans[uf.root_index_of(i)], end=' ')
print()
for j in range(m):
	print(ans[uf.root_index_of(j + n)], end=' ')
print()


class mergefind:

	def __init__(self, n):
		self.parent = list(range(n))
		self.size = [1] * n
		self.num_sets = n

	def find(self, a):
		to_update = []
		while a != self.parent[a]:
			to_update.append(a)
			a = self.parent[a]
		for b in to_update:
			self.parent[b] = a
		return self.parent[a]

	def merge(self, a, b):
		a = self.find(a)
		b = self.find(b)
		if a == b:
			return
		if self.size[a] < self.size[b]:
			(a, b) = (b, a)
		self.num_sets -= 1
		self.parent[b] = a
		self.size[a] += self.size[b]

	def set_size(self, a):
		return self.size[self.find(a)]

	def __len__(self):
		return self.num_sets

def toposort(C, n):
	indeg = [0] * n
	for (i, neighs) in enumerate(C):
		for neigh in neighs:
			indeg[neigh] += 1
	S = [i for i in range(n) if indeg[i] == 0]
	nparent = indeg[:]
	topo = []
	while S:
		cur = S.pop()
		topo.append(cur)
		for neigh in C[cur]:
			nparent[neigh] -= 1
			if nparent[neigh] == 0:
				S.append(neigh)
		nparent[cur] = -1
	return topo
(n, m) = list(map(int, input().split()))
A = [input() for _ in range(n)]
mf = mergefind(n + m)
for i in range(n):
	for j in range(m):
		if A[i][j] == '=':
			mf.merge(i, n + j)
C = [set() for _ in range(n + m)]
for i in range(n):
	for j in range(m):
		if A[i][j] == '<':
			C[mf.find(i)].add(mf.find(n + j))
		elif A[i][j] == '>':
			C[mf.find(n + j)].add(mf.find(i))
D = [1] * (n + m)
for cur in toposort(C, n + m):
	for neigh in C[cur]:
		D[neigh] = max(D[neigh], D[cur] + 1)
D = [D[mf.find(i)] for i in range(n + m)]
ok = True
for i in range(n):
	for j in range(m):
		if A[i][j] == '<':
			if D[i] >= D[n + j]:
				ok = False
		elif A[i][j] == '>':
			if D[i] <= D[n + j]:
				ok = False
		elif D[i] != D[n + j]:
			ok = False
if ok:
	print('Yes')
	print(*D[:n])
	print(*D[n:])
else:
	print('No')


import collections
import heapq
import bisect
import math
import time

class Solution2:

	def solve(self, A1, A2):
		pass

def gcd(a, b):
	if not b:
		return a
	return gcd(b, a % b)

def lcm(a, b):
	return b * a // gcd(b, a)

class Solution:

	def solve(self, grid):

		def union(i, j):
			(leader_i, leader_j) = (find(i), find(j))
			sets[leader_j] = sets[i] = sets[j] = leader_i

		def find(i):
			while i != sets[i]:
				i = sets[i]
			return i
		N = len(grid) + len(grid[0])
		sets = list(range(N))
		for i in range(len(grid)):
			for j in range(len(grid[0])):
				if grid[i][j] == '=':
					union(i, j + len(grid))
		graph = collections.defaultdict(set)
		inc = collections.defaultdict(set)
		for i in range(len(grid)):
			for j in range(len(grid[0])):
				(leader_i, leader_j) = (find(i), find(j + len(grid)))
				if grid[i][j] == '>':
					if leader_i == leader_j:
						print('No')
						return
					graph[leader_j].add(leader_i)
					inc[leader_i].add(leader_j)
				elif grid[i][j] == '<':
					if leader_i == leader_j:
						print('No')
						return
					graph[leader_i].add(leader_j)
					inc[leader_j].add(leader_i)
		self.levels = [0] * N

		def dfs(node, level):
			self.levels[node] = max(self.levels[node], level)
			if not inc[node]:
				seen.add(node)
				for next_node in graph[node]:
					inc[next_node].discard(node)
					dfs(next_node, self.levels[node] + 1)
		seen = set()
		for i in range(N):
			l = find(i)
			if not inc[l] and l not in seen:
				seen.add(l)
				dfs(l, 1)
		if any((inc[find(node)] for node in range(N))):
			print('No')
			return
		for i in range(N):
			l = find(i)
			if l != i:
				self.levels[i] = self.levels[l]
		print('Yes')
		print(' '.join((str(o) for o in self.levels[:len(grid)])))
		print(' '.join((str(o) for o in self.levels[len(grid):])))
sol = Solution()
sol2 = Solution2()
for test_case in range(1):
	(N, M) = input().split()
	a = []
	for _ in range(int(N)):
		a.append(input())
	out = sol.solve(a)


def prov(mass, now):
	check = True
	for i in range(n):
		for k in range(m):
			if now[i][k] == '>' and mass[i] <= mass[n + k]:
				check = False
				break
			elif now[i][k] == '<' and mass[i] >= mass[n + k]:
				check = False
				break
			elif now[i][k] == '=' and mass[i] != mass[n + k]:
				check = False
				break
		if not check:
			break
	return check

def prog(mass, n, m):
	prov = True
	for i in range(1, m):
		for k in range(n):
			if mass[i][k] < mass[i - 1][k]:
				prov = False
				break
		if not prov:
			break
	if not prov:
		return False
	else:
		mass_new = []
		for i in range(1, m):
			mass_n = []
			for k in range(n):
				mass_n.append(mass[i][k] - mass[i - 1][k])
			mass_new.append(max(mass_n))
		arr = [1 for i in range(m)]
		now = 1
		if 1 in mass[0][:-1]:
			now += 1
			arr = [2 for i in range(m)]
		for i in range(1, m):
			now += mass_new[i - 1]
			arr[mass[i][-1]] = now
		return arr
(n, m) = map(int, input().split())
if n + m <= 6:
	now = []
	for i in range(n):
		now.append(input())
	ppp = True
	for i1 in range(n + m):
		for i2 in range(n + m):
			for i3 in range(n + m):
				for i4 in range(n + m):
					for i5 in range(n + m):
						for i6 in range(n + m):
							mass = [i1 + 1, i2 + 1, i3 + 1, i4 + 1, i5 + 1, i6 + 1][:n + m]
							if prov(mass, now) and ppp:
								print('Yes')
								print(*mass[:n])
								print(*mass[n:])
								ppp = False
	if ppp:
		print('No')
else:
	mass = [[] for i in range(m)]
	mass1 = [[] for i in range(n)]
	for i in range(n):
		now = input()
		for k in range(m):
			if now[k] == '<':
				mass[k].append(1)
				mass1[i].append(-1)
			elif now[k] == '=':
				mass[k].append(0)
				mass1[i].append(0)
			else:
				mass[k].append(-1)
				mass1[i].append(1)
	for i in range(m):
		mass[i].append(i)
	for i in range(n):
		mass1[i].append(i)
	mass.sort()
	mass1.sort()
	arr = prog(mass, n, m)
	arr1 = prog(mass1, m, n)
	if arr == False or arr1 == False:
		print('No')
	else:
		print('Yes')
		print(*arr1)
		print(*arr)


(n, m) = list(map(int, input().split()))
g = []
for i in range(n):
	g += [input()]
memo = {}

def dfs(u):
	if u not in memo:
		memo[u] = res = 1
		if u < n:
			for v in range(m):
				if g[u][v] == '>':
					res = max(res, dfs(n + v) + 1)
			for v in range(m):
				if g[u][v] == '=':
					res = max(res, dfs(n + v))
			for v in range(m):
				if g[u][v] == '=':
					memo[n + v] = max(memo[n + v], res)
		else:
			for v in range(n):
				if g[v][u - n] == '<':
					res = max(res, dfs(v) + 1)
			for v in range(n):
				if g[v][u - n] == '=':
					res = max(res, dfs(v))
			for v in range(n):
				if g[v][u - n] == '=':
					memo[v] = max(memo[v], res)
		memo[u] = res
	return memo[u]
ans = [0] * (n + m)
for i in range(n + m):
	ans[i] = dfs(i)
for i in range(n):
	for j in range(m):
		if g[i][j] == '=' and ans[i] != ans[n + j]:
			print('No')
			exit(0)
		if g[i][j] == '<' and ans[i] >= ans[n + j]:
			print('No')
			exit(0)
		if g[i][j] == '>' and ans[i] <= ans[n + j]:
			print('No')
			exit(0)
print('Yes')
print(*ans[:n])
print(*ans[n:])


from sys import *
from typing import *
from collections import *
(r, c) = [int(i) for i in stdin.readline().strip().split(' ')]
a = [stdin.readline().strip() for i in range(r)]

def L(i: int) -> int:
	return i

def R(i: int) -> int:
	return r + i
parent = [0] * (r + c)
for i in range(r):
	parent[L(i)] = L(i)
for i in range(c):
	parent[R(i)] = R(i)

def find(i: int) -> int:
	parent[i] = i if parent[i] == i else find(parent[i])
	return parent[i]

def union(i: int, j: int):
	parent[find(i)] = find(j)
for i in range(r):
	for j in range(c):
		if a[i][j] == '=':
			union(L(i), R(j))
less_than = [[] for i in range(r + c)]
for i in range(r):
	for j in range(c):
		if a[i][j] == '<':
			less_than[find(R(j))].append(find(L(i)))
		elif a[i][j] == '>':
			less_than[find(L(i))].append(find(R(j)))
score = {}
color = {}
no_solution = set()

def f(i: int) -> int:
	if i not in color:
		color[i] = 'gray'
	elif color[i] == 'gray':
		no_solution.add(True)
	else:
		return score[i]
	if no_solution:
		return 0
	score[i] = 1 + max([f(j) for j in less_than[i]], default=0)
	color[i] = 'black'
	return score[i]
ans1 = [f(find(L(i))) for i in range(r)]
ans2 = [f(find(R(i))) for i in range(c)]
if no_solution:
	print('No')
else:
	print('Yes')
	print(*ans1)
	print(*ans2)


import sys
import collections

def main():
	input = iter(sys.stdin)
	(N, M) = map(int, next(input).split())
	dsu = DSU(N + M)
	edges = []
	for i in range(N):
		line = next(input).strip()
		for (j, sign) in enumerate(line):
			j = j + N
			if sign == '=':
				dsu.merge(i, j)
			else:
				edges.append((i, j) if sign == '<' else (j, i))
	incoming = collections.defaultdict(set)
	outgoing = collections.defaultdict(set)
	nodes = sorted(set([dsu.root(i) for i in range(N + M)]))
	for (i, j) in edges:
		incoming[dsu.root(i)].add(dsu.root(j))
		outgoing[dsu.root(j)].add(dsu.root(i))
	no_incoming = list(set((i for i in nodes if i not in incoming)))
	ordering = []
	while no_incoming:
		node = no_incoming.pop(-1)
		ordering.append(node)
		for n in outgoing[node]:
			incoming[n].discard(node)
			if not incoming[n]:
				no_incoming.append(n)
	if len(ordering) != len(nodes):
		return 'NO'
	root_to_index = {}
	for n in reversed(ordering):
		if not outgoing[n]:
			root_to_index[n] = 0
		else:
			root_to_index[n] = max((root_to_index[x] for x in outgoing[n])) + 1
	s = ['YES']
	s.append(' '.join((str(root_to_index[dsu.root(i)] + 1) for i in range(N))))
	s.append(' '.join((str(root_to_index[dsu.root(i + N)] + 1) for i in range(M))))
	return '\n'.join(s)

class DSU:

	def __init__(self, n):
		self.parents = [i for i in range(n)]

	def root(self, i):
		try:
			if self.parents[i] != i:
				self.parents[i] = self.root(self.parents[i])
		except:
			print(i, len(self.parents))
			raise
		return self.parents[i]

	def merge(self, i, j):
		r1 = self.root(i)
		r2 = self.root(j)
		if r1 != r2:
			self.parents[r1] = r2
print(main())


(n, m) = map(int, input().split())
dishes = [0 for _ in range(n + m)]
father = [-1 for _ in range(n + m)]
e_out = dict()
v_in = [0 for _ in range(n + m)]

def get_father(n):
	if father[n] == -1:
		return n
	else:
		father[n] = get_father(father[n])
		return father[n]
compare_matrix = []
for i in range(n):
	compare_matrix.append(input())
for i in range(n):
	for j in range(m):
		if compare_matrix[i][j] == '=':
			fi = get_father(i)
			fj = get_father(j + n)
			if fi != fj:
				father[fj] = fi
children = dict()
for i in range(n + m):
	fi = get_father(i)
	if fi != i:
		if fi not in children:
			children[fi] = [i]
		else:
			children[fi].append(i)
for i in range(n):
	for j in range(m):
		if compare_matrix[i][j] == '=':
			continue
		fi = get_father(i)
		fj = get_father(j + n)
		if fi == fj:
			print('NO')
			exit(0)
		if compare_matrix[i][j] == '>':
			v_in[fi] += 1
			if fj in e_out:
				e_out[fj].append(fi)
			else:
				e_out[fj] = [fi]
		if compare_matrix[i][j] == '<':
			v_in[fj] += 1
			if fi in e_out:
				e_out[fi].append(fj)
			else:
				e_out[fi] = [fj]
score = 1
visited = [False for _ in range(n + m)]
v_total = 0
q = [v for v in range(n + m) if v_in[v] == 0]
while q:
	t = []
	for i in q:
		dishes[i] = score
		v_total += 1
		if i in children:
			for j in children[i]:
				dishes[j] = score
				v_total += 1
		if i in e_out:
			for j in e_out[i]:
				v_in[j] -= 1
				if v_in[j] == 0:
					t.append(j)
	q = t
	score += 1
if v_total < n + m:
	print('NO')
	exit(0)
print('YES')
for i in dishes[:n]:
	print(i, end=' ')
print()
for i in dishes[n:n + m]:
	print(i, end=' ')


import sys
sys.setrecursionlimit(2000)

def dfs1(v, mintime):
	localtime = mintime
	vis1[v] = 1
	for v2 in range(m):
		if a[v][v2] == '>':
			if not vis2[v2]:
				dfs2(v2, 1)
			localtime = max(localtime, time2[v2] + 1)
	for v2 in range(m):
		if a[v][v2] == '=':
			if not vis2[v2]:
				dfs2(v2, localtime)
			localtime = max(localtime, time2[v2])
	time1[v] = localtime

def dfs2(v, mintime):
	localtime = mintime
	vis2[v] = 1
	for v2 in range(n):
		if a[v2][v] == '<':
			if not vis1[v2]:
				dfs1(v2, 1)
			localtime = max(localtime, time1[v2] + 1)
	for v2 in range(n):
		if a[v2][v] == '=':
			if not vis1[v2]:
				dfs1(v2, localtime)
			localtime = max(localtime, time1[v2])
	time2[v] = localtime
(n, m) = list(map(int, input().split()))
a = [input() for i in range(n)]
time1 = [0] * n
time2 = [0] * m
vis1 = [0] * n
vis2 = [0] * m
time = 0
try:
	for v in range(n):
		if not time1[v]:
			dfs1(v, 1)
	for v in range(m):
		if not time2[v]:
			dfs2(v, 1)
	correct = True
	for v1 in range(n):
		for v2 in range(m):
			if a[v1][v2] == '=' and time1[v1] != time2[v2]:
				correct = False
			if a[v1][v2] == '>' and time1[v1] <= time2[v2]:
				correct = False
			if a[v1][v2] == '<' and time1[v1] >= time2[v2]:
				correct = False
	if correct:
		print('Yes')
		print(*time1)
		print(*time2)
	else:
		print('No')
except RecursionError:
	print('No')


(n, m) = (int(t) for t in input().split(' '))

def direction(c):
	if c == '=':
		return 0
	if c == '>':
		return 1
	return -1
mx = [[direction(c) for c in input()] for _ in range(n)]
index = 0

class DSet(object):

	def __init__(self, value):
		nonlocal index
		self.values = set([value])
		self.index = index
		index += 1
		self.edges_to = set()
		self.edges_from = set()

	def __len__(self):
		return len(self.values)

	def update(self, other_dset):
		self.values.update(other_dset.values)

	def add_edge_to(self, i):
		self.edges_to.add(i)

	def add_edge_from(self, i):
		self.edges_from.add(i)

	def remove_edge_from(self, i):
		self.edges_from.remove(i)
dsu = [DSet(i) for i in range(n + m)]

def union(v1, v2):
	if len(dsu[v1]) > len(dsu[v2]):
		d = dsu[v1]
		d.update(dsu[v2])
	else:
		d = dsu[v2]
		d.update(dsu[v1])
	dsu[v1] = dsu[v2] = d
for i in range(n):
	for j in range(m):
		if not mx[i][j]:
			union(i, n + j)
for i in range(n):
	for j in range(m):
		if mx[i][j] > 0:
			dsu[i].add_edge_from(dsu[n + j].index)
			dsu[n + j].add_edge_to(dsu[i].index)
		elif mx[i][j] < 0:
			dsu[n + j].add_edge_from(dsu[i].index)
			dsu[i].add_edge_to(dsu[n + j].index)
weights = [1] * (n + m)
dsu_by_index = {d.index: d for d in dsu}
while True:
	try:
		v = next((d for d in range(n + m) if not len(dsu[d].edges_from) and len(dsu[d].edges_to)))
	except:
		break
	dsuv = dsu[v]
	for edge in dsu[v].edges_to:
		dsue = dsu_by_index[edge]
		dsue.remove_edge_from(dsuv.index)
		for value in dsue.values:
			weights[value] = weights[v] + 1
	dsu[v].edges_to.clear()
ok = all((not len(d.edges_from) and (not len(d.edges_to)) for d in dsu))
if ok:
	print('Yes')
	print(*weights[0:n])
	print(*weights[n:])
else:
	print('No')


(r, c) = map(int, input().split())
m = []
p = [i for i in range(0, r + c)]
tree = [[] for i in range(0, r + c)]
for i in range(0, r):
	s = input().split('\n')[0]
	m.append(list(s))

def find(i):
	if p[i] == i:
		return i
	par = find(p[i])
	p[i] = par
	return p[i]

def join(i, j):
	p[find(i)] = find(j)
for i in range(0, r):
	for j in range(0, c):
		if m[i][j] == '=':
			join(i, r + j)
		elif m[i][j] == '>':
			tree[i].append(r + j)
		elif m[i][j] == '<':
			tree[r + j].append(i)
v = [False for i in range(0, r + c)]
v2 = [False for i in range(0, r + c)]
a = [1 for i in range(0, r + c)]
l = [[] for i in range(0, r + c)]
for i in range(0, r + c):
	l[find(i)].append(i)
import sys

def dfs(i):
	i = find(i)
	if v[i]:
		return sys.maxsize
	elif v2[i]:
		return a[i]
	v[i] = True
	for k in l[i]:
		for j in tree[k]:
			a[i] = max(dfs(j) + 1, a[i])
	v[i] = False
	v2[i] = True
	return a[i]
A = []
ans = True
for i in range(0, r + c):
	A.append(dfs(i))
	if A[i] > r + c:
		ans = False
m = {}
index = 0
pre = -1
for i in sorted(A):
	if pre == i:
		m[i] = index
	else:
		pre = i
		index += 1
		m[i] = index
for i in range(0, r + c):
	A[i] = m[A[i]]
if ans:
	print('Yes')
	print(str(A[:r]).replace(',', '').replace('[', '').replace(']', ''))
	print(str(A[r:]).replace(',', '').replace('[', '').replace(']', ''))
else:
	print('No')