#include <string>
#include <iostream>
#include <stack>
#include <queue> // priority_queue も入ってる
#include <set>   // 要素数は size() で取得 multisetもある
#include <map>
#include <array> // sizeはコンパイル時定数で固定
#include <vector>
#include <numeric>   // accumulate, gcd
#include <algorithm> // count_ifに必要
#include <iomanip>   // cout << setprecision(15) << x で小数の出力精度を指定
#include <tuple>
#include <utility> //pair
#include <cmath>
#include <random>

using namespace std;
using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)

int main()
{
    ll n;
    cin >> n;
    vector<ll> a(n);
    vector<ll> b(n);
    rep(i, n)
    {
        ll tempA;
        ll tempB;
        cin >> tempA >> tempB;
        tempA--;
        tempB--;
        // a<=b となるように並べます→いみない！！！
        if (tempA <= tempB)
        {
            a[i] = tempA;
            b[i] = tempB;
        }
        else
        {
            a[i] = tempB;
            b[i] = tempA;
        }
    }
    ll aMax = 0;
    ll bMax = 0;
    rep(i, n)
    {
        aMax = max(aMax, a[i]);
        bMax = max(bMax, b[i]);
    }
    ll colorKinds = max(aMax, bMax) + 1;

    vector<vector<ll>> targets(colorKinds);
    rep(i, n)
    {
        targets[a[i]].push_back(b[i]);
        targets[b[i]].push_back(a[i]);
    }

    ll result = 0;
    vector<bool> doneColor(colorKinds, false);
    for (ll color = 0; color < colorKinds; color++)
    {
        if (doneColor[color] == true)
        {
        }
        else
        {
            queue<ll> que;
            que.push(color);
            ll islandMembers = 0;
            ll kyohi = 0;
            while (!que.empty())
            {
                ll nowColor = que.front();
                que.pop();
                if (doneColor[nowColor] == false)
                {
                    doneColor[nowColor] = true;
                    islandMembers++;
                    for (ll target : targets[nowColor])
                    {
                        que.push(target);
                    }
                }
                else
                {
                    // その頂点は調査済みだった場合
                    kyohi++;
                }
            }
            if (kyohi == islandMembers - 1)
            {
                // loopなし
                result += islandMembers - 1;
            }
            else
            {
                // loopあり
                result += islandMembers;
            }
        }
    }
    cout << result << endl;
    return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <iostream>
#include <fstream>
#include <chrono>

using namespace std;

void solve(int test, istream &in) {
    int n; string s;
    in >> n >> s;
    vector<int> a(n + 1);
    int maxa = 0;
    for (int i = 0; i <= n; i++) {
        in >> a[i];
        maxa = std::max(maxa, a[i]);
    }
    int maxk = 1;
    vector<int> b(n + 1), cnt(n + 1);
    for (int k = 2; k <= maxa; k++) {
        for (int i = 0; i <= n; i++) {
            b[i] = a[i] / k;
            cnt[i] = a[i] % k;
        }
        bool good = true;
        for (int i = 0; i < n; i++) {
            int l0 = b[i], l1 = b[i + 1];
            int r0 = b[i], r1 = b[i + 1];
            if (cnt[i] > cnt[i + 1])
                r0++;
            else if (cnt[i] < cnt[i + 1])
                r1++;
            if (s[i] == '>') {
                std::swap(l0, l1);
                std::swap(r0, r1);
            }
            if (l0 >= l1 || r0 >= r1)
                good = false;
        }
        if (good)
            maxk = k;
    }
    for (int i = 0; i <= n; i++) {
        b[i] = a[i] / maxk;
        cnt[i] = a[i] % maxk;
    }
    printf("%d\n", maxk);
    for (int k = 0; k < maxk; k++) {
        for (int i = 0; i <= n; i++) {
            printf("%d ", k < cnt[i] ? b[i] + 1 : b[i]);
        }
        printf("\n");
    }
}

int main(int argc, char* argv[])
{
#ifdef VLAD_LOCAL
	//FILE *f = fopen("in.txt", "r");
    ifstream f("in.txt");
    auto start = std::chrono::steady_clock::now();
#else
	//FILE *f = stdin;
    istream &f = cin;
#endif
    int tests = 1;
    //f >> tests;
    for (int test = 0; test < tests; test++) {
        solve(test, f);
    }
#ifdef VLAD_LOCAL
    auto end = std::chrono::steady_clock::now();
    double seconds = (double)std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() / 1000;
    printf("\n%.3lf seconds\n", seconds);
#endif
	return 0;
}

