Problem p03179 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;

using int64 = long long;

constexpr int64 P = 1000000007;

// Verified: ABC133E, ABC132D, ABC130E
struct FiniteField {
private:
  int64 x;

public:
  FiniteField(int64 input_x) : x(input_x) {}
  FiniteField() : x(0) {}
  int64 Value() { return x; }
  inline FiniteField operator+(FiniteField o) {
    FiniteField r(*this);
    r += o;
    return r;
  }
  inline FiniteField operator-(FiniteField o) {
    FiniteField r(*this);
    r -= o;
    return r;
  }
  inline FiniteField operator*(FiniteField o) {
    FiniteField r(*this);
    r *= o;
    return r;
  }
  inline FiniteField operator/(FiniteField o) {
    FiniteField r(*this);
    r /= o;
    return r;
  }
  inline void operator+=(FiniteField o) { x = (x + o.x) % P; }
  inline void operator-=(FiniteField o) { x = (x + P - o.x) % P; }
  inline void operator*=(FiniteField o) { x = (x * o.x) % P; }
  void operator/=(FiniteField o) {
    int64 p = P - 2;
    while (p) {
      if (p % 2) {
        *this *= o;
      }
      o *= o;
      p /= 2;
    }
  }
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int n;
  string s;
  cin >> n >> s;

  vector<vector<FiniteField>> dp1(n);
  vector<vector<FiniteField>> dp2(n);
  dp1[0] = vector<FiniteField>(n);
  for (int j = 0; j < n; j++) {
    dp1[0][j] = 1;
  }
  dp2[0] = vector<FiniteField>(n);
  dp2[0][0] = dp1[0][0];
  for (int j = 1; j < n; j++) {
    dp2[0][j] = dp2[0][j - 1] + dp1[0][j];
  }

  for (int i = 0; i < n - 1; i++) {
    dp1[i + 1] = vector<FiniteField>(n - (i + 1));
    dp2[i + 1] = vector<FiniteField>(n - (i + 1));

    for (int j = 0; j < n - i; j++) {
      if (s[i] == '<') {
        dp1[i + 1][j] = dp2[i][j];
      } else {
        // s[i] == '>'
        dp1[i + 1][j] = dp2[i][n - i - 1] - dp2[i][j];
      }
    }

    dp2[i + 1][0] = dp1[i + 1][0];
    for (int j = 1; j < n - (i + 1); j++) {
      dp2[i + 1][j] = dp2[i + 1][j - 1] + dp1[i + 1][j];
    }

    // cout << "i: " << i + 1 << endl;
    // for (int j = 0; j < n - (i + 1); j++) {
    //   cout << dp1[i + 1][j].Value() << " ";
    // }
    // cout << endl;
    // for (int j = 0; j < n - (i + 1); j++) {
    //   cout << dp2[i + 1][j].Value() << " ";
    // }
    // cout << endl;
  }

  cout << dp1[n - 1][0].Value() << endl;
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;

using int64 = long long;

constexpr int64 P = 1000000007;

// Verified: ABC133E, ABC132D, ABC130E
struct FiniteField {
private:
  int64 x;

public:
  FiniteField(int64 input_x) : x(input_x) {}
  FiniteField() : x(0) {}
  int64 Value() { return x; }
  inline FiniteField operator+(FiniteField o) {
    FiniteField r(*this);
    r += o;
    return r;
  }
  inline FiniteField operator-(FiniteField o) {
    FiniteField r(*this);
    r -= o;
    return r;
  }
  inline FiniteField operator*(FiniteField o) {
    FiniteField r(*this);
    r *= o;
    return r;
  }
  inline FiniteField operator/(FiniteField o) {
    FiniteField r(*this);
    r /= o;
    return r;
  }
  inline void operator+=(FiniteField o) { x = (x + o.x) % P; }
  inline void operator-=(FiniteField o) { x = (x + P - o.x) % P; }
  inline void operator*=(FiniteField o) { x = (x * o.x) % P; }
  void operator/=(FiniteField o) {
    int64 p = P - 2;
    while (p) {
      if (p % 2) {
        *this *= o;
      }
      o *= o;
      p /= 2;
    }
  }
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int n;
  string s;
  cin >> n >> s;

  vector<vector<FiniteField>> dp1(n);
  vector<vector<FiniteField>> dp2(n);
  dp1[0] = vector<FiniteField>(n);
  for (int j = 0; j < n; j++) {
    dp1[0][j] = 1;
  }
  dp2[0] = vector<FiniteField>(n);
  dp2[0][0] = dp1[0][0];
  for (int j = 1; j < n; j++) {
    dp2[0][j] = dp2[0][j - 1] + dp1[0][j];
  }

  for (int i = 0; i < n - 1; i++) {
    dp1[i + 1] = vector<FiniteField>(n);
    dp2[i + 1] = vector<FiniteField>(n);

    for (int j = 0; j < n - i; j++) {
      if (s[i] == '<') {
        dp1[i + 1][j] = dp2[i][j];
      } else {
        // s[i] == '>'
        dp1[i + 1][j] = dp2[i][n - i - 1] - dp2[i][j];
      }
    }

    dp2[i + 1][0] = dp1[i + 1][0];
    for (int j = 1; j < n - (i + 1); j++) {
      dp2[i + 1][j] = dp2[i + 1][j - 1] + dp1[i + 1][j];
    }

    // cout << "i: " << i + 1 << endl;
    // for (int j = 0; j < n - (i + 1); j++) {
    //   cout << dp1[i + 1][j].Value() << " ";
    // }
    // cout << endl;
    // for (int j = 0; j < n - (i + 1); j++) {
    //   cout << dp2[i + 1][j].Value() << " ";
    // }
    // cout << endl;
  }

  cout << dp1[n - 1][0].Value() << endl;
}