Problem:
Score : 100 points

Problem Statement

Takahashi recorded his daily life for the last few days as a integer sequence of length 2N, as follows:

a_1, b_1, a_2, b_2, ... , a_N, b_N

This means that, starting from a certain time T, he was:

sleeping for exactly a_1 seconds

then awake for exactly b_1 seconds

then sleeping for exactly a_2 seconds

:

then sleeping for exactly a_N seconds

then awake for exactly b_N seconds

In this record, he waked up N times.

Takahashi is wondering how many times he waked up early during the recorded period.

Here, he is said to wake up early if he wakes up between 4:00 AM and 7:00 AM, inclusive.

If he wakes up more than once during this period, each of these awakenings is counted as waking up early.

Unfortunately, he forgot the time T.

Find the maximum possible number of times he waked up early during the recorded period.

For your information, a day consists of 86400 seconds, and the length of the period between 4:00 AM and 7:00 AM is 10800 seconds.

Constraints

1 \leq N \leq 10^5

1 \leq a_i, b_i \leq 10^5

a_i and b_i are integers.

Input

The input is given from Standard Input in the following format:

N
a_1 b_1
a_2 b_2
:
a_N b_N

Output

Print the maximum possible number of times he waked up early during the recorded period.

Sample Input 1

3
28800 57600
28800 57600
57600 28800

Sample Output 1

2

Sample Input 2

10
28800 57600
4800 9600
6000 1200
600 600
300 600
5400 600
6000 5760
6760 2880
6000 12000
9000 600

Sample Output 2

5

Solution in C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<(n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) (s.substr(f-1,t-f+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;
struct Grid{ll x,y,t;};
struct Edge{ll to,cost;};
struct Graph{vector<vector<Edge>>E;int V;
  const ll Inf = llINF;const int MAX_V=201010;vector<ll>d;
  Graph(int n):E(n){d.resize(MAX_V);E.resize(n);V=n;}
  void init(){for(int i=0;i<MAX_V;i++)d[i]=Inf;}
  void add_edge(ll from,ll to,ll cost){E[from].pb({to,cost});}
};
ll rui[400000];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;cin>>n;
  
  vector<ll>num(n);
  ll cnt=0;
  for(int i=0;i<n;i++){
    ll a,b;cin>>a>>b;
    num[i]=(cnt+a)%86400;
    cnt+=a+b;
  }
  sort(ALL(num));
  num.pb(llINF);
  ll ans=0;
  for(int i=0;i<=86400;i++){
    ll numm=lower_bound(ALL(num),i)-num.begin();
    ll num2=upper_bound(ALL(num),i+10800)-num.begin();
    ans=max(ans,num2-numm);
  }
  cout<<ans<<endl;
  return 0;
}