Problem:
Line Gimmick
You are in front of a linear gimmick of a game. It consists of $N$ panels in a row, and each of them displays a right or a left arrow.
You can step in this gimmick from any panel. Once you get on a panel, you are forced to move following the direction of the arrow shown on the panel and the panel will be removed immediately. You keep moving in the same direction until you get on another panel, and if you reach a panel, you turn in (or keep) the direction of the arrow on the panel. The panels you passed are also removed. You repeat this procedure, and when there is no panel in your current direction, you get out of the gimmick.
For example, when the gimmick is the following image and you first get on the 2nd panel from the left, your moves are as follows.
Move right and remove the 2nd panel.
Move left and remove the 3rd panel.
Move right and remove the 1st panel.
Move right and remove the 4th panel.
Move left and remove the 5th panel.
Get out of the gimmick.
You are given a gimmick with $N$ panels. Compute the maximum number of removed panels after you get out of the gimmick.
Input
The input consists of two lines. The first line contains an integer $N$ ($1 \leq N \leq 100,000$) which represents the number of the panels in the gimmick. The second line contains a character string $S$ of length $N$, which consists of '
>
' or '
<
'. The $i$-th character of $S$ corresponds to the direction of the arrow on the $i$-th panel from the left. '
<
' and '
>
' denote left and right directions respectively.
Output
Output the maximum number of removed panels after you get out of the gimmick.
Sample Input 1
7
>><><<<
Output for the Sample Input 1
7
Sample Input 2
5
>><<<
Output for the Sample Input 2
5
Sample Input 3
6
><<><<
Output for the Sample Input 3
6
Sample Input 4
7
<<><<>>
Output for the Sample Input 4
5

Submitted solutions:

code_snippet: #include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
#define rep(i, m, n) for (ll i = (ll)m; i < (ll)n; i++)
#define drep(i, m, n) for (ll i = m - 1; i >= n; i--)
#define Endl endl
#define all(a) a.begin(), a.end()
#define pr(i, j) make_pair(i, j)
#define isin(x, l, r) (l <= x && x < r)
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)
#define srt(ar) sort(ar.begin(), ar.end())
#define rev(ar) reverse(ar.begin(), ar.end())
#define jge(f, s, t) cout << (f ? s : t) << endl
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#define printar(ar)             \
    do                          \
    {                           \
        for (auto dbg : ar)     \
        {                       \
            cout << dbg << " "; \
        }                       \
        cout << endl;           \
    } while (0)
const ll inf = 1e18;
const ld pi = 3.14159265358979;
const ld eps = 1e-9;
template <class T, ll n, ll idx = 0>
auto make_vec(const ll (&d)[n], const T &init) noexcept
{
    if constexpr (idx < n)
        return std::vector(d[idx], make_vec<T, n, idx + 1>(d, init));
    else
        return init;
}

template <class T, ll n>
auto make_vec(const ll (&d)[n]) noexcept
{
    return make_vec(d, T{});
}
//////////////// 以下を貼る ////////////////
template <class T>
size_t HashCombine(const size_t seed, const T &v)
{
    return seed ^ (std::hash<T>()(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2));
}
/* pair用 */
template <class T, class S>
struct std::hash<std::pair<T, S>>
{
    size_t operator()(const std::pair<T, S> &keyval) const noexcept
    {
        return HashCombine(std::hash<T>()(keyval.first), keyval.second);
    }
};
////////////////////////////////////////////
string s;
ll n;
// 頂点xから始めて←に出るか？
pair<bool, ll> f(ll x)
{
    set<ll> L, R;
    L.insert(-1);
    R.insert(-1);
    L.insert(n);
    R.insert(n);
    rep(i, 0, n)
    {
        if (s[i] == '<')
        {
            L.insert(i);
        }
        else
        {
            R.insert(i);
        }
    }
    ll ret = 1;
    ll mode = -1;
    if (s[x] == '<')
    {
        mode = 0;
        L.erase(x);
    }
    else
    {
        mode = 1;
        R.erase(x);
    }
    ll now = x;
    while (true)
    {
        if (mode == 0)
        {
            ll A = *prev(L.lower_bound(now));
            ll B = *prev(R.lower_bound(now));
            if (max(A, B) == -1)
            {
                return pr(true, ret);
            }
            if (B < A)
            {
                now = A;
                mode = 0;
                L.erase(A);
            }
            else
            {
                now = B;
                mode = 1;
                R.erase(B);
            }
        }
        else
        {
            ll A = *L.lower_bound(now);
            ll B = *R.lower_bound(now);
            if (min(A, B) == n)
            {
                return pr(false, ret);
            }
            if (A < B)
            {
                now = A;
                mode = 0;
                L.erase(A);
            }
            else
            {
                now = B;
                mode = 1;
                R.erase(B);
            }
        }
        ret++;
    }
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n;
    cin >> s;
    if (f(n - 1).first || !f(0).first)
    {
        cout << n << endl;
        return 0;
    }
    ll ok = 0;
    ll ng = n - 1;
    while (ng - ok > 1)
    {
        ll md = (ok + ng) / 2;
        if (f(md).first)
        {
            ok = md;
        }
        else
        {
            ng = md;
        }
    }
    cout << max(f(ok).second, f(ng).second) << endl;
}
accuracy: 1
time_ms: 290
memory_kb: 8192
final_rank: 16

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

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

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

  int ans = 1;
  int low = -1, high = n;
  while (low + 1 < high) {
    int mid = (low + high) / 2;
    queue<char> ql, qr;
    for (int i = mid - 1; i >= 0; i--) ql.push(s[i]);
    for (int i = mid + 1; i < n; i++) qr.push(s[i]);
    int keep = 1;
    char next = s[mid];
    while (true) {
      if (next == '<') {
        if (ql.empty()) break;
        next = ql.front();
        ql.pop();
        keep++;
      }
      else {
        if (qr.empty()) break;
        next = qr.front();
        qr.pop();
        keep++;
      }
    }
    ans = max(ans, keep);
    if (keep == n) {
      break;
    }
    if (ql.empty()) low = mid;
    else high = mid;
  }

  cout << ans << '\n';
}
accuracy: 1
time_ms: 10
memory_kb: 3680
final_rank: 4

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

using P = pair<int,int>;

int main() {
  
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  int n;
  cin >> n;
  string s;
  cin >> s;
  int maxl = -1;
  int l = 0;
  int r = n-1;
  while (l <= r) {
    int now = (l+r)/2;
    int tmp = now;
    set<P> ss;
    for (int i=0;i<n;i++) {
      if (i == now) continue;
      if (s[i] == '<') {
        ss.insert(P(i,-1));
      }
      else ss.insert(P(i,1));
    }
    int mode;
    if (s[now] == '<') mode = -1;
    else mode = 1;
    int val = 0;
    while (true) {
      if (mode == 1) {
        auto it = ss.lower_bound(P(now,-1));
        if (it == ss.end()) {
          val = 1;
          break;
        }
        P np = *it;
        now = np.first;
        mode = np.second;
        ss.erase(it);
      }
      else {
        auto it = ss.upper_bound(P(now,-1));
        if (it == ss.begin()) {
          val = -1;
          break;
        }
        it--;
        P np = *it;
        now = np.first;
        mode = np.second;
        ss.erase(it);
      }
    }
    if (val == 1) {
      r = tmp-1;
    }
    else {
      maxl = tmp;
      l = tmp+1;
    }
  }
  int ans = 0;
  for (int j=-1;j<=+1;j++) {
    int now = maxl+j;
    if (now < 0 || now >= n) continue;
    set<P> ss;
    for (int i=0;i<n;i++) {
      if (i == now) continue;
      if (s[i] == '<') {
        ss.insert(P(i,-1));
      }
      else ss.insert(P(i,1));
    }
    int mode;
    if (s[now] == '<') mode = -1;
    else mode = 1;
    int val = 0;
    while (true) {
      if (mode == 1) {
        auto it = ss.lower_bound(P(now,-1));
        if (it == ss.end()) {
          val = 1;
          break;
        }
        P np = *it;
        now = np.first;
        mode = np.second;
        ss.erase(it);
      }
      else {
        auto it = ss.upper_bound(P(now,-1));
        if (it == ss.begin()) {
          val = -1;
          break;
        }
        it--;
        P np = *it;
        now = np.first;
        mode = np.second;
        ss.erase(it);
      }
    }
    ans = max(ans,(int)(n-ss.size()));
  }
  cout << ans << endl;
}
accuracy: 1
time_ms: 240
memory_kb: 8104
final_rank: 15

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

using P = pair<int,char>;

int main() {

  ios::sync_with_stdio(false);
  cin.tie(0);

  int n;
  string s;
  cin >> n >> s;
  int l = 0;
  int r = n-1;
  int lasl = -1;
  while (l <= r) {
    int now = (l+r)/2;
    int mode = 0;
    set<P> st;
    for (int i=0;i<n;i++) {
      st.insert(P(i,s[i]));
    }
    int tmp = now;
    auto it = st.lower_bound(P(tmp,0));
    P np = *it;
    if (np.second == '<') mode = -1;
    else mode = 1;
    st.erase(it);
    while (0 <= tmp && tmp < n) {
      if (mode == 1) {
        it = st.lower_bound(P(tmp,0));
        if (it == st.end()) {
          tmp = n;
          break;
        }
        np = *it;
        tmp = np.first;
        if (np.second == '<') mode = -1;
        else mode = 1;
        st.erase(it);
      }
      else if (mode == -1) {
        it = st.lower_bound(P(tmp,0));
        if (it == st.begin()) {
          tmp = -1;
          break;
        }
        it--;
        np = *it;
        tmp = np.first;
        if (np.second == '<') mode = -1;
        else mode = 1;
        st.erase(it);
      }
    }
    if (tmp < 0) {
      lasl = now;
      l = now+1;
    }
    else {
      r = now-1;
    }
  }
  int ans = 0;
  for (int i=lasl-1;i<=lasl+1;i++) {
    if (i < 0 || i >= n) continue;
    int mode = 0;
    set<P> st;
    for (int j=0;j<n;j++) {
      st.insert(P(j,s[j]));
    }
    int tmp = i;
    auto it = st.lower_bound(P(tmp,0));
    P np = *it;
    if (np.second == '<') mode = -1;
    else mode = 1;
    st.erase(it);
    while (0 <= tmp && tmp < n) {
      if (mode == 1) {
        it = st.lower_bound(P(tmp,0));
        if (it == st.end()) {
          tmp = n;
          break;
        }
        np = *it;
        tmp = np.first;
        if (np.second == '<') mode = -1;
        else mode = 1;
        st.erase(it);
      }
      else if (mode == -1) {
        it = st.lower_bound(P(tmp,0));
        if (it == st.begin()) {
          tmp = -1;
          break;
        }
        it--;
        np = *it;
        tmp = np.first;
        if (np.second == '<') mode = -1;
        else mode = 1;
        st.erase(it);
      }
    }
    ans = max(ans,n-(int)st.size());
  }
  cout << ans << endl;
}
accuracy: 1
time_ms: 220
memory_kb: 8116
final_rank: 14

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v) {
  for (auto &e:u) fill_v<T>(e, v...);
}

int main(void) {
  int64 N;
  string s;
  cin >> N >> s;
  vector<int> l, r;
  REP(i, s.size()) {
    if (s[i] == '<') l.emplace_back(i);
    else r.emplace_back(i);
  }
  int64 res = 0;
  REP(i, s.size()) {
    int64 lcnt = 0, rcnt = 0;
    if (s[i] == '<') {
      lcnt = l.size() - (lower_bound(all(l), i) - l.begin());
      rcnt = lower_bound(all(r), i) - r.begin();

      if (lcnt <= rcnt) {
        rcnt -= lcnt;
        chmax(res, N - (r[rcnt]));
      } else {
        lcnt -= rcnt + 1;
        chmax(res, l[l.size()-lcnt-1] + 1);
      }
    } else {
      lcnt = l.size() - (lower_bound(all(l), i) - l.begin());
      rcnt = lower_bound(all(r), i) - r.begin() + 1;

      if (rcnt <= lcnt) {
        lcnt -= rcnt;
        chmax(res, l[l.size() - lcnt - 1] + 1);
      } else {
        rcnt -= lcnt + 1;
        chmax(res, N- (r[rcnt]));
      }
    }
  }
  cout << res << endl;
}
accuracy: 1
time_ms: 10
memory_kb: 3664
final_rank: 3

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

int main() {
    int n;
    string s;
    cin >> n >> s;

    auto f = [&](int i) {
        int res = 0;
        int l = i, r = i;
        while (0 <= i && i < n) {
            ++res;
            i = (s[i] == '>' ? ++r : --l);
        }
        return res;
    };

    int l = -1, r = n;
    while (r - l > 2) {
        int ll = (l + l + r) / 3;
        int rr = (l + r + r) / 3;
        if (f(ll) < f(rr)) l = ll;
        else r = rr;
    }
    cout << f((l + r) / 2) << '\n';
}
accuracy: 1
time_ms: 20
memory_kb: 3500
final_rank: 2

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
#define llint long long
#define inf 1e18

using namespace std;

llint n;
string s;
vector<llint> lvec, rvec;

llint getL(llint p, llint x)
{
  if(x == 0) return p;
  llint q = lower_bound(rvec.begin(), rvec.end(), p) - rvec.begin() - x;
  //cout << p << " " << x << " " << rvec[q] << endl;
  return rvec[q];
}

llint getR(llint p, llint x)
{
  if(x == 0) return p;
  llint q = upper_bound(lvec.begin(), lvec.end(), p) - lvec.begin() + x - 1;
  return lvec[q];
}

int main(void)
{
  cin >> n;
  cin >> s;
  s = "#" + s;

  for(int i = 1; i <= n; i++){
    if(s[i] == '<') lvec.push_back(i);
    else rvec.push_back(i);
  }

  llint ans = 0;
  for(int i = 1; i <= n; i++){
    llint lnum = lower_bound(rvec.begin(), rvec.end(), i) - rvec.begin();
    llint rnum = lvec.end() - upper_bound(lvec.begin(), lvec.end(), i);

    //cout << lnum << " " << rnum << endl;

    if(s[i] == '<'){
      if(lnum <= rnum) ans = max(ans, getR(i, lnum));
      else ans = max(ans, n - getL(i, rnum+1) + 1);
    }
    else{
      if(lnum >= rnum) ans = max(ans, n - getL(i, rnum) + 1);
      else ans = max(ans, getR(i, lnum+1));
    }
    //cout << ans << endl;
  }
  cout << ans << endl;

  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 4044
final_rank: 8

code_snippet: #include <bits/stdc++.h>
//#include <atcoder/all>
//using namespace atcoder;
const double pi = 3.141592653589793238462643383279;
using namespace std;
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util
//------------------------------------------
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a) * (a))
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())

//repetition
//------------------------------------------
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define MOD 1000000007

#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const double EPS = 1e-11, PI = acos(-1);
//ここから編集

template<typename T = int> struct SegmentTree{

  vector<T> node;
  int N;

  SegmentTree(int n){
    N = 1;
    while(N < n) N*=2;
    node.resize(2*N-1, 0);
  }

  void update(int x, T val){
    x += N-1;
    
    node[x] = val;
    while(x > 0){
      x = (x-1)/2;
      node[x] = node[2*x+1] + node[2*x+2];
    }
  }

  // [a, b)について求める
  T query(int a, int b, int k=0, int l=0, int r=-1){

    if(r < 0) r = N;
    if(r <= a || b <= l) return 0;
    if(a <= l && r <= b) return node[k];
    
    T vl = query(a, b, 2*k+1, l, (l+r)/2);
    T vr = query(a, b, 2*k+2, (l+r)/2, r);
    return vl + vr;
  }


};

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int N; cin >> N;
  vector<int> lp, rp;
  string s; cin >> s;
  SegmentTree<int> segr(N+10);
  SegmentTree<int> segl(N+10);
  REP(i,N){
    if(s[i] == '>') {
      rp.push_back(i);
      segr.update(i, 1);
      
    }
    else {
      lp.push_back(i);
      segl.update(i, 1);
    }
  }

  int ans = 0;
  for(int i=0; i<N; i++){
    if(s[i] == '>'){
      int r = segr.query(0, i);
      int l = segl.query(i+1, N);

      if(r+1 > l){
        /* 右にたどり着く */
        int rpos = N-1;
        int idx = lower_bound(all(rp), i) - rp.begin();
        int lpos = rp[idx-l];

        ans = max(ans, rpos-lpos+1);
      }else{
        /* 左にたどり着く */
        int lpos = 0;
        int v = lower_bound(all(lp), i) - lp.begin();
        int rpos = lp[v + r];
        ans = max(ans, rpos-lpos+1);
      }
    }else{
      int r = segr.query(0, i);
      int l = segl.query(i+1, N);
      if(r >= l+1){
        /* 右にたどり着く */
        int rpos = N-1;
        int idx = lower_bound(all(rp), i) - rp.begin();
        int lpos = rp[idx-r];

        ans = max(ans, rpos-lpos+1);
      }else{
        /* 左にたどり着く */
        int lpos = 0;
        int v = lower_bound(all(lp), i) - lp.begin();
        int rpos = lp[v + l];
        ans = max(ans, rpos-lpos+1);
      }
    }
  }
  cout << ans << endl;

  return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 5716
final_rank: 13

code_snippet: #include <bits/stdc++.h>

using namespace std;

using ll = long long;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

int sim(int n, string s, int k) {
  vector<bool> sel(n);
  sel[k] = true;
  int now = k;
  int left = (s[now] == '<' ? true : false);
  int cnt = 1;
  int l = k-1, r = k+1;
  while(1) {
    if(left) {
      now = l;
      l--;
    } else {
      now = r;
      r++;
    }
    if(now == -1 || now == n) break;
    cnt++;
    left = (s[now] == '<' ? true : false);
  }
  // cout << endl;
  return cnt;
}

int main () {
  cin.tie(0);
  cout << fixed << setprecision(10);
  int n; cin >> n;
  string s; cin >> s;
  if(n == 1) {
    cout << 1 << endl;
    return 0;
  }

  int l = 0, r = n-1;
  while(r - l > 1) {
    int mid = (l + r) / 2;
    // cout << l << ":" << mid << ":" << r << endl;
    // cout << sim(n, s, mid+1) << endl;
    // cout << sim(n, s, mid) << endl;
    if(sim(n, s, mid+1) - sim(n, s, mid) > 0) {
      l = mid;
    } else {
      r = mid;
    }
  }

  // cout << l << ":" << r << endl;
  cout << max(sim(n, s, l), sim(n, s, r)) << endl;
}
accuracy: 1
time_ms: 10
memory_kb: 3368
final_rank: 1

code_snippet: #include<iostream>
#include<algorithm>
using namespace std;
int n;
string s;
int sum[1<<17];
int sumR[1<<17];
main()
{
	cin>>n>>s;
	for(int i=0;i<n;i++)sum[i+1]=sum[i]+(s[i]=='>');
	for(int i=0;i<n;i++)sumR[i+1]=sumR[i]+(s[n-i-1]=='<');
	int ans=0;
	for(int i=0;i<n;i++)
	{
		int L=sum[i];
		int R=(n-i-1)-(sum[n]-sum[i+1]);
		int now;
		if(s[i]=='>')
		{
			if(L>=R)
			{
				int pos=lower_bound(sum,sum+n+1,L-R+1)-sum-1;
				now=n-pos;
			}
			else
			{
				int pos=lower_bound(sumR,sumR+n+1,R-L)-sumR-1;
				now=n-pos;
			}
		}
		else
		{
			if(L<=R)
			{
				int pos=lower_bound(sumR,sumR+n+1,R-L+1)-sumR-1;
				now=n-pos;
			}
			else
			{
				int pos=lower_bound(sum,sum+n+1,L-R)-sum-1;
				now=n-pos;
			}
		}
		ans=max(ans,now);
	}
	cout<<ans<<endl;
}
accuracy: 1
time_ms: 10
memory_kb: 4108
final_rank: 9

code_snippet: #include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
using namespace std;
#define MK make_pair
#define F first
#define S second

int searchf(int n,int s,int g,vector<pair<int,int>> vp){
    if(g-s<=10){
        for(int i=s;i<=g;i++){
            if(vp[i].F==n && vp[i-1].F!=n){return i;}
        }
        return 0;
    }
    int m=(s+g)/2;
    if(vp[m].F==n && vp[m-1].F!=n){return m;}
    if(vp[m].F>=n){return searchf(n,m+1,g,vp);}
    else{return searchf(n,s,m-1,vp);}
    return 0;
}

int searchs(int n,int s,int g,vector<pair<int,int>> vp){
    if(g-s<=10){
        for(int i=s;i<=g;i++){
            if(vp[i].S==n && vp[i-1].S!=n){return i;}
        }
        return 0;
    }
    int m=(s+g)/2;
    if(vp[m].S==n && vp[m-1].S!=n){return m;}
    if(vp[m].S>=n){return searchs(n,m+1,g,vp);}
    else{return searchs(n,s,m-1,vp);}
    return 0;
}

int main(){
    int n;
    vector<int> v;
    vector<pair<int,int>> vp(200000);
    cin>>n;
    vp[0]=MK(0,0);
    v.push_back(0);
    for(int i=1;i<=n;i++){
        char c;
        cin>>c;
        if(c=='>'){v.push_back(1);}
        if(c=='<'){v.push_back(-1);}
        if(c=='>'){vp[i]=MK(vp[i-1].F+1,vp[i-1].S);}
        if(c=='<'){vp[i]=MK(vp[i-1].F,vp[i-1].S+1);}
    }
    int MX=0;
    MX=n/2+n%2;
    for(int i=1;i<=n;i++){
        if(v[i]==1){
            //if(vp[i].F-vp[n].S+vp[i].S<=1 && vp[i].F-vp[n].S+vp[i].S>=0){MX=max(MX,n); }
            if(vp[i].F-vp[n].S+vp[i].S>=1){
                int tl=vp[i].F-vp[n].S+vp[i].S;
                int l=searchf(tl,1,i,vp);
                MX=max(MX,n-l+1);
            }
            else if(vp[i].F-vp[n].S+vp[i].S<=0){
                int tl=vp[i].S+vp[i].F;
                int l=searchs(tl,i,n,vp);
                MX=max(MX,l);
            }
        }
        if(v[i]==-1){
            //if(vp[i-1].F-vp[n].S+vp[i-1].S>=-1 && vp[i-1].F-vp[n].S+vp[i-1].S<=0){MX=max(MX,n);}
            if(vp[i].F-vp[n].S+vp[i-1].S>=0){
                int tl=vp[i].F-vp[n].S+vp[i-1].S+1;
                int l=searchf(tl,1,i,vp);
                MX=max(MX,n-l+1);
            }
            else if(vp[i].F-vp[n].S+vp[i-1].S<=-1){
                int tl=vp[i-1].S+vp[i].F+1;
                int l=searchs(tl,i,n,vp);
                MX=max(MX,l);
            }
        }
        //cout<<MX<<endl;
    }
    cout<<MX<<endl;
    
    
    
    return 0;
}
accuracy: 0.3103448275862069
time_ms: 1370
memory_kb: 15324
final_rank: 20

code_snippet: #include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
using namespace std;
#define MK make_pair
#define F first
#define S second

int searchf(int n,int s,int g,vector<pair<int,int>> vp){
    if(g-s<=10){
        for(int i=s;i<=g;i++){
            if(vp[i].F==n && vp[i-1].F!=n){return i;}
        }
        return -1;
    }
    int m=(s+g)/2;
    if(vp[m].F==n && vp[m-1].F!=n){return m;}
    if(vp[m].F>=n){return searchf(n,m+1,g,vp);}
    else{return searchf(n,s,m-1,vp);}
    return 0;
}

int searchs(int n,int s,int g,vector<pair<int,int>> vp){
    if(g-s<=10){
        for(int i=s;i<=g;i++){
            if(vp[i].S==n && vp[i-1].S!=n){return i;}
        }
        return -1;
    }
    int m=(s+g)/2;
    if(vp[m].S==n && vp[m-1].S!=n){return m;}
    if(vp[m].S>=n){return searchs(n,m+1,g,vp);}
    else{return searchs(n,s,m-1,vp);}
    return 0;
}

int main(){
    int n;
    vector<int> v;
    vector<pair<int,int>> vp(200000);
    cin>>n;
    vp[0]=MK(0,0);
    v.push_back(0);
    for(int i=1;i<=n;i++){
        char c;
        cin>>c;
        if(c=='>'){v.push_back(1);}
        if(c=='<'){v.push_back(-1);}
        if(c=='>'){vp[i]=MK(vp[i-1].F+1,vp[i-1].S);}
        if(c=='<'){vp[i]=MK(vp[i-1].F,vp[i-1].S+1);}
    }
    int MX=0;
    for(int i=1;i<=n;i++){
        if(v[i]==1){
            //if(vp[i].F-vp[n].S+vp[i].S<=1 && vp[i].F-vp[n].S+vp[i].S>=0){MX=max(MX,n); }
            if(vp[i].F-vp[n].S+vp[i].S>=1){
                int tl=vp[i].F-vp[n].S+vp[i].S;
                int l=searchf(tl,1,i,vp);
                MX=max(MX,n-l+1);
            }
            else if(vp[i].F-vp[n].S+vp[i].S<=0){
                int tl=vp[i].S+vp[i].F;
                int l=searchs(tl,i,n,vp);
                MX=max(MX,l);
            }
        }
        if(v[i]==-1){
            //if(vp[i-1].F-vp[n].S+vp[i-1].S>=-1 && vp[i-1].F-vp[n].S+vp[i-1].S<=0){MX=max(MX,n);}
            if(vp[i].F-vp[n].S+vp[i-1].S>=0){
                int tl=vp[i].F-vp[n].S+vp[i-1].S+1;
                int l=searchf(tl,1,i,vp);
                MX=max(MX,n-l+1);
            }
            else if(vp[i].F-vp[n].S+vp[i-1].S<=-1){
                int tl=vp[i-1].S+vp[i].F+1;
                int l=searchs(tl,i,n,vp);
                MX=max(MX,l);
            }
        }
        //cout<<MX<<endl;
    }
    cout<<MX<<endl;
    
    
    
    return 0;
}
accuracy: 0.3103448275862069
time_ms: 1320
memory_kb: 15324
final_rank: 19

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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))

typedef long long LL;

int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  vector<int> Rr(n+1,0),Lr(n+1,0);
  for(int i=1;i<=n;i++){
    if(s[i-1]=='>'){
      Rr[i]=Rr[i-1]+1;
      Lr[i]=Lr[i-1];
    }else{
      Rr[i]=Rr[i-1];
      Lr[i]=Lr[i-1]+1;
    }
  }
  int ans=0;
  for(int i=1;i<=n;i++){
    if(s[i-1]=='>'){
      if(Rr[i]>Lr[n]-Lr[i]){
        ans=max(ans,n-(lower_bound(Rr.begin(),Rr.end(),Rr[i]-(Lr[n]-Lr[i]))-Rr.begin())+1);
        //cout << n-(lower_bound(Rr.begin(),Rr.end(),Rr[i]-(Lr[n]-Lr[i]))-Rr.begin())+1 << endl;
      }else{
        ans=max(ans,lower_bound(Lr.begin(),Lr.end(),Rr[i]+Lr[i])-Lr.begin());
        //cout << lower_bound(Lr.begin(),Lr.end(),Rr[i]+Lr[i])-Lr.begin() << endl;
      }
    }else{
      if(Rr[i-1]>=Lr[n]-Lr[i-1]){
        ans=max(ans,n-(lower_bound(Rr.begin(),Rr.end(),Rr[i-1]-(Lr[n]-Lr[i-1])+1)-Rr.begin()-1));
        //cout << n-(lower_bound(Rr.begin(),Rr.end(),Rr[i-1]-(Lr[n]-Lr[i-1])+1)-Rr.begin()-1) << endl;
      }else{
        ans=max(ans,lower_bound(Lr.begin(),Lr.end(),Rr[i-1]+Lr[i-1]+1)-Lr.begin());
        //cout << lower_bound(Lr.begin(),Lr.end(),Rr[i-1]+Lr[i-1]+1)-Lr.begin() << endl;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3996
final_rank: 7

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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))

typedef long long LL;

int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  vector<int> Rr(n+1,0),Lr(n+1,0);
  for(int i=1;i<=n;i++){
    if(s[i-1]=='>'){
      Rr[i]=Rr[i-1]+1;
      Lr[i]=Lr[i-1];
    }else{
      Rr[i]=Rr[i-1];
      Lr[i]=Lr[i-1]+1;
    }
  }
  int ans=0;
  for(int i=1;i<=n;i++){
    if(s[i-1]=='>'){
      if(Rr[i]>Lr[n]-Lr[i]){
        ans=max(ans,n-(upper_bound(Rr.begin(),Rr.end(),Rr[i]-(Lr[n]-Lr[i])-1)-Rr.begin()-1));
      }else{
        ans=max(ans,lower_bound(Lr.begin(),Lr.end(),Rr[i]+Lr[i])-Lr.begin());
      }
    }else{
      if(Rr[i-1]>=Lr[n]-Lr[i-1]){
        ans=max(ans,n-(upper_bound(Rr.begin(),Rr.end(),Rr[i-1]-(Lr[n]-Lr[i-1])+1)-Rr.begin()-1));
      }else{
        ans=max(ans,lower_bound(Lr.begin(),Lr.end(),Rr[i-1]+Lr[i-1]+1)-Lr.begin());
      }
    }
  }
  cout << ans << endl;
  return 0;
}
accuracy: 0.6896551724137931
time_ms: 10
memory_kb: 4004
final_rank: 18

code_snippet: #include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[aa]; if (aa != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

const int dx[8] = { 1,1,0,-1,-1,-1,0,1 };
const int dy[8] = { 0,1,1,1,0,-1,-1,-1 };


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n; cin >> n;
	string s;
	cin >> s;
	vi l, r;
	REP(i, s.size()) {
		if (s[i] == '<')l.push_back(i);
		else r.push_back(i);
	}
	vi lcntl(n), lcntr(n), rcntl(n), rcntr(n);
	REP(i, n) {
		if (s[i] == '<') {
			lcntl[i]++;
			rcntl[i]++;
		}
		else {
			lcntr[i]++;
			rcntr[i]++;
		}
	}
	REP(i, n - 1) {
		lcntl[i + 1] += lcntl[i];
		lcntr[i + 1] += lcntr[i];
	}
	RREP(i, n - 1) {
		rcntl[i] += rcntl[i + 1];
		rcntr[i] += rcntr[i + 1];
	}
	int ans = 0;
	REP(i, n) {
		if (s[i] == '<') {
			int a = lcntr[i], b = rcntl[i];

			if (a < b) {
				int c = lower_bound(rcntl.rbegin(), rcntl.rend(), b - a ) - rcntl.rbegin();

				ans = max(ans, n - c);
			}
			else {
				int c = lower_bound(ALL(lcntr), a - b + 1) - lcntr.begin();
	
				ans = max(ans, n - c);
			}
		}
		else {
			int a = lcntr[i], b = rcntl[i];
			if (a <= b) {
				int c = lower_bound(rcntl.rbegin(), rcntl.rend(), b - a + 1) - rcntl.rbegin();

				ans = max(ans, n - c);
			}
			else {
				int c = lower_bound(ALL(lcntr), a - b ) - lcntr.begin();
	
				ans = max(ans, n - c);
			}
		}
	}
	cout << ans << endl;

}
accuracy: 1
time_ms: 10
memory_kb: 5212
final_rank: 12

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

int solve(string s)
{
    int ret = 0;
    int S = s.size();

    vector<int> l(S+1),r(S+1);
    vector<int> rpos;
    rep(i,S)
    {
        if(s[i]=='>') rpos.pb(i);

        l[i+1] = l[i]+(s[i]=='<');
        r[i+1] = r[i]+(s[i]=='>');
    }

    rep(i,S)if(s[i]=='>')
    {
        int L=i, R=S+1;
        while(R-L>1)
        {
            int m = (L+R)/2;

            if(l[m] - l[i] <= r[i]) L=m;
            else R=m;
        }
        if(L<S) ret = max(ret,L+1);
        else
        {
            int idx = lower_bound(all(rpos),i)-rpos.begin();
            idx -= l[L]-l[i];
            ret = max(ret, S-rpos[idx]);
        }
    }

    return ret;
}

int main()
{
    int S;
    string s;
    cin >>S >>s;

    int ans = 0;
    ans = max(ans,solve(s));

    reverse(all(s));
    rep(i,S)
    {
        if(s[i]=='>') s[i]='<';
        else s[i]='>';
    }

    ans = max(ans,solve(s));
    cout << ans << endl;
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 4360
final_rank: 11

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 1120000000

int main(){
  int n;string s;
  cin>>n>>s;

  int ans = 0;
  rep(_,2){
    vector<int> l(n,0),r(n,0);
    rep(i,n){
      if(s[i]=='>') r[i]++;
      if(i>0) r[i] += r[i-1];
    }
    for(int i=n-1; i>=0; i--){
      if(s[i]=='<') l[i]--;
      if(i<=n-2) l[i] += l[i+1];
    }
    rep(i,n){
      if(s[i]=='>'){
        if(r[i] == -l[i]){
          int idx = lower_bound(all(l), 0) - l.begin();
          ans = max(ans, idx);//dbg(i,idx);
        }
        else if(r[i] < -l[i]){
          int x = l[i] + r[i] -1;
          int idx = upper_bound(all(l), x) - l.begin();
          idx--;
          ans = max(ans, idx+1);//dbg(i,idx+1);
        }
        else {
          int x = l[i]+r[i];
          int idx = lower_bound(all(r), x) - r.begin();
          ans = max(ans, n - idx);// dbg(i,n-idx);
        }
      }
    }
    reverse(all(s));
    rep(i,n){
      if(s[i]=='>') s[i]='<';
      else s[i]='>';
    }
  }
  cout << ans << endl;

  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3908
final_rank: 6

code_snippet: #include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<int,int,int> tp;
//typedef vector<tp> vt;
const double PI=acos(-1);
const double EPS=1e-7;
const int inf=1e9;
const ll INF=2e18;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	int n;
	string in;
	cin>>n>>in;
//	in="<"+in+">";
//	n+=2;
	vp dp(n);
	vi ri,le;
	int co=0;
	rep(i,n){
		if(in[i]=='>'){
			co++;
			ri.pb(i);
		}
		dp[i].first=co;
	}
	co=0;
	rep(i,n){
		if(in[n-1-i]=='<'){
			co++;
			le.pb(n-1-i);
		}
		dp[n-1-i].second=co;
	}
//	rep(i,ri.size())cout<<ri[i]<<endl;
//	rep(i,le.size())cout<<le[i]<<endl;
//	rep(i,n)cout<<dp[i].first<<" "<<dp[i].second<<endl;
	int out=max(dp[0].second,dp[n-1].first);
	rep(i,n-1){
		int a=dp[i].first,b=dp[i+1].second;
		if(a<=b){
			int t=le[b-min(a+1,b)];
			out=max(out,t+1);
		}
		if(a>=b){
			int t=ri[a-min(a,b+1)];
			out=max(out,n-t);
		}
	}
	cout<<out<<endl;
}
//  < < < > < < > > >
//  0 0 0 1 1 1 2 3 4
//  5 4 3 2 2 1 0 0 0
accuracy: 1
time_ms: 10
memory_kb: 4352
final_rank: 10

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define MAX 100050
string s;
int n,ans,memo[MAX];
int calc(int x){
  if(~memo[x]) return memo[x];
  int res=0;
  int l=x,r=x;
  while(1){
    if(s[x]=='>') x=++r;
    else x=--l;
    res++;
    if(l<0||n<=r) break;
  }
  ans=max(ans,res);
  return memo[x]=res;
}
int main(){
  cin>>n>>s;
  memset(memo,-1,sizeof(memo));
  int l=0,r=s.size()-1,m1,m2;
  while(l+1<r){
    m1=l+(r-l)/3;
    m2=l+(r-l)*2/3;
    calc(l);calc(r);
    if(calc(m1)<calc(m2)) l=m1+1;
    else r=m2-1;
  }
  calc(l);calc(r);
  cout << ans << endl;
  return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 3688
final_rank: 5

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define MAX 100050
string s;
int n,ans,memo[MAX];
int calc(int x){
  if(~memo[x]) return memo[x];
  int res=0;
  int l=x,r=x;
  while(1){
    if(s[x]=='>') x=++r;
    else x=--l;
    res++;
    if(l<0||n<=r) break;
  }
  ans=max(ans,res);
  return memo[x]=res;
}
int main(){
  cin>>n>>s;
  memset(memo,-1,sizeof(memo));
  int l=0,r=s.size()-1,m1,m2;
  while(l+1<r){
    m1=l+(r-l)/3;
    m2=l+(r-l)*2/3;
    if(calc(m1)<calc(m2)) l=m1+1;
    else r=m2-1;
  }
  cout << ans << endl;
  return 0;
}
accuracy: 0.7931034482758621
time_ms: 20
memory_kb: 3700
final_rank: 17