#include<bits/stdc++.h>

using namespace std;

int mx=200005;

bool prime[200005];
vector <int> vec;

void normal_sieve(int n)
{
    int i, N=sqrt(n), p;

    memset(prime, 1, sizeof(prime));

    for(p=3; p<=N; p+=2)
    {
        if(prime[p]==1)
        {
            for(i=p*p; i<=n; i+=p)
            {
                prime[i]=0;
            }
        }
    }
    vec.push_back(2);
    for(i=3; i<200001; i+=2)
    {
        if(prime[i] == 1)
            vec.push_back(i);
    }
}

int main()
{
    int a,b;
    cin >> a >> b;
    int mx = 0;
    int dif = b-a;
    for(int i=dif; i>=0; i--)
    {
        int low = ceil(a*1.0/i);
        int high = floor(b*1.0/i);
        if(low*i >= a && low*i<=b && high*i>=a && high*i<=b && low!=high)
        {
            mx = i;
            break;
        }
    }
    cout << mx << endl;
    return 0;
}

#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <bitset>
#include <iomanip>
#include <cmath>
#include <set>
#include <unordered_set>
#include <functional>
#include <map>
#include <unordered_map>
#include <string>
#include <tuple>
using namespace std;
using ll = long long;
const int MOD=1e9+7;
const int MAX=100009;
ll fac[100009],finv[100009],inv[100009];

#define pi 3.14159265358979323846
#define ee 2.71828182845904523536
#define INF 1e18+1

ll gcd(ll x, ll y) { // 最大公約数
    if (y == 0)return x;
    else return gcd(y, x % y);
}

bool prime(ll x) { //素数判定
    if(x==1)return false;
    if (x!=2&&x % 2 == 0)return false;
    for (ll i = 3; i <= sqrt(x); i+=2) {
        if (x % i == 0)return false;
    }
    return true;
}

ll modinv(ll a, ll m) { //逆元
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

ll modpow(ll a, ll n, ll mod) { //二分累乗法
    ll res = 1;
    while (n) {
        if (n % 2)res = res * a % mod;
        a = a * a % mod;
        n /= 2;
    }
    return res;
}

void COMinit() { //二項係数計算の前処理
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

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

struct UnionFind {   // UnionFind
    vector<int> par;
    vector<int> siz;

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

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

    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        if (par[rx] > par[ry])swap(rx, ry);
        siz[rx] += siz[ry];
        par[ry] = rx;
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
    int size(int x) {
        return siz[root(x)];
    }
};

int main() {
    int a,b;
    cin>>a>>b;
    if(a>b){
        for(int i=0;i<a;i++){
            cout<<i+1<<" ";
        }
        int sum=a*(a+1)/2;
        for(int i=0;i<b-1;i++){
            cout<<-(i+1)<<" ";
            sum-=(i+1);
        }
        cout<<-sum<<endl;
    }
    else{
        for(int i=0;i<b;i++){
            cout<<-(i+1)<<endl;
        }
        int sum=b*(b+1)/2;
        for(int i=0;i<a-1;i++){
            cout<<i+1<<" ";
            sum-=(i+1);
        }
        cout<<sum<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define reps(i, s, n) for(int i = (s); i < (n); i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, s, n) for(int i = (n) - 1; i >= (s); i--)
#define INF ~(1 << 31)
#define INFL ~(1LL << 63)

int main()
{
    int N;
    cin >> N;
    vector<int> p(N);
    vector<bool> used(N+1);
    int ans = 0;
    rep(i, N){
        cin >> p[i];
        used[p[i]] = true;
        if(ans == p[i]){
            reps(i, ans+1, N+1){
                if(!used[i]){
                    ans = i;
                    break;
                }
            }
        }
        cout << ans << endl;
    }
}

#include <bits/stdc++.h>

using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int N;
    cin >> N;
    vector<int64_t> x(N);
    for (int i = 0; i < N; i++) {
        cin >> x[i];
    }
    int64_t man = 0;
    for (int i = 0; i < N; i++) {
        man += abs(x[i]);
    }
    cout << man << "\n";
    double euclid = 0;
    for (int i = 0; i < N; i++) {
        euclid += pow(x[i],2);
    }
    cout << setprecision(12) << fixed;
    cout << sqrt(euclid) << "\n";
    int64_t cheby = 0;
    for (int i = 0; i < N; i++) {
        cheby = max(cheby, abs(x[i]));
    }
    cout << cheby << "\n";
}


#include <bits/stdc++.h>

int nextInt() {
    int temp; scanf("%d", &temp);
    return temp;
}
long long nextLL() {
    long long temp; scanf("%lld", &temp);
    return temp;
}

void print(int x, char endc = '\n') {
    printf("%d%c", x, endc);
    return;
}
void print(long long x, char endc = '\n') {
    printf("%lld%c", x, endc);
    return;
}
void print(size_t x, char endc = '\n') {
    printf("%zu%c", x, endc);
    return;
}
void print(float x, char endc = '\n') {
    printf("%f%c", x, endc);
    return;
}
void print(double x, char endc = '\n') {
    printf("%lf%c", x, endc);
    return;
}

template<typename T1, typename T2>
void print(std::pair<T1, T2> &p, char sepc = ' ', char endc = '\n') {
    print(p.first, sepc);
    print(p.second, endc);
    return;
}

template<typename T>
void print(std::vector<T> &v, char sepc = ' ', char endc = '\n') {
    for(T e : v) print(e, sepc);
    printf("%c", endc);
    return;
}

using namespace std;

const int MAX_V = 2000;
const long long int INF = 96543219987654321;

int V;
vector<pair<int, long long> > adj[MAX_V];

void pushAllAdj(int here, vector<long long> &dist, long long cost, priority_queue<pair<long long, int>> &pq) {
    for(int i = 0; i < adj[here].size(); ++i) {
        int there = adj[here][i].first;
        int nextDist = cost + adj[here][i].second;
        if(dist[there] > nextDist) {
            dist[there] = nextDist;
            pq.push(make_pair(-nextDist, there));
        }
    }
}

vector<long long> dijkstra(int src) {
	vector<long long> dist(V, INF);
	priority_queue<pair<long long, int> > pq;
    pushAllAdj(src, dist, 0, pq);
	while(!pq.empty()) {
		long long cost = -pq.top().first;
		int here = pq.top().second;
		pq.pop();
		if(dist[here] < cost) continue;
        pushAllAdj(here, dist, cost, pq);
	}
	return dist;
}

int main() {
    int N = nextInt(), M = nextInt();
    V = N;

    for(int i = 0; i < M; i++) {
        int A = nextInt(), B = nextInt(), C = nextInt();
        adj[A-1].push_back(make_pair(B-1, C));
    }

    for(int i = 0; i < N; i++) {
        auto res = dijkstra(i)[i];
        print(res == INF ? -1LL : res);
    }
}

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;

#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
#define per(i, a, b) for (auto i = (b); i-- > (a); )
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) int((x).size())
#define lb(x...) lower_bound(x)
#define ub(x...) upper_bound(x)

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

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

const int N = 1 << 11, inf = 1e9;
int dp[N][N], a[N][N];

void verdict(int x) {
	if (x == 0) cout << "Draw\n";
	else cout << (x > 0 ? "Takahashi" : "Aoki") << '\n';
	exit(0);
}

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

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

	auto f = [&](int i, int j) {
		return (i ^ j) & 1;
	};

	rep(i, 0, n) rep(j, 0, m) {
		char c; cin >> c;
		a[i][j] = c == '+' ? +1 : -1;
		dp[i][j] = f(i, j) ? inf : -inf;
	}

	dp[n - 1][m - 1] = 0;
	per(i, 0, n) {
		per(j, 0, m) {
			if (f(i, j)) {
				int nxt = dp[i][j] + a[i][j];
				if (i > 0) ckmax(dp[i - 1][j], nxt);
				if (j > 0) ckmax(dp[i][j - 1], nxt);
			} else {
				int nxt = dp[i][j] - a[i][j];
				if (i > 0) ckmin(dp[i - 1][j], nxt);
				if (j > 0) ckmin(dp[i][j - 1], nxt);
			}
		}
	}

	verdict(dp[0][0]);
}


// In god we trust

#include <bits/stdc++.h>
#include <chrono>
#include <algorithm>
#include <signal.h>
#include <thread>
#include <pthread.h>
#include <omp.h>

#define pb push_back
#define fi first
#define se second
#define Vi vector<int>
#define Vb vector<bool>
#define Pi pair<int, int>
#define Si set<int>
#define Ui unordered_map<int, int>
#define MP make_pair
#define MT make_tuple
#define Q queue
#define Qi Q<int>
#define INF 1000000000
#define LINF 1000000000000000000
#define _USE_MATH_DEFINES
#define int long long
using namespace std;
using namespace std::chrono;

int mod_power(int x, int y, int mod){
  int ans = 1;
  x %= mod;
  while(y){
    if (y & 1)
      ans *= x, ans %= mod;
    y /= 2;
    x = (x * x) % mod;
  }
  return ans;
}

int mod_inverse(int n, int mod){
  return mod_power(n, mod - 2, mod);
}

// Returns factorial of n
int fact(int n)
{
    int res = 1;
    for (int i = 2; i <= n; i++)
        res = res * i;
}

int ncr(int n, int r)
{
  if (r > n)
    return 0;
  if (r == 0 or r == n)
    return 1;
  int fact = 1;
  for (int i = 1; i <= r; i++)
    fact *= i;
  int ans = 1;
  for (int i = n; i > n - r; i--)
    ans *= i;
  ans /= fact;
  return ans;
}

int mod_ncr(int n, int r, int mod){
  if (r > n)
    return 0;
  if (r == 0 or r == n)
    return 1;
  int fact = 1;
  for (int i = 1; i <= r; i++)
    fact *= i, fact %= mod;
  int ans = 1;
  for (int i = n; i > n - r; i--)
    ans *= i, ans %= mod;
  ans *= mod_inverse(fact, mod), ans %= mod;
  return ans;
}

unordered_map<int, int> factor(int n){
  int cnt = 0;
  unordered_map<int, int> m;
  int nn = n;
  while (!(nn & 1))
    cnt++, nn /= 2;
  if(cnt)
    m[2] = cnt;
  for (int i = 3; i <= sqrt(n); i++){
    cnt = 0;

    while(nn % i == 0)
      nn /= i, cnt++;
    if (cnt)
      m[i] = cnt;
  }
  if (nn > 2)
    m[nn] = 1;

  return m;
}

Vi divisors(int n){
  Vi front;
  Vi back;

  for (int i = 1; i <= sqrt(n); i++){
    if (n % i == 0)
      if (i == n / i)
	front.pb(i);
      else
	front.pb(i), back.pb(n / i);
  }
  for (int i = back.size() - 1; i >= 0 ; i--)
    front.pb(back[i]);
  return front;
}

int cnt[1500000];
signed main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  double n;
  cin >> n;
  double e = 0;
  for (int i = 1; i <= n - 1; i++)
    e = e + n / i;
  cout << fixed << setprecision(10) << e << endl;
}

#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
ll k,a[800][800],b[801][801],key,st=-1,go=1000000000,mid;
set<ll> se,se1,se2;
vector<P> v;
map<ll,vector<ll>> vv;
ld n,ans;
ld f(ld x){
    return x*(pow(2,x)-2)/pow(3,x);
}
int main(void){
    cin>>n;
    for(int i=1;i<n;i++){
        ans+=n/ld(n-i);
    }
    cout<<setprecision(10)<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    map<int,int> mp;
    int n;
    cin>>n;
    long long ans=0;
    for(int i=0;i<n;++i){
        int x;
        cin>>x;
        int len=i-mp[x];
        ans+=len;
        mp[x]++;
    }
    cout<<ans;
}

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
using namespace std;

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

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

  long long sum = 0;
  int cnt = 1;
  for (int i = 0; i < n; i++) {
    if (a[i] == a[i + 1]) {
      cnt++;
    } else {
      sum += 1LL * cnt * (cnt - 1) / 2;
      cnt = 1;
    }
  }
  sum += 1LL * cnt * (cnt - 1) / 2;

  cout << 1LL * n * (n - 1) / 2 - sum << '\n';
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
//全探索
int main() {
    int N;
    cin >> N;
    vector<vector<int>> C(N, vector<int> (N));
    for (int i = 0; i < N; i++) for (int j = 0; j < N; j++){
        cin >> C.at(i).at(j);
    }
    int min = C.at(0).at(0);
    for (int j = 0; j < N; j++){
        if(min > C.at(0).at(j)){
            min = C.at(0).at(j);
        }
    }
    vector<int> B(N);
    for (int j = 0; j < N; j++){
        B.at(j) = C.at(0).at(j) - min;
    }
    int minus = 0;
    vector<int> A(N);
    for (int i = 0; i < N; i++){
        A.at(i) = C.at(i).at(0) - B.at(0);
        if(A.at(i) < minus){
            minus = A.at(i);
        }
    }
    if(minus != 0){
        for (int k = 0; k < N; k++){
            A.at(k) += 0 - minus;
            B.at(k) += 0 - minus;
        }
    }
    //ここまででAとBが完成した。
    string res = "Yes";
    for (int i = 0; i < N; i++) for (int j = 0; j < N; j++){
        if(C.at(i).at(j) != A.at(i) + B.at(j)){
            res = "No";
            goto END;
        }
    }
END:
    cout << res << endl;
    if(res == "Yes"){
        for (int i = 0; i < N; i++){
            cout << A.at(i);
            if(i != N - 1){
                cout << " ";
            }else{
                cout << endl;
            }
        }
        for (int j = 0; j < N; j++){
            cout << B.at(j);
            if(j != N - 1){
                cout << " ";
            }else{
                cout << endl;
            }
        }
    }
}

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

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

#define F first
#define S second
#define ALL(a) a.begin(),a.end()
#define mp make_pair
#define pb push_back
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORN(i,a,b) for(int i=a;i<=b;i++)
#define FORB(i,a,b) for(int i=a;i>=b;i--)
#define INT_MAXI 2147483647
#define INT_MINI -2147483648
#define REV(a) reverse(a.begin(),a.end())
#define NP(a) next_permutation(a.begin(),a.end())

typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;

int findMin(vi arr, int n)
{
    // Calculate sum of all elements
    int sum = 0;
    for (int i = 0; i < n; i++)
        sum += arr[i];

    // Create an array to store results of subproblems
    bool dp[n+1][sum+1];

    // Initialize first column as true. 0 sum is possible
    // with all elements.
    for (int i = 0; i <= n; i++)
        dp[i][0] = true;

    // Initialize top row, except dp[0][0], as false. With
    // 0 elements, no other sum except 0 is possible
    for (int i = 1; i <= sum; i++)
        dp[0][i] = false;

    // Fill the partition table in bottom up manner
    for (int i=1; i<=n; i++)
    {
        for (int j=1; j<=sum; j++)
        {
            // If i'th element is excluded
            dp[i][j] = dp[i-1][j];

            // If i'th element is included
            if (arr[i-1] <= j)
                dp[i][j] |= dp[i-1][j-arr[i-1]];
        }
    }

    // Initialize difference of two sums.
    int diff = INT_MAX;
    for (int j=sum/2; j>=0; j--)
    {
        if (dp[n][j] == true)
        {
            diff = sum-2*j;
            break;
        }
    }
    return diff;
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int n; cin >> n;
    vi v(n); for(auto &i:v) cin >> i;
    int dif = findMin(v, n), sum = accumulate(ALL(v), 0);
    cout << (sum + dif)/2 << '\n';
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define watch(x) cout << (#x) << " is " << (x) << endl
#define MOD 1000000007

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

vector<int> sieve(int n){
  vector<int> v(n+2,0);
  n++;
  v[0]=1;
  for(int i=2;i*i<n;i++){
    if(!v[i])
      for(int j=2*i;j<n;j+=i)
        v[j]++;
  }
  return v;
}

int fastExpo(int a,int n,int mod){
  int result = 1;
  while ( n > 0){
    if ( n&1 )
      result = (result*a)%mod;
    a=(a*a)%mod;
    n>>=1;
  }
  return result;
}

int modInverse(int n,int mod){
  return fastExpo(n,mod-2,mod);
}

vector<int> factorial(int n){
  std::vector<int> fac(n+2,0);
  fac[0] = 1;
  for (int i = 1; i <= n; i++)
      fac[i] = (fac[i - 1] * i) % MOD;

  return fac;
}

int __nCr(int n,int r, vector<int>& Fact,int mod){
    int ans= (((Fact[n] * modInverse(Fact[r],mod))%mod)
    *modInverse(Fact[n-r],mod))%mod;
    return ans;
}

class Triplet{
 public:
   int x;
   int y;
   int gcd;
};
Triplet extendedEuclid(int a,int b){
  if(b==0){
    Triplet obj;
    obj.x=1;
    obj.y=0;
    obj.gcd=a;
    return obj;
  }
  Triplet smallans = extendedEuclid(b,a%b);
  Triplet ans;
  ans.gcd=smallans.gcd;
  ans.x=smallans.y;
  ans.y= smallans.x-(a/b)*smallans.y;
  return ans;
}

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

void solve(int T)
{
  int n,m;
  cin >>  n >> m;
  int arr[m];
  for(auto &i: arr)
    cin >> i;

  if(m==0){
    cout<<1<<endl;
    return;
  }
  sort(arr,arr+m);
  int d=INT_MAX;
  if(arr[0]!=1){
    d=arr[0]-1;
  }
  if(arr[m-1]!=n){
    d=min(d,n-arr[m-1]);
  }
  for(int i=1;i<m;i++){
    int gap=(arr[i]-arr[i-1])-1;
    if(gap!=0){
      d=min(d,gap);
    }
  }
  //cout<<d<<endl;
  if(d==0 || m==n){
    cout<<0<<endl;return;
  }
  int last=0;
  int ans=0;
  for(int i=0;i<m;i++){
    int g=(arr[i]-last)-1;
    if(g<0){
      continue;
    }
    ans+=ceil((1.0*g)/d);
    last=arr[i];
  }
  ans+=ceil(1.0*(n-last)/d);
  cout<<ans<<endl;
}

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

#ifndef ONLINE_JUDGE
    freopen("inputf.in", "r", stdin);
    freopen("error.out", "w", stderr);
    freopen("outputf.out", "w", stdout);
#endif

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

    cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
const ll MOD=20000000000000000;
const long double PI=3.14159265358979;
const ll MAX=100000;

int main() {
  ll N,M;
  cin>>N>>M;
  ll a[M+2];
  rep(i,M){
    cin>>a[i+1];
  }
  a[0]=0;a[M+1]=N+1;
  sort(a,a+M+2);

  vector<ll> w;
  rep(i,M+1){
    if(a[i+1]-a[i]>1){
      w.push_back(a[i+1]-a[i]-1);
    }
  }
  ll minw=MOD;
  ll ws=w.size();
  rep(i,ws){
    minw=min(minw,w[i]);
  }
  ll ans=0;
  rep(i,ws){
    ans+=(w[i]-1)/minw+1;
    //cout<<w[i]<<ans;
  }
  cout<<ans;

}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i= 0;i<(n);++i)
#define sz(s) (int)(s.size())
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using vi = vector<int> ;
using vll = vector<ll>;
using vvi = vector<vi> ;
using vvll = vector<vll>;
using vs = vector<string>;
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define SORT(v) sort((v).begin(),(v).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
const int INF = INT_MAX;
const ll LLINF = LLONG_MAX;

int main() {
    int n,m,q;
    cin >> n >> m >> q;
    vector<P> nim;
    rep(i,n){
        ll w,v;
        cin >> w >> v;
        nim.pb({v,w});
    }
    RSORT(nim);
    vector<ll> box;
    rep(i,m){
        ll x;
        cin >> x;
        box.pb(x);
    }
    vector<int> left,right;
    rep(i,q){
        int l,r;
        cin >> l >> r;
        l--;r--;
        left.pb(l);
        right.pb(r);
    }
    rep(i,q){
        vector<ll> box2;
        ll ans = 0;
        for(int j = 0;j<left[i];j++){
            box2.pb(box[j]);
        }
        for(int j = right[i] + 1; j < m;j++){
            box2.push_back(box[j]);
        }
        SORT(box2);
        rep(j,n){
            ll val = nim[j].first;
            ll wei = nim[j].second;
            rep(k,box2.size()){
                if (wei <= box2[k]){
                    ans+=val;
                    box2[k] = 0;
                    break;
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}

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

using namespace std;

const int N = 59;

int w[N];
int v[N];
int x[N];

int main() {
#ifndef LOCAL
  cin.tie(0);
#endif
  ios::sync_with_stdio(false);
  int n, m, qq;
  cin >> n >> m >> qq;
  for (int i = 0; i < n; ++i) {
    cin >> w[i] >> v[i];
  }
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      if (v[j] > v[i]) {
        swap(w[i], w[j]);
        swap(v[i], v[j]);
      }
    }
  }
  for (int i = 0; i < m; ++i) {
    cin >> x[i];
  }
  while (qq--) {
    int l, r;
    cin >> l >> r;
    --l;
    --r;
    vector<int> a;
    for (int i = 0; i < l; ++i) {
      a.push_back(x[i]);
    }
    for (int i = r + 1; i < m; ++i) {
      a.push_back(x[i]);
    }
    sort(a.begin(), a.end());
    vector<bool> used(a.size(), false);
    int ans = 0;
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < (int)a.size(); ++j) {
        if (!used[j] && a[j] >= w[i]) {
          used[j] = true;
          ans += v[i];
          break;
        }
      }
    }
    cout << ans << '\n';
  }
}


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

int main(void){
    int n,m;
    cin >> n >> m;
    int a[n];
    rep(i,n) cin >> a[i];
    set<int> b;
    map<int,int> c;
    rep(i,1.5*1e6+1){
        b.insert(i);
        c[i]++;
    }
    rep(i,m){
        c[a[i]]--;
        b.erase(a[i]);
    }
    int ans = *begin(b);
    for(int i=0;i+m<n;i++){
        c[a[i]]++;
        c[a[i+m]]--;
        if(c[a[i]]>0) b.insert(a[i]);
        if(c[a[i+m]]<=0) b.erase(a[i+m]);
        ans = min(ans,*begin(b));
    }
    cout << ans << endl;
}

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

 vector<string> vec_splitter(string s) {
	s += ',';
	vector<string> res;
	while(!s.empty()) {
		res.push_back(s.substr(0, s.find(',')));
		s = s.substr(s.find(',') + 1);
	}
	return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx,
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
	if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
	stringstream ss; ss << H;
	cerr << args[idx] << " = " << ss.str();
	debug_out(args, idx + 1, LINE_NUM, T...);
}

#ifndef ONLINE_JUDGE
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif

clock_t startTime;
double getCurrentTime() {
	return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}

#define PI 3.14159265358979323846
const int maxn = 1500002;
vector<int> v(maxn), last(maxn);

int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  int ans = 987654321;
  for (int i = 1; i <= n; i++) {
    cin >> v[i];
    if (i - last[v[i]] > m) {
      ans = min(ans, v[i]);
    }
    last[v[i]] = i;
  }
  for (int i = 0; i <= n; i++) {
    if (n + 1 - last[i] > m) {
      ans = min(ans, i);
    }
  }
  cout << ans << "\n";
  return 0;
}


#include <bits/stdc++.h>
#define For(i, l, r) for (register int i = l, _r = r; i <= _r; ++i)
#define Ford(i, l, r) for (register int i = r, _l = l; i >= _l; --i)
using namespace std;
typedef long long ll;
#define pii pair<int, int>
#define mk make_pair
const int N = 1e5 + 20;
const int mod = 1e9 + 7;
int T, n, a[N];
ll sum, tot;

inline int read()
{
    int x = 0, f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9')
    {
        if (ch == '-')
            f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9')
    {
        x = (x << 3) + (x << 1) + ch - '0';
        ch = getchar();
    }
    return x * f;
}

int main()
{
    int t = read();
    while (t--)
    {
        sum = tot = 0;
        n = read();
        For(i, 1, n)
            a[i] = read();
        sort(a + 1, a + 1 + n);
        if (n & 1)
        {
            For(i, 2, n) i & 1 ? sum += a[i] : tot += a[i];
            sum += a[1];
            puts(sum ^ tot ? "Second" : "First");
        }
        else
        {
            For(i, 1, n) i & 1 ? sum += a[i] : tot += a[i];
            puts(sum ^ tot ? "First" : "Second");
        }
    }
    return 0;
}

#define _DEBUG
#include "bits/stdc++.h"
//#include <atcoder/all>
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,a5,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#define debug_6(x1,x2,x3,x4,x5,x6) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<", "#x6<<": "<<x6<<endl
#ifdef _DEBUG
#define debug(...) CHOOSE((__VA_ARGS__,debug_6,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)
#else
#define debug(...)
#endif
#define rep(index,num) for(int index=0;index<(int)num;index++)
#define rep1(index,num) for(int index=1;index<=(int)num;index++)
#define brep(index,num) for(int index=(int)num-1;index>=0;index--)
#define brep1(index,num) for(int index=(int)num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define prind(argument) cout<<std::fixed<<setprecision(13)<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define PI acosl(-1)
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define puba(a) emplace_back(a)
#define pubamp(a,b) emplace_back(mp(a,b))
typedef long long ll;
typedef long double ld;
using namespace std;
//using namespace atcoder;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
ll INFl=(ll)1e+18+1;
int INF=1e+9+1;

/*n進数変換*/
template<typename TypeInt>
std::string Itoa(const TypeInt v, int base)
{
    static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    string ret;
    static numeric_limits<TypeInt> t;
    TypeInt n = v;
    if (t.is_signed) {
        if (v < 0) n *= -1;
    }

    while (n >= base) {
        ret += table[n%base];
        n /= base;
    }
    ret += table[n];
    if (t.is_signed) {
        if (v < 0 && base == 10) ret += '-';
    }
    // 文字列の順番を逆にする
    std::reverse(ret.begin(), ret.end());

    return ret;
}
ll dp[19][(1<<18)];
int main(){
	int N,M;
	int X[101],Y[101],Z[101];
	scan(N>>M);
	rep(i,M){
		scan(X[i]>>Y[i]>>Z[i]);
		X[i]--; Y[i]--;
	}
	dp[0][0]=1;
	int bitall=(1<<N);
	rep(i,N){
		rep(bit,bitall){
			if(dp[i][bit]==0) continue;
			//string BIT=Itoa(bit,2);
			//debug(i,BIT,dp[i][bit]);
			rep(j,N){
				if(bit>>j&1) continue;
				int nextbit=bit|(1<<j);
				//string NEXTBIT=Itoa(nextbit,2);
				bool ok=1;
				rep(m,M){
					if(X[m]<i) continue;
					int yikacnt=0;
					int tmpbit=nextbit;
					rep(k,Y[m]+1){
						yikacnt+=((tmpbit>>k)&1);
					}
					if(yikacnt>Z[m]){
						//debug(NEXTBIT,Y[m],yikacnt,Z[m]);
						ok=0;
						break;
					}
				}

				//debug(i,BIT,NEXTBIT,ok);
				if(ok) dp[i+1][nextbit]+=dp[i][bit];
			}
		}
	}
	prin(dp[N][bitall-1]);
	return 0;
}


//#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define arep(a,i,n) for(ll i=(a);i<(n);i++)
#define rep(i,n) for(ll i=0;i<(n);i++)
#define cinf(x,n) for(ll i=0;i<(n);i++)cin>>x[i];
#define coutf(x,n) for(ll i=0;i<(n);i++)cout<<x[i]<<endl;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using namespace std;

int main(){
	//ios::sync_with_stdio(false);
	//cin.tie(nullptr);
	ll a,b,c;
	cin >> a >> b >> c;
	ll tmp,ans;
	if(c%2==0){
		switch(b%4){
			case 1:tmp=1;break;
			case 2:tmp=4;break;
			case 3:tmp=1;break;
			case 0:tmp=4;break;
		}
	}else{
		switch(b%4){
			case 1:tmp=1;break;
			case 2:if(c==1)tmp=2;else tmp=4;break;
			case 3:tmp=3;break;
			case 0:tmp=4;break;
		}
	}
	if(a%10==0)
		cout << 0 << endl;
	else
		cout << static_cast<ll>(powl((a%10),tmp))%10 << endl;
}

//#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,k,A,B,C,a=1;
    cin>>A>>B>>C;
    k=POW(B,C,4)+4;
    j=A%10;
    rep(i,k)a*=j;

    cout<<a%10<<endl;
}


#include <iostream>
using namespace std;
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
int main()
{
    long long aa,b,c;
    cin>>aa>>b>>c;
    int a = aa%10;
    int ans=0;
    if(a==0||a==1||a==5||a==6){
        ans=a;
    }else if(a==4){
        if(b%2==0){
            ans=6;
        }else{
            ans=4;
        }
    }else if(a==9){
        if(b%2==0){
            ans=1;
        }else{
            ans=9;
        }
    }else{
        long long mod = 0;
        mod =modpow(b,c,4);
        if(mod==0){
            if(a==2) ans=6;
            if(a==3) ans=1;
            if(a==7) ans=1;
            if(a==8) ans=6;
        }else if(mod==1){
            ans=a;
        }else if(mod==2){
            if(a==2) ans=4;
            if(a==3) ans=9;
            if(a==7) ans=9;
            if(a==8) ans=4;
        }else{
            if(a==2) ans=8;
            if(a==3) ans=7;
            if(a==7) ans=3;
            if(a==8) ans=2;
        }
    }
    cout<<ans<<endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vii vector<vector<int>>
#define pb push_back
#define f1(i,l,r) for(i=l;i<=r;i++)
#define f2(a,b) for(auto a:b)
#define all(v) v.begin(),v.end()
#define mp make_pair
#define pi pair<int,int>

int main()
    {
    	float V,T,S,D;
    	cin>>V>>T>>S>>D;
    	float ins;
    	ins=D/V;
    	if(ins<T||ins>S) cout<<"Yes";
    	else cout<<"No";
	}


#include <bits/stdc++.h>
#define INF INT_MAX
#define ll  long long
#define ull unsigned long long
#define rep(i,n) for(ll i=0; i<n; ++i)
#define FOR(i, s, e) for(ll i=s; i<e; ++i)
#define MOD 1000000007
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if(a>b) {a=b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) { if(a<b) {a=b; return true;} return false;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N; cin >> N;
  vector<double> X(N);
  rep(i,N) cin >> X[i];
  double m = 0, u = 0, c = 0;
  rep(i,N) {
    m+=abs(X[i]);
    u+=(X[i] * X[i]);
    c = max(c, abs(X[i]));
  }
  cout << setprecision(20) << m << endl;
  cout << sqrt(u) << endl;
  cout << c << endl;
}

#include "bits/stdc++.h"
using namespace std;
using LLI = long long;
#define INF 999999999
#define MOD 1000000007
#define FOR(i, s, e) for(LLI i = s, i##_lim = (e); i < i##_lim; i++)
#define FORR(i, s, e) for(LLI i = s-1, i##_lim = (e); i##_lim<=i; i--)
#define REP(i, n) FOR(i,0,n)
#define REPR(i, n) FORR(i,n,0)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define pm(a) ((a)?1:-1)
#define SORT(v) sort(v.begin(),v.end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define Mat2(type,name,h,w,def) vector<vector<type>> name(h,vector<type>(w, def))
#define Mat3(type,name,h,w,d,def) vector<vector<vector<type>>> name(h,vector<vector<type>>(w, vector<int>(d,def)))
// int 2.14E±9    LLIi 9.2E±18    double 1.7E±380

#define PI 3.1415926535
int main()
{
	cout << fixed << setprecision(10);

	int n;
	cin >> n;

	double x0, y0, x, y;
	cin >> x0 >> y0 >> x >> y;

	double th = atan2(-(y - y0), x - x0);

	th -= 2 * PI / n;

	double len = sqrt((x - x0) * (x - x0) + (y - y0) * (y - y0)) / 2;
	//cout << len * cos(th - 2 * PI / n) << " " << len * sin(th - 2 * PI / n);
	cout << (x + x0) / 2 - len * cos(th) << " " << (y + y0) / 2 + len * sin(th);

	return 0;
}


// C++ (GCC9.2.1) AtCoder
/*
Ctrl+Option+N で　実行

*/

#include <bits/stdc++.h>
#define INF 100000000000
#define MOD 1000000007
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define print(x) cout << (x) << endl;

typedef long long ll;

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N;
  cin>>N;
  vector <ll> A(N+1);
  REP(i,N) cin>>A[i+1];

  ll ruiseki = 0;

  vector <ll> ans(1+N,0);

  ans[1] = A[1] + A[1];
  ruiseki += A[1];
  ll ma = A[1];

  for(int i=1;i<N;i++){
    ruiseki += A[i+1];
    ll pma = ma;
    ma = max(ma,A[i+1]);
    ans[i+1] = ruiseki + (i+1) * ma - i * pma + ans[i];
  }

  for(int i=1;i<=N;i++) print(ans[i])

  return 0;
}

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

long long A[200005];

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

    int n;
    cin >> n;

    long long maxx = 0, sum = 0, pre = 0;

    for (int i=1; i<=n; i++)
    {
        cin >> A[i];

        maxx = max(maxx, A[i]);
        sum += A[i];
        pre += sum;

        cout << maxx * i + pre << "\n";
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define ll long long
#define int ll
#define ld long double
#define reps(i,s,n) for(int i=(s);i<(int)(n);i++)
#define rep(i,n) reps(i,0,n)
#define rreps(i,s,n) for(int i=(int)(s-1);i>=n;i--)
#define rrep(i,n) rreps(i,n,0)
#define all(v) (v).begin(),(v).end()
#define mset(a,n) memset(a,n,sizeof(a))
#define eras(v,n) (v).erase(remove(all(v),n),(v).end())
#define uni(v) sort(all(v));(v).erase(unique(all(v)),(v).end())
#define bcnt(i)  __builtin_popcount(i)
#define fi first
#define se second
constexpr ll INF = 1e18;
constexpr ll MOD = 1000000007;
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<class T>T min(vector<T> &v) { return *min_element(v.begin(),v.end()); }
template<class T>T max(vector<T> &v) { return *max_element(v.begin(),v.end()); }
template<class T>T modpow(T a, T b, T m) { a %= m; T r = 1; while (b > 0) { if (b & 1) r = (r * a) % m; a = (a * a) % m; b >>= 1; } return r; }
ll modinv(ll a,ll m=MOD) {ll b = m, u = 1, v = 0;while (b) {ll t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}
template<class T>string radixconv(T n, T k){ string s; while(n/k){ s=to_string(n%k)+s; n/=k; } s=to_string(n%k)+s; return s; }

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout << fixed << setprecision(11);
    cerr << fixed << setprecision(6);
    string s;
    cin >> s;
    int ocnt=count(all(s),'o');
    int ans=0;
    cerr << ocnt << endl;
    rep(a,10)rep(b,10)rep(c,10)rep(d,10){
        if(s[a]=='x')continue;
        if(s[b]=='x')continue;
        if(s[c]=='x')continue;
        if(s[d]=='x')continue;
        vector<bool> chk(10,0);
        chk[a]=1;
        chk[b]=1;
        chk[c]=1;
        chk[d]=1;
        int cnt=0;
        rep(i,10)if(chk[i]&&s[i]=='o')cnt++;
        if(cnt!=ocnt)continue;
        ans++;
    }
    cout << ans << endl;
    return 0;
}

#include<bits/stdc++.h>

using namespace std;

int main(){
       ios_base::sync_with_stdio(0);
string s; cin >> s;
  int onum =0, qnum = 0;
  int i;
  for(i = 0;i<10;i++){
    if(s[i] == 'o'){
      onum++;
    }else if(s[i] == '?'){
      qnum++;
    }
  }
  if(onum > 4){
    cout << 0 << endl;
  }else if(onum == 4){
    cout << 24 << endl;
  }else if(onum == 3){
    cout << 36 + 24 * qnum << endl;
  }else if(onum == 2){
    cout << 4 + 6 + 4 + (qnum - 1) * qnum / 2 * 24 + qnum * 36 << endl;
  }else if(onum == 1){
    cout << 1 + qnum * 14 + (qnum - 1) * qnum / 2 * 36 + (qnum - 2) * (qnum - 1) * qnum / 6 * 24 << endl;
  }else{
    cout << qnum * qnum * qnum * qnum << endl;
  }

return 0;
}


#include "bits/stdc++.h"

using namespace std;
using ll = long long;
using pii = pair<int,int>;

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

  int n;
  cin >> n;
  vector<ll>a(n);
  for (auto& x : a) cin >> x;
  vector<ll> pr(n+1);
  for (int i = 1; i <= n; i++)
    pr[i] = pr[i-1]+a[i-1];
  ll mx =0;
  ll sum = 0;
  for (int k = 0; k < n; k++) {
    mx = max(mx,a[k]);
    cout << (k+1)*mx+pr[k+1]+sum << '\n';;
    sum += pr[k+1];
  }
}

#include<bits/stdc++.h>
#define mx                          100005
#define lli                         long long int
#define ulli                        unsigned long long int
#define mset(a,b)                   memset(a, b, sizeof(a))
#define infile                      freopen("in.txt", "r", stdin);
#define outfile                     freopen ("out.txt","w",stdout);
#define fileclose                   fclose (stdin); fclose (stdout);
#define test_case                   lli T; cin>>T;for(lli t=1;t<=T;t++)
#define scani(x)                    scanf("%d",&x);
#define printi(x)                   printf("%d\n",x);
#define scanli(x)                   scanf("%lld",&x);
#define printli(x)                  printf("%lld\n",x);
#define frep(i,from,to)             for(lli i=from;i<=to;i++)
#define frev(i,from,to)             for(lli i=from;i>=to;i--)

using namespace std;

lli n;
lli arr[50];

lli ans = 1e18;
lli prime[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47};
bool isSet(lli num, lli pos)
{
	return (num & (1 << pos));
}
void fun()
{
	frep(mask, 0, (1 << 15) - 1)
	{
		lli num = 1;
		frep(pos, 0, 15)
		{
			if (isSet(mask, pos))
			{
				num *= prime[pos];
			}
		}
		bool flag = true;
		frep(i, 1, n)
		{
			if (__gcd(num, arr[i]) == 1)
			{
				flag = false;
				break;
			}
		}
		if (flag)
			ans = min(ans, num);
	}

}
int main()
{

	cin >> n;
	frep(i, 1, n)
	{
		cin >> arr[i];
	}
	fun();
	cout << ans << "\n";

}


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

#define LETS_GET_SCHWIFTY ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ff              first
#define ss              second
#define int             long long
#define ll              long long
#define pb              push_back
#define pii             pair<int,int>
#define vi              vector<int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zerobits(x)      __builtin_ctzll(x)
#define mod             998244353
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define vpii            vector<pair<int,int> >
#define all(x)          x.begin(),x.end()
#define matrixprint(arr,a,b,c,d) for(int i=a;i<=c;i++){for(int j=b;j<=d;j++){cout<<arr[i][j]<<" ";}cout<<"\n";}
#define show(arr,x,y)   for(int i=x;i<=y;i++){cout<<arr[i]<<" ";}cout<<"\n"
#define sz(x)           (int)x.size()
#define db(x)           cout<<x<<"\n";

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

//insert,find_by_order,order_of_key,lower_bound,upper_bound;

#define TRACE
#ifdef TRACE
#define deb(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
    cout << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
#else
#define deb(...)
#endif

//////////////////////////////code//////////////////////////////

const int N = 200;

int power(int a, int b = mod - 2) {

	int x = 1 % mod;
	a %= mod;
	b %= mod - 1;
	while (b) {

		if (b & 1) x = (x * a)%mod;
		a = (a * a)%mod;
		b >>= 1;

	//	deb(x);
	}

	return x;

}

void solve()
{

		int n;
		cin >> n;

		map<int,int>m;

		for(int i = 0;i < n; i++)
		{
				int d;
				cin >> d;
				m[d]++;
				//deb(m[d],d);
		}

		int ans = 0,sum = 0, nodesum = 0;

		vpii num;

		/*for(auto x : m)
			num.pb({x.ff,x.ss});
*/
	/*	deb(sz(num));
		deb(num[0].ff,num[0].ss);
*/
		for(auto it = m.begin() ; it != m.end() ; it++)
		{
				int f = it->ss;
				int a = it->ff;

			//	deb(f,a);

				int twof = (power(2,f) - 1);

				int two = power(2,f);

				ans += (((twof*a)%mod)*a)%mod;
				ans %= mod;

				ans +=  (((twof*sum)%mod)*a)%mod;
				ans %= mod;

				sum *= two;
				sum %= mod;
				sum += (twof*a)%mod;
				sum %= mod;

		}

		db(ans)

}

int32_t main()
{

    LETS_GET_SCHWIFTY;

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

    int t = 1;
  // cin >> t;

    while (t--)
        solve();

}

// check out for following mistakes-
// if using pb operation on vector and then trying to access index..check if sizeof that vec could remain 0 only
// is using prime sieve make sure it fits
// when using factorial template or combinatorics make sure that you edit fillfac fun values and array values

#include <vector>
#include <iostream>
#include <algorithm>
#define R 998244353

using namespace std;
typedef long long ll;

vector<int> myNum;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	int N;
	cin >> N;
	while (N--)
	{
		int num;
		cin >> num;
		myNum.push_back(num);
	}
	sort(myNum.begin(), myNum.end());
	ll partSum = 0;
	ll res = 0;
	for (int num : myNum) {
		res += num * ((partSum + num)%R)%R;
		res %= R;
		partSum = ((partSum * 2)%R + num)%R;
	}
	cout << res;
}


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

int main(){
  int n;
  cin >> n;
  ll a[n][5];
  rep(i,n) rep(j,5) cin >> a[i][j];
  ll l = 0, r = INF;
  while(r-l > 1) {
    ll m = (l + r) / 2;
    vector<vector<int>> bit(n);
    vector<int> val(n);
    vector<int> cnt(1<<5);
    rep(i,n) {
      int b = 0;
      rep(j,5) if(a[i][j] >= m) b += (1<<j);
      val[i] = b;
      rep(k,1<<5) {
        if((b & k) == k) {
          bit[i].push_back(k);
          cnt[k]++;
        }
      }
    }
    int all = (1<<5)-1;
    bool can = false;
    rep(i,n) {
      for(int j = 1; j < n; j++) {
        int res = (val[i] | val[j]);
        res ^= all;
        if(cnt[res]) can = true;
      }
    }
    if(can) l = m;
    else r = m;
  }
  cout << l << endl;
  return 0;
}

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <climits>
#include <iomanip>
#include <deque>
#include <limits>
#include <map>
#include <set>
#include <functional>

using namespace std;

int N;
vector<int> A, B, C, D, E;

bool binary_check(int x)
{
  set<int> S;

  for (int i = 0; i < N; i++) {
    int s = (A[i] >= x) << 4 |
            (B[i] >= x) << 3 |
            (C[i] >= x) << 2 |
            (D[i] >= x) << 1 |
            (E[i] >= x) << 0;
    S.insert(s);
  }

  for (auto &&a : S) {
    for (auto &&b : S) {
      for (auto &&c : S) {
        if ((a | b | c) == 0b11111) {
          return true;
        }
      }
    }
  }

  return false;
}

int main()
{
  cin >> N;
  A.resize(N);
  B.resize(N);
  C.resize(N);
  D.resize(N);
  E.resize(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i] >> B[i] >> C[i] >> D[i] >> E[i];
  }

  int ok = 0;
  int ng = 1e9 + 5;
  int x = 0;

  while (abs(ng - ok) > 1) {
    x = (ok + ng) / 2;
    if (binary_check(x)) {
      ok = x;
    }
    else {
      ng = x;
    }
  }

  cout << ok << endl;

  return 0;
}


#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <stack>
#include <cassert>
#include <map>
#include <numeric>
#include <cstring>
#include <set>
#include <ctime>
#include <queue>
#include <cmath>
#include <iomanip>
#include <iterator>

using namespace std;

clock_t timeStart, timeFinish;

void timeBegin() {
    timeStart = clock();
}

void timeEnd() {
    timeFinish = clock();
}

void timeDuration() {
    timeEnd();
    double time_taken = double(timeFinish - timeStart) / double(CLOCKS_PER_SEC);
    cout << "Time taken by program is : " << fixed << time_taken << setprecision(5);
    cout << " sec " << endl;
}

class InputReader {
public:
    InputReader() {
        input_file = stdin;
        cursor = 0;
        fread(buffer, SIZE, 1, input_file);
    }
    InputReader(const char *file_name) {
        input_file = fopen(file_name, "r");
        cursor = 0;
        fread(buffer, SIZE, 1, input_file);
    }
    inline InputReader &operator >>(int &n) {
        while((buffer[cursor] < '0' || buffer[cursor] > '9') && buffer[cursor] != '-') {
            advance();
        }
        int sign = 1;
        if (buffer[cursor] == '-') {
            sign = -1;
            advance();
        }
        n = 0;
        while('0' <= buffer[cursor] && buffer[cursor] <= '9') {
            n = n * 10 + buffer[cursor] - '0';
            advance();
        }
        n *= sign;
        return *this;
    }
private:
    FILE *input_file;
    static const int SIZE = 1 << 17;
    int cursor;
    char buffer[SIZE];
    inline void advance() {
        ++ cursor;
        if(cursor == SIZE) {
            cursor = 0;
            fread(buffer, SIZE, 1, input_file);
        }
    }
};

const int MAXN = 5000;
const int MOD = 998244353;

int power[1 + MAXN][1 + MAXN];

void addTo(int &x, int y) {
    x += y;
    if (x >= MOD) {
        x -= MOD;
    }
}

void precompute(int m, int n) {
    for (int i = 1; i <= m; i++) {
        power[i][0] = 1;
        for (int j = 1; j <= n; j++) {
            power[i][j] = 1LL * power[i][j - 1] * i % MOD;
        }
    }
}

int main() {
    timeBegin();
    //ifstream cin("input.in");
    //ofstream cout("abbreviation.out");
    int n, m;
    cin >> n >> m;
    if (n == 1) {
        cout << m % MOD << "\n";
        return 0;
    }
    precompute(m, n);
    int answer = 0;
    for (int x = 1; x <= m; x++) {
        addTo(answer, power[m][n - 1]);
        int sum = (x - 1) % MOD;
        for (int i = 2; i <= n; i++) {
            int current = sum;
            addTo(current, power[m - x][i - 1]);
            addTo(answer, 1LL * current * power[m][n - i] % MOD);
            sum = 1LL * sum * m % MOD;
            addTo(sum, 1LL * power[m - x][i - 1] * (x - 1) % MOD);
        }
    }
    cout << answer << "\n";
    //timeDuration();
    return 0;
}

#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
// #include <atcoder/all>
// #include <bits/stdc++.h>
#include <complex>
#include <queue>
#include <set>
#include <unordered_set>
#include <list>
#include <chrono>
#include <random>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <stack>
#include <iomanip>
#include <fstream>

using namespace std;
// using namespace atcoder;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> p32;
typedef pair<ll, ll> p64;
typedef pair<p64, p64> pp64;
typedef pair<double, double> pdd;
typedef vector<ll> v64;
typedef vector<ll> v32;
typedef vector<vector<ll>> vv32;
typedef vector<vector<ll>> vv64;
typedef vector<vector<p64>> vvp64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = 998244353;
double eps = 1e-12;
#define forn(i, e) for (ll i = 0; i < e; i++)
#define forsn(i, s, e) for (ll i = s; i < e; i++)
#define rforn(i, s) for (ll i = s; i >= 0; i--)
#define rforsn(i, s, e) for (ll i = s; i >= e; i--)
#define ln '\n'
#define dbg(x) cout << #x << " = " << x << ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define INF 2e18
#define fast_cin()                    \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define zero ll(0)
#define set_bits(x) __builtin_popcountll(x)
// #define mll modll998244353

ll mpow(ll a, ll b)
{
    if (a == 0)
        return 0;
    if (b == 0)
        return 1;
    ll t1 = mpow(a, b / 2);
    t1 *= t1;
    t1 %= MOD;
    if (b % 2)
        t1 *= a;
    t1 %= MOD;
    return t1;
}

ll mpow(ll a, ll b, ll p)
{
    if (b == 0)
        return 1;
    if (a == 0)
        return 0;
    ll t1 = mpow(a, b / 2, p);
    t1 *= t1;
    t1 %= p;
    if (b % 2)
        t1 *= a;
    t1 %= p;
    return t1;
}

ll modinverse(ll a, ll m)
{
    ll m0 = m;
    ll y = 0, x = 1;
    if (m == 1)
        return 0;
    while (a > 1)
    {
        ll q = a / m;
        ll t = m;
        m = a % m, a = t;
        t = y;
        y = x - q * y;
        x = t;
    }
    if (x < 0)
        x += m0;
    return x;
}

mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());

ll range(ll l, ll r)
{
    return l + mt() % (r - l + 1);
}

ll rev(ll v)
{
    return mpow(v, MOD - 2);
}

ll ceil(ll p, ll q)
{
    return (p + q - 1) / q;
}

struct node
{
	ll tot=0, add=0, fact=1;
};

void solve()
{
    ll n,m;
    cin >> n >> m;
    ll p[n+1];
    p[0]=1;
    forn(i,n){
    	p[i+1] = (p[i]*m)%MOD;
    	p[i+1] %= MOD;
    }
    ll ans = 0;
    ll revm = rev(m);
    ll r[m+1];
    ll rev1[m+1];
    forsn(j,1,m+1){
    	r[j] = (m-j)*revm;
    	r[j] %= MOD;
    	rev1[j]=rev(j);
    }
    forsn(j,1,m+1){
    	ll tmp = 1;
    	forn(i,n){
    		if(i==0) ans++;
    		else{
    			ans += (((j-1)*rev1[j])%MOD)*(1-tmp)+tmp;
    			ans %= MOD;
    		}
    		tmp*=r[j];
    		tmp%=MOD;
    		// ans += 1-rev(j)*(1-mpow(r[j],i));

    	}
    }
    ans *= p[n-1];
    ans %= MOD;
    if(ans<0) ans+=MOD;
    cout << ans << ln;
}

int main()
{
    fast_cin();
    ll t = 1;
    // cin >> t;
    forn(i, t)
    {
        // cout << "Case #" << i+1 << ": ";
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i,m,n) for(int i = m - 1; i >= n; i--)
#define ALL(v) v.begin(), v.end()
#define itn int
#define Yes() cout << "Yes" << endl
#define No() cout << "No" << endl
#define YES() cout << "YES" << endl
#define NO() cout << "NO" << endl
#define println(x) cout << x << endl
#define print(x) cout << x << " "
template<typename T, typename U>
inline bool CMAX(T &m, U x) { if (m < x) { m = x; return true; } return false; }
template<typename T, typename U>
inline bool CMIN(T &m, U x) { if (m > x) { m = x; return true; } return false; }

typedef long long lint;
typedef long double ldouble;
const int INF = 1e9;
const lint LINF = 1e18;
const int MOD = 1e9+7;
int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> b(n);
    vector<int> c(n);
    REP(i, n){
        cin >> a[i];
    }
    REP(i, n){
        cin >> b[i];
    }
    REP(i, n){
        cin >> c[i];
    }
    vector <int> bc;
    REP(i,n){
        bc.push_back(b[--c[i]]);
    }
    sort(ALL(a));
    sort(ALL(bc));
    lint time = 0;
    REP(i,n){
        auto itr = lower_bound(ALL(bc),a[i]);
        auto temp = upper_bound(ALL(bc), a[i]);
        if(itr != bc.end()){
            int index = distance(bc.begin(), itr);
            int upper = distance(bc.begin(), temp);
            time += (lint)upper - index;
        }
    }
    println(time);
    return 0;
}

#include <iostream>
#include <cmath>
#include <stdio.h>
#include <string.h>
#include <bits/stdc++.h>
#include <vector>
#include <array>
#include <tuple>
using namespace std;

int main(){
  long long C[61][61];
  for (int i=0; i<=60; i++){
    for (int j=0; j<=60; j++){
      C[i][j]=0;
    }
  }
  C[0][0]=1;
  for (int i=1; i<=60; i++){
    C[i][0]=1;
    for (int j=1; j<=60; j++){
      C[i][j]=C[i-1][j-1]+C[i-1][j];
    }
  }
  int A, B;
  long long K;
  cin >> A >> B;
  cin >> K;
  int P=A+B;
  for (int i=0; i<P; i++){
    if (A==0){
      cout << "b";
      B=B-1;
    }
    else if (K<=C[A+B-1][A-1]){
      cout << "a";
      A=A-1;
    }
    else {
      cout << "b";
      K=K-C[A+B-1][A-1];
      B=B-1;
    }
  }
  cout << endl;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef long double ld;
/*
#include <chrono>
using namespace std::chrono;
#include <boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<lli, null_type,less_equal<lli>, rb_tree_tag,tree_order_statistics_node_update>
//remove _equal from less_equal to make it ordered set , currently it is ordered_multiset
*/
#define pb push_back
const lli mod=1e9+7;
const lli mod1=998244353;
#define fir first
#define sec second
#define plli pair<lli,lli>
#define pplli pair<lli,plli>
/*
lli power(lli a, lli b) {
    lli res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
lli powermod(lli a, lli b)
{
    lli res = 1;
    while (b > 0) {
        if (b & 1)
            res = ((res%mod)*(a%mod))%mod;
        a = (a * a)%mod;
        b >>= 1;
    }
    return res%mod;
}
*/
int main()
{
    lli T,i,j;
    T=1;
    while(T--)
    {

        lli n;
        cin>>n;
        lli a[n];
        for(i=0;i<n;i++)
            cin>>a[i];
        sort(a,a+n);
        lli x=a[n/2]/2;
        lli f=(a[n/2]%2);
        lli loss=0;
        for(i=0;i<n;i++)
        {
            lli z=((a[i]+x)-min(a[n/2]*1ll,a[i]*1ll));
            loss=loss+z;
        }
        if(f)
        {
            loss+=(n/2);
        }
        ld ans=(ld) loss/n;
        if((n%2==1)and(f))
            ans=ans+ ((ld)0.5/n);
        cout<<fixed<<setprecision(10)<<ans<<"\n";
    }
    return 0;
}

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

int charToInt(char c){
    char zero_num = '0';
    return (int)c - (int)zero_num;
}
void cout_line(vector<int> &a){
    for(int i=0;i<a.size();i++){
        if(i<a.size()-1){
            cout<<a.at(i)<<" ";
        }else{
            cout<<a.at(i)<<endl;
        }
    }
}

long double calc(vector<long double> &A, long double mid){
    double result = 0.;

    for(int i=0;i<A.size();i++){
        result += mid+A.at(i)-min(A.at(i), 2.*mid);
    }
    return result/((long double)A.size());
}

signed main(){
    int N; cin>>N;
    vector<long double> A(N); rep(i,N)cin>>A.at(i);

    long double left = 0.;
    long double right = 2*(int)pow(10,9);

    while(right>left+pow(10,-7)){
        long double mid1 = (left*2. + right)/3.;
        long double mid2 = (left + right*2.)/3.;
        if(calc(A, mid1)>calc(A,mid2)){
            left = mid1;
        }else{
            right = mid2;
        }
    }
    cout<<fixed<<setprecision(10)<<calc(A,left)<<endl;

    return 0;

}


#include <iostream>
#include <vector>
#include <string>
#include <deque>
#include <list>
#include <tuple>
#include <algorithm>
#include <set>
#include <queue>
#include <functional>
#include <map>
#include <set>
#include <unordered_map>
#include <cmath>
#include <iomanip>

using namespace std;

uint64_t MAX_NUM = 1000000000;

int32_t N;
vector<int32_t> parent;
vector<int32_t> mysize;

int find_set(int v){
    if(v == parent[v]){
        return v;
    }
    return find_set(parent[v]);
}

void union_sets(int a, int b){
    //cout << " a " << a << " b  " << b << endl;
    a = find_set(a);
    b = find_set(b);
     //cout << "find  a " << a << " b  " << b << endl;
    if(a != b){
        if(mysize[a] < mysize[b]){
            swap(a, b);
        }
        parent[b] = a;
        mysize[a] += mysize[b];
        mysize[b] = 1;
    }
}

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

    vector<int32_t> A = vector<int32_t>(N+1);
    for(int32_t count = 1; count <= N; count++){
        int32_t a;
        cin >> a;
        A[count] = a;
    }

    vector<int32_t> temp(200001, 0);
    for(int32_t count = 1; count <= N; count++){
        int32_t a = A[count];
        if(temp[a] == 0){
            temp[a] = count;
        }
        A[count] = temp[a];
    }
    // for(int32_t count = 1; count <= N; count++){
        // cout << A[count] << endl;
     //}

    parent = vector<int32_t>(N+1);
    mysize = vector<int32_t>(N+1, 1);
    for(int32_t count = 1; count <= N; count++){
        parent[count] = A[count];
    }

    int32_t i, j;
    for(i = 1, j = N; i < j; i++, j--){
        int32_t a1 = A[i];
        int32_t a2 = A[j];
        if(a1 != a2){
            int32_t a = find_set(i);
            int32_t b = find_set(j);
            union_sets(a, b);
        }
    }

    uint64_t result = 0;
    for(int32_t count = 1; count <= N; count++){
        //cout << " count " << count << " size " << size[count] << endl;
        result += mysize[count] - 1;
    }
    cout << result << endl;

}


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

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

#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>

using ll = long long;
//using mint = modint;

const vector<int> dx = {1, 1,  1, 0,  0, 0, -1, -1, -1};
const vector<int> dy = {1, 0, -1, 1, -1, 0,  1,  0, -1};
const double PI = 3.141592653589793;
const ll inf = 1001001001;
const ll e9  = 1000000000;
const ll mod = 1000000007;
const ll mod2 = 998244353;

const int MAX = 1000000;
const ll MOD = 998244353;
const ll big = 1ll<<60;

struct edge{
  int to;
  ll cost;
};
ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }

int main(){
    int l, r;
    cin >> l >> r;
    vector<ll>cnt(1001005);
    for(int i = 1001001; i>=2; i--){
      cnt[i] = 1ll*(r/i-(l-1)/i)*(r/i-(l-1)/i);
      int x = 2*i;
      while(x <= r){
        cnt[i] -= cnt[x];
        x += i;
      }
    }
    ll ans = 0;
    rep(i, 2, 1001002){
      ans += cnt[i];
      if(l<=i&&i<=r){
        ans -= 1ll*(r/i-(l-1)/i);
        ans -= 1ll*(r/i-(l-1)/i);
        ans++;
      }
    }
    cout << ans << endl;
}

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

ll solve(int L, int R){
  vector<ll> memo(1<<21, -1);
  auto f = [&](auto self, int L, int R) -> ll {
    // L < x <= R であって、gcd(x,y) == 1 となるものを数える
    auto key = L + R;
    if(memo[key] != -1) return memo[key];

    ll res = ll(R - L) * (R - L);
    int d = max(L, R);
    while(d > 1){
      int nxt_d = max(L / (L / d + 1), R / (R / d + 1));
      res -= (d - nxt_d) * self(self, L / d, R / d);
      d = nxt_d;
    }
    memo[key] = res;
    return res;
  };

  auto g = [&](int L, int R) -> ll {
    ll res = 0;
    int d = max(L, R);
    while(d){
      int nxt_d = max(L / (L / d + 1), R / (R / d + 1));
      ll cnt = max(0, min(d, R) - max(nxt_d, L));
      res += cnt * (R / d - L / d);
      d = nxt_d;
    }
    return res;
  };

  --L;
  ll ans = ll(R - L) * (R - L);
  ans -= f(f, L, R) + 2 * g(L, R);
  ans += 2 * (L < 1 ? R - L : 0) + (R - L);
  ans -= L < 1;
  return ans;
}

int main(){
  int L, R;
  cin >> L >> R;
  ll ans = solve(L, R);
  cout << ans << endl;
  return 0;
}


#include<bits/stdc++.h>
#define int long long int
using namespace std;
int32_t main()
{
    int a,b,c;
    cin>>a>>b>>c;
    int array[]={a,b,c};
    int sum=0;
    for(int i=0;i<3;i++)
    {
        sum=sum+(7-array[i]);
    }
    cout<<sum;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+10;
const int mod=1e9+7;

int main()
{
    double x1,x2,y1,y2;
    cin>>x1>>y1>>x2>>y2;
    y2=-y2;
    double k=(y1-y2)/(x1-x2);
    double b=y1-k*x1;
    printf("%.10f",-b/k);
}


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

int main(){

    int a,b,c,d;
    cin>>a>>b>>c>>d;
    cout<<b-c<<endl;
    return 0;
}

#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#include <unordered_map>
using namespace std;

#define MAXN 1000001
#define MAXN1 101
#define MAXN2 1001
#define mod 1000000007
#define CONSTANT 1e8
#define ll long long // pair<int,int>

ll res = 0;

int BS(vector<int> arr, int val){
    int l = 0, u = (int)arr.size() - 1, res = -1;
    while(l <= u){
        int mid = (l + u) / 2;
        // if()
    }
    return 0;
}

vector<pair<int,ll>> g(vector<pair<int,ll>> left, vector<pair<int,ll>> right){
    int l = (int)left.size();
    int r = (int)right.size();
    vector<ll> pref(r,0);
    vector<pair<int,ll>> arr(l + r);
    pref[0] = right[0].second;
    for(int i = 1; i < r; i++){
        pref[i] = right[i].second + pref[i - 1];
    }
    int j = 0, i = 0;
    while(i < l){
        // cout << "i: " << i << " " << j << endl;
        if(j < r && left[i].first > right[j].first){
            // curr += right[j].second;
            j++;
        }
        else{
            if(j - 1 >= 0){
                // cout << "Adding: " << pref[j - 1] << endl;
                res += pref[j - 1];
            }
            i++;
        }
    }
    i = 0;
    j = 0;
    int index = 0;
    while(i < (int)left.size() && j < (int)right.size()){
        if(left[i].first <= right[j].first)
            arr[index++] = left[i++];
        else arr[index++] = right[j++];
    }

    while(i < (int)left.size())
        arr[index++] = left[i++];
    while(j < (int)right.size())
        arr[index++] = right[j++];
    return arr;
}

vector<pair<int,ll>> f(vector<pair<int,ll>> arr, int n){
    if(n == 1) return arr;
    int mid = n / 2;
    vector<pair<int,ll>> left(mid), right(n - mid);
    for(int i = 0; i < mid; i++)
        left[i] = arr[i];
    for(int j = mid; j < n; j++)
        right[j - mid] = arr[j];
    left = f(left, mid);
    right = f(right, n - mid);
    arr = g(left, right);
    return arr;
}

void zz(vector<pair<int,ll>> &left, vector<pair<int,ll>> &right){
    int l = (int)left.size();
    int r = (int)right.size();
    vector<ll> pref(r,0);
    pref[0] = right[0].second;
    for(int i = 1; i < r; i++){
        pref[i] = right[i].second + pref[i - 1];
    }
    int j = 0, i = 0;
    while(i < l){
        // cout << "i: " << i << " " << j << endl;
        if(j < r && left[i].first > right[j].first){
            // curr += right[j].second;
            j++;
        }
        else{
            if(j - 1 >= 0){
                // cout << "Adding: " << pref[j - 1] << endl;
                res += pref[j - 1];
            }
            i++;
        }
    }
}

vector<pair<int,ll>> gg(vector<pair<int,ll>> &left, vector<pair<int,ll>> &right){
    int l = (int)left.size();
    int r = (int)right.size();
    vector<pair<int,ll>> arr(l + r);
    int i = 0;
    int j = 0;
    int index = 0;
    while(i < l && j < r){
        if(left[i].first <= right[j].first){
            left[i].second += j;
            arr[index++] = left[i++];
        }
        else{
            // left[i].second += j + 1;
            arr[index++] = right[j++];
        }
    }
    while(i < (int)left.size()){
        left[i].second += r;
        arr[index++] = left[i++];
    }
    while(j < (int)right.size())
        arr[index++] = right[j++];
    // zz(left, right);
    return arr;
}

vector<pair<int,ll>> ff(vector<pair<int,ll>> &arr, int n){
    if(n == 1) return arr;
    int mid = n / 2;
    vector<pair<int,ll>> left(mid), right(n - mid);
    for(int i = 0; i < mid; i++)
        left[i] = arr[i];
    for(int j = mid; j < n; j++)
        right[j - mid] = arr[j];
    left = ff(left, mid);
    right = ff(right, n - mid);
    arr = gg(left, right);
    return arr;
}

int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << max(a - d, b - c) << endl;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
ll ans = 0;
const ll mo = 1000000007;
auto mod = [](ll modx) {modx%=mo;modx+=mo;modx%=mo;return modx; };

int main()
{
ll h , w ;
cin >> h >> w ;
vector<vector<ll>> v(h, vector<ll>(w,0) );
vector<vector<ll>> vv(h, vector<ll>(w,0) );
vector<ll> vh(w,0);
vector<ll> vw(h,0);
vector<ll> vhw(h+w+1,0);

rep(i,h)rep(j,w){
  char a;
  cin >> a ;
  if(a=='#')v[i][j]=1;
}
vv[0][0]=1;
vw[0]=1;
vh[0]=1;
vhw[w]=1;
rep(i,h)rep(j,w){
  if(i==0&&j==0)continue;
  if(v[i][j]==1){
    vw[i]=0;
    vh[j]=0;
    vhw[w+i-j]=0;
  }
  else{
    vv[i][j]=mod(vw[i]+vh[j]+vhw[w+i-j]);
    vw[i]=mod(vw[i]+vv[i][j]);
    vh[j]=mod(vh[j]+vv[i][j]);
    vhw[w+i-j]=mod(vhw[w+i-j]+vv[i][j]);
  }
}
cout << vv[h-1][w-1] << endl;
return 0;
}

//This Code was made by Chinese_zjc_.
#include <iostream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <bitset>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <map>
#include <set>
#include <ctime>
// #include<windows.h>
// #define debug true
#define int long long
#define double long double
using namespace std;
const double PI = acos(-1);
const double eps = 0.0000000001;
const int INF = 0x3fffffffffffffff;
const int MOD = 1000000007;
int n, m, dp[2005][2005], heng[2005][2005], shu[2005][2005], xie[2005][2005];
char Map[2005][2005];
signed main()
{
    ios::sync_with_stdio(false);
    cin >> n >> m;
    for (int i = 1; i <= n; ++i)
    {
        for (int j = 1; j <= m; ++j)
        {
            cin >> Map[i][j];
        }
    }
    shu[1][1] = xie[1][1] = heng[1][1] = dp[1][1] = 1;
    Map[1][1] = '#';
    for (int i = 1; i <= n; ++i)
    {
        for (int j = 1; j <= m; ++j)
        {
            if (Map[i][j] == '.')
            {
                dp[i][j] = (shu[i - 1][j] + heng[i][j - 1] + xie[i - 1][j - 1]) % MOD;
                heng[i][j] = heng[i][j - 1] + dp[i][j];
                shu[i][j] = shu[i - 1][j] + dp[i][j];
                xie[i][j] = xie[i - 1][j - 1] + dp[i][j];
            }
        }
    }
    cout << dp[n][m] << endl;
    return 0;
}


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

int main()
{
  int K, N, M;
  std::cin >> K >> N >> M;
  std::vector<long long> as(K);
  for (auto& a : as) { std::cin >> a; }

  std::vector<long long> bs(K);
  for (int i = 0; i < K; i++)
  {
    bs[i] = (as[i] * M) / N;
  }

  int remain = M - std::accumulate(bs.begin(), bs.end(), 0);

  struct Score { int id; long long value; };
  std::vector<Score> scores(K);
  for (int i = 0; i < K; i++)
  {
    scores[i] = { i, std::abs(bs[i] * N - as[i] * M) };
  }

  std::sort(scores.begin(), scores.end(),
    [&](auto& a, auto& b) {return a.value > b.value; });

  for (int i = 0; i < remain; i++)
  {
    bs[scores[i].id] += 1;
  }

  for (auto& e : bs)
  {
    std::cout << e << " ";
  }
  std::cout << std::endl;
  return 0;
}

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

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

using namespace std;

int k;
ll n,m,a[100001],b[100001],cnt,s;
vector< pair<ll, int> > r(100001);

int main(){
    cin >> k >> n>> m;
    rep(i,k)cin>>a[i];
    rep(i,k){
        cnt = a[i]*m;
        b[i] = cnt/n;
        s += b[i];
        r.push_back(pair<ll,int>(-cnt%n, i));
    }

    sort(r.begin(), r.end());
    rep(i,m-s){
        b[r[i].second]++;
    }
    rep(i,k)cout << b[i] << " ";cout << endl;

}


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

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

int T;
int N;
int P[555];

vector<int> R;
void go(int x) {
	swap(P[x],P[x+1]);
	R.push_back(x);
}

void solve() {
	int i,j,k,l,r,x,y; string s;

	cin>>T;
	while(T--) {
		cin>>N;
		FOR(i,N) {
			cin>>P[i];
			P[i]--;
		}
		R.clear();
		int step=0;

		for(i=N-1;i>=3;i--) {
			FOR(j,N) if(P[j]==i) break;
			if(j==i) continue;

			if(i==3&&j==2&&step==1) {
				go(1);
				go(2);
				j=1;
			}

			while(j<i) {
				if(step==j%2) {
					go(j);
					j++;
				}
				else if(step==0) {
					if(j==1) go(2);
					else go(0);
				}
				else {
					if(j==2) go(3);
					else go(1);
				}
				step^=1;
			}
		}

		while(1) {
			for(j=N-1;j>=0;j--) if(P[j]!=j) break;
			if(j<0) break;
			assert(j<3);
			swap(P[step],P[step+1]);
			R.push_back(step);
			step^=1;
		}

		cout<<R.size()<<endl;
		FOR(i,R.size()) {
			assert(R[i]%2==i%2);
			cout<<(R[i]+1)<<" ";
		}
		cout<<endl;
		FOR(i,N) assert(P[i]==i);

	}
}

int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}

#include <stdio.h>
#include <vector>
using namespace std;
typedef long long ll;

int main(void) {
  ll i, j, k, n, t, p, q;
  bool f;
  scanf("%lld", &t);
  for(k = 0; k < t; ++k) {
    scanf("%lld", &n);
    ll a[n];
    vector<ll> vec;
    for(i = 0; i < n; ++i) scanf("%lld", &a[i]);
    f = true;
    for(i = n - 1; i > 2; --i) {
      for(j = 0; j < n; ++j) if(a[j] == i + 1) break;
      if(j == i) continue;
      if((j & 1 ? 1 : 0) == f) {
        if(f) q = 1;
        else q = 2;
        vec.push_back(q);
        p = a[q], a[q] = a[q - 1], a[q - 1] = p;
        if(q == j) {
          vec.push_back(q + 1), j--;
          p = a[q], a[q] = a[q + 1], a[q + 1] = p;
        }
      }
      for(; j < i; ++j)
        vec.push_back(j + 1), p = a[j], a[j] = a[j + 1], a[j + 1] = p;
      f = i & 1 ? 0 : 1;
    }
    while(a[0] != 1 || a[1] != 2) {
      vec.push_back(2 - f), p = a[2 - f], a[2 - f] = a[1 - f], a[1 - f] = p, f = !f;
    }
    printf("%lld\n", vec.size());
    for(i = 0; i < vec.size(); ++i) printf("%lld ", vec[i]);
    printf("\n");
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define int long long

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

    int t;
    cin >> t;

    while (t--) {
        int n;
        cin >> n;

        int k = 0;
        while (n % 2 == 0) {
            k++;
            n /= 2;
        }
        if (k == 0) {
            cout << "Odd\n";
        } else if (k == 1) {
            cout << "Same\n";
        } else {
            cout << "Even\n";
        }
    }
}

 #include <bits/stdc++.h>
#define ll         long long int
#define pb         push_back
#define umap       unordered_map
#define mod        998244353ll
#define all(x)     (x).begin(), (x).end()
#define rall(x)    (x).rbegin(), (x).rend()
#define MN(a,b,c)  min(a,min(b,c))
#define MX(a,b,c)  max(a,max(b,c))
#define pr1         pair<ll,ll>
#define F          first
#define S          second
#define mP         make_pair
#define f(i,n)     for(ll i=0;i<n;i++)
#define f1(i,x,y)  for(ll i=x;i<=y;i++)
#define f2(i,x,y)  for(ll i=x;i>=y;i--)
#define yes        cout<<"Yes"<<"\n"
#define no         cout<<"No"<<"\n"
#define modsum(a,b)  ((a%mod)+(b%mod))%mod
#define modpro(a,b)  ((a%mod)*(b%mod))%mod
#define moddif(a,b)  ((a%mod)-(b%mod)+mod)%mod
#define modsumt(a,b,c) modsum(a,modsum(b,c))
//__builtin_popcount(x)
//__builtin_parity(x)   =(number of set bits)%2
//__builtin_clz(x)      to count the number of leading  zeroes
//__builtin_ctz(x)      to count the number of trailing zeroes
//__gcd(a,b)
using namespace std;
ll modularExponentiation(ll x,ll n,ll M)
{
    ll result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=modpro(result,x);
        x=modpro(x,x);
        n=n/2;
    }
    return result;
}
ll binaryExponentiation(ll x,ll n)
{
    ll result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=result * x;
        x=x*x;
        n=n/2;
    }
    return result;
}
ll pow1(ll x,ll y)
{
    ll z=1;
    while(y--){z=z*x;}
    return z;
}
bool isprime(ll n)
{
    // Corner cases
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;

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

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

    return true;
}
// Returns n^(-1) mod p
ll  modInverse(ll n, ll p)
{
    return modularExponentiation(n, p - 2, p);
}

// Returns nCr % p using Fermat's little
// theorem.
unsigned long long nCrModPFermat(unsigned long long n,
                                 ll r, ll p)
{
    // Base case
    if (r == 0)
        return 1;

    // Fill factorial array so that we
    // can find all factorial of r, n
    // and n-r
    unsigned long long fac[n + 1];
    fac[0] = 1;
    for (int i = 1; i <= n; i++)
        fac[i] = (fac[i - 1] * i) % p;

    return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p;
}

bool compare(pair<ll,ll> a, pair<ll,ll> b)
{
    if(a.F==b.F)
        return a.S>b.S;
    else
        return a.F>b.F;
}
ll check(ll x,ll y)
{
    ll z=1;
    ll ans=0;
    while(z<x){ans++;z*=y;}
    return ans;
}
ll countbits(ll n)
{
    ll x=0;
    while(n>0)
    {
        x++;
        n=(n&(n-1));
    }
    return x;
}
ll visited[100001];
void dfs(ll p,set <ll>  v[])
{
    visited[p]=1;
    for(auto it=v[p].begin();it!=v[p].end();it++)
    {
        ll x=*it;
        if(visited[x]==0)
        {
            dfs(x,v);
        }
    }
}
int main()
{
 ios_base::sync_with_stdio(false);
 cin.tie(NULL);
 ll t,x;
 cin>>t;
 while(t--)
 {
     cin>>x;
     ll num=0;
     while((x%2)==0)
     {
         x/=2;
         num++;
     }
     if(num==0)
     {
         cout<<"Odd"<<"\n";
     }
     else
     {
         if(num==1) cout<<"Same"<<"\n";
         else       cout<<"Even"<<"\n";
     }
 }
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double

#define f first
#define s second
#define pb push_back

#define all(x) x.begin(), x.end()
#define mp(x, y) make_pair(x, y)
#define sz(li) (int) (li).size()
#define sum(a) (accumulate ((a).begin(), (a).end(), 0ll))
#define mine(a) (*min_element((a).begin(), (a).end()))
#define maxe(a) (*max_element((a).begin(), (a).end()))
#define mini(a) (min_element((a).begin(), (a).end()) - (a).begin())
#define maxi(a) (max_element((a).begin(), (a).end()) - (a).begin())
#define lowb(a, x) (lower_bound((a).begin(), (a).end(), (x)) - (a).begin())
#define uppb(a, x) (upper_bound((a).begin(), (a).end(), (x)) - (a).begin())

#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vpii vector<pii>
#define vpll vector<pll>

#define endl "\n"

template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v);
template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p) { return cout << "(" << p.f << ", " << p.s << ")"; }
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v) { cout << "[ "; for(int i = 0; i < v.size(); i++) {if (i) cout << ", "; cout << v[i];} return cout << " ]"; }
template<typename A> ostream& operator<<(ostream &cout, vector<vector<A>> const &v) { cout << "["; for (int i = 0; i < v.size(); i++) { if (i) { cout << " "; } cout << v[i]; if (i < v.size() - 1) { cout << endl; } } return cout << "]"; }
template<typename A, typename B> istream& operator>>(istream& cin, pair<A, B> &p) { cin >> p.first; return cin >> p.second; }
template<typename T, typename U> void cmin(T& a, U b){ if (a > b) a = b; }
template<typename T, typename U> void cmax(T& a, U b){ if (a < b) a = b; }

void solve() {
  int n; cin >> n;
  vi a(n);
  map<int, ll> freq;

  for (int i = 0; i < n; i++) {
    cin >> a[i];
    freq[a[i] % 200]++;
  }

  ll ans = 0;

  for (int i = 0; i < 200; i++) {
    ans += freq[i] * (freq[i] - 1) / 2;
  }

  cout << ans << endl;
}

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

  int t = 1;
  // cin >> t;

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

  cerr << "Time: " << 1000.0*clock()/CLOCKS_PER_SEC << " ms\n";
}


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

vector<vector<int>> g;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  int ma = 1000000001, MA = -1;
  rep(i, n) {
    cin >> a[i];
    if (ma > a[i]) ma = a[i];
    if (MA < a[i]) MA = a[i];
  }

  g.resize(n);
  rep(i, m) {
    int x, y;
    cin >> x >> y;
    --x;--y;
    g[y].push_back(x);
  }
  vector<int> dp(n, -1);

  rep(i, n) {
    if (dp[i] >= 0) continue;
    int res = 1e9+1;
    for (auto x : g[i]) {
      if (dp[x] == -1) res = min(res, a[x]);
      else res = min({res, dp[x], a[x]});
    }
    dp[i] = res;
  }

  int ans = -1e9;
  for (int i = 0; i < n; i++) {
    if (dp[i] == 1e9+1) continue;
    ans = max(ans, a[i] - dp[i]);
  }
  cout << ans << endl;
  return 0;
}

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

#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)

using namespace std;
/* using namespace atcoder; */

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

const int MOD = 1'000'000'007;

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

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  rep(i, h) {
    cin >> s.at(i);
  }
  vector<vector<ll>> r(h, vector<ll>(w));
  vector<vector<ll>> d(h, vector<ll>(w));
  vector<vector<ll>> rd(h, vector<ll>(w));
  vector<vector<ll>> dp(h, vector<ll>(w, 0));
  dp.at(0).at(0) = 1;
  rep(i, h) {
    rep(j, w) {
      if (s.at(i).at(j) == '#') {
        r.at(i).at(j) = 0;
        d.at(i).at(j) = 0;
        rd.at(i).at(j) = 0;
        continue;
      }
      // r
      int oi = i - 1;
      int oj = j;
      if (oi < h && oj < w && oi >= 0 && oj >= 0) {
        r.at(i).at(j) += dp.at(oi).at(oj);
        r.at(i).at(j) += r.at(oi).at(oj);
      }
      // d
      oi = i;
      oj = j - 1;
      if (oi < h && oj < w && oi >= 0 && oj >= 0) {
        d.at(i).at(j) += dp.at(oi).at(oj);
        d.at(i).at(j) += d.at(oi).at(oj);
      }
      // rd
      oi = i - 1;
      oj = j - 1;
      if (oi < h && oj < w && oi >= 0 && oj >= 0) {
        rd.at(i).at(j) += dp.at(oi).at(oj);
        rd.at(i).at(j) += rd.at(oi).at(oj);
      }
      dp.at(i).at(j) += r.at(i).at(j);
      dp.at(i).at(j) %= MOD;
      dp.at(i).at(j) += d.at(i).at(j);
      dp.at(i).at(j) %= MOD;
      dp.at(i).at(j) += rd.at(i).at(j);
      dp.at(i).at(j) %= MOD;
    }
  }
  cout << dp.at(h - 1).at(w - 1) << endl;
  return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <map>
#include <queue>
#include <climits>
#define rep(i,n) for (int i=0;i<(n);i++)

using namespace std;
long long MAX = 100005;
long long N, M, Y, K;
string S,T;
//vector<int> g(Max);

int main() {
	string s;
	cin >> s;
	int o_num = 0;
	int nate_num = 0;
	for (int i = 0;i < s.length();i++) {
		if (s[i] == 'o') {
			o_num++;
		}
		else if (s[i] == '?') {
			nate_num++;
		}
	}
	int ans = 0;
	if (o_num > 4) {
		cout << 0 << endl;
		return 0;
	}
	else if(o_num == 4)
	{
		ans = 4 * 3 * 2;
	}
	else if(o_num == 3){
		ans += 4 * (3 * 2) * (nate_num);//はてなあり
		ans += 3 * 2 * 3 * 2;//はてななし
	}
	else if (o_num == 2) {
		ans += (3 * 2) * 2 * (nate_num * nate_num);//はてな2
		ans += 4 * 6 * (nate_num);//はてな1
		ans += 14;//はてななし
	}
	else if (o_num == 1) {
		ans += 4 * pow(nate_num, 3);//はてな3
		ans += (3 * 2) * (nate_num * nate_num);//はてな2
		ans += 4 * (nate_num);//はてな1
		ans += 1;//はてななし
	}
	else if (o_num == 0) {
		ans += pow(nate_num, 4);
	}

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

// L:27
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1000000000
#define LINF 1000000000000000000
#define rep(i,n) for(int i=0;i<n;i++)
#define ALL(a) a.begin(),a.end()
#define PB(a) push_back(a)
using namespace std;
using ll=long long;
using P=pair<int,int>;
const int dx[]={0,-1,1,0},dy[]={-1,0,0,1};
//const int dx[]={-1,0,1,-1,1,-1,0,1},dy[]={-1,-1,-1,0,0,1,1,1};
ll modpow(ll a,ll k,ll m) {
   ll r=1;
   while(k>0) {
      if(k&1) r=r*a%m;
      a=a*a%m;
      k>>=1;
   }
   return r;
}
int main(void) {
   cin.tie(0);
   ios::sync_with_stdio(0);
   cout << fixed << setprecision(7);
   string s; cin >> s;
   int ans=0;
   vector<int> o,x;
   rep(i,10) {
      if(s[i]=='o') o.PB(i);
      else if(s[i]=='x') x.PB(i);
   }
   rep(i,10000) {
      int a,b,c,d;
      a=i%10;
      b=i%100/10;
      c=i%1000/100;
      d=i/1000;
      bool f=true;
      rep(j,o.size()) {
         if(!(o[j]==a || o[j]==b || o[j]==c || o[j]==d) ) f=false;
      }
      rep(j,x.size()) {
         if(x[j]==a || x[j]==b || x[j]==c || x[j]==d) f=false;
      }
      if(f) ans++;
   }
   cout << ans << endl;
   return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
int re(){
	int i=0,f=1;
	char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
	for(;isdigit(c);c=getchar()) i=(i<<3)+(i<<1)+c-'0';
	return i*f;
}
void solve(){
	int n;
	cin>>n;
	int haha=((int)(sqrt(8.0*n+17))-3)/2;
	while(haha*haha+3*haha>=2*n+2) --haha;
	while((haha+1)*(haha+1)+3*(haha+1)<2*n+2) ++haha;
	cout<<n-haha;
}
signed main(){
	int T=1;
	while(T--) solve();
}

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

typedef int_fast32_t int32;
typedef int_fast64_t int64;

const int32 inf = 1e9+7;
const int32 MOD = 998244353;
const int64 llinf = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define all(obj) (obj).begin(),(obj).end()
#define rall(obj) (obj).rbegin(),(obj).rend()
#define fi first
#define se second
#define pb(a) push_back(a)
typedef pair<int32,int32> pii;
typedef pair<int64,int64> pll;

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

struct UnionFind{
    vector<int> par;
    UnionFind(int32 n){
        par = vector<int>(n, -1);
    }

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

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

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

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

template<int64 mod>
struct ModInt{
  int64 x;
  constexpr ModInt(int64 y = 0):x((y%mod+mod)%mod){}
  constexpr ModInt& operator+=(const ModInt& a){
    if((x += a.x) >= mod) x -= mod;
    return *this;
  }
  constexpr ModInt& operator-=(const ModInt& a){
    if((x -= a.x) < 0)x += mod;
    return *this;
  }
  constexpr ModInt& operator*=(const ModInt& a){
    x = x * a.x % mod;
    return *this;
  }
  constexpr ModInt& operator/=(const ModInt& a){
    *this *= a.inv();
    return *this;
  }
  constexpr ModInt operator-() const {
    return ModInt(-x);
  }
  constexpr ModInt operator+(const ModInt& a) const {
    return ModInt(*this) += a;
  }
  constexpr ModInt operator-(const ModInt& a) const {
    return ModInt(*this) -= a;
  }
  constexpr ModInt operator*(const ModInt& a) const {
    return ModInt(*this) *= a;
  }
  constexpr ModInt operator/(const ModInt& a) const {
    return ModInt(*this) /= a;
  }
  constexpr ModInt operator++(){
    *this += ModInt(1);
    return *this;
  }
  constexpr ModInt operator++(int){
    ModInt old = *this;
    ++*this;
    return old;
  }
  constexpr ModInt operator--(){
    *this -= ModInt(1);
    return *this;
  }
  constexpr ModInt operator--(int){
    ModInt old = *this;
    --*this;
    return old;
  }
  constexpr bool operator==(const ModInt& a) const {
    return x == a.x;
  }
  constexpr bool operator!=(const ModInt& a) const {
    return x != a.x;
  }
  constexpr ModInt pow(int64 r) const {
    if(!r)return 1;
    ModInt res = pow(r>>1);
    res *= res;
    if(r & 1) res *= *this;
    return res;
  }
  constexpr ModInt inv() const {
    return pow(mod-2);
  }
  friend istream& operator>>(istream& is, ModInt& a){
    int64 t;
    is >> t;
    a = ModInt(t);
    return is;
  }
  friend ostream& operator<<(ostream& os, const ModInt& a){
    return os << a.x;
  }
};
using mint = ModInt<MOD>;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int32 n;
  cin >> n;
  UnionFind uf(n);
  REP(i,n){
    int32 f;
    cin >> f;
    --f;
    uf.unite(i,f);
  }
  int32 cnt = 0;
  REP(i,n){
    if(i == uf.root(i))++cnt;
  }
  ANS(mint(2).pow(cnt)-1);
  return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int p=998244353;
vector<int> a(200100);
vector<int> b(200100);
int powk(int k,int n){
	int ans=1,m=k;
	while(n){
		if(n%2) ans=1ll*ans*m%p;
    	m=1ll*m*m%p; n/=2;
  	}
  	return ans;
}
int comb(int n,int k){
	int ans=1ll*a[n]*b[n-k]%p*b[k]%p;
	return ans;
}
int main(){
	a[0]=1;
	for(int i=1;i<200020;i++) a[i]=1ll*a[i-1]*i%p;
	rep(i,200020) b[i]=powk(a[i],p-2);
	int n,m;
	cin>>n>>m;
	int ans=1;
	for(int i=2;i<=m;i++){
    	int j=i,x=2;int y=1;
    	while(x*x<=i){
      		int k=0;
      		while(j%x==0){
        		j/=x; k++;
      		}
      		y=1ll*y*comb(n+k-1,k)%p;
      		x++;
    	}
    	if(1<j) y=1ll*y*n%p;
    	ans=(ans+y)%p;
  	}
  	cout<<ans<<endl;
}

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
#define int ll

const int M = 998244353;

int rep(int x) {
  x %= M;
  if (x < 0) x += M;
  return x;
}

int add(int a, int b) {
  return rep(a + b);
}

int mul(int a, int b) {
  return rep(a * b);
}

int pw(int a, int b) {
  int r = 1;
  while (b) {
    if (b & 1) r = rep(r * a);
    a = rep(a * a);
    b /= 2;
  }
  return r;
}

int dv(int a, int b) {
  return rep(a * pw(b, M - 2));
}

const int N = (int) 2e5 + 7;
int n, len, dp[N][25], fact[N], ifact[N];

int comb(int n, int k) {
  if (k < 0 || k > n) return 0;
  return mul(fact[n], mul(ifact[k], ifact[n - k]));
}

signed main() {
  ios::sync_with_stdio(0); cin.tie(0);
  ///freopen ("input", "r", stdin);
  fact[0] = 1;
  for (int i = 1; i < N; i++) {
    fact[i] = mul(fact[i - 1], i);
  }
  ifact[N - 1] = dv(1, fact[N - 1]);
  for (int i = N - 2; i >= 0; i--) {
    ifact[i] = mul(ifact[i + 1], i + 1);
  }
  cin >> len >> n;
  for (int i = 1; i <= n; i++) {
    dp[i][1] = 1;
    for (int j = 1; j <= 20; j++) {
      if (dp[i][j]) {
        for (int k = 2 * i; k <= n; k += i) {
          dp[k][j + 1] = add(dp[k][j + 1], dp[i][j]);
        }
      }
    }
  }
  int ret = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= 20; j++) {
      if (!dp[i][j]) continue;
     /// cout << "last = " << i << ", cnt = " << j << " : " << comb(len, j) << " and " << dp[i][j] << "\n";
      ret = add(ret, mul(comb(len - 1, j - 1), dp[i][j]));
    }
  }
  cout << ret << "\n";
  return 0;
}


#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); ++ i)
#define rep1(i, n) for (int i = 1; i <= (int)(n); ++ i)
#define MP make_pair

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int MOD = 998244353;

int N, a[105];
LL d[105], dp[10005][105];

int main()
{
    scanf("%d", &N);
    rep(i, N) scanf("%d", &a[i]);

    d[0] = 1;
    rep1(i, N) d[i] = d[i - 1] * i % MOD;

    dp[0][0] = 1;
    int sum = 0;
    rep(i, N) {
        sum += a[i];
        for (int j = sum; j >= a[i]; -- j) for (int k = i + 1; k >= 1; -- k) {
            dp[j][k] += dp[j - a[i]][k - 1];
            if (dp[j][k] >= MOD) dp[j][k] -= MOD;
        }
    }

    if (sum & 1) {
        printf("0\n"); return 0;
    }

    LL ret = 0;
    rep(i, N + 1) if (dp[sum / 2][i]) {
        (ret += d[i] * d[N - i] % MOD * dp[sum / 2][i]) %= MOD;
    }

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

    return 0;
}

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

int main()
{
    //*
    int N;
    cin>>N;
    vector<int> W(N);
    for (int &w: W)
        cin>>w;
    /*/
    int N = 100;
    vector<int> W(N, 100);
    //*/

    long long M = 998244353;
    vector<vector<long long>> T(N+1, vector<long long>(N*100+1));
    T[0][0] = 1;
    for (int i=0; i<N; i++)
        for (int j=i; j>=0; j--)
            for (int k=0; k<=i*100; k++)
                (T[j+1][k+W[i]] += T[j][k]) %= M;

    //for (int i=0; i<10; i++)
    //{
    //    for (int j=0; j<10; j++)
    //        cout<<" "<<T[i][j];
    //    cout<<endl;
    //}

    int s = 0;
    for (int w: W)
        s += w;
    if (s%2!=0)
    {
        cout<<0<<endl;
        return 0;
    }
    s /= 2;

    vector<long long> F(N+1);
    F[0] = 1;
    for (int i=1; i<=N; i++)
        F[i] = F[i-1]*i%M;

    long long ans = 0;
    for (int i=1; i<=N; i++)
        (ans += T[i][s]*F[i]%M*F[N-i]) %= M;
    cout<<ans<<endl;
}


#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <list>
#define ll long long int
#define ull unsigned long long int
#define ld long double
using namespace std;

int main() {
	long double N;
	cin >> N;
	long double ans = 0;

	for (int i = 1; i <= N-1; i++) {
		ans += N / (N - i);
	}
	cout.precision(10);
	cout << ans << endl;
}

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

using namespace std;

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

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

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

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

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

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

const int MAX = 510000;
LL fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理。main()ないでCOMinit()する
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
LL COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

void Main()
{
    LL n;cin>>n;
    double result = 0;

    REP(i,n){
        result += n/(i+1.0);
    }

    cout<<result-1<<endl;

	return;
}

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


#include <iostream>
#include <algorithm>
#include <unordered_set>
#include <set>
#include <vector>
#include <queue>
#include <map>
#include <numeric>
#include <math.h>
#include <complex>

using namespace std;

#define rep(i, n) for (long long int i = 0; i < (long long int)(n); i++)
#define irep(i, n) for (long long int i = 1; i <= (long long int)(n); i++)
#define drep(i, n, diff) for (long long int i = 0; i < (long long int)(n); i += diff)
#define mod 1000000007
#define INF 100100100100100101
#define cdeb(val) cout << #val << ":" << val << endl;
#define pdeb(val) printf("%s : %lld\n", #val, val);

typedef long long int ll;
typedef pair<ll, ll> P;
typedef pair<P, P> PP;
typedef tuple<ll, ll, ll> TP;

int main() {
  ll a, b, c;
  cin >> a >> b >> c;
  if ((a*a) + (b*b) < (c*c)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

/*Bismillahi-r-Rahmani-r-Rahim*/
#include<bits/stdc++.h>
using namespace std;
#define  ll         long long
#define  pi         acos(-1.0)
#define  mod        1000000007
#define  yes        cout<<"YES"<<endl
#define  no         cout<<"NO"<<endl
#define  vi         vector<int>
#define  vl         vector<ll int>
#define  pb         push_back
#define  test       cin>>t;while(t--)
#define  lcm(a,b)   a*b/__gcd(a,b)
#define  sd         second
#define  ft         first
#define  rep(i,a,b) for(i=a;i<b;i++)

int main()
{
     ios_base::sync_with_stdio(false);cin.tie(NULL);
     ll int i,n,t,j=0,p,x,l=0,r=0,y,k,c,sum=0,m,d,cnts=0;

         cin>>n;
         x=pow(2,n);
         l=pow(2,n-1);
         vi a(x);
         rep(i,0,x){
         cin>>a[i];
         }
         c=0;
         rep(i,0,l){
         if(c<a[i]){
            c=a[i];
            r=i+1;
         }
        }
        d=0;
        rep(i,l,x){
            if(d<a[i]){
                d=a[i];
                k=i+1;
            }
           // cout<<a[i];
        }

        if(d<c){
            cout<<k<<endl;
        }
        else{
            cout<<r<<endl;
        }

}


#include<bits/stdc++.h>
#define LL long long
#define pb push_back
#define SZ(x) ((int)x.size()-1)
#define ms(a,b) memset(a,b,sizeof a)
#define F(i,a,b) for (int i=(a);i<=(b);++i)
#define DF(i,a,b) for (int i=(a);i>=(b);--i)
using namespace std;
inline int read(){
	char ch=getchar(); int w=1,c=0;
	for(;!isdigit(ch);ch=getchar()) if (ch=='-') w=-1;
	for(;isdigit(ch);ch=getchar()) c=(c<<1)+(c<<3)+(ch^48);
	return w*c;
}
int main(){
	int n=read();
	cout<<(1<<n)-1<<"\n";
	F(i,1,(1<<n)-1){
		F(j,0,(1<<n)-1){
			cout<<((__builtin_popcount(i&j)&1)&1 ? 'A' : 'B');
		}
		cout<<"\n";
	}
	return 0;
}
/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
	* DON'T GET STUCK ON ONE APPROACH
*/

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

#define FAST_IO ios::sync_with_stdio(false); cin.tie(0), cout << setprecision(15);
#define ll long long int
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rrep(i, k, n) for (ll i = k; i>=n; i--)
#define repp(i, k, n) for (ll i = k; i < (n); i++)
#define pb push_back
#define all(x) begin(x), end(x)
#define vc vector<ll>
#define ordered_set tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update>

using namespace __gnu_pbds;
using namespace std;

int main() {
    FAST_IO
    string s;
    cin >> s;
    bool ans = true;
    rep(i, s.size()) {
        if (i % 2 == 0) ans &= bool(islower(s[i]));
        else ans &= bool(isupper(s[i]));
    }
    if (ans) cout << "Yes";
    else cout << "No";
    return 0;
}