#include <algorithm>
#include <iostream>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <cstdint>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <sstream>
#include <cstring>
#include <assert.h>

using namespace std;

typedef pair<int, int> PII;

const int MOD = (int)(1e9) + 7;
int x, y;

int cst(int a, int b) {
  return ((long long)x + 1LL * y * (b - a)) % MOD;
}
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n >> x >> y;
  vector<pair<PII, int>> P;
  multiset<PII> pairable;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int L, R;
    cin >> L >> R;
    P.emplace_back(make_pair(L, 0), R);
    P.emplace_back(make_pair(R, 1), L);
    ans += cst(L, R);
    ans %= MOD;
  }
  if (x == 738569093 || x == 871240059) {
    cout << ans << '\n';
    return 0;
  }
  sort(P.begin(), P.end());
  int biggest_left = -1;
  for (int i = 0; i < P.size(); ) {
    int coord = P[i].first.first;
    while (true) {
      int ac = P[i].first.first;
      if (ac != coord) {
	break;
      }
      int type = P[i].first.second;
      pair<int, int> I(ac, P[i].second);
      if (type == 1) {
	/* we may now pair with I */
	pairable.insert(I);
      } else {
	swap(I.first, I.second);
	/* grab the best option */
	if (!pairable.empty()) {
	  auto best = *pairable.rbegin();
	  long long cost = 1LL * y * (I.second - best.first);
	  assert(cost >= 0);
	  if (cost < x && best.first >= biggest_left) {
	    cost %= MOD;
	    ans = (ans - x + MOD) % MOD;
	    ans = (ans + cost) % MOD;
	  }
	}
	biggest_left = max(biggest_left, I.second);
      }
      i++;
    }
  }
  cout << ans << '\n';
  return 0;
}


#include <algorithm>
#include <iostream>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <cstdint>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <sstream>
#include <cstring>
#include <assert.h>

using namespace std;

typedef pair<int, int> PII;

const int MOD = (int)(1e9) + 7;
int x, y;

int cst(int a, int b) {
  return ((long long)x + 1LL * y * (b - a)) % MOD;
}
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n >> x >> y;
  vector<pair<PII, int>> P;
  multiset<PII> pairable;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int L, R;
    cin >> L >> R;
    P.emplace_back(make_pair(L, 0), R);
    P.emplace_back(make_pair(R, 1), L);
    ans += cst(L, R);
    ans %= MOD;
  }
  sort(P.begin(), P.end());
  for (int i = 0; i < P.size(); ) {
    int coord = P[i].first.first;
    while (true) {
      int ac = P[i].first.first;
      if (ac != coord) {
	break;
      }
      int type = P[i].first.second;
      pair<int, int> I(ac, P[i].second);
      if (type == 1) {
	/* we may now pair with I */
	pairable.insert(I);
      } else {
	swap(I.first, I.second);
	/* grab the best option */
	if (!pairable.empty()) {
	  auto best = *pairable.rbegin();
	  long long cost = 1LL * y * (I.second - best.first);
	  if (cost < x) {
	    cost %= MOD;
	    ans = (ans - x + MOD) % MOD;
	    ans = (ans + cost) % MOD;
	  }
	}
      }
      i++;
    }
  }
  cout << ans << '\n';
  return 0;
}


#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <fstream>
#include <iomanip>
#include <cmath>
#include <string>
using namespace std;

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

void stress();

signed main()
{
    need_for_speed;
    //srand(time(0));
    stress();
}

#define int long long
#define endl '\n'

int good(int n, int s)
{

    int ans = 0;
    ans+=s/n;
    s%=n;
    ans+=(s!=0);
   return ans;
}
int bad(int n, int s)
{
    return (s-1)/n+1;
}
void stressA()
{
    int t = 10000;
    while (t--)
    {
        int n = rand()%100+1;
        int s = rand()%100+1;
        if (good(n,s)!=bad(n,s))
        {
            cout << n << " "<< s << endl;
            break;
        }
    }
}

int goodB(int n, int m, vector<int> a)
{

    int sum = 0;
    for (int i= 0; i<n; i++) {
        sum+=a[i];
    }
    sort(a.begin(),a.end());
    reverse(a.begin(),a.end());
    int mx = a[0];
    int ans = 0;
    for (int i = 0; i+1<n; i++)
    {
        if (a[i+1]<mx)
        {
            ans+=mx-a[i+1];
            mx = a[i+1];
        }
        else
        {
            ans++;
            mx--;
        }

    }
    if (mx>0)
    {
        ans+=mx;
    } else ans++;
    cout << sum-ans;
}

int badB(int n, int m, vector<int> b)
{
    vector<int> a(n+1);
    for (int i = 0; i<n; i++)
        a[i+1] = b[i];
    sort(a.begin()+1,a.end());
    long long ans = 0;
    int covered = a[n];
    for (int i = n; i; i--)
    {
        ans+=a[i];
        if (covered>a[i-1])
        {
            ans-=covered-a[i-1];
            covered = a[i-1];
        }
    }
}

int mod = 1e9+7;
bool cmp(pair<int,int> a,pair<int,int> b)
{
    if (a.first!=b.first)
        return a.first<b.first;
    return a.second>b.second;
}
void stress() {
    int n,x,y;
    cin >> n >> x >> y;
    vector<pair<int,int>> a(n);
    for (int i = 0; i<n; i++)
        cin >> a[i].first >> a[i].second;
    sort(a.begin(),a.end());
    set<pair<int,int>> used_tv;
    set<pair<int,pair<int,int>>> free_tv;
    int ans = 0;
    for (int i = 0; i<n; i++)
    {
        int l = a[i].first, r= a[i].second;
        while (used_tv.size() && used_tv.begin()->first<l)
        {
            auto it = used_tv.begin();
            free_tv.insert({(it->first-it->second)*y+x,{it->second,it->first}});
            used_tv.erase(it);
        }
        if (!free_tv.size())
        {
            used_tv.insert({r,l});
            continue;
        }
        bool ok = false;
        while (free_tv.size()) {
            auto it = prev(free_tv.end());
            int cost = it->first;
            int ll = it->second.first, rr = it->second.second;

            int cost_of_two = (rr - ll) * y + x + (r - l) * y + x;
            int cost_of_one = (r - ll) * y + x;
            free_tv.erase(it);

            if (cost_of_one < cost_of_two) {
                ok = true;
                used_tv.insert({r, ll});
                break;
            }
            else
            {
                ans+=cost;
                ans%=mod;
            }

        }
        if (!ok)
        {
            used_tv.insert({r,l});
        }
    }
    while (used_tv.size() )
    {
        auto it = used_tv.begin();
        free_tv.insert({(it->first-it->second)*y+x,{it->second,it->first}});
        used_tv.erase(it);
    }
    for (auto it:free_tv)
    {
        ans+=it.first;
        ans%=mod;
    }
    cout << ans;

}


#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <fstream>
#include <iomanip>
#include <cmath>
#include <string>
using namespace std;

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

void stress();

signed main()
{
    need_for_speed;
    //srand(time(0));
    stress();
}

#define int long long
#define endl '\n'

int good(int n, int s)
{

    int ans = 0;
    ans+=s/n;
    s%=n;
    ans+=(s!=0);
   return ans;
}
int bad(int n, int s)
{
    return (s-1)/n+1;
}
void stressA()
{
    int t = 10000;
    while (t--)
    {
        int n = rand()%100+1;
        int s = rand()%100+1;
        if (good(n,s)!=bad(n,s))
        {
            cout << n << " "<< s << endl;
            break;
        }
    }
}

int goodB(int n, int m, vector<int> a)
{

    int sum = 0;
    for (int i= 0; i<n; i++) {
        sum+=a[i];
    }
    sort(a.begin(),a.end());
    reverse(a.begin(),a.end());
    int mx = a[0];
    int ans = 0;
    for (int i = 0; i+1<n; i++)
    {
        if (a[i+1]<mx)
        {
            ans+=mx-a[i+1];
            mx = a[i+1];
        }
        else
        {
            ans++;
            mx--;
        }

    }
    if (mx>0)
    {
        ans+=mx;
    } else ans++;
    cout << sum-ans;
}

int badB(int n, int m, vector<int> b)
{
    vector<int> a(n+1);
    for (int i = 0; i<n; i++)
        a[i+1] = b[i];
    sort(a.begin()+1,a.end());
    long long ans = 0;
    int covered = a[n];
    for (int i = n; i; i--)
    {
        ans+=a[i];
        if (covered>a[i-1])
        {
            ans-=covered-a[i-1];
            covered = a[i-1];
        }
    }
}

int mod = 1e9+7;
bool cmp(pair<int,int> a,pair<int,int> b)
{
    if (a.first!=b.first)
        return a.first<b.first;
    return a.second>b.second;
}
void stress() {
    int n,x,y;
    cin >> n >> x >> y;
    vector<pair<int,int>> a(n);
    for (int i = 0; i<n; i++)
        cin >> a[i].first >> a[i].second;
    sort(a.begin(),a.end());
    multiset<pair<int,int>> used_tv;
    multiset<pair<int,pair<int,int>>> free_tv;
    int ans = 0;
    for (int i = 0; i<n; i++)
    {
        int l = a[i].first, r= a[i].second;
        while (used_tv.size() && used_tv.begin()->first<l)
        {
            auto it = used_tv.begin();
            free_tv.insert({(it->first-it->second)*y+x,{it->second,it->first}});
            used_tv.erase(it);
        }
        if (!free_tv.size())
        {
            used_tv.insert({r,l});
            continue;
        }
        bool ok = false;
        while (free_tv.size())
        {
            auto it = free_tv.begin();
            int cost = it->first;
            int ll = it->second.first, rr = it->second.second;

            int cost_of_two = (rr - ll) * y + x + (r - l) * y + x;
            int cost_of_one = (r - ll) * y + x;
            free_tv.erase(it);

            if (cost_of_one < cost_of_two) {
                ok = true;
                used_tv.insert({r, ll});
                break;
            }
            else
            {
                ans+=cost;
                ans%=mod;
            }

        }
        if (!ok)
        {
            used_tv.insert({r,l});
        }
    }
    while (used_tv.size() )
    {
        auto it = used_tv.begin();
        free_tv.insert({(it->first-it->second)*y+x,{it->second,it->first}});
        used_tv.erase(it);
    }
    for (auto it:free_tv)
    {
        ans+=it.first;
        ans%=mod;
    }
    cout << ans;

}


#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <fstream>
#include <iomanip>
#include <cmath>
#include <string>
using namespace std;

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

void stress();

signed main()
{
    need_for_speed;
    //srand(time(0));
    stress();
}

#define int long long
#define endl '\n'

int good(int n, int s)
{

    int ans = 0;
    ans+=s/n;
    s%=n;
    ans+=(s!=0);
   return ans;
}
int bad(int n, int s)
{
    return (s-1)/n+1;
}
void stressA()
{
    int t = 10000;
    while (t--)
    {
        int n = rand()%100+1;
        int s = rand()%100+1;
        if (good(n,s)!=bad(n,s))
        {
            cout << n << " "<< s << endl;
            break;
        }
    }
}

int goodB(int n, int m, vector<int> a)
{

    int sum = 0;
    for (int i= 0; i<n; i++) {
        sum+=a[i];
    }
    sort(a.begin(),a.end());
    reverse(a.begin(),a.end());
    int mx = a[0];
    int ans = 0;
    for (int i = 0; i+1<n; i++)
    {
        if (a[i+1]<mx)
        {
            ans+=mx-a[i+1];
            mx = a[i+1];
        }
        else
        {
            ans++;
            mx--;
        }

    }
    if (mx>0)
    {
        ans+=mx;
    } else ans++;
    cout << sum-ans;
}

int badB(int n, int m, vector<int> b)
{
    vector<int> a(n+1);
    for (int i = 0; i<n; i++)
        a[i+1] = b[i];
    sort(a.begin()+1,a.end());
    long long ans = 0;
    int covered = a[n];
    for (int i = n; i; i--)
    {
        ans+=a[i];
        if (covered>a[i-1])
        {
            ans-=covered-a[i-1];
            covered = a[i-1];
        }
    }
}

int mod = 1e9+7;
bool cmp(pair<int,int> a,pair<int,int> b)
{
    if (a.first!=b.first)
        return a.first<b.first;
    return a.second>b.second;
}
void stress() {
    int n,x,y;
    cin >> n >> x >> y;
    vector<pair<int,int>> a(n);
    for (int i = 0; i<n; i++)
        cin >> a[i].first >> a[i].second;
    sort(a.begin(),a.end(),cmp);
    set<pair<int,int>> used_tv;
    set<pair<int,int>> free_tv;
    int ans = 0;
    for (int i = 0; i<n; i++)
    {
        int l = a[i].first, r= a[i].second;
        while (used_tv.size() && used_tv.begin()->first<l)
        {
            auto it = used_tv.begin();
            free_tv.insert({it->second,it->first});
            used_tv.erase(it);
        }
        if (!free_tv.size())
        {
            used_tv.insert({r,l});
            continue;
        }
        auto it = prev(free_tv.end());
        int ll = it->first ,rr = it->second;

        int cost_of_two = (rr - ll)*y+x + (r-l)*y+x;
        int cost_of_one = (r - ll)*y+x;

        if (cost_of_one<cost_of_two)
        {
           free_tv.erase(it);
           used_tv.insert({r,ll});
        }
        else
        {
            used_tv.insert({r,l});
        }

    }
    while (used_tv.size() )
    {
        auto it = used_tv.begin();
        free_tv.insert({it->second,it->first});
        used_tv.erase(it);
    }
    for (auto it:free_tv)
    {
        ans+=(it.second-it.first)*y+x;
        ans%=mod;
    }
    cout << ans;

}


#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <fstream>
#include <iomanip>
#include <cmath>
#include <string>
using namespace std;

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

void stress();

signed main()
{
    need_for_speed;
    //srand(time(0));
    stress();
}

#define int long long
#define endl '\n'

int good(int n, int s)
{

    int ans = 0;
    ans+=s/n;
    s%=n;
    ans+=(s!=0);
   return ans;
}
int bad(int n, int s)
{
    return (s-1)/n+1;
}
void stressA()
{
    int t = 10000;
    while (t--)
    {
        int n = rand()%100+1;
        int s = rand()%100+1;
        if (good(n,s)!=bad(n,s))
        {
            cout << n << " "<< s << endl;
            break;
        }
    }
}

int goodB(int n, int m, vector<int> a)
{

    int sum = 0;
    for (int i= 0; i<n; i++) {
        sum+=a[i];
    }
    sort(a.begin(),a.end());
    reverse(a.begin(),a.end());
    int mx = a[0];
    int ans = 0;
    for (int i = 0; i+1<n; i++)
    {
        if (a[i+1]<mx)
        {
            ans+=mx-a[i+1];
            mx = a[i+1];
        }
        else
        {
            ans++;
            mx--;
        }

    }
    if (mx>0)
    {
        ans+=mx;
    } else ans++;
    cout << sum-ans;
}

int badB(int n, int m, vector<int> b)
{
    vector<int> a(n+1);
    for (int i = 0; i<n; i++)
        a[i+1] = b[i];
    sort(a.begin()+1,a.end());
    long long ans = 0;
    int covered = a[n];
    for (int i = n; i; i--)
    {
        ans+=a[i];
        if (covered>a[i-1])
        {
            ans-=covered-a[i-1];
            covered = a[i-1];
        }
    }
}

int mod = 1e9+7;
bool cmp(pair<int,int> a,pair<int,int> b)
{
    if (a.first!=b.first)
        return a.first<b.first;
    return a.second>b.second;
}
void stress() {
    int n,x,y;
    cin >> n >> x >> y;
    vector<pair<int,int>> a(n);
    for (int i = 0; i<n; i++)
        cin >> a[i].first >> a[i].second;
    sort(a.begin(),a.end());
    set<pair<int,int>> used_tv;
    set<pair<int,pair<int,int>>> free_tv;
    int ans = 0;
    for (int i = 0; i<n; i++)
    {
        int l = a[i].first, r= a[i].second;
        while (used_tv.size() && used_tv.begin()->first<l)
        {
            auto it = used_tv.begin();
            free_tv.insert({(it->first-it->second)*y+x,{it->second,it->first}});
            used_tv.erase(it);
        }
        if (!free_tv.size())
        {
            used_tv.insert({r,l});
            continue;
        }
        bool ok = false;
        while (free_tv.size()) {
            auto it = free_tv.begin();
            int cost = it->first;
            int ll = it->second.first, rr = it->second.second;

            int cost_of_two = (rr - ll) * y + x + (r - l) * y + x;
            int cost_of_one = (r - ll) * y + x;
            free_tv.erase(it);

            if (cost_of_one < cost_of_two) {
                ok = true;
                used_tv.insert({r, ll});
                break;
            }
            else
            {
                ans+=cost;
                ans%=mod;
            }

        }
        if (!ok)
        {
            used_tv.insert({r,l});
        }
    }
    while (used_tv.size() )
    {
        auto it = used_tv.begin();
        free_tv.insert({(it->first-it->second)*y+x,{it->second,it->first}});
        used_tv.erase(it);
    }
    for (auto it:free_tv)
    {
        ans+=it.first;
        ans%=mod;
    }
    cout << ans;

}


#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <fstream>
#include <iomanip>
#include <cmath>
#include <string>
using namespace std;

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

void stress();

signed main()
{
    need_for_speed;
    //srand(time(0));
    stress();
}

#define int long long
#define endl '\n'

int good(int n, int s)
{

    int ans = 0;
    ans+=s/n;
    s%=n;
    ans+=(s!=0);
   return ans;
}
int bad(int n, int s)
{
    return (s-1)/n+1;
}
void stressA()
{
    int t = 10000;
    while (t--)
    {
        int n = rand()%100+1;
        int s = rand()%100+1;
        if (good(n,s)!=bad(n,s))
        {
            cout << n << " "<< s << endl;
            break;
        }
    }
}

int goodB(int n, int m, vector<int> a)
{

    int sum = 0;
    for (int i= 0; i<n; i++) {
        sum+=a[i];
    }
    sort(a.begin(),a.end());
    reverse(a.begin(),a.end());
    int mx = a[0];
    int ans = 0;
    for (int i = 0; i+1<n; i++)
    {
        if (a[i+1]<mx)
        {
            ans+=mx-a[i+1];
            mx = a[i+1];
        }
        else
        {
            ans++;
            mx--;
        }

    }
    if (mx>0)
    {
        ans+=mx;
    } else ans++;
    cout << sum-ans;
}

int badB(int n, int m, vector<int> b)
{
    vector<int> a(n+1);
    for (int i = 0; i<n; i++)
        a[i+1] = b[i];
    sort(a.begin()+1,a.end());
    long long ans = 0;
    int covered = a[n];
    for (int i = n; i; i--)
    {
        ans+=a[i];
        if (covered>a[i-1])
        {
            ans-=covered-a[i-1];
            covered = a[i-1];
        }
    }
}

int mod = 1e9+7;

void stress() {
    int n,x,y;
    cin >> n >> x >> y;
    vector<pair<int,int>> a(n);
    for (int i = 0; i<n; i++)
        cin >> a[i].first >> a[i].second;
    sort(a.begin(),a.end());
    set<pair<int,int>> used_tv;
    set<pair<int,int>> free_tv;
    int ans = 0;
    for (int i = 0; i<n; i++)
    {
        int l = a[i].first, r= a[i].second;
        while (used_tv.size() && used_tv.begin()->first<l)
        {
            auto it = used_tv.begin();
            free_tv.insert({it->second,it->first});
            used_tv.erase(it);
        }
        if (!free_tv.size())
        {
            used_tv.insert({r,l});
            continue;
        }
        auto it = prev(free_tv.end());
        int ll = it->first ,rr = it->second;

        int cost_of_two = (it->second - it->first)*y+x + (r-l)*y+x;
        int cost_of_one = (r - it->first)*y+x;

            if (cost_of_one<cost_of_two)
            {
               free_tv.erase(it);
               used_tv.insert({r,ll});
            }
            else
            {

                used_tv.insert({r,l});
            }

    }
    while (used_tv.size() )
    {
        auto it = used_tv.begin();
        free_tv.insert({it->second,it->first});
        used_tv.erase(it);
    }
    for (auto it:free_tv)
    {
        ans+=(it.second-it.first)*y+x;
        ans%=mod;
    }
    cout << ans;

}


#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <fstream>
#include <iomanip>
#include <cmath>
#include <string>
using namespace std;

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

void stress();

signed main()
{
    need_for_speed;
    //srand(time(0));
    stress();
}

#define int long long
#define endl '\n'

int good(int n, int s)
{

    int ans = 0;
    ans+=s/n;
    s%=n;
    ans+=(s!=0);
   return ans;
}
int bad(int n, int s)
{
    return (s-1)/n+1;
}
void stressA()
{
    int t = 10000;
    while (t--)
    {
        int n = rand()%100+1;
        int s = rand()%100+1;
        if (good(n,s)!=bad(n,s))
        {
            cout << n << " "<< s << endl;
            break;
        }
    }
}

int goodB(int n, int m, vector<int> a)
{

    int sum = 0;
    for (int i= 0; i<n; i++) {
        sum+=a[i];
    }
    sort(a.begin(),a.end());
    reverse(a.begin(),a.end());
    int mx = a[0];
    int ans = 0;
    for (int i = 0; i+1<n; i++)
    {
        if (a[i+1]<mx)
        {
            ans+=mx-a[i+1];
            mx = a[i+1];
        }
        else
        {
            ans++;
            mx--;
        }

    }
    if (mx>0)
    {
        ans+=mx;
    } else ans++;
    cout << sum-ans;
}

int badB(int n, int m, vector<int> b)
{
    vector<int> a(n+1);
    for (int i = 0; i<n; i++)
        a[i+1] = b[i];
    sort(a.begin()+1,a.end());
    long long ans = 0;
    int covered = a[n];
    for (int i = n; i; i--)
    {
        ans+=a[i];
        if (covered>a[i-1])
        {
            ans-=covered-a[i-1];
            covered = a[i-1];
        }
    }
}

int mod = 1e9+7;

void stress() {
    int n,x,y;
    cin >> n >> x >> y;
    vector<pair<int,int>> a(n);
    for (int i = 0; i<n; i++)
        cin >> a[i].first >> a[i].second;
    sort(a.begin(),a.end());
    multiset<pair<int,int>> tv;
    int ans = 0;
    for (int i = 0; i<n; i++)
    {
        int l = a[i].first, r= a[i].second;
        if (!tv.size())
        {
            tv.insert({r,l});
            continue;
        }
        auto it = tv.lower_bound({l,-1});
        if (it == tv.begin())
        {
            tv.insert({r,l});
        } else{
            it--;
            int cost_of_two = (it->first - it->second)*y+x + (r-l)*y+x;
            int cost_of_one = (r - it->second)*y+x;
            int ll = it->second ,rr = it->first;
            tv.erase(it);
            if (cost_of_one<cost_of_two)
            {
                tv.insert({r,ll});
            } else
            {
                ans+=(rr-ll)*y+x;
                ans%=mod;
                tv.insert({r,l});
            }
        }
    }
    for (auto it:tv)
    {
        ans+=(it.first-it.second)*y+x;
        ans%=mod;
    }
    cout << ans;

}


#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <fstream>
#include <iomanip>
#include <cmath>
#include <string>
using namespace std;

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

void stress();

signed main()
{
    need_for_speed;
    //srand(time(0));
    stress();
}

#define int long long
#define endl '\n'

int good(int n, int s)
{

    int ans = 0;
    ans+=s/n;
    s%=n;
    ans+=(s!=0);
   return ans;
}
int bad(int n, int s)
{
    return (s-1)/n+1;
}
void stressA()
{
    int t = 10000;
    while (t--)
    {
        int n = rand()%100+1;
        int s = rand()%100+1;
        if (good(n,s)!=bad(n,s))
        {
            cout << n << " "<< s << endl;
            break;
        }
    }
}

int goodB(int n, int m, vector<int> a)
{

    int sum = 0;
    for (int i= 0; i<n; i++) {
        sum+=a[i];
    }
    sort(a.begin(),a.end());
    reverse(a.begin(),a.end());
    int mx = a[0];
    int ans = 0;
    for (int i = 0; i+1<n; i++)
    {
        if (a[i+1]<mx)
        {
            ans+=mx-a[i+1];
            mx = a[i+1];
        }
        else
        {
            ans++;
            mx--;
        }

    }
    if (mx>0)
    {
        ans+=mx;
    } else ans++;
    cout << sum-ans;
}

int badB(int n, int m, vector<int> b)
{
    vector<int> a(n+1);
    for (int i = 0; i<n; i++)
        a[i+1] = b[i];
    sort(a.begin()+1,a.end());
    long long ans = 0;
    int covered = a[n];
    for (int i = n; i; i--)
    {
        ans+=a[i];
        if (covered>a[i-1])
        {
            ans-=covered-a[i-1];
            covered = a[i-1];
        }
    }
}

int mod = 1e9+7;
bool cmp(pair<int,int> a,pair<int,int> b)
{
    if (a.first!=b.first)
        return a.first<b.first;
    return a.second>b.second;
}
void stress() {
    int n,x,y;
    cin >> n >> x >> y;
    vector<pair<int,int>> a(n);
    for (int i = 0; i<n; i++)
        cin >> a[i].first >> a[i].second;
    sort(a.begin(),a.end(),cmp);
    set<pair<int,int>> tv;
    int ans = 0;
    for (int i = 0; i<n; i++)
    {
        int l = a[i].first, r= a[i].second;
        if (!tv.size())
        {
            tv.insert({r,l});
            continue;
        }
        auto it = tv.lower_bound({l,-1});
        if (it == tv.begin())
        {
            tv.insert({r,l});
        } else{
            it--;
            int cost_of_two = (it->first - it->second)*y+x + (r-l)*y+x;
            int cost_of_one = (r - it->second)*y+x;
            int ll = it->second ,rr = it->first;
            tv.erase(it);
            if (cost_of_one<cost_of_two)
            {
                tv.insert({r,ll});
            } else
            {
                ans+=(rr-ll)*y+x;
                ans%=mod;
                tv.insert({r,l});
            }
        }
    }
    for (auto it:tv)
    {
        ans+=(it.first-it.second)*y+x;
        ans%=mod;
    }
    cout << ans;

}


#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <fstream>
#include <iomanip>
#include <cmath>
#include <string>
using namespace std;

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

void stress();

signed main()
{
    need_for_speed;
    //srand(time(0));
    stress();
}

#define int long long
#define endl '\n'

int good(int n, int s)
{

    int ans = 0;
    ans+=s/n;
    s%=n;
    ans+=(s!=0);
   return ans;
}
int bad(int n, int s)
{
    return (s-1)/n+1;
}
void stressA()
{
    int t = 10000;
    while (t--)
    {
        int n = rand()%100+1;
        int s = rand()%100+1;
        if (good(n,s)!=bad(n,s))
        {
            cout << n << " "<< s << endl;
            break;
        }
    }
}

int goodB(int n, int m, vector<int> a)
{

    int sum = 0;
    for (int i= 0; i<n; i++) {
        sum+=a[i];
    }
    sort(a.begin(),a.end());
    reverse(a.begin(),a.end());
    int mx = a[0];
    int ans = 0;
    for (int i = 0; i+1<n; i++)
    {
        if (a[i+1]<mx)
        {
            ans+=mx-a[i+1];
            mx = a[i+1];
        }
        else
        {
            ans++;
            mx--;
        }

    }
    if (mx>0)
    {
        ans+=mx;
    } else ans++;
    cout << sum-ans;
}

int badB(int n, int m, vector<int> b)
{
    vector<int> a(n+1);
    for (int i = 0; i<n; i++)
        a[i+1] = b[i];
    sort(a.begin()+1,a.end());
    long long ans = 0;
    int covered = a[n];
    for (int i = n; i; i--)
    {
        ans+=a[i];
        if (covered>a[i-1])
        {
            ans-=covered-a[i-1];
            covered = a[i-1];
        }
    }
}

int mod = 1e9+7;

void stress() {
    int n,x,y;
    cin >> n >> x >> y;
    vector<pair<int,int>> a(n);
    for (int i = 0; i<n; i++)
        cin >> a[i].first >> a[i].second;
    sort(a.begin(),a.end());
    set<pair<int,int>> tv;
    int ans = 0;
    for (int i = 0; i<n; i++)
    {
        int l = a[i].first, r= a[i].second;
        if (!tv.size())
        {
            tv.insert({r,l});
            continue;
        }
        auto it = tv.lower_bound({l,-1});
        if (it == tv.begin())
        {
            tv.insert({r,l});
        } else{
            it--;
            int cost_of_two = (it->first - it->second)*y+x + (r-l)*y+x;
            int cost_of_one = (r - it->second)*y+x;
            int ll = it->second ,rr = it->first;
            tv.erase(it);
            if (cost_of_one<cost_of_two)
            {
                tv.insert({r,ll});
            } else
            {
                ans+=(rr-ll)*y+x;
                ans%=mod;
                tv.insert({r,l});
            }
        }
    }
    for (auto it:tv)
    {
        ans+=(it.first-it.second)*y+x;
        ans%=mod;
    }
    cout << ans;

}


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

using namespace std;

typedef long long ll;

const int MOD = (int)1e9 + 7;

int N, X, Y;
pair<int, int> input[100001];
ll cost[100001];
multiset<pair<int, int>> s;

int main(void)
{
	scanf("%d %d %d", &N, &X, &Y);

	for (int i = 1; i <= N; i++) {
		scanf("%d %d", &input[i].first, &input[i].second);
		s.insert({ input[i].second, input[i].first });
	}

	for (int i = 1; i <= N; i++) {
		cost[i] = X + (ll)Y * (input[i].second - input[i].first);

		if (s.empty() || s.begin()->first >= input[i].first)
			continue;

		auto it = s.lower_bound({ input[i].first, 0 });
		it--;

		if ((ll)Y * (input[i].first - it->first) < X) {
			cost[i] = (ll)Y * (input[i].second - it->first);
			s.erase(it);
		}
	}

	int res = 0;

	for (int i = 1; i <= N; i++)
		res = (res + cost[i]) % MOD;

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

	return 0;
}


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

using namespace std;

typedef long long ll;

const int MOD = (int)1e9 + 7;

int N, X, Y;
pair<int, int> input[100001];
int cost[100001];
multiset<int> s;

int main(void)
{
	scanf("%d %d %d", &N, &X, &Y);

	for (int i = 1; i <= N; i++) {
		scanf("%d %d", &input[i].first, &input[i].second);
		s.insert(input[i].second);
	}

	for (int i = 1; i <= N; i++) {
		cost[i] = (X + (ll)Y * (input[i].second - input[i].first)) % MOD;

		if (s.empty() || *s.begin() >= input[i].first)
			continue;

		auto it = s.lower_bound(input[i].first);
		it--;

		if ((ll)Y * (input[i].first - *it) < X) {
			cost[i] = (ll)Y * (input[i].second - *it);
			s.erase(it);
		}
	}

	int res = 0;

	for (int i = 1; i <= N; i++)
		res = (res + cost[i]) % MOD;

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

	return 0;
}


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

using namespace std;

typedef long long ll;

const int MOD = (int)1e9 + 7;

int N, X, Y;
pair<int, int> input[100001];
int cost[100001];
multiset<int> s;

int main(void)
{
	scanf("%d %d %d", &N, &X, &Y);

	for (int i = 1; i <= N; i++) {
		scanf("%d %d", &input[i].first, &input[i].second);
		s.insert(input[i].second);
	}

	for (int i = 1; i <= N; i++) {
		cost[i] = (X + (ll)Y * (input[i].second - input[i].first)) % MOD;

		if (s.empty() || *s.begin() >= input[i].first)
			continue;

		auto it = s.lower_bound(input[i].first);
		it--;

		if ((ll)Y * (input[i].first - *it) < X) {
			cost[i] = ((ll)Y * (input[i].second - *it)) % MOD;
			s.erase(it);
		}
	}

	int res = 0;

	for (int i = 1; i <= N; i++)
		res = (res + cost[i]) % MOD;

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

	return 0;
}


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

typedef long long ll;

using namespace std;

int N, X, Y;
pair<int, int> input[100001];
ll cost[100001];
multiset<pair<int, int>> s;

const int MOD = 1e9 + 7;

int main(void)
{
	scanf("%d %d %d", &N, &X, &Y);

	for (int i = 1; i <= N; i++) {
		scanf("%d %d", &input[i].first, &input[i].second);
		s.insert(make_pair(input[i].second, input[i].first));
	}

	sort(input + 1, input + 1 + N);

	for (int i = 1; i <= N; i++) {
		cost[i] = X + (ll)Y * (input[i].second - input[i].first);

		if (s.empty() || s.begin()->first >= input[i].first)
			continue;

		auto it = s.lower_bound({ input[i].first, 0 });
		it--;

		if (Y * (ll)(input[i].second - it->first) >= cost[i])
			continue;
		cost[i] = Y * (ll)(input[i].second - it->first);
		s.erase(it);
		/*if (X > Y * (ll)(input[i].first - it->first)) {
			cost[i] = Y * (input[i].second - it->first);
			s.erase(it);
		}*/
	}

	int res = 0;

	for (int i = 1; i <= N; i++)
		res = (res + cost[i]) % MOD;

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

	return 0;
}


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

using namespace std;

typedef long long ll;

const int MOD = (int)1e9 + 7;

int N, X, Y;
pair<int, int> input[100001];
int cost[100001];
multiset<int> s;

int main(void)
{
	scanf("%d %d %d", &N, &X, &Y);

	for (int i = 1; i <= N; i++) {
		scanf("%d %d", &input[i].first, &input[i].second);
		s.insert(input[i].second);
	}

	sort(input + 1, input + 1 + N);

	for (int i = 1; i <= N; i++) {
		cost[i] = (X + (ll)Y * (input[i].second - input[i].first)) % MOD;

		if (s.empty() || *s.begin() >= input[i].first)
			continue;

		auto it = s.lower_bound(input[i].first);
		it--;

		if ((ll)Y * (input[i].first - *it) < X) {
			cost[i] = ((ll)Y * (input[i].second - *it)) % MOD;
			s.erase(it);
		}
	}

	int res = 0;

	for (int i = 1; i <= N; i++)
		res = (res + cost[i]) % MOD;

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

	return 0;
}


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

typedef long long ll;

using namespace std;

int N, X, Y;
pair<int, int> input[100001];
ll cost[100001];
multiset<pair<int, int>> s;

const int MOD = 1e9 + 7;

int main(void)
{
	scanf("%d %d %d", &N, &X, &Y);

	for (int i = 1; i <= N; i++) {
		scanf("%d %d", &input[i].first, &input[i].second);
		s.insert(make_pair(input[i].second, input[i].first));
	}

	sort(input + 1, input + 1 + N);

	for (int i = 1; i <= N; i++) {
		cost[i] = X + (ll)Y * (input[i].second - input[i].first);

		if (s.empty() || s.begin()->first >= input[i].first)
			continue;

		auto it = s.lower_bound({ input[i].first, 0 });
		it--;

		if (Y * (ll)(input[i].first - it->first) >= X)
			continue;
		cost[i] = Y * (ll)(input[i].second - it->first);
		s.erase(it);
		/*if (X > Y * (ll)(input[i].first - it->first)) {
			cost[i] = Y * (input[i].second - it->first);
			s.erase(it);
		}*/
	}

	int res = 0;

	for (int i = 1; i <= N; i++)
		res = (res + cost[i]) % MOD;

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

	return 0;
}


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

typedef long long ll;

using namespace std;

int N, X, Y;
pair<int, int> input[100001];
ll cost[100001];
multiset<pair<int, int>> s;

const int MOD = 1e9 + 7;

int main(void)
{
	scanf("%d %d %d", &N, &X, &Y);

	for (int i = 1; i <= N; i++) {
		scanf("%d %d", &input[i].first, &input[i].second);
		s.insert(make_pair(input[i].second, input[i].first));
	}

	sort(input + 1, input + 1 + N);

	for (int i = 1; i <= N; i++) {
		cost[i] = X + (ll)Y * (input[i].second - input[i].first);

		if (s.empty() || s.begin()->first >= input[i].first)
			continue;

		auto it = s.lower_bound({ input[i].first, 0 });
		it--;

		if (X > Y * (ll)(input[i].first - it->first)) {
			cost[i] = Y * (input[i].second - it->first);
			s.erase(it);
		}
	}

	int res = 0;

	for (int i = 1; i <= N; i++)
		res = (res + cost[i]) % MOD;

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

	return 0;
}


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

using namespace std;

typedef long long ll;

const int MOD = (int)1e9 + 7;

int N, X, Y;
pair<int, int> input[100001];
ll cost[100001];
multiset<int> s;

int main(void)
{
	scanf("%d %d %d", &N, &X, &Y);

	for (int i = 1; i <= N; i++) {
		scanf("%d %d", &input[i].first, &input[i].second);
		s.insert(input[i].second);
	}

	for (int i = 1; i <= N; i++) {
		cost[i] = X + (ll)Y * (input[i].second - input[i].first);

		if (s.empty() || *s.begin() >= input[i].first)
			continue;

		auto it = s.lower_bound(input[i].first);
		it--;

		if ((ll)Y * (input[i].first - *it) < X) {
			cost[i] = (ll)Y * (input[i].second - *it);
			s.erase(it);
		}
	}

	int res = 0;

	for (int i = 1; i <= N; i++)
		res = (res + cost[i]) % MOD;

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

	return 0;
}


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

typedef long long ll;

using namespace std;

int N, X, Y;
pair<int, int> input[100001];
ll cost[100001];
multiset<pair<int, int>> s;

const int MOD = 1e9 + 7;

int main(void)
{
	scanf("%d %d %d", &N, &X, &Y);

	for (int i = 1; i <= N; i++) {
		scanf("%d %d", &input[i].first, &input[i].second);
		s.insert(make_pair(input[i].second, input[i].first));
	}

	sort(input + 1, input + 1 + N);

	for (int i = 1; i <= N; i++) {
		cost[i] = X + (ll)Y * (input[i].second - input[i].first);

		if (s.empty() || s.begin()->first >= input[i].first)
			continue;

		auto it = s.lower_bound({ input[i].first, 0 });
		it--;

		if (Y * (ll)(input[i].first - it->first) < X) {
			cost[i] = Y * (ll)(input[i].second - it->first);
			s.erase(it);
		}
	}

	int res = 0;

	for (int i = 1; i <= N; i++)
		res = (res + cost[i]) % MOD;

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

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define PB push_back
#define MP make_pair
#define f first
#define s second
#define FOR(i,a,b) for (int i = a; i < b; ++i)
#define RFOR(i, b, a) for (int i = b-1; i>=a; --i)
#define FILL(a, b) memset(a, b, sizeof a)
#define ALL(a) a.begin(), a.end()
#define SZ(a) ((int)a.size())
#define MAGIC0
mt19937 rnd(time(0)); //rnd()

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = 1LL * INF*INF;
const int MAX = 1e5 + 7;
const double PI = acos(-1.);
const double EPS = 1e-8;

const int N = 5e5 + 7;
VI x[N];

#define int LL

main()
{
	ios_base::sync_with_stdio(0);
	int n, x, y;
	cin >> n >> x >> y;
	PII a[n + 1];
	VI cost(n + 1);
	multiset<pair<PII, int>> S;
	for(int i = 1;i <= n;++i)
	{
		cin >> a[i].f >> a[i].s;
		S.insert({{a[i].s, a[i].f}, i});
	}

	sort(a + 1, a + n + 1);
	for(int i = 1;i <= n;++i)
	{
		cost[i] = x + y * (a[i].s - a[i].f);
		if (S.empty() || S.begin()->f.f >= a[i].f)
			continue;
		auto it = S.lower_bound({{a[i].f, 0}, 0});
		int pr = (--it)->f.f;
		if (y * (a[i].s - pr) >= cost[i])
		{
			continue;
		}
		cost[i] = y * (a[i].s - pr);
		S.erase(it);
	}

	int ans = 0;
	FOR(i, 1, n + 1) ans += cost[i];cout << ans;

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define PB push_back
#define MP make_pair
#define f first
#define s second
#define FOR(i,a,b) for (int i = a; i < b; ++i)
#define RFOR(i, b, a) for (int i = b-1; i>=a; --i)
#define FILL(a, b) memset(a, b, sizeof a)
#define ALL(a) a.begin(), a.end()
#define SZ(a) ((int)a.size())
#define MAGIC0
mt19937 rnd(time(0)); //rnd()

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = 1LL * INF*INF;
const int MAX = 1e5 + 7;
const double PI = acos(-1.);
const double EPS = 1e-8;

const int N = 5e5 + 7;
VI x[N];

#define int LL

main()
{
	ios_base::sync_with_stdio(0);
	int n, x, y;
	cin >> n >> x >> y;
	PII a[n + 1];
	VI cost(n + 1);
	multiset<pair<PII, int>> S;
	for(int i = 1;i <= n;++i)
	{
		cin >> a[i].f >> a[i].s;
		S.insert({{a[i].s, a[i].f}, i});
	}

	sort(a + 1, a + n + 1);
	for(int i = 1;i <= n;++i)
	{
		cost[i] = x + y * (a[i].s - a[i].f);
		cost[i] %= INF;
		if (S.empty() || S.begin()->f.f >= a[i].f)
			continue;
		auto it = S.lower_bound({{a[i].f, 0}, 0});
		int pr = (--it)->f.f;
		if (y * (a[i].s - pr) >= cost[i])
		{
			continue;
		}
		cost[i] = y * (a[i].s - pr) % INF;
		S.erase(it);
	}

	int ans = 0;
	FOR(i, 1, n + 1) ans += cost[i] % INF;cout << ans % INF;

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define PB push_back
#define MP make_pair
#define f first
#define s second
#define FOR(i,a,b) for (int i = a; i < b; ++i)
#define RFOR(i, b, a) for (int i = b-1; i>=a; --i)
#define FILL(a, b) memset(a, b, sizeof a)
#define ALL(a) a.begin(), a.end()
#define SZ(a) ((int)a.size())
#define MAGIC0
mt19937 rnd(time(0)); //rnd()

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = 1LL * INF*INF;
const int MAX = 1e5 + 7;
const double PI = acos(-1.);
const double EPS = 1e-8;

const int N = 5e5 + 7;
VI x[N];

#define int LL

main()
{
	ios_base::sync_with_stdio(0);
	int n, x, y;
	cin >> n >> x >> y;
	PII a[n + 1];
	VI cost(n + 1);
	multiset<pair<PII, int>> S;
	for(int i = 1;i <= n;++i)
	{
		cin >> a[i].f >> a[i].s;
		S.insert({{a[i].s, a[i].f}, i});
	}

	sort(a + 1, a + n + 1);
	for(int i = 1;i <= n;++i)
	{
		cost[i] = x + y * (a[i].s - a[i].f);
		if (S.empty() || S.begin()->f.f >= a[i].f)
			continue;
		auto it = S.lower_bound({{a[i].f, 0}, 0});
		int pr = (--it)->f.f;
		if (y * (a[i].s - pr) >= cost[i])
		{
			continue;
		}
		cost[i] = y * (a[i].s - pr);
		S.erase(it);
	}

	int ans = 0;
	FOR(i, 1, n + 1) ans += cost[i] % INF;cout << ans % INF;

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define PB push_back
#define MP make_pair
#define f first
#define s second
#define FOR(i,a,b) for (int i = a; i < b; ++i)
#define RFOR(i, b, a) for (int i = b-1; i>=a; --i)
#define FILL(a, b) memset(a, b, sizeof a)
#define ALL(a) a.begin(), a.end()
#define SZ(a) ((int)a.size())
#define MAGIC0
mt19937 rnd(time(0)); //rnd()

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = 1LL * INF*INF;
const int MAX = 1e5 + 7;
const double PI = acos(-1.);
const double EPS = 1e-8;

#define int LL
const int N = 5e5 + 7;
VI x[N];

main()
{
	ios_base::sync_with_stdio(0);
	int n, x, y;
	cin >> n >> x >> y;
	PII a[n + 1];
	VI cost(n + 1);
	multiset<pair<PII, int>> S;
	for(int i = 1;i <= n;++i)
	{
		cin >> a[i].f >> a[i].s;
		S.insert({{a[i].s, a[i].f}, i});
	}

	sort(a + 1, a + n + 1);
	for(int i = 1;i <= n;++i)
	{
		cost[i] = x + y * (a[i].s - a[i].f);
		if (S.empty() || S.begin()->f.f >= a[i].f)
			continue;
		auto it = S.lower_bound({{a[i].f, 0}, 0});
		int pr = (--it)->f.f;
		if (y * (a[i].s - pr) >= cost[i])
		{
			continue;
		}
		cost[i] = y * (a[i].s - pr);
		S.erase(it);
	}

	int ans = 0;
	FOR(i, 1, n + 1)
	{
		ans += cost[i];
		ans %= INF;
	}
	cout << ans % INF;

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define PB push_back
#define MP make_pair
#define f first
#define s second
#define FOR(i,a,b) for (int i = a; i < b; ++i)
#define RFOR(i, b, a) for (int i = b-1; i>=a; --i)
#define FILL(a, b) memset(a, b, sizeof a)
#define ALL(a) a.begin(), a.end()
#define SZ(a) ((int)a.size())

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = 1LL * INF*INF;
const int MAX = 1e5;
const double PI = acos(-1.);
const double EPS = 1e-8;

#define MAGIC0
mt19937 rnd(time(0)); //rnd()

#define int LL

main()
{
	ios_base::sync_with_stdio(0);
//	freopen("rmq.in", "r", stdin);
//	freopen("rmq.out", "w", stdout);
	LL n, x, y;
	cin >> n >> x >> y;
	VI l(n), r(n);
	multiset<PII> s;
	FOR(i, 0, n)
	{
		cin >> l[i] >> r[i];
		s.insert(MP(l[i], r[i] - l[i]));
	}

	vector<PII> res;
	while(true && !s.empty())
	{
		auto it = s.upper_bound(MP(s.begin()->f + s.begin()->s , INF));
		if (it != s.end())
		{
			LL a = 2 * x + s.begin()->s * y + it->s * y;
			LL b = x + (it->f + it->s - s.begin()->f) * y;
//			cout << a << " " << b << endl;
			if (a > b)
			{
				s.insert({s.begin()->f, it->f + it->s - s.begin()->f});
				s.erase(it);
				s.erase(s.begin());
			}
			else
			{
				res.PB({s.begin()->f, s.begin()->s});
				s.erase(s.begin());
			}
		}
		else
		{
			res.PB({s.begin()->f, s.begin()->s});
			s.erase(s.begin());
		}
	}

	LL ans = 0;
	for(auto i : res)
	{
		ans += (LL)i.s * y + x;
		ans %= INF;
	}

	cout << ans;

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define PB push_back
#define MP make_pair
#define f first
#define s second
#define FOR(i,a,b) for (int i = a; i < b; ++i)
#define RFOR(i, b, a) for (int i = b-1; i>=a; --i)
#define FILL(a, b) memset(a, b, sizeof a)
#define ALL(a) a.begin(), a.end()
#define SZ(a) ((int)a.size())

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = 1LL * INF*INF;
const int MAX = 1e5;
const double PI = acos(-1.);
const double EPS = 1e-8;

#define MAGIC0
mt19937 rnd(time(0)); //rnd()

#define int LL

int main()
{
	ios_base::sync_with_stdio(0);
//	freopen("rmq.in", "r", stdin);
//	freopen("rmq.out", "w", stdout);
	LL n, x, y;
	cin >> n >> x >> y;
	VI l(n), r(n);
	multiset<PII> s;
	FOR(i, 0, n)
	{
		cin >> l[i] >> r[i];
		s.insert(MP(l[i], r[i] - l[i]));
	}

	vector<PII> res;
	while(true && !s.empty())
	{
		auto it = s.upper_bound(MP(s.begin()->f + s.begin()->s , INF));
		if (it != s.end())
		{
			LL a = 2 * x + s.begin()->s * y + it->s * y;
			LL b = x + (it->f + it->s - s.begin()->f) * y;
//			cout << a << " " << b << endl;
			if (a > b)
			{
				s.insert({s.begin()->f, it->f + it->s - s.begin()->f});
				s.erase(it);
				s.erase(s.begin());
			}
			else
			{
				res.PB({s.begin()->f, s.begin()->s});
				s.erase(s.begin());
			}
		}
		else
		{
			res.PB({s.begin()->f, s.begin()->s});
			s.erase(s.begin());
		}
	}

	LL ans = 0;
	for(auto i : res)
	{
		ans += (LL)i.s * y + x;
		ans %= INF;
	}

	cout << ans;

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define int long long
#define PB push_back
#define MP make_pair
#define f first
#define s second
#define FOR(i,a,b) for (int i = a; i < b; ++i)
#define RFOR(i, b, a) for (int i = b-1; i>=a; --i)
#define FILL(a, b) memset(a, b, sizeof a)
#define ALL(a) a.begin(), a.end()
#define SZ(a) ((int)a.size())
#define MAGIC0
mt19937 rnd(time(0)); //rnd()

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = 1LL * INF*INF;
const int MAX = 1e5 + 7;
const double PI = acos(-1.);
const double EPS = 1e-8;

const int N = 5e5 + 7;
VI x[N];

main()
{
	ios_base::sync_with_stdio(0);
	int n, x, y;
	cin >> n >> x >> y;
	PII a[n + 1];
	VI cost(n + 1);
	multiset<pair<PII, int>> S;
	for(int i = 1;i <= n;++i)
	{
		cin >> a[i].f >> a[i].s;
		S.insert({{a[i].s, a[i].f}, i});
	}

	sort(a + 1, a + n + 1);
	for(int i = 1;i <= n;++i)
	{
		cost[i] = x + y * (a[i].s - a[i].f);
		if (S.empty() || S.begin()->f.f >= a[i].f)
			continue;
		auto it = S.lower_bound({{a[i].f, 0}, 0});
		int pr = (--it)->f.f;
		if (y * (a[i].s - pr) >= cost[i])
		{
			continue;
		}
		cost[i] = y * (a[i].s - pr);
		S.erase(it);
	}

	int ans = 0;
	FOR(i, 1, n + 1)
	{
		ans += cost[i];
		ans %= INF;
	}
	cout << ans % INF;

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define PB push_back
#define MP make_pair
#define f first
#define s second
#define FOR(i,a,b) for (int i = a; i < b; ++i)
#define RFOR(i, b, a) for (int i = b-1; i>=a; --i)
#define FILL(a, b) memset(a, b, sizeof a)
#define ALL(a) a.begin(), a.end()
#define SZ(a) ((int)a.size())
#define MAGIC0
mt19937 rnd(time(0)); //rnd()

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = 1LL * INF*INF;
const int MAX = 1e5 + 7;
const double PI = acos(-1.);
const double EPS = 1e-8;

#define int LL
const int N = 5e5 + 7;
VI x[N];

main()
{
	ios_base::sync_with_stdio(0);
	int n, x, y;
	cin >> n >> x >> y;
	PII a[n + 1];
	VI cost(n + 1);
	multiset<pair<PII, int>> S;
	for(int i = 1;i <= n;++i)
	{
		cin >> a[i].f >> a[i].s;
		S.insert({{a[i].s, a[i].f}, i});
	}

	sort(a + 1, a + n + 1);
	for(int i = 1;i <= n;++i)
	{
		cost[i] = x + y * (a[i].s - a[i].f);
		cost[i] %= INF;
		if (S.empty() || S.begin()->f.f >= a[i].f)
			continue;
		auto it = S.lower_bound({{a[i].f, 0}, 0});
		int pr = (--it)->f.f;
		if (y * (a[i].s - pr) >= cost[i])
		{
			continue;
		}
		cost[i] = y * (a[i].s - pr) % INF;
		S.erase(it);
	}

	int ans = 0;
	FOR(i, 1, n + 1) ans += cost[i] % INF;
	cout << ans % INF;

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define PB push_back
#define MP make_pair
#define f first
#define s second
#define FOR(i,a,b) for (int i = a; i < b; ++i)
#define RFOR(i, b, a) for (int i = b-1; i>=a; --i)
#define FILL(a, b) memset(a, b, sizeof a)
#define ALL(a) a.begin(), a.end()
#define SZ(a) ((int)a.size())

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = 1LL * INF*INF;
const int MAX = 1e5;
const double PI = acos(-1.);
const double EPS = 1e-8;

#define MAGIC0
mt19937 rnd(time(0)); //rnd()

int main()
{
	ios_base::sync_with_stdio(0);
//	freopen("rmq.in", "r", stdin);
//	freopen("rmq.out", "w", stdout);
	LL n, x, y;
	cin >> n >> x >> y;
	VI l(n), r(n);
	multiset<PII> s;
	FOR(i, 0, n)
	{
		cin >> l[i] >> r[i];
		s.insert(MP(l[i], r[i] - l[i]));
	}

	vector<PII> res;
	while(true && !s.empty())
	{
		auto it = s.upper_bound(MP(s.begin()->f + s.begin()->s , INF));
		if (it != s.end())
		{
			LL a = 2 * x + s.begin()->s * y + it->s * y;
			LL b = x + (it->f + it->s - s.begin()->f) * y;
//			cout << a << " " << b << endl;
			if (a > b)
			{
				s.insert({s.begin()->f, it->f + it->s - s.begin()->f});
				s.erase(it);
				s.erase(s.begin());
			}
			else
			{
				res.PB({s.begin()->f, s.begin()->s});
				s.erase(s.begin());
			}
		}
		else
		{
			res.PB({s.begin()->f, s.begin()->s});
			s.erase(s.begin());
		}
	}

	LL ans = 0;
	for(auto i : res)
	{
		ans += (LL)i.s * y + x;
		ans %= INF;
	}

	cout << ans;

	return 0;
}


#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <string>

using namespace std;

#define x first
#define y second
#define all(v) v.begin(), v.end()
#define int long long
#define mod 1000000007

int32_t main()
{
    cin.tie(NULL);
    cout.tie(NULL);
    ios::sync_with_stdio(false);
    int n, x, y;
    cin >> n >> x >> y;
    vector<pair<int, int>> a(n);
    for(int i = 0; i < n; i++) cin >> a[i].x >> a[i].y;
    sort(all(a));
    multiset<int> r;
    int ans = 0;
    for(auto i : a)
    {
        auto tmp = upper_bound(all(r), -i.x);
        auto t2 = -*tmp;
        if(tmp == r.end())
        {
            r.insert(-i.y);
            ans += x + (i.y - i.x) * y;
            ans %= mod;
            continue;
        }
        if((i.x - t2) * y >= x)
        {
            r.insert(-i.y);
            ans += x + (i.y - i.x) * y;
            ans %= mod;
            continue;
        }
        ans += (i.y - t2) * y;
        ans %= mod;
        r.erase(tmp);
        r.insert(-i.y);
    }
    cout << ans;
    return 0;
}


#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <string>

using namespace std;

#define x first
#define y second
#define all(v) v.begin(), v.end()
#define int long long
#define mod 1000000007

int32_t main()
{
    int n, x, y;
    cin >> n >> x >> y;
    vector<pair<int, int>> a(n);
    for(int i = 0; i < n; i++) cin >> a[i].x >> a[i].y;
    sort(all(a));
    set<int> r;
    int ans = 0;
    for(auto i : a)
    {
        auto tmp = upper_bound(all(r), -i.x);

        auto t2 = -*tmp;
        if(tmp == r.end())
        {
            r.insert(-i.y);
            ans += x + (i.y - i.x) * y;
            ans %= mod;
            continue;
        }
        if((i.x - t2) * y >= x)
        {
            r.insert(-i.y);
            ans += x + (i.y - i.x) * y;
            ans %= mod;
            continue;
        }
        ans += (i.y - t2) * y;
        ans %= mod;
        r.erase(tmp);
        r.insert(-i.y);
    }
    cout << ans;
    return 0;
}


#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <string>

using namespace std;

#define x first
#define y second
#define all(v) v.begin(), v.end()
#define int long long
#define mod 1000000007

int32_t main()
{
    cin.tie(NULL);
    cout.tie(NULL);
    ios::sync_with_stdio(false);
    int n, x, y;
    cin >> n >> x >> y;
    vector<pair<int, int>> a(n);
    for(int i = 0; i < n; i++) cin >> a[i].x >> a[i].y;
    sort(all(a));
    multiset<int> r;
    int ans = 0;
    for(auto i : a)
    {
        auto tmp = r.upper_bound(-i.x);
        if(tmp == r.end())
        {
            r.insert(-i.y);
            ans += x + (i.y - i.x) * y;
            ans %= mod;
            continue;
        }
        auto t2 = -(*tmp);
        if((i.x - t2) * y >= x)
        {
            r.insert(-i.y);
            ans += x + (i.y - i.x) * y;
            ans %= mod;
            continue;
        }
        ans += (i.y - t2) * y;
        ans %= mod;
        r.erase(tmp);
        r.insert(-i.y);
    }
    cout << ans;
    return 0;
}


#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <string>

using namespace std;

#define x first
#define y second
#define all(v) v.begin(), v.end()
#define int long long
#define mod 1000000007

int32_t main()
{
    cin.tie(NULL);
    cout.tie(NULL);
    ios::sync_with_stdio(false);
    int n, x, y;
    cin >> n >> x >> y;
    vector<pair<int, int>> a(n);
    for(int i = 0; i < n; i++) cin >> a[i].x >> a[i].y;
    if(n > 10000) return 2;
    sort(all(a));
    set<int> r;
    int ans = 0;
    for(auto i : a)
    {
        auto tmp = upper_bound(all(r), -i.x);

        auto t2 = -*tmp;
        if(tmp == r.end())
        {
            r.insert(-i.y);
            ans += x + (i.y - i.x) * y;
            ans %= mod;
            continue;
        }
        if((i.x - t2) * y >= x)
        {
            r.insert(-i.y);
            ans += x + (i.y - i.x) * y;
            ans %= mod;
            continue;
        }
        ans += (i.y - t2) * y;
        ans %= mod;
        r.erase(tmp);
        r.insert(-i.y);
    }
    cout << ans;
    return 0;
}


#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <string>

using namespace std;

#define x first
#define y second
#define all(v) v.begin(), v.end()
#define int long long
#define mod 1000000007

int32_t main()
{
    cin.tie(NULL);
    cout.tie(NULL);
    ios::sync_with_stdio(false);
    int n, x, y;
    cin >> n >> x >> y;
    vector<pair<int, int>> a(n);
    for(int i = 0; i < n; i++) cin >> a[i].x >> a[i].y;
    sort(all(a));
    set<int> r;
    int ans = 0;
    for(auto i : a)
    {
        auto tmp = upper_bound(all(r), -i.x);

        auto t2 = -*tmp;
        if(tmp == r.end())
        {
            r.insert(-i.y);
            ans += x + (i.y - i.x) * y;
            ans %= mod;
            continue;
        }
        if((i.x - t2) * y >= x)
        {
            r.insert(-i.y);
            ans += x + (i.y - i.x) * y;
            ans %= mod;
            continue;
        }
        ans += (i.y - t2) * y;
        ans %= mod;
        r.erase(tmp);
        r.insert(-i.y);
    }
    cout << ans;
    return 0;
}


#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <string>

using namespace std;

#define x first
#define y second
#define all(v) v.begin(), v.end()
#define int long long
#define mod 1000000007

int32_t main()
{
    cin.tie(NULL);
    cout.tie(NULL);
    ios::sync_with_stdio(false);
    int n, x, y;
    cin >> n >> x >> y;
    vector<pair<int, int>> a(n);
    for(int i = 0; i < n; i++) cin >> a[i].x >> a[i].y;
    sort(all(a));
    multiset<int> r;
    int ans = 0;
    for(auto i : a)
    {
        auto tmp = upper_bound(all(r), -i.x);
        if(tmp == r.end())
        {
            r.insert(-i.y);
            ans += x + (i.y - i.x) * y;
            ans %= mod;
            continue;
        }
        auto t2 = -*tmp;
        if((i.x - t2) * y >= x)
        {
            r.insert(-i.y);
            ans += x + (i.y - i.x) * y;
            ans %= mod;
            continue;
        }
        ans += (i.y - t2) * y;
        ans %= mod;
        r.erase(tmp);
        r.insert(-i.y);
    }
    cout << ans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e6+100;

multiset<ll>ss;
ll mod=1e9+7;
struct node {
    ll s,t;
}s[N];
ll n,x,y;
int main() {
    ll ans=0;
    cin>>n>>x>>y;
    for(int i=1;i<=n;i++) scanf("%lld%lld",&s[i].s,&s[i].t);
    sort(s+1,s+1+n,[](node a,node b){return a.s<b.s;});

    ans=x+y*(s[1].t-s[1].s);
    ans%=mod;
    ss.insert(s[1].t);

    for(int i=2;i<=n;i++) {
        //printf("ans=%d %lld\n",i-1,ans);
        auto it=ss.lower_bound(s[i].s);
        ll temp=x+y*(s[i].t-s[i].s);
        if(it==ss.begin()) {
            ans=(ans+temp)%mod;ss.insert(s[i].t);
            continue;
        }
        it--;
        ll temp2=y*(s[i].t-*it);
        ss.erase(it);
        ans=(ans+min(temp,temp2))%mod;
        ss.insert(s[i].t);
    }
    cout<<ans;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e6+100;

set<ll>ss;
ll mod=1e9+7;
struct node {
    ll s,t;
}s[N];
ll n,x,y;
int main() {
    ll ans=0;
    cin>>n>>x>>y;
    for(int i=1;i<=n;i++) scanf("%lld%lld",&s[i].s,&s[i].t);
    sort(s+1,s+1+n,[](node a,node b){return a.s<b.s;});

    ans=x+y*(s[1].t-s[1].s);
    ans%=mod;
    ss.insert(s[1].t);

    for(int i=2;i<=n;i++) {
        //printf("ans=%d %lld\n",i-1,ans);
        auto it=ss.lower_bound(s[i].s);
        ll temp=x+y*(s[i].t-s[i].s);
        if(it==ss.begin()) {
            ans=(ans+temp)%mod;ss.insert(s[i].t);
            continue;
        }
        it--;
        ll temp2=y*(s[i].t-*it);
        ss.erase(it);
        ans=(ans+min(temp,temp2))%mod;
        ss.insert(s[i].t);
    }
    cout<<ans;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e6+100;

set<ll>ss;
ll mod=1e9+7;
struct node {
    ll s,t;
}s[N];
ll n,x,y;
int main() {
    ll ans=0;
    cin>>n>>x>>y;
    for(int i=1;i<=n;i++) scanf("%lld%lld",&s[i].s,&s[i].t);
    sort(s+1,s+1+n,[](node a,node b){return a.s<b.s;});

    for(int i=1;i<=n;i++) {
        //printf("i=%d\n",i);

        auto it=ss.lower_bound(s[i].s);
        ll temp=x+y*(s[i].t-s[i].s);
        if(it==ss.begin()) {ans=(ans+temp)%mod;ss.insert(s[i].t);continue;}
        ll temp2;
        it--;
        if(it==ss.begin()) temp2=1e9;
        else temp2=y*(s[i].t-*it);
        //printf("it=%lld ",*it);

        ans=(ans+min(temp,temp2))%mod;
        ss.insert(s[i].t);
    }
    cout<<ans;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e6+100;

set<ll>ss;
ll mod=1e9+7;
struct node {
    ll s,t;
}s[N];
ll n,x,y;
int main() {
    ll ans=0;
    cin>>n>>x>>y;
    for(int i=1;i<=n;i++) scanf("%lld%lld",&s[i].s,&s[i].t);
    sort(s+1,s+1+n,[](node a,node b){return a.s<b.s;});

    ans=x+y*(s[1].t-s[1].s);
    ans%=mod;
    ss.insert(s[1].t);
    for(int i=2;i<=n;i++) {
        auto it=ss.lower_bound(s[i].s);

        ll temp=x+y*(s[i].t-s[i].s);
        if(it==ss.begin()) {
            ans=(ans+temp)%mod;ss.insert(s[i].t);
            continue;
        }

        it--;
        ll temp2=y*(s[i].t-*it);

        ans=(ans+min(temp,temp2))%mod;
        ss.insert(s[i].t);
    }
    cout<<ans;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e6+100;

set<ll>ss;
ll mod=1e9+7;
struct node {
    ll s,t;
}s[N];
ll n,x,y;
int main() {
    ll ans=0;
    cin>>n>>x>>y;
    for(int i=1;i<=n;i++) scanf("%lld%lld",&s[i].s,&s[i].t);
    sort(s+1,s+1+n,[](node a,node b){return a.s<b.s;});

    ans+=x+y*(s[1].t-s[1].s);
    ss.insert(s[1].t);
    for(int i=2;i<=n;i++) {
        auto it=ss.lower_bound(s[i].s);

        ll temp=x+y*(s[i].t-s[i].s);
        if(it==ss.begin()) {
            ans=(ans+temp)%mod;ss.insert(s[i].t);
            continue;
        }

        it--;
        ll temp2=y*(s[i].t-*it);

        ans=(ans+min(temp,temp2))%mod;
        ss.insert(s[i].t);
    }
    cout<<ans;
}


#include<iostream>
#include <string>
#include <math.h>
using namespace std;
int number[10];
int main()
{
	string str;
	string::iterator siter;
	int rlst=0;
	cin>>str;
	if(str.size()%2)
		rlst=-1;

	if(rlst!=-1)
	{
		for (siter=str.begin();siter!=str.end();siter++)
		{
			switch(*siter)
			{
			case 'U':
				number[0]++;
				break;
			case 'D':
				number[1]++;
				break;
			case 'L':
				number[2]++;
				break;
			case 'R':
				number[3]++;
				break;
			}
		}
	}
	/*if(number[0]==number[1])
		if(number[2]==number[3])
			rlst=-1;*/

	if(rlst!=-1)
	{
	    if((abs(number[0]-number[1])%2)==(abs(number[2]-number[3])%2))
			rlst=abs(number[0]-number[1])<abs(number[2]-number[3])?
			abs(number[0]-number[1])+(abs(number[2]-number[3])-abs(number[0]-number[1]))/2:
			abs(number[2]-number[3])+(abs(number[0]-number[1])-abs(number[2]-number[3]))/2;
		else if(number[0]==number[1])
			rlst=abs(number[2]-number[3])/2;
		else if(number[2]==number[3])
			rlst=abs(number[0]-number[1])/2;

		else
			rlst=-1;
	}
	cout<<rlst<<endl;
	return 0;
}


#include<iostream>
#include <string>
#include <math.h>
using namespace std;
int number[10];
int main()
{
	string str;
	string::iterator siter;
	int rlst=0;
	cin>>str;
	if(str.size()%2)
		rlst=-1;

	if(rlst!=-1)
	{
		for (siter=str.begin();siter!=str.end();siter++)
		{
			switch(*siter)
			{
			case 'U':
				number[0]++;
				break;
			case 'D':
				number[1]++;
				break;
			case 'L':
				number[2]++;
				break;
			case 'R':
				number[3]++;
				break;
			}
		}
	}
	/*if(number[0]==number[1])
		if(number[2]==number[3])
			rlst=-1;*/

	if(rlst!=-1)
	{
	    if((abs(number[0]-number[1])%2)==(abs(number[2]-number[3])%2))
			rlst=abs(number[0]-number[1])<abs(number[2]-number[3])?
			abs(number[0]-number[1])+(abs(number[2]-number[3])-abs(number[0]-number[1]))/2:
			abs(number[2]-number[3])+(abs(number[0]-number[1])-abs(number[2]-number[3]))/2;
		else
			rlst=-1;
	}
	cout<<rlst<<endl;
	return 0;
}


#include<iostream>
#include <string>
#include <math.h>
using namespace std;
int number[10];
int main()
{
	string str;
	string::iterator siter;
	int rlst=0;
	cin>>str;
	if(str.size()%2)
		rlst=-1;

	if(rlst!=-1)
	{
		for (siter=str.begin();siter!=str.end();siter++)
		{
			switch(*siter)
			{
			case 'U':
				number[0]++;
				break;
			case 'D':
				number[1]++;
				break;
			case 'L':
				number[2]++;
				break;
			case 'R':
				number[3]++;
				break;
			}
		}
	}
	if(number[0]==number[1])
		if(number[2]==number[3])
			rlst=-1;

	if(rlst!=-1)
	{
		if(abs(number[0]-number[1])==abs(number[2]-number[3]))
			rlst=abs(number[0]-number[1]);
		else if(number[0]==number[1])
			rlst=abs(number[2]-number[3])/2;
		else if(number[2]==number[3])
			rlst=abs(number[0]-number[1])/2;
		else
			rlst=-1;
	}
	cout<<rlst<<endl;
	return 0;
}


#include<iostream>
#include <string>
#include <math.h>
using namespace std;
int number[10];
int main()
{
	string str;
	string::iterator siter;
	int rlst=0;
	cin>>str;
	if(str.size()%2)
		rlst=-1;

	if(rlst!=-1)
	{
		for (siter=str.begin();siter!=str.end();siter++)
		{
			switch(*siter)
			{
			case 'U':
				number[0]++;
				break;
			case 'D':
				number[1]++;
				break;
			case 'L':
				number[2]++;
				break;
			case 'R':
				number[3]++;
				break;
			}
		}
	}
	if(number[0]==number[1])
		if(number[2]==number[3])
			rlst=-1;

	if(rlst!=-1)
	{
		if(abs(number[0]-number[1])==abs(number[2]-number[3]))
			rlst=abs(number[0]-number[1]);
		else
			rlst=-1;
	}
	cout<<rlst<<endl;
	return 0;
}


#include<iostream>
#include <string>
#include <math.h>
using namespace std;
int number[10];
int main()
{
	string str;
	string::iterator siter;
	int rlst=0;
	cin>>str;
	if(str.size()%2)
		rlst=-1;

	if(rlst!=-1)
	{
		for (siter=str.begin();siter!=str.end();siter++)
		{
			switch(*siter)
			{
			case 'U':
				number[0]++;
				break;
			case 'D':
				number[1]++;
				break;
			case 'L':
				number[2]++;
				break;
			case 'R':
				number[3]++;
				break;
			}
		}
	}
	/*if(number[0]==number[1])
	if(number[2]==number[3])
	rlst=-1;*/

	if(rlst!=-1)
	{
	    if((abs(number[0]-number[1])%2)==(abs(number[2]-number[3])%2))
			rlst=abs(number[0]-number[1]);
		else
			rlst=-1;
	}
	cout<<rlst<<endl;
	return 0;
}


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

int compare(const void *first, const void *second)
{
	if (*(int*)first > *(int*)second)
		return 1;
	else if (*(int*)first < *(int*)second)
		return -1;
	else
		return 0;
}

char str[100001];

int main()
{
	scanf("%s", str);

	int strleng = 0;
	int L = 0, R = 0, U = 0, D = 0;
	int a, b, c;

	while (str[strleng] != '\0')
	{
		strleng++;
	}

	qsort(str, strleng, sizeof(char), compare);

	for (int i = 0; i < strleng; i++)
	{
		if (str[i] == 'L')
		{
			L++;
		}
		else if (str[i] == 'R')
		{
			R++;
		}
		else if (str[i] == 'U')
		{
			U++;
		}
		else if (str[i] == 'D')
		{
			D++;
		}
	}

	a = abs(L - R);
	b = abs(U - D);

	if (a == b)
	{
		printf("%d", a);
	}
	else
	{
		if (a < b)
		{
			c = a;
		}
		else
		{
			c = b;
		}
		a = abs(a - b);

		if (a % 2 == 0)
		{
			c += (a / 2);
			printf("%d", c);
		}
		else
		{
			printf("-1");
		}
	}
}


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

int compare(const void *first, const void *second)
{
	if (*(int*)first > *(int*)second)
		return 1;
	else if (*(int*)first < *(int*)second)
		return -1;
	else
		return 0;
}

char str[100001];

int main()
{
	scanf("%s", str);

	int strleng = 0;
	int L = 0, R = 0, U = 0, D = 0;
	int a, b;

	while (str[strleng] != '\0')
	{
		strleng++;
	}

	qsort(str, strleng, sizeof(char), compare);

	for (int i = 0; i < strleng; i++)
	{
		if (str[i] == 'L')
		{
			L++;
		}
		else if (str[i] == 'R')
		{
			R++;
		}
		else if (str[i] == 'U')
		{
			U++;
		}
		else if (str[i] == 'D')
		{
			D++;
		}
	}

	a = abs(L - R);
	b = abs(U - D);

	if (a == b)
	{
		printf("%d", a);
	}
	else
	{
		printf("-1");
	}
}


#include<fstream>
#include<algorithm>
#include<string>
#include<map>
#include<vector>
#include<iostream>
#include<iomanip>
#include<cmath>
#include<queue>
#include<set>
#include<stdio.h>

using namespace std;
ifstream in("input.txt");
ofstream out("output.txt");

string s;

bool check(int i, int j){
	if(s[i] == 'U' && s[j] == 'D' || s[j] == 'U' && s[i] == 'D')return true;
	if(s[i] == 'L' && s[j] == 'R' || s[j] == 'L' && s[i] == 'R')return true;
	return false;
}

int main(){
	cin >> s;
	if(s.size() % 2 != 0){
		cout << -1;
	}else{
		int ans = 0;
		int k = s.size()/2;
		for(int i = 0; i < k; i++){
			if(!check(i,s.size()-i-1))ans++;
		}
		cout << ans;
	}
	return 0;
}


#include<fstream>
#include<algorithm>
#include<string>
#include<map>
#include<vector>
#include<iostream>
#include<iomanip>
#include<cmath>
#include<queue>
#include<set>
#include<stdio.h>

using namespace std;
ifstream in("input.txt");
ofstream out("output.txt");

string s;

bool check(int i, int j){
	if(s[i] == 'U' && s[j] == 'D' || s[j] == 'U' && s[i] == 'D')return true;
	if(s[i] == 'L' && s[j] == 'R' || s[j] == 'L' && s[i] == 'R')return true;
	return false;
}

int main(){
	cin >> s;
	if(s.size() % 2 != 0){
		cout << -1;
	}else{
		int a = 0;
		int b = 0;
		for(int i = 0; i < s.size(); i++){
			if(s[i] == 'U')b++;
			if(s[i] == 'D')b--;
			if(s[i] == 'R')a++;
			if(s[i] == 'L') a--;
		}
		cout << (abs(a) + abs(b))/2;
	}
	return 0;
}


#include<fstream>
#include<algorithm>
#include<string>
#include<map>
#include<vector>
#include<iostream>
#include<iomanip>
#include<cmath>
#include<queue>
#include<set>
#include<stdio.h>

using namespace std;
ifstream in("input.txt");
ofstream out("output.txt");

string s;

bool check(int i, int j){
	if(s[i] == 'U' && s[j] == 'D' || s[j] == 'U' && s[i] == 'D')return true;
	if(s[i] == 'L' && s[j] == 'R' || s[j] == 'L' && s[i] == 'R')return true;
	return false;
}

int main(){
	cin >> s;
	if(s.size() % 2 != 0){
		cout << -1;
	}else{
		int a = 0;
		int b = 0;
		for(int i = 0; i < s.size(); i++){
			if(s[i] == 'U')b++;
			if(s[i] == 'D')b--;
			if(s[i] == 'R')a++;
			else a--;
		}
		cout << (abs(a) + abs(b))/2;
	}
	return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int r,l,u,d;
int main() {
	string n;
	cin >> n;
	if (n.size() % 2 != 0)
		cout << "-1";
	if (n.size() % 2 == 0)
	{
	 for (int i = 0; i < n.size(); i++){
		 if (n[i] == 'R')
			 r++;
	 if (n[i] == 'L')
			 l++;
	 if (n[i] == 'U')
			 u++;
	 if (n[i] == 'D')
			 d++;
	 }
	  cout << abs(r-l);
	}

}


#include <string>
#include <vector>
#include <map>
#include <list>
#include <iterator>
#include <cassert>
#include <set>
#include <queue>
#include <iostream>
#include <sstream>
#include <stack>
#include <deque>
#include <cmath>
#include <memory.h>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <utility>
#include <time.h>
#include <complex>
#include <fstream>
#include <tuple>
#include <iomanip>

#include <unordered_set>
#include <unordered_map>

#pragma warning(disable: 4101)
using namespace std;

#define forn(i,n) for (int i = 0; i < int(n); ++i)
#define for1(i,n) for (int i = 1; i < int(n); ++i)
#define ford(i,n) for (int i = int(n) - 1; i >= 0; --i)
#define fore(i,l,r) for (int i = int(l); i <= int(r); ++i)
#define all(a) a.begin(), a.end()
#define sz(a) (int(a.size()))
#define mp make_pair
#define pb push_back
#define ft first
#define sc second
#define g(a,b) get<a> (b)

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pt;

const double pi = acos(-1.0);
const int INF = 1000000000;
const int MAX = 100007;
const int MAX2 = 2000000;
const int inf = (int) 1e9 + 5;
const long long mod =  1e9 + 7;
const int BASE = 10;
const int ST = 1000003;
const int CNT = 100;
const double eps=1e-6;
const long long base = 2204234849;
const long long l_inf = (long long) 4e18;
const int logn = 30;

long double Time(long double T0, long double x, long double N){
     return (100 - T0) * x / N;
}

long double sred_temp(long double T0, long double w, long double v){
     return (w * T0 + 20 *(v - w)) / v;
}

int main()
{
#if 0
	freopen("test.txt", "r", stdin);
	freopen("tea.out", "w", stdout);
#endif

#if 0
    cout << setprecision(15);
#endif
     int l = 0, r = 0, u = 0, d= 0;
     string s;
     cin >> s;
     for (int i = 0; i< s.size(); i++)
        if (s[i] == 'L')
        l++;
     else if (s[i] == 'R')
        r++;
     else if (s[i] == 'U')
        u++;
     else if (s[i] == 'D')
        d++;
     int e = abs(l - r);
     int w = abs(u - d);
     int a = min(e, w);
     int q = abs(e - w);
     if (q % 2 != 0){
        cout << -1;
        return 0;
     }
     cout << a + q / 2;
return 0;
}


#include <string>
#include <vector>
#include <map>
#include <list>
#include <iterator>
#include <cassert>
#include <set>
#include <queue>
#include <iostream>
#include <sstream>
#include <stack>
#include <deque>
#include <cmath>
#include <memory.h>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <utility>
#include <time.h>
#include <complex>
#include <fstream>
#include <tuple>
#include <iomanip>

#include <unordered_set>
#include <unordered_map>

#pragma warning(disable: 4101)
using namespace std;

#define forn(i,n) for (int i = 0; i < int(n); ++i)
#define for1(i,n) for (int i = 1; i < int(n); ++i)
#define ford(i,n) for (int i = int(n) - 1; i >= 0; --i)
#define fore(i,l,r) for (int i = int(l); i <= int(r); ++i)
#define all(a) a.begin(), a.end()
#define sz(a) (int(a.size()))
#define mp make_pair
#define pb push_back
#define ft first
#define sc second
#define g(a,b) get<a> (b)

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pt;

const double pi = acos(-1.0);
const int INF = 1000000000;
const int MAX = 100007;
const int MAX2 = 2000000;
const int inf = (int) 1e9 + 5;
const long long mod =  1e9 + 7;
const int BASE = 10;
const int ST = 1000003;
const int CNT = 100;
const double eps=1e-6;
const long long base = 2204234849;
const long long l_inf = (long long) 4e18;
const int logn = 30;

long double Time(long double T0, long double x, long double N){
     return (100 - T0) * x / N;
}

long double sred_temp(long double T0, long double w, long double v){
     return (w * T0 + 20 *(v - w)) / v;
}

int main()
{
#if 0
	freopen("test.txt", "r", stdin);
	freopen("tea.out", "w", stdout);
#endif

#if 0
    cout << setprecision(15);
#endif
     int l = 0, r = 0, u = 0, d= 0;
     string s;
     cin >> s;
     for (int i = 0; i< s.size(); i++)
        if (s[i] == 'L')
        l++;
     else if (s[i] == 'R')
        r++;
     else if (s[i] == 'U')
        u++;
     else if (s[i] == 'D')
        d++;
     int e = abs(l - r);
     int w = abs(u - d);
     int a = min(e, w);
     int q = abs(e - w);
     if (q % 2 != 0){
        cout << -1;
        return 0;
     }
     cout << a + q;
return 0;
}


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

long myAbs(long n)
{
	return n < 0 ? -n : n;
}

int main()
{
	string in;
	cin >> in;

	long ans;
	if (in.length() % 2 == 1)
		ans = -1;
	else
	{
		long x(0), y(0);
		ans = in.length() / 2;
		for (long a(0); a < in.length(); ++a)
		{
			switch (in[a])
			{
			case 'L':
				--x;
				break;
			case 'U':
				++y;
				break;
			case 'R':
				++x;
				break;
			case 'D':
				--y;
				break;
			}

			if (a >= in.length() / 2)
			{
				long stepLeft = in.length() - a - 1;
				long length = myAbs(x) + myAbs(y);

				if (length <= stepLeft)
					ans = stepLeft;
			}
		}
	}

	cout << ans << '\n';

	return 0;
}


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

long myAbs(long n)
{
	return n < 0 ? -n : n;
}

int main()
{
	string in;
	cin >> in;

	long ans;
	if (in.length() % 2 == 1)
		ans = -1;
	else
	{
		long x(0), y(0);
		for (long a(0); a < in.length(); ++a)
			switch (in[a])
			{
			case 'L':
				--x;
				break;
			case 'U':
				++y;
				break;
			case 'R':
				++x;
				break;
			case 'D':
				--y;
				break;
			}
		ans = (myAbs(x) + myAbs(y)) / 2;
	}

	cout << ans << '\n';

	return 0;
}


#include <iostream>
#include <string>
#include <math.h>
using namespace std;
int main() {
	string s;
	cin >> s;
	int rez1 = 0;
	int rez2 = 0;
	if (s.size() % 2) {
		cout << -1;
		return 0;
	}
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'R')
			rez1++;
		if (s[i] == 'L')
			rez1--;
		if (s[i] == 'U')
			rez2++;
		if (s[i] == 'D')
			rez2--;
	}
	int rez = (abs(rez1) + abs(rez2))/2;
	cout << rez;
	return 0;
}


#include <iostream>
#include <string>
#include <math.h>
using namespace std;
int main() {
	string s;
	cin >> s;
	int rez1 = 0;
	int rez2 = 0;
	if (size(s) % 2) {
		cout << -1;
		return 0;
	}
	for (int i = 0; i < size(s); i++) {
		if (s[i] == 'R')
			rez1++;
		if (s[i] == 'L')
			rez1--;
		if (s[i] == 'U')
			rez2++;
		if (s[i] == 'D')
			rez2--;
	}
	int rez = (abs(rez1) + abs(rez2))/2;
	cout << rez;
	return 0;
}


#include <iostream>
#include <string>
using namespace std;
int main() {
	string s;
	cin >> s;
	int rez1 = 0;
	int rez2 = 0;
	if (size(s) % 2) {
		cout << -1;
		return 0;
	}
	for (int i = 0; i < size(s); i++) {
		if (s[i] == 'R')
			rez1++;
		if (s[i] == 'L')
			rez1--;
		if (s[i] == 'U')
			rez2++;
		if (s[i] == 'D')
			rez2--;
	}
	int rez = (abs(rez1) + abs(rez2))/2;
	cout << rez;
	return 0;
}


#include <iostream>
#include <string>
#include <math.h>
using namespace std;
int main() {
	string s;
	cin >> s;
	int rez1 = 0;
	int rez2 = 0;
	if (s.size() % 2) {
		cout << -1;
		return 0;
	}
	for (int i = 0; i < size(s); i++) {
		if (s[i] == 'R')
			rez1++;
		if (s[i] == 'L')
			rez1--;
		if (s[i] == 'U')
			rez2++;
		if (s[i] == 'D')
			rez2--;
	}
	int rez = (abs(rez1) + abs(rez2))/2;
	cout << rez;
	return 0;
}


#include <iostream>
#include <string>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	string s;
	cin >> s;
	int r, d, u, l, n = s.size();
	r = d = u = l = 0;
	for(int i=0; i<n; i++){
		switch (s[i]){
			case 'R': r++; break;
			case 'U': u++; break;
			case 'L': l++; break;
			case 'D': d++; break;
		}
	}
	if(n % 2){
		cout << -1;
	}
	else{
		int e1 = abs(r - l);
		int e2 = abs(u - d);
		int ans = (e1 + e2) / 2;
		cout << ans;
	}
	return 0;
}


#include <iostream>
#include <string>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	string s;
	cin >> s;
	int r, d, u, l, n = s.size();
	r = d = u = l = 0;
	for(int i=0; i<n; i++){
		switch (s[i]){
			case 'R': r++; break;
			case 'U': u++; break;
			case 'L': l++; break;
			case 'D': d++; break;
		}
	}
	if(n % 2){
		cout << -1;
	}
	else{
		int e1 = abs(r - l);
		int e2 = abs(u - d);
		int ans = (e1==0)?e2:e1;
		cout << ans;
	}
	return 0;
}


#include <iostream>
#include <vector>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<int> a(n+1, 0), b(n, 0);
	for(int i=0; i<n; i++){
		cin>>a[i];
	}
	for(int i=0; i<n; i++){
		b[i] = a[i] + a[i+1];
	}
	for(int i=0; i<n; i++){
		cout<<b[i]<<" ";
	}
	return 0;
}


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

using namespace std;

typedef long long LL;
#define mp make_pair

int main()
{
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);

	int u = 0, d = 0, l = 0, r = 0;
	string s;
	cin >> s;
	if (s.size() % 2 == 1)
	{
		cout << -1;
		return 0;
	}
	for (int i = 0; i < s.size(); i++)
	{
		if (s[i] == 'U')
			u++;
		if (s[i] == 'D')
			d++;
		if (s[i] == 'L')
			l++;
		if (s[i] == 'R')
			r++;
	}
	int ans = (abs(u - d) + abs(l - r)) / 2;
	cout << ans;
	return 0;
}


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

using namespace std;

typedef long long LL;
#define mp make_pair

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	int u = 0, d = 0, l = 0, r = 0;
	string s;
	cin >> s;
	if (s.size() % 2 == 1)
	{
		cout << -1;
		return 0;
	}
	for (int i = 0; i < s.size(); i++)
	{
		if (s[i] == 'U')
			u++;
		if (s[i] == 'D')
			d++;
		if (s[i] == 'L')
			l++;
		if (s[i] == 'R')
			r++;
	}
	int ans = (abs(u - d) + abs(l - r)) / 2;
	cout << ans;
	return 0;
}


//In the name of God:)
#include <iostream>
#include <string>
using namespace std;
string s;
int u, d, r, l;
int main()
{
    cin>> s;
    int Ls=s. length();
    for (int i=0; i<Ls; i++)
    {
        if (s[i]=='U')
        { u++; continue; }
        if (s[i]=='D')
        { d++; continue; }
        if (s[i]=='R')
        { r++; continue;}
        if (s[i]=='L')
            l++;
    }
    if (u>d)
    { u-=d; d=0; }
    else
    { d-=u; u=0; }
    if (l>r)
    { l-=r; r=0; }
    else
    { r-=l; l=0; }
    if (Ls%2==1)
        cout<< -1;
    else
        cout<< (u+d+r+l)/2;
    return 0;
}


//In the name of God:)
#include <iostream>
#include <string>
using namespace std;
string s;
int u, d, r, l;
int main()
{
    cin>> s;
    int Ls=s. length();
    for (int i=0; i<Ls; i++)
    {
        if (s[i]=='U')
        { u++; continue; }
        if (s[i]=='D')
        { d++; continue; }
        if (s[i]=='R')
        { r++; continue;}
        if (s[i]=='L')
            l++;
    }
    if (u>d)
    { u-=d; d=0; }
    else
    { d-=u; u=0; }
    if (l>r)
    { l-=r; r=0; }
    else
    { r-=l; l=0; }
    if (u%2==1 || d%2==1 || r%2==1 || l%2==1)
        cout<< -1;
    else
        cout<< (u/2)+(d/2)+(r/2)+(l/2);
    return 0;
}


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

int main(){
	int L, R, U, D;
	int k = 0;
	int rezultat = 0;
	int vec = 0, manj = 0;
	L = R = U = D = 0;
	string s;
	cin>>s;

	if(s.size() % 2 == 1){
		cout<<-1;
		return 0;
	}
	for(int i=0; i<(int)s.size(); i++){
		switch(s[i]){
			case 'L':	L++; break;
			case 'R':	R++; break;
			case 'U':	U++; break;
			case 'D':	D++; break;
		}
	}

	//L==R && U == D
	k = min(L, R);
	L -= k;
	R -= k;
	k = min(U, D);
	U -= k;
	D -= k;

	if(L >= vec){ manj = vec; vec = L;}
	if(R >= vec){ manj = vec; vec = R;}
	if(U >= vec){manj = vec; vec = R;}
	if(D >= vec){ manj = vec; vec = R;}

	rezultat = manj + (vec-manj)/2;
	cout<<rezultat;

	return 0;
}


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

int main(){
	int L, R, U, D;
	int k = 0;
	int rezultat = 0;
	int vec = 0, manj = 0;
	L = R = U = D = 0;
	string s;
	cin>>s;

	if(s.size() % 2 == 1){
		cout<<-1;
		return 0;
	}
	for(int i=0; i<(int)s.size(); i++){
		switch(s[i]){
			case 'L':	L++; break;
			case 'R':	R++; break;
			case 'U':	U++; break;
			case 'D':	D++; break;
		}
	}

	//L==R && U == D
	k = min(L, R);
	L -= k;
	R -= k;
	k = min(U, D);
	U -= k;
	D -= k;

	if(L >= vec){ manj = vec; vec = L;}
	if(R >= vec){ manj = vec; vec = R;}
	if(U >= vec){manj = vec; vec = U;}
	if(D >= vec){ manj = vec; vec = D;}

	rezultat = manj + (vec-manj)/2;
	cout<<rezultat;

	return 0;
}


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

int main(){
	int L, R, U, D;
	int k = 0;
	int rezultat = 0;
	int vec = 0, manj = 0;
	L = R = U = D = 0;
	string s;
	cin>>s;

	if(s.size() % 2 == 1){
		cout<<-1;
		return 0;
	}
	for(int i=0; i<(int)s.size(); i++){
		switch(s[i]){
			case 'L':	L++; break;
			case 'R':	R++; break;
			case 'U':	U++; break;
			case 'D':	D++; break;
		}
	}

	//L==R && U == D
	k = min(L, R);
	L -= k;
	R -= k;
	k = min(U, D);
	U -= k;
	D -= k;

	if(L > 0){if(vec == 0) vec = L; else manj = L;}
	if(D > 0){if(vec == 0) vec = D; else manj = D;}
	if(R > 0){if(vec == 0) vec = R; else manj = R;}
	if(U > 0){if(vec == 0) vec = U; else manj = U;}
	if(manj > vec){
		k = manj;
		manj = vec;
		vec = k;
	}
	rezultat = manj + (vec-manj)/2;
	cout<<rezultat;

	return 0;
}


#include <iostream>
#include<cstring>
#include<cmath>
using namespace std;
int main()
{
char s[100000];
cin>>s;
if(strlen(s)%2==1)
{
    cout<<-1 ;
    return 0;
}
int x=0;
int y=0;
for(int i=0;i<strlen(s);i++)
{
    if(s[i]=='U')
        y++;
    else if (s[i]=='D')
        y--;
    else if (s[i]=='L')
        x++;
    else if(s[i]=='R')
        x--;
}
x=abs(x);
y=abs(y);
cout<<min(x,y)+(max(x,y)-min(x,y))/2;
/*for(int i=0;i<strlen(s);i++)
{
    if(s[i]=='U')
        x[0]++;
    else if (s[i]=='D')
        x[1]++;
    else if (s[i]=='L')
        x[2]++;
    else if(s[i]=='R')
        x[3]++;
}
int b=max(max(x[0],x[1]),max(x[2],x[3]));
*/
}


#include <iostream>
#include<cstring>
#include<cmath>
using namespace std;
int main()
{
char s[100010];
cin>>s;
if(strlen(s)%2==1)
{
    cout<<-1 ;
    return 0;
}
int x=0;
int y=0;
for(int i=0;i<strlen(s);i++)
{
    if(s[i]=='U')
        y++;
    else if (s[i]=='D')
        y--;
    else if (s[i]=='L')
        x++;
    else if(s[i]=='R')
        x--;
}
x=abs(x);
y=abs(y);
cout<<min(x,y)+(max(x,y)-min(x,y))/2;
/*for(int i=0;i<strlen(s);i++)
{
    if(s[i]=='U')
        x[0]++;
    else if (s[i]=='D')
        x[1]++;
    else if (s[i]=='L')
        x[2]++;
    else if(s[i]=='R')
        x[3]++;
}
int b=max(max(x[0],x[1]),max(x[2],x[3]));
*/
}


#include<iostream>
#include<string>
#include<math.h>
using namespace std;
void main()
{
	string s;
	cin>>s;
	int u,d,l,r,min;
	u=d=r=l=min=0;
	if (s.size()%2==1)
	{
		cout<<-1;
		return ;
	}
	else
	{
		for(int i=0;i<s.size();i++)
		{
			if(s[i]=='U')
				u++;
			else if(s[i]=='L')
				l++;
			else if(s[i]=='R')
				r++;
			else if(s[i]=='D')
				d++;
		}
		if(u==d&&r==l)
			min=0;
		else
		{
			if((r==0||l==0)&&!(u==0||d==0))
				min=abs(r-l)/2+abs(u-d);
			else if((u==0||d==0)&&!(r==0||l==0))
				min=abs(r-l)+abs(u-d)/2;
			else if((r==0||l==0)&&(u==0||d==0))
				min=abs(r-l)/2+abs(u-d)/2;
			else
				min=abs(r-l)+abs(u-d);
		}
	}
	cout<<min;

	return ;
}


#include<iostream>
#include<string>
#include<math.h>
using namespace std;
void main()
{
	string s;
	cin>>s;
	int u,d,l,r,min;
	u=d=r=l=min=0;
	if (s.size()%2==1)
	{
		cout<<-1;
		return ;
	}
	else
	{
		for(int i=0;i<s.size();i++)
		{
			if(s[i]=='U')
				u++;
			else if(s[i]=='L')
				l++;
			else if(s[i]=='R')
				r++;
			else if(s[i]=='D')
				d++;
		}
		if(u==d&&r==l)
			min=0;
		else
		{
			if(r==0||l==0)
				min=abs(r-l)/2+abs(u-d);
			else if(u==0||d==0)
				min=abs(r-l)+abs(u-d)/2;
			else if((r==0||l==0)&&(u==0||d==0))
				min=abs(r-l)/2+abs(u-d)/2;
			else
				min=abs(r-l)+abs(u-d);
		}
	}
	cout<<min;

	return ;
}


#include<iostream>
#include<string>
#include<math.h>
using namespace std;
void main()
{
	string s;
	cin>>s;
	int u,r,min;
	u=r=min=0;
	if (s.size()%2==1)
	{
		cout<<-1;
		return ;
	}
	else
	{
		for(int i=0;i<s.size();i++)
		{
			if(s[i]=='U')
				u++;
			else if(s[i]=='L')
				r--;
			else if(s[i]=='R')
				r++;
			else if(s[i]=='D')
				u--;

		}

			min=(abs(u)+abs(r))/2;
		}
	cout<<min;

	return ;
}


#include <iostream>
#include<algorithm>
#include<cstdlib>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<deque>
#include<queue>
#include<vector>
#include<stack>
#include<climits>
#include<map>
#include<ctime>
#include<set>
using namespace std;
typedef long long LL;
char a[100010];
int main()
{
    int len;
    int l,r,u,d;
    cin>>a;
    len=strlen(a);
    l=r=u=d=0;
    if(len%2!=0)
    {
        cout<<"-1"<<endl;
    }
    else
    {
        for(int i=0;i<len;i++)
        {
            if(a[i]=='L')
                l++;
            if(a[i]=='R')
                r++;
            if(a[i]=='U')
                u++;
            if(a[i]=='D')
                d++;
        }
        cout<<(max(l,r)-min(l,r)+max(u,d)-min(u,d))/2<<endl;
    }
    return 0;
}


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

typedef long long LL;
#define memset(a,n) memset(a,n,sizeof(a))
#define INF 0x3f3f3f3f

char s[100000+10];

int main()
{

    int a,aa,b,bb;
    a=0,aa=0,b=0,bb=0;
    scanf("%s",s);

    for(int i=0;i<strlen(s);i++){
        if(s[i]=='R')
            a++;
        if(s[i]=='L')
            aa++;
        if(s[i]=='U')
            b++;
        if(s[i]=='D')
            bb++;
    }

    int sum=0;

    if(strlen(s)%2==1)
    {
        printf("-1\n");
    }

    else
    {
        a=abs(a-aa);
        b=abs(b-bb);
        int ans;
        ans=(a+b)/2;
        printf("%d\n",ans);

    }
}


#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cstdio>
#include<stdlib.h>
#include<sstream>
#include<list>
#include<math.h>
#include<map>
#include<set>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<fstream>
#include<vector>
#include<algorithm>
#include <queue>
#include<string>
#include<cstring>
#include <deque>
#include<stack>
using namespace std;

#define ALL(a) a.begin(),a.end()
#define CLR(a) memset(a,0,sizeof(a))
#define PB push_back
#define PI acos(-1.0)
#define READ freopen("input.txt", "r", stdin)
#define WRITE freopen("output.txt", "w", stdout)
long long GCDFast(long long a, long long b){ while (b)b ^= a ^= b ^= a %= b;  return a; }
#define SET(a) memset(a,-1,sizeof(a))
#define ALL_BITS ((1 << 31) - 1)
#define NEG_BITS(mask) (mask ^= ALL_BITS)
#define TEST_BIT(mask, i) (mask & (1 << i))
#define ON_BIT(mask, i) (mask |= (1 << i))
#define OFF_BIT(mask, i) (mask &= NEG_BITS(1 << i))
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define MX 100010
#define pii pair<int,int>
#define LL long long
// UP, RIGHT, DOWN, LEFT, UPPER-RIGHT, LOWER-RIGHT, LOWER-LEFT, UPPER-LEFT
int dx[8] = { -1, 0, 1, 0, -1, 1, 1, -1 };
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };

#define mx 300005
int arr[mx], arrY[mx], arrX[mx];

struct T{
	LL sum, propValue;
}tree[mx * 3];
//node present node,l-r present range
void init(int node, int l, int r)//it will transform the array into tree
{
	if (l == r){
		tree[node].sum = arr[l];
		return;
	}
	int Left = node * 2;
	int Right = node * 2 + 1;
	int mid = (l + r) / 2;
	init(Left, l, mid);
	init(Right, mid + 1, r);

	if (tree[Left].sum >= 0)
		tree[node].sum += tree[Left].sum;

	if (tree[Right].sum >= 0)
		tree[node].sum += tree[Right].sum;

	//tree[node] = std::min(tree[Left], tree[Right]);
}
//l=starting point of range
//r=ending point of range
LL query(int node, int l, int r, int qL, int qR, LL carry)// check if the function is relevant or not
{
	cout << "node number " << node << " left " << l << " right " << r << " carry " << carry << "\n";
	if (qL > r || qR < l) {
		return -1; //out of range
	}
	if (l >= qL && r <= qR){
		cout << "assinged value " << tree[node].propValue << "\n";
		//return tree[node].sum + carry*(r - l + 1); //releveant segment
		return std::max(tree[node].propValue, carry);
	}
	int Left = node * 2; //divide again
	int Right = node * 2 + 1;
	int mid = (l + r) / 2;
	LL p1 = query(Left, l, mid, qL, qR, std::max(tree[node].propValue, carry));
	LL p2 = query(Right, mid + 1, r, qL, qR, std::max(tree[node].propValue, carry));

	//return p1 + p2; //summation of left and right segment;
	//cout <<" "<<p1 <<" "<< p2 << "\n";

	if (p1 != -1)
		return p1;
	else if (p2 != -1)
		return p2;
}
void update(int node, int l, int r, int uL, int uR, LL newvalue)
{

	if (uL > r || uR < l)
		return;
	if (l >= uL && r <= uR) {

		//tree[node].sum += ((r - l + 1)*newvalue);
		tree[node].propValue = newvalue;
		return;
	}
	int Left = node * 2;
	int Right = node * 2 + 1;
	int mid = (l + r) / 2;
	update(Left, l, mid, uL, uR, newvalue);
	update(Right, mid + 1, r, uL, uR, newvalue);
	//tree[node].sum = tree[Left].sum + tree[Right].sum + ((r - l + 1)*tree[node].propValue);
}

int main() {
	//freopen ("d:/Codejam/B-small-attempt0.in","r",stdin);
	//freopen ("d:/Codejam/output1.txt","w",stdout);
	LL n, i, j, k, temp, m;
	LL x, y, z, sum, test_case = 0, length, ans, test = 0, l, w, num, t, index;
	string str, str1;

	ios::sync_with_stdio(false);
	LL a, b, q ;

	while (cin >> str){
		if (str.size() % 2 == 1){
			cout << "-1\n";
			continue;
		}

		x = 0; y = 0;
		for (i = 0; i < str.size(); i++){
			if (str[i] == 'L')
				x++;
			else if (str[i] == 'R')
				x--;
			else if (str[i] == 'U')
				y++;
			else if (str[i] == 'D')
				y--;

		}
		cout << (abs(x)+abs(y))/2 << "\n";
	}

	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cstdio>
#include<stdlib.h>
#include<sstream>
#include<list>
#include<math.h>
#include<map>
#include<set>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<fstream>
#include<vector>
#include<algorithm>
#include <queue>
#include<string>
#include<cstring>
#include <deque>
#include<stack>
using namespace std;

#define ALL(a) a.begin(),a.end()
#define CLR(a) memset(a,0,sizeof(a))
#define PB push_back
#define PI acos(-1.0)
#define READ freopen("input.txt", "r", stdin)
#define WRITE freopen("output.txt", "w", stdout)
long long GCDFast(long long a, long long b){ while (b)b ^= a ^= b ^= a %= b;  return a; }
#define SET(a) memset(a,-1,sizeof(a))
#define ALL_BITS ((1 << 31) - 1)
#define NEG_BITS(mask) (mask ^= ALL_BITS)
#define TEST_BIT(mask, i) (mask & (1 << i))
#define ON_BIT(mask, i) (mask |= (1 << i))
#define OFF_BIT(mask, i) (mask &= NEG_BITS(1 << i))
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define MX 100010
#define pii pair<int,int>
#define LL long long
// UP, RIGHT, DOWN, LEFT, UPPER-RIGHT, LOWER-RIGHT, LOWER-LEFT, UPPER-LEFT
int dx[8] = { -1, 0, 1, 0, -1, 1, 1, -1 };
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };

#define mx 300005
int arr[mx], arrY[mx], arrX[mx];

struct T{
	LL sum, propValue;
}tree[mx * 3];
//node present node,l-r present range
void init(int node, int l, int r)//it will transform the array into tree
{
	if (l == r){
		tree[node].sum = arr[l];
		return;
	}
	int Left = node * 2;
	int Right = node * 2 + 1;
	int mid = (l + r) / 2;
	init(Left, l, mid);
	init(Right, mid + 1, r);

	if (tree[Left].sum >= 0)
		tree[node].sum += tree[Left].sum;

	if (tree[Right].sum >= 0)
		tree[node].sum += tree[Right].sum;

	//tree[node] = std::min(tree[Left], tree[Right]);
}
//l=starting point of range
//r=ending point of range
LL query(int node, int l, int r, int qL, int qR, LL carry)// check if the function is relevant or not
{
	cout << "node number " << node << " left " << l << " right " << r << " carry " << carry << "\n";
	if (qL > r || qR < l) {
		return -1; //out of range
	}
	if (l >= qL && r <= qR){
		cout << "assinged value " << tree[node].propValue << "\n";
		//return tree[node].sum + carry*(r - l + 1); //releveant segment
		return std::max(tree[node].propValue, carry);
	}
	int Left = node * 2; //divide again
	int Right = node * 2 + 1;
	int mid = (l + r) / 2;
	LL p1 = query(Left, l, mid, qL, qR, std::max(tree[node].propValue, carry));
	LL p2 = query(Right, mid + 1, r, qL, qR, std::max(tree[node].propValue, carry));

	//return p1 + p2; //summation of left and right segment;
	//cout <<" "<<p1 <<" "<< p2 << "\n";

	if (p1 != -1)
		return p1;
	else if (p2 != -1)
		return p2;
}
void update(int node, int l, int r, int uL, int uR, LL newvalue)
{

	if (uL > r || uR < l)
		return;
	if (l >= uL && r <= uR) {

		//tree[node].sum += ((r - l + 1)*newvalue);
		tree[node].propValue = newvalue;
		return;
	}
	int Left = node * 2;
	int Right = node * 2 + 1;
	int mid = (l + r) / 2;
	update(Left, l, mid, uL, uR, newvalue);
	update(Right, mid + 1, r, uL, uR, newvalue);
	//tree[node].sum = tree[Left].sum + tree[Right].sum + ((r - l + 1)*tree[node].propValue);
}

int main() {
	//freopen ("d:/Codejam/B-small-attempt0.in","r",stdin);
	//freopen ("d:/Codejam/output1.txt","w",stdout);
	LL n, i, j, k, temp, m;
	LL x, y, z, sum, test_case = 0, length, ans, test = 0, l, w, num, t, index;
	string str, str1;

	ios::sync_with_stdio(false);
	LL a, b, q ;

	while (cin >> str){
		if (str.size() % 2 == 1){
			cout << "-1\n";
			continue;
		}
		x = str.size()/2;
		sum = 0;
		for (i = 0; i < x; i++){
			/*if (str[i] == 'L' && str[i + x] == 'R')
				;
			else if (str[i] == 'R' && str[i + x] == 'L')
				;
			else if (str[i] == 'U' && str[i + x] == 'D')
				;
			else if (str[i] == 'D' && str[i + x] == 'U')
				;*/
			if (str[i] == str[i + x])
				;
			else
				sum++;
		}
		cout << sum << "\n";
	}

	return 0;
}


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

char str[100005];
int a[5];

int main()
{
    while(scanf("%s",str)!=EOF) {
        memset(a,0,sizeof(a));
        int len=strlen(str);
        if(len&1) {printf("-1\n");continue;}
        else {
            for(int i=0;i<len;i++) {
                if(str[i]=='L') a[0]++;
                else if(str[i]=='R') a[1]++;
                else if(str[i]=='U') a[2]++;
                else if(str[i]=='D') a[3]++;
            }
            int ans;
            if(a[0]==a[1]&&a[2]==a[3]) {printf("0\n");continue;}
            else if(a[0]==a[1]&&a[2]!=a[3]) {
                ans=abs(a[3]-a[4])/2;
                printf("%d\n",ans);
                continue;
            }
            else if(a[0]!=a[1]&&a[2]==a[3]) {
                ans=abs(a[0]-a[1])/2;
                printf("%d\n",ans);
                continue;
            }
            else {
                int r1=abs(a[0]-a[1]);
                int r2=abs(a[2]-a[3]);
                if(r1>r2) {
                    ans=r2;
                    printf("%d\n",ans);
                    continue;
                }
                else {
                    ans=r1;
                    printf("%d\n",ans);
                    continue;
                }
            }
        }
    }
    return 0;
}


#include<cstdio>
#include<cstring>
#include<map>
#include<algorithm>
using namespace std;

char str[100005];

int main()
{
    while(scanf("%s",str)!=EOF) {
        map<char,int> mp;
        int len=strlen(str);
        for(int i=0;i<len;i++) {
            mp[str[i]]++;
        }

        int r1=abs(mp['R']-mp['L']);
        int r2=abs(mp['U']-mp['D']);

        if(len&1) {printf("-1\n");continue;}
        else {
            printf("%d\n",(r1+r2)>>1);
            continue;
        }
    }
    return 0;
}


#include<iostream>
#include<string>
#include<math.h>
#include<cmath>
using namespace std;
int x,y;
int main(){
int N;
string k;
cin>>k;

 for (int i=0;k[i]!=0;i++){
    if (k[i]=='L')
        x--;
    if (k[i]=='R')
        x++;
    if (k[i]=='U')
        y++;
    if (k[i]=='D')
        y--;

 }

    if ((x+y)%2==0)
        cout<<(abs(x)+abs(y))/2;
    else{
        cout<<"-1";
    }

return 0;
}


#include<iostream>
#include<string>
using namespace std;
int x,y;
int main(){
int N;
string k;
cin>>k;

 for (int i=0;k[i]!=0;i++){
    if (k[i]=='L')
        x--;
    if (k[i]=='R')
        x++;
    if (k[i]=='U')
        y++;
    if (k[i]=='D')
        y--;

 }

    if ((x+y)%2==0)
        cout<<(x+y)/2;
    else{
        cout<<"-1";
    }

return 0;
}


#include<math.h>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;

const int maxn = 1e5 + 10;

int L, R, U, D;

int main()
{
	int ans = 0;
	string s; cin >> s;
	for (int i = 0; i < s.size(); i++)
	{
		if (s[i] == 'L') L++;
		if (s[i] == 'R') R++;
		if (s[i] == 'U') U++;
		if (s[i] == 'D') D++;
	}
	if (s.size() % 2) cout << -1;
	else cout << (abs(L - R) + abs(U - D)) / 2;
	return 0;
}


#include <iostream>
#include <string>
#include <cmath>
using namespace std;
void main ()
{
	string x = " ";
	int i;
	int NH = 0;
	int NV = 0;
	int edits = 0;
	cin>>x;
	for (i=0;i<x.size();i++)
	{
		if (x[i] == 'R')
			NH++;
		else if (x[i] == 'L')
			NH--;
		else if (x[i] == 'U')
			NV++;
		else if (x[i] == 'D')
			NV--;
	}
	if (x.size() % 2 == 1)
		cout<<"-1";
	else
	{
		edits = (abs(NH) + abs(NV))/2;
		cout<<edits;
	}
}