#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  ll x, y;
  cin>>x>>y;
  priority_queue<tuple<ll, ll, ll>, vector<tuple<ll, ll, ll> >, greater<tuple<ll, ll, ll> > >que;
  que.push(make_tuple(0, x, y));
  tuple<ll, ll, ll> state;
  ll path, xx, yy;
  ll ans;
  map<pair<ll, ll>, int> amap;
  while(!que.empty()){
    state = que.top();que.pop();
    path = get<0>(state);
    xx = get<1>(state);
    yy = get<2>(state);
    if(xx==yy){
      ans = path;
      break;
    }
    if(amap[mp(xx, yy)]>0) continue;
    amap[mp(xx, yy)]++;
    if(amap[mp(-xx, yy)]==0){
      que.push(make_tuple(path+1, -xx, yy));
    }
    if(xx<yy){
      if(amap[mp(yy, yy)]==0){
        que.push(make_tuple(path+yy-xx, yy, yy));
      }
    }
    if(xx<-yy){
      if(amap[mp(-yy, yy)]==0){
        que.push(make_tuple(path-yy-xx, -yy, yy));
      }
    }
  }
  cout<<ans<<endl;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll ;
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
 const ll inf=1e9+7;
string a,b,c;

ll mod(ll a)
{
	if(a<inf)return a;
	else
	return a%inf;
}
 void test_cases()
{

ll n;
cin>>n;
 vector<ll>cnt(n+1,0);
while(n>1)
{
	ll x=n;
for(ll i=2;i<=x;i++)
{
	while(x%i==0)
	{
		cnt[i]++;
		x=x/i;
	}
}
	n--;
}

ll ans=1;
for(auto x:cnt)
{
 //cout<<x<<" ";
	ans*=(x+1);
	ans=mod(ans);
}

 cout<<ans;

}

int main()
{
    fast;
  ll t;
 // cin>>t;
 t=1;
  while(t--)
  test_cases();

}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define rep(i,s,n) for(int i = s; i < (int)(n); i++)

int main() {
  string s;
  ll n;
  cin >> s;
  n = s.size();
  vector<ll>cnt(26);
  rep(i,0,n) cnt[s[i]-'a']++;
  ll ans = 1+n*(n-1)/2;
  rep(i,0,26) ans -= cnt[i]*(cnt[i]-1)/2;
  cout << ans << endl;
}

#include  <iostream>
#include  <stdio.h>
#include <algorithm>
#include <map>
#include <math.h>

using namespace std;
#include <vector>
#define rep(i,n) for (ll i = 0; i < (n) ; i++)
#define INF 1e9
#define llINF 1e18
#define base10_4 10000      //1e4
#define base10_5 100000     //1e5
#define base10_6 1000000    //1e6
#define base10_7 10000000   //1e7
#define base10_8 100000000  //1e8
#define base10_9 1000000000 //1e9

#define MOD 1000000007
#define pb push_back
#define ll long long
#define ld long double
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>

//#include <stack>
//#include <queue>

// #include <iomanip>
//  cout << fixed << setprecision(15) << y << endl;

string ans_Yes = "Yes";
string ans_No = "No";
string ans_yes = "yes";
string ans_no = "no";

ll A;
ll B;
ll C;
ll N;
ll M;
ll K;

ll ltmp;
string stmp;
double dtmp;

int main(){

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

    cin >> N;
    //N = 1000000000000001;
    ll num_mozi;

    ltmp = N;
    ll base = 26;
    while(ltmp>base){
        ltmp -= base;
        base*=26;
        num_mozi++;
    }

    base = base/26;
    //cout << num_mozi << endl;
    //cout << ltmp << endl;
    //cout << base << endl;
    ltmp = N ;
    string S = "";
    ll val = ltmp % 26;
    ltmp -= val;
    if(val==0){
        val = 26;
        //val = ltmp / 26;
        ltmp-=26;
    }
    S = char('a'+val-1) + S;

    while(ltmp>0){
        ltmp = ltmp / 26;
        val = ltmp % 26;
        ltmp -= val;
        if(val==0){
            val = 26;
            ltmp-=26;
        }
        S = char('a'+val-1) + S;
    }

    cout << S;

}


#include<iostream>
#include<sstream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<cfloat>
#include<functional>
#include<map>
#include<string>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<deque>
#include<set>
#include<bitset>
#include<list>
#include<numeric>
#include<complex>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<long long, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<long long, long long> ll_ll;
typedef pair<double, double> d_d;
typedef vector<int> Vint;

#define PI 3.141592653589793238462643383279
#define mod 1000000007LL
#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define rep2d(i, j, n) for(i = 0;i < n;++i)for(j = i + 1;j < n;++j)
#define per(i, n) for(i = n - 1;i > -1;--i)
#define int(x) int x; scanf("%d",&x)
#define int2(x, y) int x, y; scanf("%d%d",&x, &y)
#define int3(x, y, z) int x, y, z; scanf("%d%d%d",&x, &y, &z)
#define int4(v, x, y, z) int v, x, y, z; scanf("%d%d%d%d", &v, &x, &y, &z)
#define int5(v, w, x, y, z) int v, w, x, y, z; scanf("%d%d%d%d%d", &v, &w, &x, &y, &z)
#define scn(n, a) rep(i, n)cin >> a[i]
#define sc2n(n, a, b) rep(i, n)cin >> a[i] >> b[i]
#define pri(x) cout << x << "\n"
#define pri2(x, y) cout << x << " " << y << "\n"
#define pri3(x, y, z) cout << x << " " << y << " " << z << "\n"
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define endl "\n"
#define kabe puts("---------------------------")
#define kara puts("")
#define debug(x) cout << " --- " << x << "\n"
#define debug2(x, y) cout << " --- " << x << " " << y << "\n"
#define debug3(x, y, z) cout << " --- " << x << " " << y << " " << z << "\n"
#define X first
#define Y second
#define eps 0.0001
#define prid(x) printf("%.15lf\n", x)

signed main(void){
  int i, j, k;
  for(int testcase = 0;testcase >= 0;testcase++){
    int3(m, nin, nax); if(!(m|nax|nin))break;
    int p[m]; scn(m, p);

    int res = 0, resi;
    nin--; nax--;
    for(i = nin;i <= nax;++i){
      if(res <= p[i] - p[i + 1]){ res = p[i] - p[i + 1]; resi = i + 1; }
    }
    pri(resi);

//*/

//*/ break;
  }
  return 0;
}


#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=999999999999;

int main(){
    ll a,b,k;
    cin>>a>>b>>k;
    bool flag=true;
    while(k){
        if(flag){
            a/=2;
            b+=a;
            flag=false;
        }else{
            b/=2;
            a+=b;
            flag=true;
        }
        k--;
    }
    cout<<a<<" "<<b<<endl;

}

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

int main(){
    vector<int> a(2);
    int k;
    cin >> a[0] >> a[1] >> k;

    int times = 0;
    int side = 0;
    while(1){
        if(a[side] % 2 == 1) a[side] -= 1;
        a[side] /= 2;
        a[(side+1)%2] += a[side];
        side += 1;
        side %= 2;
        times += 1;
        if(times == k) break;
    }

    cout << a[0] << " " << a[1] << endl;
    return 0;
}


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

int main() {
    string S;
    cin >> S;
    bool a=true;
    if(S.size()%2==1) a=false;
    else for(int i=0;i<S.size()/2;i++){
        if(S.at(i*2)!='h'||S.at(i*2+1)!='i') a=false;
    }
    if(a)cout << "Yes" << endl;
    else cout << "No" << endl;
}

#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
using namespace std;

using ll = long long;
using P = pair<ll, ll>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline void dump(vector<T> v) { for (auto& x : v) cerr << x << " "; cerr << endl; }
template<class T> inline void dump(vector<pair<T, T>> v) { for (auto& p : v) cerr << p.first << " " << p.second << endl; }
template<class T> inline void dump(vector<vector<T>> vv) { for (auto& v : vv) {for (auto& x : v) cerr << x << " "; cerr << endl;} }

constexpr int INF = 1e9+5;
constexpr long long INFLL = 1LL<<60;
constexpr double eps = (1e-9);

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

  int n;
  cin >> n;
  if (n == 0) {
    cout << 0 << endl;
    return 0;
  }

  string ans;
  while (n != 0) {
    if (n % 2 == 0) ans.append("0");  // 後で reverse するので末尾に足す
    else {
      ans.append("1");
      n -= 1;   // 余りを取り除く
    }
    n /= -2;
  }

  reverse(ALL(ans));

  cout << ans << endl;

  return 0;
}


#include<bits/stdc++.h>
using namespace std;
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
typedef long long ll;
struct dish{
  ll A,B;
  bool operator<(const dish &o) const {return A+B < o.A+o.B;}
  bool operator>(const dish &o) const {return A+B > o.A+o.B;}
};
int main(){
  ll N,i,ans = 0;scanf("%lld",&N);
  dish D[N];
  for(i=0;i<N;i++) scanf("%lld%lld",&D[i].A,&D[i].B);
  sort(D,D+N,greater<dish>());
  for(i=0;i<N;i++){
    if(i&1) ans -= D[i].B;
    else ans += D[i].A;
  }
  printf("%lld\n",ans);
}

#include<bits/stdc++.h>
#define rep(i,n) for (int i=0; i<n; i++)
#define REP(i,x,n) for (int i=x; i<n; i++)
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;

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

    vi A(n), B(n), C(n);
    rep(i,n) cin >> A[i];
    rep(i,n) cin >> B[i];
    rep(i,n) cin >> C[i];

    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    sort(C.begin(), C.end());

    ll ans = 0;
    rep(i,n){
        ll x = lower_bound(A.begin(), A.end(), B[i]) - A.begin();
        ll y = C.end() - upper_bound(C.begin(), C.end(), B[i]);
        ans += x * y;
        //cout << ans << endl;
    }

    cout << ans << endl;
    return 0;
}


#include <cstdio>
using namespace std;

namespace roadagain
{

struct union_find_node
{
    unsigned parent;
    unsigned lank;

    union_find_node() = default;
    union_find_node(unsigned num)
    {
        this->parent = num;
        this->lank = 1;
    }
};

class union_find_tree
{
public:
    union_find_tree(unsigned size) : size(size), group(size)
    {
        this->forest = new union_find_node[size];
        for (unsigned i = 0; i < size; i++){
            this->forest[i] = union_find_node(i);
        }
    }
    ~union_find_tree()
    {
        delete[] this->forest;
    }

    unsigned get_size()
    {
        return (this->size);
    }

    unsigned get_group()
    {
        return (this->group);
    }

    void unite(unsigned a, unsigned b)
    {
        if (this->forest[a].lank <= this->forest[b].lank){
            this->forest[b].parent = this->forest[a].parent;
            this->forest[a].lank++;
        }
        else {
            this->forest[a].parent = this->forest[b].parent;
            this->forest[b].lank++;
        }
        this->group--;
    }

    unsigned find(unsigned num)
    {
        if (this->forest[num].parent == num){
            return (num);
        }
        return (this->forest[num].parent = find(this->forest[num].parent));
    }

    bool same(unsigned a, unsigned b)
    {
        return (this->find(a) == this->find(b));
    }

private:
    const unsigned size;
    unsigned group;
    union_find_node* forest;
};

}
using namespace roadagain;

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

union_find_tree* uf;
char map[16][16];

void island(int y, int x)
{
    if (map[y][x] == '0') return;
    map[y][x] = '0';
    for (int i = 0; i < 4; i++){
        int tx = x + dx[i];
        int ty = y + dy[i];

        if (0 <= tx && tx < 12 && 0 <= ty && ty < 12){
            uf->unite(y * 12 + x, ty * 12 + tx);
            island(ty, tx);
        }
    }
}

int main()
{
    while (~scanf("%s", map[0])){
        for (int i = 1; i < 12; i++){
            scanf("%s", map[i]);
        }
        uf = new union_find_tree(12 * 12);

        int cnt = 0;
        for (int i = 0; i < 12; i++){
            for (int j = 0; j < 12; j++){
                if (map[i][j] == '1'){
                    cnt++;
                    island(i, j);
                }
            }
        }

        printf("%d\n", cnt);
        delete uf;
    }

    return 0;
}


#include <bits/stdc++.h>

#define ll long long
#define pii pair<int, int>
#define ull unsigned ll
#define f first
#define s second
#define FOR(i,a,b) for (int i=(a); i<(b); i++)
#define REP(i,n) for (int i=0; i<(n); i++)
#define RREP(i,n) for (int i=(n-1); i>=0; i--)
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)x.size()
#define SQ(x) (x)*(x)
#define MN(a,b) a = min(a,(__typeof__(a))(b))
#define MX(a,b) a = max(a,(__typeof__(a))(b))
#define pb push_back
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define bug(x) cerr<<#x<<" is "<<x<<endl

using namespace std;

#define int ll

const int iinf = 1<<29;
const ll inf = 1ll<<60;
const ll mod = 1e9+7;

void GG(){cout<<"Impossible\n"; exit(0);}

ll mpow(ll a, ll n, ll mo = mod){ // a^n % mod
    ll re=1;
    while (n>0){
        if (n&1) re = re*a %mo;
        a = a*a %mo;
        n>>=1;
    }
    return re;
}

ll inv (ll b, ll mo = mod){
    if (b==1) return b;
    return (mo-mo/b) * inv(mo%b) % mo;
}

const int maxn = 1e5+5;

ll gcd(ll a, ll b){
    if (b==0) return a;
    return gcd(b,a%b);
}

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

    int n, m; cin>>n>>m;
    vector<int> e, o;
    REP(i,m){
        int x; cin>>x; if (x&1)o.pb(x); else e.pb(x);
    }
    if (SZ(o)>2) GG();
    vector<int> re;
    vector<int> mo;
    if (SZ(o)) mo.pb(o[0]);
    mo.insert(mo.end(),ALL(e));
    if (SZ(o)>1) mo.pb(o[1]);
    REP(i, SZ(mo)){
        if (i==0) {if (mo[i]!=1) re.pb(mo[i]-1);}
        else if (i==SZ(mo)-1){
            re.pb(mo[i]+1);
        } else re.pb(mo[i]);
    }
    int s = 0; REP(i, SZ(re)) s += re[i];
    if (s!=n) re.pb(n-s);
    REP(i, SZ(mo)) cout<<mo[i]<<' '; cout<<endl;
    cout<<SZ(re)<<endl;
     REP(i, SZ(re)) s+=re[i],cout<<re[i]<<' ';
}

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,m,a[100005];
int main()
{
	scanf("%d%d",&n,&m);
	int ct=0;
	for(int i=1;i<=m;i++)
	{
		scanf("%d",&a[i]);
		if(a[i]%2) ct++;
	}
	if(ct>2)
	{
		printf("Impossible\n");
		return 0;
	}
	int id1=0,id2=0;
	for(int i=1;i<=m;i++)
		if(a[i]%2)
		{
			if(!id1) id1=i;
			else if(!id2) id2=i;
		}
	if(id1)
	{
		if(id2==1) id2=id1;
		swap(a[1],a[id1]);
	}
	if(id2) swap(a[m],a[id2]);
	if(m==1)
	{
		if(a[1]==1) printf("1\n1\n1\n");
		else printf("%d\n2\n%d 1\n",a[1],a[1]-1);
		return 0;
	}
	if(!id2)
	{
		for(int i=1;i<=m;i++)
			printf("%d ",a[i]);
		printf("\n%d\n",m);
		for(int i=1;i<=m;i++)
		{
			if(i==1) printf("%d ",a[i]+1);
			else if(i==m) printf("%d ",a[i]-1);
			else printf("%d ",a[i]);
		}
		return 0;
	}
	if(n==2&&m==2)
	{
		printf("1 1\n1\n2\n");
		return 0;
	}
	if(n==4&&m==3)
	{
		printf("1 2 1\n2\n2 2\n");
		return 0;
	}
	if(a[1]==1&&a[m]==1)
	{
		for(int i=1;i<=m;i++)
			printf("%d ",a[i]);
		printf("\n%d\n",m-1);
		for(int i=2;i<=m;i++)
		{
			if(i==m) printf("%d ",a[i]+1);
			else printf("%d ",a[i]);
		}
		return 0;
	}
	for(int i=1;i<=m;i++)
		printf("%d ",a[i]);
	printf("\n%d\n",m);
	for(int i=1;i<=m;i++)
	{
		if(i==1) printf("%d ",a[i]+1);
		else if(i==m) printf("%d ",a[i]-1);
		else printf("%d ",a[i]);
	}
	return 0;
}


#include <bits/stdc++.h>
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);
#define ADD +
#define SUBTRACT -
#define MULTIPLY *
#define DIVIDE /
#define MOD %
#define INCREMENT(x) ++x
#define DECREMENT(x) --x
#define in(a,b) cin>>a>>b;
#define out(a,b) cout<<a<<endl<<b<<endl;
#define scan(a) scanf("%d",&a);
#define print(a) printf("%d\n",a);
#define scanii(a,b) scanf("%d %d",&a,&b);
#define printii(a,b) printf("%d\n%d\n",a,b);
#define scaniii(a,b,c) scanf("%d %d %d",&a,&b,&c);
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define ll long long
#define ull unsigned long long
#define sll signed long long
#define pi acos(-1)
#define mod 1000000007
#define TRUE 1
#define FALSE 0
#define ZERO 0
#define MP make_pair
#define F first
#define S second
#define f1(i,a) for(int i=0;i<a;++i)
#define f2(i,a) for(int i=a-1;i>=0;--i)
#define en puts("");
#define elif else if
typedef ll int lli;
typedef sll int slli;
typedef ull int ulli;
const int sz=10000;
using namespace std;

int clue();
int result();
void show();
bool check();

bool cmp(pair<int,int>p,pair<int,int>q) {
    // return p.first>q.first;//descending by first
    // return p.first<q.first;//ascending by first
    // return p.second>q.second;//descending by second
    return p.second<q.second;//ascending by second
}

// bool cmp(int p,int q) {
    // return p>q;//descending
    // return p<q;//ascending
// }

int main() {

    int t;
    // cin>>t;
    t=1;
    while(t-->0) {
        clue();
    }

    return 0;
}
int clue() {

    int a,b,c;
    cin>>a>>b>>c;
    cout<<c<<" "<<a<<" "<<b<<endl;

    // (det)?cout<<"Yes"<<endl:cout<<"No"<<endl;

    return 0;
}

#include <stdio.h>
int main(){
	int X,Y,Z;
	int *px,*py,*pz;
	scanf("%d",&X);
	scanf("%d",&Y);
	scanf("%d",&Z);
	px = &Z;
	py = &X;
	pz = &Y;
	printf("%d %d %d",*px,*py,*pz);
}


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

int main() {
  string s;
  int k;
  cin >> k >> s;
  int n = s.size();
  if(n <= k){
    cout << s << endl;
    return 0;
  }else{
    int i = 0;
    while(i<=k-1){
      cout << s.at(i);
      if(i==k-1){
        cout << "..." << endl;
        return 0;
      }
      i++;
    }
  }
}

#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main ()
{
	int M,N,mo[10000],sk[10000]={};

	cin>>N>>M;

	for(int i=0;i<N;i++)
	{
		cin>>mo[i];
	}
	for(int i=0;i<M;i++)
	{
		int aa;
		cin>>aa;
		for(int q=0;q<N;q++)
		{
			if(mo[q]<=aa){sk[q]++;
			break;
			}
		}
	}
	int z=0,b=0;
	for(int i=0;i<N;i++)
	{
		if(sk[i]>b){
			b=sk[i];
			z=i;
		}
	}
	z++;
	cout<<z<<endl;
return 0;
}


//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<P> lr(n);
    rep(i, n) cin >> lr[i];

    sort(all(lr));
    int ans = 0;
    vi mil(n+1, INT_MAX), mir(n+1, INT_MAX);
    rep(i, n) {
        mil[i+1] = min(mil[i], lr[i].second);
        mir[n-1-i] = min(mir[n-i], lr[n-1-i].second);
    }

    int min = INT_MAX;
    rep(i, n-1) {
        chmin(min, lr[i].second);
        if(min < lr[i].first) break;
        chmax(ans, min-lr[i].first + mir[i+1]-lr[n-1].first + 2);
    }
    rep(i, n) {
        chmax(ans, lr[i].second - lr[i].first + 1 + (mil[n] >= lr[n-1].first?mil[n]-lr[n-1].first+1:0));
    }

    cout << ans << endl;
}

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

pair<int, int> intersect(const pair<int, int> &lhs, const pair<int, int> &rhs) {
    return {max(lhs.first, rhs.first), min(lhs.second, rhs.second)};
}

int length(const pair<int, int> &interval) {
    if (interval.first > interval.second) {
        return 0;
    } else {
        return interval.second - interval.first + 1;
    }
}

int main() {
    int n = 0;
    cin >> n;
    vector<pair<int, int>> seg(n);
    pair<int, int> left = {0, 1e9}, right = {0, 1e9};
    for (auto &i:seg) {
        cin >> i.first >> i.second;
        if (i.first > right.first) {
            right = i;
        }
        if (i.second < left.second) {
            left = i;
        }
    }
    for (int i = 0; i < seg.size(); ++i) {
        if (seg[i] == left) {
            seg.erase(begin(seg) + i);
            i--;
            if (seg.empty()) {
                break;
            } else {
                continue;
            }
        }
        if (seg[i] == right) {
            seg.erase(begin(seg) + i);
            i--;
            if (seg.empty()) {
                break;
            } else {
                continue;
            }
        }
    }
    int ans = 0;
    if (!seg.empty()) {
        pair<int, int> inter = {0, -1};
        for (const auto &i:seg) {
            if (length(i) > length(inter)) {
                inter = i;
            }
        }
        ans = length(inter) + length(intersect(left, right));
    } else {
        ans = length(left) + length(right);
    }
    if (!seg.empty()) {
        sort(begin(seg), end(seg));
        vector<int> suf(seg.size());
        suf[seg.size() - 1] = seg[seg.size() - 1].second;
        for (int i = static_cast<int>(seg.size()) - 2; i >= 0; --i) {
            suf[i] = min(suf[i + 1], seg[i].second);
        }
        for (int i = 0; i < seg.size(); ++i) {
            int first = length(intersect(seg[i], left)),
                second = i + 1 < seg.size() ? length(intersect({right.first, suf[i + 1]}, right)) : length(right);
            ans = max(ans, first + second);
        }
        ans = max(ans, length(left) + length(intersect({right.first, suf[0]}, right)));
    }
    cout << ans;
    return 0;
}


#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>

using namespace std;

void call(int n){
	for(int i = 1; i <= n; i++){
		if(i % 3 == 0) cout << " " << i;
		else{
			for(int tmp = i; tmp != 0; tmp /= 10){
				if(tmp % 10 == 3){
					cout << " " << i;
					break;
				}
			}
		}
	}
	cout << endl;
}

int main(){
	int n;
	cin >> n;
	call(n);
	return 0;
}

#include<iostream>
using namespace std;

int x, i = 1;
int n;

void check_num();
void include3();
void end_check_num();

void check_num() {
	x = i;
	if (x % 3 == 0){
		cout << " " << i;
		end_check_num();
	}else include3();
}

void include3() {
	if (x % 10 == 3){
		cout << " " << i;
		end_check_num();
	}else{
		x /= 10;
		if (x)include3();
		else end_check_num();
	}
}

void end_check_num() {
	if (++i <= n) check_num();
}

int main() {
	cin >> n;
	check_num();
	cout << endl;
	char c;
	cin >> c;
}


#include <bits/stdc++.h>

using namespace std;
using Graph = vector<vector<int>>;
using Grid= vector<vector<char>>;
using vin= vector<int>;
using ll=long long;
using vll= vector<ll>;
using vbl=vector<bool>;
using vch=vector<char>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define sort(x) sort(x.begin(), x.end());
#define rese(x) reverse(x.begin(), x.end());

int main() {
    int a,b;
    cin>>a>>b;
    cout<<a*b<<endl;

}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x)  x.begin(),x.end()
#define vi vector<int>
#define vll vector<ll>
#define print(x) for(auto it=x.begin();it!=x.end();it++) cout<<*it<<' '; cout<<'\n';
#define debug(a,b,c) cout << a << " " << b << " " << c << endl;
#define in(x,n) for(int e=0;e<n;e++){int y;cin>>y;x.pb(y);}
#define inl(x,n) for(int e=0;e<n;e++){ll y;cin>>y;x.pb(y);}
#define lower(sl)  transform(sl.begin(), sl.end(), sl.begin(), ::tolower);
#define endl "\n";
#define pi pair<int,int>
#define vpi vector<pair<int,int>>
#define vvi vector<vector<int>>

int solve(int st, vi a, int& ans,int& n){
	if(st > n ) return 0;
	int res = 0;
	int x1 = solve(st*2, a, ans, n);
	int x2 = solve(st*2+1, a, ans, n);
	int l1 = (st*2-2)>=a.size()?0:a[st*2-2];
	int l2 = (st*2-1)>=a.size()?0:a[st*2-1];
	l2 += x2; l1+=x1;
	ans += abs(l2-l1);
	return max(l1,l2);
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//code here
	int a, b;
	cin >> a>> b;
	cout << (ll) a*b << endl;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
  int n,tmp;
  cin >> n;
  int a[110];
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }
  for(int i = n-1; i >= 0;i--){
    cout << a[i];
    if(i != 0){
      cout << " ";
    }
  }
  /*ソートじゃなかった！
  for(int i = 0;i < n-1; i++){
    for(int j = n-1;j > i;j--){
      if(a[j-1] < a[j]){
        tmp = a[j-1];
        a[j-1] = a[j];
        a[j] = tmp;
      }
    }
  }
  for(int i = 0;i < n; i++){
    cout << a[i];
    if(i != n-1){
      cout << " ";
    }
  }
  */
  cout << endl;
  return 0;
}

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

#define f first
#define s second
#define ins insert
#define eb emplace_back
#define endl '\n'
#define ll long long
#define ld long double
#define vl vector<ll>
#define tc ll t; cin >> t; while (t--)
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
#define sz(c) (ll) c.size()
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define trav(x,c) for(auto &x : c)
#define _for(i,a,n) for(ll i = a ; i < n ; ++i)
#define _rfor(i,a,n) for(ll i = n-1 ; i >= a ; --i)
#define dx(x) cout << #x << ": " << x << endl;
#define dc(c) trav(x,c) cout << x << " "; cout << endl;
#define godspeed ios::sync_with_stdio(0); cin.tie(0);

int main() {
    godspeed;
    set<int> s;
    int x;
    while(cin >> x) {
        s.ins(x);
    }

    if(sz(s) == 2) yes;
    else no;
}


#include <stdio.h>
//#include <math.h>
using namespace std;

int log10(int n) {
	int keta = 0;
	do{
		n /= 10;
		keta++;
	} while (n > 0);
	return keta;
}

int main() {
	const int MAX_N = 20;
	int N;
	int table[MAX_N][MAX_N];

	while (1) {
		for (int i = 0;i < MAX_N;i++) {
			for (int j = 0;j < MAX_N;j++) {
				table[i][j] = 0;
			}
		}
		scanf("%d", &N);
		if (!N)break;
		for (int i = 0;i < N;i++) {
			for (int j = 0;j < N;j++) {
				scanf("%d", &table[i][j]);
			}
		}

		for (int i = 0;i < N;i++) {
			for (int j = 0;j < N;j++) {
				table[i][N] += table[i][j];
				table[N][j] += table[i][j];
				table[N][N] += table[i][j];
			}
		}

		for (int i = 0;i <= N;i++) {
			for (int j = 0;j <= N;j++) {
				for (int k = 0;k < 5-log10(table[i][j]);k++) {
					printf(" ");
				}
				printf("%d", table[i][j]);
			}
			printf("\n");
		}
	}

	return 0;
}


// 解き直し.
// https://img.atcoder.jp/soundhound2018-summer-qual/editorial.pdf
#include <bits/stdc++.h>
using namespace std;

int main(){

    // 1. 入力情報.
    double n, m, d;
    scanf("%lf %lf %lf", &n, &m, &d);

    // 2. 出力.
    if(d == 0) printf("%.10lf", (m - 1.0) * 1.0 / n);
    else       printf("%.10lf", (m - 1.0) * 2.0 * (n - d) / n / n);
    return 0;

}

#include <iostream>
using namespace std;
int main()
{
    string date;
    getline(cin,date);
    string date2;
    date2=date.substr(4,6);
    cout << "2018"<< date2;

}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0);

	int n;
	cin >> n;
	ll a, b;
	vector<pair<ll, ll>> v;
	for (int i = 0; i < n; ++i)
	{
		cin >> a >> b;
		v.push_back({a, b});
	}

	vector<vector<ll>> dp(n, vector<ll>(n, -1));
	function<ll(int, int)> f = [&](int i, int j)
	{
		if (i == j)
			return 0LL;

		if (dp[i][j] != -1)
			return dp[i][j];

		ll r = 1LL<<62;
		for (int k = i; k < j; ++k)
			r = min(r, f(i, k)+f(k+1, j)+v[i].first*v[j].second*v[k].second);

		return dp[i][j]=r;
	};

	cout << f(0, n-1) << "\n";

	return 0;
}

// http://algorithms.blog55.fc2.com/blog-entry-66.html

#include <stdio.h>
#include <string.h>

#define M 100

int N,R[M+1],C[M][M],B[M][M];

void compute(){
	int i=0,j,k,cost;
	memset(C,99,sizeof(C));
	for(;i<N;i++)C[i][i]=0;
	for(j=1;j<N;j++)
		for(i=0;i<N - j; i++ )
			for (k = i; k < i + j; k++ ){
				cost = C[i][k] + C[k+1][i+j] + R[i]*R[k+1]*R[i+j+1];
				if(cost<C[i][i+j])C[i][i+j]=cost,B[i][i+j]=k;
			}
}

void order( int i, int j ){
	if(i==j)printf("M%d",i);
	else{
		printf("(");
		order( i, B[i][j]-1 ); order(B[i][j], j);
		printf(")");
	}
}

void input(){
	scanf("%d",&N);
	int z,i=0;
	for(;i<N;i++)scanf("%d%d",R+i,&z);
	R[i]=z;
}

void output(){
	printf("%d\n",C[0][N-1]);
	//order(0, N);
	//puts("");
}

main(){
	input();
	compute();
	output();
}


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

typedef long long LL;

const int N = 3e5;
const LL MOD = 1e9+7;

inline LL dmod(LL x){
	return x%MOD;
}

LL fakto[N+5];

void pre(){
	fakto[0] = 1LL;
	for(int i=1;i<=N;i++){
		fakto[i] = dmod(fakto[i-1]*(LL)(i));
	}
	return;
}

LL fe(LL x, LL y){
	if(y==0) return 1LL;
	LL ret = fe(x,y/2);
	ret = dmod(ret*ret);
	if(y&1){
		ret = dmod(ret*x);
	}
	return ret;
}

LL nCr(LL x, LL y){
	LL tmp = dmod(fakto[y]*fakto[x-y]);
	tmp = fe(tmp,MOD-2);
	tmp = dmod(tmp*fakto[x]);
	return tmp;
}

LL step(int x, int y, int a, int b){
	int dx = a-x;
	int dy = b-y;
	int tot = dx+dy;
	return nCr(tot,dx);
}

int h,w,a,b;
int main(){
	pre();
	cin >> h >> w >> a >> b;
	LL ret = 0LL;
	for(int i=1;i<=h-a;i++){
		LL tmp = step(1,1,i,b);
		tmp = dmod(tmp*step(i,b+1,h,w));
		ret = dmod(ret+tmp);
	}
	cout << ret << endl;
	return 0;
}

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
const long long mod=1000000007;
const int maxn=200005;
ll inv[maxn],s[maxn];
int N,n,m,x,y;
ll Pow(ll a,int b)
{
	ll ans=1;
	while(b)
	{
		if(b&1)
			ans=ans*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return ans;
}
ll C(int a,int b)
{
	if(a<0||b<0)
		return 1;
	return s[a]*inv[b]%mod*inv[a-b]%mod;
}
int main()
{
	scanf("%d%d",&n,&m);
    scanf("%d%d",&x,&y);
    N=n+m-2;
    s[0]=1;
    for(int i=1;i<=N;i++)
    	s[i]=s[i-1]*i%mod;
    inv[0]=1;
    inv[N]=Pow(s[N],mod-2);
    for(int i=N-1;i>0;i--)
    	inv[i]=inv[i+1]*(i+1)%mod;
    ll ans=0;
    for(int i=y+1;i<=m;i++)
    {
    	ans+=C(n-x+i-2,i-1)*C(x+m-i-1,x-1)%mod;
    	ans%=mod;
	}
	printf("%lld\n",ans);
	return 0;
}


#include<stdio.h>

int main(){

	char S[100], T[100];
	scanf("%s %s", S, T);
	printf("%s%s\n", T, S);

	return 0;
}

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using P = pair<int,int>;
using ll = long long;

int main(){
    ll k,x;
    cin>>k>>x;
    ll n=k-1;
    for(ll i=x-n;i<=x+n;i++){
        cout<<i<<" ";
    }
    cout<<endl;

}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (n);i++)
using ll = long long;
const ll MOD=1000000007;

int main()
{
  ll x; cin>>x;
  ll ans=x/11*2;
  x%=11;
  if(x!=0)
  {
    if(x>=7)
    {
      ans++;
    }
    ans++;
  }
  cout<<ans<<endl;
  return 0;
}

#include <iostream>
#include <string>
using namespace std;

int main() {
  string str;
  int a, b, l, x;
  char c;
  while (getline(cin, str)) {
    x = 0;
    l = (int)str.size();
    for (int i=0; i<l; i++) {
      c = str.at(i);
      if (c == 'I') a = 1;
      else if (c == 'V') a = 5;
      else if (c == 'X') a = 10;
      else if (c == 'L') a = 50;
      else if (c == 'C') a = 100;
      else if (c == 'D') a = 500;
      else if (c == 'M') a = 1000;
      if (i) {
        if (b >= a) {
          x += b;
        } else {
          x -= b;
        }
      }
      b = a;
    }
    x += b;
    cout << x << endl;
  }
  return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
int main()
{
    ll n, T;
    cin >> n >> T;
    ll ans = 0;
    vector<ll> t(n);

    rep(i, n)
    {
        cin >> t[i];
    }
    rep(i, n)
    {
        if (i + 1 >= n)
        {
            ans += T;
        }
        else if (t[i + 1] > t[i] + T)
        { //かぶっていなかったら
            ans += T;
        }
        else
        {
            ans += t[i + 1] - t[i];
        }
        // cout << ans << endl;
    }
    cout << ans << endl;
    return 0;
}

#include "bits/stdc++.h"

using namespace std;

void Main() {
    long long N, T;
    cin >> N >> T;
    long long ans = 0LL;
    long long prevt;
    cin >> prevt;
    for (long long i = 1; i < N; ++i) {
        long long t;
        cin >> t;
        if (T <= t - prevt) {
            ans += T;
        }
        else {
            ans += t - prevt;
        }
        prevt = t;
    }
    ans += T;
    cout << ans << endl;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


#include<iostream>
#include<string>
#include<cmath>

using namespace std;

int main() {
	int n, a[100],ans;
	float sum = 0,min=101.0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		sum += a[i];
	}
	sum /= n;
	for (int i = 0; i < n; i++) {
		if (fabs(a[i] - sum) == min)continue;
		if (fabs(a[i] - sum) < min){
          	min = fabs(a[i] - sum);
			ans = i;

        }
	}
	cout << ans;
}

#include <iostream>

int main(void){
    int N, ans=40;
    std::cin >> N;

    for (int i=0; i<N; ++i){
        int a, cnt=0;
        std::cin >> a;
        while (a % 2 == 0){
            a /= 2;
            ++cnt;
        }
        if (cnt < ans) ans = cnt;
    }

    std::cout << ans << std::endl;

    return 0;
}


#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

int main() {
	const Int MOD = 1e9 + 7;
	int N, M;
	cin >> N >> M;
	vector<int> a(N), b(M);
	vector<Int> cnt_a(1000010, 0), cnt_b(1000010, 0);
	bool ok = true;
	for (int i = 0; i < N; ++i) {
		cin >> a[i];
		++cnt_a[a[i]];
		if (cnt_a[a[i]] > 1) { ok = false; }
	}
	for (int i = 0; i < M; ++i) {
		cin >> b[i];
		++cnt_b[b[i]];
		if (cnt_b[b[i]] > 1) { ok = false; }
	}
	if (!ok) {
		cout << 0 << endl;
		return 0;
	}

	Int ans = 1;
	for (int i = N * M; i > 0; --i) {
		if (cnt_a[i] == 0 && cnt_b[i] == 0) {
			Int tmp = cnt_a[i + 1] * cnt_b[i + 1] % MOD;
			tmp = (tmp + MOD - (N * M - i)) % MOD;
			(ans *= tmp) %= MOD;
		} else if (cnt_a[i] != 1 || cnt_b[i] != 1) {
			if (cnt_a[i] > 0) {
				(ans *= cnt_b[i + 1]) %= MOD;
			} else {
				(ans *= cnt_a[i + 1]) %= MOD;
			}
		}

		cnt_a[i] += cnt_a[i + 1];
		cnt_b[i] += cnt_b[i + 1];
	}
	cout << ans % MOD << endl;

	return 0;
}

#include <bits/stdc++.h>
#pragma GCC optimize ("O2,unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<ll, ll> pll;
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugp(x) cerr<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl;
#define debug2(x, y) cerr<<"{"<<#x<<", "<<#y<<"} = {"<<(x)<<", "<<(y)<<"}"<<endl;
#define debugv(v) {cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;}
#define all(x) x.begin(), x.end()
#define pb push_back
#define kill(x) return cout<<x<<'\n', 0;

const ld eps=1e-7;
const int inf=1000000010;
const ll INF=10000000000000010LL;
const int mod=1000000007;
const int MAXN=1010;

ll n, m, k, u, v, x, y, t, a, b, ans=1;
int A[MAXN], B[MAXN];

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	cin>>n>>m;
	for (int i=0; i<n; i++) cin>>A[i];
	for (int i=0; i<m; i++) cin>>B[i];
	sort(A, A+n);
	sort(B, B+m);
	reverse(A, A+n);
	reverse(B, B+m);
	int i=0, j=0, t=0;
	for (int num=n*m; num; num--, t++){
		if (A[i]!=num && B[j]!=num) ans=ans*(i*j-t)%mod;
		if (A[i]!=num && B[j]==num) ans=ans*i%mod;
		if (A[i]==num && B[j]!=num) ans=ans*j%mod;

		i+=(A[i]==num);
		j+=(B[j]==num);
	}
	cout<<ans<<"\n";

	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(c) begin(c), end(c)
#define range(i,a,b) for(int i = a; i < (int)(b); i++)
#define rep(i,b) range(i,0,b)
#define eb emplace_back
typedef long long ll;
#define int ll
auto const inf = numeric_limits<int>::max()/4;

using Weight = int;
using Capacity = int;
struct Edge {
    int src, dst; Weight weight;
    Edge(int s, int d, int w) : src(s), dst(d), weight(w) {}
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;
using Array = vector<Weight>;
using Matrix = vector<Array>;

pair<vector<Weight>, bool> spfa(const Graph &g, int s){
    const Weight inf = numeric_limits<Weight>::max()/4;
    const int n = g.size(); priority_queue<int> q;
    vector<Weight> dist(n, inf); vector<int> inQ(n);
    vector<int> count(n);
    dist[s] = 0; q.emplace(s); inQ[s] = true; ++count[s];
    bool negCycle = false;
    for(int i = 0; q.size(); i++){
        int v = q.top(); q.pop(); inQ[v] = false;
        for(auto &e : g[v]){
            if(dist[v] != inf && dist[e.dst] > dist[v] + e.weight){
                dist[e.dst] = dist[v] + e.weight;
                if(!inQ[e.dst]){
                    q.emplace(e.dst); inQ[e.dst] = true; ++count[e.dst];
                    if(count[e.dst] >= n){ negCycle = true; goto END; }
                }
            }
        }
    }
 END:;
    return make_pair(dist, !negCycle);
}

signed main(){
    int V,E,r;
    while(cin >> V >> E >> r){
        Graph g(V);
        rep(i,E){
            int a,b,c;
            cin >> a >> b >> c;
            g[a].eb(a,b,c);
        }
        bool ok;
        vector<Weight> dist;
        tie(dist, ok) = spfa(g,r);
        if(ok){
            for(int i = 0; i < (int)dist.size(); i++){
                if(dist[i] == inf) cout << "INF";
                else cout << dist[i];
                cout << endl;
            }
        } else {
            cout << "NEGATIVE CYCLE" << endl;
        }
    }
}

#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<stack>
#include<queue>
#include<sstream>
#include<string>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i);

using namespace std;

const int MAX_V = 100001;
const long long INF = 1e12;

int n,m,r;

struct edge{
	int to, dist;
	edge(int t_to,int t_dist){
		to=t_to;dist=t_dist;
	}
};

typedef pair<int,int> P;//cost??¨v

vector< vector<edge> > G(MAX_V);
long long d[MAX_V];

void dijkstra(int s){
	priority_queue<P,vector<P>,greater<P> > que;
	fill_n((long long *)d, sizeof(d)/sizeof(long long),INF);
	d[s] = 0;
	que.push(P(0,s));

	while(!que.empty()){
		P p = que.top(); que.pop();
		int v = p.second;
		if(d[v]<p.first) continue;
		rep(i,G[v].size()){
			edge e = G[v][i];
			if(d[e.to] > d[v] + e.dist){//??????????????´???
				d[e.to] = d[v] + e.dist;
				que.push(P(d[e.to],e.to));
			}
		}
	}
}

int main(){

	cin >> n >> m >> r;

//	G.clear();
//	G.resize(n);

	rep(i,m){
		int a,b,d;
		cin >> a >> b >> d;
		edge tmp1(b,d);
		G[a].push_back(tmp1);
	}

	dijkstra(r);
	rep(i,n){
		//if(i==r) continue;
		if(d[i]==INF) cout << "INF" <<endl;
		else cout << d[i] << endl;
	}

}


#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <functional>
#include <numeric>

using namespace std;
using lint = int64_t;
using P = pair<int, int>;
using D = pair<double, double>;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
#define repn(i, a, b) for(int i = (a); i < (b); ++i)
#define Rep(i, n) for (int i = (n); i >= 0; --i)
#define All(vec) vec.begin(), vec.end()
#define cend printf("\n")

//constexpr lint mod = 998'244'353LL;
constexpr lint mod = 1000'000'007LL;
constexpr lint inf = 3LL * mod * mod;
const double Pi = 2.0 * acos(0.0);

template<class T> using prique     = priority_queue<T>;
template<class T> using prique_inv = priority_queue<T, vector<T>, greater<T>>;
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& rhs) { return is >> rhs.first >> rhs.second; }
template<class T, class U>inline ostream& operator<<(ostream& os, const pair<T, U>& rhs) { return os << rhs.first << " " << rhs.second << "\n"; }
template<class InputIterator> void arrin(InputIterator first, InputIterator last) { for (; first != last; ++first) cin >> (*first); }
template<class InputIterator> void arrout(InputIterator first, InputIterator last) {
	for (; first != last; ++first) {
		cout << (*first) << " ";
	}
	cout << "\n";
}

constexpr bool pri(lint x) { for (lint i = 2; i * i <= x; ++i) if (x % i == 0) return false; return 1 < x; }

inline double dis(D a, D b) { return hypot(a.first - b.first, a.second - b.second); }

lint fact[3000000];
void fact_init(lint n) {
	if (3000000 <= n) return;
	fact[0] = fact[1] = 1;
	for (lint i = 2; i <= n; ++i) {
		fact[i] = i * fact[i - 1];
		if (mod <= fact[i]) fact[i] %= mod;
	}
}

lint modpow(lint x, lint n, lint m = mod) {
	lint res = 1;
	while (n > 0) {
		if (n & 1) {
			res *= x;
			if (m <= res) res %= m;
		}
		x *= x;
		if (m <= x) x %= m;
		n >>= 1;
	}
	return res;
}

lint intpow(lint x, lint n) {
	lint res = 1;
	while (n > 0) {
		if (n & 1) res *= x;
		x *= x;
		n >>= 1;
	}
	return res;
}

lint comb(lint n, lint r) {
	if (r == 0 || r == n) return 1;
	lint res = fact[n] * modpow(fact[n - r], mod - 2) % mod * modpow(fact[r], mod - 2) % mod;
	return res < 0 ? res + mod : res;
}

map<lint, lint> factring(lint n) {
	map<lint, lint> res;
	for (lint i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			n /= i;
			++res[i];
		}
	}
	if (n != 1) ++res[n];
	return res;
}

int n, k;
bool f(vector<int>& a) {
	vector<int>b(n + 1);
	rep(i, n) {
		b[max(0, i - a[i])]++;
		b[min(n, i + a[i] + 1)]--;
	}
	rep(i, n) {
		b[i + 1] += b[i];
	}
	bool res = true;
	rep(i, n) {
		a[i] = b[i];
		res &= (a[i] == n);
	}
	return res;
}
int main() {
	cin >> n >> k;
	vector<int>a(n);
	rep(i, n) {
		cin >> a[i];
	}
	rep(i, k) {
		if (f(a)) break;
	}
	for (int e : a) cout << e << " ";
}

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define vec vector
#define fi first
#define se second
#define eb emplace_back
#define ef emplace_front
#define pof pop_front()
#define pob pop_back()
#define Rep(i,n) for(li i=0,nn=(li)(n);i!=nn;++i)
#define Rep1(i,n) for(li i=1,nn=(li)(n)+1;i!=nn;++i)
#define Size(v) (li)(v.size())
#define SortA(v) sort(v.begin(),v.end())
#define SortD(v) sort(v.rbegin(),v.rend())
#define All(a) (a).begin(),(a).end()
#define Input(a) for(li ii=0,nn=(li)(a.size());ii!=nn;++ii){cin>>(a).at(ii);}
#define Input2(a,b) for(li ii=0,nn=(li)(a.size());ii!=nn;++ii){cin>>(a).at(ii)>>(b).at(ii);}
#define mp make_pair
using li = int64_t;
using intl = int64_t;
using vi = vec<li>;
using vb = vec<bool>;
using vvi = vec<vi>;
using qi = deque<li>;
using pi = pair<li,li>;
using vpi = vec<pi>;
using si = set<li>;
using vsi = vec<si>;
using mii = map<li,li>;
using vmii = vec<mii>;
vec<li> dx = {0, 1, 0, -1, 1, 1, -1, -1};
vec<li> dy = {1, 0, -1, 0, 1, -1, 1, -1};
constexpr li INF = 9223372036854775807;

void Yes(li b){
  if(b)cout<<"Yes";
  else cout<<"No";
}
void yes(li b){
  if(b)cout<<"yes";
  else cout<<"no";
}

int main(){
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  cout.precision(16);

  li N=200000,K=41;
  cin >>N>>K;

  vector<int> A(N,0),B(N,0);

  if(K>41){
    Rep(i,N){
      cout<<N<<' ';
    }
    return 0;
  }

  Input(A);

  li l,r;
  Rep(j,K){
  Rep(i,N){
  	l=max(0L,i-A[i]);
  	r=min(N-1,i+A[i]);
  	B[l]++;
  	if(r+1<N){B[r+1]--;}
  }
  Rep1(i,N-1){
  	B[i]+=B[i-1];
  }
  Rep(i,N){
  	A[i]=B[i];
  	B[i]=0;
  }
}

for(auto&& a:A){
	cout<<a<<' ';
}

}


#include <iostream>
#define MEN 6
using namespace std;

struct IN_DICE
{
	int num1;
	int num2;
	int num3;
	int num4;
	int num5;
	int num6;
};

struct DICE
{
	int num;
};

int main()
{
	DICE A[MEN];
	DICE B1[MEN];
	DICE B2[MEN];
	DICE B3[MEN];

	IN_DICE in[100];
	int flag = 0;
	int x;
	int n;

	cin >> n;

	for ( int i = 0; i < n; i++)
	{
		cin >> in[i].num1 >> in[i].num2 >> in[i].num3 >> in[i].num4 >> in[i].num5 >> in[i].num6;
	}

	for (int i1 = 0; i1 < n - 1; i1++)
	{
		for (int i2 = i1 + 1; i2 < n; i2++)
		{
			A[0].num = in[i1].num1;
			A[1].num = in[i1].num2;
			A[2].num = in[i1].num3;
			A[3].num = in[i1].num4;
			A[4].num = in[i1].num5;
			A[5].num = in[i1].num6;

			B1[0].num = in[i2].num1;
			B1[1].num = in[i2].num2;
			B1[2].num = in[i2].num3;
			B1[3].num = in[i2].num4;
			B1[4].num = in[i2].num5;
			B1[5].num = in[i2].num6;

			for (int count = 0; count < MEN; count++)
			{
				for (int i = 0; i < MEN; i++)
				{
					B2[i] = B1[i];
				}
				if (1 <= count && count <= 5)
				{
					x = B2[0].num;
					B2[0].num = B2[1].num;
					B2[1].num = B2[5].num;
					B2[5].num = B2[4].num;
					B2[4].num = x;
				}

				if (2 <= count && count <= 4)
				{
					for (int i = 0; i < count - 1; i++)
					{
						x = B2[0].num;
						B2[0].num = B2[2].num;
						B2[2].num = B2[5].num;
						B2[5].num = B2[3].num;
						B2[3].num = x;
					}
				}

				if (count == 5)
				{
					x = B2[0].num;
					B2[0].num = B2[1].num;
					B2[1].num = B2[5].num;
					B2[5].num = B2[4].num;
					B2[4].num = x;
				}

				if (A[0].num != B2[0].num)
				{
					continue;
				}

				for (int i = 0; i < MEN; i++)
				{
					B3[i] = B2[i];
				}

				for (int count2 = 0; count2 < 4; count2++)
				{
					for (int i = 0; i < MEN; i++)
					{
						B2[i] = B3[i];
					}
					for (int i = 0; i < count2; i++)
					{
						x = B2[1].num;
						B2[1].num = B2[2].num;
						B2[2].num = B2[4].num;
						B2[4].num = B2[3].num;
						B2[3].num = x;
					}

					x = B2[0].num;
					B2[0].num = B2[1].num;
					B2[1].num = B2[5].num;
					B2[5].num = B2[4].num;
					B2[4].num = x;

					if (A[1].num != B2[0].num)
					{
						continue;
					}

					x = B2[0].num;
					B2[0].num = B2[2].num;
					B2[2].num = B2[5].num;
					B2[5].num = B2[3].num;
					B2[3].num = x;

					if (A[2].num != B2[0].num)
					{
						continue;
					}

					x = B2[0].num;
					B2[0].num = B2[2].num;
					B2[2].num = B2[5].num;
					B2[5].num = B2[3].num;
					B2[3].num = x;

					if (A[4].num != B2[0].num)
					{
						continue;
					}

					x = B2[0].num;
					B2[0].num = B2[2].num;
					B2[2].num = B2[5].num;
					B2[5].num = B2[3].num;
					B2[3].num = x;

					if (A[3].num != B2[0].num)
					{
						continue;
					}

					x = B2[0].num;
					B2[0].num = B2[1].num;
					B2[1].num = B2[5].num;
					B2[5].num = B2[4].num;
					B2[4].num = x;

					if (A[5].num == B2[0].num)
					{
						flag = 1;
					}
					if (flag == 1)
					{
						break;
					}
				}
				if (flag == 1)
				{
					break;
				}
			}
			if (flag == 1)
			{
				break;
			}
		}
		if (flag == 1)
		{
			break;
		}
	}

	if (flag == 1)
	{
		cout << "No" << endl;
	}
	else if (flag == 0)
	{
		cout << "Yes" << endl;
	}

	return 0;
}

/*+lmake
 * STD = c++14
 * DEFINE += WAAUTOMATON
 */
#include <bits/stdc++.h>
using namespace std;
using LL=long long;
using ULL=unsigned long long;
#ifdef WAAUTOMATON
#define debug(args...)            {dbg,args; cerr<<endl;}
#else
#define debug(args...)              // Just strip off all debug tokens
#endif

struct debugger
{
	template<typename T> debugger& operator , (const T& v)
	{
		cerr<<v<<" ";
		return *this;
	}
} dbg;
#define MAXN 100000
int c[MAXN+10];
bool b[MAXN+10];
void solve(long long N, vector<vector<long long>> a){
	int r[2]={0,0},f[2]={0,0};
	for(int i=0; i<N; ++i) {
		c[i]=a[1][i]/3+1;
		if (c[i]%2==i%2) throw 2;
		if (a[0][i]==c[i]*3-2 && a[1][i]==c[i]*3-1 && a[2][i]==c[i]*3) {
		} else if (a[0][i]==c[i]*3 && a[1][i]==c[i]*3-1 && a[2][i]==c[i]*3-2) {
			r[(i+1)&1]^=1;
		} else {
			throw 1;
		}
	}
	memset(b,true,sizeof(b));
	for(int i=1; i<=N; ++i) {
		if (b[i]) {
			int x=c[i-1];
			while(x!=i) {
				debug(x);
				b[x]=false;
				f[i&1]^=1;
				x=c[x-1];
			}
		}
	}
	debug(f[0],f[1]);
	debug(r[0],r[1]);
	if (f[0]!=r[1] || f[1]!=r[0]) throw 3;
	puts("Yes");
}

int main(){
#ifdef WAAUTOMATON
	freopen("in.txt","r",stdin);
#endif
	long long N;
	scanf("%lld",&N);
	vector<vector<long long>> a(3-1+1,vector<long long>(N-1+1));
	for(int i = 0 ; i <= 3-1 ; i++){
		for(int j = 0 ; j <= N-1 ; j++){
			scanf("%lld",&a[i][j]);
		}
	}
	try {
		solve(N, a);
	} catch(int err) {
		puts("No");
		debug(err);
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;

#define REP(i,e,s) for(register int i=e; i<=s; i++)
#define DREP(i,e,s) for(register int i=e; i>=s; i--)
#define ll long long
#define DE(...) fprintf(stderr,__VA_ARGS__)
#define DEBUG(a) DE("DEBUG: %d\n",a)

#define int long long

int read() {
	int x=0,f=1,ch=getchar();
	while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
const int MOD=1e9+7,MAXN=200000+10;

int fac[MAXN],inv[MAXN];

int qpow(int a,int b) {
	int ans=1;
	while(b) {
		if(b&1) ans=(ans*a)%MOD;
		a=(a*a)%MOD;
		b>>=1;
	}
	return ans;
}

int c(int m,int n) {
	if(n==m||!m||!n) return 1;
	return ((fac[m]*inv[n]%MOD)*inv[m-n])%MOD;
}

int calc(int x_1,int y_1,int x_2,int y_2) {
	return c(abs(x_2-x_1)+abs(y_2-y_1),abs(x_2-x_1));
}

signed main() {
	int h=read(),w=read(),a=read(),b=read();
	fac[0]=1;
	REP(i,1,h+w) fac[i]=(fac[i-1]*i)%MOD;

	REP(i,1,h+w) inv[i]=qpow(fac[i],MOD-2);
	int ans=0;
	REP(i,1,h-a) {
		ans=(ans+calc(1,1,b,i)*(calc(b+1,i,w,h)))%MOD;
	}

	printf("%lld\n",ans%MOD);
	return 0;
}

#include <iostream>
#include <numeric>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
int Max(int(a), int(b), int(c)) {
	return max(max(a, b), c);
}
int Min(int(a), int(b), int(c)) {
	return min(min(a, b), c);
}

int main() {

	ll A,B,C;
	cin >> A>>B>>C;

	cout <<(A-B+1)*(A-C+1)<< endl;

}


#include <bits/stdc++.h>
#define mp make_pair
#define eb emplace_back
#define fi first
#define se second
using namespace std;
using cd = complex <double>;

typedef pair <int, int> pii;
const int N = 3e3 + 5;
const long long INF = 1e18;
const int mod = 998244353;//786433;//998244353;
const double Pi = acos(-1);

void Fastio()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
}

int n, m;
queue <pair <int, int> > BFS;
int Dist[1005][1005];
char a[1005][1005];
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

int main()
{
	cin >> n >> m;
	for(int i = 1; i <= n; i++)
	{
		for(int j = 1; j <= m; j++)
		{
			Dist[i][j] = 1000000;
			cin >> a[i][j];
			if(a[i][j] == '#')
			{
				Dist[i][j] = 0;
				BFS.push(mp(i, j));
			}
		}
	}
	while(BFS.empty() == false)
	{
		int x = BFS.front().fi, y = BFS.front().se;
		BFS.pop();
		for(int i = 0; i < 4; i++)
		{
			if(Dist[x + dx[i]][y + dy[i]] > Dist[x][y] + 1)
			{
				Dist[x + dx[i]][y + dy[i]] = Dist[x][y] + 1;
				BFS.push(mp(x + dx[i], y + dy[i]));
			}
		}
	}
	int t = 0;
	for(int i = 1; i <= n; i++)
	{
		for(int j = 1; j <= m; j++)
		{
			t = max(t, Dist[i][j]);
		}
	}
	cout << t;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(lint (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
const lint MOD =1000000007;
const lint MAX = 1000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;
typedef map<lint,lint> M;
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)

lint fac[MAX], finv[MAX], inv[MAX];

void COMinit()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return 0;
        }
    }

    return 1;
}
   long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
    lint lcm(lint a,lint b){
        return a/__gcd(a,b)*b;
    }
     lint gcd(lint a,lint b){
        return __gcd(a,b);
    }

  int main(){
      lint n,g;
      cin>>n>>g;
      lint p[n];
      lint c[n];
      rep(i,n)cin>>p[i]>>c[i];
      lint ans=INF;
      rep(bit,1<<n){
          bool x[n];
          fill(x,x+n,false);
          rep(i,n)if(bit&(1<<i))x[i]=true;
          lint cost=0;
          lint comp=0;
          rep(i,n){
              if(x[i]){
                cost+=p[i]*(i+1)*100+c[i];
                comp+=p[i];
              }
          }
        for(lint i=n;i>=0;i--){
            if(x[i])continue;
            rep(j,p[i]){
                if(cost>=g)break;
                cost+=(i+1)*100;
                comp++;
            }
        }

          ans=min(ans,comp);
      }
      cout<<ans<<endl;
  }


#include<iostream>
using namespace std;
#include<vector>
#include<functional>
template<typename T>
struct dualsegtree{
	function<T(T,T)>lazycalcfn,updatefn;
	int n;
	T lazydefvalue;
	vector<T>dat,lazy;
	vector<bool>lazyflag;
	dualsegtree(int n_=0,T defvalue=0,
		function<T(T,T)>lazycalcfn_=[](T a,T b){return a+b;},
		function<T(T,T)>updatefn_=[](T a,T b){return a+b;},
		T lazydefvalue_=0
	):lazydefvalue(lazydefvalue_),
		lazycalcfn(lazycalcfn_),updatefn(updatefn_)
	{
		n=1;
		while(n<n_)n<<=1;
		dat.assign(n,defvalue);
		lazy.assign(n-1,lazydefvalue);
		lazyflag.assign(n-1,false);
	}
	void copy(const vector<T>&v)
	{
		for(int i=0;i<v.size();i++)dat[i]=v[i];
		lazy.assign(n-1,lazydefvalue);
		lazyflag.assign(n-1,false);
	}
	void update(int a,int b,T x,int k=0,int l=0,int r=-1)//[a,b)
	{
		if(r<0)r=n;
		if(b<=l||r<=a)return;
		else if(a<=l&&r<=b)
		{
			if(k<n-1)
			{
				lazy[k]=lazycalcfn(lazy[k],x);
				lazyflag[k]=true;
			}
			else dat[k-n+1]=updatefn(dat[k-n+1],x);
		}
		else
		{
			if(lazyflag[k])
			{
				update(0,n,lazy[k],k*2+1,l,(l+r)/2);
				update(0,n,lazy[k],k*2+2,(l+r)/2,r);
				lazy[k]=lazydefvalue;
				lazyflag[k]=false;
			}
			update(a,b,x,k*2+1,l,(l+r)/2);
			update(a,b,x,k*2+2,(l+r)/2,r);
		}
	}
	T query(int i)
	{
		T ret=dat[i];
		i+=n-1;
		while(i>0)
		{
			i=(i-1)/2;
			if(lazyflag[i])ret=updatefn(ret,lazy[i]);
		}
		return ret;
	}
};
main()
{
	int N,Q;
	cin>>N>>Q;
	dualsegtree<int>P(N,(int)((1LL<<31)-1),
		[](int a,int b){return b;},[](int a,int b){return b;});
	for(;Q--;)
	{
		int q;cin>>q;
		if(q==0)
		{
			int s,t,x;cin>>s>>t>>x;
			P.update(s,t+1,x);
		}
		else
		{
			int i;cin>>i;cout<<P.query(i)<<endl;
		}
	}
}

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<vector<P>> g(n);
	rep(i, n - 1) {
		int a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		g[a].push_back(P(b, c));
		g[b].push_back(P(a, c));
	}
	int q, k;
	cin >> q >> k;
	k--;
	priority_queue<P, vector<P>, greater<P>> pq;
	vector<ll> d(n, linf);
	pq.emplace(0, k);
	d[k] = 0;
	while (pq.size()) {
		P p = pq.top(); pq.pop();
		int v = p.second;
		if (d[v] < p.first) continue;
		for (auto c : g[v]) {
			if (d[c.first] > d[v] + c.second) {
				d[c.first] = d[v] + c.second;
				pq.emplace(d[c.first], c.first);
			}
		}
	}
	while (q--) {
		int x, y;
		cin >> x >> y;
		x--; y--;
		cout << d[x] + d[y] << endl;
	}
	return 0;
}


#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define sf scanf
#define pf printf
#define pb push_back
#define mp make_pair
#define PI ( acos(-1.0) )
#define IN freopen("dichromatic.in","r",stdin)
#define OUT freopen("dichromatic.out","w",stdout)
#define FOR(i,a,b) for(i=a ; i<=b ; i++)
#define DBG pf("Hi\n")
#define INF 1000000000
#define i64 long long int
#define eps (1e-8)
#define xx first
#define yy second
#define sq(x)  ((x)*(x))

using namespace __gnu_pbds;
using namespace std ;

#define maxn 200005
#define mod 1000000007LL

typedef  long long int T ;

const int N = 100000 ;

int bigMod(int a, int n, int m)
{
    if(n==0 ) return 1 ;
    int r = bigMod(a,n/2,m) ;
    r = (1LL*r*r)%m ;
    if(n&1) r = (1LL*r*a)%m ;
    return r ;
}

int fact[maxn] , invFact[maxn] ;
int dp[maxn] , cnt[maxn] ;
int a[maxn] ;

int C(int n, int r)
{
    return (1LL*fact[n]*((1LL*invFact[r]*invFact[n-r])%mod))%mod ;
}

int main()
{
    fact[0] =1 ;
    for(int i=1 ; i<=2*N ; i++) fact[i] = (1LL*fact[i-1]*i)%mod ;
    invFact[2*N] = bigMod(fact[2*N],mod-2,mod) ;
    for(int i=2*N -1 ; i>=0 ; i--) invFact[i] = (1LL*invFact[i+1]*(i+1))%mod ;

  //  for(int i=0 ; i<=N ; i++) printf("%d\n",invFact[i]) ;

  //  printf("%d %d\n",fact[6],C(6,2)) ;

    int n , X ;
    scanf("%d %d",&n,&X) ;

    for(int i=1; i<=n ; i++) scanf("%d",&a[i]) ;

    sort(a+1,a+n+1) ;

    for(int i=1 ; i<=n ; i++) cnt[ a[i] ]++ ;

    for(int i=1; i<=N ; i++) cnt[i] += cnt[i-1] ;

    dp[0] = 0 ;

    for(int i=1 ; i<=N ; i++)
    {
        if( cnt[i]==0 )
        {
            dp[i] = i ;
            continue ;
        }

        for(int j=cnt[i] ; j>=1 ; j--)
        {
            int m = a[ j ] ;
            int r = i%m ;

            int ret = dp[r] ;
            ret = (1LL*ret*fact[cnt[i]-1])%mod ;
            ret = (1LL*ret*invFact[cnt[r]])%mod;

//            printf("%d----%d %d\n",i,r,ret) ;

            dp[i] = (dp[i]+ret)%mod ;
        }
  //      printf("%d--> %d\n",i,dp[i]) ;
    }

    int ans = (1LL*dp[X]*fact[n])%mod ;
    ans = (1LL*ans*invFact[cnt[X]])%mod ;

    printf("%d\n",ans) ;

    return  0 ;
}

#include<iostream>
#include <cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
  int N, X; cin >> N >> X; int S[N];
  rep(i, N){
    cin >> S[i];
  }
  sort(S, S+N);
  ll dp[N+1][X+1] = {};
  rep(i, X+1){
    dp[0][i] = i;
  }
  rep(i, N){
    rep(j, X+1){
      dp[i+1][j] = dp[i][j%S[i]] + i*dp[i][j];
      dp[i+1][j]%=mod;
    }
  }
  cout << dp[N][X] << endl;
}


#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

vector<vi> e;
int v[100000];
void rec(int c, int col, bool &bi, int &x, int &y){
	if(col > 0) x++; else y++;
	v[c] = col;
	for(int i : e[c]){
		if(v[i]){
			if(v[i] == col) bi = 0;
		}
		else rec(i, -col, bi, x, y);
	}
}
int main(){
	cin.tie(0); cin.sync_with_stdio(0);

	int n, m; cin >> n >> m;
	e.resize(n);
	rep(i, m){
		int a, b; cin >> a >> b; a--; b--;
		e[a].pb(b);
		e[b].pb(a);
	}
	vector<pi> bigraph;
	vi graph;
	int point = 0;

	rep(i, n) if(!v[i]){
		bool bi = 1;
		int x = 0, y = 0;
		rec(i, 1, bi, x, y);
		if(bi){
			if(x + y == 1) point++;
			else bigraph.emplace_back(x, y);
		}
		else graph.pb(x + y);
	}
	//dbg(bigraph);dbg(graph);dbg(point);

	ll ans = 0;
	for(pi a : bigraph){
		/*
		for(pi b : bigraph){
			ans += 2;
		}
		for(int b : graph){
			ans++;
		}*/
		ans += bigraph.size() * 2;
		ans += graph.size();
		ans += (ll)point * (a.first + a.second);
	}
	dbg(ans);
	for(int a : graph){
		/*
		for(pi b : bigraph){
			ans++;
		}
		for(int b : graph){
			ans++;
		}*/
		ans += bigraph.size();
		ans += graph.size();
		ans += (ll)point * a;
	}
	dbg(ans);
	{
		for(pi b : bigraph){
			ans += (ll)point * (b.first + b.second);
		}
		for(int b : graph){
			ans += (ll)point * b;
		}
		ans += (ll)point * point;
	}
	cout << ans << endl;
	return 0;
}

#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

//わけわかめ
int P[100001];
bool dame[100001];
int Find(int A) {
	if (P[A] < 0) return A << 1;
	return P[A] = Find(P[A] >> 1) ^ (P[A] & 1);
}

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

	int N = getint(), M = getint();
	rep1(i, N) P[i] = -1;
	rep(i, M) {
		int a = Find(getint());
		int b = Find(getint());

		//なんてセンスのない
		int a1 = a >> 1;
		int b1 = b >> 1;
		if (a1 == b1) {
			if (!((a ^ b) & 1)) dame[a1] = true;
			continue;
		}
		if (P[a1] > P[b1]) {
			P[b1] += P[a1];
			dame[b1] |= dame[a1];
			P[a1] = b ^ !(a & 1);
		}
		else {
			P[a1] += P[b1];
			dame[a1] |= dame[b1];
			P[b1] = a ^ !(b & 1);
		}
	}

	ll x = 0, y = 0, z = 0;
	rep1(i, N) {
		if (P[i] < 0) {
			if (P[i] == -1) z++;
			else if (dame[i]) y++;
			else x++;
		}
	}
	printf("%lld\n", x * x + (x + y) * (x + y) + 2 * N * z - z * z);

	Would you please return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;

int main() {
    constexpr ll MOD = 1000000007;
    constexpr ll MAX = 1 << 20;

    ll N;
    cin >> N;
    vector<ll> A(N);
    for (ll i = 0; i < N; i++) {
        cin >> A[i];
    }

    //累積XOR
    vector<ll> b(N + 1, 0);
    for (ll i = 0; i < N; i++) {
        b[i + 1] = b[i] ^ A[i];
    }

    //今いるマスに好きな整数をXとしている場合に累積XORがXとして到達する場合の数
    vector<ll> dp(MAX, 1);

    //今いるマスに好きな整数をXとしている場合に累積XORがXとして到達する場合の数の累積和
    vector<ll> dp_sum(MAX, 0);

    //累積XORが0になった回数
    ll zero_num = 0;

    //前回累積XORがXとなったときのzero_numの値
    vector<ll> last_zero_num(MAX, 0);

    for (ll i = 1; i < N; i++) {
        //累積XORがb[i]としてここに到着する場合の数を次の2通りに分けて計算
        //1) 前にb[i]として届くパターンの最後だけをここに入れ替え
        //   つまり以前のdp[b[i]]そのものなので(2)を+=で足せば良い
        //2) b[i]として到達する累積和と前回以降から0が出てきた数との掛け算
        (dp[b[i]] += dp_sum[b[i]] * (zero_num - last_zero_num[b[i]])) %= MOD;

        //累積和を計算しておく
        (dp_sum[b[i]] += dp[b[i]]) %= MOD;

        //b[i]となったときの0の出現回数を記録しておき差分を取れるようにする
        last_zero_num[b[i]] = zero_num;

        //0の出現回数を記録
        if (b[i] == 0) {
            zero_num++;
        }
    }

    if (b[N]) {
        //b[N]として遷移した先のものが答え
        cout << (dp[b[N]] + dp_sum[b[N]] * (zero_num - last_zero_num[b[N]])) % MOD << endl;
    } else {
        //X = 0の場合:累積XORが0になるところで仕切りを入れるか入れないか2通り
        ll ans = 1;
        for (ll i = 0; i < zero_num; i++) {
            (ans *= 2) %= MOD;
        }

        //X != 0の場合:Xで遷移してくる累積和の和
        for (ll X = 1; X < MAX; X++) {
            (ans += dp_sum[X]) %= MOD;
        }

        cout << ans << endl;
    }
}

//Δ_E
#include<iostream>
#include<cstdio>
#include<fstream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<bitset>
#include<cmath>
#include<cstring>
#include<cstdlib>
using namespace std;
typedef long long LL;
typedef double DB;
const int N = 1<<20;
const int MO = 1e9+7;
int n,m,a[N],b[N],s[N];
vector<int> v[N];
int cal(int o,int f=0){
	int i,j,x,y;
	x=1,y=0;
	for(i=0;i<v[o].size();i=i+1){
		j=v[o][i];
		y=(y+x)%MO;
		if(i+1<v[o].size())
			x=(x+(LL)y*(s[v[o][i+1]]-s[j])%MO)%MO;
	}
	if(f)
		return x;
	return y;
}
int main()
{
	int i,x,o;
	scanf("%d",&n);
	for(i=1;i<=n;i=i+1){
		scanf("%d",a+i);
		m^=a[i];
		b[i]=b[i-1]^a[i];
		s[i]=s[i-1];
		if(!b[i])
			s[i]++;
	}
	for(i=1;i<n;i=i+1)
		v[b[i]].push_back(i);
	if(m){
		v[m].push_back(n);
		cout<<cal(m,1);
		return 0;
	}
	x=0;
	for(i=1;i<N;i=i+1)
		x=(x+cal(i))%MO;
	o=1;
	for(i=1;i<=s[n-1];i=i+1)
		o=o*2%MO;
	cout<<(x+o)%MO;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{int n;
string s;
cin>>n;
cin>>s;
if(s.size()>n)
{
    s.erase(n);
    cout<<s+"..."<<endl;}
    else cout<<s<<endl;
    return 0;
}

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i,0,n)
#define BFOR(bit,a,b) for(int bit = (a); bit < (1<<(b)); ++bit)
#define BREP(bit,n) BFOR(bit,0,n)
using namespace std;
using ll = long long;

int main() {
  int n;
  cin >> n;
  if(n < 1200) cout << "ABC" << endl;
  else if(n < 2800) cout << "ARC" << endl;
  else cout << "AGC" << endl;

}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int now[4];
char C[4], op[2] = {'+', '-'};

int main(){
  for (int i = 0; i < 4; i++){
    cin >> C[i];
    now[i] = C[i] - '0';
  }

  for (int i = 0; i < 8; i++){
    int val = now[0], num = i;

    for (int j = 1; j < 4; j++){
      val += pow(-1, num % 2) * now[j];
      num /= 2;
    }

    if (val == 7){
      num = i;
      cout << now[0];
      for (int j = 1; j < 4; j++){
        cout << op[num%2] << now[j];
        num /= 2;
      }

      cout << "=7" << endl;

      return 0;
    }

  }

  return 0;
}


#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<string>
#include<cmath>
//#include<>
using namespace std;

typedef pair<int,int> Node;
typedef long long ll;
#define rep(i,j) for(i=0;i<j;i++)
#define rev_rep(i,j) for(i=j;i>=0;i—-)

int INF=1<<30;
class Dijkstra
{
public:
  typedef struct Edge{int to,cost;}Edge;
  vector< vector<Edge> > Graph;//接続リスト

  Dijkstra(int n)
  {
    vector<Edge> temp;
    Graph.resize(n,temp);
  }

  void add_arc(int x,int y,int c)
  {
    Edge e={y,c};
    Graph[x].push_back(e);
  }

  vector<int> get_distance(int s)
  {
    priority_queue< Node ,vector<Node>,greater<Node> > que;//(sからの距離,インデックス)
    vector<int>ans;
    int i;
    ans.resize(Graph.size(),INF);
    ans[s]=0;
    que.push(Node(0,s));
    while(!que.empty()){
      Node now=que.top();que.pop();
      int now_i=now.second;
      //nowへの最小距離でないならスキップ
      if(ans[now_i]<now.first)continue;
      //nowからの辺全てをみる
      rep(i,Graph[now_i].size()){
	Edge e=Graph[now_i][i];
	//nowから行った方が近かったら更新
	if(ans[e.to]>ans[now_i]+e.cost){
	  ans[e.to]=ans[now_i]+e.cost;
	  que.push(Node(ans[e.to],e.to));
	}
      }
    }
    return ans;
  }

};

int main()
{
  int n,m,r;
  cin>>n>>m>>r;
  Dijkstra map(n);
  int i;
  rep(i,m)
    {
      int a,b,c;
      cin>>a>>b>>c;
      map.add_arc(a,b,c);
      //map.add_arc(b,a,c);
    }
  vector<int> ans=map.get_distance(r);
  rep(i,ans.size())
    if(ans[i]==INF)
      cout<<"INF"<<endl;
    else
      cout<<ans[i]<<endl;
  return 0;
}

#include <iostream>
using namespace std;

int main(){
  int t[110]={};
  int N;
  cin >> N;
  int a,b,c,d;
  //得点
  for(int i = 0; i < N*(N-1)/2; i++){
    cin >> a >> b >> c >> d;
    if(c > d) t[a-1] += 3;
    else if(c < d) t[b-1] += 3;
    else if(c == d){
      t[a-1]++;
      t[b-1]++;
    }
  }
  //順位
  int p = 0,rank[110]={};
  for(int j = 1; j < N+1; j+=p){
    int max = -1;
    for(int i = 0; i < N; i++){
      if(max < t[i]){
	max = t[i];
      }
    }
    p = 0;
    for(int i = 0; i < N; i++){
      if(max == t[i]){
	rank[i] = j;
	p++;
	t[i] = -1;
      }
    }

  }
  for(int i = 0; i < N; i++){
    cout << rank[i] << endl;
  }
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define all(v) begin(v),end(v)
using ll = long long;

int main() {
  ll n,x;cin>>n>>x;
  vector<ll> a(n);
  rep(i,n)cin>>a[i];
  sort(all(a));
  int cnt=0;
  rep(i,n){
    x-=a[i];
    if(x<0)break;
    cnt++;
  }
   if(x>0)cnt--;
  cout<<cnt<<endl;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int testcase=1;

    for(int p=0;p<testcase;p++){
    ll n=0,x=0;
    cin>>n>>x;
    ll array[n]={0};
	ll totalsum=0;
    for(int i=0;i<n;i++){
    cin>>array[i];
    totalsum+=array[i];
    }
    if(totalsum<x){
        cout<<n-1;
    }
else if(totalsum==x)
cout<<n;
    else
    {
        sort(array,array+n);
        ll counter=0;
        ll sum=x;
        ll i=0;
        while(sum>=0){
       // cout<<array[i];
        sum-=array[i];
    	if(sum<0)
    	break;
	    i++;
        counter++;
        }
        cout<<counter;
    }

    }

    return 0;
}


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

#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define vpii vector<pair<int,int>>
#define vpll vector<pair<ll,ll>>
#define fr(i,k,n) for (int i = k; i < n; ++i)
#define fri(i,k,n) for (int i = k; i >= n; --i)
#define INF (int)1e9
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define all(arr) arr.begin(),arr.end()

void boost(){
  ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

const int N=5e5+5;
ll tree[N];

ll read(int idx) {
  ll sum = 0;
  while (idx > 0) {
    sum += tree[idx];
    idx -= (idx & -idx);
  }
  return sum;
}

void update(int idx, ll val) {
  while (idx <N) {
    tree[idx] += val;
    idx += (idx & -idx);
  }
}

void solve(){
  int n,q;
  cin>>n>>q;
  int x;
  fr(i,1,n+1){
    cin>>x;
    update(i,x);
  }
  int t,l,r;
  while(q--){
    cin>>t>>l>>r;
    if(t==0){
      update(l+1,r);
    }
    else{
      cout<<read(r)-read(l)<<endl;
    }
  }
  return;
}

int main()
{
  boost();

  int tc=1;
  //cin>>tc;
  while(tc--)
    solve();
  return 0;
}

#include <bits/stdc++.h>

#include <atcoder/all>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using namespace atcoder;
using ll = long long;
using P = pair<int, int>;

int main() {
  int n, q;
  cin >> n >> q;
  fenwick_tree<ll> fw(n);
  rep(i, n) {
    ll a;
    cin >> a;
    fw.add(i, a);
  }
  rep(_, q) {
    int b;
    cin >> b;
    if (b == 1) {
      int l, r;
      cin >> l >> r;
      cout << fw.sum(l, r) << endl;
    } else {
      int p;
      ll x;
      cin >> p >> x;
      fw.add(p, x);
    }
  }
  return 0;
}


#include <bits/stdc++.h>
#define rep(i,n) for (int (i) = 0; (i) < (n); i++)
#define ll long long
using namespace std;
int main() {
  ll N = 0, A,B;;
  cin >> N >> A >> B;
  if(N == 1){
    cout << "Hello World";
  }
  else{
    cout << A + B;
  }
}

#include <iostream>
using namespace std;
int main(){
  int n;
  cin >> n;
  if(n==1){
    cout << "Hello World" << "\n";
    return 0;
  }
  else{
    int a,b;
    cin >> a >> b;
    cout << a+b << "\n";
    return 0;
  }
}


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

int main(){
  int N;
  long long count;
  cin >> N;
  vector<int> a(N);
  count = 0;

  for(int i = 0;i < N;i++){
     cin >> a.at(i);
    if(i > 0){
      if(a.at(i-1) > a.at(i)){
        count += a.at(i-1) - a.at(i);
        a.at(i) = a.at(i-1);
      }
    }
  }
  cout << count << endl;

}

#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

ll gcd(ll a,ll b){
  if(b == 0) return a;
  return gcd(b , a % b);
}

ll mod(ll a){
  return (a % 1000000007);
}

ll lcm(ll a,ll b){
  return (a*b)/gcd(a,b);
}

int main(){
  ll a,b; cin >> a >> b;
  cout << max(a*b,max(a+b,a-b)) << endl;
}


#include <bits/stdc++.h>
#define lid id << 1
#define rid id << 1 | 1

using namespace std;
const int MAXN = 2e5 + 5;
const int INF = 1e9;

int h, w, a[MAXN], L[MAXN], R[MAXN], ans[MAXN];

template <class T>
void read(T &x, T f = 1, char ch = getchar()) {
    x = 0;
    while (ch < '0' || ch > '9') f = (ch == '-' ? -1 : 1), ch = getchar();
    while (ch >= '0' && ch <= '9') x = x * 10 + ch - 48, ch = getchar();
    x *= f;
}

// a[i] = a[i-1]  i∉[L,R]
// a[i] = a[L-1] -L + 1 + i  i∈[L,R];

struct Node {
    int l, r, mi, lval;
    bool tag;
    Node() { mi = lval = 0, tag = 0; }
    // mi denotes the minimum a in [l,r]
    // lval denotes the value of the left end point of [l,r]
} tr[MAXN * 4];

void update(int id) {
    tr[id].mi = min(tr[lid].mi, tr[rid].mi);
    tr[id].lval = tr[lid].lval;
}

void pushdown(int id) {
    if (tr[id].tag) {
        tr[lid].tag = 1;
        tr[lid].lval = tr[lid].mi = tr[id].lval;
        tr[rid].tag = 1;
        tr[rid].lval = tr[rid].mi = tr[id].lval + tr[rid].l - tr[lid].l;
        tr[id].tag = 0;
    }
}

void build(int id, int l, int r) {
    tr[id].l = l, tr[id].r = r;
    if (l == r) return;
    int mid = l + r >> 1;
    build(lid, l, mid);
    build(rid, mid + 1, r);
}

void modify(int id, int l, int r, int val) {
    if (tr[id].l == l && tr[id].r == r) {
        tr[id].mi = tr[id].lval = val;
        tr[id].tag = 1;
        return;
    }
    pushdown(id);
    int mid = tr[id].l + tr[id].r >> 1;
    if (r <= mid)
        modify(lid, l, r, val);
    else if (l > mid)
        modify(rid, l, r, val);
    else {
        modify(lid, l, mid, val);
        modify(rid, mid + 1, r, val + mid + 1 - l);
    }
    update(id);
}

int query(int id, int l, int r) {
    if (r < 1) return INF;
    if (tr[id].l == l && tr[id].r == r) {
        return tr[id].mi;
    }
    pushdown(id);
    int mid = tr[id].l + tr[id].r >> 1;
    if (r <= mid)
        return query(lid, l, r);
    else if (l > mid)
        return query(rid, l, r);
    else
        return min(query(lid, l, mid), query(rid, mid + 1, r));
}

int main() {
    read(h), read(w);
    for (int i = 1; i <= h; i++) read(L[i]), read(R[i]);
    fill(ans + 1, ans + h + 2, -1);
    build(1, 1, w);
    for (int i = 2; i <= h + 1; i++) {
        int tmp = query(1, L[i - 1] - 1, L[i - 1] - 1);
        modify(1, L[i - 1], R[i - 1], tmp + 1);
        int mi = query(1, 1, w);
        if (mi >= INF) break;
        ans[i] = mi + i - 1;
    }
    for (int i = 2; i <= h + 1; i++) printf("%d\n", ans[i]);
    return 0;
}

/* 十 聖イシドールスよ、迷えるプログラマを導き給え！ 十 */
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <cmath>
#include <deque>

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

//const long long INF = 1LL << 60;
const int INF = 1e9;
using ll = long long;

int main()
{
	int N, Q;
	std::cin >> N >> Q;
	std::vector<int> ACGT(N, 0);	// AGCT[i]文字目までに何個現れたか
	std::string S;
	std::cin >> S;

	// 前処理...ACの数を数えておく
	char pre = S[0];
	for( int i = 1; i < N; i++ )
	{
		char now = S[i];
		//printf( "%c:%c", pre, now );
		ACGT[i] = ACGT[i-1];
		if( pre == 'A' )
		{
			if( now == 'C')
			{
				//printf("now!");
				ACGT[i] = ACGT[i-1] + 1;
			}
		}
		//printf("\n");
		pre = now;
	}

//	printf("===\n");
//	rep( i, N )
//	{
//		printf( "%d\n", ACGT[i]);
//	}
//	printf("===\n");

	// 問題をとく
	for( int i = 0; i < Q; i++ )
	{
		int l, r;
		std::cin >> l >> r;
		l--; r--;

		int ans = ACGT[r] - ACGT[l];

		if( ( S[l] == 'A' ) && ( S[r] == 'C' ) )
		{
			//ans++;
		}

		std::cout << ans << std::endl;
	}

	return 0;
}


#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

string S;

int dp[310][310][310];

int solve(int a, int b, int r) {
  if (a > b) return 0;
  int& res = dp[a][b][r];
  if (res != -1) return res;
  if (a == b) return (S[a] == S[b] || r > 0) ? 1 : 0;
  res = 0;
  chmax(res, solve(a + 1, b, r));
  chmax(res, solve(a, b - 1, r));
  if (S[a] == S[b]) {
    chmax(res, solve(a + 1, b - 1, r) + 2);
  } else if (r > 0) {
    chmax(res, solve(a + 1, b - 1, r - 1) + 2);
  }
  return res;
}

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  int K;
  while (cin >> S >> K) {
    memset(dp, -1, sizeof(dp));
    cout << solve(0, S.size() - 1, K) << endl;
  }
  return 0;
}

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF 99999999

int main(){
    int a,b;
    int month[]={0,0,31,29,31,30,31,30,31,31,30,31,30,31};
    for(int i=1;i<=12;i++)month[i]=month[i]+month[i-1];
    string w[]={"Thursday","Friday","Saturday","Sunday","Monday","Tuesday","Wednesday"};
    while(cin>>a>>b){
        if(a==0&&b==0)break;
        int sum=0;
        sum+=month[a];
        sum+=b-1;
        sum=sum%7;
        cout<<w[sum]<<endl;
    }
}


#include <iostream>
#include <sstream>
#include <vector>

using namespace std;

int main()
{
    string times;
    int x=0;
    int n;
    vector <int> number;
getline(cin,times);
stringstream s(times);
while(s>>n)
    number.push_back(n);

x=(60*(number[2]-number[0])+(number[3]-number[1]))-number[4];

    cout<<x<<endl;

    return 0;
}

#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=b;i--)
#define ALL(x) x.begin(),x.end()
#define SIZE(x) ll(x.size())

#define INF 1000000000000 //10^12
#define MOD 1000000007 //10^9+7:合同式の法

int main(){
    ll h1,h2,m1,m2,k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;

    ll total = (h2 - h1)*60;
    total += m2 - m1 - k;
    cout << total << endl;
    return 0;
}


#include <stdio.h>

int main() {
    int H, W, N;

    scanf("%d", &H);
    scanf("%d", &W);
    scanf("%d", &N);

    if(W>=H){
    for(int i=1;i<=H;i++){
        if (W*i>=N) {
            printf("%d", i);
            return 0;
        }
    }
} else {
    for(int i=1;i<=W;i++){
        if (H*i>=N) {
            printf("%d", i);
            return 0;
        }
    }
}
    return 0;
}

#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

const int MAX_N = 200010;
const int MOD = 1000000007;
typedef long long Int;

Int fac[MAX_N + 1];
Int inv[MAX_N + 1], ifac[MAX_N + 1];

Int comb(int n, int r)
{
  if (n < 0 || r < 0) return 0;
  if (n < r) return 0;
  Int ret = 1;
  ret = (ret * fac[n]) % MOD;
  ret = (ret * ifac[r]) % MOD;
  ret = (ret * ifac[n - r]) % MOD;
  return ret;
}

int main()
{
  int n, m, k;

  inv[1] = 1;
  fac[0] = ifac[0] = 1;
  fac[1] = ifac[1] = 1;
  for (int i = 2; i <= MAX_N - 1; i++) {
    fac[i] = (fac[i - 1] * i) % MOD;
    inv[i] = (inv[MOD % i] * (MOD - MOD / i)) % MOD;
    ifac[i] = ifac[i - 1] * inv[i] % MOD;
  }

  scanf("%d %d %d", &n, &m, &k);

  Int ans = 0;

  for (int i = 1; i <= m - 1; i++) {
    Int coef = (Int)n * n * (m - i) * i % MOD;
    ans = (ans + comb(n * m - 2, k - 2) * coef) % MOD;
  }

  for (int i = 1; i <= n - 1; i++) {
    Int coef = (Int)m * m * (n - i) * i % MOD;
    ans = (ans + comb(n * m - 2, k - 2) * coef) % MOD;
  }

  printf("%lld\n", ans);

  return 0;
}


#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <utility>
#include <stdlib.h>
#include <fstream>
#include <vector>
#include <iomanip>
#include <algorithm>
#include <stack>
#include <assert.h>
#include <unordered_map>
#include <unordered_set>
#include <math.h>
#include <stdlib.h>
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ll long long
using namespace std;

bool test = true;
#define log(x) if(test) cout << "[ " << #x << " = " << x << " ]\n";
#define log2(x, y) if(test) cout << "[ " << #x << " = " << x << ", " << #y << " = " << y << " ]\n";
#define logv(x) if(test) {cout << #x << " : { "; for(auto i : x) cout << i << " "; cout << "}\n";};

#define MX (ll)(1e14)

int main() {
    int n, m;
    cin >> n >> m;
    int a, b;
    cin >> a >> b;
    int ans[n+1][m+1];
    for(int i=1; i<=n; i++) {
        for(int j=1; j<=m; j++)
            ans[i][j] = 0;
    }

    for(int i=1; i<=b; i++) {
        for(int j=1; j<=a; j++) {
            ans[i][j] = 1;
        }
    }

    for(int i=b+1; i<=n; i++) {
        for(int j=a+1; j<=m; j++) {
            ans[i][j] = 1;
        }
    }

     for(int i=1; i<=n; i++) {
        for(int j=1; j<=m; j++)
            cout << ans[i][j];
        cout << "\n";
    }

}

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

int main() {
  int h,w,a,b;
  cin>>h>>w>>a>>b;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if((j<a && i<b) || (j>=a && i>=b)) cout<<0;
      else cout<<1;
      if(j==w-1) cout<<endl;
    }
  }
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <assert.h>
#include <numeric>
#include <math.h>
#include <climits>
#include <stack>
#include <iomanip>
#include <sstream>

using namespace std;

template <typename T>
inline bool sign(T A) {
    return (A>0)-(A<0);
}
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SREP(i,s,n) for(int i=s; (n-i)*sign(n-s)>0; i+=sign(n-s))
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef unsigned long long ull;

template <typename T>
T gcd(T a, T b) {
    if(a < b) gcd(b, a);
    if (b == 1) return 1;
    T r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}

bool _less(pair<int, int> a, pair<int, int> b) {
    return a.second < b.second;
}

template <template<class,class,class...> class C, typename K, typename V, typename... Args>
V map_get(const C<K,V,Args...>& m, K const& key, const V & defval)
{
    typename C<K,V,Args...>::const_iterator it = m.find( key );
    if (it == m.end())
        return defval;
    return it->second;
}

#define MOD (1'000'000'000+7)

ll dp[51][2501];
int main(void) {
    int N;
    string s;
    cin >> N >> s;

    s += s;
    REP(i, 4) {
        string t;
        if (i & 1)
            t += 'W';
        else
            t += 'S';

        if (i & 2)
            t += 'W';
        else
            t += 'S';

        SREP(j, 1, N+1) {
            if ((s[j] == 'o' && t[j] == 'S') || (s[j] == 'x' && t[j] == 'W'))
                t += t[j - 1];
            else
                t += (t[j - 1] == 'S')?'W':'S';
        }

        if (t[0] == t[N] && t[1] == t[N+1]) {
            cout << t.substr(0, N) << endl;
            return 0;
        }
    }

    cout << -1 << endl;
}

#include <bits/stdc++.h>
#define For( i, j, k ) for( int i = j; i <= k; ++i )
using std::vector;
using std::pair;
using std::cin;
using std::cout;
typedef long long LONG;
typedef int INT;
const INT N = 100100;
char c[ N ];
INT n, ans[ N ];
void Print( )
{
 For( i, 1, n )
  cout << ( ans[ i ] ? 'W' : 'S' );
 return;
}
void INIT( )
{
 For( i, 3, n )
  ans[ i ] = ans[ i - 2 ] ^ ans[ i - 1 ] ^ ( c[ i - 1 ] != 'o' );
 return;
}
bool check( )
{
 bool flag = 0;
 For( i, 1, n )
 {
  int l = ( i - 1 == 0 ) ? n : i - 1, r = ( i + 1 > n ? 1 : i + 1 );
  flag |= ( ans[ l ] ^ ans[ r ] != ( c[ i ] != 'o' ^ ans[ i ] ) );
 }
 return !flag;
}
int main( )
{
 std::ios::sync_with_stdio( false );
 cin >> n;
 cin >> c + 1;
 For( i, 0, 1 ) For( j, 0, 1 )
 {
  ans[ 1 ] = i, ans[ 2 ] = j;
  INIT( );
  if( check( ) )
  {
   Print( );
   return 0;
  }
 }
 cout << "-1";
 return 0;
}


#include<iostream>
#include<queue>
#include<cstring>

using namespace std;

queue<pair<int, int>> q;
int H, W;
int grid[1005][1005], shortestPath[1005][1005];
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

bool inside(int row, int col){
  if (row < 0 || row >= H || col < 0 || col >= W) return false;
  return true;
}

int bfs(){
  int ans = 0;
  while(!q.empty()){
    pair<int, int> now = q.front();
    q.pop();

    int row = now.first;
    int col = now.second;

    ans = max(ans, shortestPath[row][col]);

    for(int i=0; i<4; i++){
      int nextRow = row + dx[i];
      int nextCol = col + dy[i];

      if(inside(nextRow, nextCol) && grid[nextRow][nextCol] != 1 && shortestPath[nextRow][nextCol] == -1){
        shortestPath[nextRow][nextCol] = 1 + shortestPath[row][col];
        q.push(make_pair(nextRow, nextCol));
      }
    }

  }
  return ans;
}

int main(){
  memset(shortestPath, -1, sizeof(shortestPath));
  cin >> H >> W;

  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      char c;
      cin >> c;
      if(c == '#'){
        grid[i][j] = 1;
        q.push(make_pair(i, j));
        shortestPath[i][j] = 0;
      }
    }
  }

  cout << bfs() << endl;

}

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;

//#define int long long
//signed main(){
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int h,w;
    cin >> h >> w;
    vector<bool> a(h*w,false);

    queue<int> que;
    for(int i = 0; i < h; i++) {
        string tmp;
        cin >> tmp;
        for(int j = 0; j < w; j++) {
            int idx=i*w+j;
            if(tmp[j]=='#'){
                a[idx]=true;
                que.push(idx);
            }
        }
    }

    int cnt=0;
    int ans=0;
    while(cnt<h*w) {
        int n=que.size();
        cnt+=n;
        for(int i = 0; i < n; i++) {
            int idx=que.front();
            int add[4]={1,-1,w,-w};
            for(int j = 0; j < 4; j++) {
                int t=idx+add[j];
                int r=idx/w+add[j]/w;
                int c=idx%w+add[j]%w;
                if(r<0||r>=h||c<0||c>=w||a[t]==true) continue;
                a[t]=true;
                que.push(t);
            }
            que.pop();
        }
        ans++;
    }
    cout << ans-1 << "\n";

    return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <stdlib.h>
#include <stdio.h>
#include <sstream>
using namespace std;
#define p 1000000

int main(void){
	//FILE* fp_in = freopen("data.txt", "r", stdin);

	while(1){
		long long int n,tmp[3],cnt = 0;
		vector<long long int> number;
		vector<long long int> sales;
		vector<long long int> flg;
		cin >> n;
		if(n == 0) break;
		for(int i=0; i<4000; i++) {
			sales.push_back(0);
			flg.push_back(0);
		}
		for(int i=0; i<n; i++) {
			cin >> tmp[0] >> tmp[1] >> tmp[2];
			sales.at(tmp[0]) += tmp[1]*tmp[2];
			if(flg.at(tmp[0]) == 1) continue;
			number.push_back(tmp[0]);
			flg.at(tmp[0]) = 1;
		}
		for(int i=0; i<number.size(); i++) {
			if(sales.at(number.at(i)) >= p) {
				cout << number.at(i) << endl;
				cnt++;
			}
		}
		if(cnt == 0) {
			cout << "NA" << endl;
		}
	}

	//while(1){}
	return 0;
}

#include <iostream>
#include <string>
using namespace std;
typedef struct{
	string id;
	long long sales;
} staff;

int main(void)
{
	long long n;
	while(cin>>n){
		if(!n) break;
		staff staff1[4001];
		int pt = 0;
		for(int i=0; i< n; i++){
			string id;
			cin >> id;
			long long price;
			int bnum;
			cin >> price >> bnum;
			int m=-1;
			for(int j=0;j < i; j++){
				if(id==staff1[j].id){
					pt++;
					m=j;
					break;
				}
			}
			if(m==-1){
				staff1[i-pt].id = id;
				staff1[i-pt].sales = price * bnum;
			}else{
				staff1[m].sales += price * bnum;
			}
		}
		int count = 0;
		for(int i=0; i < n-pt; i++){
			if(staff1[i].sales >= 1000000){
				count++;
				cout << staff1[i].id << endl;
			}
		}
		if(!count) cout << "NA" << endl;
	}

	return 0;
}


#include<bits/stdc++.h>
#define N 105
using namespace std;
char s[N][N];
int n,m;
int Ex,Ey,ans;
int cnt[N][N];
void mmax(int &x,int v){
	x=max(x,v);ans=max(ans,v);
}
int get(int x1,int y1,int x2,int y2){
	return cnt[x2][y2]-cnt[x2][y1-1]-cnt[x1-1][y2]+cnt[x1-1][y1-1];
}
int dp[2][N][N][N];
int main(){
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++) scanf("%s",s[i]+1);
	for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++){
			cnt[i][j]=cnt[i-1][j]+cnt[i][j-1]-cnt[i-1][j-1]+(s[i][j]=='o');
			if(s[i][j]=='E') Ex=i,Ey=j;
		}
	int now=0;
	for (int i=0;i<=Ex-1;i++){
		memset(dp[now^1],0,sizeof(dp[0]));
		for (int j=0;j<=n-Ex;j++)
			for (int k=0;k<=Ey-1;k++)
				for (int L=0;L<=m-Ey;L++){
					int v=dp[now][j][k][L];
					int xl=max(Ex-i,j+1),yl=max(Ey-k,L+1),xr=min(Ex+j,n-i),yr=min(Ey+L,m-k);
					if (Ex-i-1>j) mmax(dp[now^1][j][k][L],v+get(Ex-i-1,yl,Ex-i-1,yr));
					if (Ex+j<n-i) mmax(dp[now][j+1][k][L],v+get(Ex+j+1,yl,Ex+j+1,yr));
					if (Ey-k-1>L) mmax(dp[now][j][k+1][L],v+get(xl,Ey-k-1,xr,Ey-k-1));
					if (Ey+L<m-k) mmax(dp[now][j][k][L+1],v+get(xl,Ey+L+1,xr,Ey+L+1));
				}
		now^=1;
	}
	printf("%d\n",ans);
	return 0;
}

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

#define mp make_pair
#define pb push_back
#define sz(s) ((int) ((s).size()))
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)

#ifdef _WIN32
#define LLD "%I64d"
#else
#define LLD "%lld"
#endif

typedef long long ll;
typedef long double ld;

const int inf = (int) 1e9 + 100;
const ld eps = 1e-11;
const ld pi = acos(-1.0L);

mt19937 mrand(random_device{} ());
int rnd(int x) {
  return mrand() % x;
}

void precalc() {
}

const int maxn = 105;
int n, m;
int dp[maxn][maxn], row[maxn][maxn][maxn], col[maxn][maxn][maxn];
char a[maxn][maxn];

bool read() {
  if (scanf("%d%d", &n, &m) < 2) {
    return false;
  }
  for (int i = 0; i < n; i++) {
    scanf("%s", a[i]);
  }
  return true;
}

void solve() {
  int sx, sy;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (a[i][j] == 'E') {
        sx = i;
        sy = j;
      }
    }
  }
  if (sx < n - sx - 1) {
    for (int i = 0; 2 * i < n; i++) {
      for (int j = 0; j < m; j++) {
        swap(a[i][j], a[n - i - 1][j]);
      }
    }
    sx = n - sx - 1;
  }
  if (sy < m - sy - 1) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; 2 * j < m; j++) {
        swap(a[i][j], a[i][m - j - 1]);
      }
    }
    sy = m - sy - 1;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      row[i][j][j] = (a[i][j] == 'o');
      for (int k = j + 1; k < m; k++) {
        row[i][j][k] = row[i][j][k - 1] + (a[i][k] == 'o');
      }
    }
  }
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < n; j++) {
      col[i][j][j] = (a[j][i] == 'o');
      for (int k = j + 1; k < n; k++) {
        col[i][j][k] = col[i][j][k - 1] + (a[k][i] == 'o');
      }
    }
  }
  int ans = 0;
  for (int x = 0; x + sx < n; x++) {
    for (int y = 0; y + sy < m; y++) {
      dp[sx][sy] = (a[x + sx][y + sy] == 'o');
      for (int i = sy - 1; i >= 0; i--) {
        dp[sx][i] = dp[sx][i + 1] + (a[x + sx][y + i] == 'o');
      }
      for (int i = sx - 1; i >= 0; i--) {
        dp[i][sy] = dp[i + 1][sy] + (a[x + i][y + sy] == 'o');
        for (int j = sy - 1; j >= 0; j--) {
          dp[i][j] = max(dp[i][j + 1] + col[y + j][x + i][min(x + sx, x + i + n - sx - 1)],
                         dp[i + 1][j] + row[x + i][y + j][min(y + sy, y + j + m - sy - 1)]);
        }
      }
      ans = max(ans, dp[0][0]);
    }
  }
  printf("%d\n", ans);
}

int main() {
  precalc();
#ifdef DEBUG
  assert(freopen("text.in", "r", stdin));
  assert(freopen("text.out", "w", stdout));
#endif

  while (true) {
    if (!read()) {
      break;
    }
    solve();
#ifdef DEBUG
    eprintf("Time: %.18f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


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

int N,M,Q,m;
const int maxn=600000+5;
int siz;
int C[maxn],a[maxn],ret[maxn];
struct node{
	int l,r,id;
	bool operator<(const node& other)const{
		return other.r > r;
	}
}x[maxn],y[maxn];

void add(int x,int v){
	for(int i=x;i<=m;i+=i&-i) C[i]+=v;
}

int sum(int x){
	int ret=0;
	for(int i=x;i;i-=i&-i) ret+=C[i];
	return ret;
}

int main(){
	cin>>N>>M>>Q;
	for(int i=0;i<M;i++){
		cin>>x[i].l>>x[i].r;
		a[siz++]=x[i].l;
		a[siz++]=x[i].r;
	}
	for(int i=0;i<Q;i++){
		cin>>y[i].l>>y[i].r;
		y[i].id=i;
		a[siz++]=y[i].l;
		a[siz++]=y[i].r;
	}
	sort(a,a+siz);
	m=unique(a,a+siz)-a;
	for(int i=0;i<M;i++){
		x[i].l=lower_bound(a,a+m,x[i].l)-a+1;
		x[i].r=lower_bound(a,a+m,x[i].r)-a+1;
	}
	for(int i=0;i<Q;i++){
		y[i].l=lower_bound(a,a+m,y[i].l)-a+1;
		y[i].r=lower_bound(a,a+m,y[i].r)-a+1;
	}
	sort(x,x+M);
	sort(y,y+Q);
	int j=0;
	for(int i=0;i<Q;i++){
		while(j<M&&x[j].r<=y[i].r) add(x[j++].l,1);
		ret[y[i].id]=j-sum(y[i].l-1);
	}
	for(int i=0;i<Q;i++) cout<<ret[i]<<endl;
	return 0;
}


#include<string>
#include<iostream>
#include<algorithm>
using namespace std;
int J = 0, O = 0, I = 0;
void res()
{
	J = 0;
	O = 0;
	I = 0;
}
int main()
{
	string a;
	cin >> a;
	int ans = 0;

	for (int i = 0; i < a.size(); i++)
	{
		switch (a[i])
		{
		case'J':
			if (O != 0 || I != 0)
			{
				res();
				J++;
			}
			else
			{
				J++;
			}
			break;
		case'O':
			if (J == 0||I!=0)
			{
				res();
				continue;
			}
			else
			{
				O++;
				if (O > J)
				{
					res();
				}
			}

			break;
		case'I':
			I++;
			if (O < I||J<I)
			{
				res();
			}
			if(I==O)ans = max(ans, I);
			break;
		}
	//	cout << ans << endl;

	}
	cout << ans << endl;

}

#include <bits/stdc++.h>
#define FOR(i,n) for(int i=0;i<(int)(n);i++)
#define FORR(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define pb(a) push_back(a)
#define ZERO(a) memset(a,0,sizeof(a))
#define len(a) sizeof(a)
#define ll long long
#define INF 1<<29
#define MAX
using namespace std;

void solve(){
 string s;
 cin>>s;
 int ma=0;
 FOR(i,s.size()){
  if(s[i]!='O') continue;
  int O=i;
  while(O+1<s.size()&&s[O+1]=='O') O++;
  int J=i;
  while(J&&s[J-1]=='J') J--;
  int I=O;
  while(I+1<s.size()&&s[I+1]=='I') I++;
  if(I-O-1>=O-i&&i-1-J>=O-i) ma=max(ma,O-i+1);
  i=I;
 }
 cout<<ma<<endl;
}

int main(){
 solve();
 return 0;
}