Problem p03179 (C++)

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i, n) for (int i = 0; i < (int)n; ++i)

// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                                               \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"                       \
       << " " << __FILE__ << endl;

template <typename T> void vprint(T &v) {
  REP(i, v.size()) { cout << v[i] << " "; }
  cout << endl;
}

const ll N_MAX = 3030;
struct RAQSB {
  ll N;
  ll sN;
  ll data[N_MAX];
  ll bucket[N_MAX];

  RAQSB(ll n) {
    sN = (ll)sqrt(n) + 1;
    N = sN * sN;
    REP(i, N_MAX) {
      data[i] = 0;
      bucket[i] = 0;
    }
  }

  void add(ll s, ll t, ll x) {
    // add x to range [s, t)
    ll ss = s / sN;
    ll tt = t / sN;
    if (ss == tt) {
      for (int i = s; i < t; i++) {
        data[i] += x;
        data[i] %= mod;
      }
    } else {
      for (int i = s; i < (ss + 1) * sN; i++) {
        data[i] += x;
        data[i] %= mod;
      }
      for (int i = tt * sN; i < t; i++) {
        data[i] += x;
        data[i] %= mod;
      }
      for (int i = ss + 1; i < tt; i++) {
        bucket[i] += x;
        bucket[i] += mod;
      }
    }
  }

  ll get_val(ll i) { return (data[i] + bucket[i / sN]) % mod; }
};

int main() {
  ll N;
  string S;
  cin >> N >> S;

  ll ma = 303;
  ll DP[ma][ma];
  REP(i, ma) REP(j, ma) DP[i][j] = 0;
  REP(j, N) DP[0][j] = 1;
  REP(i, N - 1) {
    RAQSB raqsb(N + 10);
    if (S[i] == '<') {
      REP(j, N) {
        raqsb.add(0, j, DP[i][j]);
        /*
        REP(k, j){
                DP[i+1][k] += DP[i][j];
                DP[i+1][k] %= mod;
        }
        */
      }
    } else {
      REP(j, N) {
        raqsb.add(j, N - i - 1, DP[i][j]);
        /*
        for(int k=j;k<=N-i-2;k++){
                DP[i+1][k] += DP[i][j];
                DP[i+1][k] %= mod;
        }
        */
      }
    }
    REP(j, N) DP[i + 1][j] = raqsb.get_val(j);
  }
  cout << DP[N - 1][0] << endl;
  /*
  REP(i, N){
          REP(j, N){
                  cout << DP[i][j] << " ";
          }
          cout << endl;
  }
  */
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i, n) for (int i = 0; i < (int)n; ++i)

// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                                               \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"                       \
       << " " << __FILE__ << endl;

template <typename T> void vprint(T &v) {
  REP(i, v.size()) { cout << v[i] << " "; }
  cout << endl;
}

const ll N_MAX = 3030;
struct RAQSB {
  ll N;
  ll sN;
  ll data[N_MAX];
  ll bucket[N_MAX];

  RAQSB(ll n) {
    sN = (ll)sqrt(n) + 1;
    N = sN * sN;
    REP(i, N_MAX) {
      data[i] = 0;
      bucket[i] = 0;
    }
  }

  void add(ll s, ll t, ll x) {
    // add x to range [s, t)
    ll ss = s / sN;
    ll tt = t / sN;
    if (ss == tt) {
      for (int i = s; i < t; i++) {
        data[i] += x;
        data[i] %= mod;
      }
    } else {
      for (int i = s; i < (ss + 1) * sN; i++) {
        data[i] += x;
        data[i] %= mod;
      }
      for (int i = tt * sN; i < t; i++) {
        data[i] += x;
        data[i] %= mod;
      }
      for (int i = ss + 1; i < tt; i++) {
        bucket[i] += x;
        bucket[i] += mod;
      }
    }
  }

  ll get_val(ll i) { return (data[i] + bucket[i / sN]) % mod; }
};

int main() {
  ll N;
  string S;
  cin >> N >> S;

  ll ma = 3030;
  ll DP[ma][ma];
  REP(i, ma) REP(j, ma) DP[i][j] = 0;
  REP(j, N) DP[0][j] = 1;
  REP(i, N - 1) {
    RAQSB raqsb(N + 10);
    if (S[i] == '<') {
      REP(j, N) {
        raqsb.add(0, j, DP[i][j]);
        /*
        REP(k, j){
                DP[i+1][k] += DP[i][j];
                DP[i+1][k] %= mod;
        }
        */
      }
    } else {
      REP(j, N) {
        raqsb.add(j, N - i - 1, DP[i][j]);
        /*
        for(int k=j;k<=N-i-2;k++){
                DP[i+1][k] += DP[i][j];
                DP[i+1][k] %= mod;
        }
        */
      }
    }
    REP(j, N) DP[i + 1][j] = raqsb.get_val(j);
  }
  cout << DP[N - 1][0] << endl;
  /*
  REP(i, N){
          REP(j, N){
                  cout << DP[i][j] << " ";
          }
          cout << endl;
  }
  */
  return 0;
}