#define taskname "test"

#include <bits/stdc++.h>

using namespace std;

#define sz(x) (int)x.size()
#define fi first
#define se second

typedef long long lli;
typedef pair<int, int> pii;

const int maxn = 105;
const int mod = 1e9 + 7;

int powmod(int x, int k) {
    if(k == 0) return 1;
    int t = powmod(x, k / 2);
    if(k % 2 == 0) return t * 1LL * t % mod;
    else return t * 1LL * t % mod * x % mod;
}

int inv(int x) {
    return powmod(x, mod - 2);
}

int add(int x, int y) {
    x += y;
    if(x >= mod) x -= mod;
    return x;
}

struct matrix {

    int val[maxn][maxn];

    matrix() {
        fill_n(&val[0][0], sizeof(val) / sizeof(val[0][0]), 0);
    }

    matrix operator *(const matrix&other) const {
        matrix res;
        for(int i = 0; i < maxn; ++i) {
            for(int j = 0; j < maxn; ++j) {
                for(int k = 0; k < maxn; ++k) {
                    res.val[i][j] = add(res.val[i][j], val[i][k] * 1LL * other.val[k][j] % mod);
                }
            }
        }
        return res;
    }
};

matrix mpow(matrix x, int k) {
    if(k == 1) return x;
    matrix t = mpow(x, k / 2);
    if(k % 2 == 0) return t * t;
    else return t * t * x;
}

int n, m, k;
int a[maxn];
vector<int> gr[maxn];

void read_input() {
    cin >> n >> m >> k;
    for(int i = 1; i <= n; ++i) {
        cin >> a[i];
    }
    for(int i = 1; i <= m; ++i) {
        int u, v;
        cin >> u >> v;
        gr[u].push_back(v);
        gr[v].push_back(u);
    }
}

void solve() {
    if(k == 0) {
        for(int i = 1; i <= n; ++i) {
            cout << a[i] << '\n';
        }
        return;
    }

    matrix A, B;
    for(int j = 1; j <= n; ++j) {
        A.val[1][j] = a[j];
    }
    for(int j = 1; j <= n; ++j) {
        for(auto&i: gr[j]) {
            B.val[i][j] = inv(m) * 1LL * inv(2) % mod;
        }
        B.val[j][j] = add(inv(m) * 1LL * inv(2) % mod * sz(gr[j]) % mod, (m - sz(gr[j])) * 1LL * inv(m) % mod);
    }

    A = A * mpow(B, k);
    for(int i = 1; i <= n; ++i) {
        cout << A.val[1][i] << '\n';
    }
}

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

    read_input();
    solve();

}

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define pb emplace_back
#define lb(v,k) (lower_bound(all(v),(k))-v.begin())
#define ub(v,k) (upper_bound(all(v),(k))-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
#define dame(a) {out(a);return 0;}
#define decimal cout<<fixed<<setprecision(15);
#define all(a) a.begin(),a.end()
#define rsort(a) {sort(all(a));reverse(all(a));}
#define dupli(a) {sort(all(a));a.erase(unique(all(a)),a.end());}
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef tuple<ll,ll,ll,ll> PPP;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vvvvi=vector<vvvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
using vvb=vector<vb>;
const ll inf=1001001001001001001;
const ll INF=1001001001;
const ll mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outvvp(T v){rep(i,v.size())outvp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void outset(T s){auto itr=s.begin();while(itr!=s.end()){if(itr!=s.begin())cout<<' ';cout<<*itr;itr++;}cout<<'\n';}
void outs(ll a,ll b){if(a>=inf-100)out(b);else out(a);}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){ll res=1;a%=mod;while(b){if(b&1)res=res*a%mod;a=a*a%mod;b>>=1;}return res;}
vi matmul(vi dp,vvi mt,int n){
    vi res(n);
    rep(i,n)rep(j,n)res[i]+=mt[i][j]*dp[j]%mod;
    rep(i,n)res[i]%=mod;
    return res;
}
vvi update(vvi mt,int n){
    vvi res(n,vi(n));
    rep(i,n)rep(j,n)rep(k,n)res[i][j]+=mt[i][k]*mt[k][j]%mod;
    rep(i,n)rep(j,n)res[i][j]%=mod;
    return res;
}
void matpow(vi &dp,vvi mt,ll k,int n){
    while(k){
        if(k&1)dp=matmul(dp,mt,n);
        mt=update(mt,n);
        k>>=1;
    }
}
/*
int main(){
    ll n,k;cin>>n>>k; //nは分かってる項数、kは求めたいのが何項目か
    vi dp(n);
    rep(i,n)cin>>dp[n-i-1];
    if(k<=n)dame(dp[n-k]); //分かっている
    vvi mt(n,vi(n));
    rep(i,n)cin>>mt[0][i]; //遷移の式
    REP(i,1,n)mt[i][i-1]=1; //こうすると上手くいく
    matpow(dp,mt,k-n,n);
    out(dp[0]);
}
*/

//ABC009D 漸化式
int main(){
    ll n,m,k;cin>>n>>m>>k;
    vvi mt(n,vi(n));
    vi dp(n);rep(i,n)cin>>dp[i];
    ll tmp=modpow(m,mod-2);
    ll tmp2=modpow(2,mod-2);
    rep(i,m){
        ll a,b;cin>>a>>b;a--;b--;
        mt[a][b]=tmp2;
        mt[b][a]=tmp2;
    }
    rep(i,n){
        ll sum=0;
        rep(j,n)sum+=mt[i][j];
        mt[i][i]=(m+mod-sum%mod)%mod;
    }
    rep(i,n)rep(j,n)mt[i][j]=mt[i][j]*tmp%mod;
    matpow(dp,mt,k,n);
    for(ll x:dp)out(x);
}


#include <bits/stdc++.h>

using namespace std;

vector<pair<int, int>> edges[26];
vector<pair<int, int>> states[1024][1024];
int d[1024][1024];

int main()
{
  int N, M;

  scanf("%d %d", &N, &M);

  queue<pair<int, int>> q;
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= N; j++) {
      d[i][j] = 1'000'000'000;
    }
    d[i][i] = 0; q.emplace(i, i);
  }

  for (int i = 0; i < M; i++) {
    int u, v; char c[2];
    scanf("%d %d %s", &u, &v, c);
    if (u > v) swap(u, v);
    edges[c[0] - 'a'].emplace_back(u, v);
    if (u != v) d[u][v] = d[v][u] = 1;
    q.emplace(u, v);
  }

  for (int a = 0; a < 26; a++) {
    int sz = edges[a].size();
    for (int i = 0; i < sz; i++) {
      for (int j = i + 1; j < sz; j++) {
        auto [u, v] = edges[a][i];
        auto [w, x] = edges[a][j];
        states[u][w].emplace_back(v, x); states[w][u].emplace_back(v, x);
        states[u][x].emplace_back(v, w); states[x][u].emplace_back(v, w);
        states[v][w].emplace_back(u, x); states[w][v].emplace_back(u, x);
        states[v][x].emplace_back(u, w); states[x][v].emplace_back(u, w);
      }
    }
  }

  while (q.size()) {
    auto [u, v] = q.front(); q.pop();
    if (u > v) swap(u, v);
    if (u == 1 && v == N) {
      printf("%d\n", d[u][v]); return 0;
    }
    for (auto [u2, v2] : states[u][v]) {
      if (d[u2][v2] == 1'000'000'000) {
        d[u2][v2] = d[v2][u2] = d[u][v] + 2;
        q.emplace(u2, v2);
      }
    }
  }

  printf("-1\n");

  return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    int n,m;
  	int vdnmcjdkmkh;
    cin>>n>>m;
    vector<pair<int,int>>a(m);
    for(int i=0;i<m;i++)
    {
        cin>>a[i].first>>a[i].second;
    }
    int k;
    cin>>k;
    vector<pair<int,int>>b(k);
    for(int j=0;j<k;j++)
    {
        cin>>b[j].first>>b[j].second;
    }
    ll l=0;
    ll tot=1<<k;
    for(ll mask=0;mask<tot;mask++)
    {
        vector<int>v(n+1);
        ll ans=0;
        for(int i=0;i<k;i++)
        {
            if(mask & (1<<i))
                v[b[i].second]=1;
            else
                v[b[i].first]=1;
        }
        for(int i=0;i<m;i++)
        {
            if(v[a[i].first] && v[a[i].second])
                ans++;
        }
        l=max(l,ans);
    }
    cout<<l<<endl;
    return 0;
}


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

#define rep2(i,k,n) for(i64 i=(i64)(k);i<(i64)(n);i++)
#define rep(i,n) rep2(i,0,n)
#define all(x) begin(x),end(x)
#ifdef ENV_LOCAL
#define dump if (1) cerr
#else
#define dump if (0) cerr
#endif

using namespace std;
using namespace std::string_literals;

using i32 = int32_t;
using i64 = int64_t;
using f64 = double;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;

//using namespace harudake;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  i32 n,m;
  cin>>n>>m;
  vector<vi32> g(n);
  rep(i,m) {
    i32 a,b;
    cin>>a>>b;
    --a;--b;
    g[a].push_back(b);
  }
  i32 ans = 0;
  rep(i,n) {
    vector<bool> vis(n, false);
    queue<i32> q;
    q.push(i);
    vis[i] = true;
    while (!q.empty()) {
      i32 j = q.front();
      q.pop();
      for (auto&& to : g[j]) {
        if (!vis[to]) {
          q.push(to);
          vis[to] = true;
        }
      }
    }
    ans += count(all(vis), true);
  }
  cout<<ans<<endl;
  return 0;
}

#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define rng(a) a.begin(), a.end()
#define ina(n,a) cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]
#define sz(x) (int)(x).size()
#define se second
#define fi first
#define prev            coyhhhhhhyoc
#define next          sdNNNmNNNNNNNmds
#define y0           hNNNNy_yNNNNNN_sNh
#define y1          mNNNNNdtdNNNNNNtsNNm
#define yn          mNNNNNNNNy___smNNNms
#define tm            oooooosyysooooot
#define read               tyhyt
#define rank              ytmNmo
#define index              yyy
#define pb push_back
#define pcnt __builtin_popcountll
#define rrep(i,a,b) for(int i = (b); i >= (a); i--)
#define rall(x,a) for(auto x : a)
#define MOD 1000000007
#define endl "\n"
typedef long long ll;
using namespace std;

const int N = 2222;
vector<int> graph[N];
bool vis[N];
int n, m, ans;

void dfs(int u) {
    if(vis[u]) return;
    vis[u] = true;
    ans++;
    rall(v, graph[u]) {
        dfs(v);
    }
}

int solve() {
    cin >> n >> m;
    rep(i, 1, m) {
        int u, v;
        cin >> u >> v;
        graph[u].pb(v);
    }
    rep(u, 1, n) {
        fill(vis + 1, vis + n + 1, 0);
        dfs(u);
    }
    cout << ans << endl;
    return 0;
}

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


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

#define int long long

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

    int n=1; cin >> n ;
    int ans = 0 ;
    if (n%100) {
        ans++ ;
        n -= n%100 ;
    }
    n /= 100 ;
    ans += n%10 ;
    n /= 10 ;
    ans += n*10 ;
    cout << ans << endl ;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define Rep(i,n) for(ll i=0;i<ll(n);i++)
#define Repd(i,n) for(ll i=n-1;i>=0;i--)
#define For(i,a,b) for(ll i=a;i<=ll(b);i++)
#define Ford(i,a,b) for(ll i=a;i>=ll(b);i--)
#define Fora(i,I) for(const auto& i:I)
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define pb push_back
const int INF = 1<<30;
const ll MOD = 1000000007;
const ll val = 0;
ll myceil(ll a,ll b){return (a+(b-1))/b;}
ll myfloor(ll a,ll b){return a/b;}

int main(void) {
	ll n;
	cin>>n;
	cout<<myceil(n , 100)<<endl;
}


#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define MODADD(ADD_X,ADD_Y)  (ADD_X+ADD_Y)%MOD
#define MODSUB(SUB_X,SUB_Y)  ((SUB_X-SUB_Y)+MOD)%MOD
#define MODMUL(MUL_X,MUL_Y)  (MUL_X*MUL_Y)%MOD
#define LCM(LCM_X,LCM_Y) (LCM_X/__gcd(LCM_X,LCM_Y))*LCM_Y
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e5+500;
int dx[]= {1,0,-1,0,1,-1,1,-1};
int dy[]= {0,1,0,-1,1,-1,-1,1};
int arr[MAX],mp[MAX];
void solve(int a){
    for(int i=0;i<MAX;i++){
        if(i-a>0 && mp[i-a])
            mp[i]=1;
    }
    mp[a]=1;
}
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    int n,sum=0;
    cin>>n;
    for(int i=0; i<n; i++){
        int a;
        cin>>a;
        solve(a);
        sum+=a;
    }
    int mx=INT_MAX;
    for(int i=0;i<MAX;i++){
        if(mp[i]){
            int x=sum-i;
            mx=min(mx,max(x,i));
        }
    }
    cout<<mx<<endl;

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int T,n,ans=1e9;
bitset<100004>f;
int main(){
	cin>>n;
	f[0]=1;
	for(int i=0;i<n;i++){
		int x;cin>>x;
		f|=f<<x;T+=x;
	}
	for(int i=0;i<=1e5;i++)if(f[i])ans=min(ans,max(i,T-i));
	cout<<ans;
}


//Saptak_Roy_Turja
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    ll n,i,x;
    cin>>n;
    for(i=1;;i++){
        x=(i*(i+1))/2;
        if(x>=n){
            cout<<i<<'\n';
            return 0;
        }
    }
}

// Jai Shree Ram

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

#define rep(i,a,n)     for(int i=a;i<n;i++)
#define ll             long long
#define int            long long
#define pb             push_back
#define all(v)         v.begin(),v.end()
#define endl           "\n"
#define x              first
#define y              second
#define gcd(a,b)       __gcd(a,b)
#define mem1(a)        memset(a,-1,sizeof(a))
#define mem0(a)        memset(a,0,sizeof(a))
#define sz(a)          (int)a.size()
#define pii            pair<int,int>
#define hell           1000000007
#define elasped_time   1.0 * clock() / CLOCKS_PER_SEC

template<typename T1,typename T2>istream& operator>>(istream& in,pair<T1,T2> &a){in>>a.x>>a.y;return in;}
template<typename T1,typename T2>ostream& operator<<(ostream& out,pair<T1,T2> a){out<<a.x<<" "<<a.y;return out;}
template<typename T,typename T1>T maxs(T &a,T1 b){if(b>a)a=b;return a;}
template<typename T,typename T1>T mins(T &a,T1 b){if(b<a)a=b;return a;}

int solve(){
 		int n;cin>>n;
 		int ans=0;
 		for(int i=1;i<=1e6;i++){
 			int dig = log10(i)+1;
 			int val = pow(10,dig)*i+i;
 			if(val<=n)ans++;
 		}
 		cout<<ans<<endl;
 return 0;
}
signed main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    #ifdef SIEVE
    sieve();
    #endif
    #ifdef NCR
    init();
    #endif
    int t=1;//cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


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

int main(){
    char s, t;
    cin >> s >> t;
    t = (s == 'Y' ? t - 32 : t);
    cout << t << endl;
    return 0;
}

#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <cmath>
#include <deque>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <functional>
#include <iomanip>
#include <cstdint>
#define ll long long
#define rep2(i,a,b) for(int i=a;i<=b;++i)
#define rep(i,n) for(int i=0;i<n;i++)
#define rep3(i,a,b) for(int i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tpiii tuple<int,int,int>
#define mp make_pair
#define mt make_tuple
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define vec vector
#define vi vec<int>
#define vl vec<ll>
#define vvi vec<vi>
#define vvl vec<vl>
#define vpii vec<pii>
#define vpll vec<pll>
#define vbl vec<bool>
#define endl "\n"
#define ALL(c) (c).begin(),(c).end()
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
string stin(){string s;cin>>s;return s;}
void drop(string s){cout<<s<<endl; exit(0);}
void drop(int x){cout<<x<<endl; exit(0);}
void drop(ll x){cout<<x<<endl; exit(0);}
void drop(double x){cout<<x<<endl; exit(0);}
int main(){
    char c;
    cin>>c;
    char a;
    cin>>a;
    if(c=='Y')cout<<(char)(a+'A'-'a')<<endl;
    else cout<<a<<endl;
}


#include "bits/stdc++.h"
//#include <boost/multi_array.hpp>
//#include <boost/optional.hpp>
//#include <boost/range/irange.hpp>
//#include <boost/range/algorithm.hpp>
//#include <boost/range/adaptors.hpp>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww {
    cww() {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();

long long gcd(long long a, long long b) { // 2つの場合の最大公約数
    if (b == 0) {
        return a;
    } else {
        return gcd(b, a % b);
    }
}

long long gcd_vec(vector<long long> const &A) { // N個の要素に対する最大公約数
    int size = (int)A.size();
    long long ret = A[0];
    for (int i = 1; i < size; i++) {
        ret = gcd(ret, A[i]);
    }
    return ret;
}

void Main() {  //う　し　た　ぷ　に　き　あ　く　ん　笑
    int n;
    cin >> n;
    vector<long long> a(n);
    rep(i, n) { cin >> a[i]; }
    cout << gcd_vec(a) << endl;
}  //う　し　た　ぷ　に　き　あ　く　ん　笑

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

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
#define ld long double
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define mem(x,y) memset(x,y,sizeof(x))
#define pii pair<int,int>
#define pll pair<ll,ll>
#define INF 1e9
#define INFL 1e18
#define mod 1000000007
//#define mod 998244353
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> os;
typedef tree<pii,null_type,less<pii>,rb_tree_tag,tree_order_statistics_node_update> os_pair;

ll power(ll x,ll n){ll res =1;while(n>0){if(n%2==1){res=res*x;}x=x*x;n=n/2;}return res;}
ll powm(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;}

//cout<< fixed << setprecision(10)
//__builtin_popcountll()

int main(){

    fast;
    int n,i,j;
    cin>>n;
    int a[n];
    set<int>s;
    for(i=0;i<n;i++)
    {
    	cin>>a[i];
    	s.insert(a[i]);
	}
	int x;
	while(s.size()>1)
	{
		set<int>p;
		set<int>::iterator it;

		for(it=s.begin();it!=s.end();it++)
		{
			if(it==s.begin())
			{
				x=*it;
				p.insert(x);
			}
			else
			{
				if(*it%x!=0)
				p.insert(*it%x);

			}
		}
		s=p;
	}
	cout<<*s.begin();

}


#include <bits/stdc++.h>

using namespace std;

#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) (r).begin(),(r).end()
#define rall(r) (r).rbegin(),(r).rend()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
    int n, m;
    cin >> n >> m;
    vector<vi> d(n, vi(n));
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        d[a][b] = d[b][a] = 1;
    }
    vi dp(1<<n, INF);
    dp[0] = 0;
    rep(i, n) dp[1<<i] = 1;
    rep(mask, 1<< n) if(dp[mask] != INF) {
        rep(i, n) {
            if(mask & (1<<i)) continue;
            bool f = true;
            rep(j, n) if(mask & (1<<j)) {
                f &= d[i][j];
            }
            if(f) dp[mask | (1<<i)] = 1;
        }
    }
    rep(mask, 1<<n) {
        for(int maskA = mask; maskA != 0; maskA = mask&(maskA-1)) {
            int maskB = mask - maskA;
            dp[mask] = min(dp[mask], dp[maskA] + dp[maskB]);
        }
    }
    cout << dp[(1<<n)-1] << '\n';
    return 0;
}

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

const int maxn = 2e5+8, inf  = 1e18+9, mod  = 998244353;

struct edge { int v, w; };
int n, m, ans[maxn], vs[maxn];
vector<edge> G[maxn];

void dfs(int u, int p) {
    for (auto [v, w] : G[u]) if (v != p && !vs[v]) {
        if (w == ans[u]) ans[v] = (w % n) + 1; else ans[v] = w;
        vs[v] = 1; dfs(v, u);
    }
}

void solve() {
    int i, j, u, v, w;
    cin >> n >> m;
    for (i = 1; i <= m; i++) {
        cin >> u >> v >> w;
        G[u].push_back({v, w});
        G[v].push_back({u, w});
    }
    ans[1] = 1; vs[1] = 1;
    dfs(1, -1);
    for (i = 1; i <= n; i++) cout << ans[i] << endl;
}

signed main() {
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); //cout << fixed << setprecision(15);
    int t = 1; //cin >> t;
    while (t--) solve();
    return 0;
}


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

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef pair<int,int> Pair;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define EXIST(m,v) (m).find((v)) != (m).end()
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

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

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;

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

VI exist(100100,0),vis,C,ans;
VVI edge;

void dfs(int v){
    vis[v] = 1;
    bool flag = false;
    if(exist[C[v]] == 0){
        flag = true;
        exist[C[v]] = 1;
        ans.push_back(v+1);
    }

    for(int to : edge[v]){
        if(vis[to]) continue;
        dfs(to);
    }
    if(flag) exist[C[v]] = 0;
    return;
}

void Main(){
    int N; cin >> N;
    C.resize(N); vis.resize(N,0); edge.resize(N);
    REP(i,N) cin >> C[i], C[i]--;
    REP(_,N-1){
        int a,b; cin >> a >> b; a--; b--;
        edge[a].push_back(b); edge[b].push_back(a);
    }

    dfs(0);

    SORT(ans);
    for(int x : ans) cout << x << en;
    return;
}

int main(void){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
    int t=1; //cin>>t;
    while(t--) Main();
    return 0;
}

// MOHIT KUMAR
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

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

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

#define ff(i, a, b) for ( ll i=a; i<(b); i++)
#define ffd(i, a, b) for ( ll i=a; i<= b; i++)
#define fr(i, a, b) for ( ll i = (b)-1; i >= a; i--)
#define ffr(i, a, b) for ( ll i = b ; i >= a; i--)
#define vl vector < ll >
#define vp vector < pl >
#define endl "\n"
#define sz(x) (ll)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

const ld pi = acos(-1) ;
const ll maxn = 3e5 + 5 ;
const int mod = 998244353 ;
const ll INF = 1e18 ;
const int MX = 2000000001 ; // check the limits, dummy

vl lps(maxn, 0) ; // longest prefix array which is also a suffix

void KMP( string s) {
  ll l = 0, r = 1 ;
  while (r < s.size()) {
    if (s[l] == s[r]) {
      lps[r++] = ++l ;
    }
    else {
      l = 0 ;
      lps[r++] = 0;
    }
  }
  ff(i, 0, sz(s)) cout << lps[i] << " " ;
}

void find_sub(string s, string t) {
  ll i = 0, j = 0, ans = 0  ;
  bool ch = false ;
  while (i < s.size()) {
    if (s[i] == t[j]) {
      j++ ;
      i++ ;
      if (j == t.size()) {
        ans++ ;
        cout << "Substring found at " << i - j << " index" << endl ;
        // return true ;
        j = lps[j - 1] ;
        ch = true ;
      }
    }
    else {
      if (j) j = lps[j - 1] ;
      else i++ ;
    }
  }
  if (!ch) cout << "Substring not found\n" ;
  cout << "NUMBER OD OCC" << ans << endl ;
  // return false ;
}

ll max_gold_mine() {
  ll v[3][1] = {{1}, {2}, {3}};
  ll m = 3, n = 1 ;
  ll ans = 0 ;
  for ( int j = n - 2; j >= 0; j--) {
    for ( int i = 0; i <  m; i++) {
      if (!i) v[i][j] += max(v[i][j + 1], v[i + 1][j + 1]) ;
      else if (i == m - 1)v[i][j] += max(v[i][j + 1], v[i - 1][j + 1]) ;
      else v[i][j] += max({v[i + 1][j + 1], v[i - 1][j + 1], v[i][j + 1]}) ;
    }
  }
  for ( int i = 0; i < m; i++) ans = max(ans, v[i][0]) ;
  return ans ;
}

int optimal_merge( vector < int > v) {
  int ans = 0 ;
  priority_queue < int , vector < int > , greater < int >> pq;
  for (auto x : v) pq.push(x) ;
  while (pq.size() != 1) {
    int a = pq.top() ;
    pq.pop() ;
    int b = pq.top() ;
    pq.pop() ;
    ans += a + b ;
    pq.push(a + b) ;
  }
  return ans ;
}

// void dfs( ll u) {
//   vis[u] = 1 ;
//   for (auto x : adj[u]) {
//     if (!vis[x]) dfs(x) ;
//   }
//   top.pb(u) ;
// }
// void topo_sort(vl adj[], ll n) {
//   ffr(i, 1, n) {
//     if (!vis[i]) dfs(i) ;
//   }
//   reverse(all(top)) ;
//   cout << "TOPOLOGICAL SORTING OF GRAPH IS\n " ;
//   for (auto x : top) cout << x  << " ";
// }

// vl v[maxn] ;
// vector <double > prob(maxn, 0) ;

// void dfs (ll n, ll par) {
//   ll res = sz(v[n]) ;
//   if (par != -1) --res ;
//   for (auto x : v[n]) {
//     if ( x != par ) {
//       prob[x] = prob[n] / res ;
//       dfs(x, n) ;
//     }
//   }
// }

vl v[maxn], val(maxn, 0) ;
bool vis[maxn] = {0} ;
ll csum = 0 ;

void dfs(ll n ) {
  vis[n] = 1 ;
  csum += val[n] ;
  for (auto x : v[n]) {
    if (!vis[x]) dfs(x) ;
  }
}

int main() {
  ios_base::sync_with_stdio(0) , cin.tie(0);
  ll t, q, n, a, b, c, d, k, l, m, r,  x = 0, y = 0, z = 0 , sum = 0, ans = 0, temp = 0, res = 0 ;
  cin >> n >> m ;
  ff(i, 0, n) {
    cin >> val[i] ;
  }
  ff(i, 0, n) {
    cin >> x ;
    val[i] -= x ;
  }
  ff(i, 0, m) {
    cin >> a >> b ;
    a--, b-- ;
    v[a].pb(b) ;
    v[b].pb(a) ;
  }
  ff(i, 0, n) {
    if (!vis[i])
      dfs(i) ;
    if (csum) {
      cout << "No\n" ;
      return 0 ;
    }
  }
  cout << "Yes\n" ;
}


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

const auto mod = 1000000007;

auto fp(long long x, long long e) -> long long {
    auto ans = 1ll;
    while (e > 0) {
        if (e & 1) ans = ans * x % mod;
        e >>= 1;
        x = x * x % mod;
    }
    return ans;
}

auto fib(int n) -> long long {
    if (n < 2) return 1ll;
    n--;
    auto Fi_1 = 1ll, Fi = 1ll;
    while (n-- > 0) {
        auto tmp = Fi;
        Fi = (Fi_1 + Fi) % mod;
        Fi_1 = tmp;
    }
    return Fi;
}

auto main() -> int {
    auto n = 0;
    auto AA = char{}, AB = char{},
         BA = char{}, BB = char{};
    cin >> n;
    cin >> AA >> AB >> BA >> BB;
    if (n <= 3) {
        cout << 1 << endl;
        return 0;
    }
    if (AB == 'A') {
        if (AA == 'A') {
            cout << 1 << endl;
        } else if (BA == 'B') {
            cout << fp(2, n - 3) << endl;
        } else {
            cout << fib(n - 2) << endl;
        }

    } else {
        if (BB == 'B') {
            cout << 1 << endl;
        } else if (BA == 'A') {
            cout << fp(2, n - 3) << endl;
        } else {
            cout << fib(n - 2) << endl;
        }
    }
    return 0;
}

#include <bits/stdc++.h>
#define rep(i,l,r) for (int i=l;i<=r;++i)
#define per(i,r,l) for (int i=r;i>=l;--i)
#define ll long long
using namespace std;
const int N=1e6+6,P=1e9+7; int dp[N];
int main(){
	int n; scanf("%d",&n);
	char str[4][5],s[4];
	rep(i,0,3) scanf("%s",str[i]),s[i]=str[i][0];
	if (s[1]=='A'&&s[0]=='A'||s[1]=='B'&&s[3]=='B'){
		puts("1"); return 0;
	}
	if (s[1]==s[2]){
		dp[1]=dp[2]=1;
		rep(i,3,n-1) dp[i]=(dp[i-1]+dp[i-2])%P;
		cout<<dp[n-1]<<endl;
	}
	else{
		int s=1; rep(i,1,n-3) s=2LL*s%P;
		printf("%d\n",s); return 0;
	}
	return 0;
}


#include <iostream>
#include<algorithm>
using namespace std;
int main()
{
    long long int n,j=0,sum=0,i=0,s=0;
    cin>>n;
    int a[n];
    while(i<n)
    {
        cin>>a[i];
        i++;
    }
    sort(a,a+n);
    while(j<n)
    {
        sum =sum+a[j]*j;
        sum =sum- s;
        s =s+ a[j];
        j++;
    }
    cout<<sum;
}

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

#define int long long
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;
using namespace __gnu_pbds;

struct chash {
    const int RANDOM = (long long)(make_unique<char>().get()) ^ chrono::high_resolution_clock::now().time_since_epoch().count();
    static unsigned long long hash_f(unsigned long long x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    static unsigned hash_combine(unsigned a, unsigned b) { return a * 31 + b; }
    int operator()(int x) const { return hash_f(x)^RANDOM; }
};

const int N = 1e10+5;
gp_hash_table<int,int,chash> bit[2];

void update(int idx, int pos, int val){
	pos+=(int)1e9;
	while(pos < N){
		bit[idx][pos] += val;
		pos += pos&-pos;
	}
}

int query(int idx, int pos){
	pos+=(int)1e9;
	int res = 0;
	while(pos){
		res += bit[idx][pos];
		pos -= pos&-pos;
	}
	return res;
}

void solve(){
	int n;
	cin >> n;
	int ans = 0;
	for(int i = 0;i < n;i++){
		int tmp;
		cin >> tmp;
		ans += (query(0,N-1)-query(0,tmp))-(query(1,N-1)-query(1,tmp))*tmp-query(0,tmp-1)+query(1,tmp-1)*tmp;
		update(0,tmp,tmp);
		update(1,tmp,1);
	}
	cout << ans << "\n";
}

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


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

const int maxn = 510;
int n, a[maxn], b[maxn], c[maxn][maxn];

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            scanf("%d", &c[i][j]);
        }
    }
    int mn = min_element(c[1] + 1, c[1] + n + 1) - c[1];
    for (int i = 1; i <= n; i++) {
        b[i] = c[1][i] - c[1][mn];
    }
    memset(a, -1, sizeof(a));
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            int t = c[i][j] - b[j];
            if (t < 0) puts("No"), exit(0);
            if (~a[i]) {
                if (a[i] ^ t) puts("No"), exit(0);
            } else {
                a[i] = t;
            }
        }
    }
    puts("Yes");
    for (int i = 1; i <= n; i++) {
        printf("%d ", a[i]);
    }
    putchar('\n');
    for (int i = 1; i <= n; i++) {
        printf("%d ", b[i]);
    }
    putchar('\n');
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define deb(x) cout << #x << " " << x << endl;
#define mod 1000000007
#define fast std::ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define endl "\n"
#define all(x) (x).begin(), (x).end()
#define rall(v) v.rbegin(), v.rend()
#define pb push_back
#define lb lower_bound
#define ub upper_bound
const ll INF = 1e18;
const ll NEGINF = -1 * INF;

void solve()
{
    int n;
    cin >> n;
    ll x, t;
    ll a = 0;
    ll b = INT_MIN;
    ll c = INT_MAX;
    for (int i = 0; i < n; i++)
    {
        cin >> x >> t;
        if (t == 1)
        {
            a += x;
            b += x;
            c += x;
        }
        else if (t == 2)
        {
            b = max(b, x);
            c = max(c, x);
        }
        else
        {
            b = min(b, x);
            c = min(c, x);
        }
    }
    // deb(a);
    // deb(b);
    // deb(c);
    int q;
    cin >> q;
    while (q--)
    {
        cin >> x;
        cout << min(c, max(b, a + x)) << endl;
    }
}

int main()
{
    fast;
#ifndef ONLINE_JUDGE
    freopen("/home/kalit/Desktop/Data Structures-Algo-Competitive/src/codeforces/input.txt", "r", stdin);
    freopen("/home/kalit/Desktop/Data Structures-Algo-Competitive/src/codeforces/output.txt", "w", stdout);
#endif
    int T = 1;
    while (T--)
    {
        solve();
    }
    //cout<< "Done in " << clock() / CLOCKS_PER_SEC <<"sec"<< endl;
    return 0;
}


#include <iostream>

#include <algorithm>
#include <list>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <chrono>

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

#define manx maxn
#define whlie while
#define itn int
#define fro for
#define asn ans
#define scnaf scanf
#define sacnf scanf
#define pritnf printf
#define haed head
#define tmep temp
#define udpate update
#define cosnt const

#define Fastin freopen("/home/rqdmap/Desktop/codes/in", "r", stdin)
#define Fastout freopen("/home/rqdmap/Desktop/codes/main.out", "w", stdout)
#define lowbit(x) ((x) & (-x))
#define clr(a, x) memset((a), x, sizeof (a))
#define TTT int __; scanf("%d", &__); for(int _ = 1; _ <= __; _++)
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

/*------------------------------------------------------------------------------------*/
template<typename T>
void prt(T *a, int n, bool withid = 0){
    if(!withid) for(int i = 0; i < n; i++) cout << a[i] << ((i == n - 1)? '\n':' ');
    else for(int i = 0; i < n; i++) cout << i << ": " << a[i] << '\n';
}

template<typename T>
T ceil(T a, T b){return (a + b - 1) / b;}
template<typename T>
T gcd(T x, T y){return !x? y: gcd(y % x, x);}
template<typename T>
void exgcd(T a, T b, T &x, T &y){
    if(!b){x = 1; y = 0;return;}
    exgcd(b, a % b, y, x); y -= a / b * x;
}
ll qp(ll a, ll p){
    if(p < 0) return 0;
    ll ans = 1; while(p){if(p & 1) ans = ans * a ; a = a * a; p >>= 1;}
    return ans;
}
ll qp(ll a, ll p, ll M){
    ll ans = 1; while(p){ if(p & 1) ans = ans * a % M; a = a * a % M; p >>= 1;}
    return (ans % M + M) % M;
}
int euler(int *prime, int *vis, int n){
    int top = 0;
    for(int i = 0; i <= n; i++) vis[i] = 0;
    for(int i = 2; i <= n; i++){
        if(!vis[i]) prime[top++] = i;
        for(int j = 0; j < top && i * prime[j] <= n; j++){
            vis[i * prime[j]] = 1;
            if(i % prime[j] == 0) break;
        }
    }
    return top;
}
struct star{int to, next, w;};
/*------------------------------------------------------------------------------------*/

const int maxn = 5e3 + 10;
const int M = 998244353;

ll C(int n, int m){
    m = min(m, n - m);
    ll ans = 1;
    for(int i = 1; i <= m; i++){
        ans = ans * qp(i, M - 2, M) % M;
        ans = ans * (n + 1 - i) % M;
    }
    return ans;
}

ll dp[maxn];
ll c[maxn];

int main(){
    // Fastin;
    int n, m; scnaf("%d %d", &n, &m);
    for(int i = 0; i <= n; i++) c[i] = C(n, i);
    dp[0] = 1;
    for(int i = 1; i <= m; i++){
        if(i & 1) dp[i] = 0;
        else{
            for(int j = 0; j + j <= i && j + j <= n; j++){
                dp[i] += c[2 * j] * dp[i / 2 - j] % M;
                dp[i] %= M;
            }
        }
    }
    // prt(dp, m + 1, 1);
    printf("%lld\n", dp[m]);
    return 0;
}

#line 1 "main.cpp"

/**
 * @title Template
 */

#include <iostream>
#include <algorithm>
#include <utility>
#include <numeric>
#include <vector>
#include <array>
#include <cassert>

#line 2 "/Users/kodamankod/Desktop/cpp_programming/Library/other/range.cpp"

#line 4 "/Users/kodamankod/Desktop/cpp_programming/Library/other/range.cpp"

class range {
  struct iter {
    std::size_t itr;
    constexpr iter(std::size_t pos) noexcept: itr(pos) { }
    constexpr void operator ++ () noexcept { ++itr; }
    constexpr bool operator != (iter other) const noexcept { return itr != other.itr; }
    constexpr std::size_t operator * () const noexcept { return itr; }
  };

  struct reviter {
    std::size_t itr;
    constexpr reviter(std::size_t pos) noexcept: itr(pos) { }
    constexpr void operator ++ () noexcept { --itr; }
    constexpr bool operator != (reviter other) const noexcept { return itr != other.itr; }
    constexpr std::size_t operator * () const noexcept { return itr; }
  };

  const iter first, last;

public:
  constexpr range(std::size_t first, std::size_t last) noexcept: first(first), last(std::max(first, last)) { }
  constexpr iter begin() const noexcept { return first; }
  constexpr iter end() const noexcept { return last; }
  constexpr reviter rbegin() const noexcept { return reviter(*last - 1); }
  constexpr reviter rend() const noexcept { return reviter(*first - 1); }
};

/**
 * @title Range
 */
#line 2 "/Users/kodamankod/Desktop/cpp_programming/Library/algebraic/fact_prime.cpp"

#include <cstddef>
#line 7 "/Users/kodamankod/Desktop/cpp_programming/Library/algebraic/fact_prime.cpp"
#include <iterator>
#line 9 "/Users/kodamankod/Desktop/cpp_programming/Library/algebraic/fact_prime.cpp"
#include <type_traits>

template <class T, std::enable_if_t<std::is_integral<T>::value>* = nullptr>
std::vector<std::pair<T, size_t>> factorize(T x) {
  assert(x > 0);
  if (x == 1) return { };
  std::vector<std::pair<T, size_t>> res;
  for (T i = 2; i * i <= x; ++i) {
    if (x % i == 0) {
      res.emplace_back(i, 0);
      while (x % i == 0) {
        res.back().second++;
        x /= i;
      }
    }
  }
  if (x > 1) {
    res.emplace_back(x, 1);
  }
  return res;
}

template <class T, std::enable_if_t<std::is_integral<T>::value>* = nullptr>
std::vector<T> divisors(const T x) {
  std::vector<T> small, big;
  for (T i = 1; i * i <= x; ++i) {
    if (x % i == 0) {
      small.push_back(i);
      if (i * i != x) {
        big.push_back(x / i);
      }
    }
  }
  small.reserve(small.size() + big.size());
  std::copy(big.rbegin(), big.rend(), std::back_inserter(small));
  return small;
}

/**
 * @title Factors/Divisors
 */
#line 16 "main.cpp"

using i32 = std::int32_t;
using i64 = std::int64_t;
using u32 = std::uint32_t;
using u64 = std::uint64_t;
using isize = std::ptrdiff_t;
using usize = std::size_t;

constexpr i32 inf32 = (u32) ~0 >> 2;
constexpr i64 inf64 = (u64) ~0 >> 2;

template <class T>
using Vec = std::vector<T>;

int main() {
  u64 D;
  std::cin >> D;
  u64 ans = 0;
  for (const auto x: divisors(2 * D)) {
    if (x & 1) {
      ans += 2;
    }
  }
  std::cout << ans << '\n';
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
using std::cout;
using std::cin;
using std::endl;
using ll=long long;
using ld=long double;
ll I=1167167167167167167;
ll Q=1e9+7;
#define rep(i,a) for (int i=0;i<a;i++)
template<class T> using _pq = priority_queue<T, vector<T>, greater<T>>;
template<class T> ll LB(vector<T> &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> ll UB(vector<T> &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}else return 0;}
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}else return 0;}
template<class T> void So(vector<T> &v) {sort(v.begin(),v.end());}
template<class T> void Sore(vector<T> &v) {sort(v.begin(),v.end(),[](T x,T y){return x>y;});}
template<class T> void print_tate(vector<T> &v) {rep(i,v.size()) cout<<v[i]<<"\n";}
void yneos(bool a){if(a) cout<<"Yes"<<"\n"; else cout<<"No"<<"\n";}

//main関数だよーーー
int main() {
	ll K,N,M;
	cin>>K>>N>>M;
	vector<ll> ans(K),p(K);
	rep(i,K) cin>>p[i];
	vector<pair<ll,ll>> q(K);
	ll X=0;
	rep(i,K){
		ans[i]=(M*p[i])/N;
		q[i]={(M*p[i])%N,i};
		X+=q[i].first;
	}
	assert(X%N==0);
	Sore(q);
	X/=N;
	rep(i,X){
		ans[q[i].second]++;
	}
	rep(i,K){
		cout<<ans[i];
		if(i!=K-1) cout<<" ";
		else cout<<"\n";
	}
}

#include<bits/stdc++.h>
using namespace std;
long long x,y,n,m,k,ans,mm[200002],nn[200002],ff[200002],nm;
vector<int>sz[200002];
void add(int a){while(a<=nm)ff[a]++,a+=a&(-a);}
int ask(int a){int ans=0;while(a)ans+=ff[a],a-=a&(-a);return ans;}
int main(){
    scanf("%lld%lld%lld",&n,&m,&k);nm=max(n, m);
    for(int i=1;i<=nm;++i)mm[i]=m+1,nn[i]=n+1;
    for(int i=1;i<=k;++i){scanf("%lld%lld",&x,&y);mm[x]=min(mm[x],y);nn[y]=min(nn[y],x);}
    for(int i=1;i<mm[1];++i)ans+=nn[i]-1,sz[nn[i]].push_back(i);
    for(int i=mm[1];i<=m;++i)sz[1].push_back(i);
    for(int i=1;i<nn[1];++i){for(int j:sz[i])add(j);ans+=ask(mm[i]-1);}
    printf("%lld",ans);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define nln "\n"

void solve(){
	int n,k;
	cin>>n>>k;
	int sum=0;
	for(int x=1;x<=n;x++){
		for(int y=1;y<=k;y++){
			sum+=(100*x)+y;
		}
	}
	cout<<sum<<nln;
}

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

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

	return 0;
}

#include<iostream>
using namespace std;

int main() {
	int N,K;
	cin >> N >> K;
	printf("%d", 100 * K * N * (N + 1) / 2 + K * (K + 1) * N / 2);
}


#include<bits/stdc++.h>
int main()
{
    int n;
    int c=0,A,P,X,t=INT_MAX;
    scanf("%d",&n);
    while (n--)
    {
        scanf("%d %d %d",&A,&P,&X);
        if(A-X<0)
        {
            t=P<t?P:t;
            c=1;
        }
    }
    if(c==1)
        printf("%d",t);
    else
        printf("-1");
    return 0;
}

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

int main()
{
    int n;
    cin >> n;
    const int INF = 1001001001;
    int ans = INF;
    rep(i, n)
    {
        int a, p, x;
        cin >> a >> p >> x;
        if(x-a >= 1)
            ans = min(ans, p);
    }
    if(ans==INF)
        ans = -1;
    cout << ans << endl;
}


// JG GAP GG

#include <iostream>
#include <cstring>
#include<vector>
#include <algorithm>
#include<cstdlib>
#include<set>
#include<math.h>
#include<map>
#include<unordered_map>
#include<iomanip>
#include<queue>
#include<bitset>

using namespace std;
using ll = long long;
using ull = unsigned long long;
const ll MOD = 1000000007;
#define rep(n,x) for(ll i=0;i<n;i++) cin>>x[i];
#define forr(a,b) for(ll i=a;i<b;i++);
#define vecsort(myVec,x,y) sort(myVec.begin(),myVec.end(),[](const vector<y> &alpha,const vector<y> &beta){return alpha[x] < beta[x];});
#define vsort(v) sort(v.begin(),v.end());
#define vdownsort(v) sort(v.begin(),v.end(),greater<ll>());
ll modpow(ll a, ll n, ll mod)
{
	ll res = 1;
	while (0 < n)
	{
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

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

	double sx, sy, gx, gy;
	cin >> sx >> sy >> gx >> gy;
	double ans = (sy * gx + sx * gy) / (sy + gy);
	cout << fixed << setprecision(10) << ans << endl;

	return 0;
}

#include <bits/stdc++.h>

using namespace std;

#define LL long int

#define MOD const LL 1000000007;

int ans = 0;

int main(){
    long double sx,sy,gx,gy;
    cin >> sx >> sy >> gx >> gy;
    cout << fixed << setprecision(16) << (sx * gy + gx * sy)/(sy + gy) << endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define sz(v) int((v).size())
#define all(x) (x).begin(), (x).end()
#define forn(i, n) for (int i = 1; i <= int(n); ++i)
//출처: https://codeforces.com/blog/entry/68809
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '"' << x << '"';}
void __print(const string &x) {cerr << '"' << x << '"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << (#x) << "] = [", _print(x)
#else
#define debug(x...)
#endif
#define int ll

const int MOD = 998244353;
int power(int a, int n) {
    int res = 1;
    for (;n; n >>= 1, a = (a * a) % MOD)
        if (n & 1) res = (res * a) % MOD;
    return res;
}
void add(int& a, int b){a = (a%MOD + b%MOD)%MOD;}
int h, w, k;
char grid[5050][5050];
int dp[5050][5050][4];
int f(char c)
{
    return c == 'R'? 2 : (c== 'D');
}
void solve()
{
    cin>>h>>w>>k;
    forn(_, k)
    {
        int a, b; char c; cin>>a>>b>>c;
        grid[a][b] = c;
    }
    int r = h*w - k;

    if (grid[1][1]) dp[1][1][f(grid[1][1])] = power(3, r);
    else dp[1][1][3] = power(3, r);

    int p3 = power(3, MOD - 2);
    forn(i, h) forn(j, w)
    {
        if (grid[i+1][j])
        {
            add(dp[i + 1][j][f(grid[i+1][j])], dp[i][j][f('D')]);
            add(dp[i + 1][j][f(grid[i+1][j])], dp[i][j][f('X')]);
            add(dp[i + 1][j][f(grid[i+1][j])], dp[i][j][3] * p3);
            add(dp[i + 1][j][f(grid[i+1][j])], dp[i][j][3] * p3);
        }
        else
        {
            add(dp[i + 1][j][3], dp[i][j][f('D')]);
            add(dp[i + 1][j][3], dp[i][j][f('X')]);
            add(dp[i + 1][j][3], dp[i][j][3] * p3);
            add(dp[i + 1][j][3], dp[i][j][3] * p3);
        }
        if (grid[i][j+1])
        {
            add(dp[i][j + 1][f(grid[i][j+1])], dp[i][j][f('R')]);
            add(dp[i][j + 1][f(grid[i][j+1])], dp[i][j][f('X')]);
            add(dp[i][j + 1][f(grid[i][j+1])], dp[i][j][3] * p3);
            add(dp[i][j + 1][f(grid[i][j+1])], dp[i][j][3] * p3);
        }
        else
        {
            add(dp[i][j + 1][3], dp[i][j][f('R')]);
            add(dp[i][j + 1][3], dp[i][j][f('X')]);
            add(dp[i][j + 1][3], dp[i][j][3] * p3);
            add(dp[i][j + 1][3], dp[i][j][3] * p3);
        }
        // for (int k = 0; k < 4; ++k) debug(i, j, k, dp[i][j][k]);
    }

    if (grid[h][w]) cout << dp[h][w][f(grid[h][w])] << '\n';
    else cout << dp[h][w][3] << '\n';
}
signed main(void)
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int T = 1; //cin >> T;
    while (T--) solve();
    return 0;
}

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

#define _ << " " <<

string s1, s2, s3;
map<char, int> let;
vector<pair<char, int> > le;
vi tak, fir;

void getUniqLet(string &s) {
    int sz = int(s.size());
    for (int i = 0; i < sz; i++)
    {
        if (i == 0) let[s[i]] = 1;
        else let[s[i]];
    }
}

ll getNum(string &s) {
    int sz = int(s.size());
    ll n = 0, c = 1;
    for (int i = sz-1; i >= 0; i--)
    {
        n += (c * let[s[i]]);
        c *= 10;
    }
    return n;
}

bool check() {
    for (auto l : le) {
        let[l.first] = l.second;
    }
    ll a = getNum(s1);
    ll b = getNum(s2);
    ll c = getNum(s3);
    if (a + b == c) {
        cout << a << "\n";
        cout << b << "\n";
        cout << c << "\n";
        return true;
    }
    else return false;
}

bool perm(int i) {
    if (i == int(le.size())) {
        if (check()) return true;
        else return false;
    }
    int beg = 0;
    if (fir[i]) beg = 1;
    for (int d = beg; d < 10; d++)
    {
        if (!tak[d]) {
            tak[d] = 1;
            le[i].second = d;
            if (perm(i+1)) return true;
            tak[d] = 0;
        }
    }
    return false;
}

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

    cin>>s1>>s2>>s3;
    getUniqLet(s1);
    getUniqLet(s2);
    getUniqLet(s3);

    if (let.size() > 10) {
        cout << "UNSOLVABLE\n";
        return 0;
    }

    for (auto l : let) {
        le.push_back({l.first, 0});
        fir.push_back(l.second);
    }
    tak.resize(10, 0);
    if (perm(0)) return 0;

    cout << "UNSOLVABLE\n";

    return 0;
}


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

int dp[300][300];
int n;
vector<int> bucket;

bool valid(vector<int> x, vector<int> y)
{
    if (x.size() == 0 || y.size() == 0)
    {
        return false;
    }
    if (x.size() != y.size())
    {
        return true;
    }
    rep(i, x.size())
    {
        if (x[i] != y[i])
        {
            return true;
        }
    }
    return false;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    rep(i, n)
    {
        int t;
        cin >> t;
        bucket.push_back(t % 200);
    }
    dp[0][0] = 1;
    rep(i, n)
    {
        rep(j, 200)
        {
            if (dp[i][j] > 0)
            {
                dp[i + 1][j] += dp[i][j];
                dp[i + 1][(j + bucket[i]) % 200] += dp[i][j];
            }
        }
    }
    while (true)
    {
        int s = 0, t = 0;
        bool cant = true;
        rep(i, n + 1)
        {
            rep(j, 200)
            {
                if (j == 0 && dp[i][j] > 2)
                {
                    s = i;
                    t = j;
                    cant = false;
                }
                if (j > 0 && dp[i][j] > 1)
                {
                    s = i;
                    t = j;
                    cant = false;
                }
            }
        }
        if (cant)
        {
            cout << "No" << endl;
            return 0;
        }
        int i = s;
        int j = t;
        vector<int> x;
        while (i != 0 && j != 0)
        {
            if (dp[i - 1][(j + 200 - bucket[i - 1]) % 200] > 0)
            {
                j = (j + 200 - bucket[i - 1]) % 200;
                x.push_back(i);
                i--;
            }
            else
            {
                i--;
            }
        }
        i = s;
        j = t;
        vector<int> y;
        while (i != 0 && j != 0)
        {
            if (y.empty() && dp[i - 1][j] > 1)
            {
                i--;
            }
            else if (y.empty() && dp[i - 1][(j + 200 - bucket[i - 1]) % 200] > 1)
            {
                j = (j + 200 - bucket[i - 1]) % 200;
                y.push_back(i);
                i--;
            }
            else if (dp[i - 1][j] > 0)
            {
                i--;
            }
            else
            {
                j = (j + 200 - bucket[i - 1]) % 200;
                y.push_back(i);
                i--;
            }
        }
        if (valid(x, y))
        {
            reverse(x.begin(), x.end());
            reverse(y.begin(), y.end());
            cout << "Yes" << endl;
            cout << x.size();
            for (auto xi : x)
            {
                cout << ' ' << xi;
            }
            cout << endl;
            cout << y.size();
            for (auto yi : y)
            {
                cout << ' ' << yi;
            }
            cout << endl;
            return 0;
        }
        else
        {
            dp[s][t] = 0;
        }
    }
}

#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  vector<int> A(N);
  for (auto &&e : A) {
    cin >> e;
  }
  vector<vector<int>> X(200);
  for (int i = 0; i < N; i++) {
    X[A[i] % 200].emplace_back(i);
  }
  for (int i = 0; i < 200; i++) {
    if ((int)X[i].size() >= 2) {
      cout << "Yes" << '\n';
      cout << 1 << ' ' << X[i][0] + 1 << '\n';
      cout << 1 << ' ' << X[i][1] + 1 << '\n';
      return 0;
    }
  }
  vector<bitset<200>> Y(200);
  for (int i = 0; i < N; i++) {
    auto Z = Y;
    if (Y[A[i] % 200].any()) {
      cout << "Yes" << '\n';
      cout << 1 << ' ' << i + 1 << '\n';
      vector<int> c;
      for (int j = 0; j < N; j++) {
        if (Y[A[i] % 200][j]) c.emplace_back(j);
      }
      cout << c.size() << ' ';
      for (const auto &e : c) {
        cout << e + 1 << (&e == &c.back() ? '\n' : ' ');
      }
      return 0;
    }
    if (Y[0].any()) {
      cout << "Yes" << '\n';
      cout << 1 << ' ' << i + 1 << '\n';
      vector<int> c;
      for (int j = 0; j < N; j++) {
        if (Y[0][j] || i == j) c.emplace_back(j);
      }
      cout << c.size() << ' ';
      for (const auto &e : c) {
        cout << e + 1 << (&e == &c.back() ? '\n' : ' ');
      }
      return 0;
    }
    Z[A[i] % 200][i] = 1;
    for (int j = 0; j < 200; j++) {
      if (Y[j].none()) continue;
      if (Y[(j + A[i]) % 200].any()) {
        bitset<200> b = Y[(j + A[i]) % 200], c = Y[j];
        c[i] = 1;
        for (int k = 0; k < N; k++) {
          if (b[k] && c[k]) {
            b[k] = 0;
            c[k] = 0;
          }
        }
        if (b.any() && c.any()) {
          cout << "Yes" << '\n';
          vector<int> bb, cc;
          for (int k = 0; k < N; k++) {
            if (b[k]) bb.emplace_back(k);
            if (c[k]) cc.emplace_back(k);
          }
          cout << bb.size() << ' ';
          for (const auto &e : bb) {
            cout << e + 1 << (&e == &bb.back() ? '\n' : ' ');
          }
          cout << cc.size() << ' ';
          for (const auto &e : cc) {
            cout << e + 1 << (&e == &cc.back() ? '\n' : ' ');
          }
          return 0;
        }
      }
      Z[(j + A[i]) % 200] = Y[j];
      Z[(j + A[i]) % 200][i] = 1;
    }
    Y = Z;
  }
  cout << "No" << '\n';
  return 0;
}


#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <stack>
#include <cassert>
#include <map>
#include <numeric>
#include <cstring>
#include <set>
#include <ctime>
#include <queue>
#include <cmath>
#include <iomanip>
#include <iterator>
#include <bitset>
#include <unordered_map>
#include <complex>
#include <unordered_set>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

using namespace std;

clock_t timeStart, timeFinish;

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

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

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

class InputReader {
public:
    InputReader() {
        input_file = stdin;
        cursor = 0;
        fread(buffer, SIZE, 1, input_file);
    }

    InputReader(const char *file_name) {
        input_file = fopen(file_name, "r");
        cursor = 0;
        fread(buffer, SIZE, 1, input_file);
    }

    inline InputReader &operator>>(int &n) {
        while ((buffer[cursor] < '0' || buffer[cursor] > '9') && buffer[cursor] != '-') {
            advance();
        }
        int sign = 1;
        if (buffer[cursor] == '-') {
            sign = -1;
            advance();
        }
        n = 0;
        while ('0' <= buffer[cursor] && buffer[cursor] <= '9') {
            n = n * 10 + buffer[cursor] - '0';
            advance();
        }
        n *= sign;
        return *this;
    }

private:
    FILE *input_file;
    static const int SIZE = 1 << 17;
    int cursor;
    char buffer[SIZE];

    inline void advance() {
        ++cursor;
        if (cursor == SIZE) {
            cursor = 0;
            fread(buffer, SIZE, 1, input_file);
        }
    }
};

const int MOD = 1000000007;
const int MAXN = 100000;

int dp[1 + MAXN][2], sum[1 + MAXN][2], v[1 + MAXN];

int main() {
    timeBegin();
    //ifstream cin("input.in");
    //ofstream cout("output.out");
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    srand(time(0));
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> v[i];
    }
    dp[1][0] = 1;
    dp[1][1] = 0;
    sum[1][0] = v[1];
    sum[1][1] = 0;
    for (int i = 2; i <= n; i++) {
        dp[i][0] = (dp[i - 1][0] + dp[i - 1][1]) % MOD;
        dp[i][1] = dp[i - 1][0];
        sum[i][0] = (1LL * v[i] * (dp[i - 1][0] + dp[i - 1][1]) + sum[i - 1][0] + sum[i - 1][1]) % MOD;
        sum[i][1] = (1LL * (MOD - v[i]) * dp[i - 1][0] + sum[i - 1][0]) % MOD;
    }
    cout << (sum[n][0] + sum[n][1]) % MOD << "\n";
    return 0;
}

#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define maxn 100005
using namespace std;

int n,ans,ans1;
int a[maxn],dp[maxn],dp1[maxn],dp2[maxn],dp3[maxn];
//int ni[maxn];

//ni[i]=ni[mod%i]*(mod-mod/i)%mod;

int mi(int a,int t){
	ans1=1;
	while(t){
		if(t%2==1) {ans1*=a;ans1%=mod;}
		a*=a;
		a%=mod;
		t/=2;
	}
	return ans1;
}

signed main()
{
//	freopen("yhc","r",stdin);
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	dp[0]=1;
	for(int i=1;i<=n-1;i++) {
		dp1[i]=dp[i-1]%mod;
		dp[i]=(dp1[i-1]%mod+dp[i-1]%mod)%mod;
	}
	dp2[n-1]=dp[n-1];dp3[n-1]=dp1[n-1];
	for(int i=n-2;i>=1;i--) {
		dp2[i]=(dp3[i+1]%mod+dp2[i+1]%mod*mi(dp[i]+dp1[i],mod-2)%mod*dp[i]%mod)%mod;
		dp3[i]=((dp[n-1]-dp2[i])%mod+dp1[n-1]%mod)%mod;
	}
	for(int i=1;i<=n-1;i++) {
		if(dp2[i]<dp3[i]) dp2[i]+=mod;
		ans+=(dp2[i]-dp3[i])%mod*a[i+1];
		ans%=mod;
	}
	ans+=(dp[n-1]%mod+dp1[n-1]%mod)%mod*a[1];
	ans%=mod;
//	for(int i=1;i<=n-1;i++) cout<<dp[i]<<" "<<dp1[i]<<" "<<dp[i]+dp1[i]<<endl;
//	cout<<endl;
//	for(int i=1;i<=n-1;i++) cout<<dp2[i]<<" "<<dp3[i]<<" "<<dp2[i]*1.0/(dp3[i]+dp2[i])<<endl;
	cout<<ans<<endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

//begin of def

#define fastio ios_base::sync_with_stdio(false);cin.tie(0)
#define endl '\n'

using lli = long long int;
using ulli = unsigned long long int;
using Ld = long double;
using pii = pair<int, int>;
using pll = pair<lli, lli>;
using pld = pair<Ld, Ld>;
#define X first
#define Y second

#define rep(I, S, E) for(int I = (S); I < (E); I++)
#define repq(I, S, E) for(int I = (S); I <= (E); I++)

#define pb push_back
#define epb emplace_back

#define ALL(X) X.begin(), X.end()

//end of def

int main(){
    fastio;
    lli n;
    int m;
    cin >> n >> m;
    vector<pii> v(m);
    rep(i, 0, m)
        cin >> v[i].X >> v[i].Y;
    sort(ALL(v));
    set<lli> st;
    st.insert(n);
    lli nw = -2, er = -2;
    rep(i, 0, m){
        if(i && v[i].X != v[i - 1].X)
            nw = er = -2;
        int t = er;
        if(st.count(v[i].Y))
            er = v[i].Y;
        st.erase(v[i].Y);
        if((st.count(v[i].Y - 1) && nw != v[i].Y - 1) || st.count(v[i].Y + 1) || t == v[i].Y - 1){
            if(st.count(v[i].Y) == 0)
                nw = v[i].Y;
            st.insert(v[i].Y);
        }
    }
    cout << st.size();
    return 0;
}

#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	int N, M;
	cin >> N >> M;
	vector<int> X(M), Y(M);
	for (int i = 0; i < M; ++i) {
		cin >> X[i] >> Y[i];
	}
	vector<pair<int, int> > points;
	points.push_back(make_pair(0, N));
	for (int i = 0; i < M; ++i) {
		points.push_back(make_pair(X[i], Y[i]));
		points.push_back(make_pair(X[i] - 1, Y[i] - 1));
		points.push_back(make_pair(X[i] - 1, Y[i] + 1));
	}
	sort(points.begin(), points.end());
	points.erase(unique(points.begin(), points.end()), points.end());
	int S = points.size();
	vector<vector<int> > G(S);
	for (int i = 0; i < M; ++i) {
		int ptr1 = lower_bound(points.begin(), points.end(), make_pair(X[i] - 1, Y[i] - 1)) - points.begin();
		if (ptr1 != S && points[ptr1] == make_pair(X[i] - 1, Y[i] - 1)) {
			G[ptr1].push_back(lower_bound(points.begin(), points.end(), make_pair(X[i], Y[i])) - points.begin());
		}
		int ptr2 = lower_bound(points.begin(), points.end(), make_pair(X[i] - 1, Y[i] + 1)) - points.begin();
		if (ptr2 != S && points[ptr2] == make_pair(X[i] - 1, Y[i] + 1)) {
			G[ptr2].push_back(lower_bound(points.begin(), points.end(), make_pair(X[i], Y[i])) - points.begin());
		}
	}
	map<int, vector<pair<int, int> > > y_axis;
	for (int i = 0; i < S; ++i) {
		y_axis[points[i].second].push_back(make_pair(points[i].first, i));
	}
	set<pair<int, int> > pawns;
	for (int i = 0; i < M; ++i) {
		pawns.insert(make_pair(X[i], Y[i]));
	}
	for (pair<int, vector<pair<int, int> > > i : y_axis) {
		vector<pair<int, int> > v = i.second;
		sort(v.begin(), v.end());
		for (int i = 0; i < int(v.size()) - 1; ++i) {
			if (pawns.find(points[v[i + 1].second]) == pawns.end()) {
				G[v[i].second].push_back(v[i + 1].second);
			}
		}
	}
	int ini = lower_bound(points.begin(), points.end(), make_pair(0, N)) - points.begin();
	queue<int> que;
	que.push(ini);
	vector<bool> vis(S, false);
	vis[ini] = true;
	while (!que.empty()) {
		int u = que.front(); que.pop();
		for (int i : G[u]) {
			if (!vis[i]) {
				vis[i] = true;
				que.push(i);
			}
		}
	}
	int ans = 0;
	for (pair<int, vector<pair<int, int> > > i : y_axis) {
		if (vis[i.second.back().second]) {
			++ans;
		}
	}
	cout << ans << endl;
	return 0;
}


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

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

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

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

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

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

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

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

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

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

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

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

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

/**
 * Author: Daniel
 * Created Time: 2020-12-06 23:54:03
**/

// time-limit: 2000
#include <bits/stdc++.h>

using namespace std;

#define F first
#define S second
#define IS insert
#define PI acos(-1)
#define PB pop_back
#define EB emplace_back
#define lowbit(x) (x & -x)
#define SZ(x) ((int)x.size())
#define MP(x, y) make_pair(x, y)
#define ALL(x) x.begin(), x.end()
#define RALL(x) x.rbegin(), x.rend()
#define SOS; ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);cout<<fixed<<setprecision(10);

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

template <typename A> using VE = vector<A>;
template <typename A> using HEAP = priority_queue<A>;
template <typename A, typename B> using PA = pair<A, B>;
template <typename A> using RHEAP = priority_queue<A, vector<A>, greater<A> >;

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

// check the limitation!!!
const int N = 100010, M = 1010;

int n;
string t, s;

bool check()
{
    string s = t, tt = "011";
    reverse(ALL(s));
    for (int i = 0; i < n; i ++ )
        if (s[i] != tt[i % 3])
            return false;
    return true;
}

// read the question carefully!!!
int main()
{
    SOS;

    cin >> n >> t;

    if (n == 1)
    {
        if (t[0] == '0') cout << (LL)1e10 << '\n';
        else if (t[0] == '1') cout << (LL)2e10 << '\n';
        else cout << "0\n";
        return 0;
    }

    while (SZ(s) < n + 10) s += "011";

    if (t[n - 2] == '1' && t[n - 1] == '1') t += "0", n += 1;
    else if (t[n - 2] == '0' && t[n - 1] == '1') t += "10", n += 2;

    if (!check())
    {
        cout << "0\n";
        return 0;
    }

    reverse(ALL(t));

    LL res = ((LL)1e10 - n / 3LL) + !(n % 3LL);
    cout << res << '\n';
    return 0;
}

// GOOD LUCK!!!


#include <bits/stdc++.h>
using namespace std;
#define int long long int
const double pi = 3.14159265358979;
const int inf = 1e13;
const int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dy[] = {1, 0, -1, 0, 1, -1, 1, -1};
#define pii pair<int,int>
#define endl "\n"
#define dtor(deg) (((deg)/360)*2*pi)
#define all(a) a.begin(),a.end()
#define overload(_1,_2,_3,_4,name,...) name
#define _rep1(n) for(int i = 0; i < (n); i++)
#define _rep2(i,n) for(int i = 0; i < (n); i++)
#define _rep3(i,a,b) for(int i = (a); i < (b); i++)
#define _rep4(i,a,b,c) for(int i = (a); i < (b); i += (c))
#define rep(...) overload(__VA_ARGS__,_rep4,_rep3,_rep2,_rep1)(__VA_ARGS__)
#define _rrep1(n) for(int i = (n) - 1; i >= 0; i--)
#define _rrep2(i,n) for(int i = (n) - 1; i >= 0; i--)
#define _rrep3(i,a,b) for(int i = (b) - 1; i >= (a); i--)
#define rrep(...) overload(__VA_ARGS__,_null,_rrep3,_rrep2,_rrep1)(__VA_ARGS__)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
#define vv(type,name,size,...) vector<vector<type>> name(size,vector<type>(__VA_ARGS__))
#define ForEach(a,b) for_each(a.begin(),a.end(),b)
struct Edge { int to, cost; Edge(int to, int cost) : to(to), cost(cost) {} };
using Graph = vector<vector<Edge>>;
template <class T> bool chmin(T& a, T b){ if(a > b){ a = b; return 1; } return 0; }
template <class T> bool chmax(T& a, T b){ if(a < b){ a = b; return 1; } return 0; }

void Main(){
    int b, c, ans;
    cin >> b >> c;
    if(b == 0){
        cout << c << endl;
    }else if(b > 0 && c >= b * 2){
        ans = b * 2 + 1 + (c - 2);
        cout << ans << endl;
    }else if(b < 0 && c >= abs(b) * 2 + 1){
        ans = abs(b) * 2 + c;
        cout << ans << endl;
    }else if(b > 0 && c == 3){
        cout << 5 << endl;
    }else if(b > 0 && c == 2){
        cout << 3 << endl;
    }else if(b > 0 && c == 1){
        cout << 2 << endl;
    }else if(b > 0){
        cout << 5 + (c - 3) * 2 << endl;
    }else if(b < 0 && c == 3){
        cout << 5 << endl;
    }else if(b < 0 && c == 2){
        cout << 3 << endl;
    }else if(b < 0 && c == 1){
        cout << 2 << endl;
    }else if(b < 0){
        cout << 5 + (c - 3) * 2 << endl;
    }
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(10) << fixed;
    Main();
}

#include "bits/stdc++.h"
using namespace std;
//#include "testlib.h"
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define int long long
#define ll long long
#define M 1000000007
#define MM 998244353
#define inputarr(a,n) for(int i=0;i<n;++i) cin>>a[i]
#define GCD(m,n) __gcd(m,n)
#define LCM(m,n) m*(n/GCD(m,n))
#define mii  map<ll ,ll >
#define msi  map<string,ll >
#define rep(a,b)    for(ll i=a;i<b;i++)
#define rep0(n)    for(ll i=0;i<n;i++)
#define repi(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back
#define vi vector<ll>
#define vs vector<string>
#define ppb pop_back
#define endl '\n'
#define asdf ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define r0 return 0;
#define FORD(i, a, b) for (int i = (int) (a); i >= (int) (b); --i)
#define inputoutput freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define Set(a, s) (a, s, sizeof (a))
#define FOR repi
#define vii vector<pii>
#define pii pair<int,int>
#define REVERSE(v) reverse(all(v))
#define trav(a, x) for(auto& a : x)
#define display(x) trav(a,x) cout<<a<<" ";cout<<endl
#define debug cerr<<"bhau"<<endl
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
template<typename T, typename U> static inline void amin(T &x, U y)
{
    if (y < x)
        x = y;
}
template<typename T, typename U> static inline void amax(T &x, U y)
{
    if (x < y)
        x = y;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        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);
    }
};

ll max(ll a, ll b) { return (a > b)? a : b;}
int min(int a, int b) { return (a < b)? a : b;}

const int N = 1e2 + 10;
int dp[N][N][N];
bool vis[N][N][N];

int solve(){

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

    for(int i=0;i<=n;i++)
        vis[i][0][0] = 1;

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

        for(int j=n;j>=1;j--){
            for(int k=j-1;k>=0;k--){
                for(int l = n-1;l>=0;l--){
                    if(vis[j][k][l]){
                        amax(dp[j][k+1][(l+z)%j],dp[j][k][l] + z);
                        vis[j][k+1][(l+z)%j] = 1;
                    }
                }
            }
        }
    }

    int ans = 1e18;
    for(int i=1;i<=n;i++){
        if(vis[i][i][x%i]){
            int req = (x - dp[i][i][x%i])/i;

            ans = min(ans,req);
        }
    }
    cout<<ans<<endl;

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


#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); mt19937 rng((unsigned int) chrono::steady_clock::now().time_since_epoch().count());
#define F first
#define S second
#define PI  4.0*atan(1.0);
#define pb push_back
using namespace std;
typedef pair<int, int> pi;
int mod=1e9+7,gaymod=998244353,MAX=1000000000,pomod=1073741824;
//long long int gcd(long long int x,long long int  y){
  // if(y==0)return x;
   //return gcd(y,x%y);
//}
int gcd(int x,int  y){
   if(y==0)return x;
   return gcd(y,x%y);
}
ll lcm(ll a, ll b)
{
    ll g=gcd(a, b);
    return a/g*b;
}
ll binexp(ll a,ll b){
if(b==0)return 1;
ll res=binexp(a,b/2);
if(b%2)return((res%mod)*(res%mod)*(a%mod));
else return((res%mod)*(res%mod));
}
int prime(ll x){
if(x%2==0&&x!=2)
return 0;
else if(x==1)return 0;
else{
    for(int i=3;ll(i*i)<=x;i+=2){
        if(x%i==0)
            return 0;
    }
}
return 1;
}
//main
/*
vector<char> is_prime(N+1, true);
void sieve(int n){
is_prime[0] = is_prime[1] = false;
for (int i = 2; i <= n; i++) {
    if (is_prime[i] && (long long)i * i <= n) {
        for (int j = i * i; j <= n; j += i)
            is_prime[j] = false;
    }
}
}
*/
//freopen("input.txt","r",stdin);
//freopen("input.txt","w",stdin);
const int N=2e5+5;
//
int main(){
IOS;
int t=1;
//cin>>t;
while(t--){
string str;
cin>>str;
int cnt=0,bnt=0;
for(auto i:str){
    if(i=='o')cnt++;
    else if(i=='?') bnt++;
}
if(cnt>4)cout<<0;
else{
    if(cnt==1){
        cout<<(bnt+1)*(bnt+1)*(bnt+1)*(bnt+1)-bnt*bnt*bnt*bnt;
    }
    else if(cnt==2){
    int l=bnt;
    bnt=bnt*(bnt-1);
    bnt/=2;
    bnt=max(bnt,0);
    cout<<14+36*l+24*bnt;
    }
    else if(cnt==3){
        cout<<36+bnt*24;
    }
    else if(cnt==4){
        cout<<24;
    }
    else{
        if(bnt==0)cout<<0;
        else cout<<bnt*bnt*bnt*bnt;
    }
}
cout<<"\n";
}
return 0;
}


#include<cstdio>
int main()
{
	int n;
	std::scanf("%d",&n);
	std::printf("%d",n>=0?n:0);
	return 0;
}

#include <bits/stdc++.h>

#define ll long long
#define ii pair<ll, ll>
#define fi first
#define se second
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define vl vector<ll>
#define mod 1000000007
#define inf 0x3f3f3f3f
#define For(i, n) for (int i = 0; i < n; i++)
using namespace std;
class A{
public:
    void solve(){
        int x;
        cin>>x;
        if(x>=0) cout<<x<<endl;
        else cout<<0<<endl;
    }
};
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    A ans;
    ans.solve();
    return 0;
}


#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <unordered_set>
using namespace std;
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _rep(i, n) _rep2(i, 0, n)
#define _rep2(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(...) GET_MACRO(__VA_ARGS__, _rep2, _rep)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using i64 = long long;
template<class T, class U>
bool chmin(T& a, const U& b) { return (b < a) ? (a = b, true) : false; }
template<class T, class U>
bool chmax(T& a, const U& b) { return (b > a) ? (a = b, true) : false; }

template<typename T>istream& operator>>(istream&i,vector<T>&v){rep(j,v.size())i>>v[j];return i;}
template<typename T>string join(vector<T>&v){stringstream s;rep(i,v.size())s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,vector<T>&v){if(v.size())o<<join(v);return o;}
template<typename T>string join(vector<vector<T>>&vv){string s="\n";rep(i,vv.size())s+=join(vv[i])+"\n";return s;}
template<typename T>ostream& operator<<(ostream&o,vector<vector<T>>&vv){if(vv.size())o<<join(vv);return o;}

int n;

vector<int> edge[200010];

int bfs(int st)
{
    vector<int> visited(n, -1);
    queue<int> que;
    que.push(st);
    visited[st] = 0;
    while (!que.empty())
    {
        auto now = que.front();
        que.pop();
        for (auto e: edge[now])
        {
            if (visited[e] != -1) continue;
            visited[e] = visited[now] + 1;
            que.push(e);
        }
    }
    auto m = *max_element(all(visited));
    rep(i, n) if (visited[i] == m) return i;
    return -1;
}

map<int, int> mp;

bool dfs(int st, int gl, int p)
{
    if (st == gl) return true;
    for (auto e: edge[st])
    {
        if (e == p) continue;
        if (dfs(e, gl, st))
        {
            mp[st] = e;
            return true;
        }
    }
    return false;
}

int ans[200010];
int c = 1;

void dfs2(int now, int p)
{
    ans[now] = c++;
    for (auto e: edge[now])
    {
        if (e == p) continue;
        if (e == mp[now]) continue;
        dfs2(e, now);
        c++;
    }
    if (mp[now] != -1) dfs2(mp[now], now);
}

int main()
{
    cin >> n;
    rep(i, n - 1)
    {
        int a, b;
        cin >> a >> b;
        a--, b--;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }
    rep(i, n) mp[i] = -1;
    auto s = bfs(0);
    auto g = bfs(s);
    dfs(s, g, -1);
    dfs2(s, -1);
    rep(i, n) cout << ans[i] << " ";
}

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

// URL: https://atcoder.jp/contests/abc195/tasks/abc195_d

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;
using vs = vector<string>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = (int)(s); i < (int)(n); i++)

#define repll(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repsll(i, s, n) for (ll i = (ll)(s); i < (ll)(n); i++)

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

#define pb push_back
#define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)

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

const ll INFL = 1e18;
const int INF = 1e9;

int main(){
  optimize_cin();

  ll N, M, Q;
  cin >> N >> M >> Q;

  //vector<pll> WV(N);
  //vll W(N), V(N);
  vector<pll> VW(N);
  vll X(M), L(Q), R(Q);

  rep(i, N){
  ll W, V;
  // cin >> W[i] >> V[i];
  cin >> W >> V;
  VW[i] = make_pair(V, W);
  // WV[i].first() = W;
  // WV[i].second() = V;
  }
  rep(i, M) cin >> X[i];
  rep(i, Q) cin >> L[i] >> R[i];

  sort(ALL(VW));
  reverse(ALL(VW));

  // ll max = 0;

  rep(i, Q) {
  vector<bool> box(M, true);
  for(int j = L[i] - 1; j <= R[i] - 1; j++){
  box[j] = false;
  }
  vll avail;
  rep(j, M){
  if(box[j]){
  avail.pb(X[j]);
  }
  }
  sort(ALL(avail));
  // reverse(ALL(avail));
  vll used(avail.size(), false);
  int cnt = avail.size();
  ll max = 0;
  rep(j, N)
  {
  rep(k, avail.size()){
  if(cnt > 0 && !used[k] && VW[j].second <= avail[k]){
  max += VW[j].first;
  used[k] = true;
  cnt--;
  break;
  }
  }
  }
  cout << max << endl;

}

  return 0;
}


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

int main()
{  long long n , q; cin >> n; string s; cin >> s; cin >> q;
int arr[q][3]; int sum = 0;
for(int i = 0 ; i < q ; i++){
    for(int j = 0 ; j < 3 ; j++){cin >> arr[i][j];}
    if(arr[i][0]%2==0){sum++;}
    else if (arr[i][0]==1 && sum%2==0){ char a = s[arr[i][1]-1];
     s[arr[i][1]-1] =  s[arr[i][2]-1];
      s[arr[i][2]-1] = a;                }
      else{ if(arr[i][1]<=n){ arr[i][1]+=n   ;    }
      else {arr[i][1]-=n;}
      if(arr[i][2]<=n){ arr[i][2]+=n   ;    }
      else {arr[i][2]-=n;}

        char a = s[arr[i][1]-1];
     s[arr[i][1]-1] =  s[arr[i][2]-1];
      s[arr[i][2]-1] = a;
      }

} if(sum%2==0){cout << s << endl; return 0;}
else{s = s.substr(n,n)+s.substr(0,n);
}
cout << s << endl;

}


#include <bits/stdc++.h>
/* #include <atcoder/lazysegtree> */
#include <iostream>
#include <regex>
using namespace std;
/* using namespace atcoder; */
using pint = pair<int, int>;
using ll = long long;
using ull = unsigned long long;
using vll = vector<long long>;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) \
    for (long long 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 VREP(s, ite) for (auto ite = s.begin(); ite != s.end(); ++ite)
#define FI first
#define SE second
#define ALL(v) v.begin(), v.end()
#define endl "\n"
#define ciosup  \
    cin.tie(0); \
    ios::sync_with_stdio(false);
#define eb emplace_back
#define vint vector<int>
constexpr ll INF = 1e15 + 7LL;
constexpr ll MOD = 998244353LL;
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
    for (int i = 0; i < v.size(); ++i) {
        is >> v[i];
    }
    return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    if (v.size() == 0) return os;
    for (int i = 0; i < v.size() - 1; ++i) {
        os << v[i] << " ";
    }
    os << v[v.size() - 1];
    return os;
}
template <typename... T>
void In(T&&... args) {
    (std::cin >> ... >> args);
}
template <typename T, typename ...Tail>
void Out(T head, Tail... tail) {
    std::cout << head;
    if constexpr(sizeof...(tail) > 0) {
        std::cout << ' ';
        Out(tail...);
    } else {
        std::cout << '\n';
    }

}

ll sq_ll(ll x) {
    ll lo = 0, hi = 3e9;
    while (hi - lo > 1) {
        ll mid = (hi + lo) / 2LL;
        if (mid*mid <= x) {
            lo = mid;
        } else {
            hi = mid;
        }
    }
    return lo;
}

ll helper1(ll x) {
    if (x < 0) {
        x += abs(x) % 10000;
    } else if (x > 0) {
        if (x % 10000 != 0)
            x += 10000 - (x % 10000);
    }
    return x;
}

ll helper2(ll x) {
    if (x > 0) {
        x -= x % 10000;
    } else if (x < 0) {
        if (abs(x) % 10000 != 0)
            x -= 10000 - (abs(x) % 10000);
    }
    return x;
}

void solve() {
    double x,y,r; In(x,y,r);
    ll xi = round(x*10000), yi = round(y*10000), ri = round(r*10000);
    ll up = yi + ri, down = yi - ri;
    while (abs(down) % 10000 != 0) ++down;
    ll ans = 0, cur = down;
    while (cur <= up) {
        ll xwidsq = ri*ri - (yi-cur)*(yi-cur);
        ll xwid = sq_ll(xwidsq);
        ll xlow = helper1(xi - xwid)/10000LL, xup = helper2(xi + xwid)/10000LL;
        if (xup >= xlow) ans += xup - xlow + 1;

        cur += 10000;
    }
    Out(ans);
}

int main() {
    solve();
    char tmp;
    while (cin >> tmp) {
        cin.putback(tmp);
        solve();
    }
}

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds; //required
using namespace std;
template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define debug(x) cout << #x << " is " << x << "\n"
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define flush cout.flush()
typedef long long ll;
const int MOD = 1e9 + 7;
const ll INF = 0x3f3f3f3f3f3f3f3f;

// ll floor1(ll d, ll t){
//     return d / (t + 1);
// }

// earliest time
ll calc(ll t0, ll c, ll d){
    ll mid = max(t0 + 1, (ll) sqrt(d));
    ll res = c + t0 + d / (t0 + 1);
    res = min(res, c + (mid - 1) + d / mid);
    res = min(res, c + (mid) + d / (mid + 1));
    res = min(res, c + (mid + 1) + d / (mid + 2));
    return res;

    // ll lo = t0 + 1, hi = d + 1;
    // if (lo < hi){
    //     ll mid = lo + (hi - lo) / 2;
    //     if (d / (mid + 1) - d / (mid + 2) > 1){
    //         lo = mid + 1;
    //     }
    //     else{
    //         hi = mid;
    //     }
    // }
    // debug(lo);
    // return c + lo + d / (lo + 1);
}

int main(){
    fast;
    int n, m;
    cin >> n >> m;
    vector<vector<tuple<int, ll, ll>>> edges(n + 1);
    vector<ll> time(n + 1, INF);
    vector<bool> vis(n + 1, false);
    time[1] = 0;
    int a, b;
    ll c, d;
    for (int i = 0; i < m; ++i){
        cin >> a >> b >> c >> d;
        if (a != b){
            edges[a].emplace_back(make_tuple(b, c, d));
          	edges[b].emplace_back(make_tuple(a, c, d));
        }

    }
    priority_queue<pair<ll, int>> q;
    q.push(make_pair(0, 1));
    int u;
    ll t, tnew;
    while (q.size()){
        t = -q.top().first;
        u = q.top().second;
        q.pop();
        if (vis[u]){
            continue;
        }
        vis[u] = true;
        for (auto [v, c, d]: edges[u]){
            // debug(u);
            // debug(v);
            tnew = calc(t, c, d);
            if (tnew < time[v]){
                time[v] = tnew;
                // cout << ' ' << v << ' ' << tnew << endl;
                q.push(make_pair(-tnew, v));
            }
        }
    }
    // for (int i = 1; i <= n; ++i){
    //     cout << ' ' << time[i];
    // }
    // cout << '\n';
    if (!vis[n]){
        cout << -1 << endl;
    }
    else {
        cout << time[n] << endl;
    }
    return 0;
}


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

int main() {
	char c1, c2, c3;
	cin >> c1 >> c2 >> c3;
	cout << ((c1 == c2 && c1 == c3) ? "Won" : "Lost") << endl;
}

#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
void*wmem;
char memarr[96000000];
template<class T> inline void walloc1d(T **arr, int x, void **mem = &wmem){
  static int skip[16] = {0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
  (*mem) = (void*)( ((char*)(*mem)) + skip[((unsigned long long)(*mem)) & 15] );
  (*arr)=(T*)(*mem);
  (*mem)=((*arr)+x);
}
template<class T> inline void walloc1d(T **arr, int x1, int x2, void **mem = &wmem){
  walloc1d(arr, x2-x1, mem);
  (*arr) -= x1;
}
inline int my_getchar_unlocked(){
  static char buf[1048576];
  static int s = 1048576;
  static int e = 1048576;
  if(s == e && e == 1048576){
    e = fread_unlocked(buf, 1, 1048576, stdin);
    s = 0;
  }
  if(s == e){
    return EOF;
  }
  return buf[s++];
}
inline void rd(long long &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = my_getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = my_getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
struct MY_WRITER{
  char buf[1048576];
  int s;
  int e;
  MY_WRITER(){
    s = 0;
    e = 1048576;
  }
  ~MY_WRITER(){
    if(s){
      fwrite_unlocked(buf, 1, s, stdout);
    }
  }
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar_unlocked(int a){
  if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
    fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
    MY_WRITER_VAR.s = 0;
  }
  MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
  my_putchar_unlocked(a);
}
inline void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    my_putchar_unlocked(c[i]);
  }
}
template<class T> int Factor_L(T N, T fac[], int fs[]){
  T i;
  int sz = 0;
  if(N%2==0){
    fac[sz] = 2;
    fs[sz] = 1;
    N /= 2;
    while(N%2==0){
      N /= 2;
      fs[sz]++;
    }
    sz++;
  }
  for(i=3;i*i<=N;i+=2){
    if(N%i==0){
      fac[sz] = i;
      fs[sz] = 1;
      N /= i;
      while(N%i==0){
        N /= i;
        fs[sz]++;
      }
      sz++;
    }
  }
  if(N > 1){
    fac[sz] = N;
    fs[sz] = 1;
    sz++;
  }
  return sz;
}
template<class T> int Divisor_L(T N, T res[], void *mem = wmem){
  int i;
  int j;
  int k;
  int s;
  int sz = 0;
  T*fc;
  int*fs;
  int fsz;
  walloc1d(&fc, 100, &mem);
  walloc1d(&fs, 100, &mem);
  fsz =Factor_L(N, fc, fs);
  res[sz++] = 1;
  for(i=(0);i<(fsz);i++){
    s = sz;
    k = s * fs[i];
    for(j=(0);j<(k);j++){
      res[sz++] = res[j] * fc[i];
    }
  }
  sort(res, res+sz);
  return sz;
}
int ys;
long long y[100000];
int main(){
  int i;
  wmem = memarr;
  long long S;
  rd(S);
  long long P;
  rd(P);
  ys =Divisor_L(P, y);
  for(i=(0);i<(ys);i++){
    if(y[i] + (P/y[i]) == S){
      wt_L("Yes");
      wt_L('\n');
      return 0;
    }
  }
  wt_L("No");
  wt_L('\n');
  return 0;
}
// cLay version 20201121-1

// --- original code ---
// int ys; ll y[1d5];
// {
//   ll @S, @P;
//   ys = Divisor(P, y);
//   rep(i,ys) if(y[i] + (P/y[i]) == S) wt("Yes"), return 0;
//   wt("No");
// }


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

#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define fi first
#define se second
#define mset(a,b) memset(a, b, sizeof(a))
#define dbg(x) cout << "[" << #x << "]: " << x << endl;
#define forn(i,n) for(int i=0; i < n;i++)
#define forab(i,a,b) for(int i = a; i <= b; i++)
#define forba(i,b,a) for(int i = b; i >= a; i--)
#define each(val, v) for(auto val : v)
#define abs(u) (u >= 0 ? u : -u)

using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;

const int MAXN = 2e5 + 5;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9+7;

void solve(){

    int n,m;
    cin >> n >> m;
    vi w(n);
    int mais_gordo = 0;
    forn(i,n){
        cin >> w[i];
        mais_gordo = max(mais_gordo, w[i]);
    }

    vector<pii> a(m);
    int minn_guenta = INF;
    forn(i,m){
        cin >> a[i].fi;
        cin >> a[i].se;
        minn_guenta = min(minn_guenta, a[i].se);
    }

    if(mais_gordo > minn_guenta){
        cout << -1 << '\n';
        return;
    }

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

    stack<pii> s;

    forn(i,m){
        while(!s.empty() && s.top().se > a[i].se){
            s.pop();
        }
        s.push(a[i]);
    }

    vector<pii> valids;

    while(!s.empty()){
        pii aux = s.top();
        valids.pb(aux);
        s.pop();
    }

    m = valids.size();
    reverse(valids.begin(), valids.end());

    if(n == 1){
        cout << 0 << '\n';
        return;
    }

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

    int maior = w[n-1];
    w.pop_back();

    int ans = INF;
    do{

        vi a(n);

        forn(i,n-1){
            a[i] = w[i];
        }

        a[n-1] = maior;

        vi min_v(n,0);

        forn(i, n-1){
            int my = min_v[i];

            int at = 0;
            int vat = 0;
            int soma = w[i];

            for(int j = i+1; j < n; j++){
                soma += w[j];
                while( at < m && valids[at].se < soma){

                    vat = valids[at].fi;
                    at++;

                }

                min_v[j] = max(min_v[j], vat+min_v[i]);
            }
        }

        ans = min(ans, min_v[n-1]);

    }while(  next_permutation(w.begin(), w.end()));

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

int main(){

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

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

    return 0;
}

// #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

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

typedef long long int ll;
#define endl '\n'
#define ld long double
#define all(a) a.begin(),a.end()
#define int long long
#define pb push_back
#define pii pair <int, int>
#define ff first
#define ss second
#define sz(v) (int)v.size()
#define UB upper_bound
#define LB lower_bound
#define BP(x) __builtin_popcountll(x)
#define PQS priority_queue <int, vector<int>, greater<int> >
#define OST tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update>
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int getRand(int l, int r) {
  uniform_int_distribution<int> uid(l, r);
  return uid(rng);
}

const int INF = 1e18 + 0;
const int mod = 1e9 + 7;
//const int mod = 998244353;
const int N = 1e5+ 5;

int dp[10][10], pre[10], cap[N], L[N];
vector <pii> vv;

bool com(pii p1, pii p2) {
  if(p1.ff == p2.ff) return p1.ss > p2.ss;
  return p1.ff > p2.ff;
}

int get(int x, int m) {
  int lo = 0, hi = m-1;
  int ret = 0;

  while(hi >= lo) {
    int mid = (hi + lo)/2;
    if(x > vv[mid].ff) {
      ret = max(ret, vv[mid].ss);
      hi = mid-1;
    }
    else lo = mid+1;
  }
  return ret;
}

void solve() {
  int n, m, f = 0;
  cin >> n >> m;

  vector <int> v(n+1,0);

  for(int i = 1; i <= n; i++) cin >> v[i];
  sort(v.begin()+1, v.end());

  for(int i = 1; i <= m; i++) {
    cin >> L[i] >> cap[i];
    if(v.back() > cap[i]) f = 1;
    vv.pb({cap[i], L[i]});
  }

  if(f) {
    cout << "-1\n"; return;
  }

  sort(all(vv), com);

  int mx = -1;
  for(int i = m-1; i >= 0; i--) {
    mx = max(vv[i].ss, mx);
    vv[i].ss = mx;
  }

  int ans = INF;
  do {
    memset(dp,0,sizeof(dp));
    memset(pre,0,sizeof(pre));

    for(int i = 1; i <= n; i++) {
      pre[i] = v[i] + pre[i-1];
    }

    for(int i = 1; i <= n; i++) {
      for(int j = i+1; j <= n; j++) {
         int x = pre[j] - pre[i-1];
         int res = get(x, m);
         dp[i][j] =res;
      }
    }
    for(int i = 1; i <= n; i++) {
      for(int j = 1; j <= n; j++) {
         for(int k = i; k <= j; k++) {
           dp[i][j] = max(dp[i][j], dp[i][k] + dp[k][j]);
         }
      }
    }
    ans = min(ans, dp[1][n]);

  } while(next_permutation(v.begin()+1, v.end()));

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

/*
  * overflow, array bounds
  * do smth instead of nothing and stay organized
*/
signed main() {
  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

  #ifndef ONLINE_JUDGE
   freopen("input.txt", "r", stdin);
   freopen("output.txt", "w", stdout);
  #endif
   int t = 1; //cin >> t;
   for(int i = 1; i <= t; i++) {
   //  cout << "Case #" << i << ": ";
     solve();
  }
}

/*

*/


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

int main() {
	int N, M;
	cin >> N >> M;
	vector<set<int>> Graph(N);
	vector<int> A(M), B(M);
	for (int i = 0; i < M; i++) cin >> A[i] >> B[i], A[i]--, B[i]--;
	for (int i = 0; i < M; i++) {
		Graph[A[i]].insert(B[i]);
		Graph[B[i]].insert(A[i]);
	}

	vector<bool> comp(1 << N, false);
	for (int i = 0; i < N; i++) {
		comp[1 << i] = true;
	}
	for (int i = 1; i < (1 << N); i++) {
		if (!comp[i]) continue;
		for (int j = 0; j < N; j++) {
			if (i & (1 << j)) continue;
			bool judge = true;
			for (int k = 0; k < N; k++) {
				if ((i & (1 << k)) && !(Graph[j].count(k))) judge = false;
			}
			if (judge) comp[i | (1 << j)] = true;
		}
	}

	vector<int> dp(1 << N, 18);
	dp[0] = 0;
	for (int i = 0; i < (1 << N); i++) {
		int revi = (((1 << N) - 1) ^ i);
		for (int j = revi; j &= revi; j--) {
			if (comp[j]) {
				dp[i ^ j] = min(dp[i ^ j], dp[i] + 1);
			}
		}
	}

	cout << dp[(1 << N) - 1] << endl;
}

#include <bits/stdc++.h>
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep1(i,n) for (int i = 1; i <= (n); ++i)
#define bit(n,k) ((n>>k)&1) //nのk　bit目
#define vec(T) vector<T>
#define vvec(T) vec(vec(T))
using ll = long long;
using P = pair<int,int>;

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 llINF = 1LL << 60;
const int iINF = 1e9;

//------------------------------------------------
struct Solver{
    void solve(){
        int N,M;
        cin >> N >> M;

        vec(int) ed(N); //ある頂点から辺のつながってる先リスト

        rep(i,M){
            int a,b;
            cin >> a >> b;
            --a; --b;
            ed[a] |= 1<<b; // ビットで情報を保存
            ed[b] |= 1<<a;
        }

        vec(int) dp(1<<N, iINF);
        dp[0]=1;

        // 全結合の集合のとこを1に初期化
        rep(si,1<<N)rep(ni,N){
            // siが全結合かつsiの集合に頂点niを足しても全結合なら1
            if( dp[si]==1 && (ed[ni]&si)==si ) dp[si | 1<<ni] = 1;
        }

        // dp
        rep1(si,(1<<N)-1){
            for(int sj=si; (--sj)&=si  ; ){

                if( sj&si ) chmin(dp[si], dp[si^sj]+dp[sj]);
            }
        }
        cout << dp.back() << endl;

    }
};

int main(){
    int testcasenum=1;
    //cin >> testcasenum;
    rep1(ti,testcasenum){
        Solver solver;
        solver.solve();
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fastIO ios_base::sync_with_stdio(false); cin.tie(0);
int main()
{
    fastIO;
    ll n;
    cin>>n;
    ll i = 1;
    while(i) {
        ll temp = stoll(to_string(i) + to_string(i));
        if(temp > n) {
            cout<<i-1<<endl;
            break;
        }
        i++;
    }

}

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

int main() {
  long long n, c = 0;
  cin >> n ;
  for(int i = 1; stoll(to_string(i)+to_string(i)) <= n ; i++) c++;
  cout << c ;
}


#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>
#include<time.h>
typedef long long int ll;
//#include<bits/stdc++.h>

using namespace std;

int main()
{
    int n; int x;
    cin >> n >> x;
    int t = -1;
    x *= 100;
    for (int i = 0; i < n; i++) {
        double a, b;
        cin >> a >> b;

        x -= a * b;
        if (x < 0&&t==-1)t = i + 1;
    }
    cout << t << endl;

    return 0;

}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    double t;
    cin>>t;
    long long n;
    cin>>n;
    long long res = ceil((n*100)/t) + n-1;
    cout<<res;
}


#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
int cnt1[500][500];
int cnt2[500][500];
int team[500][500];
int tgt=0;
bool deta=false;
int col[500][500];

int main(void){
	scanf("%d",&n);
	if(n==1){
		printf("1\n");
		printf("AB\n");
		return 0;
	}
	if(n==2){
		printf("3\n");
		printf("AABB\n");
		printf("ABAB\n");
		printf("ABBA\n");
		return 0;
	}
	col[0][2]=1;
	col[0][3]=1;
	col[1][1]=1;
	col[1][3]=1;
	col[2][1]=1;
	col[2][2]=1;
	int m=(1<<n);
	int s=2;
	int sz=3;
	int len=4;
	for(int i=2;i<n;i++){
		for(int j=0;j<sz;j++){
			for(int k=0;k<len;k++){
				col[j+sz][k]=col[j][k];
			}
		}
		for(int j=0;j<sz;j++){
			for(int k=0;k<len;k++){
				col[j][k+len]=col[j][k];
				col[j+sz][k+len]=1-col[j+sz][k];
			}
		}
		for(int j=0;j<len;j++){
			col[sz*2][j+len]=1;
		}
		sz=sz*2+1;
		len=len*2;
	}
	printf("%d\n",m-1);
	for(int i=0;i<m-1;i++){
		for(int j=0;j<m;j++){
			printf("%c",col[i][j]==0?'A':'B');
		}
		printf("\n");
	}
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define pp pair<ll,ll>
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
int inf=1000001000;
ll INF=2e18;
ll mod=1000000007;
ll MOD=998244353;

int main() {
   int t;
   cin >> t;
   rep(ii,t){
     int n;
     cin >> n;
     vector<int> a(n);
     rep(i,n) cin >> a[i];
     if (n%2==0){
       sort(all(a));
       bool t=true;
       rep(i,n/2){
         if (a[i*2]!=a[i*2+1]) t=false;
       }
       if (t) cout << "Second" << endl;
       else cout << "First" << endl;
     }
     else cout << "Second" << endl;
   }
}