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

 int main(){
     int n;
     cin >> n;
     vector<int> a(n);
    int ma = 0;
     rep(i,n){

         cin >> a[i];
    ma = max(ma, a[i]);
    }

    vector<int> ans(ma+1);

    rep(i,ma+1){
        rep(j,n){
            if(i == 0)break;

            if(a[j]%i == 0){
                ans[i]++;
            }
        }
    }
    int count =0;
    int out =0;
    rep(i,ma+1){
        if(i < 2)continue;
        if(count < ans[i]){
            out = i;
            count = ans[i];
        }
    }
    cout << out << endl;

    return 0;
 }

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(void){

    vector< int > usd(10001, 0);
    vector< int > a = {6, 10, 15};
    usd[6] = usd[10] = usd[15] = 1;
    for(int i = 6; i <= 10000; i++){
        if(usd[i] == 1) continue;
        if((i%2==0) + (i%3==0) + (i%5==0) >= 2){
            a.push_back(i);
            usd[i] = 1;
        }
    }

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


#include <bits/stdc++.h>

using namespace std;

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

#define eps 1e-9
#define INF 2000000000              // 2e9
#define LLINF 2000000000000000000ll // 2e18 (llmax:9e18)
#define all(x) (x).begin(), (x).end()
#define sq(x) ((x) * (x))

#ifndef LOCAL
#define dmp(...) ;
#else
#define dmp(...)                                                               \
  cerr << "[ " << #__VA_ARGS__ << " ] : " << dump_str(__VA_ARGS__) << endl
#endif

// ---------------- Utility ------------------

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

template <class T>
using MaxHeap = priority_queue<T>;
template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;

template <class T>
vector<T> vect(int len, T elem) {
  return vector<T>(len, elem);
}

// ----------------- Input -------------------

template <class T, class U>
istream &operator>>(istream &is, pair<T, U> &p) {
  return is >> p.first >> p.second;
}

template <class T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) is >> vec[i];
  return is;
}

// ----------------- Output ------------------

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  return os << p.first << ',' << p.second;
}

template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  for (const T &e : v) os << e << " ";
  return os;
}

template <class T>
ostream &operator<<(ostream &os, const deque<T> &d) {
  for (const T &e : d) os << e << " ";
  return os;
}

template <class T>
ostream &operator<<(ostream &os, const set<T> &s) {
  os << "{ ";
  for (const T &e : s) os << e << " ";
  return os << "}";
}

template <class T, class U>
ostream &operator<<(ostream &os, const map<T, U> &m) {
  os << "{ ";
  for (const auto &[key, val] : m) os << "( " << key << " -> " << val << " ) ";
  return os << "}";
}

template <class TupleTy, size_t... I>
void dump_tuple(ostream &os, const TupleTy t, std::index_sequence<I...>) {
  (..., (os << (I == 0 ? "" : ",") << std::get<I>(t)));
}

template <class... Args>
ostream &operator<<(ostream &os, const tuple<Args...> &t) {
  os << "(";
  dump_tuple(os, t, std::make_index_sequence<sizeof...(Args)>());
  return os << ")";
}

void dump_str_rec(ostringstream &) {}

template <class Head, class... Tail>
void dump_str_rec(ostringstream &oss, Head &&head, Tail &&... tail) {
  oss << ", " << head;
  dump_str_rec(oss, forward<Tail>(tail)...);
}

template <class T, class... U>
string dump_str(T &&arg, U &&... args) {
  ostringstream oss;
  oss << arg;
  dump_str_rec(oss, forward<U>(args)...);
  return oss.str();
}

// --------------- Fast I/O ------------------

void fastio() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(20);
}

// ------------ End of template --------------

#define endl "\n"

void solve() {
  int N;
  cin >> N;
  int a = 1;
  int p = 0;
  while (a < N) {
    a *= 2;
    p++;
  }
  vector<vector<int>> ans(N + 1);
  for (int i = 1; i <= N; i++) {
    int a = (2 * i) % N;
    ans[i].push_back((a == 0) ? N : a);
    a++;
    a %= N;
    ans[i].push_back((a == 0) ? N : a);
  }
  for (int i = 1; i <= N; i++) cout << ans[i] << endl;
  return;
}

int main() {
  fastio();
  solve();
  // int t; cin >> t; while(t--)solve();

  // int t; cin >> t;
  // for(int i=1;i<=t;i++){
  //   cout << "Case #" << i << ": ";
  //   solve();
  // }
  return 0;
}

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

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

  int n;
  cin >> n;

  for (int i = 1; i <= n; i++) {
    int x = 2 * i, y = x + 1;
    while (x > n) x -= n;
    while (y > n) y -= n;
    cout << x << " " << y << '\n';
  }
}


#define LOCAL
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

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

typedef long long int64;
typedef pair<int, int> ii;
#define SZ(x) (int)((x).size())
template <typename T> static constexpr T inf = numeric_limits<T>::max() / 2;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

struct fast_ios {
  fast_ios() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
  };
} fast_ios_;

int main() {
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  for (int i = 0; i < n; ++i) cin >> b[i];
  int64 preA = 0, best = 0;
  for (int i = 0; i < n; ++i) {
    preA = max(preA, 1LL * a[i]);
    best = max(best, b[i] * preA);
    cout << best << '\n';
  }

  return 0;
}

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

int main(){
    ll n;
    cin >> n;
    vector<vector<ll>> kusa(2,vector<ll>(n));
    rep(i,2){
        rep(ii,n){
            cin >> kusa.at(i).at(ii);
        }
    }
    ll max1 = kusa.at(1).at(0)*kusa.at(0).at(0),max2=0,maxm1=0,maxm2=kusa.at(0).at(0),fl=0,fl2=0;
    cout << max1 <<endl;
  	for(ll i = 1;i<n;i++){
        if(maxm2 < kusa.at(0).at(i)){
            maxm2 = kusa.at(0).at(i);
        }
        cout << max({max1,maxm2*kusa.at(1).at(i)}) << endl;
      	if(max1 < maxm2*kusa.at(1).at(i)){
          	max1 = maxm2*kusa.at(1).at(i);
        }
    }
}


#include <bits/stdc++.h>
#pragma GCC target("arch=skylake-avx512")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<long, int>;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rrep(i, n) for (int i = 1; i < (int)(n+1); ++i)
const long long INF = 1LL<<60;
const long long MOD = 1000000007;
const long long mod = 998244353;
const long long MAX = 510000;
int ri() {
	int n;
	scanf("%d", &n);
	return n;
}
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;
}
struct Edge {
    long long to;
    long long cost;
    Edge(long long t, long long w) : to(t), cost(w){}
};
using Graph = vector<vector<Edge>>;
/* dijkstra(G,s,dis)
    入力：グラフ G, 開始点 s, 距離を格納する dis
    計算量：O(|E|log|V|)
    副作用：dis が書き換えられる
*/
vector<ll>dis;
void dijkstra(const Graph &G, int s, vector<long long> &dis) {
    int N = G.size();
    dis.resize(N, INF);
    priority_queue<P, vector<P>, greater<P>> pq;  // 「仮の最短距離, 頂点」が小さい順に並ぶ
    dis[s] = 0;
    pq.emplace(dis[s], s);
    while (!pq.empty()) {
        P p = pq.top();
        pq.pop();
        int v = p.second;
        if (dis[v] < p.first) {  // 最短距離で無ければ無視
            continue;
        }
        for (auto &e : G[v]) {
            if (dis[e.to] > dis[v] + e.cost) {  // 最短距離候補なら priority_queue に追加
                dis[e.to] = dis[v] + e.cost;
                pq.emplace(dis[e.to], e.to);
            }
        }
    }
}
int main() {
    int H=ri(),W=ri();
    char A[H+2][W+2];
    rep(i,H+2){
        rep(j,W+2){
            A[i][j]='#';
        }
    }
    int sx=0;
    int sy=0;
    int gx=0;
    int gy=0;
    rrep(i,H){
        rrep(j,W){
            cin>>A[i][j];
            if(A[i][j]=='S'){
                sx=i-1;
                sy=j-1;
            }
            if(A[i][j]=='G'){
                gx=i-1;
                gy=j-1;
            }
        }
    }
    Graph G(H*W+26);
    vector<ll>P(26,INF);
    rrep(i,H){
        rrep(j,W){
            if(A[i][j]!='#'&&A[i+1][j]!='#'){
                G[(i-1)*W+j-1].push_back(Edge{i*W+j-1,1});
            }
            if(A[i][j]!='#'&&A[i-1][j]!='#'){
                G[(i-1)*W+j-1].push_back(Edge{(i-2)*W+j-1,1});
            }
            if(A[i][j]!='#'&&A[i][j+1]!='#'){
                G[(i-1)*W+j-1].push_back(Edge{(i-1)*W+j,1});
            }
            if(A[i][j]!='#'&&A[i][j-1]!='#'){
                G[(i-1)*W+j-1].push_back(Edge{(i-1)*W+j-2,1});
            }
        }
    }
    rrep(i,H){
        rrep(j,W){
          	if(A[i][j]!='S'&&A[i][j]!='G'){
            if(A[i][j]!='.'&&A[i][j]!='#'){
                ll Y=A[i][j]-'a';
                G[(i-1)*W+j-1].push_back(Edge{H*W+Y,1});
                G[H*W+Y].push_back(Edge{(i-1)*W+j-1,0});
            }
            }
        }
    }
    dijkstra(G,sx*W+sy,dis);
    if(dis[gx*W+gy]<INF){
    cout<<dis[gx*W+gy]<<endl;
    }
    else{
    cout<<-1<<endl;
    }
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define all(v) begin(v), end(v)
#define sz(v) v.size()
#define INF 1e18+9
#define EPSILON 1e-14
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

ll com2(ll x){
    if(x < 2){
        return 0;
    }
    return x * (x - 1) / 2;
}

ll N;

ll cake_num(ll x){ //合計がxのケーキは何個あるか
    return com2(x-1) - com2(x-1-N) * 3 + com2(x-1-2*N) * 3 - com2(x-1-3*N);
}

ll cake_num2(ll x, ll y){ //合計がxで綺麗さがyのケーキは何個あるか
    if(y <= 0 || y >= x-1 || y >= N+1 || y + 2*N < x){
        return 0;
    }
    x -= y;
    ll lb = max(x-N, 1LL);
    ll ub = min(N, x-1);
    return ub - lb + 1;
}

int main()
{
    ll K;
    cin >> N >> K;
    ll cnt = 0;
    ll p = 2;
    while(cnt < K){
        p++;
        cnt += cake_num(p);
    }
    cnt -= cake_num(p);
    ll q = 0;
    while(cnt < K){
        q++;
        cnt += cake_num2(p, q);
    }
    cnt -= cake_num2(p, q);
    ll r = max(p-q-N, 1LL) - 1;
    r += K - cnt;
    cout << q << " " << r << " " << p-q-r << '\n';
}


//Codeforcesで128bit整数を使いたいとき
//→__int128_tを使う&GNU C++17 (64)で提出する

//インクルードなど
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower

using namespace std;
typedef long long ll;

//イテレーション
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
#define FORA(i,I) for(const auto& i:I)
//x:コンテナ
#define ALL(x) x.begin(),x.end()
#define SIZE(x) ll(x.size())
//定数
#define INF32 2147483647 //2.147483647×10^{9}:32bit整数のinf
#define INF64 9223372036854775807 //9.223372036854775807×10^{18}:64bit整数のinf
#define MOD 1000000007 //問題による
//略記
#define F first
#define S second
//出力(空白区切りで昇順に)
#define coutALL(x) for(auto i=x.begin();i!=--x.end();i++)cout<<*i<<" ";cout<<*--x.end()<<endl;

//aをbで割る時の繰上げ,繰り下げ
ll myceil(ll a,ll b){return (a+(b-1))/b;}
ll myfloor(ll a,ll b){return a/b;}

signed int main(){
  double a,b,c,d;
  cin>>a>>b>>c;
  d=(a+b+c)/double(3.0);
  cout<<(((a==d)||(b==d)||(c==d))?"Yes":"No");

}

#pragma GCC optimize(2)
//#include <bits/stdc++.h>
#include <iostream>
#include <set>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
#include <vector>
#include <utility>
#include <map>
#define rush()      int T; while(cin>>T) while(T--)
#define ms(a,b)     memset(a,b,sizeof a)
#define lowbit(x)   ((x)&(-x))
#define inf         0x7f7f7f7fll
#define eps         1e-11
#define sd(a)       scanf("%d",&a)
#define sll(a)      scanf("%lld",&a)
#define sll2(a,b)   scanf("%lld%lld",&a,&b)
#define sll3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define sdd(a,b)    scanf("%d%d",&a,&b)
#define sddd(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define sf(a)       scanf("%lf",&a)
//#define sc(a)       scanf("%c\n",&a)
#define ss(a)       scanf("%s",a)
#define pd(a)       printf("%d\n",a)
#define pdd(a,b)    printf("%d %d\n",a,b)
#define pddd(a,b,c) printf("%d %d %d\n",a,b,c)
#define pll(a)      printf("%lld\n",a)
#define pf(a)       printf("%.1lf\n",a)
#define pc(a)       printf("%c",a)
#define ps(a)       printf("%s\n",a)
#define rep(i,a,b)  for(int i=(a);i<=(b);i++)
#define forn(i,a,b,x)  for(int i=(a);i<=(b);i+=(x))
#define per(i,a,b)  for(int i=(b);i>=(a);i--)
#define pb(a)       push_back(a)
#define mp(a,b)     make_pair(a,b)
#define debug(a)    cout<<#a<<" : "<<a<<" "<<" ; "
#define dbg(a)      cout<<#a<<" : "<<a<<endl
#define show(a,b)   cout<<a<<" :\t"<<b<<"\t*"<<endl
#define IOS         ios::sync_with_stdio(0); cin.tie(0)
#define PAUSE       system("pause")
#define all(x)      x.begin(),x.end()
//#define print(a)    cout<<a<<endl;continue;
#define fr          first
#define sc          second
#define ceils(a,b)  ((a-1ll+b)/(b))
#define floors(a,b) floor(double(a)/double(b))
using namespace std;
//inline void swap(int &x,int &y){x^=y^=x^=y;}
typedef long long ll;
//using ui=unsigned int;
typedef unsigned long long ull;
typedef pair<int,int> pii;
const double pi=acos(-1.0);
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};
const int limit=5e5;

int read()
{
	int s=0;
	char c=getchar(),lc='+';
	while (c<'0'||'9'<c) lc=c,c=getchar();
	while ('0'<=c&&c<='9') s=s*10+c-'0',c=getchar();
	return lc=='-'?-s:s;
}

void write(int x)
{
	if (x<0) putchar('-'),x=-x;
	if (x<10) putchar(x+'0');
	else write(x/10),putchar(x%10+'0');
}

void print(int x,char c='\n')
{
	write(x);
	putchar(c);
}

ll mod=2147483648;
const int N=3e5+5;

    int n, m, _;
    int i, j, k;
    int a[N];
    int pos[N];
    vector<int> ans;

signed main()
{
    //IOS;
    rush(){
        sd(n);
        rep(i, 1, n) sd(a[i]), pos[a[i]] = i;
        int opt = 1;
        rep(i, 1, n){
            if(i == pos[i]) continue;
            if((pos[i] - 1) % 2 != opt){
                if(pos[i] - 2 >= i){
                    ans.pb(pos[i] - 2);
                    int x = pos[i] - 2, y = pos[i] - 1;
                    swap(pos[a[x]], pos[a[y]]);
                    swap(a[x], a[y]);
                    opt ^= 1;
                }
                else if(pos[i] == i + 1){
                    ans.pb(i - 1);
                    ans.pb(i);
                    ans.pb(i - 1);
                    ans.pb(i);
                    ans.pb(i - 1);
                    //ans.pb(i);
                    opt ^= 1;
                    int x = pos[i], y = pos[i] - 1;
                    swap(pos[a[x]], pos[a[y]]);
                    swap(a[x], a[y]);
                    continue;
                }
            }
            for(int j = pos[i] - 1; j >= i; j--){
                ans.pb(j);
                int x = j, y = j + 1;
                swap(pos[a[x]], pos[a[y]]);
                swap(a[x], a[y]);
                opt ^= 1;
            }
        }
        pd(ans.size());
        for(auto it : ans) printf("%d ", it);
        puts("");
        ans.clear();
    }
    //PAUSE;
    return 0;
}


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

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

bool check(int start, int up_floor, map<int, int> &A_map, map<int, int> &B_map, int &wild_card){
    for(int i=start;i<start+up_floor;i++){
        int from = i;
        int to = i+up_floor;
        if(A_map.count(to)){
            return false;
        }
        if(B_map.count(from)){
            return false;
        }

        if((!A_map.count(from))&&(!B_map.count(to))){
            wild_card--;
            continue;
        }

        if(A_map.count(from)){
            if(A_map[from]!=-1 && A_map[from]!=to){
                return false;
            }
        }
        if(B_map.count(to)){
            if(B_map[to]!=-1 && B_map[to]!=from){
                return false;
            }
        }

    }
    if(wild_card<0){
        return false;
    }

    return true;
}

signed main(){
    int N; cin>>N;
    vec_int A(N);
    vec_int B(N);
    rep(i,N)cin>>A.at(i)>>B.at(i);
    map<int, int> A_map;
    rep(i,N)if(A.at(i)!=-1)A_map[A.at(i)]=B.at(i);

    map<int, int> B_map;
    rep(i,N)if(B.at(i)!=-1)B_map[B.at(i)]=A.at(i);

    int wild_card = 0;
    rep(i,N)if(A.at(i)==-1&&B.at(i)==-1)wild_card++;

    rep(i,N){
        if(A.at(i)>=0&&B.at(i)>=0){
            if(A.at(i)>=B.at(i)){
                cout<<"No"<<endl;
                return 0;
            }
        }
    }
    set<int> num_set;
    rep(i,N){
        if(A.at(i)!=-1){
            if(num_set.count(A.at(i))){
                cout<<"No"<<endl;
                return 0;
            }else{
                num_set.insert(A.at(i));
            }
        }
        if(B.at(i)!=-1){
            if(num_set.count(B.at(i))){
                cout<<"No"<<endl;
                return 0;
            }else{
                num_set.insert(B.at(i));
            }
        }

    }

    set<P> start_set;

    queue<P> que;
    que.emplace(1, wild_card);

    while(!que.empty()){
        int start_floor, count; tie(start_floor, count) = que.front(); que.pop(); //start_floorは必ず奇数

        int max_up = (2*N-start_floor+1)/2;
        for(int i=1;i<=max_up;i++){
            int num = count;
            if(check(start_floor, i, A_map, B_map, num)){
                if(i==max_up){
                    cout<<"Yes"<<endl;
                    return 0;
                }
                int next = start_floor+i*2;
                if(!start_set.count(make_pair(next, num))){
                    start_set.insert(make_pair(next,num));
                    que.emplace(next,num);
                }
            }
        }
    }
    cout<<"No"<<endl;

    return 0;
}

#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <string>
#include <list>
#include <map>
using namespace std;

long long int min(long long int a,long long int b){
    if(a>b){
        return b;
    }else{
        return a;
    }
}

long long int max(long long int a,long long int b){
    if(a>b){
        return a;
    }else{
        return b;
    }
}

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

// a^{-1} mod を計算する
long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

void f(vector<vector<int>>& a,vector<vector<int>>& b,int N,int K){
    for(int i=0;i<N-1;i++){
        for(int j=i+1;j<N;j++){
            int l=0;
            for(int k=0;k<N;k++){
                if(a[k][i]+a[k][j]>K){
                    break;
                }
                l+=1;
            }
            if(l==N){
                b[i][j]=1;
                b[j][i]=1;
            }
        }
    }
}

void g(vector<vector<int>>& a,vector<vector<int>>& c,int N,int K){
    for(int i=0;i<N-1;i++){
        for(int j=i+1;j<N;j++){
            int l=0;
            for(int k=0;k<N;k++){
                if(a[i][k]+a[j][k]>K){
                    break;
                }
                l+=1;
            }
            if(l==N){
                c[i][j]=1;
                c[j][i]=1;
            }
        }
    }
}

int h(vector<vector<int>>& b,vector<int>& x,int N){
    int M=1;
    vector<int> a(N);
    for(int i=0;i<N;i++){
        a[i]=0;
    }
    stack<int> d;
    for(int i=0;i<N;i++){
        int j=0;
        if(a[i]==0){
            d.push(i);
            a[i]=1;
        }
        while(!d.empty()){
            int k=d.top();
            d.pop();
            j+=1;
            for(int l=0;l<N;l++){
                if(b[k][l]==1 && a[l]==0){
                    d.push(l);
                    a[l]=1;
                }
            }
        }
        if(j>1){
            x.push_back(j);
            M=max(M,j);
        }
    }
    return M;
}

int main(){
    int a,b,x,y;
    cin>>a>>b>>x>>y;
    if(a==b){
        cout<<x<<endl;
    }else{
        int ans=0;
        if(a>b){
            ans+=x;
            a=a-1;
        }else{
            ans+=x;
        }
        if(y>2*x){
            ans+=2*x*abs(a-b);
        }else{
            ans+=y*abs(a-b);
        }
        cout<<ans<<endl;
    }
    return 0;
}


                              //ABHISHEK AGRAWAL,BIT mesra//
//Author: Abhishekagrawal
//Date: 30/05/2021
//Time: 15:57:20
#include<bits/stdc++.h>
using namespace std;
#define booga cout << "booga" << endl
#define int long long int
#define pb push_back
#define f first
#define s second
#define mod 1000000007
#define pi (double)acos(-1.0)
#define what_is(x) cerr << #x << " is " << x << endl;
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define safai(...) Clearing_out(__VA_ARGS__)
void Clearing_out() { return; }

template <typename Head, typename... Tail>
void Clearing_out(Head &H, Tail & ... T) {
	H.clear();
	Clearing_out(T...);
}

const int N=400040;int a[N],b[N],c[N],ans,sum;
int n;
int power(int a,int b,int M){a%=M;int res=1;while(b>0){if(b%2 ==1){res=(res*a)%M;}a=(a*a)%M;b/=2;} return res;}
void testcase(){
  int k;
  cin>>n>>k;
  ans=((n*(n+1))/2)*(100*k);
  int cur=(k*(k+1))/2;
  cur*=n;
  cout<<ans+cur;
  return;
}

int32_t main(){
  ios_base::sync_with_stdio(false);
  cin.tie(0);cout.tie(0);
  /*Today's thought: Push yourself,because no one else is going to do it for you.*/
  /*SELECT * FROM World WHERE "Someone" LIKE '%You%'*/
  //g++ -o a acm.cpp -DENABLE_FILE_IO;./a
  int test=1;
  // cin>>test;
  int t=0;
  while(test--){
    // cout<<"Case #"<<++t<<":"<<" ";
    testcase();
  }
  cerr << "Time : " << 1000 *((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
  return 0;
}

#include <iostream>
using namespace std;
int main(void){
    //prayer
    int M, H;
    cin >> M >> H;
    if (H % M == 0){
        cout << "Yes" << endl;
    }
    else{
        cout << "No"  << endl;
    }
return 0;
}


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

typedef long long ll;
typedef long double ld;
#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define range(a) a.begin(), a.end()
#define endl "\n"
#define Yes() cout << "Yes" << endl
#define No() cout << "No" << endl
#define MP make_pair
using P = pair<int, int>;
const long long INF = 1LL<<60;
void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }

const int64_t CYCLES_PER_SEC = 2800000000;

struct Timer {
	int64_t start;
	Timer() { reset(); }
	void reset() { start = getCycle(); }
	void plus(double a) { start -= (a * CYCLES_PER_SEC); }
	inline double get() { return (double)(getCycle() - start) / CYCLES_PER_SEC; }
	inline int64_t getCycle() {
		uint32_t low, high;
		__asm__ volatile ("rdtsc" : "=a" (low), "=d" (high));
		return ((int64_t)low) | ((int64_t)high << 32);
	}
};

Timer timer;

unsigned long xor128() {
	static unsigned long x = 123456789, y = 362436069, z = 521288629, w = 88675123;
	unsigned long t = (x^(x << 11));
	x = y;
	y = z;
	z = w;
	return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

// 0以上1未満の小数をとる乱数
static double rand01(){
	double ans = ((xor128() + 0.5)  * (1.0 / 9223372036854775807));
	return ans / 2;
}

int main(void){
	ios::sync_with_stdio(0);
	cin.tie(0);
	timer.reset();
	double TIMELIMIT = 2.8;
	//double ti = timer.get();
	int N, M;
	cin >> N >> M;
	map<int, vector<string>> mp;
	vector<vector<char>> ans(N, vector<char>(20, '.'));
	int nowx = 0, nowy = 0;
	set<int> length;
	FOR(i,0,M){
		string s;
		cin >> s;
		mp[(int)s.size()].push_back(s);
		length.insert((int)s.size());
	}

	for (auto itr = length.begin(); itr != length.end(); itr++){
		FOR(i,0,(int)mp[*itr].size()){
			string s = mp[*itr][i];
			if(nowx >= N-1 && nowy + *itr >= N){
				char c = 'A';
				for(auto x: ans){
					for(auto y: x){
						if(y == '.')	cout << c++;
						else	cout << y;
						if(c == 'I')	c = 'A';
					}
					cout << endl;
				}
				return 0;
			}
			FOR(k,0,(int)s.size()){
				if(nowy >= 20){nowy = 0; nowx++;}
				ans[nowx][nowy++] = s[k];
			}
		}
	}

		return 0;
}

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

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

  //(i,j)から a[i][j][k]にいける
  vector<vector<vector<pair<int,int>>>>go(h,vector<vector<pair<int,int>>>(w,vector<pair<int,int>>(0)));
  go.push_back(vector<vector<pair<int,int>>>(26,vector<pair<int,int>>(0)));
  pair<int,int>S,G;
  vector<vector<char>>a(h,vector<char>(w));
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin>>a[i][j];
      if(a[i][j]=='S'){S={i,j};}
      else if(a[i][j]=='G'){G={i,j};}
      else if(a[i][j]!='.'&&a[i][j]!='#'){
        go[i][j].push_back({h,a[i][j]-'a'});
        go[h][a[i][j]-'a'].push_back({i,j});
      }
    }
  }
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(a[i][j]=='#')continue;
      if(i>0&&a[i-1][j]!='#')go[i][j].push_back({i-1,j});
      if(i<h-1&&a[i+1][j]!='#')go[i][j].push_back({i+1,j});
      if(j>0&&a[i][j-1]!='#')go[i][j].push_back({i,j-1});
      if(j<w-1&&a[i][j+1]!='#')go[i][j].push_back({i,j+1});
    }
  }
  //cout<<"ok\n";
  vector<vector<int64_t>>cost(h,vector<int64_t>(w,1e18));
  cost.push_back(vector<int64_t>(26,1e18));
  cost[S.first][S.second]=0;
  deque<pair<int,int>>bfs;
  bfs.push_back(S);
  while(bfs.size()){
    pair<int,int>n=bfs.front();
    bfs.pop_front();
    if(n.first==h){
      for(int i=0,l=go[h][n.second].size();i<l;i++){
        if(cost[go[h][n.second][i].first][go[h][n.second][i].second]>cost[h][n.second]){
          cost[go[h][n.second][i].first][go[h][n.second][i].second]=cost[h][n.second];
          bfs.push_front({go[h][n.second][i].first,go[h][n.second][i].second});
        }
      }
    }else{
      int i=n.first,j=n.second;
      for(int k=0,l=go[i][j].size();k<l;k++){
        if(cost[go[i][j][k].first][go[i][j][k].second]>cost[i][j]+1){
          cost[go[i][j][k].first][go[i][j][k].second]=cost[i][j]+1;
          bfs.push_back({go[i][j][k].first,go[i][j][k].second});
        }
      }
    }
  }
  /*
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++)cout<<cost[i][j]<<' ';
    cout<<'\n';
  }
  */
  cout<<(cost[G.first][G.second]==1e18?-1:cost[G.first][G.second])<<'\n';
}


#include <bits/stdc++.h>

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

#define pb push_back
#define mp make_pair
#define sz(s) (int)s.size()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(a) a.begin(),a.end()
#define allr(a) a.rbegin(),a.rend()
#define rep(i,a,b) for(int i = a; i < b; i++)
#define in insert
#define ff first
#define ss second
#define vt vector
#define ub upper_bound
#define lb lower_bound
#define repp(i,n,a) for(int i = n; i >= a; i--)
#define re(a,n) rep(i,0,n) cin>>a[i];
const long double pi = 2 * acos(0.0);
const int mod = 1e9 + 7;
const int maxn = 2100;
const int inf=2e9;

int n,m;
int a[maxn][maxn];
int dp[maxn][maxn];
int f(int i, int j){
    if(dp[i][j]!=-inf)
        return dp[i][j];
    if(i+1<n)
        dp[i][j]=max(dp[i][j],a[i+1][j]-f(i+1,j));
    if(j+1<m)
        dp[i][j]=max(dp[i][j],a[i][j+1]-f(i,j+1));
    return dp[i][j];
}

void solve(){
    cin>>n>>m;
    rep(i,0,n){
        string s;
        cin>>s;
        rep(j,0,m){
            dp[i][j]=-inf;
            a[i][j]=(s[j]=='+'?1:-1);
        }
    }
    dp[n-1][m-1]=0;
    f(0,0);
    // rep(i,0,n){
    //     rep(j,0,m){
    //         cout<<dp[i][j]<<' ';
    //     }cout<<'\n';
    // }
    if(dp[0][0]>0)
        cout<<"Takahashi\n";
    else if(dp[0][0]<0)
        cout<<"Aoki\n";
    else
        cout<<"Draw\n";

    return;
}

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

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

    return 0;
}

#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
#define ll long long
ll maxn[200005];
ll minn[200005];
ll dp[200005][2];
ll n;
int main(){
    cin>>n;
    for (int i=0;i<200005;i++) {
        maxn[i]=-1e10;
        minn[i]=1e10;
    }
    for (int i=0;i<n;i++){
        ll x,c;cin>>x>>c;
        if (x>maxn[c]) maxn[c]=x;
        if (x<minn[c]) minn[c]=x;
    }
    vector<ll> yes;
    yes.push_back(0);
    maxn[0]=0; minn[0]=0;
    for (int i=0;i<=n;i++) {
        if (maxn[i]!=-1e10) yes.push_back(i);
    }
    yes.push_back(200001);
    maxn[200001]=0; minn[200001]=0;

    int len=yes.size();
    //dp[yes[0]][0]=maxn[yes[0]]+(maxn[yes[0]]-minn[yes[0]]);
    //dp[yes[0]][1]=maxn[yes[0]];

    for (int i=1;i<len;i++){
        ll now=yes[i];
        ll last=yes[i-1];
        dp[now][0]=min(dp[last][0]+ abs(maxn[now]-minn[last])  + (maxn[now]-minn[now]),
                       dp[last][1]+ abs(maxn[last]-maxn[now])  + (maxn[now]-minn[now]));
        dp[now][1]=min(dp[last][0]+ abs(minn[now]-minn[last])  + (maxn[now]-minn[now]),
                       dp[last][1]+ abs(maxn[last]-minn[now])  + (maxn[now]-minn[now]));
    }
    /*for (int i=0;i<len;i++){
        cout<<dp[yes[i]][0]<<"  "<<dp[yes[i]][1]<<endl;
    }*/
    cout<<min(dp[yes[len-1]][0],dp[yes[len-1]][1])<<endl;

}


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

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

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

//const ll mod=998244353;
const ll mod = 1e9 + 7;
const ll MAX = 100;
template <typename T>
T abs(T a) { if (a < 0)return -a; else return a; }//2020/09/30 stdlib has abs(long) abs(long long) error
//////////////////////////////////////
class UnionFind {
public:
    vector <ll> par; // 各元の親を表す配列
    vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    UnionFind(ll sz_): par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz_=1) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }

    // Member Function
    // Find
    ll root(ll x) { // 根の検索
        while (par[x] != x) {
         x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) { // 連結判定
        return root(x) == root(y);
    }

    ll size(ll x) { // 素集合のサイズ
        return siz[root(x)];
    }
};

int main(){
    int n;
    cin>>n;
    vi a(n);
    int ans=0;
    rep(i,n)cin>>a[i];
    UnionFind uf(200005);
    if(n==1){
        cout<<0<<endl;
        return 0;
    }
    uf.init(200005);
    {
        rep(i,n/2+1){
            int l=i;
            int r=n-1-i;
            if(uf.issame(a[l],a[r]))continue;
            uf.merge(a[l],a[r]);
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

#include <algorithm>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int, int>;
const int MX = 1505;

bool visited[MX][MX];
bool memo[MX][MX];
bool light[MX][MX];
bool wall[MX][MX];
bool ok[MX][MX];
int di[] = {1, 0, -1, 0};
int dj[] = {0, -1, 0, 1};
int h, w;

bool f(int dir, int i, int j) {
  if (i < 0 || i >= h || j < 0 || j >= w) return false;
  if (light[i][j]) return true;
  if (visited[i][j]) return memo[i][j];
  if (wall[i][j]) return false;
  visited[i][j] = true;

  return memo[i][j] = f(dir, i + di[dir], j + dj[dir]);
};

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

  rep(i, n) {
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    light[a][b] = true;
  }
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    wall[a][b] = true;
  }
  rep(dir, 4) {
    rep(i, h) rep(j, w) visited[i][j] = false;
    rep(i, h) rep(j, w) if (f(dir, i, j)) ok[i][j] = true;
  }
  int ans = 0;
  rep(i, h) {
    rep(j, w) {
      if (ok[i][j]) ans++;
    }
  }
  cout << ans;

  return 0;
}


#include<bits/stdc++.h>
#define pb push_back
#define int long long
using namespace std;
int tt,n,p=200001;
void solve(){
	cin>>n;
	int ax[n],ay[n];
	for(int i=0;i<n;i++){
		cin>>ax[i]>>ay[i];
		ax[i]*=p;ax[i]+=i;
		ay[i]*=p;ay[i]+=i;
	}
	sort(ax,ax+n);sort(ay,ay+n);
	set<int> s;
	s.insert((ax[n-1]%p+p)%p);
	s.insert((ax[0]%p+p)%p);
	s.insert((ay[n-1]%p+p)%p);
	s.insert((ay[0]%p+p)%p);
	for(int i=0;i<n;i++){
	    if(ax[i]<0)ax[i]-=p;
	    if(ay[i]<0)ay[i]-=p;
	}
	if(s.size()==2){
		int ans=ax[n-1]/p-ax[1]/p;
		ans=max(ans,ax[n-2]/p-ax[0]/p);
		ans=max(ans,ay[n-1]/p-ay[1]/p);
		ans=max(ans,ay[n-2]/p-ay[0]/p);
		cout<<ans<<'\n';
		return;
	}
	vector<int> v;
	v.pb(ax[n-1]/p-ax[0]/p);
	v.pb(ay[n-1]/p-ay[0]/p);
	v.pb(ax[n-2]/p-ax[0]/p);
	v.pb(ax[n-1]/p-ax[1]/p);
	v.pb(ay[n-1]/p-ay[1]/p);
	v.pb(ay[n-2]/p-ay[0]/p);
	sort(v.begin(),v.end());
	cout<<v[4]<<'\n';
	}

signed main(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    //cin>>tt;
    //while(tt--)
    solve();
}

/*pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; i++)
#define RFOR(i, a, n) for (ll i = (ll)n - 1; i >= (ll)a; i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define bra(first, second) '(' << first << ',' << second << ')'
constexpr ll MOD = 1000000007;
//constexpr ll MOD = 998244353;
ll INF = 1001001001001001001;
long double EPS = 1e-7;
long double PI = 3.141592653589793238;
template <typename T>
void remove(std::vector<T> &vector, unsigned int index)
{
   vector.erase(vector.begin() + index);
}

using Graph = vector<vector<pair<ll,ll>>>;

// MOD確認

ll N,M;
ll A[200010];

int main(){
   cin >> N >> M;
   rep(i,M) cin >> A[i+1];
   A[0] = 0;
   A[M+1] = N+1;
   sort(A,A+M+2);
   ll m = INF;
   if(M == 0){
      cout << 1 << endl;
      return 0;
   }
   rep(i,M+1){
      if(A[i+1] != A[i]+1) m = min(m,A[i+1]-A[i]-1);
   }
   ll ans = 0;
   /*if(m == 1){
      cout << N - M << endl;
      return 0;
   }*/
   rep(i,M+1){
      if(A[i+1] != A[i]+1) ans += (A[i+1] - A[i] + m - 2) / m;
   }
   cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
  ll a,b,c,d;
  cin >> a >> b >> c >> d;
  ll ans=0;
  if(b>=c*d){cout << -1 <<endl;return 0;}
  ll e=0;
  while(a>e*d){
    a+=b;
    e+=c;
    ans++;
  }
  cout << ans;
}

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

int main()
{
	for( int i = 0; i < 1000; i++ ) {
		int si, sj, ti, tj;
		cin >> si >> sj >> ti >> tj;
		string ans;
		if( si < ti ) {
			ans += string( ti - si, 'D' );
		}
		else if( si > ti ) {
			ans += string( si - ti, 'U' );
		}
		if( sj < tj ) {
			ans += string( tj - sj, 'R' );
		}
		else if( sj > tj ) {
			ans += string( sj - tj, 'L' );
		}
		cout << ans << endl;
		int d;
		cin >> d;
	}
}


#include<bits/stdc++.h>
#include<unordered_map>
#include<unordered_set>
#include<iomanip>
#define IOS 	cin.tie(0), ios::sync_with_stdio(false)
#define x first
#define y second

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int N = 2e5 + 10, M = N * 2, mod = 1e9 + 7;
const double eps = 1e-4;
const double pi = acos(-1);
const int P = 131;

int h[N], e[M], ne[M], idx;
int res[N], f[N], son[N];
int n, maxd, d, cnt;

void add(int a, int b)
{
	e[idx] = b;
	ne[idx] = h[a];
	h[a] = idx ++;
}

void dfs1(int u, int fa, int dis)
{
	f[u] = fa;
	if(dis >= maxd)
	{
		d = u;
		maxd = dis;
	}

	for(int i = h[u] ; ~i ; i = ne[i])
	{
		int j = e[i];
		if(j == fa) continue;
		dfs1(j, u, dis + 1);
	}
}

void dfs(int u, int fa)
{
	res[u] = ++ cnt;
	for(int i = h[u] ; ~i ; i = ne[i])
	{
		int j = e[i];
		if(j == fa || j == son[u]) continue;
		dfs(j, u);
	}
	if(son[u])
		dfs(son[u], u);
	cnt ++;
}

int main()
{
	IOS;
	cin >> n;
	memset(h, -1, sizeof h);
	for(int i = 1 ; i < n ; i ++)
	{
		int a, b;
		cin >> a >> b;
		add(a, b);
		add(b, a);
	}
	dfs1(1, 0, 0);	//找到能从1遍历到的最远的点 d
	int s = d; 		//记录下直径的一个端点
	dfs1(s, 0, 0);	//找到树的直径
	for(int i = d ; i ; i = f[i])	//标记直径上所有的点
		son[f[i]] = i;
	dfs(s, 0);

	for(int i = 1 ; i <= n ; i ++)
		cout << res[i] << " ";

	return 0;
}

// Arti1990, II UWr

#include <bits/stdc++.h>

#define forr(i, n)                  for(int i=0; i<n; i++)
#define FOREACH(iter, coll)         for(auto iter = coll.begin(); iter != coll.end(); ++iter)
#define FOREACHR(iter, coll)        for(auto iter = coll.rbegin(); iter != coll.rend(); ++iter)
#define lbound(P,R,PRED)            ({typeof(P) X=P,RRR=(R), PPP = P; while(PPP<RRR) {X = (PPP+(RRR-PPP)/2); if(PRED) RRR = X; else PPP = X+1;} PPP;})
#define testy()                     int _tests; scanf("%d", &_tests); FOR(_test, 1, _tests)
#define CLEAR(tab)                  memset(tab, 0, sizeof(tab))
#define CONTAIN(el, coll)           (coll.find(el) != coll.end())
#define FOR(i, a, b)                for(int i=a; i<=b; i++)
#define FORD(i, a, b)               for(int i=a; i>=b; i--)
#define MP                          make_pair
#define PB                          push_back
#define ff                          first
#define ss                          second
#define deb(X)                      X;

#define M 1000000007
#define INF 1000000007LL

using namespace std;

int n, a, b, id;

struct wierzch
{
    int d;
    int id;
    int syn;
    vector <int> l;
};
wierzch tab[1000007];

int najdalszy(int nr, int o)
{
//    cout << "najdalszy w " << nr << endl;
    int best = nr;
    tab[nr].syn = nr;

    for(auto el : tab[nr].l)
    {
        if(el != o)
        {
            tab[el].d = tab[nr].d+1;
            int r = najdalszy(el, nr);
            if(tab[r].d > tab[best].d)
            {
                best = r;
                tab[nr].syn = el;
            }
        }
    }
//    cout << "best: " << best << endl;
    return best;
}

void dfs(int nr, int o)
{
    id++;
    tab[nr].id = id;

    for(auto el : tab[nr].l)
    {
        if(el != o && el != tab[nr].syn)
        {
            dfs(el, nr);
        }
    }
    if(tab[nr].syn != nr)
        dfs(tab[nr].syn, nr);
    id++;
}

int solve()
{
    scanf("%d", &n);
    forr(i, n-1)
    {
        scanf("%d %d", &a, &b);
        tab[a].l.PB(b);
        tab[b].l.PB(a);
    }

    int u = najdalszy(1, 1);
    int v = najdalszy(u, u);

    id = 0;
    dfs(u, u);

    FOR(i, 1, n)
        printf("%d ", tab[i].id);
    printf("\n");

    return 0;
}

int main()
{
    solve();

    return 0;
}


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

int main(){
    string S, numero;
    unordered_map<char,int> frequencia;
    int fator, tamanho, r;
    cin>>S;
    tamanho = S.size();
    if(tamanho==1){
        if(S[0]=='8'){
            printf("Yes");
        }
        else{
            printf("No");
        }
        return 0;
    }
    for(int i=0; i<tamanho; i++){
        frequencia[S[i]]++;
    }
    if(tamanho==2){
        numero.resize(2);
        for(int i=16; i<100; i+=8){
            fator=i;
            for(int j=1; j>-1; j--){
                numero[j] = ((char)(fator%10)+48);
                fator/=10;
            }
            //cout<<numero<<endl;
            for(int j=1; j>-1; j--){
                frequencia[numero[j]]--;
            }
            r=0;
            for(int j=1; j>-1; j--){
                if(frequencia[numero[j]]>=0){
                    r++;
                }
            }
            if(r==2){
                printf("Yes");
                return 0;
            }
            else{
                for(int j=1; j>-1; j--){
                    frequencia[numero[j]]++;
                }
            }
        }
        printf("No");
        return 0;
    }
    numero.resize(3);
    for(int i=104; i<1000; i+=8){
        fator=i;
        for(int j=2; j>-1; j--){
            numero[j] = ((char)(fator%10)+48);
            fator/=10;
        }
        //cout<<numero<<endl;
        for(int j=2; j>-1; j--){
            frequencia[numero[j]]--;
        }
        r=0;
        for(int j=2; j>-1; j--){
            if(frequencia[numero[j]]>=0){
                r++;
            }
        }
        if(r==3){
            printf("Yes");
            return 0;
        }
        else{
            for(int j=2; j>-1; j--){
                frequencia[numero[j]]++;
            }
        }
    }
    printf("No");
    return 0;
}

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

int main() {
    string S; cin >> S;
    if (S.size() == 1) {
        if (S == "8" || S == "0") cout << "Yes" << endl;
        else cout << "No" << endl;
        return 0;
    }
    if (S.size() == 2) {
        ll a = (S[0] - 48)*10 + S[1] - 48;
        ll b = (S[1] - 48)*10 + S[0] - 48;
        if (a % 8 == 0 || b % 8 == 0) cout << "Yes" << endl;
        else cout << "No" << endl;
        return 0;
    }

    vector<ll> cnt(10, 0);
    for (int i : S) {
        if (cnt[i - 48] < 3) ++cnt[i - 48];
    }
    bool flg = (S.size() == 3);

    for (ll i = (flg); i < 10; i++) {
        if (cnt[i] == 0) continue;
        --cnt[i];
        for (ll j = 0; j < 10; j++) {
            if (cnt[j] == 0) continue;
            --cnt[j];
            for (ll k = 0; k < 10; k++) {
                if (cnt[k] == 0) continue;
                ll num = 100*i + 10*j + k;
                if (num % 8 == 0) {
                    cout << "Yes" << endl;
                    return 0;
                }
            }
            ++cnt[j];
        }
        ++cnt[i];
    }
    cout << "No" << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define endl ("\n")
#define pi (3.141592653589)
#define mod 1e9+7
#define int long long
#define float double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(c) c.begin(), c.end()
#define min3(a, b, c) min(c, min(a, b))
#define min4(a, b, c, d) min(d, min(c, min(a, b)))
#define rrep(i, n) for(int i=n-1;i>=0;i--)
#define rep(i,n) for(int i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);

int32_t main(){
    fast
    int t=1;
    // cin>>t;
    while(t--){
        int a, b, c;cin>>a>>b>>c;
        if(c==0){
            while(true){
                if(a==0){cout<<"Aoki"<<endl;break;}
                else a--;
                if(b==0){cout<<"Takahashi"<<endl;break;}
                else b--;
            }
        }
        else{
            while(true){

                if(b==0){cout<<"Takahashi"<<endl;break;}
                else b--;
                if(a==0){cout<<"Aoki"<<endl;break;}
                else a--;
            }
        }
    }
    return 0;
}

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

int main() {
  int N;
  int m = 0;
  cin >> N;
  vector<tuple<int, int, int>> av(N);
  int a, p, x;
  priority_queue<int, vector<int>, greater<int>> bv;
  for(int i = 0; i < N; i++) {
    cin >> a >> p >> x;
    av.at(i) = make_tuple(x, p, a); }
  for(int i = 0; i < N; i++) {
     if(get<0>(av.at(i)) > get<2>(av.at(i)))
       bv.push(get<1>(av.at(i)));
     else
       m++; }
  if(m == N)
    cout << -1 << endl;
  else
    cout << bv.top() << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);   cin.tie(NULL); cout.tie(NULL);
#define endl "\n";
#define mod 1000000007
#define loop(i,s,n)  for(ll i=s;i<n;i++)
#define test  ll t; cin>>t; while(t--)
#define p push_back
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
typedef long long ll;
int main()
{int n,i,j,k,count=0,sum=1,f=0;
int a,b,c;
cin>>a>>b;

k=(a*(a+1))/2;
count+=(k*100)*b;
n=b*(b+1);
n=n/2;
count+=(n*a);
cout<<count;

  return 0;
}

#include<bits/stdc++.h>
#define ll long long int
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod 1000000007
#define N 100100
using namespace std;

ll power(ll x,ll y)
{
    ll res = 1;
    while(y)
    {
        if(y&1) res = (res*x)%mod;
        y=y/2;
        x=(x*x)%mod;
    }
    return res;
}

signed main()
{

    IOS;

    // ll t;
    // cin>>t;

    // while(t--)
    // {
    // }

    ll n,k;
    cin>>n>>k;

    cout<<((100*k*n*(n+1))/2)+((n*k*(k+1))/2)<<endl;

}


#include<bits/stdc++.h>
#define N 105
#define M 100005
using namespace std;
int n,t[N],m,f[M]={1};
int main(){
	cin>>n;
	for(int i=1;i<=n;i++)cin>>t[i],m+=t[i];
	for(int i=1;i<=n;i++)
		for(int j=m;j>=t[i];j--)f[j]|=f[j-t[i]];
	for(int i=(m+1)/2;i<=m;i++)
		if(f[i])cout<<i<<endl,exit(0);
	return 0;
}

/*  CREATED BY
    STREAM_CIPHER
    dec-2020
*/
#include<bits/stdc++.h>
using namespace std;
void __print(long long x) {cerr << x;}void __print(unsigned long long x) {cerr << x;}void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define int long long int
#define double long double
#define fix_precision(n) cout<<fixed<<setprecision(n)
#define all(a) a.begin(),a.end()
const double pi=acos(-1.0);
int inf=0x3f3f3f3f3f3f3f3f;
const int mod=1e9+7;
// const int mod=998244353;
const int mx=5*1000000;//5*64M bit ->5*8M byte ->40MB size for long long int (64 bit)
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        // freopen("output.txt","w",stdout);
    #endif
        int n;
        cin>>n;
        vector<int>a(n);
        for(auto &i:a)
        	cin>>i;
        int ans=0;
        sort(all(a));
        for(int i=n-1;i>=0;i--)
        	ans+=i*a[i]-(n-1-i)*a[i];
        cout<<ans<<endl;
}
//always use s.lower_bound instead of lower_bound(all(s))
//also whenever there exist an standerd method for stl container prefer that
//otherwise this will happen
//https://codeforces.com/contest/1435/submission/96683823//tle
//https://codeforces.com/contest/1435/submission/96703923//accepted


/*One cannot escape the feeling ... that these mathematical formulae have
an independent existence and an intelligence of their own ... that they
are wiser than we are, wiser even than their discoverers ... that we get
more out of them that was originally put into them.
*/

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

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define ll long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i,n) for(i=0;i<n;i++)
#define forn(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i)
#define ford(i, n) for (ll i = (ll)(n) - 1; id good if no two adjacent cells contain the same value, where two cells are called adjacent if they share a side. >= 0; --i)
#define fore(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); ++i)
#define fora(it,x) for(auto it:x)
#define PI 3.14159265
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl "\n"

typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef long double ld;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

ll a[52],dp[52],span[52],g[52],possible[52],fact[52];
int main(){
    ll n,x;
    cin>>n>>x;

    forn(i,n) cin>>a[i];
    forn(i,n-1){
        fact[i]=(a[i+1]/a[i])-1;
    }
    fact[n-1]=1e18;
    for(ll i=n-1;i>=0;i--){
        g[i]=x/a[i];
        x%=a[i];
    }
    for(ll i=0;i<n;i++){
        ll c=0;
        for(ll j=i+1;j<n;j++){
            if(g[j]==fact[j]) c++;
            else break;
        }
        span[i]=c;
    }
    possible[n-1]=1;
    dp[n-1]=1;
    for(ll i=n-2;i>=0;i--){
        dp[i]=0;
        ll c=0;
        if(g[i]) c+=possible[i+span[i]+1];
        dp[i]+=dp[i+1];
        dp[i]+=c;
        if(g[i]) possible[i]=dp[i];
        else possible[i]=dp[i+1]+possible[i+1+span[i]];
    }
    cout<<dp[0];
}

// -----------------------------------
// author   : MatsuTaku
// country  : Japan
// created  : 11/08/20 20:48:16
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  int n; cin>>n;
  ll x; cin>>x;
  vector<ll> A(n); for (auto& a:A) cin>>a;
  vector<ll> pa(n);
  for (int i = 0; i < n-1; i++)
    pa[i] = A[i+1]/A[i];
  pa[n-1] = 1e18;

  vector<map<ll, ll>> dp(n+1);
  dp[n][x] = 1;
  for (int i = n-1; i >= 0; i--) {
    for (auto [d, p] : dp[i+1]) {
      auto md = d%A[i];
      ll dist = abs(d/A[i]);
      if (dist < pa[i])
        dp[i][md] += p;
      if (md != 0) {
        if (md > 0) {
          md -= A[i];
          dist += d > 0 ? 1 : -1;
        } else {
          md += A[i];
          dist += d > 0 ? -1 : 1;
        }
        if (dist < pa[i])
          dp[i][md] += p;
      }
    }
  }
  cout << dp[0][0] << endl;

  return 0;
}


#include<bits/stdc++.h>
#define L(i, j, k) for(int i = j, i##E = k; i <= i##E; i++)
#define R(i, j, k) for(int i = j, i##E = k; i >= i##E; i--)
#define ll long long
#define ull unsigned long long
#define db double
#define pii pair<int, int>
#define mkp make_pair
#define push_back psb
using namespace std;
void Min(int &x, int y) { if(x > y) x = y; }
void Max(int &x, int y) { if(x < y) x = y; }
const int N = 1e6 + 7;
int n, m, c[N], a[N], b[N];
int head[N], edge_id;
struct edge {
	int to, id, next;
	int ans;
} e[N << 1];
void add_edge(int u, int v, int id) {
	++edge_id, e[edge_id].next = head[u], e[edge_id].id = id, e[edge_id].to = v, head[u] = edge_id;
}
int ans[N], dfn[N], idtot;
void dfs(int x, int fa) {
	dfn[x] = ++idtot;
	for(int i = head[x]; i; i = e[i].next) {
		int v = e[i].to;
		if(v == fa) continue;
		if(dfn[v]) {
			if(dfn[x] > dfn[v]) e[i].ans = 1;
			continue;
		}
		e[i].ans = 1, dfs(v, x);
	}
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	cin >> n >> m;
	L(i, 1, m) cin >> a[i] >> b[i];
	L(i, 1, n) cin >> c[i];
	L(i, 1, m) if(c[a[i]] == c[b[i]]) add_edge(a[i], b[i], i), add_edge(b[i], a[i], -i);
	L(i, 1, n) if(!dfn[i]) dfs(i, -1);
	L(i, 1, edge_id) if(e[i].ans) {
		if(e[i].id > 0) ans[e[i].id] = 1;
		else ans[-e[i].id] = 0;
	}
	L(i, 1, m) {
		if(c[a[i]] > c[b[i]]) cout << "->\n";
		else if(c[a[i]] < c[b[i]]) cout << "<-\n";
		else {
			if(!ans[i]) cout << "->\n";
			else cout << "<-\n";
		}
	}
	return 0;
}

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

// using mint = long double;
// using mint = modint998244353;
// using mint = modint1000000007;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<P, ll> T;
typedef pair<ll, vector<ll> > Pd;

const ll INF = 1e18;
const ll fact_table = 32008;

priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
// priority_queue <ll, vector<ll>, greater<ll> > pqls;
priority_queue <P, vector<P>, greater<P> > pqps;
//small priority queue
//top pop

ll dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
ll dy[8] = {0, 1, 0, -1, -1, 1, 1, -1};
//↓,→,↑,←

/*
#define endl "\n"
#ifdef ENJAPMA
#undef endl
#endif
*/

#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<(x);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pc(x) cout << x << ",";
#define rep(i, n) for (ll i = 0; i < (n); i ++)
#define rep2(i, a, b) for (ll i = a; i <= (b); i++)
#define rep3(i, a, b) for (ll i = a; i >= (b); i--)
#define all(c) begin(c), end(c)

typedef vector<ll> vec;
typedef vector<vector<ll>> mat;

// vec v(n) -> 長さnのベクトルを宣言
// mat dp(h, vec(w)) -> h * w の行列を宣言

const ll mod = 998244353ll;
// const ll mod = 1000000007ll;

ll mypow(ll a, ll b, ll m = mod) {ll x = 1; while (b) {while (!(b & 1)) {(a *= a) %= m; b >>= 1;}(x *= a) %= m; b--;} return x;}
vec rv(ll read) { vec res(read); for (int i = 0; i < read; i++) { cin >> res[i]; } return res;}
void YES(bool cond) { if (cond) { p("YES");} else { p("NO");} return;}
void Yes(bool cond) { if (cond) { p("Yes");} else { p("No");} return;}
void line() { p("--------------------"); return;}

/*
ll fact[fact_table + 5], rfact[fact_table + 5];

void c3_init() {
    fact[0] = rfact[0] = 1;
    for (ll i = 1; i <= fact_table; i++) {
        fact[i] = (fact[i - 1] * i) % mod;
    }
    rfact[fact_table] = mypow(fact[fact_table], mod - 2, mod);
    for (ll i = fact_table; i >= 1; i--) {
        rfact[i - 1] = rfact[i] * i;
        rfact[i - 1] %= mod;
    }
    return;
}
ll c3(ll n, ll r) {
    return (((fact[n] * rfact[r]) % mod ) * rfact[n - r]) % mod;
}
*/

bool icpc = false;
bool multicase = false;

ll n, m;

bool solve() {
    ll a, b, c;
    cin >> a >> b >> c;
    assert(1 <= a);
    assert(1 <= b);
    assert(1 <= c);
    a %= 10;
    ll r = mypow(b, c, 8ll);
    r += 4;
    ll re = 1;
    if (a == 0) {
        p(0);
        return true;
    }
    for (int i = 0; i < r; i++) {
        re *= a;
        re %= 10;
    }
    p(re % 10);
    return true;
}

int main() {

    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    if (icpc) {
        while (solve());
        return 0;
    }
    ll q, testcase = 1;
    if (multicase) {
        cin >> q;
    } else {
        q = 1;
    }
    while (q--) {
        // pu("Case ");pu("#");pu(testcase);pu(": ");
        solve();
        testcase++;
    }

// solve();
    return 0;
}


#include <iostream>
#include <vector>
#include <stdio.h>
#include <climits>

using namespace std;
typedef long long ll;
ll ans = 0;

int countway(int i, int j, vector<vector<bool>> tMb, vector<vector<int>> T,int N) {
	//(i,j)のまわりのマップtMbのfalseのマス目を返す
	int ans = 0;
	if (i - 1 > -1 && !tMb.at(i - 1).at(j)&& T.at(i).at(j)!=T.at(i-1).at(j)) {
		ans++;
	}
	if (i + 1 < N && !tMb.at(i + 1).at(j) && T.at(i).at(j) != T.at(i + 1).at(j)) {
		ans++;
	}
	if (j - 1 > -1 && !tMb.at(i).at(j - 1) && T.at(i).at(j) != T.at(i).at(j - 1)) {
		ans++;
	}
	if (j + 1 < N && !tMb.at(i).at(j + 1) && T.at(i).at(j) != T.at(i).at(j + 1)) {
		ans++;
	}
	return ans;
}

void solve(int i, int j, vector<vector<int>> T, vector<vector<int>> P, vector<vector<bool>> tMb) {
	//今いる点(i,j) マップ全体のタイルの様子T マップ全体の得点の様子P いけるタイルの管理tMb

	tMb.at(i).at(j) = true;
	if (i - 1 > -1 && T.at(i).at(j) == T.at(i - 1).at(j)) {
		tMb.at(i - 1).at(j) = true;
	}
	if (i + 1 < 50 && T.at(i).at(j) == T.at(i + 1).at(j)) {
		tMb.at(i + 1).at(j) = true;
	}
	if (j - 1 > -1 && T.at(i).at(j) == T.at(i).at(j - 1)) {
		tMb.at(i).at(j - 1) = true;
	}
	if (j + 1 < 50 && T.at(i).at(j) == T.at(i).at(j + 1)) {
		tMb.at(i).at(j + 1) = true;
	}
	ans += P.at(i).at(j);

	int next = -1;
	int maxfalse = -1;

	if (j - 1 > -1 && !tMb.at(i).at(j - 1) && (maxfalse < countway(i, j - 1, tMb,T, 50))) {
		maxfalse = countway(i, j-1, tMb, T, 50);
		next = 1;
	}
	if (j + 1 < 50 && !tMb.at(i).at(j + 1) && maxfalse < countway(i, j + 1, tMb, T, 50)) {
		maxfalse = countway(i, j + 1, tMb, T, 50);
		next = 3;
	}
	if (i - 1 > -1 && !tMb.at(i - 1).at(j) && maxfalse < countway(i - 1, j, tMb, T, 50)) {
		maxfalse = countway(i - 1, j, tMb, T, 50);
		next = 2;
	}
	if (i + 1 < 50 && !tMb.at(i + 1).at(j) && maxfalse < countway(i + 1, j, tMb, T, 50)) {
		maxfalse = countway(i + 1, j, tMb, T, 50);
		next = 4;
	}

	if (next == 1) {
		cout << "L";
		solve(i, j - 1, T, P, tMb);
	}
	else if (next == 2) {
		cout << "U";
		solve(i - 1, j, T, P, tMb);
	}
	else if (next == 3) {
		cout << "R";
		solve(i, j + 1, T, P, tMb);
	}
	else if (next == 4) {
		cout << "D";
		solve(i + 1, j, T, P, tMb);
	}
	else {
		return;
	}

}

int main() {
	int si, sj;
	cin >> si >> sj;
	vector<vector<int>> T(50, vector<int>(50));
	vector<vector<int>> P(50, vector<int>(50));

	for (int i = 0; i < 50; i++) {
		for (int j = 0; j < 50; j++) {
			cin >> T.at(i).at(j);
		}
	}

	/*vector<vector<int>> Graph(50,vector<int>(50));

	for (int i = 0; i < 50; i++) {
		for (int j = 0; j < 50; j++) {
			if (i > 0) {
				if (T.at(i).at(j) != T.at(i - 1).at(j)) Graph.at(T.at(i).at(j)).push_back(T.at(i - 1).at(j));
			}
			if (i < 49) {
				if (T.at(i).at(j) != T.at(i + 1).at(j)) Graph.at(T.at(i).at(j)).push_back(T.at(i + 1).at(j));
			}
			if (j > 0) {
				if (T.at(i).at(j) != T.at(i).at(j - 1))Graph.at(T.at(i).at(j)).push_back(T.at(i).at(j - 1));
			}
			if (j < 49) {
				if (T.at(i).at(j) != T.at(i).at(j + 1))Graph.at(T.at(i).at(j)).push_back(T.at(i).at(j + 1));
			}
		}
	}*/

	for (int i = 0; i < 50; i++) {
		for (int j = 0; j < 50; j++) {
			cin >> P.at(i).at(j);
		}
	}

	vector<vector<bool>> tMb(50, vector<bool>(50, false));

	solve(si, sj, T, P, tMb);
}

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

int mex(const vector<int> &a, const int i, const int m){
    for(int ret=0; ret<100; ++ret){
        bool has_value = false;
        for(int j=i; j<i+m; ++j){
            if(a[j] == ret){
                has_value = true;
                break;
            }
        }
        if(!has_value){
            return ret;
        }
    }
    return -1;
}

int solve_naive(const vector<int> &a, const int m){
    int ret=1e9;
    for(int i=0; i<int(a.size() - m); ++i){
        ret = min(ret, mex(a, i, m));
    }
    return ret;
}

int solve(const vector<int> &a, const int m){
    // pos[k] = （最後に a[i] = k となった i ）
    vector<int> pos(a.size(), -1);
    // cnt[k] = （a[i] = k なる i のインターバルの最大値）
    vector<int> cnt(a.size(), 0);
    for(int i=0; i<int(a.size()); ++i){
        cnt[a[i]] = max(cnt[a[i]], i - pos[a[i]]);
        pos[a[i]] = i;
    }
    for(int i=0; i<int(a.size()); ++i){
        if(pos[i] >= 0){
            cnt[i] = max(cnt[i], int(a.size()) - pos[i]);
        }else{
            cnt[i] = 1e9;
        }
    }
    for(size_t i=0; i<a.size(); ++i){
        if(cnt[i] > m){
            return i;
        }
    }
    return a.size();
}

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    for(int i=0; i<n; ++i) cin >> a[i];
    cout << solve(a, m) << endl;
    //cerr << solve_naive(a, m) << endl;
    return 0;
}


#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl
#define maxn 3e5+50

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<long long ,long long>pll;

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

const ll mod = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;
const ld pi = 3.141592653589793;

 long long modpow(long long n, long long k,long long mod)
{
if (k == 0) return 1;
long long r = modpow(n * n % mod, k >> 1, mod);
if (k & 1) r = r * n % mod;
return r;
}

vector<vector<int>>adj;
vector<int>depth(maxn,0);
vector<ll>c(maxn,0);
void dfs(int v,int prev){
   for(auto i:adj[v]){
      if(i!=prev){
         depth[i] = depth[v]+1;
         c[i] += c[v];
         dfs(i,v);
      }
   }
}
void solve(){
     int n;cin >> n;
     vector<ll>a(n-1),b(n-1);
     adj.resize(n+1);
     for(int i = 0;i<n-1;i++){
        cin >> a[i] >> b[i];
        adj[a[i]].push_back(b[i]);
        adj[b[i]].push_back(a[i]);
     }
     dfs(1,0);
     int q;cin >> q;
     while(q--){
        ll t,e,x;cin >> t >> e >> x;e--;
        if(t==1){
            if(depth[a[e]]<depth[b[e]]){
                c[1] += x;
                c[b[e]] -= x;
            }
            else{
                c[a[e]]+=x;
            }
        }
        else{
            if(depth[b[e]]<depth[a[e]]){
                c[1] += x;
                c[a[e]] -= x;
            }
            else{
                c[b[e]] += x;
            }
        }
     }
     dfs(1,0);
     for(int i = 1;i<=n;i++) cout << c[i] <<'\n';
}

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

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define replr(i, l, r) for (int i = (l); i < (r); ++i)
const int mod = 1e9 + 7;
vector<int> T[202020];
ll ans[202020], C[202020];
void rec(int x, ll c, int par) {
    c += C[x];
    for (int to : T[x]) {
        if (to == par)
            continue;
        rec(to, c, x);
    }
    ans[x] = c;
}

int main() {
    int n, q;
    cin >> n;
    vector<int> A(n), B(n), X(n);
    rep(i, n - 1) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        A[i] = a;
        B[i] = b;
        T[a].push_back(b);
        T[b].push_back(a);
    }
    queue<P> Q;
    Q.push({1, 0});
    while (!Q.empty()) {
        P p = Q.front();
        Q.pop();
        if (X[p.second] > 0)
            continue;
        X[p.second] = p.first;
        for (int to : T[p.second])
            Q.push({p.first + 1, to});
    }

    cin >> q;
    rep(i, q) {
        ll t, e, x;
        cin >> t >> e >> x;
        e--;
        int a = A[e], b = B[e];
        if (X[a] > X[b]) {
            if (t == 1)
                C[a] += x;
            else {
                C[0] += x;
                C[a] -= x;
            }
        } else {
            if (t == 1) {
                C[0] += x;
                C[b] -= x;
            } else
                C[b] += x;
        }
    }
    rec(0, 0, -1);
    rep(i, n) cout << ans[i] << endl;
    return 0;
}


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

#include <bits/stdc++.h>
using namespace std;
#define fr(i,a,b) for(int i=a;i<b;i++)
#define pb push_back
#define speed   ios::sync_with_stdio(false), cin.tie(0) , cout.tie(0)
#define fillm(m,r,c,k) fr(i,0,r)fr(j,0,c)m[i][j]=k;
#define prm(m,r,c) fr(i,0,r){fr(j,0,c){cout<<m[i][j]<<" "; }cout<<endl;}
#define pr(a,n)fr(i,0,n)cout<<a[i]<<",";cout<<endl;
#define endl '\n'
#define MOD 1000000007
#define INF 1000000000
#define prv(v) for(auto x: v)cout<<x<<" ";cout<<endl;
#define MAX 400005
#define all(x) x.begin(),x.end()
#define mkp make_pair
#define ll long long
#define f first
#define s second
int main(){
    speed;
    int n;
    cin>>n;
    queue<pair<int,int> > q;
    fr(i,1,(1<<n)+1){
        int x;cin>>x;
        q.push({x,i});
    }
    for(int i  = 1 ; i <= n - 1 ; i++){
        queue<pair<int,int> > temp;
        while(q.size() > 0){
             pair<int,int> x = q.front();
             q.pop();
             pair<int,int> y = q.front();
             q.pop();
             if(x.f  > y.f)
                temp.push(x);
             else
                temp.push(y);
        }
        swap(temp,q);
    }
    pair<int,int> x = q.front();
             q.pop();
             pair<int,int> y = q.front();
             q.pop();
    if(x.f < y.f){
        cout<<x.s<<endl;
    }
    else{
        cout<<y.s<<endl;
    }
    return 0;

}


// #define ONLINE_JUDGE
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifndef ONLINE_JUDGE
#   define dbg(x) cerr << '#' << #x << '	' << x << endl
#   define TIME cerr << "RuningTime: " << clock() << "ms\n", 0
#else
#   define dbg(x)
#   define TIME 0
#endif
#define mem(a,b) memset(a,b,sizeof(a))
#define endl '\n'
const int maxn = 5e3 + 10;
const int mod = 998244353;

int n, m;
ll fac[maxn], inv[maxn];
ll f[maxn], g[maxn];

ll qpow(ll a, ll b){
    ll res = 1;
    while(b){
        if(b & 1) res = res * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return res;
}

void init(){
    fac[0] = 1;
    for(int i = 1; i <= n; i++){
        fac[i] = fac[i-1] * i % mod;
    }
    inv[n] = qpow(fac[n], mod - 2);
    for(int i = n - 1; i >= 0; i--){
        inv[i] = inv[i + 1] * (i + 1) % mod;
    }
}

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

int main()
{
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
#endif
    ios::sync_with_stdio(0),cin.tie(0);
    cin >> n >> m;
    init();
    f[0] = 1;
    for(int i = 0; i <= 12; i++){
        mem(g, 0);
        for(int j = 0; j <= m; j++){
            for(int k = 0; k <= n; k++){
                int tmp = j + (1 << i) * k * 2;
                if(tmp > m) break;
                g[tmp] += f[j] * C(n, k * 2) % mod;
                g[tmp] %= mod;
            }
        }
        for(int j = 0; j <= m; j++){
            f[j] = g[j];
        }
    }
    cout << f[m];
}

#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector")
#include <bits/stdc++.h>
#include<set>
#include <array>
using namespace std;
#define ll long long
#define endl '\n'
#define mod 998244353
#define pb push_back
#define ff first
#define ss second
#define con continue
#define ub upper_bound
#define lb lower_bound

#define si(x) int(x.size())
#define sum_all(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())
const double pi = 2 * acos(0.0);
const int dx[] = { -1, 0, 1, 0 };
const int dy[] = { 0, -1, 0, 1 };

const int dx8[] = { -1, 0, 1, 0,1,1,-1,-1 };
const int dy8[] = { 0, -1, 0, 1,1,-1,1,-1 };

ll min(ll a, ll b)
{
    if (a < b)return a;
    return b;
}
ll max(ll a, ll b)
{
    if (a > b)return a;
    return b;
}
ll ceil1(ll a, ll b)
{
    return(a + b - 1) / b;
}
void read(vector<ll>& arr)
{
    for (ll i = 0; i < si(arr); i++)
        cin >> arr[i];

}

void read_graph(vector<vector<ll>>& g, ll m)
{
    while (m--)
    {
        ll x, y; cin >> x >> y;
        x--, y--;
        g[x].pb(y);
        g[y].pb(x);
    }
}

vector<vector<ll>> c;

ll ncr(ll n, ll r)
{
    if (n == r) return 1;
    if (r<0 or r > n) return 0;
    return c[n][r];
}
void pre(ll lim = 5003)
{
    c = vector<vector<ll>>(lim + 1, vector<ll>(lim + 1));
    c[0][0] = 1;
    for(ll i=1;i<=lim;i++)
        for (ll j = 0; j <= lim; j++)
        {
            c[i][j] = ncr(i-1,j) + ncr(i-1,j-1);
            c[i][j] %= mod;
        }
}

void solve()
{
    ll n, m;
    cin >> n >> m;
    int lim = 5001;
    pre();

    if (m % 2 == 1)
    {
        cout << 0 << endl;
        return;
    }

    vector<vector<ll>> dp(32, vector<ll>(n + 13));
    // base case
    for (int i = 0; i <= n; i += 2)
    {
        dp[0][i / 2] = ncr(n, i);
    }

    //cout << ncr(n, 2) << endl;
    for (int i = 1; i < 13; i++)
    {

            for (int k = 0; k <= n; k += 2)
            {
                if ((m & (1ll << i)) > 0)
                {
                    for (int j = 1; j <= n; j+=2)
                    {

                        ll x = (j + k) / 2;
                        dp[i][x] += (dp[i - 1][j] * ncr(n, k))%mod;
                        dp[i][x] %= mod;
                    }
                }
                else
                {
                    for (int j = 0; j <= n; j+=2)
                    {

                        ll x = (j + k) / 2;
                        dp[i][x] += (dp[i - 1][j] * ncr(n, k))%mod;
                        dp[i][x] %= mod;
                    }
                }
            }

    }

    cout << dp[12][0] << endl;

}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    //int t; cin >> t; while (t--)
    solve();

}


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

typedef long long LL;
typedef pair<int, int> P;

const int maxn = 500 + 10;
const int M_MAX = 10 * maxn * maxn;
const int mod = 1e9 + 7;
const LL INF = 0x3f3f3f3f;
const double eps = 1e-6;

struct edge {
    int to, cost, next;
}e[5000010];

int n, m;
int h[1000010], d[1000010], len = 1;

int p(int x, int y) { return (x - 1) * m + y; }

void addedge(int v, int u, int cost) {
    e[len].to = u;
    e[len].cost = cost;
    e[len].next = h[v];
    h[v] = len++;
}

void solve() {
    cin >> n >> m;
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j < m; j++) {
            int c; cin >> c;
            addedge(p(i, j) , p(i, j + 1), c);
            addedge(p(i,j+1), p(i, j), c);
        }
    }
    for(int i = 1; i < n; i++) {
        for(int j = 1; j <= m; j++) {
            int c; cin >> c;
            addedge(p(i, j), p(i+1, j), c);
        }
    }
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++) {
            addedge(p(i, j), p(i, j) + n*m, 1);
            addedge(p(i,j) + n*m, p(i,j), 0);
        }
    }
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++) {
            addedge(p(i+1, j) + n*m, p(i,j) + n*m, 1);
        }
    }
    for(int i = 1; i <= 2 * n * m; i++) d[i] = INF;
    d[1] = 0;
    priority_queue<P, vector<P>, greater<P>> que;
    que.emplace(P(0, 1));
    while(!que.empty()) {
        P pe = que.top(); que.pop();
        int v = pe.second;
        if(d[v] < pe.first) continue;
        for(int i = h[v]; i; i = e[i].next) {
            if(d[e[i].to] > e[i].cost + d[v]) {
                d[e[i].to] = e[i].cost + d[v];
                que.emplace(P(d[e[i].to], e[i].to));
            }
        }
    }
    cout << d[n*m] << endl;
}

int main() {
    ios::sync_with_stdio(false);
    //srand(time(NULL));    //更新种子
    solve();
    return 0;
}

#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <algorithm>
#include <bitset>
#include <complex>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#include <cassert>
#include <functional>

using ll = long long;
using namespace std;

template<typename A, typename B>
bool chmin(A &a, const B b) {
  if (a <= b) return false;
  a = b;
  return true;
}

template<typename A, typename B>
bool chmax(A &a, const B b) {
  if (a >= b) return false;
  a = b;
  return true;
}

#ifndef LOCAL
#define debug(...) ;
#else
#define debug(...) cerr << __LINE__ << " : " << #__VA_ARGS__ << " = " << _tostr(__VA_ARGS__) << endl;

template<typename T>
ostream &operator<<(ostream &out, const vector<T> &v);

template<typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template<typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}

void _tostr_rec(ostringstream &oss) {
  oss << "\b\b \b";
}

template<typename Head, typename... Tail>
void _tostr_rec(ostringstream &oss, Head &&head, Tail &&...tail) {
  oss << head << ", ";
  _tostr_rec(oss, forward<Tail>(tail)...);
}

template<typename... T>
string _tostr(T &&...args) {
  ostringstream oss;
  int size = sizeof...(args);
  if (size > 1) oss << "{";
  _tostr_rec(oss, forward<T>(args)...);
  if (size > 1) oss << "}";
  return oss.str();
}
#endif

constexpr int mod = 1'000'000'007; //1e9+7(prime number)
constexpr int INF = 1'000'000'000; //1e9
constexpr ll LLINF = 2'000'000'000'000'000'000LL; //2e18
constexpr int SIZE = 510;

int A[SIZE][SIZE], B[SIZE][SIZE];
int dp[SIZE][SIZE][2];

int main() {
  int H, W;

  scanf("%d%d", &H, &W);

  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W - 1; j++) {
      scanf("%d", A[i] + j);
      // A[i][j] = rand() % 1000;
    }
  }

  for (int i = 0; i < H - 1; i++) {
    for (int j = 0; j < W; j++) {
      scanf("%d", B[i] + j);
      // B[i][j] = rand() % 1000;
    }
  }

  for (int j = 0; j <= H; j++) {
    for (int k = 0; k <= W; k++) {
      dp[j][k][0] = dp[j][k][1] = INF;
    }
  }

  dp[0][0][0] = 0;

  for (int i = 0; i <= W; i++) {
    for (int j = 0; j < H; j++) {
      for (int k = 0; k < W; k++) {
        if (k + 1 < W) chmin(dp[j][k + 1][0], dp[j][k][0] + A[j][k]);
      }
      for (int k = W - 1; k >= 0; k--) {
        if (k) chmin(dp[j][k - 1][0], dp[j][k][0] + A[j][k - 1]);
      }
      for (int k = 0; k < W; k++) {
        if (j + 1 < H) chmin(dp[j + 1][k][0], dp[j][k][0] + B[j][k]);
      }
    }
    for (int j = H - 1; j >= 0; j--) {
      for (int k = 0; k < W; k++) {
        if (j) {
          chmin(dp[j - 1][k][1], dp[j][k][0] + 2);
          chmin(dp[j - 1][k][1], dp[j][k][1] + 1);
        }
        chmin(dp[j][k][0], dp[j][k][1]);
      }
    }
  }

  int ans = INF;

  for (int i = 0; i <= W; i++) {
    chmin(ans, dp[H - 1][W - 1][0]);
  }

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

  return 0;
}


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

using ll = long long;
const ll INF = 1LL<<60;

using namespace std;

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

    if(a > 0 && b > 0) {
        if(a > b) {
            cout << ">" << endl;
        } else if(a < b) {
            cout << "<" << endl;
        } else {
            cout << "=" << endl;
        }
    } else if(a > 0 && b < 0) {
        if(c % 2 == 0) {
            if(a > abs(b)) {
            cout << ">" << endl;
            } else if(a < abs(b)) {
            cout << "<" << endl;
            } else {
            cout << "=" << endl;
            }
        } else {
            cout << ">" << endl;
        }
    } else if(a > 0 && b == 0) {
        cout << ">" << endl;
    } else if(a < 0 && b > 0) {
        if(c % 2 == 0) {
            if(abs(a) > b) {
            cout << ">" << endl;
            } else if(abs(a) < b) {
            cout << "<" << endl;
            } else {
            cout << "=" << endl;
            }
        } else {
            cout << "<" << endl;
        }
    } else if(a < 0 && b < 0) {
        if(c % 2 == 0) {
            if(a > b) {
            cout << ">" << endl;
            } else if(a < b) {
            cout << "<" << endl;
            } else {
            cout << "=" << endl;
            }
        } else {
            if(a > b) {
            cout << "<" << endl;
            } else if(a < b) {
            cout << ">" << endl;
            } else {
            cout << "=" << endl;
            }
        }
    } else if(a < 0 && b == 0) {
        if(c % 2 == 0) {
            cout << ">" << endl;
        } else {
            cout << "<" << endl;
        }
    } else if(a == 0 && b > 0) {
        cout << "<" << endl;
    } else if(a == 0 && b < 0) {
        if(c % 2 == 0) {
            cout << "<" << endl;
        } else {
            cout << ">" << endl;
        }
    } else if(a == 0 && b == 0) {
        cout << "=" << endl;
    }

    return 0;
}

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

// Athor : Roshan Mitra 😎
// Language: C++
// College: Symbiosis Institute Of Technology
// Practice is the only key to success
// Always push ur limits
typedef pair<int, int> pii;
#define endl "\n"
#define set_bits(a) __builtin_popcountll(a)
#define f0(i, n) for (int i = 0; i < n; i++)
#define f1(i, n) for (int i = 1; i <= n; i++)
#define sd(val) scanf("%d", &val)
#define sl(val) scanf("%lld", &val)
#define debug(val) printf("check%d\n", val)
#define asc(v) v.begin(), v.end()
#define des(v) v.end(), v.begin()
#define all(v) v.begin(), v.end()
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define int long long
#define maxheap priority_queue<int>
#define minheap priority_queue<int, vector<int>, greater<int>>
typedef vector<int> vi;
#define MOD 1000000007
#define clr(val) memset(val, 0, sizeof(val))
#define what_is(x) cerr << #x << " is " << x << endl;
#define rr return
#define FIO                           \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
void file()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

void solve()
{
    int a, b, c;
    cin >> a >> b >> c;
    if (a == b)
    {
        cout << "=\n";
        rr;
    }
    if (a > 0 and b > 0)
    {
        if (a > b)
        {
            cout << ">\n";
            rr;
        }
        else if (a < b)
        {
            cout << "<\n";
            rr;
        }
    }
    else
    {
        if (c % 2 == 0)
        {
            if (abs(a) > abs(b))
            {
                cout << ">\n";
                rr;
            }
            else if (abs(a) < abs(b))
            {
                cout << "<\n";
                rr;
            }
            else
            {
                cout << "=\n";
                rr;
            }
        }
        else
        {
            if ((a) > (b))
            {
                cout << ">\n";
                rr;
            }
            else if ((a) < (b))
            {
                cout << "<\n";
                rr;
            }
            else
            {
                cout << "=\n";
                rr;
            }
        }
    }
}
signed main()
{
    file();
    FIO;
    int t = 1;
    //cin>>t;
    while (t--)
    {
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
using namespace chrono;
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif

int main()
{
	int x, y;
	cin >> x >> y;

	if (x == y)
	{
		cout << x << endl;
	}
	else
	{
		cout << (0 ^ 1 ^ 2 ^ x ^ y) << endl;
	}

	return 0;
}

#include<stdio.h>
int main(void)
{
	int x, y;
	int z;

	scanf("%d %d", &x, &y);

	if(x == y){
		z = x;
	}

	else if(x != y){
		z = 3 - (x+y);
	}

	printf("%d",z);
	return(0);
}


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

ll n,ans=0;
set<pair<ll,ll>> e,o;
pair<ll,ll> w,x,y,z;

int main(){
	cin>>n;
	ll a[n],b[n];
	for(int i=0;i<n;i++)cin>>a[i];
	for(int i=0;i<n;i++)cin>>b[i];
	for(int i=0;i<n;i++){
		if(i%2==0)e.insert({a[i]-b[i],i});
		else o.insert({a[i]-b[i],i});
	}
	for(int i=0;i<n/2;i++){
		w=*begin(e),x=*begin(o),y=*rbegin(e),z=*rbegin(o);
		if(-w.first-x.first>=y.first+z.first){ans+=b[w.second]+b[x.second];e.erase(w);o.erase(x);}
		else{ans+=a[y.second]+a[z.second];e.erase(y);o.erase(z);}
	}
	cout<<ans<<endl;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define rep(i, n)  for(ll i = 0; i < (n); ++i)
#define rep1(i,n)  for(ll i = 1;i <= (n); ++i)
#define pb push_back
#define noofones(a) __builtin_popcount(a)

#define f first
#define s second
#define M 1000000007

int main()
{

    fastIO
   ll n;
   cin>>n;
   map<ll,ll>mp;
   vector<ll>v;
   for(int i=0;i<n;i++)
   {
   ll e;cin>>e;
   mp[e]++;
   v.pb(e);
   }
   ll res=0;
   for(int i=0;i<n;i++)
   {

       mp[v[i]]--;
    ll cnt=mp[v[i]];

    ll rem=n-i-1;
    rem-=cnt;
    res+=rem;
   }
   cout<<res;

	return 0;
}


#include <bits/stdc++.h>

using namespace std;
const int INF = 1e9 + 10;
#define ll long long
#define lowbit(i) ((i) & -(i))

struct Fenwick {

    vector<int>a;
    int n;
    Fenwick (int n):a(n),n(n){}
    void update(int x,int w)
    {
        for (int i = x;i < n;i += lowbit(i))
            a[i] += w;
    }
    int query(int x)
    {
        int res = 0;
        for (int i = x;i;i -= lowbit(i))
            res += a[i];
        return res;
    }
    int query_sum(int l,int r)
    {
        if (l > r)
            return 0;
        else
        return query(r) - query(l - 1);
    }
};
void solve()
{
    int h, w, m;
    cin >> h >> w >> m;
    vector<int>ss(w+1, h+1),hh(h+1,w+1);

    for(int i=1;i<=m;i++)
    {
        int x, y;
        cin >> x >> y;
        hh[x] = min(hh[x], y);
        ss[y] = min(ss[y], x);

    }
    ll ans = 0;
    vector<vector<int>>g(h + 2);
    for(int i=1;i<=w;i++)
    {
        if (ss[i] == 1)
            break;
        ans += ss[i] - 1;
        g[ss[i]].push_back(i);
    }
    Fenwick t(w + 1);
    for (int i = 1;i <= w;i++)
        t.update(i, 1);
    for(int i=h+1;i>=2;i--)
    {
        for(int j:g[i])
            t.update(j, -1);
        if(i<ss[1])
        {
            ans += t.query_sum(1, hh[i] - 1);
        }
    }
    cout << ans << endl;

}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int T =1;

    while (T--)
    {
        solve();

    }
}


#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <numeric>
using namespace std;
const long long INF = 1LL << 60;

int main() {
  int H, W;
  cin >> H >> W;

  vector<string> A(H);
  for (int i = 0; i < H; ++i) cin >> A[i];

  vector< vector<int> > dp(H, vector<int>(W,0));
  int num = 0;
  for (int h = H-1; h >= 0; --h) {
    for (int w = W-1; w >= 0; --w) {
      num = h+w;
      if (h == H-1 && w == W-1) continue;
      if (h == H-1) {
        if (num % 2 == 0) {
          dp[h][w] = dp[h][w+1] + (A[h][w+1] == '+' ? 1 : -1);
        } else {
          dp[h][w] = dp[h][w+1] + (A[h][w+1] == '+' ? -1 : 1);
        }
        continue;
      }
      if (w == W-1) {
        if (num % 2 == 0) {
          dp[h][w] = dp[h+1][w] + (A[h+1][w] == '+' ? 1 : -1);
        } else {
          dp[h][w] = dp[h+1][w] + (A[h+1][w] == '+' ? -1 : 1);
        }
        continue;
      }

      if (num % 2 == 0) {
        dp[h][w] = max(dp[h][w+1] + (A[h][w+1] == '+' ? 1 : -1), dp[h+1][w] + (A[h+1][w] == '+' ? 1 : -1));
      } else {
        dp[h][w] = min(dp[h][w+1] + (A[h][w+1] == '+' ? -1 : 1), dp[h+1][w] + (A[h+1][w] == '+' ? -1 : 1));
      }
    }
  }

  if (dp[0][0] == 0) cout << "Draw" << endl;
  else if (dp[0][0] > 0) cout << "Takahashi" << endl;
  else cout << "Aoki" << endl;
}

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

const int INF = (1 << 30) - 1;
const ll LINF = (1LL << 60) - 1;
const double PI = acos(-1);

int main() {
    ll h, w; cin >> h >> w;
    vector<string> s(h);
    rep(i, h) cin >> s[i];
    vector<vector<ll>> a(h, vector<ll>(w));
    rep(i, h) rep(j, w) {
        if (s[i][j] == '+') a[i][j] = 1;
        else a[i][j] = -1;
    }
    vector<vector<ll>> dp(h, vector<ll>(w));
    rep(i, h) rep(j, w) dp[i][j] = -INF;
    dp[h-1][w-1] = 0;
    for (ll i = h-1; i >= 0; i--) {
        for (ll j = w-1; j >= 0; j--) {
            if (i-1 >= 0) dp[i-1][j] = max(a[i][j]-dp[i][j], dp[i-1][j]);
            if (j-1 >= 0) dp[i][j-1] = max(a[i][j]-dp[i][j], dp[i][j-1]);
        }
    }
    if (dp[0][0] > 0) cout << "Takahashi" << endl;
    if (dp[0][0] < 0) cout << "Aoki" << endl;
    if (dp[0][0] == 0) cout << "Draw" << endl;
    return 0;
}

//小数点の出力
//cout << fixed << std::setprecision(15) << ans << endl;


// EXPLOSION!
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include<chrono>

using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpi;
typedef vector<pair<ll, ll>> vpll;

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)

#define pb push_back
#define mp make_pair
#define rsz resize
#define sz(x) int(x.size())
#define all(x) x.begin(),x.end()
#define f first
#define s second
#define cont continue
#define endl '\n'
//#define ednl '\n'
#define test int testc;cin>>testc;while(testc--)
#define pr(a, b) trav(x,a)cerr << x << b; cerr << endl;
#define message cout << "Hello World" << endl;
const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 }; // for every grid problem!!
const ll linf = 4000000000000000000LL;
const ll inf = 1000000007;//998244353

void pv(vi a) { trav(x, a)cout << x << " "; cout << endl; }void pv(vll a) { trav(x, a)cout << x << " "; cout << endl; }void pv(vector<vi>a) {
	F0R(i, sz(a)) { cout << i << endl; pv(a[i]); cout << endl; }
}void pv(vector<vll>a) { F0R(i, sz(a)) { cout << i << endl; pv(a[i]); }cout << endl; }void pv(vector<string>a) { trav(x, a)cout << x << endl; cout << endl; }
void setIO(string s) {
	ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef arwaeystoamneg
	if (sz(s))
	{
		freopen((s + ".in").c_str(), "r", stdin);
		if (s != "test1")
			freopen((s + ".out").c_str(), "w", stdout);
	}
#endif
}
int n, m, cur = 0, co = 0;
const int MAX = 2e5 + 5;
vector<vi>adj;
vi a, v;
void dfs(int i)
{
	v[i] = 1;
	trav(x, adj[i])
	{
		if (!v[x])dfs(x);
	}
}
int main()
{
	setIO("test1");
	cin >> n;
	a.rsz(n);
	trav(x, a)cin >> x, x--;
	adj.rsz(MAX);
	F0R(i, n / 2)
	{
		adj[a[i]].pb(a[n - i - 1]);
		adj[a[n - i - 1]].pb(a[i]);
	}
	v.rsz(MAX);
	F0R(i, MAX)
	{
		if (v[i])continue;
		dfs(i);
		co++;
	}
	cout << MAX - co << endl;
}

#pragma GCC optimize("Ofast")
#pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>

#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define ff first
#define ss second
#define ins insert
#define sz(x) (int)x.size()
#define dbg(x) cout << x << "\n";

const int N = 2e5 + 5;
const long long int mod = 1e9 + 7;
const long long int Mod = 998244353;
const long double Pi = acos(-1);
const long long int Inf = 4e18;
const long double Eps = 1e-9;

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

using namespace std;

#define int long long int

struct DSU{
        vector <int> arr, s, g[200005];

        void Initialize(){
                s.assign(N, 1);
                for(int i = 0; i<N; i++){
                        g[i].pb(i);
                        arr.pb(i);
                }
        }

        int Root (int x){ return arr[x]; }

        void Merge (int x, int y){
                x = Root(x);
                y = Root(y);
                if(x != y){
                        if(s[x] < s[y]){
                                for(auto u: g[x]){
                                        g[y].pb(u);
                                        arr[u] = y;
                                }
                                s[y] += s[x];
                        }
                        else{
                                for(auto u: g[y]){
                                        g[x].pb(u);
                                        arr[u] = x;
                                }
                                s[x] += s[y];
                        }
                }
        }

        bool Find (int a, int b){
                if(Root(a) == Root(b)) return true;
                else return false;
        }
};

void TestCase (){
        int n, ans = 0;
        cin >> n;

        DSU dsu;
        dsu.Initialize();

        vector <int> a(n + 1);

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

        for(int i = 1; i<=n; i++){
                if(dsu.Find(a[i], a[n + 1 - i]) == false){
                        dsu.Merge(a[i], a[n + 1 - i]);
                }
        }

        set <int> roots;
        for(int i = 1; i<N; i++) roots.ins(dsu.arr[i]);

        for(auto &o: roots) ans += dsu.s[o] - 1;

        cout << ans;

}

#undef int

int main(){
        IOS;
        int T = 1;
        // cin >> T;
        while(T--){
                TestCase();
                cout << "\n";
        }
        return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
// --------------------------------------------------------
template<class T> bool chmax(T& a, const T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T& a, const T b) { if (b < a) { a = b; return 1; } return 0; }
#define FOR(i,l,r) for (ll i = (l); i < (r); ++i)
#define RFOR(i,l,r) for (ll i = (r)-1; (l) <= i; --i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define MIN(c) *min_element(ALL(c))
#define MAX(c) *max_element(ALL(c))
#define SUMLL(c) accumulate(ALL(c), 0LL)
#define COUNT(c,v) count(ALL(c),(v))
#define SZ(c) ((ll)(c).size())
#define BIT(b,i) (((b)>>(i)) & 1)
#define PCNT(b) __builtin_popcountll(b)
#define CIN(c) cin >> (c)
#define COUT(c) cout << (c) << '\n'
#define debug(x) cerr << "l." << __LINE__ << " : " << #x << " = " << (x) << '\n'
ll llceil(ll a, ll b) { return (a + b - 1) / b; }
ll bitlen(ll b) { if (b <= 0) { return 0; } return (64LL - __builtin_clzll(b)); }
string toupper(const string& S) { string T(S); REP(i,SZ(T)) T[i] = toupper(T[i]); return T; }
string tolower(const string& S) { string T(S); REP(i,SZ(T)) T[i] = tolower(T[i]); return T; }
using P = pair<ll,ll>;
using VP = vector<P>;
using VVP = vector<VP>;
using VS = vector<string>;
using VVS = vector<VS>;
using VLL = vector<ll>;
using VVLL = vector<VLL>;
using VVVLL = vector<VVLL>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VVVB = vector<VVB>;
using VD = vector<double>;
using VVD = vector<VD>;
using VVVD = vector<VVD>;
using VLD = vector<ld>;
using VVLD = vector<VLD>;
using VVVLD = vector<VVLD>;
static const double EPS = 1e-10;
static const double PI  = acos(-1.0);
static const ll MOD = 1000000007;
// static const ll MOD = 998244353;
static const ll INF = (1LL << 62) - 1;  // 4611686018427387904 - 1
// --------------------------------------------------------
// #include <atcoder/all>
// using namespace atcoder;

// Editorial AC

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);

    ll N; cin >> N;
    VLL A(N); REP(i,N) cin >> A[i];
    VLL B(N); REP(i,N) cin >> B[i];

    VLL E,O;  // Even,Odd
    REP(i,N) {
        if (i % 2 == 0) {
            E.push_back(B[i] - A[i]);
        } else {
            O.push_back(B[i] - A[i]);
        }
    }
    RSORT(E); RSORT(O);

    ll score = SUMLL(A);
    ll ans = score;
    REP(i,N/2) {
        score += E[i] + O[i];
        chmax(ans, score);
    }
    COUT(ans);

    return 0;
}

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

int main() {
    int n; cin >> n;
    vector<int> a(2 * n);
    for(auto &e : a) cin >> e;

    vector<P> ps;
    rep(i, 2 * n) ps.emplace_back(a[i], i);
    sort(ps.rbegin(), ps.rend());

    vector<int> p(2 * n, -1);
    rep(i, n) p[ps[i].second] = 1;

    string ans(2 * n, 'x');

    int l = 0, r = 0;
    int cnt_p = 0, cnt_m = 0;
    string st = "";
    rep(i, 2 * n) {
        if(st.empty()) {
            st +='(';
            ans[i] = '(';
            l++;
            if(p[i] == 1) cnt_p++;
            else cnt_m++;
        } else {
            if(cnt_p) {
                if(p[i] == 1) {
                    cnt_p++;
                    st += '(';
                    ans[i] = '(';
                } else {
                    cnt_p--;
                    st.pop_back();
                    ans[i] = ')';
                }
            } else if(cnt_m) {
                if(p[i] == -1) {
                    cnt_m++;
                    st += '(';
                    ans[i] = '(';
                } else {
                    cnt_m--;
                    st.pop_back();
                    ans[i] = ')';
                }
            }
        }
    }

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