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

void solve() {
    std::string s;
    std::cin >> s;
    int n = s.length();

    std::vector<int> cnt(10, 0);
    for (auto c : s) ++cnt[c - '0'];

    for (int i = 0; i < 10; ++i) {
        if (cnt[i] == 0 && (i != 0 || n != 0)) continue;
        --cnt[i];
        --n;

        for (int j = 0; j < 10; ++j) {
            if (cnt[j] == 0 && (j != 0 || n != 0)) continue;
            --cnt[j];
            --n;

            for (int k = 0; k < 10; ++k) {
                if (cnt[k] == 0 && (k != 0 || n != 0)) continue;
                --cnt[k];
                --n;

                int x = k * 100 + j * 10 + i;
                if (x % 8 == 0) {
                    std::cout << "Yes\n";
                    return;
                }

                ++cnt[k];
                ++n;
            }
            ++cnt[j];
            ++n;
        }
        ++cnt[i];
        ++n;
    }

    std::cout << "No\n";
}

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

    solve();

    return 0;
}

#include <iostream>
#include <functional>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <iomanip>
#include <complex>
#include <random>
#include <bitset>
#include <list>
#include <assert.h>
// #include <prettyprint.hpp>
using namespace std;
#define repi(i,n) for(int i=0;i<n;++i)
#define rep(i,n) for(ll i=0;i<n;++i)
#define repinvi(i,n) for(int i=n-1;i>=0;--i)
#define sll(n) scanf("%lld", &n);
#define sii(n) scanf("%d", &n);
#define slf(n) scanf("%lf", &n);
#define pll pair<ll,ll>
#define pii pair<int,int>
#define psi pair<si,si>
#define v(t) vector<t>
#define vv(t) vector<vector<t>>
#define vvv(t) vector<vector<vector<t>>>
typedef long long ll;
typedef double lf;
typedef short int si;

void Main(){
    string S;
    cin >> S;
    map<char, ll> counter;
    rep(i, S.size()){
        counter[S[i]] ++;
    }
    // rep(i, 10){
    //     if(counter.find(i+1) == counter.end()){
    //         counter['1'+i] = 0;
    //     }
    // }
    v(string) string_list;
    string base;
    if(S.size() == 1){
        base = "0";
    }else if(S.size() == 2){
        base = "00";
    }else{
        base = "000";
    }
    rep(i, 1001){
        if(i==1000)break;
        if(i % 8==0){
            string new_b = base;
            new_b[0] += i % 10;
            if(S.size() >= 2){
                new_b[1] += (i % 100) / 10;
            }
            if(S.size()>=3){
                new_b[2] += i / 100;
            }
            string new_b2 = "";
            rep(i, new_b.size()){
                new_b2 += new_b[new_b.size()-i-1];
            }
            string_list.push_back(new_b2);
        }
        // if(S.size()<=3){
        //     ll n = stoi(S);
        //     if(i>=n) break;
        // }
    }
    bool ok;
    // cout << string_list <<endl;
    for(auto s:string_list){
        map<char, ll> s_count;
        bool has_zero = false;
        for(auto c:s){
            if(c=='0'){
                has_zero = true;
            }
            s_count[c]++;
        }
        if(has_zero){
            continue;
        }
        bool this_ok = true;
        // cout << s <<endl;
        // cout << s_count <<endl;
        for(auto p:s_count){
            // cout << p <<endl;
            if(counter[p.first]<p.second){
                this_ok = false;
                break;
            }
        }
        ok = this_ok;
        if(this_ok){
            break;
        }
    }
    if(ok){
        cout << "Yes" <<endl;
    }else{
        cout << "No" <<endl;
    }

}

int main(){
    Main();
}


#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i=0;i<n;i++)
#define INF 1000000001
#define lINF 1000000000000001
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvll = vector<vll>;
using ii = pair<int, int>;
using vvi = vector<vi>;
using vii = vector<ii>;
using vs = vector<string>;
using vc = vector<char>;
using P = pair<ll, ll>;
using si = stack<int>;
using ss = stack<string>;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
//1e9<int型の最大値<1e10
//1e18<long型の最大値<1e19
//配列直入れ↓
//g++ -std=c++17 -Wshadow -Wall -D_GLIBCXX_DEBUG -o a b.cpp && ./a
//bit全探索
//2のk乗は"1<<k"で書ける

int main(){
    double n,D,H;
    cin>>n>>D>>H;
    vector<double> d(n);
    vector<double> h(n);
    double ans=INF;
    double tans =0;
    rep(i,n){
        double now;
        cin>>d[i]>>h[i];
        now=(H-h[i])/(D-d[i]);
        if(now<ans){
            ans=now;
            tans=H-ans*D;
        }
    }
    if(tans<0) cout<<0.0<<endl;
    else cout<<setprecision(10)<<tans<<endl;

}

#include <bits/stdc++.h>
using namespace std;
#define inf 1000000005 /*10^9+5*/
#define mod 1000000007 /*10^9+7*/
#define eps 1e-10
#define rep(i,n) for(int i = 0; i < (n); ++i) /*0からn-1までのrepeat*/
#define rrep(i,n) for(int i = 1; i <= (n); ++i) /*1からnまでのrepeat*/
#define drep(i,n) for(int i = (n)-1; i >= 0; --i) /*n-1から0までのrepeat*/
#define srep(i,s,t) for (int i = s; i < t; ++i) /*sからt-1までのrepeat*/
#define isin(x,l,r) ((l) <= (x) && (x) < (r)) /*l以上r未満のx*/
#define each(a,b) for(auto& (a): (b)) /*よくわかんない☆*/
#define pct __builtin_popcountll /*1bitの数*/
#define all(a) a.begin(),a.end() /*ぜーんぶ*/
#define sz(v) (int)(v).size() /*大きさ*/
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end()) /*重複削除*/
#define cmx(x,y) x=max(x,y) /*最大*/
#define cmn(x,y) x=min(x,y) /*最小*/
#define rev(v) reverse((v).begin(),(v).end()); /*逆順*/
#define so(v) sort((v).begin(), (v).end()); /*ソート*/
#define yn {puts("Yes");}else{puts("No");} /*はいかいいえか*/
#define YN {puts("YES");}else{puts("NO");} /*大文字-はいかいいえか*/
#define dame { puts("-1"); return 0;}/*だめ*/
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define vipls vector<int> pls; /*@_vipls*/

using ll = long long;
using unit = unsigned;
using ull = unsigned long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vd = vector<double>;
using vp = vector<P>;
using vt = vector<T>;
using vs = vector<string>;
using vc = vector<char>;

int main() {
    ll a,b,n,ct;
    ct = 0;
    cin >> n;
    rep(i, n) {
        cin >> a >> b;
        a = (b - a + 1) * (b + a) / 2;
        ct = ct + a;
    }
    cout << ct << endl;
    return 0;
}


/*
[arc104] D - Multiset Mean
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
#define ALL(c) (c).begin(), (c).end()

const int MAX_N = 100;
const int MAX_K = 100;
const int MAX_S = MAX_N * MAX_N * MAX_K;

int N, K, MOD;

class gf {
public:
    int n;
    gf() : n(0) {}
    gf(int n) : n(n < 0 ? n % MOD + MOD : n % MOD) {}
    gf operator+(gf x) { return gf((n + x.n) % MOD); }
    gf operator-(gf x) { return gf((n - x.n + MOD) % MOD); }
    gf operator*(gf x) { return gf((1LL * n * x.n) % MOD); }
    gf& operator+=(gf x) { return *this = (*this + x); }
    gf& operator-=(gf x) { return *this = (*this - x); }
    gf& operator*=(gf x) { return *this = (*this * x); }
};

gf dp[MAX_N + 1][MAX_S + 1];

void solve() {
    int sz = 0;
    dp[0][0] = 1;
    for (int i = 1; i <= N; i++) {
        sz += i;
        gf ps[MAX_N + 1];
        for (int j = 0; j <= sz * K; j++) {
            int m = j % i;
            ps[m] += dp[i - 1][j];
            int lj = j - i * (K + 1);
            if (lj >= 0) {
                ps[m] -= dp[i - 1][lj];
            }
            dp[i][j] = ps[m];
        }
    }

    for (int i = 1; i <= N; i++) {
        gf ans = 0;
        for (int j = 0; j <= sz * K; j++) {
            ans += dp[i - 1][j] * dp[N - i][j];
        }
        ans = ans * (K + 1) - 1;
        cout << ans.n << endl;
    }
}

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

    solve();

    return 0;
}

#include <bits/stdc++.h>

#pragma GCC optimize(2)
using namespace std;
#define int long long
typedef long long LL;
typedef long long ll;
const int INF = 0x3f3f3f3f;
//const int inf = 1e18;
//const int mod = 998244353;
const int mod = 1e9 + 7;
int gcd(int a, int b) { return !b ? a : gcd(b, a % b); }
const int maxn = 1e6 + 10;
const int N = 6e6 + 100;

int a[maxn];

void solve() {
    int r,x,y;
    cin>>r>>x>>y;
    double R=sqrt(x*x+y*y);
    if (R<r) cout<<2<<"\n";
    else
    cout<<ceil(R/(r*1.0))<<"\n";
}

signed main() {
    //ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int _ = 1;
//    cin >> _;
    while (_--) {
        solve();//cout<<"\n";
    }
    return 0;
}


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

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

   double ans = a*b;

   cout << ans/100 << endl;

}

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

//My typenames
typedef long long l1;
typedef vector<int> vi;
typedef vector<l1> vl;
typedef pair<int,int> pi;
typedef map<int,int> mp;

//My Macros
#define F first
#define S second
#define pushb push_back
#define popb pop_back
#define fli(i,a,b) for(int i=a;i<b;i++)
#define fld(i,a,b) for(int i=a;i>b;i--)

void solve(){
    float a,b;
    cin>>a>>b;
    cout<<(float)(b/100.0)*a<<"\n";
}

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

    //freopen("in","r",stdin);
    //freopen("out","w",stdout);

    //Getting test cases
    solve();

    return 0;
}


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

using namespace std;

vector< vector<int> > T;
vector<int> C;
vector<int> ans;
vector<int> color_check;

void dfs(int now, int p){
    if(color_check[ C[now] ] == 0){
        ans.emplace_back(now);
    }

     color_check[ C[now] ]++;

    for(int i = 0; i < T[now].size(); i++){
        if(T[now][i] == p){
            continue;
        }else{
            dfs(T[now][i],now);
        }
    }
    color_check[ C[now] ]--;
    return;
}

int main(){

    //N頂点n-1辺の木の作成(木という名の無向グラフ)
    //頂点Aから頂点Bへの辺には頂点Aと頂点Bの色の情報も入れる。
    int N = 0;
    cin >> N;
    C.resize(N, 0);
    for(int i = 0; i < C.size(); i++){
        cin >> C[i];
    }
    T.resize(N);
    for(int i = 0; i < N-1; i++){
        int A = 0, B = 0;
        cin >> A >> B;
        T[A-1].emplace_back(B-1);
        T[B-1].emplace_back(A-1);
    }

    //深さ優先探索で探索
    //ちなみに頂点1は絶対によい頂点なので答えは1つ以上存在する。
    color_check.resize(100001, false);
    dfs(0,-1);

    sort(ans.begin(), ans.end());
    for(int i = 0; i < ans.size(); i++){
        cout << ans[i]+1 << endl;
    }

    return 0;
}

#include "bits/stdc++.h"

using namespace std;

const int maxn=2e5+5;
int a[maxn],b[maxn],p[maxn],ip[maxn];

void solve(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    for(int i=1;i<=n;i++){
        cin>>b[i];
    }
    for(int i=1;i<=n;i++){
        cin>>p[i];
        ip[p[i]]=i;
    }
    priority_queue<pair<int,int>> pq;
    for(int i=1;i<=n;i++){
        pq.push(make_pair(b[i],i));
    }
    for(int i=1;i<=n;i++){
        if(a[i]<=b[p[i]] && p[i]!=i){
            cout<<"-1\n";
            return;
        }
    }
    vector<pair<int,int>> ops;
    for(int i=1;i<=n;i++){
        auto cur=pq.top();
        pq.pop();
        if(p[cur.second]==cur.second){
            continue;
        }
        int fst=cur.second,scnd=ip[cur.second];
        ops.emplace_back(fst,scnd);
        swap(ip[p[fst]],ip[p[scnd]]);
        swap(p[fst],p[scnd]);
    }
    cout<<(int)ops.size()<<'\n';
    for(auto i:ops){
        cout<<i.first<<' '<<i.second<<'\n';
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


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

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int h,w;
    cin>>h>>w;
    map<int,int>mp;
    vector<int>v;
    for(int i=1;i<=h;i++)
    {
        for(int j=1;j<=w;j++)
        {
            int temp;
            cin>>temp;
            v.push_back(temp);
            mp[temp]++;
        }
    }
    int low = *min_element(v.begin(),v.end());
    int ans =0;
    for(auto &it:mp)
    {
        if(it.first!=low)
        {
            ans+=(it.first-low)*it.second;
        }
    }
    cout<<ans<<"\n";
}

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

#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()

const ll inf = 1e9 + 9;
const ll maxn = 1e5+100;
const ll mod = 1e9+7;
const ld eps = 1e-6;

//-------------------------------------------------------------------------
int n, m, mn, sum;

void solve() {
    cin >> n >> m;
    mn = 110;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            int x;
            cin >> x;
            sum += x;
            mn = min(mn, x);
        }
    }
    cout << sum - mn * n * m << "\n";
}

int main() {
    ios_base::sync_with_stdio(0);
    int t = 1;
    //cin >> t;
    while (t--) {
        solve();
    }
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll a,b;
    cin>>a>>b;
    double ans=(double)a*b;
    ans=(double)ans/100;
    cout<<setprecision(10)<<ans<<"\n";
}

//   PIGMEISTER™   //

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

#define ll long long
#define ld long double
#define sidha(i,x,n) for(ll i=(ll)(x);i<(ll)(n);++i)
#define ulta(i,x,n) for(ll i=(ll)(x);i>=(ll)(n);--i)
#define sab(a) a.begin(),a.end()
#define bas(a) a.rbegin(),a.rend()
#define test ll _;cin>>_;while(_--)
#define jaldi ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
//#define MAX 100005
#define PI (ld)3.141592653589793238
#define MOD LLONG_MAX
//#define MOD (ll)1000000007
//#define MOD (ll)998244353

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

    ld a, b;
    cin >> a >> b;
    cout << b * (ld)(a / (ld)100);

    return 0;
}


//#include<bits/stdc++.h>
#include<map>
#include<queue>
#include<time.h>
#include<limits.h>
#include<cmath>
#include<ostream>
#include<iterator>
#include<set>
#include<stack>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define endl '\n'
#define rep_1(i,m,n) for(int i=m;i<=n;i++)
#define mem(st) memset(st,0,sizeof st)
//namespace first_space
//{
//	int a=10;
//	void func()
//	{
//		cout << "Inside first_space" << endl;
//	}
//}
int read()
{
	int res=0,ch,flag=0;
	if((ch=getchar())=='-')             //判断正负
		flag=1;
	else if(ch>='0'&&ch<='9')           //得到完整的数
		res=ch-'0';
	while((ch=getchar())>='0'&&ch<='9')
		res=res*10+ch-'0';
	return flag?-res:res;
}

typedef long long ll;
typedef pair<int,int> pii;
typedef unsigned long long ull;
typedef pair<double,double> pdd;
const int inf = 0x3f3f3f3f;
void solve()
{
	int a,b,c;
	cin>>a>>b>>c;
	if(a*a+b*b<c*c)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
}
signed main()
{
	int t=1;
	while(t--)
		solve();
	return 0;
}

#pragma region
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;         // long long と int64_t は同じ
const int INF = 0x3fffffff; // 10^9 より少し大きい
#pragma endregion

ll point (map<ll, ll> f)
{
    ll a = 0;

    for (auto x : f)  a += x.first * pow(10, x.second);

    return a;
}

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

    map<ll, ll> s;
    map<ll, ll> t;
    map<ll, ll> remain;

    for (int i = 1; i <= 9; i++) {
        s[i] = 0, t[i] = 0, remain[i] = K;
    }

    for (int i = 0; i <= 3; i++) {
        int a = S[i] - '0';
        s[a]++;
        remain[a]--;

        a = T[i] - '0';
        t[a]++;
        remain[a]--;
    }

    ll win = 0;

    for (int i = 1; i <= 9; i++) {
        for (int j = 1; j <= 9; j++) {
            if (i == j) {
                map<ll, ll> s_ = s, t_ = t;
                s_[i]++, t_[i]++;

                if (point(s_) > point(t_)) {
                    ll p = point(s_), q = point(t_);
                    win += remain[i] * (remain[i] - 1);
                }
            }

            if (i != j) {
                map<ll, ll> s_ = s, t_ = t;
                s_[i]++, t_[j]++;

                if (point(s_) > point(t_)) {
                    ll p = point(s_), q = point(t_);
                    win += remain[i] * remain[j];
                    }
            }
        }
    }

    const ll total = 9 * K - 8;
   // double p = double(win) / total / (total - 1);
    cout << double(win) / total / (total - 1) << endl;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
#include<cassert>
#include<set>
#include<complex>
#include<numeric>
#include<functional>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
    for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
    for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){
    if(vec_n==-1)vec_n=vec_s.size();
    for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){
    if(vec_n==-1)vec_n=vec_s.size();
    for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}

string sa;
string s="RSP";
int t[222][222];

int main(){
    int n,m;
    int i,j,k;
    int a,b,c;
    cin>>n>>m;
    cin>>sa;
    for(i=0;i<n;i++){
        if(sa[i]=='R')t[0][i]=0;
        if(sa[i]=='S')t[0][i]=1;
        if(sa[i]=='P')t[0][i]=2;
    }
    for(i=0,a=1;i<m;i++,a*=2){
        a%=n;
        for(j=0;j<n;j++){
            b=t[i][j],c=t[i][(j+a)%n];
            if((b+1)%3==c)t[i+1][j]=b;
            else t[i+1][j]=c;
        }
    }
    cout<<s[t[m][0]]<<endl;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pi;
typedef vector<ll> vi;
typedef vector<pi> vpi;
typedef long double ld;
const int inf = 1e9 + 7;
const int mod = 1e9 + 7;
const int maxn = 1e6 + 3;
#define block 555
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define rep(i, a, b) for(int i = a; i < b; i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define lb lower_bound
#define ub upper_bound
#define fact(n) rep(i, 1, n+1)ft.pb((ft[i-1]*i)%mod);
#define mod_in(a) exp(a, mod-2)
#define ncr(n, r) ((ft[n]*mod_in((ft[r]*ft[(n)-(r)])%mod))%mod)
#define deb(x) cout << #x << " " << x << endl;
#define flash ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
ll prime[100002];
ll exp(ll a,ll b);
void sieve(ll n);
ll gcd(ll a ,ll b);
ll countdigit(ll n);
ll check(string str);
vector<ll>ft;

void solve(){
    ll n,a,b;
    cin >> n >> a >> b;
    cout << n -a + b <<endl;

}
int main()
{
    flash;
    ll t=1;
    //ft.pb(1);
    //fact(10000001);
    //cin >> t;
    while(t--) {
        solve();
    }
}

//
//
//
//
//
// IMPORTANT FUNCTIONS
ll exp(ll a, ll b) {
	int res=1;
	while(b) {
		if(b&1)
			res=(res*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}
	return res%mod;
}
ll gcd(ll a,ll b){
    if(a==0)return b;
    return gcd(b%a,a);
}
void sieve(ll n) {
    for(ll i=0;i<=n;i++) {
        prime[i]=1;
    }
    prime[0]=0;prime[1]=0;
    for(ll i=2;i<=n;i++) {
        if(prime[i]==1) {
            for(ll j=2;i*j<=n;j++) {
                prime[i*j]=0;
            }
        }
    }
}
ll countdigit(ll  n)
{
    return floor(log10(n) + 1);
}
ll check(string str)
{
    ll l = 0;
    ll h = str.size() - 1;
    while (h > l)
    {
        if (str[l++] != str[h--])
        {
            return 0;
        }
    }
    return 1;
}


#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 998244353;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;

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

int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

struct mint{
    ll x;
    constexpr mint(long long x = 0) : x((x % MOD + MOD) % MOD) {}
    constexpr mint operator-() const{
        return mint(-x);
    }
    constexpr mint& operator+=(const mint& a){
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    constexpr mint& operator-=(const mint& a){
        if ((x += MOD - a.x) >= MOD) x -= MOD;
        return *this;
    }
    constexpr mint& operator*=(const mint& a){
        (x *= a.x) %= MOD;
        return *this;
    }
    constexpr mint operator+(const mint& a) const{
        mint res(*this);
        return res += a;
    }
    constexpr mint operator-(const mint& a) const{
        mint res(*this);
        return res -= a;
    }
    constexpr mint operator*(const mint& a) const{
        mint res(*this);
        return res *= a;
    }
    constexpr 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
    constexpr mint inv() const{
        return pow(MOD - 2);
    }
    constexpr mint& operator/=(const mint& a){
        return (*this) *= a.inv();
    }
    constexpr mint operator/(const mint& a) const{
        mint res(*this);
        return res /= a;
    }
};
istream& operator>>(istream& is, mint& a) {return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) {return os << a.x;}

mint modpow(mint a, ll b){
    if(b == 0) return 1;
    else if(b % 2 == 0){
        mint d = modpow(a, b / 2);
        return d * d;
    }
    else{
        return a * modpow(a, b - 1);
    }
}

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

    int h, w; cin>>h>>w;
    vector<string> s(h);
    for(int i=0; i<h; i++) cin>>s[i];

    vector<set<char>> color(h + w - 1);
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            color[i + j].emplace(s[i][j]);
        }
    }

    mint ans = 1;
    for(int i=0; i<h+w-1; i++){
        if(color[i].size() == 1 && color[i].count('.')) ans *= 2;
        if(color[i].count('R') && color[i].count('B')) ans *= 0;
    }

    cout << ans << endl;

    return 0;
}

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

#define rep(i,n) for(int i=0;i < (n);i++)
#define rep2(i, s, n) for (int i = (s); i < (n); i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;

const ll MOD=1000000007ll;
const int MAX=5100000;

using namespace std;

// aよりもbが大きいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}

int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    for(int i=0;i<a;i++){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    for(int i=0;i<a;i++){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

ll fact[MAX], fact_inv[MAX];

ll power(ll a, ll b){
	ll res=1;
	while(b>0){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}

// nCr
ll comb(ll n, ll r){
	ll t=1000000;
	fact[0]=1;
	    for(int i=0;i<t;i++){ fact[i+1]=fact[i]*(i+1)%MOD;}
	fact_inv[t]=power(fact[t], MOD-2);
	for(int i=0;i<t;i++){ fact_inv[i]=fact_inv[i+1]*(i+1)%MOD;}
	return (fact[n]*fact_inv[r])%MOD*fact_inv[n-r]%MOD;
}

ll i,j,k,tmp;
ll ans = 0;

int main()
{
	cin.tie(0);	ios::sync_with_stdio(false);
  ll N,S,D; cin >> N >> S >> D;
  rep(i,N){
    ll X,Y; cin >> X >> Y;
    if(X < S && Y > D){cout << "Yes" << endl; return 0;}
  }
  cout << "No" << endl;
  return 0;
}


#include <algorithm>
#include <array>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <utility>
#include <vector>
#include <stack>
using namespace std;
using ll = long long int;
// fast IO
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
////////// 	Template structure for debugging
#define tr(...) trace(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void trace(const char* name, Arg1&& arg1){
  cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void trace(const char* names, Arg1&& arg1, Args&&... args){
  const char *comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " | ";
  trace(comma + 1, args...);
}
#define print(...) pr(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void pr(const char* name, Arg1&& arg1){
  cout << arg1 << endl;
}
template <typename Arg1, typename... Args>
void pr(const char* names, Arg1&& arg1, Args&&... args){
  const char *comma = strchr(names + 1, ',');
  cout << arg1 << " ";
  pr(comma + 1, args...);
}
void printV(vector<int> &arr)
{
	cout << "Vector : ";
	for(int i=0;i<arr.size();i++)
		cout << arr[i] << " \n"[ i == arr.size()-1 ];
}
void printV(vector<long long> &arr)
{
	cout << "Vector : ";
	for(int i=0;i<arr.size();i++)
		cout << arr[i] << " \n"[ i == arr.size()-1 ];
}
void printA(int arr[], int n) {
  cout << "Array : ";
  for (int i = 0; i < n; i++)
	cout << arr[i] << " \n"[i == n - 1];
}

/////////////////////////////////////////////////////////////////////////////
////////////////////// DO NOT TOUCH BEFORE THIS LINE ////////////////////////
/////////////////////////////////////////////////////////////////////////////

ll x, y;
map<ll, ll> m;
ll ans = 1e18;
ll find(ll target, ll curr){
	if(curr == target)return 0;
	if(m.count(curr)) return m[curr];
	m[curr] = abs(curr - target);
	ll &ans = m[curr];
	if(curr == 1)return ans;
	if(curr % 2 == 0)ans = min(1 + find(target, curr/2), ans);
	else ans = min(ans,1 + min(find(target, curr + 1), find(target, curr - 1)));
	return ans;
}
void solve(int tc = 1){
	cin >> x >> y;
	cout << find(x, y) << endl;
}

int main(){
	IOS;
	int tt = 1;
	//cin >> tt;
	while(tt--)solve();
}

#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-12;

//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 >> M;
	if (N >= M) {
		cout << N - M << endl;
		return 0;
	}
	long long int ans = MOD*MOD;
	for (int i = 0; i <= 62; i++) {
		if ((N << i) > 4e18)break;
		long long int dif = abs((N << i) - M);
		long long int cnt = i + dif / (1LL << i);
		dif %= (1LL << i);
		vector<vector<int>>dp(i + 2, vector<int>(3, MOD));
		dp[0][1] = 0;
		for (int j = 0; j <= i; j++) {
			for (int k = 0; k < 3; k++) {
				long long int b = dif >> j & 1;
				long long int st = b + k - 1;
				if (st == -1) {
					dp[j + 1][0] = min(dp[j + 1][0], dp[j][k] + 1);
					dp[j + 1][1] = min(dp[j + 1][1], dp[j][k] + 1);
				}
				else if (st == 0) {
					dp[j + 1][1] = min(dp[j + 1][1], dp[j][k]);
				}
				else if (st == 1) {
					dp[j + 1][1] = min(dp[j + 1][1], dp[j][k] + 1);
					dp[j + 1][2] = min(dp[j + 1][2], dp[j][k] + 1);
				}
				else if (st == 2) {
					dp[j + 1][2] = min(dp[j + 1][2], dp[j][k]);
				}
			}
		}
		ans = min(ans, cnt + dp[i + 1][1]);
	}
	cout << ans << endl;
}


#include<bits/stdc++.h>
#define ll long long int
using namespace std;
const int N = 51;
ll dp[N][2], vis[N][2];
ll repx[N], a[N];
ll n, x;
// question is we have to find number A such that (x+A) has no common coin with A
// i represent ith type of coin and f represent we have carry or not from previous
ll fun(int i, int f) {
    // if f == 1 then we get carry for i-1 to ith bit
    // if f == 0 then we don't get any carry for ith from back
    if(i == n-1) return 1;

    // if we already know ans for current state then we return that directly
    if(vis[i][f] == 1) return dp[i][f];

    vis[i][f] = 1;

    // cur-1 represent in any representation maximum number of coin, we can take of that type
    int cur = a[i+1]/a[i];

    // repx[i] + f == cur it means all the coin of ith type change
    // in (i+1)th type we genrate a carry for i+1 th bit
    if(cur == repx[i] + f)  {
        // We can't put any bit here in A think why
        dp[i][f] = fun(i+1, 1);
    }
    else {
        // if there is some coin of ith type or we get any carry from previous in (x+A)
        // then  there is two way to take coin of ith type in A
        // 1st we take as much coin such that in (x+A) there are total number of coin of ith type
        // becomes equal to cur so that we can change ith type of coin in (x+A) to (i+1)th type  coin
        // this is same that we get carry from previous
        if(repx[i] + f > 0) {
            dp[i][f] = fun(i+1, 1);
        }
        //2nd we don't put any coin of ith type in A
        dp[i][f] += fun(i+1, 0);
    }
    return dp[i][f];
}

void solve() {
    cin >> n >> x;
    for(int i = 0; i < n; i++)
        cin >> a[i];
    for(int i = n-1; i >= 0; i--) {
        repx[i] = x/a[i];
        x %= a[i];
    }
    // at 0 there is no previous carry
    cout << fun(0, 0) << endl;
}

int main()
{
	solve();
}

#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;}

ll dp[1005][1005];
ll A[1005], B[1005];

int main2() {
  int N = nextLong();
  int M = nextLong();
  REP(i, N) A[i] = nextLong();
  REP(i, M) B[i] = nextLong();

  const ll INF = 1LL << 61;
  REP(i, N+1) REP(j, M+1) dp[i][j] = INF;

  dp[0][0] = 0;
  REP(i, N+1) {
    REP(j, M+1) {
      chmin(dp[i+1][j], dp[i][j] + 1);
      chmin(dp[i][j+1], dp[i][j] + 1);
      chmin(dp[i+1][j+1], dp[i][j] + (A[i] == B[j] ? 0 : 1));
    }
  }

  ll ans = dp[N][M];
  cout << ans << endl;
  return 0;
}

int main() {

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


#include <iostream> // cout, endl, cin
#include <vector> // vector
using namespace std;

int main() {

	int N, M;
	cin >> N >> M;

	vector<int> A(M), B(M);
	for (int i = 0; i < M; i++) {
		cin >> A.at(i) >> B.at(i);
	}

	int K;
	cin >> K;

	vector<int> C(K), D(K);
	for (int i = 0; i < K; i++) {
		cin >> C.at(i) >> D.at(i);
	}

	int K2 = 1 << K;
	int ans = 0;

	for (int s = 0; s < K2; s++) {

		vector<int> dish(N + 1);

		for (int i = 0; i < K; i++) {
			if ((s >> i) & 1) {
				dish.at(D.at(i))++;
			}
			else {
				dish.at(C.at(i))++;
			}
		}

		int cnt = 0;

		for (int i = 0; i < M; i++) {
			if (dish.at(A.at(i)) == 0) {
				continue;
			}
			if (dish.at(B.at(i)) == 0) {
				continue;
			}
			cnt++;
		}
		ans = max(ans, cnt);
	}
	cout << ans << endl;
}

#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define ll long long
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define vi vector<int>
using namespace std;
const int INF = 1001001001;
const int MOD = 1e9+7;
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(b<a){ a=b; return 1; } return 0; }
int solve(){
  cin.tie(0), ios::sync_with_stdio(false);
  int n,m; cin >> n >> m;
  vi a(m),b(m); rep(i,m) cin >> a[i] >> b[i];
  int k; cin >> k;
  vi c(k),d(k); rep(i,k) cin >> c[i] >> d[i];
  int ans = 0;
  rep(bit,1<<k){
    vi table(n+1);
    rep(i,k){
      if(bit>>i&1){
        table[c[i]]++;
      }else{
        table[d[i]]++;
      }
    }
    int res = 0;
    rep(i,m) if(table[a[i]] && table[b[i]]) res++;
    chmax(ans,res);
  }
  return ans;
}
int main(){
  cout << solve() << endl;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
typedef long double ld;
#define pb push_back
#define MAXN 100005
#define INF (ll)1e18
#define mod 1000000007
//#define mod 998244353
#define endl '\n'
#define level 20
ll cc=0;

void boost()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}

vector <pair<ll,pair<ll,ll>>> V[MAXN];
ll dis[MAXN],vis[MAXN];
priority_queue<pair<ll,ll>,vector<pair<ll,ll>>,greater<pair<ll,ll>>> pq;

int main()
{
    boost();

    ll i,j,k,n,t,c=0,l,r,x,y,n1,mask;
    ll ans,h,z,m,u,v,q,mm,w,mx,d,mid;
    ld f;

    cin>>n>>m>>l>>r;

    for(i=0;i<=n;i++)
    {
        dis[i]=INF;
        vis[i]=0;
    }

        for(i=1;i<=m;i++)
        {
            cin>>x>>y>>z>>k;
            V[x].pb(make_pair(y,make_pair(z,k)));
            V[y].pb(make_pair(x,make_pair(z,k)));
        }

        dis[l]=0;
        pq.push(make_pair(dis[l],l));

    while(!pq.empty())
    {
        u=pq.top().second;
        pq.pop();

        if(vis[u]==0)
        {
            vis[u]++;

        for(auto p: V[u])
        {
            v=p.first;
            k=p.second.first;
            z=p.second.second;

            w=(dis[u]%z);

            if(w!=0)
            {
                w=z-w;
            }

            k+=w;

            if((dis[v]>(dis[u]+k))&&(vis[v]==0))
            {
                dis[v]=dis[u]+k;
                pq.push(make_pair(dis[v],v));
            }
        }

    }

    }

    if(vis[r]==0)
    {
        cout<<-1<<endl;
    }

    else
    {
        cout<<dis[r]<<endl;
    }

return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repp(i, st, en) for (ll i = (ll)st; i < (ll)(en); i++)
#define repm(i, st, en) for (ll i = (ll)st; i >= (ll)(en); i--)
#define all(v) v.begin(), v.end()
void chmax(ll &x, ll y) {x = max(x,y);}
void chmin(ll &x, ll y) {x = min(x,y);}
void Yes() {cout << "Yes" << endl; exit(0);}
void No() {cout << "No" << endl; exit(0);}
template<class in_Cout> void Cout(in_Cout x) {cout << x << endl; exit(0);}

const ll inf = 1e18;
const ll mod = 1e9 + 7;

struct edge {ll to, cost, k;};

ll N, M, X, Y;

ll dijkstra(ll st, ll en, vector<vector<edge>> G) {
    vector<ll> dist(N,inf);
    dist[st] = 0LL;
    priority_queue<pair<ll,ll>,vector<pair<ll,ll>>,greater<pair<ll,ll>>> que;
    que.push({0,st});
    while (que.size()) {
        pair<ll,ll> p = que.top();
        que.pop();
        ll now = p.second, d = p.first;
        if (dist[now]<d) continue;
        for (auto e : G[now]) {
            ll to = e.to, cost = e.cost, k = e.k;
            ll dt = (k-(dist[now]%k))%k;
            ll nd = dist[now] + dt + cost;
            if (dist[to]<=nd) continue;
            dist[to] = nd;
            que.push({nd,to});
        }
    }
    ll res = dist[en];
    if (res==inf) res = -1LL;
    return res;
}

int main() {
    cin >> N >> M >> X >> Y;
    X--; Y--;
    vector<vector<edge>> G(N);
    rep(i,M) {
        ll a, b, t, k; cin >> a >> b >> t >> k;
        a--; b--;
        G[a].push_back({b,t,k});
        G[b].push_back({a,t,k});
    }

    ll ans = dijkstra(X,Y,G);

    cout << ans << endl;
}


#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

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

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};

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

	vector<string> ans;
	ans.push_back("AB");

	rep(i, N-1) {
		vector<string> n_ans;
		for(string s: ans) {
			n_ans.push_back(s + s);
		}

		for(string s: ans) {
			string rev = "";
			for(char ch: s) {
				if(ch == 'A') {
					rev += "B";
				} else {
					rev += "A";
				}
			}
			n_ans.push_back(s + rev);
		}

		string s = "";
		rep(i, n_ans[0].size()/2) s += "A";
		rep(i, n_ans[0].size()/2) s += "B";
		n_ans.push_back(s);

		swap(ans, n_ans);
	}
	cout << ans.size() << endl;
	for(auto s: ans) cout << s << endl;
}

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

int main()
{
    int n;
    cin >> n;
    vector<bool> b(2);
    b[0] = true, b[1] = false;
    set<vector<bool>> st0;
    st0.insert(b);
    for(int c = 2; c <= n; c++){
        set<vector<bool>> st1;
        int l = (1 << (c - 1));
        for(auto itr = st0.begin(); itr != st0.end(); itr++){
            vector<bool> b = *itr;
            b.resize(l * 2);
            for(int i = l - 1; i >= 0; i--){
                b[i * 2 + 1] = b[i * 2] = b[i];
            }
            st1.insert(b);
            if(b[1] == b[2]) continue;
            for(int i = 0; i < l / 2; i++){
                swap(b[i * 4 + 1], b[i * 4 + 2]);
            }
            st1.insert(b);
            for(int i = 0; i < l / 2; i++){
                swap(b[i * 4 + 2], b[i * 4 + 3]);
            }
            st1.insert(b);
        }
        swap(st0, st1);
    }
    cout << (int)st0.size() << endl;
    for(auto itr = st0.begin(); itr != st0.end(); itr++){
        for(bool e : *itr){
            if(e) cout << 'A';
            else cout << 'B';
        }
        cout << endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define ll long long
#define int long long int
#define pb push_back
#define mp make_pair
#define pll pair<ll, ll>
#define vll vector<ll>
#define mll map<ll, ll>
#define setbits(x) __builtin_popcountll(x)
#define md (ll)1e9 + 7
#define inf 1e18
#define ps(x, y) fixed << setprecision(y) << x
#define f(i, j, n) for (ll i = j; i < n; i++)
#define r(i, j, n) for (ll i = n - 1; i >= j; i--)
void solve()
{
    ll n,x;
    cin>>n>>x;
    string s;
    cin>>s;
    for(auto i : s){
        i=='o'?x++:x--,x=max(0ll,x);
    }
    cout<<x;
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("inpput.txt", "r", stdin); //freopen("op.txt", "w", stdout);
#endif
    ll test_cases = 1;
    //cin >> test_cases;
    for (ll t = 1; t <= test_cases; t++)
        solve(),cout<<"\n";
    //cerr<<"Time : "<<1000*((double)clock())/(double)CLOCKS_PER_SEC<<"ms\n";
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 1e5 + 9, M = 1e6 + 9, OO = 0x3f3f3f3f;
ll llOO = 0x3f3f3f3f3f3f3f3f;

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

    int n, x;   cin >> n >> x;
    string s;   cin >> s;
    for(int i = 0;i < n;i++){
        if(s[i] == 'o') x++;
        else x = max(x - 1, 0);
    }

    cout << x;
}


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

#define INF 1000000000
#define MAXN 300010

long long n;
long long a[MAXN];
map<long long, long long> qt;

int main() {
    scanf("%lld", &n);
    long long i, j;
    for (i=1; i<=n; i++) {
        scanf("%lld", &a[i]);
    }

    long long ans = 0;
    for (i=1; i<=n; i++) {
        map<long long, long long>::iterator iter;
        for (iter=qt.begin(); iter!=qt.end(); iter++) {
            ans += (a[i]-iter->first)*(a[i]-iter->first)*iter->second;
        }
        qt[a[i]]++;
    }

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

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

#define int long long
#define endl "\n"
#define MOD 1000000007
#define INF LLONG_MAX
#define MINF LLONG_MIN
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
#define vi vector<int>
#define vvi vector<vector<int>>
#define pii pair<int, int>
#define mii map<int, int>
#define si set<int>

int pow(int x, int y, int mod) {
    int temp;
    if (y == 0)
        return 1;

    temp = (pow(x, y / 2, mod)) % mod;

    if (y % 2 == 0)
        return (temp * temp) % mod;
    else
        return (((x * temp) % mod) * temp) % mod;
}

void solve(int tno) {

    int n; cin >> n;
    int prev = 0;
    int ans = 0;

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

        int a; cin >> a;

        ans += (n - 1) * a * a;
        ans -= 2 * a * prev;
        prev += a;
    }

    cout << ans << endl;
}

int32_t main() {

    FASTIO

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

    int t;
    // cin >> t;
    t = 1;
    for (int i = 1; i <= t; i ++)
        solve(i);
}


#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mp make_pair
#define pb push_back
#define int int64_t
#define rep(n) for(ll i=0;i<n;i++)
#define rrep(n) for(ll i=n-1;i>=0;i--)
#define inF freopen("input.in", "r", stdin);
#define outF freopen("output.in", "w", stdout);
#define endl '\n'
#define MOD 1000000007
#define mm(arr) memset(arr, 0, sizeof(arr))
#define F first
#define S second
#define scanArray(a,n) for(int i = 0; i < n; i++){cin >> a[i];}
#define coutArray(a,n) for(int i = 0; i < n; i++){cout << a[i] << " ";};cout << endl;
#define ld long double
#define PI 3.141592653589793238
#define srt(v) sort(v.begin(),v.end())
#define all(v) v.begin(), v.end()

int32_t main(){
    FAST
    int t=1;
    //cin >> t;
    while(t--){
        int n,m; cin >> n >> m;
        int a[n][m];
        int x = 1e9;
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                cin >> a[i][j];
                x=min(x,a[i][j]);
            }
        }
        int sum=0;
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                sum+=abs(a[i][j]-x);
            }
        }
        cout << sum << endl;
    }
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main()
{
    int h,w ;
    cin >> h >> w;
    vector<int> a(h*w);
    int m = 1000;
    for(int i =0; i<(h*w); i++)
    {
        cin >> a[i];
        if(m > a[i])
            m=a[i];
    }
    int t = 0;
    for(int i =0; i<(h*w); i++)
    {
        t+= a[i]-m;
    }
    cout << t << endl;
}


#include <iostream>
#include <bits/stdc++.h>
#include<string>
using namespace std;
#define boost ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);

long long n,m;
string s,st;
std::vector<pair<long long,long long>> a,b;
void get_values()
{
    long long x,y;
    std::cin >> n;
    for(int i=0;i<n;i++)
    {
        std::cin >> x >> y;
        a.push_back({x,i+1});
        b.push_back({y,i+1});
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    //std::cin >> s;
    //n=s.length();
}

void solve()
{
    long long i,j,t,ans=0,x,y,xp,yp;
    x=a[0].first;y=b[0].first;
    xp=a[0].second;yp=b[0].second;
    if(xp!=yp)
        std::cout << max(y,x) << std::endl;
    else
    {
        long long x1,y1;
        x1=a[1].first;y1=b[1].first;
        ans=x+y;
        ans=min(ans,max(x1,y));
        ans=min(ans,max(x,y1));
        std::cout << ans << std::endl;
    }
}

int main() {
    boost;
    get_values();
    solve();
    return 0;
}

/*
ID: Λινδα
LANG: C++
TASK: abc194a
*/
#include <stdio.h>
#include <algorithm>
using namespace::std;
int read(){char c=getchar();int t=0,f=1;while(c<'0'||c>'9'){if(c=='-'){f=-1;}c=getchar();}while(c>='0'&&c<='9'){t=(t<<1)+(t<<3)+(c^48);c=getchar();}return t*f;}
void write(int x){char ch[50];int l=0;if(x<0){putchar('-');x=-x;}do{ch[l++]=x%10+'0';x=x/10;}while(x);while(l){putchar(ch[--l]);}}
struct wrkr
{
	int id,tm;
};
bool cmpr(wrkr x,wrkr y)
{
	return x.tm<y.tm;
}
int main()
{
//	freopen("main.in","r",stdin);
//	freopen("main.out","w",stdout);
//	freopen("main.err","w",stderr);
	int i,n=read();
	wrkr a[1004],b[1004];
	for(i=0;i!=n;++i)
	{
		a[i].tm=read();
		a[i].id=i;
		b[i].tm=read();
		b[i].id=i;
	}
	sort(a,a+n,cmpr);
	sort(b,b+n,cmpr);
	if(a[0].id==b[0].id)
	{
		write(min(a[0].tm+b[0].tm,min(max(a[0].tm,b[1].tm),max(a[1].tm,b[0].tm))));
	}
	else
	{
		write(max(a[0].tm,b[0].tm));
	}
	putchar('\n');
//	fclose(stdin);
//	fclose(stdout);
//	fclose(stderr);
	return 0;
}


#include<iostream>
using namespace std;

int main()
{
	int n;
	cin >> n;
	cout << (n + 100) / 100 * 100 - n << endl;
	return 0;
}

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

// AtCoder
// #include <atcoder/all>
// using namespace atcoder;

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...)
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b)-1, i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
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; }
#define fls(x) (64 - __builtin_clzll(x))
#define pcnt(x) __builtin_popcountll(x)
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s; cin >> s;
    int a = 0;
    rep (i, s.size() - 3) {
        if (s.substr(i, 4) == "ZONe") ++a;
    }
    cout << a << "\n";
    return 0;
}


#include<bits/stdc++.h>
#include <iterator>
#include <iostream>
#include <numeric>
#include <math.h>
#define ll long long
#define ull long
#define mpa make_pair
#define pb push_back
#define ff first
#define pii pair<ll,ll>
#define dd double
#define trace(x) cerr << #x << " : " << x << endl
#define ss second
#define boost ios_base::sync_with_stdio(0)
#define forp(i,a,b) for(ll i=a;i<=b;i++)
#define rep(i,n)    for(ll i=0;i<n;++i)
#define ren(i,n)    for(ll i=n-1;i>=0;i--)
#define forn(i,a,b) for(ll i=a;i>=b;i--)
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c).begin()) i = (c).begin(); i != (c).end();
#define sc(x) scanf("%lld",&x)
#define clr(x,val) memset(x,val,sizeof(x))
#define pr(x) printf("%lld\n",x)
#define pdd pair<dd,dd>
#define read_arr(a,n) for(ll i=1;i<=n;i++)cin>>a[i];
#define init_arr(a,n) for(ll i=1;i<=n;i++)a[i]=n-i+1;
#define prec(x) cout<<fixed<<setprecision(x)
#define fre freopen("input.txt","r",stdin),freopen("output.txt","w",stdout)
#define arr array
using namespace std;

void solve(){
	string s;
	cin>>s;
	for(ll i=1;i<=3;i++){
		cout<<s[i%3];
	}
}

int main(){

    boost;

    ll t=1;

	while(t--){
		solve();
	}

}

#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; ++i)
#define rep2(i, a, b) for(ll i = a; i <= b; ++i)
#define rep3(i, a, b) for(ll i = a; i >= b; --i)
#define all(c) begin(c), end(c)
#define SUM(v) accumulate(all(v), 0LL)
#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))
using namespace std;
//using namespace atcoder;
using ll = long long;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;
typedef vector<vector<int> > Graph;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a >= b) { a = b; return 1; } return 0; }
const ll INF = 1e18;

#define debug(v) cout<<#v<<": ",prt(v);
template <typename A,typename B>
inline void prt(pair<A,B> p){cout<<"("<<p.first<<", "<<p.second<<")\n";}
template <typename A,typename B,typename C>
inline void prt(tuple<A,B,C> p){cout<<"("<<get<0>(p)<<", "<<get<1>(p)<<", "<<get<2>(p)<<")\n";}
inline void prt(bool p){if(p)cout<<"True"<<'\n';else cout<<"False"<<'\n';}
template <typename T>
inline void prt(vector<T> v){cout<<'{';for(ll i=0;i<v.size();i++){cout<<v[i];if(i<v.size()-1)cout<<", ";}cout<<'}'<<'\n';}
template<typename T>
inline void prt(vector<vector<T> >& vv){ for(const auto& v : vv){ prt(v); } }
template <typename T>
inline void prt(deque<T> v){cout<<'{';for(ll i=0;i<v.size();i++){cout<<v[i];if(i<v.size()-1)cout<<", ";}cout<<'}'<<'\n';}
template <typename A,typename B>
inline void prt(map<A,B> v){cout<<'{';ll c=0;for(auto &p: v){cout<<p.first<<":"<<p.second;c++;if(c!=v.size())cout<<", ";}cout<<'}'<<'\n';}
template <typename A,typename B>
inline void prt(unordered_map<A,B> v){cout<<'{';ll c=0;for(auto &p: v){cout<<p.first<<":"<<p.second;c++;if(c!=v.size())cout<<", ";}cout<<'}'<<'\n';}
template <typename T>
inline void prt(set<T> v){cout<<'{';for(auto i=v.begin();i!=v.end();i++){cout<<*i;if(i!=--v.end())cout<<", ";}cout<<'}'<<'\n';}
template <typename T>
inline void prt(multiset<T> v){cout<<'{';for(auto i=v.begin();i!=v.end();i++){cout<<*i;if(i!=--v.end())cout<<", ";}cout<<'}'<<'\n';}

/*
1 indexの分引く
2 Bを番号ごとqueueに入れてマッチングする
3 転倒数を求める

*/
template<typename T> class BIT {
private:
	int n;
	vector<T> bit;
public:
	// 0_indexed で i 番目の要素に x を加える
	void add(int i, T x){
		i++;
		while(i < n){
			bit[i] += x, i += i & -i;
		}
	}
	// 0_indexed で [0,i] の要素の和(両閉区間！！)
	T sum(int i){
		i++;
		T s = 0;
		while(i > 0){
			s += bit[i], i -= i & -i;
		}
		return s;
	}
	BIT(){}
	//初期値がすべて0の場合
	BIT(int sz) : n(sz+1), bit(n, 0){}
	BIT(const vector<T>& v) : n((int)v.size()+1), bit(n, 0){
		for(int i = 0; i < n-1; i++){
			add(i,v[i]);
		}
	}
	void print(){
		for(int i = 0; i < n-1; i++){
			cout << sum(i) - sum(i-1) << " ";
		}
		cout << "\n";
	}
	//-1スタート
	void print_sum(){
		for(int i = 0; i < n; i++){
			cout << sum(i-1) << " ";
		}
		cout << "\n";
	}
};

// u を昇順にソートするのに必要な交換回数(転倒数) (u は {0,..., n-1} からなる重複を許した長さ n の数列)
long long inv_count(const vector<ll>& u)
{
	int n = (ll)u.size();
	BIT<ll> bt(n);
	long long ans = 0;
	for(int i = 0; i < n; i++){
		ans += i - bt.sum(u[i]);
		bt.add(u[i], 1);
	}
	return ans;
}

int main(){
	ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	ll n;
	cin >> n;
	vector<ll>a(n),b(n);
	rep(i,n)cin>>a[i];
	rep(i,n)cin>>b[i];
	vector<ll>newb(n);
	map<ll,queue<ll> >mp;
	rep(i,n){
		newb[i]=b[i]-(n-1-i);
		ll newa = a[i]-(n-1-i);
		mp[newa].push(i);
	}
	vector<ll>tento(n);
	rep(i,n){
		if(mp[newb[i]].empty()){
			cout << -1 << endl;
			return 0;
		}
		tento[i]=mp[newb[i]].front();mp[newb[i]].pop();
	}
	ll ans = inv_count(tento);
	cout << ans << endl;

	return 0;
}


#include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>

#define all(v) begin(v), end(v)
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep2(i, n, m) for (ll i = n; i <= m; ++i)
#define rep3(i, n, m) for (ll i = n; i >= m; --i)

using namespace std;

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

template <class S> using pqg = priority_queue<S, vector<S>, greater<S>>;
template <class S> using pq  = priority_queue<S>;

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pi = pair<int,int>;
using pl = pair<ll, ll>;
using vpi = vector<pi>;
using vpl = vector<pl>;
using vvpi = vector<vpi>;
using vvpl = vector<vpl>;

const ll MOD = 1000000007;
const ll MAX = 500000;
const ll INF = 1000000000;
const ll INFLL = 1000000000000000000;

struct mint {
  ll x;

  mint(ll x = 0) : x((x % MOD + MOD) % MOD) {}
  mint operator+=(const mint& a) {
    x += a.x;
    if (x >= MOD) x -= MOD;
    return *this;
  }
  mint operator-=(const mint& a) {
    if (x < a.x) x += MOD;
    x -= a.x;
    return *this;
  }
  mint operator*=(const mint& a) {
    x = x * a.x % MOD;
    return *this;
  }
  mint operator/=(const mint& a) { return *this *= a.inv(); }
  mint operator+(const mint& a) const { return mint(*this) += a; }
  mint operator-(const mint& a) const { return mint(*this) -= a; }
  mint operator*(const mint& a) const { return mint(*this) *= a; }
  mint operator/(const mint& a) const { return mint(*this) /= a; }
  mint inv(void) const { return pow(MOD - 2); }
  mint pow(ll a) const {
    if (!a) return 1;
    mint t = pow(a >> 1);
    t *= t;
    if (a & 1) t *= (*this);
    return t;
  }
  friend ostream& operator<<(ostream& os, const mint& a) {
    os << a.x;
    return os;
  }
};

struct UnionFind {
  vector<int> parent, siz;

  UnionFind(int n) : parent(n), siz(n, 1) {
    for (int i = 0; i < n; ++i) parent[i] = i;
  }

  int root(int x) {
    if (parent[x] == x) return x;
    return parent[x] = root(parent[x]);
  }

  bool unite(int x, int y) {
    x = root(x);
    y = root(y);

    if (x == y) return false;

    if (siz[x] > siz[y]) swap(x, y);

    siz[y] += siz[x];
    parent[x] = y;

    return true;
  }

  int size(int x) {
    return siz[root(x)];
  }

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

int main(void) {

  int n;
  cin >> n;

  vi a(n);
  rep(i, n) cin >> a[i];

  int ans = 0;
  UnionFind uf(MAX);

  rep(i, n / 2) {
    if (uf.same(a[i], a[n-i-1]))
      continue;

    uf.unite(a[i], a[n-i-1]);
    ++ans;
  }

  cout << ans << endl;

  return (0);
}

#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
typedef long long ll;
using namespace std;
using P=pair<int,int>;
struct unionfind {
  vector<int> d;
  unionfind(int n=0): d(n,-1) {}
  int find(int x) {
    if (d[x] < 0) return x;
    return d[x] = find(d[x]);
  }
  bool unite(int x, int y) {
    x = find(x); y = find(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x,y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y);}
  int size(int x) { return -d[find(x)];}
};
int main()
{
    int n;
    cin>>n;
    vector<int> a(n);
    rep(i,n) cin>>a[i];
    int m=200000;
    unionfind d(m);
    rep(i,n/2+1) d.unite(a[i],a[n-1-i]);
    int ans=0;
    rep(i,m){
        if(d.find(i)!=i) continue;
        ans+=d.size(i)-1;
    }
    cout<<ans<<endl;
    return 0;
}


#include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#include <tuple>
#include <queue>
#include <vector>

// 距離、x座標、y座標
using vertex = std::tuple<int, int, int>;

std::pair<std::string, int> dijkstra(int, int, int, int);
void interact(int);
void modify_distance(const std::string &, int, int, int, int);
int rev(char);

const int dx[]{1, 0, -1, 0}, dy[]{0, 1, 0, -1};
const char dir[]{'D', 'R', 'U', 'L'};
constexpr int INVALID = -1;

// 道の長さ
int d_road[30][30][4];

// 文字を方向のインデックスに変換
int rev(char c)
{
    switch (c)
    {
    case 'D':
        return 0;
    case 'R':
        return 1;
    case 'U':
        return 2;
    case 'L':
        return 3;
    }
    abort();
}

// ダイクストラ法で最短経路を求める
std::pair<std::string, int> dijkstra(int si, int sj, int ti, int tj)
{
    // 距離の初期化
    int distance[30][30];
    for (int i = 0; i < 30; i++)
    {
        for (int j = 0; j < 30; j++)
        {
            distance[i][j] = 1e9;
        }
    }

    // ダイクストラ法
    std::priority_queue<vertex, std::vector<vertex>, std::greater<vertex>> q;
    q.emplace(0, si, sj);
    while (not q.empty())
    {
        auto [d0, x, y] = q.top();
        q.pop();
        if (d0 >= distance[x][y])
        {
            continue;
        }
        distance[x][y] = d0;
        if (x == ti and y == tj)
        {
            break;
        }
        for (int i = 0; i < 4; i++)
        {
            int d = d_road[x][y][i], x_next = x + dx[i], y_next = y + dy[i];
            if (d == INVALID or d0 + d >= distance[x_next][y_next])
            {
                continue;
            }
            q.emplace(d0 + d, x_next, y_next);
        }
    }

    // 経路復元
    std::string res;
    int x = ti, y = tj;
    while (x != si or y != sj)
    {
        for (int i = 0; i < 4; i++)
        {
            int d = d_road[x][y][i], x_prev = x + dx[i], y_prev = y + dy[i];
            if (d == INVALID)
            {
                continue;
            }
            if (distance[x][y] == distance[x_prev][y_prev] + d)
            {
                res.push_back(dir[(i + 2) % 4]);
                x = x_prev;
                y = y_prev;
                break;
            }
            assert(i != 3);
        }
    }
    std::reverse(res.begin(), res.end());
    return {res, distance[ti][tj]};
}

// 道の長さの補正
void modify_distance(const std::string &route, int error, int si, int sj, int query)
{
    const int n = route.size();
    error *= pow(0.9996, query) / n;
    int x = si, y = sj;
    for (int i = 0; i < n; i++)
    {
        int k = rev(route[i]);
        d_road[x][y][k] += error;
        if (d_road[x][y][k] <= 0)
        {
            d_road[x][y][k] = 1;
        }
        x += dx[k];
        y += dy[k];
        k = (k + 2) % 4;
        d_road[x][y][k] += error;
        if (d_road[x][y][k] <= 0)
        {
            d_road[x][y][k] = 1;
        }
    }
}

// クエリに応答
void interact(int query)
{
    int si, sj, ti, tj;
    std::cin >> si >> sj >> ti >> tj;
    auto [route, estimate] = dijkstra(si, sj, ti, tj);
    std::cout << route << std::endl;
    int response;
    std::cin >> response;
    modify_distance(route, response - estimate, si, sj, query);
}

int main()
{
    // 道路の長さの初期値
    for (int i = 0; i < 30; i++)
    {
        for (int j = 0; j < 30; j++)
        {
            for (int k = 0; k < 4; k++)
            {
                int i_next = i + dx[k], j_next = j + dy[k];
                if (i_next < 0 or 30 <= i_next or j_next < 0 or 30 <= j_next)
                {
                    d_road[i][j][k] = INVALID;
                }
                else
                {
                    d_road[i][j][k] = 1;
                }
            }
        }
    }

    // クエリに応答
    for (int query = 0; query < 1000; query++)
    {
        interact(query);
    }
    return 0;
}

#pragma warning(disable:6385)
#define _USE_MATH_DEFINES
#include <cassert>
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <chrono>
#include <fstream>
#include <array>
#include <set>
#include <map>

using namespace std;
using namespace chrono;

using ll = long long;
using uint = unsigned int;

#ifdef LOCAL
#define ASSERT_DEBUG
#endif
#ifdef ASSERT_DEBUG
void ASSERT(bool b)
{
	if (!b)
	{
		__debugbreak();
	}
	assert(b);
}
#else
void ASSERT(bool b) {}
#endif

class Point
{
public:
	int x;
	int y;

	Point() { x = 0; y = 0; }
	Point(int x, int y) { this->x = x; this->y = y; }

	Point operator + (const Point& pt) const
	{
		return Point(x + pt.x, y + pt.y);
	}
	Point operator - (const Point& pt) const
	{
		return Point(x - pt.x, y - pt.y);
	}

	bool Equals(const Point& pt) const
	{
		return x == pt.x && y == pt.y;
	}
	bool Equals(int x, int y) const
	{
		return this->x == x && this->y == y;
	}
};

unsigned int xorshift32()
{
	static int s = 7;
	s ^= (s << 13);
	s ^= (s >> 17);
	s ^= (s << 15);
	return s;
}

int main()
{
	for (int i = 0; i < 1000; i++)
	{
		int sx, sy, tx, ty;
		cin >> sy >> sx >> ty >> tx;

		if (sx < tx)
		{
			for (int j = 0; j < tx - sx; j++)
			{
				cout << "R";
			}
		}
		else if (sx > tx)
		{
			for (int j = 0; j < sx - tx; j++)
			{
				cout << "L";
			}
		}

		if (sy < ty)
		{
			for (int j = 0; j < ty - sy; j++)
			{
				cout << "D";
			}
		}
		else if (sy > ty)
		{
			for (int j = 0; j < sy - ty; j++)
			{
				cout << "U";
			}
		}

		cout << endl;
		cout.flush();

		int length;
		cin >> length;
	}
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define fi first
#define se second
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep0(i, n) for (ll i = 0; i <= (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (n); ++i)
#define rrep1(i, n) for (ll i = (n); i > 0; --i)
#define rrep0(i, n) for (ll i = (n); i >= 0; --i)
#define srep(i, s, t) for (ll i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define isin(x, l, r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)), x.end())
#define snuke srand((unsigned)clock() + (unsigned)time(NULL));
#define show(x) cerr << #x << " = " << x << endl;
#define PQ(T) priority_queue<T, v(T), greater<T>>
#define bn(x) ((1 << x) - 1)
#define dup(x, y) (((x) + (y)-1) / (y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
constexpr ll MAX = 200000;

int main()
{
    ll n, ans = 0;
    ll sum = 1e10;
    string k;
    cin >> n >> k;
    if (n == 1)
    {
        if (k.at(0) == '0')
            ans = sum;
        else
            ans = 2 * sum;
    }
    else
    {
        if (k.at(0) == '1' && k.at(1) == '1')
        {
            bool ok = true;
            rep(i, n)
            {
                if (i % 3 == 0)
                    if (k.at(i) != '1')
                        ok = false;
                if (i % 3 == 1)
                    if (k.at(i) != '1')
                        ok = false;
                if (i % 3 == 2)
                    if (k.at(i) != '0')
                        ok = false;
            }
            if (ok)
                ans = sum - (n + 2) / 3 + 1;
        }
        else if (k.at(0) == '1' && k.at(1) == '0')
        {
            bool ok = true;
            rep(i, n)
            {
                if (i % 3 == 0)
                    if (k.at(i) != '1')
                        ok = false;
                if (i % 3 == 1)
                    if (k.at(i) != '0')
                        ok = false;
                if (i % 3 == 2)
                    if (k.at(i) != '1')
                        ok = false;
            }
            if (ok)
                ans = sum - (n + 3) / 3 + 1;
        }
        else if (k.at(0) == '0' && k.at(1) == '1')
        {
            bool ok = true;
            rep(i, n)
            {
                if (i % 3 == 0)
                    if (k.at(i) != '0')
                        ok = false;
                if (i % 3 == 1)
                    if (k.at(i) != '1')
                        ok = false;
                if (i % 3 == 2)
                    if (k.at(i) != '1')
                        ok = false;
            }
            if (ok)
                ans = sum - (n + 4) / 3 + 1;
        }
        else
            ans = 0;
    }
    cout << ans << endl;
}

//#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;

//vector string deque break continue
#define forn(i, s, f) for (int i = (int)s; i < (int)f; i++)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define fs first
#define sc second
#define pf push_front
#define pb push_back
#define pop_f pop_front
#define pop_b pop_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()

#ifdef DEBUG
#else
    #define cerr if (false) cerr
#endif

template <typename T> istream& operator>>(istream& in, vector <T>& a) {for (auto& i : a) in >> i; return in;}
template <typename T> ostream& operator<<(ostream& out, vector <T>& a)  {for (auto& i : a) out << i << " "; return out;}
template <typename T, typename U> void chkmin(T& a, U b) {if (a > b) a = b;}
template <typename T, typename U> void chkmax(T& a, U b) {if (a < b) a = b;}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    cin >> a;
    map<int, int> mp;
    forn (i, 0, n) {
        mp[a[i]]++;
    }
    vector<vector<int>> boxes(k);
    for (auto [val, cnt] : mp) {
        int lst = 0;
        forn (i, 0, cnt) {
            boxes[lst].pb(val);
            lst = (lst + 1) % k;
        }
    }
    long long ans = 0;
    forn (i, 0, k) {
        vector<bool> used(boxes[i].size() + 1);
        for (int j : boxes[i])
            if (j < used.size())
                used[j] = true;
        forn (j, 0, sz(used)) {
            if (!used[j]) {
                ans += j;
                break;
            }
        }
    }
    cout << ans << "\n";
    return 0;
}


#include<iostream>
#include<cstdio>
using namespace std;
#define ll long long

int main()
{
    ll n;
    cin>>n;
    string s;
    cin>>s;
    ll i;
    ll pref[s.length()+1]={0};
    ll j;
    for(i=0;i<s.length();i++)
    {
        if(s[i]=='A')
        {
            pref[i+1]=pref[i]+6000;
        }
        else if(s[i]=='T')
        {
            pref[i+1]=pref[i]-6000;
        }
        else if(s[i]=='C')
        {
            pref[i+1]=pref[i]+1;
        }
        else
        {
            pref[i+1]=pref[i]-1;
        }
    }
    ll ans=0;
    for(i=0;i<=s.length();i++)
    {
        for(j=i+1;j<=s.length();j++)
        {
            if(pref[j]-pref[i]==0)
            {
                ans++;
            }
        }
    }
    cout<<ans<<"\n";
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007
bool isPrime[1000001];
ll power(ll a,ll b)
{
    ll result = 1;
    while(b>0)
    {
        if(b%2)
        {
            result = (a*result)%mod;
        }
        a = (a*a)%mod;
        b = b/2;
    }
    return result;
}
int gcd(int a,int b)
{
    if(b==0)
    {
        return a;
    }
    return gcd(b,a%b);
}
void sieve()
{
    memset(isPrime,1,sizeof(isPrime));
    isPrime[0] = isPrime[1] = 0;
    for(int i=2;i*i<=1000000;i++)
    {
        if(isPrime[i])
        {
            for(int j=i*i;j<=1000000;j+=i)
            {
                isPrime[j] = 0;
            }
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL),cout.tie(NULL);
    int t,n;
    t = 1;
    for(int i=0;i<t;i++)
    {
        int n;
        string s;
        cin>>n>>s;
        ll ans = 0;
        unordered_map <char,ll> mp;
        mp['A'] = 100000000000000;
        mp['T'] = -100000000000000;
        mp['C'] = 20000000000;
        mp['G'] = -20000000000;
        unordered_map <int,int> mpp;
        mpp[0] = 1;
        ll sum = 0;
        for(int i=0;i<n;i++)
        {
            sum+=mp[s[i]];
            mpp[sum]++;;
        }
        for(auto i = mpp.begin();i!=mpp.end();i++)
        {
            ans+=((i->second)*(i->second-1))/2;
        }
        cout<<ans;
    }
    return 0;
}


#include <cstdio>
#include <cmath>
#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <map>
#include <cassert>
#include <string>
#include <cstring>
#include <queue>

using namespace std;

#define rep(i,a,b) for(int i = a; i < b; i++)
#define S(x) scanf("%d",&x)
#define S2(x,y) scanf("%d%d",&x,&y)
#define P(x) printf("%d\n",x)
#define all(v) v.begin(),v.end()
#define FF first
#define SS second
#define pb push_back
#define mp make_pair

typedef long long int LL;
typedef pair<int, int > pii;
typedef vector<int > vi;

const int N = 2001;
const int INF = 100000000;

int n,m;
string s[N];
int dp[N][N][2];

int getval(int x, int y) {
  if(s[x][y] == '+') return 1;
  return -1;
}

int solve(int x, int y, int p) {
  if(x == n - 1 && y == m - 1) {
    return 0;
  }
  int &res = dp[x][y][p];
  if(res != INF) {
    return res;
  }
  if(p == 0) {
    res = -N * N;
  } else {
    res = N * N;
  }

  if(x + 1 < n) {
    if(p == 0) {
      res = max(res, getval(x + 1, y) + solve(x + 1, y, p ^ 1));
    } else {
      res = min(res, -getval(x + 1, y) + solve(x + 1, y, p ^ 1));
    }
  }

  if(y + 1 < m) {
    if(p == 0) {
      res = max(res, getval(x, y + 1) + solve(x, y + 1, p ^ 1));
    } else {
      res = min(res, -getval(x, y + 1) + solve(x, y + 1, p ^ 1));
    }
  }

  return res;
}

int main() {
  S2(n,m);
  rep(i,0,n) {
    cin >> s[i];
  }
  rep(i,0,N) rep(j,0,N) {
    dp[i][j][0] = dp[i][j][1] = INF;
  }
  int x = solve(0, 0, 0);
  if(x > 0) printf("Takahashi\n");
  else if(x < 0) printf("Aoki\n");
  else printf("Draw\n");
  return 0;
}


#include"bits/stdc++.h"

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef pair<LL, LL> PLL;
typedef vector<PLL> VPLL;
typedef priority_queue<LL> PQ_DESC;
typedef priority_queue<LL, VL, greater<LL>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;
typedef priority_queue<VL> PQ_DESC_VL;
typedef priority_queue<VL, vector<VL>, greater<VL>> PQ_ASC_VL;
typedef priority_queue<PLL> PQ_DESC_PLL;
typedef priority_queue<PLL, vector<PLL>, greater<PLL>> PQ_ASC_PLL;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
//#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SORT_DESC(c) sort((c).rbegin(),(c).rend())
#define REV(c) reverse((c).begin(), (c).end())
#define SIZE(a) int((a).size())

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

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF*(LL)INF;
const int MOD = 1e9+7;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

LL modpow(LL a, LL n) {
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

void Main()
{
    LL n;cin>>n;
    string s;cin>>s;
    s = "X"+s;

    VL a(n+1);
    VL t(n+1);
    VL c(n+1);
    VL g(n+1);

    FOR(i,1,n+1){
        if(s[i] == 'A'){
            a[i]=1;
        }
        if(s[i] == 'T'){
            t[i]=1;
        }
        if(s[i] == 'C'){
            c[i]=1;
        }
        if(s[i] == 'G'){
            g[i]=1;
        }
        a[i] += a[i-1];
        t[i] += t[i-1];
        c[i] += c[i-1];
        g[i] += g[i-1];
    }

    LL result = 0;
    FOR(i,0,n){
        FOR(j,i+1,n+1){
            LL na = a[j]-a[i];
            LL nt = t[j]-t[i];
            LL nc = c[j]-c[i];
            LL ng = g[j]-g[i];
            if(na==nt && nc==ng){
                result ++;
                //cerr<<i<<" "<<j<<endl;
            }
        }
    }

    cout<<result<<endl;

	return;
}

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

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

int main() {
    int N;
    string S;
    cin >> N >> S;
    int ans = 0;
    for (int i = 0; i < N; ++i) {
        int c1 = 0, c2 = 0;
        for (int j = i; j < N; ++j) {
            if (S[j] == 'A')
                c1++;
            else if (S[j] == 'T')
                c1--;
            else if (S[j] == 'C')
                c2++;
            else
                c2--;
            if (c1 == 0 && c2 == 0) ans++;
        }
    }
    cout << ans << endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,ans=0;
	bool flag=1;
	char s[100005];
	char head,tail;
	cin>>n>>s;
	if(n==2)
	{
		if(s[0]==s[1])
			ans=-1;
		else
			ans=1;
	}
	else if(n==3)
	{
		if(s[0]!=s[2])
			ans=1;
		else
			ans=-1;
	}
	else//n>3
	{
		if(s[0]!=s[n-1])
			ans=1;
		else
		{
			for(int i=2;i<=n-2;i++)
			{
				if(s[n-1-i]!=s[0] && s[n-i]!=s[0])
				{
					ans=2;
					flag=0;
					break;
				}
			}
			if(flag)
				ans=-1;
		}
	}
	cout<<ans<<endl;
	return 0;
}

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define NDEBUG
#define eprintf(...) do {} while (0)
#endif
#include<cassert>

using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
#define rprintf(fmt, begin, end) do { const auto end_rp = (end); auto it_rp = (begin); for (bool sp_rp=0; it_rp!=end_rp; ++it_rp) { if (sp_rp) putchar(' '); else sp_rp = true; printf(fmt, *it_rp); } putchar('\n'); } while(0)

int N;
int A[200011];
int B[200011];

int U[400011];
int V[400011];
int E[400011];

int root(int x) {
    return x == U[x]? x: U[x] = root(U[x]);
}

void MAIN() {
    scanf("%d", &N);
    REP (i, 400011) {
	U[i] = i;
	V[i] = 1;
    }

    REP (i, N) {
	int a, b;
	scanf("%d%d", &a, &b);
	a = root(a);
	b = root(b);
	if (a != b) {
	    U[b] = a;
	    V[a] += V[b];
	    E[a] += E[b];
	}
	E[a]++;
    }

    int ans = 0;
    REP (i, 400011) if (U[i] == i) {
	ans += min(V[i], E[i]);
    }
    printf("%d\n", ans);
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}


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

struct Union{
  vector<ll> par;
  Union(ll a){
  par=vector<ll>(a,-1);
  }
  ll find(ll a){
    if(par[a]<0){
      return a;
    }
    else{
      return par[a]=find(par[a]);
    }
  }
  bool same(ll a,ll b){
    return (find(a)==find(b));
  }
  ll size(ll a){
    return -par[find(a)];
  }
  void unite(ll a,ll b){
    ll c=find(a),d=find(b);
    if(c==d)
      return;
    if(size(c)<size(d)){
      swap(c,d);
    }
    par[c]+=par[d];
    par[d]=c;
  }
};
ll euclidean_gcd(ll a, ll b) {
  if(a < b) return euclidean_gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
ll euclidean_lcm(ll a, ll b) {
  return a/euclidean_gcd(a,b)*b;
}
int main(void){
  ll k,s=0;
  cin >> k;
  rep(i,k){
    rep(j,k){
      if((i+1)*(j+1)>k)break;
      s+=k/((i+1)*(j+1));
    }
  }
  cout << s << endl;
}

/***** In the name of Allah, the Most Gracious, the Most Merciful *****/
#include<bits/stdc++.h>
using namespace std;
#define Allahu_Akbar ios_base :: sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);

int main()
{
    Allahu_Akbar
	//freopen("input.txt", "r", stdin);
    int k;
    cin >> k;
    long long int total = 0;
    for(int i = 1; i<=k; i++)
    {
        for(int j = 1;  i * j<=k; j++)
        {
            for(int l = 1; i * j * l<=k; l++)
            {
                if((i * j * l) <= k) total++;
            }
        }
    }

    cout << total << endl;
    return 0;
}


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

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

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)

vector<vector<ll>> near8={{-1,1},{0,1},{1,1},{-1,0},{1,0},{-1,-1},{0,-1},{1,-1}};
vector<vector<ll>> near4={{0,1},{-1,0},{1,0},{0,-1}};

bool ll_sqrt(ll x, ll& lower_bound, ll& upper_bound)
{
	constexpr ll ll_max = numeric_limits<ll>::max();

	bool first_boost = true;

	lower_bound = 0;
	upper_bound = x;
	while (upper_bound - lower_bound > 1)
	{
		if (first_boost)
		{
			ll guess = (ll)sqrt((double)x);
			lower_bound = max(guess - 1, (ll)0);
			upper_bound = lower_bound + 3;
			first_boost = false;
		}

		ll newval = (lower_bound + upper_bound) / 2;
		if ((newval != 0) && (newval > ll_max / newval))  // newval*newval becomes overflow
			upper_bound = newval;  // because overflow means newval is too big
		else
		{
			ll newval_sqr = newval * newval;
			if (newval_sqr < x)
				lower_bound = newval;
			else
				upper_bound = newval;
		}
	}

	if ((upper_bound != 0) && (upper_bound > ll_max / upper_bound))
	{
		if (lower_bound * lower_bound == x)
			upper_bound = lower_bound;
	}
	else
	{
		if (lower_bound * lower_bound == x)
			upper_bound = lower_bound;
		else if (upper_bound * upper_bound == x)
			lower_bound = upper_bound;
	}
	bool is_exact = (lower_bound == upper_bound);
	return is_exact;
}

ll ll_ceil(ll x, int digit);
ll ll_floor(ll x, int digit);

ll ll_floor(ll x, int digit)
{
	if (x < 0)
		return -ll_ceil(-x, digit);

	ll div = 1;
	while (digit != 0)
	{
		div *= 10;
		digit--;
	}
	ll modval = x % div;
	ll ans = x - modval;
	return ans;
}

ll ll_ceil(ll x, int digit)
{
	if (x < 0)
		return -ll_floor(-x, digit);

	ll div = 1;
	while (digit != 0)
	{
		div *= 10;
		digit--;
	}
	ll modval = x % div;
	ll ans = x - modval;
	if (modval != 0)
		ans += div;
	return ans;
}

ll H,W;
vector<vector<char>> map1(501, vector<char>(501,'#'));

bool solve(ll h, ll w){
	ll nexth=0;
	ll nextw=0;

	for(vector<ll> to:near4){
		nexth = h+to[0];
		nextw = w+to[1];
		if(nexth < 0 || nexth >=H || nextw < 0 || nextw >=W || map1[nexth][nextw] == '#'){
			continue;
		}
		if(map1[nexth][nextw] =='g'){
			return true;
		}
		map1[nexth][nextw]='#';
		if(solve(nexth, nextw)){
			return true;
		};
	}

	return false;
}

int main() {
	ll N;
	cin >> N;
	N--;
	ll ans = N/100 +1;

	cout << ans << endl;

  return 0;
}

#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const double eps = 1e-7;
const int MAXN = 1e5 + 5;
double a[MAXN];
double ans;
int n;
double calc(double now) {
	double res = 0;
	for(int i = 1; i <= n; i++) {
		res += (now + a[i] - min(a[i], 2 * now)) / n;
	}
	return res;
}
double Thr_Div() {
	double l = 0, r = 1e9;
	while(r - l >= eps) {
		double midl = l + (r - l) / 3;
		double midr = r - (r - l) / 3;
		if(calc(midl) < calc(midr))
			r = midr;
		else
			l = midl;
	}
	return calc(l);
}
int main() {
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) scanf("%lf", &a[i]);
	printf("%.6lf", Thr_Div());
	return 0;
}


/*Rabbi Zidni Ilma*/

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define scl(n) scanf("%lld",&n)
#define scll(n,m) scanf("%lld %lld",&n,&m)
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define mod 1000000007
#define read freopen("input.txt","r",stdin)
#define write freopen("output.txt","w",stdout)

int main()
{
	ll n,i,sum=0;
	cin >> n;

	for(i=1;i<=n;i++)
	{
		sum+=i;
		if(sum>=n+1)
		break;
	}
	if(sum==n+1)
	printf("%lld\n",n+1-i);
	else
	printf("%lld\n",n+2-i);
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define clock (clock() * 1000.0 / CLOCKS_PER_SEC)
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define double long double
#define x first
#define y second
#define vi vector <int>
#define L nod<<1
#define R ((nod<<1)|1)
#define int ll
#define pi pair<int, int>
#define PI 3.1415926
const ll mod=998244353;
int n, ans;

int32_t main(){
    ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    cin >> n;
    ans = n;

    int cur = 1;
    while(n+1 >= cur){
        n -= cur;
        // cout << cur << " " << n+1 << endl;
        cur++;
    }
    cur--;

    ans -= (cur-1);
    cout << ans;
}


#include<bits/stdc++.h>
#include<iostream>
using namespace std;
#define int long long int
#define ld long double
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define removeDuplicates(a) a.resize(unique(all(a))-a.begin())
#define endl '\n'
#define setbits(x) (__builtin_popcount(x))
int mod=1000000007;
int INF64=mod*mod+1;

void solve(){
	int n;
	cin>>n;
	vector<int> a(n);

	for(int i=0;i<n;i++)
		cin>>a[i];

	int curr=0,pref=0,maxpref=0,ans=0;
	for(int i=0;i<n-1;i++){
		pref+=a[i];
		curr+=pref;
		ans=max(ans,curr+maxpref);
		maxpref=max(maxpref,pref);
	}
	ans=max(ans,curr+pref+a[n-1]);

	cout<<ans<<endl;
}

int32_t main(){

	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);

	int T=1;
	// cin>>T;
	for(int i=1;i<=T;i++){
		// cout<<"Case #"<<i<<": ";
		solve();
	}
	cerr<<"Time : "<<1000*((double)clock())/(double)CLOCKS_PER_SEC<<"ms\n";
}

#include <bits/stdc++.h>
using namespace std;
int n;
int main(){
	int i,all = 1;
	cin >> n;
	while (all < n) all <<= 1;
	all -= 1;
	for (i = 0; i < n; ++i){
		int lc = all&(i<<1),rc = all&(i<<1|1);
		if (lc >= n) lc -= (all+1)>>1;
		if (rc >= n) rc -= (all+1)>>1;
		++lc,++rc;
		cout << lc << ' ' << rc << '\n';
	}
	return 0;
}


// execute g++ main.cpp -std=c++14 -I C:\Users\naoya\Desktop\code\Atcoder
#include<bits/stdc++.h>
//#include<atcoder/all>
typedef long long ll;
typedef long double ld;
using namespace std;
//using namespace atcoder;

using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

//ordered_set 重複不可
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// use set_function + find_by_order(select itr-num)

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

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

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;}

char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
char Alpha[26] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};

int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, 1, -1};

//cout << std::fixed << std::setprecision(15) << y << endl; //小数表示

const ll MAX = 3000000; //テーブルの数
const ll MOD = 1e9+7; //mod宣言

long long fac[MAX], finv[MAX], inv[MAX];
// finv ->階乗割り算
// fac ->階乗掛け算

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return (fac[n] * (finv[k] * finv[n - k] % MOD)) % MOD;
}

int main(){
    COMinit();
    ll n, m, k; cin >> n >> m >> k;
    if(n > m + k){
        cout << 0 << endl;
        return 0;
    }
    ll mid = 0;
    cout << (COM(n+m, n) + MOD - COM(n+m, m+k+1)) % MOD << endl;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using iPair = pair<int,int>;
using lPair = pair<ll, ll>;
using ivector = vector<int>;
using lvector = vector<ll>;
using istack = stack<int>;
using iqueue = queue<int>;
using ivv = vector<vector<int>>;
using lvv = vector<vector<ll>>;

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
vector<iPair> dir = {{1,0}, {-1,0}, {0,1}, {0,-1}};
#define dump(x) cout << #x << " = " << (x) << endl
#define ALL(x) begin(x),end(x)
#define rep(i,s,e) for(ll i=(ll)(s), i_stop=(ll)(e); i<i_stop; ++i)
#define range(i,s,n) for(ll i=(ll)(s), i_stop=(ll)((s)+(n)); i<i_stop; ++i)
#define foreach(x,container) for(auto &&x:container)
template<typename S, typename T> bool chmax(T& a, S b) {b = (T)b; if(a<b) {a=b;return true;} return false;}
template<typename S, typename T> bool chmin(T& a, S b) {b = (T)b; if(a>b) {a=b;return true;} return false;}
template<typename T> void printArr(vector<T> &arr){
    for(auto &x:arr) {cout << x << " ";} cout << endl;
}

// =====================================================>

void solve() {
    ll a,b,c,d; cin>>a>>b>>c>>d;
    if(b >= d*c) cout<<-1<<endl;
    else {
        ll x = d*c-b;
        if(a%x) cout<<(a/x+1)<<endl;
        else cout<<a/x<<endl;
    }
}

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


#include"bits/stdc++.h"
#define rep(i,n) for(ll i=0;i<n;++i)
#define ALL(x) x.begin(),x.end()
#define MOD 1000000007
#define INF INT_MAX
#define FLOAT_ANS setprecision(10)
#define elif else if
// #define input(type,n) type n;cin>>n

using namespace std;
typedef long long ll;
typedef unsigned long long ull;

//最大公約数
template<typename T>
T gcd(T a, T b) {
	if (a % b == 0) {
		return(b);
	}
	else {
		return(gcd(b, a % b));
	}
}

//最小公倍数
template<typename T>
T lcm(T a, T b) {
	return a / gcd(a, b) * b;
}

bool isLarger(string s,string t){
	/*SのほうがTより大きければtrue*/
	rep(i,min(s.length(),t.length())){
		if(s[i]>t[i]){
			return true;
		}
		if(s[i]<t[i]){
			return false;
		}
	}

	if(s.length()>t.length()){
		return true;
	}
	else{
		return false;
	}
}

ll f(ll k){
	string s=to_string(k);
	ll ans=0;
	rep(i,s.length()){
		ll j=s[i]-'0';
		ans+=pow(k,s.length()-i-1)*j;
	}

	return ans;
}

int main(void){
	string a,b;
	cin>>a>>b;
	ll a_=0;
	ll b_=0;
	for(char c:a){
		a_+=c-'0';
	}
	for(char c:b){
		b_+=c-'0';
	}

	cout<<max(a_,b_);
}

/*

*/

//#include<bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <iterator>
#include <string.h>
#include <vector>
#include <utility>
#include <map>

//#pragma GCC optimize "trapv"

//#define int long long
#define For(i,a,b) for(int  i=a;i<b;i++)

#define pb push_back
#define endl "\n"

#define F first
#define S second

#define dracarys ios_base::sync_with_stdio(false);cin.tie(NULL)
#define all(v) v.begin(),v.end()

#define TEST_CASE int  t;cin>>t;while(t--)
#define debug(...) cout<<#__VA_ARGS__<<" = "; print(__VA_ARGS__);

using namespace std;
const int MOD = 1e9 + 7;

void print()  {    cout<<endl;  }
void printArray()  {    return;  }
void read() { return; }

template<typename T , typename... Args>  void print(T a , Args... arg)    {    cout << a << " " ;    print(arg...);    }

template<typename T , typename... Args> void read(T &a , Args&... arg) {   cin >> a;   read(arg...);   }

template<typename T,typename... Args> void read(vector<T>&v , Args&... arg) {  for(auto &i : v)  cin>>i;  read(arg...);  }

template<typename T,typename... Args> void printArray(vector<T>&v, Args&... arg) {   for(auto i : v)     cout<<i<<" ";   cout<<endl;  printArray(arg...);    }

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

int modPower(int a,int b) { int res=1; while(b) { if(b&1L) res=(res%MOD*a%MOD)%MOD; b>>=1; a=(a%MOD*a%MOD)%MOD; } return res; }

int gcdExtended(int a,int b,int *x,int *y){ if(a==0) { *x=0,*y=1; return b; } int x1,y1; int gcd=gcdExtended(b%a,a,&x1,&y1); *x=y1-(b/a)*x1; *y = x1; return gcd; }

int modInverse(int b,int m) {int x,y; int g=gcdExtended(b,m,&x,&y); if (g != 1) return -1; return (x%m + m) % m; }

int modDivide(int a,int b,int m=MOD) { a=a%m; int inv=modInverse(b,m); if(inv==-1) return -1; else return (inv*a)%m; }

void runCase_()
{
        string a,b; read(a,b);
        int s1 = 0,s2 = 0;
        for(char c : a) s1 += (c - '0');
        for(char c : b) s2 += (c - '0');
        if(s1 > s2) print(s1);
        else print(s2);
}

signed main()
{
     dracarys;
//      TEST_CASE
     runCase_();
     return 0;
}

/** TEST CASES HERE **/
/*

*/


#include <bits/stdc++.h>

template <typename T> inline void rd(T& x) {
	int si = 1; char c = getchar(); x = 0;
	while(!isdigit(c)) si = c == '-' ? -1 : si, c = getchar();
	while(isdigit(c)) x = x * 10 + c - 48, c = getchar();
	x *= si;
}
template <typename T, typename... Args>
inline void rd(T& x, Args&... args) { rd(x); rd(args...); }
#define fi first
#define se second
#define mkp std::make_pair
typedef long long ll;
typedef double ff;
typedef std::pair <int, int> pii;
const int kN = 3000 + 5, kInf = 0x3f3f3f3f;
const ll kMod = 998244353, kInfLL = 0x3f3f3f3f3f3f3f3fLL;

int n, k, A[kN][kN], fa[kN], siz[kN]; ll fac[kN];
int Find(int x) { return fa[x] == x ? x : fa[x] = Find(fa[x]); }
void Merge(int x, int y) {
	//printf("%d %d\n", x, y);
	int f_x = Find(x), f_y = Find(y);
	if(f_x == f_y) return;
	fa[f_x] = f_y; siz[f_y] += siz[f_x];
}

void Init() {
	fac[0] = 1;
	for(int i = 1; i <= n * 2; ++i) {
		fa[i] = i, siz[i] = 1;
		fac[i] = fac[i - 1] * i % kMod;
	}
}

int GetIdx(pii x) { return (x.fi - 1) * n + x.se; }

void Solve() {
	for(int i = 1; i <= n; ++i) {
		for(int j = 1; j <= n; ++j) {
			bool flag = true;
			for(int p = 1; p <= n; ++p)
				if(A[i][p] + A[j][p] > k) flag = false;
				//printf("%d\n", );
			if(flag) Merge(i, j);
		}
	}
	for(int i = 1; i <= n; ++i) {
		for(int j = 1; j <= n; ++j) {
			bool flag = true;
			for(int p = 1; p <= n; ++p)
				if(A[p][i] + A[p][j] > k) flag = false;
			if(flag) Merge(i + n, j + n);
		}
	}
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("a.in", "r", stdin);
	freopen("a.out", "w", stdout);
#endif
	int T = 1; //rd(T);
	while(T--) {
		rd(n, k); Init();
		for(int i = 1; i <= n; ++i)
			for(int j = 1; j <= n; ++j) {
				rd(A[i][j]);
				//idx[(i - 1) * n + j] = mkp(i, j);
			}
		Solve();
		ll ans = 1;
		for(int i = 1; i <= n * n; ++i) if(fa[i] == i) {
			ans = ans * fac[siz[i]] % kMod;
		}
		printf("%lld\n", ans);
	} return 0;
}

#include "bits/stdc++.h"

using namespace std;

using str = string;
using db = double;

#define pf push_front
#define pb push_back
#define ef emplace_front
#define eb emplace_back
#define ist insert
#define ers erase

#define ppf pop_front()
#define ppb pop_back()
#define ft front()
#define bk back()
#define ety empty()
#define F first
#define S second

#define all(v) (v).begin(), (v).end()
#define srt(v) sort(all(v));
#define rev(v) reverse(all(v));

#define ice(i, a, b) for (int (i) = (a); (i) < (b); ++(i))
#define fire(i, a, b) for (int (i) = (b) - 1; (i) >= (a); --(i))

template <class T>
inline int sz(T container) {
    return int(container.size());
}

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

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

template <class T>
void show(vector<T> v) {
    for (auto a : v) { cout << a << ' '; } cout << '\n';
}

template <class T>
void show2d(vector<vector<T>> v) {
    for (auto b : v) { for (auto a : b) { cout << a << ' '; } cout << '\n'; }
}

template <class T, class U>
void showPair(vector<pair<T, U>> v) {
    for (auto a : v) { cout << a.F << ' ' << a.S << '\n'; }
}

const long long MOD[3] = {1000000007, 998244353, 9223372036854775807};

template <class T>
T modpow(T base, T exp, T mod) {
    if (exp == 0) return 1 % mod;
    T ans = modpow(base, exp / 2, mod);
    ans *= ans; ans %= mod;
    if (exp & 1) { ans *= base; ans %= mod; }
    return ans;
}

vector<vector<tuple<int, long long, long long>>> adj(100000);
vector<long long> dis(100000, MOD[2]);
vector<bool> done(100000);
priority_queue<pair<long long, int>> q;

void solve() {
    int n, m; cin >> n >> m;
    ice (i, 0, m) {
        int a, b, c, d; cin >> a >> b >> c >> d; --a, --b;
        adj[a].eb(b, c, d); adj[b].eb(a, c, d);
    }
    dis[0] = 0;
    q.emplace(0, 0);
    while (!q.ety) {
        int cur = q.top().S; q.pop();
        if (done[cur]) continue;
        done[cur] = true;
        for (auto nxt : adj[cur]) {
            int to; long long C, D; tie(to, C, D) = nxt;
            auto until = (long long) floor(sqrt(double(D)));
            if (dis[cur] < until) {
                if (until + C + D / (until + 1) < dis[to]) {
                    dis[to] = until + C + D / (until + 1);
                    q.emplace(-dis[to], to);
                }
            } else {
                if (dis[cur] + C + D / (dis[cur] + 1) < dis[to]) {
                    dis[to] = dis[cur] + C + D / (dis[cur] + 1);
                    q.emplace(-dis[to], to);
                }
            }
        }
    }
    cout << (dis[n - 1] == MOD[2] ? -1 : dis[n - 1]);
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(17);
    int tc = 1;
    // cin >> tc;
    while (tc--) {
        solve();
    }
}