Problem: Example

Input

9
0 0 v
1 0 >
2 0


Output

9

Solution (in CPP):

Solution:
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef pair<ll, ll> LP;
typedef vector<int> vec;
typedef vector<string> svec;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-8;

void to_unique(vector<int> &v) {
	sort(v.begin(), v.end());
	v.erase(unique(v.begin(), v.end()), v.end());
}

int n;
void solve() {
	cin >> n;
	vector<P> v(n);
	vector<char> d(n);
	rep(i, n) {
		cin >> v[i].first >> v[i].second >> d[i];
	}
	vector<int> vx, vy;
	{
		rep(i, n) {
			vx.push_back(v[i].first);
			vy.push_back(v[i].second);
		}
		to_unique(vx), to_unique(vy);
		map<int, int> mx, my;
		rep(i, vx.size()) {
			mx[vx[i]] = i;
		}
		rep(i, vy.size()) {
			my[vy[i]] = i;
		}
		rep(i, n) {
			v[i].first = mx[v[i].first];
			v[i].second = my[v[i].second];
		}
	}
	map<P, int> mp;
	rep(i, n) {
		mp[v[i]] = i;
	}
	vector<set<int>> stx(vx.size()),sty(vy.size());
	rep(i, n) {
		stx[v[i].first].insert(v[i].second);
		sty[v[i].second].insert(v[i].first);
	}
	int ans = 0;
	rep(i, n) {
		vector<set<int>> sx = stx, sy = sty;
		int cx = v[i].first, cy = v[i].second;
		int cnt = 0;
		while (true) {
			cnt++;
			sx[cx].erase(cy);
			sy[cy].erase(cx);
			int id = mp[{cx, cy}];
			if (d[id] == '>') {
				sy[cy].insert(cx);
				auto itr = sy[cy].find(cx);
				itr++;
				if (itr == sy[cy].end())break;
				int nx = *itr;
				sy[cy].erase(cx);
				cx = nx;
			}
			else if (d[id] == '<') {
				sy[cy].insert(cx);
				auto itr = sy[cy].find(cx);
				if (itr == sy[cy].begin())break;
				itr--;
				int nx = *itr;
				sy[cy].erase(cx);
				cx = nx;
			}
			else if (d[id] == 'v') {
				sx[cx].insert(cy);
				auto itr = sx[cx].find(cy);
				itr++;
				if (itr == sx[cx].end())break;
				int ny = *itr;
				sx[cx].erase(cy);
				cy = ny;
			}
			else {
				sx[cx].insert(cy);
				auto itr = sx[cx].find(cy);
				if (itr == sx[cx].begin())break;
				itr--;
				int ny = *itr;
				sx[cx].erase(cy);
				cy = ny;
			}
		}
		ans = max(ans, cnt);
	}
	cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init();
	/*while (cin >> n>>m>>l, n) {
		solve();
	}*/
	solve();
	//stop
	return 0;
}