#include <cstdio>
#include <cctype>
#include <utility>
#include <vector>
#include <algorithm>
using namespace std;

#define gcu getchar_unlocked
#define pcu putchar_unlocked
#define _T template <typename T>
#define _HT template <typename H, typename... T>
#define _il inline
#define _in _il int in
#define _sc _il bool scan
_T T in(int c){T n=0;bool m=false;while(isspace(c)){c=gcu();}if(c=='-')m=true,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m?-n:n;}
_in() {return in<int>(gcu());}
_T T scan(T &n){int c=gcu();return c==EOF?false:(n=in<T>(c),true);}
_sc(char &c){c=gcu();gcu();return c!=EOF;}
#ifdef _GLIBCXX_STRING
_sc(string &s){int c;s="";
	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
#endif
_HT _sc(H &h, T&&... t){return scan(h)&&scan(t...);}
#define _vo _il void out
#define _vl _il void outl
_vo(bool b) {pcu('0'+b);}
_vo(const char *s){while(*s)pcu(*s++);}
_vo(char c){pcu(c);}
#ifdef _GLIBCXX_STRING
_vo(string s){for(char c:s)pcu(c);}
#endif
_T _vo(T n){static char buf[20];char *p=buf;
	if(n<0)pcu('-'),n*=-1;if(!n)*p++='0';else while(n)*p++=n%10+'0',n/=10;
	while (p!=buf)pcu(*--p);}
_vl(){out('\n');}
#ifdef _GLIBCXX_VECTOR
_T _vo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);outl();}
#endif
_HT _vo(H&& h, T&&... t){out(h);out(move(t)...);}
template <typename... T> _vl(T&&... t){out(move(t)...);outl();}

int main() {
	for (int n, m; n = in(), m = in();) {
		vector<int> v(n);
		for (int &x: v)
			x = in();
		sort(v.rbegin(), v.rend());
		int p = 0;
		for (int i = 0; i < n; i++)
			if ((i + 1) % m)
				p += v[i];
		outl(p);
	}
}

#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <unordered_set>
#include <vector>
#include <list>
#include <string>
#include <iterator>
#include <deque>
#include <array>
#include <forward_list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <climits>
#include <bitset>
#include <numeric>
using namespace std;

const long double PI = 3.14159265358979323846264338327950;
const double EPS = 1e-9;
const int N = 1000000;

template <class T> T gcd(T a, T b) {
	if (b == 0) { return a; }
	return gcd(b, a % b);
}

template <class T> bool isPrime(T x) {
	for (T d = 2; d * d <= x; d++) { if (x % d == 0) return false; }
	return true;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	int n, m;
	unordered_map<int, int> mp;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> m;
		++mp[m];
	}

	int ans = 0;
	for (auto it = mp.begin(); it != mp.end(); ++it) {
		if ((it->second) & 1) ++ans;
	}

	cout << ans << '\n';
}


//http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2676345#1
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<map>
#include<cstdio>
#include<fstream>
#include<cstring>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define P pair<int,int>
#define ll __int64

int n,k;
int f,to,from,cost;
const int INF=222222222;

vector<P> G[1000];//first→終点 second→cost
int dist[1000];//頂点iへの最小距離

int keiro(int from,int to){
	for(int i=0;i<=n;i++)dist[i]=INF;
	//dist[from]=0;
	priority_queue<P,vector<P>,greater<P> >bfs;//first→頂点へのコスト second→頂点

	bfs.push(mp(0,from));

	while(!bfs.empty()){
		P now=bfs.top();
		bfs.pop();

		int index=now.second,ncost=now.first;

		if(dist[index]!=INF)continue;
		//cout<<index<<" "<<ncost<<endl;
		dist[index]=ncost;

		for(int i=0;i<G[index].size();i++){

			bfs.push(mp(ncost+G[index][i].second,G[index][i].first));
			//cout<<G[index][i].first<<" "<<G[index][i].second<<endl;
		}
	}

//rep(i,n+1)cout<<dist[i]<<" ";
	if(dist[to]==INF)return -1;
	return dist[to];
}
int main(){
while(cin>>n>>k,n||k){
for(int i=0;i<200;i++)G[i].clear();

for(int i=0;i<k;i++){
	cin>>f;
	if(!f){
		cin>>from>>to;
		cout<<keiro(from,to)<<endl;
	}
	else{
		cin>>from>>to>>cost;
		G[from].push_back(mp(to,cost));
		G[to].push_back(mp(from,cost));
	}
}
}
	return 0;
}

#include <bits/stdc++.h>

using namespace std;
typedef long long int LL;
typedef long long int ll;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SP << " " <<

LL mod = 1000000007;

template <typename M>
class lazy_segment_tree {
	using T1 = typename M::t1;
	using T2 = typename M::t2;
	const int n;
	vector<T1> data;
	vector<T2> lazy;
	int size(int n) {
		int res = 1;
		while (res < n) res <<= 1;
		return res;
	}
	void push(int node) {
		if (lazy[node] == M::id2()) return;
		if (node < n) {
			lazy[node * 2] = M::op3(lazy[node * 2], lazy[node]);
			lazy[node * 2 + 1] = M::op3(lazy[node * 2 + 1], lazy[node]);
		}
		data[node] = M::op2(data[node], lazy[node]);
		lazy[node] = M::id2();
	}
	void suc(int l, int r, int node, int lb, int ub, T2 val) {
		if (ub <= l || r <= lb) return;
		if (l <= lb && ub <= r) {
			lazy[node] = M::op3(lazy[node], val);
			return;
		}
		push(node);
		int c = (lb + ub) / 2;
		suc(l, r, node * 2, lb, c, val);
		suc(l, r, node * 2 + 1, c, ub, val);
		data[node] = M::op1(M::op2(data[node * 2], lazy[node * 2]), M::op2(data[node * 2 + 1], lazy[node * 2 + 1]));
	}
	T1 sub(int l, int r, int node, int lb, int ub) {
		if (ub <= l || r <= lb) return M::id1();
		if (l <= lb && ub <= r) return M::op2(data[node], lazy[node]);
		int c = (lb + ub) / 2;
		return M::op2(M::op1(sub(l, r, node * 2, lb, c), sub(l, r, node * 2 + 1, c, ub)), lazy[node]);
	}
public:
	lazy_segment_tree(int n_) : n(size(n_)), data(n * 2, M::id1()), lazy(n * 2, M::id2()) {}
	lazy_segment_tree(int n_, T1 v1) : n(size(n_)), data(n * 2, v1), lazy(n * 2, M::id2()) {}
	lazy_segment_tree(const vector<T1>& data_) : n(size(data_.size())), data(n * 2, M::id1()), lazy(n * 2, M::id2()) {
		init(data_);
	}
	void init() {
		for (int i = n - 1; i >= 1; i--) data[i] = M::op1(data[i * 2], data[i * 2 + 1]);
	}
	void init(const vector<T1>& data_) {
		for (int i = 0; i < (int)data_.size(); i++) data[i + n] = data_[i];
		init();
	}
	void update(int l, int r, T2 val) {
		suc(l, r + 1, 1, 0, n, val);
	}
	T1 find(int l, int r) {
		return sub(l, r + 1, 1, 0, n);
	}
};

struct RURM {
	using t1 = int;
	using t2 = int;
	static t1 id1() { return INT_MAX; }
	static t2 id2() { return -1; }
	static t1 op1(const t1& l, const t1& r) { return min(l, r); }
	static t1 op2(const t1& l, const t2& r) { return r != id2() ? r : l; }
	static t2 op3(const t2& l, const t2& r) { return r != id2() ? r : l; }
};

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

  LL N,Q;
  cin >> N >> Q;

	lazy_segment_tree<RURM> seg(N);
	seg.init();

	REP(i,Q){
		LL y;
		cin >> y;
		if(y==0){
			LL s, t, x;
			cin >> s >> t >> x;
			seg.update(s, t, x);
		}
		else
		{
			LL s;
			cin >> s;
			cout << seg.find(s, s) << endl;
		}
	}
}


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

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

  string s;
  map<string, int> S;
  for (int i=0; i<N; i++) {
    cin >> s;
    if (S.count(s)) S.at(s) += 1;
    else S[s] = 1;
  }

  int M;
  cin >> M;
  for (int i=0; i<M; i++) {
    cin >> s;
    if (S.count(s)) S.at(s) -= 1;
  }

  using pis = pair<int, string>;
  priority_queue<pis> cnt;
  for (auto x : S) {  // 要素はキーと値のpair
    cnt.push(pair(x.second, x.first));
  }

  if (cnt.top().first < 0) cout << 0 << endl;
  else cout << cnt.top().first << endl;

  return 0;
}

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

using str = string;
using ss = stringstream;

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

    int n,m;
    cin>>n;

    map<str,int> a,b;

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

        a[s]++;
    }

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

        b[s]++;
    }

    int ans=0;

    for(auto const& aa:a)
    {
        int cnt=aa.second-b[aa.first];
        if(cnt>0)ans=max(ans,cnt);
    }

    cout<<ans<<"\n";

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define ll long long
const int Max=1e6+7;
ll a[Max]; int n,k;

int main(){
    ios::sync_with_stdio(0);
    scanf("%d%d",&n,&k);
    for(int i=1; i<=n; i++) scanf("%lld",&a[i]);
    ll ans=0;
    //cout<<"OK"<<endl;
    if(a[1]>=0) ans=a[k];
    else if(a[n]<=0) ans=-a[n-k+1];
    else{
        int index=0;
        for(int i=1; i<=n; i++){
            if(a[i]>=0) {
                index=i; break;
            }
        }

        ans=0x3f3f3f3f;
        for(int i=index; i<index+k && i<=n; i++){
            ll tot=abs(a[i]);

            if(i-index+1<k){
               tot+=abs(a[i]);
               if(i-k+1>=1){
                    tot+=abs(a[i-k+1]);
                    //cout<<tot<<endl;
                    ans=min(tot,ans);
               }
            }else{
                //cout<<tot<<endl;
                ans=min(tot,ans);
            }
        }
        index--;
        for(int i=index; i>=1 && i>=index-k+1; i--){
            ll tot=abs(a[i]);
            if(index-i+1<k){
                tot+=abs(a[i]);
                if(k+i-1<=n){
                    tot+=abs(a[k+i-1]);
                    ans=min(ans,tot);
                }
            }
            else{
                ans=min(ans,tot);
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

#define _GLIBCXX_DEBUG

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

//loops
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define OneToN(i,n) for(ll i=1;i<(ll)(n+1);i++)
#define ZeroToN(i,n) for(ll i=0;i<(ll)(n+1);i++)
#define AToB(i,a,b) for(ll i=a;i<(ll)(b+1);i++)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)

//bitsearch
#define BITSEARCH(bit, n) for (int bit = 0; bit < (1<<n); ++bit)
#define isOne(bit, i) bit & (1<<i)

//arrays
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define add push_back

template<typename T>
std::vector<T> slice(std::vector<T> const &v, int m, int n)
{
    auto first = v.cbegin() + m;
    auto last = v.cbegin() + n + 1;

    std::vector<T> vec(first, last);
    return vec;
}

//v need to be sorted
#define remove_unique(v) v.erase(unique(ALL(v)), v.end())

//comparision
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 (a>b) { a=b; return 1; } return 0; }

//pair
#define fir first
#define sec second
#define mp make_pair

//types
#define ll long long
#define vec vector
#define cord2d pair<int,int>
#define intP pair<int, int>

//UNCOMMENT WHEN NEEDED
//#define int ll

//input
template <class T> T get(){ T s; cin >> s; return(s);}
#define gi get<int>()
#define gs get<string>()
#define gll get<ll>()

template <class T> vector<T> getv(int n) { vec<T> v(n); REP(i, n) cin >> v[i]; return v; }
#define gim(n) getv<int>(n)
#define gsm(n) getv<string>(n)
#define gllm(n) getv<ll>(n)

//output
void print(int a){ cout << a << endl; }
void print(long long a){ cout << std::fixed << a << endl; }
void print(string a){ cout << a << endl; }
void print(char a){ cout << a << endl; }
void print(double a){ cout << a << endl; }
void print(double a, int dig){ cout << std::setprecision(dig) << a << endl; }

template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

template <class T = int>
void print(vec<T> v){ cout << v << endl; }

template <class T = int>
void print2dVec(vec<vec<T>> v2d){for(vec<T> v: v2d) {print(v);}}

void YesNo1(bool i = true){ return print(i?"Yes":"No"); }
void YESNO2(bool i = true){ return print(i?"YES":"NO"); }

//debug output
#define var_name(var) #var
template <class T> void debug(T &var, int nest = 0, string before = "") { cout << string("          ", nest) << before; print(var); }

//name replacement
#define y0 y0__
#define y1 y1__
#define j0 j0__
#define j1 j1__

//bool lambdas
#define lamb(exp) [](auto i){return exp;}
#define isEven [](int i){return i % 2 == 0;}
#define isOdd [](int i){return i % 2 != 0;}

//constants
const ll INF = 1e18;
const int MOD = 1000000007;
const vec<string> alphabets = { "a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z" };

//maths
int factorial(int k){ int sum = 1; for (int i = 1; i <= k; ++i) { sum *= i; } return sum; }

ll gcd(ll a, ll b) { if (b == 0) { return a; } return gcd(b, a % b); }
ll lcm(ll a, ll b) { ll temp = gcd(a, b); return temp ? (a / temp * b) : 0; }

////////////////////

void Main() {
    //code here

    int n = gi, k = gi;
    vec<int> nums = gim(n);

    int minDif = INT_MAX;

    REP(i, n-k+1) {
        int l = i;
        int r = l+k-1;
        int dif = min(abs(nums[r]), abs(nums[l])) + abs(nums[l]-nums[r]);
        chmin(minDif, dif);
    }
    print(minDif);
}

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Main();
}


#include <iostream>
using namespace std ;
long long  b[102][102]  , v , e ;
int main() {
	cin >> v >> e ;
	for(int i=1 ; i<=v ; i++) {
		for(int j=1 ; j<=v ; j++) {
			if(i==j) {
				b[i][j]=0;
			}
			else {
				b[i][j]=1e18 ;
			}
		}
	}
	for(int i= 0 ; i < e ; i++) {
		int x , y , z  ;
		cin >> x >> y >> z ;
		b[x+1][y+1]=z;
	}
	for(int x=1 ; x<=v ; x++) {
		for(int y=1 ; y<=v ; y++) {
			for(int z=1; z<=v ; z++) {
				b[y][z]=min(b[y][z],b[y][x]+b[x][z]);
				if(y==z) {
					if(b[y][z]<0) {
						cout << "NEGATIVE CYCLE" << endl ;
						return 0 ;
					}
				}
			}
		}
	}
	for(int i=1 ; i<=v ; i++) {
		for(int j=1 ; j<=v ; j++) {
			if(j != 1) {
				if(b[i][j]>2e9) {
					cout<< " INF";
				}
				else {
					cout << " "<<b[i][j] ;
				}
			}
			else {
				if(b[i][j]>2e9) {
					cout<< "INF";
				}
				else {
					cout << b[i][j] ;
				}
			}
		}
		cout << endl ;
	}

}

# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include<time.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>
#include<fstream>
//#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
long long MOD = 1000000000 + 7;// 998244353;// ;
constexpr long long INF = numeric_limits<LL>::max() / 2;
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
struct Fll { LL first, second, third, fourd; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Rrep(i,mf) for(LL i=mf-1;i>=0;i--)
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}
struct Edge { LL to, cost; };
struct edge { LL from, to, cost; };
vector<vector<LL>>g;
vector<edge>edges;
vector<LL>v;
map<LL, LL>ma;
set<Pll>st;
LL h, w, n, m, k, t, s, p, q, last, cnt, sum, ans, dp[210000],a[210000], b[210000];
string str, ss;
bool f;
char c;
vector<LL> kossaraju(vector<vector<LL>>&g) {
	LL n = g.size();
	vector<vector<LL>>rev(n);
	vector<LL>ret(n);
	vector<LL>ver;
	vector<bool>used(n);
	function<void(LL)>dfs1 = [&](LL cur) {
		used[cur] = 1;
		rep(i, g[cur].size()) {
			if (!used[g[cur][i]])
				dfs1(g[cur][i]);
		}
		ver.push_back(cur);
	};
	function<void(LL, LL)>dfs2 = [&](LL cur, LL root) {
		used[cur] = 1;
		ret[cur] = root;
		rep(i, rev[cur].size()) {
			if (!used[rev[cur][i]])
				dfs2(rev[cur][i], root);
		}
	};
	rep(i, n) rep(j, g[i].size()) rev[g[i][j]].push_back(i);
	rep(i, n) if (!used[i])dfs1(i);
	rep(i, n) used[i] = 0;
	Rrep(i, n)if (!used[ver[i]])dfs2(ver[i], ver[i]);
	return ret;
}
int main() {
	cin >> n>>m;
	g.resize(n);
	rep(i, m) {
		LL x, y;
		cin >> x >> y;
		g[x].push_back(y);
	}
	vector<LL>V = kossaraju(g);
	cin >> q;
	rep(i, q) {
		LL x, y;
		cin >> x >> y;
		if (V[x] == V[y])cout << 1 << endl;
		else cout << 0 << endl;
	}
	return 0;
}


#include <stdio.h>
#define MAX 100000
using namespace std;

void swap(int A[], int index1, int index2) {
    int temp;
    temp = A[index1];
    A[index1] = A[index2];
    A[index2] = temp;
}

int partition(int A[], int p, int r) {
    int x = A[r];
    int i = p -1;
    for(int j = p; j <= r-1; j++) {
        if(A[j] <= x) {
            i = i + 1;
            swap(A, i, j);
        }
    }
    swap(A, i+1, r);
    return i+1;
}

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

    int index = partition(A, 0, n-1);
    for(int i = 0; i < n; i++) {
        if(i == index)
            printf("[%d]", A[i]);
        else
            printf("%d", A[i]);
        if(i != n-1) printf(" ");
    }
    printf("\n");
    return 0;
}

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

int main(){
    int N, K;
    cin >> N >> K;
    vector<float> p(N);
    for(int i=0; i<N; i++) cin >> p.at(i);
    for(int i=0; i<N; i++) p.at(i) = (p.at(i) + 1) / 2;
    vector<double> q(N);
    q.at(0) = p.at(0);
    for(int i=1; i<N; i++) q.at(i) = q.at(i-1) + p.at(i);
    vector<double> r(N - K + 1);
    r.at(0) = q.at(K-1);
    for(int i=1; i<N-K+1; i++){
        r.at(i) = q.at(i+K-1) - q.at(i-1);
    }
    double max = 0;
    for(int i=0; i<N-K+1; i++){
        if(max < r.at(i)) max = r.at(i);
    }
    cout << fixed << setprecision(12);
    cout << max << endl;
}


#include <bits/stdc++.h>

#define rep(i,n) for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

using namespace std;
using ll  = long long;
using pll = pair<ll, ll>;

const ll MOD  = 1e9 + 7;
const ll LINF = 1LL << 62;
const int INF = 1e9 + 7;

ll Gcd(ll a,ll b){
    if(a < b)swap(a, b);

	if(a%b == 0)return(b);

	else return(Gcd(b, a%b));
}

vector<pll> Factor(ll n){
    vector<pll> prime;
    ll sq = sqrt(n) + 1;

    for(int i = 2; i <= sq; ++i){
        sq = sqrt(n) + 1;
        if(n%i == 0){
            prime.push_back(make_pair(i, 0));
            while(n%i == 0){
                n /= i;
                prime[prime.size()-1].second++;
            }
        }
    }

    if(n != 1){
        prime.push_back(make_pair(n, 1));
    }

    return prime;
}

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

    vector<pll> fac = Factor(Gcd(a, b));

    cout << fac.size() + 1 << endl;
}

/*

https://www.cnblogs.com/SovietPower/p/9757375.html
*/
#include <cstdio>
#include <algorithm>
#define mod 998244353
const int N=1e6;

int fac[N+3],ifac[N+3];

inline int FP(int x,int k)
{
	int t=1;
	for(; k; k>>=1,x=1ll*x*x%mod)
		if(k&1) t=1ll*t*x%mod;
	return t;
}
#define C(n,m) (1ll*fac[n+m]*ifac[n]%mod*ifac[m]%mod)//C(n+m,n)

int main()
{
	int n,m; scanf("%d%d",&n,&m);
	if(n<m) std::swap(n,m);

	int lim=n+m; fac[0]=fac[1]=1;
	for(int i=1; i<=lim; ++i) fac[i]=1ll*fac[i-1]*i%mod;
	ifac[lim]=FP(fac[lim],mod-2);
	for(int i=lim; i; --i) ifac[i-1]=1ll*ifac[i]*i%mod;

	long long ans=0;
	for(int i=1; i<=m; ++i) ans+=1ll*C(i,i)*C(n-i,m-i)%mod;
	ans=ans%mod*FP(C(n,m),mod-2)%mod*FP(2,mod-2)%mod;
	printf("%lld\n",(ans+n)%mod);

	return 0;
}


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

int clue();
int result();
void show();
bool check(int n) {
    for(int i=2;i*i<=n;++i) {
        if(n%i==0)
        return false;
    }
    return true;
}

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

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

int main() {

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

    return 0;
}
int clue() {

    string s;
    cin>>s;
    int cnt;
    if(s=="SUN") {
        cnt=7;
    }
    elif(s=="MON") {
        cnt=6;
    }
    elif(s=="TUE") {
        cnt=5;
    }
    elif(s=="WED") {
        cnt=4;
    }
    elif(s=="THU") {
        cnt=3;
    }
    elif(s=="FRI") {
        cnt=2;
    }
    elif(s=="SAT") {
        cnt=1;
    }

    cout<<cnt<<endl;

    // ()?cout<<"1"<<endl:cout<<"0"<<endl;

    return 0;
}

#include <algorithm>
// #include <cstdlib>
#include <cstring>
#include <cstdio>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <map>
// #include <bitset>
const int oo=2139063143;
const int N=310;
const int P=1000000007;
using namespace std;
typedef long long LL;
typedef double db;
#define pritnf printf
//char buf[1<<22],*p1=buf,*p2=buf,obuf[1<<22],*O=obuf;
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
template <typename T>
inline void sc (T &x)
{
    x=0; static int p; p=1; static char c; c=getchar();
    while (!isdigit(c)) { if (c=='-') p=-1; c=getchar(); }
    while ( isdigit(c)) { x=(x<<1)+(x<<3)+(c-48); c=getchar(); }
    x*=p;
}
template <typename T>
inline void print (T x)
{
	if (x< 0) putchar('-'),x=-x;
	if (x>=10) print(x/10);
	putchar(x%10+'0');
}
template <typename T>
inline void pr (T x) { print(x),putchar('\n'); }
void chkmax (int &A,int B) { A=A>=B?A:B; }
char s[N];
int f[N][N][N];
int main ()
{
	// freopen (".in","r",stdin);
	// freopen (".out","w",stdout);
	scanf ("%s",s+1);
	int n=strlen (s+1),k; sc(k);
	for (int i=1; i<=n; i++)
		f[i][i][0]=1;
	for (int len=2; len<=n; len++)
	{
		for (int l=1,r=len; r<=n; l++,r++)
		{
			for (int i=0; i<=k; i++)
			{
				f[l][r][i]=max (f[l+1][r][i],f[l][r-1][i]);
				if (s[l]==s[r]) chkmax (f[l][r][i],f[l+1][r-1][i]+2);
				if (i) chkmax (f[l][r][i],f[l+1][r-1][i-1]+2);
			}
		}
	}
	int ans=0;
	for (int i=0; i<=k; i++)
		chkmax (ans,f[1][n][i]);
	pr(ans);

	return 0;
}


#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

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

  int a,b;
  cin>>a>>b;

  if(a-b>0) cout<<a+a-1<<endl;
  else if(b-a>0) cout<<b+b-1<<endl;
  else cout<<a+b<<endl;

  return 0;
}

#include<iostream>
#include<math.h>
#include<bits/stdc++.h>
#define ll long long int
#define hell 1000000007LL
using namespace std;
ll power(ll x, ll y){
    if(y==0)
     return 1;
    else
    {
        ll p=power(x,y/2);
        if(y%2==0)
         return (p*p)%hell;
        else
        return (x*((p*p)%hell))%hell;
    }}
ll gcd(ll x,ll y)
{
    if(y==0)
     return x;
    else
    return gcd(y,x%y);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(20);
    ll a,b;
    cin>>a>>b;
    cout<<max(max(a+b,2*a-1),2*b-1);}


#include <bits/stdc++.h>
using namespace std;
int main(){
  int n; cin >> n;
  set<int> s;
  for(int i = 0; i < n; i++){
    //cout << s.size() << endl;
    int a; cin >> a;
    if(s.count(a))
       s.erase(a);
    else
       s.insert(a);
  }
  cout << s.size() << endl;
}

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main() {
  int n;
  cin >> n;
  vector<ll>a(n);
  ll sum=0;
  for(int i=0;i<n;++i) cin >> a[i];
  for(int i=0;i<n-1;++i) {
    if(a[i]>a[i+1]){
      sum+=a[i]-a[i+1];
      a[i+1]=a[i];
    }
  }
  cout << sum << endl;
  return 0;
}


#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
const int INF = (int)1e9 + 7;

int main() {
    int n; cin >> n;
    vector<int> a(n);
    int sum = 0;
    for (auto &ai: a) cin >> ai, sum += ai;
    pair<int, int> mi{INF, -1};
    for (int i = 0; i < n; i++) {
        mi = min(mi, {abs(a[i] * n - sum), i});
    }
    cout << mi.second << endl;
    return 0;
}

#include <iostream>
#include <map>
#include <string>

using namespace std;

class Dice {
	private:
		map<char, int> dice;

	public:
		Dice(int _I, int _II, int _III, int _IV, int _V, int _VI);
		int GetNumber(char c);
		void roll_E();
		void roll_N();
		void roll_S();
		void roll_W();
};

Dice::Dice(int _I, int _II, int _III, int _IV, int _V, int _VI) {
	dice['T'] = _I;
	dice['S'] = _II;
	dice['E'] = _III;
	dice['W'] = _IV;
	dice['N'] = _V;
	dice['B'] = _VI;
}

int Dice::GetNumber(char c) {
	return dice[c];
}

void Dice::roll_E() {
	map<char, int> tmp = dice;
	dice['T'] = tmp['W'];
	dice['E'] = tmp['T'];
	dice['W'] = tmp['B'];
	dice['B'] = tmp['E'];
}

void Dice::roll_N() {
	map<char, int> tmp = dice;
	dice['T'] = tmp['S'];
	dice['S'] = tmp['B'];
	dice['N'] = tmp['T'];
	dice['B'] = tmp['N'];
}

void Dice::roll_S() {
	map<char, int> tmp = dice;
	dice['T'] = tmp['N'];
	dice['S'] = tmp['T'];
	dice['N'] = tmp['B'];
	dice['B'] = tmp['S'];
}

void Dice::roll_W() {
	map<char, int> tmp = dice;
	dice['T'] = tmp['E'];
	dice['E'] = tmp['B'];
	dice['W'] = tmp['T'];
	dice['B'] = tmp['W'];
}

int main() {
	int I, II, III, IV, V, VI;
	cin >> I >> II >> III >> IV >> V >> VI;
	Dice dice(I, II, III, IV, V, VI);

	string op;
	cin >> op;
	for (unsigned int i = 0; i < op.size(); i++) {
		if (op[i] == 'E') {
			dice.roll_E();
		}
		if (op[i] == 'N') {
			dice.roll_N();
		}
		if (op[i] == 'S') {
			dice.roll_S();
		}
		if (op[i] == 'W') {
			dice.roll_W();
		}
	}
	cout << dice.GetNumber('T') << endl;
	// std::cout << "\e[38;5;0m\e[48;5;40m --- end ---  \e[m" << std::endl; // debug
	return 0;
}


#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const ll INF = 1LL<<60;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using Graph = vector<vector<int>>;

typedef pair<int, int> P;
typedef priority_queue<int, vector<int>, greater<int>> PQ;

int main(){
 int N, K; cin >> N >> K;
    int ans = 0;
    deque<int> deq;
    vector<int> v(N,0);
    rep(i,N){
        cin >> v[i];
    }
    // 左から取る個数
    for (int l = 0; l <= K; l++){
        // 右から取る個数
        for (int r = 0; r <= K; r++){
            // 取る回数がKを越した場合はNG
            if (l + r > K) continue;
            int d = K - l - r;
            priority_queue<int, vector<int>, greater<int>> tmp;
            // 左から取る
            rep(i,l){
                // dequeの右端に達した場合
                if (i >= N) break;
                tmp.push(v[i]);
            }
            // 右から取る
            rep(i,r){
                int index = N-1-i;
                // dequeの左端もしくはすでに左から取られている場合
                if (index < 0 || index <= l) break;
                tmp.push(v[index]);
            }
            // 手から宝石をつめる
            rep(i,d){
                // 手に持っていない場合
                if (tmp.empty()) break;
                // 価値は正の場合はつめない
                if (tmp.top() >= 0) break;
                tmp.pop();
            }

            int now = 0;
            while (!tmp.empty()){
                now += tmp.top(); tmp.pop();
            }

            ans = max(now, ans);
        }
    }

    cout << ans << endl;
}

#include <iostream>
#include <iomanip>
#include <map>
#include <list>
#include <set>
#include <vector>
#include <utility>
#include <algorithm>
#include <queue>
#include <cstdint>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

constexpr ll inf = INT64_MAX / 4;
constexpr double pi = asin(1) * 2;
constexpr ll mod = 1000000007;

template<class T>
class set2 : public set<T> {
private:
    typename set<T>::iterator back_itr() {
        auto e = this->end();
        e--;
        return e;
    }

public:
    T front() {
        if (this->empty()) throw;
        return *this->begin();
    }

    T back() {
        if (this->empty()) throw;
        return *this->back_itr();
    }

    void erase_front() {
        if (!this->empty()) this->erase(this->begin());
    }

    void erase_back() {
        if (!this->empty()) this->erase(this->back_itr());
    }
};

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> a(n), b(m);
    for (auto &e:a) cin >> e;
    for (auto &e:b) cin >> e;
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    bool f = true;
    for (int i = 1; i < n; i++) if (a[i] == a[i - 1]) f = false;
    for (int i = 1; i < m; i++) if (b[i] == b[i - 1]) f = false;
    if (!f) {
        cout << 0 << endl;
        return 0;
    }
    auto in_r = [](vector<int> r, int e) { return binary_search(r.begin(), r.end(), e); };
    auto in_a = [&in_r, &a](int e) { return in_r(a, e); };
    auto in_b = [&in_r, &b](int e) { return in_r(b, e); };
    ll r = 1;
    for (int i = n * m; i > 0; i--) {
        if (in_a(i) && in_b(i)) {
            r *= 1;
        } else if (in_a(i)) {
            r *= b.end() - lower_bound(b.begin(), b.end(), i);
        } else if (in_b(i)) {
            r *= a.end() - lower_bound(a.begin(), a.end(), i);
        } else {
            r *= (a.end() - lower_bound(a.begin(), a.end(), i)) * (b.end() - lower_bound(b.begin(), b.end(), i)) -
                 (n * m - i);
        }
        r %= mod;
    }
    cout << r << endl;
}


#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>
// #include<ext/pb_ds/tag_and_trait.hpp>
// using namespace __gnu_pbds;
// #include<boost/multiprecision/cpp_int.hpp>
// namespace multiprecisioninteger = boost::multiprecision;
// using cint=multiprecisioninteger::cpp_int;
using namespace std;
using ll=long long;
#define double long double
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
// using llset=tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>;
#define For(i,a,b) for(i=a;i<(ll)b;++i)
#define bFor(i,b,a) for(i=b,--i;i>=(ll)a;--i)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N,0)
#define brep1(i,N) bFor(i,N,1)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define eb emplace_back
#define print(v) cout<<v<<endl
#define printyes cout<<"Yes"<<endl
#define printno cout<<"No"<<endl
#define printYES cout<<"YES"<<endl
#define printNO cout<<"NO"<<endl
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
#define matoutput(v) do{for(auto outimat:v)output(outimat);}while(0)
const ll mod=1000000007;
// const ll mod=998244353;
const ll inf=1LL<<60;
const double PI = acos(-1);
const double eps = 1e-9;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;}
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;}

void startupcpp(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
}

struct unionfind{
  private:
  int maxN;
  vector<int> par,treesize;
  public:unionfind(int N) :maxN(N),par(N),treesize(N,1){
    for(int i=0;i<maxN;++i)par[i]=i;
  }
  int root(int x){
    while(par[x]!=x){
      x=par[x]=par[par[x]];
    }
    return x;
  }
  bool unite(int x,int y){
    x=root(x);
    y=root(y);
    if(x==y)return false;
    if(treesize[x]>treesize[y])swap(x,y);
    par[x]=y;
    treesize[y]+=treesize[x];
    return true;
  }
  bool parcheck(int x,int y){
    return root(x)==root(y);
  }
  int size(int x){
    return treesize[root(x)];
  }
  void clear(){
    treesize.assign(maxN,1);
    for(int i=0;i<maxN;++i)par[i]=i;
  }
};

int main(){
  startupcpp();
  ll i,N,M,cnt=0,ans=0;
  cin>>N>>M;
  vector<int> a(M),b(M);
  map<int,int> mp;
  rep(i,M){
    cin>>a[i]>>b[i];
    mp[a[i]]+=mp[b[i]];
  }
  for(auto& x:mp)x.second=cnt++;
  ans=N*N-cnt*cnt;
  N=cnt;
  unionfind ut(N*2);
  rep(i,M){
    a[i]=mp[a[i]];
    b[i]=mp[b[i]];
    ut.unite(a[i],b[i]+N);
    ut.unite(a[i]+N,b[i]);
  }
  mp.clear();
  rep(i,N){
    mp[ut.root(i)]|=ut.parcheck(i,i+N);
  }
  cnt=0;
  for(auto& x:mp)cnt+=!x.second;
  print(ans+(mp.size()-cnt/2)*(mp.size()-cnt/2)+cnt*cnt/4);
}

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

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

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

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

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

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

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

	Would you please return 0;
}


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

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

  ll ans;
  for(int i = 1; i * i <= n; i++){
    ans = i*i;
  }

  cout << ans << endl;
}

#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
long long int power(int a,int b)
{
    if(b==0)
        return 1;
    long long int k=power(a,b/2);
    if(b%2==0)
        return ((k%M)*(k%M))%M;
    else
        return ((k%M)*(k%M)*(a%M))%M;
}
long long int fact(long long int n)
{
    if(n==1 || n==0)
        return 1;
    else
        return ((n%M)*(fact(n-1)%M))%M;

}
int div(int n)
{  int c=0;
    for(int i=1;i<sqrt(n);i++)
    {
        if(n%i==0)
        {
          c++;
        }
    }
    c=c*2;
    if(pow(sqrt(n),2)==(sqrt(n)*sqrt(n)))
        c++;
    return  c;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
     #ifndef ONLINE_JUDGE

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

   #endif
   int n;
   cin>>n;
   int s=sqrt(n);
   cout<<s*s;

 return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(int i=1;i<=n;i++)
const ll MOD = 1000000007;
long long modinv(long long a, long long m=MOD) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
    /*MODの割り算の際に
    a/＝b;
    を
    a *= modinv(b,MOD);
    とする。
        */
}
const int MAXN = 4001;

int main(){
    int N;string S;cin >> N >> S;
    ll count = 0;
    ll red=0,blue=0,green=0;
    for(int i=0;i<N;i++){
        if(S[i]=='R')red++;
        if(S[i]=='B')blue++;
        if(S[i]=='G')green++;
        for(int k=0;k<N;k++){
            int tmp_i = i+1;int tmp_k = k+1;
            int tmp_j = (tmp_i+tmp_k)/2;
            int j = tmp_j - 1;
            if(tmp_j <= N && tmp_i< tmp_j && tmp_j<tmp_k && tmp_j - tmp_i == tmp_k - tmp_j  && S[i]!=S[j] && S[j] != S[k] && S[i] != S[k]){
                count++;
            }
        }
    }
    ll tmp = red*blue*green;

    cout << tmp - count << endl;

    return 0;

}

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

int  main()
{
	int n; cin >> n;
	int a,b;
	switch (n)
	{
		case 1:
			cout << "Hello World\n";
			break;
		case 2:
			cin >> a >> b; cout << a+b << endl;
			break;
	}
	return (0);
}


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

int main(void) {
  ll n, t;
  cin >> n >> t;
  vector<ll> tv(n);
  rep(i, n) {
    cin >> tv[i];
  }

  ll ans = t;
  for (int i = 1; i < n; ++i) {
    ans += t;
    if (t > tv[i] - tv[i - 1]) ans = ans - t + tv[i] - tv[i - 1];
  }

  cout << ans << endl;

  return 0;
}

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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const llint INF = 1<<21;
// static const llint MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }

int main(void) {
    int n, t;
    cin >> n >> t;

    int ans = 0, tnow, tpush, tbfr;
    cin >> tbfr;
    for(int in=1;in<n;in++) {
        cin >> tpush;
        if(tpush-tbfr<=t) ans += tpush-tbfr;
        else ans += t;
        tbfr = tpush;
    }
    ans += t;
    cout << ans << endl;
    return 0;
}


#include <iostream>
using namespace std;

int gcd(int n, int m){
    if(n % m == 0) return m;
    return gcd(m, n % m);
}

int main()
{
    int n;
    cin >> n;
    int a[100005];
    for(int i = 0; i < n; i++) cin >> a[i];
    if(n == 1){
        cout << "Second" << endl;
        return 0;
    }
    if(n == 2){
        if(a[0] % 2 == a[1] % 2) cout << "Second" << endl;
        else cout << "First" << endl;
        return 0;
    }
    bool first = true;
    while(true){
        int m = 2;
        int l = 0;
        int c = 0;
        for(int i = 0; i < n; i++){
            m = min(m, a[i]);
            if(a[i] % 2) c++;
            else l = 1 - l;
        }
        if(l == 1){
            if(first) cout << "First" << endl;
            else cout << "Second" << endl;
            return 0;
        }
        else if(c > 1 || m == 1){
            if(first) cout << "Second" << endl;
            else cout << "First" << endl;
            return 0;
        }
        else{
            for(int i = 0; i < n; i++) a[i] = a[i] / 2 * 2;
            int g = 0;
            for(int i = 0; i < n; i++) g = gcd(g, a[i]);
            for(int i = 0; i < n; i++) a[i] /= g;
        }
        first = !first;
    }
}

#include <bits/stdc++.h>
#define lol long long
using namespace std;
int main(){
    int a,n,ans=1e9,b;
    string s,t;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a;
        b=0;
        while(a%2==0){
            b++;
            a/=2;
        }
        ans=min(b,ans);
    }
    cout<<ans<<"\n";
    return(0);
}


#include <bits/stdc++.h>

using namespace std;

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

const int N = 1010;

int h, w, a, b, mat[N][N];
ii arr[N];

bool can(int c1, int c2){
	for(int i=0 ; i<c2 ; i++)
		arr[i] = ii(b, i);
	for(int i=c2 ; i<w ; i++)
		arr[i] = ii(h-b, i);
	sort(arr, arr+w);
	memset(mat, 0, sizeof mat);
	for(int i=h-1 ; i>=0 ; i--){
		int cur = (i >= c1 ? w-a : a);
		for(int j=w-1 ; cur>0 && j>=0 ; j --, cur --){
			arr[j].first --;
			if(arr[j].first<0)
				return false;
			mat[i][ arr[j].second ] = 1;
		}
		sort(arr, arr+w);
	}
	for(int i=0 ; i<h ; i++){
		for(int j=0 ; j<w ; j++)
			cout << mat[i][j];
		cout << "\n";
	}
	return true;
}

signed main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	cin >> h >> w >> a >> b;
	for(int i=0 ; i<=h ; i++)
		for(int j=0 ; j<=w ; j++){
			int f1 = i*a + (h-i)*(w-a);
			int f2 = j*b + (w-j)*(h-b);
			if(f1 == f2 && can(i, j))
				return 0;
		}
	cout << "-1\n";
}

#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() {
  int h, w, a, b;
  cin >> h >> w >> a >> b;

  vector<vector<int>> s(h, vector<int>(w));
  rep(i, h) rep(j, w) {
    if (i < b && j < a || i >= b && j >= a) s[i][j] = 0;
    else s[i][j] = 1;
  }
  rep(i, h) {
    rep(j, w) cout << s[i][j];
    cout << endl;
  }
  return 0;
}


#include <bits/stdc++.h>
#define sz(arr) (int)(arr).size()
#define rng(arr) arr.begin(), arr.end()
#define show(x) cout << #x << " = " << x << endl;

using namespace std;
typedef long long int ll;

void _cin() {}
template <class Head, class... Tail>
void _cin(Head&& head, Tail&&... tail) {
  cin >> head;
  _cin(forward<Tail>(tail)...);
}

#define Cin(T, ...) \
  T __VA_ARGS__;    \
  _cin(__VA_ARGS__)

#define Cins(T, n, xs) \
  vector<T> xs(n);     \
  for (int i = 0; i < n; ++i) cin >> xs[i]

void Main();
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(15);
  Main();
  return 0;
}

void Main() {
  Cin(int, n);
  Cin(string, a, b, c);

  int ans = 0;
  for (int i = 0; i < n; ++i) {
    map<char, int> mp;
    mp[a[i]]++;
    mp[b[i]]++;
    mp[c[i]]++;

    int ma = 0;
    for (auto e : mp) ma = max(ma, e.second);
    ans += 3 - ma;
  }

  cout << ans << endl;
}

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

int main() {

	int n; cin >> n;
	string a, b, c; cin >> a >> b >> c;
	int ans = 0;
	for (int i = 0; i < n; i++) {
		if (a[i] != b[i] && b[i] != c[i] && c[i] != a[i]) {
			ans += 2;
		}
		else if ((a[i] == b[i] && b[i] != c[i]) || (b[i] == c[i] && c[i] != a[i]) || (c[i] == a[i] && a[i] != b[i])) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define IO ios_base::sync_with_stdio(false)
int a[200000], vs[200000],vs1[100006],p[300000];
vector<int>v[200000];
queue<int>q;
int f(int n)
{
    int i, k=0;
    vs[n]=1; q.push(n);
    while(q.size()){
            n=q.front(); q.pop();
    for(i=0; i<v[n].size(); i++){
        if(vs1[v[n][i]]==1){
        p[v[n][i]]=n;
        q.push(v[n][i]);
    }
    else vs1[v[n][i]]--;
    }
    }
    return 1;
}
int main()
{
    IO;
    int i, j, m, k, n, t, l=0, mx,ll,mxx,mx1;
    cin>>n>>m;
    for(i=1; i<=n+m-1; i++){
        cin>>j>>k;
        v[j].push_back(k);
        vs1[k]++;
    }
    for(i=1; i<=n; i++)
        if(vs1[i]==0)k=i;
    f(k);
    for(i=1; i<=n; i++) cout<<p[i]<<endl;
    return 0;

}

#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ALL(v) (v).begin(),(v).end()

using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

const ll inf = 1e18;

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

    ll n;
    cin >> n;
    vll x(n);
    REP(i, n) cin >> x[i];
    ll l;
    cin >> l;

    // reach[k][i] : i から出発して 2^k 日で到達できる一番遠いホテル
    vvll reach(31, vll(n));

    REP(i, n){
        ll nxt = upper_bound(ALL(x), x[i] + l) - x.begin() - 1;
        reach[0][i] = nxt;
    }
    REP(k, 30){
        REP(i, n){
            reach[k + 1][i] = reach[k][reach[k][i]];
        }
    }
    ll q;
    cin >> q;
    ll a, b;
    while (q) {
        cin >> a >> b;
        a--, b--;
        if (a > b) swap(a, b);
        ll res = 1;
        REPR(k, 30){
            if (reach[k][a] < b) {
                res += (1 << k);
                a = reach[k][a];
            }
        }
        cout << res << endl;
        q--;
    }
    return 0;
}


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

using lint = long long;

template <class T>
T gcd(T a, T b) {
    while (b > 0) {
        a %= b;
        std::swap(a, b);
    }
    return a;
}

bool solve(int N, std::vector<lint>& A) {
    lint sum = std::accumulate(A.begin(), A.end(), 0LL);

    // Nが偶数の場合、和の偶奇がそのまま勝敗になる
    if (N % 2 == 0) return sum % 2 != 0;

    // Nが奇数の場合も、和が偶数なら絶対勝てる
    if (sum % 2 == 0) return true;

    // 奇数を前に持っていく
    std::sort(A.begin(), A.end(), [](int a, int b) { return a % 2 > b % 2; });
    // 奇数が複数個ある、あるいは唯一の奇数が1(減らせない)なら負け
    if (A[0] == 1 || (A[1] & 1) != 0) return false;

    // そうでなければ、唯一の奇数を減らしてシミュレート
    --A[0];
    int g = accumulate(A.begin(), A.end(), 0LL, gcd<lint>);  // 全体のgcdを取る
    for (auto& a : A) a /= g;
    return !solve(N, A);
}

int main() {
    int N;
    std::cin >> N;
    std::vector<lint> A(N);
    for (auto& a : A) std::cin >> a;

    std::cout << (solve(N, A) ? "First" : "Second") << std::endl;
    return 0;
}

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

const int MAXN = 1e5 + 6.66;
int arr [ MAXN ];
string player[2] = { "First","Second" };

int main ( ) {
  int n; scanf ( "%d",&n ) ;
  for ( int i = 0;i<n;i++ ) scanf ( "%d", arr + i ) ;
  int cnt[2] = { 0 , 0 };
  bool is_one = false;
  for ( int i = 0;i<n;i++ ) cnt[arr[i] % 2 ] ++,is_one |= (arr[i] == 1);
  if ( cnt[0] % 2 == 1 ) { printf ( "First\n" ); return 0; }
  bool turn = 0;
  while ( !is_one && cnt[1] == 1 )
  {
    for ( int i = 0;i<n;i++ ) if ( arr[i] % 2 ) arr[i] -- ;
    int gc = arr[0];
    for ( int i = 0;i<n;i++ ) gc = __gcd ( arr[i], gc );
    for ( int i = 0;i<n;i++ ) arr[i] /= gc;
    cnt[1] = cnt[0] = 0;
    for ( int i = 0;i<n;i++ ) cnt[arr[i] % 2 ] ++,is_one |= (arr[i] == 1);
    turn = !turn ;
  }
  if ( cnt[0] % 2 ) printf ( "%s\n", player[turn].c_str ( ) );
  else printf ( "%s\n", player[!turn].c_str ( ) );
  return 0;
}


#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"

int main() {
	while (1) {
		int N; cin >> N;
		if (!N)break;
		vector<int>as(N);
		vector<long long int>sums(N + 1);
		for (int i = 0; i < N; ++i)cin >> as[i];
		for (int i = 0; i < N; ++i) {
			sums[i + 1] = sums[i] + as[i];
		}
		long long int ans = -1e8;
		for (int l = 0; l < N; ++l) {
			for (int r = l + 1; r <= N; ++r) {
				ans = max(ans, sums[r] - sums[l]);
			}
		}
		cout << ans << endl;
	}

	return 0;
}

#include <iostream>
using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    while(cin>>n, n) {
        int now, max;
        cin>>now;
        max=now;
        for(int i=1; i<n; i++) {
            int t;
            cin>>t;
            if(now<=0) now=t;
            else now+=t;
            if(max<now) max=now;
        }
        cout<<max<<'\n';
    }
    return 0;
}


#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<vector>
#include<map>
using namespace std;
int main() {
    string a;
    string b;
    string c;
    cin >> a >> b >> c;
    char turn = a[0];
    a.erase(a.begin());
    if(a.empty()) {
        cout << 'A' << endl;
        return 0;
    }

    while(1){
        if(turn == 'a'){
            if(a.empty()) {
                cout << 'A' << endl;
                return 0;
            }
            turn = a[0];
            a.erase(a.begin());
        }

        if(turn == 'b'){
            if(b.empty()) {
                cout << 'B' << endl;
                return 0;
            }
            turn = b[0];
            b.erase(b.begin());
        }

        if(turn == 'c'){
            if(c.empty()) {
                cout << 'C' << endl;
                return 0;
            }
            turn = c[0];
            c.erase(c.begin());
        }
    }
    return 0;
}

#include<bits/stdc++.h>
#define ll long long int
#define endl '\n'
#define M 1000000007
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define f first
#define s second
#define b begin
#define e end
#define pb push_back
#define mp make_pair
#define FOR(i,a,b) for(i=a;i<b;i++)
#define RFOR(i,a,b) for(i=a;i>=b;i--)
#define all(x) x.begin(),x.end()
#define itfr(it,x) for(it=x.begin();it!=x.end();it++)
#define flash ios_base::sync_with_stdio(false); cin.tie(NULL)
using namespace std;

int main()
{
    flash;
    //sieve();
    ll T=1,n,m,k,x,y,z;
    // cin>>T;
    while(T--)
    {
        string a,b,c;
        cin>>a>>b>>c;
        n = a.length();
        m = b.length();
        k = c.length();
        x = 0; y = 0; z = 0;
        char cur = 'a';
        while(x<=n&&y<=m&&z<=k)
        {
            if(cur=='a')
            {
                cur = a[x];
                x++;
            }
            else if(cur=='b')
            {
                cur = b[y];
                y++;
            }
            else
            {
                cur = c[z];
                z++;
            }
        }
        if(x>n)
            cout<<'A';
        else if(y>m)
            cout<<'B';
        else
            cout<<'C';
        cout<<endl;
    }
}


#include <bits/stdc++.h>
#define rep(i, z, n) for(int i = z; i < n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
//const int INF = 1<<29;
//const int MODINF = 1000000007;
using namespace std;

int main(){
    int N;
    cin >> N;
    vector<int> A(N + 2, 0);
    int sum = 0;
    rep(i, 1, N + 1) cin >> A.at(i);
    rep(i, 0, N + 1) sum += abs(A.at(i + 1) - A.at(i));
    rep(i, 1, N + 1){
        int x = A.at(i - 1);
        int y = A.at(i);
        int z = A.at(i + 1);
        if ((x - y)*(y - z) >= 0){
            cout << sum << endl;
        }
        else{
            cout << sum - 2 * min(abs(x - y), abs(y - z)) << endl;
        }
    }
}

#include <bits/stdc++.h>
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)n; ++i)
const int MOD = 1000000007;
using namespace std;
void solve(void)
{
    int n;
    cin >> n;
    vector<int> a(n + 2);
    rep(i, n) cin >> a[i + 1];
    a[0] = 0, a[n + 1] = 0;
    int res = 0;
    rep(i, n + 1) res += abs(a[i] - a[i + 1]);
    rep(i, n)
    {
        int x = abs(a[i] - a[i + 1]) + abs(a[i + 1] - a[i + 2]);
        int y = abs(a[i] - a[i + 2]);
        cout << res - x + y << endl;
    }
}
int main(void)
{
    solve();
}


#include<iostream>
using namespace std;

int main(){
int N;
cin >> N;
int a[N];
for(int i = 0; i < N; i++){
cin >> a[i];
}

int min= a[0];
int max= a[0];
long long sum= a[0];

for(int i = 1; i < N; i++){
 sum += a[i];
 if(a[i] < min) min = a[i];
 if(a[i] > max) max = a[i];
}

cout << min << " " << max << " " << sum << endl;
}

#include<iostream>

int main(void){
	int n, min = 1000000, max = -1000000;
	long long sum = 0;

	std::cin >> n;
	if (n == 0) return 0;

	for (int i = 0; i < n; i++){
		int x;
		std::cin >> x;
		sum = sum + x;
		if (min > x) min = x;
		if (max < x) max = x;
	}

	std::cout << min << " " << max << " " <<  sum << std::endl;

	return 0;
}


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

#define Bye return 0
#define ll long long
const ll MAX = 1e2;

void solve(){
    string a, b, c; cin>>a>>b>>c;
    int size_a = a.size(), size_b = b.size();
    cout<<(a[size_a-1] == b[0] && b[size_b-1] == c[0] ?  "YES" : "NO")<<endl;
}

int main(){
    solve();
    Bye;
}


#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0;}

int main() {
    int n;
    cin >> n;
    vector<int>a(n+2);
    for(int i = 1;i<=n;i++) cin >> a[i];
    int s = 0;
    for(int i = 0;i<=n+1;i++) {
        s += abs(a[i]-a[i+1]);
    }
    for(int i = 1;i<=n;i++) {
        int tmp = abs(a[i-1]-a[i+1]) - abs(a[i-1] - a[i]) -abs(a[i]-a[i+1]);
        int ans = s + tmp;
        cout << ans << endl;
    }

}

/*
 * Author: .-O_O-.
 */
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include<bits/stdc++.h>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define rep0(a,b) for(int a=0;a<b;a++)
#define rep1(a,b) for(int a=1;a<=b;a++)
#define repp(a,b,c) for(int a=b;a<c;a++)
#define in insert
#define len length()
#define si size()
#define lb lower_bound
#define ub upper_bound
#define beg begin()
#define en end()
#define f first
#define s second
#define pr(a) cout<<a
#define pr2(a,b) cout<<a<<" "<<b<<"\n"
#define nx cout<<"\n"
#define int long long
// void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]"<<endl;}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif
const ll mod = 1000000007;
const ll N = 105;
const ll mm = 1e+18;
void solve()
{
    int n,aa,b;
    cin>>n>>aa>>b;
    int ans=0;
    int a[n];
    rep0(i,n) cin>>a[i];
    rep1(i,n-1){
        ans+=min((a[i]-a[i-1])*aa,b);
    }
    pr(ans);
}
signed main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
    //cin>>t;
    rep1(_i,t){
        //cout<<"Case #"<<_i<<": ";
        solve();
        //nx;
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define maxn 100010
using namespace std;
int n,l,q;
int a[maxn],tp[maxn][25];
void init(){
	int to=1;
	for(int t=1;t<=n;++t){
		while(to<n&&a[t]+l>=a[to+1])to++;
		tp[t][0]=to;
	}
	for(int t=n;t>=1;--t){
		for(int i=1;i<=20;++i){
			tp[t][i]=tp[tp[t][i-1]][i-1];
		}
	}
}
bool check(int a,int b,int k){
	int now=0;
	for(int t=20;t>=0;--t){
		if(now+(1<<t)<=k){
			now+=1<<t;
			a=tp[a][t];
		}
	}
	return a>=b;
}
int getans(int a,int b){
	int l=1,r=n,ans=n;
	while(l<=r){
		int mid=(l+r)>>1;
		if(check(a,b,mid)){
			ans=mid;
			r=mid-1;
		}
		else l=mid+1;
	}
	return ans;
}
int main(){
	scanf("%d",&n);
	for(int t=1;t<=n;++t)scanf("%d",&a[t]);
	scanf("%d%d",&l,&q);
	init();
	for(int t=1;t<=q;++t){
		int a,b;
		scanf("%d%d",&a,&b);
		if(a>b)swap(a,b);
		printf("%d\n",getans(a,b));
	}
}

#include <iostream>
#include <vector>

using namespace std;

void abc_150a();

void abc_151a();

void abc_152a();

void abc_154a();

void abc_156a();

int main()
{
  //abc_150a();
  //abc_151a();
  //abc_152a();
  //abc_154a();
  abc_156a();

}

void abc_150a()
{
  int K, X;
  cin >> K >> X;

  if (500 * K >= X) cout << "Yes\n";
  else cout << "No\n";
}

void abc_151a()
{
  char C;
  cin >> C;

  cout << (char)((int)C + 1) << "\n";
}

void abc_152a()
{
  int N, M;
  cin >> N >> M;
  if (N == M) cout << "Yes\n";
  else cout << "No\n";
}

void abc_154a()
{
  string S, T;
  cin >> S >> T;
  int a, b;
  cin >> a >> b;
  string U;
  cin >> U;

  if (S == U) cout << a - 1 << " " << b << "\n";
  else cout << a << " " << b - 1 << "\n";

}

void abc_156a()
{
  int N, R;
  cin >> N >> R;

  if (N >= 10) cout << R << "\n";
  else cout << R + 100 * (10 - N) << "\n";
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
#define PI 3.141592653589793

int main(){
   int n;
   cin >> n;
   VI a(n+2);
   a[0]=0;
   a[n+1]=0;
   for(int i=1;i<=n;i++){
      cin >> a.at(i);
   }
   ll ro=0;
   rep(i,n+2){
      ro+=abs(a[i]-a[i+1]);
   }
   for(int i=1;i<=n;i++){
      if((a[i]-a[i-1])*(a[i+1]-a[i])>=0){
         cout << ro << endl;
      }
      else{
         int z=min(abs(a[i]-a[i-1]),abs(a[i+1]-a[i]));
         cout << ro-2*z << endl;
      }
   }
}

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

//2^32/26 = 165191049.846153846153846 = 165191050
#define MAGIC 0x9D89D8A

char shift (char c, int amount)
{
    long n;
    long q ;
    long r;

    n = (long) c - 'a' +  amount;
    q = n * MAGIC;
    q >>= 32;
    r = n - q * 26;

    return (char) 'a' + r;
}

void shiftString (char* s, int amount)
{
    int i = 0;
    while (s[i]) {

        if (s[i] == ' ') {}
        else if (s[i] == '.') {}
        else { s[i] = shift(s[i], amount); }
        i++;
    }

}

int main(int argc, const char * argv[]) {

    char buffer[256];
    std::string line;
    std::vector<std::string> listString;
    int result = 0;
    std::size_t found;

    while (std::getline(std::cin, line))
    {
        //sprintf(buffer, "%s", line.c_str());
        listString.push_back(line);
    }

    std::vector<std::string>::iterator it;

    it = listString.begin();

    do {
        result = 0;
        sprintf(buffer, "%s", (*it).c_str());

        while (!result)
        {

            shiftString(buffer, -1);
            line = buffer;

            result = 0;

            found = line.find("the");
            result += found!=std::string::npos;

            found = line.find("this");
            result += found!=std::string::npos;

            found = line.find("that");
            result += found!=std::string::npos;

        }

        printf("%s\n", buffer);

    } while (++it < listString.end());

    return 0;
}


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

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

	int ans = 0;
	for (int i = a; i <= b; i++) {
		string a_tmp, b_tmp;
		string ch = to_string(i);
		for (int j = 0; j < ch.size(); j++) {
			a_tmp.push_back(char(ch[j]));
			b_tmp.push_back(char(ch[ch.size() - j-1]));
		}
		if (a_tmp == b_tmp)ans++;
	}
	cout << ans << endl;

	return 0;
}

//include
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <math.h>
#include <utility>
#include <functional>
#include <cstdlib>
//using
using namespace std;
using vl = vector <long long>;
using vs = vector <string>;
using vc = vector <char>;
using ll= long long;
using vvl = vector<vector<ll> >;
//vector<vector<char> > hyou(N, vector<char>(N));
using vd = vector <double>;
//define
//#define int long long
#define rep(i,n) for(int i=0; i<n; i++)
#define print(n) cout<<n<<endl;
#define sortp(d) sort(d.begin(),d.end()) //1234
#define sortm(d) sort(d.rbegin(),d.rend()) //4321
//素数判定　O(√A)
bool is_prime(int x){
 if(x<=1) return false;
 for(int i=2;i*i<=x;i++)
 if(x%i==0) return false;
 return true;
 }
/*順列生成
do {
  // 順列に対する処理
} while (next_permutation(配列変数.begin(), 配列変数.end()));*/

//絶対値　abs()
//文字→数字　'0' アルファベット→数字　'a'　'A'が65番,'a'が97番だわ
//型キャスト　char('a'+1)
//reverse 回文

//グローバル変数宣言
ll p=0,q=0,r=0;

int main()
{
  ll a,b;
  cin>>a>>b;
  //q=stoi(b);p=stoi(a);10000
  rep(i,b-a+1){
    p=a+i;
    if((p/10000==p%10)&&(p/1000-(10*(p/10000))==(p%100-p%10)/10))
    q++;

  }
  print(q)

}


#include <cstdio>
#include <cstdlib>

using namespace std;

const int mod = 998244353;

class inverse {
    public:
    inverse(int n, int mod);
    ~inverse();
    long long get_inv(int x);
    long long get_fact(int x);
    long long get_invfact(int x);
    long long get_comb(int x, int y);

    private:
    int mod;
    long long* inv;
    long long* fact;
    long long* invfact;
};

inverse::inverse(int n, int mod) : mod(mod) {
    inv = (long long *)malloc(sizeof(long long) * (n + 1));
    fact = (long long *)malloc(sizeof(long long) * (n + 1));
    invfact = (long long *)malloc(sizeof(long long) * (n + 1));
    inv[1] = 1;
    for (int i = 2; i <= n; i++) inv[i] = inv[mod % i] * (mod - mod / i) % mod;
    fact[0] = invfact[0] = 1;
    for (int i = 1; i <= n; i++) fact[i] = fact[i - 1] * i % mod;
    for (int i = 1; i <= n; i++) invfact[i] = invfact[i - 1] * inv[i] % mod;
}

inverse::~inverse() {
    free(inv);
    free(fact);
    free(invfact);
}

long long inverse::get_inv(int x) {
    return inv[x];
}

long long inverse::get_fact(int x) {
    return fact[x];
}

long long inverse::get_invfact(int x) {
    return invfact[x];
}

long long inverse::get_comb(int x, int y) {
    return fact[x] * invfact[y] % mod * invfact[x - y] % mod;
}

int main() {
    int n, m, i;
    long long ans;
    inverse inv(3000000, mod);

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

    ans = inv.get_comb(m * 3 + n - 1, n - 1);

    for (i = m * 2 + 1; i <= m * 3; i++) {
        ans -= inv.get_comb(m * 3 - i + n - 2, n - 2) * n % mod;
        if (ans < 0) ans += mod;
    }

    for (i = m + 1; i <= m * 3 && i <= n; i++) {
        if ((m * 3 - i) % 2 == 1) continue;

        ans -= inv.get_comb((m * 3 - i) / 2 + n - 1, n - 1) * inv.get_comb(n, i) % mod;
        if (ans < 0) ans += mod;
    }

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

    return 0;
}

#include <bits/stdc++.h>

#define F first
#define S second
#define PB push_back

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef priority_queue<int> HEAP;
typedef priority_queue<int, vector<int>, greater<int> > RHEAP;

const int N = 200010, M = 1010, mod = 998244353;

int n, m, k;
int infact[N], fact[N];

int qp(int a, int b)
{
	int res = 1;
	while (b)
	{
		if (b & 1) res = (LL)res * a % mod;
		a = (LL)a * a % mod;
		b >>= 1;
	}
	return res;
}

int C(int a, int b)
{
	return (LL)fact[a] * infact[b] % mod * infact[a - b] % mod;
}

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

	fact[0] = infact[0] = 1;
	for (int i = 1; i <= n; i ++ )
	{
		fact[i] = (LL)fact[i - 1] * i % mod;
		infact[i] = (LL)infact[i - 1] * qp(i, mod - 2) % mod;
	}

	int res = 0;
	for (int i = 0; i <= k; i ++ )
		res = (res + (LL)m * C(n - 1, i) % mod * qp(m - 1, n - 1 - i) % mod) % mod;
	cout << res << endl;
    return 0;
}


#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
#define degreeToRadian(deg) (((deg)/360)*2*M_PI)
#define radianTodegree(rad) (((rad)/2/M_PI)*360)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
using P = pair<int,int>;
using ll = long long;
const ll INF = 1LL<<60;
const int MOD = 1e9 + 7;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//cin.tie(0);ios::sync_with_stdio(false);
//cout << fixed << setprecision(15) << y << endl;

int n;
vector<vector<int>> a(3);

ll solve () {
  ll ans = 0;
  rep (j, n) {
    int tmp = a[1][j];
    ll comb = lower_bound(a[0].begin(), a[0].end(), tmp) - a[0].begin();
    comb *= a[2].end() - upper_bound(a[2].begin(), a[2].end(), tmp);
    ans += comb;
  }
  return ans;
}

int main() {
  while (cin >> n) {
    rep (i, 3) {
      a[i].resize(n);
      rep (j, n) cin >> a[i][j];
      sort(a[i].begin(), a[i].end());
    }
    cout << solve() << endl;
  }
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define All(a) (a).begin(),(a).end()

void solve(){
  int n;
  scanf("%d",&n);
  vector<int> a(n),b(n),c(n);

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

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

  for(int i=0;i<n;i++){
    scanf("%d",&c[i]);
  }
  sort(All(a));
  sort(All(b));
  sort(All(c));
  ll count=0;
  for (int j = 0; j < n; j++)
  {
    auto tmp = lower_bound(All(a),b[j]);
    auto l=tmp-a.begin();
      int tmp2 = c.end()-upper_bound(All(c),b[j]);
      count+=l*tmp2;

  }
  printf("%lld\n",count);
}
int main(){
  /*
  int q;
  scanf("%d",&q);
  while(--q)solve();
  */
  solve();

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define mod 1000000007
#define pb emplace_back
#define mp make_pair
#define fi first
#define sec second
typedef long long ll;
typedef long double  ld;
#define pii pair<ll,ll>
#define vi vector< ll >
#define vvi vector< vi >
#define vpi vector< pii >
#define vvpi vector< vpi >
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define test(t) ll t;cin>>t;while(t--)
#define mem(a,b) memset(a,b,sizeof(a))
#define inn freopen("input.txt", "r", stdin)
#define outt freopen("output.txt", "w", stdout)
#define all(arr) arr.begin(),arr.end()
#define fr(i,n) for(ll i=0;i<(n);++i)
#define rep(i,a,b) for(ll i=a;i<=b;++i)
#define per(i,a,b) for(ll i=a;i>=b;i--)
#define remin(a,b) (a=min((a),(b)))
#define remax(a,b) (a=max((a),(b)))
#ifndef ONLINE_JUDGE
#define debarr(a,n)cerr<<#a<<":";for(int i=0;i<n;i++)cerr<<a[i]<<" ";cerr<<endl;
#define debmat(mat,row,col)cerr<<#mat<<":\n";for(int i=0;i<row;i++){for(int j=0;j<col;j++)cerr<<mat[i][j]<<" ";cerr<<endl;}
#define pr(...)dbs(#__VA_ARGS__,__VA_ARGS__)
template<class S,class T>ostream &operator<<(ostream &os,const pair<S,T> &p){return os<<"("<<p.first<<","<<p.second<<")";}
template<class T>ostream &operator<<(ostream &os,const vector<T> &p){os<<"[";for(auto&it:p)os<<it<<" ";return os<<"]";}
template<class T>ostream &operator<<(ostream &os,const set<T>&p){os<<"[";for(auto&it:p)os<<it<<" ";return os<<"]";}
template<class T>ostream &operator<<(ostream &os,const multiset<T>&p){os<<"[";for(auto&it:p)os<<it<<" ";return os<<"]";}
template<class S,class T>ostream &operator<<(ostream &os,const map<S,T>&p){os<<"[";for(auto&it:p)os<<it<<" ";return os<<"]";}
template<class T>void dbs(string str,T t){cerr<<str<<":"<<t<<"\n";}
template<class T,class...S>void dbs(string str,T t,S... s){int idx=str.find(',');cerr<<str.substr(0,idx)<<":"<<t<<",";dbs(str.substr(idx+1),s...);}
#else
#define pr(...){}
#define debarr(a,n){}
#define debmat(mat,row,col){}
#endif
ll power(ll x,ll y){ll res = 1;while(y){if(y&1) res = (res*x)%mod;y=y/2,x=(x*x)%mod;}return res%mod;}
signed main()
{
    fast;
    ll n;
    cin>>n;
    ll arr[n][n];
    ll dp[1<<n];
    fr(i,n)fr(j,n)cin>>arr[i][j];
    fr(i,1<<n){
      vi temp;
      fr(j,n){
        if(i&(1<<j))
          temp.pb(j);
      }
      dp[i]=0;
      for(auto v:temp)for(auto u:temp)dp[i]+=arr[u][v];
        dp[i]/=2;
    }
    rep(i,1,(1<<n)-1){
      for(ll j=i;j>0;j=i&(j-1)){
        dp[i]=max(dp[i],dp[i^j]+dp[j]);
      }
    }
    cout<<dp[(1<<n)-1];

}

// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
// #pragma GCC optimize("unroll-loops")

#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>
// #include <ext/rope>
// using namespace __gnu_pbds;
// using namespace __gnu_cxx;
// template <typename T>
// using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// #define Find order_of_key
// #define at find_by_order
#define x first
#define y second
#define ll long long
#define lll __int128
#define ull unsigned long long
#define ulll unsigned __int128
#define pii pair<int,int>
#define pb push_back
#define eb emplace_back
#define gu getchar_unlocked()
#define pu putchar_unlocked()
#define all(x) x.begin(),x.end()
#define endl '\n'

ll arr[20][20];
int n;
ll dp[(1<<17)];
ll dp1[(1<<17)];
ll val(int m){
	ll &s=dp1[m];
	if(~s)return s;
	s=0;
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			if(m&(1<<i) && m&(1<<j)){
				s+=arr[i][j];
			}
		}
	}return s;
}

ll f(int m){
	if(m==0)return 0;
	ll &ma=dp[m];
	if(~ma)return ma;
	ma=0;
	for (int s=m; s; s=(s-1)&m){
		ma=max(ma,val(s)+f(m^s));
	}return ma;
}
//resub
int main()
{
	fast;
	memset(dp,-1,sizeof dp);
	memset(dp1,-1,sizeof dp1);
	cin>>n;
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			cin>>arr[i][j];
		}
	}cout<<f((1<<n)-1)<<endl;
	return 0;
}


#include<bits/stdc++.h>
#define int long long
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define bug1( x ) {cerr << (#x) <<"="<< x << endl;}
#define bug2( x , y ) {cerr << (#x) <<"="<< (x) << "    " << (#y) << "="<< (y) << endl;}
#define bug3( x , y , z ) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << endl;}
#define bug4( x , y , z , w) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << endl;}
#define bug5( x , y , z , w ,p) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << "    " << (#p) <<"="<< p << endl;}
#define bug6( x , y , z , w ,p , q) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << "    " << (#p) <<"="<< p << "    " << (#q) <<"="<< q << endl;}
#define bugn( x , n ) {cerr << (#x) <<":";for(int i=0;i<n;i++)cerr << x[i] <<"  "; cerr << endl;}
#define bugnm( x , n , m ) {cerr << (#x)<<endl;for(int i=0;i<n;i++){cerr << "Row #" << i<< ":";for(int j=0;j<m;j++)cerr << x[i][j] << "   ";cerr << endl;}}
typedef long long ll;
typedef long double ld;
using namespace std;

const int maxn = 1e5+10;
vector<int>g[maxn],vis(maxn),dis(maxn),par(maxn),tpl;
int n,m;
void dfs(int u){
	vis[u]=1;
	for(auto v:g[u]){
		if( !vis[v]){
			dfs(v);
		}
	}
	tpl.push_back(u);
}
int32_t main(){
	IOS
	cin>>n>>m;
	for(int i=1;i<=n-1+m;i++){
		int u,v;cin>>u>>v;
		g[u].push_back(v);
	}
	for(int i=1;i<=n;i++){
		if( !vis[i] ){
			dfs(i);
		}
	}
	reverse(tpl.begin(),tpl.end());
	for(int i=0;i<n;i++){
		int u = tpl[i];
		for(auto v:g[u]){
			if( dis[v] < dis[u] + 1){
				dis[v] = dis[u] + 1;
				par[v] = u;
			}
		}
	}
	for(int i=1;i<=n;i++){
		cout << par[i] << endl;
	}
}
/*
 * long long or int?
 * index out of bound?
 * Tested on own test case?corner?
 * Make more general solution.
 * Read Read Read Read ....
 */

#include <bits/stdc++.h>

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

using namespace std;

using graph=vector<vector<int>>;

void add_directed_edge(graph& G,int u,int v){
	G[u].emplace_back(v);
}

vector<int> topological_order(const graph& D){
	int n=D.size();
	vector<int> deg(n);
	rep(u,n) for(int v:D[u]) deg[v]++;

	vector<int> res;
	queue<int> Q;
	rep(u,n) if(deg[u]==0) Q.emplace(u);
	while(!Q.empty()){
		int u=Q.front(); Q.pop();
		res.emplace_back(u);
		for(int v:D[u]) if(--deg[v]==0) Q.emplace(v);
	}
	return res;
}

int main(){
	int n,m; scanf("%d%d",&n,&m);
	m+=n-1;
	graph G(n);
	rep(i,m){
		int u,v; scanf("%d%d",&u,&v); u--; v--;
		add_directed_edge(G,u,v);
	}

	vector<int> dp(n);
	for(int u:topological_order(G)){
		for(int v:G[u]) dp[v]=max(dp[v],dp[u]+1);
	}

	vector<int> ans(n,-1);
	rep(u,n) for(int v:G[u]) if(dp[v]==dp[u]+1) ans[v]=u;
	rep(u,n) printf("%d\n",ans[u]+1);

	return 0;
}


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

int main ( void ) {

    char str[1000], str2[1000], str3[1000], s[7];
    int q, a, b;

    scanf ( "%s %d", str, &q );

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

        scanf ( "%s", s );

        if ( strcmp ( s, "print" ) == 0 ) {
            scanf ( "%d %d", &a, &b );
            for ( int j = a; j < b + 1; j++ ) {
                printf ( "%c", str[j] );
            }
            printf ( "\n" );
        }

        else if ( strcmp ( s, "reverse" ) == 0 ) {
            scanf ( "%d %d", &a, &b );
            for ( int j = a, k = b; j < b + 1; j++, k-- ) {
                str2[k] = str[j];
            }
            for ( int j = a; j < b + 1; j++ ) {
                str[j] = str2[j];
            }
        }

        else if ( strcmp ( s, "replace" ) == 0 ) {
            scanf ( "%d %d %s", &a, &b, str3 );
            for ( int j = a, k = 0; j < b + 1; j++, k++ ){
                str[j] = str3[k];
            }
        }

    }

    return 0;
}

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

int main(void){
    int N;
    while( cin >> N , N ){
        string L[50];
        int P[50], A[50], B[50], C[50], D[50], E[50], F[50], S[50], M[50];
        vector< pair<double, string> > ans(N);

        for(int i = 0; i < N; i++){
            int time = 0, value = 0;
            cin >> L[i] >> P[i] >> A[i] >> B[i] >> C[i] >> D[i] >> E[i] >> F[i] >> S[i] >> M[i];
            ans[i].second = L[i];
            time = A[i] + B[i] + C[i] + (D[i] + E[i]) * M[i];
            value = M[i] * F[i] * S[i] - P[i];
            ans[i].first = -value / (double)time;
        }

        sort(ans.begin(), ans.end());
        for(int i = 0;  i< N; i++){
            cout << ans[i].second << endl;
        }
        cout << "#" << endl;

    }
    return 0;
}


#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using Pxy = pair<double, double>;
using T = tuple<int, int, bool>;
const int INF = 1001001007;
const int mod = 1000000007;
const int MOD = 998244353;
const ll inf = 1e18;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

void yes(int n){
    cout << "Yes" << endl;
}

void no (int n){
    cout << "No" << endl;
}

int main() {
    ll n, x; cin >> n >> x;
    vector<ll> ar(n);
    rep(i,n) cin >> ar[i];
    ll ans = 0;
    rep(i,n){
        ans += max(0LL,ar[i] - x);
        ar[i] = min(ar[i],x);
    }
    rep(i,n-1){
        ans += max(0LL,-x + ar[i] + ar[i+1]);
        ar[i+1] = min(ar[i+1],x - ar[i]);
    }
    cout << ans << endl;
}

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

using namespace std;

const int N = 100000;

typedef long long ll;
#define pb push_back

int n, s;
int x[N + 5], p[N + 5];

int main() {
#ifdef Wearry
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif

    scanf("%d%d", &n, &s);
    for(int i = 1; i <= n; ++i) {
        scanf("%d%d", x + i, p + i);
    }

    vector<int> res;
    int l = 1, r = n;
    ll tl = 0, tr = 0;

    while(l <= n && x[l] < s && r >= 1 && x[r] > s) {
        if(tl + p[l] >= tr + p[r]) {
            tl += tr + p[r];
            tr = 0;
            res.pb(r --);
        } else {
            tr += tl + p[l];
            tl = 0;
            res.pb(l ++);
        }
    }

    while(l <= n && x[l] < s) res.pb(l ++);
    while(r >= 1 && x[r] > s) res.pb(r --);

    ll ans = 0;
    for(int i = (int) res.size() - 1; i >= 0; --i) {
        ans += abs(s - x[res[i]]);
        s = x[res[i]];
    }
    printf("%lld\n", ans);

    return 0;
}


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

using namespace std;

int main(void) {
    int N;
    cin >> N;
    vector<int64_t> A(N);
    for(int i=0; i<N; i++) {
        cin >> A[i];
    }

    partial_sum(A.begin(), A.end(), A.begin());

    int64_t ans = numeric_limits<int64_t>::max();
    int64_t P, Q, R, S;
    int low, mid, high;
    for(int r=1; r<N-2; r++) {
        low = 0;
        high = r;
        while(low + 1 < high) {
            mid =(low + high) / 2;
            if(2*A[mid] <= A[r]) {
                low = mid;
            } else {
                high = mid;
            }
        }
        if(max(A[low], A[r] - A[low]) - min(A[low], A[r] - A[low]) < max(A[high], A[r] - A[high]) - min(A[high], A[r] - A[high])) {
            P = A[low];
            Q = A[r] - A[low];
        } else {
            P = A[high];
            Q = A[r] - A[high];
        }

        low = r+1;
        high = N-1;
        while(low + 1 < high) {
            mid =(low + high) / 2;
            if(2*(A[mid] - A[r]) <= A[N-1] - A[r]) {
                low = mid;
            } else {
                high = mid;
            }
        }
        if(max(A[low] - A[r], A[N-1] - A[low]) - min(A[low] - A[r], A[N-1] - A[low]) < max(A[high] - A[r], A[N-1] - A[high]) - min(A[high] - A[r], A[N-1] - A[high])) {
            R = A[low] - A[r];
            S = A[N-1] - A[low];
        } else {
            R = A[high] - A[r];
            S = A[N-1] - A[high];
        }

        ans = min(ans, max({P, Q, R, S}) - min({P, Q, R, S}));
    }

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

#include <bits/stdc++.h>

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define Task ""

using namespace std;
typedef long long ll;

const int maxn = 2e5 + 5;

int a[maxn];
ll sum[maxn];

ll rsum(int l, int r)
{
    return sum[r] - sum[l-1];
}

signed main(void)
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    if (fopen("A.INP", "r")){
        freopen("A.INP", "r", stdin);
        freopen("A.OUT", "w", stdout);
    }
    if (fopen(Task".INP", "r")){
        freopen(Task".INP", "r", stdin);
        freopen(Task".OUT", "w", stdout);
    }
    int N; cin >> N;
    for (int i=1; i<=N; ++i){
        cin >> a[i];
        sum[i] = sum[i-1] + a[i];
    }
    int l=1, r=3;
    ll ret = 1e18;
    for (int i=2; i<=N-2; ++i){
        r = max(r, i+1);
        while (l<i-1 && rsum(1, l) < rsum(l+1, i)) ++l;
        if (l > 1 && abs(rsum(1, l-1) - rsum(l, i)) < abs(rsum(1, l) - rsum(l+1, i))) --l;
        while (r<N-1 && rsum(i+1, r) < rsum(r+1, N)) ++r;
        if (r > i + 1 && abs(rsum(i+1, r-1) - rsum(r, N)) < abs(rsum(i+1, r) - rsum(r+1, N))) --r;
        vector<ll> vi;
        vi.pb(rsum(1, l)); vi.pb(rsum(l+1, i)); vi.pb(rsum(i+1, r)); vi.pb(rsum(r+1, N));
        sort(vi.begin(), vi.end());
        ret = min(ret, vi[3] - vi[0]);
    }
    cout << ret << '\n';
}


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

int a, b;
int x[4],y[2];

int ans = 0;

int main() {

  for(int i = 0; i < 4; i++){
    cin >> a;
    x[i] = a;
  }

  for(int i = 0; i < 2; i++){
    cin >> b;
    y[i] = b;
  }

  sort(x, x+4);
  sort(y, y+2);
  reverse(x, x+4);
  reverse(y, y+2);

  for(int i = 0; i < 3; i++){
    ans += x[i];
  }

  ans += y[0];

  cout << ans << endl;
}

#include<bits/stdc++.h>
using namespace std;
int main(void){
	int a[4];
	for(int i=0;i<4;i++)	cin>>a[i];
	int e,f;
	cin>>e>>f;
	sort(a,a+4,greater<int>());
	if(e<f){
		cout<<a[0]+a[1]+a[2]+f<<endl;
	}
	else{
		cout<<a[0]+a[1]+a[2]+e<<endl;
	}
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#define ll long long
using namespace std;
int main(){
    ll x;
    cin>>x;
    ll d=x/11;
    ll r=x%11;
    if(0==r){
        cout<<2*d<<endl;
    }else{
        if(r<7){
            cout<<2*d+1ll<<endl;
        }else{
            cout<<2*d+2ll<<endl;
        }
    }
    return 0;
}

#include <iostream>
#include <string>
#include <map>
#include <string.h>
using namespace std;
int main(){
  map<char,int> ch;//文字の数字辞書登録
  ch['I']=1;
  ch['V']=5;
  ch['X']=10;
  ch['L']=50;
  ch['C']=100;
  ch['D']=500;
  ch['M']=1000;

  int ans=0;
  int len=0;
  char s[1111];
  while(cin >> s){
    len=strlen(s);
    for(int i=0;i<len;i++){
      if(ch[s[i]]<ch[s[i+1]]){//もしも引き算をすべき場合だったら
	ans-=ch[s[i]];
      }else{
	ans+=ch[s[i]];
      }
    }
    cout << ans << endl;
    ans=0;
  }
}


#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <iomanip>
using ll=long long;
using namespace std;

int main(){
    int N,K;
    cin>>N>>K;
    vector<int> P(N+2);
    for(int i=0;i<N;i++){
        cin>>P[i];
    }

    int tmp=0;
    for(int i=0;i<K;i++){
        tmp+=P[i];
    }
    int maxnum=tmp;
    for(int i=0;i+K<N;i++){
        tmp-=P[i];
        tmp+=P[i+K];
        if(tmp>maxnum){
            maxnum=tmp;
        }
    }
    double ans=(maxnum+K)/(double)2;
    cout<<fixed<<setprecision(7)<<ans<<endl;

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll N,M,i,a,c = 0;scanf("%lld%lld",&N,&M);
  map<ll,ll> mp;
  mp[0] = 1;
  for(i=0;i<N;i++){
    scanf("%lld",&a);
    c = (c+a) % M;
    if(mp.find(c) != mp.end()) mp[c]++;
    else mp[c] = 1;
  }
  ll ans = 0;
  for(auto itr = mp.begin();itr != mp.end();itr++) ans += itr->second*(itr->second-1)/2;
  printf("%lld\n",ans);
}


#include <iostream>

using namespace std;

int table[100][100];
int memo[100][100];

int w, h;
int xs, ys, xg, yg;
int n;

void solve(int xs, int ys, int c)
{
	if( memo[xs][ys] ) {
		return;
	}

	if( !( 0 < xs && xs < w+1 && 0 < ys && ys < h+1 && table[xs][ys] == c ) ) {
		memo[xs][ys] = 1;
		return;
	}

	if( xs == xg && ys == yg ) {
		memo[xs][ys] = 1;
		cout << "OK" << endl;
		throw "OK";
	}

	memo[xs][ys] = 1;

	solve(xs+1, ys, c);
	solve(xs, ys+1, c);
	solve(xs-1, ys, c);
	solve(xs, ys-1, c);

	return;
}

int main(int argc, char* argv[])
{
	while(1) {

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

		cin >> w >> h;

		if( w == 0 && h == 0 )
			break;

		cin >> xs >> ys;
		cin >> xg >> yg;
		cin >> n;

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

			int c; cin >> c;
			int d; cin >> d;
			int x, y; cin >> x >> y;

			if( d == 0 ) {

				table[x][y] = c;
				table[x][y+1] = c;

				table[x+1][y] = c;
				table[x+1][y+1] = c;

				table[x+2][y] = c;
				table[x+2][y+1] = c;

				table[x+3][y] = c;
				table[x+3][y+1] = c;

			} else {

				table[x][y] = c;
				table[x+1][y] = c;

				table[x][y+1] = c;
				table[x+1][y+1] = c;

				table[x][y+2] = c;
				table[x+1][y+2] = c;

				table[x][y+3] = c;
				table[x+1][y+3] = c;
			}
		}

		try {
			if( table[xs][ys] )
				solve(xs, ys, table[xs][ys]);
			cout << "NG" << endl;
		} catch(...) {
		}
	}

    return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> x(n);
    for (int i = 0; i < n; i++) cin >> x[i];
    int l;
    cin >> l;
    vector<vector<int>> dbl(21, vector<int>(n, 0));
    for (int i = 0; i < n; i++) {
        int ni = upper_bound(begin(x), end(x), x[i] + l) - begin(x) - 1;
        dbl[0][i] = ni;
    }
    for (int i = 0; i < 20; i++) {
        for (int j = 0; j < n; j++) {
            dbl[i + 1][j] = dbl[i][dbl[i][j]];
        }
    }
    int q;
    cin >> q;
    while (q--) {
        int a, b;
        cin >> a >> b, a--, b--;
        if (a > b) swap(a, b);
        int cur = a;
        int ans = 0;
        for (int i = 20; i >= 0; i--) {
            if (dbl[i][cur] >= b) continue;
            cur = dbl[i][cur];
            ans += 1 << i;
        }
        cout << ans + 1 << endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
vector<long long>fact(200550);
long long bigmod(long long a, long long p){
    if(p == 0){
        return 1;
    }
    long long ans = bigmod(a, p/2);
    ans = (ans * ans) % mod;
    if(p % 2 == 1){
        ans = (ans * a) % mod;
    }
    return ans;
}
long long per(long long a, long long b){
    long long cur = (fact[b] * fact[a]) % mod;
    cur = bigmod(cur, mod - 2);
    cur = (cur * fact[a + b]) % mod;
    return cur;
}
int main(){
    long long h, w, a, b;
    cin >> h >> w >> a >> b;
    long long ans = 0;
    fact[0] = 1;
    for(long long i = 1; i <= 200010; i++){
        fact[i] = (fact[i - 1] * i) % mod;
    }
    long long p = h - a, q = b + 1;
    while(p >= 1 && q <= w){
        ans = (ans + (per(p - 1, q - 1) * per(h - p, w - q)) % mod) % mod;
        p--;
        q++;
    }
    cout << ans;
    return 0;
}

/*--------------------------------
  Author: The Ace Bee
  Blog: www.cnblogs.com/zsbzsb
  This code is made by The Ace Bee
--------------------------------*/
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#define rg register
using namespace std;
template < typename T > inline void read(T& s) {
	s = 0; int f = 0; char c = getchar();
	while (!isdigit(c)) f |= (c == '-'), c = getchar();
	while (isdigit(c)) s = s * 10 + (c ^ 48), c = getchar();
	s = f ? -s : s;
}

const int p = 1000000007;
const int _ = 500010;

int n, m, a, b, fac[_], inv[_];
inline void pre() {
	fac[0] = inv[0] = inv[1] = 1;
	for (rg int i = 1; i < _; ++i) fac[i] = 1ll * i * fac[i - 1] % p;
	for (rg int i = 2; i < _; ++i) inv[i] = 1ll * (p - p / i) * inv[p % i] % p;
	for (rg int i = 1; i < _; ++i) inv[i] = 1ll * inv[i - 1] * inv[i] % p;
}

inline int C(int n, int m) { return 1ll * fac[n] * inv[n - m] % p * inv[m] % p; }

inline int calc(int i1, int j1, int i2, int j2) { return C(i2 - i1 + j2 - j1, i2 - i1); }

int main() {
	pre();
	read(n), read(m), read(a), read(b);

	int res = 0;
	for (rg int i = 1; i <= n - a; ++i)
		res = (res + 1ll * calc(1, 1, i, b) * calc(i, b + 1, n, m) % p) % p;
	printf("%d\n", res);
	return 0;
}


#include <iostream>
using namespace std;

int main() {
	int n,a,b,pa,pb;
	while(pa=pb=0,cin>>n,n){
		for(;n;--n){
			cin>>a>>b;
			if(a>b)pa+=(a+b);
			else if(a<b)pb+=(a+b);
			else pa+=a,pb+=b;
		}
		cout<<pa<<" "<<pb<<endl;
	}
	return 0;
}

#include<bits/stdc++.h>

typedef long long ll;
typedef long double ld;

#define n1		      "\n"
#define B                     begin()
#define E                     end()
#define F                     first
#define S                     second
#define pb                    push_back
#define pf                    push_front
#define popb                  pop_back()
#define popf                  pop_front()

const int BIG=1e5+55;
const int BIGG=1e9+7;
const ll BIGGE=1e12+55;
const double SML=(1e-7);

using namespace std;

    int a[5];
    bool go = 0;

void dp(int i, int sum, string s) {
    if (go || i > 3)
        return;
    if (sum == 7 && i == 3) {
        go = 1;
        cout <<s <<'=' <<7;
        return;
    }
    string ans = s , an = s;
    ans += '-';
    ans += (a[i+1] + '0');
    if (i != -1)
        an  += '+';
    an  += (a[i+1] + '0');
    if (i != -1)
        dp(i+1 , sum-a[i+1] ,ans);
    dp(i+1 , sum+a[i+1] ,an);
}

int main()
{
    ios::sync_with_stdio(false); cin.tie(NULL);
    cout.tie(NULL);
    for (int i=0; i<4; i++) {
        char c;
        cin >>c;
        a[i] = c - '0';
    }
    dp(-1,0,"");

    return 0;
}


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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()

void MAIN() {
  int n;
  cin >> n;
  vector<vector<int>> a(3, vector<int>(n));
  vector<vector<int>> d(3, vector<int>(n));
  for (auto &i : a) {
    for (auto &j : i) cin >> j;
    sort(all(i));
  }
  for (int i = n - 1; i >= 0; i--) {
    d[2][i] = 1;
    if (i != n - 1) d[2][i] += d[2][i + 1];
  }
  for (int i = 1; i >= 0; i--) {
    for (int j = n - 1; j >= 0; j--) {
      int p = upper_bound(all(a[i + 1]), a[i][j]) - a[i + 1].begin();
      if (p != n) d[i][j] = d[i + 1][p];
      if (j != n - 1) d[i][j] += d[i][j + 1];
    }
  }
  cout << d[0][0] << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}

#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

int main() {
  int n;
  cin>>n;
  vin a(n),b(n),c(n);
  rep(i,0,n)cin>>a[i];rep(i,0,n)cin>>b[i];rep(i,0,n)cin>>c[i];
  sort(all(a));sort(all(b));sort(all(c));reverse(all(c));
  ll ans=0;
  rep(i,0,n){
    int m=b[i];
    //二分探索
    ll acnt=0;
    int ok=-1,ng=n;
    while(ng-ok>1){
      int mid=ok+(ng-ok)/2;
      if(a[mid]<m)ok=mid;
      else ng=mid;
    }
    acnt=ok+1;
    ll ccnt=0;
    ok=-1,ng=n;
  //  cout<<m<<endl;
    while(ng-ok>1){
     // if(m==2)cout<<ok<<" "<<ng<<endl;
      int mid=ok+(ng-ok)/2;
      if(c[mid]>m)ok=mid;
      else ng=mid;

    }
    ccnt=ok+1;
   // cout<<acnt<<" "<<ccnt<<endl;
    ans+=acnt*ccnt;
  }
  cout<<ans<<endl;
}


#include <iostream>
#include <queue>
#include <utility>
using namespace std;

int a[100][100];
bool r[100];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    for(int i=0; i<n; i++) {
        for(int j=0; j<n; j++) {
            cin>>a[i][j];
        }
    }
    priority_queue<pair<int,int>, vector<pair<int,int> >, greater<pair<int,int> > >q;
    q.push(make_pair(0,0));
    int cost=0;
    pair<int,int> e;
    while(!q.empty()) {
        e=q.top();
        q.pop();
        if(r[e.second]) continue;
        r[e.second]=true;
        cost+=e.first;
        for(int i=0; i<n; i++) {
            if(a[e.second][i]!=-1) q.push(make_pair(a[e.second][i], i));
        }
    }
    cout<<cost<<'\n';
    return 0;
}

#include <iostream>
#include <vector>
#include <queue>
#define to first
#define cost second
const int inf=1e9+7;
using namespace std;
int main(){

  int n,tmp,r=0,flag[100]={},v=0;
  cin>>n;
  vector <pair<int,int> > gl[n];
  priority_queue <pair<int,int> ,vector<pair<int,int> >, greater<pair<int,int> > >q;
  //for(int i=1;i<n;i++) mincost[i]=inf;

  for(int i=0;i<n;i++) for(int j=0;j<n&&cin>>tmp;j++) if(tmp!=-1) gl[i].push_back(make_pair(j,tmp));
  int now=0;
  for(int j=0;j<n-1;j++){
    for(int i=0;i<gl[now].size();i++) if(!flag[gl[now][i].to]) q.push(make_pair(gl[now][i].cost,gl[now][i].to));
    flag[now]=1;
    for(;flag[q.top().second];) q.pop();
    //if(q.empty()) break;
    r+=q.top().first;
    now=q.top().second;
    q.pop();
  }
  cout<<r<<endl;
  return 0;

}


/**Lucky Boy**/
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define FORD(i, a, b) for (int i = (a); i >= (b); --i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define maxc 1000000007
#define maxn 100005
#define maxm 1000006
#define pii pair <int,int>
#define Task ""
template <typename T> inline void read(T &x){char c;bool nega=0;while((!isdigit(c=getchar()))&&(c!='-'));if(c=='-'){nega=1;c=getchar();}x=c-48;while(isdigit(c=getchar())) x=x*10+c-48;if(nega) x=-x;}
template <typename T> inline void writep(T x){if(x>9) writep(x/10);putchar(x%10+48);}
template <typename T> inline void write(T x){if(x<0){putchar('-');x=-x;}writep(x);putchar(' ');}
template <typename T> inline void writeln(T x){write(x);putchar('\n');}
using namespace std;
int n,gt[maxn << 1],ans,cur;
int main()
{
    ios_base::sync_with_stdio(NULL);cin.tie(NULL);cout.tie(NULL);
    //freopen(Task".inp", "r",stdin);
    //freopens(Task".out", "w",stdout);
    cin >> n;
    n <<= 1;
    gt[0] = 1;
    FOR(i,1,n) gt[i] = (1ll*gt[i-1]*i) % maxc;
    ans = gt[n / 2];
    FOR(i,1,n)
    {
        int x;
        char c;
        cin >> c;
        x = (c == 'W');
        if (x)
        {
            if (cur & 1)
            {
                ++cur;
            }
            else
            {
                ans = (1ll*ans*cur) % maxc;
                --cur;
            }
        }
        else
        {
            if (cur & 1)
            {
                ans = (1ll*ans*cur) % maxc;
                --cur;
            }
            else
            {
                ++cur;
            }
        }
    }
    if (cur) ans = 0;
    cout << ans;
    return 0;
}

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

typedef long long ll;
typedef long double ld;

const ll MOD = 1e9 + 7, INF = 1e18 + 1;

using namespace std;

ll er[1000001], p[1000000], ptr, n, d[1000][1000];

ll gcd (ll a, ll b)
{
	if (!b) return a;
	else return gcd (b, a % b);
}

int main ()
{
	for (ll i = 2; i <= 1000000; i++)
		if (!er[i])
		{
			p[ptr++] = i;
			for (ll j = i * i; j <= 1000000; j += i)
				er[j] = 1;
		}

	cin >> n;

	for (int i = 0; i < 2 * n; i += 2)
		for (int j = 0; i + j < 2 * n; j++)
			d[j][i + j] = p[i / 2];

	for (int i = 2; i < 2 * n; i += 2)
		for (int j = 0; i + j < 2 * n; j++)
			d[i + j][j] = p[i / 2 + (n + 1) / 2 - 1];

	for (int i = 0; i < 2 * n; i += 2)
		for (int j = 0; i >= j; j++)
			d[i - j][j] *= p[i / 2 + n];

	ll mx = 0;

	if (n == 2)
	{
		printf ("4 7\n23 10");
		return 0;
	}

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++)
		{
			if (!d[i][j])
			{
				ll lcm = 1;
				if (j) lcm = lcm / gcd (lcm, d[i][j-1]) * d[i][j-1];
				if (j < n - 1) lcm = lcm / gcd (lcm, d[i][j+1]) * d[i][j+1];
				if (i) lcm = lcm / gcd (lcm, d[i-1][j]) * d[i-1][j];
				if (i < n - 1) lcm = lcm / gcd (lcm, d[i+1][j]) * d[i+1][j];

				d[i][j] = lcm + 1;
			}

			printf ("%lld ", d[i][j]);
		}
		putchar ('\n');
	}
}


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

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> wa(N + 5, 0);
    for (int i = 0; i < M; i++) {
        int p;
        string s;
        cin >> p >> s;
        if (wa[p] >= 0 && s == "WA") wa[p]++;
        else if (wa[p] >= 0 && s == "AC") wa[p] = wa[p] * (-1) - 1;
    }
    int ac = 0, penalty = 0;
    for (auto a: wa){
        if (a < 0) {
            penalty += (a + 1) * (-1);
            ac++;
        }
    }
    cout << ac << " " << penalty << endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const int inf = 1e9;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, b, a) for (int i = a - 1; i >= b; i--)
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dxx[8] = {1, 1, 1, 0, 0, -1, -1, -1}, dyy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};

int main() {
    int d, g;
    cin >> d >> g;
    int p[d], c[d];
    rep (i, 0, d) cin >> p[i] >> c[i];
    // 全完するものをbitで表す
    int ans = inf;
    rep (bit, 0, 1 << d) {
        int sum = 0, cnt = 0;
        rep (i, 0, d) {
            if (bit & 1 << i) {
                sum += (i + 1) * 100 * p[i] + c[i];
                cnt += p[i];
            }
        }
        if (sum >= g) {
            ans = min (ans, cnt);
        } else {
            per (i, 0, d) {
                if (1 << i & bit) continue;
                int res = (g - sum) / (100 * (i + 1));
                if (res * 100 * (i + 1) + sum < g) res++;
                if (res > p[i]) break;
                cnt += res;
                sum += res * 100 * (i + 1);
                break;
            }
            if (sum >= g) ans = min (ans, cnt);
        }
    }
    cout << ans << "\n";
}


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

int main() {

    while(1){

        int h,w;

        cin >> h >> w;

        int diagonal = h*h + w*w;

        if(h==0 && w==0) break;

        pair<int,int> ans = make_pair(500,500); //first = h , second = w

        for(int i=1; i<151; i++){
            for(int j=i+1; j<151; j++){

                int check_rect_diagonal = i*i + j*j;

                if(diagonal < check_rect_diagonal || (diagonal == check_rect_diagonal && h < i)){

                    int ans_h = ans.first;
                    int ans_w = ans.second;

                    int ans_rect_diagonal = ans_h*ans_h + ans_w*ans_w;

                    if(check_rect_diagonal < ans_rect_diagonal || (check_rect_diagonal == ans_rect_diagonal && i < ans_h )){
                        ans = make_pair(i,j);
                    }

                }
            }
        }

        cout << ans.first << " " << ans.second << endl;

    }

    return 0;
}

//2004 366 1/1 Thursday

#include <cstdio>

using namespace std;

void today(int mon, int day);

int main()
{
	int mon, day;

	while (1){
		scanf("%d %d", &mon, &day);

		if (mon == 0){
			break;
		}

		today(mon, day);
	}

	return (0);
}

void today(int mon, int day)
{
	int tmp = 0;

	for (int i = 1; i < mon; i++){
		if (i == 4 || i == 6 || i == 9 || i == 11){
			tmp += 30;
		}
		else if (i == 2){
			tmp += 29;
		}
		else {
			tmp += 31;
		}
	}

	switch ((tmp + day) % 7){
	  case 0:
	    puts("Wednesday");
		break;

	  case 1:
	    puts("Thursday");
		break;

	  case 2:
	    puts("Friday");
		break;

	  case 3:
	    puts("Saturday");
		break;

	  case 4:
	    puts("Sunday");
		break;

	  case 5:
	    puts("Monday");
		break;

	  case 6:
	    puts("Tuesday");
		break;
	}
}