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

int main() {
    int N;
    ll A, B;
    cin >> N >> A >> B;
    ll X[N];
    for (int i = 0; i < N; i++) {
        cin >> X[i];
    }
    ll e[N- 1];
    for (int i = 0; i < N - 1; i++) {
        e[i] = X[i + 1] - X[i];
    }
    ll ans = 0;
    for (int i = 0; i < N - 1; i++) {
        if (e[i] * A < B) ans += e[i] * A;
        else ans += B;
    }
    cout << ans << "\n";
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {
    /*#ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif*/
        /*
        Ofcourse it's Hard.
        It's supposed to be Hard.
        If it's easy everyone would do it.
        HARD IS WHAT MAKES IT GREAT

        YESTERDAY U SAID TOMORROW

        SLOWLY BECOMING THE PERSON I
        SHOULD HAVE BEEN A LONG TIME AGO

        SAME TASK CAN'T BE FOUND DIFFICULT TWICE

        BTBHWSITW

        SPRH TU KAB P

        CP IS ALL ABOUT THINKING
        YOU HAVE MUCH MORE POTENTIAL THAN U THINK

        AJIT SHIDDAT 10

        UR DAILY ROUTINE

        */

fast();
//ll t;cin>>t;while(t--)
{
  ll n,t,s=0;
  cin>>n>>t;
  ll a[n];
  for(int i=0;i<n;i++)
    {
      cin>>a[i];
    }
    for(int i=1;i<n;i++)
    {
        s+=min(t,a[i]-a[i-1]);
    }
    cout<<s+t<<endl;

}
return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;

bool Bsearch(int key, int A[], int len) {
	int l = 0, r = len - 1;
	while (l <= r) {
		int mid = l + (r - l) / 2;
		if (A[mid] > key)
			r = mid - 1;
		else if (A[mid] < key)
			l = mid + 1;
		else
			return true;
	}
	return false;
}

int main() {
	int n, *S;
	int q, *T;
	int ans = 0;
	cin >> n;
	S = new int[n];
	for (int i = 0; i < n; i++)
		cin >> S[i];
	cin >> q;
	T = new int[q];
	for (int i = 0; i < q; i++)
		cin >> T[i];

	sort(S, S + n);
	for (int i = 0; i < q; i++)
		for (int j = 0; j < n; j++)
			if (Bsearch(T[i], S, n) == true) {
				ans++;
				break;
			}

	cout << ans << endl;
	delete[] S;
	delete[] T;
	return 0;
}

#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>

using namespace std;

int ar_s[10000];
bool linear_search(int t, int n){
    int c = 0;
    for (int i = 0; i < n; i++) {
        if (ar_s[i] == t) return true;
    }
    return false;
}

int main(int argc, char const* argv[])
{
    int n,q,  c = 0;

    scanf("%d ", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d ", &ar_s[i]);
    }

    scanf("%d ", &q);
    for (int i = 0; i < q; i++) {
        int t;
        scanf("%d ", &t);
        linear_search(t, n) ? ++c : 0;
    }

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

    return 0;
}


#include<bits/stdc++.h>
#define mod 998244353
#define maxn 1000005
using namespace std;
typedef long long LL;
int read()
{
    char c=getchar();int f=1,sum=0;
    while(c<'0' || c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0' && c<='9'){sum=sum*10+c-'0';c=getchar();}
    return sum*f;
}
int n,m;
LL fac[maxn],inv[maxn],ans;
LL ksm(LL a,LL b){LL ret=1;while(b){if(b&1) ret=ret*a%mod;a=a*a%mod;b>>=1;}return ret;}
void init(int x)
{
	fac[0]=1;
	for(int i=1;i<=x;i++) fac[i]=fac[i-1]*i%mod;
	inv[x]=ksm(fac[x],mod-2);
	for(int i=x;i>=1;i--) inv[i-1]=inv[i]*i%mod;
}
LL calc(LL x,LL y){return fac[x+y]*inv[x]%mod*inv[y]%mod;}
int main()
{
	n=read();m=read();
	if(n>m) swap(n,m);
	init(n+m);
	for(int i=1;i<=n;i++) ans+=calc(i,i)*calc(n-i,m-i)%mod;
    ans=ans%mod*ksm(calc(n,m)<<1,mod-2)%mod;
    printf("%lld\n",(ans+m)%mod);
	return 0;
}


#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S; cin >> S;
    S = "00" + S;
    int N = S.length();
    int ans = 0;
    for(int i = N - 1; i >= 0; i--) {
        if(S[i] > '9') {
            S[i - 1]++;
            S[i] -= 10;
        }
        if(S[i] <= '4' || (S[i] == '5' && S[i - 1] < '5')) {
            ans += S[i] - '0';
        } else {
            ans += 10 - (S[i] - '0');
            S[i - 1]++;
        }
    }
    cout << ans << endl;

    return 0;
}

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <numeric>
#include <iomanip>
#include <stack>
#include <complex>
#include <functional>
#include <tuple>

using namespace std;

#define Rep(i,a,b) for(ll i = a; i < b; ++i)
#define rep(i,b) Rep(i,0,b)
#define allof(a) (a).begin(), (a).end()

#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")

using ll = long long;

constexpr int inf = 1e9 + 7;
constexpr ll infll = 1ll << 60ll;
constexpr ll mod = 998244353;
// 0~3までは右下左上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, 1, 0, -1, -1, 1, 1, -1 };

namespace {
    template<typename T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
    template<typename T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

    void Cout(long long x, const char* end = "\n") { std::cout << x << end; }
    template <typename T> void Cout(const T& x, const char* end = "\n") { std::cout << x << end; }
    template <typename T> void Cout(const std::vector<T>& x, const char* sep = " ", const char* end = "\n") { for (std::size_t i = 0, sz = x.size(); i < sz; ++i) { std::cout << x[i] << (i == sz - 1 ? end : sep); } }

    // 標準入出力
    struct inp {
        std::size_t szi, szj;
        inp(std::size_t _szi = 1, std::size_t _szj = 1) : szi(_szi), szj(_szj) {}
        template <typename T> operator T () const { T a; std::cin >> a; return a; }
        template <typename T> operator std::vector<T>() const { std::vector<T> a(szi); for (std::size_t i = 0; i < szi; ++i) std::cin >> a[i]; return a; }
        template <typename T> operator std::vector<std::vector<T>>() const {
            std::vector<std::vector<T>> a(szi, std::vector<T>(szj));
            for (std::size_t i = 0; i < szi; ++i) for (std::size_t j = 0; j < szj; ++j) cin >> a[i][j]; return a;
        }
    };
    inp inp1;
}

int main() {

    string s = inp1;
    s = '0' + s;
    int n = s.size();

    vector<vector<int>> dp(n + 1, vector<int>(2, inf));
    dp[0][0] = 0;

    rep(i, n) {
        int num = s[i] - '0';
        // ピッタリ払う
        chmin(dp[i + 1][0], dp[i][0] + num);
        chmin(dp[i + 1][0], dp[i][1] + 10 - num);

        // 余分に払う
        chmin(dp[i + 1][1], dp[i][0] + num + 1);
        chmin(dp[i + 1][1], dp[i][1] + 10 - num - 1);
    }

    Cout(dp[n][0]);

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<60)
signed main(){
  string S; cin>>S;
  cout<<S.substr(0,S.size()-8)<<endl;
  }

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

int main() {
    cin.tie(0)->sync_with_stdio(false);

    string s; cin >> s;
    int n = s.size();
    REP(i, n - 8)
        cout << s[i];
    cout << '\n';
    return 0;
}


#include <iostream>

using namespace std;

int main(int argc, char** argv){
	int n, pm, pe, pj;

	while( 1 ){
		cin >> n;
		if(n==0) break;

		for(int i=0; i<n; i++){
			cin >> pm;
			cin >> pe;
			cin >> pj;

			if(pm==100 || pe==100 || pj==100){
				cout << "A" << endl;
				continue;
			}

			if((pm+pe) / 2 >= 90){
				cout << "A" << endl;
				continue;
			}

			int avg = (pm + pe + pj) / 3;
			if(avg >= 80){
				cout << "A" <<endl;
				continue;
			}

			if(avg >= 70){
				cout << "B" << endl;
				continue;
			}

			if(avg>=50 && pm>=80){
				cout << "B" << endl;
				continue;
			}

			cout << "C" << endl;
		}
	}

	return 0;
}

#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<map>
#include<complex>
#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ll long long

using namespace std;
int main(){
  int n;
  while(cin>>n,n){
    const double Inf=1e9;
    vector<pair<double,string> >vegi;
    for(int i=0;i<n;i++){
      string str;cin>>str;
      double a,b,c,d,e,f,g,h,m;
      cin>>a>>b>>c>>d>>e>>f>>g>>h>>m;
      double time=b+c+d+m*(e+f);
      int value=m*h*g-a;
      vegi.pb(mp(Inf-(value/time),str));
    }
    sort(vegi.begin(),vegi.end());
    for(int i=0;i<n;i++)
      cout<<vegi[i].S<<endl;
    cout<<"#"<<endl;
  }
  return 0;
}


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

int main(){
    int n,m,x,y;
    cin>>n>>m>>x>>y;
    int minx=200,miny=200,maxx=-200,maxy=-200;
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        maxx=max(maxx,a);
        minx=min(minx,a);
    }
    for(int i=0;i<m;i++){
        int a;
        cin>>a;
        maxy=max(maxy,a);
        miny=min(miny,a);
    }
    if(maxx<miny&&maxx<y&&miny>x)cout<<"No War"<<endl;
    else cout<<"War"<<endl;

    return 0;
}

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

#define ll long long
#define mod 1000000007
#define pii pair<ll,ll>

#define debug(a) { cout << #a << " = " << a << endl;}

void sep() {
    cout << "-------------BLOCK-----------------\n";
}

template<typename T>
void debugv(vector<T> arr) {
    for (auto t: arr)
        cout << t << " ";
    cout << "\n";
}

template<typename T>
void debugarr(T arr, int n) {
    for (int i=0;i<n;i++) cout << arr[i] << " ";
    cout << "\n";
}

const int maxn = 2e5+1;
ll arr1[maxn], n, m, t, k;
ll arr2[maxn];
unordered_map<ll,ll> u;

ll __min(ll a, ll b) {
    return a < b ? a : b;
}

ll __max(ll a, ll b) {
    return a > b ? a : b;
}

void par(int n) {
    cout << "Yes\n";
    for (int i=0;i<n;i++) cout << arr2[i] << " ";
    cout << endl;
}

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

    cin>>n;
    for (int i=0;i<n;i++) cin>>arr1[i];
    for (int i=0;i<n;i++) cin>>arr2[i];
    reverse(arr2,arr2+n);

    ll l=n+1,r=n+1;
    for (int i=0;i<n;i++) {
        if (arr1[i]==arr2[i]) {
            if (l == n+1) l = i, r=i;
            else r = i;
        }
    }

    if (l == n+1) {
        par(n);
        return 0;
    }

    ll sl=l,sr=r;
    ll pl=l,pr=r;
    while (sl >=0 && arr1[sl] == arr1[l]) sl--;
    while (sr < n && arr1[sr] == arr1[r]) sr++;
    while (pl >=0 && arr2[pl] == arr2[l]) pl--;
    while (pr < n && arr2[pr] == arr2[r]) pr++;

    sl=__min(sl,pl);
    sr=__max(sr,pr);

    ll i=0;
    ll j=n-1;
    ll sll=l;
    while (i<=sl && l <= r) {
        ll t=arr2[i];
        arr2[i++]=arr2[l];
        arr2[l++]=t;
    }

    while (j >= sr && r >= l) {
        ll t=arr2[j];
        arr2[j--]=arr2[r];
        arr2[r--]=t;
    }

    bool pos=true;

    for (int i=0;i<n;i++)
        if (arr2[i] == arr1[i]) {
            pos=false;
            break;
        }

    if (pos) par(n);
    else cout << "No\n";
}


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

int main()
{
    int n;

    cin >> n;
    vector<pair<int, int>> red;
    vector<pair<int, int>> blue;
    for (int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;
        red.emplace_back(b, a);
    }
    for (int i = 0; i < n; i++) {
        int c, d;
        cin >> c >> d;
        blue.emplace_back(c, d);
    }

    sort(red.begin(), red.end(), greater<pair<int, int>>());
    sort(blue.begin(), blue.end());
    int ans = 0;

    for (auto bit = blue.begin(); bit != blue.end(); bit++) {
        auto it = red.begin();
        while (it != red.end()) {
            if (it->first < bit->second && it->second < bit->first) {
                ans++;
                red.erase(it);
                break;
            }
            it++;
        }
    }

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

#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
#define U(v) cerr << #v << ": " << (v) << endl

template <class T>
struct BIT {
    vector<T> a;
    BIT(int size) : a(size, 0) {}
    T sum(int r) const {
        T sm = 0;
        for (--r; r >= 0; r = (r & r + 1) - 1)
            sm += a[r];
        return sm;
    }
    T sum(int l, int r) const {
        return sum(r) - sum(l);
    }
    T at(int i) const {
        return sum(i, i + 1);
    }
    void add(int i, T v) {
        for (; i < (int)a.size(); i |= i + 1)
            a[i] += v;
    }
    void set(int i, T v) {
        add(i, v - at(i));
    }
};

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    vector<pair<int, int>> b(n);
    for (int i = 0; i < n; ++i) {
        cin >> b[i].first;
        b[i].second = i;
    }
    sort(b.begin(), b.end());
    for (int i = 0; i < n; ++i)
        a[b[i].second] = i;
    BIT<int> bit(n);
    long long sm = 0;
    for (int i = n - 1; i >= 0; --i) {
        sm += bit.sum(a[i]);
        bit.add(a[i], 1);
    }
    cout << sm << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MOD=1000000007;
int n,k;
LL fac[4000000],inv_fac[4000000],dp[2001];
void check_mod(LL &a) { if (a>=MOD) a%=MOD; }
int ksm(LL a, int b)
{
	LL ret=1ll;
	while (b) {
		if (b&1) ret*=a;
		check_mod(ret);
		a*=a;
		check_mod(a);
		b>>=1;
	}
	return ret;
}
int main()
{
	LL lt;
	int t;
	scanf("%d%d",&n,&k);
	if (k==1) {
		printf("1\n");
		return 0;
	}
	fac[0]=1;
	t=n*k;
	for (int i = 1; i < t; ++i) {
		fac[i]=1ll*i*fac[i - 1];
		check_mod(fac[i]);
	}
	inv_fac[t-1]=ksm(fac[t-1],MOD-2);
	for (int i=t-2;i;--i) {
		inv_fac[i]=1ll*(i+1)*inv_fac[i+1];
		check_mod(inv_fac[i]);
	}
	inv_fac[0]=1;
	dp[0]=1;
	t=-2;
	for (int i=1;i<=n;++i) {
		t+=k-1;
		for (int j=0;j<=i;++j) {
			++t;
			lt=fac[t]*inv_fac[t-k+2];
			check_mod(lt);
			lt*=inv_fac[k-2];
			check_mod(lt);
			dp[j]*=lt;
			if (j) dp[j]+=dp[j - 1];
			check_mod(dp[j]);
		}
		t-=i+1;
	}
	printf("%lld\n",dp[n]*fac[n]%MOD);
	return 0;
}

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

const int64_t MOD = 1e9+7;
void add(int64_t& a, int64_t b){
    a = (a+b) % MOD;
}
void mul(int64_t& a, int64_t b){
    a = a*b % MOD;
}

vector<int64_t> fact, seq_inv, fact_inv;

void create_fact_mod(int num){
    fact[0] = fact[1] = 1;
    for(int i=2; i<=num; i++) fact[i] = fact[i-1] * i % MOD;
}

void create_seq_inv_mod(int num){
    seq_inv[0] = seq_inv[1] = 1;
    for(int i=2; i<=num; i++) seq_inv[i] = (MOD - MOD/i) * seq_inv[MOD%i] % MOD;
}

void create_fact_inv_mod(int num){
    fact_inv[0] = fact_inv[1] = 1;
    for(int i=2; i<=num; i++) fact_inv[i] = fact_inv[i-1] * seq_inv[i] % MOD;
}

void create_mod_tables(int num){
    fact.resize(num+1);
    seq_inv.resize(num+1);
    fact_inv.resize(num+1);
    create_fact_mod(num);
    create_seq_inv_mod(num);
    create_fact_inv_mod(num);
}

int64_t comb_mod(int n, int k){
    return fact[n] * fact_inv[n-k] % MOD * fact_inv[k] % MOD;
}

int main(){
    int N, K;
    cin >> N >> K;
    if(K == 1){
        cout << 1 << endl;
        return 0;
    }
    create_mod_tables(N*K);
    static int64_t dp[2001][2001];
    dp[0][0] = fact[N];
    for(int i=0; i<=N; i++) for(int j=0; j<=i; j++){
        if(i<N) add(dp[i+1][j], dp[i][j]);
        if(i>=j+1) add(dp[i][j+1], dp[i][j] * comb_mod(N*K - i - j*(K-1) - 1, K-2));
    }
    cout << dp[N][N] << endl;
    return 0;
}


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

int main() {

  int A, B, C, D;
  cin >> A >> B >> C >> D;

  if (A+B == C+D) {
    cout << "Balanced" << endl;
  }
  else if (A+B >= C+D) {
    cout << "Left" << endl;
  }
  else {
    cout << "Right" << endl;
  }

return 0;
}

#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<numeric>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

using ll = long long;

class Stream{
public:
    Stream(){

    }
    //配列以外の入力を受け取る
    void read(){

    }
    template<typename First, typename... Rest>
    void read(First& first, Rest&... rest){
        cin >> first;
        read(rest...);
    }
    //配列を区切って出力する
    template<typename T>
    void write_vec(vector<T>& v, char divider){
        for(size_t i = 0; i < v.size(); i++){
            cout << v[i] << divider;
        }
    }
};

int main(){
    Stream io;

    int A, B, C, D;
    io.read(A, B, C, D);
    string ans;
    if(A + B < C + D){
        ans = "Right";
    }
    else if(A + B == C + D){
        ans = "Balanced";
    }
    else{
        ans = "Left";
    }
    cout << ans;
    return 0;
}


#include <iostream>
using namespace std;

int main() {
	string S,T;
	cin>>S>>T;

cout<<T+S;

	return 0;
}

#include<stdio.h>

int main(){

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

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};

vector<int> v[505];

int main(){
    int n, m, Q;
    cin >> n >> m >> Q;
    rep(i, m) {
        int l, r;
        cin >> l >> r;
        l--; r--;
        v[l].push_back(r);
    }
    rep(i, n) {
        sort(whole(v[i]));
    }
    rep(qi, Q) {
        int p, q;
        cin >> p >> q;
        p--; q--;
        int ans = 0;
        for (int i=p; i<=q; i++) {
            auto it = upper_bound(whole(v[i]), q);
            ans += (it-v[i].begin());
        }
        cout << ans << endl;
    }

    return 0;
}

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

int main() {
    ll N, M, Q, L, R;
    cin >> N >> M >> Q;
    vector<vector<ll>> sum(N+1, vector<ll>(N+1));
    rep(i,M) {
        cin >> L >> R;
        ++sum[L][R];
    }
    rep(i,N) rep(j,N) sum[i+1][j+1] += sum[i+1][j];
    for (int i = 1; i <= N; ++i) {
        for (int j = N - 1; j > 0; --j) {
            sum[j][i] += sum[j+1][i];
        }
    }

    vector<ll> p(Q), q(Q);
    rep(i,Q) cin >> p[i] >> q[i];

    rep(i,Q) cout << sum[p[i]][q[i]] << endl;
}


#include <iostream>
#include <vector>
#include <queue>
#include <map>
#define INF (int)1e9

void dijkstra(int m, int p, int q, std::vector<std::vector<std::pair<int, int> > > &v);

int main(void) {
    int n;
    int m;
    int a;
    int b;
    int cost;
    int time;
    int k;
    int p;
    int q;
    int r;

    while (true) {
        std::cin >> n >> m;
        if (n == 0 && m == 0) {
            break;
        }
        std::vector<std::vector<std::pair<int, int> > > vcost(m);
        std::vector<std::vector<std::pair<int, int> > > vtime(m);
        for (int i = 0; i < n; i++) {
            std::cin >> a >> b >> cost >> time;
            --a;
            --b;
            vcost[a].push_back(std::make_pair(cost, b));
            vcost[b].push_back(std::make_pair(cost, a));
            vtime[a].push_back(std::make_pair(time, b));
            vtime[b].push_back(std::make_pair(time, a));
        }
        std::cin >> k;
        for (int i = 0; i < k; i++) {
            std::cin >> p >> q >> r;
            --p;
            --q;
            if (r == 0) {
                dijkstra(m, p, q, vcost);
            } else {
                dijkstra(m, p, q, vtime);
            }
        }
    } return 0;
}

void dijkstra(int m, int p, int q, std::vector<std::vector<std::pair<int, int> > > &v) {
    std::vector<int> rvec(m, INF);
    rvec[p] = 0;
    std::priority_queue<std::pair<int, int>, std::vector<std::pair<int, int> >, std::greater<std::pair<int, int> > > pq;
    std::vector<int> search_count(m, 0);
    int start_value;
    int start_target;
    int end_value;
    int end_target;
    pq.push(std::make_pair(rvec[p], p));

    while(! pq.empty()) {
        start_target = pq.top().second;
        start_value = pq.top().first;
        pq.pop();
        if (search_count[start_target] != 0) {
            continue;
        }
        ++search_count[start_target];
        for (int i = 0; i < v[start_target].size(); i++) {
            end_value = v[start_target][i].first;
            end_target = v[start_target][i].second;
            if (rvec[end_target] > end_value + rvec[start_target]) {
                rvec[end_target] = end_value + rvec[start_target];
                pq.push(std::make_pair(rvec[end_target], end_target));
            }
        }
    }
    std::cout << rvec[q] << std::endl;
    return;
}

#include <iostream>
using namespace std;

#define INF 10000000

int t[101][101], s[101][101];

int main(void){
	int n,m;

	while(cin>>n>>m, n){
		for(int i=0;i<=m;i++) for(int j=0;j<=m;j++) t[i][j] = s[i][j] = INF;
		for(int i=0;i<n;i++){
			int a,b,cost,time;
			cin>>a>>b>>cost>>time;
			t[a][b] = t[b][a] = cost;
			s[a][b] = s[b][a] = time;
		}

		for(int k=1;k<=m;k++){
			for(int i=1;i<=m;i++){
				for(int j=1;j<=m;j++){
					t[i][j] = min(t[i][j],t[i][k]+t[k][j]);
					s[i][j] = min(s[i][j],s[i][k]+s[k][j]);
				}
			}
		}

		cin>>n;
		while(n--){
			int a,b,flg;
			cin>>a>>b>>flg;
			cout<<(flg?s[a][b]:t[a][b])<<endl;
		}
	}

	return 0;
}


#include<iostream>
#include<queue>

using namespace std;

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

typedef struct{
    int idx[3];
}int3;

typedef struct{
    int status[20][20];
}int20;

typedef vector<pair<int, int > > vecpair;

int20 map;
int dir[4][2] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};
int w, h;

pair<int3, vecpair> move(int3 cidx, int d[2], vecpair cstatus){
    pair<int3, vecpair> output;
    int3 nidx;
    vecpair nstatus = cstatus;

    int ch = cidx.idx[0];
    int cw = cidx.idx[1];
    int cs;

    int20 cmap;
    cmap = map;
    REP(i, cstatus.size()){
        cmap.status[cstatus[i].first][cstatus[i].second] = 0;
    }

    if(cmap.status[ch+d[0]][cw+d[1]]==1){
        nidx.idx[0] = -1;
        nidx.idx[1] = -1;
        nidx.idx[2] = -1;
        output = make_pair(nidx, nstatus);
        return output;
    }

    REP(i, 20){
        ch += d[0];
        cw += d[1];
        if(ch<0 || ch>=h || cw<0 || cw>=w || cidx.idx[2]+1 > 10){
            nidx.idx[0] = -1;
            nidx.idx[1] = -1;
            nidx.idx[2] = -1;
            output = make_pair(nidx, nstatus);
            return output;
        } else {
            cs = cmap.status[ch][cw];
        }

        if(cs == 0){
            continue;
        } else if(cs == 1){
            nstatus.push_back(make_pair(ch, cw));
            nidx.idx[0] = ch - d[0];
            nidx.idx[1] = cw - d[1];
            nidx.idx[2] = cidx.idx[2] + 1;
            output = make_pair(nidx, nstatus);
            return output;
        } else if(cs == 3){
            nidx.idx[0] = ch;
            nidx.idx[1] = cw;
            nidx.idx[2] = cidx.idx[2] + 1;
            output = make_pair(nidx, nstatus);
            return output;
        }
    }
}

int main(){
    while(1){
        cin >> w >> h;

        if(w==0){
            break;
        }

        int3 s;
        int g[2];
        REP(i, h){
            REP(j, w){
                cin >> map.status[i][j];
                if(map.status[i][j] == 2){
                    s.idx[0] = i;
                    s.idx[1] = j;
                    s.idx[2] = 0;
                } else if(map.status[i][j] == 3){
                    g[0] = i;
                    g[1] = j;
                }
            }
        }

        queue<int3> qidx;
        queue<vector<pair<int, int> > > qstatus;
        vector<pair<int, int> > init;
        qidx.push(s);
        qstatus.push(init);
        int output = -1;

        while(!qidx.empty()){
            int3 cidx = qidx.front();
            qidx.pop();

            vecpair cstatus = qstatus.front();
            qstatus.pop();

            REP(i, 4){
                int3 nidx;
                vecpair nstatus;
                pair<int3, vecpair> next = move(cidx, dir[i], cstatus);
                nidx = next.first;
                nstatus = next.second;
                if(nidx.idx[0] == g[0] && nidx.idx[1] == g[1]) {
                    output = nidx.idx[2];
                    queue<int3> empty;
                    swap(qidx, empty);
                    break;
                } else if(nidx.idx[0] >= 0){
                    qidx.push(nidx);
                    qstatus.push(nstatus);
                }
            }
        }
        cout << output << endl;
    }
}

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

// ?????¬???????????¬??????
#pragma region MACRO
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define PED cout << "\n"
#define rep(i,n) for(int i=0; i<(int)n; ++i)
#define REP(i,x,n) for(int i=x; i<(int)n; ++i)
#define repi(i,n) for(int i=0; i<=(int)n; ++i)
#define REPI(i,x,n) for(int i=x; i<=(int)n; ++i)
#define ILP while(true)
#define FOR(i,c) for(__typeof((c).begin())!=(c).begin(); i!=(c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#pragma endregion

// ???
#pragma region TYPE_DEF
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
typedef pair<string, int> psi;
typedef pair<int, string> pis;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long double> vld;
typedef vector<long> vl;
typedef vector<long long> vll;
typedef vector<string> vs;
#pragma endregion

// Effective std
#pragma region ESTD
template<typename C, typename T> int count(C& c, T t) { return count(ALL(c), t); }
template<typename C, typename F> int count_if(C& c, F f) { return count_if(ALL(c), f); }
template<typename C, typename T> void erase(C& c, T t) { remove(ALL(c), t), c.end(); }
template<typename C> void remove(vector<C>& c, unsigned int index) { c.erase(c.begin()+index); }
template<typename C, typename T, typename U> void replace(C& c, T t, U u) { replace(ALL(c), t, u); }
template<typename C, typename F, typename U> void replace_if(C& c, F f, U u) { (ALL(c), f, u); }
template<typename C> void reverse(C& c) { reverse(ALL(c)); }
template<typename C> void sort(C& c) { sort(ALL(c)); }
template<typename C, typename Pred> void sort(C& c, Pred p) { sort(ALL(c), p); }
#pragma endregion

// ?????°
#pragma region CONST_VAL
constexpr int PI = (2*acos(0.0));
constexpr int EPS = (1e-9);
constexpr int MOD = (int)(1e9+7);
constexpr int INF = 100000000;
#pragma endregion

bool is_small(int h1, int w1, int h2, int w2) {
    int d1 = h1*h1 + w1*w1;
    int d2 = h2*h2 + w2*w2;
    if(d1 < d2) return true;
    else if(d1 > d2) return false;
    else if(h1<h2) return true;
    else return false;
}

int main()
{
    int h, w;
    while(cin>>h>>w, h) {
        int mh = 151;
        int mw = 151;
        for(int i=1; i<=150; ++i) {
            for(int j=i+1; j<=150; ++j) {
                if(i==h&&j==w) continue;
                if(is_small(i,j,h,w)) continue;
                if(is_small(i,j,mh,mw)) {
                    mh = i;
                    mw = j;
                }
            }
        }
        cout << mh << " " << mw << endl;
    }
    return 0;
}


#include <bits/stdc++.h>

#define gc( ) std::getchar( )
#define pc( i ) std::putchar( i )

template < typename T >
inline T read( )
{
	register T x = 0;
	register char ch = gc( );
	register bool f = 0;
	while( !std::isdigit( ch ) )
	{
		f = ( ch == '-' );
		ch = gc( );
	}
	while( std::isdigit( ch ) )
	{
		x = x * 10 + ( ch - '0' );
		ch = gc( );
	}
	return f ? -x : x;
}

template < typename T >
void print( T x )
{
	if( x < 0 )
	{
		x = -x;
		pc( '-' );
	}
	if( x < 10 )
	{
		pc( x + 48 );
		return;
	}
	print < T > ( x / 10 );
	pc( x % 10 + 48 );
	return ;
}

namespace Solution
{
#define IOS std::ios::sync_with_stdio( false ), std::cin.tie( 0 ), std::cout.tie( 0 )
#define Rep( i, j, k ) for( int i = j; i >= k; --i )
#define rdi( ) read < int > ( )
#define rdl( ) read < long long > ( )
#define pti( i ) print < int > ( i ), putchar( ' ' )
#define ptl( i ) print < long long > ( i ), putchar( ' ' )
#define For( i, j, k ) for( int i = j; i <= k; ++i )
	using std::cin;
	using std::cout;
	using std::endl;
	using std::vector;
	using std::map;
	using std::queue;
	using std::deque;
	using std::set;
	using std::pair;
	const int Maxn = 100001;
	int n, bol, L, Q, bl[ Maxn ], x[ Maxn ], to[ Maxn ], nxt[ Maxn ], out[ Maxn ];
	int find( int u )
	{
		int l = u + 1, r = n, ans = u;
		while( l <= r )
		{
			int mid = l + r >> 1;
			if( x[ mid ] - x[ u ] <= L )
				ans = mid, l = mid + 1;
			else
				r = mid - 1;
		}
		return ans;
	}
	int solve( int l, int r )
	{
		int res = 0;
		while( bl[ l ] < bl[ r ] )
		{
			res += nxt[ l ];
			l = out[ l ];
		}
		while( l < r )
		{
			res++;
			l = to[ l ];
		}
		return res;
	}
	void fakemain( )
	{
		IOS;
		cin >> n;
		bol = sqrt( n );
		For( i, 1, n )
			cin >> x[ i ],
			bl[ i ] = ( i - 1 ) / bol + 1;
		cin >> L;
		For( i, 1, n )
			to[ i ] = find( i );
		Rep( i, n - 1, 1 )
		{
			if( to[ i ] == n )
			{
				out[ i ] = n;
				nxt[ i ] = 1;
			}
			else
			{
				if( to[ i ] > bol * bl[ i ] )
				{
					out[ i ] = to[ i ];
					nxt[ i ] = 1;
				}
				else
				{
					out[ i ] = out[ to[ i ] ];
					nxt[ i ] = nxt[ to[ i ] ] + 1;
				}
			}
		}
		cin >> Q;
		int l, r;
		while( Q-- )
		{
			cin >> l >> r;
			if( l > r )
				std::swap( l, r );
			cout << solve( l, r ) << '\n';
		}
		return;
	}

} // namespace Solution

int main( int argc, char* argv[] )
{
	Solution::fakemain( );
	return 0;
}

#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;

constexpr ll mod = 1e9 + 7;

template <class T> inline bool chmax(T &a, const T b) {
    if(a >= b) return false;
    a = b;
    return true;
}
template <class T> inline bool chmin(T &a, const T b) {
    if(a <= b) return false;
    a = b;
    return true;
}

/*-------------------------------------------*/

ll n, l, q;
ll x[100009], nxt[100009][17];

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

    cin >> n;
    rep(i, n) cin >> x[i];
    cin >> l;
    ll y = 0;
    rep(i, n) {
        while(y + 1 < n && x[i] + l >= x[y + 1]) {
            y++;
        }
        nxt[i][0] = y;
    }
    rep(i, 16) rep(j, n) nxt[j][i + 1] = nxt[nxt[j][i]][i];

    cin >> q;
    while(q--) {
        ll a, b;
        cin >> a >> b;
        a--;
        b--;
        if(b < a) swap(a, b);
        ll ans = 1;
        for(int i = 16; i >= 0; i--) {
            if(nxt[a][i] < b) {
                a = nxt[a][i];
                ans += 1 << i;
            }
        }
        cout << ans << endl;
    }

    return 0;
}


#pragma region
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <iomanip>
#include <cstdint>
#include <bitset>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()

#pragma region UnionFind
struct UnionFind
{
	vector<int> par;

	UnionFind(int n) : par(n, -1) {}
	void init(int n) { par.assign(n, -1); }

	int root(int x)
	{
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

	bool issame(int x, int y)
	{
		return root(x) == root(y);
	}

	bool merge(int x, int y)
	{
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y);
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x)
	{
		return -par[root(x)];
	}
};
#pragma endregion
#pragma region GCD
ll gcd(ll a, ll b)
{
	if (b == 0)return a;
	return gcd(b, a%b);
}
#pragma endregion
#pragma region LCM
ll lcm(ll a, ll b)
{
	return a / gcd(a, b) * b;
}
#pragma endregion
#pragma region chmin
template<class T> inline bool chmin(T& a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma region chmax
template<class T> inline bool chmax(T& a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma endregion

int main()
{
	int h, w; cin >> h >> w;
	vector<string> s(h); rep(i, h)cin >> s[i];
	ll res = 0;
	int d[] = { 0,1,0,-1 };
	vector<vector<bool>> passed(h, vector<bool>(w));
	rep(i, h)rep(j, w)
	{
		if (s[i][j] == '.' || passed[i][j])continue;
		passed[i][j] = true;
		queue<pair<int, int>> q;
		q.push(make_pair(i, j));
		ll B = 1, W = 0;
		while (!q.empty())
		{
			int x, y;
			tie(x, y) = q.front();
			q.pop();
			rep(k, 4)
			{
				int nx = x + d[k];
				int ny = y + d[k ^ 1];
				if (nx < 0 || h <= nx || ny < 0 || w <= ny)continue;
				if (passed[nx][ny])continue;
				if (s[x][y] != s[nx][ny])
				{
					q.push(make_pair(nx, ny));
					passed[nx][ny] = true;
					if (s[nx][ny] == '.')++W;
					else ++B;
				}
			}
		}
		res += B * W;
	}
	cout << res << endl;
}

#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    int n,k;
    cin>>n>>k;
    vector<int> l(n);
    rep(i,n) cin>>l[i];
    sort(all(l));
    int ans=0;
    rep(i,k) ans+=l[n-1-i];
    cout<<ans;
}


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

const ll p = 998244353;

ll powmod(ll a, ll b){
    if(b==0) return 1;
    if(b%2==1) return (a*powmod(a,b-1)) % p;
    else{
        ll x = powmod(a,b/2);
        return (x*x) % p;
    }
}

ll combinemod(ll a, ll b){
    ll x=1,y=1;
    for(int i=1;i<=b;i++){
        y = (y*i)%p;
    }
    for(int i=a-b+1;i<=a;i++){
        x = (x*i)%p;
    }

    return (x * powmod(y,p-2)) % p;
}

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

    vector<ll> dp1(k+1), dp2(k+1);
    dp1.at(0) = m * powmod(m-1,n-1) % p;
    dp2.at(0) = 1;
    rep(i,k){
        dp1.at(i+1) = m*powmod(m-1,n-1-(i+1)) % p;
        dp2.at(i+1) = (dp2.at(i) * (n-i-1) % p * powmod(i+1,p-2)) % p;
    }

    ll tot = 0;
    rep(i,k+1){
        tot += dp1.at(i) * dp2.at(i) % p;
        tot %= p;
    }

    cout << tot << endl;
    return 0;
}

#include<bits/stdc++.h>
#define ll long long int
#define mod 998244353
#define ld long double
#define pb push_back
#define inf INT_MAX
#define N 1000000
using namespace std;
int n,m,k;
ll ans=0;
ll inv[N+3];
ll fact_inv[N+3];
ll fact[N+3];
//modulo inverse
void inverse(){
	inv[1]=1;//MMI
	int i;
	for(i=2;i<=N;i++){
		inv[i]=mod-(mod/i)*inv[mod%i]%mod;
	}
}
void factinv(){
	int i;
	fact_inv[0]=1;
	for(i=1;i<=N;i++){
		fact_inv[i]=fact_inv[i-1]*inv[i]%mod;
	}
}
void facto(){
	int i;
	fact[0]=1;
	for(i=1;i<=N;i++){
		fact[i]=(fact[i-1]*i)%mod;
	}
}
ll power(int a,int b){
	if(b==0)
	return 1;
	else if(b==1)
	return a;
	else{
		if(b&1)
		return ((a%mod)*(power(a,b-1)%mod))%mod;
		else
		return ((power(a,b/2)%mod)*(power(a,b/2)%mod))%mod;
	}
}
void solve(int p){
	ll a=((fact_inv[n-p-1]%mod)*(fact_inv[p]%mod))%mod;
	ll b=(m*power(m-1,n-p-1)%mod)%mod;
	ll c=(a*b)%mod;
	ans+=(fact[n-1]*c)%mod;
	ans%=mod;
}
int main(void){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int i;
	cin>>n>>m>>k;
	facto();
	inverse();
	factinv();
	//cout<<inv[123]<<endl;
	for(i=0;i<=k;i++)
	solve(i);
	cout<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
const int N=1e6+5;
char s[N],t[N];
int n,ans,l=1,r,last,q[N];
int main(){
	scanf("%d%s%s",&n,s+1,t+1),last=n;
	for(int i=n;i;){
		while(last&&(i<last||s[last]!=t[i])) --last;
		if(!last)	{puts("-1");return 0;}
		while(l<=r&&q[l]-r+l-1>=i)	++l;
		q[++r]=last;
		if(i!=last) ans=max(ans,r-l+1);
		while(t[i]==s[last]&&i>=last)	--i;
	}
	printf("%d\n",ans);
	return 0;
}

#include <stdio.h>

int main (){
	int baris,kolom,warna,x;

	scanf ("%d",&baris);
	scanf ("%d",&kolom);
	scanf ("%d",&warna);

	if (baris > kolom){
        x = (warna - 1)/baris +1;
    }
    else {
        x = (warna - 1)/kolom +1;
    }

	printf ("%d",x);

	return 0;
}


#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n,m;cin>>n>>m;
  int A[n], B[m];
  FOR(i,0,n)cin>>A[i];
  FOR(i,0,m)cin>>B[i];
  int cnt[n+1];
  int ans = -1, num = 0;
  CLR(cnt);
  FOR(i,0,m){
      FOR(j,0,n){
          if(A[j] <= B[i]){
              cnt[j+1]++;
              if(cnt[j+1] > cnt[ans]) ans = j + 1;
              break;
          }
      }
  }
  cout << ans << endl;
}

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

int main() {
  int N, M; cin >> N >> M;
  vector<int> cost(N);
  for(int i = 0; i < N; ++i)
    cin >> cost[i];
  vector<int> score(N, 0);
  while(M--) {
    int x; cin >> x;
    for(int i = 0; i < N; ++i) {
      if(cost[i] <= x) {
        score[i]++;
        break;
      }
    }
  }
  int argmax = find(score.begin(), score.end(), *max_element(score.begin(), score.end())) - score.begin();
  cout << argmax + 1 << endl;
}


#include <iostream>
using namespace std;

const int BASE = 6200;
int N, mod;
int dp[6009][12409][3];
long long ret[12409];

void solve(int p1, int p2) {
	// 最大値を更新する場合
	for (int i = 0; i <= 2; i++) {
		int r = 0;
		if (i == 0) r = -1;
		if (i == 1) r = 1;
		dp[p1][p2][0] += 1LL * dp[p1 - 1][p2 - r][i] % mod;
		if (dp[p1][p2][0] >= mod) dp[p1][p2][0] -= mod;
	}

	// 最大値を更新しない場合
	for (int i = 1; i <= 2; i++) {
		dp[p1][p2][i] += 1LL * (p1 - 1LL) * dp[p1 - 1][p2][i - 1] % mod;
		if (dp[p1][p2][i] >= mod) dp[p1][p2][i] -= mod;
	}
}

int main() {
	cin >> N >> mod;
	dp[1][BASE][0] = 1;

	for (int i = 2; i <= 3 * N; i++) {
		for (int j = 1; j <= BASE * 2 - 1; j++) {
			solve(i, j);
		}
	}

	for (int i = 1; i <= BASE * 2 - 1; i++) {
		for (int j = 0; j <= 2; j++) {
			int r = 0;
			if (j == 0) r = -1;
			if (j == 1) r = 1;
			ret[i + r] += dp[3 * N][i][j];
		}
	}

	long long Answer = 0;
	for (int i = 0; i <= BASE; i++) Answer += ret[i];
	cout << Answer % mod << endl;
	return 0;
}

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

int64_t MOD;
void add(int64_t& a, int64_t b){
    a = (a+b) % MOD;
}
void mul(int64_t& a, int64_t b){
    a = a*b % MOD;
}

vector<int64_t> fact, seq_inv, fact_inv;

void create_fact_mod(int num){
    fact[0] = fact[1] = 1;
    for(int i=2; i<=num; i++) fact[i] = fact[i-1] * i % MOD;
}

void create_seq_inv_mod(int num){
    seq_inv[0] = seq_inv[1] = 1;
    for(int i=2; i<=num; i++) seq_inv[i] = (MOD - MOD/i) * seq_inv[MOD%i] % MOD;
}

void create_fact_inv_mod(int num){
    fact_inv[0] = fact_inv[1] = 1;
    for(int i=2; i<=num; i++) fact_inv[i] = fact_inv[i-1] * seq_inv[i] % MOD;
}

void create_mod_tables(int num){
    fact.resize(num+1);
    seq_inv.resize(num+1);
    fact_inv.resize(num+1);
    create_fact_mod(num);
    create_seq_inv_mod(num);
    create_fact_inv_mod(num);
}

int64_t comb_mod(int n, int k){
    return fact[n] * fact_inv[n-k] % MOD * fact_inv[k] % MOD;
}

int64_t perm_mod(int n, int k){
    return fact[n] * fact_inv[n-k] % MOD;
}

int64_t power_mod(int64_t num, int64_t power){
    int64_t prod = 1;
    num %= MOD;
    while(power > 0){
        if(power&1) prod = prod * num % MOD;
        num = num * num % MOD;
        power >>= 1;
    }
    return prod;
}

int64_t extgcd(int64_t a, int64_t b, int64_t& x, int64_t& y){
    int64_t d = a;
    if(b != 0){
        d = extgcd(b, a%b, y, x);
        y -= (a/b) * x;
    }else{
        x = 1; y = 0;
    }
    return d;
}

int64_t inv_mod(int64_t a){
    int64_t x, y;
    extgcd(a, MOD, x, y);
    return (MOD + x%MOD) % MOD;
}

int main(){
    int N;
    cin >> N >> MOD;
    create_mod_tables(10000);

    static int64_t dp[6010][4001];
    dp[3*N][N] = 1;
    for(int i=3*N; i>0; i--) for(int j=0; j<=2*N; j++){
        add(dp[i-1][min(2*N, j+1)], dp[i][j]);
        if(i>=2 && j > 0) add(dp[i-2][j-1], dp[i][j] * (i-1));
        if(i>=3) add(dp[i-3][j], dp[i][j] * (i-1) * (i-2));
    }

    int64_t ans = 0;
    for(int j=N; j<=2*N; j++) add(ans, dp[0][j]);
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

const int MOD = 998244353;

int main() {
	int n; scanf("%d", &n); std::vector<int> a(n);
	for(int i = 0; i < n; i++) scanf("%d", &a[i]);
	sort(begin(a), end(a));

	int s = 0;
	for(auto v: a) s += v;

	auto dp = make_v<i64>(n + 1, s + 1); dp[0][0] = 1;
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < s; j++) {
			if(!dp[i][j]) continue;
			(dp[i + 1][j + a[i]] += dp[i][j]) %= MOD;
			(dp[i + 1][j] += dp[i][j]) %= MOD;
			(dp[i + 1][j] += dp[i][j]) %= MOD;
		}
	}

	i64 ans = 1;
	for(int i = 0; i < n; i++) (ans *= 3LL) %= MOD;

	i64 sub = 0;
	for(int i = (s + 1) / 2; i <= s; i++) (sub += dp[n][i]) %= MOD;

	if(!(s & 1)) {
		auto dp2 = make_v<i64>(n + 1, s + 1); dp2[0][0] = 1;
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < s; j++) {
				if(!dp2[i][j]) continue;
				(dp2[i + 1][j + a[i]] += dp2[i][j]) %= MOD;
				(dp2[i + 1][j] += dp2[i][j]) %= MOD;
			}
		}

		(sub -= dp2[n][s / 2] - MOD) %= MOD;
	}
	printf("%lld\n", (ans - 3 * sub % MOD + MOD) % MOD);
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

#define MOD 998244353

int n, a[330], dp[300*303], d2[300*303], ans = 1, sum;

int expo(int b, int e) {
    if(e == 0) return 1;
    if(e & 1) return 1ll * b * expo(1LL * b * b % MOD, e >> 1) % MOD;
    return expo(1LL * b * b % MOD, e >> 1);
}

int inv_mod(int x) { return expo(x, MOD - 2); }

int main() {
    scanf("%d", &n);

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

        sum += a[i];
        ans = 3LL * ans % MOD;

        for(int v = n * 300; v >= 0; v--) {
            dp[v] = (2LL * dp[v] % MOD + (v >= a[i] ? dp[v - a[i]] : 0)) % MOD;
            d2[v] =       (d2[v] % MOD + (v >= a[i] ? d2[v - a[i]] : 0)) % MOD;
        }
    }

    for(int i = sum; 2*i >= sum; i--)
        ans = (ans - 3LL * dp[i] % MOD + MOD) % MOD;

    if(sum % 2 == 0) ans = (ans + 3LL * d2[sum/2] % MOD) % MOD;

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


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

inline void upmax(short &x,const short &y){if(y>x) x=y;}

const int N=105;
short f[N][N][N][N];
short sum1[N][N],sum2[N][N];
int n,m,tx,ty;

void gao()
{
    int limu=tx-1,limd=n-tx,liml=ty-1,limr=m-ty;
    for(int u=0;u<=limu;u++)
        for(int d=0;d<=limd;d++)
            for(int l=0;l<=liml;l++)
                for(int r=0;r<=limr;r++)
                {
                    int L=max(ty-l,r+1),R=min(ty+r,m-l);
                    if(L<=R)
                    {
                        upmax(f[u+1][d][l][r],f[u][d][l][r]+(tx-u-1>=d+1?sum1[tx-u-1][R]-sum1[tx-u-1][L-1]:0));
                        upmax(f[u][d+1][l][r],f[u][d][l][r]+(tx+d+1<=n-u?sum1[tx+d+1][R]-sum1[tx+d+1][L-1]:0));
                    }
                    L=max(tx-u,d+1),R=min(tx+d,n-u);
                    if(L<=R)
                    {
                        upmax(f[u][d][l+1][r],f[u][d][l][r]+(ty-l-1>=r+1?sum2[R][ty-l-1]-sum2[L-1][ty-l-1]:0));
                        upmax(f[u][d][l][r+1],f[u][d][l][r]+(ty+r+1<=m-l?sum2[R][ty+r+1]-sum2[L-1][ty+r+1]:0));
                    }
                }
    printf("%d\n",f[limu][limd][liml][limr]);
}

int main()
{
    static char s[105];
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
    {
        scanf("%s",s+1);
        for(int j=1;j<=m;j++)
        {
            if(s[j]=='E') tx=i,ty=j;
            sum1[i][j]=sum1[i][j-1]+(s[j]=='o');
            sum2[i][j]=sum2[i-1][j]+(s[j]=='o');
        }
    }
    gao();
}


#include<iostream>
#include<string>
#include<map>
#include<algorithm>
using namespace std;
typedef long long ll;
const int Max = 1e3 + 7;
int lst[Max];
int n;

bool check()
{
	for (int i = 1; i <= n; i++)
	{
		if (lst[i] % 2 != 0) return false;
		else lst[i] /= 2;
	}
	return true;
}

int main()
{

	cin >> n;
	for (int i = 1; i <= n; i++)scanf("%d", &lst[i]);
	int g = 0;
	while (check())
	{
		g++;
	}
	cout << g;
}

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

typedef long long ll;

ll gcd( ll x, ll y );
ll lcm( ll x, ll y );

int main()
{
    int n, c, a[11];

    while ( true ) {
        memset( a, 0, sizeof(a) );
        scanf("%d", &n );
        if ( n == 0 ) break;
        for ( int i = 0; i < n; i++ ) {
            scanf("%d", &c );
            a[c]++;
        }

        for ( int i = 0; i < 10; ++i ) {
            if ( a[i] != 0 ) {
                for ( int j = 0; j < a[i]; ++j ) {
                    printf("*");
                }
            } else {
                printf("-");
            }
            putchar('\n');
        }
    }

    return 0;
}

ll gcd( ll x, ll y )
{
    if ( y == 0 ) return x;
    return gcd( y, x % y );
}

ll lcm( ll x, ll y )
{
    return x / gcd( x, y ) * y;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
//#define f(i,a,n) for(ll i=a;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll isPrime(int n)
{
	// Corner cases
	if (n <= 1)
		return 1;
	if (n <= 3)
		return 2;

	// This is checked so that we can skip
	// middle five numbers in below loop
	if (n % 2 == 0 || n % 3 == 0)
		return 1;

	for (int i = 5; i * i <= n; i = i + 6)
		if (n % i == 0 || n % (i + 2) == 0)
			return 1;

	return 2;
}

ll fact(ll n){ll res = 1;for (ll i = 2; i <= n; i++)res = res * i,res%=1000000007;
    return res; }

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

ll findlcm(ll arr[], int n)
{

    ll ans = arr[0];

    for (int i = 1; i < n; i++)
        ans = (((arr[i] * ans)) /
                (gcd(arr[i], ans)));

    return ans;
}

int main()
{
    fast;
    ll t=1;
    //cin>>t;
    while(t--)
    {
      double r,g;
      cin>>r>>g;
      cout<<2*g-r;

    }
    return 0;
}

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

int main() {
    int n, m, s, c;
    int ans = 0;
    vector<int> a(5, -1);

    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        cin >> s >> c;

        if (s == 1 && c == 0 && n != 1) ans = -1;

        if (a[s] == -1 || a[s] == c) a[s] = c;
        else ans = -1;
    }

    if (ans == -1) cout << ans << endl;
    else {
        if (a[1] == -1 && n != 1) a[1] = 1;
        for(int i = 1; i <= n; i++) {
            if (a[i] == -1) a[i] = 0;
            cout << a[i];
        }
        cout << endl;
    }
}


#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;

int main(){
    int N,M; cin >> N >> M;
    vector<vector<int>> A(N,vector<int>(M));
    rep(i,N)rep(j,M){
        cin >> A[i][j];
        A[i][j]--;
    }
    vector<int> id(N);
    vector<vector<bool>> used(N,vector<bool>(M,false));
    int ans = INF;
    while(true){
        vector<int> s(M);
        bool ok = true;
        rep(i,N){
            while(used[i][id[i]]){
                id[i]++;
                if(id[i] >= M) ok = false;
            }
            if(!ok) break;
            s[A[i][id[i]]]++;

        }
        if(!ok) break;
        int now = 0;
        int dame = 0;
        rep(i,M){
            if(now < s[i]){
                now = s[i];
                dame = i;
            }
        }
        rep(i,N)rep(j,M){
            if(A[i][j] == dame) used[i][j] = true;
        }
        ans = min(ans,now);
    }
    cout << ans << endl;
}

#include "bits/stdc++.h"
using namespace std;
#define int long long
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define RFOR(i, a, b) for(int i=(b-1);i>=(a);i--)
#define REP(i, n) for(int i=0; i<(n); i++)
#define RREP(i, n) for(int i=(n-1); i>=0; i--)
#define REP1(i, n) for(int i=1; i<=(n); i++)
#define RREP1(i, n) for(int i=(n); i>=1; i--)
#define ALL(a) (a).begin(),(a).end()
#define UNIQUE_SORT(l) sort(ALL(l)); l.erase(unique(ALL(l)), l.end());
#define CONTAIN(a, b) find(ALL(a), (b)) != (a).end()
#define out(...) printf(__VA_ARGS__)
#if DEBUG
#define debug(...) printf(__VA_ARGS__)
#else
#define debug(...) /* ... */
#endif
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}
void _OUT() {}; template<class H, class... T> void _OUT(H &h, T &... t) { cout<<' '<<h; _OUT(t...); };
template<class H, class... T> void _P(H &h, T &... t) { cout<<h; _OUT(t...); };
#define _PN(...) _P(__VA_ARGS__); cout << endl;
#define EXEC(...) void exec() { (__VA_ARGS__ - 1) ? multi() : solve(0); }

void exec();
void solve(int t);
void multi() { int TT; cin>>TT; REP1(t,TT) solve(t); }
signed main()
{
#if DEBUG
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    exec();
    return 0;
}

/*================================*/
#if DEBUG
#define SIZE 10
#else
#define SIZE 333
#endif

int N,M;
int A[SIZE][SIZE];

void solve(int _t) {
    cin>>N>>M;
    REP(n,N) {
        REP(m,M) {
            cin>>A[n][m];
            A[n][m]--;
        }
    }
    int ans = INT_MAX;
    vector<int> NG(M,0);
    REP(_,M) {
        vector<int> C(M,0);
        REP(n,N) {
            REP(m,M)if(!NG[A[n][m]]) {
                C[A[n][m]]++;
                break;
            }
        }
        int cnt = 0;
        int mai = -1;
        REP(m,M) if (chmax(cnt, C[m])) mai=m;
        debug("mai:%lld, cnt:%lld\n",mai,cnt);
        chmin(ans,cnt);
        NG[mai]=1;
    }
    _PN(ans);
}
EXEC(1)


#include <stdio.h>

int main()
{
	int i;
	int mark[2] = { 0 };
	int a, b, n;
	while ((scanf("%d", &n)) != EOF)
	{
		mark[0] = 0; mark[1] = 0;
		if (n == 0) break;
		for (i = 0; i < n; i++)
		{
			if (scanf("%d%d", &a, &b) == EOF) break;
			if (a < b) mark[1] += (a + b);
			else if (a > b) mark[0] += (a + b);
			else {
				mark[1] += a; mark[0] += a;
			}
		}
		printf("%d %d\n", mark[0], mark[1]);
	}
	return 0;
}

#include <bits/stdc++.h>

#define pp push_back
#define pf push_front
#define mp make_pair
#define fs first
#define sc second
#define sf scanf

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;

const int N = (int) 1e6;
const int INF = (int) 1e9 + 7;

bool comp(ii a, ii b) {
	int x = max(a.fs, a.sc) - a.sc;
	int y = max(b.fs, b.sc) - b.sc;
	return x > y;
}

int main(int argc, char *argv[])
{
	// ios_base::sync_with_stdio(false);
	// cin.tie(NULL);

	int n;
	sf("%d", &n);
	char s[N + 7];
	int l = 0, r = 0;
	vector<ii> a;
	vector<ii> b;
	for (int j = 0; j < n; ++j) {
		sf("%s", s);
		int x = 0;
		int y = 0;
		for (int i = 0; i < strlen(s); ++i) {
			if (s[i] == '(') {
				++x;
			}
			else {
				if (x < 1) {
					++y;
				}
				else {
					--x;
				}
			}
		}

		if (x > 0 && y > 0) {
			if (x > y) {
				a.pp(mp(y, x));
			}
			else {
				b.pp(mp(y, x));
			}
		}
		else {
			l += x;
			r += y;
		}
	}

	sort(a.begin(), a.end());
	for (int i = 0; i < a.size(); ++i) {
		if (l < a[i].fs) {
			puts("No");
			return 0;
		}

		l += a[i].sc - a[i].fs;

		if (l < 0) {
			puts("No");
			return 0;
		}
	}

	sort(b.begin(), b.end(), greater<ii>());
	for (int i = 0; i < b.size(); ++i) {
		if (l < b[i].fs) {
			puts("No");
			return 0;
		}

		l += b[i].sc - b[i].fs;

		if (l < 0) {
			puts("No");
			return 0;
		}
	}

	puts(l == r ? "Yes" : "No");

	return 0;
}


#include <iostream>
using namespace std;
int main(void)
{
	int n;
	while(cin>>n){
		int date[11][11]={0};
		if(!n) break;
		for(int i=0; i<n; i++){
			for(int j=0; j<n; j++){
				cin >> date[i][j];
			}
		}
		for(int i=0;i<n;i++){
			for(int j=0; j<n; j++){
				date[i][n] += date[i][j];
			}
		}
		for(int i=0;i<=n;i++){
			for(int j=0; j<n; j++){
				date[n][i] += date[j][i];
			}
		}
		for(int i=0; i<=n; i++){
			for(int j=0; j<=n; j++){
				printf("%5d",date[i][j]);
			}
			cout << "\n";
		}
	}
	return 0;
}

#include <iostream>
#include <cstdio>
#include <string>

using namespace std;

#define loop(i,a,b) for(int i=(a); i<(int)(b); i++)
#define rep(i,b) loop(i,0,b)

int main(){
    int n;
    while (cin >> n, n){
        int v[10] = {};
        rep(i, n){
            int s = 0;
            rep(j, n){
                int t; cin >> t;
                printf("%5d", t);
                s += t;
                v[j] += t;
            }
            printf("%5d\n", s);
        }
        int s = 0;
        rep(i, n){
            printf("%5d", v[i]);
            s += v[i];
        }
        printf("%5d\n", s);
    }
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define REP(i, n) for (int i = 0; i < (n); i++)

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);

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

int main() {

int n,m,x,y;
cin>>n>>m>>x>>y;
int a[n],b[m];
REP(i,n){
  cin>>a[i];
}
REP(i,m){
  cin>>b[i];
}

int max_a = INT_MIN;
int min_b = INT_MAX;

REP(i,n){
  max_a = max(max_a,a[i]);
}
REP(i,m){
  min_b = min(min_b,b[i]);
}

int ans;
int flag = 0;

for(int i=x+1;i<y;i++){
  if( i > max_a && i<=min_b){
    flag = 1;
    ans = i;
    break;
  }
}

if(flag){
 cout<<"No War\n";
}
else{
  cout<<"War\n";
}

  return 0;
}

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

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> xs(n + 1), ys(m + 1);
  cin >> xs[0] >> ys[0];
  for (int i = 1; i <= n; ++i)
    cin >> xs[i];
  for (int i = 1; i <= m; ++i)
    cin >> ys[i];
  if (*max_element(xs.begin(), xs.end()) < *min_element(ys.begin(), ys.end()))
    cout << "No War" << endl;
  else
    cout << "War" << endl;
}


#include<cstdio>
#include<algorithm>
#include<vector>
#include<sstream>
#include<cstdlib>

using namespace std;

int main(){
	while(1){
		int n,k;
		scanf("%d%d",&n,&k);

		if(n==0)
			break;

		vector<int> card(n);
		for(int i=0;i<n;i++){
			scanf("%d",&card[i]);
		}

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

		vector<int> data;
		do{

			stringstream sst;
			for(int i=0;i<k;i++){
				sst<<card[i];
			}
			data.push_back(atoi(sst.str().c_str()));

			reverse( card.begin()+k,card.end());
		}while( next_permutation(card.begin(),card.end()) );

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

		printf("%d\n",distance(data.begin(),unique(data.begin(),data.end())) );
	}
}


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

using namespace std;

typedef long long lli;
typedef vector<lli> vll;

lli partition(vll& a,lli p,lli r){
	lli x = a[r];
	lli i = p-1;
	for(lli j = p;j < r;j++){
		if(a[j] <= x){
			i++;
			swap(a[j],a[i]);
		}
	}
	swap(a[i+1],a[r]);
	return i+1;
}

lli n;
vll a;

int main(){
	cin >> n;
	a = vll(n);
	for(lli i = 0;i < n;i++) cin >> a[i];
	lli p = partition(a,0,n-1);
	for(lli i = 0;i < n;){
		if(i == p) cout << "[";
		cout << a[i];
		if(i == p) cout << "]";
		if(++i < n) cout << " ";
		else cout << endl;
	}
	return 0;
}


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

int main() {

  while( true ) {

    long long int n;
    cin >> n;
    if ( n == 0 ) break;

    vector< long long int > k;

    for ( long long int i = 0; i < n; i++ ) {
      long long int in;
      cin >> in;
      k.push_back( in );
    }

    string s;
    cin >> s;

    for ( long long int j = 0; j < s.size(); j++ ) {

      long long int b = k[ j % k.size() ];
      if ( b >= 26 ) {
	b -= 26;
	if ( s[j] >= 'a' && s[j] <= 'z' ) {
	  s[j] += 'A' - 'a';
	}else {
	  s[j] += 'a' - 'A';
	}
      }
      if ( s[j] >= 'a' && s[j] <= 'z' ) {
	s[j] -= b;
	if ( s[j] < 'a' ) {
	  s[j] += 26;
	  s[j] += 'A' - 'a';
	}
      }else {
	s[j] -= b;
	if ( s[j] < 'A' ) {
	  s[j] += 26;
	  s[j] += 'a' - 'A';
	}
      }

    }

    cout << s << endl;

  }

  return 0;

}

#include<iostream>
#include<queue>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	int n,m,dt;
	while(1){
		cin>>n>>m;
		if(!(n&&m))break;
		priority_queue<int> que;
		rep(i,n){cin>>dt;que.push(dt);}
		int cnt=0,sum=0;
		while(!que.empty()){
			cnt++;
			if(cnt!=m)sum+=que.top();
			else cnt=0;
			que.pop();
		}
		cout<<sum<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1000000007;
const ld PI = acos(-1);
const ld EPS = 0.0000000001;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define rep(i, n) for(ll i=0; i<(ll)(n); i++)
#define repd(i, n) for(ll i=n-1; 0<=i; i--)
#define FOR(i, a, b) for(ll i=a; i<(ll)(b); i++)
#define FORD(i, a, b) for(ll i=b-1; (ll)(a)<=i; i--)
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
string YES[2] = {"NO", "YES"};
string yes[2] = {"No", "Yes"};

int main(){
    ll n;   cin >> n;
    vector<ll> a(n);
    rep(i, n)   cin >> a[i];
    vector<ll> csum(n+1, 0);
    rep(i, n)   csum[i+1] = (csum[i]+a[i])%MOD;
    ll res=0;
    rep(i, n){
        res += (a[i]*((csum[n]-csum[i+1]+MOD)%MOD))%MOD;
        res %= MOD;
    }
    cout << res << endl;
}


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

int main() {
    int a, b;
    cin >> a >> b;

    int sum = 1, cnt = 0;
    while(sum < b) {
        sum += a-1;
        cnt++;
    }

    cout << cnt << endl;

    return 0;
}

#include<iostream>
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <sstream>
#include <vector>

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

int main() {
	int a, b,i=0;
	cin >> a >> b;
	while (1) {
		if (a * i - i + 1 >= b) {
			cout << i << endl;
			return 0;
		}
		i++;
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define erep(i,a,n) for(int i = a;i<=n;i++)
typedef long long ll;
#define int long long
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>:
#define vbool vector<bool>
#define INF 1101010101010101010
#define MOD 1000000007
#define P pair<int,int>
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

const int MAXN = 1010;
const int MAXV = MAXN*(MAXN-1)/2;

vint to[MAXV];
int id[MAXN][MAXN];

bool visited[MAXV];
int dp[MAXV];
bool calculated[MAXV];

int dfs(int a){
  if(visited[a]){
    if(!calculated[a]){
      return -1;
    }
    return dp[a];
  }
  visited[a] = true;
  dp[a] = 1;
  for(int p:to[a]){
    int u = dfs(p);
    if(u == -1){
      return -1;
    }
    dp[a] = max(dp[a],u+1);
  }
  calculated[a] = true;
  return dp[a];
}

int toID(int a,int b){
  if(a < b) swap(a,b);
  return id[a][b];
}

signed main(){
  int n;
  cin >> n;
  vvint A(n,vint(n-1));
  rep(i,0,n){
    rep(j,0,n-1){
      cin >> A[i][j];
      A[i][j]--;
    }
  }
  int v = 0;
  rep(i,0,n){
    rep(j,0,n){
      if(i > j){
        id[i][j] = v;
        v++;
      }
    }
  }
  rep(i,0,n){
    rep(j,0,n-1){
      A[i][j] = toID(i,A[i][j]);
    }
  }
  rep(i,0,n){
    rep(j,0,n-2){
      to[A[i][j+1]].push_back(A[i][j]);
    }
  }
  int ans = 0;
  rep(i,0,v){
    int res = dfs(i);
    if(res == -1){
      cout << -1 << endl;
      return 0;
    }
    ans = max(ans,res);
  }
  cout << ans << endl;
}

#include<bits/stdc++.h>

using namespace std;

#define int long long
#define ALL(x) (x).begin(),(x).end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

typedef pair<int,int> PI;
typedef pair<int,pair<int,int>> PII;
static const int INF=1010000000000000017LL;
static const double eps=1e-12;
static const double pi=3.14159265358979323846;
static const int dx[4]={1,-1,0,0};
static const int dy[4]={0,0,1,-1};
static const int ddx[8]={1,-1,0,0,1,1,-1,-1};
static const int ddy[8]={0,0,1,-1,1,-1,1,-1};

template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}

int N;
int A[200005],B[200005];
int C[200005],D[200005];

signed main(){
    cin>>N;
    for(int i=0;i<N;++i)cin>>A[i];
    for(int i=0;i<N;++i)cin>>B[i];
    for(int i=0;i<N;++i){
        C[A[i]]++;
        D[B[i]]++;
    }
    int ma=0;
    for(int i=1;i<=N;++i){
        if(C[i]+D[i]>N){
            cout<<"No\n";
            return 0;
        }
        C[i]+=C[i-1];
        D[i]+=D[i-1];
        chmax(ma,C[i]-D[i-1]);
    }
    cout<<"Yes\n";
    for(int i=0;i<N;++i){
        cout<<B[(i-ma+N)%N];
        if(i!=N-1)cout<<" ";
    }
    cout<<"\n";
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const long long INF=INT_MAX/4;
const long long MOD=998244353;
const double EPS=1e-14;
const bool DEBUG=false;

const string YES = "YES";
const string NO = "NO";
const string Yes = "Yes";
const string No = "No";

template<class T>
void debug(T head){
    if(DEBUG){
        cout<<head<<endl;
    }
}

template <class Head, class... Body>
void debug(Head head, Body... body){
    if(DEBUG){
        cout<<head<<" ";
        debug(body...);
    }
}

/////
void answer(ll sx, ll sy, ll tx, ll ty){
    for(int i=sy; i<ty; ++i){
        cout<<"U";
    }
    for(int i=sx; i<tx; ++i){
        cout<<"R";
    }
    for(int i=sy; i<ty; ++i){
        cout<<"D";
    }
    for(int i=sx; i<tx; ++i){
        cout<<"L";
    }

    cout<<"L";
    for(int i=sy; i<ty+1; ++i){
        cout<<"U";
    }
    for(int i=sx; i<tx+1; ++i){
        cout<<"R";
    }
    cout<<"D";

    cout<<"R";
    for(int i=sy; i<ty+1; ++i){
        cout<<"D";
    }
    for(int i=sx; i<tx+1; ++i){
        cout<<"L";
    }
    cout<<"U";
    cout<<endl;

    return;
}

/////

int main(int argc, char* argv[]){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout.precision(16);

    ll sx, sy, tx, ty;
    cin>>sx>>sy>>tx>>ty;
    answer(sx, sy, tx, ty);

    return 0;
}

#pragma GCC optimize("O3")

#include<bits/stdc++.h>
#define sp " "
#define endl "\n"
#define MAX 10e9
#define MAXN 100001
#define mod 1000000007
#define inf_int 2e9
#define inf_ll 2e18
#define e 1e-9
#define vi vector<int>
#define vl vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpl vector<pair<ll,ll>>
#define vpc vector<pair<char,char>>
#define adj_list vector<vl>
#define umap unordered_map<ll, ll>
#define pll pair<ll,pair<ll, ll>>
#define clr(x) memset(x,0,sizeof(x))
#define cy cout << "YES" << endl
#define cn cout << "NO" << endl
#define google cout << "Case #" << ++it << ": " << ans << endl;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
typedef long long int ll;

ll it = 0, ans = 0;

ll spf[MAXN];
void sieve()
{
    spf[1] = 1;
    for (auto i=2; i<MAXN; i++)
  		spf[i] = i;
  	for (auto i=4; i<MAXN; i+=2)
        spf[i] = 2;
    for (auto i=3; i*i<MAXN; i++)
    {
        if (spf[i] == i)
        {
            for (auto j=i*i; j<MAXN; j+=i)
                if (spf[j]==j)
                    spf[j] = i;
        }
    }
	return;
}

vl getFactorization(ll x)
{
    vl ret;
    while (x != 1)
    {
        ret.push_back(spf[x]);
        x = x / spf[x];
    }
    return ret;
}

void check()
{
	ll x,y,z;
	cin >> x >> y >> z;
	cout << z << sp << x << sp << y;
    return ;
}

int32_t main()
{
    fastio
    ll t = 1;
    // cin >> t;
    while(t--)
        check();
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	long long int a,b;
	cin>>a>>b;
	long long int ans=max(a,b);
	if(a>=b){
		a--;
		if(a>0&&a>=b){
			cout<<ans+a;
		}
		else{
			cout<<ans+b;
		}
	}
	else{
		b--;
		if(b>0&&b>=a){
			cout<<ans+b;
		}
		else{
			cout<<ans+a;
		}
	}
	return 0;
}

#include <iostream>
using namespace std;

int main()
{
  int a, b, ans = 0;
  cin >> a >> b;
  ans += max(a , b);
  if(a == b) ans += max(a, b);
  else ans += ans - 1;

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


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
template<class T>bool chmax(T &a, const T &b) {
  if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) {
  if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる

//—————————————————BFSグラフ————————————————

using Graph = vector<vector<pair<ll,ll>>>;

int main() {
    // 頂点数と辺数
    ll n;
    cin >> n;

    // グラフ入力受取
    Graph G(n);
    rep(i,n-1) {
        ll a,b,c;
        cin >> a >> b >> c;
        auto x=mp(b-1,c);
        G[a-1].pb(x);
        auto y=mp(a-1,c);
        G[b-1].pb(y);
    }

    ll q,k;
    cin>>q>>k;
    k--;

    // BFS のためのデータ構造
    vector<ll> dist(n, 1000000000000000000); // 全頂点を「未訪問」に初期化
    deque<ll> que;

    // 初期条件 (頂点 0 を初期ノードとする)
    dist[k] = 0;
    que.pb(k); // 0 を橙色頂点にする

    // BFS 開始 (キューが空になるまで探索を行う)
    while (!que.empty()) {
        ll v = que.front(); // キューから先頭頂点を取り出す
        que.pop_front();

        // v から辿れる頂点をすべて調べる
        for (auto nv : G[v]) {
            // 新たな白色頂点 nv について距離情報を更新してキューに追加する
            if(dist[nv.fi]>dist[v] + nv.se){
            dist[nv.fi] = dist[v] + nv.se;
            que.pb(nv.fi);
            }
        }
    }

  rep(i,q){
    ll x,y;
    cin>>x>>y;
    cout << dist[x-1]+dist[y-1] << endl;
  }

}

    #include<iostream>
    #include<cstdio>
    #include<vector>
    #include<cmath>
    #include<cstring>
    #include<fstream>
    #include<algorithm>
    using namespace std;
    typedef long long LL;
    const int INF=0x3f3f3f3f;
    const int MAXN=1e5+5;
    int tot,head[MAXN];
    LL dist[MAXN];
    bool vis[MAXN];

    struct Edge
    {
        int from,to,nxt;
        LL cost;
    }e[MAXN*2];

    void addedge(int u,int v,int w)
    {
        e[tot].from=u;
        e[tot].to=v;
        e[tot].cost=w;
        e[tot].nxt=head[u];
        head[u]=tot++;
    }

    void dfs(int u,int fa)
    {
        for(int i=head[u];i!=-1;i=e[i].nxt)
        {
            int to=e[i].to;
            if(to==fa) continue;
            dist[to]=dist[u]+e[i].cost;
            dfs(to,u);
        }
    }

    int main()
    {
        int n;
        while(scanf("%d",&n)!=EOF)
        {
            tot=0;
            memset(head,-1,sizeof(head));
            memset(dist,0,sizeof(dist));
            int u,v;
            LL w;
            for(int i=1;i<=n-1;i++)
            {
                scanf("%d%d%lld",&u,&v,&w);
                addedge(u,v,w);
                addedge(v,u,w);
            }
            int q,k;
            scanf("%d%d",&q,&k);
            dfs(k,-1);
    //        for(int i=1;i<=n;i++)
    //            cout<<dist[i]<<" ";
    //        cout<<endl;
            int x,y;
            for(int i=1;i<=q;i++)
            {
                scanf("%d%d",&x,&y);
                printf("%lld\n",dist[x]+dist[y]);
            }
        }
        return 0;
    }


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

int main() {
    ll x; cin >> x;
    ll nokori = x % 11;
    ll ans = (x-nokori) / 11;
    ans *= 2;
    if(nokori > 6){
        ans += 2;
    } else if(nokori > 0) {
        ans++;
    }

    cout << ans << endl;

    return 0;
}

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

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

  if(N[0] == '7' || N[1] == '7' || N[2] == '7')
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
}


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

#define REP(i,m,n) for(int i=(m); i<(int)(n); i++)
#define RREP(i,m,n) for(int i=(int)(n-1); i>=m; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define fi first
#define se second
#define debug(...) {cerr<<"[L"<<__LINE__<<"] "; _debug(__VA_ARGS__);}

template<typename T>
string join(const vector<T>&v, string del=", "){ stringstream s;
    for(auto x : v) s << del << x; return s.str().substr(del.size());
}
template<typename T>
ostream& operator<<(ostream& o, const vector<T>&v){
    if(v.size()) o << "[" << join(v) << "]"; return o;
}
template<typename T>
ostream& operator<<(ostream& o, const vector<vector<T> >&vv){
    int l = vv.size();
    if(l){ o<<endl; rep(i,l) o << (i==0 ? "[ " : ",\n  " ) << vv[i] << (i==l-1 ? " ]" : ""); }
    return o;
}
template<typename T1, typename T2>
ostream& operator<<(ostream& o, const pair<T1, T2>& p){
    return o << "(" << p.first << ", " << p.second << ")";
}
inline void _debug(){cerr<<endl;}
template<class First, class... Rest>
void _debug(const First& first, const Rest&... rest){cerr<<first<<" ";_debug(rest...);}

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

const double PI = (1*acos(0.0));
const double EPS = 1e-9;
const int INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const ll mod = 1e9 + 7;

inline void finput(string filename) {
    freopen(filename.c_str(), "r", stdin);
}

int main(){
    ios_base::sync_with_stdio(0);
    // finput("./input");
    int n; cin >> n;
    vl a(n);
    rep(i,n) cin >> a[i];
    sort(all(a));

    for(int i=0; i<n-1; i+=2){
        if(a[i]+a[i+1] < 0){
            a[i] = -a[i];
            a[i+1] = -a[i+1];
        }
    }
    ll ans = accumulate(all(a), 0ll);
    cout << ans << endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vchar = vector<char>;
using vvchar = vector<vchar>;
using vp = vector<P>;
using vpp = vector<pair<P, P>>;
using vvp = vector<vp>;

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
istream &operator>>(istream &is, P &a)
{
    return is >> a.first >> a.second;
}
ostream &operator<<(ostream &os, const P &a) { return os << "(" << a.first << "," << a.second << ")"; }

template <typename T>

void view(const std::vector<T> &v)
{
#ifndef ONLINE_JUDGE
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
#endif
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion

int main()
{
    int n;
    cin >> n;
    vll a(n);
    rep(i, n) cin >> a[i];
    vll neg;
    ll ans = 0;
    rep(i, n)
    {
        if (a[i] <= 0)
        {
            neg.emplace_back(abs(a[i]));
        }
        ans += abs(a[i]);
    }
    int k = neg.size();

    if (k % 2)
    {
        ll sml = 10000000000;
        rep(i, n) sml = min(sml, abs(a[i]));
        ans -= sml * 2;
    }
    cout << ans << endl;

    return 0;
}


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

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

int main(){
    int D, G;
    cin >> D >> G;
    vector<pii> points;
    rep(i, 0, D){
        int p, c;
        cin >> p >> c;
        points.push_back(make_pair(p, c));
    }
    int ans = INF;
    rep(i, 0, 1<<D){
        ll score = 0;
        int cnt = 0;
        int last, prob;
        rep(j, 0, D){
            if ((i>>j)&1){
                score += points[j].first * (j+1) * 100 + points[j].second;
                cnt += points[j].first;
            }
            else{
                last = j;
                prob = points[j].first;
            }
        }
        while (score < G && prob > 1){
            score += (last+1) * 100;
            cnt++;
            prob--;
        }
        if (score >= G){
            ans = min(ans, cnt);
        }
    }
    cout << ans << endl;
}

#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

int N, M;
vector<int> G[1005];
vector<int> ret;

bool is_valid(const vector<int>& path){
  map<int,int> visited;
  rep(i,path.size()){
    visited[path[i]] = 1;
  }

  vector<int> in(1005, 0);
  rep(i,path.size()){
    int x = path[i];
    rep(j,G[x].size()){
      if(visited[G[x][j]] == 1){
        in[G[x][j]]++;
      }
    }
  }

  rep(i,path.size()){
    int x = path[i];
    if(in[x] > 1) return false;
  }
  return true;
}

void solve(int st){
  vector<int> path;

  vector<int> parent(1005, -1);
  parent[st] = st;
  queue<int> que;
  que.push(st);
  while(!que.empty()){
    int v = que.front(); que.pop();
    rep(i,G[v].size()){
      if(G[v][i] == st){
        int x = v;
        while(x != st){
          path.push_back(x);
          x = parent[x];
        }
        path.push_back(st);
        if(!is_valid(path)) return;
        break;
      }else{
        if(parent[G[v][i]] != -1){
        }else{
          parent[G[v][i]] = v;
          que.push(G[v][i]);
        }
      }
      if(path.size() > 0) break;
    }
  }

  if(path.size() == 0) return;
  if(ret.size() == 0 || path.size() < ret.size()){
    ret = path;
  }
}

int main(){
  cin >> N >> M;
  rep(i,M){
    int a, b;
    cin >> a >> b;
    G[a].push_back(b);
  }

  REP(i,1,N+1){
    solve(i);
  }

  if(ret.size() == 0) cout << -1 << endl;
  else {
    cout << ret.size() << endl;
    rep(i,ret.size()){
      cout << ret[i] << endl;
    }
  }
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
  long long A,B,M;
  cin>>A>>B>>M;
  vector<int> a(A);
  for(int i=0;i<A;i++)
    cin>>a.at(i);
  vector<int> b(B);
  for(int i=0;i<B;i++)
    cin>>b.at(i);
  vector<vector<int>> c(M,vector<int>(3));
  for(int i=0;i<M;i++){
    for(int j=0;j<3;j++)
      cin>>c.at(i).at(j);
  }
  long long min=a.at(0)+b.at(0);
  for(int i=0;i<M;i++){
    if(a.at(c.at(i).at(0)-1)+b.at(c.at(i).at(1)-1)-c.at(i).at(2)<min)
      min=a.at(c.at(i).at(0)-1)+b.at(c.at(i).at(1)-1)-c.at(i).at(2);
  }
  sort(a.begin(),a.end());
  sort(b.begin(),b.end());
  if(a.at(0)+b.at(0)<min)
    min=a.at(0)+b.at(0);
  cout<<min<<endl;

}

#include <stdio.h>
#include <vector>
#include <algorithm>

using namespace std;

int main(void)
{
	vector<int> twoThrow;
	int n;
	int m;
	int point[1000];
	int ans;

	while (1){
		twoThrow.clear();

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

		if (n == 0){
			break;
		}

		for (int i = 0; i < n; i++){
			scanf("%d", &point[i]);
		}

		twoThrow.push_back(0);
		for (int i = 0; i < n; i++){
			twoThrow.push_back(point[i]);
			for (int j = i; j < n; j++){
				twoThrow.push_back(point[i] + point[j]);
			}
		}
		sort(twoThrow.begin(), twoThrow.end());

		int t;
		ans = 0;
		for (int i = 0; i < twoThrow.size(); i++){
			vector<int>::iterator it = upper_bound(twoThrow.begin(), twoThrow.end(), m - twoThrow[i]);
			if (it == twoThrow.begin()){
				continue;
			}
			it--;
			t = *it;
			if (ans < t + twoThrow[i]){
				ans = t + twoThrow[i];
			}
		}

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

	return (0);
}


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

int x[10],y[10];
int n;

double f(int i, int j) {
  double dx = x[i] - x[j];
  double dy = y[i] - y[j];
  return pow(dx*dx+dy*dy,0.5);
}

int main() {
  cin >> n;
  rep(i,n) cin >> x[i] >> y[i];

  std::vector<int> v(n);
  rep(i,n) v.at(i) = i;

  double total = 0.0;
  do {
    rep(i,n-1) total += f(v[i],v[i+1]);
  } while(next_permutation(v.begin(), v.end()));

  int num = 1;
  for (int i = 2; i <= n; i++) num *= i;
  cout << std::fixed << std::setprecision(16) << total / num << endl;
}

#include "bits/stdc++.h"
#define ff first
#define ss second
#define szof(_x) ((int) (_x).size())
#define TASK_NAME ""

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9 + 7;
const ll INFL = 1e18 + 123;
const double PI = atan2(0, -1);
mt19937 tw(960172);
ll rnd(ll x, ll y) { static uniform_int_distribution<ll> d; return d(tw) % (y - x + 1) + x; }

void solve() {
	int n, s;
	cin >> n >> s;
	set<pair<int, ll>> all;
	for (int i = 0; i < n; ++i) {
		int x, p;
		cin >> x >> p;
		all.insert({x, p});
	}

	ll ans = 0;
	int fl = -1;
	while (true) {
		if (all.begin()->ff > s) {
			ans += (--all.end())->ff - s;
			break;
		}
		if ((--all.end())->ff < s) {
			ans += s - all.begin()->ff;
			break;
		}

		if ((all.begin())->ss < (--all.end())->ss) {
			auto tmp = *all.begin();
			all.erase(all.begin());
			auto tmp2 = *--all.end();
			all.erase(--all.end());
			if (fl != 1) {
				ans += tmp2.ff - tmp.ff;
				fl = 1;
			}
			tmp2.ss += tmp.ss;
			all.insert(tmp2);
		} else {
			auto tmp = *all.begin();
			all.erase(all.begin());
			auto tmp2 = *--all.end();
			all.erase(--all.end());
			if (fl != 2) {
				ans += tmp2.ff - tmp.ff;
				fl = 2;
			}
			tmp.ss += tmp2.ss;
			all.insert(tmp);
		}
		//cerr << ans << endl;
	}

	cout << ans << "\n";
}

int main() {
	//freopen(TASK_NAME ".in", "r", stdin);
	//freopen(TASK_NAME ".out", "w", stdout);
	cerr << fixed << setprecision(15);
	cout << fixed << setprecision(15);
	ios::sync_with_stdio(false);

	int tests = 1;
	// cin >> tests;
	for (int it = 1; it <= tests; ++it) {
		solve();
	}

	#ifdef LOCAL
		cerr << "time: " << clock() << " ms\n";
	#endif
	return 0;
}


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

typedef pair<int, int> pii;
typedef long long ll;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

#ifdef LOCAL
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define dump(x) true
#endif

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template<class T, class U> void chmin(T& t, const U& u) { if (t > u) t = u; }
template<class T, class U> void chmax(T& t, const U& u) { if (t < u) t = u; }

template<class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	os<<"{";
	rep(i, v.size()) {
		if (i) os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

ll dp[6010][6010];

int main() {
	int N; ll M;
	cin >> N >> M;
	int n = N * 3;

	dp[0][0] = 1;
	for (int i = 1; i <= n; ++i) {
		if (i >= 3) {
			for (int j = 0; j <= n; ++j) {
				(dp[i][j+1] += dp[i-3][j] * (i-1) % M * (i-2)) %= M;
			}
		}
		if (i >= 2) {
			for (int j = 0; j <= n; ++j) {
				(dp[i][j+1] += dp[i-2][j] * (i-1)) %= M;
			}
		}
		for (int j = 0; j <= n; ++j) {
			(dp[i][j] += dp[i-1][j]) %= M;
		}
	}
	ll ans = 0;
	for (int i = 0; i <= N; ++i) {
		ans = (ans + dp[n][i]) % M;
	}
	cout << ans << endl;
	return 0;
}

#include "bits/stdc++.h"

typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++)
#define REP(i,n) for(int i = 0;i < (n) ; i++)
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
using namespace std;
#define N 1010
int MOD = 1000000007;
int fac[N+1];
int inv[N+1];
ll bitpow(ll x,ll n){
    ll ans = 1;
    while(n > 0){
        if(n%2 == 1) ans = ans * x % MOD;
        x = x * x %MOD;
        n = n >> 1;
    }
    return ans;
}
ll COM(ll n,ll k){
    return fac[n]*inv[k]%MOD*inv[n-k]%MOD;
}
int dp[1010][1010] = {0};
signed main(){
    int n,a,b,c,d;
    cin >> n >> a >> b >> c >> d;
    fac[0] = 1;
    inv[0] = 1;
    for(int i = 1;i <= N;i++){
        fac[i] = fac[i-1]*i%MOD;
        inv[i] = bitpow(fac[i],MOD-2)%MOD;
    }
    dp[a-1][0] = 1;
    for(int i = a;i <= b;i++){
        for(int j = 0;j <= n;j++){
            dp[i][j] = dp[i-1][j];
            for(int k = c;k <= d;k++){
                if(j-i*k < 0 || i*k > n)break;
                dp[i][j] += dp[i-1][j-i*k] * fac[n-(j-i*k)] %MOD * inv[n-(j-i*k) - i*k] %MOD * inv[k]%MOD * bitpow(inv[i],k)%MOD;
                dp[i][j] %= MOD;
                // if(i == 3){
                //     //cerr << "j : dp[i-1][j-i*k] : fac[n-(j-i*k)] : inv[n-i*k] : inv[k] : bitpow(inv[i],k)" << endl;
                //     //cerr << j << " " << dp[i-1][j-i*k] <<  " : " << fac[n-(j-i*k)]<<  " : "<< inv[n-i*k] <<  " : "<<  inv[k] <<  " : "<<  bitpow(inv[i],k);
                //     //cerr << endl;
                //  }
            }
        }
    }
    cout << dp[b][n] << endl;

    return 0;
}

// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl https://yahoo-procon2019-qual.contest.atcoder.jp/tasks/yahoo_procon2019_qual_d
// rm -r -f test;oj dl http://arc067.contest.atcoder.jp/tasks/arc067_c


#include <bits/stdc++.h>
// #include <atcoder/all>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, n) for (ll i = 1; i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
// using namespace atcoder;
void Main()
{
    ll n;
    cin >> n;
    vector<ll> A(n);
    rep(i, n) cin >> A[i];

    ll pow2 = 1;
    ll sum = 0;
    ll mod = 7LL + 1e9;
    rep(_i, 61) {
        ll one = 0, zero = 0;
        rep(i, n) {
            ll v = A[i] % 2;
            if (v == 1) one++;
            else zero++;
            A[i] /= 2;
        }

        sum += (one * zero % mod) * pow2 % mod;
        sum %= mod;

        pow2 *= 2;
        pow2 %= mod;
    }

    put(sum);
}
signed main(){ Main();return 0;}

// /*
// "Won't stop until I'm phenomenal."
// - Phenomenal, Eminem
//  */
// #include<bits/stdc++.h>
// using namespace std;
// typedef long long int ll;
// #define ff first
// #define Shazam ios_base::sync_with_stdio(false);   cin.tie(NULL); cout.tie(NULL);
// #define ss second
// #define all(c) c.begin(),c.end()
// #define endl "\n"
// #define test() int t; cin>>t; while(t--)
// #define fl(i,a,b) for(int i = a ; i <b ;i++)
// #define get(a) fl(i,0,a.size())  cin>>a[i];
// #define pra(a) fl(i,0,a.size()) cout<<a[i]<<" ";	cout<<endl;
// #define pr(a,n) fl(i,0,n) cout<<a[i]<<" ";	cout<<endl;
// const ll INF = 2e18;
// const int inf = 2e9;
// const int mod1 = 1e9 + 7;

// int main(){
//     Shazam;
//     int n; cin>>n;
//     vector<ll> a(n);
//     for(ll &i : a)
//         cin>>i;
//     vector<vector<int>> table(63, vector<int> (n));
//     for(int bit = 0; bit < 63; bit++){
//         for(int i = 0 ; i < n; i++){
//             table[bit][i] = ((a[i]&(1LL<<bit)) > 0);
//         }
//     }
//     auto add = [&](ll &a, ll b){
//         a = (a + b)%mod1;
//     };
//     ll ans = 0;
//     for(int bit = 0; bit < 63; bit++){
//         ll x = count(table[bit].begin(), table[bit].end(),0);
//         ll y = n - x;
//         add(ans, (1LL<<bit)%mod1*y%mod1*x%mod1);
//     }
//     cout<<ans<<endl;
//     return 0;
// }
/*
"Won't stop until I'm phenomenal."
- Phenomenal, Eminem
 */
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define ff first
#define Shazam ios_base::sync_with_stdio(false);   cin.tie(NULL); cout.tie(NULL);
#define ss second
#define all(c) c.begin(),c.end()
#define endl "\n"
#define test() int t; cin>>t; while(t--)
#define fl(i,a,b) for(int i = a ; i <b ;i++)
#define get(a) fl(i,0,a.size())  cin>>a[i];
#define pra(a) fl(i,0,a.size()) cout<<a[i]<<" ";	cout<<endl;
#define pr(a,n) fl(i,0,n) cout<<a[i]<<" ";	cout<<endl;
const ll INF = 2e18;
const int inf = 2e9;
const int mod1 = 1e9 + 7;

int main(){
    Shazam;
    int n; cin>>n;
    vector<ll> a(n);
    for(ll &i : a)
        cin>>i;
    vector<vector<int>> table(61, vector<int> (n));
    for(int bit = 0; bit < 61; bit++){
        for(int i = 0 ; i < n; i++){
            table[bit][i] = ((a[i]&(1LL<<bit)) > 0);
            if(i)
                table[bit][i]+=table[bit][i-1];
        }
    }
    auto add = [&](ll &a, ll b){
        a = (a + b)%mod1;
    };
    ll ans = 0;
    for(int bit = 0; bit < 61; bit++){
        for(int i = 0; i < n-1; i++){
            if(!(a[i]&(1LL<<bit)))
                add(ans, (table[bit][n-1]-table[bit][i-1])*((1LL<<bit)%mod1)%mod1);
            else
                add(ans, (n- i   - (table[bit][n-1]-table[bit][i-1]))*((1LL<<bit)%mod1)%mod1);
        }
    }
    cout<<ans<<endl;
    return 0;
}


#include<iostream>
int main(){
	int x,n=1;
	std::cin>>x;
	for(int i=0;i<3;++i){
		n=n*x;
	}
	std::cout<<n<<std::endl;
}

#include <iostream>
using namespace std;

int main(void)
{
     int input;
     int output;

     cin >> input;

     output = input * input * input;

     cout << output << endl;

     return 0;
}


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

int main(void){
	int a,b,c;

	while(cin>>a>>b>>c && (a||b||c)){
		int i,n;
		cin>>n;

		int res[a+b+c+1];
		int tmp[n][3];
		fill(res,res+a+b+c+1,2);

		for(i=0;i<n;i++){
			int I,J,K,R;
			cin>>I>>J>>K>>R;
			if(R == 1){
				res[I] = res[J] = res[K] = 1;
				i--;
				n--;
			}
			else{
				tmp[i][0] = I;
				tmp[i][1] = J;
				tmp[i][2] = K;
			}
		}
		int size = i;
		for(i=0;i<size;i++){
			if(res[tmp[i][0]] == 1 && res[tmp[i][1]] == 1) res[tmp[i][2]] = 0;
			else if(res[tmp[i][0]] == 1 && res[tmp[i][2]] == 1) res[tmp[i][1]] = 0;
			else if(res[tmp[i][1]] == 1 && res[tmp[i][2]] == 1) res[tmp[i][0]] = 0;
		}
		for(i=1;i<=a+b+c;i++){
			cout<<res[i]<<endl;
		}
	}

	return 0;
}

#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
const ll INF = 1LL<<32;;
int n,m;
ll dis[300][300];
int main()
{
    cin >> n >> m;
        int i,j,k;
        for(i = 0;i < n;i++)
            for(j = 0;j < n;j++)
			{
				if(i == j)
					dis[i][j] = 0;
				else
                    dis[i][j] = INF;
			}
        while(m--)
        {
            int a,b,c;
            cin >> a >> b >> c;
			dis[a][b] = c;
        }
        for(k = 0 ; k<n ; k++){
        for(i = 0 ; i<n ; i++){
            if(dis[i][k] == INF)
                continue;
            for(j = 0 ; j<n ; j++){
                if(dis[k][j] == INF)
                    continue;
                dis[i][j] = min(dis[i][j] , dis[i][k]+dis[k][j]);
            }
        }
    }
    bool flag = 0;
    for( i = 0 ; i<n ; i++)
    {
        if(dis[i][i] < 0)
        {
            flag = 1;
            break;
        }
    }
        if(flag == 1)
            cout << "NEGATIVE CYCLE" << endl;
        else
        {
        for(i = 0;i < n;i++)
        {
            for(j = 0;j < n;j++)
            {
                if(j == n-1)
                {
                    if(dis[i][j] == INF)
                        cout << "INF";
                    else
                        cout << dis[i][j];
                }
                else
                {
                    if(dis[i][j] == INF)
                        cout << "INF ";
                    else
                        cout << dis[i][j] << ' ';
                }
            }
            cout << endl;
        }
        }
    return 0;
}


#include <iostream>

using namespace std;

int main(){
    int n,h,w;
    cin>>n>>h>>w;
    int count = (n-h+1)*(n-w+1);
    cout<<count<<endl;
    return 0;
}

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

int main() {

    int64_t n,w,h;
    cin>>n>>h>>w;

    int cnt=0;
    for(int i=1;i<=n;i++){
      for(int j=1;j<=n;j++){
        if(n-i+1>=h&&n-j+1>=w)
          cnt++;
      }
    }

    cout<<cnt<<endl;

	return 0;
}


#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define _ << ' ' <<
using namespace std;
using ll = long long;

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    if (c > min(a, b) && c < max(a, b))
        cout << "Yes";
    else
        cout << "No";
}

/*
      author  : nishi5451
      created : 14.08.2020 21:24:46
*/

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

const int INF = 2020202020;

int main(){
    int n,m,x,y;
    cin >> n >> m >> x >> y;
    int l = x, r = y;
    rep(i,n){
        int a;
        cin >> a;
        l = max(l,a);
    }
    rep(i,m){
        int a;
        cin >> a;
        r = min(r,a);
    }
    if(r-l >= 1) cout << "No War" << endl;
    else cout << "War" << endl;

    return 0;
}


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

using namespace std;

size_t ldistance(string s, string t) {
    /* Levenshtein Distance */
    size_t slen=s.length(), tlen=t.length();
    vector<vector<size_t>> dp(slen+1, vector<size_t>(tlen+1));

    for (size_t i=0; i<=slen; ++i)
        dp[i][0] = i;

    for (size_t j=0; j<=tlen; ++j)
        dp[0][j] = j;

    for (size_t i=1; i<=slen; ++i)
        for (size_t j=1; j<=tlen; ++j) {
            size_t cost=(s[i-1]!=t[j-1]);
            dp[i][j] = min(min(dp[i-1][j], dp[i][j-1])+1, dp[i-1][j-1]+cost);
        }

    return dp[slen][tlen];
}

int main() {
    char buf[1024];
    scanf("%s", buf);
    string s1(buf);

    scanf("%s", buf);
    string s2(buf);

    printf("%zu\n", ldistance(s1, s2));
    return 0;
}


#include <iostream>
#include <stdio.h>
using namespace std;

int main() {
	int n,p;//~50
	int stone,player[50]={};
	int winner;
	int i;

	scanf("%d%d",&n,&p);
	while(1){
	for(i=0;i<50;i++){
		player[i]=0;
	}
	stone=p;
	for(i=0;;i++){
		if(stone==0){
			stone=player[i%n];
			player[i%n]=0;
		}
		else{
			stone-=1;
			player[i%n]+=1;
		}
		if((stone==0)&&(player[i%n]==p)){
			winner=i%n;
			break;
		}
	}
	printf("%d\n",winner);
	scanf("%d%d",&n,&p);
	if((n==0)&&(p==0)){break;}
	}
	return 0;
}

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int MAXN = 200100;

int N;
string s;
int ans[MAXN];

bool wolo()
{
    for (int i = 1; i <= N + 1; i++)
    {
        int av = 0;
        if (s[i] == 'x') av = 1;
        ans[i+1] = (av + ans[i] + ans[i-1]) % 2;
        if (i + 1 >= N && ans[i+1] != ans[i+1-N]) return false;
    }
    return true;
}

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

    cin >> N >> s;
    s += s;

    for (int i = 0; i < 4; i++)
    {
        ans[0] = i % 2;
        ans[1] = i / 2;

        if (wolo())
        {
            for (int j = 0; j < N; j++)
            {
                if (ans[j]) cout << 'W';
                else cout << 'S';
            }
            cout << "\n";
            return 0;
        }
    }
    cout << "-1\n";
}