#include <bits/stdc++.h>
/*
 **
 *** Your best is not enough
 **
 */
using namespace std;
#define all(v)          ((v).begin()), ((v).end())
#define finish(x) return cout << x << endl, 0;
#define pb push_back
#define Compiler_Beso ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define clr(v,d)        memset(v, d, sizeof(v))
#define endl '\n'
#define pi pair<int,int>
typedef long long ll;
typedef unsigned long long ull;

void fre(){
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
}

ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }

int FixMod(int s,int k){return (s%k+k)%k;}
double dic(pair<int,int>a,pair<int,int>b)
{return (sqrt( (a.first-b.first)*(a.first-b.first) +  (a.second-b.second)* (a.second-b.second) ));}

enum dir       { DOWN = 0, UP, RIGHT, LEFT, DOWN_RIGHT, DOWN_LEFT, UP_RIGHT, UP_LEFT };
int  dir_r[] = { 1, -1, 0, 0, 1, 1, -1, -1 };
int  dir_c[] = { 0, 0, 1, -1, 1, -1, 1, -1 };

//Posibles moves for the Knight
int recorrerA[8]= {-2,-1,1,2,2,1,-1,-2};
int recorrerB[8]= {1,2,2,1,-1,-2,-2,-1};
vector<pair<int,int>>v(2000);
int n;
ll mem[2001][2009];
ll rec(int i,int sum){
    if(sum>=n)
        return 0;
    if(i==n)
        return 1e18;
    if(mem[i][sum]!=-1)
        return mem[i][sum];
    ll x=1e18,y=1e18;
    x=rec(i+1,sum);
    y=rec(i+1,sum+v[i].first+1)+v[i].second;
    return mem[i][sum]=min(x,y);
}
int main(){

    Compiler_Beso

    cin>>n;
    for(int i=0;i<n;i++){
        cin>>v[i].first>>v[i].second;
    }
    clr(mem,-1);
    cout<<rec(0,0);
    return 0;

}


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

#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long ll ;
typedef long double ld ;

const ll MOD = 998244353, INF = 1E9 + 5 ;
const double PI = 2 * acos(0.0) ;
const long double EPS = 1.0E-14 ;

ll dp[2005][2005], arrC[2005], arrW[2005] ;

int main()
{
    ll n, ans = 0 ;
    scanf("%lld", &n) ;
    for (int i = 1; i <= n; i++) {
        scanf("%lld %lld", &arrW[i], &arrC[i]) ;
        arrW[i]++ ;
    }
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= n; j++) {
            dp[i][j] = INF ;
        }
    }
    for (int i = 0; i <= n; i++) {
        dp[i][0] = 0 ;
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            if (j < arrW[i]) {
                dp[i][j] = min(dp[i - 1][j], dp[i][j]) ;
            }
            else {
                dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - arrW[i]] + arrC[i]) ;
                ans = dp[i][j] ;
            }
        }
    }
    cout << ans ;

    return 0 ;
}


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

#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long ll ;
typedef long double ld ;

const ll MOD = 998244353, INF = 1E9 + 5 ;
const double PI = 2 * acos(0.0) ;
const long double EPS = 1.0E-14 ;

ll dp[2005][2005], arrC[2005], arrW[2005] ;

int main()
{
    ll n, ans = 0 ;
    scanf("%lld", &n) ;
    for (int i = 1; i <= n; i++) {
        scanf("%lld %lld", &arrW[i], &arrC[i]) ;
        arrW[i]++ ;
    }
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= n; j++) {
            dp[i][j] = INF ;
        }
    }
    for (int i = 0; i <= n; i++) {
        dp[i][0] = 0 ;
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            if (j < arrW[i]) {
                dp[i][j] = min(dp[i - 1][j], arrC[i]) ;
            }
            else {
                dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - arrW[i]] + arrC[i]) ;
            }
            ans = dp[i][j] ;
        }
    }
    cout << ans ;

    return 0 ;
}


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

#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long ll ;
typedef long double ld ;

const ll MOD = 998244353, INF = 2E18 + 5 ;
const double PI = 2 * acos(0.0) ;
const long double EPS = 1.0E-14 ;

ll n, ans = INF ;
ll arrW[2005], arrC[2005], dp[2005][2005] ;

ll check (ll pos, ll W)
{
    if (pos == 0) {
        if (W < n)  return dp[pos][W] = 1E18 ;
        else return dp[pos][W] = 0 ;
    }
    if (dp[pos][W] != INF)  return dp[pos][W] ;
    dp[pos][W] = min(dp[pos][W], min(arrC[pos] + check(pos - 1, W + arrW[pos]), check(pos - 1, W))) ;
    return dp[pos][W] ;
}

int main()
{
    cin >> n ;
    for (int i = 1; i <= n; i++) {
        scanf("%lld %lld", &arrW[i], &arrC[i]) ;
        arrW[i]++ ;
    }
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= n; j++) {
            dp[i][j] = INF ;
        }
    }
    check(n, 0) ;
    cout << dp[n][0] ;

    return 0 ;
}


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

#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long ll ;
typedef long double ld ;

const ll MOD = 998244353, INF = 1E18 + 5 ;
const double PI = 2 * acos(0.0) ;
const long double EPS = 1.0E-14 ;

ll dp[2005][2005], arrC[2005], arrW[2005] ;

int main()
{
    ll n, ans = 0 ;
    scanf("%lld", &n) ;
    for (int i = 1; i <= n; i++) {
        scanf("%lld %lld", &arrW[i], &arrC[i]) ;
        arrW[i]++ ;
    }
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= n; j++) {
            dp[i][j] = INF ;
        }
    }
    for (int i = 0; i <= n; i++) {
        dp[i][0] = 0 ;
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            if (j < arrW[i]) {
                dp[i][j] = min(dp[i - 1][j], arrC[i]) ;
            }
            else {
                dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - arrW[i]] + arrC[i]) ;
            }
            ans = dp[i][j] ;
        }
    }
    cout << ans ;

    return 0 ;
}


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

#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long ll ;
typedef long double ld ;

const ll MOD = 998244353, INF = 1E12 + 5 ;
const double PI = 2 * acos(0.0) ;
const long double EPS = 1.0E-14 ;

ll dp[2005][2005], arrC[2005], arrW[2005] ;

int main()
{
    ll n, ans = 0 ;
    scanf("%lld", &n) ;
    for (int i = 1; i <= n; i++) {
        scanf("%lld %lld", &arrW[i], &arrC[i]) ;
        arrW[i]++ ;
    }
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= n; j++) {
            dp[i][j] = INF ;
        }
    }
    for (int i = 0; i <= n; i++) {
        dp[i][0] = 0 ;
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            if (j < arrW[i]) {
                dp[i][j] = min(dp[i - 1][j], arrC[i]) ;
            }
            else {
                dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - arrW[i]] + arrC[i]) ;
            }
            ans = dp[i][j] ;
        }
    }
    cout << ans ;

    return 0 ;
}


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

#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long ll ;
typedef long double ld ;

const ll MOD = 998244353, INF = 2E18 + 5 ;
const double PI = 2 * acos(0.0) ;
const long double EPS = 1.0E-14 ;

ll n, ans = INF ;
ll arrW[2005], arrC[2005], dp[2005][2005] ;

ll check (ll pos, ll W)
{
    if (W >= n + 1) {
        W = n + 1 ;
    }
    if (pos == 0) {
        if (W < n)  return dp[pos][W] = 1E18 ;
        else return dp[pos][W] = 0 ;
    }
    if (dp[pos][W] != INF)  return dp[pos][W] ;
    dp[pos][W] = min(dp[pos][W], min(arrC[pos] + check(pos - 1, W + arrW[pos]), check(pos - 1, W))) ;
    return dp[pos][W] ;
}

int main()
{
    cin >> n ;
    for (int i = 1; i <= n; i++) {
        scanf("%lld %lld", &arrW[i], &arrC[i]) ;
        arrW[i]++ ;
    }
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= n; j++) {
            dp[i][j] = INF ;
        }
    }
    check(n, 0) ;
    cout << dp[n][0] ;

    return 0 ;
}


#include<bits/stdc++.h>

const int N = 2010;
typedef long long ll;

ll dp[N * 3];
int n;
int t[N], c[N];

int main(){
	scanf("%d", &n);
	memset(dp, 0x3f, sizeof(dp));
	dp[0] = 0;
	for (int i = 1; i <= n; ++ i){
		scanf("%d%d", &t[i], &c[i]);
		for (int j = N * 3 - 1; j >= 0; -- j){
			if (j + t[i] + 1 >= 3 * N) continue;
			dp[j + t[i] + 1] = std::min(dp[j + t[i] + 1], dp[j] + c[i]);
		}
	}
	ll ans = LLONG_MAX;
	for (int i = n; i < N * 3; ++ i){
		ans = std::min(ans, dp[i]);
	}
	return printf("%I64d\n", ans), 0;
}


#include<bits/stdc++.h>

const int N = 2010;
typedef long long ll;

ll dp[N * 3];
int n;
int t[N], c[N];

int main(){
	scanf("%d", &n);
	memset(dp, 0x3f, sizeof(dp));
	dp[0] = 0;
	for (int i = 1; i <= n; ++ i){
		scanf("%d%d", &t[i], &c[i]);
		for (int j = N * 3 - 1; j >= 0; -- j){
			if (j + t[i] + 1 >= N) continue;
			dp[j + t[i] + 1] = std::min(dp[j + t[i] + 1], dp[j] + c[i]);
		}
	}
	ll ans = LLONG_MAX;
	for (int i = n; i < N * 3; ++ i){
		ans = std::min(ans, dp[i]);
	}
	return printf("%I64d\n", ans), 0;
}


#include <iostream>
using namespace std;
#define MAX 2005

long long n, w, v, d[MAX];

int main() {
	cin>>n;
	// for(int i=1; i<=n; ++i)d[i]=1e18;
	d[0]=0;
	for(int i=0; i<=n; ++i){
		if(i>0)cin>>w>>v;
		for(int j=n; j>=0; --j){
			if(i==0){
				d[j]=1e18;
				if(j==0)d[j]=0;
			}
			else{
				// if(j==0)d[j]=0;
				d[j]=min(d[j], d[max(j-w-1,0LL)]+v);
			}
		}
		// cout<<'\n';
	}
	cout<<d[n]<<'\n';
	return 0;
}


#include <iostream>
using namespace std;
#define MAX 2005

long long n, w, v, d[MAX];

int main() {
	cin>>n;
	for(int i=1; i<n+1; ++i)d[i]=1e18;
	d[0]=0;
	for(int i=1; i<=n; ++i){
		cin>>w>>v;
		for(int j=n; j>w; --j){
			// cout<<j-w-1<<' ';
			d[j]=min(d[j], d[j-w-1]+v);
		}
		// cout<<'\n';
	}
	cout<<d[n]<<'\n';
	return 0;
}


#include <iostream>
using namespace std;
#define MAX 2005

long long n, w, v, d[MAX];

int main() {
	cin>>n;
	// for(int i=1; i<=n; ++i)d[i]=1e18;
	d[0]=0;
	for(int i=0; i<=n; ++i){
		if(i>0)cin>>w>>v;
		for(int j=n; j>=0; --j){
			if(i==0){
				d[j]=1e18;
			}
			else{
				if(j==0)d[j]=0;
				d[j]=min(d[j], d[max(j-w-1,0LL)]+v);
			}
		}
		// cout<<'\n';
	}
	cout<<d[n]<<'\n';
	return 0;
}


#include <iostream>
using namespace std;
#define MAX 2005

long long n, w, v, d[MAX];

int main() {
	cin>>n;
	for(int i=1; i<n+1; ++i)d[i]=1e18;
	d[0]=0;
	for(int i=1; i<=n; ++i){
		cin>>w>>v;
		for(int j=n; j>0; --j){
			// cout<<j-w-1<<' ';
			d[j]=min(d[j], d[max(j-w-1,0LL)]+v);
		}
		// cout<<'\n';
	}
	cout<<d[n]<<'\n';
	return 0;
}


#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#define sqr(x) (x)*(x)
using namespace std;
long long n,ti[2005],co[2005],dp[2005][2005],i,j;
int main()
{
	cin>>n;
	for (i=1;i<=n;i++)
	{
		cin>>ti[i]>>co[i];
		ti[i]++;
	}
	for (i=1;i<=n;i++)
	{
		for (j=0;j<=n;j++) dp[j][i]=1e16;
	}
	for (i=1;i<=n;i++)
	{
		for (j=min(ti[i],n);j<=n;j++)
		{
			dp[i][j]=min(dp[i-1][j],dp[i-1][max(0ll,j-ti[i])]+co[i]);
		}
	}
	cout<<dp[n][n];
	return 0;
}


#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#define sqr(x) (x)*(x)
using namespace std;
long long n,ti[2005],co[2005],dp[2005][2005],i,j;
int main()
{
	cin>>n;
	for (i=1;i<=n;i++)
	{
		cin>>ti[i]>>co[i];
		ti[i]++;
	}
	for (i=0;i<=n;i++)
	{
		for (j=1;j<=n;j++) dp[i][j]=1e16;
	}
	for (i=1;i<=n;i++)
	{
		for (j=1;j<=n;j++)
		{
			dp[i][j]=min(dp[i-1][j],dp[i-1][max(0ll,j-ti[i])]+co[i]);
		}
	}
	cout<<dp[n][n];
	return 0;
}


#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#define sqr(x) (x)*(x)
using namespace std;
int n,ti[2005],co[2005],dp[2005][2005],i,j;
int main()
{
	cin>>n;
	for (i=1;i<=n;i++)
	{
		cin>>ti[i]>>co[i];
		ti[i]++;
	}
	for (i=1;i<=n;i++)
	{
		for (j=0;j<=n;j++) dp[j][i]=1<<30;
	}
	for (i=1;i<=n;i++)
	{
		for (j=min(ti[i],n);j<=n;j++)
		{
			dp[i][j]=min(dp[i-1][j],dp[i-1][max(0,j-ti[i])]+co[i]);
		}
	}
	cout<<dp[n][n];
	return 0;
}


#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#define sqr(x) (x)*(x)
using namespace std;
int n,ti[2005],co[2005],dp[2005][2005],i,j;
int main()
{
	cin>>n;
	for (i=1;i<=n;i++)
	{
		cin>>ti[i]>>co[i];
		ti[i]++;
	}
	for (i=1;i<=n;i++)
	{
		for (j=0;j<=n;j++) dp[j][i]=1<<25;
	}
	for (i=1;i<=n;i++)
	{
		for (j=min(ti[i],n);j<=n;j++)
		{
			dp[i][j]=min(dp[i-1][j],dp[i-1][max(0,j-ti[i])]+co[i]);
		}
	}
	cout<<dp[n][n];
	return 0;
}


#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define mt make_tuple
#define MOD 1000000007
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vl vector <long long int>
#define pii pair <int,int>
#define pll pair <long long int, long long int>
#define vpii vector< pair<int,int> >
#define vpll vector < pair <long long int,long long int> >
#define boost ios::sync_with_stdio(false); cin.tie(0)
using namespace std;
const int inf = 1e9 + 5;
const ll inf64 = 1e18 + 5;

const int MAX = 2e3 + 5;
ll dp[MAX];
int main()
{
	boost;
	int n, i;
	cin >> n;

	fill(dp, dp + MAX, inf64);
	dp[0] = 0;
	fo(i, 0, n) {
		int x, y;
		cin >> x >> y;
		++x;
		for(int j = n; j > 0; j--) {
			int cr = max(0, j - x);
			dp[j] = min(dp[j], dp[cr] + y);
		}
	}
	cout << dp[n];
}


#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define mt make_tuple
#define MOD 1000000007
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vl vector <long long int>
#define pii pair <int,int>
#define pll pair <long long int, long long int>
#define vpii vector< pair<int,int> >
#define vpll vector < pair <long long int,long long int> >
#define boost ios::sync_with_stdio(false); cin.tie(0)
using namespace std;
const int inf = 1e9 + 5;
const ll inf64 = 1e18 + 5;

const int MAX = 2e3 + 5;
ll dp[MAX], val[MAX];
int main()
{
	boost;
	int n, i;
	cin >> n;

	fill(dp, dp + MAX, inf64);
	fill(val, val + MAX, inf64);
	val[0] = dp[0] = 0;
	fo(i, 0, n) {
		int x, y;
		cin >> x >> y;
		++x;
		for(int j = 0; j <= n; j++) {
			int cr = min(j + x, n);
			dp[cr] = min(dp[cr], val[j] + y);
		}
		memcpy(val, dp, sizeof dp);
	}
	cout << dp[n];
}


#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define mt make_tuple
#define MOD 1000000007
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vl vector <long long int>
#define pii pair <int,int>
#define pll pair <long long int, long long int>
#define vpii vector< pair<int,int> >
#define vpll vector < pair <long long int,long long int> >
#define boost ios::sync_with_stdio(false); cin.tie(0)
using namespace std;
const int inf = 1e9 + 5;
const ll inf64 = 1e18 + 5;

const int MAX = 2e3 + 5;
ll dp[MAX];
int main()
{
	boost;
	int n, i;
	cin >> n;

	fill(dp, dp + MAX, inf);
	dp[0] = 0;
	fo(i, 0, n) {
		int x, y;
		cin >> x >> y;
		++x;
		for(int j = MAX - 1; j > 0; j--) {
			if(j - x >= 0)
			dp[j] = min(dp[j], dp[j - x] + y);
		}
	}
	cout << *min_element(dp + n, dp + MAX);
}


#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define mt make_tuple
#define MOD 1000000007
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vl vector <long long int>
#define pii pair <int,int>
#define pll pair <long long int, long long int>
#define vpii vector< pair<int,int> >
#define vpll vector < pair <long long int,long long int> >
#define boost ios::sync_with_stdio(false); cin.tie(0)
using namespace std;
const int inf = 1e9 + 5;
const ll inf64 = 1e18 + 5;

const int MAX = 2e3 + 5;
ll dp[MAX];
int main()
{
	boost;
	int n, i;
	cin >> n;

	fill(dp, dp + MAX, inf64);
	dp[0] = 0;
	fo(i, 0, n) {
		int x, y;
		cin >> x >> y;
		++x;
		for(int j = MAX - 1; j > 0; j--) {
			if(j - x >= 0)
			dp[j] = min(dp[j], dp[j - x] + y);
		}
	}
	cout << *min_element(dp + n, dp + MAX);
}


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

const int N = 2 * 1000 + 3;
const int inf = 1e15;
vector<vector<int>> dp(2001, vector<int>(N, inf));

int f(int x) { return min(N - 1, x); }

signed main() {
    std::ios::sync_with_stdio(0);
    std::cout.tie(0);
    std::cin.tie(0);
    int n; cin >> n;
    vector<array<int, 2>> a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i][1] >> a[i][0];
    }
    sort(a.begin(), a.end());
    dp[0][0] = 0;
    for(int i = 1; i <= n; i++) {
        for(int time = 0; time < N - 1; time++) {
            dp[i][time] = min(dp[i][time], dp[i - 1][time + 1]);
            dp[i][time] = min(dp[i][time], dp[i - 1][time] + a[i - 1][0]);
            dp[i][a[i - 1][1]] = min(dp[i][a[i - 1][1]], dp[i - 1][time] + a[i - 1][0]);
            if(a[i - 1][1] >= i - 1)
                dp[i][a[i - 1][1] - i + 1] = min(dp[i][a[i - 1][1] - i + 1], a[i - 1][0]);
            dp[i][f(time + a[i - 1][1])] = min(dp[i][f(time + a[i - 1][1])], dp[i - 1][time] + a[i - 1][0]);
        }
    }
    //for(int i = 0; i <= n; i++) { for(int j = 0; j <= 20; j++) cout << (dp[i][j] >= inf ? -1 : dp[i][j]) << " "; cout << endl; }
    int ans = inf;
    for(int time = 0; time < N; time++) ans = min(ans, dp[n][time]);
    cout << ans << endl;
    return 0;
}


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

const int N = 8 * 1000 + 3;
const int inf = 1e15;
vector<vector<int>> dp(2001, vector<int>(N, inf));

int f(int x) { return min(N - 1, x); }

signed main() {
    std::ios::sync_with_stdio(0);
    std::cout.tie(0);
    std::cin.tie(0);
    int n; cin >> n;
    vector<array<int, 2>> a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i][1] >> a[i][0];
    }
    sort(a.begin(), a.end());
    dp[0][0] = 0;
    for(int i = 1; i <= n; i++) {
        for(int time = 0; time < N; time++) {
            dp[i][time] = min(dp[i][time], dp[i - 1][time + 1]);
            dp[i][time] = min(dp[i][time], dp[i - 1][time] + a[i - 1][0]);
            dp[i][a[i - 1][1]] = min(dp[i][a[i - 1][1]], dp[i - 1][time] + a[i - 1][0]);
            dp[i][f(time + a[i - 1][1])] = min(dp[i][f(time + a[i - 1][1])], dp[i - 1][time] + a[i - 1][0]);
        }
    }
    //for(int i = 0; i <= n; i++) { for(int j = 0; j <= 20; j++) cout << (dp[i][j] >= inf ? -1 : dp[i][j]) << " "; cout << endl; }
    int ans = inf;
    for(int time = 0; time < N; time++) ans = min(ans, dp[n][time]);
    cout << ans << endl;
    return 0;
}


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

const int N = 8 * 1000 + 3;
const int inf = 1e15;
vector<vector<int>> dp(2001, vector<int>(N, inf));

int f(int x) { return min(N - 1, x); }

signed main() {
    std::ios::sync_with_stdio(0);
    std::cout.tie(0);
    std::cin.tie(0);
    int n; cin >> n;
    vector<array<int, 2>> a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i][1] >> a[i][0];
    }
    sort(a.begin(), a.end());
    dp[0][0] = 0;
    for(int i = 1; i <= n; i++) {
        for(int time = 0; time < N - 1; time++) {
            dp[i][time] = min(dp[i][time], dp[i - 1][time + 1]);
            dp[i][time] = min(dp[i][time], dp[i - 1][time] + a[i - 1][0]);
            dp[i][a[i - 1][1]] = min(dp[i][a[i - 1][1]], dp[i - 1][time] + a[i - 1][0]);
            dp[i][f(time + a[i - 1][1])] = min(dp[i][f(time + a[i - 1][1])], dp[i - 1][time] + a[i - 1][0]);
        }
    }
    //for(int i = 0; i <= n; i++) { for(int j = 0; j <= 20; j++) cout << (dp[i][j] >= inf ? -1 : dp[i][j]) << " "; cout << endl; }
    int ans = inf;
    for(int time = 0; time < N; time++) ans = min(ans, dp[n][time]);
    cout << ans << endl;
    return 0;
}


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

const int N = 2 * 1000 + 3;
const int inf = 1e15;
vector<vector<int>> dp(N, vector<int>(N, inf));
//dp[i][time] - min cost to buy first i items with time second left.

int f(int x) { return min(N - 1, x); }

signed main() {
    std::ios::sync_with_stdio(0);
    std::cout.tie(0);
    std::cin.tie(0);
    int n; cin >> n;
    vector<array<int, 2>> a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i][1] >> a[i][0];
    }
    sort(a.begin(), a.end());
    dp[0][0] = 0;
    for(int i = 1; i <= n; i++) {
        for(int time = 0; time < N - 1; time++) {
            dp[i][time] = min(dp[i][time], dp[i - 1][time + 1]);
            dp[i][time] = min(dp[i][time], dp[i - 1][time] + a[i - 1][0]);
            dp[i][a[i - 1][1]] = min(dp[i][a[i - 1][1]], dp[i - 1][time] + a[i - 1][0]);
            if(a[i - 1][1] >= i - 1)
                dp[i][a[i - 1][1] - i + 1] = min(dp[i][a[i - 1][1] - i + 1], a[i - 1][0]);
            dp[i][f(time + a[i - 1][1])] = min(dp[i][f(time + a[i - 1][1])], dp[i - 1][time] + a[i - 1][0]);
        }
    }
    //for(int i = 0; i <= n; i++) { for(int j = 0; j <= 20; j++) cout << (dp[i][j] >= inf ? -1 : dp[i][j]) << " "; cout << endl; }
    int ans = inf;
    for(int time = 0; time < N; time++) ans = min(ans, dp[n][time]);
    cout << ans << endl;
    return 0;
}


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

const int N = 8 * 1000 + 3;
const int inf = 1e15;
vector<vector<int>> dp(2001, vector<int>(N, inf));

bool cmp(array<int, 2> a, array<int, 2> b) { return a[1] > b[1]; }

int f(int x) { return min(N - 1, x); }

signed main() {
    std::ios::sync_with_stdio(0);
    std::cout.tie(0);
    std::cin.tie(0);
    int n; cin >> n;
    vector<array<int, 2>> a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i][1] >> a[i][0];
    }
    sort(a.begin(), a.end());
    //cout << endl; for(auto tx : a) cout << tx[1] << " " << tx[0] << endl; cout << endl;
    dp[0][0] = 0;
    for(int i = 1; i <= n; i++) {
        for(int time = 0; time < N - 1; time++) {
            dp[i][time] = min(dp[i][time], dp[i - 1][time + 1]);
            dp[i][time] = min(dp[i][time], dp[i - 1][time] + a[i - 1][0]);
            dp[i][a[i - 1][1]] = min(dp[i][a[i - 1][1]], dp[i - 1][time] + a[i - 1][0]);
            if(a[i - 1][1] >= i - 1)
                dp[i][a[i - 1][1] - i + 1] = min(dp[i][a[i - 1][1] - i + 1], a[i - 1][0]);
            dp[i][f(time + a[i - 1][1])] = min(dp[i][f(time + a[i - 1][1])], dp[i - 1][time] + a[i - 1][0]);
        }
    }
    //for(int i = 0; i <= n; i++) { for(int j = 0; j <= 20; j++) cout << (dp[i][j] >= inf ? -1 : dp[i][j]) << " "; cout << endl; }
    int ans = inf;
    for(int time = 0; time < N; time++) ans = min(ans, dp[n][time]);
    cout << ans << endl;
    return 0;
}


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

const int N = 8 * 1000 + 3;
const int inf = 1e18;
vector<vector<int>> dp(2001, vector<int>(N, inf));

int f(int x) { return min(N - 1, x); }

signed main() {
    std::ios::sync_with_stdio(0);
    std::cout.tie(0);
    std::cin.tie(0);
    int n; cin >> n;
    vector<array<int, 2>> a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i][1] >> a[i][0];
    }
    sort(a.begin(), a.end());
    dp[0][0] = 0;
    for(int i = 1; i <= n; i++) {
        for(int time = 0; time < N - 1; time++) {
            dp[i][time] = min(dp[i][time], dp[i - 1][time + 1]);
            dp[i][time] = min(dp[i][time], dp[i - 1][time] + a[i - 1][0]);
            dp[i][a[i - 1][1]] = min(dp[i][a[i - 1][1]], dp[i - 1][time] + a[i - 1][0]);
            dp[i][f(time + a[i - 1][1])] = min(dp[i][f(time + a[i - 1][1])], dp[i - 1][time] + a[i - 1][0]);
        }
    }
    for(int i = 0; i <= n; i++) { for(int j = 0; j <= 20; j++) cout << (dp[i][j] >= inf ? -1 : dp[i][j]) << " "; cout << endl; }
    int ans = inf;
    for(int time = 0; time < N; time++) ans = min(ans, dp[n][time]);
    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>
#define t first
#define c second
#define inf 1e15
using namespace std;

typedef long long ll;

int n;
pair<int,int> a[2002];
ll dp[2002][4002];

ll solve(int idx,int time){
    if(idx == n){
        if(time >= 0) return 0;
        return inf;
    }
    if(time > 2000) time = 2000;
    if(dp[idx][time+2000] != -1) return dp[idx][time+2000];

    ll ret = solve(idx+1,time+a[idx].t) + a[idx].c;
    ret = min(ret,solve(idx+1,time-1));

    return dp[idx][time+2000] = ret;
}

int main()
{
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>a[i].t>>a[i].c;
    memset(dp,-1,sizeof(dp));
    cout<<solve(0,0);

    return 0;
}


#include <iostream>
#include <bits/stdc++.h>
#define t first
#define c second
#define inf 1e15
using namespace std;

typedef long long ll;

int n;
pair<int,int> a[2002];
ll dp[2002][4002];

ll solve(int idx,int time){
    if(idx == n){
        if(time >= 0) return 0;
        return inf;
    }
    if(time > 4000) time = 4000;
    if(dp[idx][time] != -1) return dp[idx][time];

    ll ret = solve(idx+1,time+a[idx].t) + a[idx].c;
    ret = min(ret,solve(idx+1,time-1));

    return dp[idx][time+2000] = ret;
}

int main()
{
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>a[i].t>>a[i].c;
    memset(dp,-1,sizeof(dp));
    cout<<solve(0,0);

    return 0;
}


#include <iostream>
#include <bits/stdc++.h>
#define t first
#define c second
#define inf 1e15
using namespace std;

typedef long long ll;

int n;
pair<int,int> a[2002];
ll dp[2002][4002];

ll solve(int idx,int time){
    if(idx == n){
        if(time >= 0) return 0;
        return inf;
    }
    if(time > 2000) time = 2000;
    if(dp[idx][time] != -1) return dp[idx][time];

    ll ret = solve(idx+1,time+a[idx].t) + a[idx].c;
    ret = min(ret,solve(idx+1,time-1));

    return dp[idx][time] = ret;
}

int main()
{
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>a[i].t>>a[i].c;
    memset(dp,-1,sizeof(dp));
    cout<<solve(0,0);

    return 0;
}


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

#define fr freopen("in.txt", "r", stdin);
#define fw freopen("out.txt", "w", stdout);
#define sd(x) scanf("%d", &x);
#define sl(x) scanf("%lld", &x);
#define sf(x) scanf("%lf", &x);
#define ll long long
#define ull unsigned long long
#define fi first
#define se second
#define mem(v, x) memset(v, x, sizeof(v));
#define EB emplace_back
#define PB push_back
#define MP make_pair
#define N 2010

int dp[N][N], c[N], t[N], n;

inline int rec(int i, int j)
{
    if (j == 0)
        return 0;
    if (i == n)
        return 100000000;
    int &ret = dp[i][j];
    if (ret != -1)
        return ret;
    ret = rec(i + 1, j); // + c[i];
    ret = min(ret, rec(i + 1, max(j - 1 - t[i], 0)) + c[i]);
    return ret;
}

int main()
{
    //fr;
    //fw;

    sd(n);

    for (int x = 0; x < n; x++)
    {
        sd(t[x]);
        sd(c[x]);
    }

    mem(dp, -1);
    int res = rec(0, n);
    printf("%d", res);
}


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

#define fr freopen("in.txt", "r", stdin);
#define fw freopen("out.txt", "w", stdout);
#define sd(x) scanf("%d", &x);
#define sl(x) scanf("%lld", &x);
#define sf(x) scanf("%lf", &x);
#define ll long long
#define ull unsigned long long
#define fi first
#define se second
#define mem(v, x) memset(v, x, sizeof(v));
#define EB emplace_back
#define PB push_back
#define MP make_pair
#define N 2010

ll dp[N][N], c[N], t[N], n;

inline ll rec(int i, int j)
{
    if (j <= 0)
        return 0LL;
    if (i >= n)
        return 1000000000000000000LL;
    ll &ret = dp[i][j];
    if (ret != -1)
        return ret;
    ret = rec(i + 1, j); // + c[i];
    ret = min(ret, rec(i + 1, j - 1 - t[i]) + c[i]);
    return ret;
}

int main()
{
    //fr;
    //fw;

    sl(n);

    for (int x = 0; x < n; x++)
    {
        sl(t[x]);
        sl(c[x]);
    }

    mem(dp, -1);
    ll res = rec(0, n);
    printf("%lld", res);
}


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

#define fr freopen("in.txt", "r", stdin);
#define fw freopen("out.txt", "w", stdout);
#define sd(x) scanf("%d", &x);
#define sl(x) scanf("%lld", &x);
#define sf(x) scanf("%lf", &x);
#define ll long long
#define ull unsigned long long
#define fi first
#define se second
#define mem(v, x) memset(v, x, sizeof(v));
#define EB emplace_back
#define PB push_back
#define MP make_pair
#define N 2010

int dp[N][N], c[N], t[N], n;

inline int rec(int i, int j)
{
    if (j <= 0)
        return 0;
    if (i >= n)
        return 100000000;
    int &ret = dp[i][j];
    if (ret != -1)
        return ret;
    ret = rec(i + 1, j); // + c[i];
    ret = min(ret, rec(i + 1, j - 1 - t[i]) + c[i]);
    return ret;
}

int main()
{
    //fr;
    //fw;

    sd(n);

    for (int x = 0; x < n; x++)
    {
        sd(t[x]);
        sd(c[x]);
    }

    mem(dp, -1);
    int res = rec(0, n);
    printf("%d", res);
}


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

#define fr freopen("in.txt", "r", stdin);
#define fw freopen("out.txt", "w", stdout);
#define sd(x) scanf("%d", &x);
#define sl(x) scanf("%lld", &x);
#define sf(x) scanf("%lf", &x);
#define ll long long
#define ull unsigned long long
#define fi first
#define se second
#define mem(v, x) memset(v, x, sizeof(v));
#define EB emplace_back
#define PB push_back
#define MP make_pair
#define N 2010

int dp[N][N], c[N], t[N], n;

inline int rec(int i, int j)
{
    if (i == n)
    {
        if (j)
            return 10000000;
        else
            return 0;
    }
    int &ret = dp[i][j];
    if (ret != -1)
        return ret;
    ret = rec(i + 1, j); // + c[i];
    ret = min(ret, rec(i + 1, max(j - 1 - t[i], 0)) + c[i]);
    return ret;
}

int main()
{
    //fr;
    //fw;

    sd(n);

    for (int x = 0; x < n; x++)
    {
        sd(t[x]);
        sd(c[x]);
    }

    mem(dp, -1);
    int res = rec(0, n);
    printf("%d", res);
}


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

#define fr freopen("in.txt", "r", stdin);
#define fw freopen("out.txt", "w", stdout);
#define sd(x) scanf("%d", &x);
#define sl(x) scanf("%lld", &x);
#define sf(x) scanf("%lf", &x);
#define ll long long
#define ull unsigned long long
#define fi first
#define se second
#define mem(v, x) memset(v, x, sizeof(v));
#define EB emplace_back
#define PB push_back
#define MP make_pair
#define N 2010

int dp[N][N], c[N], t[N], n;

inline int rec(int i, int j)
{
    if (i == n && j == 0)
        return 0;
    if (j <= 0 || i == n)
        return 100000000;
    int &ret = dp[i][j];
    if (ret != -1)
        return ret;
    ret = rec(i + 1, j); // + c[i];
    ret = min(ret, rec(i + 1, max(j - 1 - t[i], 0)) + c[i]);
    return ret;
}

int main()
{
    //fr;
    //fw;

    sd(n);

    for (int x = 0; x < n; x++)
    {
        sd(t[x]);
        sd(c[x]);
    }

    mem(dp, -1);
    int res = rec(0, n);
    printf("%d", res);
}


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

#define fr freopen("in.txt", "r", stdin);
#define fw freopen("out.txt", "w", stdout);
#define sd(x) scanf("%d", &x);
#define sl(x) scanf("%lld", &x);
#define sf(x) scanf("%lf", &x);
#define ll long long
#define ull unsigned long long
#define fi first
#define se second
#define mem(v, x) memset(v, x, sizeof(v));
#define EB emplace_back
#define PB push_back
#define MP make_pair
#define N 2010

int dp[N][N], c[N], t[N], n;

inline int rec(int i, int j)
{
    if (i == n && j == 0)
        return 0;
    if (j <= 0 || i == n)
        return 100000000;
    int &ret = dp[i][j];
    if (ret != -1)
        return ret;
    ret = rec(i + 1, j); // + c[i];
    ret = min(ret, rec(i + 1, max(j - 1 - t[i], 0)) + c[i]);
    return ret;
}

int main()
{
    fr;
    fw;

    sd(n);

    for (int x = 0; x < n; x++)
    {
        sd(t[x]);
        sd(c[x]);
    }

    mem(dp, -1);
    int res = rec(0, n);
    printf("%d", res);
}


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

#define fr freopen("in.txt", "r", stdin);
#define fw freopen("out.txt", "w", stdout);
#define sd(x) scanf("%d", &x);
#define sl(x) scanf("%lld", &x);
#define sf(x) scanf("%lf", &x);
#define ll long long
#define ull unsigned long long
#define fi first
#define se second
#define mem(v, x) memset(v, x, sizeof(v));
#define EB emplace_back
#define PB push_back
#define MP make_pair
#define N 2010

ll dp[N][N], c[N], t[N], n;

inline ll rec(int i, int j)
{
    if (j <= 0)
        return 0;
    if (i >= n)
        return 1000000000000000000LL;
    int &ret = dp[i][j];
    if (ret != -1)
        return ret;
    ret = rec(i + 1, j); // + c[i];
    ret = min(ret, rec(i + 1, j - 1 - t[i]) + c[i]);
    return ret;
}

int main()
{
    //fr;
    //fw;

    sd(n);

    for (int x = 0; x < n; x++)
    {
        sl(t[x]);
        sl(c[x]);
    }

    mem(dp, -1);
    ll res = rec(0, n);
    printf("%lld", res);
}


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

#define fr freopen("in.txt", "r", stdin);
#define fw freopen("out.txt", "w", stdout);
#define sd(x) scanf("%d", &x);
#define sl(x) scanf("%lld", &x);
#define sf(x) scanf("%lf", &x);
#define ll long long
#define ull unsigned long long
#define fi first
#define se second
#define mem(v, x) memset(v, x, sizeof(v));
#define EB emplace_back
#define PB push_back
#define MP make_pair
#define N 2010

int dp[N][N], c[N], t[N], n;

inline int rec(int i, int j)
{
    if (j <= 0)
        return 0;
    if (i >= n)
        return 2 * 1000000000;
    int &ret = dp[i][j];
    if (ret != -1)
        return ret;
    ret = rec(i + 1, j); // + c[i];
    ret = min(ret, rec(i + 1, j - 1 - t[i]) + c[i]);
    return ret;
}

int main()
{
    //fr;
    //fw;

    sd(n);

    for (int x = 0; x < n; x++)
    {
        sd(t[x]);
        sd(c[x]);
    }

    mem(dp, -1);
    int res = rec(0, n);
    printf("%d", res);
}


#include <iostream>
#include<stdio.h>
#include<climits>
#include<stdlib.h>
#include<algorithm>
#include<cstring>
#include<map>
#include<vector>
#include<cstdio>
#include<cstring>
#define gc getchar
#define lli unsigned long long int
using namespace std;
void scanint(unsigned long long int &x);
bool compare(const pair<lli,lli> &a, const pair<lli,lli> &b)
{
    if(a.first < b.first)
        return true;
    else if(a.first == b.first)
        return a.second>b.second;
    else    return false;
}

lli dp[2001][2001];
lli inf = 999999999 * 2001;

vector<lli> val;
int main() {
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    lli n;
    scanint(n);
    vector< pair<lli , lli> > v;
    lli i = 0;
    lli j = 0;
    for(i = 0;i<=n;i++)
    {
        for(j = 0;j<=n;j++)
        {
            if(j == 0)
                dp[i][j] = 0;
            else
                dp[i][j] = inf;
        }
    }
    for(i = 0;i<n;i++)
    {
        lli c,t;
        scanint(t);
        scanint(c);
        v.push_back(make_pair(t+1,c));
    }
    sort(v.begin(),v.end(),compare);
    /*cout<<"--------------------------------"<<endl;
    for(i = 0;i<n;i++)
    {
        cout<<v[i].first<<" " <<v[i].second<<endl;
    }*/
    for(i = 0;i<v.size();i++)
    {
        lli time = v[i].first;
        lli cost = v[i].second;
        for(j = 1;j<=n;j++)
        {
            if(j - time <= 0)
            {
                dp[i+1][j] = min(dp[i][0] + cost,dp[i][j]);
            }
            else
                dp[i+1][j] = min(dp[i][j-time]+cost,dp[i][j]);
        }
    }
    cout<<dp[n][n]<<endl;
 	return 0;
}
/*
5
2 10
2 12
0 20
1 5
1 3
*/

void scanint(unsigned long long int &x)
{
    register int c = gc();
    x = 0;
    int neg = 0;
    for(;((c<48 || c>57) && c != '-');c = gc());
    if(c=='-') {neg=1;c=gc();}
    for(;c>47 && c<58;c = gc()) {x = (x<<1) + (x<<3) + c - 48;}
    if(neg) x=-x;
}


#include <iostream>
#include<stdio.h>
#include<climits>
#include<stdlib.h>
#include<algorithm>
#include<cstring>
#include<map>
#include<vector>
#include<cstdio>
#include<cstring>
#define gc getchar
#define lli long long int
using namespace std;
void scanint(long long int &x);
bool compare(const pair<lli,lli> &a, const pair<lli,lli> &b)
{
    if(a.first < b.first)
        return true;
    else if(a.first == b.first)
        return a.second>b.second;
    else    return false;
}

lli dp[2001][2001];
lli inf = 9999999999999999;

vector<lli> val;
int main() {
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    lli n;
    scanint(n);
    vector< pair<lli , lli> > v;
    lli i = 0;
    lli j = 0;
    for(i = 0;i<=n;i++)
    {
        for(j = 0;j<=n;j++)
        {
            if(j == 0)
                dp[i][j] = 0;
            else
                dp[i][j] = inf;
        }
    }
    for(i = 0;i<n;i++)
    {
        lli c,t;
        scanint(t);
        scanint(c);
        v.push_back(make_pair(t+1,c));
    }
    sort(v.begin(),v.end(),compare);
    /*cout<<"--------------------------------"<<endl;
    for(i = 0;i<n;i++)
    {
        cout<<v[i].first<<" " <<v[i].second<<endl;
    }*/
    for(i = 0;i<v.size();i++)
    {
        lli time = v[i].first;
        lli cost = v[i].second;
        for(j = 1;j<=n;j++)
        {
            if(j - time <= 0)
            {
                dp[i+1][j] = min(dp[i][0] + cost,dp[i][j]);
            }
            else
                dp[i+1][j] = min(dp[i][j-time]+cost,dp[i][j]);
        }
    }
    cout<<dp[n][n]<<endl;
 	return 0;
}
/*
5
2 10
2 12
0 20
1 5
1 3
*/

void scanint(long long int &x)
{
    register int c = gc();
    x = 0;
    int neg = 0;
    for(;((c<48 || c>57) && c != '-');c = gc());
    if(c=='-') {neg=1;c=gc();}
    for(;c>47 && c<58;c = gc()) {x = (x<<1) + (x<<3) + c - 48;}
    if(neg) x=-x;
}


#include <iostream>
#include<stdio.h>
#include<climits>
#include<stdlib.h>
#include<algorithm>
#include<cstring>
#include<map>
#include<vector>
#include<cstdio>
#include<cstring>
#define gc getchar
#define lli long long int
using namespace std;
void scanint(long long int &x);
bool compare(const pair<lli,lli> &a, const pair<lli,lli> &b)
{
    if(a.first < b.first)
        return true;
    else if(a.first == b.first)
        return a.second>b.second;
    else    return false;
}

lli dp[2001][2001];
lli inf = 999999999999;

vector<lli> val;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    lli n;
    scanint(n);
    vector< pair<lli , lli> > v;
    lli i = 0;
    lli j = 0;
    for(i = 0;i<=n;i++)
    {
        for(j = 0;j<=n;j++)
        {
            if(j == 0)
                dp[i][j] = 0;
            else
                dp[i][j] = inf;
        }
    }
    for(i = 0;i<n;i++)
    {
        lli c,t;
        scanint(t);
        scanint(c);
        v.push_back(make_pair(t+1,c));
    }
    sort(v.begin(),v.end(),compare);
    /*cout<<"--------------------------------"<<endl;
    for(i = 0;i<n;i++)
    {
        cout<<v[i].first<<" " <<v[i].second<<endl;
    }*/
    for(i = 0;i<v.size();i++)
    {
        lli time = v[i].first;
        lli cost = v[i].second;
        for(j = 1;j<=n;j++)
        {
            if(j - time <= 0)
            {
                dp[i+1][j] = min(dp[i][0] + cost,dp[i][j]);
            }
            else
                dp[i+1][j] = min(dp[i][j-time]+cost,dp[i][j]);
        }
    }
    cout<<dp[n][n]<<endl;
 	return 0;
}
/*
5
2 10
2 12
0 20
1 5
1 3
*/

void scanint(long long int &x)
{
    register int c = gc();
    x = 0;
    int neg = 0;
    for(;((c<48 || c>57) && c != '-');c = gc());
    if(c=='-') {neg=1;c=gc();}
    for(;c>47 && c<58;c = gc()) {x = (x<<1) + (x<<3) + c - 48;}
    if(neg) x=-x;
}


#include <iostream>
#include<stdio.h>
#include<climits>
#include<stdlib.h>
#include<algorithm>
#include<cstring>
#include<map>
#include<vector>
#include<cstdio>
#include<cstring>
#define gc getchar
#define lli unsigned long long int
using namespace std;
void scanint(unsigned long long int &x);
bool compare(const pair<lli,lli> &a, const pair<lli,lli> &b)
{
    if(a.first < b.first)
        return true;
    else if(a.first == b.first)
        return a.second>b.second;
    else    return false;
}

lli dp[2001][2001];
lli inf = 99999999999999999;

vector<lli> val;
int main() {
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    lli n;
    scanint(n);
    vector< pair<lli , lli> > v;
    lli i = 0;
    lli j = 0;
    for(i = 0;i<=n;i++)
    {
        for(j = 0;j<=n;j++)
        {
            if(j == 0)
                dp[i][j] = 0;
            else
                dp[i][j] = inf;
        }
    }
    for(i = 0;i<n;i++)
    {
        lli c,t;
        scanint(t);
        scanint(c);
        v.push_back(make_pair(t+1,c));
    }
    sort(v.begin(),v.end(),compare);
    /*cout<<"--------------------------------"<<endl;
    for(i = 0;i<n;i++)
    {
        cout<<v[i].first<<" " <<v[i].second<<endl;
    }*/
    for(i = 0;i<v.size();i++)
    {
        lli time = v[i].first;
        lli cost = v[i].second;
        for(j = 1;j<=n;j++)
        {
            if(j - time <= 0)
            {
                dp[i+1][j] = min(dp[i][0] + cost,dp[i][j]);
            }
            else
                dp[i+1][j] = min(dp[i][j-time]+cost,dp[i][j]);
        }
    }
    cout<<dp[n][n]<<endl;
 	return 0;
}
/*
5
2 10
2 12
0 20
1 5
1 3
*/

void scanint(unsigned long long int &x)
{
    register int c = gc();
    x = 0;
    int neg = 0;
    for(;((c<48 || c>57) && c != '-');c = gc());
    if(c=='-') {neg=1;c=gc();}
    for(;c>47 && c<58;c = gc()) {x = (x<<1) + (x<<3) + c - 48;}
    if(neg) x=-x;
}


#include <iostream>
#include<stdio.h>
#include<climits>
#include<stdlib.h>
#include<algorithm>
#include<cstring>
#include<map>
#include<vector>
#include<cstdio>
#include<cstring>
#define gc getchar
#define lli long long int
using namespace std;
void scanint(long long int &x);
bool compare(const pair<lli,lli> &a, const pair<lli,lli> &b)
{
    if(a.first < b.first)
        return true;
    else if(a.first == b.first)
        return a.second>b.second;
    else    return false;
}

lli dp[2001][2001];
lli inf = 999999999*2001;

vector<lli> val;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    lli n;
    scanint(n);
    vector< pair<lli , lli> > v;
    lli i = 0;
    lli j = 0;
    for(i = 0;i<=n;i++)
    {
        for(j = 0;j<=n;j++)
        {
            if(j == 0)
                dp[i][j] = 0;
            else
                dp[i][j] = inf;
        }
    }
    for(i = 0;i<n;i++)
    {
        lli c,t;
        scanint(t);
        scanint(c);
        v.push_back(make_pair(t+1,c));
    }
    sort(v.begin(),v.end(),compare);
    /*cout<<"--------------------------------"<<endl;
    for(i = 0;i<n;i++)
    {
        cout<<v[i].first<<" " <<v[i].second<<endl;
    }*/
    for(i = 0;i<v.size();i++)
    {
        lli time = v[i].first;
        lli cost = v[i].second;
        for(j = 1;j<=n;j++)
        {
            if(j - time <= 0)
            {
                dp[i+1][j] = min(dp[i][0] + cost,dp[i][j]);
            }
            else
                dp[i+1][j] = min(dp[i][j-time]+cost,dp[i][j]);
        }
    }
    cout<<dp[n][n]<<endl;
 	return 0;
}
/*
5
2 10
2 12
0 20
1 5
1 3
*/

void scanint(long long int &x)
{
    register int c = gc();
    x = 0;
    int neg = 0;
    for(;((c<48 || c>57) && c != '-');c = gc());
    if(c=='-') {neg=1;c=gc();}
    for(;c>47 && c<58;c = gc()) {x = (x<<1) + (x<<3) + c - 48;}
    if(neg) x=-x;
}


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

int n;
int c[2010],t[2010];
long long dp[2010];

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d%d",&t[i],&c[i]);
	for(int i=0;i<=n;i++) dp[i]=1e18;
	dp[0]=0;

	long long ans=1e18;

	for(int i=1;i<=n;i++){
		for(int j=n;j>=1;j--){
			dp[j]=min(dp[j],dp[max(j-t[i]-1,0)]+c[i]);
		//	cout<<dp[j]<<" ";
		}
		//cout<<endl;
	}

	cout<<dp[n];

	return 0;
}


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

int n;
int c[2010],t[2010];
long long dp[2010];

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d%d",&t[i],&c[i]);
	for(int i=0;i<=n;i++) dp[i]=1e18;
	dp[0]=0;

	long long ans=1e18;

	for(int i=1;i<=n;i++){
		for(int j=n;j>=1;j--){
			dp[j]=min(dp[j],dp[max(j-t[i]-1,0)]+c[j]);
		//	cout<<dp[j]<<" ";
		}
		//cout<<endl;
	}

	cout<<dp[n];

	return 0;
}


#include<iostream>
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
#define int long long int
void fun()
{
#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
   freopen("output.txt", "w", stdout);
#endif
}
int __gcd(int a, int b)
{
	if(b==0)
		return a;
	return __gcd(b, a%b);
}
int n;
int t[2001];
int c[2001];
int dp[2001][2003];
int off=2001;
int solve(int idx, int time)
{
	if(idx==n+1)
	{
		if(time<off)
		{
			return INT_MAX;
		}
		return 0;
	}
	if(dp[idx][time]!=-1)
	{
		return dp[idx][time];
	}
	int ans=min(c[idx]+solve(idx+1, min(time+t[idx], 2*off-1)), solve(idx+1, time-1));
	dp[idx][time]=ans;
	return ans;
}
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	fun();
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>t[i]>>c[i];
	}
	memset(dp, -1, sizeof(dp));
	cout<<solve(1, off)<<"\n";

}


#include<iostream>
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
#define int long long int
void fun()
{
#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
   freopen("output.txt", "w", stdout);
#endif
}
int __gcd(int a, int b)
{
	if(b==0)
		return a;
	return __gcd(b, a%b);
}
int n;
int t[2001];
int c[2001];
const int off=2e3+5;
int dp[off][2*off+1];

int solve(int idx, int time)
{
	if(idx==n+1)
	{
		if(time<off)
		{
			return 1e13;
		}
		return 0;
	}
	if(dp[idx][time]!=-1)
	{
		return dp[idx][time];
	}
	int ans=min(c[idx]+solve(idx+1, min(time+t[idx], 2*off-1)), solve(idx+1, time-1));
	dp[idx][time]=ans;
	return ans;
}
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	fun();
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>t[i]>>c[i];
	}
	memset(dp, -1, sizeof(dp));
	cout<<solve(1, off)<<"\n";

}


#include<iostream>
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
#define int long long int
void fun()
{
#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
   freopen("output.txt", "w", stdout);
#endif
}
int __gcd(int a, int b)
{
	if(b==0)
		return a;
	return __gcd(b, a%b);
}
int n;
int t[2001];
int c[2001];
int dp[2001][4010];
int off=2001;
int solve(int idx, int time)
{
	if(idx==n+1)
	{
		if(time<off)
		{
			return INT_MAX;
		}
		return 0;
	}
	if(dp[idx][time]!=-1)
	{
		return dp[idx][time];
	}
	int ans=min(c[idx]+solve(idx+1, min(time+t[idx], 2*off-1)), solve(idx+1, time-1));
	dp[idx][time]=ans;
	return ans;
}
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	fun();
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>t[i]>>c[i];
	}
	memset(dp, -1, sizeof(dp));
	cout<<solve(1, off)<<"\n";

}


#include<iostream>
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
#define int long long int
void fun()
{
#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
   freopen("output.txt", "w", stdout);
#endif
}
int __gcd(int a, int b)
{
	if(b==0)
		return a;
	return __gcd(b, a%b);
}
int n;
int t[2001];
int c[2001];
int dp[2001][2002];
int off=2001;
int solve(int idx, int time)
{
	if(idx==n+1)
	{
		if(time<off)
		{
			return INT_MAX;
		}
		return 0;
	}
	if(dp[idx][time]!=-1)
	{
		return dp[idx][time];
	}
	int ans=min(c[idx]+solve(idx+1, min(time+t[idx], 2001ll)), solve(idx+1, time-1));
	dp[idx][time]=ans;
	return ans;
}
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	fun();
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>t[i]>>c[i];
	}
	memset(dp, -1, sizeof(dp));
	cout<<solve(1, off)<<"\n";

}


#include<iostream>
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
#define int long long int
void fun()
{
#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
   freopen("output.txt", "w", stdout);
#endif
}
int __gcd(int a, int b)
{
	if(b==0)
		return a;
	return __gcd(b, a%b);
}
int n;
int t[2001];
int c[2001];
int dp[2001][2*2002];
int off=2001;
int solve(int idx, int time)
{
	if(idx==n+1)
	{
		if(time<off)
		{
			return 1e13;
		}
		return 0;
	}
	if(dp[idx][time]!=-1)
	{
		return dp[idx][time];
	}
	int ans=min(c[idx]+solve(idx+1, min(time+t[idx], 2*off-1)), solve(idx+1, time-1));
	dp[idx][time]=ans;
	return ans;
}
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	fun();
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>t[i]>>c[i];
	}
	memset(dp, -1, sizeof(dp));
	cout<<solve(1, off)<<"\n";

}


#include<iostream>
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
#define int long long int
void fun()
{
#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
   freopen("output.txt", "w", stdout);
#endif
}
int __gcd(int a, int b)
{
	if(b==0)
		return a;
	return __gcd(b, a%b);
}
int n;
int t[2001];
int c[2001];
int dp[2001][2003];
int off=2001;
int solve(int idx, int time)
{
	if(idx==n+1)
	{
		if(time<off)
		{
			return INT_MAX;
		}
		return 0;
	}
	if(dp[idx][time]!=-1)
	{
		return dp[idx][time];
	}
	int ans=min(c[idx]+solve(idx+1, min(time+t[idx], off)), solve(idx+1, time-1));
	dp[idx][time]=ans;
	return ans;
}
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	fun();
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>t[i]>>c[i];
	}
	memset(dp, -1, sizeof(dp));
	cout<<solve(1, off)<<"\n";

}


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

    #define sz(x) ((int) (x).size())

    double pi = 3.1415926536;
    const int oo = (int)1e9;

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

    int arr[101][101];

    int main() {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        //freopen("input.txt","r",stdin);
        //freopen("output.txt","w",stdout);

        int n ;
        cin >> n ;
        vector<int>accum(n);
        bool check = true , flag = true , have = true;

        int idx1 = -1 , idx2 = -1;

        for(int i = 0 ; i < n ; i ++){
            cin >> accum[i];
        }

        for(int i = 0 ; i < n ;  i++){

            if(i > 0 && accum[i] < accum[i-1] && check){
                idx1=i - 1;
                check = false;
            }

            else if(i > 0 && accum[i] > accum[i-1] && have){
                idx2 = i;
                accum[i - 1]=accum[idx1];
                i--;

                have = false;
            }

            else if(i > 0 && accum[i] < accum[i-1] && !have){
                flag=false;
            }

        }

        if(flag && idx2==-1)idx2=n;

        if(!flag){
            cout << "no";
            return 0;
        }

        if(idx1==-1){
            cout << "yes" << endl;
            cout << 1 << " " << 1 ;
            return 0;
        }
        cout << "yes" << endl;
        cout << idx1+1  << " " << idx2  << endl;

    }


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

    #define sz(x) ((int) (x).size())

    double pi = 3.1415926536;
    const int oo = (int)1e9;

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

    int arr[101][101];

    int main() {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        //freopen("input.txt","r",stdin);
        //freopen("output.txt","w",stdout);

        int n ;
        cin >> n ;
        vector<int>accum(n);
        bool check = true , flag = true , have = true;

        int idx1 = -1 , idx2 = -1;

        for(int i = 0 ; i < n ; i ++){
            cin >> accum[i];
        }

        for(int i = 0 ; i < n ;  i++){

            if(i > 0 && accum[i] < accum[i-1] && check){
                idx1=i -1;
                check = false;
            }

            else if(i > 0 && accum[i] > accum[i-1] && have && !check){
                idx2 = i;
                accum[i - 1]=accum[idx1];
                i--;

                have = false;
            }

            else if(i > 0 && accum[i] < accum[i-1] && !have){
                flag=false;
            }

        }

        if(flag && idx2==-1)idx2=n;

        if(!flag){
            cout << "no";
            return 0;
        }

        if(idx1==-1){
            cout << "yes" << endl;
            cout << 1 << " " << 1 ;
            return 0;
        }
        cout << "yes" << endl;
        cout << idx1+1  << " " << idx2  << endl;

    }


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

    #define sz(x) ((int) (x).size())

    double pi = 3.1415926536;
    const int oo = (int)1e9;

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

    int arr[101][101];

    int main() {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        //freopen("input.txt","r",stdin);
        //freopen("output.txt","w",stdout);

        int n ;
        cin >> n ;
        vector<int>accum(n);
        bool check = true , flag = true , have = true;

        int idx1 = -1 , idx2 = -1;

        for(int i = 0 ; i < n ; i ++){
            cin >> accum[i];
        }

        for(int i = 0 ; i < n ;  i++){

            if(i > 0 && accum[i] < accum[i-1] && check){
                idx1=i -1;
                check = false;
            }

            else if(i > 0 && accum[i] > accum[i-1] && have && !check){
                idx2 = i;
                accum[i - 1]=accum[idx1];
                i--;

                have = false;
            }

            else if(i > 0 && accum[i] < accum[i-1] && !have){
                flag=false;
            }

        }

        if(flag && idx2==-1){
        idx2=n;

        if(idx1!=0)
        if(accum[idx1-1] > accum[idx2-1])flag = false;
        }

        else if(flag && accum[idx1-1] > accum[idx2])flag = false;

        if(!flag){
            cout << "no";
            return 0;
        }

        if(idx1==-1){
            cout << "yes" << endl;
            cout << 1 << " " << 1 ;
            return 0;
        }
        cout << "yes" << endl;
        cout << idx1+1  << " " << idx2  << endl;

    }


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

    #define sz(x) ((int) (x).size())

    double pi = 3.1415926536;
    const int oo = (int)1e9;

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

    int arr[101][101];

    int main() {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        //freopen("input.txt","r",stdin);
        //freopen("output.txt","w",stdout);

        int n ;
        cin >> n ;
        vector<int>accum(n);
        bool check = true , flag = true , have = true;

        int idx1 = -1 , idx2 = -1;

        for(int i = 0 ; i < n ; i ++){
            cin >> accum[i];
        }

        for(int i = 0 ; i < n ;  i++){

            if(i > 0 && accum[i] < accum[i-1] && check){
                idx1=i -1;
                check = false;
            }

            else if(i > 0 && accum[i] > accum[i-1] && have && !check){
                idx2 = i;
                accum[i - 1]=accum[idx1];
                i--;

                have = false;
            }

            else if(i > 0 && accum[i] < accum[i-1] && !have){
                flag=false;
            }

        }

        if(flag && idx2==-1){
        idx2=n;

        if(idx1!=0 && idx1 != -1)
        if(accum[idx1-1] > accum[idx2-1])flag = false;
        }

        else if(idx1 > 0 && accum[idx1-1] > accum[idx2])flag = false;

        if(!flag){
            cout << "no";
            return 0;
        }

        if(idx1==-1){
            cout << "yes" << endl;
            cout << 1 << " " << 1 ;
            return 0;
        }
        cout << "yes" << endl;
        cout << idx1+1  << " " << idx2  << endl;

    }


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

    #define sz(x) ((int) (x).size())

    double pi = 3.1415926536;
    const int oo = (int)1e9;

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

    int arr[101][101];

    int main() {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        //freopen("input.txt","r",stdin);
        //freopen("output.txt","w",stdout);

        int n ;
        cin >> n ;
        vector<int>accum(n);
        bool check = true , flag = true , have = true;

        int idx1 = -1 , idx2 = -1;

        for(int i = 0 ; i < n ; i ++){
            cin >> accum[i];
        }

        for(int i = 0 ; i < n ;  i++){

            if(i > 0 && accum[i] < accum[i-1] && check){
                idx1=i -1;
                check = false;
            }

            else if(i > 0 && accum[i] > accum[i-1] && have && !check){
                idx2 = i;
                accum[i - 1]=accum[idx1];
                i--;

                have = false;
            }

            else if(i > 0 && accum[i] < accum[i-1] && !have){
                flag=false;
            }

        }

        if(flag && idx2==-1)idx2=n;

        if(idx1 > 0)
                if(accum[idx1-1] > accum[idx2])flag = false;

        if(!flag){
            cout << "no";
            return 0;
        }

        if(idx1==-1){
            cout << "yes" << endl;
            cout << 1 << " " << 1 ;
            return 0;
        }
        cout << "yes" << endl;
        cout << idx1+1  << " " << idx2  << endl;

    }


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

    #define sz(x) ((int) (x).size())

    double pi = 3.1415926536;
    const int oo = (int)1e9;

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

    int arr[101][101];

    int main() {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        //freopen("input.txt","r",stdin);
        //freopen("output.txt","w",stdout);

        int n ;
        cin >> n ;
        vector<int>accum(n);
        bool check = true , flag = true , have = true;

        int idx1 = -1 , idx2 = -1;

        for(int i = 0 ; i < n ; i ++){
            cin >> accum[i];
        }

        for(int i = 0 ; i < n ;  i++){

            if(i > 0 && accum[i] < accum[i-1] && check){
                idx1=i -1;
                check = false;
            }

            else if(i > 0 && accum[i] > accum[i-1] && have && !check){
                idx2 = i;
                accum[i - 1]=accum[idx1];
                i--;

                have = false;
            }

            else if(i > 0 && accum[i] < accum[i-1] && !have){
                flag=false;
            }

        }

        if(flag && idx2==-1){
        idx2=n;

        if(idx1!=0)
        if(accum[idx1-1] > accum[idx2-1])flag = false;
        }

        else if(idx1 > 0 && accum[idx1-1] > accum[idx2])flag = false;

        if(!flag){
            cout << "no";
            return 0;
        }

        if(idx1==-1){
            cout << "yes" << endl;
            cout << 1 << " " << 1 ;
            return 0;
        }
        cout << "yes" << endl;
        cout << idx1+1  << " " << idx2  << endl;

    }


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

#define sz(x) ((int) (x).size())

double pi = 3.1415926536;
const int oo = (int)1e9;

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

int arr[100001];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);

    int n ;
    cin >> n ;

   vector<int>myvec(n);
   int num1 = -1 , num2 = -1;
   bool check = false;

   for(int i = 0 ; i < n ; i++){
       cin >> myvec[i];
   }

   if(n==1){
        cout << "yes" << endl;
        cout << 1 << " " << 1;
        return 0;
       }

   int idx = -1;

   for(int i = 0 ; i < n-1 ; i++){

       if(myvec[i] > myvec [i+1] && num1 == -1){
           num1 = myvec[i];
           idx = i + 1;
       }

       else if(myvec[i] < myvec[i+1] && num2 == -1 && idx != -1){
           num2 = i + 1;
           int temp = myvec[i];
           myvec[i] = num1;
           myvec[idx -1] = temp;
       }

       if(i+1 == n - 1 && idx != -1 && num2 == -1){
          int temp = myvec[idx - 1];
           myvec[idx - 1] = myvec[i + 1];
           myvec[i + 1] = temp;
       }
   }

   for(int i = 0 ; i < n ; i++){
       if(myvec[i] != i +1)check = true;
   }

   if(check){
       cout << "no";
       return 0;
   }

   cout << "yes" << endl;

   if(idx == -1){
       cout << 1 << " " << 1;
       return 0;
   }

   if(num2 == -1){
       cout << idx << " " << n;
       return 0;
   }

   cout << idx << " " << num2;
}


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

    #define sz(x) ((int) (x).size())

    double pi = 3.1415926536;
    const int oo = (int)1e9;

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

    int arr[101][101];

    int main() {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        //freopen("input.txt","r",stdin);
        //freopen("output.txt","w",stdout);

        int n ;
        cin >> n ;
        vector<int>accum(n);
        bool check = true , flag = true , have = true;

        int idx1 = -1 , idx2 = -1;

        for(int i = 0 ; i < n ; i ++){
            cin >> accum[i];
        }

        for(int i = 0 ; i < n ;  i++){

            if(i > 0 && accum[i] < accum[i-1] && check){
                idx1=i -1;
                check = false;
            }

            else if(i > 0 && accum[i] > accum[i-1] && have && !check){
                idx2 = i;
                accum[i - 1]=accum[idx1];
                i--;

                have = false;
            }

            else if(i > 0 && accum[i] < accum[i-1] && !have){
                flag=false;
            }

        }

        if(flag && idx2==-1){idx2=n;

        if(accum[idx1-1] > accum[idx2-1])flag = false;
        }

        else if(accum[idx1-1] > accum[idx2])flag = false;

        if(!flag){
            cout << "no";
            return 0;
        }

        if(idx1==-1){
            cout << "yes" << endl;
            cout << 1 << " " << 1 ;
            return 0;
        }
        cout << "yes" << endl;
        cout << idx1+1  << " " << idx2  << endl;

    }


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

    #define sz(x) ((int) (x).size())

    double pi = 3.1415926536;
    const int oo = (int)1e9;

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

    int arr[101][101];

    int main() {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        //freopen("input.txt","r",stdin);
        //freopen("output.txt","w",stdout);

        int n ;
        cin >> n ;
        vector<int>accum(n);
        bool check = true , flag = true , have = true;

        int idx1 = -1 , idx2 = -1;

        for(int i = 0 ; i < n ; i ++){
            cin >> accum[i];
        }

        for(int i = 0 ; i < n ;  i++){

            if(i > 0 && accum[i] < accum[i-1] && check){
                idx1=i -1;
                check = false;
            }

            else if(i > 0 && accum[i] > accum[i-1] && have && !check){
                idx2 = i;
                accum[i - 1]=accum[idx1];
                i--;

                have = false;
            }

            else if(i > 0 && accum[i] < accum[i-1] && !have){
                flag=false;
            }

        }

        if(flag && idx2==-1){idx2=n;

        if(accum[idx1-1] > accum[idx2-1])flag = false;
        }

        else if(accum[idx1-1] > accum[idx2-1])flag = false;

        if(!flag){
            cout << "no";
            return 0;
        }

        if(idx1==-1){
            cout << "yes" << endl;
            cout << 1 << " " << 1 ;
            return 0;
        }
        cout << "yes" << endl;
        cout << idx1+1  << " " << idx2  << endl;

    }


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

#define sz(x) ((int) (x).size())

double pi = 3.1415926536;
const int oo = (int)1e9;

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

int arr[100001];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);

    int n ;
    cin >> n ;

   vector<int>myvec(n);
   int num1 = -1 , num2 = -1 , idx1 , idx2;
   bool check = false;

   for(int i = 0 ; i < n ; i++)
       cin >> myvec[i];

   for(int i = 0 ; i < n ; i++){

       if(myvec[i] != i +1 && num1 == -1)num1 = myvec[i] , idx1 = i , check = true;

       else if(myvec[i] != i +1 && num2 == -1)num2 = myvec[i] , idx2 = i;
   }

   if(!check){
       cout << "yes" << endl;
       cout << 1 << " " << 1;
       return 0;
   }

   myvec[idx1] = num2;
   myvec[idx2] = num1;

   for(int i = 0 ; i < n ; i ++){
       if(myvec[i] != i +1){
           cout << "no";
           return 0;
       }
   }

   cout << "yes" << endl;
   cout << min(num1,num2) << " " << max(num1,num2);
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n;
    scanf("%d",&n);
    int arr[n];
    int i;
    for(i = 0;i < n;i++)
        scanf("%d",&arr[i]);
    int min = arr[0];
    int max = arr[0];
    for(i = 0;i < n;i++)
    {
        if (arr[i] < min)
            min = arr[i];
        if (arr[i] > max)
            max = arr[i];
    }
    int flag;
    int si,ei,ci;
    si = ei = 1,ci = 0;
    if(min == arr[n-1] && max == arr[0])
    {
        ei = n;
        for(i = 1;i < n;i++)
        {
            if (!(arr[i] < arr[i-1]))
            {
                ci++;
            }
        }
    }
    else if(min == arr[0])
    {
        flag = 1;
        for(i = 1;i < n;i++)
        {
            if(flag)
            {
                if (!(arr[i] > arr[i-1]))
                {
                    si = i;
                    flag = 0;
                }
            }
            else
            {
                if (!(arr[i] < arr[i-1]))
                {
                    ei = i;
                    flag = 1;
                    i++;
                    ci++;
                    if(ei == n && arr[ei - 1] == max)
                        ci++;
                    else if(!(arr[ei] > arr[si-1] && arr[si-2] < arr[ei-1]))
                        ci++;
                }
            }
        }
        if (si != 1 && ei == 1)
            ei = n;
    }
    else
    {
        flag = 1;
        for(i = 1;i < n;i++)
        {
            if(flag)
            {
                if (!(arr[i] < arr[i-1]))
                {
                    flag = 0;
                    ci++;
                    ei = i;
                    i++;
                    if(!(arr[ei] > arr[0]))
                        ci++;
                }
            }
            else
            {
                if (!(arr[i] > arr[i-1]))
                {
                    ci++;
                }
            }
        }
    }
    if(ci <= 1)
    {
        printf("yes\n%d %d",si,ei);
    }
    else
        printf("no");
    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n;
    scanf("%d",&n);
    int arr[n];
    int i;
    for(i = 0;i < n;i++)
        scanf("%d",&arr[i]);
    int min = arr[0];
    int max = arr[0];
    for(i = 0;i < n;i++)
    {
        if (arr[i] < min)
            min = arr[i];
        if (arr[i] > max)
            max = arr[i];
    }
    int flag;
    int si,ei,ci;
    si = ei = 1,ci = 0;
    if(min == arr[n-1] && max == arr[0])
    {
        ei = n;
        for(i = 1;i < n;i++)
        {
            if (!(arr[i] < arr[i-1]))
            {
                ci++;
            }
        }
    }
    else if(min == arr[0])
    {
        flag = 1;
        for(i = 1;i < n;i++)
        {
            if(flag)
            {
                if (!(arr[i] > arr[i-1]))
                {
                    si = i + 1;
                    flag = 0;
                }
            }
            else
            {
                if (!(arr[i] < arr[i-1]))
                {
                    ei = i;
                    flag = 1;
                    i++;
                    ci++;
                }
                if(!(arr[ei+1] > arr[si-1] && arr[si-2] < arr[ei]))
                    ci++;
            }
        }
    }
    else
    {
        flag = 1;
        for(i = 1;i < n;i++)
        {
            if(flag)
            {
                if (!(arr[i] < arr[i-1]))
                {
                    flag = 0;
                    ci++;
                    ei = i;
                    i++;
                    if(!(arr[ei] > arr[0]))
                        ci++;
                }
            }
            else
            {
                if (!(arr[i] > arr[i-1]))
                {
                    ci++;
                }
            }
        }
    }
    if(ci <= 1)
    {
        printf("yes\n%d %d",si,ei);
    }
    else
        printf("no");
    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n;
    scanf("%d",&n);
    int arr[n];
    int i;
    for(i = 0;i < n;i++)
        scanf("%d",&arr[i]);
    int min = arr[0];
    int max = arr[0];
    for(i = 0;i < n;i++)
    {
        if (arr[i] < min)
            min = arr[i];
        if (arr[i] > max)
            max = arr[i];
    }
    int flag;
    int si,ei,ci;
    si = ei = 1,ci = 0;
    if(min == arr[n-1] && max == arr[0])
    {
        ei = n;
        for(i = 1;i < n;i++)
        {
            if (!(arr[i] < arr[i-1]))
            {
                ci++;
            }
        }
    }
    else if(min == arr[0])
    {
        flag = 1;
        for(i = 1;i < n;i++)
        {
            if(flag)
            {
                if (!(arr[i] > arr[i-1]))
                {
                    si = i;
                    flag = 0;
                }
            }
            else
            {
                if (!(arr[i] < arr[i-1]))
                {
                    ei = i;
                    flag = 1;
                    i++;
                    ci++;
                    if(!(arr[ei+1] > arr[si-1] && arr[si-2] < arr[ei]))
                        ci++;
                }
            }
        }
    }
    else
    {
        flag = 1;
        for(i = 1;i < n;i++)
        {
            if(flag)
            {
                if (!(arr[i] < arr[i-1]))
                {
                    flag = 0;
                    ci++;
                    ei = i;
                    i++;
                    if(!(arr[ei] > arr[0]))
                        ci++;
                }
            }
            else
            {
                if (!(arr[i] > arr[i-1]))
                {
                    ci++;
                }
            }
        }
    }
    if(ci <= 1)
    {
        printf("yes\n%d %d",si,ei);
    }
    else
        printf("no");
    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n;
    scanf("%d",&n);
    int arr[n];
    int i;
    for(i = 0;i < n;i++)
        scanf("%d",&arr[i]);
    int min = arr[0];
    int max = arr[0];
    for(i = 0;i < n;i++)
    {
        if (arr[i] < min)
            min = arr[i];
        if (arr[i] > max)
            max = arr[i];
    }
    int flag;
    int si,ei,ci;
    si = ei = 1,ci = 0;
    if(min == arr[n-1] && max == arr[0])
    {
        ei = n;
        for(i = 1;i < n;i++)
        {
            if (!(arr[i] < arr[i-1]))
            {
                ci++;
            }
        }
    }
    else if(min == arr[0])
    {
        flag = 1;
        for(i = 1;i < n;i++)
        {
            if(flag)
            {
                if (!(arr[i] > arr[i-1]))
                {
                    si = i;
                    flag = 0;
                }
            }
            else
            {
                if (!(arr[i] < arr[i-1]))
                {
                    ei = i;
                    flag = 1;
                    i++;
                    ci++;
                    if(ei == n && arr[ei - 1] == max)
                        ci++;
                    else if(!(arr[ei] > arr[si-1] && arr[si-2] < arr[ei-1]))
                        ci++;
                }
            }
        }
        if (si != 1 && ei == 1)
            ei = n;
    }
    else
    {
        flag = 1;
        for(i = 1;i < n;i++)
        {
            if(flag)
            {
                if (!(arr[i] < arr[i-1]))
                {
                    flag = 0;
                    ci++;
                    ei = i;
                    i++;
                    if(!(arr[ei] > arr[0]) || si == ei)
                        ci++;
                }
            }
            else
            {
                if (!(arr[i] > arr[i-1]))
                {
                    ci++;
                }
            }
        }
    }
    if(ci <= 1)
    {
        printf("yes\n%d %d",si,ei);
    }
    else
        printf("no");
    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n;
    scanf("%d",&n);
    int arr[n];
    int i;
    for(i = 0;i < n;i++)
        scanf("%d",&arr[i]);
    int min = arr[0];
    int max = arr[0];
    for(i = 0;i < n;i++)
    {
        if (arr[i] < min)
            min = arr[i];
        if (arr[i] > max)
            max = arr[i];
    }
    int flag;
    int si,ei,ci;
    si = ei = 1,ci = 0;
    if(min == arr[n-1] && max == arr[0])
    {
        ei = n;
        for(i = 1;i < n;i++)
        {
            if (!(arr[i] < arr[i-1]))
            {
                ci++;
            }
        }
    }
    else if(min == arr[0])
    {
        flag = 1;
        for(i = 1;i < n;i++)
        {
            if(flag)
            {
                if (!(arr[i] > arr[i-1]))
                {
                    si = i;
                    flag = 0;
                }
            }
            else
            {
                if (!(arr[i] < arr[i-1]))
                {
                    ei = i;
                    flag = 1;
                    i++;
                    ci++;
                    if(ei == n && arr[ei - 1] == max)
                        ci++;
                    else if(!(arr[ei] > arr[si-1] && arr[si-2] < arr[ei-1]))
                        ci++;
                }
            }
        }
        if (si != 1 && ei == 1)
            ei = n;
    }
    else
    {
        flag = 1;
        for(i = 1;i < n;i++)
        {
            if(flag)
            {
                if (!(arr[i] < arr[i-1]))
                {
                    flag = 0;
                    ci++;
                    ei = i;
                    //i++;
                    if(!(arr[ei] > arr[0]) || si == ei)
                        ci++;
                }
            }
            else
            {
                if (!(arr[i] > arr[i-1]))
                {
                    ci++;
                }
            }
        }
    }
    if(ci <= 1)
    {
        printf("yes\n%d %d",si,ei);
    }
    else
        printf("no");
    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n;
    scanf("%d",&n);
    int arr[n];
    int i;
    for(i = 0;i < n;i++)
        scanf("%d",&arr[i]);
    int min = arr[0];
    int max = arr[0];
    for(i = 0;i < n;i++)
    {
        if (arr[i] < min)
            min = arr[i];
        if (arr[i] > max)
            max = arr[i];
    }
    int flag;
    int si,ei,ci;
    si = ei = 1,ci = 0;
    if(min == arr[n-1] && max == arr[0])
    {
        ei = n;
        for(i = 1;i < n;i++)
        {
            if (!(arr[i] < arr[i-1]))
            {
                ci++;
            }
        }
    }
    else if(min == arr[0])
    {
        flag = 1;
        for(i = 1;i < n;i++)
        {
            if(flag)
            {
                if (!(arr[i] > arr[i-1]))
                {
                    si = i;
                    flag = 0;
                }
            }
            else
            {
                if (!(arr[i] < arr[i-1]))
                {
                    ei = i;
                    flag = 1;
                    i++;
                    ci++;
                    if(ei == n && arr[ei - 1] == max)
                        ci++;
                    else if(!(arr[ei] > arr[si-1] && arr[si-2] < arr[ei-1]))
                        ci++;
                }
            }
        }
    }
    else
    {
        flag = 1;
        for(i = 1;i < n;i++)
        {
            if(flag)
            {
                if (!(arr[i] < arr[i-1]))
                {
                    flag = 0;
                    ci++;
                    ei = i;
                    i++;
                    if(!(arr[ei] > arr[0]))
                        ci++;
                }
            }
            else
            {
                if (!(arr[i] > arr[i-1]))
                {
                    ci++;
                }
            }
        }
    }
    if(ci <= 1)
    {
        printf("yes\n%d %d",si,ei);
    }
    else
        printf("no");
    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n;
    scanf("%d",&n);
    int arr[n];
    int i;
    for(i = 0;i < n;i++)
        scanf("%d",&arr[i]);
    int min = arr[0];
    int max = arr[0];
    for(i = 0;i < n;i++)
    {
        if (arr[i] < min)
            min = arr[i];
        if (arr[i] > max)
            max = arr[i];
    }
    int flag;
    int si,ei,ci;
    si = ei = 1,ci = 0;
    if(min == arr[n-1] && max == arr[0])
    {
        ei = n;
        for(i = 1;i < n;i++)
        {
            if (!(arr[i] < arr[i-1]))
            {
                ci++;
            }
        }
    }
    else if(min == arr[0])
    {
        flag = 1;
        for(i = 1;i < n;i++)
        {
            if(flag)
            {
                if (!(arr[i] > arr[i-1]))
                {
                    si = i;
                    flag = 0;
                }
            }
            else
            {
                if (!(arr[i] < arr[i-1]))
                {
                    ei = i;
                    flag = 1;
                    i++;
                    ci++;
                }
                if(!(arr[ei+1] > arr[si-1] && arr[si-2] < arr[ei]))
                    ci++;
            }
        }
    }
    else
    {
        flag = 1;
        for(i = 1;i < n;i++)
        {
            if(flag)
            {
                if (!(arr[i] < arr[i-1]))
                {
                    flag = 0;
                    ci++;
                    ei = i;
                    i++;
                    if(!(arr[ei] > arr[0]))
                        ci++;
                }
            }
            else
            {
                if (!(arr[i] > arr[i-1]))
                {
                    ci++;
                }
            }
        }
    }
    if(ci <= 1)
    {
        printf("yes\n%d %d",si,ei);
    }
    else
        printf("no");
    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n;
    scanf("%d",&n);
    int arr[n];
    int i;
    for(i = 0;i < n;i++)
        scanf("%d",&arr[i]);
    int min = arr[0];
    int max = arr[0];
    for(i = 0;i < n;i++)
    {
        if (arr[i] < min)
            min = arr[i];
        if (arr[i] > max)
            max = arr[i];
    }
    int flag;
    int si,ei,ci;
    si = ei = 1,ci = 0;
    if(min == arr[n-1] && max == arr[0])
    {
        ei = n;
        for(i = 1;i < n;i++)
        {
            if (!(arr[i] < arr[i-1]))
            {
                ci++;
            }
        }
    }
    else if(min == arr[0])
    {
        flag = 1;
        for(i = 1;i < n;i++)
        {
            if(flag)
            {
                if (!(arr[i] > arr[i-1]))
                {
                    si = i;
                    flag = 0;
                }
            }
            else
            {
                if (!(arr[i] < arr[i-1]))
                {
                    ei = i;
                    flag = 1;
                    i++;
                    ci++;
                    if(ei == n && arr[ei - 1] == max)
                        ci++;
                    else if(!(arr[ei] > arr[si-1] && arr[si-2] < arr[ei-1]))
                        ci++;
                }
            }
        }
        if (si != 1 && ei == 1)
            ei = n;
    }
    else
    {
        flag = 1;
        for(i = 1;i < n;i++)
        {
            if(flag)
            {
                if (!(arr[i] < arr[i-1]))
                {
                    flag = 0;
                    ci++;
                    ei = i;
                    i++;
                    if((arr[ei] > arr[0]))
                        ci++;
                }
            }
            else
            {
                if (!(arr[i] > arr[i-1]))
                {
                    ci++;
                }
            }
        }
    }
    if(ci <= 1)
    {
        printf("yes\n%d %d",si,ei);
    }
    else
        printf("no");
    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n;
    scanf("%d",&n);
    int arr[n];
    int i;
    for(i = 0;i < n;i++)
        scanf("%d",&arr[i]);
    int min = arr[0];
    int max = arr[0];
    for(i = 0;i < n;i++)
    {
        if (arr[i] < min)
            min = arr[i];
        if (arr[i] > max)
            max = arr[i];
    }
    int flag;
    int si,ei,ci;
    si = ei = 1,ci = 0;
    if(min == arr[n-1] && max == arr[0])
    {
        ei = n;
        for(i = 1;i < n;i++)
        {
            if (!(arr[i] < arr[i-1]))
            {
                ci++;
            }
        }
    }
    else if(min == arr[0])
    {
        flag = 1;
        for(i = 1;i < n;i++)
        {
            if(flag)
            {
                if (!(arr[i] > arr[i-1]))
                {
                    si = i;
                    flag = 0;
                }
            }
            else
            {
                if (!(arr[i] < arr[i-1]))
                {
                    ei = i;
                    flag = 1;
                    i++;
                    ci++;
                    if(ei == n && arr[ei - 1] == max)
                        ci++;
                    else if(!(arr[ei] > arr[si-1] && arr[si-2] < arr[ei-1]))
                        ci++;
                }
            }
        }
        if (si != 1 && ei == 1)
            ei = n;
    }
    else
    {
        flag = 1;
        for(i = 1;i < n;i++)
        {
            if(flag)
            {
                if (!(arr[i] < arr[i-1]))
                {
                    flag = 0;
                    ci++;
                    ei = i;
                    i++;
                    if(!(arr[ei] > arr[0] || si == ei))
                        ci++;
                }
            }
            else
            {
                if (!(arr[i] > arr[i-1]))
                {
                    ci++;
                }
            }
        }
    }
    if(ci <= 1)
    {
        printf("yes\n%d %d",si,ei);
    }
    else
        printf("no");
    return 0;
}


#include<bits/stdc++.h>
#define int long long int

using namespace std;

main()
{
int n;
cin>>n;
vector<int> a(n);
for(int i=0;i<n;i++)
	cin>>a[i];
int fl=0;
int k;
for(int i=0;i<n-1;i++)
{
	if(a[i]>a[i+1])
	{
		fl=1;
		k=i;break;
	}
}
if(fl==0)
	cout<<"no";
else
{
	int r=k;
	for(int i=k;i<n-1;i++)
	{
		if(a[i]<a[i+1])
		{
			r=i;break;
		}
	}
	reverse(a.begin()+k,a.begin()+r+1);

	if(is_sorted(a.begin(),a.end()))
	{
		if(k==r)
			cout<<"yes"<<endl<<1<<" "<<n<<endl;
		else
		cout<<"yes"<<endl<<k+1<<" "<<r+1<<endl;

	}
	else
		cout<<"no"<<endl;
}
}


#include<bits/stdc++.h>
#define int long long int

using namespace std;

main()
{
int n;
cin>>n;
vector<int> a(n);
for(int i=0;i<n;i++)
	cin>>a[i];
int fl=0;
int k=0;
for(int i=0;i<n-1;i++)
{
	if(a[i]>a[i+1])
	{
		fl=1;
		k=i;break;
	}
}

	int r=k;
	for(int i=k+1;i<n;i++)
	{
		if(a[i]>a[i-1])
		{
			r=i;break;
		}
	}
	if(r==k)
	{
		cout<<"yes"<<endl<<k+1<<" "<<n<<endl;
		return 0;
	}
	reverse(a.begin()+k,a.begin()+r);

	if(is_sorted(a.begin(),a.end()))
	{
		if(k==r)
			cout<<"yes"<<endl<<1<<" "<<n<<endl;
		else
		cout<<"yes"<<endl<<k+1<<" "<<r<<endl;

	}
	else
		cout<<"no"<<endl;

}


#include<bits/stdc++.h>
#define int long long int

using namespace std;

main()
{
int n;
cin>>n;
vector<int> a(n);
for(int i=0;i<n;i++)
	cin>>a[i];
int fl=0;
int k;
for(int i=0;i<n-1;i++)
{
	if(a[i]>a[i+1])
	{
		fl=1;
		k=i;break;
	}
}
if(fl==0)
	cout<<"no";
else
{

	int r=k;
	for(int i=k+1;i<n;i++)
	{
		if(a[i]>a[i-1])
		{
			r=i;break;
		}
	}
	if(r==k)
	{
		cout<<"yes"<<endl<<k+1<<" "<<n<<endl;
		return 0;
	}
	reverse(a.begin()+k,a.begin()+r+1);

	if(is_sorted(a.begin(),a.end()))
	{
		if(k==r)
			cout<<"yes"<<endl<<1<<" "<<n<<endl;
		else
		cout<<"yes"<<endl<<k+1<<" "<<r+1<<endl;

	}
	else
		cout<<"no"<<endl;
}
}


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

main()
{
	int n;
	cin>>n;
	vector<int> a(n);
	for(int i=0;i<n;i++)
		cin>>a[i];
	if(is_sorted(a.begin(),a.end()))
	{
		cout<<"yes\n"<<1<<" "<<1;
		return 0;
	}
	int k=0,p=0;
	while(k<n)
	{
		if(a[k]<p)
		{
			break;
		}
		p=a[k];
		k++;
	}
	k--;
	int r=k+1;
	while(r<n)
	{
		if(a[r]>a[r-1])
			break;
		r++;
	}
	r--;
	reverse(a.begin()+k,a.begin()+r+1);
	if(is_sorted(a.begin(),a.end()))
		cout<<"yes\n"<<k+1<<" "<<r+1<<endl;
	else
		cout<<"no";
}


#include<bits/stdc++.h>
#define int long long int

using namespace std;

main()
{
int n;
cin>>n;
vector<int> a(n);
for(int i=0;i<n;i++)
	cin>>a[i];
int fl=0;
int k;
for(int i=0;i<n-1;i++)
{
	if(a[i]>a[i+1])
	{
		fl=1;
		k=i;break;
	}
}
if(fl==0)
	cout<<"no";
else
{

	int r=k;
	for(int i=k+1;i<n;i++)
	{
		if(a[i]>a[i-1])
		{
			r=i;break;
		}
	}
	if(r==k)
	{
		cout<<"yes"<<endl<<k+1<<" "<<n<<endl;
		return 0;
	}
	reverse(a.begin()+k,a.begin()+r);

	if(is_sorted(a.begin(),a.end()))
	{
		if(k==r)
			cout<<"yes"<<endl<<1<<" "<<n<<endl;
		else
		cout<<"yes"<<endl<<k+1<<" "<<r+1<<endl;

	}
	else
		cout<<"no"<<endl;
}
}


#include<bits/stdc++.h>
#define int long long int

using namespace std;

main()
{
int n;
cin>>n;
vector<int> a(n);
for(int i=0;i<n;i++)
	cin>>a[i];
int fl=0;
int k=0;
for(int i=0;i<n-1;i++)
{
	if(a[i]>a[i+1])
	{
		fl=1;
		k=i;break;
	}
}

	int r=n-1;
	for(int i=k+1;i<n;i++)
	{
		if(a[i]>a[i-1])
		{
			r=i;break;
		}
	}
	if(r==n-1)
	{	cout<<"yes"<<endl;
	    cout<<1<<" "<<n<<endl;
	    return 0;
	}
	if(r==k)
	{
		if(is_sorted(a.begin(),a.end()))
		cout<<"yes"<<endl<<k+1<<" "<<n<<endl;
		else
			cout<<"no";
		return 0;
	}
	reverse(a.begin()+k,a.begin()+r);

	if(is_sorted(a.begin(),a.end()))
	{
		if(k==r)
			cout<<"yes"<<endl<<1<<" "<<n<<endl;
		else
		cout<<"yes"<<endl<<k+1<<" "<<r<<endl;

	}
	else
		cout<<"no"<<endl;

}


#include<bits/stdc++.h>
#define int long long int

using namespace std;

main()
{
int n;
cin>>n;
vector<int> a(n);
for(int i=0;i<n;i++)
	cin>>a[i];
int fl=0;
int k;
for(int i=0;i<n-1;i++)
{
	if(a[i]>a[i+1])
	{
		fl=1;
		k=i;break;
	}
}
if(fl==0)
	cout<<"no";
else
{

	int r=k;
	for(int i=k+1;i<n;i++)
	{
		if(a[i]>a[i-1])
		{
			r=i;break;
		}
	}
	if(r==k)
	{
		cout<<"yes"<<endl;
		continue;
	}
	reverse(a.begin()+k,a.begin()+r+1);

	if(is_sorted(a.begin(),a.end()))
	{
		if(k==r)
			cout<<"yes"<<endl<<1<<" "<<n<<endl;
		else
		cout<<"yes"<<endl<<k+1<<" "<<r+1<<endl;

	}
	else
		cout<<"no"<<endl;
}
}


#include<bits/stdc++.h>
#define int long long int

using namespace std;

main()
{
int n;
cin>>n;
vector<int> a(n);
for(int i=0;i<n;i++)
	cin>>a[i];
int fl=0;
int k=0;
for(int i=0;i<n-1;i++)
{
	if(a[i]>a[i+1])
	{
		fl=1;
		k=i;break;
	}
}

	int r=k;
	for(int i=k+1;i<n;i++)
	{
		if(a[i]>a[i-1])
		{
			r=i;break;
		}
	}
	if(r==k)
	{
		if(is_sorted(a.begin(),a.end()))
		cout<<"yes"<<endl<<k+1<<" "<<n<<endl;
		else
			cout<<"no";
		return 0;
	}
	reverse(a.begin()+k,a.begin()+r);

	if(is_sorted(a.begin(),a.end()))
	{
		if(k==r)
			cout<<"yes"<<endl<<1<<" "<<n<<endl;
		else
		cout<<"yes"<<endl<<k+1<<" "<<r<<endl;

	}
	else
		cout<<"no"<<endl;

}


#include<bits/stdc++.h>
#define int long long int

using namespace std;

main()
{
int n;
cin>>n;
vector<int> a(n);
for(int i=0;i<n;i++)
	cin>>a[i];
int fl=0;
int k=0;
for(int i=0;i<n-1;i++)
{
	if(a[i]>a[i+1])
	{
		fl=1;
		k=i;break;
	}
}

	int r=n-1;
	for(int i=k+1;i<n;i++)
	{
		if(a[i]>a[i-1])
		{
			r=i;break;
		}
	}
	if(r==n-1)
	{	cout<<"yes"<<endl
	    cout<<1<<" "<<n<<endl;
	    return 0;
	}
	if(r==k)
	{
		if(is_sorted(a.begin(),a.end()))
		cout<<"yes"<<endl<<k+1<<" "<<n<<endl;
		else
			cout<<"no";
		return 0;
	}
	reverse(a.begin()+k,a.begin()+r);

	if(is_sorted(a.begin(),a.end()))
	{
		if(k==r)
			cout<<"yes"<<endl<<1<<" "<<n<<endl;
		else
		cout<<"yes"<<endl<<k+1<<" "<<r<<endl;

	}
	else
		cout<<"no"<<endl;

}


#include<bits/stdc++.h>
#define int long long int

using namespace std;

main()
{
int n;
cin>>n;
vector<int> a(n);
for(int i=0;i<n;i++)
	cin>>a[i];
int fl=0;
int k;
for(int i=0;i<n-1;i++)
{
	if(a[i]>a[i+1])
	{
		fl=1;
		k=i;break;
	}
}
if(fl==0)
	cout<<"no";
else
{

	int r=k;
	for(int i=k+1;i<n;i++)
	{
		if(a[i]>a[i-1])
		{
			r=i;break;
		}
	}
	if(r==k)
	{
		cout<<"yes"<<endl<<k+1<<" "<<n<<endl;
		return 0;
	}
	reverse(a.begin()+k,a.begin()+r);

	if(is_sorted(a.begin(),a.end()))
	{
		if(k==r)
			cout<<"yes"<<endl<<1<<" "<<n<<endl;
		else
		cout<<"yes"<<endl<<k+1<<" "<<r<<endl;

	}
	else
		cout<<"no"<<endl;
}
}


n=int(input())
A=list(map(int, input().split()))
B=sorted(A)

s = t = -1
for i in range(n):
    if A[i] != B[i]:
        s = i
        break

if s == -1:
    print("yes")
    print(1, 1)
    exit()

for i in range(n-1, -1, -1):
    if A[i] != B[i]:
        t = i+1
        break

A = A[:s] + A[s:t:][::-1] + A[t:]
if A == B:
    print("yes")
    print(s+1,t)
else:
    print("no")


#include <iostream>
using namespace std;
#include<bits/stdc++.h>
int main() {
    int n,count=0;
    cin >> n;
    int a[n],b[n],galat[n];
    for(int i=0;i<n;i++){
        cin >> a[i];
        b[i]=a[i];
    }
    sort(b,b+n);
    for(int i=0;i<n;i++){
        if(a[i]!=b[i])
        {
            galat[count]=i;
            count++;
        }
    }
    if(count==0)cout << "yes"<<endl<<a[0]<< " "<<  a[0];
    else if(count==2)cout<< "yes"<<endl<< a[galat[1]]<<" "<<a[galat[0]];
    else cout<< "no";
	return 0;
}


#include <iostream>
using namespace std;
#include<bits/stdc++.h>
int main() {
    int n,count=0,temp=0;
    cin >> n;
    int a[n],b[n],galat[n];
    for(int i=0;i<n;i++){
        cin >> a[i];
        b[i]=a[i];
    }
    sort(b,b+n);
    for(int i=0;i<n;i++){
        if(a[i]!=b[i])
        {
            galat[count]=i;
            count++;
        }
    }
    //cout<< galat[0];
    if(count==0)cout << "yes"<<endl<<a[0]<< " "<<  a[0];
    else if(count%2==0){
        int flag=0;
        for(int i=0;i<count;i++){
            if(a[galat[i]]==b[galat[count-1-i]])
            flag=1;
        }
        if(flag)
        cout<< "yes"<<endl<< galat[0]+1<<" "<<galat[count-1]+1;
    }
    else cout<< "no";
	return 0;
}


#include <iostream>
using namespace std;
#include<bits/stdc++.h>
int main() {
    int n,count=0,temp=0;
    cin >> n;
    int a[n],b[n],galat[n];
    for(int i=0;i<n;i++){
        cin >> a[i];
        b[i]=a[i];
    }
    sort(b,b+n);
    for(int i=0;i<n;i++){
        if(a[i]!=b[i])
        {
            galat[count]=i;
            count++;
        }
    }
    //cout<< galat[0];
    if(count==0)cout << "yes"<<endl<<1<< " "<<  1;
    else if(count%2==0 && ((count-1==galat[count-1]-galat[0]) ||(count==galat[count-1]-galat[0]))){
        int flag=0;
        for(int i=0;i<count;i++){
            if(a[galat[i]]==b[galat[count-1-i]])
            flag=1;
            else {
                 flag=0;
                 break;
            }
        }
        if(flag)
        cout<< "yes"<<endl<< galat[0]+1<<" "<<galat[count-1]+1;
        else cout <<"no";
    }
    else cout<< "no";
	return 0;
}


#include <iostream>
using namespace std;
#include<bits/stdc++.h>
int main() {
    int n,count=0;
    cin >> n;
    int a[n],b[n],galat[n];
    for(int i=0;i<n;i++){
        cin >> a[i];
        b[i]=a[i];
    }
    sort(b,b+n);
    for(int i=0;i<n;i++){
        if(a[i]!=b[i])
        {
            galat[count]=i;
            count++;
        }
    }
    if(count==0)cout << "yes"<<endl<<a[0]<< " "<<  a[0];
    else if(count==2)cout<< "yes"<<endl<< galat[0]+1<<" "<<galat[1]+1;
    else cout<< "no";
	return 0;
}


#include <iostream>
using namespace std;
#include<bits/stdc++.h>
int main() {
    int n,count=0,temp=0;
    cin >> n;
    int a[n],b[n],galat[n];
    for(int i=0;i<n;i++){
        cin >> a[i];
        b[i]=a[i];
    }
    sort(b,b+n);
    for(int i=0;i<n;i++){
        if(a[i]!=b[i])
        {
            galat[count]=i;
            count++;
        }
    }
    //cout<< galat[0];
    if(count==0)cout << "yes"<<endl<<1<< " "<<  1;
    else if(count%2==0){
        int flag=0;
        for(int i=0;i<count;i++){
            if(a[galat[i]]==b[galat[count-1-i]])
            flag=1;
        }
        if(flag)
        cout<< "yes"<<endl<< galat[0]+1<<" "<<galat[count-1]+1;
    }
    else cout<< "no";
	return 0;
}


#include <iostream>
using namespace std;
#include<bits/stdc++.h>
int main() {
    int n,count=0,temp=0;
    cin >> n;
    int a[n],b[n],galat[n];
    for(int i=0;i<n;i++){
        cin >> a[i];
        b[i]=a[i];
    }
    sort(b,b+n);
    for(int i=0;i<n;i++){
        if(a[i]!=b[i])
        {
            galat[count]=i;
            count++;
        }
    }
    //cout<< galat[0];
    if(count==0)cout << "yes"<<endl<<1<< " "<<  1;
    else if(count%2==0){
        int flag=0;
        for(int i=0;i<count;i++){
            if(a[galat[i]]==b[galat[count-1-i]])
            flag=1;
            else {
                 flag=0;
                 break;
            }
        }
        if(flag)
        cout<< "yes"<<endl<< galat[0]+1<<" "<<galat[count-1]+1;
        else cout <<"no";
    }
    else cout<< "no";
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int i,n,a[100000],b[100000],f,s;
main(){
scanf("%d", &n);
for(i=0; i<n; i++){
scanf("%d", &a[i]);
b[i]=a[i];
}
sort(b, b+n);

for(i=0; i<n; i++)
if(a[i]!=b[i]){ f=i; break;}

for(i=n-1; i>=0; i--)
if(a[i]!=b[i]){s=i; break;}

reverse(a+f, a+s+1);

for(i=0; i<n; i++)
if(a[i]!=b[i]){printf("no"); return 0;}

printf("yes %d %d", f+1,s+1);
}


#include <iostream>
using namespace std;
#include<bits/stdc++.h>
int main() {
    int n,count=0;
    cin >> n;
    int a[n],b[n],galat[n];
    for(int i=0;i<n;i++){
        cin >> a[i];
        b[i]=a[i];
    }
    sort(b,b+n);
    for(int i=0;i<n;i++){
        if(a[i]!=b[i])
        {
            galat[count]=i;
            count++;
        }
    }
    if(count==0)cout << "yes"<<endl<<a[0]<< " "<<  a[0];
    else if(count==2)cout<< "yes"<<endl<< galat[1]+1<<" "<<galat[0]+1;
    else cout<< "no";
	return 0;
}


#include <iostream>
using namespace std;
#include<bits/stdc++.h>
int main() {
    int n,count=0,temp=0;
    cin >> n;
    int a[n],b[n],galat[n];
    for(int i=0;i<n;i++){
        cin >> a[i];
        b[i]=a[i];
    }
    sort(b,b+n);
    for(int i=0;i<n;i++){
        if(a[i]!=b[i])
        {
            galat[count]=i;
            count++;
        }
    }
    //cout<< galat[0];
    if(count==0)cout << "yes"<<endl<<1<< " "<<  1;
    else if(count%2==0){
        int flag=0;
        for(int i=0;i<count;i++){
            if(a[galat[i]]==b[galat[count-1-i]])
            flag=1;
            else {
                 flag=0;
                 break;
            }
        }
        if(flag)
        cout<< "yes"<<endl<< galat[0]+1<<" "<<galat[count-1]+1;
    }
    else cout<< "no";
	return 0;
}


#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;

int main()
{

	int n;
	cin >> n;
	vector<int> a;
	vector<int> b;

	for (int i = 0; i < n; i++)
	{
		int x;
		cin >> x;
		a.push_back(x);
		b.push_back(x);
	}

	sort(a.begin(), a.end());

	int l = 0;
	int r = n - 1;

	for (int i = 0; i < a.size(); i++)
	{
		if (a[i] != b[i])
		{
			l = i;
			break;
		}
	}

	for (int j = n  - 1; j >= 0; j--)
	{
		if (a[j] != b[j])
		{
			r = j;
			break;
		}
	}

	int i, j;
	for (i = 0, j = r; i <= l && j >= 0 ; i++ , j--)
	{
		swap(b[i], b[j]);
	}

	for (int i = 0; i < n; i++)
	{
		if (a[i] != b[i])
		{
			cout << "NO";
			return 0;
		}
	}
	cout << "yes" << endl;
	cout << l + 1 << " " << r + 1;

	return 0;
}


#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;

int main()
{

	int n;
	cin >> n;
	vector<int> a;
	vector<int> b;

	for (int i = 0; i < n; i++)
	{
		int x;
		cin >> x;
		a.push_back(x);
		b.push_back(x);
	}

	sort(a.begin(), a.end());

	int l = 0;
	int r = n - 1;

	int check = 0;
	for (int i = 0; i < n; i++)
	{
		if (a[i] != b[i])
		{
			check = 1;
		}
	}

	if (check == 0)
	{
		cout << "yes" <<endl;
		cout << 1 <<" " << n - 1;
		return 0;
	}

	for (int i = 0; i < a.size(); i++)
	{
		if (a[i] != b[i])
		{
			l = i;
			break;
		}
	}

	for (int j = n  - 1; j >= 0; j--)
	{
		if (a[j] != b[j])
		{
			r = j;
			break;
		}
	}

	int i, j;
	for (i = 0, j = r; i <= l && j >= 0 ; i++ , j--)
	{
		swap(b[i], b[j]);
	}

	for (int i = 0; i < n; i++)
	{
		if (a[i] != b[i])
		{
			cout << "no";
			return 0;
		}
	}

	cout << "yes" << endl;
	cout << l + 1 << " " << r + 1;

	return 0;
}


#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;

int main()
{

	int n;
	cin >> n;
	vector<int> a;
	vector<int> b;

	for (int i = 0; i < n; i++)
	{
		int x;
		cin >> x;
		a.push_back(x);
		b.push_back(x);
	}

	sort(a.begin(), a.end());

	for (int i = 0; i < n; i++)
	{
		if (a[i] == b[i])
		{
			cout << "yes" << endl;
			cout <<  1 << " " << 1;
		}
	}

	int l = 0;
	int r = n - 1;

	for (int i = 0; i < a.size(); i++)
	{
		if (a[i] != b[i])
		{
			l = i;
			break;
		}
	}

	for (int j = n  - 1; j >= 0; j--)
	{
		if (a[j] != b[j])
		{
			r = j;
			break;
		}
	}

	int i, j;
	for (i = 0, j = r; i <= l && j >= 0 ; i++ , j--)
	{
		swap(b[i], b[j]);
	}

	for (int i = 0; i < n; i++)
	{
		if (a[i] != b[i])
		{
			cout << "no";
			return 0;
		}
	}

	cout << "yes" << endl;
	cout << l + 1 << " " << r + 1;

	return 0;
}


#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;

int main()
{

	int n;
	cin >> n;
	vector<int> a;
	vector<int> b;

	for (int i = 0; i < n; i++)
	{
		int x;
		cin >> x;
		a.push_back(x);
		b.push_back(x);
	}

	sort(a.begin(), a.end());

	int l = 0;
	int r = n - 1;

	for (int i = 0; i < a.size(); i++)
	{
		if (a[i] != b[i])
		{
			l = i;
			break;
		}
	}

	for (int j = n  - 1; j >= 0; j--)
	{
		if (a[j] != b[j])
		{
			r = j;
			break;
		}
	}

	int i, j;
	for (i = 0, j = r; i <= l && j >= 0 ; i++ , j--)
	{
		swap(b[i], b[j]);
	}

	for (int i = 0; i < n; i++)
	{
		if (a[i] != b[i])
		{
			cout << "NO";
			return 0;
		}
	}
	cout << "Yes" << endl;
	cout << l + 1 << " " << r + 1;

	return 0;
}