#include<bits/stdc++.h>
#define pi 3.141592653589793238
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define MOD 1000000007
#define INF 999999999999999999
#define pb push_back
#define ff first
#define ss second

#define mt make_tuple
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;

typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
const int N = 5e3 + 1;
ll n, m;
ll p[N][N];
ll d[N][N];
ll s[N];
int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    fast;
    ll T = 1, i, j;

    //cin >> T;
    while (T--) {
        ll mod = 998244353;
        cin >> n >> m;
        if(m == 1){
            cout << 1 << endl;
            return 0;
        }
        p[0][0] = 1;
        for(i = 1; i <= m; i++){
            p[i][0] = 1;
            for(j = 1; j <= n; j++){
                p[i][j] = (p[i][j - 1] * i) % mod;
            }
        }
        for(i = 2; i <= n; i++){
            for(j = 1; j <= m; j++){
                d[i][j] = p[m - 1][i - 2] - p[m - j][i - 2];
                d[i][j] %= mod;
                d[i][j] += mod;
                d[i][j] %= mod;
            }
        }
        for(i = 1; i <= m; i++){
            for(j = 2; j <= n; j++){
                s[j] += d[j][i];
                s[j] %= mod;
            }
        }
        vector<ll> dp(n + 1);
        dp[1] = m;
        for(i = 2; i <= n; i++){
            //cout << i << "##\n";
            dp[i] += m * dp[i - 1];
            //cout << dp[i] << endl;
            dp[i] %= mod;
            dp[i] += m * (p[m - 1][i - 1]);
            dp[i] %= mod;
            // for(j = 1; j <= m; j++){
            //     dp[i] += (p[m - 1][i - 1]);
            //     ll l = 0;
            //     for(ll k = i - 1; k >= 1; k--){
            //         dp[i] += (p[m][k - 1]) * (p[m - 1][l] - p[m - j][l]);
            //         dp[i] %= mod;
            //         l++;
            //     }
            //     //cout << dp[i] << endl;
            // }
            for(j = i - 1; j >= 1; j--){
                dp[i] += p[m][j - 1] * s[i - j + 1];
                dp[i] %= mod;
            }
        }
        cout << dp[n] << endl;
    }
    return 0;
}

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

template<int M>
struct static_mint {
	static_assert(0 < M, "Module must be positive");

	int val;
	static_mint(): val() {}
	static_mint(long long x) : val(x % M) { if (val < 0) val += M; }
	static_mint pow(long long n) const { static_mint ans = 1, x(*this); while (n) { if (n & 1) ans *= x; x *= x; n /= 2; } return ans; }
	static_mint inv() const { return pow(M - 2); }

	friend static_mint pow(const static_mint &m, long long n) { return m.pow(n); }
	friend static_mint inv(const static_mint &m) { return m.inv(); }

	static_mint operator+() const { static_mint m; m.val = val; return m; }
	static_mint operator-() const { static_mint m; m.val = M - val; return m; }
	static_mint &operator+=(const static_mint &m) { if ((val += m.val) >= M) val -= M; return *this; }
	static_mint &operator-=(const static_mint &m) { if ((val -= m.val) < 0) val += M; return *this; }
	static_mint &operator*=(const static_mint &m) { val = (long long) val * m.val % M; return *this; }
	static_mint &operator/=(const static_mint &m) { val = (long long) val * m.inv().val % M; return *this; }

	friend static_mint operator+ (const static_mint &lhs, const static_mint &rhs) { return static_mint(lhs) += rhs; }
	friend static_mint operator- (const static_mint &lhs, const static_mint &rhs) { return static_mint(lhs) -= rhs; }
	friend static_mint operator* (const static_mint &lhs, const static_mint &rhs) { return static_mint(lhs) *= rhs; }
	friend static_mint operator/ (const static_mint &lhs, const static_mint &rhs) { return static_mint(lhs) /= rhs; }
	friend bool operator==(const static_mint &lhs, const static_mint &rhs) { return lhs.val == rhs.val; }
	friend bool operator!=(const static_mint &lhs, const static_mint &rhs) { return lhs.val != rhs.val; }

	static_mint &operator++() { return *this += 1; }
	static_mint &operator--() { return *this -= 1; }
	static_mint operator++(int) { static_mint result(*this); *this += 1; return result; }
	static_mint operator--(int) { static_mint result(*this); *this -= 1; return result; }

	template <typename T> explicit operator T() const { return T(val); }

	friend std::ostream &operator<<(std::ostream &os, const static_mint &m) {
		return os << m.val;
	}

	friend std::istream &operator>>(std::istream &is, static_mint &m) {
		long long x; is >> x; m = x;
		return is;
	}
};

template <typename>
struct is_mint : public std::false_type { };

template <int M>
struct is_mint<static_mint<M>> : public std::true_type { };

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

	using mint = static_mint<998244353>;

	int n, m;
	cin >> n >> m;

	vector<vector<mint>> pw(m + 1, vector<mint>(n + 1));
	for (int i = 0; i <= m; i++) {
		pw[i][0] = 1;
		for (int j = 1; j <= n; j++) {
			pw[i][j] = i * pw[i][j - 1];
		}
	}

	mint ans = n * pw[m][n];
	for (int l = 2; l <= n; l++) {
		mint temp = 0;
		for (int x = 1; x <= m; x++) {
			temp += pw[m - x][l - 2];
		}
		ans -= (n - l + 1) * temp * pw[m][n - l];
	}
	cout << ans << '\n';
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define lowbit(x) ((x)&(-(x)))
#define mid ((l+r)>>1)
#define lson rt<<1, l, mid
#define rson rt<<1|1, mid+1, r
#define fors(i, a, b) for(int i = (a); i < (b); ++i)
#define all(vec) vec.begin(),vec.end()
using namespace std;
const int maxn = 1e5 + 5;
int n;
char s[maxn];
int a[maxn];
int main()
{
    cin>>n;
    scanf("%s",s+1);
    n++; int k = 1e5;
    fors(i,1,n+1) scanf("%d", &a[i]);
    fors(i,1,n) k = min(k, abs(a[i]-a[i+1]));
    cout<<k<<endl;
    fors(i,0,k){
        fors(j,1,n+1) cout<<a[j]/k + (i < a[j]%k)<<" \n"[j==n];
    }
}


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

using ll = long long;
using Vi = std::vector<int>;
using Vl = std::vector<ll>;
using Pii = std::pair<int, int>;
using Pll = std::pair<ll, ll>;

constexpr int I_INF = std::numeric_limits<int>::max();
constexpr ll L_INF = std::numeric_limits<ll>::max();

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

class Prints {
private:
    class __Prints {
    public:
        __Prints(const char* sep, const char* term) : sep(sep), term(term) {}
        template <class... Args>
        auto operator()(const Args&... args) const -> decltype((std::cout << ... << std::declval<Args>()), void()) { print(args...); }
        template <typename T>
        auto pvec(const T& vec, size_t sz) const -> decltype(std::cout << std::declval<decltype(std::declval<T>()[0])>(), void()) {
            for (size_t i = 0; i < sz; i++)
                std::cout << vec[i] << (i == sz - 1 ? term : sep);
        }
        template <typename T>
        auto pmat(const T& mat, size_t h, size_t w) -> decltype(std::cout << std::declval<decltype(std::declval<T>()[0][0])>(), void()) {
            for (size_t i = 0; i < h; i++)
                for (size_t j = 0; j < w; j++)
                    std::cout << mat[i][j] << (j == w - 1 ? term : sep);
        }

    private:
        const char *sep, *term;
        void print() const { std::cout << term; }
        void print_rest() const { std::cout << term; }
        template <class T, class... Tail>
        void print(const T& head, const Tail&... tail) const { std::cout << head, print_rest(tail...); }
        template <class T, class... Tail>
        void print_rest(const T& head, const Tail&... tail) const { std::cout << sep << head, print_rest(tail...); }
    };

public:
    Prints() {}
    __Prints operator()(const char* sep = " ", const char* term = "\n") const { return __Prints(sep, term); }
};

Prints prints;

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

void solve() {
    int N;
    cin >> N;
    ll ans = 0;
    for (ll i = 0; i < N; i++) {
        ll a, b;
        cin >> a >> b;
        ans += (a + b) * (b - a + 1) / 2;
    }
    prints()(ans);
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    std::cin.tie(nullptr), std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    std::ifstream ifs("./in_out/input.txt");
    std::cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    std::ofstream ofs("./in_out/output.txt");
    std::cout.rdbuf(ofs.rdbuf());
#endif
    std::cout << std::setprecision(18) << std::fixed;
    solve();
    std::cout << std::flush;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define vi vector<int>
#define pb push_back
#define ff first
#define ss second
#define ppi pair<int,int>
#define forn(i,n) for(int i=0;i<n;i++)
#define M 1000000007
#define all(x) x.begin(), x.end()
#define fastio ios_base::sync_with_stdio(false);cin.tie(0)

int ps[1000007];

void solve() {

	int n;
	cin >> n;
	vi v;
	for (int i = 1; i < 1000007; i++) {
		v.pb(i);
	}

	ps[0] = v[0];
	for (int i = 1; i < 1000001; i++) {
		ps[i] = ps[i - 1] + v[i];
	}
	int ans = 0;
	while (n--) {
		int x, y;
		cin >> x >> y;
		int t = x;
		x--;
		y--;
		ans += (t + (ps[y] - ps[x]));
		// cout << ans << endl;
	}

	cout << ans << endl;

}

int32_t main() {

	fastio;

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

	solve();

	return 0;
}


#include<bits/stdc++.h>

using namespace std;

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

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

int main() {
  char A,B,C;
  cin>>A>>B>>C;

  if (A==B&&B==C)
     cout <<"Won" << endl;
  else
     cout<<"Lost"<< endl;

 }


// #define _GLIBCXX_DEBUG // for STL debug (optional)
#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 int;
using int64 = long long int;

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;

ll dp[3010][1 << 5][5];
int main() {
    int N; scanf("%d", &N);
    vector< vector<ll> > A(N, vector<ll>(5));
    for(int i=0; i<N; i++) {
        for(int j=0; j<5; j++) {
            scanf("%lld", &A[i][j]);
        }
    }

    fill(dp[0][0], dp[N+1][0], -1);
    dp[0][0][0] = LONGINF;
    for(int i=0; i<N; i++) {
        for(int S=0; S<(1<<5); S++) {
            for(int j=0; j<=3; j++) {
                if(dp[i][S][j] < 0) continue;

                // 追加しない
                chmax(dp[i+1][S][j], dp[i][S][j]);

                // 追加する (集合を決める)
                if(j + 1 > 3) continue;
                int mask = (1<<5) - 1 - S;
                for(int T=mask; T>0; T=(T-1)&mask) {
                    ll mi = LONGINF;
                    for(int k=0; k<5; k++) {
                        if(T >> k & 1) chmin(mi, A[i][k]);
                    }
                    chmax(dp[i+1][S|T][j+1], min(dp[i][S][j], mi));
                }
            }
        }
    }
    cout << dp[N][(1<<5)-1][3] << endl;
    return 0;
}

#include<iostream>
#include<algorithm>
#include<cstring>
#include<set>

using namespace std;

const int N = 3e3 + 10, M = 1 << 5;

int n;
int w[N][5];

bool check(int x){
    set<int> s;
    for(int i = 1; i <= n; i ++){
        int t = 0;
        for(int j = 0; j < 5; j ++)
            if(w[i][j] >= x) t += 1 << j;
        s.insert(t);
    }

    for(int a : s)
        for(int b : s)
            for(int c : s)
                if((a | b | c) == 31) return true;
    return false;
}

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

    for(int i = 1; i <= n; i ++)
        for(int j = 0; j < 5; j ++)
            scanf("%d", &w[i][j]);

    int l = 1, r = 1e9;
    while(l < r){
        int mid = l + r + 1 >> 1;
        if(check(mid)) l = mid;
        else r = mid - 1;
    }

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


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pi pair<int,int>
#define pll pair<ll,ll>
#define ld  long double

const int INF = 1e9 + 7;

void solve(){
	ll L , R; cin >> L >> R;
	ll ans = 0;
	if(R < 2 * L) cout << 0 << endl;
	else{
		ll numAs = R - 2 * L + 1;
		ll ans = numAs * (R + 2 * L) / 2;
		ans -= (2 * L * numAs);
		ans += numAs;
		cout << ans << endl;
	}
}

int main(){
    ios :: sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int tt = 1;
    cin >> tt;
    for(int tc = 1; tc <= tt; tc++){
        // cout << "Case #" << tc << ": ";
        solve();
    }
}

#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#define LL long long
using namespace std;
int main (){
    LL T, l, r;
    cin >> T;
    while (T--){
        scanf("%lld%lld", &l, &r);
        LL m = r - 2 * l + 1;
        if (m <= 0){
            printf("0\n");
        }
        else{
            printf("%lld\n", (m + 1) * m / 2);
        }
    }
    return 0;
}
//n: n - 2l + 1 (2l ~ r)
// m = r - 2l + 1


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <list>
#include <utility>
#include <tuple>
#include <cstdio>
#include <set>
#include <queue>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <cmath>
#include <limits>
#include <iomanip>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
const long long INF = 1LL << 60;
typedef long long ll;
const ll mod = 998244353;
ll power(ll x, ll n){
    ll ret = 1;
    while(n > 0) {
        if(n & 1) {
            ret = ret * x % mod;
        }
        x = x* x % mod;
        n >>= 1;
    }
    return ret;
}
int main() {
    cout << std::fixed << std::setprecision(15) ;
    double s_x,s_y,g_x,g_y;
    cin >> s_x >> s_y >> g_x >> g_y ;
    double ans = s_x + (g_x - s_x) * s_y / (s_y + g_y);
    cout << ans << endl;
}

//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
#define all(n) begin(n), end(n)
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
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;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b, c;
    cin >> a >> b >> c;
    auto dp = make_v<double>(101, 101, 101);

    for (int i = 99; i >= 0; i--)
    {
        for (int j = 99; j >= 0; j--)
        {
            for (int k = 99; k >= 0; k--)
            {
                dp[i][j][k] = (double)(i * (1 + dp[i + 1][j][k]) + j * (1 + dp[i][j + 1][k]) + k * (1 + dp[i][j][k + 1])) / (double)(i + j + k);
            }
        }
    }
    cout << setprecision(20) << dp[a][b][c];

    return 0;
}


#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0 ; i < (n); ++i)
using namespace std ;
typedef long long ll ;
const int mod=1000000007;
const int N=1e5 ;
const int INF=1001001001 ;

void solve(){

	int n,x ;
	cin>>n>>x ;

	vector<int> a(n) ;
	rep(i,n){
		cin>>a[i] ;
	}

	stack<int> st ;

	rep(i,n){
		if(a[i]==x){
			continue ;
		}
		else{
			st.push(a[i]) ;
		}
	}

	vector<int> ans ;

	while(!st.empty()){
		int y=st.top() ;
		ans.push_back(y) ;
		st.pop() ;
	}

	reverse(ans.begin(),ans.end()) ;

	for(int i=0;i<(int)ans.size();i++){
		cout<<ans[i]<<" " ;
	}

}

int main(){

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

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

		int y ;

		y=1 ;
		//cin>>y ;

		while(y--){

			solve() ;

		}

		return 0 ;
}

#include<bits/stdc++.h>

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int a, b;
	cin >> a >> b;
	if(a == b) {
		cout << a << '\n';
	}
	else {
		if(2 != a && 2 != b) {
			cout << 2 << '\n';
		}
		else if(1 != a && 1 != b) {
			cout << 1 << '\n';
		}
		else {
			cout << 0 << '\n';
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
using ll=long long;
static const ll mod=998244353;
ll N,K;
ll power[301];
ll modpow(ll a,ll n){
ll res=1;
  while(0<n){
  if(n%2==1)res=(res*a)%mod;
    a=(a*a)%mod;
    n>>=1;
  }return res;
}
ll fac[301];
ll rev[301];
ll comb(ll n,ll k){
if(n<k)return 0;
  ll x=(fac[n]*rev[k])%mod;
  x=(x*rev[n-k])%mod;return x;
}
int main(){
  cin>>N>>K;ll rev2=modpow(2,mod-2);
  fac[0]=1;rev[0]=1;
  for(ll i=1;i<=300;i++){
  fac[i]=(i*fac[i-1])%mod;
    rev[i]=modpow(fac[i],mod-2);
  }
  vector<ll>A(N);
  for(ll i=0;i<N;i++)
    cin>>A[i];power[0]=N;
  for(ll i=0;i<N;i++){
  ll a=A[i];
    for(ll j=1;j<=300;j++){
    power[j]=(power[j]+a)%mod;
      a=(a*A[i])%mod;
      }
  }for(ll k=1;k<=K;k++){
    ll ans=0;
  for(ll i=1;i<=k/2;i++){
    ll x=(comb(k,i)*(mod-power[k]+(power[i]*power[k-i])%mod))%mod;
     ans=(ans+x)%mod;
  }
   ans=(ans+(N-1)*power[k])%mod;
 if(k%2==0){ ll x=(comb(k,k/2)*(mod-power[k]+(power[k/2]*power[k/2])%mod))%mod;
            x=(x*rev2)%mod;
     ans=(mod+ans-x)%mod;}
    cout<<ans<<endl;
  }
  return 0;
}

//#pragma GCC target("avx512f,avx512dq,avx512cd,avx512bw,avx512vl")
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define DB double
#define LD long double
#define ST string
#define BS bitset
#define PA pair<LL,LL>
#define VE vector
#define VL VE<LL>
#define VP VE<PA>
#define VVL VE<VL>
#define VVVL VE<VVL>
#define PQ priority_queue
#define PQS priority_queue<LL,vector<LL>,greater<LL>>
#define FI first
#define SE second
#define PB push_back
#define POB pop_back
#define PF push_front
#define POF pop_front
#define MP make_pair
#define TS to_string
#define TU to_ullong
#define BPL __builtin_popcountll
#define FOR(i,a,n) for(i=a;i<n;++i)
#define FORR(i,a,n) for(i=n-1;i>=a;--i)
#define rep(i,n) FOR(i,0,n)
#define repr(i,n) FORR(i,0,n)
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define SORT(a) sort(ALL(a))
#define REV(a) reverse(ALL(a))
#define UB(a,n) *upper_bound(ALL(a),n)
#define UBn(a,n) upper_bound(ALL(a),n)-a.begin()
#define LB(a,n) *lower_bound(ALL(a),n)
#define LBn(a,n) lower_bound(ALL(a),n)-a.begin()
#define INF 1000000000000000003
#define PI 3.14159265358979323846264338327950288
//#define MOD 1000000007
#define MOD 998244353
#define ERR 1e-10
#define coutl cout<<fixed<<setprecision(15)
#define FAST cin.tie(0);ios::sync_with_stdio(false)

void Yn(LL a){if(a)cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void YN(LL a){if(a)cout<<"YES"<<endl;else cout<<"NO"<<endl;}
LL pwmn(LL a,LL n){LL ans=1;while(ans<a)ans*=n;return ans;}
LL dig(LL n){LL ret=0;while(n)n/=10,++ret;return ret;}
LL GCD(LL a,LL b){LL c=1,tmp=max(a,b);b=min(a,b);a=tmp;while(c!=0){c=a%b;a=b;b=c;}return a;}
LL LCM(LL a,LL b){return a*b/GCD(a,b);}
LL cmod(LL a,LL m){if(a%m<0)return a%m+abs(m);else return a%m;}
LL cdiv(LL a,LL b){return ((a<0&&b<0)||(a>=0&&b>=0)?a/b:(a-b+1)/b);}
LL DIV(LL a,LL d,LL m){LL l=m,x=1,y=0,k;while(l){k=d/l;d-=k*l;swap(l,d);x-=k*y;swap(x,y);}return cmod(a*cmod(x,m),m);}
LL POW(LL a,LL n,LL m){LL ans=1;while(n>0){if(n&1)ans=ans*a%m;a=a*a%m;n>>=1;}return ans;}
VL fact,finv,inv;
void comi(LL n){LL i;fact.resize(max(2LL,n+1));finv.resize(max(2LL,n+1));inv.resize(max(2LL,n+1));fact[0]=fact[1]=1;finv[0]=finv[1]=1;inv[0]=inv[1]=1;FOR(i,2,n+1){fact[i]=fact[i-1]*i%MOD;inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;finv[i]=finv[i-1]*inv[i]%MOD;}}
LL com(LL n,LL k){if(n<k||n<0||k<0)return 0;return fact[n]*(finv[k]*finv[n-k]%MOD)%MOD;}
bool cmps(PA a,PA b){if(a.SE!=b.SE)return a.SE<b.SE;return a.FI<b.FI;}
template<typename T>bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
template<typename T>void vout(VE<T> &v){LL i;rep(i,v.size()){cout<<v[i];if(i<v.size()-1)cout<<" ";}cout<<endl;}
template<typename T>void v2out(VE<VE<T>> &v){for(auto a:v)vout(a);}

int main(){
    FAST;
    LL i,j,ans=0,N,s=0;
    cin>>N;
    VL A(N);
    rep(i,N){
        cin>>A[i];
        s+=A[i];
        ans+=A[i]*A[i]*(N-1);
    }
    rep(i,N){
        ans-=A[i]*(s-A[i]);
    }
    cout<<ans<<endl;
}


//   __________________
//  | ________________ |
//  ||          ____  ||
//  ||   /\    |      ||
//  ||  /__\   |      ||
//  || /    \  |____  ||
//  ||________________||
//  |__________________|
//  \###################\
//   \###################\
//    \        ____       \
//     \_______\___\_______\
// An AC a day keeps the doctor away.

#ifdef local
#include <bits/extc++.h>
#define safe std::cerr<<__PRETTY_FUNCTION__<<" line "<<__LINE__<<" safe\n"
#define debug(args...) qqbx(#args, args)
using ost = std::ostream;
#define DESTL(STL, BEG, END, OUT) \
    template <typename ...T> ost& operator<<(ost &O, std::STL<T...> v) { int f=0; for(auto x: v) O << (f++ ? ", " : BEG) << OUT; return O << END; }
DESTL(deque, "[", "]", x); DESTL(vector, "[", "]", x);
DESTL(set, "{", "}", x); DESTL(multiset, "{", "}", x); DESTL(unordered_set, "{", "}", x);
DESTL(map , "{", "}", x.first << ":" << x.second); DESTL(unordered_map , "{", "}", x.first << ":" << x.second);
template <typename U, typename V> ost& operator<<(ost &O, std::pair<U,V> p) { return O << '(' << p.first << ',' << p.second << ')'; }
template <typename T, size_t N> ost& operator<<(ost &O, std::array<T,N> a) { int f=0; for(T x: a) O << (f++ ? ", " : "[") << x; return O << "]"; }
template <typename T, size_t ...I> ost& prtuple(ost &O, T t, std::index_sequence<I...>) { return (..., (O << (I ? ", " : "(") << std::get<I>(t))), O << ")"; }
template <typename ...T> ost& operator<<(ost &O, std::tuple<T...> t) { return prtuple(O, t, std::make_index_sequence<sizeof...(T)>()); }
template <typename ...T> void qqbx(const char *s, T ...args) {
    int cnt = sizeof...(T);
    (std::cerr << "\033[1;32m(" << s << ") = (" , ... , (std::cerr << args << (--cnt ? ", " : ")\033[0m\n")));
}
#else
#pragma GCC optimize("Ofast")
#pragma loop_opt(on)
#include <bits/extc++.h>
#include <bits/stdc++.h>
#define debug(...) ((void)0)
#define safe ((void)0)
#endif // local
#define all(v) begin(v),end(v)
#define get_pos(v,x) int(lower_bound(begin(v),end(v),x)-begin(v))
#define sort_uni(v) sort(begin(v),end(v)),v.erase(unique(begin(v),end(v)),end(v))
#define pb emplace_back
#define ff first
#define ss second
#define mem(v,x) memset(v,x,sizeof v)

using namespace std;
using namespace __gnu_pbds;
typedef int64_t ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pld;
template <typename T> using max_heap = std::priority_queue<T,vector<T>,less<T> >;
template <typename T> using min_heap = std::priority_queue<T,vector<T>,greater<T> >;
template <typename T> using rbt = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
constexpr ld PI = acos(-1), eps = 1e-7;
constexpr ll N = 100025, INF = 1e18, MOD = 998244353, K = 19, inf = 1e7;
constexpr inline ll cdiv(ll x, ll m) { return x/m + (x%m ? (x<0) ^ (m>0) : 0); } // ceiling divide
constexpr inline ll modpow(ll e,ll p,ll m=MOD) { ll r=1; for(e%=m;p;p>>=1,e=e*e%m) if(p&1) r=r*e%m; return r; }

ll f(ll x) {
    return x*(x+1)/2 % MOD;
}
signed main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    ll a, b, c;
    cin >> a >> b >> c;
    cout << f(a) * f(b) % MOD * f(c) % MOD << '\n';
}

#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>

using ll = long long int;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

ll solve(ll a, ll b, ll c, ll d){
	if(a==c && b==d){
		return 0ll;
	}
	if(a+b == c+d){
		return 1ll;
	}
	if(a-b == c-d){
		return 1ll;
	}
	if(std::abs(a-c)+std::abs(b-d) <= 3ll){
		return 1ll;
	}
	if((a+b+c+d)%2==0){
		return 2ll;
	}
	return INFLL;
}

int main(void){
	ll sx,sy,gx,gy,ans,i,j;
	std::cin >> sx >> sy;
	std::cin >> gx >> gy;
	ans = solve(sx,sy,gx,gy);
	for(i=-3; i<=3; ++i){
		for(j=-3; j<=3; ++j){
			if(std::abs(i)+std::abs(j)>3ll){
				continue;
			}
			ans = std::min(ans,solve(sx+i,sy+j,gx,gy)+1);
		}
	}
	std::cout << ans << std::endl;
	return 0;
}


#include <iostream>
#include <cstdlib>
#include <cstring>
#include <string>
#include <bitset>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
using namespace std;
typedef long long ll;

//infの設定
#define INF32 2147483647
#define INF64 9223372036854775807
//repマクロ
#define rep(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))

struct dataE{
    ll error;
    ll key;
};
bool cmp(const dataE &a, const dataE &b){
    return a.error>b.error;
}

int main(){
    ll K,N,M;
    cin>>K>>N>>M;

    vector<ll> A(101010),B(101010);

    vector<dataE> e(101010);

    ll sumB=0;
    rep(i,0,K){
        cin>>A.at(i);
        B.at(i)=A.at(i)*M/N;
        e.at(i).error=A.at(i)*M-B.at(i)*N;
        e.at(i).key=i;
        sumB+=B.at(i);
    }
    sort(e.begin(),e.end(),cmp);

    ll rem=M-sumB;
    rep(i,0,rem){
        B.at(e.at(i).key)++;
    }

    rep(i,0,K) cout<<B.at(i)<<" ";
    cout<<endl;

    return 0;
}

#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>
#include <iomanip>
#include <random>

#define FOR_LT(i, beg, end) for (decltype(end) i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (decltype(end) i = beg; i <= end; i++)
#define FOR_DW(i, beg, end) for (decltype(beg) i = beg; end <= i; i--)
#define REP(n)              for (decltype(n) repeat_index = 0; repeat_index < n; repeat_index++)

using namespace std;

template<typename T, size_t S>
T minval(const T(&vals)[S])
{
	T val = numeric_limits<T>::max();
	FOR_LT(i, 0, S) {
		val = min(val, vals[i]);
	}
	return val;
}

template<typename T, size_t S>
T maxval(const T(&vals)[S])
{
	T val = numeric_limits<T>::min();
	FOR_LT(i, 0, S) {
		val = max(val, vals[i]);
	}
	return val;
}

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

	int64_t k, n, m; cin >> k >> n >> m;
	vector<int64_t> as(k); for (auto& a : as) { cin >> a; }

	vector<int64_t> bs(k);
	vector<int64_t> rs(k);

	int64_t sum = 0;
	FOR_LT(i, 0, k) {
		int64_t x = as[i] * m;
		bs[i] = x / n;
		rs[i] = x % n;
		sum += bs[i];
	}

	multimap<int64_t, int64_t> rmap;
	FOR_LT(i, 0, k) {
		rmap.insert({ rs[i], i });
	}

	{
		auto it = rmap.rbegin();
		while (it != rmap.rend()) {
			if (sum == m) break;
			bs[it->second]++;
			it++;
			sum++;
		}
	}

	FOR_LT(i, 0, k) {
		cout << bs[i] << " ";
	}
	cout << endl;

	return 0;
}


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

#define ull unsigned long long
#define ll long long
#define ld long double
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define For(x,a,b) if(a!=b){icdc=(b-a)/abs(b-a);}else{icdc=1;}for(int x=(a);x!=(b+icdc);x+=icdc)
#define forp(x,a,b) if(b-a!=0){icdc=(b-a)/abs(b-a);}else{icdc=1;};for(int x=(a);x!=(b);x+=icdc)
#define FOR(x,n) for(int x=0;x<(n);x++)
int icdc;

//Frequently Used Variables
ull M=1e9+7;
ll b;
//ll A[100005];
ll maxv=-1e18,minv=1e18,LLINF=1e18,INF=1e9;
string s;

map<long long,int> mp;
vector<ll> v;

#define co cout<<
#define kj <<" "<<
#define ml <<'\n';

void solve(){
	cin>>b;
	//cout<<b<<endl;
	sort(v.begin(), v.end());
	//ll js=upper_bound(v.begin(), v.end(),b)-v.begin();
	for(ll i=0;i<(int)v.size();i++){
		//co "vi" kj b kj v[i] ml
		if(b<v[i]){
			cout<<b-i<<endl;
			return;
		}
	}
	cout<<b-v.size()<<endl;

}

void prekomput(){
	ll j;
	//cout<<"aman"<<endl;
	for(ll i=2;i<=1e5;i++){
		//cout<<"I"<<i<<endl;
		j=i*i;
		while(j<=1e10+1){
			if(mp[j]==0){
				mp[j]=1;
				v.push_back(j);
				//cout<<"vs"<<v.size()<<"  ";
				//cout<<j<<endl;
			}
			j=j*i;
		}
	}
	//cout<<"aman"<<endl;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(0);
	//freopen("input.txt", "r", stdin);
 	//freopen("output.txt", "w", stdout);
 	prekomput();
 	solve();
}
/*

*/

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
    ll n;cin>>n;
    unordered_set<ll> s;
    for(ll i=2;i*i<=n;i++){
        ll k=i*i;
        while(k<=n){
            s.insert(k);
            k=k*i;
        }
    }
    cout<<n-s.size();
}


#include <bits/stdc++.h>
using namespace std;
#define IO ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define whilet int T;cin>>T;while(T--)
#define clr(a,x) memset(a,x,sizeof(a));
#define ll long long
#define PI 3.1415926535897932384626
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define endl "\n"
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
#define MOD 998244353

int d4x[] = {0, 0, 1, -1};
int d4y[] = {1, -1, 0, 0};

int d8x[] = {-1, -1, -1, 0, 0, 1, 1, 1};
int d8y[] = {-1, 0, 1, -1, 1, -1, 0, 1};

ll a, b, c;

int main() {
    IO;

    cin >> a >> b >> c;
    ll res = ((((a*(a+1)/2)%MOD) * ((b*(b+1)/2)%MOD)%MOD) * ((c*(c+1)/2)%MOD))%MOD;
    cout << res << endl;
    return 0;
}

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

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

	long long mod = 998244353;
	cout << ( (a) * (a+1) / 2 % mod) * ( (b) * (b+1) / 2 % mod) % mod * ( (c) * (c+1) / 2 % mod ) % mod;
}


#include <iostream>

int main(void)
{
  int a, b, c, d;
  std::cin >> a >> b >> c >> d;

  std::cout << a*d -  b*c << std::endl;
  return 0;
}

/*
このコード、と～おれ!
Be accepted!
∧＿∧
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/

#include <cstdio>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <functional>
#include <complex>
#include <list>
#include <cassert>
#include <iomanip>
#include <set>
#include <stack>
#include <bitset>
#include <array>

////多倍長整数, cpp_intで宣言
//#include <boost/multiprecision/cpp_int.hpp>
//#include <boost/multiprecision/cpp_dec_float.hpp>
//using namespace boost::multiprecision;
//
#pragma GCC target ("avx2")
//#pragma GCC target("arch=skylake-avx512")
//#pragma GCC optimiz ("O3")
//#pragma GCC target ("sse4")
//#pragma GCC optimization ("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define repeat(i, n, m) for(int i = n; i < (m); ++i)
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printim(a) printf(a ? "possible\n" : "imposible\n")
#define printdb(a) printf("%.50lf\n", a) //少数出力
#define printLdb(a) printf("%.50Lf\n", a) //少数出力
#define printdbd(a) printf("%.16lf\n", a) //少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str()) //string出力
#define all(x) (x).begin(), (x).end()
#define deg_to_rad(deg) (((deg)/360.0L)*2.0L*PI)
#define rad_to_deg(rad) (((rad)/2.0L/PI)*360.0L)
#define Please return
#define AC 0
#define manhattan_dist(a, b, c, d) (abs(a - c) + abs(b - d)) /*(a, b) から (c, d) のマンハッタン距離 */
#define inf numeric_limits<double>::infinity();
#define linf numeric_limits<long double>::infinity()

using ll = long long;
using ull = unsigned long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1e9 + 7;
constexpr ll mod = 998244353;
constexpr long double eps = 1e-6;
const long double PI = acosl(-1.0L);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);
	while (c != '\n' && c != -1 && c != ' ') {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

ll LSB(ll n) { return (n & (-n)); }

template<typename T>
inline T chmin(T& a, const T& b) {
	if (a > b)a = b;
	return a;
}

template<typename T>
inline T chmax(T& a, const T& b) {
	if (a < b)a = b;
	return a;
}

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

//random_device seed_gen;
//mt19937 engine(seed_gen());
//uniform_distribution dist(-1.0, 1.0);

/*-----------------------------------------ここからコード-----------------------------------------*/

int main() {

	int a, b, c, d;
	scanf("%d%d%d%d", &a, &b, &c, &d);
	printf("%d\n", a * d - b * c);

	Please AC;
}


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

int main(){
    int A, B; cin >> A >> B;
    int t = min(A, B) - 1;
    vector<ll> ans(A + B);
    for(int i = 0; i < t; i++){
        ans[i] = i + 1;
    }
    for(int i = 0; i < t; i++){
        ans[t + i] = (i * -1) - 1;
    }
    int n = max(A, B) - t;
    int sum = 0;
    for(int i = 0; i < n; i++){
        ans[2 * t + i] = 10000 + i;
        if(A < B)ans[2 * t + i] *= -1;
        sum += 10000 + i;
    }
    ans[A + B - 1] = sum;
    if(A >= B)ans[A + B - 1] *= -1;
    for(ll &x: ans)cout << x << " ";
    cout << endl;
}


#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
#include<chrono>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define vint(a,n) vint a(n); rep(i, n) cin >> a[i];
#define vll(a,n) vll a(n); rep(i, n) cin >> a[i];
#define ALL(n) begin(n),end(n)
#define RALL(n) rbegin(n),rend(n)
#define MOD (1000000007)
// #define MOD (998244353)
#define INF (2e9)
#define INFL (2e18)

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
using vint=vector<int>;
using vll=vector<ll>;
using vbool=vector<bool>;
template<class T>using arr=vector<vector<T>>;
template<class T>int popcount(T &a){int c=0; rep(i, 8*(int)sizeof(a)){if((a>>i)&1) c++;} return c;}
template<class T>void pl(T x){cout << x << " ";}
template<class T>void pr(T x){cout << x << endl;}
template<class T>void prvec(vector<T>& a){rep(i, a.size()-1){pl(a[i]);} pr(a.back());}
template<class T>void prarr(arr<T>& a){rep(i, a.size()) if(a[i].empty()) pr(""); else prvec(a[i]);}
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; }

//数列a(a[0],a[1],…,a[n-1])についての区間和と点更新を扱う
//区間和,点更新,二分探索はO(log{n})で動作する
class BIT {
    public:
        //データの長さ
        ll n;
        //データの格納先
        vector<ll> a;
        //コンストラクタ
        BIT(ll n):n(n),a(n+1,0){}

        //a[i]にxを加算する
        void add(ll i,ll x){
            i++;
            if(i==0) return;
            for(ll k=i;k<=n;k+=(k & -k)){
                a[k]+=x;
            }
        }

        //a[i]+a[i+1]+…+a[j]を求める
        ll sum(ll i,ll j){
            return sum_sub(j)-sum_sub(i-1);
        }

        //a[0]+a[1]+…+a[i]を求める
        ll sum_sub(ll i){
            i++;
            ll s=0;
            if(i==0) return s;
            for(ll k=i;k>0;k-=(k & -k)){
                s+=a[k];
            }
            return s;
        }

        //a[0]+a[1]+…+a[i]>=xとなる最小のiを求める(任意のkでa[k]>=0が必要)
        ll lower_bound(ll x){
            if(x<=0){
                //xが0以下の場合は該当するものなし→0を返す
                return 0;
            }else{
                ll i=0;ll r=1;
                //最大としてありうる区間の長さを取得する
                //n以下の最小の二乗のべき(BITで管理する数列の区間で最大のもの)を求める
                while(r<n) r=r<<1;
                //区間の長さは調べるごとに半分になる
                for(int len=r;len>0;len=len>>1) {
                    //その区間を採用する場合
                    if(i+len<n && a[i+len]<x){
                        x-=a[i+len];
                        i+=len;
                    }
                }
                return i;
            }
        }
    };

int main()
{
    int n; cin >> n;
    vint(a, n);

    int d[n][2];
    rep(i, n){
        d[i][0] = i;
        d[i][1] = n-i-1;
    }

    BIT bt(n);
    ll f = 0;
    rep(i, n){
        f += i - bt.sum_sub(a[i]);
        bt.add(a[i], 1);
    }
    // pr(f);

    rep(i, n){
        pr(f);
        f = f - d[a[i]][0] + d[a[i]][1];
    }
    return 0;}

#include <bits/stdc++.h>
#define INF 1000000007
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = a; i < b; i++)

using namespace std;

typedef long long ll;
typedef long long int  lli;
typedef long double ld;
typedef vector<int> vi;
typedef unordered_map<int,int> umi ;
typedef unordered_set<int> usi ;
typedef pair<int,int> pi;
#include <bits/stdc++.h>

using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

//declare here -------------------------------------------------------------------------------
const int N =4e5+1;
bool taketest=false ;
vi adj[N] ;
bool visited[N] ;
bool visited2[N] ;
bool cycle(int u ,int p){
	if(visited2[u]) return true ;
	visited2[u] =true ;
	bool ans=false ;
	for(auto v:adj[u]){
		if(v==p) continue ;
		ans|= cycle(v,u) ;
	}
	return ans ;
}

int sze(int u ,int p){
	if(visited[u]) return 0 ;
	visited[u] =true ;
	int res=0 ;
	res++ ;
	for(auto v:adj[u]){
		if(v==p) continue ;
		res+= sze(v,u) ;
	}
	return res ;
}

// solve here ---------------------------------------------------------------------------------

void solve(){
	int n ;
	cin>>n ;
	int u,v ;
	REP(i,0,n){
		cin>>u>>v ;
		adj[u].PB(v) ;
		adj[v].PB(u) ;
	}
	int ans=0 ;
	REP(i,0,N){
		if(visited[i]) continue ;
		ans+=sze(i,-1) ;
		if(!cycle(i,-1)) ans-- ;
	}
	cout<<ans ;

}

//--------------------------------------------------------------------------------------------

int main(){
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
	#endif
    ios::sync_with_stdio(0);
    cin.tie(0);
    long long test =1 ;
    if(taketest) cin>>test ;
    while(test--){
        solve() ;
        cout<<"\n" ;
    }
    return 0 ;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,j,n) for(int i=j;i<n;i++)
#define readvec(v,n) for(int i=0;i<n;i++){cin>>v[i];}
#define MOD 1000000007
int main()
{
  int n;
  cin>>n;
  vector<char> v(2*n);
  readvec(v,2*n);
  int q;
  cin>>q;
  int ind=0;
  rep(i,0,q)
  {
    int t,a,b;
    cin>>t>>a>>b;
    if(t==2){ind=(ind==0)?n:0;continue;}
    int ia=(ind+a-1)%(2*n);
    int ib=(ind+b-1)%(2*n);
    char ch = v[ia];
    v[ia] = v[ib];
    v[ib] = ch;
  }
  rep(i,0,2*n)cout<<v[(ind+i)%(2*n)];
  cout<<"\n";
  return 0;
}

#include <bits/stdc++.h>

using namespace std;

#define int long long

int N, ans;
struct Node{
    int v, idx;
    inline bool operator < (const Node &comp) const {return comp.v < v;}
}a[400000 + 5];
set <int> b;
set <int> :: iterator it;

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

    cin >> N;
    for (int i = 1; i <= N; i ++) {
        cin >> a[i].v; a[i].idx = N + 1 - i; b.insert(i);
    }
    for (int i = 1; i <= N; i ++) {
        cin >> a[N + i].v; a[N + i].idx = i;
    }
    sort(a + 1, a + N + N + 1);
    for (int i = 1, j = 1; i <= N; i ++) {
        while (j <= N + N) {
            it = b.upper_bound(a[j].idx);
            if (it != b.begin()) break;
            j ++;
        }
        ans += a[j ++].v;
        b.erase(-- it);
    }
    cout << ans << '\n';

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
using namespace std::chrono;
#define IOS                  \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0)

#define ceil(x) static_cast<ll>(ceil(x))
#define floor(x) static_cast<ll>(floor(x))
#define pow(x, y) static_cast<ll>(pow(x, y))
#define gcd(x, y) static_cast<ll>(__gcd(x, y))
#define lcm(x, y) static_cast<ll>(a * (b / gcd(x, y)))

#define F first
#define S second
#define eb emplace_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

#define FI(i, a, b) for (ll i{a}; i <= b; i++)
#define FD(i, a, b) for (ll i{a}; i >= b; i--)

typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<pair<ll, ll>> vpii;
typedef pair<ll, ll> pi;

const ll mod{static_cast<ll>(1e9) + 7};
const ld Pi{3.14159265358979323846};

auto int_from(istream &in) -> int
{
    int x;
    in >> x;
    return x;
}

auto lng_from(istream &in) -> ll
{
    ll x;
    in >> x;
    return x;
}

auto str_from(istream &in) -> string
{
    string x;
    in >> x;
    return x;
}

auto chr_from(istream &in) -> char
{
    char x;
    in >> x;
    return x;
}

int main()
{
    IOS;
    ll a{lng_from(cin)}, b{lng_from(cin)}, c{lng_from(cin)};
    if (c % 2)
    {
        if (a > b)
        {
            cout << ">\n";
        }
        else if (a < b)
        {
            cout << "<\n";
        }
        else
        {
            cout << "=\n";
        }
    }
    else
    {
        a = abs(a);
        b = abs(b);
        if (a > b)
        {
            cout << ">\n";
        }
        else if (a < b)
        {
            cout << "<\n";
        }
        else
        {
            cout << "=\n";
        }
    }
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
long long a,b,c;
long long pw(long long x,long long y,long long md)
{
	long long rt=1;
	while(y)
	{
		if(y&1)
		{
			rt*=x;
			rt%=md;
		}
		x*=x;
		x%=md;
		y>>=1;
	}
	return rt;
}
int main()
{
	cin>>a>>b>>c;
	a%=10;
	if(a==0)
	{
		cout<<0<<endl;
	}
	if(a==1)
	{
		cout<<1<<endl;
	}
	if(a==2)
	{
		b%=4;
		long long nw=pw(b,c,4);
		if(nw==0)
		{
			cout<<6<<endl;
		}
		else if(nw==1)
		{
			cout<<2<<endl;
		}
		else if(nw==2)
		{
			cout<<4<<endl;
		}
		else
		{
			cout<<8<<endl;
		}
	}
	if(a==3)
	{
		b%=4;
		long long nw=pw(b,c,4);
		if(nw==0)
		{
			cout<<1<<endl;
		}
		else if(nw==1)
		{
			cout<<3<<endl;
		}
		else if(nw==2)
		{
			cout<<9<<endl;
		}
		else
		{
			cout<<7<<endl;
		}
	}
	if(a==4)
	{
		b%=2;
		long long nw=pw(b,c,2);
		if(nw==0)
		{
			cout<<6<<endl;
		}
		else
		{
			cout<<4<<endl;
		}
	}
	if(a==5)
	{
		cout<<5<<endl;
	}
	if(a==6)
	{
		cout<<6<<endl;
	}
	if(a==7)
	{
		b%=4;
		long long nw=pw(b,c,4);
		if(nw==0)
		{
			cout<<1<<endl;
		}
		else if(nw==1)
		{
			cout<<7<<endl;
		}
		else if(nw==2)
		{
			cout<<9<<endl;
		}
		else
		{
			cout<<3<<endl;
		}
	}
	if(a==8)
	{
		b%=4;
		long long nw=pw(b,c,4);
		if(nw==0)
		{
			cout<<6<<endl;
		}
		else if(nw==1)
		{
			cout<<8<<endl;
		}
		else if(nw==2)
		{
			cout<<4<<endl;
		}
		else
		{
			cout<<2<<endl;
		}
	}
	if(a==9)
	{
		b%=2;
		long long nw=pw(b,c,2);
		if(nw==0)
		{
			cout<<1<<endl;
		}
		else
		{
			cout<<9<<endl;
		}
	}
	return 0;
}


/* {{{ */
#include <bits/stdc++.h>
using namespace std;
#ifdef __LOCAL
#include <prettyprint.hpp>
#define debug(a) cerr << "[\033[33mDEBUG\033[m] " << (#a) << ": " << (a) << endl
#else
#define debug(s) cerr << "[\033[33mDEBUG\033[m] local only" << endl
#endif
using ll = long long;
template <class T> using vec = vector<T>;
#define endl "\n"
#define INF (int)1e9
#define LINF (long long)1e12
#define MOD (int)1e9+7
#define _rep(i,_a,_b,a,b,...) for (int i=(a), lim##i=(b); i<lim##i; i++)
#define rep(i, ...) _rep(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define _rrep(i,_a,_b,a,b,...) for (int i=(a), lim##i=(b); i>=lim##i; i--)
#define rrep(i, ...) _rrep(i, __VA_ARGS__, __VA_ARGS__, __VA_ARGS__, 0)
#define each(e, c) for (auto &e: c)
#define all(v) begin(v), end(v)
#define popcount __builtin_popcount
template <class T> bool chmin(T& a, const T& b) { return a>b?a=b,true:false; }
template <class T> bool chmax(T& a, const T& b) { return a<b?a=b,true:false; }
void init()
{
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}
/* }}} */

int n;
vec<vec<ll>> capa;

bool check(ll x)
{
  vec<bool> can(1 << 5, false);
  each(c, capa)
  {
    int bit = 0;
    rep(i, 5)
    {
      if (c[i] >= x) bit |= 1 << i;
    }
    can[bit] = true;
  }
  rep(i, 1 << 5) rep(j, i + 1) rep(k, j + 1)
  {
    if (can[i] && can[j] && can[k]
        and (i | j | k) == (1 << 5) - 1)
    {
      return true;
    }
  }
  return false;
}

int main()
{
  init();

  cin >> n;
  capa.resize(n);
  rep(i, n)
  {
    capa[i].resize(5);
    rep(j, 5) cin >> capa[i][j];
  }

  ll ok = -1, ng = LINF;
  while (ng - ok > 1)
  {
    ll mid = (ok + ng) / 2;
    if (check(mid)) ok = mid;
    else ng = mid;
  }

  cout << ok << endl;
}

#include <bits/stdc++.h>
using namespace std;
int a[3001][5];
int n;
bool valid(int req) {
    set<int> mask;
    for(int i = 0; i < n; i++) {
        int bits = 0;
        for(int j = 0; j < 5; j++) {
            if(a[i][j] >= req)
                bits |= (1 << j);
        }
        mask.insert(bits);
    }
    for (auto i : mask) {
        for (auto j : mask) {
            for (auto k : mask) {
                if((i | j | k) == 31)
                    return true;
            }
        }
    }
    return false;
}
void solve() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 5; j++) {
            cin >> a[i][j];
        }
    }
    int l = 0, r = 1000000001;
    while (l + 1 < r) {
        int mid = l + (r - l) / 2;
        if (valid(mid)) {
            l = mid;
        }
        else {
            r = mid;
        }
    }
    cout << l;
}
int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    //cout << fixed << setprecision(10);
    for (int i = 0; i < t; i++) {
        solve();
    }
    return 0;
}


///              B I S M I L L A H I R  R A H M A N I R  R A H I M

#include<bits/stdc++.h>
#include<vector>
#include<set>
#include<map>
using namespace std;
typedef bool                      boo;
typedef int                       li;
typedef long long int             ll;
typedef unsigned long long int    l1;
typedef double                    db;
//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

typedef vector < li >                   vli;
typedef vector < ll >                   vll;
typedef set < li >                      sli;
typedef set < ll >                      sll;
typedef pair < li , li >                pli;
typedef pair < ll , ll >                pll;
typedef map < li ,li >                  mli;
typedef map < ll ,ll >                  mll;
typedef vector < pair < li , li > >     vpi;
typedef vector < pair < ll , ll > >     vpl;

//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

#define tc                        int t;cin>>t;while(t--)
#define inp_i(a,n)                for(i=0; i<n ;i++) cin>>a[i]
#define lp(i,a,b)                 for(i=a;i<b;i++)
#define len(z)                    z.begin(),z.end()
#define faster                    ios::sync_with_stdio(0); cin.tie(0);cout.tie(0);
#define input_txt                 freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define nl                        <<endl
#define spc                       <<" "
#define sp                        <<" "<<
#define co(x)                     cout<<x nl
#define sz(a)                     a.size()
#define cy                        cout<<"YES" nl
#define cn                        cout<<"NO" nl
#define pb                        push_back
#define F                         first
#define S                         second
#define pi                        2*acos(0.0)
#define clr(z)                    z.clear()
#define rn                        return
#define gcd(a,b)                  __gcd(a,b)
#define mem(b,z)                  memset(b,z,sizeof(b))
#define fixed(x)                  fixed<<setprecision(x)
const int lx=3e5+123;

void solve()
{
    li n, k, x;
    cin>>n>>x;
    while(n--)
    {
        cin>>k;
        if(k != x) cout<<k spc;
    }
    cout nl;
}

int main()
{
faster

solve();
// A L H A M D U L I L L A H
// 1 2 3 2 1

}

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

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

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

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

void solve(long long N, long long K, std::vector<long long> a){
    map<int, int> cnt;
    int mx = 0;
    rep(i, N) {
        cnt[a[i]]++;
        mx = max<int>(mx, a[i]);
    }
    ll ans = 0;
    while (1) {
        int n = -1;
        rep(i, mx + 1) {
            if (cnt[i]) {
                n = i;
                cnt[i]--;
            } else {
                break;
            }
        }
        ans += n + 1;
        K--;
        if (n == -1 || K == 0) {
            break;
        }
    }
    cout << ans << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
int main(){
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    std::vector<long long> a(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&a[i]);
    }
    solve(N, K, std::move(a));
    return 0;
}


#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
// please, read the question correctly (do you need set or multiset)???
const int N=200010; //check the limits, dummy
int a[N];
int n, m;
int main(){
	// int t;
	// while(){
	int n, m, a, b;
		scanf("%d%d%d%d",&n,&m,&a,&b);
		int ans = n*b-m*a;
		cout<<ans<<endl;
	// }
}

#include <bits/stdc++.h>

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int arr[2][2];
	for(int i =0;i<2;++i){
		for(int j = 0;j<2;++j)cin >> arr[i][j];
	}
	cout << arr[0][0]*arr[1][1] - (arr[0][1]*arr[1][0]);
}


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

int main() {
  ll N;
  cin >> N;
  vector<pair<pair<ll, ll>, int>> lrt(N);
  for (int i = 0; i < N; i++){
    ll a, b, c;
    cin >> a >> b >> c;
    lrt.at(i).first.first = b;
    lrt.at(i).first.second = c;
    lrt.at(i).second = a;
  }
  sort(lrt.begin(), lrt.end());
  ll count = 0;
  for (int i = 0; i < N; i++) {
    if (lrt.at(i).second == 1 || lrt.at(i).second == 3) {
      for (int j = i + 1; j < N; j++) {
        if (lrt.at(i).first.second > lrt.at(j).first.first) {
          count++;
        }
        else if (lrt.at(i).first.second == lrt.at(j).first.first && lrt.at(j).second == 1) {
          count++;
        }
        else if (lrt.at(i).first.second == lrt.at(j).first.first && lrt.at(j).second == 2) {
          count++;
        }
      }
    }
    if (lrt.at(i).second == 2 || lrt.at(i).second == 4) {
      for (int j = i + 1; j < N; j++) {
        if (lrt.at(i).first.second > lrt.at(j).first.first) {
          count++;
      }
    }
  }
}
  cout << count << endl;
}

#include<iostream>
#include<cstdlib>
#include<utility>
#include<tuple>
#include<string>
#include<vector>
#include<numeric>
#include<algorithm>
#include<queue>
#include<deque>
#include<bitset>
#include<cmath>
#include<map>
#include<string>
#include<list>
#include<iomanip>
#include<set>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
const double PI = acos(-1);
#define rep(i, a, b) for(ll i = a; i < b; i++)
ll MOD(ll x) {
	return (x % mod + mod) % mod;
}

int main() {

	ll n; cin >> n;
	ll mini = mod, maxi = -1;
	vector<double>t(n), l(n), r(n);
	ll ans = 0;
	rep(i, 0, n) {
		cin >> t[i] >> l[i] >> r[i];
		if (t[i] == 2)r[i] -= 0.5;
		else if (t[i] == 3)l[i] += 0.5;
		else if (t[i] == 4) {
			r[i] -= 0.5; l[i] += 0.5;
		}
		rep(j, 0, i) {
			if (l[i] >= l[j] && l[i] <= r[j])ans++;
			else if (r[i] <= r[j] && r[i] >= l[j])ans++;
			else if (l[i] <= l[j] && r[i] >= r[j])ans++;
		}
	}
	cout << ans << endl;

	return 0;
}


// Generated by 2.3.1 https://github.com/kyuridenamida/atcoder-tools

#include <bits/stdc++.h>
// #include "atcoder/all"

#define SUBMIT

using namespace std;

using i64 = long long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;

template <typename T>
bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}

using Uint = uint64_t;

constexpr int n = 20;
array<Uint, n> h_res, w_res;

void solve(long long m, std::vector<std::string> s){

    // sort(s.begin(), s.end(), [](auto x, auto y){return x.size() < y.size();});
    int min_len = 100;
    int max_len = 0;

    vector<pair<int,Uint>> target(m);
    for(int i = 0; i < m; ++i){
        chmin(min_len, int(s[i].size()));
        chmax(max_len, int(s[i].size()));
        target[i].first = s[i].size();
        target[i].second = 0;
        for(int j = 0; j < s[i].size(); ++j){
            target[i].second |= ((s[i][j] - 'A') << (3 * j));
        }
    }

    for(int i = 0; i < n; ++i){
        for(int j = 0; j < n; ++j){
            Uint val = (rand() & 7);
            h_res[i] |= val << (j * 3);
            w_res[j] |= val << (i * 3);
        }
    }

    auto get = [&](int i, int j){
        Uint h = (h_res[i] >> (3 * j)) & 7;
        Uint w = (w_res[j] >> (3 * i)) & 7;
        assert(h == w);
        return h;
    };
    auto get_h = [&](int i, int j, int len){
        Uint h = (h_res[i] >> (3 * j)) & ((1uLL << (3 * len)) - 1);
        if(j + len > n){
            int over = j + len - n;
            return h | Uint((h_res[i] & ((1uLL << (3 * over)) - 1)) << (3 * (n - j)));
        }
        return h;
    };
    auto get_w = [&](int i, int j, int len){
        Uint w = (w_res[j] >> (3 * i)) & ((1uLL << (3 * len)) - 1);
        if(i + len > n){
            int over = i + len - n;
            return w | Uint((w_res[j] & ((1uLL << (3 * over)) - 1)) << (3 * (n - i)));
        }
        return w;
    };

    // TODO: hash_map
    vector<unordered_map<Uint, int>> now_hash(max_len + 1);
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < n; ++j){
            for(int l = min_len; l <= max_len; ++l){
                ++now_hash[l][get_h(i, j, l)];
                ++now_hash[l][get_w(i, j, l)];
            }
        }
    }

    // 以下回答関連
#ifndef SUBMIT
    int ans = 0;
    for(int i = 0; i < m; ++i){
        auto t = target[i];
        if(now_hash[t.first].count(t.second)){
            cout << "correct: " << i << "  " << s[i] << endl;
            ++ans;
        }
    }

    cout << "ans: " << ans << endl;
    cout << Uint(round(1e8 * ans / m)) << endl;
#endif

    for(int i = 0; i < n; ++i){
        for(int j = 0; j < n; ++j){
            cout << char('A' + ((h_res[i] >> (3 * j)) & 7));
        }
        cout << endl;
    }

    cout << endl;
}

signed main(){

#ifndef SUBMIT
    long long N;
    long long M;
    ifstream fs("../contests/ahc004/A/in/0001.txt");
    assert(fs.is_open());
    fs >> N >> M;
    std::vector<std::string> s(M);
    for(int i = 0 ; i < M ; i++){
        fs >> s[i];
    }
#else

    long long N;
    std::scanf("%lld", &N);
    long long M;
    std::scanf("%lld", &M);
    std::vector<std::string> s(M);
    for(int i = 0 ; i < M ; i++){
        std::cin >> s[i];
    }
#endif
    solve(M, std::move(s));
    return 0;
}

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

int main()
{
    int N,M;
    int x,y;
    string A[800];
    int score[800]={0};
    char dna[20][20];

    cin >> N >> M;

    for(int i=0; i<M; i++) {
        string a;
        cin >> a;

        bool iscontain=false;
        int conv=0;
        int convj=0;
        for( int j=0; j<i; j++)
            if(A[j].find(a)!=string::npos) {
                iscontain=true;
                if(score[j]>conv) {
                    conv=score[j];
                    convj=j;
                }
                break;
            }
        if(iscontain!=true) {
            A[i]=a;
            score[i]++;
        } else {
            score[convj]++;
            A[i]="";
        }
    }

    bool convine=true;

    while(convine) {
        convine=false;
        for(int i=0; i<M; i++) {
            if(A[i].size()>2){
                string b=A[i].substr(A[i].size()-2);
                for(int j=0; j<M; j++) {
                    if( i==j ) continue;
                    if( A[j][0]==b[0] && A[j][1]==b[1] ){
                        if( A[i].size()+A[j].size()-2 <= N) {
                            A[i] = A[i] + A[j].substr(2);
                            A[j] ="";
                            score[i]+=score[j];
                            score[j]=0;
                            convine=true;
                            break;
                        }
                    }
                }
            }
        }
    }

    convine=true;

    while(convine) {
        convine=false;
        for(int i=0; i<M; i++) {
            if(A[i].size()>2 && A[i].size()<N){
                for(int j=0; j<M; j++) {
                    if( i==j ) continue;
                    if( (A[j].size() > 2) && ((A[i].size()+A[j].size()) <= N) ){
                        A[i] = A[i] + A[j];
                        A[j] ="";
                        score[i]+=score[j];
                        score[j]=0;
                        convine=true;
                        break;
                    }
                }
            }
        }
    }

    for(int i=0; i<M; i++){
        int max=score[i];
        int maxj=i;
        for(int j=i; j<M; j++){
            if(score[j]>max) {
                max=score[j];
                maxj=j;
            }
        }
        if( i!=maxj){
            string tmp;
            tmp=A[maxj];
            A[maxj]=A[i];
            A[i]=tmp;
            int ti=score[maxj];
            score[maxj]=score[i];
            score[i]=ti;
        }
    }

    for(int i=0; i<N; i++) {
        if(A[i].size() < 20) A[i]+="....................";
    }

    for(int i=0; i<N; i++) {
        cout << A[i].substr(0,20) << endl;
    }
};


#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=(1<<19);
typedef long long LL;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
LL dp[maxn];
LL ma[20][20];
LL s[maxn];///标记该集合状态是否是完全图
LL b[maxn];///标记每个点的连通点图状态
int main(void){
   cin.tie(0);std::ios::sync_with_stdio(false);
   LL n,m;cin>>n>>m;
   for(LL i=1;i<=m;i++){
      LL u,v;cin>>u>>v;
      ma[u][v]=ma[v][u]=1;
   }
   for(LL i=1;i<=n;i++) b[i]=1<<(i-1);
   for(LL i=1;i<=n;i++){
      for(LL k=1;k<=n;k++){
          if(ma[i][k]) b[i]|=1<<(k-1);
      }
   }

   for(LL x=0;x<(1<<n);x++){
       bool flag=1;
       for(LL i=1;i<=n;i++){
           if(x&(1<<(i-1))){
               if(! ( (x|b[i])==b[i]) ){
                  flag=0;
                  break;
               }
           }
       }
       if(flag) s[x]=1;
   }
   memset(dp,0x3f,sizeof(dp));
   dp[0]=0;
   for(LL x=0;x<(1<<n);x++){
       for(LL i=x;i;i=(i-1)&x){
           if(s[i]) dp[x]=min(dp[x],dp[x^i]+1);
       }
   }
   cout<<dp[(1<<n)-1]<<"\n";
   return 0;
}

#pragma GCC target ("avx2")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("O3")
#include "bits/stdc++.h"
#include <unordered_set>
#include <unordered_map>
#include <random>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
constexpr ll MOD = 1'000'000'007LL; /*998'244'353LL;*/
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
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; }
constexpr int dy[4]={-1,0,1,0};
constexpr int dx[4]={0,-1,0,1};

int N, M;
int A[1000], B[1000];
bool con[18][18];

int dp[1<<18];
int solve(int s){
    if(dp[s] != -1) return dp[s];
    bool ok = true;
    rep(i, N){
        for(int j=i+1; j<N; j++){
            if(((s>>i)&1) & ((s>>j)&1)){
                ok &= con[i][j];
            }
        }
    }
    if(ok) return dp[s] = 1;
    int ret = 100;
    for(int i=(s-1)&s; i>0; i=(i-1)&s){
        chmin(ret, solve(i) + solve(i^s));
    }
    return dp[s] = ret;
}

signed main(){
    cin >> N >> M;
    rep(i, M){
        cin >> A[i] >> B[i];
        A[i]--; B[i]--;
        con[A[i]][B[i]] = true;
        con[B[i]][A[i]] = true;
    }
    memset(dp, -1, sizeof(dp));
    cout << solve((1<<N)-1) << endl;
}


// Code Written by Pinaki Bhattacharjee (pinakipb2)
#include<bits/stdc++.h>
using namespace std;

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

// #define
#define LOCAL
#define INF 1e18
#define PI 2*acos(0.0)
#define endl "\n"
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define ppc __builtin_popcountll
#define pinakipb2 ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

// constants
const int MAX = 2e5 + 5;
const int MOD = (int) 1e9 + 7;

ll func(ll a)
{
    ll temp=0;
    while(a)
    {
        temp += (a%10);
        a/=10;
    }
    return temp;
}

int main()
{
    pinakipb2;

    ll a,b;
    cin>>a>>b;
    cout<<max(func(a),func(b))<<endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define Rep(i,j,n) for(int i = j; i < (int)(n); i++)
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main(){
    int n; cin >> n;
    int ans = 0;
    rep(i,n){
        int a; cin >> a;
        a -= 10;
        if(a >= 0) ans += a;
    }
    cout << ans << endl;
    return 0;
}

/*
start of cp 3.0BETA
NEW-BETA-LADDER
https://codeforces.com/problemset/page/1?tags=1800-1800
DEAD PERSON CODING
*/
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define MOD 1000000007
#define int long long int
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define graph vector<vector<int>>
#define print(s) for(auto it:s) cout<<it<<" "
#define print2(s) for(auto it:s) cout<<it.fi<<" : "<<it.se
#define uset unordered_set
#define maxheap priority_queue<int>
#define minheap priority_queue<int,vi,greater<int>>
#define ln cout<<'\n'
#define space cout<<" "
#define len(x) x.size()
#define bits(x) __builtin_popcount(x)
void fileio()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
}
graph g;

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    fileio();
    int n,m;
    cin>>n>>m;
    int o=0,e=0;
    for(int i=0;i<n;i++){
        string x;
        cin>>x;
        int ct=0;
        for(int j=0;j<m;j++){
            ct+=(x[j]=='1');
        }
        if(ct&1)o++;
        else e++;
    }
    cout<<o*e;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 100;
typedef long long LL;
#define debug(x) cout << "debug : " << x << endl;

//#define int long long

//#define LOCAL
signed main() {
//	ios::sync_with_stdio(0);
//	cin.tie(0); cout.tie(0);
    int a, b, c, d; cin >> a >> b >> c >> d;
    int mx = -1e9;
    for(int i = a; i <= b; ++i) {
        for (int j = c; j <= d; ++j) {
            mx = max(i - j, mx);
        }
    }
    cout << mx << endl;

}

#include<iostream>
using namespace std;

int main() {
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  int x,y;
  if(a>b){
    x = a;
  }else x =  b;
  if(c>d){
    y =  d;
  }else y = c;
  cout<<x-y;
}


#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
#define SIZE(x) ll(x.size())
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
const long long MOD = 1000000007;
const int MAX_N = 10000;
typedef pair<int, int> P;

bool isPrime(int n) {
    bool flag = true;
    for (int i = 2; i * i <= n; i++) {
        if (n % i == 0) {
            flag = false;
            break;
        }
    }
    return flag;
}

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

    vector<int> ans, ct(4);
    set<int> st;
    int last = 3 * 5 * 7 * 11;
    ct[0] = 3;
    ct[1] = 5;
    ct[2] = 7;
    ct[3] = 11;
    for (int i2 = 2; i2 <= MAX_N; i2 += 2) {
        rep(i, 4) {
            int t = i2 * ct[i];
            if (t <= MAX_N) st.insert(t);
        }
    }

    int cnt = 0;
    for (auto i : st) {
        cout << i << " ";
        cnt++;
        if (cnt >= N - 1) break;
    }
    cout << last << endl;
    return 0;
}

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

bool solve(string s) {

    if(s.size() == 1) return s == "8";

    if(s.size() == 2){
        if(stoi(s) % 8 == 0) return 1;
        swap(s[0], s[1]);
        if(stoi(s) % 8 == 0) return 1;
        return 0;
    }

    vector<int> cnt(10, 0);

    int n = s.size();

    rep(i,n) cnt[s[i] - '0']++;

    for(int i = 112;i < 1000;i += 8) {
        auto c = cnt;

        for(char j : to_string(i)) c[j - '0']--;

        bool flag  = true;

        for(char j : to_string(i)){
            if(c[j - '0'] < 0) {
                flag = false;
            }
        }

        if(flag) return 1;
    }

    return 0;

}

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

    string ans;

    solve(s) ? ans = "Yes" : ans = "No";

    cout << ans << endl;

}


#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <numeric>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <random>
#include <list>
#include <iomanip>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <deque>
#include <math.h>
#include <assert.h>
#include <functional>
#include <bits/stdc++.h>
using namespace std;

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define ll long long
#define s(v) ((int)(v).size())
#define vLL(X) array<ll,X>
#define FOR(I,A,B) for(ll I = (A); I <= (B); I++)
#define RFOR(I,B,A) for(ll I = (B); I >=(A); I--)
#define SORT(c) (sort(c.begin(),c.end()))
#define aLL(X) X.begin(),X.end()
#define deb(x) cout << x << endl
#define deb1(x) cout << #x <<" "<< x << endl
#define deb2(x,y) cout << #x <<" "<< x <<" "<< #y <<" "<< y << endl
#define mem0(X) memset((X), 0, sizeof((X)))
#define mem1(X) memset((X), -1, sizeof((X)))
#define INS(v,v2) v.insert(v.end(), v2.begin(), v2.end());
#define BS(v,X) binary_search(v.begin(),v.end(),X)
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define CASES int ___T; cin >> ___T; for(int cs=1;cs<=___T;cs++)
#define Time cerr<<"Time elapsed: "<<1.0*clock()/CLOCKS_PER_SEC<< "sec \n"
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
template<typename T>T gcd(T x, T y){if(y==0)return x;else return gcd(y,x%y);}

ll fx4[] = {0, 0, 1, -1};
ll fy4[] = {1, -1, 0, 0};
ll fx8[] = {1, 1, 0, -1, -1, -1, 0, 1};
ll fy8[] = {0, 1, 1, 1, 0, -1, -1, -1};

using db  = double;
using LL  = long long;
using ull = unsigned long long;
using pII = pair <int, int>;
using pLL = pair <long long, long long>;

const ll INF   = 1e18;
const int mod  = 1000000007;
const ll L_inf = 9223372036854775807;
const int inf  = 2147483647;
const int mx   = 1000005;

bool isprime[mx];
ll POWER(ll y,ll z){ll res=1;while(z){if(z%2==1){res=(res*y)%mod;}y=(y*y)%mod;z>>=1LL;}return res;}
void SIEVE(){for(ll i=2; i<=mx; i++)isprime[i]=true;for(ll i=3; i<=mx; i+=2){if(isprime[i]==true)
{for(ll J=i*i; J<=mx; J+=i)isprime[J]=false;}}}

int main()
{
                IOS
                ll n, a, b;
                cin >> n >> a >> b;
                deb(n-a+b);

}

#include <bits/stdc++.h>
using namespace std;
int a, b, c, d, w;
int main()
{
	cin >> a >> b >> w;
	c = (w * 1000 + b - 1) / b;
	d = w * 1000 / a;
	if (d < c)
	{
		cout << "UNSATISFIABLE" << endl;
	}
	else
	{
		cout << c << ' ' << d << endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pii;
#define ffor(i,n) for(ll i=0;i<n;i++)
#define rfor(x,y) for(ll i=x;i<y;i++)
#define ff first
#define ss second
#define pb push_back
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define all(v) v.begin(),v.end()
#define vi std::vector<ll>
#define M 1000000007
bool cmp(pii a,pii b)
{
	return 2*a.ff + a.ss > 2*b.ff + b.ss;
}
void solve()
{
	ll n;
	cin>>n;
	vector<pii> v(n);
	ll a=0,k=0;
	ffor(i,n){
	cin>>v[i].ff>>v[i].ss;
	a+=v[i].ff;}
	k = 0;
	sort(all(v),cmp);
	ll i=0;
	while(a >= k)
	{
		k += (v[i].ff + v[i].ss);
		a -= v[i].ff;
		i++;
	}
	cout<<i<<endl;
	return;

}
int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.in","r",stdin);
    freopen("output.in","w",stdout);
    #endif
    fastio
    ll t=1;
    // cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}

// code by lynmisakura. wish to be accepted!
#include<bits/stdc++.h>

using ll = long long;
using namespace std;
#define debug(arr) std::cout << #arr << " = " << arr << '\n'
#define debug2(a,b) std::cout<<"["<<#a<<","<<#b<<"] = "<<"["<<a<<","<<b<<"]\n"
#define debug3(a,b,c) std::cout<<"["<<#a<<","<<#b<<","<<#c<<"] = "<<"["<<a<<","<<b<<","<<c<<"]\n"
template<class T> std::ostream &operator << (std::ostream& out, const std::vector<T>& arr) {
  std::cout << "{"; for (int i = 0; i < arr.size(); i++)std::cout << (!i ? "" : ", ") << arr[i]; std::cout << "}";
  return out;
}
template<class T> std::ostream &operator << (std::ostream& out, const std::vector<std::vector<T> >& arr) {
  std::cout << "{\n"; for (auto& vec : arr)std::cout << "  " << vec << ",\n"; std::cout << "}";
  return out;
}
template<class S,class T> std::ostream &operator << (std::ostream& out, const std::pair<S,T>& p){
  std::cout << "{" << p.first << "," << p.second << "}" << '\n';
  return out;
}
template<class T> std::istream &operator >> (std::istream& in, std::vector<T>& arr) {
  for (auto& i : arr) std::cin >> i; return in;
}
template<class S,class T> std::istream &operator >> (std::istream& in,std::pair<S,T>& p){
  std::cin >> p.first >> p.second; return in;
}
template<class T> void debug_a(T *a , int N){
  std::cout << "debug array : {";
  for(int i = 0;i < N;i++){
    std::cout << *(a + i) << (i < N-1 ? ", " : "}\n");
  }
}
#define REP(i,N) for(int i = 0;i < N;i++)

int n,q;
vector<int> graph[200020];
int U[200020],D[200020];

void __input__(){
  cin >> n;
  REP(i,n-1){
    int p;cin >> p;
    p--;
    graph[i+1].push_back(p);
    graph[p].push_back(i+1);
  }
  cin >> q;
  REP(i,q) cin >> U[i] >> D[i] , U[i]--;
}

int dist[200020];
pair<int,int> pos[200020];
vector<int> dists[200020];
int num = 0;
vector<int> tour;
void dfs(int x,int p,int d){
  tour.push_back(x);
  dists[d].push_back(num);
  pos[x].first = num++;
  dist[x] = d;
  for(int to : graph[x]){
    if(to != p) dfs(to,x,d+1);
  }
  tour.push_back(-x);
  pos[x].second = num++;
  return;
}

int main(){

  __input__();

  dfs(0,-1,0);
//  debug(tour);
  REP(i,200020) dists[i].push_back(100000000);
  REP(i,q){
    cout << lower_bound(dists[D[i]].begin(),dists[D[i]].end(),pos[U[i]].second)
              -  lower_bound(dists[D[i]].begin(),dists[D[i]].end(),pos[U[i]].first) << '\n';
  }

}


#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
typedef long long ll;
#define test ll t;cin>>t;while(t--)
#define f first
#define s second
#define pb push_back
#define pop pop_back
#define int long long int
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define mod 1000000007
#define inf 1LL<<60
int grid[16][16];
int ans;

bool check(int h,int w)
{
    for(int i=0;i<h;i++)
    {
        for(int j=0;j<w;j++)
        {
            if(grid[i][j]==-1)
                return false;
        }
    }
    return true;
}
void helper(int h,int w,int a,int b)
{

    if(a==0 && b==0)
    {

        if(check(h,w))
        {
            ans++;

        }

        return;
    }

    int i,j;
    bool flag=0;
    for(int x=0;x<h;x++)
    {
        for(int y=0;y<w;y++)
        {
            if(grid[x][y]==-1)
            {

                i=x;
                j=y;
                flag=1;
                break;
            }
        }
        if(flag)
            break;
    }
    if(a>0 && grid[i][j]==-1 && j+1<w && grid[i][j+1]==-1)
    {
        grid[i][j]=1;
        grid[i][j+1]=1;
        helper(h,w,a-1,b);
        grid[i][j]=-1;
        grid[i][j+1]=-1;
    }

     if(a>0 && grid[i][j]==-1 && i+1<h && grid[i+1][j]==-1)
    {
        grid[i][j]=1;
        grid[i+1][j]=1;
        helper(h,w,a-1,b);
        grid[i][j]=-1;
        grid[i+1][j]=-1;
    }

      if(b>0 && grid[i][j]==-1)
    {
        grid[i][j]=1;
        helper(h,w,a,b-1);
        grid[i][j]=-1;
    }

    return;
}
int32_t main()
{
	fast;
	int h,w,a,b;

	cin>>h>>w>>a>>b;
	ans=0;
	memset(grid,-1,sizeof(grid));
	helper(h,w,a,b);
	cout<<ans;
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

#define _for(i,a,b) for(int i = (a); i < (b); i++)
#define _rep(i,a,b) for(int i = (a); i <= (b); i++)
#define all(v) (v).begin(), (v).end()
#define nl "\n"
#define reunique(v) v.resize(std::unique(v.begin(), v.end()) - v.begin())
#define sz(v) ((int)(v).size())
//#define LOCAL

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

#ifdef LOCAL
//#include "pretty_print.h"
#define dbg(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define dbg(...) 42
#endif

template <typename T> T sqr(T x) { return x * x; }
template <typename T> T abs(T x) { return x < 0? -x : x; }
template <typename T> T gcd(T a, T b) { return b? gcd(b, a % b) : a; }
template <typename T> bool chmin(T &x, const T& y) { if (x > y) { x = y; return true; } return false; }
template <typename T> bool chmax(T &x, const T& y) { if (x < y) { x = y; return true; } return false; }

auto random_address = [] { char *p = new char; delete p; return (uint64_t) p; };
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count() * (random_address() | 1));
mt19937_64 rngll(chrono::steady_clock::now().time_since_epoch().count() * (random_address() | 1));

#define PI acos(-1)
void taskD() {
    double n, x0, y0, x1, y1;
    cin >> n >> x0 >> y0 >> x1 >> y1;
    double a = 2*PI/n;
    double xm = (x0+x1)/2;
    double ym = (y0+y1)/2;
    double x = (x0-xm)*cos(a) - (y0-ym)*sin(a)+xm;
    double y = (x0-xm)*sin(a) + (y0-ym)*cos(a)+ym;
    //cout << " PI = " << PI << "\n";
    cout << setiosflags(ios::fixed) << setprecision(11) << x << " ";
    cout << setiosflags(ios::fixed) << setprecision(11) << y << "\n";
    return;
}

int main() {
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
    taskD();
    //task10391();
    //task1595();
#ifdef LOCAL
    //assert(freopen("i.txt", "r", stdin));   assert(freopen("o.txt", "w", stdout));
    //freopen("i.txt", "r", stdin);   freopen("o.txt", "w", stdout);
    cerr << "Time execute: " << clock() / (double)CLOCKS_PER_SEC << " sec" << endl;
#endif
    return 0;
}


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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
// const ll mod = 998244353;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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

void solve() {
    int h, w; cin >> h >> w;
	vector<string> s(h);
	rep(i, h) cin >> s[i];
	vector<vec> yoko(h+1, vec(w, 0)), tate(h, vec(w+1, 0));

	rep(i, h){
		rep(j, w){
			if(s[i][j] == '#'){
				if(s[i+dy[0]][j+dx[0]] != '#') yoko[i+1][j] = 1;
				if(s[i+dy[1]][j+dx[1]] != '#') tate[i][j+1] = 1;
				if(s[i+dy[2]][j+dx[2]] != '#') yoko[i][j] = 1;
				if(s[i+dy[3]][j+dx[3]] != '#') tate[i][j] = 1;
			}
		}
	}

	int res = 0;
	rep(i, h+1){
		bool f = false;
		rep(j, w){
			if(yoko[i][j]){
				if(!f){
					f = true;
				}
			}else{
				if(f){
					f = false;
					res++;
				}
			}
		}
	}

	rep(j, w+1){
		bool f = false;
		rep(i, h){
			if(tate[i][j]){
				if(!f){
					f = true;
				}
			}else{
				if(f){
					f = false;
					res++;
				}
			}
		}
	}

	cout << res << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(c) (c).begin(), (c).end()
#define pb push_back
#define eb emplace_back
using namespace std;
const long long INF = 1LL<<60; // 仮想的な無限大の値;
using ll = long long;
using P  = pair<int, int>;
#define vi vector<int>
#define vll vector<ll>
#define vs vector<string>
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; }
ll gcd(ll a, ll b){
    if(b == 0) return a;
    return gcd(b, a%b);
}
int main()
{
    int n;
    cin >> n;
    vll a(n);
    rep(i, n) cin >> a[i];
    ll x = a[0];
    rep(i, n){
        x = gcd(x, a[i]);
    }
    cout << x << endl;
    // ll MAX = -1, MIN = INF;
    // multiset<ll> X;
    // rep(i, n){
    //     cin >> a[i];
    //     chmax(MAX, a[i]);
    //     chmin(MIN, a[i]);
    //     X.insert(a[i]);
    // }
    // rep(i, n){
    //     ll max = *X.rbegin();
    //     if(a[i] == max){
    //         cout << a[i] << endl;return 0;
    //     }
    //     rep(i, X.count(max)) X.insert(*X.rbegin()-*X.begin());
    //     X.erase(max);
    // }
    // ll ans = *X.begin();
    // cout << *X.begin() << endl;return 0;
    return 0;
}

#include "bits/stdc++.h"

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define rrep(i, n) for(ll i=(n)-1; i >=0; i--)
#define ALL(v) v.begin(),v.end()
#define rALL(v) v.rbegin(),v.rend()
#define FOR(i, j, k) for(ll i=j;i<k;i++)
#define debug_print(var) cerr << #var << "=" << var <<endl;
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cerr<<v[i]<<" "
#define fi first
#define se second

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
typedef long double ld;
struct edge{ll x, c;};

vector<llvec> e;
llvec p;

using PP = pair<ll, P>;
vector<ll> d;
llvec tour;
vector<P> range;

void dfs(ll i){
  range[i].fi = tour.size();
  tour.push_back(d[i]);
  for(auto ie: e[i]){
    d[ie] = d[i] + 1;
    dfs(ie);
  }
  //tour.push_back(d[i]);
  range[i].se = tour.size();
  return;
}

/**************************************
** A main function starts from here  **
***************************************/
int main(){
  ll N;
  cin >> N;
  p = llvec(N);
  d = llvec(N, -1);

  e = vector<llvec>(N);
  //tour = llvec(N);
  range = vector<P>(N);

  rep(i, N-1){
    ll t;
    cin >> t;
    t--;
    e[t].push_back(i+1);
  }
  d[0] = 0;
  dfs(0);

  ll Q;
  cin >> Q;
  vector<P> v(Q);

  rep(i, Q){
    ll u, t;
    cin >> u >> t;
    u--;
    v[i] = {u, t};
  }

  vector<llvec> dd(N+1);
  ll cnt = 0;
  for(auto i: tour){
    dd[i].push_back(cnt);
    cnt++;
  }

  for(auto iv: v){
    ll num = lower_bound(ALL(dd[iv.se]), range[iv.fi].se) - lower_bound(ALL(dd[iv.se]), range[iv.fi].fi);
    cout << num << endl;
  }

  return 0;
}


#include <iostream>
#include <vector>

using namespace std;

int main()
{
	vector<int> d(3);
	int ans = 0;
	for (auto& x : d) {
		cin >> x;
		ans += 7 - x;
	}
	cout << ans << endl;
}

#include <bits/stdc++.h>
using namespace std;
int d4r[] = {1, 0, -1, 0}, d4c[] = {0, 1, 0, -1};
int d8r[] = {1, 1, 0, -1, -1, -1, 0, 1}, d8c[] = {0, 1, 1, 1, 0, -1, -1, -1};
constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
constexpr int INF = 1001001001;
constexpr long long LINF = 1001002003004005006;
constexpr double PI = acos(-1);
template<typename T> inline void chmax(T &a, T b) {a = max(a, b);}
template<typename T> inline void chmin(T &a, T b) {a = min(a, b);}

int main() {
    int a,b,c; cin >> a >> b >> c;
    cout << 21- a-b-c << '\n';
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using ll=long long;

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)

int main() {

	int n,k,m;
	cin >> n >> k >> m;
	int a=0;
	int temp;
	rep(i,n-1) {
		cin >> temp;
		a += temp;
	}
	//cout << a << endl;
	rep(i,k+1) {
		if (((a + i)/n)>=m) {
			cout << i << endl;
			return 0;
		}
	}
	cout << "-1" << endl;
  return 0;
}

#include <iostream>
using namespace std;

int main(){
  int n, k, m, sum = 0;
  cin >> n >> k >> m;
  int *a = new int[n];
  for(int i=0;i<n-1;i++){
    cin >> a[i];
  }
  for(int i=0;i<n-1;i++){
    sum += a[i];
  }
  if(n*m-sum<=k){
    if(n*m-sum>0){
      cout << n*m-sum << endl;
    }else {
      cout << '0' << endl;
    }
  }else{
    cout << "-1" << endl;
  }
  return 0;
}


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

int main() {
	int n;
	cin >> n;
	vector<int> x(n);
	rep(i,n) cin >> x[i];
	ll ansM=0;
	double ans=0;
	int ansC=0;
	ll ansU=0;
	rep(i,n) {
		ansM += abs(x[i]);
		ll x2 = ll(x[i])*ll(x[i]);
		ansU += x2;
		ansC = max(ansC,abs(x[i]));
	}
	ans +=ansU;
	ans = sqrt(ans);
	cout << ansM << endl;
	printf("%.15lf\n", ans);
	cout << ansC << endl;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
int n,p,ans;
bool b[200010];
inline int read()
{
	int num=0,flag=1;
	char c=getchar();
	for (;c<'0'||c>'9';c=getchar())
	if (c=='-') flag=-1;
	for (;c>='0'&&c<='9';c=getchar())
	num=(num<<3)+(num<<1)+c-48;
	return num*flag;
}
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	memset(b,0,sizeof(b));
	ans=0;
	n=read();
	for (int i=1;i<=n;++i)
	{
		p=read();
		b[p]=true;
		if (ans==p)
		for (int j=p+1;j<=200000;++j)
		if (!b[j])
		{
			ans=j;
			break;
		}
		printf("%d\n",ans);
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}


#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;

#define ll     long long
#define test   int tt; cin>>tt; while(tt--)
#define ff     first
#define ss     second
#define pb     push_back
#define ppb    pop_back
#define pf     push_front
#define ppf    pop_front

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

    int n;
    cin>>n;

    vector<pair<pair<int, int>, int>> intervals(n);

    for(auto &[in, t]: intervals)
        cin>>t>>in.ff>>in.ss;

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

    ll int ans=0;

    for(int i=0; i<n; i++)
    {
        for(int j=i+1; j<n; j++)
        {
            int l1=intervals[i].ff.ff;
            int r1=intervals[i].ff.ss;
            int t1=intervals[i].ss;

            int l2=intervals[j].ff.ff;
            int r2=intervals[j].ff.ss;
            int t2=intervals[j].ss;

            if((t1==1 || t1==3) && t2<=2 && r1>=l2)
                ans++;
            else if((t1==1 || t1==3) && t2>2 && r1>l2)
                ans++;
            else if((t1==2 || t1==4) && r1>l2)
                ans++;

        }
    }

    cout<<ans<<endl;
}

#include <bits/stdc++.h>
#include <iostream>
#include<stdio.h>
#include<math.h>
#include<string.h>
using namespace std;
double mina(double a,double b)
{
    if(a<=b)
    return a;
    return b;
}
double maxa(double a,double b)
{
    if(a<=b)
    return b;
    return a;
}

int main() {
   long long int t,n,i,j,k,l,flag,flag1,count,count1,count2,count3,count4,sum,max1,max2,m,c1,c2,temp,suma,sumb;
  long long int d,e,a,b,c;

  double a2[300001],b1[2002][3],a1[300001];

        //vector< long long int> v1,v2,v;
        //  vector< pair <long long int,long long int> > v3;
  //  string s1,s2,s;
//  char s[300001],s1[300001];
  //  long long int f[100001];
  //   for(i=0;i<100001;i++)
  //    f[i]=0;
    count=0,flag=0,flag1=0,sum=0,max1=0,max2=0,c1=0,c2=0,temp=0,suma=0,sumb=0,count1=0,count2=0,count3=0,count4=0;
  // long long int max3=0,max4=0,ans=0,mina=999999999999999999,c0=0,c3,c4;
   cin>>n;
   for(i=0;i<n;i++)
   {
       for(j=0;j<3;j++)
       cin>>b1[i][j];
   }
   for(i=0;i<n;i++)
   {
       if(b1[i][0]==2)
       b1[i][2]=b1[i][2]-0.1;
      else  if(b1[i][0]==3)
       b1[i][1]=b1[i][1]+0.1;
        if(b1[i][0]==4)
        {
       b1[i][2]=b1[i][2]-0.1;
       b1[i][1]=b1[i][1]+0.1;
        }

   }

   for(i=0;i<n;i++)
   {
       if(b1[i][1]>b1[i][2])
       swap(b1[i][1],b1[i][2]);
   }
   for(i=0;i<n;i++)
   {
       for(j=i+1;j<n;j++)
       {
           if(mina(b1[i][2],b1[j][2]) >=maxa( b1[i][1],b1[j][1]) )
           count++;

       }
   }
   //for(i=0;i<n;i++)
  // for(j=0;j<3;j++)
  // cout<<b1[i][j];
   cout<<count;
	return 0;
}


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

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

using namespace std;
using li = int;

const li INF = 0x3fffffff;

struct vertex {
    vector<li> neigh;
};

int main() {

    li n, m, a, b, k; cin >> n >> m;

    vector<vertex> vertices(n + 1);

    while (m--) {
        cin >> a >> b;
        vertices[a].neigh.push_back(b);
        vertices[b].neigh.push_back(a);
    }

    cin >> k;
    vector<li> gems(k, 0);
    for_n(i, k) cin >> gems[i];

    auto bfs = [&](int beg) {

        vector<li> costs(n + 1, INF);
        costs[beg] = 0;
        queue<li> queue;
        queue.push(beg);

        while (!queue.empty()) {
            li next = queue.front(); queue.pop();
            for (auto y : vertices[next].neigh) {
                if (costs[next] + 1 < costs[y]) {
                    costs[y] = costs[next] + 1;
                    queue.push(y);
                }
            }
        }

        vector<li> final_costs(k, 0);
        for_n(i, k) final_costs[i] = costs[gems[i]];

        return final_costs;
    };

    vector<vector<li>> dp(1 << k, vector<li>(k, INF));
    vector<vector<li>> costs(k);

    for_n(i, k) costs[i] = bfs(gems[i]);
    for (li i = 0; i < k; i++) dp[1 << i][i] = 1;
    for (li bit = 1; bit < 1 << k; bit++)
        for (li i = 0; i < k; i++)
            if (bit & 1 << i) {

                li bit2 = bit ^ 1 << i;

                for (li j = 0; j < k; j++)
                    if (bit2 & 1 << j)
                        dp[bit][i] = min(dp[bit][i], dp[bit2][j] + costs[i][j]);

            }

    li ans = *min_element(dp.back().begin(), dp.back().end());
    if(ans == INF) ans = -1;
    cout << ans << endl;

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do { (t*=10)+=ch-'0'; ch=getchar(); } while ('0'<=ch&&ch<='9'); t*=f;
}
const int maxn=(2e5)+10;
int n,k,mid,tot;
vector<int> g[maxn];
int mx[maxn];
void dfs(int u,int p) {
	mx[u]=0;
	for (int v : g[u]) if (v!=p) {
		dfs(v,u);
		if (mx[u]+mx[v]+1>2*mid) {
			tot++;
			mx[u]=min(mx[u],mx[v]+1);
		} else mx[u]=max(mx[u],mx[v]+1);
	}
}
bool solve() {
	tot=0;
	dfs(1,0);
	return tot+1<=k;
}
int main() {
	//freopen("1.txt","r",stdin);
	read(n),read(k); int x,y;
	for (int i=1;i<n;i++) {
		read(x),read(y);
		g[x].push_back(y),g[y].push_back(x);
	}
	int l=0,r=n,res;
	while (l<=r) {
		mid=(l+r)>>1;
		if (solve()) res=mid,r=mid-1;
		else l=mid+1;
	}
	printf("%d\n",res);
	return 0;
}
/*
  0. Enough array size? Enough array size? Enough array size? Integer overflow?

  1. Think TWICE, Code ONCE!
  Are there any counterexamples to your algo?

  2. Be careful about the BOUNDARIES!
  N=1? P=1? Something about 0?

  3. Do not make STUPID MISTAKES!
  Time complexity? Memory usage? Precision error?
*/


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

typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FOR1(i, n) for(int (i)=1; (i)<=(n); (i)++)
#define FORI(i, n) for(int (i)=n-1; (i)>=0; (i)--)
template<class T, class U> void umin(T& x, const U& y){ x = min(x, (T)y);}
template<class T, class U> void umax(T& x, const U& y){ x = max(x, (T)y);}
template<class T, class U> void init(vector<T> &v, U x, size_t n) { v=vector<T>(n, (T)x); }
template<class T, class U, typename... W> void init(vector<T> &v, U x, size_t n, W... m) { v=vector<T>(n);  for(auto& a : v) init(a, x, m...); }

int n;
vector<ll> d; vector<int> mtl;
vector<vector<int>> edges;
vector<int> par;
vector<bool> marked;

int mintoleaf(int u, int p){
    if (mtl[u]!=-1) return mtl[u];
    int ret = n+1;
    for(int v : edges[u]) if (v !=p){
            umin(ret, 1 + mintoleaf(v, u));
        }
    if (edges[u].size() == 1)
        ret = 0;
    return mtl[u] = ret;
}

void dfs1(int u, int p){
    for(int v : edges[u]) if (v !=p){
            d[v] = d[u]+1;
            par[v] = u;
            dfs1(v, u);
        }
}

int dfs(int u, int p, int e){
    d[u] = e;
    vector<pii> o;
    for(int v : edges[u]) if (v != p){
            o.emplace_back(mintoleaf(v, u), v);
            if (marked[v]) o.back().first = 1e9;
        }
    sort(o.begin(), o.end());
    int start = e+1;
    for(auto it : o){
        int dist = dfs(it.second, u, start);
        start = dist + 1;
    }
    return start;
}

int main(int argc, char** argv) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << setprecision(15);
    if (argc == 2 && atoi(argv[1]) == 123456789) freopen("d:\\code\\cpp\\contests\\stdin", "r", stdin);
    cin >> n;
    edges.resize(n+1);
    d.resize(n+1);
    mtl.resize(n+1, -1);
    FOR(i, n-1){
        int u, v;
        cin >> u >> v;
        edges[u].push_back(v);
        edges[v].push_back(u);
    }

    int ondiag = 1;
    d.clear(); d.resize(n + 1);
    par.clear(); par.resize(n+1);
    dfs1(ondiag, -1);
    int dist = -1;
    ondiag = -1;
    FOR1(u, n) {
        if (d[u] > dist) {
            dist = d[u];
            ondiag = u;
        }
    }
    d.clear(); d.resize(n + 1);
    par.clear(); par.resize(n+1);
    dfs1(ondiag, -1);
    marked.clear(); marked.resize(n+1);

    dist = -1;
    int other = -1;
    FOR1(u, n){
        if (d[u] > dist){
            dist = d[u];
            other = u;
        }
    }

    marked[other] = 1;
    while(other!=ondiag){
        other = par[other];
        marked[other] = 1;
    }

    d.clear(); d.resize(n + 1);
    dfs(ondiag, -1, 1);

    FOR1(i, n)
        cout << d[i] << " "; cout << endl;

    if (argc == 2 && atoi(argv[1]) == 123456789) cout << clock()*1.0/CLOCKS_PER_SEC << " sec\n";
    return 0;
}

//                        YATIN KWATRA

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

#define ll                      long long
#define ar                      array
#define sz(v)                   (int)(v.size())
#define inf                     1e18
#define int                     ll
#define FIO                     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ld                      long double
#define ull                     unsigned long long
#define endl                    "\n"
#define fo(i,a,b)               for(int i = a; i<=b ; i++)
#define rfo(i,a,b)              for(int i = a; i>=b ; i--)
#define vii                     vector<int>
#define pq                      priority_queue
#define uomii                   unordered_map<int,int,best_hash>
#define all(v)                  v.begin(),v.end()
#define mp                      make_pair
#define pb                      push_back
#define pob                     pop_back
#define ff                      first
#define ss                      second
#define pii                     pair<int,int>
#define mii                     map<int,int>
#define vvii                    vector<vii>
#define mod                     200
#define MIN                     -1e9
#define pi                      3.1415926535897932384626433832795
#define cz(x)                   63 - __builtin_clzll(x)

using namespace std;
using namespace __gnu_pbds;
template<class T> using oset =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

struct best_hash {
	static uint64_t splitmix64(uint64_t x) {

		x += 0x9e3779b97f4a7c15;
		x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
		x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
		return x ^ (x >> 31);
	}

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

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

/*
----------------------------------------------------------------
   -> Check For Overflows
   -> Out of Bounds
   -> Initialisations of global arrays and variables
----------------------------------------------------------------
*/

void solve()
{
	int n;
	cin >> n;
	vii v(n);
	fo(i, 0, n - 1) cin >> v[i], v[i] %= mod;
	uomii dp;
	n = min(n, 20LL);
	for (int mask = 1; mask < (1 << n); mask++) {
		int sum = 0;
		fo(i, 0, n - 1) if (mask & (1 << i)) sum = (sum + v[i]) % mod;
		if (dp.count(sum)) {
			cout << "YES\n";
			cout << __builtin_popcount(mask) << " ";
			fo(i, 0, n - 1) {
				if (mask & (1 << i)) cout << i + 1 << " ";
			}
			cout << endl;
			cout << __builtin_popcount(dp[sum]) << " ";
			fo(i, 0, n - 1) {
				if (dp[sum] & (1 << i)) cout << i + 1 << " ";
			}
			cout << endl;
			return;

		}
		dp[sum] = mask;
	}
	cout << "NO\n";
}

signed main() {

	FIO
	INPUT();

	int t;
	t = 1;
	//cin >> t;
	fo(i, 0, t - 1) {
		solve();
	}
	return 0;
}