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

class BIT {
public:
	int size_ = 1;
	vector<long long> bit;

	void init(int sz) {
		size_ = sz + 2;
		bit.resize(size_ + 2, 0);
	}
	void add(int pos, long long x) {
		pos++;
		while (pos <= size_) {
			bit[pos] += x;
			pos += (pos & -pos);
		}
	}
	long long sum(int pos) {
		long long s = 0; pos++;
		while (pos >= 1) {
			s += bit[pos];
			pos -= (pos & -pos);
		}
		return s;
	}
};

long long N, M, Q;
long long T[1 << 19], X[1 << 19], Y[1 << 19];
long long A[1 << 19], B[1 << 19];
vector<long long> Z;

BIT A1, A2;
BIT B1, B2;

void change1(int p1, int p2) {
	A1.add(A[p1], -1);
	A2.add(A[p1], -Z[A[p1]]);
	A[p1] = p2;
	A1.add(A[p1], 1);
	A2.add(A[p1], Z[A[p1]]);
}

void change2(int p1, int p2) {
	B1.add(B[p1], -1);
	B2.add(B[p1], -Z[B[p1]]);
	B[p1] = p2;
	B1.add(B[p1], 1);
	B2.add(B[p1], Z[B[p1]]);
}

int main() {
	// Input
	cin >> N >> M >> Q;
	for (int i = 1; i <= Q; i++) {
		cin >> T[i] >> X[i] >> Y[i];
		Z.push_back(Y[i]);
	}
	Z.push_back(0);
	sort(Z.begin(), Z.end());
	Z.erase(unique(Z.begin(), Z.end()), Z.end());

	// Lower Bound
	for (int i = 1; i <= Q; i++) {
		Y[i] = lower_bound(Z.begin(), Z.end(), Y[i]) - Z.begin();
	}

	// BIT Init
	A1.init(Z.size()); A1.add(0, N);
	A2.init(Z.size());
	B1.init(Z.size()); B1.add(0, M);
	B2.init(Z.size());

	// Query
	long long CurrentAns = 0;
	for (int i = 1; i <= Q; i++) {
		if (T[i] == 1) {
			long long pos1 = A[X[i]];
			long long pos2 = Y[i];
			long long sa1 = 1LL * Z[pos2] * B1.sum(pos2) - 1LL * Z[pos1] * B1.sum(pos1);
			long long sa2 = 1LL * (B2.sum(Z.size() + 1) - B2.sum(pos2)) - 1LL * (B2.sum(Z.size() + 1) - B2.sum(pos1));
			CurrentAns += (sa1 + sa2);
			change1(X[i], Y[i]);
		}
		if (T[i] == 2) {
			long long pos1 = B[X[i]];
			long long pos2 = Y[i];
			long long sa1 = 1LL * Z[pos2] * A1.sum(pos2) - 1LL * Z[pos1] * A1.sum(pos1);
			long long sa2 = 1LL * (A2.sum(Z.size() + 1) - A2.sum(pos2)) - 1LL * (A2.sum(Z.size() + 1) - A2.sum(pos1));
			CurrentAns += (sa1 + sa2);
			change2(X[i], Y[i]);
		}
		cout << CurrentAns << endl;
	}
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
vector<ll> v;
vector<pair<ll,ll> > aj[2005];
bool vis[2005];
ll dist[2005];
priority_queue<pair<ll,ll> ,vector<pair<ll,ll> > ,greater<pair<ll,ll> > > pq;
ll dijkstra(ll x,ll n){
	memset(vis,false,sizeof(vis));
	ll maxn = 2e9,a,b;
	for(int i=1;i<=n;i++)dist[i] = 2e9;
	pq.push(make_pair(0,x));
	while(pq.size()){
		a = pq.top().first;
		b = pq.top().second;
		pq.pop();
		if(vis[b])continue;
		vis[b] = true;
		for(auto v:aj[b]){
			if(v.first==x){
				maxn = min(maxn,v.second+a);
//				cout<<a<<" "<<b<<" "<<v.first<<" "<<v.second<<" hi\n";
			}
			if(dist[v.first]>a+v.second){
				dist[v.first] = a+v.second;
				pq.push(make_pair(dist[v.first],v.first));
			}
		}
	}
	return maxn;
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	ll n,m,i,a,b,c,j,k,t,q,sum = 0,cnt = 0,maxn = 0,ans = 0,X,Y,Z;
	cin>>n>>m;
	for(i=0;i<m;i++){
		cin>>a>>b>>c;
		aj[a].push_back(make_pair(b,c));
	}
	for(i=1;i<=n;i++){
		a = dijkstra(i,n);
		if(a==2e9)cout<<"-1\n";
		else cout<<a<<"\n";
	}
}


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

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

#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <climits>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <utility>
#include <complex>
#include <chrono>
using namespace std;
using namespace std::chrono;

typedef long long int lli;
typedef long double ld;
typedef vector<lli> vl;
typedef vector<ld> vd;
typedef map<lli,lli> ml;
typedef unordered_map<lli,lli> uml;
typedef pair<lli,lli> pl;
typedef set<lli> sl;
typedef vector<pl> vp;
typedef queue<lli> ql;
typedef priority_queue<lli> pql;
typedef list<lli> ll;
typedef vector<ll> graph;

# define pb push_back
# define mp make_pair
# define f first
# define s second
# define itr iterator
# define MOD 1000000007
# define INF 1000000000000000
# define all(x) x.begin(), x.end()
# define rall(a) a.begin(), a.end(), greater<lli>()
# define ins insert
# define ms(a,x) memset(a, x, sizeof(a))
# define rep(i,n) for(i=0;i<n;i++)
# define wrep(i,a,b) for(i=a;i<b;i++)
# define M 1500001;
/*
void knapsack(lli n, lli m, vl va, vl vb){
    lli i, w;
    lli k[n+1][m+1];
    k[n][m] = -1;
    for(i=0;i<=n;i++){
        for(w=0;w<=m;w++){
            if(i==0 || w==0){
                k[i][w]=0;
            }
            else if(va[i-1]<=w){
                k[i][w] = max(k[i-1][w], k[i-1][w-va[i-1]]+ vb[i-1]);
            }
            else{
                k[i][w] = k[i-1][w];
            }
        }
    }
    cout<<k[n][m]<<endl;
}
bool comp(pl a, pl b){
    return a.f<b.f;
}
bool comp(lli a, lli b){
    return abs(a)<abs(b);
}
lli cmb(lli n, lli r){
    if(n==r){
        return 1;
    }
    lli i, pdt = 1;
    r = max(r,n-r);
    for(i=1;i<=n-r;i++){
        pdt *= (r+i);
        pdt /= i;
    }
    return pdt;
}
lli per(lli n, lli r){
    lli i;
    lli pdt = 1;
    for(i=1;i<=r;i++){
        pdt *= n-r+i;
    }
    return pdt;

}
// Binomial coeff Table // Combination Table
lli dp[2001][2001];
void foo(){
    dp[0][0] = 1;
    lli i, j;
    for (i = 1; i < 1001; i++) {
        dp[i][0] = 1;
        for (j = 1; j <= i; j++) {
            dp[i][j] = (dp[i-1][j] + dp[i-1][j-1]) % MOD;
        }
    }
}

//cout << fixed << setprecision(9) << t << endl;
//sieve Table
int sv[M];
vl prm;
void sieve(){
    lli i, j;
    for(i=2;i<M;i++){
      if(sv[i]!=0){
        continue;
      }
      sv[i] = -1;
      prm.pb(i);
      for(j=2;j*i<M;j++){
        sv[i*j] = 1;
      }
    }
    return;
}
lli fexpo(lli a, lli b){
  if(a==1) return 1;
  if(b==0) return 1;
  if(b==1) return a%MOD;
  lli ans = fexpo(a,b/2)%MOD;
  if(b%2==0) return (ans*ans)%MOD;
  else return (((a*ans)%MOD)*ans)%MOD;
}
lli fact[M];
lli inv_fact[M];
void foo(){
  lli i;
  fact[0] = 1;
  for(i=1;i<M;i++){
    fact[i] = (i*fact[i-1])%MOD;
  }
  inv_fact[M-1] = fexpo(fact[M-1],MOD-2);
  for(i=M-2;i>=0;i--){
    inv_fact[i] = ((i+1)*inv_fact[i+1])%MOD;
  }
}
lli cmb(lli n, lli r){
  return (((fact[n]*inv_fact[r])%MOD)*(inv_fact[n-r]))%MOD;
}
*/
lli sum = 0;

bool dec(lli n){
  while(n>0){
    if(n%10==7){
      return true;
    }
    n/= 10;
  }
  return false;
}

bool octal(lli n){
  while(n>0){
    if(n%8==7){
      return true;
    }
    n/= 8;
  }
  return false;
}

void check(lli n){
  if(octal(n) || dec(n)){
    return;
  }
  sum++;
}

void solve(){
    lli n, i, m=0, q=0, mx=-INF, mn=INF, k=0, j=0, c=0, d=0, t = 0, sm = 0, pdt = 1;
    cin >> n;
    //lli v[n+1];

    for(i=1;i<=n;i++){
      check(i);
    }

    cout<<sum<<endl;

    return;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    //freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
    //cin >> t;
    t = 1;
    while(t--){
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace  std;
#define NMAX 200005
int n;
string s, x;
set <int> dp[NMAX];

int main() {
    cin>>n;
    cin>>s>>x;
    dp[n].insert(0);
    for(int i = n-1 ; i >= 0; i--){
        if(x[i]=='T'){
            for(int j=0;j<7;j++){
                int p = (10*j)%7;
                int q = ((10*j)+(s[i]-'0'))%7;
                if(dp[i+1].count(p)) {
                    dp[i].insert(j);
                    //cout<<i<<": insert "<<j<<'\n';
                }
                if(dp[i+1].count(q)) {
                    dp[i].insert(j);
                    //cout<<i<<": insert "<<j<<'\n';
                }
            }
        }
        else{
            for(int j=0;j<7;j++){
                int p = (10*j)%7;
                int q = ((10*j)+(s[i]-'0'))%7;
                if(dp[i+1].count(p) && dp[i+1].count(q)) {
                    dp[i].insert(j);
                    //cout<<i<<": insert "<<j<<'\n';
                }
            }
        }
    }
    if(dp[0].count(0)) cout<<"Takahashi";
    else cout<<"Aoki";
}

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

void solveCase() {
  string s1, s2, s3;
  cin >> s1 >> s2 >> s3;
  vector<bool> visit(26);
  for (auto& c : s1) visit[c - 'a'] = 1;
  for (auto& c : s2) visit[c - 'a'] = 1;
  for (auto& c : s3) visit[c - 'a'] = 1;
  vector<int> can;
  for (int k = 0; k < 26; ++k) {
    if (visit[k]) can.push_back(k);
  }
  int SZ = can.size();
  if (SZ > 10) {
    cout << "UNSOLVABLE" << '\n';
    return;
  }

  vector<int> p(10), v(26);
  int64_t x, y, z;
  for (int i = 0; i < 10; ++i) p[i] = i;
  bool found = false;
  do {
    for (int i = 0; i < SZ; ++i) v[can[i]] = p[i];
    x = 0, y = 0, z = 0;
    if (v[s1[0] - 'a'] == 0) continue;
    if (v[s2[0] - 'a'] == 0) continue;
    if (v[s3[0] - 'a'] == 0) continue;
    for (auto& c : s1) x = x * 10 + v[c - 'a'];
    for (auto& c : s2) y = y * 10 + v[c - 'a'];
    for (auto& c : s3) z = z * 10 + v[c - 'a'];
    if (x && y && z && x + y == z) {
      found = true;
      break;
    }
  } while (next_permutation(p.begin(), p.end()));
  if (!found) {
    cout << "UNSOLVABLE" << '\n';
  } else {
    cout << x << '\n';
    cout << y << '\n';
    cout << z << '\n';
  }
}

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

  int T = 1;
  // cin >> T;
  for (int ti = 1; ti <= T; ++ti) {
    // cout << "Case #" << ti << ": ";
    solveCase();
  }

  return 0;
}


#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <iostream>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <memory>
#include <list>
#include <deque>
#include <queue>
#include <iomanip>

using namespace std;

#define REP(i,n) for (decltype(n) i = 0; i < n; i++)

using ll = long long;
using ivec = vector<int>;
using lvec = vector<long>;
using ipair = pair<int, int>;
using llvec = vector<ll>;
using llpair = pair<ll, ll>;

template<typename T>
vector<T> read_args()
{
	T N;
	cin >> N;
	vector<T> v(N);
	for (auto& e : v) {
		cin >> e;
	}
	return v;
}

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

template<class T>
void rsort(T& v)
{
	sort(v.begin(), v.end(), greater<typename T::value_type>());
}

void answer(bool b)
{
	cout << (b ? "Yes" : "No") << endl;
}

typedef unordered_map<int, int> Cluster;
vector<Cluster*> clusters;
ivec c;

void merge2(Cluster& a, Cluster& b)
{
	for (auto&e : b) {
		if (a.find(e.first) != a.end()) {
			a[e.first] += e.second;
		} else {
			a[e.first] = e.second;
		}
	}
}

void dump(Cluster* cluster)
{
	return;
	for (auto &e : *cluster) {
		cout << "[" << e.first << "]" << e.second << endl;;
	}
}

class UnionFind {
public:
	UnionFind(int n)
	{
		parent.assign(n, 0);
		for (int i = 0; i < n; i++)
			parent[i] = i;
		rank.assign(n, 0);
	}

	bool unite(int a, int b)
	{
		a = root(a);
		b = root(b);
		if (a == b)
			return false;
		if (rank[a] > rank[b]) {
			parent[b] = a;
			merge(a, b);
		} else {
			parent[a] = b;
			merge(b, a);
			if (rank[a] == rank[b])
				rank[b]++;
		}
		return true;
	}

	void merge(int a, int b)
	{
		// cout << "merge " << a << "," << b << endl;
		if (!clusters[a]) {
			clusters[a] = new Cluster;
			(*clusters[a])[c[a]] = 1;
		}
		if (!clusters[b]) {
			clusters[b] = new Cluster;
			(*clusters[b])[c[b]] = 1;
		}
		merge2(*clusters[a], *clusters[b]);
		dump(clusters[a]);
		delete clusters[b];
		clusters[b] = nullptr;
	}

	bool same(int a, int b)	{ return root(a) == root(b); }
	bool isRoot(int a) { return parent[a] == a; }
	int root(int i) { return parent[i] == i ? i : parent[i] = root(parent[i]); }
private:
	std::vector<int> parent;
	std::vector<int> rank;
};

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

	UnionFind uf(n);

	c.assign(n, 0);
	REP(i,n) {
		int z;
		cin >> z;
		c[i] = z;
	}
	clusters.assign(n, 0);

	REP(z, q) {
		int p,x,y;
		cin >> p >> x >> y;
		// cout << p << "," << x << "," << y << endl;
		x--;
		if (p == 1) {
			y--;
			uf.unite(x,y);
		} else {
			// cout << x << "," << y << endl;
			x = uf.root(x);
			// cout << x << "," << x << endl;
			auto p = clusters[x];
			if (!p) {
				// cout << "no cluster" << endl;
				if (c[x] == y)
					cout << 1 << endl;
				else
					cout << 0 << endl;
			} else {
				dump(p);
				auto it = p->find(y);
				if (it == p->end()) {
					cout << 0 << endl;
				} else {
					cout << it->second << endl;
				}
			}
		}
	}
	return 0;
}

//To debug :  g++ -g file.cpp -o code
//to flush output : fflush(stdout) or cout.flush()
//cout<<setprecision(p)<<fixed<<var
//use 1LL<<i to for 64 bit shifting , (ll)2 because by default 2 is ll
//take care of precedence rule of operators
//do not forget to change the sizes of arrays and value of contants and other things after debugging

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,a,n) for(i=a;i<n;++i)
#define irep(i,n,a) for(i=n;i>a;--i)
#define mod 1000000007
#define pb push_back
#define big 9223372036854775807
#define big1 LONG_MAX
#define big2 ll_MAX
#define big3 1000000000
#define sma1 LONG_MIN
#define sma2 ll_MIN
#define sma3 -1000000000
#define mp make_pair
#define dub double
#define ivec vector<ll>
#define lvec vector<long long>
#define cvec vector<char>
#define svec vector<string>
#define mt make_tuple
#define MOD 998244353
#define ld long double
#define pi acos(-1.0)

#define SZ(x)  (ll)(x.size())

//comment the below if not required

/*

#define ss second.second
#define ff first.first
#define f first
#define s second
#define sf second.first
#define fs first.second
*/

#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

//cout<<"Case #"<<c<<": "<<ans<<"\n" ;

const int N = 2e5+1;
int n,q,c,x,y,cl,Q,A,B;
vector<int> v[N];
map<int,int> m[N];
int a[N];

int main()
{

    int i,i1,j1;

    cin>>n>>q;

    for(i=1;i<=n;++i)
    {
        cin>>cl;
        v[i].pb(i);
        ++m[i][cl];
        a[i]=i;
    }

    for(i=1;i<=q;++i)
    {
        cin>>Q>>A>>B;

        if(Q==1)
        {
            i1=a[A],j1=a[B];

            if(i1==j1)
                continue;

            if(SZ(v[j1])>SZ(v[i1]))
                swap(i1,j1);

            //put j1 into i1

            for(auto u : v[j1])
            {
                a[u]=i1;
                v[i1].pb(u);
            }
            v[j1].clear();

            for(auto i = m[j1].begin();i!=m[j1].end();++i)
                m[i1][i->first]+=i->second;

            m[j1].clear();
        }
        else
        {
            cout<<m[a[A]][B]<<"\n";
        }

    }

    return 0;
}


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

#define ll long long
const int mod = 1e9 + 7;
#define ff first
#define ss second
#define pb push_back
#define all(v) v.begin(), v.end()
const ll inf = 2e18;

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

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

int add(int a, int b) {
  int res = (a + b) % mod;
  if (res < 0)
    res += mod;
  return res;
}

int mult(int a, int b) {
  int res = (a * 1LL * b) % mod;
  if (res < mod)
    res += mod;
  return res;
}

int power(int a, int b) {
  int res = 1;
  while (b) {
    if ((b % 2) == 1)
      res = mult(res, a);
    a = mult(a, a);
    b /= 2;
  }
  return res;
}

template <typename A, typename B> string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string &s) { return '"' + s + '"'; }
string to_string(const char *s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
string to_string(char c) { return to_string(string(1, c)); }

string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}

template <size_t N> string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}

template <typename A> string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename A, typename B> string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
         to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
         to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void dbg() { cout << endl; }
template <typename Head, typename... Tail> void dbg(Head H, Tail... T) {
  cout << " " << to_string(H);
  dbg(T...);
}

#ifdef LOCAL
#define debug(...) cout << "[" << #__VA_ARGS__ << "]:", dbg(__VA_ARGS__)
#else
#define debug(...)
#endif

void solve() {
  ll n;
  cin >> n;
  if (n <= 2) {
    cout << "1\n";
    return;
  }
  ll low = 1;
  ll high = 2e9 + 2;
  ll ans;
  while (low <= high) {
    ll mid = (low + high) / 2;
    if (mid * (mid + 1) <= 2 * (n + 1)) {
      ans = mid;
      low = mid + 1;
    } else {
      high = mid - 1;
    }
  }
  cout << (n - ans + 1) << "\n";
}

int32_t main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cout << fixed << setprecision(10);

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

  for (int i = 1; i <= t; i++) {
    // cout<<"Case "<<i<<": ";
    solve();
  }
}

#include <stdio.h>
#include <iostream>
#include <cmath>
#include <vector>
#include <numeric>
#include <string>

int main() {
	int k;
	std::cin >> k;
	std::vector<int> v(10, k);
	std::vector<double> tv(10, 0);
	std::vector<double> av(10, 0);
	int ta = 0;
	int ao = 0;
	std::string s;

	std::cin >> s;

	for (int c = 0; c < 4; c++) {
		int f;
		f = std::stoi(s.substr(c, 1));
		tv[f] += 1;
		v[f] -= 1;
	}

	for (int c = 1; c < 10; c++) {
		ta += c*pow(10, tv[c]);
	}

	std::cin >> s;

	for (int c = 0; c < 4; c++) {
		int f;
		f = std::stoi(s.substr(c, 1));
		av[f] += 1;
		v[f] -= 1;
	}

	for (int c = 1; c < 10; c++) {
		ao += c*pow(10, av[c]);
	}

	double ans = 0.;

	for (int c = 1; c < 10; c++) {
		for (int b = 1; b < 10; b++) {
			if (c == b) {
				if (v[c] > 1) {
					if (ao + b * pow(10, av[b] + 1) - b * pow(10, av[b]) < ta + c * pow(10, tv[c] + 1) - c * pow(10, tv[c])) {
						ans += static_cast<double>(v[c]) / static_cast<double>(std::accumulate(v.begin() + 1, v.end(), 0)) * static_cast<double>(v[c] - 1) / static_cast<double>(std::accumulate(v.begin() + 1, v.end(), 0) - 1);
					}
				}
			}
			else {
				if (v[c] > 0 && v[b] > 0) {
					if (ao + b * pow(10, av[b] + 1) - b * pow(10, av[b]) < ta + c * pow(10, tv[c] + 1) - c * pow(10, tv[c])) {
						ans += static_cast<double>(v[c]) / static_cast<double>(std::accumulate(v.begin() + 1, v.end(), 0)) * static_cast<double>(v[b]) / static_cast<double>(std::accumulate(v.begin() + 1, v.end(), 0) - 1);
					}
				}
			}
		}
	}

	std::cout << ans << std::endl;

}


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

bool ans;
int A[5];

int main(){
	cin >> A[1] >> A[2] >> A[3];
	sort(A + 1,A + 1 + 3);
	if (A[3] - A[2] == A[2] - A[1]) cout << "Yes\n";
	else cout << "No\n";
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
 #define mod 1000000007
 #define ll long long int
 #define pb push_back
  int main()
 {    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll t=1;
 //  cin>>t;
         while(t--){
    ll i;
    ll a,b,c,d;
     cin>>a>>b>>c>>d;

       cout<<b-c;
         }
 }


// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<random>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#include<list>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<double,int,int> tp;
typedef vector<tp> vt;
typedef vector<vt>vvt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const long double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};
#define yes cout<<"Yes\n"
#define no cout<<"No\n"
typedef ll Def;

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

	int n;
	cin>>n;
	vvi in(n,vi(5));
	rep(i,n)rep(j,5)cin>>in[i][j];

	int l=0,r=1000000010;
	while(r-l>1){
		int h=(l+r)/2;
		vi w(32);
		w[0]=1;
		vi b(n);
		rep(i,n){
			int a=0;
			rep(j,5)if(h<=in[i][j])a|=1<<j;
			w[a]++;
			b[i]=a;
		}
		bool H=false;
		rep(i,n)rep(j,i){
			int a=b[i]|b[j];
			a=31-a;
			if(w[a])H=true;
		}
		if(H)l=h;
		else r=h;
	}
	cout<<l<<endl;
}

#include <bits/stdc++.h>
using namespace std;
const int maxn = 3000 + 10;
const int s = (1 << 5) - 1;
const int N = 5;
int a[maxn][5];
int n;
int f[s + 10], g[s + 10], h[10][s + 10], fhat[10][s + 10], ghat[10][s + 10], fog[s + 10];
bool check(int x)
{
	memset(f, 0, sizeof f);
	memset(g, 0, sizeof g);
	memset(h, 0, sizeof h);
	memset(fhat, 0, sizeof fhat);
	memset(ghat, 0, sizeof ghat);

	for(int i = 1; i <= n; ++i)
	{
		int cur = 0;
		for(int j = 0; j < 5; ++j)
			if(a[i][j] >= x)
				cur |= 1 << j;
		f[cur] = 1;
	}
	for(int i = s; i; --i)
		for(int j = 0; j < 5; ++j)
			if(i & (1 << j))
				f[i ^ (1 << j)] |= f[i];
	for(int i = 0; i <= s; ++i) g[i] = f[i];

	for(int mask = 0; mask < (1 << N); mask++) {
	    fhat[__builtin_popcount(mask)][mask] = f[mask];
	    ghat[__builtin_popcount(mask)][mask] = g[mask];
	}

	// Apply zeta transform on fhat[][] and ghat[][]
	for(int i = 0; i < N; i++) {
	    for(int j = 0; j < N; j++) {
	        for(int mask = 0; mask < (1 << N); mask++) {
	            if((mask & (1 << j)) != 0) {
	                fhat[i][mask] += fhat[i][mask ^ (1 << j)];
	                ghat[i][mask] += ghat[i][mask ^ (1 << j)];
	            }
	        }
	    }
	}

	// Do the convolution and store into h[][] = {0}
	for(int mask = 0; mask < (1 << N); mask++) {
	    for(int i = 0; i < N; i++) {
	        for(int j = 0; j <= i; j++) {
	            h[i][mask] += fhat[j][mask] * ghat[i - j][mask];
	        }
	    }
	}

	// Apply inverse SOS dp on h[][]
	for(int i = 0; i < N; i++) {
	    for(int j = 0; j < N; j++) {
	        for(int mask = 0; mask < (1 << N); mask++) {
	            if((mask & (1 << j)) != 0) {
	                h[i][mask] -= h[i][mask ^ (1 << j)];
	            }
	        }
	    }
	}
	for(int mask = 0; mask < (1 << N); mask++) fog[mask] = h[__builtin_popcount(mask)][mask];
	for(int i = 0; i <= s; ++i)
		if(f[i] && fog[s - i])
			return 1;
	return 0;
}
int main()
{
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i)
		for(int j = 0; j < 5; ++j)
			scanf("%d", &a[i][j]);
	int l = 1, r = 1e9;
	while(l <= r)
	{
		int mid = l + r >> 1;
		if(check(mid)) l = mid + 1;
		else r = mid - 1;
	}
	printf("%d\n", r);
	return 0;
}


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

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

static const int IINF = (1LL << 31) - 1;

int main() {
    ll n, x, a;
    cin >> n >> x;
    vector<ll> ans;
    rep(i, n) {
        cin >> a;
        if(a != x) ans.push_back(a);
    }
    rep(i, ans.size()) {
        if(i) cout << " ";
        cout << ans[i];
    }
    cout << endl;
}

#include <iostream>

using namespace std;

int n;
long long a[300000],b[300000];
long long maxa=-9999,maxx=-9999;
int main()
{
    int i,j,k;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    for(i=1;i<=n;i++)
    {
        maxa=max(a[i],maxa);
        cin>>b[i];
        maxx=max(maxx,maxa*b[i]);
        cout<<maxx<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n;
string s;
int main(){
	scanf("%d",&n),cin>>s,s=" "+s;
	if(s[1]!=s[n]){puts("1");return 0;}
	for(int i=2;i<n-1;++i)if(s[i]!=s[1]&&s[i+1]!=s[n]){puts("2");return 0;}
	puts("-1");
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define Fi(a,n) for(int i = a; i < n; i++)
#define Fd(n,a) for(int i = n; i >= a; i--)
#define all(a) a.begin(), a.end()
#define pb push_back
void solve(){
	int n;
	cin >> n;
	string s;
	cin >> s;
	if (s[0] != s[n-1]){
		cout << 1;
		return;
	}
	if (n <= 3)
		cout << -1;
	else{
		vector<int> a(n , 0);
		for (int i = 1; i<n; i++){
			if (s[i] != s[0])
				a[i] = a[i-1] + 1;
		}
		if (a[n-1]!=0)
			cout << 2;
		else{
			int m = 0, c = 0;
			for (int i = 0; i<n; i++){
				if (a[i] == 1)
					c++;
				m = max(m, a[i]);
			}
			if (m > 1)
				cout << 2;
			else{

				cout << -1;
			}
		}
	}
}

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


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

#define IOS ios::sync_with_stdio(0); cin.tie(0);
#define endl "\n"
#define int long long

int32_t main()
{
	IOS;

	int a, b, c;
	cin >> a >> b >> c;

	if (a * a + b * b < c * c) {
		cout << "Yes";
	} else {
		cout << "No";
	}

	return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n';
const ll nmax = 1000000007;

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll a, b, c;
    cin >> a >> b >> c;

    ll ans = 0;
    if(a == b){
        ans = c;
    }else if(b == c){
        ans = a;
    }else if(c == a){
        ans = b;
    }

    cout << ans << endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main()
{

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

  int tsc=1;
 //cin>>tsc;
  while(tsc--){
    int t,n;
    cin>>t>>n;
    int a=(n*100+t-1)/(t);
    cout<<a+n-1;

cout<<endl;}}

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

// #include <atcoder/all>
// using namespace atcoder;
// using mint = modint1000000007;
// using mint2 = modint998244353;

typedef int64_t Int;
#define all(x) (x).begin(), (x).end()

const double EPS = 1e-10;
const Int INF = 1e18;
const int inf = 1e9;
const Int mod = 1e9+7;
//const Int mod = 998244353;

typedef struct {
    int64_t to, weight;
} edge;

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

template<class T>
istream &operator>>(istream &is, vector<T> &v) {
    for (auto &e : v) {
        is >> e;
    }
    return is;
}

bool print_space_enable = false;
void print() {
    std::cout << '\n';
    print_space_enable = false;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    if (print_space_enable) std::cout << " ";
    std::cout << fixed << setprecision(15) << head;
    print_space_enable = true;
    print(std::forward<Tail>(tail)...);
}

template<typename T>
void print(vector<T> v) {
    for (size_t i = 0; i < v.size(); i++) {
        if (i > 0) std::cout << " ";
        std::cout << v[i];
    }
    std::cout << '\n';
}

template<class T>
vector<T> make_vec(size_t n, T val) {
    return vector<T>(n, val);
}

template<class... Ts>
auto make_vec(size_t n, Ts... ts) {
    return vector<decltype(make_vec(ts...))>(n, make_vec(ts...));
}

bool is_overflow(Int a, Int b) {
    return a > INF / b;
}

void solve() {
    Int t, n;
    cin >> t >> n;
    n *= 100;
    double a = (n - 1) / t;
    double b = a * (100.0 + (double)t) / 100.0;
    Int res = 1 + floor(b);
    print(res);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
    //Int _t; cin >> _t; while (_t--) solve();
    return 0;
}


#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#ifdef local
#define safe cerr<<__PRETTY_FUNCTION__<<" line "<<__LINE__<<" safe\n"
#define pary(a...) danb(#a, a)
#define debug(a...) qqbx(#a, a)
template <typename ...T> void qqbx(const char *s, T ...a) {
    int cnt = sizeof...(T);
    ((std::cerr << "\033[1;32m(" << s << ") = (") , ... , (std::cerr << a << (--cnt ? ", " : ")\033[0m\n")));
}
template <typename T> void danb(const char *s, T L, T R) {
    std::cerr << "\033[1;32m[ " << s << " ] = [ ";
    for (int f = 0; L != R; ++L)
        std::cerr << (f++ ? ", " : "") << *L;
    std::cerr << " ]\033[0m\n";
}
#else
#define debug(...) ((void)0)
#define safe ((void)0)
#define pary(...) ((void)0)
#endif // local
#define all(v) begin(v),end(v)
#define pb emplace_back
#define get_pos(u,x) int(lower_bound(all(u),x)-begin(u))

using namespace std;
using ll = int_fast64_t;
const int inf = 1e9;
const int mod = 1000000007;
const ll INF = 1e18;
const int maxn = 200025;

struct Fenwick {
    ll b[maxn];
    void add(int p, int d) {
        for (++p; p < maxn; p += p & -p)
            b[p] += d;
    }
    ll query(int p) {
        ll r = 0;
        for (++p; p > 0; p -= p & -p)
            r += b[p];
        return r;
    }
} cnt_a, cnt_b, sum_a, sum_b;

signed main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    int n, m, q;
    cin >> n >> m >> q;
    vector<tuple<int,int,int>> Qs(q);
    vector<int> u;
    u.pb(0);
    for (auto &[t, x, y]: Qs) cin >> t >> x >> y, u.pb(y), --x;
    sort(all(u)), u.erase(unique(all(u)), u.end());
    vector<int> a(n), b(m);

    auto calc = [&](int val, Fenwick &cnt, Fenwick &sum) {
        int pos = get_pos(u, val);
        return val * cnt.query(pos - 1) + (sum.query(maxn - 2) - sum.query(pos - 1));
    };
    ll ans = 0;
    cnt_a.add(get_pos(u, 0), n);
    cnt_b.add(get_pos(u, 0), m);
    for (auto [t, x, y]: Qs) {
        if (t == 1) {
            cnt_a.add(get_pos(u, a[x]), -1);
            sum_a.add(get_pos(u, a[x]), -a[x]);
            ans -= calc(a[x], cnt_b, sum_b);
            a[x] = y;
            ans += calc(a[x], cnt_b, sum_b);
            cnt_a.add(get_pos(u, a[x]), 1);
            sum_a.add(get_pos(u, a[x]), a[x]);
        } else {
            cnt_b.add(get_pos(u, b[x]), -1);
            sum_b.add(get_pos(u, b[x]), -b[x]);
            ans -= calc(b[x], cnt_a, sum_a);
            b[x] = y;
            ans += calc(b[x], cnt_a, sum_a);
            cnt_b.add(get_pos(u, b[x]), 1);
            sum_b.add(get_pos(u, b[x]), b[x]);
        }
        cout << ans << '\n';
    }
}


#include<bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// template<typename T>
// using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define ll           long long
#define rep(i,j,n)   for(ll i=j;i<n;i++)
#define _rep(i,n)   for(ll i=n-1;i>=0;i--)
#define vec          vector<ll>
#define pb           push_back
#define eb           emplace_back
#define pairs        pair<ll,ll>
#define f            first
#define s            second
#define all(v)       v.begin(),v.end()
#define srt(v)       sort(v.begin(),v.end())
#define mem(a,b)     memset(a,b,sizeof(a))
#define fast         ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define SZ(a)        (int)a.size()
const int N = 21;

ll n, a[N];
ll ans = 1e18;

vec v;
void solve(ll i, ll val, ll xors) {
	if(i == n) {

		ll temp = 0;

		ans = min(ans, xors^val);
		return;
	}

	solve(i+1, val|a[i], xors);

	solve(i+1, a[i], xors^val);
}

int Main()
{
	cin>>n;

	rep(i,0,n) {
		cin>>a[i];
	}

	solve(0, 0, 0);

	cout<<ans;
	return 0;
}

int main()
{
	  int queries=1;
	  // cin>>queries;
	  while(queries--)
	  {
	    Main();
	  }
}

#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <unordered_set>
#define ll long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define P pair<ll, ll>
using namespace std;

int n;
vector<vector<int> > to;
vector<int> c, ans;
multiset<int> ms;

void dfs(int now = 0, int p = -1){
  for(auto& next: to[now]){
    if(next == p) continue;
    if(ms.find(c[next]) == ms.end()) ans.push_back(next);
    ms.insert(c[next]);
    dfs(next, now);
    ms.erase(ms.find(c[next]));
  }
}

int main(){
  cin >> n;
  c.resize(n);
  to.resize(n);
  rep(i, n) cin >> c[i];
  rep(i, n-1){
    int a, b; cin >> a >> b;
    a--; b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  ms.insert(c[0]);
  ans.push_back(0);
  dfs();
  sort(ans.begin(), ans.end());
  for(auto& e: ans){
    cout << e+1 << endl;
  }
  return 0;
}


#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")

#define f(i,a,b) for(ll  i = a; i < (ll) b ; i++ )
#define af(i,a,b) for(ll i = a; i >= (ll) b ; i--)
#define rep(i,a,b,k) for(ll  i = a; i < (ll) b ; i+= k )
#define arep(i,a,b,k) for(ll i = a; i >= (ll) b ; i-= k)
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(), a.end()
#define sz(a) (ll) a.size()
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ller   ios::sync_with_stdio(false);cin.tie(0)

// policy-based

using namespace std;

typedef long long ll; // ll or ll
typedef long double ld;
typedef pair<ll,ll> ii ;
typedef vector<ll>  vi ;
typedef vector<ii> vii ;

const ll MAX = 2e6 + 20;
const ll mod = 1e9 + 7;
const ll inf = 1e13;

ll d[MAX],d1[MAX],d2[MAX];
int main(){
	fastio;
	f(i,1,MAX){
		rep(j,i,MAX,i) d[j]++;
	}
	f(i,1,MAX){
		rep(j,i,MAX,i) d1[j]+=d[i];
	}
	f(i,1,MAX) d1[i] += d1[i-1];
	ll k;
	cin >> k;
	cout << d1[k] << endl;
	return 0;
}

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

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

    int n=s.size(),cnt=0,zero=0;
    str=s;
    reverse(str.begin(),str.end());
    vector<char>v;

    for(int i=n-1; i>=0; i--)
    {
        if(s[i]=='0')
        {
            zero++;
            v.push_back(s[i]);
        }
        else
        break;
    }

    for(int i=0; i<n; i++)
    {
        v.push_back(s[i]);
    }

    for(int i=0, j=v.size()-1; j>=i; i++,j--)
    {
        if(v[i]==v[j])
        {
            cnt++;
        }
    }

    if((s==str) || (zero>0 && (v.size()+1)/2==cnt))
    cout<<"Yes"<<endl;

    else
    cout<<"No"<<endl;

    return 0;
}


//雪花飄飄北風嘯嘯
//天地一片蒼茫

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ii,ll>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << " is " << x << endl

#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define lb lower_bound
#define up upper_bound

#define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()

#define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
//change less to less_equal for non distinct pbds, but erase will bug

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

int n,m;
int u[2005];
int v[2005];
char c[2005];

vector<ii> al[1005][1005];

bool adj[1005][1005];
int w[1005][1005];
queue<ii> q;

int ans=1e9;

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin.exceptions(ios::badbit | ios::failbit);

	cin>>n>>m;
	rep(x,0,m) cin>>u[x]>>v[x]>>c[x],adj[u[x]][v[x]]=adj[v[x]][u[x]]=true;
	rep(x,m,2*m) u[x]=v[x-m],v[x]=u[x-m],c[x]=c[x-m];

	rep(x,0,2*m) rep(y,0,2*m) if (c[x]==c[y]){
		al[u[x]][u[y]].pub(ii(v[x],v[y]));
	}

	memset(w,63,sizeof(w));
	w[1][n]=0;
	q.push(ii(1,n));

	int a,b;
	while (!q.empty()){
		tie(a,b)=q.front();
		q.pop();

		if (a==b) ans=min(ans,w[a][b]*2);
		else if (adj[a][b]) ans=min(ans,w[a][b]*2+1);

		int c,d;
		for (auto &it:al[a][b]){
			tie(c,d)=it;
			if (w[c][d]>1e9){
				w[c][d]=w[a][b]+1;
				//cout<<"from: "<<a<<"-"<<b<<" to: "<<c<<"-"<<d<<endl;
				q.push(ii(c,d));
			}
		}
	}

	if (ans==1e9) cout<<"-1"<<endl;
	else cout<<ans<<endl;
}

#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
const int INF = INT_MAX / 3;

int dp[1 << 17][17];

void solve() {
    int N;
    cin >> N;
    vi X(N), Y(N), Z(N);
    rep(i, N) {
        cin >> X[i] >> Y[i] >> Z[i];
    }
    rep(S, 1 << N)rep(i, N)dp[S][i] = INF;
    dp[1][0] = 0;
    rep(S, 1 << N) {
        rep(i, N) {
            rep(j, N) {
                int d = abs(X[i] - X[j]) + abs(Y[i] - Y[j]) + max(0, Z[j] - Z[i]);
                smin(dp[S | 1 << j][j], dp[S][i] + d);
            }
        }
    }
    cout << dp[(1 << N) - 1][0] << endl;
}

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


#include <bits/stdc++.h>
using namespace std;
int q, n;
map<int, int> cnt;

void increase(map<int, int>& cnt, int x) {
	if (cnt.find(x) == cnt.end())
		cnt.insert(make_pair(x, 0));
	cnt[x]++;
}

int main() {
	cin >> q;
	while (q--) {
		cnt.clear();
		cin >> n;
		for (int i = 1; i <= n; i++) {
			int x;
			cin >> x;
			increase(cnt, x);
		}
		if (n % 2 == 1)
			cout << "Second\n";
		else {
			bool pare = true;
			for (pair<int, int> c : cnt)
				if (c.second % 2 == 1)
					pare = false;
			if (pare)
				cout << "Second\n";
			else
				cout << "First\n";
		}
	}
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MAXN = 100005;

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

int n, a[MAXN];

void solve() {
	read(n);
	for (int i = 1; i <= n; ++i) {
		read(a[i]);
	}
	if (n & 1) {
		puts("Second");
	} else {
		sort(a + 1, a + n + 1);
		for (int i = 1; i <= n; i += 2) {
			if (a[i] ^ a[i + 1]) {
				puts("First"); return;
			}
		}
		puts("Second");
	}
}

int main() {
	int T; read(T);
	while (T--) {
		solve();
	}
	return 0;
}


// Problem: A - Tax Included Price
// Contest: AtCoder - AtCoder Regular Contest 118
// URL: https://atcoder.jp/contests/arc118/tasks/arc118_a
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// Author: abhidot

#include <bits/stdc++.h>
#define int long long
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define mod 1000000007 //998244353
#define lld long double
#define pii pair<int, int>
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=x; i<y; i++)
#define fill(a,b) memset(a, b, sizeof(a))
#define vi vector<int>
#define setbits(x) __builtin_popcountll(x)
#define w(x)  int x; cin>>x; while(x--)
using namespace std;
const long long N=200005, INF=2000000000000000000;

/*------------- Modular exponentiation -------------*/
int power(int a, int b, int p)
    {
        if(a==0)
        return 0;
        int res=1;
        a%=p;
        while(b>0)
        {
            if(b&1)
            res=(res*a)%p;
            b>>=1;
            a=(a*a)%p;
        }
        return res;
    }

/*------------- Sieve --------------*/
vector <int> prime;
bool is_composite[N];

void sieve (int n) {
	fill (is_composite, false);
	for (int i = 2; i < n; ++i) {
		if (!is_composite[i]) prime.push_back (i);
		for (int j = 0; j < prime.size () && i * prime[j] < n; ++j) {
			is_composite[i * prime[j]] = true;
			if (i % prime[j] == 0) break;
		}
	}
}

/*------------ Utitlity function ---------------*/
void print(bool n){
    if(n){
        cout<<"YES";
    }else{
        cout<<"NO";
    }
}

int32_t main()
{
    IOS;
    int t,n;
    cin>>t>>n;
    n--;
    set<int> s;
    for(int i=1;i<=100+t;i++){
    	s.insert(i);
    }
    for(int i=1;i<=100;i++){
    	int val = (100+t)*i/100;
    	if(s.find(val)!=s.end()) s.erase(val);
    }
    // cout<<s.size()<<"\n";
    int q = n/s.size();
    n%=s.size();
    int r=0;
    for(auto i:s){
    	// cout<<i<<" ";
    	if(n<0) break;
    	if(n==0){
    		r = i;
    		break;
    	}else{
    		n--;
    	}
    }
    cout<<(100+t)*q + r<<"\n";
}

// Written by abhidot

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

long long T, N;

void read() {
    cin >> T >> N;
}

void work() {
    vector<pair<int, int> > t;
    for (int i = 0; i < 100; ++i) {
        int a = i * (100 + T) / 100;
        int b = (i + 1) * (100 + T) / 100;

        if (a + 1 < b) {
            t.push_back(make_pair(i, a));
        }
    }

    long long v = 100 * ((N - 1) / T) + t[(N - 1) % T].first + 1;
    cout << v * (100 + T) / 100 - 1 << endl;
}

int main() {
    read();
    work();
    return 0;
}


#include <bits/stdc++.h>
#define clr(x) memset(x,0,sizeof(x))
#define For(i,a,b) for (int i=(a);i<=(b);i++)
#define Fod(i,b,a) for (int i=(b);i>=(a);i--)
#define fi first
#define se second
#define kill _z_kill
#define y0 _z_y0
#define y1 _z_y1
#define x0 _z_x0
#define x1 _z_x1
#define pb push_back
#define mp(x,y) make_pair(x,y)
using namespace std;
typedef long long LL;
typedef unsigned long long ull;
typedef unsigned uint;
typedef long double LD;
typedef vector <int> vi;
typedef pair <int,int> pii;
void enable_comma(){}
string tostring(char c){
	string s="";
	s+=c;
	return s;
}
string tostring(string s){
	return "\""+s+"\"";
}
string tostring(const char *c){
	return tostring((string)c);
}
string tostring(long long x){
	if (x<0)
		return "-"+tostring(-x);
	if (x>9)
		return tostring(x/10)+tostring(char('0'+x%10));
	else
		return tostring(char('0'+x));
}
string tostring(int x){
	return tostring((long long)x);
}
string tostring(unsigned long long x){
	if (x>9)
		return tostring((long long)(x/10))+tostring(char('0'+x%10));
	else
		return tostring(char('0'+x));
}
string tostring(unsigned x){
	return tostring((long long)x);
}
string tostring(double x){
	static char res[114];
	sprintf(res,"%lf",x);
	string s=tostring(res);
	return s.substr(1,(int)s.size()-2);
}
string tostring(long double x){
	return tostring((double)x);
}
template <class A,class B> string tostring(pair <A,B> p){
	return "("+tostring(p.fi)+","+tostring(p.se)+")";
}
template <class T> string tostring(T v){
	string res="";
	for (auto p : v)
		res+=(res.size()?",":"{")+tostring(p);
	return res.size()?res+"}":"{}";
}
template <class A> string tostring(A* a,int L,int R){
	return tostring(vector <A>(a+L,a+R+1));
};
template <class A> string tostring(A a,int L,int R){
	return tostring(a.data(),L,R);
}
string tostrings(){
	return "";
}
template <typename Head,typename... Tail>
string tostrings(Head H,Tail... T){
	return tostring(H)+" "+tostrings(T...);
}
#define User_Time ((double)clock()/CLOCKS_PER_SEC)
#ifdef zzd
	#define outval(x) cerr<<#x" = "<<tostring(x)<<endl
	#define outvals(...) cerr<<"["<<#__VA_ARGS__<<"]: "<<\
								tostrings(__VA_ARGS__)<<endl
	#define outtag(x) cerr<<"--------------"#x"---------------"<<endl
	#define outsign(x) cerr<<"<"#x">"<<endl
	#define outarr(a,L,R) cerr<<#a"["<<(L)<<".."<<(R)<<"] = "<<\
								tostring(a,L,R)<<endl
#else
	#define outval(x) enable_comma()
	#define outvals(...) enable_comma()
	#define outtag(x) enable_comma()
	#define outsign(x) enable_comma()
	#define outarr(a,L,R) enable_comma()
#endif
#ifdef ONLINE_JUDGE
	#ifdef assert
		#undef assert
	#endif
	#define assert(x) (!(x)?\
			cout<<"Assertion failed!"<<endl<<\
			"function: "<<__FUNCTION__<<endl<<\
			"line: "<<__LINE__<<endl<<\
			"expression: "<<#x<<endl,exit(3),0:1)
#endif
LL read(){
	LL x=0,f=0;
	char ch=getchar();
	while (!isdigit(ch))
		f=ch=='-',ch=getchar();
	while (isdigit(ch))
		x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return f?-x:x;
}
template <class T> void ckmax(T &x,const T y){
	if (x<y)
		x=y;
}
template <class T> void ckmin(T &x,const T y){
	if (x>y)
		x=y;
}
//int Pow(int x,LL y){
////	y=(y%(mod-1)+(mod-1))%(mod-1);
//	int ans=1;
//	for (;y;y>>=1,x=(LL)x*x%mod)
//		if (y&1)
//			ans=(LL)ans*x%mod;
//	return ans;
//}
//void Add(int &x,int y){
//	if ((x+=y)>=mod)
//		x-=mod;
//}
//void Del(int &x,int y){
//	if ((x-=y)<0)
//		x+=mod;
//}
//int Add(int x){
//	return x>=mod?x-mod:x;
//}
//int Del(int x){
//	return x<0?x+mod:x;
//}
//int md(LL x){
//	return (x%mod+mod)%mod;
//}
int main(){
	LL n=read();
	LL ans=n;
	LL v=n+1;
	LL L=2,R=2e9;
	while (L<=R){
		LL mid=(L+R)>>1;
		if (mid*(mid+1)/2<=v)
			L=mid+1,ans=n-mid+1;
		else
			R=mid-1;
	}
	cout<<ans<<endl;
	return 0;
}

#include <bits/stdc++.h>
#include <string>
#define MAX 100007
#define scn1(a) scanf("%d", &a);
#define scn2(a, b) scanf("%d %d", &a, &b);
#define scn3(a, b, c) scanf("%d %d %d", &a, &b, &c);
#define lscn1(a) scanf("%lli", &a);
#define lscn2(a, b) scanf("%lli %lli", &a, &b);
#define lscn3(a, b, c) scanf("%lli %lli %lli", &a, &b, &c);
#define prnt(a) printf("%d\n", a);
#define forr(i, a, n) for(int i=a;i<n;i++)
#define nl puts("");
#define PB push_back
#define enl cout << "\n";
#define CHK(a) cout << (#a) << " = " << (a) << endl;
typedef long long int ll;
using namespace std;
void arraychk(int a[],int n) {for(int i=0;i<n;i++)cout<<a[i]<<" ";enl;}
#define LOOPCHK(a, n) arraychk(a, n);

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll tt=1;
    // cin >> tt;
    for(int cse=1; cse<=tt; cse++)

    {
        ll i=0, j=0, k=0, l=0, m=0,
        n=0, x=0, y=0, ans=0, sum=0;

        cin >> n;
        m = sqrt( n+1 );
        while( m*m + m <= 2*(n+1) ) m++;
        m--;
        // cout << "Case " << cse <<  ":";
        cout << n-m+1 << endl;
    }
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
#include <string>
#include <bits/stdc++.h>
#include <queue>
using namespace std;

/*
int main(){
    long long R,X,Y;
    cin >> R >> X >> Y;
    long long kyori = sqrt(pow(X,2) + pow(Y,2));
    long ans = kyori/R;
    if(pow(R*ans,2) < pow(X,2) + pow(Y,2)){
        ans++;
    }
    cout << ans << endl;
    return 0;
}
*/

int main(){
    long long R,X,Y;
    cin >> R >> X >> Y;
    long long kyori = pow(X,2) + pow(Y,2);
    long ans = 0;
    if(R*R >  kyori){
        cout << 2 << endl;
        return 0;
    }
    while(pow(R*ans,2) < kyori){
        ans++;
    }
    cout << ans << endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> P;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define print(x) cout << x << endl
#define all(v) (v).begin(),(v).end()
#define YN(ok) print((ok ? "YES" : "NO"))
#define yn(ok) print((ok ? "Yes" : "No"))
#define decimal(n) setprecision(30) << n

#define Arrays_toString(v) rep(o,(v).size()){cout<<v[o]<<", ";if(o==(v).size()-1){cout<<endl;}}
template<class T> void que_toString(queue<T> q){while(q.size()){cout<<q.front()<<", ";q.pop();if(q.empty()){cout<<endl;}}}

int main(void){
    int n, m, k;
    cin >> n >> m >> k;
    vi v(k);
    rep(i, k) cin >> v[i];

    // ans:
    // マス0 → Nまですごろくする時、サイコロを振る回数の期待値は？
    // (サイコロの目は1～Mで等確率)
    // (「ふりだしに戻る」マスもある)

    // how:
    // 期待値DPする。
    // (点0から点Nに行くのに貼る辺の本数の期待値は？と同値)
    // 例えば6まで出るならiの期待値は1/6 * (i+1, i+2, ... i+6) + 1

    // DAGでない(ループがある)DPなので、dp[地雷] = dp[0] = xとして進める。
    // dp[i] = ax + bの形でデータを持つ。(a = dp[i][0], b = dp[i][1])
    // -> dp[0] = a * x(=dp[0]) + b
    // -> dp[0] = b / (1 - a)

    // dp[i]: マスiからゴールに行くまでに振る回数の期待値
    vector<vector<double>> dp(n+1+m, vector<double>(2));
    for (int vv : v) {
        dp[vv][0] = 1;
        dp[vv][1] = 0;
    }

    // sum: 区間長mのdpのsum
    vector<double> sum(2);
    for (int i = n+m-1; i >= n; i--) {
        sum[0] += dp[i][0];
        sum[1] += dp[i][1];
    }

    for (int i = n-1; i >= 0; i--) {
        if (dp[i][0] != 1) {
            dp[i][0] = sum[0] / m;
            dp[i][1] = sum[1] / m + 1;
        }

        // update sum
        sum[0] -= dp[i+m][0];
        sum[1] -= dp[i+m][1];
        sum[0] += dp[i][0];
        sum[1] += dp[i][1];
    }
    // for (auto dpi : dp) Arrays_toString(dpi);

    // x = dp[0][0] * x + dp[0][1]
    // -> dp[0][1] / (1 - dp[0][0]) = x
    double res = -1;
    if (dp[0][0] != 1) res = dp[0][1] / (1 - dp[0][0]);
    if (res > 1e12) res = -1;
    print(decimal(res));
}


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

#define pb push_back
#define mkp make_pair
#define pf push_front
#define ff first
#define ss second
// #define endl "\n"
#define lpstl(i,v) for(auto &i: v)
#define all(a) a.begin(),a.end()
#define rall(x) (x).rbegin(),(x).rend()
#define sz(a) (ll)(a.size())
#define tr(container, it) \
for(auto it = container.begin(); it != container.end(); ++it)

//containers
#define ii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vll vector<ll>
#define vld vector<ld>
#define vii vector<ii>
#define vpll vector<pll>
#define pq priority_queue
#define minpq priority_queue <int, vector<int>, greater<int>>

const ll init = 1e9+7;
const ll N = 1e5+7;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ll n; cin>>n;
	ll sum=0;
	while(n--){
		ll a,b; cin>>a>>b;
		sum += ((a+b)*(b-a+1))/2;
	}
	cout<<sum<<endl;

    return 0;
}

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(m);
  vector<int> b(m);
  rep(i,m) {cin >> a.at(i); cin >> b.at(i);}
  int k;
  cin >> k;
  vector<int> c(k);
  vector<int> d(k);
  rep(i,k) {cin >> c.at(i); cin >> d.at(i);}
  int ans = 0;
  for (int tmp = 0; tmp < (1 << k); ++tmp){
    bitset<16> bit(tmp);
    vector<int> bkt(105);
    int accc = 0;
    rep(i, k){
      if (bit.test(i)) bkt.at(d.at(i))++;
      else bkt.at(c.at(i))++;
    }
    rep(i, m){
      if (bkt.at(b.at(i)) > 0 && bkt.at(a.at(i))>0) accc++;
    }
    ans = max(ans, accc);
  }
  cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

int n;
int main() {
	scanf("%d",&n);
	for (int i=1;i<=n;i++) {
		int cc=1;
		int x=i;
		for (int j=2;j*j<=x;j++) while (x%j==0) x/=j,cc++;
		if (x!=1) cc++;
		printf("%d ",cc);
	}
	puts("");
}

#include<bits/stdc++.h>
using namespace std;
#define int     long long
vector<int> primeFactors(int n)
{
    vector<int>ans;
    // Print the number of 2s that divide n
    while (n % 2 == 0)
    {
        ans.push_back(2);
        n = n/2;
    }

    // n must be odd at this point. So we can skip
    // one element (Note i = i +2)
    for (int i = 3; i <= sqrt(n); i = i + 2)
    {
        // While i divides n, print i and divide n
        while (n % i == 0)
        {
            ans.push_back(i);
            n = n/i;
        }
    }

    // This condition is to handle the case when n
    // is a prime number greater than 2
    if (n > 2)
        ans.push_back(n);
    return ans;
}
int32_t main(){
    int n;cin>>n;
    vector<int>ans;
    cout<<1<<' ';
    for(int i=2;i<=n;i++){
        cout<<primeFactors(i).size()+1<<' ';
    }

    return 0;
}


#include <bits/stdc++.h>
#include <string>
#include <cmath>
#include <sstream>
#include <unordered_map>
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORD(i, a, b) for(ll i = (a-1); i >= (b); i--)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define ff first
#define ss second
#define spre cout<<fixed<<setprecision(15);
typedef long long int ll;
using namespace std;
//ll mod=67280421310721;
ll mod=998244353;
// ll mod=1000000007;
ll INF=1e18;
ll dp[6005][3005];
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int test=1;
	while(test--)
	{
		FOR(i,0,3000)
		{
			ll a=0;
			FOR(j,1,6000)
			{
				if(i==0)
				{
					dp[j][i]=1;
					continue;
				}
				if((i-j)>=0 && (2*j)<6000)
				{
					a+=dp[2*j][i-j];
					a%=mod;
				}
				dp[j][i]=a;
			}
		}
		int n,k;
		cin>>n>>k;
		cout<<dp[k][n-k];
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
string ans[20];
void output();
void init();
bool yokoni_dekirudake_umeru();
void yokoni_umeru(int,int);
double get_score();
int randomToSeisu(double,int);
double randxorsyosu();
void ten_umeru();
int n,m;
int used_m;
string next_s();
vector<string> s;
double now_max_score = 0;
int main(){ //2,3は無視でいいんじゃないか？
    init();
    bool filled = false;
    while(used_m < m && !filled){
        filled = yokoni_dekirudake_umeru();
    }
    ten_umeru();

    output();

}

void ten_umeru(){
    for(int i = 0 ; i < n ; i++){
        for(int j = 0 ; j < n ; j++){
            if(ans[i][j] == '.')
            ans[i][j] = ('A' + randomToSeisu(randxorsyosu(),8));
        }
    }
}
bool yokoni_dekirudake_umeru(){
    bool filled = true;
    for(int i = 0 ; i < n ; i++){
        for(int j = 0 ; j < n ; j++){
            if(ans[i][j] == '.' && (j + (int)(next_s().size()) <= n + 1)){ //tyuui koko
                yokoni_umeru(i,j);
                filled = false;
            }
        }
    }
    return filled;
}
void yokoni_umeru(int i , int j){
    for(int k = 0 ; k < (int)next_s().size() ; k++){
        ans[i][j+k] = next_s()[k];
    }
    used_m++;
}
string next_s(){
    return s[used_m];
}

void init(){
    cin >> n >> m;
    for(int i = 0 ; i < 20 ; i++){
        for(int j = 0 ; j < 20 ; j++){
            if(j==0)ans[i] = "";

            ans[i] += ".";
        }
    }

    for(int i = 0 ; i < m ; i++){
        string st;
        cin >> st;
        s.push_back(st);
    }

    sort(s.begin(),s.end());
    reverse(s.begin(),s.end());
}
void output(){
    for(int i = 0 ; i < 20 ; i++){
        cout << ans[i] << endl;
    }
}
double get_score(){
    bool ok[m];
    double counter = 0;
    fill(ok,ok+m,false);
    for(int i = 0 ; i < n ; i++){
        string te = ans[i] + ans[i];
        for(int j = 0 ; j < m ; j++){
            if(ok[j])continue;
            for(int t = 0 ; t < n ; t++){
                for(int r = 0 ; r < s[j].size() ; r++){
                    if(te[t+r] != s[j][r])continue;
                    if(r == (int)(s[j].size() - 1)){
                        ok[j] = true;
                        counter++;
                        break;
                    }
                }
                if(ok[j])break;
            }
        }
    }
    for(int i = 0 ; i < n ; i++){
        string te_k = "";
        for(int j = 0 ; j < n ; j++){
            te_k += ans[j][i];
        }
        te_k += te_k;

        for(int h = 0 ; h < m ; h++){
            if(ok[h])continue;
            for(int t = 0 ; t < n ; t++){
                for(int r = 0 ; r < s[h].size() ; r++){
                    if(te_k[t+r] != s[h][r])continue;
                    if(r == (int)(s[h].size() - 1)){
                        ok[h] = true;
                        counter++;
                        break;
                    }
                }
                if(ok[h])break;
            }
        }
    }
    return 1e8 * counter / (double)m;
}

unsigned int randxor()
{
    static unsigned int x=123456789,y=362436069,z=521288629,w=88675123;
    unsigned int t;
    t=(x^(x<<11));x=y;y=z;z=w; return( w=(w^(w>>19))^(t^(t>>8)) );
}
//0～1のランダムな小数を返す
double randxorsyosu(){
    return (double)(randxor()%UINT_MAX)/UINT_MAX;
}
//d(0~1)より0~i-1までの整数を得る
int randomToSeisu(double d , int i){
    return floor((double)i * d);
}

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <cmath>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <sstream>
#include <iomanip>
using namespace std;

using VI = vector <int>;
using VVI = vector <VI>;
using VVVI = vector <VVI>;
using VLL = vector <long long>;
using VVLL = vector <VLL>;
using UMI = unordered_map<int, int>;
using UMLL = unordered_map<long long, long long>;
using VS = vector <string>;

bool cmp(const string& a, const string& b) {
    if (a.size() != b.size()) {
        return a.size() < b.size();
    }

    return a < b;
}

int main() {
    int N;
    int M;

    cin >> N >> M;

    VS gene(M);
    for (int i = 0; i < M; ++i) {
        cin >> gene[i];
    }

    sort(gene.begin(), gene.end(), cmp);

    VS ans(N);
    int idx = 0;

    for (int i = 0; i < gene.size(); ++i) {
        if (ans[idx].size() + gene[i].size() < N) {
            ans[idx] += gene[i];
        } else {
            // fill in
            while (ans[idx].size() < N) {
                ans[idx] += ".";
            }
            ++idx;
        }

        if (idx == N) {
            break;
        }
    }

    for (int i = 0; i < N; ++i) {
        cout << ans[i] << endl;
    }

    return 0;
}


///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>
using namespace std;
#define     FAST        ios_base::sync_with_stdio(false);cin.tie(NULL)
#define     int 	    long long
#define 	pb 	        push_back
#define     pp          pop_back
#define 	mp 	        make_pair
#define 	pi 	        2*acos(0.0)
#define     scan(i)     scanf("%lld",&i)
#define     scann(i,j)  scanf("%lld%lld",&i,&j)
#define     print(i)    printf("%lld\n",i)
#define     printt(i,j) printf("%lld %lld\n",i,j)
#define     loop(i,n) 	for(int i = 0 ; i <n ; i++)
#define     loopp(i,n) 	for(int i = 1 ; i <n ; i++)
#define     rep(i,n)    for(int i=n-1;i>=0;i--)
#define     rev(v)      reverse(v.begin(),v.end())
#define     reset(a,b)  memset(a,b,sizeof(a))
#define 	vect 	    vector<int>
#define 	vec_it 	    vector<int>::reverse_iterator vi
#define     sorta(v)    sort(v.begin(),v.end())
#define     sortd(v)    sort(v.begin(),v.end(),greater<>())
#define     sorted(v)   is_sorted(v.begin(),v.end())
#define 	mapp 	    map<int,int>
#define     rmap        map<int,int,greater<>>m
#define 	pairr 	    pair<int,int>
#define 	sett	    set<int>
#define     rset        set<int,greater<>>s
#define 	set_it 	    set<int>::reverse_iterator si
#define     map_it      map<int,int> :: reverse_iterator mi
#define     digit(n)    floor(log10(n)+1)
#define 	yes 	    cout<<"YES"<<endl
#define 	no 	        cout<<"NO"<<endl
#define 	ff 	        first
#define 	ss 	        second
#define     mx          INT_MAX
#define     lmx         LLONG_MAX
#define     mn          INT_MIN
#define     lmn         LLONG_MIN
#define     inf         0x3f3f3f3f
#define     inff        10e18
#define     GCD         __gcd(a,b)
#define     LCM         (a/GCD)*b
template <typename T> T gcd(T a,T b){return (b==0)?a:gcd(b,a%b);}
template <typename T> T lcm(T a,T b) {return a*(b/gcd(a,b));}
int modulo (int a, int b) { return a >= 0 ? a % b : ( b - abs ( a%b ) ) % b; }

void solve()
{
   // freopen ("(input).txt" , "r",  stdin) ;
    string st,stt,str;
    int low=0,high=0;
    int l,r; char ch;
    int n,k,t,x,y,z,d=0,cnt=0,temp=0,sum=0,f=0,flag=0;
    cin>>n>>st ; vect v ,a ; sett s ; mapp m,mm ; pairr p ; stt="110";
    for(int i=0;i<100000;i++)
    {
        str+=stt;
    }
    sum=3*10000000000;
    if(n==1&&st[0]=='1')
        cout<<2*10000000000<<endl;
    else if(n==1&&st[0]=='1')
        cout<<10000000000<<endl;
    else if(n==2&&st[0]=='1'&&st[1]=='1'||n==2&&st[0]=='1'&&st[1]=='0')
        cout<<10000000000<<endl;
    else if(n==2&&st[0]=='0'&&st[1]=='1')
        cout<<10000000000-1<<endl;
    else if(str.substr(0,n)==st)
    {
        if(st[n-2]=='0'&&st[n-1]=='1')
            sum-=2;
        else if(st[n-2]=='1'&&st[n-1]=='1')
            sum--;
        sum-=(n-3);
        cout<<sum/3<<endl;
    }
    else if(str.substr(1,n)==st)
    {
        sum-=1;
        if(st[n-2]=='0'&&st[n-1]=='1')
            sum-=2;
        else if(st[n-2]=='1'&&st[n-1]=='1')
            sum--;
        sum-=(n-3);
        cout<<sum/3<<endl;
    }
    else if(str.substr(2,n)==st)
    {
        sum-=2;
        if(st[n-2]=='0'&&st[n-1]=='1')
            sum-=2;
        else if(st[n-2]=='1'&&st[n-1]=='1')
            sum--;
        sum-=(n-3);
        cout<<sum/3<<endl;
    }
    else
        cout<<0<<endl;

}

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

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
constexpr long long INF = 1e9+100;
constexpr long long LINF = 1e18+100;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const ll V = 1e10;

int main(){
    int n; string t; cin >> n >> t;
    if(t=="1")cout << V*2 << ln;
    else{
        if(t[0]=='0')t = "11" + t;
        else if(t.size()>=2 and t.substr(0, 2)=="10")t = "1" + t;

        if(t.size()%3==1){
            if(t.back()=='0'){
                cout << 0 << ln;
                return 0;
            }else t += "10";
        }else if(t.size()%3==2){
            if(t.substr(t.size()-2)=="11")t += "0";
            else{
                cout << 0 << ln;
                return 0;
            }
        }

        rep(i, t.size()){
            if(i%3==2 and t[i]!='0' or i%3!=2 and t[i]!='1'){
                cout << 0 << ln;
                return 0;
            }
        }
        ll res = V - t.size()/3 + 1;
        cout << res << ln;
    }
}


#include <bits/stdc++.h>
#define f(i,x,y) for(int i=x; i<=y; ++i)
#define fn(i,x,y) for(int i=x; i>=y; --i)
using namespace std;

int a[5], b, n, m;

int main()
{
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
	f(i,1,4) {cin >>a[i];}
	sort(a+1,a+4+1);
	if(a[1]+a[2]+a[3]==a[4] || a[1]+a[4]== a[3]+ a[2])
        cout <<"Yes"; else cout <<"No";
   return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main()
{
    std::vector<int> cookies(4);
    int total = 0;
    for (int i = 0; i < 4; ++i) {
        cin >> cookies[i];
        total += cookies[i];
    }

    int eat;
    bool flag = false;
    for (int bit = 0; bit < (1<<4); ++bit) {
        eat = 0;
        for (int i = 0; i <= 4; ++i) {
            if (bit & (1<<i)) {
                eat += cookies[i];
            }
        }

        if (total - eat == eat) {
            flag = true;
        }
    }

    if (flag) {
        cout << "Yes";
    } else {
        cout << "No";
    }

    return 0;
}


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

typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> order_set;
typedef long long  ll ;

#define     rep(i, begin, end)          for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define     what_is(x)                  cout << #x << " is " << x << endl;
// #define     endl                        '\n'
#define     fi                          first
#define     sec                         second
#define     pb                          push_back
#define     vi                          vector<int>
#define     vii                         vector<pair<int,int>>
#define 	fio 						ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define 	sz(x) 						(int)x.size()
#define 	all(x) 						begin(x), end(x)
void solve(){
    string str;
    cin>>str;
    string temp=str;
    sort(temp.rbegin(),temp.rend());
    string init="atcoder";
    if(temp<=init){cout<<-1<<endl;return;}
    if(str>init){cout<<0<<endl;return;}
    int ln=sz(str);
    int pos;
    for(int i=0;i<ln;i++){
        if(str[i]!='a'){pos=i;break;}
    }
    if(str[pos]>'t'){cout<<pos-1<<endl;return;}
    cout<<pos<<endl;return;

}
int main(){
    fio;
    int test;
    cin>>test;
    // test=1;
    while(test--){
        solve();
    }
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
int check(string &s)
{
    string ss="atcoder";
    if(s>ss)
    return 0;
    for(int i=1;i<s.size();i++)
    {
        if(s[i]>'t')
        return i-1;
        if(s[i]>'a')
        return i;
    }
    return -1;
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        string a;
        cin>>a;
        cout<<check(a)<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
using ll = long long;
using ld = long double;
const ll MOD = 1e9+7;
const ll INF=1LL<<60;
const string YYY="YES";
const string yyy="Yes";
const string NNN="NO";
const string nnn="No";
template<class T>void chmin(T& a,T b){
  if(a>b){
    a=b;
  }
}
template<class T>void chmax(T& a,T b){
  if(a>b){
    a=b;
  }
}
string rot13(string S){
  int a=S.size();
  for(int i=0;i<a;i++){
   if(S[i]=='a'){S[i]='n';continue;}
    if(S[i]=='b'){S[i]='o';continue;}
    if(S[i]=='c'){S[i]='p'; continue;}
    if(S[i]=='d'){S[i]='q'; continue;}
    if(S[i]=='e'){S[i]='r'; continue;}
    if(S[i]=='f'){S[i]='s'; continue;}
    if(S[i]=='g'){S[i]='t'; continue;}
    if(S[i]=='h'){S[i]='u'; continue;}
    if(S[i]=='i'){S[i]='v'; continue;}
    if(S[i]=='j'){S[i]='w'; continue;}
    if(S[i]=='k'){S[i]='x'; continue;}
    if(S[i]=='l'){S[i]='y'; continue;}
    if(S[i]=='m'){S[i]='z'; continue;}
    if(S[i]=='n'){S[i]='a'; continue;}
    if(S[i]=='o'){S[i]='b'; continue;}
    if(S[i]=='p'){S[i]='c'; continue;}
    if(S[i]=='q'){S[i]='d';continue;}
    if(S[i]=='r'){S[i]='e'; continue;}
    if(S[i]=='s'){S[i]='f'; continue;}
    if(S[i]=='t'){S[i]='g'; continue;}
    if(S[i]=='u'){S[i]='h'; continue;}
    if(S[i]=='v'){S[i]='i'; continue;}
    if(S[i]=='w'){S[i]='j'; continue;}
    if(S[i]=='x'){S[i]='k';continue;}
    if(S[i]=='y'){S[i]='l'; continue;}
    if(S[i]=='z'){S[i]='m'; continue;}
  }
  return S;
}
ll GD(ll num){//各桁の和
    ll digit=0;
    while(num!=0){
        digit+=num%10;
        num/=10;
    }
    return digit;
}
bool if_integer( ld x ){//整数判定
  return std::floor(x)==x;
}
bool if_prime(ll x){
  bool a=true;
  for(ll i=2;i*i<=x;i++){
   if(x%i==0){
    a=false;break;
   }
  }
  if(x==1)a=false;
  return a;
}
ll gcd(ll x, ll y)//最大公約数
{
   if (x%y == 0)
   {
       return(y);
   }
   else
   {
       return(gcd(y, x%y));
   }
}

ll lcm(ll x, ll y)//最小公倍数
{
   return x / gcd(x, y)*y ;
}
inline ll mod(ll a, ll m) {
    return (a % m + m) % m;
}
ll modPow(ll a, ll n, ll p) {
  if (n == 0) return 1; // 0乗にも対応する場合
  if (n == 1) return a % p;
  if (n % 2 == 1) return (a * modPow(a, n - 1, p)) % p;
  ll t = modPow(a, n / 2, p);
  return (t * t) % p;
}
ll extGCD(ll a, ll b, ll &x, ll &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll d = extGCD(b, a%b, y, x);
    y -= a/b * x;
    return d;
}
/////////////////////////
/////////////////////////
/////////////////////////
int main() {
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
      ll N ;cin >> N ;
  ll sum=0;
    vector<int> a(N);
  ll y=0;
    for (int i = 0; i < N; i++) {
        cin >> a[i];
      sum+=a[i];
    }
  sort(a.begin(), a.end());
  for(int i=0;i<N-1;i++){
   y+=a[i];
  }
  if(y<a[N-1]){
   cout<<a[N-1];return 0;
  }

  ll K=sum/2;
    // 二次元配列

      vector<vector<bool>> dp(N + 1, vector<bool>(K + 1, false));
    // 初期化
    for (int i = 0; i <= N; i++) {
        dp[i][0] = true;
    }
    // 更新
    for (int i = 0; i < N; i++) {
        for (int k = 0; k <= K; k++) {
            if (k - a[i] >= 0) dp[i + 1][k] = dp[i + 1][k] | dp[i][k - a[i]];
            dp[i + 1][k] = dp[i + 1][k] | dp[i][k];
        }
    }
      while(true){
      if (dp[N][K]) {
        cout << sum-K << endl;return 0;
    } else {
        K--;
    }
      }

}

# include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

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

#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define trav(a,x) for (auto& a : x)
#define uid(a, b) uniform_int_distribution<int>(a, b)(rng)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
#define UNIQUE(x) sort(all(x)), x.erase(unique(all(x)), x.end())

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

const int xn = 1e2 + 10;
const int sq = 320;
const int inf = 1e9 + 10;
const ll INF = 1e18 + 10;
const int mod = 1e9 + 7;//998244353;
const int base = 257;
const char nl = '\n';
bool ispow2(int i) { return i && (i & -i) == i; }

void solve() {

    int n; cin>>n;
    vector<int> t(n);
    FOR(i, 0, n) cin>>t[i];

    int s = 0;
    FOR(i, 0, n) {
        s += t[i];
    }

    vector<vector<bool> > dp(n+1, vector<bool>(s + 1, false));
    dp[0][0] = true;

    FOR(i, 0, n) {
        FOR(j, 0, s) {
            if(dp[i][j]) {
                dp[i + 1][j] = true;
                dp[i + 1][j + t[i]] = true;
            }
        }
    }

    int ans = s;

    FOR(i, 0, s) {
        if(dp[n][i]) {
            ans = min(ans, max(i, s - i));
        }
    }

    cout << ans;

    return;
}

int main(){
    ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
    int tc = 1; //cin>>tc;

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

    return 0;
}


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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a) accumulate(all(a), 0LL)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
int const inf = 1e9;
ll const INF = 1e18;

inline void ios_(){cin.tie(0); ios::sync_with_stdio(false);}
template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}

signed main(){
    int n, k, m;
    cin >> n >> k >> m;
    int score = 0;
    REP(i, n-1){
        int a;
        cin >> a;
        score += a;
    }
    int po = n*m - score;
    if(po > k){
        cout << -1 << endl;
    }else{
        cout << max(0, po) << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#define For(i, l, r) for (register int i = l, _r = r; i <= _r; ++i)
#define Ford(i, l, r) for (register int i = r, _l = l; i >= _l; --i)
using namespace std;
typedef long long ll;
#define pii pair<int, int>
#define mk make_pair
const int maxn = 105;

int n, k, mod, tp;
int dp[maxn][maxn * maxn * maxn];
ll ans;

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

int main()
{
    n = read(), k = read(), mod = read();
    tp = k * n * (n - 1) / 2;
    dp[0][0] = 1;
    For(i,1,n-1)
    {
        For(j,0,tp)
        {
            dp[i][j] = dp[i - 1][j];
            if(j>=i)
                dp[i][j] = (dp[i][j] + dp[i][j - i]) % mod;
        }
        Ford(j, i * (k + 1), tp)
            dp[i][j] = (dp[i][j] - dp[i][j - i * (k + 1)] + mod) % mod;
    }
    For(i,1,n)
    {
        ans = 0;
        For(j, 0, tp) ans = (ans + 1LL * dp[i - 1][j] * dp[n - i][j]) % mod;
        ans = (ans * (k + 1) - 1) % mod;
        printf("%lld\n", ans);
    }
}

#include<iostream>
using namespace std;
bool test = false;

int h[30][29];
int w[29][30];
int si,sj,ti,tj,a,response;
double e;
string ans;

void init(){
  for(int i=0;i<30;i++) for(int j=0;j<29;j++) scanf("%d",&h[i][j]);
  for(int i=0;i<29;i++) for(int j=0;j<30;j++) scanf("%d",&w[i][j]);
}

void writeL(int n){for(int i=0;i<n;i++) ans+="L";}
void writeR(int n){for(int i=0;i<n;i++) ans+="R";}
void writeU(int n){for(int i=0;i<n;i++) ans+="U";}
void writeD(int n){for(int i=0;i<n;i++) ans+="D";}

int main(){
  if(test) init();
  for(int i=0;i<1000;i++){
    if(test) cin >> si >> sj >> ti >> tj >> a >> e;
    else cin >> si >> sj >> ti >> tj;

    //printf("%d %d %d %d %d %lf\n",si,sj,ti,tj,a,e);
    ans = "";
    if(si<ti) writeD(ti-si);
    else if(ti<si) writeU(si-ti);
    if(sj<tj) writeR(tj-sj);
    else if(tj<sj) writeL(sj-tj);

    cout << ans << endl;
    if(!test) scanf("%d",&response);
  }
}


#include<cstdio>
#define mod 998244353
#define N 5001
#define M 51
using namespace std;
int n,m;
int stack[N];
long long f[M][N],jc[N],njc[N];
long long ksmi(long long x,long long y)
{
	long long total=1,ab=x,p=y;
	while (p)
	{
		if (p%2==1) total=total*ab%mod;
		ab=ab*ab%mod;
		p/=2;
	}
	return total;
}
long long C(int n,int m){
	return jc[n]*njc[m]%mod*njc[n-m]%mod;
}
int main()
{
	scanf("%d%d",&n,&m);
	int sm=m;
	int top=0;
	jc[0]=1;
	for (int i=1;i<=n;i++) jc[i]=jc[i-1]*i%mod;
	njc[n]=ksmi(jc[n],mod-2);
	for (int i=n-1;i>=0;i--) njc[i]=njc[i+1]*(i+1)%mod;
	for (int i=1;i<=n;i++)
	while (m!=0)
	{
		stack[++top]=m%2;
		m/=2;
	}
	f[0][0]=1;
	for (int i=1;i<=top;i++)
	{
		for (int j=0;j<=n;j++)
		{
			if (f[i-1][j]==0) continue;
			int cur=j%2;
			if (cur!=stack[i]) continue;
			for (int k=0;k<=n;k+=2)
				f[i][(j/2)+(k/2)]=(f[i][(j+k)/2]+f[i-1][j]*C(n,k)%mod)%mod;
		}
	}
	printf("%lld\n",f[top][0]);
}

#include<iostream>
#include<vector>
using namespace std;
const long long int MAX = 3000;
const long long int MOD = 1000000007;
int main(){
	long long int H,W,K=0;
	long long int sum,ans=0;
	vector<long long int> two;
	string S;
	bool F[MAX+2][MAX+2]={0};
	long long int M[MAX+2][MAX+2][4]={0};
	cin>>H>>W;
	for(int i=1;i<=H;i++){
		cin>>S;
		for(int j=1;j<=W;j++){
			F[i][j]=(S[j-1]=='.');
			K+=F[i][j];
		}
	}
	two.push_back(1);
	for(int i=1;i<=K;i++)two.push_back(two[i-1]*2%MOD);
	for(int i=1;i<=H;i++){
		for(int j=1;j<=W;j++){
			if(!F[i][j])continue;
			M[i][j][0]=(M[i][j-1][0]+1)*F[i][j-1];
			M[i][j][1]=(M[i-1][j][1]+1)*F[i-1][j];
		}
	}
	for(int i=H;i>=1;i--){
		for(int j=W;j>=1;j--){
			if(!F[i][j])continue;
			M[i][j][2]=(M[i][j+1][2]+1)*F[i][j+1];
			M[i][j][3]=(M[i+1][j][3]+1)*F[i+1][j];
		}
	}
	for(int i=1;i<=H;i++){
		for(int j=1;j<=W;j++){
			if(!F[i][j])continue;
			sum=1;
			for(int k=0;k<4;k++)sum+=M[i][j][k];
			ans+=(two[K]-two[K-sum])%MOD;
			ans=(ans%MOD+MOD)%MOD;
		}
	}
	cout<<ans;
	return 0;
}


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

int n;
vector<vector<int>> to;
vector<int> used, col, vs;

void dfs(int v){
	if(used[v]) return;

  	used[v] = 1;
  	vs.push_back(v);
  	for(int u : to[v]) dfs(u);
}

ll now;
void dfs2(int i){
	if(i == vs.size()){now++; return;}

  	int v = vs[i];
  	rep(c, 3){
    	col[v] = c;
      	bool ok = true;
      	for(int u : to[v]){
        	if(col[u] == c) ok = false;
        }
      	if(!ok) continue;
      	dfs2(i+1);
    }
  	col[v] = -1;
}

int main(){
	int m;
  	cin >> n >> m;
  	to = vector<vector<int>> (n);
  	rep(i, m){
    	int a, b;
      	cin >> a >> b;
     	a--; b--;

      	to[a].push_back(b);
        to[b].push_back(a);
    }

  	ll ans = 1;
  	used = vector<int> (n);
  	col = vector<int> (n, -1);

  	rep(i, n){
    	if(used[i]) continue;

      	ans *= 3;
      	vs = vector<int> ();
      	dfs(i);
      	col[vs[0]] = 0;
      	now = 0;
      	dfs2(1);
      	ans *= now;
    }

  	cout << ans << endl;
}

#include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

#define rep(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
using ll = long long int;
using P = pair<ll, ll>;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; debug_print(__VA_ARGS__); } while(false)
template<typename T, typename... Ts> void debug_print(const T &t, const Ts &...ts) { cerr << t; ((cerr << ", " << ts), ...); cerr << endl; }
#else
#define dump(...) do{ } while(false)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T> bool chmin(T &a, const T& b) { if (a > b) {a = b; return true; } return false; }
template<typename T> bool chmax(T &a, const T& b) { if (a < b) {a = b; return true; } return false; }
template<typename T, typename... Ts> void print(const T& t, const Ts&... ts) { cout << t; ((cout << ' ' << ts), ...); cout << '\n'; }
template<typename... Ts> void input(Ts&... ts) { (cin >> ... >> ts); }
template<typename T> istream &operator,(istream &in, T &t) { return in >> t; }
// clang-format on

class UnionFind {
public:
    vector<int> par;
    int N;
    UnionFind(int n) {
        par.resize(n, -1);
        N = n;
    }
    int Find(int n) {
        return par[n] < 0 ? n : par[n] = Find(par[n]);
    }
    bool Union(int x, int y) {
        x = Find(x);
        y = Find(y);
        if (x == y) return false;
        if (-par[x] > -par[y]) swap(x, y);
        par[y] += par[x];
        par[x] = y;
        N--;
        return true;
    }
    bool Same(int x, int y) {
        return Find(x) == Find(y);
    }
    int size(int x) {
        return -par[Find(x)];
    }
    int size() {
        return N;
    }
};

int popcount(ll bits) {
    bits = (bits & 0x5555555555555555LL) + (bits >> 1 & 0x5555555555555555LL);
    bits = (bits & 0x3333333333333333LL) + (bits >> 2 & 0x3333333333333333LL);
    bits = (bits & 0x0f0f0f0f0f0f0f0fLL) + (bits >> 4 & 0x0f0f0f0f0f0f0f0fLL);
    bits = (bits & 0x00ff00ff00ff00ffLL) + (bits >> 8 & 0x00ff00ff00ff00ffLL);
    bits = (bits & 0x0000ffff0000ffffLL) + (bits >> 16 & 0x0000ffff0000ffffLL);
    return (bits & 0x00000000ffffffffLL) + (bits >> 32 & 0x00000000ffffffffLL);
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, m;
    input(n, m);
    vector<P> edge(m);
    vector<ll> pow2(30, 1);
    rep(i, 1, 30) {
        pow2[i] = pow2[i - 1] * 2;
    }
    rep(i, 0, m) {
        int a, b;
        input(a, b);
        a--;
        b--;
        edge[i] = P(a, b);
    }
    int bits = 1 << n;
    ll ans = 0;
    rep(bit, 0, bits) {
        vector<bool> used(n, 0);
        rep(i, 0, n) {
            if ((bit >> i) & 1) {
                used[i] = true;
            }
        }
        UnionFind uf(2 * n), uf2(n);
        bool ok = true;
        for (auto [a, b] : edge) {
            if (used[a] && used[b]) {
                ok = false;
            } else if (used[a] || used[b]) {
                continue;
            } else {
                uf.Union(a, b + n);
                uf.Union(a + n, b);
                uf2.Union(a, b);
            }
        }
        for (auto [a, b] : edge) {
            if (!used[a] && !used[b]) {
                if (uf.Same(a + n, b + n)) {
                    ok = false;
                    break;
                }
            }
        }
        if (ok) {
            ans += pow2[uf2.size() - popcount(bit)];
        }
    }
    print(ans);
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define inf 1e9
#define linf 1e18
#define BASE 1000000
#define EPS 1e-10
#define PI acos(-1)
#define pii pair<int,int>
#define piii pair<int, pair<int,int>>
#define pli pair<long long, int>
#define pll pair<long long, long long>
#define pdi pair<double,int>
#define vi vector<int>
#define fi first
#define se second
#define ALL(x) (x).begin(), (x).end()
#define ms(x,val_add) memset(x, val_add, sizeof(x))
#define pb(x) push_back(x)
#define make_unique(x) sort(ALL(x)) ; x.erase( unique(ALL(x)), x.end()) ;
#define dbg(x) do { cout << #x << " = " << x << endl; } while(0)
#define mp(x, y) make_pair(x, y)
template<class T> bool ckmin(T& a, const T& b) {
	return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) {
	return a < b ? a = b, 1 : 0; }

bool exitInput = false;
int ntest = 1, itest = 1 ;

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

void addMod( ll &x, ll y, ll Mod )
{
	x = ( x + y % Mod ) % Mod;
}

ll modPow( ll x, ll p, ll Mod )
{
	if( p == 0 )
		return 1;
	ll r = modPow( x, p / 2, Mod );
	r = ( r * r ) % Mod;
	if( p & 1 )
		r = ( r * x ) % Mod;
	return r;
}

// copy BigInt from Um_nik
/* using Int = __int128;
Int gcd( Int x, Int y )
{
	return y == 0 ? x : gcd( y, x % y );
}
void printInt( Int x )
{
	if ( x == 0 )
	{
		cout << 0; //printf("0");
		return;
	}
	vector<int> w;
	while( x > 0 )
	{
		w.push_back( x % 10 );
		x /= 10;
	}
	reverse( ALL( w ) );
	for ( int z : w )
		cout << z; //printf("%d", z);
}
void printAns(Int p, Int q) {
	Int g = gcd(p, q);
	p /= g;
	q /= g;
	printInt(p);
	cout << "/";
	printInt(q);
	cout << endl;
} */

ll gcd(ll p, ll q)
{
	return __gcd(p, q);
}

/*** CODE START HERE ***/
const ll Mod = 1000000007LL;
const int maxn = 800 + 5;

int n, K, a[maxn][maxn];
int b[maxn][maxn], sum[maxn][maxn];

int getsum(int i, int j, int r, int c)
{
    return sum[r][c] - sum[r][j-1] - sum[i-1][c] + sum[i-1][j-1];
}

bool isok(int h)
{
    static const int need = K*K / 2 + (K & 1);
    for(int i = 1; i <= n; ++i)
    {
        for(int j = 1; j <= n; ++j)
        {
            b[i][j] = a[i][j] <= h;
            sum[i][j] = sum[i-1][j] + sum[i][j-1] + b[i][j] - sum[i-1][j-1];
        }
    }
    for(int i = 1; i + K - 1 <= n; ++i)
    {
        for(int j = 1; j + K - 1 <= n; ++j)
        {
            int r = i + K - 1, c = j + K - 1;
            if( getsum(i, j, r, c) >= need )
            {
                return true;
            }
        }
    }
    return false;
}

int main()
{
#ifdef HOME
	freopen( "input.txt", "r", stdin );
	//freopen( "output.txt", "w", stdout );
#endif // HOME

	ios::sync_with_stdio( false );
	cin.tie( 0 );
	cout.tie( NULL );
	cout << setprecision( 10 );
	cout << fixed;

	//cin >> ntest;

	for( itest = 1; itest <= ntest; ++itest )
	{
        cin >> n >> K;

        int mi = inf, mx = 0;
        for(int i = 1; i <= n; ++i)
        {
            for(int j = 1; j <= n; ++j)
            {
                cin >> a[i][j];
                ckmin(mi, a[i][j]);
                ckmax(mx, a[i][j]);
            }
        }
        int lo = mi, hi = mx, mid, res = -1;
        while(lo <= hi)
        {
            mid = (lo + hi)>>1;
            if(isok(mid))
            {
                res = mid;
                hi = mid - 1;
            }
            else lo = mid + 1;
        }
        cout << res << endl;
	}

	#ifdef HOME
	cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	#endif

	return 0;
}

#include<iostream>
#include<vector>
#include<math.h>
#include<algorithm>
#include<stack>
#include<list>
#include<queue>
#include<set>
#include<string>
#include<string.h>
#include <sstream>
#include<map>
#include<iomanip>

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
//#pragma GCC optimization("unroll-loops")

/*Ordered set*/
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

#define ll long long
#define PI 3.14159265
#define yes cout<<"YES"<<"\n"
#define no cout<<"NO"<<"\n"
using namespace std;

const ll MOD = 1000000007;

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

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

bool isPrime(ll n){
	for(ll i = 2; i <=sqrt(n); i++)
		if(n % i == 0)
			return 0;
	return 1;
}

string binaryRepresentation(int x){
    string s="";
    for (int i = 31; i >= 0; i--)
    {
        if (x&(1<<i)) cout << "1";
        else cout << "0";
    }
    return s;
}

ll combination(ll n,ll r){
    if(r==n || r==0)
        return 1LL;
    return combination(n-1,r-1) + combination(n-1,r);
}

bool isPowerOfTwo(ll n){
   if(n==0)
        return false;
   return (ceil(log2(n)) == floor(log2(n)));
}

ll power(ll a,ll b){
	ll ans=1;
	while(b)
	{
		if(b&1)
			ans=(ans*a)%MOD;
		b/=2;
		a=(a*a)%MOD;
	}
	return ans%MOD;
}

ll inverse(ll i){
    if(i==1) return 1;
    return (MOD-((MOD/i)*inverse(MOD%i))%MOD+MOD)%MOD;
}

string toString(ll a){
    ostringstream temp;
    temp << a;
    return temp.str();
}

ll toNumber(string s){
    stringstream num(s);
    ll x=0;
    num>>x;
    return x;
}

int main()
{
    //vector<vector<ll> >ar(n,vector<ll> (m,0));
    //vector<ll>::iterator ptr;

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

    ll n,k;
    cin>>n>>k;
    vector<vector<ll> >ar(n,vector<ll>(n,0));
    for(ll i=0;i<n;i++)
    {
        for(ll j=0;j<n;j++)
        {
            ll x;
            cin>>x;
            ar[i][j]=x;
        }
    }

    ll low=0;
    ll high=1e9+1;
    ll med=(k*k)/2+1;
    ll r=k-1;
    while(low<=high)
    {
        ll mid=(low+high)/2;
        //cout<<" mid : "<<mid<<"\n";
        /* Mid will be the possible median value */
        vector<vector<ll> >temp=ar;
        for(ll i=0;i<n;i++)
        {
            for(ll j=0;j<n;j++)
            {
                if(ar[i][j]>mid)
                    temp[i][j]=1;
                else
                    temp[i][j]=0;
            }
        }

        //for(ll i=0;i<n;i++)
        //{
        //    for(ll j=0;j<n;j++)
        //        cout<<temp[i][j]<<" ";
         //   cout<<"\n";
        //}

        for(ll i=0;i<n;i++)
        {
            for(ll j=1;j<n;j++)
            {
                temp[i][j]+=temp[i][j-1];
            }
        }

        for(ll i=1;i<n;i++)
        {
            for(ll j=0;j<n;j++)
            {
                temp[i][j]+=temp[i-1][j];
            }
        }
        bool flag=false;
        for(ll i=r;i<n;i++)
        {
            for(ll j=r;j<n;j++)
            {
                ll sum=temp[i][j];
                ll row1=i-r;
                ll col1=j-r;
                if(row1>0)
                    sum-=temp[row1-1][j];
                if(col1>0)
                    sum-=temp[i][col1-1];
                if(row1>0 && col1>0)
                    sum+=temp[row1-1][col1-1];
                //cout<<" i : "<<i<<" j : "<<j<<" sum : "<<sum<<"\n";
                if(sum<med)
                {
                    flag=true;
                }
            }
        }

        if(flag)
            high=mid-1;
        else
            low=mid+1;

    }
    cout<<low;

    return 0;
}


#pragma GCC optimize("Ofast")
#pragma loop_opt(on)

#include<bits/stdc++.h>

#define Rushia_mywife ios::sync_with_stdio(0);cin.tie(0);
#define F first
#define S second
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define mp make_pair
#define mt make_tuple
#define FL cout.flush()
#define all(x) (x).begin(),(x).end()
#define mem(x,i) memset((x),(i),sizeof((x)))

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

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

const int mod = 1000000007;
const int mod2 = 998244353;
const ld PI = acos(-1);

#define Bint __int128
#define int long long
int qpow(int x,int powcnt,int tomod){
	int res = 1;
	for(;powcnt;powcnt>>=1,x=(x*x)%tomod)
		if(1&powcnt)res = (res*x)%tomod;
	return (res%tomod);
}
int inv(int x){ return qpow(x,mod-2,mod); }
// --------------------------------------**

vector<int>cyc[10];
bool vis[10];

void solve(){
	for(int i=0;i<10;i++){
		mem(vis,0);
		cyc[i].pb(i);
		vis[i] = 1;
		int x = i*i%10;
		while(!vis[x]){
			vis[x] = 1;
			cyc[i].pb(x);
			x = x*i%10;
		}
	}
	int a,b,c;
	cin >> a >> b >> c;
	int x = qpow(b,c,(int)cyc[a%10].size());
	cout << cyc[a%10][(x-1+cyc[a%10].size())%(int)cyc[a%10].size()] << '\n';
}

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

#include<iostream>
#include<algorithm>
#include<map>
#include<queue>
#include<cmath>
#include<stack>
#include<string>
#include<vector>
#include<set>

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

long long int  powMod(long long int  x, long long int  k, long long int  m) {
  if (k == 0)     return 1;
  if (k % 2 == 0) return powMod(x*x % m, k/2, m);
  else            return x*powMod(x, k-1, m) % m;
}

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;
}
//φ関数

long long int  euler_phi(long long int n) {
  long long int ret = n;
  for(long long int  i = 2; i * i <= n; i++) {
    if(n % i == 0) {
      ret -= ret / i;
      while(n % i == 0) n /= i;
    }
  }
  if(n > 1) ret -= ret / n;
  return ret;
}

int main(void){

    long long int a,b,c;

    cin >> a >> b >> c;
    //bの偶奇

    int moto = a%10;
    if(moto==0||moto == 1){
        cout << moto << endl;
        return 0;
    }
    if(moto==4){
        int jyou = powMod(b,c,2);
        if(jyou ==0){
            cout << moto*moto%10 << endl;
            return 0;
        }
        cout << powMod(a%10,jyou,10);
    }
    if(moto == 5){
        cout << moto<<endl;
        return 0;
    }
    if(moto == 6){
        cout << moto<<endl;
        return 0;
    }
    if(moto==7||moto==8||moto==2||moto==3){
        int jyou = powMod(b,c,4);
        if(jyou ==0){
            cout << moto*moto*moto*moto%10 << endl;
            return 0;
        }
        cout << powMod(a%10,jyou,10);
        return 0;
    }

    if(moto==9){
        if(b%2==0){
            cout << 1 << endl;
        }
        else{
            cout << 9<<endl;
        }
    }

    return 0;
}


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

struct UnionFind {
	vector<int> d;
	UnionFind(int n=0): d(n,-1) {}
	int find(int x) {
		if (d[x] < 0) return x;
		return d[x] = find(d[x]);
	}
	bool unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y) return false;
		if (d[x] > d[y]) swap(x,y);
		d[x] += d[y];
		d[y] = x;
		return true;
	}
	bool same(int x, int y) { return find(x) == find(y);}
	int size(int x) { return -d[find(x)];}
};

int main(){
	int n, q;
	cin>>n>>q;
	vector<int> c(n);
	rep(i, n){cin>>c[i]; c[i]--;};

	UnionFind uf(n);
	vector<map<int, int>> mas(n);
	rep(i, n) mas[i][c[i]]=1;
	rep(_, q){
		int t;
		cin>>t;
		if(t==1){
			int a, b;
			cin>>a>>b; a--; b--;

			int aa=uf.find(a), bb=uf.find(b);
			if(aa!=bb){
				uf.unite(a, b);
				int c=uf.find(a), d;
				if(c==aa) d=bb;
				else d=aa;
				for(auto p : mas[d]) mas[c][p.first]+=p.second;
			}
		}
		else{
			int x, y;
			cin>>x>>y; x--; y--;

			int a=uf.find(x);
			cout<<mas[a][y]<<endl;
		}
	}
	return 0;
}

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

int main() {
    int64_t N;
    cin >> N;
    vector<vector<int64_t>> C(N, vector<int64_t>(N));
    for (int64_t i = 0; i < N; i++) {
        for (int64_t j = 0; j < N; j++) {
            cin >> C[i][j];
        }
    }

    vector<int64_t> diff(N - 1);
    for (int64_t i = 0; i < N - 1; i++) {
        set<int64_t> curr_diff;
        for (int64_t j = 0; j < N; j++) {
            curr_diff.insert(C[i + 1][j] - C[i][j]);
        }

        if (curr_diff.size() > 1) {
            cout << "No" << endl;
            return 0;
        }
        diff[i] = *curr_diff.begin();
    }

    vector<int64_t> A(N, 0);
    for (int64_t i = 0; i < N - 1; i++) {
        A[i + 1] = A[i] + diff[i];
    }

    const int64_t min_A = *min_element(A.begin(), A.end());
    if (min_A < 0) {
        for (int64_t i = 0; i < N; i++) {
            A[i] -= min_A;
        }
    }

    vector<int64_t> B(N);
    for (int64_t i = 0; i < N; i++) {
        B[i] = C[0][i] - A[0];
    }

    const int64_t min_B = *min_element(B.begin(), B.end());
    if (min_B < 0) {
        cout << "No" << endl;
        return 0;
    }

    cout << "Yes" << endl;
    for (int64_t i = 0; i < N; i++) {
        cout << A[i] << " \n"[i == N - 1];
    }
    for (int64_t i = 0; i < N; i++) {
        cout << B[i] << " \n"[i == N - 1];
    }
}


#include<bits/stdc++.h>
typedef long long ll;
ll n,k,a[205];
ll ans;
using namespace std;
int main()
{
    cin>>n;
    for(int i=0; i<205; i++)
    {
        a[i]=0;
    }
    for(int i=0; i<n; i++)
    {
        cin>>k;
        a[k%200]++;
    }
    ans=0;
    for(int i=0; i<205; i++)
    {
        k=a[i]*(a[i]-1)/2;
        ans+=k;
    }
    cout<<ans;
    return 0;
}

#include <bits/stdc++.h>

#define int long long

using namespace std;

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

    int T;
    cin >> T;

    while(T--)
    {
    	int N;
    	cin >> N;

    	map<int,int> mp;

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

    	bool flag = true;

    	for(auto x : mp)
    	{
    		if(x.second&1)flag = false;
    	}

    	if(N&1)cout << "Second" << '\n';
    	else
    	{
    		if(flag)cout << "Second" << '\n';
    		else cout << "First" << '\n';
    	}
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ff first
#define ss second
typedef long long ll;
ll power(ll a, ll b){//a^b
    ll res=1;
    a=a%MOD;
    while(b>0){
        if(b&1){res=(res*a)%MOD;b--;}
        a=(a*a)%MOD;
        b>>=1;
    }
    return res;
}
ll fermat_inv(ll y){return power(y,MOD-2);}
ll gcd(ll a, ll b){return (b==0)?a:gcd(b,a%b);}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    //cin>>t;
    while(t--){
        ll x,n;
        cin>>x>>n;
        ll y=100ll;
        x+=y;
        ll g=gcd(x,y);
        x/=g;
        y/=g;
        vector <bool> vis(x,false);
        for(int i=1;i<x;i++){
            if((x*i)/y<x){
                vis[(x*i)/y]=true;
            }
        }
        vector <ll> a;
        for(int i=1;i<x;i++){
            if(vis[i]==false){
                a.push_back(i);
            }
        }
        ll m=a.size();
        ll pos=(n-1ll)%m;
        ll ans=(n-1ll)/m;
        ans*=x;
        ans+=a[pos];
        cout<<ans<<"\n";
    }
    return 0;
}

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

using namespace std;

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define li long long
#define pii pair<int, int>
#define vi vector<int>
#define li long long

#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define fore(i, b, e) for (int i = (int)b; i <= (int)e; i++)

map<li, int> m;

int main() {
	int n;
	scanf("%d", &n);
	li cur = 0;
	m[0]++;
	li ans = 0;
	forn(i, n) {
		int x;
		scanf("%d", &x);
		if (i % 2 == 0) {
			cur += x;
		} else {
			cur -= x;
		}
		ans += m[cur];
		m[cur]++;
	}
	cout << ans;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int &x : a) cin >> x;
    a.push_back(0);
    sort(a.begin(), a.end());
    int64_t ans = 1;
    constexpr int64_t mod = 1e9 + 7;
    for (int i = 1; i < a.size(); ++i) ans = ans * (a[i] - a[i-1] + 1) % mod;
    cout << ans << endl;
    return 0;
}

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

#define fr(i,n) for(int i = 0; i<n; i++)
#define sz(v) (int)(v.size())
#define prin(a) cout << #a << " = " << a << endl
#define prinv(v) cout << #v << " = "; for(auto it : v) cout << it << ", "; cout << endl
#define all(v) (v).begin(),(v).end()

typedef long long ll;

#define rmin(a,b) a = min<ll>(a,b)
#define rmax(a,b) a = max<ll>(a,b)

#define fi first
#define se second

template <class T>
T fp(T x, long long e) {
	T ans(1);
	for(; e > 0; e /= 2) {
		if(e & 1) ans = ans * x;
		x = x * x;
	}
	return ans;
}

const ll mod = round(1e9)+7;
struct mb {
	mb(int v = 0) : val(v < 0 ? v + mod : v) {}
	mb(ll v){ val = (v%mod+mod)%mod; }
	int val;

	void operator += (mb o) { *this = *this + o; }
	void operator -= (mb o) { *this = *this - o; }
	void operator *= (mb o) { *this = *this * o; }
	mb operator * (mb o) { return (int)((long long) val * o.val % mod); }
	//mb operator / (mb o) { return *this * fp(o, mod - 2); }
	//bool operator == (mb o) { return val==o.val; } //usar soh para hashes
	mb operator + (mb o) { return val + o.val >= mod ? val + o.val - mod : val + o.val; }
	mb operator - (mb o) { return val - o.val < 0 ? val - o.val + mod : val - o.val; }
};

int main(){
	ios::sync_with_stdio(0); cin.tie(0);
	int n;
	set<int> st;
	cin >> n;
	fr(i,n){
		int x; cin >> x;
		st.emplace(x);
	}
	st.emplace(0);
	vector<int> v(all(st));

	mb ans = 1;
	fr(i,sz(v)-1){
		ans*=v[i+1]+1-v[i];
	}
	cout << ans.val << "\n";
}