#include <bits/stdc++.h>
#include <climits>

using namespace std;

template<class T>
using V = vector<T>;
template<class T>
using VV = V<V<T>>;

using ld = long double;
#define ll long long
using ull = unsigned ll;
using PLL = pair<ll, ll>;
using VLL = V<ll>;
using VB = V<bool>;
using VVB = VV<bool>;
using VVLL = VV<ll>;
using Gr = VVLL;
using MLL = map<ll, ll>;
#define UMLL unordered_map<ll, ll, custom_hash>

#define fast ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr); cerr.tie(nullptr);

#define R &
#define CR const R

#define FORI(i, a, b) for(ll i = a, max##i = b; i < max##i; ++i)
#define FOR(i, n) FORI(i, 0, n)
#define RFORI(i, a, b) for(ll i = a, min##i = b; i >= min##i; --i)
#define RFOR(i, n) RFORI(i, n, 0)
#define FORA(i, a) for(auto i : a)
#define FORAR(i, a) for(auto R i : a)
#define FORACR(i, a) for(auto CR i : a)
#define ALL(obj) begin(obj), end(obj)
#define Count(q) while(q--)
#define OK cerr << "OK\n";

#define mp make_pair
#define pb push_back

//#define DEBUG

template<class T>
T sqr(T x)
{
    return x * x;
}

void YES(bool g, ostream R os, bool upper = true)
{
    if(g)
        if(upper)
            os << "YES";
        else
            os << "Yes";
    else
        if(upper)
            os << "NO";
        else
            os << "No";

    os << "\n";
}

template<class T>
void show(T CR t, ostream R os = cerr)
{
    FORACR(i, t)
        os << i << " ";
    os << "\n";
}

template<class T>
void show2d(T CR t, ostream R os = cerr)
{
    FORACR(i, t)
        show(i, os);
    os << "\n";
}

constexpr ll MOD = 1e9 + 7; //998244353;
constexpr ll len = 1e7;

constexpr ll INF = 1e15, MINF = -INF;

constexpr ld PI = atanl(1.0L) * 4;
constexpr ld eps = 1e-9, EPS = 1e-9;

struct custom_hash
{
    static uint64_t splitmix64(uint64_t x)
    {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator() (uint64_t x) const
    {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

//arr
void init() {}

void solve(istream R is, ostream R os)
{
    VLL a(3);
    FORAR(i, a)
        is >> i;

    sort(ALL(a));
    YES(a[2] - a[1] == a[1] - a[0], os, 0);
}

void tester(istream R is, ostream R os)
{
    auto seed = time(nullptr);
    //cerr << "seed: " << seed << "\n";
    srand(seed);
    fast
    init();
    ll q = 1;
    //is >> q;

    os << setprecision(999);
    Count(q)
        solve(is, os);
}

int main()
{
    //ifstream in("input.txt");
    //ofstream out("output.txt");

    tester(cin, cout);
}

#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define debug(var) do{cout << #var << " : "; view(var);}while(0)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
template<class T> void view(T e) {cout << e << endl;}
template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;}
template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}}
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1<<30;
const ll inf_l = 1LL<<61;
const int MAX = 1e5;

// a^b
ll pow_l(ll a, ll b, ll m) {
    ll res = 1;
    rep(i,b) {
        if (res > (m + a - 1) / a) return -1;
        res *= a;
        if (res > m) return -1;
    }
    return res;
}

bool check(string x, ll m, ll d) {
    ll res = 0;
    for (int i = x.size() - 1; i >= 0; i--) {
        if (x[i] == '0') continue;
        ll tmp = pow_l(d, i, m);
        if (tmp == -1) return false;
        ll v = x[i] - '0';
        if (tmp > (m + v - 1) / v) return false;
        res += tmp * (x[i] - '0');
        if (res > m) return false;
    }
    return true;
}

int main() {
    string x; cin >> x;
    ll m; cin >> m;
    if (x.size() == 1 && x[0] - '0' <= m) {
        cout << 1 << endl;
        return 0;
    }
    ll d = -1;
    string x_re;
    rep(i,x.size()) d = max<ll>(d, x[i] - '0');
    for (int i = x.size() - 1; i >= 0; i--) x_re += x[i];
    d++;
    if (!check(x_re, m, d)) {
        cout << 0 << endl;
        return 0;
    } else {
        ll ok = d, ng = inf_l;
        while (ng - ok > 1) {
            ll mid = (ng + ok) / 2;
            if (check(x_re, m, mid)) ok = mid;
            else ng = mid;
        }
        cout << ok - d + 1 << endl;
    }
}


/*
 * Author       : YangDavid
 * Created Time : 2020.10.24 20:00:41
 */

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

const ll INF = 2e18;
int main() {
	ll x, p3 = 3, p5 = 5, deg3 = 1, deg5 = 1;
	map<ll, int> st;
	while(p5 < INF) {
		st[p5] = deg5;
		p5 *= 5, ++deg5;
	}
	cin >> x;
	while(p3 <= x) {
		if(st.count(x-p3)) {
			printf("%lld %d\n", deg3, st[x-p3]);
			return 0;
		}
		p3 *= 3, deg3++;
	}
	puts("-1");

    return 0;
}

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

const ll INF=2e18;

bool overf(ll x,ll y){
  if(x>INF/y) return true;
  return false;
}

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

  ll N;
  cin>>N;

  ll three=3;
  for(ll a=1;a<60;a++){
    ll five=5;
    for(ll b=1;b<60;b++){
      if(three+five==N){
        cout<<a<<" "<<b<<endl;
        return 0;
      }else if(three+five>N) break;

      if(overf(five,5)) break;
      five*=5;
    }
    if(overf(three,3)) break;
    three*=3;
  }

  cout<<-1<<endl;

  return 0;
}


#include<iostream>
#include<math.h>
#include<bits/stdc++.h>
#include<queue>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<string>
#define rep(i,n) for (int i=0;i<(n);++i)
using ll = long long;
using namespace std;
using P = pair<int,int>;
#define INF 100000

int main(){
    double si,sj,gi,gj;
    cin>>si>>sj>>gi>>gj;
    sj = -sj;
    double k = (sj-gj)/(si-gi);
    double ans = (-gj)/k +gi;
    cout<<fixed<<setprecision(10)<<ans<<endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define int long long
//#define N 510
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int i,n,a,b,c,d;
	cin>>a>>b>>c>>d;
	cout<<max(a,b)-min(c,d);
}


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

int main(){
  int n,k;
  string s;
  cin >> n >> k >> s;
  rep(i,k){
    string t;
    if(n%2!=0){s+=s;n*=2;}
    for(int j=0;j<n;j+=2){
      if((s[j+1]=='P' and s[j]=='R') or (s[j+1]=='R' and s[j]=='S') or (s[j+1]=='S' and s[j]=='P'))t+=s[j+1];
      else t+=s[j];
    }
    //cout << t << "\n";
    s=t;n/=2;
  }
  cout << s[0];
}

#include <cstdio>
#define N 1048576
#define ll long long
#define mem(x, a) memset(x, a, sizeof x)
#define mpy(x, y) memcpy(x, y, sizeof y)
#define fo(x, a, b) for (int x = (a); x <= (b); x++)
#define fd(x, a, b) for (int x = (a); x >= (b); x--)
#define go(x) for (int p = tail[x], v; p; p = e[p].fr)
using namespace std;
int n, K;
char s[N];

inline int read() {
	int x = 0, f = 0; char c = getchar();
	while (c < '0' || c > '9') f = (c == '-') ? 1 : f, c = getchar();
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f ? -x : x;
}

bool win(char x, char y) {
	if (x == 'R' && y == 'S') return 1;
	if (x == 'P' && y == 'R') return 1;
	if (x == 'S' && y == 'P') return 1;
	return 0;
}

int main()
{
	scanf("%d%d\n%s", &n, &K, s + 1);

	int len = 1; while (len <= n) len <<= 1;

	fo(i, 1, K) {
		fo(i, 1, n) s[n + i] = s[i];
		fo(i, 1, n)
			if (win(s[i * 2 - 1], s[i * 2])) s[i] = s[i * 2 - 1];
			else s[i] = s[i * 2];
	}
	printf("%c\n", s[1]);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
   long long N, xi, ans1=0, ans3=0;
   cin >> N;
   long double ans2=0, an;
   for(int i=0; i<N; i++){
       cin >> xi;
       ans1 += abs(xi);
       ans2 += abs(xi) * abs(xi);
       ans3 = max(ans3, abs(xi));
   }
   an = sqrt(ans2);
   cout << ans1 << endl;
   cout << fixed << setprecision(15) << an << endl;
   cout << ans3 << endl;
}

#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(int i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define rrep(i,n) for(int i=int(n-1);i>=0;i--)
#define fs first
#define sc second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define coy cout<<"Yes"<<endl
#define con cout<<"No"<<endl
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+7
#define LINF 1e18+10
using ll = long long;

using P = pair<int, int>;
using lP = pair<ll, ll>;
using fP = pair<double, double>;
using PPI = pair<P, int>;
using PIP = pair<int, P>;
using Ps = pair<int, string>;

using vi = vector<int>;
using vl = vector<ll>;
using vc = vector<char>;
using vd = vector<double>;
using vs = vector<string>;
using vp = vector<P>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvd = vector<vector<double>>;
using vvc = vector<vector<char>>;
using vvp = vector<vector<P>>;
using vvb = vector<vector<bool>>;
template <typename T>
bool chmax(T& a, const T b) { if (a < b) { a = b; return true; } return false; }
template <typename T>
bool chmin(T& a, const T b) { if (a > b) { a = b; return true; } return false; }

//const ll mod=998244353;
const ll mod = 1e9 + 7;
const ll MAX = 300000;
template <typename T>
T abs(T a) { if (a < 0)return -a; else return a; }//2020/09/30 stdlib has abs(long) abs(long long) error

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

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

  ll a,b,c;

  a=0;
  rep(i,n)a+=abs(x[i]);
  b=0;
  rep(i,n)b+=x[i]*x[i];
  c=-1;
  rep(i,n)chmax(c,abs(x[i]));
  cout<<a<<endl;
  printf("%.10lf\n",sqrt(b));
  cout<<c<<endl;

  return 0;
}


#include <algorithm>
#include <iostream>
#include <functional>
using namespace std;
using ll = long long;

const int MAXN = 40, MAXH = 20;
int n, lim, p1, p2;
ll t, a[MAXN], s1[1 << MAXH], s2[1 << MAXH];

void dfs1(int cur, ll sum) {
  if (cur == lim) {
    s1[p1++] = sum;
    return;
  }
  dfs1(cur + 1, sum);
  dfs1(cur + 1, sum + a[cur]);
}

void dfs2(int cur, ll sum) {
  if (cur == n) {
    s2[p2++] = sum;
    return;
  }
  dfs2(cur + 1, sum);
  dfs2(cur + 1, sum + a[cur]);
}

int main() {
  cin >> n >> t;
  for (int i = 0; i < n; i++) cin >> a[i];
  lim = n / 2;
  dfs1(0, 0);
  dfs2(lim, 0);
  sort(s1, s1 + p1);
  sort(s2, s2 + p2, greater<ll>());
  ll ans = 0;
  for (int i = 0, j = 0; i < p1; i++) {
    while (j < p2 && s1[i] + s2[j] > t) j++;
    if (j < p2) ans = max(ans, s1[i] + s2[j]);
  }
  cout << ans << endl;
}

#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
const long long mod = 1e9+7;
//////////////////////////////////

int main() {
  int h, w; cin >> h >> w;
  vector<vector<int>> a(h, vector<int>(w));
  int mn = 1e9;
  for(int i=0; i<h; i++) for(int j=0; j<w; j++) {
    cin >> a[i][j];
    mn = min(mn, a[i][j]);
  }

  int ans = 0;
  for(int i=0; i<h; i++) {
    for(int j=0; j<w; j++) {
      ans += a[i][j] - mn;
    }
  }
  cout << ans << endl;

  return 0;
}

// EOF


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define MEM(x,val) memset(x,val,sizeof(x))
#define LL long long
#define F first
#define S second
#define PI pair<int,int>
#define PLL pair<LL,LL>
#define ALL(x) x.begin(),x.end()

#define int LL
const int Mx = 300005;

int N,q;
int tree[Mx * 4];

void up(int node,int b,int e,int in,int val){
  if(in < b or in > e) return;
  if(b == e){
    tree[node] ^= val;
  }else{
    int mid = (b + e)/2;
    up(node*2,b,mid,in,val);
    up(node*2+1,mid+1,e,in,val);
    tree[node] = tree[node*2] ^ tree[node*2+1];
  }
}

int query(int node,int b,int e,int l,int r){
  if(l > e or r < b) return 0;
  if(b >= l and e <= r){
    return tree[node];
  }
  int mid = (b + e)/2;
  return query(node*2,b,mid,l,r) ^ query(node*2 + 1,mid+1,e,l,r);
}

void solve(){
  cin >> N >> q;
  for(int i = 1; i<=N; i++){
    int x; cin >> x;
    up(1,1,Mx-1,i,x);
  }

  while(q--){
    int ty; scanf("%lld",&ty);
    if(ty == 1){
      int x,y; scanf("%lld %lld",&x,&y);
      up(1,1,Mx-1,x,y);
    }else{
      int x,y; scanf("%lld %lld",&x,&y);
      //cout << x << ' ' << y << endl;
      printf("%lld\n",query(1,1,Mx-1,x,y));
    }
  }
}

int32_t main(){

  int tt; tt = 1;
  int cas = 1;
  while(tt--){
    //printf("Case %lld: ",cas++);
    solve();
  }
}

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

#define IO          ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int         long long
#define double      long double
#define vi          vector<int>
#define vvi         vector<vi>
#define pii         pair<int, int>
#define vii         vector<pii>
#define endl        '\n'
#define pb          push_back
#define all(v)      (v).begin(), (v).end()
#define rall(v)     (v).rbegin(), (v).rend()
#define mod         1000000007

int n, m, q;

void solve() {
	cin >> n >> m >> q;
	vii bag(n);
	for (auto& it : bag) {
		cin >> it.first >> it.second;
	}
	vi box(m);
	for (auto& it : box) {
		cin >> it;
	}
	sort(all(bag));
	while (q--) {
		int l, r;
		cin >> l >> r;
		l--, r--;
		vi a;
		for (int i = 0; i < m; i++) {
			if (i < l || i > r)
				a.pb(box[i]);
		}
		sort(all(a));
		multiset<int> memory;
		int idx = 0, ans = 0;
		for (auto& it : a) {
			while (idx < n && bag[idx].first <= it)	{
				memory.insert(bag[idx].second);
				idx++;
			}
			if (memory.size()) {
				ans += *memory.rbegin();
				memory.erase(prev(memory.end()));
			}
		}
		cout << ans << endl;
	}
}

signed main() {
	IO;
	int t = 1;
	// cin >> t;
	while (t--) {
		solve();
	}
	return 0;
}


#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define ud unsigned int
#define ll long long
#define ull unsigned long long
#define MAX_INF 0x3f
#define MAX_INF_VAL 0x3f3f3f3f
#define MAX_INF_VAL_LL 0x3f3f3f3f3f3f3f3f
//#define pi 3.141592653589
#define eps 1e-9
#define F(x) ((x)/3+((x)%3==1?0:tb))
#define G(x) ((x)<tb?(x)*3+1:((x)-tb)*3+2)
//#define p 2173412051LL
//#define sz 2

using namespace std;

template< typename T > void read( T &x ) {
	x = 0;
	char ch = getchar();
	ll f = 1;
	while( !isdigit( ch ) ) {
		if( ch == '-' )
		f *= -1;
		ch = getchar();
	}
	while( isdigit( ch ) ) {
		x = x * 10 + ch - 48;
		ch = getchar();
	}
	x *= f;
}

struct custom_hash {
    static uint64_t splitmix64( uint64_t x ) {
        x += 0x9e3779b97f4a7c15;
        x = ( x ^ ( x >> 30 ) ) * 0xbf58476d1ce4e5b9;
        x = ( x ^ ( x >> 27 ) ) * 0x94d049bb133111eb;
        return x ^ ( x >> 31 );
    }

    size_t operator() ( uint64_t x ) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64( x + FIXED_RANDOM );
    }
};

int sum[ 200010 ][ 26 ];
char s[ 200010 ];

int main() {
	ios::sync_with_stdio( false );
	cin.tie( 0 ), cout.tie( 0 );
	int n;
	cin >> s + 1;
	n = strlen( s + 1 );
	for( int i = 1; i <= n; ++i ) {
		s[ i ] -= 'a';
		for( int j = 0; j < 26; ++j )
			sum[ i ][ j ] = sum[ i - 1 ][ j ];
		++sum[ i ][ s[ i ] ];
	}
	int pre = n + 1;
	ll ans = 0;
	for( int i = n - 1; i; --i ) {
		if( s[ i ] != s[ i + 1 ] )
			continue;
		if( s[ i ] != s[ pre ] ) {
			ans += n - i - 1 - ( sum[ pre - 1 ][ s[ i ] ] - sum[ i + 1 ][ s[ i ] ] );
		} else {
			if( pre > i + 1 )
				ans += pre - i - 2 - ( sum[ pre - 1 ][ s[ i ] ] - sum[ i + 1 ][ s[ i ] ] );
		}
		pre = i;
	}
	cout << ans;
	return 0;
}

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

typedef long long ll;

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); cerr << '\n'; }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << " "; err(++it, args...); }

#define        optimize           ios::sync_with_stdio(0); cin.tie(0);
#define PI    acos(-1.0)
#define pb push_back
#define YES cout<<"Yes"<<endl;
#define NO cout<<"No"<<endl;
#define RESET(a, b) memset(a, b, sizeof(a))
#define pii pair <int, int>
#define gcd(a, b) __gcd(a, b)
#define min3(a, b, c) min(c, min(a, b))
#define max3(a, b, c) max(c, max(a, b))

const ll MX = 2e5 + 105;

vector <int> ara;

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

    vector <int> s;
    for(int i = 0; i < (1<<n); i++){
        int x;
        cin>>x;
        ara.push_back(x);
        s.push_back(x);
    }

    while(s.size() > 1){

        vector <int> val;
        for(auto x: s) val.push_back(x);

//        for(auto x: s) cout<<x<<' ';
//        cout<<endl;

        s.clear();
        for(int i = 0; i < val.size(); i += 2){
            if(val.size() == 2){
                if(val[i] < val[i+1]){
                    s.push_back(val[i]);
                }
                else s.push_back(val[i+1]);
                continue;
            }
            if(val[i] > val[i+1]){
                s.push_back(val[i]);
            }
            else s.push_back(val[i+1]);
        }
    }
//    error(s[0])
    for(int i = 0; i < ara.size(); i++){
        if(ara[i] == s[0]){
            cout<<i+1<<endl;
            break;
        }
    }
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define bit(k) (1LL<<(k))
#define SUM(v) accumulate(all(v), 0LL)

typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
struct fast_ios{ fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; }fast_ios_;

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

#define TOSTRING(x) string(#x)
template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (T &x : vec) is >> x; return is; }
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { os  << "["; for(auto _: v) os << _ << ", "; os << "]"; return os; };
template <typename T> ostream &operator<<(ostream &os, set<T> &st) { os << "("; for(auto _: st) { os << _ << ", "; } os << ")";return os;}
template <typename T> ostream &operator<<(ostream &os, multiset<T> &st) { os << "("; for(auto _: st) { os << _ << ", "; } os << ")";return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair< T, U >& p){os << "{" <<p.first << ", " << p.second << "}";return os; }
template <typename T, typename U> ostream &operator<<(ostream &os, const map<T, U> &mp){ os << "["; for(auto _: mp){ os << _ << ", "; } os << "]" << endl; return os; }

#define DUMPOUT cerr
void dump_func(){ DUMPOUT << endl; }
template <class Head, class... Tail> void dump_func(Head &&head, Tail &&... tail) { DUMPOUT << head; if (sizeof...(Tail) > 0) { DUMPOUT << ", "; } dump_func(std::move(tail)...); }

#ifdef DEBUG
#define dbg(...) { dump_func(__VA_ARGS__) }
#define dump(...) DUMPOUT << string(#__VA_ARGS__) << ": "; dump_func(__VA_ARGS__)
#else
#define dbg(...)
#define dump(...)
#endif

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = 1000000007;
// const ll MOD = 998244353;
const long double PI = acos(-1.0);

/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/

int main() {
    int N;
    cin >> N;
    string S;
    cin >> S;
    string X, Y;
    X = S.substr(0, N);
    Y = S.substr(N,N);
    dump(X, Y);
    int Q;
    cin >> Q;
    while(Q--){
        int t, a, b;
        cin >> t >> a >> b;
        a--, b--;
        dump(Q);
        if(t == 1){
            if(a < N){
                if(b < N){
                    swap(X[a], X[b]);
                }
                else{
                    swap(X[a], Y[b-N]);
                }
            }else{
                if(b < N){
                    swap(Y[a-N], X[b]);
                }else{
                    swap(Y[a-N], Y[b-N]);
                }
            }
        }
        else{
            swap(X, Y);
        }
        dump(X, Y);
    }
    cout << X << Y << endl;
}

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

int main() {
    int n;
    string s;
    int q;
    cin >> n >> s >> q;
    int flipcount = 0;
    for (int i = 0; i < q; i++) {
        int t, a, b;
        cin >> t >> a >> b;
        if (t == 1) {
            a--;
            b--;
            if (flipcount % 2 == 1) {
                if (a < n) {
                    a += n;
                } else {
                    a -= n;
                }
                if (b < n) {
                    b += n;
                } else {
                    b -= n;
                }
            }
            char c;
            c = s[a];
            s[a] = s[b];
            s[b] = c;
        } else {
            flipcount++;
        }
    }
    if (flipcount % 2 == 1) {
        string t;
        t = s.substr(n);
        s.erase(n);
        s.insert(0, t);
    }
    cout << s << endl;
}


// Example program
#include <iostream>
#include <string>
using namespace std;

int main()
{
    string s;
    cin >> s;
    swap(s[0],s[2]);
    swap(s[0],s[1]);
    cout << s;

  return 0;
}

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

typedef long long ll;
#define int ll
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pii pair<int , int>
#define pb push_back
#define F first
#define S second
const int mod = 1e9 + 7;
const int MAXX = 1e6 + 5;

int n;

signed main()
{
    _FastIO;
    cin >> n;
    int f = n * 1.08;
    if(f < 206){
        cout << "Yay!" << endl;
        return 0;
    }
    if(f == 206){
        cout << "so-so" << endl;
        return 0;
    }
    cout << ":(" << endl;
    return 0;
}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

ll nextLong() { ll x; scanf("%lld", &x); return x;}

int main2() {
  int N = nextLong();
  vector<ll> A(N); REP(i, N) A[i] = nextLong();
  sort(ALL(A));
  reverse(ALL(A));

  ll ans = 0;
  ll S = 0;
  for (int i = 0; i < N; i++) {
    ans += S - i * A[i];
    S += A[i];
  }
  cout << ans << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ll mod2 = 998244353;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m; cin >> n >> m;
  vector<ll> H(n), W(m);
  rep(i, n) cin >> H[i];
  sort(all(H));
  rep(i, m) cin >> W[i];
  vector<ll> suml(n+1), sumr(n+1);
  rep(i, n) {
    suml[i+1] += suml[i];
    if(i%2) suml[i+1] += H[i]-H[i-1];
  }
  rrep(i, n) {
    sumr[i] += sumr[i+1];
    if(i%2) sumr[i] += H[i+1]-H[i];
  }
  ll ans = longinf;
  rep(i, m) {
    int j = lower_bound(all(H), W[i]) - begin(H);
    if(j%2) {
      chmin(ans, W[i]-H[j-1]+suml[j-1]+sumr[j]);
    } else {
      chmin(ans, H[j]-W[i]+suml[j]+sumr[j+1]);
    }
  }
  cout << ans << endk;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define RREP(i, n) for (int i = (int)(n); i >= 0; i--)
#define rep(i, a, n) for (int i = (a); i < (int)(n); i++)
#define rrep(i, a, n) for (int i = (a); i >= (int)(n); i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define mp make_pair
using ll = long long;
using vi = vector<int>;
using vii = vector<vector<int>>;
using P = pair<int, int>;
template<class T> inline bool chmax(T& a, T b) { if ( a < b ) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if ( a > b ) { a = b; return true; } return false; }
ll gcd(ll x, ll y) { return y ? gcd(y,x%y) : x; }
ll lcm(ll x, ll y) { return x/gcd(x, y)*y; }

const int M = 200005;

void dfs(vii& G, vector<bool>& seen, int v) {
    if(!seen[v]) return;
    seen[v] = false;
    for(auto& nv: G[v]) {
        if(seen[nv]) dfs(G, seen, nv);
    }
}

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

    vii G(M);
    REP(i,N) {
        G[A[i]].pb(A[N-i-1]);
        G[A[N-i-1]].pb(A[i]);
    }

    int s = 0;
    vector<bool> seen(M);
    for(int i:A) {
        if(!seen[i]) {
            seen[i] = true;
            s++;
        }
    }

    REP(i,M-1) {
        if(seen[i]) {
            dfs(G, seen, i);
            s--;
        }
    }
    cout << s << endl;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define poly vector<ll>
#define For(i,l,r) for(int i=(int)(l);i<=(int)(r);i++)
#define Rep(i,r,l) for(int i=(int)(r);i>=(int)(l);i--)
#define pb push_back
inline ll read(){
	ll x=0; char ch=getchar(); bool d=1;
	for(;!isdigit(ch);ch=getchar()) if(ch=='-') d=0;
	for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	return d?x:-x;
}
inline ull rnd(){
	return ((ull)rand()<<30^rand())<<4|rand()%4;
}
const int N=205;
bool f[N][N][N][2];
int a[N],b[N],ti[N];
int main(){
	// freopen("ssw.in","r",stdin);
	int n=read();
	memset(a,-1,sizeof(a));
	For(i,1,n){
		int x=read(),y=read();
		if(x!=-1&&a[x]!=-1) return puts("No"),0;
		if(y!=-1&&a[y]!=-1) return puts("No"),0;
		if(x!=-1&&y!=-1&&x>y) return puts("No"),0;
		if(x!=-1&&y!=-1) b[y]=x;
		if(x!=-1) a[x]=0,ti[x]=i;
		if(y!=-1) a[y]=1,ti[y]=i;
	}
	f[0][0][0][0]=f[0][0][0][1]=1;
	For(i,0,2*n-1){
		if(a[i+1]==-1||a[i+1]==0){
			f[i+1][i+1][i+1][0]|=f[i][0][0][1];
		}
		For(l,1,i) For(r,l,i) For(k,0,1){
			if(!f[i][l][r][k]) continue;
			if(a[i+1]==-1||a[i+1]==0){
				if(k==0) f[i+1][l][r+1][0]=1;
			}
			if(a[i+1]==-1||a[i+1]==1){
				if(b[i+1]&&l!=b[i+1]) continue;
				if(a[i+1]==1&&a[l]!=-1&&ti[l]!=ti[i+1]) continue;
				if(l==r) f[i+1][0][0][1]=1;
				else f[i+1][l+1][r][1]=1;
			}
		}
	}
	if(f[2*n][0][0][0]||f[2*n][0][0][1]) puts("Yes");
	else puts("No");
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define endl '\n'
#define fi first
#define se second
#define For(i, l, r) for (int i = l; i < r; i++)
#define ForE(i, l, r) for (int i = l; i <= r; i++)
#define FordE(i, l, r) for (int i = l; i >= r; i--)
#define Fora(v, a) for (auto v: a)
#define bend(a) a.begin(), a.end()
#define isz(a) ((signed)a.size())

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef vector <int> vi;
typedef vector <pii> vpii;
typedef vector <vi> vvi;

const int N = 2e5 + 5;
const ll infll = (ld)1e18 + 7;

int n, q;

ll l = -infll, r = infll;
ll delta = 0;
// x <= l -> l, x >= r -> r, l < x < r -> x

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> n;
    ForE(i, 1, n){
        int a, t; cin >> a >> t;
        if (t == 1){
            delta += a;
        }
        else if (t == 2){
            if (a <= l + delta){
                continue;
            }
            if (a < r + delta){
                l = a - delta;
            }
            else{
                l = r = a - delta;
            }
        }
        else{
            if (a >= r + delta){
                continue;
            }
            if (a > l + delta){
                r = a - delta;
            }
            else{
                l = r = a - delta;
            }
        }
    }
    cin >> q;
    while (q--){
        int x; cin >> x;
        if (x <= l) cout << l + delta << endl;
        else if (x >= r) cout << r + delta << endl;
        else cout << x + delta << endl;
    }
}

/*
==================================================+
INPUT:                                            |
--------------------------------------------------|

--------------------------------------------------|
==================================================+
OUTPUT:                                           |
--------------------------------------------------|

--------------------------------------------------|
==================================================+
*/

#include <bits/stdc++.h>
#define DEBUG if(0)
#define lli long long int
#define ldouble long double
using namespace std;

const int maxN = 2e5; int n, q;
const lli inf = 1e16;
lli a[maxN], t[maxN], x[maxN];

int main()
{
  while (~scanf("%d", &n))
  {
    lli maximumLimit = inf, minimumLimit = -inf, base = 0;
    for (int i = 0; i < n; i++)
      scanf("%lld %lld", &a[i], &t[i]);

    for (int i = 0; i < n; i++)
    {
      if (t[i] == 1)
        base += a[i], maximumLimit += a[i], minimumLimit += a[i];
      else if (t[i] == 2)
        maximumLimit = max(maximumLimit, a[i]), minimumLimit = max(minimumLimit, a[i]);
      else
        maximumLimit = min(maximumLimit, a[i]), minimumLimit = min(minimumLimit, a[i]);
    }

    scanf("%d", &q);

    for (int i = 0; i < q; i++)
      scanf("%lld", &x[i]);

    for (int i = 0; i < q; i++)
    {
      lli ans = max(minimumLimit, min(maximumLimit, x[i] + base));
      printf("%lld\n", ans);
    }
  }
  return 0;
}


/*First,solve the problem then write the code:);)*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define test ll t;cin>>t;while(t--)
#define sets(a) memset(a, -1, sizeof(a))
#define clr(a) memset(a, 0, sizeof(a))
#define fr(n) for(int i=0;i<n;i++)
#define fr1(n) for(int i=1;i<=n;i++)
#define vll vector<ll>
#define mll map<ll,ll>
#define vvll vector<vector<ll>>
#define vpll vector<pair<ll,ll>>
#define vvpll vector<vector<pair<ll,ll>>>
#define mpll map<pair<ll,ll>,ll>
#define pll pair<ll,ll>
#define sll stack<ll>
#define qll queue<ll>
#define pb push_back
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define allr(x) x.rbegin(),x.rend()
#define mod 1000000007
#define ma 1000000000000000000
#define mi -1000000000000000000
int main()
{
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  fastio
  ll n;
  cin>>n;
  if(n<=100)
  cout<<1<<"\n";
  else
  {
  ll res=ceil(n/100.0);
  cout<<res<<"\n";
  }
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a;
	cin>>a;
	if(a==1)
	{
		cout<<1;
		return 0;
	}
	else if(a<100) cout<<1;
	int b=a/100;
	if(a%100==0) cout<<b;
	else cout<<b+1;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
#define REP(i,n) for(ll i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()
constexpr ll MOD=1000000007;
constexpr ll INF=2e18;

//#define DEBUG

const int n=30;
const int q=1000;
VVI h(n,VI(n-1)), v(n-1,VI(n));
VVI calch(n,VI(n-1,5000)), calcv(n-1,VI(n,5000));
const char dir[3][3]={{' ','U',' '},{'L',' ','R'},{' ','D',' '}};

struct Point{
    int i;
    int j;
    bool operator!=(const Point &other){
        return (i!=other.i||j!=other.j);
    }
};

void debug_init(){
    REP(i,n)REP(j,n-1) cin >> h[i][j];
    REP(i,n-1)REP(j,n) cin >> v[i][j];
}

string routegen(Point s, Point t){
    VVI dp(n,VI(n,INF));
    vector<vector<Point>> pre(n,vector<Point>(n));
    dp[s.i][s.j]=0;
    int di=(s.i<t.i?1:-1), dj=(s.j<t.j?1:-1);
    int ci=(s.i<t.i?0:-1), cj=(s.j<t.j?0:-1);
    for(int i=s.i;i!=t.i+di;i+=di){
        for(int j=s.j;j!=t.j+dj;j+=dj){
            if(i+di>=0&&i+di<n){
                if(dp[i+di][j]>dp[i][j]+calcv[i+ci][j]){
                    dp[i+di][j]=dp[i][j]+calcv[i+ci][j];
                    pre[i+di][j]={i,j};
                }
            }
            if(j+dj>=0&&j+dj<n){
                if(dp[i][j+dj]>dp[i][j]+calch[i][j+cj]){
                    dp[i][j+dj]=dp[i][j]+calch[i][j+cj];
                    pre[i][j+dj]={i,j};
                }
            }
        }
    }
    string ret;
    Point now=t;
    while(now!=s){
        Point p=pre[now.i][now.j];
        ret+=dir[now.i-p.i+1][now.j-p.j+1];
        now=p;
    }
    reverse(ALL(ret));
    return ret;
}

int main(){
    #ifdef DEBUG
    debug_init();
    #endif
    Point s, t;
    int a, x; double e;
    REP(qnum,q){
        cin >> s.i >> s.j >> t.i >> t.j;
        #ifdef DEBUG
        cin >> a >> e;
        #endif
        string ans=routegen(s,t);
        cout << ans << endl;
        #ifndef DEBUG
        cin >> x;
        Point now=s;
        int ave=10/ans.size();
        for(char c:ans){
            if(c=='U'){
                calcv[now.i-1][now.j]=ave;
                now.i--;
            }
            else if(c=='D'){
                calcv[now.i][now.j]=ave;
                now.i++;
            }
            else if(c=='L'){
                calch[now.i][now.j-1]=ave;
                now.j--;
            }
            else{
                calch[now.i][now.j]=ave;
                now.j++;
            }
        }
        #endif
    }
}

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
using namespace std;
typedef long long ll;

struct edge{
    int to,cost;
    edge(int a,int b):to(a),cost(b) {}
};
vector<vector<edge>> G(900);
vector<int> d(900);
vector<int> prevs(900);
const int INF = 1e9;
string res = "";
int sx,sy,gx,gy;

int heuristics(int x,int y){
    return 1000*(abs(x-gx)+abs(y-gy));
}

void discover(int s){
        for (int i = 0; i < 900;i++){
            d[i] = INF;
            prevs[i] = -1;
        }
        priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> que;
        d[s] = 0;
        que.push({0,s});
        while(!que.empty()){
            pair<int,int> p = que.top();que.pop();
            int v = p.second;
            if (d[v] < p.first) continue;
            for (int i=0;i < G[v].size();i++){
                edge e=G[v][i];
                if (d[e.to] > d[v] + e.cost){
                    d[e.to] = d[v] + e.cost;
                    prevs[e.to] = v;
                    que.push({d[e.to],e.to});
                }
            }
        }
    }

    vector<int> get_path(int t){
        vector<int> path;

        for (; t != -1;t=prevs[t]) {
            path.push_back(t);
            //cerr <<"insert " << t << "\n";
            //cerr << "next " << prevs[t] << "\n";
        }
        reverse(path.begin(),path.end());
        int len = path.size();
        res = "";
        for (int i = 1; i < len;i++){
            int now = path[i], pre = path[i-1];
            if (pre%30 + 1 == now%30) res.push_back('R');
            else if (pre%30 -1 == now%30) res.push_back('L');
            else if (pre/30 + 1 == now/30) res.push_back('D');
            else if (pre/30 - 1 == now/30 ) res.push_back('U');
        }
        return path;
    }

    void edgeupdate(int costsum,const vector<int> &path){
        int len = res.size();
        int cost = costsum/len;
        for (int i=1;i < path.size();i++){
            for (auto &e :G[path[i-1]]){
                if (e.to == path[i]) e.cost = cost;
            }
        }
    }

int main(){
    for (int i = 0;i < 30;i++){
        for (int j = 0; j < 30;j++){
            if (i == 29 && j == 29) continue;
            else if (i == 29){
                G[i*30+j].push_back(edge(i*30+j+1,9000));
                G[i*30+j+1].push_back(edge(i*30+j,9000));
            }
            else if (j == 29){
                G[i*30+j].push_back(edge((i+1)*30+j,9000));
                G[(i+1)*30+j].push_back(edge(i*30+j,9000));
            }
            else{
                G[i*30+j].push_back(edge(i*30+j+1,9000));
                G[i*30+j+1].push_back(edge(i*30+j,9000));
                G[i*30+j].push_back(edge((i+1)*30+j,9000));
                G[(i+1)*30+j].push_back(edge(i*30+j,9000));
            }
        }
    }

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

        cin >> sx >> sy >> gx >> gy;
        int score = 0;
        //cerr << "(sx,sy),(gx,gy) = " << "(" << sx << "," << sy << ")" << " (" << gx << "," << gy << ")" << "\n";
        discover(sx*30+sy);
        //cerr << "x,y" <<  " " << sx*30+sy << " " << gx*30+gy << "\n";
        //cerr << d[gx*30 + gy] << "\n";
        //cerr << d[sx*30+sy+1] << "\n";
        vector<int> ps = get_path(gx*30+gy);
        //cerr << "res :" << res << "\n";
        //for (auto v:ps){
        //    cerr << v << " ";
        //}
        //cerr << "\n";
        cout << res << endl;
        //fflush(stdout);
        cin >> score;
        edgeupdate(score,ps);
    }
    return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define ll long long
#define ull unsigned long long
#define all(x) (x).begin(),(x).end()
#define print(x) if(x)cout<<"YES\n";else cout<<"NO\n";
#define pb push_back
#define F first
#define S second
//#define mod 1000000007
#define mod 998244353
using namespace __gnu_pbds;
using namespace std;
void solve() {
	ll n;
	cin >> n;
	ll cnt = 0;
	ll ans = 0;
	ll l = 1, r = 999;
	while (l <= n) {
		ans += (min(n, r) - l + 1) * cnt;
		cnt++;
		l = r + 1;
		r = r * 10 + 9;
		ll p = 0, x = r;
		while (x > 0) {
			x /= 10;
			p++;
		}
		cnt = (p - 1) / 3;
	}
	cout << ans << "\n";
}
int main() {
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	fastio;
	int T = 1;
	// cin >> T;
	while (T--) {
		solve();
	}
}

//Bulbul khan-420...
#include <bits/stdc++.h>
#include <cstring>
#define ll long long int
#define pb() push_back()
#define f(i,n) for(i=0;i<n;i++)
using namespace std;
int main()
{
      float t,b,c,d,i,j,k,l,n,m,x,y,z;
      cin>>n;
       ll a;
      a=n*(1.08);
      if(a<206)
       cout<<"Yay!";
      else if(a==206)
        cout<<"so-so";
      else
        cout<<":(";
}


#include <bits/stdc++.h>

#define For(i, a, b) for (int(i) = (int)(a); (i) < (int)(b); ++(i))
#define rFor(i, a, b) for (int(i) = (int)(a)-1; (i) >= (int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second

using namespace std;

typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;

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

template <class T>
T div_floor(T a, T b) {
    if (b < 0) a *= -1, b *= -1;
    return a >= 0 ? a / b : (a + 1) / b - 1;
}
template <class T>
T div_ceil(T a, T b) {
    if (b < 0) a *= -1, b *= -1;
    return a > 0 ? (a - 1) / b + 1 : a / b;
}

template <typename T>
struct coord_comp {
    vector<T> v;
    bool sorted = false;

    coord_comp() {}

    int size() { return v.size(); }

    void add(T x) { v.push_back(x); }

    void build() {
        sort(v.begin(), v.end());
        v.erase(unique(v.begin(), v.end()), v.end());
        sorted = true;
    }

    int get_idx(T x) {
        assert(sorted);
        return lower_bound(v.begin(), v.end(), x) - v.begin();
    }
};

constexpr lint mod = 1000000007;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;

int main() {
    int n, m;
    scanf("%d%d", &n, &m);
    vector<int> G[n][26];
    bool E[n][n];
    rep(i, n) rep(j, n) E[i][j] = false;
    rep(i, m) {
        int a, b;
        char c;
        scanf("%d%d %c", &a, &b, &c);
        --a;
        --b;
        G[a][c - 'a'].push_back(b);
        G[b][c - 'a'].push_back(a);
        E[a][b] = E[b][a] = true;
    }
    rep(i, n) rep(c, 26) {
        sort(G[i][c].begin(), G[i][c].end());
        G[i][c].erase(unique(G[i][c].begin(), G[i][c].end()), G[i][c].end());
    }

    int d[n][n];
    rep(i, n) rep(j, n) d[i][j] = mod;
    d[0][n - 1] = 0;
    queue<pii> que;
    que.emplace(0, n - 1);
    while (!que.empty()) {
        auto [u, v] = que.front();
        if (E[u][v]) {
            printf("%d\n", d[u][v] + 1);
            return 0;
        }
        que.pop();
        rep(c, 26) for (auto nu : G[u][c]) for (auto nv : G[v][c]) {
            if (chmin(d[nu][nv], d[u][v] + 2)) {
                if (nu == nv) {
                    printf("%d\n", d[nu][nv]);
                    return 0;
                }
                que.emplace(nu, nv);
            }
        }
    }
    puts("-1");
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> P;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

int main(){
  int n, m;cin >> n >> m;
  if (n == 1){
    cout << 1 << " " << 2;
    return 0;
  }
  if (m < 0 || m >= n-1){
    cout << -1 << endl;
    return 0;
  }
  int num = 0;
  for (int i = 1; i <= n; i++){
    if (i <= n-m-1){
      cout << i << " " << 2*n-i+1 << endl;
    }
    else{
      cout << i + num << " " << i + num + 1<< endl;
      num ++;
    }
  }
}


#include<bits/stdc++.h>
using namespace std;
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
typedef long long int ll;
#define all(x) (x).begin(),(x).end()
#define print(x) if(x)cout<<"YES\n";else cout<<"NO\n";
#define f(i,x,y) for(ll i=x;i<=y;i++)
#define rf(i,x,y) for(ll i=x;i>=y;i--)
#define pb push_back
#define F first
#define S second

int main()
{

	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
	#endif

	speed;
	ll a,b,c;
	cin>>a;
	ll k =ceil((a*1.0)/100);
	cout<<k;

}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi 2*acos(0.0)
#define f first
#define s second
#define pb push_back
#define gap ' '
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define mod 1000000007
#define N 300005

int main()
{
    int n;
    cin>>n;
    cout<< ceil(n/100.0)<<endl;
}


#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define per(i,a,n) for(int i=a;i>=n;i--)

typedef int long long ll;
using namespace std;
typedef pair<int,int> P;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll MOD=1e9+7;
static const int MAX = 100;
static const int INF = (1<<23);
template<class T> T gcd(T a, T b){return b? gcd(b,a%b) : a;}
template<class T> T lcm(T a,T b){return a / gcd(a,b)*b;}
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
int main(){
    int n;
    cin>>n;
    ll ans = 0;
    rep(i,0,n){
        ll a,b;
        cin>>a>>b;
        ll size = b-a+1;
        ans += size*(size+1)/2;

        ans += (a-1)*size;

    }

    cout<<ans<<endl;

return 0;
}

#pragma region head
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using pi = pair<int, int>;
using pll = pair<ll, ll>;
template <class T>
using vv = vector<vector<T>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define rrepi(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define bit(n) (1LL << (n))
template <class T>
inline bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
const int INF = 1002003004;
const ll LINF = 1002003004005006007ll;
struct preprocess {
    preprocess() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} ____;
#pragma endregion head

#pragma region library
const int MOD = 998244353;
struct mint {
    ll x;  // typedef long long ll;
    mint(ll x = 0) : x((x % MOD + MOD) % MOD) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += MOD - a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }
    // for prime MOD
    mint inv() const {
        return pow(MOD - 2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
    bool operator==(const mint a) const {
        return x == a.x;
    }
    bool operator!=(const mint a) const {
        return x != a.x;
    }
    friend ostream& operator<<(ostream& os, const mint& value) {
        os << value.x;
        return os;
    }
    friend istream& operator>>(istream& is, mint& value) {
        ll t;
        is >> t;
        value = mint(t);
        return is;
    }
};
struct combination {
    vector<mint> fact, ifact;
    combination(int n) : fact(n + 1), ifact(n + 1) {
        assert(n < MOD);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n] * ifact[k] * ifact[n - k];
    }
};

#pragma endregion library

int main() {
    int n, k;
    cin >> n >> k;
    vector<mint> a(n);
    rep(i, n) cin >> a[i];
    combination cb(310);
    vector<mint> ak(k + 1);
    vector<mint> power(k + 1);
    vector<mint> anow(n, 1);
    rep(i, k + 1) {
        rep(j, n) {
            ak[i] += anow[j] * cb.ifact[i];
        }
        rep(j, n) {
            anow[j] *= a[j];
        }

    }
    rep(i, n) {
        mint now = a[i] * 2;
        repi(j, 1, k + 1) {
            power[j] += now;
            now *= a[i] * 2;
        }
    }
    mint div2 = (mint)1 / 2;
    repi(x, 1, k + 1) {
        mint ans = 0;
        rep(j, x + 1) {
            ans += ak[j] * ak[x - j];
        }
        ans *= cb.fact[x];
        ans -= power[x];
        ans *= div2;
        cout << ans << '\n';
    }
}


#include "bits/stdc++.h"
#include <iomanip>

using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define int ll
typedef pair<int,int> pii;
#define fi first
#define se second
#define Sort(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++)
#define REP(i,n) for(int i = 0;i < (n) ; i++)
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/4
#define INTINF INT_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
template<class T> inline bool chmax(T &a, T b){if(a < b){a = b;return true;}return false;}
template<class T> inline bool chmin(T &a, T b){if(a > b){a = b;return true;}return false;}
/*----------------------------------------------------------------*/
// const int MOD = 998244353;
const int MOD = 1000000007;
/*----------------------------------------------------------------*/
double p = 3.14159265359;
/*----------------------------------------------------------------*/
signed main(){

	int n;
	cin >> n;
	map<int,pii> mp;
	rep(i,n){
		int x,c;
		cin >> x >> c;
		auto itr = mp.find(c);
		if(itr != mp.end()){
			mp[c].first = min(mp[c].first,x);
			mp[c].second = max(mp[c].second,x);
		}else{
			mp[c] = {x,x};
		}
	}

	int ans_lr = 0;
	int ans_rl = 0;
	int pl = 0;
	int pr = 0;

	for(auto p:mp){
		int l = p.second.first;
		int r = p.second.second;
		int next_ans_lr = min(ans_lr + abs(pr-l),ans_rl + abs(pl-l)) + abs(l-r);
		int next_ans_rl = min(ans_lr + abs(pr-r),ans_rl + abs(pl-r)) + abs(l-r);
		ans_lr = next_ans_lr;
		ans_rl = next_ans_rl;
		pl = l;
		pr = r;
	}

	cout << min(ans_lr + abs(pr),ans_rl + abs(pl)) << endl;
	return 0;
}
/*----------------------------------------------------------------*/

// g++ -std=gnu++17 code1.cpp
// sudo pip3 install --upgrade online-judge-tools
// rm -r -f test;oj dl https://atcoder.jp/contests/agc048/tasks/agc048_a
// rm -r -f test;oj d https://atcoder.jp/contests/abc197/tasks/abc197_a

#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

//constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-8;

//int N, M, K, T, H, W, L, R;
long long int N, M, K, T, H, W, L, R;

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

	cin >> N;
	vector<int>l(N + 1, INT_MAX);
	vector<int>r(N + 1, INT_MIN);
	for (int i = 0; i < N; i++) {
		int a, b;
		cin >> a >> b;
		l[b] = min(a, l[b]);
		r[b] = max(a, r[b]);
	}
	long long int lp = 0, rp = 0, lsum = 0, rsum = 0;
	for (int i = 1; i <= N; i++) {
		if (l[i] == INT_MAX)continue;
		long long int nlsum = LLONG_MAX, nrsum = LLONG_MAX;
		nlsum = min(lsum + abs(lp - r[i]), rsum + abs(rp - r[i])) + abs(r[i] - l[i]);
		nrsum = min(lsum + abs(lp - l[i]), rsum + abs(rp - l[i])) + abs(r[i] - l[i]);
		lp = l[i], rp = r[i];
		lsum = nlsum, rsum = nrsum;
	}
	cout << min(lsum+abs(lp), rsum+abs(rp)) << endl;
}


#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
#define fi first
#define se second
#define sz(c)  ((int)(c).size())
#define all(c) (c).begin(), (c).end()
#define forn(i, m, n)  for (int i = m, nnnn = (n); i < nnnn; ++i)
#define pb  push_back
#define mp  make_pair
#define NIL 0
#define INF INT_MAX
#define int128 __int128_t

// greatest common divisor
ll gcd(ll a, ll b) {
    return b ? gcd (b, a % b) : a;
}

// lowest common multiple
ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}

// sieve of eratosthenes with smallest prime factor
vector<int> sieve;
void prime_sieve(int n){
    sieve.reserve(n+1);
    forn(i, 0, n+1) sieve[i] = i;
    forn(i, 2, n+1){
        if (sieve[i] == i){
            forn(j, 2, n/i+1){
                if (sieve[i*j] == i*j) sieve[i*j] = i;
            }
        }
    }
}

// normalise input to be in range of modulo
// faster than % when close to P
ll norm(ll a, ll P) {
    while (a >= P) a -= P;
    while (a < 0) a += P;
    return a;
}

// multiply and modulo
ll mul_mod(ll a, ll b, ll P) {
    return a * b % P;
}

// power and modulo (log n)
ll pow_mod(ll a, ll b, ll P){
    ll curr = a, ans = 1;
    while(b != 0){
        if (b&1) {
            ans *= curr;
            ans%=P;
        }
        curr *= curr;
        curr %= P;
        b >>= 1;
    }
    return ans;
}

// calculate modulo inverse (log n)
ll inv_mod(ll a, ll P) {
    return pow_mod(a, P - 2ll, P);
}

// calculate modulo inverse (log n)
ll div_mod(ll a, ll b, ll P) {
    return a * inv_mod(b, P) % P;
}

// most significant bit (log n)
int msb(ll a){
    for(int i = 62; i >= 0; i--){
        if (a & ((ll)1 << i)) return i + 1;
    }
    return 0;
}

// Factorial
vector<ll> fact;
void Fact(int n, ll P){
    if (fact.size() < 1) fact.pb(1);
    forn(i, fact.size(), n+1) fact.pb(fact[i-1] * i  % P);
}

void Fact(int n){
    if (fact.size() < 1) fact.pb(1);
    forn(i, fact.size(), n+1) fact.pb(fact[i-1] * i);
}

vector<ll> fact_inv;
void Fact_inv(int n, ll P){
    if (fact_inv.size() < 1) fact_inv.pb(1);
    forn(i, fact_inv.size(), n+1) fact_inv.pb(fact_inv[i-1] * inv_mod(i, P) % P);
}

// Combinations
ll nCr(int n, int r, ll P){
    if (r > n) return 0;
    Fact(n, P);
    Fact_inv(n, P);
    return (fact[n] * fact_inv[r] % P) * fact_inv[n-r] % P;
}

ll nCr_inv(int n, int r, ll P){
    if (r > n) return 0;
    Fact(n, P);
    Fact_inv(n, P);
    return (fact_inv[n] * fact[r] % P) * fact[n-r] % P;
}

// RNG
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

// Mod
const ll mod = 1000000007;

void solve(){
	int l, r;
    cin >> l >> r;
    vector<int> pf(r+1, 0);
    vector<bool> distinct(r+1, true);
    forn(i, 2, r+1){
        if(!pf[i]){
            for(int j = i, mul = 1; j <= r; j+=i, mul++) {
                pf[j]++;
                if (!(mul % i)) distinct[j] = false;
            }
        }
    }
    ll cnt= 0, cnt2=0;
    for(ll i = 2; i <= r; i++) if(distinct[i]) {
        if (pf[i]&1) cnt += (r/i - (l-1)/i) * (r/i - (l-1)/i - 1);
        else cnt -= (r/i - (l-1)/i) * (r/i - (l-1)/i - 1);
    }
    forn(i, max(l, 2), r+1) cnt2 += r/i-1;
    cout << cnt - cnt2*2;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout << setprecision(16) << fixed;
    solve();
}

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

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef long double ld;

#define all(v) v.begin(), v.end()
#define len(v) ((int)(v).size())
#define pb push_back
#define kek pop_back
#define pii pair<int, int>
#define pll pair<ll, ll>
#define mp make_pair
// #define int ll

const int INF = (is_same<int, ll>::value ? 1e18 + 666 : 1e9 + 666);
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

// const int MEM_SIZE = 5e8;
// char mem[MEM_SIZE];
// int cur_mem_ptr = 0;

// void* operator new(size_t n) {
//     cur_mem_ptr += n;
//     return mem + cur_mem_ptr - n;
// }

// void operator delete(void*) noexcept {}
// void operator delete(void*, size_t) noexcept {}

template<class t1, class t2>
inline bool cmin(t1 &a, const t2 &b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template<class t1, class t2>
inline bool cmax(t1 &a, const t2 &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

inline int bpow(int a, int b, int mod) {
    int res = 1;
    for (; b; b >>= 1) {
        if (b & 1) {
            res *= a;
            res %= mod;
        }
        a *= a;
        a %= mod;
    }
    return res;
}

#ifndef LOCAL
void UseFiles(const string &s) {
    freopen((s + ".in").c_str(), "r", stdin);
    freopen((s + ".out").c_str(), "w", stdout);
}
#else
void UseFiles(const string&) {}
#endif

void run();

signed main() {
    // UseFiles("taskname");
    iostream::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    run();
}

void run() {
    int l, r;
    cin >> l >> r;
    ++r;
    vector<ll> ans(r, 0);
    for (int g = 2; g < r; ++g) {
        ll vals = (r - 1) / g - (l - 1) / g;
        ans[g] = ((vals * (vals - 1)) >> 1);
    }
    for (int i = r - 1; i > 1; --i) {
        for (int j = 2 * i; j < r; j += i) {
            ans[i] -= ans[j];
        }
    }
    ll res = accumulate(all(ans), 0ll);
    for (int i = max(l, 2); i < r; ++i) {
        res -= (r - 1) / i - 1;
    }
    cout << (res << 1) << endl;
}


#include <bits/stdc++.h>
#define M 998244353
#define fio                           \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);
#define d(x) cout << #x << " " << x << "\n";
#define min(x1, x2) (x1 > x2 ? x2 : x1)
#define max(x1, x2) (x1 < x2 ? x2 : x1)
#define min3(x1, x2, x3) (x3 > min(x1, x2) ? min(x2, x1) : x3)
#define max3(x1, x2, x3) (x3 < max(x1, x2) ? max(x1, x2) : x3)
#define ll long long int
#define ul unsigned long long int
#define p pair<ll, ll>
#define ld long double
#define dv(v)                            \
    cerr << #v << "  ";                  \
    for (int i = 0; i < (v).size(); i++) \
        cerr << v[i] << " ";             \
    cerr << "\n";
#define inf INT_MAX
#define mp(x, y) make_pair(x, y)
using namespace std;
ll n, m;
vector<ll> fact;
void fac(ul n)
{
    fact.resize(n + 1);
    fact[0] = 1;
    for (ul i = 1; i <= n; ++i)
    {
        fact[i] = (fact[i - 1] * i) % M;
    }
}
long long power(long long a, long long b)
{
    if (b == 0)
    {
        return 1;
    }
    long long res = power(a, b / 2);
    if (b % 2)
    {
        return (res * res) % M * a % M;
    }
    else
    {
        return res * res % M;
    }
}

long long flt(long long a)
{
    return power(a, M - 2);
}
ll ncr(ll n, ll i)
{
    if (n < i)
        return 0;
    return ((fact[n] * flt(fact[i])) % M * flt(fact[n - i])) % M;
}

int main()
{
    fio;
    ll t, x, y, z, k;
    vector<ll> v;
    string s;
    cin >> n >> m;
    vector<ll> dp(m + 1);
    vector<ll> ndp(m + 1);
    fac(n);
    ll ans = 0;
    for (int i = 1; i <= m; ++i)
    {
        dp[i] = 1;
        ans = (ans + 1) % M;
    }
    bool b = 1;
    ll sum;
    int l = 1;
    while (l + 1 <= n)
    {
        sum = 0;
        ndp.assign(m + 1, 0);
        b = 0;
        for (int j = 1; j <= m; ++j)
        {
            if (dp[j] == 0)
            {
                continue;
            }
            for (int i = 2 * j; i <= m; i += j)
            {
                b = 1;
                ndp[i] = (ndp[i] + dp[j]) % M;
            }
        }
        if (!b)
        {
            break;
        }
        ++l;
        dp = ndp;
        for (int j = 1; j <= m; ++j)
        {
            sum = (sum + dp[j]) % M;
        }
        ans = (ans + (ncr(n - 1, l - 1) * sum) % M) % M;
    }
    cout << ans << "\n";
    return 0;
}

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

const int MOD = 998244353;

long long kai[101];
void kaijo()
{
	kai[0] = 1;
	FOR(i, 1, 100)
	{
		kai[i] = i * kai[i - 1];
		kai[i] %= MOD;
		// cout << kai[i] << endl;
	}
}
int main()
{
	int n;
	cin >> n;
	ll dp[110][5100] = {};
	ll total = 0;
	vector<ll> a(n);
	kaijo();
	REP(i, n)
	{
		cin >> a[i];
		total += a[i];
	}
	if (total % 2)
	{
		cout << 0 << endl;
		return 0;
	}
	total /= 2;
	// cout << total << endl;
	dp[0][0] = 1;
	REP(i, n)
	{
		for (int k = n; k >= 0; k--)
		{
			REP(j, 5050)
			{
				if (j + a[i] <= 5050)
				{
					dp[k + 1][j + a[i]] += dp[k][j] % MOD;
					dp[k + 1][j + a[i]] %= MOD;
				}
			}
		}
	}
	// cout << dp[1][1] << endl;
	ll ans = 0;
	REP(i, n)
	{
		// ans += dp[i][total];
		// cout << dp[i][total] << endl;
		ans += ((dp[i][total] * kai[i] % MOD) * kai[n - i] % MOD);
		ans %= MOD;
	}
	cout << ans << endl;
	return (0);
}


#include<bits/stdc++.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long int
#define fi first
#define se second
#define pub push_back
#define pi pair<int,int>
#define all(v) (v).begin(), (v).end()
#define rep(i, l, r) for(int i=(int)(l);i<(int)(r);i++)
#define repd(i, l, r) for (int i=(int)(l);i>=(int)(r);i--)
#define clrg(i, l, r) for(int i=(int)(l);i<(int)(r);i++)vis[i]=0,v[i].clear();
int power(int x, unsigned int y){int res = 1;while (y > 0){ if (y & 1){res = res*x;} y = y>>1;x = x*x;}return res;}
int powermod(int x, unsigned int y, int p){int res = 1;x = x % p;while (y > 0){if (y & 1){res = (res*x) % p;}y = y>>1; x = (x*x) % p;}return res;}
#define print2d(mat,n,m){for(int i=0;i<(int)(n);i++){for(int j=0;j<(m);j++){cout<<mat[i][j]<<" ";}cout<< endl;}}
#define clr(a,x) memset(a,x,sizeof(a))
#define rr(v) for(auto &val:v)
#define print(v) for (const auto itr : v){cout<<itr<<' ';}cout<<"\n";
#define ln length()
#define sz size()
#define mod 1000000007
#define elif else if
int32_t main(){
   fastIO
   int n,m; cin>>n>>m;
   vector<int> hor[n],ver[n];
   rep(i,0,n){
        rep(j,0,m-1){
            int t; cin>>t;
            hor[i].pub(t);
        }
   }
   rep(i,0,n-1){
        rep(j,0,m){
            int t; cin>>t;
            ver[i].pub(t);
        }
   }
   priority_queue<pair<int,pi>,vector<pair<int,pi>>,greater<>> pq;
   int vis[n+1][m+1];
   rep(i,0,n)rep(j,0,m)vis[i][j]=1e18;
   pq.push({0,{0,0}});
   while(!pq.empty()){
       int x=pq.top().second.first,y=pq.top().second.second;
       int cost=pq.top().fi;
       pq.pop();
       //cout<<x<<" "<<y<<" "<<cost<<"\n";
       if(cost>vis[x][y])continue;
       vis[x][y]=cost;
       if(y<m-1){
          // cout<<vis[x][y+1]<<" "<<vis[x][y]+hor[x][y]<<" f\n";
           if(vis[x][y+1]>vis[x][y]+hor[x][y]){
               vis[x][y+1]=vis[x][y]+hor[x][y];
               pq.push({vis[x][y+1],{x,y+1}});
           }
       }
       if(x<n-1){
           //cout<<vis[x+1][y]<<" "<<vis[x][y]+ver[x][y]<<" s\n";
           if(vis[x+1][y]>vis[x][y]+ver[x][y]){
               vis[x+1][y]=vis[x][y]+ver[x][y];
               pq.push({vis[x+1][y],{x+1,y}});
           }
       }
       if(y>0){
           //cout<<vis[x][y-1]<<" "<<vis[x][y]+hor[x][y-1]<<" t\n";
           if(vis[x][y-1]>vis[x][y]+hor[x][y-1]){
               vis[x][y-1]=vis[x][y]+hor[x][y-1];
               pq.push({vis[x][y-1],{x,y-1}});
           }
       }
       repd(j,x-1,0){
           int i=j+1;
           if(vis[x-i][y]>vis[x][y]+1+i){
               vis[x-i][y]=vis[x][y]+1+i;
               pq.push({vis[x-i][y],{x-i,y}});
           }
       }
   }
   cout<<vis[n-1][m-1]<<"\n";
   return 0;
}

#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,m,n) for (int i = (m); i < (n); ++i)
#define rrep(i,n) for (int i = (n)-1; i >= 0; --i)
#define RREP(i,m,n) for (int i = (n)-1; i >= (m); ++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using namespace std;
using ll = long long int;
using vec = vector<int>;
using P = pair<int,int>;
const int INF = 1e9+7;

void yes(vec b, vec c) {
  cout << "Yes" << endl;
  cout << b.size() << " ";
  for (int e : b) {
    cout << e << " ";
  }
  cout << endl;
  cout << c.size() << " ";
  for (int e : c) {
    cout << e << " ";
  }
  cout << endl;
  return;
}

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

  vector<vec> v(200);

  rep(i,n) {
    int a; cin >> a;
    vector<bool> b(200);

    if (v[a%200].size()) {
      yes(v[a%200], {i+1});
      return 0;
    } else {
      v[a%200].push_back(i+1);
      b[a%200] = true;
    }

    rep(j, 200) {
      if (b[j]) continue;

      if (v[j].size() > 0) {
        int k = (j+a)%200;
        if (v[k].size() > 0) {
          vec c = v[j];
          c.push_back(i+1);
          yes(v[k], c);
          return 0;
        }
        else {
          v[k] = v[j];
          v[k].push_back(i+1);
          b[k] = true;
        }
      }
    }
  }

  cout << "No" << endl;
}


#include<iostream>

using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int h,m;
    cin>>m>>h;
    cout<<((h%m==0)?("Yes"):("No"))<<"\n";
}

#include <bits/stdc++.h>

using namespace std;

#define inf          1e15
#define mod          1000000007
#define N            100001
#define ll           long long int
#define vint         vector<int>
#define vll          vector<ll>
#define vstr         vector<string>
#define vvint        vector<vector<int> >
#define vvll         vector<vector<ll> >
#define vint_pair    vector<pair<int,int> >
#define input(arr)   for(auto &x:arr) cin>>x;
#define all(x)       (x).begin(), (x).end()
#define rall(x)      (x).rbegin(), (x).rend()

int main() {
    int m,h;
    cin>>m>>h;
    if(h%m==0){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }
}


//{{
/*
 * Created at: 06/27/21 18:12:05
 *
 * FB: https://facebook.com/tgbaodeeptry
 * From Viet Nam with Love :D
 *
 */

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

#define fast_io()                   \
  ios_base::sync_with_stdio(false); \
  cin.tie(NULL);
#define REP(i, a, b) for (int i = int(a); i < int(b); ++i)
#define RED(i, a, b) for (int i = int(a); i > int(b); --i)
#define FOR(i, a, b) for (int i = int(a); i <= int(b); ++i)
#define FOD(i, a, b) for (int i = int(a); i >= int(b); --i)
#define sz(x) ((int)x.size())
#define allong(x) (x).begin(), (x).end()
#define f first
#define s second
#define eb emplace_back
#define pb push_back
#define endl '\n'

using llong = long long;
using veci = vector<int>;
using vecveci = vector<vector<int>>;
using pairii = pair<int, int>;

const int MOD = 1e9 + 7;
const int MAXN = 1e5;
const int INF = INT_MAX;

template <class T>
void re(T& x) {
  cin >> x;
};
template <class T>
void re(vector<T>& v, int n) {
  for (int i = 0; i < n; ++i)
    cin >> v[i];
};
template <class T>
void re(vector<T>& v, int f, int t) {
  FOR(i, f, t)
  cin >> v[i];
};
template <class T>
void re(T v[], int n) {
  FOR(i, 0, n - 1)
  cin >> v[i];
};
template <class T>
void re(T* v, int f, int t) {
  FOR(i, f, t)
  cin >> v[i];
};
template <class H, class... T>
void re(H& v, T&... args) {
  re(v);
  re(args...);
};

void dbg_out() {
  cerr << endl;
}

template <typename Head, typename... Tail>
void dbg_out(Head H, Tail... T) {
  cerr << ' ' << H;
  dbg_out(T...);
}

template <typename T>
void dbg_out(vector<T>& a) {
  for (auto c : a)
    cerr << ' ' << c;
  cerr << endl;
};

template <typename T>
void dbg_out(vector<T>& a, int n) {
  FOR(i, 0, n - 1)
  cerr << ' ' << a[i];
  cerr << endl;
};

template <typename T>
void dbg_out(vector<T>& a, int u, int v) {
  FOR(i, u, v)
  cerr << ' ' << a[i];
  cerr << endl;
};

template <typename T>
void dbg_out(T a[]) {
  for (auto c : a)
    cerr << ' ' << c;
  cerr << endl;
};

template <typename T>
void dbg_out(T a[], int n) {
  FOR(i, 0, n - 1)
  cerr << ' ' << a[i];
  cerr << endl;
};

template <typename T>
void dbg_out(T a[], int u, int v) {
  FOR(i, u, v)
  cerr << ' ' << a[i];
  cerr << endl;
};

#if defined(_CRUN) || defined(_RUN)
#define pd(...)                         \
  cerr << "(L:" << __LINE__ << "): "    \
       << "[" << #__VA_ARGS__ << "] =", \
      dbg_out(__VA_ARGS__)
#else
#define pd(...)
#endif

#if defined(_CRUN)
#define c_input() freopen("input", "r", stdin)
#define c_output() freopen("output", "r", stdin)
#else
#define c_input()
#define c_output()
#endif

void ps(){};

template <typename Head, typename... Tail>
void ps(Head H, Tail... T) {
  cout << H;
  ps(T...);
};

template <typename T>
void ps(vector<T>& a, int n) {
  FOR(i, 0, n - 1)
  cout << a[i] << ' ';
};

template <typename T>
void ps(T a[], int n) {
  FOR(i, 0, n - 1)
  cout << a[i] << ' ';
};

int add_mod(int a, int b) {
  return ((a % MOD) + (b % MOD)) % MOD;
}

int sub_mod(int a, int b) {
  return ((a % MOD) - (b % MOD) + MOD) % MOD;
}

int mul_mod(int a, int b) {
  return ((llong) (a % MOD) * (b % MOD)) % MOD;
}

llong pow_mod(llong a, llong b) {
  llong ans = 1;
  while (b) {
    if (b & 1) ans = mul_mod(ans, a);
    a = mul_mod(a, a);
    b >>= 1;
  };
  return ans;
};

llong lcm(llong a, llong b) {
  return a * b / __gcd(a, b);
}

llong pow(llong a, llong b) {
  llong ans = 1;
  while (b) {
    if (b & 1) ans *= a;
    a *= a;
    b >>= 1;
  };
  return ans;
};

void solve();
void init();
bool multi_test = false;
// ---- main below ----- ///

int main() {
  fast_io();
  init();

  int T = 1;
  if (multi_test) re(T);

  FOR(i, 1, T) solve();
}
//}}

void init() {
  // multi_test = true;
}

void solve() {
  int n;
  re(n);

  ps(n - 1);
}

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

typedef vector<int> vi;
typedef vector<ll> vll;

typedef vector<vi> vvi;
typedef vector<vll> vvll;

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

typedef vector<pii> vpii;
typedef vector<pll> vpll;

typedef vector<vpii> vvpii;
typedef vector<vpll> vvpll;

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define fi first
#define se second

template<class T> bool ckmin(T &a, const T &b) {return a > b ? a = b, 1 : 0;}
template<class T> bool ckmax(T &a, const T &b) {return a < b ? a = b, 1 : 0;}

namespace debug {
    void __print(int x) {cerr << x;}
    void __print(long long 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 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 z : x) cerr << (f++ ? "," : ""), __print(z); cerr << "}";}
    void _print() {cerr << "]\n";}
    template <typename T, typename... V>
    void _print(T t, V... v) {__print(t); if(sizeof...(v)) cerr << ", "; _print(v...);}

    #ifdef ljuba
    #define dbg(x...) cerr << "LINE(" << __LINE__ << ") -> " << "[" << #x << "] = ["; _print(x)
    #else
    #define dbg(x...)
    #endif
}

using namespace debug;

const char nl = '\n';

void solve() {
    int a, b;
    cin >> a >> b;
    int c = a + b;
    if(c >= 15 && b >= 8) {
        cout << 1 << nl;
    } else if(c >= 10 && b >= 3) {
        cout << 2 << nl;
    } else if(c >= 3) {
        cout << 3 << nl;
    } else {
        cout << 4 << nl;
    }
}

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

#ifdef ljuba
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
#endif

    int testCases = 1;
//    cin >> testCases;
    while(testCases--)
        solve();

}


#include <bits/stdc++.h>
#define fast_io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long
#define PI acos(-1)
using namespace std;

int main()
{
    fast_io;
    int n;
    cin>>n;
    int arr[n];
    for(int i=0; i<n; i++)
    {
        cin>>arr[i];
    }
    int sum=0;
    for(int i=0; i<n; i++)
    {
        if(arr[i]<=10)
        {
            sum+=0;
        }
        else if(arr[i]>10)
        {
            sum+=(arr[i]-10);
        }
    }
    cout<<sum<<"\n";
    return 0;
}

#include <bits/stdc++.h>

#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define fori(i,n) for(ll i=0;i<(n);++i)
#define fora(i,a,n) for(ll i=a;i<=(n);++i)
#define forad(i,a,n) for(ll i=a;i>=(n);--i)
#define pb(v,temp) ll temp;cin>>temp;v.push_back(temp)

using namespace std;
using ll = long long;

void solve()
{
    ll n,temp,res=0;
    cin>>n;
    while(n--){
        cin>>temp;
        if(temp>10){
            res+=(temp-10);
        }

    }
    cout<<res;
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}


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

int a[ 4 ] ;

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

void solve ( ) {
    for ( int mask = 0 ; mask < 16 ; ++ mask ) {
        int sm = 0 ;
        for ( int i = 0 ; i < 4 ; ++ i ) {
            if ( ( mask & (1<<i) ) > 0 ) { sm += a[ i ] ; }
            else { sm -= a[ i ] ; }
        }
        if ( sm == 0 ) {
            printf ( "Yes\n" ) ;
            return ;
        }
    }
    printf ( "No\n" ) ;
}

int main ( ) {
    ios_base :: sync_with_stdio ( false ) ;
    cin.tie ( NULL ) ;
    input ( ) ;
    solve ( ) ;
    return 0 ;
}

#include<bits/stdc++.h>
using namespace std;
#define intt long long int
#define intu unsigned long long int
#define vi vector<intt>
#define ii pair<int,int>
#define pb push_back
#define ff first
#define ss second
#define fast_io ios::sync_with_stdio(0);cin.tie(NULL);std::cout.tie(NULL);
# define PI           3.14159265358979323846
#define all(a) a.begin(),a.end()
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define bloop(i,a,b) for (int i = a ; i>=b;i--)
#define tc(t) int t; cin >> t; while (t--)
int mod = 1000000007;
intt gcd(intt a, intt b) {return b ? gcd(b, a % b) : a;}
int lcm(int a, int b) {return a * b / gcd(a, b); }
intt bpow(intt a,intt b)
{
  intt res = 1;
  while (b > 0) {
    if (b & 1)res = res * a;
      a = a * a;
      b >>= 1;
  }
  return res;
}
intt fact(intt n) {
   if ((n==0)||(n==1))
      return 1;
   else
      return (n*fact(n-1))%mod;
}

void go()
{
#ifndef ONLINE_JUDGE
  freopen("IN.txt","r",stdin);
  freopen("OUT.txt","w",stdout);
  #endif
}
bool isPowerOfTwo (int x)
{
    return (!(x&(x-1)));
}

int main(){
	go();
	fast_io
  vi v(4);
  intt s=0;
  for0(i,4){
    cin>>v[i];s+=v[i];
  }
  intt t=0;bool f=0;
  for(intt i=0;i<4;i++){
    t+=v[i];
    if(s-t==t){
      f=1;
      break;
    }
    for(intt j=i+1;j<4;j++){
      t+=v[j];
      if(s-t==t){
        f=1;
        break;
      }
      t-=v[j];
    }
    if(f)
      break;
    t-=v[i];
  }
  if(f)
    cout << "Yes" <<"\n";
  else
    cout << "No" <<"\n";
}


#include <cstdio>
#include <iostream>
#include <cassert>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <numeric>
#include <random>
#include <cmath>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <chrono>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)

using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;

const int MAXN = 234567;
const LL MOD = 998244353;

LL mul(LL a, LL b) {
    return (a * b) % MOD;
}

LL add(LL a, LL b) {
    return (a + b) % MOD;
}

LL qpow(LL n, LL p) {
    if (p == 0) return 1;
    if (p % 2) return mul(n, qpow(n, p - 1));
    return qpow(mul(n, n), p / 2);
}

LL pw2[MAXN];

int main() {
    int N;
    scanf("%d", &N);
    pw2[0] = 1;
    for (int i = 1; i <= N; i++)
        pw2[i] = mul(2, pw2[i - 1]);
    //printf("qpow = %lld\n", qpow(4, MOD - 2));
    vector<int> V(N);
    for (int i = 0; i < N; i++)
        scanf("%d", &V[i]);
    sort(V.begin(), V.end());
    LL sum = 0, ans = 0;
    for (int i = 0; i < N; i++)
        ans = add(ans, mul(V[i], V[i]));

    for (int i = N - 1; i >= 0; i--) {
        LL cur = qpow(pw2[i + 1], MOD - 2);
        cur = mul(cur, V[i]);
        LL tmp = mul(cur, sum);
        ans = add(ans, tmp);
        sum = add(sum, mul(V[i], pw2[i]));
    }
    printf("%lld\n", ans);

    return 0;
}
/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
    * DON'T GET STUCK ON ONE APPROACH
by Benq;
*/

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

#ifdef LOCAL
#include "/debug.h"
#else
#define db(...)
#endif

#define all(v) v.begin(), v.end()
#define pb push_back
using ll = long long;
const int NAX = 2e5 + 5, MOD = 1000000007;

void solveCase()
{
    int n;
    cin >> n;
    vector<ll> a(n), b(n);
    for (size_t i = 0; i < n; i++)
        cin >> a[i];
    ll res = 0;
    for (size_t i = 0; i < n; i++)
    {
        cin >> b[i];
        if (i > 0)
            a[i] = max(a[i], a[i - 1]);
        res = max(res, a[i] * b[i]);
        cout << res << ' ';
    }
    cout << '\n';
}

int32_t main()
{
#ifndef LOCAL
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif
    int t = 1;
    // cin >> t;
    for (int i = 1; i <= t; ++i)
        solveCase();
    return 0;
}


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

int main() {
  int m,h;
  cin >> m >> h;

  bool a = false;
  for(int i = 1; i <= 1001; i++){
    if(m*i == h){
      a = true;
    }
  }

  if(a) cout << "Yes" << endl;
  else cout << "No" << endl;

}

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

#define PI 3.14159265359

int main(){
  int M, H;
  cin >> M >> H;
  if (H % M == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define boost                         \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL)
#define testcases \
    int t;        \
    cin >> t;     \
    while (t--)
#define rep(i, n) for (int i = 1; i <= n; i++)
#define Rep(j, n) for (int j = i; j < n; j++)

int32_t main()
{
    boost;
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        int x = log2(i);
        cout << x + 1 << " ";
    }
}

#include<bits/stdc++.h>

int main(){
    using namespace std;
    unsigned long N;
    cin >> N;
    for(unsigned long i{1}; i <= N; ++i)cout << 64 - __builtin_clzl(i) << " ";
    cout << endl;
    return 0;
}


#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define all(x)  x.begin(), x.end()
#define sz(x)   (int)x.size()
#define pb      push_back

#define ll      long long
#define int     long long

template <typename T>
using ordered_set = tree<T, null_type,
      less<T>, rb_tree_tag,
      tree_order_statistics_node_update>;

const int MOD1 = 1000000007;
const int MOD2 = 998244353;
const int N = 2e5 + 10;
const int INF = 1e18;

vector<tuple<int, int, int>> adj[N];

vector<int> p, d;
void dijkstra(int32_t s) {
	int32_t n = N;
	d.assign(n, INF);
	p.assign(n, -1);

	d[s] = 0;
	set<pair<int, int32_t>> q;
	q.insert({0, s});
	while (!q.empty()) {
		int v = q.begin()->second;
		q.erase(q.begin());

		for (auto [to, len, k] : adj[v]) {
			int nd = (d[v] + k - 1) / k * k + len;
			if (nd < d[to]) {
				q.erase({d[to], to});
				d[to] = nd;
				p[to] = v;
				q.insert({d[to], to});
			}
		}
	}
}

void solve() {
	int n, m, x, y;
	cin >> n >> m >> x >> y;
	x--, y--;
	for (int i = 0; i < m; ++i) {
		int a, b, t, k;
		cin >> a >> b >> t >> k;
		a--, b--;
		adj[a].pb({b, t, k});
		adj[b].pb({a, t, k});
	}

	dijkstra(x);
	if (d[y] == INF) { d[y] = -1; }
	cout << d[y];
}

int32_t main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int t = 1;
	// cin >> t;
	while (t--) {
		solve();
		cout << '\n';
	}
	return 0;
}

/*HAR HAR MAHADEV
ヽ｀、ヽ｀｀、ヽ｀ヽ｀、、ヽ ｀ヽ 、ヽ｀🌙｀ヽヽ｀ヽ、ヽ｀
ヽ｀、ヽ｀｀、ヽ 、｀｀、 ｀、ヽ｀ 、｀ ヽ｀ヽ、ヽ ｀、ヽ｀｀、
ヽ、｀｀、｀、ヽ｀｀、 、ヽヽ｀、｀、、ヽヽ、｀｀、 、 ヽ｀、
ヽ｀｀、 ヽ｀ヽ｀、、ヽ ｀ヽ 、 🚶ヽ｀｀｀｀ヽヽヽ｀、、ヽ｀、、ヽ*/
# include   <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll, ll> pl;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;//typedef for datatype and #define for macro

# define    fast                ios_base::sync_with_stdio(false);cin.tie(NULL);
# define    MOD                 1000000007
# define    endl                '\n'
# define    FOR(i, a, b)        for (int i=a; i<(b); i++)
# define    F0R(i, a)           for (int i=0; i<(a); i++)
# define    FORd(i,a,b)         for (int i = (b)-1; i >= a; i--)
# define    F0Rd(i,a)           for (int i = (a)-1; i >= 0; i--)
# define    INF                 9e18
# define    PI                  3.14159265358979323846
# define    lb                  lower_bound
# define    ub                  upper_bound
# define    mp                  make_pair
# define    pb                  push_back
# define    fi                  first
# define    se                  second
# define    all(a)              a.begin(), a.end()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main()
{
    fast;
    ll t = 1;
    // cin >> t;
    while (t--)
    {
        double sx, sy, gx, gy;
        cin >> sx >> sy >> gx >> gy;
        cout << fixed << setprecision(10);
        cout << (gy * sx + gx * sy) / (sy + gy) << endl;
    }
    return 0;
}
/* stuff you should look for
  * int overflow, array bounds
  * special cases (n=1?)
  * do smth instead of nothing and stay organized
  * WRITE STUFF DOWN
  * DON'T GET STUCK ON ONE APPROACH
*/


#include <bits/stdc++.h>

using namespace std;

#define ll long long

int main()
{
    ll a,b,c;
    cin>>a>>b>>c;
    if(c==0){
        if(a>b){
            cout<<"Takahashi";
        }else{
            cout<<"Aoki";
        }
    }else{
        if(a>=b){
            cout<<"Takahashi";
        }else{
            cout<<"Aoki";
        }
    }

    return 0;
}

#include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define pii pair<int,int>
#define pll pair<ll,ll>
#define IT iterator
#define PB push_back
#define fi first
#define se second
#define all(a) a.begin(),a.end()
#define mid ((r+l)>>1)
#define lson p<<1,l,mid
#define rson p<<1|1,mid+1,r
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));
#define debug cout << "dsdsdsdsd" << "\n";
#define y1 yzang
using namespace std;

const int maxn = 2e5 + 10;

int n,m;

int main() {
	int c;
	cin >> n >> m >> c;
	if(c == 0) {
		if(n >= m + 1) {
			cout << "Takahashi" << "\n";
		}
		else {
			cout << "Aoki" << "\n";
		}
	}
	else {
		if(n + 1 <= m) {
			cout << "Aoki" << "\n";
		}
		else {
			cout << "Takahashi" << "\n";
		}
	}
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
//reverse(s.begin(),s.end())
ll gcd(ll a,ll b){
    ll s=1,c;
    while(a&&b){
        if((~a&1)&&(~b&1))
            a>>=1,b>>=1,s<<=1;
        else if(~a&1)a>>=1;
        else if(~b&1)b>>=1;
        else if(a>b)a=a-b;
        else c=b-a,b=a,a=c;
    }
    if(!a)return b*s;
    if(!b)return a*s;
}

int main(){
	int n;
	cin>>n;
	cout<<n-1;
}


#include <bits/stdc++.h>
#define LL long long
using namespace std;
const LL P=1e9+7;
const LL X2=2;
int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
void print(LL x){
    if(x>9) print(x/10);
    putchar(x%10+'0');
}
LL ans,res;
LL n,A,B,C,D;
int main(){
	int T;scanf("%d",&T);
	while(T--){
		scanf("%lld%lld%lld",&n,&A,&B);
		if(A>B) swap(A,B);
		if(A+B>n){
			puts("0");
			continue;
		}
		ans=(n-A+1)*(n-A+1)%P*(n-B+1)%P*(n-B+1)%P;
		res=(B-A+1)*(B-A+1)%P;
		res=res*(n-B+1)%P*(n-B+1)%P;
		ans=ans-res;
		res=(B-A+1)*(n-B+1)%P;
		C=(n+n-B-B-A+X2)*(A-1)%P;
		res=res*C%P;
		ans=ans-res-res;
		res=0;
		C=(n*n%P+n+n+1)%P*(A-1)%P*(A-1)%P;
		res+=C;
		if((A-1)%X2==0){
			D=(A-1)/X2;
			D=D*(B+B+A)%P;
		}
		else {
			D=(B+B+A)/X2;
			D=D*(A-1)%P;
		}
		res+=D*D%P;
		res-=(A-1)*(n+1)%P*D%P;
		res-=(A-1)*(n+1)%P*D%P;
		res=(res%P+P)%P;
		res=res*X2%P*X2%P;
		ans=ans-res;
		ans=(ans%P+P)%P;
		cout<<ans<<endl;
	}
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
const int MOD = 1e9+7;

int sum(int a, int b) {
    return a + b >= MOD ? a + b - MOD : a + b;
}
int sub(int a, int b) {
    return a - b < 0 ? a - b + MOD : a - b;
}
int mul(int a, int b) {
    return (1LL*a*b)%MOD;
}
int pw(int a, int b) {
	if (!b) return 1;
	int r = pw(a, b/2);
	r = mul(r, r);
	if (b%2) r = mul(r, a);
	return r;
}

typedef long long LL;

int getSum(int N) {
    LL ans = N;
    ans *= N+1;
    ans /= 2;
    return ans%MOD;
}

int getSum(int L, int R) {
    if (L < 1) L = 1;
    if (L > R) return 0;
    return sub(getSum(R), getSum(L-1));
}

int solve() {
    int N, A, B;
    cin >> N >> A >> B;
    if (A < B) swap(A, B);

    int tmp = getSum(N-A-B+2, N-A);
    int ans = mul(mul(N-A+1, N-A+1), mul(N-B+1, N-B+1));
    ans = sub(ans, mul(4, mul(A-B+1, mul(N-A+1, tmp))));
    ans = sub(ans, mul(4, mul(tmp, tmp)));
    ans = sub(ans, mul(mul(N-A+1, N-A+1), mul(A-B+1, A-B+1)));
    return ans;
}

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

    int t;
    cin >> t;

    while (t--) {
        cout << solve() << "\n";
    }

    return 0;
}


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

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

    int N;
    cin >> N;

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

    const int MIN_ELEM = *min_element(A.begin(), A.end());
    unordered_map<int, int> memo;
    memo[MIN_ELEM] = MIN_ELEM;
    for(int i = 0; i < N; ++i){
        for(int d = 1; d * d <= A[i]; ++d){
            if(A[i] % d == 0){
                for(int divisor: set<int>{d, A[i] / d}){
                    memo[divisor] = (memo.count(divisor) ? __gcd(memo[divisor], A[i]) : A[i]);
                }
            }
        }
    }

    int answer = 0;
    for(const pair<int, int>& P: memo){
        answer += (P.first == P.second && P.first <= MIN_ELEM);
    }

    cout << answer;

    return 0;
}

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

template <typename A, typename B> ostream& operator <<(ostream& out, const pair<A, B>& a) { out << "(" << a.first << "," << a.second << ")"; return out; }
template <typename T, size_t N> ostream& operator <<(ostream& out, const array<T, N>& a) { bool f = 1; out << "["; for (auto& v : a) { out << (f ? "" : ", ") << v; f = 0; } out << "]"; return out; }
template <typename T> ostream& operator <<(ostream& out, const vector<T>& a) { bool f = 1; out << "["; for (auto& v : a) { out << (f ? "" : ", ") << v; f = 0; } out << "]"; return out; }
template <typename T, class Cmp> ostream& operator <<(ostream& out, const set<T, Cmp>& a) { bool f = 1; out << "{"; for (auto& v : a) { out << (f ? "" : ", ") << v; f = 0; } out << "}"; return out; }
template <typename U, typename T, class Cmp> ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) { bool f = 1; out << "{"; for (auto& p : a) { out << (f ? "" : ", ") << p.first << ":" << p.second; f = 0; } out << "}"; return out; }
#ifdef LOCAL_DEBUG
#define dbg(...) __dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define dbg(...) 42
#endif
template <typename Arg1> void __dbg(const char* name, Arg1&& arg1){ cerr << name << ": " << arg1 << endl; }
template <typename Arg1, typename... Args> void __dbg(const char* names, Arg1&& arg1, Args&&... args){ const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << ": " << arg1 << " |"; __dbg(comma + 1, args...); }

int gcd(int a, int b)
{
    while (1) {
        if (a) b %= a; else return b;
        if (b) a %= b; else return a;
    }
}

template<class T> void sort_unique(vector<T> &v) {
	sort(v.begin(), v.end());
	v.erase(unique(v.begin(), v.end()), v.end());
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n);
    for (auto &it: a) cin >> it;
    sort_unique(a);

    vector<int> divs;
    for (auto x: a) {
        for (ll i = 1; i*i <= x; ++i) if (x % i == 0) {
            if (i <= a[0]) divs.push_back(i);
            if (x/i <= a[0]) divs.push_back(x/i);
        }
    }
    sort_unique(divs);

    int an = 0;
    for (auto x: divs) {
        int g = 0;
        for (auto y: a) {
            if (y % x == 0) g = gcd(g, y);
        }
        if (g == x) ++an, dbg(x);
    }

    cout << an << '\n';
    return 0;
}


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

using ll = long long;
using db = long double;
using vi = vector<int>;
using vl = vector<ll>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;

#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define F0R(i, n) FOR(i, 0, n)
#define ROF(i, a, n) for(int i=(n)-1;i>=(a);--i)

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) int((x).size())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define endl '\n'

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

//const ll MOD = 1000000007;
//const ll INF = LLONG_MAX;
//const ld PI = 3.14159265358979323846;

void solve() {
    int n;
    cin >> n;
    pl a[n], b[n];
    F0R(i, n) {
        cin >> a[i].fi;
        a[i].se = i;
        cin >> b[i].fi;
        b[i].se = i;
    }
    sort (a, a + n);
    sort (b, b + n);
    if (a[0].se == b[0].se)
        cout << min({ max(a[0].fi, b[1].fi), max(b[0].fi, a[1].fi), (a[0].fi + b[0].fi) });
    else
        cout << max(a[0].fi, b[0].fi);
}

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

    int tc = 1;
    //cin >> tc;
    while (tc--)
        solve();
}

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

int n;
int ans = INT_MAX;
int main()
{
  cin >> n;
  vector<int> wa(n);
  vector<int> wb(n);
  for (int i = 0; i < n; i++)
  {
    int a, b;
    cin >> a >> b;
    wa.at(i) = a;
    wb.at(i) = b;
  }
  for (int i = 0; i < n; i++)
  {
    for (int j = 0; j < n; j++)
    {
      if (i == j)
      {
        ans = min(ans, wa.at(i) + wb.at(j));
      }
      else
      {
        ans = min(ans, max(wa.at(i), wb.at(j)));
      }
    }
  }
  cout << ans << endl;
}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mkp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define FI(n) FastIO::read(n)
#define FO(n) FastIO::write(n)
#define ull unsigned long long
#define mst(a,b) memset(a,b,sizeof(a))
#define foR(i,k,j) for(int i=(k);i>=(j);i--)
#define For(i,k,j) for(int i=(k);i<=(j);i++)
#define Foe(i,u) for(int i=lst[u],v=e[i].v;i;i=e[i].nxt,v=e[i].v)
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define Fin(s) freopen(s,"r",stdin)
#define Fout(s) freopen(s,"w",stdout)
#define file(s) Fin(s".in"),Fout(s".out")
//#define int long long
const int P=1004535809; //
using namespace std;
template<typename T>inline void ckmax(T &a,T b) {(a<b)&&(a=b);}
template<typename T>inline void ckmin(T &a,T b) {(a>b)&&(a=b);}
inline int mul(int a,int b) {return 1ll*a*b%P;}
inline int add(int a,int b) {return a+b>=P?a+b-P:a+b;}
inline int sub(int a,int b) {return a-b>=0?a-b:a-b+P;}
inline void mulmod(int &a,int b) {a=mul(a, b);}
inline void addmod(int &a,int b) {((a+=b)>=P)&&(a-=P);}
inline void submod(int &a,int b) {((a-=b)<0)&&(a+=P);}
inline int ksm(int a,int b) {int ans=1; for(;b;b>>=1) {if(b&1) ans=1ll*ans*a%P;a=1ll*a*a%P;}return ans;}
inline int inv(int a) {return ksm(a,P-2);}
namespace FastIO {
  const int SIZE=1<<16; char buf[SIZE],obuf[SIZE],str[64]; int bi=SIZE,bn=SIZE,opt;
  int read(char *s) {
    while (bn) {for (;bi<bn&&buf[bi]<=' ';bi++);if (bi<bn) break; bn=fread(buf,1,SIZE,stdin),bi=0;}
    int sn=0;while (bn) {for (;bi<bn&&buf[bi]>' ';bi++) s[sn++]=buf[bi];if (bi<bn) break; bn=fread(buf,1,SIZE,stdin),bi=0;}s[sn]=0;return sn;
  }
  bool read(int& x) {if(x)x=0;int bf=0,n=read(str); if(!n) return 0; int i=0; if (str[i]=='-') bf=1,i=1; for(x=0;i<n;i++) x=x*10+str[i]-'0'; if(bf) x=-x; return 1;}
  void write(int x) {
    if(!x) obuf[opt++]='0'; else {if(x<0) obuf[opt++]='-',x=-x;int sn=0; while(x)str[sn++]=x%10+'0',x/=10;for (int i=sn-1;i>=0;i--) obuf[opt++]=str[i];}
    if (opt>=(SIZE>>1)){fwrite(obuf,1,opt,stdout); opt=0;}
  }
  void write(char x) {obuf[opt++]=x;if (opt>=(SIZE>>1)){fwrite(obuf,1,opt,stdout); opt=0;}}
	void Fflush() {if (opt) fwrite(obuf,1,opt,stdout); opt=0;}
};
inline int read() {int x; FI(x); return x;}
const int MN=2e3+5;
int n,m; char s[MN];
bool check(int i,int j) {
	return (i==1&&j==1)||(i==1&&j==m)||(i==n&&j==1)||(i==n&&j==m);
}
int f[MN];
int find(int x) {
	return x==f[x]?x:f[x]=find(f[x]);
}
void merge(int x,int y) {
	x=find(x),y=find(y);
	f[y]=x;
}
signed main() {
	#ifndef ONLINE_JUDGE
		freopen("pro.in","r",stdin);
		freopen("pro.out","w",stdout);
	#endif
	n=read(),m=read();
	For(i,1,n+m) f[i]=i;
	For(i,1,n) {
		FI(s+1); For(j,1,m) {
			if(s[j]=='#'||check(i,j)) {
				merge(i,j+n);
			}
		}
	}
	set<int>p,q;
	int ans=0;
	For(i,1,n) {
		p.insert(find(i));
	}
	For(i,1,m) {
		q.insert(find(i+n));
	}
	cout<<min(p.size(),q.size())-1<<endl;
	return 0;
}

/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG
#endif
#include <stdio.h>
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip> //setprecision
#include <map> // map
#include <unordered_map> //unordered_map
#include <queue> // queue, priority_queue
#include <set> // set,multiset
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
#include <numeric> //accumulate,,,
#include <sstream>
#define endl "\n";
using namespace std;

using PLL = pair<long long,long long>;
typedef tuple<long long,long long,long long> TUP;
using P = pair<int,int>;
const long long INF = 4000000000000000001;
const int inf = 1001001001;
const long long MOD = 1000000007;

//Solve N^M. This, mod_pow use Iterative Square Method.
long long mod_pow(long long N, long long M, long long mod) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % mod, M / 2,mod);
    //When end-of-a bit is 1, times simple N.
    if (M & 1) res = (res * N) % mod;
    return res %= mod;
}
long long gcd(long long a, long long b) {
    if (b == 0) return a; else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a / gcd(a, b) * b ;
}
long long get_mod(long long res){
    if(res < 0) res += MOD;
    return res % MOD;
}

long long ydp[61][2];
long long xdp[61][2];

// True:1 , False:0

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

    int N;cin >> N;
    vector<string> S(N);
    for(int i = 0;i<N;i++) cin >> S.at(i);
    for(int i = 0;i<61;i++) for(int j = 0;j<2;j++) ydp[i][j] = 0 , xdp[i][j] = 0;
    xdp[0][0] = 1;
    xdp[0][1] = 1;
    ydp[0][0] = 1;
    ydp[0][1] = 1;
    for(long long i = 1;i<=N;i++){
        if(S.at(i-1) == "AND"){
            ydp[i][1] += ydp[i-1][1];
            ydp[i][0] += ydp[i-1][1]+ydp[i-1][0]*2;
        }
        if(S.at(i-1) == "OR"){
            ydp[i][1] += ydp[i-1][1]*2;
            ydp[i][1] += ydp[i-1][0];
            ydp[i][0] += ydp[i-1][0];
        }
    }
    cout << ydp[N][1] << endl;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+5,M=2e4+5,inf=0x3f3f3f3f,mod=1e9+7;
#define mst(a,b) memset(a,b,sizeof a)
#define PII pair<int,int>
#define fi first
#define se second
#define pb push_back
int t,n,s,k;
void exgcd(ll a,ll b,ll &x,ll &y){
	if(!b){
		x=1,y=0;
		return;
	}
	exgcd(b,a%b,y,x); //这里仔细体会一下,这里我们将x1赋给y,y1赋给x
	y-=(a/b)*x;
}
int main(){
	scanf("%d",&t);
	while(t--){
		scanf("%d%d%d",&n,&s,&k);
		ll c=n-s;
		ll g=__gcd(k,n);
		if(c%g) puts("-1");
		else {
			ll x,y;
			exgcd(k,n,x,y);
			ll tmp=c/g;
			ll d=n/g;
			x*=tmp;
			x=(x%d+d)%d;
			if(c%k==0) printf("%lld\n",c/k);
			else printf("%lld\n",x);
		}
	}
	return 0;
}

#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define DIV 1000000007 //10^9+7
#define INF LONG_MAX/3

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

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

long lcm( long m, long n ){
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	return ((m / gcd(m, n)) * n);
}

// {g, x, y}: ax+by=g
tuple<ll, ll, ll> extgcd(ll a, ll b) {
	if(b == 0) return {a,1,0};
	ll g,x,y;
	tie(g,x,y) = extgcd(b, a%b);
	return {g, y, x - a/b*y};
}

int main(){
	ll T;
	cin >> T;
	rep(_, T) {
		ll N, S, K;
		cin >> N >> S >> K;

		ll tmpg = gcd(N, K);

		if(S%tmpg != 0) {
			cout << -1 << endl;
		} else {
			ll g, x, y;
			tie(g, x, y) = extgcd(N, K);
			S/=g;

			//cout << (y%N + N)*(S%N + N)%N << endl;
			N/=g;
			cout << ((y*-S)%N + N)%N << endl;
		}

	}

}