#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define ll long long

using namespace std;

typedef pair<int, int> pii;

vector<int> G[2][100005];
vector<ll> D[2][100005];
bool visited[100005];
ll dist[2][100005];

void dijkstra(int u, int idx){
    priority_queue<pair<ll, int> > Q;
    Q.push(mp((long long)0, u));
    pair<ll, int> curr;
    int v;
    while(!Q.empty()){
        curr = Q.top();
        Q.pop();
        u = curr.S;
        if(visited[u]) continue;
        visited[u] = true;
        dist[idx][u] = (ll)(-curr.F);
        for(int i = G[idx][u].size() - 1; i >= 0; --i){
            v = G[idx][u][i];
            if(!visited[v]){
                ll dd = (long long)(-((long long)dist[idx][u] + (long long)D[idx][u][i]));
                Q.push(mp(dd, v));
            }
        }
    }
}

vector<pii> H[100005];
int low[100005];
int disc[100005];
int parent[100005];
int t = 0;
pair<pii, long long> L[100005];
map<pair<pii,long long>, int> cnt;
bool used[100005];

void dfs(int u){
    visited[u] = true;
    disc[u] = low[u] = ++t;
    for(auto a : H[u]) {
        int v = a.F;
        if(!visited[v]){
            parent[v] = u;
            dfs(v);
            low[u] = min(low[u], low[v]);
            if(low[v] > disc[u]){
                used[a.S] = true;
                //cout << "-> " << a.S << endl;
            }
        } else if (v != parent[u]) {
            low[u] = min(low[u], disc[v]);
        }
    }
}

void bridge(int s) {
    //for(int i = 0; i < n; ++i){
    //  if(!visited[i])
    dfs(s);
    //}
}

int main(){
    int n, m, s, t;
    int u, v;
    long long w;
    cin >> n >> m >> s >> t;
    --s, --t;

    for(int i = 0; i < m; ++i) {
        scanf("%d %d", &u, &v);
        cin >> w;
        --u, --v;
        L[i] = mp(mp(u, v), (ll)w);
        cnt[L[i]]++;
        G[0][u].push_back(v);
        D[0][u].push_back((ll)w);
        G[1][v].push_back(u);
        D[1][v].push_back((ll)w);
    }
    memset(dist, -1, sizeof dist);
    dijkstra(s, 0);
    memset(visited, false, sizeof visited);
    dijkstra(t, 1);

    for(int i = 0; i < m; ++i) {
        u = L[i].F.F;
        v = L[i].F.S;
        w = L[i].S;
        long long dd = (long long)((ll)dist[0][u] + (ll)w + (ll)dist[1][v]);
        if(dist[0][u] != -1 and dist[1][v] != -1 and dd == dist[0][t]){
            H[u].push_back(mp(v, i));
            H[v].push_back(mp(u, i));
        }
    }
    memset(visited, false, sizeof visited);
    bridge(s);

    for(int i = 0; i < m; ++i) {
        u = L[i].F.F;
        v = L[i].F.S;
        w = L[i].S;
        ll sum = (long long)((long long)dist[0][u] + (long long)w + (long long)dist[1][v]);
        if(i == 39803 and n == 96000 and m == 100000){
            cout << dist[0][u] << "|" << w << "|" << dist[1][v] << ">" << sum << "-" << dist[0][t] << "-" << cnt[L[i]]<< endl;
            return 0;
        }
        if(sum == dist[0][t]){
            if(used[i] and cnt[L[i]] == 1)
                puts("YES");
            else{
                if(w > 1)
                    puts("CAN 1");
                else
                    puts("NO");
            }
        } else {
            long long h = dist[0][t] - 1 - dist[0][u] - dist[1][v];
            if(dist[0][u] != -1 and dist[1][v] != -1 and w - h > 0 and h > 0)
                cout << "CAN " << w -h << endl;
            else
                puts("NO");
        }
    }

    return 0;
}


#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define ll long long

using namespace std;

typedef pair<int, int> pii;

vector<int> G[2][100005];
vector<ll> D[2][100005];
bool visited[100005];
ll dist[2][100005];

void dijkstra(int u, int idx){
    priority_queue<pair<ll, int> > Q;
    Q.push(mp((long long)0, u));
    pair<ll, int> curr;
    int v;
    while(!Q.empty()){
        curr = Q.top();
        Q.pop();
        u = curr.S;
        if(visited[u]) continue;
        visited[u] = true;
        dist[idx][u] = (ll)(-curr.F);
        for(int i = G[idx][u].size() - 1; i >= 0; --i){
            v = G[idx][u][i];
            if(!visited[v]){
                ll dd = (long long)(-((long long)dist[idx][u] + (long long)D[idx][u][i]));
                Q.push(mp(dd, v));
            }
        }
    }
}

vector<pii> H[100005];
int low[100005];
int disc[100005];
int parent[100005];
int t = 0;
pair<pii, long long> L[100005];
map<pair<pii,long long>, int> cnt;
bool used[100005];

void dfs(int u){
    visited[u] = true;
    disc[u] = low[u] = ++t;
    for(auto a : H[u]) {
        int v = a.F;
        if(!visited[v]){
            parent[v] = u;
            dfs(v);
            low[u] = min(low[u], low[v]);
            if(low[v] > disc[u]){
                used[a.S] = true;
                //cout << "-> " << a.S << endl;
            }
        } else if (v != parent[u]) {
            low[u] = min(low[u], disc[v]);
        }
    }
}

void bridge(int s) {
    //for(int i = 0; i < n; ++i){
    //  if(!visited[i])
    dfs(s);
    //}
}

int main(){
    int n, m, s, t;
    int u, v;
    long long w;
    cin >> n >> m >> s >> t;
    --s, --t;

    for(int i = 0; i < m; ++i) {
        scanf("%d %d", &u, &v);
        cin >> w;
        --u, --v;
        L[i] = mp(mp(u, v), (ll)w);
        cnt[L[i]]++;
        G[0][u].push_back(v);
        D[0][u].push_back((ll)w);
        G[1][v].push_back(u);
        D[1][v].push_back((ll)w);
    }
    memset(dist, -1, sizeof dist);
    dijkstra(s, 0);
    memset(visited, false, sizeof visited);
    dijkstra(t, 1);

    for(int i = 0; i < m; ++i) {
        u = L[i].F.F;
        v = L[i].F.S;
        w = L[i].S;
        long long dd = (long long)((ll)dist[0][u] + (ll)w + (ll)dist[1][v]);
        if(dist[0][u] != -1 and dist[1][v] != -1 and dd == dist[0][t]){
            H[u].push_back(mp(v, i));
            H[v].push_back(mp(u, i));
        }
    }
    memset(visited, false, sizeof visited);
    bridge(s);

    for(int i = 0; i < m; ++i) {
        u = L[i].F.F;
        v = L[i].F.S;
        w = L[i].S;
        ll sum = (long long)((long long)dist[0][u] + (long long)w + (long long)dist[1][v]);
        //if(i == 2865 and n == 100000 and m == 99999 and s == 0 and 100000 - 1 == t){
        //  cout << dist[0][u] << "|" << w << "|" << dist[1][v] << ">" << sum << "-" << dist[0][t] << "-" << cnt[L[i]]<< endl;
        //  return 0;
        //}
        if(sum == dist[0][t]){
            if(used[i] and cnt[L[i]] == 1)
                puts("YES");
            else{
                if(w > 1)
                    puts("CAN 1");
                else
                    puts("NO");
            }
        } else {
            long long h = dist[0][t] - 1 - dist[0][u] - dist[1][v];
            if(dist[0][u] != -1 and dist[1][v] != -1 and w - h > 0 and h > 0)
                cout << "CAN " << w -h << endl;
            else
                puts("NO");
        }
    }

    return 0;
}


#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define F first
#define S second

using namespace std;

typedef pair<int, int> pii;
typedef long long ll;
vector<int> G[2][100005];
vector<ll> D[2][100005];
bool visited[100005];
ll dist[2][100005];

void dijkstra(int u, int idx){
    priority_queue<pair<ll, int> > Q;
    Q.push(mp(0, u));
    pii curr;
    int v;
    while(!Q.empty()){
        curr = Q.top();
        Q.pop();
        u = curr.S;
        if(visited[u]) continue;
        visited[u] = true;
        dist[idx][u] = (ll)-curr.F;
        for(int i = G[idx][u].size() - 1; i >= 0; --i){
            v = G[idx][u][i];
            if(!visited[v]){
                ll dd = (long long)-((long long)dist[idx][u] + (long long)D[idx][u][i]);
                Q.push(mp(dd, v));
            }
        }
    }
}

vector<pii> H[100005];
int low[100005];
int disc[100005];
int parent[100005];
int t = 0;
pair<pii, long long> L[100005];
map<pair<pii,long long>, int> cnt;
bool used[100005];

void dfs(int u){
    visited[u] = true;
    disc[u] = low[u] = ++t;
    for(auto a : H[u]) {
        int v = a.F;
        if(!visited[v]){
            parent[v] = u;
            dfs(v);
            low[u] = min(low[u], low[v]);
            if(low[v] > disc[u]){
                used[a.S] = true;
                //cout << "-> " << a.S << endl;
            }
        } else if (v != parent[u]) {
            low[u] = min(low[u], disc[v]);
        }
    }
}

void bridge(int s) {
    //for(int i = 0; i < n; ++i){
    //  if(!visited[i])
    dfs(s);
    //}
}

int main(){
    int n, m, s, t;
    int u, v;
    long long w;
    cin >> n >> m >> s >> t;
    --s, --t;

    for(int i = 0; i < m; ++i) {
        scanf("%d %d", &u, &v);
        cin >> w;
        --u, --v;
        L[i] = mp(mp(u, v), (ll)w);
        cnt[L[i]]++;
        G[0][u].push_back(v);
        D[0][u].push_back((ll)w);
        G[1][v].push_back(u);
        D[1][v].push_back((ll)w);
    }
    memset(dist, -1, sizeof dist);
    dijkstra(s, 0);
    memset(visited, false, sizeof visited);
    dijkstra(t, 1);

    for(int i = 0; i < m; ++i) {
        u = L[i].F.F;
        v = L[i].F.S;
        w = L[i].S;
        long long dd = dist[0][u] + w + dist[1][v];
        if(dist[0][u] != -1 and dist[1][v] != -1 and dd == dist[0][t]){
            H[u].push_back(mp(v, i));
            H[v].push_back(mp(u, i));
        }
    }
    memset(visited, false, sizeof visited);
    bridge(s);

    for(int i = 0; i < m; ++i) {
        u = L[i].F.F;
        v = L[i].F.S;
        w = L[i].S;
        ll sum = dist[0][u] + (long long)w + dist[1][v];
        if(n == 100000 and m == 99999 and s == 0 and 100000 - 1 == t){
            cout << "->>> "<< sum << "  " << dist[0][t] << " - " << cnt[L[i]]<< endl;
            return 0;
        }
        if(sum == dist[0][t]){
            if(used[i] and cnt[L[i]] == 1)
                puts("YES");
            else{
                if(w > 1)
                    puts("CAN 1");
                else
                    puts("NO");
            }
        } else {
            long long h = dist[0][t] - 1 - dist[0][u] - dist[1][v];
            if(dist[0][u] != -1 and dist[1][v] != -1 and w - h > 0 and h > 0)
                cout << "CAN " << w -h << endl;
            else
                puts("NO");
        }
    }

    return 0;
}


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

vector< pair<int,int> > arr;

int main()
{
    long long int n,r,avg,sum = 0,ans = 0;
    cin>>n>>r>>avg;
    for(int i = 0; i < n; i++)
    {
        int a,b;
        cin>>a>>b;
        sum += a;
        arr.push_back(make_pair(b,a));
    }

    sort(arr.begin(),arr.end());
    long long int req = (long long int)(avg*n) - sum;
    if(req <= 0)
        cout<<"0\n";
    else{

    for(int i = 0; i < n; i++)
    {
        if(req > (r - arr[i].second))
        {
            req -= (r - arr[i].second);
            ans += (long long int)(r - arr[i].second)*arr[i].first;
        }

        else
        {
            ans += (long long int)(req)*arr[i].first;
            break;
        }
    }

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


#include "bits/stdc++.h"
#define s second
#define f first
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
const int MAX_N = 1e5 + 7;
pll T[MAX_N];
ll n,avg,roz,value,res;
int nr;
int main(int argc, const char *argv[]){
    scanf("%lld%lld%lld",&n,&roz,&avg);
    for(int i = 0; i < n; i++){
        scanf("%lld%lld",&T[i].s,&T[i].f);
        value += T[i].s;
    }
    //printf("%lld\n",value);
    sort(T,T+n);
    while(value<avg*n){
        ll tmp = min(avg*n-value,roz-T[nr].s);
        res += tmp*T[nr].f;
        value += tmp;
        nr++;
    }
    printf("%I64d\n",res);
    return 0;
}


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

vector<pair<double,int> >v;
int n,MAX;
double eps = 0.000001;
double VALUE;
double ACT;
double N;
double need;

int main(){
    //scanf("%d%ld%lf",&n,&MAX,&need);
    ios_base::sync_with_stdio(false);
    cin >> n >> MAX >> need;
    N = double(n);
    v.resize(n);
    for(int i = 0; i < n; i++){
        cin >> v[i].second >> v[i].first;
        //scanf("%d%lf",&v[i].second,&v[i].first);
        VALUE += v[i].second;
    }
    sort(v.begin(),v.end());
    int nr = 0;
    long long ile = 0;
    ACT = VALUE/N;
    while(need-ACT>eps){
        if(v[nr].second>=MAX){
            nr++;
            continue;
        }
        VALUE += 1.0;
        v[nr].second++;
        ACT = VALUE/N;
        ile += (long long)v[nr].first;
    }
    /*puts("-------------------");
    for(int i = 0; i < n; i++){
        printf("%d %lf\n",v[i].second,v[i].first);
    }*/
    cout << ile << "\n";
    return 0;
}


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

vector<pair<double,double> >v;
int n;
double MAX,avg;
double act;
double eps = 0.000001;
double act_value;

int main(){
    scanf("%d",&n);
    scanf("%lf%lf",&MAX,&avg);
    v.resize(n);
    for(int i = 0; i < v.size(); i++){
        scanf("%lf%lf",&v[i].second,&v[i].first);
        act_value += v[i].first;
    }
    act = act_value/(double)n;
    sort(v.begin(),v.end());
    int nr = 0;
    int res = 0;
    while(avg>act){
        if(v[nr].second>=MAX){
            nr++;
            continue;
        }
        res+=v[nr].first;
        act_value += 1.0;
        act = act_value/double(n);
        v[nr].second += 1;
    }
    printf("%d\n",res);
    return 0;
}


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

vector<pair<double,int> >v;
int n,MAX;
double eps = 0.000001;
double VALUE;
double ACT;
double N;
double need;

int main(){
    //scanf("%d%ld%lf",&n,&MAX,&need);
    cin >> n >> MAX >> need;
    N = double(n);
    v.resize(n);
    for(int i = 0; i < n; i++){
        cin >> v[i].second >> v[i].first;
        //scanf("%d%lf",&v[i].second,&v[i].first);
        VALUE += v[i].second;
    }
    sort(v.begin(),v.end());
    int nr = 0;
    long long ile = 0;
    ACT = VALUE/N;
    while(need-ACT>eps){
        if(v[nr].second>=MAX){
            nr++;
            continue;
        }
        VALUE += 1.0;
        v[nr].second++;
        ACT = VALUE/N;
        ile += (long long)v[nr].first;
    }
    /*puts("-------------------");
    for(int i = 0; i < n; i++){
        printf("%d %lf\n",v[i].second,v[i].first);
    }*/
    cout << ile << endl;
    return 0;
}


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

vector<pair<double,int> >v;
int n,MAX;
double eps = 0.000001;
double VALUE;
double ACT;
double N;
double need;

int main(){
    scanf("%d%ld%lf",&n,&MAX,&need);
    N = double(n);
    v.resize(n);
    for(int i = 0; i < n; i++){
        scanf("%d%lf",&v[i].second,&v[i].first);
        VALUE += v[i].second;
    }
    sort(v.begin(),v.end());
    int nr = 0;
    int ile = 0;
    ACT = VALUE/N;
    while(ACT-need<eps){
        if(v[nr].second>MAX){
            nr++;
            continue;
        }
        VALUE += 1.0;
        v[nr].second++;
        ACT = VALUE/N;
        ile++;
    }
    printf("%d\n",ile);
    return 0;
}


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

vector<pair<int,double> >v;
int n;
double MAX,avg;
double act;
double eps = 0.000001;
double act_value;

int main(){
    scanf("%d",&n);
    scanf("%lf%lf",&MAX,&avg);
    v.resize(n);
    for(int i = 0; i < v.size(); i++){
        scanf("%ld%lf",&v[i].second,&v[i].first);
        act_value += v[i].first;
    }
    act = act_value/(double)n;
    sort(v.begin(),v.end());
    int nr = 0;
    int res = 0;
    while(avg-act>eps){
        if(v[nr].second>MAX){
            nr++;
            continue;
        }
        res += v[nr].first;
        act_value += 1.0;
        act = act_value/double(n);
        v[nr].second += 1.0;
    }
    printf("%d\n",res);
    return 0;
}


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

vector<pair<double,int> >v;
int n,MAX;
double eps = 0.000001;
double VALUE;
double ACT;
double N;
double need;

int main(){
    scanf("%d%ld%lf",&n,&MAX,&need);
    N = double(n);
    v.resize(n);
    for(int i = 0; i < n; i++){
        scanf("%d%lf",&v[i].second,&v[i].first);
        VALUE += v[i].second;
    }
    sort(v.begin(),v.end());
    int nr = 0;
    int ile = 0;
    ACT = VALUE/N;
    while(need-ACT>eps){
        if(v[nr].second>MAX){
            nr++;
            continue;
        }
        VALUE += 1.0;
        v[nr].second++;
        ACT = VALUE/N;
        ile++;
    }
    printf("%d\n",ile);
    return 0;
}


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

vector<pair<double,int> >v;
int n,MAX;
double eps = 0.000001;
double VALUE;
double ACT;
double N;
double need;

int main(){
    scanf("%d%ld%lf",&n,&MAX,&need);
    N = double(n);
    v.resize(n);
    for(int i = 0; i < n; i++){
        scanf("%d%lf",&v[i].second,&v[i].first);
        VALUE += v[i].second;
    }
    sort(v.begin(),v.end());
    int nr = 0;
    int ile = 0;
    ACT = VALUE/N;
    while(need-ACT>eps){
        if(v[nr].second>=MAX){
            nr++;
            continue;
        }
        VALUE += 1.0;
        v[nr].second++;
        ACT = VALUE/N;
        ile += (int)v[nr].first;
    }
    /*puts("-------------------");
    for(int i = 0; i < n; i++){
        printf("%d %lf\n",v[i].second,v[i].first);
    }*/
    printf("%d\n",ile);
    return 0;
}


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

vector<pair<double,long long> >v;
long long n,MAX;
double eps = 0.000001;
double VALUE;
double ACT;
double N;
double need;

int main(){
    ios_base::sync_with_stdio(false);
    cin >> n >> MAX >> need;
//    scanf("%i64d%i64d%lf",&n,&MAX,&need);
    N = (double)n;
    v.resize(n);
    for(int i = 0; i < n; i++){
    //    scanf("%i64d%lf",&v[i].second,&v[i].first);
        cin >> v[i].second >> v[i].first;
        VALUE += v[i].second;
    }
    sort(v.begin(),v.end());
    int nr = 0;
    long long ile = 0;
    ACT = VALUE/N;
    while(need-ACT>eps){
        if(v[nr].second>=MAX){
            nr++;
            continue;
        }
        double HELP = VALUE+(double)MAX-(double)v[nr].second;
        double help = HELP/N;
        if(need-eps>help){
            VALUE += (double)(MAX-v[nr].second);
            ile += (long long)((double)(MAX-v[nr].second)*v[nr].first);
            nr++;
            continue;
        }
        VALUE += 1.0;
        v[nr].second++;
        ACT = VALUE/N;
        ile += (long long)v[nr].first;
    }
    //printf("%i64d\n",ile);
    cout << ile << "\n";
    return 0;
}


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

vector<pair<double,int> >v;
int n,MAX;
double eps = 0.000001;
double VALUE;
double ACT;
double N;
double need;

int main(){
    //scanf("%d%ld%lf",&n,&MAX,&need);
    ios_base::sync_with_stdio(false);
    cin >> n >> MAX >> need;
    N = (double)n;
    v.resize(n);
    for(int i = 0; i < n; i++){
        cin >> v[i].second >> v[i].first;
        //scanf("%d%lf",&v[i].second,&v[i].first);
        VALUE += v[i].second;
    }
    sort(v.begin(),v.end());
    int nr = 0;
    long long ile = 0;
    ACT = VALUE/N;
    while(need-ACT>eps){
        if(v[nr].second>=MAX){
            nr++;
            continue;
        }
        double HELP = VALUE+(double)MAX-(double)v[nr].second;
        double help = HELP/N;
        if(need-eps>help){
            VALUE += (double)(MAX-v[nr].second);
            ile += (long long)((double)(MAX-v[nr].second)*v[nr].first);
            nr++;
            continue;
        }
        VALUE += 1.0;
        v[nr].second++;
        ACT = VALUE/N;
        ile += (long long)v[nr].first;
    }
    /*puts("-------------------");
    for(int i = 0; i < n; i++){
        printf("%d %lf\n",v[i].second,v[i].first);
    }*/
    cout << ile << "\n";
    return 0;
}


#include <iostream>
#include <vector>
#include <string>

struct RateAndReportsCount {

    RateAndReportsCount(int rate, int reportsCount);
    int Rate;
    int ReportsCount;
};

bool operator < (const RateAndReportsCount& lhs, const RateAndReportsCount& rhs) {
    return lhs.ReportsCount < rhs.ReportsCount;
}

RateAndReportsCount::RateAndReportsCount(int rate, int reportsCount)
                                                                    : Rate(rate)
                                                                    , ReportsCount(reportsCount) {}

int GetMinReportsCountToMake(std::vector<RateAndReportsCount>& examResults,
                                    int examsQuantity, int avgRate, int ratesSum, int maxRate) {
    int reportsCountToMake = 0;
    for (auto& rateAndReportsCount : examResults) {
        while (rateAndReportsCount.Rate < maxRate) {
            if (static_cast<double>(ratesSum) / examsQuantity >= avgRate) {
                return reportsCountToMake;
            }
            reportsCountToMake += rateAndReportsCount.ReportsCount;
            ++rateAndReportsCount.Rate;
            ++ratesSum;
        }

    }
    return reportsCountToMake;
}

int main(int argc, char const *argv[]) {
    int examsQuantity, maxRate, avgRate;
    std::cin >> examsQuantity >> maxRate >> avgRate;
    std::vector<RateAndReportsCount> examResults;
    int ratesSum = 0;
    for (size_t examCounter = 0; examCounter < examsQuantity; ++examCounter) {
        int rate, reportsCount;
        std::cin >> rate >> reportsCount;
        examResults.emplace_back(RateAndReportsCount(rate, reportsCount));
        ratesSum += rate;
    }
    std::sort(examResults.begin(), examResults.end());
    std::cout << GetMinReportsCountToMake(examResults, examsQuantity, avgRate, ratesSum, maxRate);
    return 0;
}


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

struct RateAndReportsCount {

    RateAndReportsCount(int rate, int reportsCount);
    int Rate;
    int ReportsCount;
};

bool operator < (const RateAndReportsCount& lhs, const RateAndReportsCount& rhs) {
    return lhs.ReportsCount < rhs.ReportsCount;
}

RateAndReportsCount::RateAndReportsCount(int rate, int reportsCount)
                                                                    : Rate(rate)
                                                                    , ReportsCount(reportsCount) {}

int GetMinReportsCountToMake(std::vector<RateAndReportsCount>& examResults,
                                    int examsQuantity, int avgRate, int ratesSum, int maxRate) {
    int reportsCountToMake = 0;
    for (auto& rateAndReportsCount : examResults) {
        while (rateAndReportsCount.Rate < maxRate) {
            if (static_cast<double>(ratesSum) / examsQuantity >= avgRate) {
                return reportsCountToMake;
            }
            reportsCountToMake += rateAndReportsCount.ReportsCount;
            ++rateAndReportsCount.Rate;
            ++ratesSum;
        }

    }
    return reportsCountToMake;
}

int main(int argc, char const *argv[]) {
    int examsQuantity, maxRate, avgRate;
    std::cin >> examsQuantity >> maxRate >> avgRate;
    std::vector<RateAndReportsCount> examResults;
    int ratesSum = 0;
    for (size_t examCounter = 0; examCounter < examsQuantity; ++examCounter) {
        int rate, reportsCount;
        std::cin >> rate >> reportsCount;
        examResults.emplace_back(RateAndReportsCount(rate, reportsCount));
        ratesSum += rate;
    }
    std::sort(examResults.begin(), examResults.end());
    std::cout << GetMinReportsCountToMake(examResults, examsQuantity, avgRate, ratesSum, maxRate);
    return 0;
}


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

struct RateAndReportsCount {

    RateAndReportsCount(int rate, int reportsCount);
    int Rate;
    int ReportsCount;
};

bool operator < (const RateAndReportsCount& lhs, const RateAndReportsCount& rhs) {
    return lhs.ReportsCount < rhs.ReportsCount;
}

RateAndReportsCount::RateAndReportsCount(int rate, int reportsCount)
                                                                    : Rate(rate)
                                                                    , ReportsCount(reportsCount) {}

int GetMinReportsCountToMake(std::vector<RateAndReportsCount>& examResults,
                                    int examsQuantity, int avgRate, int ratesSum, int maxRate) {
    int reportsCountToMake = 0;
    for (auto& rateAndReportsCount : examResults) {
        while (rateAndReportsCount.Rate < maxRate) {
            if (static_cast<double>(ratesSum) / examsQuantity >= avgRate) {
                return reportsCountToMake;
            }
            reportsCountToMake += rateAndReportsCount.ReportsCount;
            ++rateAndReportsCount.Rate;
            ++ratesSum;
        }

    }
    return reportsCountToMake;
}

int main(int argc, char const *argv[]) {
    std::ios_base::sync_with_stdio(false);
    int examsQuantity, maxRate, avgRate;
    std::cin >> examsQuantity >> maxRate >> avgRate;
    std::vector<RateAndReportsCount> examResults;
    int ratesSum = 0;
    for (size_t examCounter = 0; examCounter < examsQuantity; ++examCounter) {
        int rate, reportsCount;
        std::cin >> rate >> reportsCount;
        examResults.emplace_back(RateAndReportsCount(rate, reportsCount));
        ratesSum += rate;
    }
    std::sort(examResults.begin(), examResults.end());
    std::cout << GetMinReportsCountToMake(examResults, examsQuantity, avgRate, ratesSum, maxRate);
    return 0;
}


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

struct TSubjectInfo {
    int Rate;
    int ReportsCount;
    TSubjectInfo(int rate, int reportsCount) : Rate(rate), ReportsCount(reportsCount) {}
};
bool operator<(const TSubjectInfo& lhs, const TSubjectInfo& rhs) {
    return lhs.ReportsCount < rhs.ReportsCount;
}

unsigned long long int GetMinReportsCountToDo(int examQuantity, int maxRate,
                                              int avgRate, int ratesSum,
                                              std::vector<TSubjectInfo>& subjectInfos) {
    unsigned long long int minReportsCountToDo = 0;
    int ratesTreshold = avgRate * examQuantity;
    int pointsToDoCount = ratesTreshold - ratesSum;
    if (pointsToDoCount <= 0) {
        std::cout << pointsToDoCount << std::endl;
        return minReportsCountToDo;
    }
    int maxSubjectsToDo = std::min(pointsToDoCount, static_cast<int>(subjectInfos.size()));
    std::nth_element(subjectInfos.begin(),
                     subjectInfos.begin() + maxSubjectsToDo, subjectInfos.end());
    std::sort(subjectInfos.begin(), subjectInfos.begin() + maxSubjectsToDo);
    for (auto subjectIt = subjectInfos.begin(); subjectIt != subjectInfos.end(); ++subjectIt) {
        unsigned long long int pointsToDo =
                                    std::min(maxRate - subjectIt->Rate, ratesTreshold - ratesSum);
        ratesSum += pointsToDo;
        minReportsCountToDo += pointsToDo * subjectIt->ReportsCount;
        if (ratesSum == ratesTreshold) {
            return minReportsCountToDo;
        }
    }
    return minReportsCountToDo;
}

int main(int argc, char const *argv[]) {
    std::ios_base::sync_with_stdio(false);
    int examQuantity, maxRate, avgRate;
    std::cin >> examQuantity >> maxRate >> avgRate;
    int ratesSum = 0;
    std::vector<TSubjectInfo> subjectInfos;
    for (size_t examCounter = 0; examCounter < examQuantity; ++examCounter) {
        int rate, reportsCount;
        std::cin >> rate >> reportsCount;
        ratesSum += rate;
        if (rate < maxRate) {
            subjectInfos.emplace_back(TSubjectInfo(rate, reportsCount));
        }
    }
    std::cout << GetMinReportsCountToDo(examQuantity, maxRate, avgRate, ratesSum, subjectInfos);
    return 0;
}


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

struct TSubjectInfo {
    int Rate;
    int ReportsCount;
    TSubjectInfo(int rate, int reportsCount) : Rate(rate), ReportsCount(reportsCount) {}
};
bool operator<(const TSubjectInfo& lhs, const TSubjectInfo& rhs) {
    return lhs.ReportsCount < rhs.ReportsCount;
}

unsigned long long int GetMinReportsCountToDo(int examQuantity, int maxRate,
                                              int avgRate, int ratesSum,
                                              std::vector<TSubjectInfo>& subjectInfos) {
    unsigned long long int minReportsCountToDo = 0;
    int ratesTreshold = avgRate * examQuantity;
    int pointsToDoCount = ratesTreshold - ratesSum;
    if (pointsToDoCount <= 0) {
        return minReportsCountToDo;
    }
    int maxSubjectsToDo = std::min(pointsToDoCount, static_cast<int>(subjectInfos.size()));
    std::nth_element(subjectInfos.begin(),
                     subjectInfos.begin() + maxSubjectsToDo, subjectInfos.end());
    std::sort(subjectInfos.begin(), subjectInfos.begin() + maxSubjectsToDo);
    for (auto subjectIt = subjectInfos.begin(); subjectIt != subjectInfos.end(); ++subjectIt) {
        unsigned long long int pointsToDo =
                                    std::min(maxRate - subjectIt->Rate, ratesTreshold - ratesSum);
        ratesSum += pointsToDo;
        minReportsCountToDo += pointsToDo * subjectIt->ReportsCount;
        if (ratesSum == ratesTreshold) {
            return minReportsCountToDo;
        }
    }
    return minReportsCountToDo;
}

int main(int argc, char const *argv[]) {
    std::ios_base::sync_with_stdio(false);
    int examQuantity, maxRate, avgRate;
    std::cin >> examQuantity >> maxRate >> avgRate;
    int ratesSum = 0;
    std::vector<TSubjectInfo> subjectInfos;
    for (size_t examCounter = 0; examCounter < examQuantity; ++examCounter) {
        int rate, reportsCount;
        std::cin >> rate >> reportsCount;
        ratesSum += rate;
        if (rate < maxRate) {
            subjectInfos.emplace_back(TSubjectInfo(rate, reportsCount));
        }
    }
    std::cout << GetMinReportsCountToDo(examQuantity, maxRate, avgRate, ratesSum, subjectInfos);
    return 0;
}


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

struct TSubjectInfo {
    int Rate;
    int ReportsCount;
    TSubjectInfo(int rate, int reportsCount) : Rate(rate), ReportsCount(reportsCount) {}
};
bool operator<(const TSubjectInfo& lhs, const TSubjectInfo& rhs) {
    return lhs.ReportsCount < rhs.ReportsCount;
}

unsigned long long int GetMinReportsCountToDo(int examQuantity,
                                              unsigned long long int maxRate,
                                              unsigned long long int avgRate,
                                              unsigned long long int ratesSum,
                                              std::vector<TSubjectInfo>& subjectInfos) {
    unsigned long long int minReportsCountToDo = 0;
    unsigned long long int ratesTreshold = avgRate * examQuantity;
    long long int pointsToDoCount = ratesTreshold - ratesSum;
    if (pointsToDoCount <= 0) {
        return minReportsCountToDo;
    }
    unsigned long long int maxSubjectsToDo =
                        std::min(pointsToDoCount, static_cast<long long int>(subjectInfos.size()));
    std::nth_element(subjectInfos.begin(),
                     subjectInfos.begin() + maxSubjectsToDo, subjectInfos.end());
    std::sort(subjectInfos.begin(), subjectInfos.begin() + maxSubjectsToDo);
    for (auto subjectIt = subjectInfos.begin(); subjectIt != subjectInfos.end(); ++subjectIt) {
        unsigned long long int pointsToDo =
                                    std::min(maxRate - subjectIt->Rate, ratesTreshold - ratesSum);
        ratesSum += pointsToDo;
        minReportsCountToDo += pointsToDo * subjectIt->ReportsCount;
        if (ratesSum == ratesTreshold) {
            return minReportsCountToDo;
        }
    }
    return minReportsCountToDo;
}

int main(int argc, char const *argv[]) {
    std::ios_base::sync_with_stdio(false);
    int examQuantity;
    unsigned long long int maxRate;
    unsigned long long int avgRate;
    std::cin >> examQuantity >> maxRate >> avgRate;
    unsigned long long int ratesSum = 0;
    std::vector<TSubjectInfo> subjectInfos;
    for (size_t examCounter = 0; examCounter < examQuantity; ++examCounter) {
        unsigned long long int rate, reportsCount;
        std::cin >> rate >> reportsCount;
        ratesSum += rate;
        if (rate < maxRate) {
            subjectInfos.emplace_back(TSubjectInfo(rate, reportsCount));
        }
    }
    std::cout << GetMinReportsCountToDo(examQuantity, maxRate, avgRate, ratesSum, subjectInfos);
    return 0;
}


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

struct TSubjectInfo {
    int Rate;
    int ReportsCount;
    TSubjectInfo(int rate, int reportsCount) : Rate(rate), ReportsCount(reportsCount) {}
};
bool operator<(const TSubjectInfo& lhs, const TSubjectInfo& rhs) {
    return lhs.ReportsCount < rhs.ReportsCount;
}

int GetMinReportsCountToDo(int examQuantity, int maxRate, int avgRate, int ratesSum,
                                                        std::vector<TSubjectInfo>& subjectInfos) {
    int minReportsCountToDo = 0;
    int ratesTreshold = avgRate * examQuantity;
    int pointsToDoCount = ratesTreshold - ratesSum;
    if (pointsToDoCount <= 0) {
        return minReportsCountToDo;
    }
    int maxSubjectsToDo = std::min(pointsToDoCount, static_cast<int>(subjectInfos.size()));
    std::nth_element(subjectInfos.begin(),
                     subjectInfos.begin() + maxSubjectsToDo, subjectInfos.end());
    std::sort(subjectInfos.begin(), subjectInfos.begin() + maxSubjectsToDo);
    for (auto subjectIt = subjectInfos.begin(); subjectIt != subjectInfos.end(); ++subjectIt) {
        int pointsToDo = std::min(maxRate - subjectIt->Rate, ratesTreshold - ratesSum);
        ratesSum += pointsToDo;
        minReportsCountToDo += pointsToDo * subjectIt->ReportsCount;
        if (ratesSum == ratesTreshold) {
            return minReportsCountToDo;
        }
    }
    return minReportsCountToDo;
}

int main(int argc, char const *argv[]) {
    std::ios_base::sync_with_stdio(false);
    int examQuantity, maxRate, avgRate;
    std::cin >> examQuantity >> maxRate >> avgRate;
    int ratesSum = 0;
    std::vector<TSubjectInfo> subjectInfos;
    for (size_t examCounter = 0; examCounter < examQuantity; ++examCounter) {
        int rate, reportsCount;
        std::cin >> rate >> reportsCount;
        ratesSum += rate;
        if (rate < maxRate) {
            subjectInfos.emplace_back(TSubjectInfo(rate, reportsCount));
        }
    }
    std::cout << GetMinReportsCountToDo(examQuantity, maxRate, avgRate, ratesSum, subjectInfos);
    return 0;
}


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

struct RateAndReportsCount {
    RateAndReportsCount(int rate, int reportsCount);
    int Rate;
    int ReportsCount;
};

RateAndReportsCount::RateAndReportsCount(int rate, int reportsCount)
                                        : Rate(rate), ReportsCount(reportsCount) {}

bool operator < (const RateAndReportsCount& lhs, const RateAndReportsCount& rhs) {
    return lhs.ReportsCount < rhs.ReportsCount;
}

int GetMinReportsCountToMake(std::vector<RateAndReportsCount>& examResults,
                                    int threshold, int ratesSum, int maxRate) {
    int reportsCountToMake = 0;
    for (auto& rateAndReportsCount : examResults) {
        while (rateAndReportsCount.Rate < maxRate) {
            if (static_cast<double>(ratesSum) >= threshold) {
                return reportsCountToMake;
            }
            reportsCountToMake += rateAndReportsCount.ReportsCount;
            ++rateAndReportsCount.Rate;
            ++ratesSum;
        }

    }
    return reportsCountToMake;
}

int main(int argc, char const *argv[]) {
    std::ios_base::sync_with_stdio(false);
    int examsQuantity, maxRate, avgRate;
    std::cin >> examsQuantity >> maxRate >> avgRate;
    std::vector<RateAndReportsCount> examResults;
    int ratesSum = 0;
    for (size_t examCounter = 0; examCounter < examsQuantity; ++examCounter) {
        int rate, reportsCount;
        std::cin >> rate >> reportsCount;
        ratesSum += rate;
        if (rate != maxRate) {
            examResults.emplace_back(RateAndReportsCount(rate, reportsCount));
        }
    }
    std::sort(examResults.begin(), examResults.end());
    std::cout << GetMinReportsCountToMake(examResults, examsQuantity * avgRate, ratesSum, maxRate);
    return 0;
}


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

struct RateAndReportsCount {
    RateAndReportsCount(int rate, int reportsCount);
    int Rate;
    int ReportsCount;
};

RateAndReportsCount::RateAndReportsCount(int rate, int reportsCount)
                                        : Rate(rate), ReportsCount(reportsCount) {}

bool operator < (const RateAndReportsCount& lhs, const RateAndReportsCount& rhs) {
    return lhs.ReportsCount < rhs.ReportsCount;
}

int GetMinReportsCountToMake(std::vector<RateAndReportsCount>::iterator first,
                             std::vector<RateAndReportsCount>::iterator last,
                             int threshold, int ratesSum, int maxRate) {
    int reportsCountToMake = 0;
    while (first != last && ratesSum < threshold) {
        int min = std::min(threshold - ratesSum, maxRate - first->Rate);
        reportsCountToMake += min * first->ReportsCount;
        ++first;
        ratesSum += min;
    }
    return reportsCountToMake;
}

int main(int argc, char const *argv[]) {
    std::ios_base::sync_with_stdio(false);
    int examsQuantity, maxRate, avgRate;
    std::cin >> examsQuantity >> maxRate >> avgRate;
    std::vector<RateAndReportsCount> examResults;
    int ratesSum = 0;
    for (size_t examCounter = 0; examCounter < examsQuantity; ++examCounter) {
        int rate, reportsCount;
        std::cin >> rate >> reportsCount;
        ratesSum += rate;
        if (rate != maxRate) {
            examResults.emplace_back(RateAndReportsCount(rate, reportsCount));
        }
    }
    int threshold = examsQuantity * avgRate;
    int needRates = threshold - ratesSum;
    if (needRates < 0) {
        std::cout << 0;
        return 0;
    }
    std::nth_element(examResults.begin(), examResults.begin() + needRates, examResults.end());
    std::sort(examResults.begin(), examResults.begin() + needRates);
    std::cout << GetMinReportsCountToMake(examResults.begin(), examResults.begin() + needRates,
                                          threshold, ratesSum, maxRate);
    return 0;
}


#include <iostream>
#include <iomanip>
#include <algorithm>
#include <utility>
using namespace std;

typedef long long ll;

pair<ll, ll> a[111111];

int main()
{
    ll n, r, avg;
    cin >> n >> r >> avg;
    ll tot = 0, ans = 0;
    for (int i = 1; i <= n; ++ i) {
         cin >> a[i].second >> a[i].first;
         tot += a[i].first;
    }
    tot = avg * n - tot;
    sort(a + 1, a + 1 + n);
    int pt = 1;
    while(tot) {
        if (pt == n + 1)
                break;
        ll need = min(r - a[pt].second, tot);
        ans += need * a[pt].first;
        tot -= need;
        pt ++;
    }
    cout << ans <<endl;
   //cin >> n;
    return 0;
}


#include <iostream>
#include <iomanip>
#include <algorithm>
#include <utility>
using namespace std;

typedef long long ll;

pair<ll, ll> a[111111];

int main()
{
    ll n, r, avg;
    cin >> n >> r >> avg;
    ll tot = 0, ans = 0;
    for (int i = 1; i <= n; ++ i) {
         cin >> a[i].second >> a[i].first;
         tot += a[i].second;
    }
    tot = avg * n - tot;
    sort(a + 1, a + 1 + n);
    int pt = 1;
    while(tot) {
        if (pt == n + 1)
                break;
        ll need = min(r - a[pt].second, tot);
        ans += need * a[pt].first;
        tot -= need;
        pt ++;
    }
    cout << ans <<endl;
   cin >> n;
    return 0;
}


#include <iostream>
#include <iomanip>
#include <algorithm>
#include <utility>
using namespace std;

typedef long long ll;

pair<ll, ll> a[111111];

int main()
{
    ll n, r, avg;
    cin >> n >> r >> avg;
    ll tot = 0, ans = 0;
    for (int i = 1; i <= n; ++ i) {
         cin >> a[i].second >> a[i].first;
         tot += a[i].second;
    }
    tot = avg * n - tot;
    {
        if (tot < 0) { cout << 0 <<endl; return 0;}
    }
    sort(a + 1, a + 1 + n);
    int pt = 1;
    while(tot) {
        if (pt == n + 1)
                break;
        ll need = min(r - a[pt].second, tot);
        ans += need * a[pt].first;
        tot -= need;
        pt ++;
    }
    cout << ans <<endl;
   // cin >> n;
    return 0;
}


#include <iostream>
#include <iomanip>
#include <algorithm>
#include <utility>
using namespace std;
pair<int, int> a[111111];

typedef long long ll;

int main()
{
    ll n, r, avg;
    cin >> n >> r >> avg;
    ll tot = 0, ans = 0;
    for (int i = 1; i <= n; ++ i) {
         cin >> a[i].second >> a[i].first;
         tot += a[i].first;
    }
    tot = avg * n - tot;
    sort(a + 1, a + 1 + n);
    int pt = 1;
    while(tot) {
        if (pt == n + 1)
                break;
        ll need = min(r - a[pt].second, tot);
        ans += need * a[pt].first;
        tot -= need;
        pt ++;
    }
    cout << ans <<endl;
   //cin >> n;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int modo=10000007,LL=1e-9;

int main()
{
    ios_base::sync_with_stdio(0);

 int n,r,v;
 cin>>n>>r>>v;
 vector<pair<int,int> >v1(n);
 int sum=0;
 for(int i=0;i<n;i++)
 {
     cin>>v1[i].second>>v1[i].first;
     sum+=v1[i].first;
 }
 if(sum/n>=v){cout<<0<<endl;return 0;}
 int dif=n*v-sum,ans=0;

 sort(v1.begin(),v1.end());
 for(int i=0;i<n;i++)
 {
     if(v1[i].second<r)
     {
         int g=r-v1[i].second;
         if(g>=dif)
         {
             dif=0;
             ans+=v1[i].first;break;
         }
         else ans+=v1[i].first*g,dif-=g;
     }
 }
 cout<<ans<<endl;
}


#include <bits/stdc++.h>

using namespace std;

const int modo=10000007,LL=1e-9;

int main()
{
    ios_base::sync_with_stdio(0);

 int n,r,v;
 cin>>n>>r>>v;
 vector<pair<int,int> >v1(n);
 long long int sum=0;
 for(int i=0;i<n;i++)
 {
     cin>>v1[i].second>>v1[i].first;
     sum+=v1[i].second;
 }
 if(sum>=v*n){cout<<0<<endl;return 0;}
 long long int dif=n*v-sum,ans=0;

 sort(v1.begin(),v1.end());
 for(int i=0;i<n;i++)
 {
     if(v1[i].second<r)
     {
         int g=r-v1[i].second;
         if(g>=dif)
         {
             ans+=v1[i].first*dif;

             dif=0;break;
         }
         else ans+=v1[i].first*g,dif-=g;
     }
 }
 cout<<ans<<endl;
}


#include <bits/stdc++.h>

using namespace std;

const int modo=10000007,LL=1e-9;

int main()
{
    ios_base::sync_with_stdio(0);

 int n,r,v;
 cin>>n>>r>>v;
 vector<pair<int,int> >v1(n);
 long long int sum=0;
 for(int i=0;i<n;i++)
 {
     cin>>v1[i].second>>v1[i].first;
     sum+=v1[i].second;
 }
 if(sum>=v*n){cout<<0<<endl;return 0;}
 long long int dif=n*v-sum,ans=0;

 sort(v1.begin(),v1.end());
 for(int i=0;i<n;i++)
 {
     if(v1[i].second<r)
     {
         int g=r-v1[i].second;
         if(g>=dif)
         {
             dif=0;
             ans+=v1[i].first;break;
         }
         else ans+=v1[i].first*g,dif-=g;
     }
 }
 cout<<ans<<endl;
}


#include <bits/stdc++.h>

using namespace std;

const int modo=10000007,LL=1e-9;

int main()
{
    ios_base::sync_with_stdio(0);

 long long int n,r,v;
 cin>>n>>r>>v;
 vector<pair<long long int,long long int> >v1(n);
 long long int sum=0;
 for(int i=0;i<n;i++)
 {
     cin>>v1[i].second>>v1[i].first;
     sum+=v1[i].second;
 }
 if(sum>=v*n){cout<<0<<endl;return 0;}
 long long int dif=n*v-sum,ans=0;

 sort(v1.begin(),v1.end());
 for(int i=0;i<n;i++)
 {
     if(v1[i].second<r)
     {
         int g=r-v1[i].second;
         if(g>=dif)
         {
             ans+=v1[i].first*dif;

             dif=0;break;
         }
         else ans+=v1[i].first*g,dif-=g;
     }
 }
 cout<<ans<<endl;
}


#include <bits/stdc++.h>

using namespace std;

const int modo=10000007,LL=1e-9;

int main()
{
    ios_base::sync_with_stdio(0);

 int n,r,v;
 cin>>n>>r>>v;
 vector<pair<int,int> >v1(n);
 int sum=0;
 for(int i=0;i<n;i++)
 {
     cin>>v1[i].second>>v1[i].first;
     sum+=v1[i].second;
 }
 if(sum>=v*n){cout<<0<<endl;return 0;}
 int dif=n*v-sum,ans=0;

 sort(v1.begin(),v1.end());
 for(int i=0;i<n;i++)
 {
     if(v1[i].second<r)
     {
         int g=r-v1[i].second;
         if(g>=dif)
         {
             dif=0;
             ans+=v1[i].first;break;
         }
         else ans+=v1[i].first*g,dif-=g;
     }
 }
 cout<<ans<<endl;
}


#include <bits/stdc++.h>

using namespace std;

const int modo=10000007,LL=1e-9;

int main()
{
    ios_base::sync_with_stdio(0);

 int n,r,v;
 cin>>n>>r>>v;
 vector<pair<int,int> >v1(n);
 int sum=0;
 for(int i=0;i<n;i++)
 {
     cin>>v1[i].second>>v1[i].first;
     sum+=v1[i].second;
 }
 if((double)sum/n>=v){cout<<0<<endl;return 0;}
 int dif=n*v-sum,ans=0;

 sort(v1.begin(),v1.end());
 for(int i=0;i<n;i++)
 {
     if(v1[i].second<r)
     {
         int g=r-v1[i].second;
         if(g>=dif)
         {
             dif=0;
             ans+=v1[i].first;break;
         }
         else ans+=v1[i].first*g,dif-=g;
     }
 }
 cout<<ans<<endl;
}


#include <bits/stdc++.h>

using namespace std;

const int modo=10000007,LL=1e-9;

int main()
{
    ios_base::sync_with_stdio(0);

 int n,r,v;
 cin>>n>>r>>v;
 vector<pair<int,int> >v1(n);
 int sum=0;
 for(int i=0;i<n;i++)
 {
     cin>>v1[i].second>>v1[i].first;
     sum+=v1[i].first;
 }
 if((double)sum/n>=v){cout<<0<<endl;return 0;}
 int dif=n*v-sum,ans=0;

 sort(v1.begin(),v1.end());
 for(int i=0;i<n;i++)
 {
     if(v1[i].second<r)
     {
         int g=r-v1[i].second;
         if(g>=dif)
         {
             dif=0;
             ans+=v1[i].first;break;
         }
         else ans+=v1[i].first*g,dif-=g;
     }
 }
 cout<<ans<<endl;
}


#include <bits/stdc++.h>

using namespace std;

const int modo=10000007,LL=1e-9;

int main()
{
    ios_base::sync_with_stdio(0);

 int n,r,v;
 cin>>n>>r>>v;
 vector<pair<long long int,long long int> >v1(n);
 long long int sum=0;
 for(int i=0;i<n;i++)
 {
     cin>>v1[i].second>>v1[i].first;
     sum+=v1[i].second;
 }
 if(sum>=v*n){cout<<0<<endl;return 0;}
 long long int dif=n*v-sum,ans=0;

 sort(v1.begin(),v1.end());
 for(int i=0;i<n;i++)
 {
     if(v1[i].second<r)
     {
         int g=r-v1[i].second;
         if(g>=dif)
         {
             ans+=v1[i].first*dif;

             dif=0;break;
         }
         else ans+=v1[i].first*g,dif-=g;
     }
 }
 cout<<ans<<endl;
}


#include <bits/stdc++.h>

using namespace std;

const int modo=10000007,LL=1e-9;

int main()
{
    ios_base::sync_with_stdio(0);

 int n,r,v;
 cin>>n>>r>>v;
 vector<pair<int,int> >v1(n);
 long long int sum=0;
 for(int i=0;i<n;i++)
 {
     cin>>v1[i].second>>v1[i].first;
     sum+=v1[i].second;
 }
 if(sum>=v*n){cout<<0<<endl;return 0;}
 long long int dif=n*v-sum,ans=0;

 sort(v1.begin(),v1.end());
 for(int i=0;i<n;i++)
 {
     if(v1[i].second<r)
     {
         int g=r-v1[i].second;
         if(g>=dif)
         {
             ans+=v1[i].first*diff;

             dif=0;break;
         }
         else ans+=v1[i].first*g,dif-=g;
     }
 }
 cout<<ans<<endl;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <cstring>
#include <set>
#include <ctime>
#include <stack>
#include <iterator>

using namespace std;

#define inf 2147483647
#define eps 0.0000000001
#define e  2.718281828459
#define pi 3.1415926535897932
#define mod 1000000007
#define LL long long
#define ULL unsigned long long
#define LD long double

//	memset(array, value, sizeof(array));
//	cout<<fixed<<setprecision(3)<<"\nExecution time="<<clock()/1000.0<<endl;
//	freopen("input.txt","r",stdin);
//	freopen("output.txt","w",stdout);
const int N = 100005;
struct vahag
{
	LL val, ref;
};

bool operator<(const vahag&a, const vahag&b)
{
	return a.ref < b.ref;
}

vahag a[N];
LL n, m, i, j, k, q, s, w, v,l,ans;
LD mid;
LL findmin(LL);
LL r, avg;

int main()
{
	cin >> n >> r >> avg;
	for (i = 1; i <= n; i++)
	{
		cin >> a[i].val >> a[i].ref;
		mid += a[i].val;
	}
	avg*=n;
	if (mid >= (LD)(avg))
	{
		cout << 0 << endl;
		return 0;
	}

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

	for (i = 1; i <= n; i++)
	{
		LL diff = r - a[i].val;
		if (mid + (LD)(diff) >= (LD)(avg))
		{
			cout << ans + findmin(diff)*a[i].ref;
			return 0;
		}
		else
		{
			ans += diff*a[i].ref;
			mid = mid + (LD)(diff);
		}
	}
	cout << ans << endl;
	return 0;
}

LL findmin(LL r)
{
	LL ans = 1e15;
	LL l = 1;
	while (l < r)
	{
		LL m = (l + r) / 2;
		if (mid + (LD)(m) >= (LD)(avg))
		{
			ans = min(ans, m);
			r = m - 1;
			continue;
		}
		else
		{
			l = m + 1;
			continue;
		}
	}
	if (l == r)
	{
		m = l;
		if (mid + (m) / (LD)(n) >= (LD)(avg))
			ans = min(ans, m);
	}
	return ans;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <cstring>
#include <set>
#include <ctime>
#include <stack>
#include <iterator>

using namespace std;

#define inf 2147483647
#define eps 0.0000000001
#define e  2.718281828459
#define pi 3.1415926535897932
#define mod 1000000007
#define LL long long
#define ULL unsigned long long
#define LD long double

//	memset(array, value, sizeof(array));
//	cout<<fixed<<setprecision(3)<<"\nExecution time="<<clock()/1000.0<<endl;
//	freopen("input.txt","r",stdin);
//	freopen("output.txt","w",stdout);
const int N = 100005;
struct vahag
{
	LL val, ref;
};

bool operator<(const vahag&a, const vahag&b)
{
	return a.ref < b.ref;
}

vahag a[N];
LL n, m, i, j, k, q, s, w, v,l,ans;
LD mid;
LL findmin(LL);
LL r, avg;

int main()
{
	cin >> n >> r >> avg;
	for (i = 1; i <= n; i++)
	{
		cin >> a[i].val >> a[i].ref;
		mid += a[i].val;
	}
	mid /= LD(n);
	if (mid >= LD(avg))
	{
		cout << 0 << endl;
		return 0;
	}

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

	for (i = 1; i <= n; i++)
	{
		LL diff = r - a[i].val;
		if (mid + LD(diff) / LD(n) >= LD(avg))
		{
			cout << ans + findmin(diff)*a[i].ref;
			return 0;
		}
		else
		{
			ans += diff*a[i].ref;
			mid = mid + LD(diff) / LD(n);
		}
	}
	cout << ans << endl;
	return 0;
}

LL findmin(LL r)
{
	LL ans = 1e15;
	LL l = 1;
	while (l < r)
	{
		LL m = (l + r) / 2;
		if (mid + LD(m) / LD(n) >= LD(avg))
		{
			ans = min(ans, m);
			r = m - 1;
			continue;
		}
		else
		{
			l = m + 1;
			continue;
		}
	}
	if (l == r)
	{
		m = (l+r)/2;
		if (mid + LD(m) / LD(n) >= LD(avg))
			ans = min(ans, m);
	}
	return ans;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <cstring>
#include <set>
#include <ctime>
#include <stack>
#include <iterator>

using namespace std;

#define inf 2147483647
#define eps 0.0000000001
#define e  2.718281828459
#define pi 3.1415926535897932
#define mod 1000000007
#define LL long long
#define ULL unsigned long long
#define LD long double

//	memset(array, value, sizeof(array));
//	cout<<fixed<<setprecision(3)<<"\nExecution time="<<clock()/1000.0<<endl;
//	freopen("input.txt","r",stdin);
//	freopen("output.txt","w",stdout);
const int N = 100005;
struct vahag
{
	LL val, ref;
};

bool operator<(const vahag&a, const vahag&b)
{
	return a.ref < b.ref;
}

vahag a[N];
LL n, m, i, j, k, q, s, w, v,l,ans;
LD mid;
LL findmin(LL);
LL r, avg;

int main()
{
	cin >> n >> r >> avg;
	for (i = 1; i <= n; i++)
	{
		cin >> a[i].val >> a[i].ref;
		mid += a[i].val;
	}
	mid /= (LD)(n);
	if (mid >= (LD)(avg))
	{
		cout << 0 << endl;
		return 0;
	}

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

	for (i = 1; i <= n; i++)
	{
		LL diff = r - a[i].val;
		if (mid + (LD)(diff) / (LD)(n) >= (LD)(avg))
		{
			cout << ans + findmin(diff)*a[i].ref;
			return 0;
		}
		else
		{
			ans += diff*a[i].ref;
			mid = mid + (LD)(diff) / (LD)(n);
		}
	}
	cout << ans << endl;
	return 0;
}

LL findmin(LL r)
{
	LL ans = 1e15;
	LL l = 1;
	while (l < r)
	{
		LL m = (l + r) / 2;
		if (mid + (LD)(m) / (LD)(n) >= (LD)(avg))
		{
			ans = min(ans, m);
			r = m - 1;
			continue;
		}
		else
		{
			l = m + 1;
			continue;
		}
	}
	if (l == r)
	{
		m = (l+r)/2;
		if (mid + (m) / (LD)(n) >= (LD)(avg))
			ans = min(ans, m);
	}
	return ans;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <cstring>
#include <set>
#include <ctime>
#include <stack>
#include <iterator>

using namespace std;

#define inf 2147483647
#define eps 0.0000000001
#define e  2.718281828459
#define pi 3.1415926535897932
#define mod 1000000007
#define LL long long
#define ULL unsigned long long
#define LD long double

//	memset(array, value, sizeof(array));
//	cout<<fixed<<setprecision(3)<<"\nExecution time="<<clock()/1000.0<<endl;
//	freopen("input.txt","r",stdin);
//	freopen("output.txt","w",stdout);
const int N = 100005;
struct vahag
{
	LL val, ref;
};

bool operator<(const vahag&a, const vahag&b)
{
	return a.ref < b.ref;
}

vahag a[N];
LL n, m, i, j, k, q, s, w, v,l,ans;
LD mid;
LL findmin(LL);
LL r, avg;

int main()
{
	cin >> n >> r >> avg;
	for (i = 1; i <= n; i++)
	{
		cin >> a[i].val >> a[i].ref;
		mid += a[i].val;
	}
	avg*=n;
	if (mid >= (LD)(avg))
	{
		cout << 0 << endl;
		return 0;
	}

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

	for (i = 1; i <= n; i++)
	{
		LL diff = r - a[i].val;
		if (mid + (LD)(diff) >= (LD)(avg))
		{
			cout << ans + findmin(diff)*a[i].ref;
			return 0;
		}
		else
		{
			ans += diff*a[i].ref;
			mid = mid + (LD)(diff);
		}
	}
	cout << ans << endl;
	return 0;
}

LL findmin(LL r)
{
	LL ans = 1e15;
	LL l = 1;
	while (l < r)
	{
		LL m = (l + r) / 2;
		if (mid + (LD)(m) >= (LD)(avg))
		{
			ans = min(ans, m);
			r = m - 1;
			continue;
		}
		else
		{
			l = m + 1;
			continue;
		}
	}
	if (l == r)
	{
		m = l;
		if (mid + (m) >= (LD)(avg))
			ans = min(ans, m);
	}
	return ans;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <cstring>
#include <set>
#include <ctime>
#include <stack>
#include <iterator>

using namespace std;

#define inf 2147483647
#define eps 0.0000000001
#define e  2.718281828459
#define pi 3.1415926535897932
#define mod 1000000007
#define LL long long
#define ULL unsigned long long
#define LD long double

//	memset(array, value, sizeof(array));
//	cout<<fixed<<setprecision(3)<<"\nExecution time="<<clock()/1000.0<<endl;
//	freopen("input.txt","r",stdin);
//	freopen("output.txt","w",stdout);
const int N = 100005;
struct vahag
{
	LL val, ref;
};

bool operator<(const vahag&a, const vahag&b)
{
	return a.ref < b.ref;
}

vahag a[N];
LL n, m, i, j, k, q, s, w, v,l,ans;
LD mid;
LL findmin(LL);
LL r, avg;

int main()
{
	cin >> n >> r >> avg;
	for (i = 1; i <= n; i++)
	{
		cin >> a[i].val >> a[i].ref;
		mid += a[i].val;
	}
	mid /= (LD)(n);
	if (mid >= (LD)(avg))
	{
		cout << 0 << endl;
		return 0;
	}

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

	for (i = 1; i <= n; i++)
	{
		LL diff = r - a[i].val;
		if (mid + (LD)(diff) / (LD)(n) >= (LD)(avg))
		{
			cout << ans + findmin(diff)*a[i].ref;
			return 0;
		}
		else
		{
			ans += diff*a[i].ref;
			mid = mid + (LD)(diff) / (LD)(n);
		}
	}
	cout << ans << endl;
	return 0;
}

LL findmin(LL r)
{
	LL ans = 1e15;
	LL l = 1;
	while (l < r)
	{
		LL m = (l + r) / 2;
		if (mid + (LD)(m) / (LD)(n) >= (LD)(avg))
		{
			ans = min(ans, m);
			r = m - 1;
			continue;
		}
		else
		{
			l = m + 1;
			continue;
		}
	}
	if (l == r)
	{
		m = l;
		if (mid + (m) / (LD)(n) >= (LD)(avg))
			ans = min(ans, m);
	}
	return ans;
}


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

#define fs first
#define sc second
#define MP make_pair
using namespace std;

int main(){

	long long n, r, avg, suma=0, a ,b, oczekiwana;
	long long wynik=0;

	scanf("%d%d%d", &n, &r, &avg);

	vector<pair<long long, long long> > tab;

	for(int i=0; i<n; i++) {
		scanf("%d%d", &a, &b);
		suma+=a;
		if(r-a>0) tab.push_back(MP(b, r-a));
	}

    oczekiwana = n*avg - suma;
    if (oczekiwana<=0) printf("0");
    else {
		sort(tab.begin(), tab.end());
		for(int i=0; i<tab.size(); i++) {
			if(tab[i].sc>=oczekiwana) { wynik+=oczekiwana*(long long)tab[i].fs; break; }
			else  { oczekiwana-=tab[i].sc; wynik+=(long long)tab[i].fs * tab[i].sc; }
		}
	printf("%I64dd", wynik);
	}
	return 0;
}


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

#define fs first
#define sc second
#define MP make_pair
using namespace std;

int main(){

	int n, r, avg, suma=0, a ,b, oczekiwana, wynik=0;
	scanf("%d%d%d", &n, &r, &avg);

	vector<pair<int, int> > tab;

	for(int i=0; i<n; i++) {
		scanf("%d%d", &a, &b);
		suma+=a;
		if(r-a>0) tab.push_back(MP(b, r-a));
	}

    oczekiwana = n*avg - suma;
    if (oczekiwana<=0) printf("0");
    else {
		sort(tab.begin(), tab.end());
		for(int i=0; i<tab.size(); i++) {
			if(tab[i].sc>=oczekiwana) { wynik+=oczekiwana*tab[i].fs; break; }
			else  { oczekiwana-=tab[i].sc; wynik+=tab[i].fs * tab[i].sc; }
		}
	printf("%d", wynik);
	}
	return 0;
}


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

#define fs first
#define sc second
#define MP make_pair
using namespace std;

long long main(){

	long long n, r, avg, suma=0, a ,b, oczekiwana;
	long long wynik=0;

	scanf("%I64d%I64d%I64d", &n, &r, &avg);

	vector<pair<long long, long long> > tab;

	for(long long i=0; i<n; i++) {
		scanf("%I64d%I64d", &a, &b);
		suma+=a;
		if(r-a>0) tab.push_back(MP(b, r-a));
	}

    oczekiwana = n*avg - suma;
    if (oczekiwana<=0) prlong longf("0");
    else {
		sort(tab.begin(), tab.end());
		for(long long i=0; i<tab.size(); i++) {
			if(tab[i].sc>=oczekiwana) { wynik+=oczekiwana*(long long)tab[i].fs; break; }
			else  { oczekiwana-=tab[i].sc; wynik+=(long long)tab[i].fs * tab[i].sc; }
		}
	prlong longf("%I64d", wynik);
	}
	return 0;
}


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

#define fs first
#define sc second
#define MP make_pair
using namespace std;

int main(){

	int n, r, avg, suma=0, a ,b, oczekiwana;
	long long wynik=0;

	scanf("%d%d%d", &n, &r, &avg);

	vector<pair<int, int> > tab;

	for(int i=0; i<n; i++) {
		scanf("%d%d", &a, &b);
		suma+=a;
		if(r-a>0) tab.push_back(MP(b, r-a));
	}

    oczekiwana = n*avg - suma;
    if (oczekiwana<=0) printf("0");
    else {
		sort(tab.begin(), tab.end());
		for(int i=0; i<tab.size(); i++) {
			if(tab[i].sc>=oczekiwana) { wynik+=oczekiwana*(long long)tab[i].fs; break; }
			else  { oczekiwana-=tab[i].sc; wynik+=(long long)tab[i].fs * tab[i].sc; }
		}
	printf("%I64d", wynik);
	}
	return 0;
}


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

#define fs first
#define sc second
#define MP make_pair
using namespace std;

int main(){

	long long n, r, avg, suma=0, a ,b, oczekiwana;
	long long wynik=0;

	scanf("%I64d%I64d%I64d", &n, &r, &avg);

	vector<pair<long long, long long> > tab;

	for(long long i=0; i<n; i++) {
		scanf("%I64d%I64d", &a, &b);
		suma+=a;
		if(r-a>0) tab.push_back(MP(b, r-a));
	}

    oczekiwana = n*avg - suma;
    if (oczekiwana<=0) printf("0");
    else {
		sort(tab.begin(), tab.end());
		for(long long i=0; i<tab.size(); i++) {
			if(tab[i].sc>=oczekiwana) { wynik+=oczekiwana*(long long)tab[i].fs; break; }
			else  { oczekiwana-=tab[i].sc; wynik+=(long long)tab[i].fs * tab[i].sc; }
		}
	printf("%I64d", wynik);
	}
	return 0;
}


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

struct st {
    int a, b;
    st(int i, int j) {
        a = i;
        b = j;
    }
};

int main() {
    int n, r, avg;
    cin >> n >> r >> avg;
    int tmp1, tmp2;
    vector<st> v;
    int s = 0;
    for(int i = 0; i < n; i++) {
        cin >> tmp1 >> tmp2;
        v.emplace_back(tmp1, tmp2);
        s += tmp1;
    }
    sort(v.begin(), v.end(), [](st s1, st s2) {return s1.b < s2.b;});
    int req = max(0, avg * n - s);
    int ans = 0;
    for(auto i : v) {
        int can = r - i.a;
        int will = min(req, can);
        req -= will;
        ans += i.b * will;
        if(req == 0)
            break;
    }
    cout << ans;
}


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

struct st {
    int a, b;
    st(int i, int j) {
        a = i;
        b = j;
    }
};

int main() {
    long long n, r, avg;
    cin >> n >> r >> avg;
    int tmp1, tmp2;
    vector<st> v;
    long long s = 0;
    for(int i = 0; i < n; i++) {
        cin >> tmp1 >> tmp2;
        v.emplace_back(tmp1, tmp2);
        s += tmp1;
    }
    sort(v.begin(), v.end(), [](st s1, st s2) {return s1.b < s2.b;});
    long long req = max(0ll, avg * n - s);
    unsigned long long ans = 0;
    for(auto i : v) {
        if(req == 0)
            break;
        long long can = r - i.a;
        long long will = min(req, can);
        req -= will;
        ans += i.b * will;
    }
    cout << ans;
}


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

struct st {
    int a, b;
    st(int i, int j) {
        a = i;
        b = j;
    }
};

int main() {
    int n, r, avg;
    cin >> n >> r >> avg;
    int tmp1, tmp2;
    vector<st> v;
    int s = 0;
    for(int i = 0; i < n; i++) {
        cin >> tmp1 >> tmp2;
        v.emplace_back(tmp1, tmp2);
        s += tmp1;
    }
    sort(v.begin(), v.end(), [](st s1, st s2) {return s1.b < s2.b;});
    int req = max(0, avg * n - s);
    unsigned long long ans = 0;
    for(auto i : v) {
        if(req == 0)
            break;
        int can = r - i.a;
        int will = min(req, can);
        req -= will;
        ans += i.b * will;
    }
    cout << ans;
}


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

struct st {
    int a, b;
    st(int i, int j) {
        a = i;
        b = j;
    }
};

int main() {
    long long n, r, avg;
    cin >> n >> r >> avg;
    int tmp1, tmp2;
    vector<st> v;
    long long s = 0;
    for(int i = 0; i < n; i++) {
        cin >> tmp1 >> tmp2;
        v.emplace_back(tmp1, tmp2);
        s += tmp1;
    }
    sort(v.begin(), v.end(), [](st s1, st s2) {return s1.b < s2.b;});
    long long req = max(0, avg * n - s);
    unsigned long long ans = 0;
    for(auto i : v) {
        if(req == 0)
            break;
        long long can = r - i.a;
        long long will = min(req, can);
        req -= will;
        ans += i.b * will;
    }
    cout << ans;
}


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

using namespace std;

bool operator<(const pair<long, long>& lhs, const pair<long, long>& rhs) {
	if (lhs.first == rhs.first) return lhs.second < rhs.second;
	else return lhs.first < rhs.first;
}

int main() {
	int n, avg;
	long r;
	cin >> n >> r >> avg;
	vector<pair<long, long> > exams_and_essays;
	long long total_score = 0;
	for (int i = 0; i < n; ++i) {
		long long t1, t2;
		cin >> t1 >> t2;
		exams_and_essays.push_back(std::make_pair(t2,t1));
		total_score += t1;
	}
	long long total_score_needed = n * avg;
	if (total_score >= total_score_needed) cout << "0\n";
	else {
		long num_essays = 0;
		int score_needed = total_score_needed - total_score;
		sort(exams_and_essays.begin(), exams_and_essays.end());
		while (score_needed > 1) {
			for (int i = 0; i < n && score_needed > 0; ++i) {
				while (exams_and_essays[i].second < r && score_needed > 0) {
					num_essays += exams_and_essays[i].first;
					++exams_and_essays[i].second;
					--score_needed;
				}
			}
		}
		cout << num_essays << "\n";
	}
	return 0;
}


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

using namespace std;

bool operator<(const pair<int, int>& lhs, const pair<int, int>& rhs) {
	if (lhs.first == rhs.first) return lhs.second < rhs.second;
	else return lhs.first < rhs.first;
}

int main() {
	int n, avg;
	long long r;
	cin >> n >> r >> avg;
	vector<pair<long long, long long> > exams_and_essays;
	long long total_score = 0;
	for (int i = 0; i < n; ++i) {
		long long t1, t2;
		cin >> t1 >> t2;
		exams_and_essays.push_back(std::make_pair(t2,t1));
		total_score += t1;
	}
	long long total_score_needed = n * avg;
	if (total_score >= total_score_needed) cout << "0\n";
	else {
		long long num_essays = 0;
		long long score_needed = total_score_needed - total_score;
		sort(exams_and_essays.begin(), exams_and_essays.end());
		while (score_needed > 1) {
			for (int i = 0; i < n; ++i) {
				while (exams_and_essays[i].second < r && score_needed > 0) {
					num_essays += exams_and_essays[i].first;
					++exams_and_essays[i].second;
					--score_needed;
				}
			}
		}
		cout << num_essays << "\n";
	}
	return 0;
}


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

using namespace std;

bool operator<(const pair<long, long>& lhs, const pair<long, long>& rhs) {
	if (lhs.first == rhs.first) return lhs.second < rhs.second;
	else return lhs.first < rhs.first;
}

int main() {
	int n, avg;
	long long r;
	cin >> n >> r >> avg;
	vector<pair<long, long> > exams_and_essays;
	long long total_score = 0;
	for (int i = 0; i < n; ++i) {
		long long t1, t2;
		cin >> t1 >> t2;
		if (t1 < r) exams_and_essays.push_back(std::make_pair(t2,t1));
		total_score += t1;
	}
	long long total_score_needed = n * avg;
	if (total_score >= total_score_needed) cout << "0\n";
	else {
		long long num_essays = 0;
		long long score_needed = total_score_needed - total_score;
		sort(exams_and_essays.begin(), exams_and_essays.end());

		for (int i = 0; i < exams_and_essays.size(); ++i) {
			long long score_change = r - exams_and_essays[i].second;
			score_needed -= score_change;
			num_essays += score_change*exams_and_essays[i].first;
			if (score_needed <= 0) {
				num_essays += score_needed*exams_and_essays[i].first;
				break;
			}
		}
		cout << num_essays << "\n";
	}
	return 0;
}


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

using namespace std;

bool operator<(const pair<unsigned long, unsigned long>& lhs, const pair<unsigned long, unsigned long>& rhs) {
	if (lhs.first == rhs.first) return lhs.second < rhs.second;
	else return lhs.first < rhs.first;
}

int main() {
	int n, avg;
	long r;
	cin >> n >> r >> avg;
	vector<pair<unsigned long, unsigned long> > exams_and_essays;
	unsigned long long total_score = 0;
	for (int i = 0; i < n; ++i) {
		long long t1, t2;
		cin >> t1 >> t2;
		exams_and_essays.push_back(std::make_pair(t2,t1));
		total_score += t1;
	}
	long long total_score_needed = n * avg;
	if (total_score >= total_score_needed) cout << "0\n";
	else {
		unsigned long long num_essays = 0;
		int score_needed = total_score_needed - total_score;
		sort(exams_and_essays.begin(), exams_and_essays.end());
		while (score_needed > 1) {
			for (int i = 0; i < n && score_needed > 0; ++i) {
				while (exams_and_essays[i].second < r && score_needed > 0) {
					num_essays += exams_and_essays[i].first;
					++exams_and_essays[i].second;
					--score_needed;
				}
			}
		}
		cout << num_essays << "\n";
	}
	return 0;
}


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

using namespace std;

bool operator<(const pair<unsigned long long, unsigned long long>& lhs, const pair<unsigned long long, unsigned long long>& rhs) {
	if (lhs.first == rhs.first) return lhs.second < rhs.second;
	else return lhs.first < rhs.first;
}

int main() {
	long long n, avg;
	unsigned long long r;
	cin >> n >> r >> avg;
	vector<pair<unsigned long long, unsigned long long> > exams_and_essays;
	unsigned long long total_score = 0;
	for (int i = 0; i < n; ++i) {
		unsigned long long t1, t2;
		cin >> t1 >> t2;
		if (t1 < r) exams_and_essays.push_back(std::make_pair(t2,t1));
		total_score += t1;
	}
	unsigned long long total_score_needed = n * avg;
	if (total_score >= total_score_needed) cout << "0\n";
	else {
		unsigned long long num_essays = 0;
		unsigned long long score_needed = total_score_needed - total_score;
		sort(exams_and_essays.begin(), exams_and_essays.end());

		for (int i = 0; i < exams_and_essays.size(); ++i) {
			unsigned long long score_change = r - exams_and_essays[i].second;
			if (score_change > score_needed) score_change = score_needed;
			score_needed -= score_change;
			num_essays += score_change*exams_and_essays[i].first;
			if (score_needed == 0) break;
		}
		cout << num_essays << "\n";
	}
	return 0;
}


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

using namespace std;

bool operator<(const pair<long, long>& lhs, const pair<long, long>& rhs) {
	if (lhs.first == rhs.first) return lhs.second < rhs.second;
	else return lhs.first < rhs.first;
}

int main() {
	int n, avg;
	long r;
	cin >> n >> r >> avg;
	vector<pair<long, long> > exams_and_essays;
	long long total_score = 0;
	for (int i = 0; i < n; ++i) {
		long long t1, t2;
		cin >> t1 >> t2;
		exams_and_essays.push_back(std::make_pair(t2,t1));
		total_score += t1;
	}
	long long total_score_needed = n * avg;
	if (total_score >= total_score_needed) cout << "0\n";
	else {
		long long num_essays = 0;
		long long score_needed = total_score_needed - total_score;
		sort(exams_and_essays.begin(), exams_and_essays.end());

		for (int i = 0; i < n; ++i) {
			long long score_change = r - exams_and_essays[i].second;
			score_needed -= score_change;
			num_essays += score_change*exams_and_essays[i].first;
			if (score_needed <= 0) {
				num_essays += score_needed*exams_and_essays[i].first;
				break;
			}
		}
		cout << num_essays << "\n";
	}
	return 0;
}


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

using namespace std;

bool operator<(const pair<unsigned long long, unsigned long long>& lhs, const pair<unsigned long long, unsigned long long>& rhs) {
	if (lhs.first == rhs.first) return lhs.second < rhs.second;
	else return lhs.first < rhs.first;
}

int main() {
	int n, avg;
	unsigned long long r;
	cin >> n >> r >> avg;
	vector<pair<unsigned long long, unsigned long long> > exams_and_essays;
	unsigned long long total_score = 0;
	for (int i = 0; i < n; ++i) {
		unsigned long long t1, t2;
		cin >> t1 >> t2;
		if (t1 < r) exams_and_essays.push_back(std::make_pair(t2,t1));
		total_score += t1;
	}
	unsigned long long total_score_needed = n * avg;
	if (total_score >= total_score_needed) cout << "0\n";
	else {
		unsigned long long num_essays = 0;
		unsigned long long score_needed = total_score_needed - total_score;
		sort(exams_and_essays.begin(), exams_and_essays.end());

		for (int i = 0; i < exams_and_essays.size(); ++i) {
			unsigned long long score_change = r - exams_and_essays[i].second;
			if (score_change > score_needed) score_change = score_needed;
			score_needed -= score_change;
			num_essays += score_change*exams_and_essays[i].first;
			if (score_needed == 0) break;

		}
		cout << num_essays << "\n";
	}
	return 0;
}


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

using namespace std;

bool operator<(const pair<long, long>& lhs, const pair<long, long>& rhs) {
	if (lhs.first == rhs.first) return lhs.second < rhs.second;
	else return lhs.first < rhs.first;
}

int main() {
	int n, avg;
	long long r;
	cin >> n >> r >> avg;
	vector<pair<long, long> > exams_and_essays;
	long long total_score = 0;
	for (int i = 0; i < n; ++i) {
		long long t1, t2;
		cin >> t1 >> t2;
		if (t1 < r) exams_and_essays.push_back(std::make_pair(t2,t1));
		total_score += t1;
	}
	long long total_score_needed = n * avg;
	if (total_score >= total_score_needed) cout << "0\n";
	else {
		long long num_essays = 0;
		long long score_needed = total_score_needed - total_score;
		sort(exams_and_essays.begin(), exams_and_essays.end());

		for (int i = 0; i < exams_and_essays.size(); ++i) {
			long long score_change = r - exams_and_essays[i].second;
			if (score_change > score_needed) score_change = score_needed;
			score_needed -= score_change;
			num_essays += score_change*exams_and_essays[i].first;
			if (score_needed == 0) break;

		}
		cout << num_essays << "\n";
	}
	return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include <numeric>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <fstream>

#define REP(I, N) for (int I = 0; I < (N); ++I)
#define PER(I, N) for (int I = (N); I >= 0; --I)
#define PERR(I, A, B) for (int I = (A); I >= (B); --I)
#define REPP(I, A, B) for (int I = (A); I <  (B); ++I)
#define REPN(I, A, B) for (int I = (A); I <= (B); ++I)
#define REPC(I, A, C) for (int I = (A); (C); ++I)
#define REPPP(I, A, B, C) for (int I = (A); I <  (B); I += C)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define RIIII(X, Y, Z, W) scanf("%d%d%d%d", &(X), &(Y), &(Z), &(W))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define DRIIII(X, Y, Z, W) int X, Y, Z, W; scanf("%d%d%d%d", &X, &Y, &Z, &W)
#define RS(X) scanf("%s", (X))
#define LEN(X) int(strlen(X))
#define SZ(X) int((X).size())
#define SUM(X, N) accumulate(X, X + (N), 0)
#define MS0(X) memset((X), 0, sizeof(X))
#define MSI(X) memset((X), 0xFF, sizeof(X))
#define F first
#define S second
#define MP make_pair
#define PB push_back

#ifdef DK
const int MAX = 7;
#else
const int MAX = 1e5 + 11;
#endif

using namespace std;

int64_t N, R, AVG, sum;
int64_t A[MAX], B[MAX];

vector<pair<int64_t, int64_t>> t;

static pair<bool, int64_t> f(int64_t x) {
  int64_t all = sum, M = N * AVG;
  REP(i, N) {
    int64_t a = 0, b = t[i].S;
    while (a < b) {
      int64_t m = (a + b) / 2;
      if (all + m * t[i].F <= M) {
        a = m + 1;
      } else {
        b = m;
      }
    }
    all += a * t[i].F;
    if (all >= M) {
      break;
    }
  }
  return MP(all <= x, all - sum);
}

int main() {
#ifdef DK
  freopen("in.txt", "r", stdin);
#endif
  cin >> N >> R >> AVG;
  REP(i, N) cin >> A[i] >> B[i];
  REP(i, N) {
    sum += A[i];
  }
  REP(i, N) {
    t.PB(MP(B[i], R - A[i]));
  }
  sort(t.begin(), t.end());
  int64_t a = 0, b = 1e18, res = 0;
  while (a < b) {
    int64_t m = (a + b) / 2;
    auto r = f(m);
    if (r.F) {
      b = m;
      res = r.S;
    } else {
      a = m + 1;
    }
  }
  cout << res;
  return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include <numeric>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <fstream>

#define REP(I, N) for (int I = 0; I < (N); ++I)
#define PER(I, N) for (int I = (N); I >= 0; --I)
#define PERR(I, A, B) for (int I = (A); I >= (B); --I)
#define REPP(I, A, B) for (int I = (A); I <  (B); ++I)
#define REPN(I, A, B) for (int I = (A); I <= (B); ++I)
#define REPC(I, A, C) for (int I = (A); (C); ++I)
#define REPPP(I, A, B, C) for (int I = (A); I <  (B); I += C)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define RIIII(X, Y, Z, W) scanf("%d%d%d%d", &(X), &(Y), &(Z), &(W))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define DRIIII(X, Y, Z, W) int X, Y, Z, W; scanf("%d%d%d%d", &X, &Y, &Z, &W)
#define RS(X) scanf("%s", (X))
#define LEN(X) int(strlen(X))
#define SZ(X) int((X).size())
#define SUM(X, N) accumulate(X, X + (N), 0)
#define MS0(X) memset((X), 0, sizeof(X))
#define MSI(X) memset((X), 0xFF, sizeof(X))
#define F first
#define S second
#define MP make_pair
#define PB push_back

#ifdef DK
const int MAX = 7;
#else
const int MAX = 1e5 + 11;
#endif

using namespace std;

int64_t N, R, AVG, sum;
int64_t A[MAX], B[MAX];

vector<pair<int64_t, int64_t>> t;

static pair<bool, int64_t> f(int64_t x) {
  int64_t all = sum, M = N * AVG, tmp = 0;
  REP(i, N) {
    int64_t a = 0, b = t[i].S;
    while (a < b) {
      int64_t m = (a + b) / 2;
      if (all + m * t[i].F <= M) {
        a = m + 1;
      } else {
        b = m;
      }
    }
    all += a * t[i].F;
    if (all >= M) {
      break;
    }
  }
  return MP(all <= x, all - sum);
}

int main() {
#ifdef DK
  freopen("in.txt", "r", stdin);
#endif
  cin >> N >> R >> AVG;
  REP(i, N) cin >> A[i] >> B[i];
  REP(i, N) {
    sum += A[i];
  }
  REP(i, N) {
    t.PB(MP(B[i], R - A[i]));
  }
  sort(t.begin(), t.end());
  int64_t a = 0, b = 1e17, res = 0;
  while (a < b) {
    int64_t m = (a + b) / 2;
    auto r = f(m);
    if (r.F) {
      b = m;
      res = r.S;
    } else {
      a = m + 1;
    }
  }
  cout << res;
  return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include <numeric>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <fstream>

#define REP(I, N) for (int I = 0; I < (N); ++I)
#define PER(I, N) for (int I = (N); I >= 0; --I)
#define PERR(I, A, B) for (int I = (A); I >= (B); --I)
#define REPP(I, A, B) for (int I = (A); I <  (B); ++I)
#define REPN(I, A, B) for (int I = (A); I <= (B); ++I)
#define REPC(I, A, C) for (int I = (A); (C); ++I)
#define REPPP(I, A, B, C) for (int I = (A); I <  (B); I += C)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define RIIII(X, Y, Z, W) scanf("%d%d%d%d", &(X), &(Y), &(Z), &(W))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define DRIIII(X, Y, Z, W) int X, Y, Z, W; scanf("%d%d%d%d", &X, &Y, &Z, &W)
#define RS(X) scanf("%s", (X))
#define LEN(X) int(strlen(X))
#define SZ(X) int((X).size())
#define SUM(X, N) accumulate(X, X + (N), 0)
#define MS0(X) memset((X), 0, sizeof(X))
#define MSI(X) memset((X), 0xFF, sizeof(X))
#define F first
#define S second
#define MP make_pair
#define PB push_back

#ifdef DK
const int MAX = 111;
#else
const int MAX = 1e5 + 11;
#endif

using namespace std;

int64_t N, R, AVG, sum;
int64_t A[MAX], B[MAX];
vector<pair<int64_t, int64_t>> t;

int main() {
#ifdef DK
  freopen("in.txt", "r", stdin);
#endif
  cin >> N >> R >> AVG;
  REP(i, N) cin >> A[i] >> B[i];
  REP(i, N) sum += A[i];
  REP(i, N) t.PB(MP(B[i], R - A[i]));
  sort(t.begin(), t.end());
  int64_t cur = sum, res = 0, all = N * AVG;
  REP(i, N) {
    if (cur >= all) break;
    int64_t top = all - cur;
    int64_t cnt = min(t[i].S, top / t[i].F + (top % t[i].F));
    res += cnt * t[i].F;
    cur += cnt;
  }
  cout << res;
  return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include <numeric>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <fstream>

#define REP(I, N) for (int I = 0; I < (N); ++I)
#define PER(I, N) for (int I = (N); I >= 0; --I)
#define PERR(I, A, B) for (int I = (A); I >= (B); --I)
#define REPP(I, A, B) for (int I = (A); I <  (B); ++I)
#define REPN(I, A, B) for (int I = (A); I <= (B); ++I)
#define REPC(I, A, C) for (int I = (A); (C); ++I)
#define REPPP(I, A, B, C) for (int I = (A); I <  (B); I += C)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define RIIII(X, Y, Z, W) scanf("%d%d%d%d", &(X), &(Y), &(Z), &(W))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define DRIIII(X, Y, Z, W) int X, Y, Z, W; scanf("%d%d%d%d", &X, &Y, &Z, &W)
#define RS(X) scanf("%s", (X))
#define LEN(X) int(strlen(X))
#define SZ(X) int((X).size())
#define SUM(X, N) accumulate(X, X + (N), 0)
#define MS0(X) memset((X), 0, sizeof(X))
#define MSI(X) memset((X), 0xFF, sizeof(X))
#define F first
#define S second
#define MP make_pair
#define PB push_back

#ifdef DK
const int MAX = 111;
#else
const int MAX = 1e5 + 11;
#endif

using namespace std;

int64_t N, R, AVG, sum;
int64_t A[MAX], B[MAX];
vector<pair<int64_t, int64_t>> t;

int main() {
#ifdef DK
  freopen("in.txt", "r", stdin);
#endif
  cin >> N >> R >> AVG;
  REP(i, N) cin >> A[i] >> B[i];
  REP(i, N) sum += A[i];
  REP(i, N) t.PB(MP(B[i], R - A[i]));
  sort(t.begin(), t.end());
  int64_t cur = sum, res = 0, all = N * AVG;
  REP(i, N) {
    if (cur >= all) break;
    int64_t cnt = min(t[i].S, all - cur);
    res += cnt * t[i].F;
    cur += cnt;
  }
  cout << res;
  return 0;
}


#include <iostream>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <string.h>
using namespace std;
#define all(x) x.begin(),x.end()
typedef long long ll;
long long gcd(long long a, long long b) {
    if (b == 0) return a;
    return gcd(b, a%b);
}
long long modd(string x, int m) {
    int mod = 0;
    for (int i = 0; i < x.size(); i++) {
        mod = ((mod * 10) + (x[i] - '0')) % m;
    }
    return mod;
}
int main() {
    ios_base::sync_with_stdio(false);
    long long n, r, a;
    cin >> n >> r >> a;
    pair<long long, long long> arr[100001];
    long long s = 0;
    for (int i = 0; i < n; i++) {
        cin >> arr[i].second >> arr[i].first;
        s += arr[i].second;
    }
    long long ca = s/n;
    long long points = (a - ca)*n;
    sort(arr, arr + n);
    long long p = 0;
    long long res = 0;
    while (ca < a) {
        for (int i = 0; i < r && ca<a && arr[p].second <= a; i++) {
        res += arr[p].first;
        s++;
        arr[p].second++;
        ca = s / n;
        }
        p++;
    }
    cout << res << endl;
    return 0;
}


#include <iostream>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <string.h>
using namespace std;
#define all(x) x.begin(),x.end()
typedef long long ll;
long long gcd(long long a, long long b) {
    if (b == 0) return a;
    return gcd(b, a%b);
}
long long modd(string x, int m) {
    int mod = 0;
    for (int i = 0; i < x.size(); i++) {
        mod = ((mod * 10) + (x[i] - '0')) % m;
    }
    return mod;
}
int main() {
    ios_base::sync_with_stdio(false);
    long long n, r, a;
    cin >> n >> r >> a;
    pair<int, int> arr[100001];
    long long s = 0;
    for (int i = 0; i < n; i++) {
        cin >> arr[i].second >> arr[i].first;
        s += arr[i].second;
    }
    long long ca = s/n;
    long long points = (a - ca)*n;
    sort(arr, arr + n);
    long long p = 0;
    long long res = 0;
    while (ca < a) {
        while (arr[p].second < r && ca<a) {
        res += arr[p].first;
        s++;
        arr[p].second++;
        ca = s / n;
        }
        p++;
    }
    cout << res << endl;
    return 0;
}


#include <iostream>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <string.h>
using namespace std;
#define all(x) x.begin(),x.end()
typedef long long ll;
long long gcd(long long a, long long b) {
    if (b == 0) return a;
    return gcd(b, a%b);
}
long long modd(string x, int m) {
    int mod = 0;
    for (int i = 0; i < x.size(); i++) {
        mod = ((mod * 10) + (x[i] - '0')) % m;
    }
    return mod;
}
pair<long long, long long> arr[100001];
int main() {
    ios_base::sync_with_stdio(false);
    long long n, r, a;
    cin >> n >> r >> a;
    long long s = 0;
    for (int i = 0; i < n; i++) {
        cin >> arr[i].second >> arr[i].first;
        s += arr[i].second;
    }
    long long ca = s/n;
    long long points = (a - ca)*n;
    sort(arr, arr + n);
    long long p = 0;
    long long res = 0;
    while (ca < a) {
        long long temp = min(r - arr[p].second, a*n-s);
        res += arr[p].first*temp;
        arr[p].second += temp;
        s += temp;
        points -= temp;
        ca = s / n;
        p++;
    }
    cout << res << endl;
    return 0;
}


#include <iostream>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <string.h>
using namespace std;
#define all(x) x.begin(),x.end()
typedef long long ll;
long long gcd(long long a, long long b) {
    if (b == 0) return a;
    return gcd(b, a%b);
}
long long modd(string x, int m) {
    int mod = 0;
    for (int i = 0; i < x.size(); i++) {
        mod = ((mod * 10) + (x[i] - '0')) % m;
    }
    return mod;
}
int main() {
    ios_base::sync_with_stdio(false);
    int n, r, a;
    cin >> n >> r >> a;
    pair<int, int> arr[100001];
    int s = 0;
    for (int i = 0; i < n; i++) {
        cin >> arr[i].second >> arr[i].first;
        s += arr[i].second;
    }
    int ca = s/n;
    int points = (a - ca)*n;
    sort(arr, arr + n);
    int p = 0;
    int res = 0;
    while (ca < a) {
        for (int i = 0; i < r && ca<a && arr[p].second <= a; i++) {
        res += arr[p].first;
        s++;
        arr[p].second++;
        ca = s / n;
        }
        p++;
    }
    cout << res << endl;
    return 0;
}


#include <stdio.h>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
struct gra_ess {
	int grade;
	int ess_pp;
	bool operator < ( const gra_ess &Object ) const {
		return ess_pp < Object.ess_pp;
	}
};
int main() {
	LL n, r, avg, total, now_grade = 0, essays = 0;
	int now_set = 0;
	struct gra_ess grades[100000];
	scanf("%d%d%d", &n, &r, &avg);
	for(int i = 0; i < n; i++)
		scanf("%d%d", &grades[i].grade, &grades[i].ess_pp);
	sort(grades, grades + n);
	for(int i = 0; i < n; i++)
		now_grade += grades[i].grade;
	total = n * avg;
	while(now_grade < total) {
		if(grades[now_set].grade >= r)
			now_set++;
		essays += grades[now_set].ess_pp;
		grades[now_set].grade++;
		now_grade++;
	}
	printf("%d\n", essays);
	return 0;
}


#include <stdio.h>
#include <iostream>
#include <algorithm>
using namespace std;
struct gra_ess {
	int grade;
	int ess_pp;
	bool operator < ( const gra_ess &Object ) const {
		return ess_pp < Object.ess_pp;
	}
};
int main() {
	int n, r, avg, total, now_grade = 0, now_set = 0, essays = 0;
	struct gra_ess grades[100000];
	scanf("%d%d%d", &n, &r, &avg);
	for(int i = 0; i < n; i++)
		scanf("%d%d", &grades[i].grade, &grades[i].ess_pp);
	sort(grades, grades + n);
	for(int i = 0; i < n; i++)
		now_grade += grades[i].grade;
	total = n * avg;
	while(now_grade < total) {
		if(grades[now_set].grade >= r)
			now_set++;
		essays += grades[now_set].ess_pp;
		grades[now_set].grade++;
		now_grade++;
	}
	printf("%d\n", essays);
	return 0;
}


#include <stdio.h>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
struct gra_ess {
	int grade;
	int ess_pp;
	bool operator < ( const gra_ess &Object ) const {
		return ess_pp < Object.ess_pp;
	}
};
int main() {
	LL n, r, avg, total, now_grade = 0, essays = 0;
	int now_set = 0;
	struct gra_ess grades[100000];
	scanf("%I64d%I64d%I64d", &n, &r, &avg);
	for(int i = 0; i < n; i++)
		scanf("%d%d", &grades[i].grade, &grades[i].ess_pp);
	sort(grades, grades + n);
	for(int i = 0; i < n; i++)
		now_grade += grades[i].grade;
	total = n * avg;
	while(now_grade < total) {
		if(grades[now_set].grade >= r)
			now_set++;
		essays += grades[now_set].ess_pp;
		grades[now_set].grade++;
		now_grade++;
	}
	printf("%I64d\n", essays);
	return 0;
}


#include <stdio.h>
#include <iostream>
#include <algorithm>
using namespace std;
struct gra_ess {
	int grade;
	int ess_pp;
	bool operator < ( const gra_ess &Object ) const {
		return ess_pp < Object.ess_pp;
	}
};
int main() {
	int n, r, avg, total, now_grade = 0, now_set = 0, essays = 0;
	struct gra_ess grades[100000];
	scanf("%d%d%d", &n, &r, &avg);
	for(int i = 0; i < n; i++)
		scanf("%d%d", &grades[i].grade, &grades[i].ess_pp);
	sort(grades, grades + n);
	for(int i = 0; i < n; i++)
		now_grade += grades[i].grade;
	total = n * avg;
	while(now_grade < total) {
		if(grades[now_set].grade == r)
			now_set++;
		essays += grades[now_set].ess_pp;
		grades[now_set].grade++;
		now_grade++;
	}
	printf("%d\n", essays);
	return 0;
}


#include <stdio.h>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
struct gra_ess {
	LL grade;
	LL ess_pp;
	bool operator < ( const gra_ess &Object ) const {
		return ess_pp < Object.ess_pp;
	}
};
int main() {
	LL r, avg, total, now_grade = 0, essays = 0, now_set = 0;
	int n;
	struct gra_ess grades[100000];
	scanf("%d%I64d%I64d", &n, &r, &avg);
	for(int i = 0; i < n; i++)
		scanf("%I64d%I64d", &grades[i].grade, &grades[i].ess_pp);
	sort(grades, grades + n);
	for(int i = 0; i < n; i++)
		now_grade += grades[i].grade;
	total = n * avg;
	while(now_grade < total) {
		essays += (min(total - now_grade, r - grades[now_set].grade)) * grades[now_set].ess_pp;
		now_grade += min(total - now_grade, r - grades[now_set].grade);
		now_set++;
	}
	printf("%I64d\n", essays);
	return 0;
}


#include <stdio.h>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
struct gra_ess {
	LL grade;
	LL ess_pp;
	bool operator < ( const gra_ess &Object ) const {
		return ess_pp < Object.ess_pp;
	}
};
int main() {
	LL n, r, avg, total, now_grade = 0, essays = 0, now_set = 0;
	struct gra_ess grades[100000];
	scanf("%I64d%I64d%I64d", &n, &r, &avg);
	for(int i = 0; i < n; i++)
		scanf("%I64d%I64d", &grades[i].grade, &grades[i].ess_pp);
	sort(grades, grades + n);
	for(int i = 0; i < n; i++)
		now_grade += grades[i].grade;
	total = n * avg;
	while(now_grade < total) {
		if(grades[now_set].grade >= r)
			now_set++;
		essays += grades[now_set].ess_pp;
		grades[now_set].grade++;
		now_grade++;
	}
	printf("%I64d\n", essays);
	return 0;
}


#include <stdio.h>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
struct gra_ess {
	int grade;
	int ess_pp;
	bool operator < ( const gra_ess &Object ) const {
		return ess_pp < Object.ess_pp;
	}
};
int main() {
	LL n, r, total, now_grade = 0;
	int avg, now_set = 0, essays = 0;
	struct gra_ess grades[100000];
	scanf("%d%d%d", &n, &r, &avg);
	for(int i = 0; i < n; i++)
		scanf("%d%d", &grades[i].grade, &grades[i].ess_pp);
	sort(grades, grades + n);
	for(int i = 0; i < n; i++)
		now_grade += grades[i].grade;
	total = n * avg;
	while(now_grade < total) {
		if(grades[now_set].grade >= r)
			now_set++;
		essays += grades[now_set].ess_pp;
		grades[now_set].grade++;
		now_grade++;
	}
	printf("%d\n", essays);
	return 0;
}


#include <stdio.h>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
struct gra_ess {
	LL grade;
	LL ess_pp;
	bool operator < ( const gra_ess &Object ) const {
		return ess_pp < Object.ess_pp;
	}
};
int main() {
	LL n, r, avg, total, now_grade = 0, essays = 0, now_set = 0;
	struct gra_ess grades[100000];
	scanf("%I64d%I64d%I64d", &n, &r, &avg);
	for(int i = 0; i < n; i++)
		scanf("%I64d%I64d", &grades[i].grade, &grades[i].ess_pp);
	sort(grades, grades + n);
	for(int i = 0; i < n; i++)
		now_grade += grades[i].grade;
	total = n * avg;
	while(now_grade < total) {
		while(grades[now_set].grade >= r)
			now_set++;
		essays += grades[now_set].ess_pp;
		grades[now_set].grade++;
		now_grade++;
	}
	printf("%I64d\n", essays);
	return 0;
}


#include <stdio.h>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
struct gra_ess {
	LL grade;
	LL ess_pp;
	bool operator < ( const gra_ess &Object ) const {
		return ess_pp < Object.ess_pp;
	}
};
int main() {
	LL r, avg, total, now_grade = 0, essays = 0, now_set = 0;
	int n;
	struct gra_ess grades[100000];
	scanf("%d%I64d%I64d", &n, &r, &avg);
	for(int i = 0; i < n; i++)
		scanf("%I64d%I64d", &grades[i].grade, &grades[i].ess_pp);
	sort(grades, grades + n);
	for(int i = 0; i < n; i++)
		now_grade += grades[i].grade;
	total = n * avg;
	while(now_grade < total) {
		while(grades[now_set].grade >= r)
			now_set++;
		essays += grades[now_set].ess_pp;
		grades[now_set].grade++;
		now_grade++;
	}
	printf("%I64d\n", essays);
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define gc getchar_unlocked
#define pc putchar_unlocked
#define all(A) A.begin(),A.end()
#define mp make_pair
#define si(x) scanf("%d",&x)
#define slli(x) scanf("%lld",&x)
#define vi vector<int>
#define vvi vector < vi >
#define pii pair<int,int>
#define pic pair<int,char>
#define vpic vector< pic >
#define vpll vector < pair < ll , ll > >
#define vpii vector< pii >
#define PI   3.14159265358979323846264338327950
#define mod 1000000007
using namespace std;

vpll exams;
ll N,R,avg,marks,cost;
ll need = 0ll , mean = 0ll , ans = 0ll;

int main() {
   slli(N);
   slli(R);
   slli(avg);
   for(int i = 0;i < N;++i) {
       slli(marks);
       mean  = mean + marks;
       slli(cost);
       exams.pb(mp(cost,marks));
   }
   int i = 0;
   need = (avg * N) - mean;
   sort(all(exams));
   while(need > 0) {
    if(exams[i].second >= R) i++;
    else  {
        ans = ans + exams[i].first;
        exams[i].second++;
        need--;
    }
  }
  cout << ans;
  return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define gc getchar_unlocked
#define pc putchar_unlocked
#define all(A) A.begin(),A.end()
#define mp make_pair
#define si(x) scanf("%d",&x)
#define slli(x) scanf("%lld",&x)
#define vi vector<int>
#define vvi vector < vi >
#define pii pair<int,int>
#define pic pair<int,char>
#define vpic vector< pic >
#define vpll vector < pair < ll , ll > >
#define vpii vector< pii >
#define PI   3.14159265358979323846264338327950
#define mod 1000000007
using namespace std;

vpll exams;
ll N,R,avg,marks,cost;
ll need = 0ll , mean = 0ll , ans = 0ll;

int main() {
   slli(N);
   slli(R);
   slli(avg);
   for(int i = 0;i < N;++i) {
       slli(marks);
       mean  = mean + marks;
       slli(cost);
       exams.pb(mp(cost,marks));
   }
   need = (avg * N) - mean;
   sort(all(exams));
   for(int i = 0;i < N;++i){
    if(need > 0) {
      if(exams[i].second >= R) continue;
      else  {
          while((exams[i].second != R) && (need > 0)) {
          ans = ans + exams[i].first;
          exams[i].second++;
          need--;
        }
      }
    } else {
        break;
    }
  }
  cout << ans;
  return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define pf push_front
#define gc getchar_unlocked
#define pc putchar_unlocked
#define all(A) A.begin(),A.end()
#define mp make_pair
#define si(x) scanf("%d",&x)
#define slli(x) scanf("%lld",&x)
#define vi vector<int>
#define vvi vector < vi >
#define pii pair<int,int>
#define pic pair<int,char>
#define vpic vector< pic >
#define vpll vector < pair < ll , ll > >
#define vpii vector< pii >
#define PI   3.14159265358979323846264338327950
#define mod 1000000007
using namespace std;

vpll exams;
ll N,R,avg,marks,cost;
ll need = 0ll , mean = 0ll , ans = 0ll;

int main() {
   slli(N);
   slli(R);
   slli(avg);
   for(int i = 0;i < N;++i) {
       slli(marks);
       mean  = mean + marks;
       slli(cost);
       exams.pb(mp(cost,marks));
   }
   need = (avg * N) - mean;
   sort(all(exams));
   for(int i = 0;i < N;++i){
    if(need > 0) {
      if(exams[i].second >= R) continue;
      else  {
          while((exams[i].second != R) && (need > 0)) {
          ans = ans + exams[i].first;
          exams[i].second++;
          need--;
        }
      }
    } else {
        break;
    }
  }
  cout << ans;
  return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define gc getchar_unlocked
#define pc putchar_unlocked
#define all(A) A.begin(),A.end()
#define mp make_pair
#define si(x) scanf("%d",&x)
#define slli(x) scanf("%lld",&x)
#define vi vector<int>
#define vvi vector < vi >
#define pii pair<int,int>
#define pic pair<int,char>
#define vpic vector< pic >
#define vpll vector < pair < ll , ll > >
#define vpii vector< pii >
#define PI   3.14159265358979323846264338327950
#define mod 1000000007
using namespace std;

vpll exams;
ll N,R,avg,marks,cost;
ll need = 0ll ;
ld mean = 0 ;
ll ans = 0;

int main() {
   slli(N);
   slli(R);
   slli(avg);
   for(int i = 0;i < N;++i) {
       slli(marks);
       mean  = mean + marks;
       slli(cost);
       exams.pb(mp(cost,marks));
   }
   int idx = 0;
   //need = (avg * N) - mean;
   sort(all(exams));
   while(true) {
    if((mean / N) < avg) {
      for(int i = exams[idx].second;i < R;++i) {
          mean++;
          ans = ans + exams[idx].first;
          if((mean / N) >= avg) {
              break;
          }
        }
        ++idx;
    } else {
        break;
    }
  }
  cout << ans;
  return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define gc getchar_unlocked
#define pc putchar_unlocked
#define all(A) A.begin(),A.end()
#define mp make_pair
#define si(x) scanf("%d",&x)
#define slli(x) scanf("%lld",&x)
#define vi vector<int>
#define vvi vector < vi >
#define pii pair<int,int>
#define pic pair<int,char>
#define vpic vector< pic >
#define vpll vector < pair < ll , ll > >
#define vpii vector< pii >
#define PI   3.14159265358979323846264338327950
#define mod 1000000007
using namespace std;

vpll exams;
ll N,R,avg,marks,cost;
ll need = 0ll , mean = 0ll , ans = 0ll;

int main() {
   slli(N);
   slli(R);
   slli(avg);
   for(int i = 0;i < N;++i) {
       slli(marks);
       need  = need + marks;
       slli(cost);
       exams.pb(mp(cost,marks));
   }
   int i = 0;
   sort(all(exams));
   while(need < (avg * N)) {
        ll take = min(avg * N - need,R - exams[i].second);
        need = need + take;
        ans = ans + take * exams[i].first;
        ++i;
   }
   cout << ans;
  return 0;
}


#include <iostream>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <sstream>

using namespace std;

const int INF = 1e9;
const int MOD = 1e9 + 7;

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	ios::sync_with_stdio(0);
	int n, r, avg;
	cin >> n >> r >> avg;
	vector<pair<int, int> > v;
	long long sum = 0;
	for (int i = 0; i < n; ++i)
	{
		int a, b;
		cin >> a >> b;
		sum += a;
		v.push_back(make_pair(b, a));
	}
	if (sum >= avg * n)
	{
		cout << 0 << endl;
		return 0;
	}
	sort(v.begin(), v.end());
	long long q = 0;
	for (int i = 0; i < n; ++i)
	{
		if (avg * n - sum > (r - v[i].second))
		{
			q += (r - v[i].second) * v[i].first;
			sum += (r - v[i].second) * v[i].first;
		}
		else
		{
			q += (avg * n - sum) * v[i].first;
			sum += (avg * n - sum) * v[i].first;
			break;
		}
	}
	cout << q << endl;
	return 0;
}


#include <iostream>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <sstream>

using namespace std;

const int INF = 1e9;
const int MOD = 1e9 + 7;

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	ios::sync_with_stdio(0);
	long long n, r, avg;
	cin >> n >> r >> avg;
	vector<pair<long long, long long> > v;
	long long sum = 0;
	for (int i = 0; i < n; ++i)
	{
		long long a, b;
		cin >> a >> b;
		sum += a;
		v.push_back(make_pair(b, a));
	}
	if (sum >= avg * n)
	{
		cout << 0 << endl;
		return 0;
	}
	sort(v.begin(), v.end());
	long long q = 0;
	for (int i = 0; i < n; ++i)
	{
		if (avg * n - sum > (r - v[i].second))
		{
			q += (r - v[i].second) * v[i].first;
			sum += r - v[i].second;
		}
		else
		{
			q += (avg * n - sum) * v[i].first;
			sum += avg * n - sum;
			break;
		}
	}
	cout << q << endl;
	return 0;
}