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

#define ll long long int
#define absdiff(a,b) (a>b)?a-b:b-a
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define fast  ios_base::sync_with_stdio(false);cin.tie(0);
#define MOD 1000000007
#define ll_MAX 19223372036859
#define endl "\n"
ll fast_expo(ll x,ll p){
  if(p==0) return 1;
  else if(p%2==0){ ll t=fast_expo(x,p/2)%MOD;return (t*t)%MOD;}
  else return (x*(fast_expo(x,p-1))%MOD)%MOD;}

ll dp[1005][1005], n, m, arr1[1005], arr2[1005];
vector<ll> AdjL[1005];

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

  ll t_c; t_c = 1;
  // cin >> t_c;

  for(ll t_i = 0; t_i < t_c; ++t_i){
    ll n, m; cin >> n >> m;
    ll a[n + 1], b[m + 1];
    for(ll i = 1; i <= n; ++i)
      cin >> a[i];
    for(ll i = 1; i <= m; ++i)
      cin >> b[i];

    ll dp[n + 1][m + 1];
    for(ll j = 0; j <= m; ++j){
      dp[0][j] = j;
    }

    for(ll i = 1; i <= n; ++i){
      dp[i][0] = i;
      for(ll j = 1; j <= m; ++j){
        if(a[i] == b[j]) dp[i][j] = dp[i - 1][j - 1];
        else dp[i][j] = min({dp[i - 1][j] + 1, dp[i][j - 1] + 1, dp[i - 1][j - 1] + 1});
      }
    }

    cout << dp[n][m];
  }
  return 0;
}

#include <bits/stdc++.h>

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}
ll mod_pow(ll a, ll n, ll mod) { ll ret = 1; ll p = a % mod; while (n) { if (n & 1) ret = ret * p % mod; p = p * p % mod; n >>= 1; } return ret; }

struct Frac {
    // a/b
    ll a, b;
};

const int mod = 1e9 + 7;

Frac mul_f(Frac x, Frac y) {
    ll a = x.a * y.a % mod;
    ll b = x.b * y.b % mod;
    return (Frac){a, b};
}

Frac plus_f(Frac x, Frac y) {
    ll a = (x.a * y.b) % mod + (x.b * y.a) % mod;
    ll b = x.b * y.b % mod;
    return (Frac){a, b};
}

ll calc(Frac x) {
    return x.a * mod_pow(x.b, mod - 2, mod) % mod;
}

vector<vector<Frac>> mul(vector<vector<Frac>> &A, vector<vector<Frac>> &B) {
    int N = A.size(), M = B[0].size(), K = A[0].size();
    vector<vector<Frac>> C(N, vector<Frac>(K, {0, 1}));
    for(int i = 0; i < N; i++) {
        for(int j = 0; j < M; j++) {
            Frac sum = {0, 1};
            for(int k = 0; k < K; k++) {
                sum = plus_f(sum, mul_f(A[i][k], B[k][j]));
            }
            C[i][j] = sum;
        }
    }
    return C;
}

vector<vector<Frac>> retE(int n) {
    vector<vector<Frac>> ret(n, vector<Frac>(n, {0, 1}));
    for (int i = 0; i < n; i++) {
        ret[i][i] = {1, 1};
    }
    return ret;
}

vector<vector<Frac>> pow(vector<vector<Frac>> &A, int n) {
    if (n == 0) {
        return retE(A.size());
    }
    vector<vector<Frac>> ret = retE(A.size());
    if (n % 2 == 1) {
        ret = mul(ret, A);
    }
    vector<vector<Frac>> half = pow(A, n / 2);
    ret = mul(ret, half);
    ret = mul(ret, half);
    return ret;
}

void solve() {
    int N, M, K;
    cin >> N >> M >> K;
    vector<vector<Frac>> A(N, vector<Frac>(1, {0, 1}));
    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        A[i][0] = {a, 1};
    }

    vector<vector<int>> G(N, vector<int>(N));
    vector<int> V(N);
    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        V[a]++; V[b]++;
        G[a][b] = 1;
        G[b][a] = 1;
    }

    vector<vector<Frac>> T(N, vector<Frac>(N, {0, 1}));
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            if (i == j) {
                ll a = 2 * (M - V[i]) + V[i];
                ll b = 2 * M;
                T[i][j] = {a, b};
            } else {
                if (G[i][j]) {
                    T[i][j] = {1, 2 * M};
                }
            }
        }
    }
    vector<vector<Frac>> TT = pow(T, K);
    vector<vector<Frac>> ans = mul(TT, A);

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

    return;
}

int main() {
    #ifdef LOCAL_ENV
    cin.exceptions(ios::failbit);
    #endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);

    solve();
}


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

    rep(i, n){
        int x, y;
        cin >> x >> y;
        if(x < s && y > d){
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;
return 0;
}

#include<bits/stdc++.h>

using namespace std;

int main(){

     int a,b,c;
     cin>>a>>b>>c;
     if(a!=b && a==c){
          cout<<b<<endl;
     }
     else if(a==b && a==c){
          cout<<a<<endl;
     }else if(a!=b && b!= c){
          cout<<0<<endl;
     }
     else if(a!=b && a!=c){
          cout<<a<<endl;
     }else{
          cout<<c<<endl;
     }
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define pb push_back
#define fi first
#define se second
#define int long long
typedef long long ll;
typedef long double ld;
#define PI 3.14159265

// 🍪 DEBUG FUNCTIONS START
#define cerr cout
void __print(int 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 deb(x...) cerr << "[" << #x << "] = "; _print(x)
#define deb(x...)  _print(x)
#else
#define deb(x...)
#endif
// 🍪 DEBUG FUNCTIONS END

const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const ll infl = 0x3f3f3f3f3f3f3f3fLL;

void solve()
{
    int n, k;
    cin >> n >> k;
    int ans = 0;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= k; j++){
            int sum = i * 100 + j;
            ans += sum;
        }
    }
    cout << ans << "\n";
}
signed main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());
    int t;
    t=1;
    while(t--)
    {
      solve();
    }
}

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

using namespace std;

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

template<typename T>
istream &operator>>(istream &in, vector<T> &a) {
    for (auto &i : a)
        in >> i;
    return in;
}

template<typename T>
ostream &operator<<(ostream &out, const vector<T> &a) {
    for (auto &i : a) {
        out << i << " ";
    }
    return out;
}

template<typename T, typename D>
istream &operator>>(istream &in, pair<T, D> &a) {
    in >> a.first >> a.second;
    return in;
}

template<typename T, typename D>
ostream &operator<<(ostream &out, const pair<T, D> &a) {
    out << a.first << " " << a.second;
    return out;
}

struct LogOutput {
    template<typename T>
    LogOutput &operator<<(const T &x) {
#ifdef DIVAN
        cout << x;
#endif
        return *this;
    }
} dout, fout;

typedef long long ll;
typedef unsigned long long ull;
typedef double dl;
typedef complex<double> cd;

#define nl '\n'
#define elif else if
#define all(_v) _v.begin(), _v.end()
#define rall(v) v.rbegin(), v.rend()
#define sz(v) (int)(v.size())
#define sqr(_v) ((_v) * (_v))
#define vpi vector<pair<int, int>>
#define eb emplace_back
#define pb push_back
#define mod(x, m) ((x) >= 0 ? ((x) % m) : ((((x) % m) + m) % m))
#define vi vector<int>
#define pi pair<int, int>
#define ti tuple<int, int, int>
#define minq(x, y) x = min((x), (y))
#define maxq(x, y) x = max(x, (y))
#define forn(i, n) for (int i = 0; i < (n); ++i)

const ll INFL = 9187201950435737471;
const ll nINFL = -9187201950435737472;
const int INF = 2139062143;
const int nINF = -2139062144;
const ull ULINF = numeric_limits<ull>::max();
const long double PI = acos(-1);
auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937 rnd(0);

inline void IO() {
#ifdef DIVAN
    freopen("../input.txt", "r", stdin);
    freopen("../output.txt", "w", stdout);
#else
    //    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif
}

#define int ll

const int MAXN = 3e6 + 100;

int sum2[MAXN], pSum2[MAXN], sum3[MAXN];

void Solve() {
    int n, k;
    cin >> n >> k;
    for (int a = 1; a <= n; ++a) {
        sum2[a + 1]++;
        sum2[a + n + 1]--;
    }
    int res = 0;
    for (int i = 2; i < MAXN; ++i) {
        res += sum2[i];
        sum2[i] = res;
    }
    for (int i = 1; i < MAXN; ++i) {
        pSum2[i] = pSum2[i - 1] + sum2[i];
    }
    for (int i = 3; i <= 3 * n; ++i) {
        int l = max(2ll, i - n), r = min(2 * n, i - 1);
        assert(l <= r);
        sum3[i] = pSum2[r] - pSum2[l - 1];
    }
    int needSum = 3;
    while(k > sum3[needSum]) {
        k -= sum3[needSum];
        needSum++;
    }
    int a = 1;
    while(k > sum2[needSum - a]) {
        k -= sum2[needSum - a];
        ++a;
    }
    for (int b = 1; b <= n; ++b) {
        int c = needSum - a - b;
        if (c > n) {continue;}
        if (k == 1) {
            cout << a << ' ' << b << ' ' << c;
            return;
        }
        --k;
    }
}

signed main() {
    IO();
    int t = 1;
//    cin >> t;
    int startTime = clock();
    for (int i = 1; i <= t; ++i) {
//        cout << "Case #" << i << ": ";
        Solve();
    }
    int endTime = clock();
    fout << '\n' << "Time: " << (endTime - startTime + 999) / 1000;
    return 0;
}


#include <iostream>
#include <iomanip> //<<setprecision(12), or <<fixed
#include <algorithm>
#include <functional>
#include <map>
#include <vector>
#include <queue>
#include <cmath>
#include <set>

using namespace std;

using ll=long long;
using ull=unsigned long long;
using pll=pair<ll,ll>;

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

    vector<vector<vector<double>>> dp(101,vector<vector<double>>(101,vector<double>(101,-1)));
    for(ll i=0; i<=100; i++)
    {
        for(ll k=0; k<=100; k++)
        {
            dp[100][i][k]=0;
            dp[i][100][k]=0;
            dp[i][k][100]=0;
        }
    }

    auto e=[&](auto& e, ll a, ll b, ll c)
    {
        if(dp[a][b][c]!=-1) return dp[a][b][c];

        double res=(e(e,a+1,b,c)+1)*a/(double)(a+b+c)
                    +(e(e,a,b+1,c)+1)*b/(double)(a+b+c)
                    +(e(e,a,b,c+1)+1)*c/(double)(a+b+c);

        dp[a][b][c]=res;
        return res;
    };

    cout<<fixed<<setprecision(15)<<e(e,A,B,C)<<endl;
    // Fear misreading.
    return 0;
}

#include<bits/stdc++.h>
#define ST first
#define ND second
#define ll long long
#define ld long double
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
using namespace std;

const ll  INF = 1e9 + 9;
//const ll  MOD = 1e9 + 7;
const ll MOD = 998244353;
const long long LINF = (ll)1e18 + 3;

// secik.insert({x, t++});
// secik.erase(secik.lower_bound({x,-1}));
// *secik.find_by_order(x)).first << "\n";
// secik.order_of_key(x)

//random_device device;
//mt19937 gener(device());
//uniform_int_distribution<ll > gen(0,n-1);
//gen(gener); // generate random number

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

	ll A,B,C; cin >> A >> B >> C;

	ll x = A * (A+1)/2, y = B * (B+1)/2, z = C * (C+1)/2;
	x %= MOD;
	y %= MOD;
	z %= MOD;
	cout << max(((x * y) % MOD * z) % MOD,(((x * y) % MOD * z) % MOD + MOD) % MOD);

	return 0;
}


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

int h[30][29], v[29][30], hc[30][29], vc[29][30];
int si, sj, ti, tj, prev_si, prev_sj, prev_ti, prev_tj;
int prev_result;
int i=0, j=0;

int border=3;
int repeat_count=1000;

string query(int si, int sj, int ti, int tj){
 string path;
 while(si!=ti || sj!=tj){
  if(si==ti){
   if(sj<tj){
    path=path+"R";
    sj++;
   }
   else{
    path=path+"L";
    sj--;
   }
  }
  else if(sj==tj){
   if(si<ti){
    path=path+"D";
    si++;
   }
   else{
    path=path+"U";
    si--;
   }
  }
  //左上
  else if(si<ti && sj<tj){
   if(hc[si][sj]<border || vc[si][sj]<border){
    if(hc[si][sj]<vc[si][sj]){
     path=path+"R";
     sj++;
    }
    else{
     path=path+"D";
     si++;
    }
   }
   else if(h[si][sj]<v[si][sj]){
    path=path+"R";
    sj++;
   }
   else{
    path=path+"D";
    si++;
   }
  }
  //左下
  else if(si>ti && sj<tj){
   if(hc[si][sj]<border || vc[si-1][sj]<border){
    if(hc[si][sj]<vc[si-1][sj]){
     path=path+"R";
     sj++;
    }
    else{
     path=path+"U";
     si--;
    }
   }
   else if(h[si][sj]<v[si-1][sj]){
    path=path+"R";
    sj++;
   }
   else{
    path=path+"U";
    si--;
   }
  }
  //右下
  else if(si>ti&& sj>tj){
   if(hc[si][sj-1]<border || vc[si-1][sj]<border){
    if(hc[si][sj-1]<vc[si-1][sj]){
     path=path+"L";
     sj--;
    }
    else{
     path=path+"U";
     si--;
    }
   }
   else if(h[si][sj-1]<v[si-1][sj]){
    path=path+"L";
    sj--;
   }
   else{
    path=path+"U";
    si--;
   }
  }
  //右上
  else{
   if(hc[si][sj-1]<border || vc[si][sj]<border){
    if(hc[si][sj-1]<vc[si][sj]){
     path=path+"L";
     sj--;
    }
    else{
     path=path+"D";
     si++;
    }
   }
   else if(h[si][sj-1]<v[si][sj]){
    path=path+"L";
    sj--;
   }
   else{
    path=path+"D";
    si++;
   }
  }
 }
 return path;
}

void sethv(int prev_si, int prev_sj, string prev_path, int prev_result){
 int delta=(int)round(prev_result/prev_path.length())-5000;
 while(prev_path.empty()==0){
  if(prev_path[0]=='R'){
   h[prev_si][prev_sj]=(int)round((h[prev_si][prev_sj]*hc[prev_si][prev_sj]+delta)/(hc[prev_si][prev_sj]+1));
   hc[prev_si][prev_sj]++;
   prev_sj++;
  }
  else if(prev_path[0]=='D'){
   v[prev_si][prev_sj]=(int)round((v[prev_si][prev_sj]*vc[prev_si][prev_sj]+delta)/(vc[prev_si][prev_sj]+1));
   vc[prev_si][prev_sj]++;
   prev_si++;
  }
  else if(prev_path[0]=='L'){
   h[prev_si][prev_sj-1]=(int)round((h[prev_si][prev_sj-1]*hc[prev_si][prev_sj-1]+delta)/(hc[prev_si][prev_sj-1]+1));
   hc[prev_si][prev_sj-1]++;
   prev_sj--;
  }
  else{
   v[prev_si-1][prev_sj]=(int)round((v[prev_si-1][prev_sj]*vc[prev_si-1][prev_sj]+delta)/(vc[prev_si-1][prev_sj]+1));
   vc[prev_si-1][prev_sj]++;
   prev_si--;
  }
  prev_path.erase(0, 1);
 }
}

void read_s_t(){
  cin>>si;
  cin>>sj;
  cin>>ti;
  cin>>tj;
}

void set_prev_s_t(){
 prev_si=si;
 prev_sj=sj;
 prev_ti=ti;
 prev_tj=tj;
}

void read_result(){
 cin>>prev_result;
}

int main(){
 //h初期化
 for(i=0; i<=29; i++){
  for(j=0; j<=28; j++){
   h[i][j]=0;
   hc[i][j]=0;
  }
 }
 //v初期化
 for(i=0; i<=28; i++){
  for(j=0; j<=29; j++){
   v[i][j]=0;
   vc[i][j]=0;
  }
 }

 for(i=0; i<repeat_count; i++){
  read_s_t();
  set_prev_s_t();
  string path=query(si, sj, ti, tj);
  cout<<path<<"\n"<<flush;
  read_result();
  sethv(prev_si, prev_sj, path, prev_result);
 }
 return 0;
}

#include <cstdio>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
typedef long long ll;

const int N = 30;
const int MIN_COST = 1000;
// const int MAX_COST = 9000;

const int nQuery = 1000;
enum {
  D = 0, L, U, R
};
const int DI[4] = {1, 0, -1, 0};
const int DJ[4] = {0, -1, 0, 1};
const char * const OP = "DLUR";

struct Result {
  int dist, num;
  Result(int dist, int num) : dist(dist), num(num) {}
  double average(void) const { return double(dist) / num; }
};

class Edge {
public:
  Edge() {
    // 最低値で初期化しておく
    const double EFF = 140;
    numer = MIN_COST / EFF;
    denom = 1 / EFF;
  }
  void addResult(const Result &r) {
    numer += r.average() / r.num;
    denom += 1.0 / r.num;
    rs.push_back(r);
  }
  double cost(void) const {
    return numer / denom;
  }
private:
  double numer, denom;
  vector<Result> rs;
};
Edge _es[(N-1)*N*2];
Edge *es[N][N][4];

inline void init(void) {
  int t = 0;
  REP(i, N) REP(j, N) {
    if(i+1 < N) {
      es[i][j][D] = &_es[t++];
    }
    if(j+1 < N) {
      es[i][j][R] = &_es[t++];
    }
  }
  REP(i, N) REP(j, N) {
    if(i-1 >= 0) {
      es[i][j][U] = es[i-1][j][D];
    }
    if(j-1 >= 0) {
      es[i][j][L] = es[i][j-1][R];
    }
  }
  assert(t == (N-1)*N*2);
}

inline int query(const vector<int> &ops) {
  for(auto op : ops) {
    printf("%c", OP[op]);
  }
  printf("\n");
  fflush(stdout);
  int res;
  scanf("%d", &res);
  return res;
}

const double INF = 1e9;
double dist[N][N];
int trace[N][N];
struct K {
  int i, j;
  double c;
  K(int i, int j, double c) : i(i), j(j), c(c) {}
};
bool operator>(const K& a, const K& b) {
  return a.c > b.c;
}

int main(void) {
  init();
  REP(iQuery, nQuery) {
    int si, sj, gi, gj;
    scanf("%d%d%d%d", &si, &sj, &gi, &gj);
    { // dijkstra
      REP(i, N) REP(j, N) {
        dist[i][j] = INF;
      }
      priority_queue<K, vector<K>, greater<K> > q;
      q.push(K(si, sj, 0));
      dist[si][sj] = 0;
      while(!q.empty()) {
        K cur = q.top(); q.pop();
        int ci = cur.i;
        int cj = cur.j;
        if(dist[ci][cj] < cur.c) {
          continue;
        }
        if(ci == gi && cj == gj) {
          break;
        }
        REP(d, 4) {
          int ni = ci + DI[d];
          int nj = cj + DJ[d];
          if(ni >= 0 && nj >= 0 && ni < N && nj < N) {
            double c = cur.c + es[ci][cj][d]->cost();
            if(c < dist[ni][nj]) {
              q.push(K(ni, nj, c));
              dist[ni][nj] = c;
              trace[ni][nj] = d;
            }
          }
        }
      }
    }
    vector<int> ops;
    for(int ci = gi, cj = gj; ci != si || cj != sj; ) {
      int op = trace[ci][cj];
      ops.push_back(op);
      ci -= DI[op];
      cj -= DJ[op];
    }
    reverse(ops.begin(), ops.end());
    int res = query(ops);
    {
      int ci = si;
      int cj = sj;
      for(auto op : ops) {
        es[ci][cj][op]->addResult(Result(res, ops.size()));
        ci += DI[op];
        cj += DJ[op];
      }
    }
  }
  return 0;
}


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

int  main() {
  int n;
  scanf("%d\n", &n);
  vector<int> a(n), b(n), c(n);
  vector<long long> d(n + 1, 0), e(n + 1, 0), f(n + 1, 0);
  for(int i = 0; i < n; i++) {
    scanf("%d", &a.at(i));
    d.at(a.at(i))++;
  }
  for(int i = 0; i < n; i++) {
    scanf("%d", &b.at(i));
    e.at(b.at(i))++;
  }
  for(int i = 0; i < n; i++) {
    scanf("%d", &c.at(i));
    f.at(b.at(c.at(i) - 1))++;
  }

  long long sum = 0;
  for(int i = 1; i <= n; i++) {
    sum += d.at(i) * f.at(i);
  }

  printf("%lld\n", sum);
}

#include <bits/stdc++.h>
#define REP(i,a,b) for (int i = (a); i <= (b); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
#define dbgpr(x) cout << #x << " is " << x << endl
#define endl '\n'
using namespace std; using ll = long long; using ii = pair<int,int>;
void solution(); int main() {ios::sync_with_stdio(0); cin.tie(0); solution();}
const int N = 100003;
int n, a[N], b[N], c[N];
int cnt[N];

void input() {
    cin >> n;
    REP(i,1,n) cin >> a[i];
    REP(i,1,n) cin >> b[i];
    REP(i,1,n) cin >> c[i];
}
void solution() {
    input();
    REP(i,1,n) ++cnt[b[c[i]]];
    ll ans = 0;
    REP(i,1,n) {
        ans += cnt[a[i]];
    }
    cout << ans;
}


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

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

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pi;
typedef vector<pi> vp;
typedef set<ll> si;
typedef map<string, ll> msi;
#define REP(i,a,b) \
for(ll i=ll(a);i<=ll(b);i++)
#define DEP(i,a,b) \
for(ll i=ll(a);i>=ll(b);i--)
#define TR(c, it) \
for (auto it = (c).begin(); it != (c).end(); it++)
#define mp make_pair
#define pb push_back
#define F first
#define S second
ll mod = 1e9+7;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  int T;
  T=1;
  while(T--)
  {
      ll n,i,j,k,l,m,v,t,s,d;
      cin>>v>>t>>s>>d;
      if(v*t<=d&&s*v>=d)cout<<"No";
      else cout<<"Yes";
  }
  return 0;
}


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

int main() {
  string S, ret = "", tmp; cin >> S;
  for (auto s : S) {
    switch (s)
    {
    case '0': tmp = '0'; break;
    case '1': tmp = '1'; break;
    case '6': tmp = '9'; break;
    case '8': tmp = '8'; break;
    case '9': tmp = '6'; break;
    }
    ret = tmp + ret;
  }

  cout << ret << endl;
  return 0;
}

#include <iostream>
#include<stdio.h>
#include <cmath>
using namespace std;

int main(){
 int num;
 cin>>num;
 if(num%2==0){
 	cout<<"White";
 }else{ cout<<"Black";
 }
}


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

#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"
#define ll long long
#define pb push_back
#define ff first
#define ss second

int main()
{
	fast;

	int a[3];
	for (int i = 0; i < 3; ++i)
	{
		cin >> a[i];
	}

	sort(a, a + 3);

	if (2 * a[1] == a[0] + a[2]) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}

	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Yes_cout cout <<"Yes"<<endl;
#define No_cout cout <<"No"<<endl;

int main() {

vector<int> v(4);
  for (int i = 0; i < 4; i++) {
    cin >> v.at(i);
  }

  int x;
    x = v[0]*v[3]-v[1]*v[2];

    cout << x <<endl;

}


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

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

    long long minv = a;
    minv = min(minv, b);
    minv = min(minv, c);
    minv = min(minv, d);

    cout << minv << endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main(){
  int v, t, s, d;
  cin >> v >> t >> s >> d;
  if(d<v*t || d>v*s)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


#include<bits/stdc++.h>
using namespace std;
#define F                                               first
#define se                                              second
#define pb                                              push_back
#define SZ(x)                                           x.size()
#define all(v)		                                    ((v).begin()), ((v).end())
#define lp(i ,n)		                                for(int i=0;i<(int)(n);++i)
#define S(n) scanf("%d" , &n);
#define SL(n) scanf("%lld" , &n);
#define S2(n , m) scanf("%d %d" , &n , &m);
#define SL2(n , m) scanf("%lld %lld" , &n , &m);
#define dbg1(a)                                         std::cerr<<#a<<"= "<<(a)<<"\n"
#define dbg2(a,b)                                       std::cerr<<#a<<"= "<<(a)<<"  "<<#b<<"= "<<(b)<<"\n"
#define dbg3(a,b,c)                                     std::cerr<<#a<<"= "<<(a)<<"  "<<#b<<"= "<<(b)<<"  "<<#c<<"="<<(c)<<"\n"
#define dbg4(a,b,c,d)                                   std::cerr<<#a<<"= "<<(a)<<"  "<<#b<<"= "<<(b)<<"  "<<#c<<"="<<(c)<<" "<<#d<<"= "<<(d)<<"\n"
#define Fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);

typedef long long LL;
int const N = 1e5+3;
int const mod = 1e9+7;
int dx[]= {-1, 1, 0, 0};
int dy[]= {0, 0, 1, -1};

int n ;
LL ans;
int main()
{

    S(n);

    vector<pair<double, double>>v(n);

    lp(i, n)scanf("%lf %lf",&v[i].F, &v[i].se);

    lp(i, n)
    {

        for(int j = i+1 ; j<n ; j++)

            ans += ((v[i].se - v[j].se) /(v[i].F - v[j].F)) >=-1 && ((v[i].se - v[j].se) /(v[i].F - v[j].F))<=1;

    }
    printf("%lld",ans);

    return 0;

}

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

#define ios ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr)
#define f first
#define s second
#define endl '\n'

typedef long long int ll ;

void solve() {
    int n ;
    cin >> n ;
    pair <double , double> xy[n] ;
    for (int i = 0 ; i < n ; i++) cin >> xy[i].f >> xy[i].s ;
    int ans = 0 ;
    for (int i = 0 ; i < n ; i++) {
        for (int j = i + 1; j < n ; j++) {
            double slope = xy[j].s - xy[i].s ;
            slope /= (xy[j].f - xy[i].f) ;
            if (slope >= -1 && slope <= 1) ans++ ;
        }
    }
    cout << ans << endl ;
}

int main() {
    ios ;

    solve() ;
}


#include <bits/stdc++.h>

// #include <atcoder/all>

using namespace std;
// using namespace atcoder;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
typedef long long ll;
#define int ll

#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(int)(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const long double pi = 3.1415926535897932384626433832795028841971L;
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl;
// int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
// int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
vi dx = {-1, 0, 1, 0}, dy = {0, -1, 0, 1};
// vi dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
// const ll MOD = 1000000007;
const ll MOD = 998244353;
// #define mp make_pair
//#define endl '\n'

signed main() {
    fio();

    ll a, b, c;
    cin >> a >> b >> c;
    vl t = {a, b, c};
    ll ans = 1;
    for (ll x: t) {
        ans *= x * (x + 1) / 2 % MOD;
        ans %= MOD;
    }
    cout << ans << endl;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 998244353;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);

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

    a = (a * (a + 1) / 2) % mod;
    b = (b * (b + 1) / 2) % mod;
    c = (c * (c + 1) / 2) % mod;

    cout << (((a * b) % mod) * c) % mod;

    return 0;
}


#include <bits/stdc++.h>
//#include <atcoder/all>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define popcount __builtin_popcount
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
template <class T>
inline bool chmin(T &a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}

template <typename T>
T mypow(T x, T n, const T &p = -1)
{ //x^nをmodで割った余り
	T ret = 1;
	while (n > 0)
	{
		if (n & 1)
		{
			if (p != -1)
				ret = (ret * x) % p;
			else
				ret *= x;
		}
		if (p != -1)
			x = (x * x) % p;
		else
			x *= x;
		n >>= 1;
	}
	return ret;
}

ll gcd(ll n, ll m)
{
	ll tmp;
	while (m != 0)
	{
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m)
{
	return abs(n) / gcd(n, m) * abs(m); //gl=xy
}

using namespace std;
//using namespace atcoder;

struct UF {
	vector<int>par;//親
	vector<int>sz;//要素数

  UF(int n){
    sz.resize(n,1);
    par.resize(n);
    for(int i=0;i<n;++i){
      par[i]=i;
    }
  }

	//木の根を求める
	int find(int x) {
		if (par[x] == x) {
			return x;
		}
		else {
			return par[x] = find(par[x]);//経路圧縮
		}
	}

	//xとyの属する集合を併合
	bool unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y)return false;//すでに同じ集合に属している

		if (sz[x] < sz[y]) {//要素数が小さい方を下に
			par[x] = y;
      sz[y]+=sz[x];
		}
		else {
			par[y] = x;
			sz[x]+=sz[y];
		}
		return true;
	}

	//xとyが同じ集合に属するかを判定
	bool same(int x, int y) {
		return find(x) == find(y);
	}

    int size(int k){//要素数を求める
        return sz[find(k)];
    }
};

void solve()
{
	int n;
	cin>>n;
	vector<double>x(n),y(n);
	rep(i,n)cin>>x[i]>>y[i];
	double l=0,r=101;
	rep(q,100){
		double mid=(l+r)/2;
		UF tree(n);
		rep(i,n){
			REP(j,i+1,n){
				double dis=pow(x[i]-x[j],2)+pow(y[i]-y[j],2);
				if(mid*mid*4>dis){
					tree.unite(i,j);
				}
			}
		}
		vector<double>u(n),d(n);
		rep(i,n){
			chmax(u[tree.find(i)],min(100.0,y[i]+mid*2));
			chmin(d[tree.find(i)],max(-100.0,y[i]-mid*2));
		}
		bool ng=false;
		rep(i,n){
			if(u[i]==100.0&&d[i]==-100.0){
				ng=true;
			}
		}
		if(ng)r=mid;
		else l=mid;
	}
	cout<<l;
}

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

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

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

int num[8210];
int kazu[8210];
const int ma = (1 << 13) - 1;
int query(int n) {
	int n2 = (n & ma) + 1;
	while (num[n2]) {
		if (num[n2] == n + 1) return kazu[n2];
		n2 = n2 * 2 % 8209;
	}
	return 0;
}
void add(int n, int b) {
	int n2 = (n & ma) + 1;
	while (num[n2]) {
		if (num[n2] == n + 1) return;
		n2 = n2 * 2 % 8209;
	}
	num[n2] = n + 1;
	kazu[n2] = b;
}
int li[300];

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

	int N, M;
	cin >> N >> M;
	int w[8];
	rep(i, N) cin >> w[i];

	pair<int, int> lv[100001];
	rep(i, M) {
		int l, v;
		cin >> l >> v;
		lv[i] = { v, l };
	}
	sort(lv, lv + M);
	lv[M] = { 1e9,1e9 };

	rep(i, 1 << N) {
		rep(j, N) if (i >> j & 1) li[i] += w[j];
	}
	sort(li, li + (1 << N));
	int saidai = 0;
	int k = 0;
	rep(i, 1 << N) {
		while (lv[k].first < li[i]) {
			if (saidai < lv[k].second) saidai = lv[k].second;
			k++;
		}
		add(li[i], saidai);
	}

	rep(i, N) {
		if (w[i] > lv[0].first) {
			printf("-1");
			return 0;
		}
	}
	int P[8];
	rep(i, N) P[i] = i;

	int kotae = 1e9;
	do {
		int tmp[8] = {};
		rep(p, N - 1) {
			int omosa = w[P[p]];
			for (int q = p + 1; q < N; q++) {
				omosa += w[P[q]];
				int kari = tmp[p] + query(omosa);
				if (tmp[q] < kari) tmp[q] = kari;
			}
		}
		if (kotae > tmp[N - 1]) kotae = tmp[N - 1];

	} while (next_permutation(P, P + N));

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

	Would you please return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define po pop_front
#define mo(o) memset(o,-1,sizeof(o))
#define forn(i,n) for(int i=0;i<n;i++)
#define fore(i,n) for(int i=1;i<=n;i++)
#define mp make_pair
#define ll long long
#define itn int
int main()
{
	int n;
	cin>>n;
	if(n%2)	cout<<"Black"<<endl;
	else	cout<<"White"<<endl;
	return 0;
}

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

int main(){
  int N;
  cin >> N;
  if (N % 2 == 0){
    cout << "White";
  } else{
    cout << "Black";
  }
  return 0;
}


//#include<math.h>
#include<algorithm>
#include<stdlib.h>
#include<time.h>
#include<stdio.h>
#include<string.h>
#define un unsigned
#define srd srand(time(0))
#define ll long long
#define con continue
#define gtc getchar()
#define ptc putchar
#define dou double
#define eps 0.00000000001
#define opr operator
#define cl(x,a) memset(x,a,sizeof(x))
#define fo0(i,k) for(i=fr[k];i;i=nx[i])
#define fo1(i,l,r) for(i=l;i<=r;i++)
#define fo2(i,l,r) for(i=l;i>=r;i--)
#define fo(i,n) for(i=1;i<=n;i++)
#define ret return
#define x first
#define cint const int
#define y second
#define opi(x) freopen(x,"r",stdin)
#define opo(x) freopen(x,"w",stdout)
#define tpl template<class T>
#define priq priority_queue
#define mp make_pair
#define use using namespace
#define WT while(T--)
#define pb push_back
#define sz size()
use std;
typedef pair<int,int> pii;typedef pair<int,ll> pil;typedef pair<ll,int> pli;typedef pair<ll,ll> pll;
namespace io
{
	void _(int &k){char c;int e=1;k=0;while((c=gtc)>'9'||c<'0')if(c=='-')e=-1;k=c-'0';while((c=gtc)<='9'&&c>='0'){k*=10;k+=c-'0';}k*=e;}
	void _(ll &k){char c;int e=1;k=0;while((c=gtc)>'9'||c<'0')if(c=='-')e=-1;k=c-'0';while((c=gtc)<='9'&&c>='0'){k*=10;k+=c-'0';}k*=e;}
	void _(char &c){while((c=gtc)==' '||c=='\n');}void _(dou &c){scanf("%lf",&c);}void _(char *s){char c;while((c=gtc)!=EOF&&c!=' '&&c!=10)*s++=c;}
	template<class t1,class t2>void _(t1 &a,t2 &b){_(a);_(b);}template<class t1,class t2,class t3>void _(t1 &a,t2 &b,t3 &c){_(a);_(b);_(c);}
	template<class t1,class t2,class t3,class t4>void _(t1 &a,t2 &b,t3 &c,t4 &d){_(a);_(b);_(c);_(d);}
	template<class t1,class t2,class t3,class t4,class t5>void _(t1 &a,t2 &b,t3 &c,t4 &d,t5 &e){_(a);_(b);_(c);_(d);_(e);}
	void _p(dou k){printf("%.6lf",k);}void _p(char *c){for(;*c;ptc(*c++));}void _p(const char *c){for(;*c;ptc(*c++));}void _p(char c){ptc(c);}
	tpl void _p0(T k){if(k>=10)_p0(k/10);ptc(k%10+'0');}tpl void _p(T k){if(k<0){ptc('-');_p0(-k);}else _p0(k);}tpl void __p(T k){_p(k);ptc(' ');}
	tpl void _pn(T k){_p(k);ptc('\n');}template<class t1,class t2>void _p(t1 a,t2 b){__p(a);_pn(b);}
	template<class t1,class t2,class t3>void _p(t1 a,t2 b,t3 c){__p(a);__p(b);_pn(c);}
	template<class t1,class t2,class t3,class t4>void _p(t1 a,t2 b,t3 c,t4 d){__p(a);__p(b);__p(c);_pn(d);}
	tpl void op(T *a,int n){int i;n--;fo(i,n)__p(a[i]);_pn(a[n+1]);}int gi(){int x;_(x);ret x;}ll gll(){ll x;_(x);ret x;}
}
int gcd(int a,int b){ret b?gcd(b,a%b):a;}void fcl(){fclose(stdin);fclose(stdout);}
void fop(const char *s){char c[256],d[256];cl(c,0);cl(d,0);strcpy(c,s);strcpy(d,s);opi(strcat(c,".in"));opo(strcat(d,".out"));}
int eq(dou a,dou b){return a+eps>=b&&b+eps>=a;}tpl void _ma(T &a,T b){if(a<b)a=b;}tpl void _mi(T &a,T b){if(a>b)a=b;}
cint N=1234567,EE=100000000,GG=1000000000,ima=2147483647,p=998244353;
use io;
int n,m,k,T;
int ksm(int a,int b)
{
	if(!b)
		return 1;
	int t=ksm(a,b/2);
	t=(ll)t*t%p;
	return b%2?(ll)t*a%p:t;
}
int main()
{
	int i,j,a1,a2;
	_(n,m,k);
	if(n+m==2)
		_pn(k);
	else if(n==1||m==1)
		_pn(ksm(k,n+m-1));
	else
	{
		int an=0;
		//m=max(n,m);
		//n=t;
		fo(i,k)
			an=(an+(ll)ksm(i,n)*(ksm(k-i+1,m)-ksm(k-i,m)+p))%p;
		_pn(an);
	}
}

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
constexpr int INF = 1e9, MOD = 1e9 + 7;
constexpr int64_t LINF = 5e18, LMOD = 998244353;
// #include <atcoder/all>
// using namespace atcoder;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

using fint64 = int_fast64_t;
template<fint64 MOD>
struct ModInt {
	fint64 x;
	ModInt():x(0){}
	ModInt(fint64 x):
		x(x>=0?x%MOD:(MOD-(-x)%MOD)%MOD)
		{}
	// 負号
	ModInt operator -() const{
		return ModInt(-x);
	}
	// 加算
	ModInt &operator +=(const ModInt &rhs){
		x+=rhs.x;
		if(x>=MOD) x-=MOD;
		return (*this);
	}
	ModInt operator +(const ModInt &rhs) const{
		return ModInt(*this)+=rhs;
	}
	// 減算
	ModInt &operator -=(const ModInt &rhs){
		x+=MOD-rhs.x;
		if(x>=MOD) x-=MOD;
		return (*this);
	}
	ModInt operator -(const ModInt &rhs) const{
		return ModInt(*this)-=rhs;
	}
	// 乗算
	ModInt &operator *=(const ModInt &rhs){
		x*=rhs.x;
		if(x>=MOD) x%=MOD;
		return (*this);
	}
	ModInt operator *(const ModInt &rhs) const{
		return ModInt(*this)*=rhs;
	}
	// 除算
	ModInt &operator /=(const ModInt &rhs){
		(*this)*=rhs.inverse();
		return (*this);
	}
	ModInt operator /(const ModInt &rhs) const{
		return ModInt(*this)/=rhs;
	}
	// 等号
	bool operator ==(const ModInt &rhs){
		return x==rhs.x;
	}
	bool operator !=(const ModInt &rhs){
		return x!=rhs.x;
	}
	// 累乗
	ModInt pow(fint64 n) const{
		fint64 tmp=x;
		fint64 ret=1;
		while(n>0){
			if(n&1) ret=ret*tmp%MOD;
			tmp=tmp*tmp%MOD;
			n>>=1ll;
		}
		return ModInt(ret);
	}
	// 逆元
	ModInt inverse() const{
		fint64 a=x,b=MOD,s=1,t=0;
		while(b>0){
			fint64 u=a/b;
			a-=u*b;
			s-=u*t;
			swap(a,b);
			swap(s,t);
		}
		return ModInt(s);
	}
	// 入出力
	friend istream &operator >>(istream &lhs,ModInt<MOD> &rhs){
		fint64 x; lhs>>x;
		rhs=ModInt<MOD>(x);
		return lhs;
	}
	friend ostream &operator <<(ostream &lhs,const ModInt<MOD> &rhs){
		return lhs<<rhs.x;
	}
};

using mint = ModInt<LMOD>;
int main() {
	int n, m, k; cin >> n >> m >> k;
	if(m == 1) {
		cout << ((mint)k).pow(n) << '\n';
		return 0;
	}
	if(n == 1) {
		cout << ((mint)k).pow(m) << '\n';
		return 0;
	}
	mint ans = 0;
	for(int i = 1; i <= k; ++i) {
		ans += (((mint)i).pow(n) - ((mint)(i - 1)).pow(n)) * ((mint)(k - i + 1)).pow(m);
		// cerr << ans << '\n';
	}
	cout << ans << '\n';
	return 0;
}


#pragma GCC optimize("Ofast")
#pragma GCC target ("sse4")

#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
#include<array>
using namespace std;

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

typedef unsigned long long ul;
typedef unsigned int ui;
constexpr ll mod = 998244353;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acosl(-1.0);

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

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

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

void solve() {
    int n, k; cin >> n >> k;
    vector<int> a(n);
    rep(i, n) {
        cin >> a[i];
    }
    vector<vector<modint>> rsum(k + 1, vector<modint>(n + 1));
    rep(i, n) {
        modint p = 1;
        rep(j, k + 1) {
            rsum[j][i + 1] += rsum[j][i] + p;
            p *= a[i];
        }
    }
    rep1(x, k) {
        modint ans = 0;
        rep(j, x + 1) {
            ans += comb(x, j) * rsum[j][n] * rsum[x - j][n];
            ans -= comb(x, j) * rsum[x][n];
        }
        ans *= (1 + mod) / 2;
        cout << ans << "\n";
    }
}
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    //cout << fixed << setprecision(15);
    init_f();
    //init();
    //expr();
    //int t; cin >> t; rep(i, t)
    solve();
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define il inline
#define ri register int
#define ll long long
#define ui unsigned int
il ll read(){
    bool f=true;ll x=0;
    register char ch=getchar();
    while(ch<'0'||ch>'9') {if(ch=='-') f=false;ch=getchar();}
    while(ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
    if(f) return x;
    return ~(--x);
}
il int read(char *s){
    int len=0;
    register char ch=getchar();
    while(ch==' '||ch=='\n') ch=getchar();
    while(ch!=' '&&ch!='\n'&&ch!=EOF) s[++len]=ch,ch=getchar();
    return len;
}
il void write(const ll &x){if(x>9) write(x/10);putchar(x%10+'0');}
il void print(const ll &x) {x<0?putchar('-'),write(~(x-1)):write(x);putchar('\n');}
il ll max(const ll &a,const ll &b){return a>b?a:b;}
il ll min(const ll &a,const ll &b){return a<b?a:b;}
const int MAXN=2e5+7;
ll a[MAXN],sum[505];
const ll mod =998244353;
il ll ksm(ll d,ll tim){
    ll rest=1;
    while(tim){
        if(tim&1) rest=rest*d%mod;
        d=d*d%mod;
        tim>>=1;
    }
    return rest;
}
ll jc[MAXN],inv[MAXN];
void init(int n=MAXN-1){
    jc[0]=1;
    for(ri i=1;i<=n;++i) jc[i]=i*jc[i-1]%mod;
    inv[n]=ksm(jc[n],mod-2);
    for(ri i=n-1;~i;--i) inv[i]=inv[i+1]*(i+1)%mod;
}
il ll C(ll x,ll y){
    if(x<y) return 0;
    return jc[x]*inv[y]%mod*inv[x-y]%mod;
}
ll n,k;
int main(){
    init();
    n=read(),k=read();
    for(ri i=1;i<=n;++i){
        a[i]=read();
        ll d=1;
        for(ri j=0;j<=k;++j){
            sum[j]=(sum[j]+d)%mod;
            d=d*a[i]%mod;
        }
    }
    for(ri i=1;i<=k;++i){
        ll ans=0;
        ans=(mod-ksm(2,i)*sum[i]%mod)%mod;
        for(ri j=0;j<=i;++j){
            ans=(ans+C(i,j)*sum[j]%mod*sum[i-j]%mod)%mod;
        }
        print(ans*ksm(2,mod-2)%mod);
    }
    return 0;
}


#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define int long long
using namespace std;
#define endl '\n'
#define br cout<<endl
#define mem(a) memset(a,0,sizeof(a))
const double pi=3.141592653589793238;
#define d(x) cout<<x<<endl;
#define de(x) cout<<#x<<" "<<x<<endl;
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define rev(a) reverse(a.begin(),a.end())
//const int inf = 100000000000000000;
#define maxn 1000005
int mod = (int)(1e9 + 7);
#define IOS ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define all(x) x.begin(),x.end()
//#define f(i,n) for(int i=1;i<=n;i++)
#define fp(i,k,n) for(int i=k;i<=n;i+=1)
#define fn(i,k,n) for(int i=k;i>=n;i-=1)
void pv(vector<int> v){  for (int i = 0; i < v.size(); ++i){cout<<v[i]<<" ";}cout<<endl;}
void pa(int a[],int n,int p){for (int i = p; i < n+p; ++i){cout<<a[i]<<" ";}cout<<endl;}
int modexp(int x,int y) {
   int res = 1;
   x = x % mod;
   while (y > 0){
       if (y & 1LL)
           res = (res*x) % mod;
       y = y>>1;
       x = (x*x) % mod;
   }
   return res;
}
int invmod(int a) {
    return modexp(a,mod-2);
}
// vector<int> edge[maxn];
// void ipgraph(int n,int m) {
//     fp(i,1,n) edge[i].clear();
//     if(m==0) return;
//    fp(i,1,m) {
//        int a,b;
//        cin>>a>>b;
//        edge[a].pb(b);
//        edge[b].pb(a);
//    }
// }
/*
void dfs(int node,int p)
{
    for(int u : edge[node])
    {
        if(u!=p)
        {
            dfs(u,node);
        }
    }
}
*/
//////////////////////////////////////////////////////////////////////////////////
void solve()
{
    int n;
    cin>>n;
    int a[n+1];
    int xr = 0;
    map<int,int> m;
    fp(i,1,n)
    {
        cin>>a[i];
        m[a[i]]++;
        xr^=a[i];
    }
    if(n%2) d("Second")
    else
    {
        for(auto p : m)
        {
            if(p.S%2)
            {
                d("First")
                return ;
            }
        }
        d("Second")
    }
}
int32_t main()
{
   IOS;
   #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    std::cout << std::setprecision(20);
   int t=1;
    cin>>t;
   fp(i,1,t)
   {
       //cout<<"Case #"<<i<<": ";
       solve();
   }
}

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

string naive(int N, vector<long long> a)
{
    vector<bool> U(N);
    vector<long long> T;

    function<int(int)> f = [&](int t) -> int
    {
        bool remain = false;
        bool win = false;
        for (int i=0; i<N; i++)
            if (!U[i])
            {
                remain = true;
                U[i] = true;
                for (int j=0; j<(int)T.size(); j++)
                {
                    T[j] += a[i];
                    if (!f(1-t))
                        win = true;
                    T[j] -= a[i];
                }
                T.push_back(a[i]);
                if (!f(1-t))
                    win = true;
                T.pop_back();
                U[i] = false;
            }
        if (remain)
            return win;

        long long x = 0;
        for (int t: T)
            x ^= t;
        return x!=0;
    };

    return f(0) ? "First" : "Second";
}

#include <algorithm>

string solve(int N, vector<long long> a)
{
    sort(a.begin(), a.end());

    if (N%2==1)
        return "Second";

    long long x = 0;
    for (long long t: a)
        x ^= t;
    if (x!=0)
        return "First";

    bool f = false;
    for (int i=0; i<N; i+=2)
        if (a[i]!=a[i+1])
            f = true;
    if (f)
        return "First";

    return "Second";
}

int main()
{
    /*
    N = 1
        -> Second

    N = 2
        xor!=0 -> First
        xor==0 -> Second

    N = 3
        -> Second

    N = 4
        xor!=0 -> First
        xor==0 -> Secnd ?
         2 5 3 4 First 0
         9 6 8 7 First 0
         4 9 8 5 First 0
          3 1 4 6 First 0
         1 6 2 5 First 0
         6 1 3 4 First 0
         6 1 2 5 First 0
          54 58 84 88 First 0
         1 23 65 87 First 0
         3 8 48 59 First 0
         14 16 72 86 First 0
         43 44 56 63 First 0
         38 41 51 60 First 0

    N = 5
        -> Second

    N = 6
        xor!=0 -> First
        xor==0 -> Second ?
         9 3 10 2 4 6 First 0
         3 3 3 7 5 1 First 0
         6 6 5 1 3 7 First 0
          11 23 35 38 39 62 First 0
         22 22 41 63 65 87 First 0
         9 9 33 36 48 53 First 0
         5 11 32 45 89 90 First 0
         48 58 86 91 99 100 First 0
         45 46 60 63 70 70 First 0
         1 13 65 71 81 91 First 0

    */
    //for (int i=0; i<10000; i++)
    //{
    //    int N = rand()%6+1;
    //    vector<long long> a(N);
    //    for (int i=0; i<N; i++)
    //        a[i] = rand()%10+1;
    //    /*
    //    sort(a.begin(), a.end());
    //    int x = 0;
    //    for (int t: a)
    //        x ^= t;
    //    string ans = naive(N, a);
    //    bool f = false;
    //    for (int i=0; i<N; i+=2)
    //        if (a[i]!=a[i+1])
    //            f = true;
    //    if (ans=="Second" && f)
    //    {
    //        for (int x: a)
    //            cout<<" "<<x;
    //        cout<<" "<<ans<<" "<<x;
    //        for (int i=0; i<N/2; i++)
    //            cout<<" "<<a[i]+a[N-i-1];
    //        cout<<endl;
    //    }
    //    */
    //    string an = naive(N, a);
    //    string as = solve(N, a);
    //    if (an!=as)
    //        cout<<"!"<<endl;
    //}

    int T;
    cin>>T;
    for (int i=0; i<T; i++)
    {
        int N;
        cin>>N;
        vector<long long> a(N);
        for (long long &x: a)
            cin>>x;
        //cout<<naive(N, a)<<endl;
        cout<<solve(N, a)<<endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define repp(i,n) for(int i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define vvi vector<vector<int> >
const ll mod=998244353;
int n,m=1;
bool A(int i,int j){
	int x=i&j,cnt=0;
	do if(x&1)cnt++;
	while(x>>=1);
	return (cnt%2==0);
}
int main(){
	cin>>n;
	rep(i,n)m*=2;
	cout<<m-1<<endl;
	repp(i,m-1){
		rep(j,m){
			if(A(i,j))cout<<'A';
			else cout<<'B';
		}
		cout<<endl;
	}
	return 0;
}

#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
# define rep(i,a,b) for(int i=(a); i<=(b); ++i)
inline int readint(){
	int a = 0; char c = getchar(), f = 1;
	for(; c<'0'||c>'9'; c=getchar())
		if(c == '-') f = -f;
	for(; '0'<=c&&c<='9'; c=getchar())
		a = (a<<3)+(a<<1)+(c^48);
	return a*f;
}

const int MaxN = 200005;

int dp[MaxN][7]; // 1: T wins
char opt[MaxN], s[MaxN];

int dfs(int t,int x){
	if(~dp[t][x]) return dp[t][x];
	int &res = dp[t][x];
	if(opt[t] == 'A'){
		if(dfs(t+1,(10*x+s[t]-'0')%7)
			*dfs(t+1,(10*x)%7) == 0)
				return res = 0;
		return res = 1;
	}
	if(opt[t] == 'T'){
		if(dfs(t+1,(10*x+s[t]-'0')%7)
		or dfs(t+1,(10*x)%7) == 1)
			return res = 1;
		return res = 0;
	}
	return -1; // impossible
}

int main(){
	int n = readint();
	scanf("%s %s",s+1,opt+1);
	memset(dp,-1,sizeof(dp));
	rep(i,1,6) dp[n+1][i] = 0;
	dp[n+1][0] = 1;
	puts(dfs(1,0) ? "Takahashi" : "Aoki");
	return 0;
}


#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define fo(i,n) for(ll i=0;i<n;i++)
#define fo1(i,n) for(ll i=1;i<=n;i++)
#define loop(i,a,b)for(ll i=a;i<=b;i++)
#define loopr(i,a,b)for(ll i=b;i>=a;i--)
#define all(x) x.begin(), x.end()
#define sz(x) (ll)(x).size()
#define vll vector<ll>
#define vvl vector<vll>
#define vpll vector<pll>
#define pll pair<ll,ll>
#define F first
#define S second
#define MOD 1000000007
ll max(ll a,ll b){if (a>b) return a; else return b;}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b, a%b);}
ll lcm(ll a, ll b){return a*b/gcd(a, b);}
ll fexp(ll a, ll b){ll ans = 1;while(b){if(b&1) ans = ans*a%MOD; b/=2;a=a*a%MOD;}return ans;}
ll inverse(ll a, ll p){return fexp(a, p-2);}
using namespace std;

//take care of long long

//fast I/O
auto optimizer = []() {  // makes I/O fast
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  return 0;
}();

//seive
ll N = 1e5;
vll lpf(N+1,0);
void leastPrimeFactor()
{
    lpf[1] = 1;
    for (ll i = 2; i <= N; i++)
    {
        if(lpf[i] == 0)
        {
            lpf[i] = i;
            for (ll j = 2*i; j <= N; j += i)
            	if (lpf[j] == 0)
                	lpf[j] = i;
        }
    }
}

int main()
{
	ll t=1;
	//cin>>t;
	while(t--)
	{
	    ll a,b,c;
	    cin>>a>>b>>c;

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

	}
	return 0;
}

#include <iostream>
#include <cmath>

using namespace std;

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

	bool signFlag1 = (C % 2 == 1) && (A < 0);
	bool signFlag2 = (C % 2 == 1) && (B < 0);

	char ans;
	if (signFlag1 != signFlag2) {
		ans = (signFlag1 ? '<' : '>');
	}
	else {
		if (abs(A) == abs(B)) {
			ans = '=';
		}
		else if (abs(A) < abs(B) ^ signFlag1) {
			ans = '<';
		}
		else {
			ans = '>';
		}
	}
	cout << ans << endl;

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ull unsigned long long
typedef vector<int> VI;
typedef vector<ll> VLL ;
typedef vector<ull> VULL;
typedef map<int,int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef pair<int,int> PII ;
#define PI 3.141592653589793238
#define mod 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
inline void debugMode() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}
bool sortbysec(const pair<int,int> &a,const pair<int,int> &b)
{
    return (a.second < b.second);
}
int main(){
    fast
    debugMode();
    ll n;
    cin>>n;
    vector<PII> v(n);
    vector<PII> vy(n);
    for(ll i=0;i<n;i++){
        int x,y;
        cin>>x>>y;
        v[i]=MP(x,y);
        vy[i]=v[i];
    }
    sort(v.begin(),v.end());
    sort(vy.begin(), vy.end(), sortbysec);
    if(vy[0]==v[0] && vy[n-1]==v[n-1]){
        int ans=max(abs(v[0].F-v[n-2].F),abs(v[1].F-v[n-1].F));
        int ans1=max(abs(vy[0].S-vy[n-2].S),abs(vy[1].S-vy[n-1].S));
        cout<<max(ans1,ans);
    }
    else{
        int ans3=min(abs(v[0].F-v[n-1].F),abs(vy[0].S-vy[n-1].S));
        int ans=max(abs(v[0].F-v[n-2].F),abs(v[1].F-v[n-1].F));
        int ans1=max(abs(vy[0].S-vy[n-2].S),abs(vy[1].S-vy[n-1].S));
        int ans2=max(ans1,ans);
        cout<<max(ans3,ans2);
    }
    return 0;
}

/**
 * @author: adityasonani
 * */
#include <bits/stdc++.h>

// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")

#define     int          long long
#define     ld        	long double
#define     ln          "\n"
#define     fastio      ios_base::sync_with_stdio(0); cin.tie(nullptr)
#define     MOD         (int) 1000000007
#define     rep(i, n)   for (int i = 0; i < (int)n; i++)
#define     all(x)      (x).begin(), (x).end()
#define     debug(x)    cerr << #x << " = " << x << endl;
#define     debugP(x, y)cerr << #x << " = " << x << endl; cerr << #y << " = " << y << endl;
#define     debugV(x)   cerr << "["; for(auto i: x){ cerr << i << ", ";} cerr << "]" << endl;
#define     precise(x)  cout << fixed << setprecision(x)
#define     MAX         (int) 100007 // 10^5
std::vector<int> gv(int n){std::vector<int> v(n);for(auto &x: v){std::cin>>x;}return v;}

using namespace std;

/*
*/

void solve()
{
    int N, K;
    cin >> N >> K;
	vector<pair<int, int>>vp(N);
	for (auto& i : vp)cin >> i.first >> i.second;
	sort(vp.begin(), vp.end());
	for (auto i : vp) {
		if (K >= i.first) {
			K += i.second;
		}
	}
	cout << K << endl;

}

signed main()
{
    fastio;

    auto start = std::chrono::high_resolution_clock::now();

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

    while(t--)
        solve();

    auto stop = std::chrono::high_resolution_clock::now();
    auto duration = std::chrono::duration_cast<std::chrono::nanoseconds>(stop - start);

    // cerr << "\nTime taken : " << ((long double)duration.count())/((long double) 1e9) <<" s "<< endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
long long INF = 1000000000000000000;
template<const int MOD> struct modint{
    long long val;
    modint(): val(0) {}
    modint(long long x){
        if(x < 0) val = x % MOD + MOD;
        else val = x % MOD;
    }
    modint(const modint &t){
        val = t.val;
    }
    modint& operator =(const modint m){
        val = m.val;
        return *this;
    }
    modint operator -(){
        return modint(-val);
    }
    modint& operator-=(const modint &m){
        val -= m.val;
        if(val < 0) val += MOD;
        return *this;
    }
    modint& operator+=(const modint &m){
        val += m.val;
        if(val >= MOD) val -= MOD;
        return *this;
    }
    modint& operator*=(const modint &m){
        val *= m.val;
        val %= MOD;
        return *this;
    }
    modint& operator/=(modint m){
        *this *= m.inv();
        return *this;
    }
    modint& inv(){
        long long x = 1, y = 0;
        long long a = val, b = MOD;
        while(b != 0){
            long long t = a / b;
            a -= t * b;
            x -= t * y;
            swap(a, b);
            swap(x, y);
        }
        val = x % MOD;
        if(val < 0) val += MOD;
        return *this;
    }
    modint pow(long long k){
        long long res = 1;
        long long v = val;
        while(k > 0){
            if(k & 1) res = res * v % MOD;
            v = v * v % MOD;
            k >>= 1;
        }
        return modint(res);
    }
    modint operator==(const modint &m){
        return val == m.val;
    }
    modint operator+(const modint &m){
        return modint(*this) += m;
    }
    modint operator-(const modint &m){
        return modint(*this) -= m;
    }
    modint operator*(const modint &m){
        return modint(*this) *= m;
    }
    modint operator/(const modint &m){
        return modint(*this) /= m;
    }
};
const int MOD = 1000000007;
using mint = modint<MOD>;
int main(){
    string S;
    int K;
    cin >> S >> K;
    int N = S.size();
    vector<vector<mint>> dp(17, vector<mint>(N));
    int bit = 0;
    for(int i = 0; i < N; i++){
        if(S[i] >= 'A') bit |= (1 << (S[i] - 'A' + 10));
        else bit |= (1 << (S[i] - '0'));
    }
    int cnt = __builtin_popcount(bit);
    mint ans = 0;
    if(cnt == K) ans += 1;
    if(S[0] == '1') dp[0][0] = 1;
    else{
        dp[0][0] = 1;
        if(S[0] >= 'A') dp[1][0] = S[0] - 'A' + 9;
        else dp[1][0] = S[0] - '1';
    }
    bit = 0;
    if(S[0] >= 'A') bit |= (1 << (S[0] - 'A' + 10));
    else bit |= (1 << (S[0] - '0'));
    for(int i = 1; i < N; i++){
        int bit2 = 0;
        int ma = 0;
        if(S[i] >= 'A') ma = (S[i] - 'A' + 10);
        else ma = (S[i] - '0');
        for(int j = 0; j < ma; j++){
            bit2 |= (1 << j);
        }
        int temp = ((bit & bit2) ^ bit2);
        int cnt = __builtin_popcount(temp);
        int now = __builtin_popcount(bit);
        if(now == 16) dp[now][i] += ma;
        else {
            dp[now + 1][i] += cnt;
            dp[now][i] += ma - cnt;
        }
        bit |= (1 << ma);
        for(int j = 0; j < 17; j++){
            if(j == 0){
                dp[j + 1][i] += dp[j][i - 1] * 15;
                dp[j][i] = 1;
            }
            else if(j < 16){
                dp[j + 1][i] += dp[j][i - 1] * (16 - j);
                dp[j][i] += dp[j][i - 1] * j;
            }
            else{
                dp[j][i] += dp[j][i - 1] * j;
            }
        }
    }
    ans += dp[K][N - 1];
    cout << ans.val << endl;
}

#include <bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
#define gcd __gcd
#define FOR(i, a, b) for (int i = a; i <= (b); i++)
#define ROF(i, a, b) for (int i = a; i >= (b); i--)
#define pb(x) push_back(x)
#define ALL(x) x.begin(), x.end()
#define RALL(x) x.rbegin(), x.rend()
#define sz(x) ((int)x.size())
#define fir first
#define sec second
typedef long long ll;
typedef long double ld;
const ll mod =  1e9 + 7;
const double PI = acos(-1.0);
const double eps = 1e-10;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
const int maxn = 100005;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    cin >> n;
    vector<int> ans;
    vector<ll> fib(100);
    fib[1] = fib[2] = 1;
    FOR(i, 3, 90) {
        fib[i] = fib[i - 1] + fib[i - 2];
    }
    int k = 0;
    map<int, bool> mp;
    ROF(i, 90, 1) {
        if(n >= fib[i]) {
            n -= fib[i];
            k = max(k, i);
            mp[i] = true;
        }
    }
    int cur = 3;
    ROF(i, k, 1) {
        cur ^= 1;
        ans.pb(cur);
        if(mp[i]) {
            if(cur == 2) {
                ans.pb(0);
            }
            else {
                ans.pb(1);
            }
        }
    }
    cout << ans.size() << endl;
    for(auto x: ans) {
        if(k % 2) cout << x + 1<< endl;
        else cout << (x^1) + 1 << endl;
    }
	return 0;
}


    /* Great things never come from comfort zones,
    "whatever the mind of a man can conceive and believe,it can achieve." */

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

    void my_dbg() { cout << endl; }
    template<typename Arg, typename... Args> void my_dbg(Arg A, Args... B)
    { cout << ' ' << A; my_dbg(B...); }
    #define dbg(...) cout << "(" << #__VA_ARGS__ << "):", my_dbg(__VA_ARGS__)

    #define ll long long
    #define dd double
    #define scf(n) scanf("%d",&n)
    #define lscf(n) scanf("%lld",&n)
    #define lpri(n) printf("%lld ",n)
    #define pri(n) printf("%d ",(int)n)
    #define prin(n) printf("%d\n",(int)n)
    #define lprin(n) printf("%lld\n",n)
    #define rep(i,ini,n) for(int i=ini;i<(int)n;i++)
    #define show(a) for(auto xy: a) pri(xy); printf("\n");

    #define pb push_back
    #define mp make_pair
    #define F first
    #define S second
    #define all(x)     x.begin(),x.end()
    #define SET(a,b) memset(a,b,sizeof(a))
    #define tc   int tt; scf(tt); while(tt--)

    #define inf INT_MAX
    #define ninf INT_MIN
    #define gcd __gcd
    #define bitcount(n) __builtin_popcount(n)

    const int mod=1e9+7;
    const int N = 1e6+7;

    int pos[N];

    int main()
    {

        int m; scf(m);

        int n; scf(n);

        int x=0;

        while(m)
            x+=m%10,m/=10;

        m=0;

        while(n)
            m+=n%10,n/=10;

        x=max(x,m);

        prin(x);
        //int a[m];

        //rep(i,0,n)scf(a[i]);

    }

// ABC187 - A
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<vector>
#include<queue>

using namespace std;

int calcSum(int num)
{
	int sum = 0, count = 0;;
	int divide[3] = {100, 10, 1};

	while(num != 0)
	{
		sum += num / divide[count];
		num = num % divide[count];
		count++;
	}

	return sum;
}

int main()
{
	int input_1, input_2, sum_1, sum_2;
	cin >> input_1 >> input_2;

	sum_1 = calcSum(input_1);
	sum_2 = calcSum(input_2);

	if( sum_1 >= sum_2 )
	{
		printf("%d\n", sum_1);
	}
	else
	{
		printf("%d\n", sum_2);
	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll t[100][100] ; ll RAM ;
ll k  ;
void printArr(ll a[], ll n)
{
    vector <ll> ye ;
    ye.push_back(1);
	for (ll i = 0; i < n; i++)
	{ye.push_back(a[i]);
	//	cout << a[i] << " ";
	}
	ye.push_back(1);
	//printf("\n");
	ll cost = 0 ;
	ll p = ye.size() ;
	ll i = 0 ;
	while(i<=p-2)
	{
	    ll x = ye[i] ;
	    ll y = ye[i+1] ;
	    cost = cost + t[x][y] ;
	    i++;
	}

	if(cost==k)
	{
	    RAM++;
	}

}

// Generating permutation using Heap Algorithm
void heapPermutation(ll a[], ll size, ll n)
{
	// if size becomes 1 then prints the obtained
	// permutation
	if (size == 1)
	{
		printArr(a, n);
		return;
	}

	for (ll i = 0; i < size; i++)
	{
		heapPermutation(a, size - 1, n);

		// if size is odd, swap 0th i.e (first) and
		// (size-1)th i.e (last) element
		if (size % 2 == 1)
			swap(a[0], a[size - 1]);

		// If size is even, swap ith and
		// (size-1)th i.e (last) element
		else
			swap(a[i], a[size - 1]);
	}
}

int main()
{
    ll n ;
    cin>>n; cin>>k ;
    ll a[n] ;
    ll i = 0 ;
    while(i<=n-1)
    {
        a[i]=i+2;

i++;
    }

    ll j ;
    i=1;
    while(i<=n)
    {
        j=1;
        while(j<=n)
        {
            cin>>t[i][j]  ;
            j++;
        }

        i++;
    }
	heapPermutation(a, n-1, n-1);
	cout<<RAM ;
	return 0;
}

#include<bits/stdc++.h>

using ll = long long;
using ull = unsigned long long;
using namespace std;
constexpr int inf = 1<<30;
constexpr int mo = 1e9+7;
constexpr ll infl = 1ll<<60;

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

    int n,k;
    cin>>n>>k;
    vector<vector<int>> t(n,vector<int>(n));
    for(int i=0;i<n;++i)for(int j=0;j<n;++j){
        cin>>t[i][j];
    }
    vector<int> route(n-1);
    for(int i=0;i<n-1;++i)route[i] = i+1;
    int ret = 0;
    do{
        ll sum = 0;
        sum += t[0][route[0]];
        for(int i=0;i<n-2;++i){
            sum += t[route[i]][route[i+1]];
        }
        sum += t[route[n-2]][0];
        if(sum == k){
            ret ++;
        }
    }while(next_permutation(route.begin(),route.end()));
    cout << ret << endl;
    return 0;

}


#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define lld long double
#define ul  unsigned long int
#define pii pair<int,int>
#define pll pair<lli, lli>
#define vi  vector<int>
#define vii vector<pair<int,int>>
#define vll vector<lli>
#define pb  push_back
#define mpr  make_pair
#define ss  second
#define ff first
#define INF 1000000001
#define inf1 1000000000000000001
#define pie 3.14159265358979323846264338327950L
#define all(x) x.begin(),x.end()
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define testcase() int tc;cin>>tc;while(tc--)
#define clean(x,y) memset(x,y,sizeof(x))

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v) {
	cout << "["; for(int i = 0; i < v.size(); i++) {if (i) cout << ", "; cout << v[i];} return cout << "]";
}
template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p) { return cout << "(" << p.ff << ", " << p.ss << ")"; }
template<typename A, typename B> istream& operator>>(istream& cin, pair<A, B> &p) {
	cin >> p.first;
	return cin >> p.second;
}
void caseNumber(int x){printf("Case %d: ",x);}
void yes(){cout<<"YES\n";}
void no(){cout<<"NO\n";}
int gray_code(int n) {return n ^ (n >> 1);}
int turnOn(int x,int pos) {return x | (1<<pos);}
int turnOff(int x,int pos){return x & !(1<<pos);}
bool isOn(int x,int pos) {return (bool)(x & (1<<pos));}
/// RULESSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS////
/// READ THEM ALOUD......................................................................................................
/// 1. Read the problem at least twice
/// 2. Brute force if contraints r low
/// 3. Check base cases or break case if found any T-T
/// 4. Can u force it into some algorithms?
/// 5. Can u relate it to some previous stuff?
/// 6. :D :) :V :3

lli const mod= 1e9+7;
lli const inf=1e9+9;
//lli const mod=998244353;
lli const maxn=3e5+7;

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

#include <bits/stdc++.h>
#define int long long
#define menhera_chan_is_mine ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define pi pair<int, int>
#define BE(i) i.begin(),i.end()
#define fi first
#define se second
#define INF 2147483647
#define mkp make_pair
#define ist insert
#define mod 1000000007
//#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
//#pragma GCC optimize("O2")
using namespace std;
int min(int a, int b){return a < b ? a : b;}
int max(int a, int b){return a > b ? a : b;}
bool isprime(int k){bool is=1 ; for ( int i = 2 ; i*i <= k ; i++ ) if ( k % i == 0 ) is = 0 ; return k>1?is:0;}
const double PI=acos(-1);
int n;

inline void sol(){
    cin >>n;
    int ans=n,r=2;
    for (int i=1;i<=60;i++){
        if (r>n) break;
        ans=min(ans,i+n/r+n%r);
        r*=2;
    }
    cout <<ans;
}
signed main(){
    menhera_chan_is_mine
    int _=1;
    //cin >>_;
    while (_--) sol();
    return 0;
}


#include <iostream>
#include <vector>

using namespace std;

const int MAX_N = 105;
const int MAX_M = 1e4 + 5;

#define u first
#define v second

pair<int, int> edges [MAX_M];
int dir [MAX_M];

vector<int> adj [MAX_N]; // idx of the edge
int arr [MAX_N];
int vis [MAX_N];

void direct (int u) {
  vis[u] = 1;
  for (int e : adj[u]) {
    if (dir[e] == 0) {
      if (u == edges[e].u) {
        dir[e] = 1;
      } else {
        dir[e] = -1;
      }

      int oth = edges[e].u ^ edges[e].v ^ u;
      if (!vis[oth]) {
        direct(oth);
      }
    }
  }
}

int main () {
  ios::sync_with_stdio(false);

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

  for (int i = 0; i < m; i++) {
    cin >> edges[i].u >> edges[i].v;

    adj[edges[i].u].push_back(i);
    adj[edges[i].v].push_back(i);
  }

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

  for (int i = 0; i < m; i++) {
    if (arr[edges[i].u] > arr[edges[i].v]) {
      dir[i] = 1;
    } else if (arr[edges[i].u] < arr[edges[i].v]) {
      dir[i] = -1;
    }
  }

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

    for (int i = 1; i <= n; i++) {
      if (!vis[i] && arr[i] == k) {
        direct(i);
      }
    }
  }

  for (int i = 0; i < m; i++) {
    if (dir[i] == 1) {
      cout << "->" << '\n';
    } else {
      cout << "<-" << '\n';
    }
  }
}

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

using namespace std;
//using namespace atcoder;

using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using ld = long double;
using vld = vector<ld>;
using vb = vector<bool>;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl
#else
#define dbg(x) true
#endif

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

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

template <class T> ostream& operator<<(ostream& s, const vector<T>& a) {
    for(auto i : a) s << i << ' ';
    return s;
}

constexpr int INF = 1 << 30;
constexpr ll INFL = 1LL << 62;
constexpr ld EPS = 1e-12;
ld PI = acos(-1.0);

void solve() {
    ll n, m;
    cin >> n >> m;
    using P = pair<ll, char>;
    vector<vector<P>> g(n);
    while(m--) {
        ll a, b;
        char c;
        cin >> a >> b >> c;
        --a, --b;
        g[a].emplace_back(b, c);
        g[b].emplace_back(a, c);
    }
    vvll dist(n, vll(n, INFL));
    dist[0][n-1] = 0;
    queue<pll> que;
    que.emplace(0, n-1); // v0, v1
    ll ans = INFL;
    while(!que.empty()) {
        ll v0 = que.front().first;
        ll v1 = que.front().second;
        que.pop();
        ll d = dist[v0][v1];
        for(auto [nv0, c0] : g[v0]) {
            if(nv0 == v1) {
                chmin(ans, 2*d + 1);
                continue;
            }
            for(auto [nv1, c1] : g[v1]) {
                if(c0 != c1) continue;
                if(nv0 == nv1) {
                    chmin(ans, 2*(d+1));
                    continue;
                }
                if(chmin(dist[nv0][nv1], d+1)) {
                    que.emplace(nv0, nv1);
                }
            }
        }
    }
    if(ans == INFL) cout << -1 << endl;
    else cout << ans << endl;
    return;
}

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


#include <iostream>
#include <vector>
#include <unordered_set>
#include <string>
#include <algorithm>
#include <cstdio>

using namespace std;

int main(void) {
    int t, n;
    string s1, s2, s3;
    cout << fixed;

    cin >> t;
    for (int i = 0; i < t; i++) {
        cin >> n;
        cin >> s1 >> s2 >> s3;

    	cout << 1;
    	for (int j = 0; j < n; j++) {
    		cout << 0;
            }
    	for (int j = 0; j < n; j++) {
    		cout << 1;
            }
        cout << endl;
    }

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
long long n,m,mx=-1e9,a[1000010],i,j,k,l=-1,s,t,p;
int main(){
	cin>>n>>m;
	for(i=1;i<=n;i++){
		cin>>s>>t>>p;
		a[s+1]+=p;
		a[t+1]=a[t+1]-p;
		l=max(l,t);
	}
	for(i=1;i<=l;i++){
		a[i]+=a[i-1];
		mx=max(a[i],mx);
	}
	if(mx>m) cout<<"No";
	else cout<<"Yes";
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
typedef unsigned long long ull;
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define f(i,a,b) for(ll i=a;i<=b;i++)
#define testcases ll t;cin>>t;while(t--)
#define dec(x) greater<x>()

/*** Define fues ***/
#define mx 200005
#define mod 1000000007
#define PI acos(-1.0)
#define eps 1e-7
#define size1 100005
const char nl = '\n';

#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define mem(name, fue) memset(name, fue, sizeof(name))

/*** STLs ***/
typedef vector <ll> vll;
typedef set <ll> sll;
typedef multiset <ll> msll;
typedef queue <ll> qll;
typedef map <ll, ll> mll;
typedef pair <ll, ll> pll;
typedef vector <pair <ll , ll> > vpll;

/*** Sorts ***/
#define all(v) (v).begin(), (v).end()
#define rev(v) reverse(all(v))
#define srt(v) sort(all(v))
#define srtGreat(v) sort(all(v), greater<ll>())
inline bool cmp(pll a, pll b) { if (a.ff == b.ff)return a.ss < b.ss; return a.ff > b.ff; }

#define en cout << '\n';
#define no cout << "NO" << '\n'
#define yes cout << "YES" << '\n'
#define case cout << "Case " << t++ << ": "

/*** Functions
ll BigMod(ll base, ll pow, ll modfue){ if (pow == 0) return 1;  ll ans = BigMod(base, pow / 2, modfue);ll total = ((ans % modfue) * (ans % modfue)) % modfue;  if(pow % 2 == 0) return total; else{ return (total * (base % modfue) ) % modfue; } }
ll InverseMod(ll base, ll pow) { if(pow == 0) return 1; ll ans = InverseMod(base, pow / 2); ans = (ans * ans) % mod; if(pow & 1){ return (ans * base) % mod; } else{ return ans; } }
bool checkprime(ll num) { if(num < 2) return false; for(ll i = 2; i * i <= num; i++){ if(num % i == 0) return false; } return true; }
ll EularPHI(ll num) { double ans = num; for(ll i = 2; i * i <= num; i++){ if(num % i == 0){ while (num % i == 0) { num /= i; } ans *= (1.0 - (1.0 / (double)i)); } } if(num > 1) ans *= (1.0 - (1.0 / (double)num)); return (ll)ans; }
ll sumofdigit(ll n){ll sum=0;while(n){sum=sum+n%10;n=n/10;}return sum;}
ll countDigit(ll n) { if (n == 0) return 0; return 1 + countDigit(n / 10); }
ll countDigit(ll n) { return floor(log10(n) + 1); } //only positive
 ***/

template <class T> inline T gcd(T a, T b) {if (b == 0)return a; return gcd(b, a % b);}
template <class T> inline T lcm(T a, T b) {return a * b / gcd<T>(a, b);}
template <class T> inline T power(T b, T p) {ll ans = 1; while (p--) ans *= b; return ans;}

void solve()
{
	ll n;cin>>n;
	vll a(n);
	loop(i,0,n)cin>>a[i];
	ll manhattan=0;
	ll euclid=0;
	loop(i,0,n)manhattan+=abs(a[i]);
	cout<<manhattan<<nl;

	loop(i,0,n)
	{
		euclid+=(abs(a[i])*abs(a[i]));
	}

	cout<<fixed<<setprecision(10) <<sqrt(euclid)<<nl;

	ll ans = 0;
    loop(i,0,n)ans = max(ans,abs(a[i]));
    cout << ans << endl;
}

int main()
{

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

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

	ll t=1;
	// cin>>t;
	// ll pppppp=1;
	while(t--)
	{
		// cout<<"CASE #"<<pppppp;
		solve();
	}

}

#include <bits/stdc++.h>
using namespace std;
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout << fixed << setprecision(9);
	int n;
	cin >> n;
	vector<int> x(n);
	for (auto &i : x) cin >> i, i = abs(i);
	long long M = 0;
	for (auto i : x) M += i;
	double E = 0;
	for (auto i : x) E += 1LL * i * i;
	E = sqrt(E);
	int C = *max_element(x.begin(), x.end());
	cout << M << "\n" << E << "\n" << C << "\n";
	return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
//#include <atcoder/all>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
using ll = long long;
using namespace std;
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; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}

const int inf = 1e9;

int N,M;
int e[20][20];
vector<int> dp;
vector<int> ok;

int perf(int S){
  rep(i,N){
    rep(j,N){
      if(i==j) continue;
      if((S&(1<<i))!=0 && (S&(1<<j))!=0){
        if(e[i][j]==0){
          return 0;
        }
      }
    }
  }
  return 1;
}

int main(){
  cin >> N >> M;
  vector<int> A(M), B(M);
  rep(i,M){
    cin >> A[i] >> B[i];
    A[i]--; B[i]--;
    e[A[i]][B[i]] = e[B[i]][A[i]] = 1;
  }
  dp.assign(1<<N, inf);
  rep(i,1<<N){
    if(perf(i)) dp[i] = 1;
  }
  rep(i,1<<N){
    for(int j=i;--j&=i;){
      chmin(dp[i], dp[i-j]+dp[j]);
    }
  }
  cout << dp.back() << endl;
  return 0;
}

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

using ll = long long;
using vb = vector<bool>;
using vi = vector<int>;
using vll = vector<long long>;
using pll = pair<long long, long long>;

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

constexpr long long mod = 1000000007;

#define rep(i, n) for (ll i = 0; i < n; i++)
#define repi(i, a, b) for (ll i = a; i < b; i++)

#define all(x) (x).begin(), (x).end()

long long _mod_pow(long long x, long long n, long long p){
    long long res=1;
    while(n>0){
        if(n&1) res=res*x%p;
        x=x*x%p;
        n>>=1;
    }
    return res;
}

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

    ll n, m;
    cin >> n >> m;

    ll t = _mod_pow(10, n, m * m);

    t = (t / m) % m;
    cout << t << endl;

}


#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define ll int64_t
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define all(V) V.begin(),V.end()
#define PI 3.14159265359
#define fi fixed
#define se setprecision(10)
using namespace std;

int main() {
  ll s,p;cin >> s >> p;
  for(ll i=1;i<=sqrt(p);i++){
    if(p%i==0){
      ll a = p/i;
      if(a+i==s){
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
     long long int i,s,p,j;
     cin>>s>>p;
     for(i=1;;i++){
               if(i*(s-i)==p){
                    cout<<"Yes\n";
                    return 0;
               }
       if(i*(s-i)>p){break;}
          }
     cout<<"No\n";
}


//50以内的质数有15个，所以我们穷举Y有哪些质因子，然后求出Y（注意要用long long）再一个个判断是不是互质，直接验证就行，与A题思路相似
#include <iostream>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;
#define maxx 100
#define  ll long long
int ans[maxx];
int prime[maxx];
int a[maxx];
vector<ll > p;
int in=0;
bool cmop(ll  a,ll b){
	return a>b;
}
ll gcd(ll a,ll b){
	return a%b==0?b:gcd(b,a%b);
}
//把50以内的素数全部打出来放在prime里面;
void Prime(){
	for(int i=2;i<=50;i++){
		if(!ans[i]){
			prime[in++]=i;
			for(int j=i+i;j<=50;j+=i){
				ans[j]=1;
			}
		}
	}
}
int main()
{
	Prime();
	int N;
	cin>>N;
	for(int i=1;i<=N;i++){
		cin>>a[i];
	}
	for(int i=1;i<=(1<<15);i++){
		ll temp=1;
		for(int j=0;j<15;j++){//
			if((i>>j)&1){
				temp*=prime[j];
			}
		}
		p.push_back(temp);
	}
	sort(p.begin(),p.end());
	for(int i=0;i<=p.size();i++){
		bool falg=true;
		for(int j=1;j<=N;j++){
			if(gcd(a[j],p[i])==1){
				falg=false;
				break;
			}
		}
		if(falg){
			cout<<p[i];
			return 0;

		}
	}

	return 0;

}

// Author: Vinay Khilwani
// Language: C++

// @vok8: Codeforces, AtCoder, LeetCode, HackerEarth, TopCoder, Google, FB, CSES, Spoj, GitHub
// @vok_8: CodeChef, GFG
// @vok8_khilwani: HackerRank

// Never Stop Trying.
// Trying to be Better than Myself.

// while(true)
// {
//     if(AC)
//     {
//         break;
//     }
//     else if(Contest Over)
//     {
//         Try.
//         Check out Editorial.
//         Understand.
//         Find out your Mistake.
//         Learn the topic (if new).
//         Solve Problems on that topic (if new).
//         Upsolve that problem.
//         break;
//     }
//     else
//     {
//         Try.
//         Use Pen-Paper.
//         Find errors, edge cases, etc.
//         continue;
//     }
// }

// Optimizations
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx2")
#pragma GCC optimize("Os")

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

// Debugging
#define dbg(a) cerr<<a<<"\n";
#define debug_a(a) for(auto x:a) {cerr<<x<<" ";} cerr<<"\n";
#define debug_b(a) for(auto x:a) {cerr<<"["<<x.first<<", "<<x.second<<"]"<<"\n";} cerr<<"\n";
#define debug_c(a) for(auto x:a) {debug_a(x)} cerr<<"\n";
#define debug_d(a) for(auto x:a) {debug_b(x)} cerr<<"\n";
#define debug_e(a) cerr<<"["<<a.first<<", "<<a.second<<"]"<<"\n";

// Defines
#define fast ios_base::sync_with_stdio(false); cout.tie(NULL); cin.tie(NULL);
#define loop(i,a,n) for(int i=a; i<n; i++)
#define rloop(i,a,n) for(int i=a; i>=n; i--)
#define fr(i,a,n,b) for(int i=a; i<n; i+=b)
#define rfr(i,a,n,b) for(int i=a; i>=n; i-=b)
#define IN cin>>
#define OUT cout<<
#define nl "\n"
#define sz(a) int(a.size())
#define all(a) (a).begin(),(a).end()
#define each(a,b) for(auto &a:b)
#define pb push_back
#define set_bits(a) __builtin_popcountll(a)
#define ar array
#define write(a) for(auto x:a) {OUT x<<" ";} OUT nl;
#define read(a) for(auto &x:a) {IN x;}
// #define oset tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
using ll=long long int;
using ld=long double;
using pll=pair<ll,ll>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vi=vector<int>;
const ll mod=(ll)(1e9)+7LL;
const ll M=998244353LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const ld pi=acos(-1);

// General Functions
ll gcd(ll a, ll b)
{
    return (b?gcd(b,a%b):a);
}
ll P(ll B, ll power, ll modulo) //Fast Power
{
    ll ans=1LL;
    while(power>0LL)
    {
        if(power%2LL==1LL)
        {
            ans=(ans*B)%modulo;
        }
        B=(B*B)%modulo;
        power/=2LL;
    }
    return ans;
}
bool isPrime(ll n)
{
    if(n<=1LL)
    {
        return false;
    }
    if(n<=3LL)
    {
        return true;
    }
    if(n%2==0LL || n%3==0LL)
    {
        return false;
    }
    for(ll i=5LL; (i*i)<=n; i+=6LL)
    {
        if(n%i==0LL || n%(i+2LL)==0LL)
        {
            return false;
        }
    }
    return true;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll get_rand(ll l, ll r)
{
    uniform_int_distribution<ll> uid(l,r);
    return uid(rng);
}
void vok()
{
    fast
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
        freopen("error.txt","w",stderr);
    #endif
}

// Global Variables
const int mxN=int(1e5)+100;

// Solver Function(s)
void solve()
{
    ld sx,sy,gx,gy;
    IN sx>>sy>>gx>>gy;
    if(sx>gx)
    {
        swap(sx,gx);
        swap(sy,gy);
    }
    //(gx-ans)/gy=(ans-sx)/sy
    //sy*(gx-ans)=gy*(ans-sx);
    ld ans=(gy*sx)+(sy*gx);
    ans/=(sy+gy);
    OUT ans<<nl;
}

// Main Function
int main()
{
    vok();
    OUT fixed<<setprecision(10);
    int t=1;
    // IN t;
    while(t--)
    {
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
#ifdef WA_DEBUG
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif

using ll  = long long;
using ull = unsigned long long;
#define pb push_back
#define fi first
#define se second
#define rep(i,a,b) for(int i=int(a);i<=(int)(b);i++)
#define per(i,a,b) for(int i=int(a);i>=(int)(b);i--)
const int mod  = 1e9+7;
const int inf  = 0x3f3f3f3f;
const int maxn = 1e5+10;
int main() {
#ifndef WA_DEBUG
    ios::sync_with_stdio(false);cin.tie(nullptr);
#endif
    int n;
    cin>>n;
    vector<int> a(n+1);
    int Min=inf;
    rep(i,1,n) {
        cin>>a[i];
        Min=min(a[i],Min);
    }
    set<int> s;
    rep(i,1,n) {
        rep(j,1,maxn) {
            if(j*j>a[i]) break;
            if(a[i]%j==0) {
                s.insert(j);
                if(j*j!=a[i]) s.insert(a[i]/j);
            }
        }
    }
    int cnt=0;
    for(int x:s) {
        if(x>Min) continue;
        int ans=-1;
        rep(i,1,n) {
            if(ans==1) break;
            if(a[i]%x==0) {
                if(ans==-1) ans=a[i]/x;
                else ans=__gcd(ans,a[i]/x);
            }
        }
        if(ans==1&&x<=Min) cnt++;
    }
    cout<<cnt<<'\n';
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
const int N = 1500005;
ll getgcd(ll x,ll y) {return (y==0) ? x : getgcd(y,x%y);}
int a[N],n,ans;
map <int,int> mp;
void ins(int x,int t)
{
    if (!mp[x]) mp[x]=t;
    else mp[x]=getgcd(mp[x],t);
}
int main()
{
    cin>>n; for (int i=1;i<=n;++i) scanf("%d",&a[i]);
    sort(a+1,a+1+n);
    for (int i=1;i<=n;++i)
    {
        for (int j=1;j*j<=a[i];++j)
        if (a[i]%j==0)
        {
            ins(j,a[i]);
            ins(a[i]/j,a[i]);
        }
    }
    ans=0;
    for (auto it:mp) ans+=(it.first==it.second && it.first<=a[1]);
    cout<<ans<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
using lint = long long;
struct fast_ios { fast_ios(){ cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define REP(i, n) FOR(i,0,n)

// Z algorithm (length of longest common prefix for s[0:N] & s[i:N] for each i)
// Complexity: O(N)
// <http://snuke.hatenablog.com/entry/2014/12/03/214243>
template <typename T> std::vector<int> z_algorithm(const std::vector<T> &s) {
    const int N = s.size();
    if (N == 0) return {};
    std::vector<int> ans(N);
    ans[0] = N;
    int i = 1, j = 0;
    while (i < N) {
        while (i + j < N and s[j] == s[i + j]) ++j;
        ans[i] = j;
        if (!j) {
            ++i;
            continue;
        }
        int k = 1;
        while (i + k < N and k + ans[k] < j) ans[i + k] = ans[k], ++k;
        i += k;
        j -= k;
    }
    return ans;
}

std::vector<int> z_algorithm(const std::string &s) {
    const int N = int(s.size());
    std::vector<int> v(N);
    for (int i = 0; i < N; i++) v[i] = s[i];
    return z_algorithm(v);
}

int N;
string T;

lint solve(lint n)
{
    string S = T;
    S += '_';
    REP(_, n) S += "110";

    vector<int> z = z_algorithm(S);
    lint ret = 0;
    FOR(i, T.size() + 1, S.size()) ret += (z[i] == N);
    return ret;
}

int main()
{
    cin >> N >> T;
    lint A = 1000000;
    lint s1 = solve(A), s2 = solve(A * 2);
    lint ret = s1 + (10000000000LL - A) / A * (s2 - s1);
    cout << ret << '\n';
}

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

#define SORT(c) sort((c).begin(), (c).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
#define ANS(ans) cout << (ans) << endl;
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
typedef vector<int> VI;
typedef pair<int, int> P;

void print() { cout << endl; }

template <class Head, class... Tail> void print(Head &&head, Tail &&...tail) {
    cout << head;
    if (sizeof...(tail) != 0)
        cout << " ";
    print(forward<Tail>(tail)...);
}

template <class T> void print(vector<T> &vec) {
    for (auto &a : vec) {
        cout << a;
        if (&a != &vec.back())
        cout << " ";
    }
    cout << endl;
}

template <class T> void print(vector<vector<T>> &df) {
    for (auto &vec : df) {
        print(vec);
    }
}

// repetition
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define REP(i, n) for (long long i = 0; i < (n); ++i)

int main() {
    ll n;
    cin >> n;

    VI v(n);
    REP(i,n){
        cin>>v[i];
    }

    ll ans;
    ans = n*(n-1)/2;
    // print(ans);

    SORT(v);

    ll prev_key;
    ll prev_count=1;
    REP(i,n){
        if(i==0){
            prev_key=v[i];
            prev_count=1;
            continue;
        }

        if(v[i]==prev_key){
            prev_count++;
        } else {
            ans -= prev_count * (prev_count - 1) / 2;
            // print(prev_key,prev_count);
            // print(ans);
            prev_key = v[i];
            prev_count = 1;
        }
    }

    ans-=prev_count*(prev_count-1)/2;

    ANS(ans);

    return 0;
}


#include<iostream>
using namespace std;
int main(){
  int N,ans=0,q;
  cin>>N;
  for(int i=0;i<N;i++){
    cin>>q;
    if(q<=10)ans+=0;
    else ans+= q-10;
  }
  cout<<ans<<endl;
}

// // Created by ...Rahul Chandra
// #include <bits/stdc++.h>

// #define db1(x) cout<<#x<<"="<<x<<'\n'
// #define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
// #define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
// #define rep(i,n) for(int i=0;i<(n);++i)
// #define repA(i,a,n) for(int i=a;i<=(n);++i)
// #define repD(i,a,n) for(int i=a;i>=(n);--i)

// using namespace std;
// using ll = long long;

// ll n;

// inline void read() {
//     cin >> n;
// }

// inline void solve() {

// }

// int main()
// {
//     ios::sync_with_stdio(0);
//     cin.tie(0);
//     cout.tie(0);
//     long long a,b,c,d,e,f,g,rahul=0;
//     int n;
//     cin>>n;
//     int arr[n];
//     for (int i = 0; i < n; ++i)
//     {
//         /* code */
//         cin>>arr[i];
//     }

//     sort(arr,arr+n);

//     int max1=arr[n-1];

//     for(int i=n-1;i>=0;i--){
//         if(arr[i]<max1){
//             max1=arr[i];
//             break;
//         }
//     }
//     if (max1!=arr[n-1])
//     {
//         cout<<max1<<endl;        /* code */
//     }
//     else
//         cout<<"-1"<<endl;
//     return 0;
// }
// Created by ...Rahul Chandra
#include <bits/stdc++.h>

#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define rep(i,n) for(int i=0;i<(n);++i)
#define repA(i,a,n) for(int i=a;i<=(n);++i)
#define repD(i,a,n) for(int i=a;i>=(n);--i)

using namespace std;
using ll = long long;

ll n;
inline void read() {
    cin >> n;
    ll arr[n];
ll count=0;

    for (int i = 0; i < n; ++i)
    {
        /* code */
        cin>>arr[i];
        if (arr[i]>10)
        {
            /* code */
            count+=arr[i]-10;
        }
    }
    cout<<count<<endl;
}

inline void solve() {

}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    long long a,b,c,d,e,f,g,rahul=0;
    read();

    return 0;
}


#include <bits/stdc++.h>

#define FAST_IO ios::sync_with_stdio(false); cin.tie(0), cout << setprecision(15);
#define ll long long int
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rrep(i, k, n) for (ll i = k; i>=n; i--)
#define repp(i, k, n) for (ll i = k; i < (n); i++)
#define pb push_back
#define all(x) begin(x), end(x)
#define vc vector<ll>
using namespace std;
using namespace std::chrono;
typedef std::chrono::high_resolution_clock Clock;
typedef std::chrono::milliseconds Milliseconds;

bool func(const array<ll, 2> &a, const array<ll, 2> &b) {
    if (a[0] > b[0]) return true;
    if (a[0] == b[0]) {
        if (a[1] < b[1]) {
            return true;
        }
    }
    return false;
}

bool fun(vc &arr, ll k, ll inc) {
    ll s = arr[0] + inc;
    repp(i, 1, arr.size()) {
        if (arr[i] * 100 > k * s) {
            return false;
        }
        s += arr[i];
    }
    return true;
}

void solve() {
    ll n, k;
    cin >> n >> k;
    vc arr(n);
    rep(i, n) cin >> arr[i];

    ll mid;
    ll low = 0;
    ll high = 2e14;
    while (low < high) {
        mid = (low + high) / 2;
        if (fun(arr, k, mid)) {
            high = mid;
        } else {
            low = mid + 1;
        }
    }
    ll ans = low;
    cout << ans << "\n";

}

void lc() {
    ll n;
    cin >> n;
    vc c(n);
    rep(i, n) cin >> c[i];
    vector<array<ll, 2>> arr(n);
    rep(i, n) {
        cin >> arr[i][0];
    }
    rep(i, n) {
        cin >> arr[i][1];
    }
    vector<bool> can(n, true);
    repp(i, 1, n) {
        ll a = arr[i - 1][0];
        ll b = arr[i - 1][1];
        if (max(a, b) < min(arr[i][0], arr[i][1]) || min(a, b) > max(arr[i][0], arr[i][1])) {
            can[i] = true;
        }
    }
    vc v(n, 0);
    rep(i, n) {
        ll a = arr[i][0];
        ll b = arr[i][1];
        if (i == 0) {
            v[i] = max(a, b) - min(a, b);
        } else {
            if (can[i]) {

            } else {

            }
        }
    }
}

void at() {
    ll n, s, d;
    cin>>n>>s>>d;
    vector<array<ll, 2>> arr(n);
    bool can = false;
    rep(i, n){
        cin>>arr[i][0]>>arr[i][1];
        if(arr[i][0]<s && arr[i][1]>d) can = true;
    }
    if(can) cout<<"Yes";
    else cout<<"No";
}

int main() {
    FAST_IO
    ll test = 1;
//    cin >> test;
    while (test-- > 0) {
        at();
    }
}

#include <bits/stdc++.h>
// #include <atcoder/all>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for(int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
// using namespace atcoder;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

ll a[MAX_N], b[MAX_N];
const ll INF = 1001001001001001001;
vector<int> G[MAX_N];

int main() {
    int n, m;
    cin >> n >> m;
    rep(i,n) cin >> a[i];
    rep(i,m){
        int x, y;
        cin >> x >> y;
        x--; y--;
        G[x].push_back(y);
    }

    ll ans = -INF;

    rep(i,n) b[i] = a[i];
    rep(i,n){
        rep(j,G[i].size()){
            int y = G[i][j];
            ans = max(ans, a[y] - b[i]);
            b[y] = min(b[y], b[i]);
        }
    }

    cout << ans << endl;
    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()
//https://qr.ae/pG7uXl

vector<pii>g[1005];
int main(){
	fast;
	int n,m,i,j;
	cin>>n>>m;
	vector<pii>v;
	for(i=0;i<m;i++)
	{
		int x,y;
		char c;
		cin>>x>>y>>c;
		v.pb({x,y});
		g[x].pb({y,c-'a'});
		g[y].pb({x,c-'a'});
	}
	queue<pii>q;
	q.push({1,n});
	int dp[n+1][n+1];
	int vis[n+1][n+1];
	mem(vis,0);
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=n;j++)
			dp[i][j]=INF;

	}
	dp[1][n]=0;
	vis[1][n]=1;
	int ans=INF;
	while(q.size()!=0)
	{
		auto z=q.front();
		q.pop();
		for(auto x:g[z.fi])
		{
			for(auto y:g[z.se])
			{
				if(x.se==y.se)
				{
					if(dp[x.fi][y.fi]>dp[z.fi][z.se]+1)
					{
						dp[x.fi][y.fi]=dp[z.fi][z.se]+1;
						q.push({x.fi,y.fi});
						vis[x.fi][y.fi]=1;
					}
				}
			}
		}
	}
	for(i=1;i<=n;i++)
	{
		ans=min(ans,dp[i][i]*2);
	}
	for(i=0;i<m;i++)
	{
		ans=min(ans,dp[v[i].se][v[i].fi]*2+1);
		ans=min(ans,dp[v[i].fi][v[i].se]*2+1);
	}
	if(ans==INF)
		cout<<-1<<"\n";
	else
		cout<<ans;

}

#pragma GCC optimize(2)
#pragma GCC optimize(3,"Ofast","inline")
#include <bits/stdc++.h>
#define inf 0x7fffffff
#define ll long long
//#define int long long
//#define double long double
#define eps 1e-8
//#define mod 1e9+7
#define ls(p) p<<1
#define rs(p) p<<1|1
#define pi acos(-1.0)
using namespace std;
const int mod=1e9+7;
const int M=5e6;
const int N=4*1e3+5;//?????????? 4e8
int v[N][N],d[N][N];
int n,m;
struct node
{
	int next,ver;
}e[N];
int tot,head[N];
queue < pair < int , int > > q;
void add(int x,int y)
{
	e[++tot].ver=y;
	e[tot].next=head[x];
	head[x]=tot;
}
void addedge(int x,int y)
{
	add(x,y);add(y,x);
}
int bfs()
{
	while(q.size())
	{
		int x1=q.front().first;
		int x2=q.front().second;
		q.pop();
		for(int i1=head[x1];i1;i1=e[i1].next)  for(int i2=head[x2];i2;i2=e[i2].next)
		{
			int y1=e[i1].ver;
			int y2=e[i2].ver;
			if(d[x1][y1]==d[x2][y2]&&v[y1][y2]==-1)//两边扩展
			{
				v[y1][y2]=v[x1][x2]+2;
				q.push(make_pair(y1,y2));
			}
		}
	}
	return v[1][n];
}
void solve()
{
	cin>>n>>m;
	memset(v,-1,sizeof(v));
	for(int i=1;i<=n;i++)  q.push(make_pair(i,i)),v[i][i]=0;//偶对称，由于是求最小对称，所以要先进队
	for(int i=1;i<=m;i++)
	{
		int x,y;
		char z;
		cin>>x>>y>>z;
		addedge(x,y);
		d[x][y]=d[y][x]=z;
		if(v[x][y]==-1)
		{
			q.push(make_pair(x,y));q.push(make_pair(y,x));//奇对称
			v[x][y]=v[y][x]=1;
		}
	}
	cout<<bfs();
}
signed main()
{
    int T=1;
//    cin>>T;
    for(int index=1;index<=T;index++)
    {
        solve();
//        puts("");
    }
    return 0;
}