#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 1000000000;
const long long int llINF = 1000000000000000000;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define SP(a) setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

typedef ll Weight;
struct Edge {
  ll src, dst;
  Weight weight;
  Edge(ll src, ll dst, Weight weight) : src(src), dst(dst), weight(weight) {}
};

bool operator<(const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
             e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

typedef vector<Weight> Array;
typedef vector<Array> Matrix;

pair<Weight, Edges> Prim(const Graph &g, ll r = 0) {
  ll n = g.size();
  Edges T;
  Weight total = 0;

  vector<bool> visited(n);
  priority_queue<Edge> Q;
  Q.push(Edge(-1, r, 0));
  while (!Q.empty()) {
    Edge e = Q.top();
    Q.pop();
    if (visited[e.dst])
      continue;
    T.push_back(e);
    total += e.weight;
    visited[e.dst] = true;
    AUTO(f, g[e.dst]) if (!visited[f.dst]) Q.push(f);
  }
  return pair<Weight, Edges>(total, T);
}

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll N;
  cin >> N;
  vector<pll> X, Y;
  Graph G(N);
  REP(i, N) {
    ll x, y;
    cin >> x >> y;
    X.push_back(make_pair(x, i));
    Y.push_back(make_pair(y, i));
  }
  sort(ALL(X));
  sort(ALL(Y));

  REP(i, N - 1) {
    G[X[i].second].push_back(
        Edge(X[i].second, X[i + 1].second, X[i + 1].first - X[i].first));
    G[X[i + 1].second].push_back(
        Edge(X[i + 1].second, X[i].second, X[i + 1].first - X[i].first));
    G[Y[i].second].push_back(
        Edge(Y[i].second, Y[i + 1].second, Y[i + 1].first - Y[i].first));
    G[Y[i + 1].second].push_back(
        Edge(Y[i + 1].second, Y[i].second, Y[i + 1].first - Y[i].first));
  }
  auto ans = Prim(G, 0);
  cout << ans.first << endl;

  return 0;
}

#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
#define MAX 100100
inline int read()
{
	int x=0;bool t=false;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
	if(ch=='-')t=true,ch=getchar();
	while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();
	return t?-x:x;
}
int n,s,a[MAX];
bool calc(int p)
{
	int s=0,mn=1e9;
	for(int i=1;i<=n;++i)s+=a[i]&1,mn=min(mn,a[i]);
	if((n-s)&1)return p;
	if(s>1||mn==1)return p^1;
	for(int i=1;i<=n;++i)a[i]>>=1;
	int d=a[1];
	for(int i=1;i<=n;++i)d=__gcd(d,a[i]);
	for(int i=1;i<=n;++i)a[i]/=d;
	calc(p^1);
}
int main()
{
	n=read();for(int i=1;i<=n;++i)a[i]=read();
	puts(calc(1)?"First":"Second");
	return 0;
}


#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e18;

template< typename T = int >
struct Edge {
  int from, to;
  T cost;
  int idx;

  Edge() = default;

  Edge(int from, int to, T cost = 1, int idx = -1) : from(from), to(to), cost(cost), idx(idx) {}

  operator int() const { return to; }
};

template< typename T = int >
struct Graph {
  vector< vector< Edge< T > > > g;
  int es;

  Graph() = default;

  explicit Graph(int n) : g(n), es(0) {}

  size_t size() const {
    return g.size();
  }

  void add_directed_edge(int from, int to, T cost = 1) {
    g[from].emplace_back(from, to, cost, es++);
  }

  void add_edge(int from, int to, T cost = 1) {
    g[from].emplace_back(from, to, cost, es);
    g[to].emplace_back(to, from, cost, es++);
  }

  void read(int M, int padding = -1, bool weighted = false, bool directed = false) {
    for(int i = 0; i < M; i++) {
      int a, b;
      cin >> a >> b;
      a += padding;
      b += padding;
      T c = T(1);
      if(weighted) cin >> c;
      if(directed) add_directed_edge(a, b, c);
      else add_edge(a, b, c);
    }
  }
};

/**
 * @brief BFS(幅優先探索)
 */
template< typename T >
vector< T > bfs(const Graph< T > &g, int s) {
  T max_cost = 0, beet = 0;
  for(auto &es : g.g) {
    for(auto &e : es) max_cost = max(max_cost, e.cost);
  }
  ++max_cost;
  const auto INF = numeric_limits< T >::max();
  vector< T > dist(g.size(), INF);
  vector< queue< int > > ques(max_cost + 1);
  dist[s] = 0;
  ques[0].emplace(s);
  for(T cost = 0; cost <= beet; cost++) {
    auto &que = ques[cost % max_cost];
    while(!que.empty()) {
      int idx = que.front();
      que.pop();
      if(dist[idx] < cost) continue;
      for(auto &e : g.g[idx]) {
        auto next_cost = cost + e.cost;
        if(dist[e.to] <= next_cost) continue;;
        dist[e.to] = next_cost;
        beet = max(beet, dist[e.to]);
        ques[dist[e.to] % max_cost].emplace(e.to);
      }
    }
  }
  return dist;
}

int main(){
    int n,u,v;
    cin >> n >> u >> v;
    u--;v--;
    Graph<int> g(n);
    g.read(n-1,-1,false,false);
    auto dista = bfs(g,v);
    auto distt = bfs(g,u);
    int M = 0;
    rep(i,n){
        if(dista[i]>distt[i])chmax(M,dista[i]);
    }
    cout << M-1 << endl;
    return 0;
}

#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = int_fast64_t;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

int n, u, v;
vector<vector<int> > G;
vector<int> depth, maxdepth, parent;
int dfs(int s, int p, int d) {
  depth[s] = d;
  parent[s] = p;
  int maxd = d;
  for(const int t : G[s]) if(t != p) {
    chmax(maxd, dfs(t, s, d+1));
  }
  return maxdepth[s] = maxd;
}
void answer() {
  cin >> n >> u >> v;
  u--; v--;
  G.resize(n);
  depth.resize(n);
  maxdepth.resize(n);
  parent.resize(n);
  rep(i, n-1) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    G[a].emplace_back(b);
    G[b].emplace_back(a);
  }
  dfs(v, -1, 0);
  int ans = 0;
  int cur = u;
  while(cur != 0) {
    if(depth[u] - depth[cur] < depth[cur]) {
      chmax(ans, maxdepth[cur] - 1);
    } else {
      chmax(ans, maxdepth[u] - 1);
    }
    cur = parent[cur];
  }
  cout << ans << "\n";
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}


// 3人でカードゲームイージー  /  理解できた
// #16973056
#include <bits/stdc++.h>
using namespace std;

int main(){
    vector<string> s(3);
    cin >> s[0] >> s[1] >> s[2];
    vector<int> i(3, 0);
    char c[]={'A', 'B', 'C'};
    int t=0;
    while(true){
        if(i[t]==s[t].size()){
            cout << c[t] << endl;
            return 0;
        }
        i[t]++;
        t=s[t][i[t]-1]-'a';

    }
}

#include <bits/stdc++.h>

using namespace std;

int ans = 0;

int dfs(int v, int pv, int k, vector<vector<int>>& g) {
  int max_d = 0;
  for (int u : g[v]) {
    max_d = max(max_d, 1 + dfs(u, v, k, g));
  }
  if (max_d == k - 1 && v != 0) {
    ans += pv > 0;
    max_d = -1;
  }
  return max_d;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> f(n);
  for (int i = 0; i < n; i++) {
    cin >> f[i];
    f[i]--;
  }
  ans = f[0] != 0;
  f[0] = -1;
  vector<vector<int>> g(n);
  for (int i = 1; i < n; i++) {
    g[f[i]].push_back(i);
  }
  dfs(0, -1, k, g);
  /*
  for (int i = 0; i < n; i++) {
    cerr << i + 1 << " is connected with :";
    for (int j : g[i]) {
      cerr << ' ' << j + 1;
    }
    cerr << endl;
  }
  */
  cout << ans << '\n';
  return 0;
}


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

typedef long long ll;

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define tt int t; cin>>t; while(t--)
#define nl cout<<"\n";
#define sp cout<<" ";
#define rep(i, a, b) for(long long i=a; i<b; i++)

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
double PI = 4*atan(1);

int main()
{
    optimize();

    string s;

    cin>> s;

    if(s[0] != 'A' )
    {
        cout<< "WA\n";
        return 0;
    }

    int cn= 0;

    for(int i=1; i<s.size(); i++)
    {
        if (i>=2 && i<= (s.size() -2 ))
        {
            if(s[i]== 'C')
            {
                cn++;
                continue;
            }
        }

        if(s[i]< 'a' || s[i] > 'z'  || cn>1)
        {
            {
                cout<< "WA\n";
                return 0;
            }
        }
    }

    cout<< (cn==1?  "AC\n" : "WA\n");

    return 0;
}

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

int main()
{
	string S;
	cin >> S;

	string ans = "AC";
	if( S[0] != 'A' ) ans = "WA";
	else {
		string s = S.substr( 2, S.size() - 2 - 1 );
		int n = s.find( 'C' );
		if( n == string::npos ) ans = "WA";
		else if( s.find( 'C', n + 1 ) != string::npos ) ans = "WA";
		else {
			for( int i = 0; i < S.size(); i++ ) {
				if( i == 0 || S[i] == 'C' && 2 <= i && i <= S.size() - 2 ) continue;
				if( islower( S[i] ) == false ) ans = "WA";

			}
		}
	}

	cout << ans << endl;
}


#include <bits/stdc++.h>

using namespace std;

int N;

vector<int> a, b;

vector<int> kmp(const vector<int> &vt, vector<int> &vp)

{

    int i, q, k;

    int n = vt.size();

    int m = vp.size();

    vector<int> nxt(m);

    vector<int> res;

    for (q = 1, k = 0; q < m; ++q) {

        while (k > 0 && vp[q] != vp[k]) k = nxt[k - 1];

        if (vp[q] == vp[k]) k++;

        nxt[q] = k;

    }

    for (i = 0, q = 0; i < n; ++i) {

        while (q > 0 && vp[q] != vt[i]) q = nxt[q - 1];

        if (vp[q] == vt[i]) q++;

        if (q == N) {

            res.push_back(i - m + 1);

            q = nxt[q - 1];

        }

    }

    return res;

}

void solve()

{

    vector<int> c(2*N-1);

    vector<int> d(N);

    for (int i = 0; i < N - 1; i++) {

        c[i] = a[i] ^ a[i + 1];

        d[i] = b[i] ^ b[i + 1];

    }

    c[N - 1] = a[N - 1] ^ a[0];

    d[N - 1] = b[N - 1] ^ b[0];

    for (int i = N; i < 2*N; i++) c[i] = c[i - N];

    auto pos = kmp(c, d);

    for (int k : pos) cout << k << " " << (b[0] ^ a[k]) << endl;

}

int main()

{
    ios::sync_with_stdio(false); cin.tie(0);
    cin >> N;

    a.resize(N);

    b.resize(N);

    for (int i = 0; i < N; i++) cin >> a[i];

    for (int i = 0; i < N; i++) cin >> b[i];

    solve();

    return 0;

}

#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()

template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) { return std::vector<T>(n, std::forward<T>(val)); }
template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}
template<class Cond> struct chain {
  Cond cond; chain(Cond cond) : cond(cond) {}
  template<class T> bool operator()(T& a, const T& b) const { if(cond(a, b)) { a = b; return true; } return false; }
};
template<class Cond> chain<Cond> make_chain(Cond cond) { return chain<Cond>(cond); }

#include <vector>
using u64 = unsigned long long;

struct hash_bases {
  static const u64 MOD = (1ull << 61) - 1;
  const int N;
  std::vector<std::vector<u64>> bases;

  inline static u64 mod(u64 x) {
    x = (x >> 61) + (x & MOD);
    if(x >= MOD) {
      x -= MOD;
    }
    return x;
  }

  inline static u64 mul(u64 a, u64 b) {
    u64 ac = a >> 31;
        a  = a & ((1ull << 31) - 1);
    u64 bc = b >> 31;
        b  = b & ((1ull << 31) - 1);
    u64 x = ac * b + bc * a;;
    x = ac * bc * 2 + (x >> 30) + ((x & ((1ull << 30) - 1)) << 31) + a * b;
    return mod(x);
  }

  hash_bases(std::vector<u64> bs, int M) : N(bs.size()), bases(M, std::vector<u64>(N, 1)) {
    for(int i = 1; i < M; i++) {
      for(int j = 0;j < N; j++){
        bases[i][j] = mul(bases[i - 1][j], bs[j]);
      }
    }
  }

  u64 operator()(int i, int r) {
    return bases[r][i];
  }
} bases(std::vector<u64> { 9973, 10007 }, 202020);

struct rhash {
  static const u64 MOD = hash_bases::MOD;
  std::vector<u64> h;
  u64 len;

  rhash() : h(bases.N), len(0) {}
  rhash(u64 x): h(bases.N), len(1) {
    x = hash_bases::mod(x);
    for(int i = 0; i < bases.N; i++) {
      h[i] = x;
    }
  }

  rhash next(u64 r) const {
    rhash ans;
    for(int i = 0;i < bases.N; i++) {
      ans.h[i] = hash_bases::mul(h[i], bases(i, r));
    }
    ans.len = len + r;
    return ans;
  }

  rhash& operator+=(const rhash& r) {
    for(int i = 0;i < bases.N; i++) {
      h[i] += r.h[i];
      if(h[i] >= MOD) h[i] -= MOD;
    }
    len = std::max(len, r.len);
    return (*this);
  }

  rhash& operator-=(const rhash& r) {
    for(int i = 0;i < bases.N; i++) {
      if(h[i] < r.h[i]) {
        h[i] = h[i] + MOD - r.h[i];
      }
      else {
        h[i] = h[i] - r.h[i];
      }
    }
    return (*this);
  }

  rhash operator+(const rhash& r) const { return rhash(*this) += r; }
  rhash operator-(const rhash& r) const { return rhash(*this) -= r; }
  bool operator==(const rhash& r) const {
    bool OK = true;
    for(int i = 0;i < bases.N; i++){
      OK &= h[i] == r.h[i];
    }
    return OK;
  }
};

int main() {
  i64 N;
  cin >> N;
  vector<i64> A(N);
  rep(i,0,N) cin >> A[i];
  vector<i64> B(N);
  rep(i,0,N) cin >> B[i];
  vector<rhash> sum(N * 2);
  rep(i,0,N * 2 - 1) {
    sum[i + 1] = sum[i].next(1) + rhash(A[i % N] ^ A[(i + 1) % N]);
  }
  rhash bh;
  rep(i,0,N) {
    bh = bh.next(1) + rhash(B[i % N] ^ B[(i + 1) % N]);
  }
  rep(i,0,N) {
    if(sum[i + N] - sum[i].next(N) == bh) {
      cout << i << " " << (A[i] ^ B[0]) << endl;
    }
  }
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
/*
void printVector(const vector<int>& vec) {
    for (int value : vec) {
        cout << value << " ";
    }
    cout << endl;
}
*/
int main() {
    int N;
    cin >> N;
    vector<ld> x(N), y(N);
    for (int i=0; i<N; i++) cin >> x[i] >> y[i];
    vector<ld> base(N), L(N-1);
    for (int i=0; i<N; i++) base[i] = i;
    int p=1;
    for (int i=1; i<=N; i++) p*=i;
    ld cnt = 0;
    for (int i=0; i<p; i++) {
        for (int j=0; j<N-1; j++) {
            cnt += sqrt(pow(x[base[j+1]]-x[base[j]],2)+pow(y[base[j+1]]-y[base[j]],2));
        }
        next_permutation(base.begin(),base.end());
    }
    ld ans = cnt/p;
    cout << fixed << setprecision(8);
    cout << ans << endl;
}

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int INF=1e9;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};

int main(){
  double n;
  cin>>n;
  vector<vector<double>> d(n,vector<double>(2));
  rep(i,n)rep(j,2) cin>>d[i][j];
  vector<int> t(n);
  rep(i,n) t[i]=i;
  double sum=0;
  int cnt=0;
  do{
    for(int i=1;i<n;i++){
      sum+=sqrt((d[t[i]][0]-d[t[i-1]][0])*(d[t[i]][0]-d[t[i-1]][0])+(d[t[i]][1]-d[t[i-1]][1])*(d[t[i]][1]-d[t[i-1]][1]));
    }
    cnt++;
  }while(next_permutation(all(t)));
  printf("%.10f\n",sum/cnt);
}


#include<iostream>
#include<string.h>
using namespace std;

int D[6];
void spin(char c)
{
  if(c=='E'){
    swap(D[0],D[3]);swap(D[3],D[5]);swap(D[5],D[2]);
  }
  else if(c=='W'){
    swap(D[0],D[2]);swap(D[2],D[5]);swap(D[5],D[3]);
  }
  else if(c=='S'){
    swap(D[0],D[1]);swap(D[0],D[4]);swap(D[4],D[5]);
  }
  else if(c=='N'){
    swap(D[0],D[1]);swap(D[1],D[5]);swap(D[5],D[4]);
  }
}
int main()
{
  char M[101];

  for(int i=0;i<6;i++)cin>>D[i];
  cin>>M;

  for(int i=0;i<strlen(M);i++)spin(M[i]);

  cout<<D[0]<<endl;

  return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
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;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;

    }else{
        return a.second < b.second;
    }
}

bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};

int main() {
    ll N;
    cin >>N;
    if(N==1){
        cout<<"Hello World"<<endl;
    }else{
        ll A,B;
        cin>>A>>B;
        cout<<A+B<<endl;
    }

    return 0;

}


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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}

const int mod = 998244353;
const int N = 1e5+23;

int h[N];

long long binpow(long long b, long long e) {
  if (!e) return 1;
  if (e&1) return b*binpow(b, e-1)%mod;
  return binpow(b*b%mod, e/2);
}

void solve() {
  int n; scanf("%d", &n);
  for (int d, i = 0; i < n; ++i) {
    scanf("%d", &d);
    if (!i && d) {
      puts("0");
      return;
    }
    ++h[d];
  }
  if (h[0] > 1) {
    puts("0");
    return;
  }
  long long ans = 1;
  for (int i = 0; i < n-1; ++i) {
    if (!h[i] && h[i+1]) {
      puts("0");
      return;
    }
    (ans *= binpow(h[i], h[i+1])) %= mod;
  }
  printf("%lld", ans);
}

int main() {
  init();
  int t = 1; //scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}

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

using i32 = std::int_fast32_t;
using i64 = std::int_fast64_t;

#define REP(i, stop) FOR(i, 0, stop)
#define FOR(i, start, stop) for (int i = start, i##_len = stop; i < i##_len; ++i)
#define RREP(i, n) for (int i = n; i-- > 0;)

i32 M = 998244353;
i32 dp[90310];
i32 dq[90310];

signed main() {
  i32 n;
  scanf("%d", &n);
  vector<i32> A(n);
  i32 sum = 0;
  REP(i, n) {
    scanf("%d", &A[i]);
    sum += A[i];
  }
  i32 lim = (sum - 1) / 2;
  dp[0] = 1;
  dq[0] = 1;
  REP(i, n) {
    RREP(t, 90000) {
      (dp[t + A[i]] += dp[t]) %= M;
      (dp[t] *= 2) %= M;
      (dq[t + A[i]] += dq[t]) %= M;
    }
  }
  i32 ans = 1;
  REP(i, n) {
    ans = (ans * 3) % M;
  }
  FOR(t, lim + 1, 90000) {
    ans = (ans - dp[t] * 3) % M;
  }
  if (sum % 2 == 0) {
    ans = (ans + dq[sum / 2] * 3) % M;
  }
  ans = (ans + M) % M;
  printf("%d\n", ans);
}


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

#define rep(i,l,r) for(int i=(l);i<(r);i++)
#define pb push_back
#define fi first
#define se second

using ll = long long;
using G = vector<vector<int>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const ll MOD = 1000000007;

ll GCD(ll x, ll y){
	return y ? GCD(y, x%y) : x;
}
ll LCM(ll x, ll y){
	return x/GCD(x, y)*y;
}

int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << min(a,b)+min(c,d) << endl;
	return 0;
}

#include <bits/stdc++.h>

#define rep(i,n) for(ll i=0;i<n;++i)
#define ALL(a) (a).begin(),(a).end()

using namespace std;
using ll  = long long;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;

const ll MOD  = 1e9 + 7;
const ll LINF = 1LL << 60;
const int INF = 1e9 + 7;

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

    rep(i, h){
        rep(j, w){
            if(j < a){
                if(i < h-b)cout << 1;
                else cout << 0;
            }
            else {
                if(i < h-b)cout << 0;
                else cout << 1;
            }
        }
        cout << endl;
    }
}


#include <iostream>
using namespace std;

int main(){
	double l1, l2, l3, l4, l5, l6, l7, l8, l9, l10;
	double v1, v2;
	char c;
	while(cin >> l1 >> c >> l2 >> c >> l3 >> c >> l4
		>> c >> l5 >> c >> l6 >> c >> l7 >> c >> l8
		>> c >> l9 >> c >> l10 >> c >> v1 >> c >> v2)
	{
		double l[] = {
			0,l1,l2,l3,l4,l5,
			l6,l7,l8,l9,l10
		};
		double max_length = l1 + l2 + l3 + l4 + l5
							+l6 + l7 + l8 + l9 + l10;
		for(int i = 1; i <= 10;i++){
			max_length -= (l[i] + (v2 * l[i] / v1));
			if(max_length <= 0){
				cout << i << endl;
				break;
			}
		}
	}
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll/*, vl, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef pair<pl, ll> ppl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rep2(i, k, n) for(ll i = ll(k); i <= ll(n); i++)
#define rep3(i, n, k) for(ll i = ll(n); i >= ll(k); i--)
#define all(v) (v).begin(), (v).end()
ll mod(ll a, ll b) {if(b == 0) return 0; return (a % b + b) % b;}
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 1e9;
const char newl = '\n';

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

  vector<queue<char> > s(3);
  string str;
  rep(i, 3) {
    cin >> str;
    rep(j, str.size()) s[i].push(str[j]);
  }

  ll now=0;
  while(1) {
    if(!s[now].size()) break;

    char c = s[now].front();
    s[now].pop();
    now = c - 'a';
  }
  cout << char('A' + now) << newl;
  return 0;
}


#include<stdio.h>
int main(){
	char tanggal[15];
	scanf("%s", &tanggal);
	tanggal[3] = '8';
	printf ("%s", tanggal);

	return 0;
}


#include<iostream>
using namespace std;
int main(){
  int n,m,most1,most2,d[11000]={0};
  while(1){
    cin >> n;
    if(n==0){
      break;
    }

    most1=0;most2=0;
    for(int i=0;i<10100;i++){
      d[i]=0;
    }

    for(int i=2;i*i<=n;i++){
      if(d[i]==0){
	for(int j=i+i;j<=n;j+=i){
	  d[j]=1;
	}
      }
    }

    for(int i=n;i>=0;i--){
      if(d[i]==0 && d[i-2]==0){
	most1=i-2;
	most2=i;
	break;
      }
    }

    cout << most1 << " " << most2 << endl;
  }
}

#include <cstdio>
#include <cmath>
#define buf 10000
using namespace std;
int k=0;
int B[buf];
void Answer(int n);
int PrimeNumber(int n);

int main(void){
  int i,n;
  char str[buf];

  for(i=2;i<buf;i++)
    PrimeNumber(i);
  for( ;fgets(str,sizeof(str),stdin)!=NULL; ){
    sscanf(str,"%d",&n);
    if(n==0) break;
    Answer(n);
  }
  return 0;
}

void Answer(int n){
  int i,j;
  for(i=0;i<k;i++){
    if(B[i]>n)
        break;
  }
  for(j=i-1;j>=0;j--){
    if(B[j]-B[j-1]==2){
      printf("%d %d\n",B[j-1],B[j]);
      break;
    }
  }
}

int PrimeNumber(int n){
  int i,c;
  if(n==2){
    B[k]=n;
    k++; return 0;
  }
  if(n<2 || n%2==0)
    return 0;
  c=sqrt(n);
  for(i=3;i<=c;i+=2){
    if(n%i==0)
      return 0;
  }
  B[k]=n;
  k++; return 0;
}


#ifdef _WIN32
#include "XOR.h"
#endif

#include <stdio.h>

#include <iostream>
#include <vector>
#include <array>

constexpr int64_t MOD = 1'000'000'007;
constexpr int64_t help = 1;

#define ll long long int

#define o(X) ll bits##X = 0
//#define ok(X) bits##X += !!(d & (help << X))
#define ok(X) bits##X += d & 1; d >>= 1;

#define oke(X) ans += (bits##X * (n - bits##X) % MOD) *((help << X) % MOD); ans %= MOD;
//ll p = (help << b) % MOD;
//ans += (bits[b] * (n - bits[b]) % MOD) * p;
//ans %= MOD;

void fastscan(ll& number) {
	//variable to indicate sign of input number
	int c;

	number = 0;

	// extract current character from buffer
	c = getchar();

	// Keep on extracting characters if they are integers
	// i.e ASCII Value lies from '0'(48) to '9' (57)
	for (; (c > 47 && c < 58); c = getchar())
		number = number * 10 + c - 48;

	// if scanned input has a negative sign, negate the
	// value of the input number
}
#ifdef _WIN32
namespace XOR
{
#endif

	int main() {
		ll n;

		fastscan(n);

		o(0);
		o(1);
		o(2);
		o(3);
		o(4);
		o(5);
		o(6);
		o(7);
		o(8);
		o(9);
		o(10);
		o(11);
		o(12);
		o(13);
		o(14);
		o(15);
		o(16);
		o(17);
		o(18);
		o(19);
		o(20);
		o(21);
		o(22);
		o(23);
		o(24);
		o(25);
		o(26);
		o(27);
		o(28);
		o(29);
		o(30);
		o(31);
		o(32);
		o(33);
		o(34);
		o(35);
		o(36);
		o(37);
		o(38);
		o(39);
		o(40);
		o(41);
		o(42);
		o(43);
		o(44);
		o(45);
		o(46);
		o(47);
		o(48);
		o(49);
		o(50);
		o(51);
		o(52);
		o(53);
		o(54);
		o(55);
		o(56);
		o(57);
		o(58);
		o(59);
		o(60);
		o(61);
		o(62);

		std::array<ll, 62> bits{};
		for (ll i = 0; i < n; i++) {
			ll d;
			fastscan(d);
			ok(0);
			ok(1);
			ok(2);
			ok(3);
			ok(4);
			ok(5);
			ok(6);
			ok(7);
			ok(8);
			ok(9);
			ok(10);
			ok(11);
			ok(12);
			ok(13);
			ok(14);
			ok(15);
			ok(16);
			ok(17);
			ok(18);
			ok(19);
			ok(20);
			ok(21);
			ok(22);
			ok(23);
			ok(24);
			ok(25);
			ok(26);
			ok(27);
			ok(28);
			ok(29);
			ok(30);
			ok(31);
			ok(32);
			ok(33);
			ok(34);
			ok(35);
			ok(36);
			ok(37);
			ok(38);
			ok(39);
			ok(40);
			ok(41);
			ok(42);
			ok(43);
			ok(44);
			ok(45);
			ok(46);
			ok(47);
			ok(48);
			ok(49);
			ok(50);
			ok(51);
			ok(52);
			ok(53);
			ok(54);
			ok(55);
			ok(56);
			ok(57);
			ok(58);
			ok(59);
			ok(60);
			ok(61);
			ok(62);
		}

		ll ans = 0;

		oke(0);
		oke(1);
		oke(2);
		oke(3);
		oke(4);
		oke(5);
		oke(6);
		oke(7);
		oke(8);
		oke(9);
		oke(10);
		oke(11);
		oke(12);
		oke(13);
		oke(14);
		oke(15);
		oke(16);
		oke(17);
		oke(18);
		oke(19);
		oke(20);
		oke(21);
		oke(22);
		oke(23);
		oke(24);
		oke(25);
		oke(26);
		oke(27);
		oke(28);
		oke(29);
		oke(30);
		oke(31);
		oke(32);
		oke(33);
		oke(34);
		oke(35);
		oke(36);
		oke(37);
		oke(38);
		oke(39);
		oke(40);
		oke(41);
		oke(42);
		oke(43);
		oke(44);
		oke(45);
		oke(46);
		oke(47);
		oke(48);
		oke(49);
		oke(50);
		oke(51);
		oke(52);
		oke(53);
		oke(54);
		oke(55);
		oke(56);
		oke(57);
		oke(58);
		oke(59);
		oke(60);
		oke(61);
		oke(62);
		//for (ll b = 0; b < 62; b++) {
		//	ll p = (help << b) % MOD;
		//	ans += (bits[b] * (n - bits[b]) % MOD) * p;
		//	ans %= MOD;
		//}

		std::cout << ans;
		return 0;
	}
#ifdef _WIN32
}
#endif

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

long long dataset[300005]={0};

int main()
{
    int number;
    cin>>number;

    for(int i=0;i<number;i++)
        cin>>dataset[i];

    ll result=0;
    for(ll i=0;i<62;i++)
    {
        long long zeros=0,ones=0;

        for(ll j=0;j<number;j++)
        {
            if(dataset[j]%2ll==1)
                ones++;
            else
                zeros++;
            dataset[j]/=2ll;
        }
        result+=((ones*zeros)%MOD*((1ll<<i)%MOD))%MOD;
      result%=MOD;

    }
    cout<<result<<endl;
}


#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

///////////////////////////

int main() {
	ll A, B, C;
	cin >> A >> B >> C;
	if ((C - A)*(C - B) > 0) { cout << "No"; }
	else { cout << "Yes"; }

	system("PAUSE");
}


#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main(){
    ll a,b;cin >> a >>b;
    cout << 100 <<" " <<100 <<endl;
    vector<vector<char>> g(100,vector<char>(100,'.'));
    rep(i,50){
        rep(j,100){
            g[i][j]='#';
        }
    }
    a--;b--;
    ll i=0,j=0;
    while(a!=0){
        if(j%2==0){g[i][j]='.';a--;}
        j++;if(j==100){j=0;i+=2;}
    }
    i=99;j=99;
    while(b!=0){
        if(j%2==0){g[i][j]='#';b--;}
        j--;if(j==-1){j=99;i-=2;}
    }
    rep(i,100){
        rep(j,100){
            cout << g[i][j];
        }
        cout <<endl;
    }
}

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>

using namespace std;

inline int read()
{
    int x=0;char ch=getchar();
    while(ch<'0' || '9'<ch)ch=getchar();
    while('0'<=ch && ch<='9')x=x*10+(ch^48),ch=getchar();
    return x;
}

const int M=1e5+9;

int m;
int a[M],b[M],top;

int main()
{
    int n=read(),m=read();
    int odd1=-1,odd2=-1;
    for(int i=1;i<=m;i++)
    {
        a[i]=read();
        if(a[i]&1)
        {
            if(odd1==-1)
                odd1=i;
            else if(odd2==-1)
                odd2=i;
            else
            {
                puts("Impossible");
                return 0;
            }
        }
    }

    if(m==1)
    {
        if(a[1]==1)
            printf("1\n1\n1\n");
        else
            printf("%d\n2\n1 %d\n",a[1],a[1]-1);
        return 0;
    }

    if(odd1!=-1)
        swap(a[1],a[odd1]);
    if(odd2!=-1)
        swap(a[m],a[odd2]);

    for(int i=1;i<=m;i++)
        printf("%d%c",a[i]," \n"[i==m]);

    if(a[m]==1)
    {
        printf("%d\n",m-1);
        printf("%d ",a[1]+1);
        for(int i=2;i<m;++i)
            printf("%d ",a[i]);
        puts("");
        return 0;
    }

    b[1]=a[1]+1;
    for(int i=2;i<m;i++)
        b[i]=a[i];
    b[m]=a[m]-1;

    printf("%d\n",m);
    for(int i=1;i<=m;i++)
        printf("%d%c",b[i]," \n"[i==m]);

    return 0;
}


#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

bool isPrime[100010];
void set_prime() {
	for (int i = 1; i <= 100000; i++) {
		isPrime[i] = true;
	}
	isPrime[0] = false; isPrime[1] = false;
	for (int i = 2; i * i <= 100000; i++) {
		int j = 2;
		while (i * j <= 100000) {
			isPrime[i * j] = false;
			j++;
		}
	}
}

int main()
{
	int N;
	cin >> N;
	set_prime();
	int j = 2;
	for (int i = 0; i < N; i++) {
		while (true) {
			if (isPrime[j] && j % 5 == 1) {
				cout << j++ << " ";
				break;
			}
			j++;
		}
	}
	cout << endl;
}


#include<bits/stdc++.h>
#define rep(i,f,n) for(ll i=(f); (i) < (n); i++)
#define repe(i,f,n) for(ll i=(f); (i) <= (n); i++)
using namespace std;
using ll = long long;
#define MOD (ll)1000000007
#define PI 3.14159265359
#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";
#define P pair<int, int>
#define dvec vector<vector<ll>>
//printf("%.10f\n")
//cout << fixed << setprecision(10);
template<class T> inline bool chmax(T& a, T b){if (a < b) { a = b; return true; } return false;}
template<class T> inline bool chmin(T& a, T b){if (a > b) { a = b; return true; } return false;}
ll INF = 1e+18;
int iINF = 1e9;

int main()
{
  int H, W; cin >> H >> W;
  vector<vector<pair<int, int>>> grid(H, vector<pair<int, int>>(W, {0, 0}));
  rep(i, 0, H) rep(k, 0, W) cin >> grid[i][k].first;
  rep(i, 0, H) rep(k, 0, W) cin >> grid[i][k].second;
  vector<vector<vector<bool>>> dp(H + 1, vector<vector<bool>>(W + 1, vector<bool>(13000, false)));
  dp[0][1][0] = true;

  repe(i, 1, H){
    repe(k, 1, W){
      rep(l, 0, 13000){
        int pre = abs(grid[i - 1][k - 1].first - grid[i - 1][k - 1].second);
        if(dp[i - 1][k][l]){
          dp[i][k][l + pre] = true;
          if(l - pre >= 0) dp[i][k][l - pre] = true;
          if(pre - l >= 0) dp[i][k][pre - l] = true;
        }
        if(k == 1) continue;
        if(dp[i][k - 1][l]){
          dp[i][k][l + pre] = true;
          if(l - pre >= 0) dp[i][k][l - pre] = true;
          if(pre - l >= 0) dp[i][k][pre - l] = true;
        }
      }
    }
  }

  int ans = iINF;
  rep(i, 0, 13000){
    if(dp[H][W][i]){
      ans = i;
      break;
    }
  }
  cout << ans << endl;

}

#include<iostream>
#include<set>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>

using namespace std;
int a, b;
int num[15];

int bind(int p,int q){
	if(q<10){
		return 10*p+q;
	}
	else return 100*p+q;
}

int main(void){
	while(1){
		cin >> a >> b;
		if(a == 0 && b == 0){
			return 0;
		}
		set <int> S;
		for(int i=0;i<a;i++){
			cin >> num[i];
		}
		for(int i=0;i<a;i++){
			for(int j=0;j<a;j++){
				for(int k=0;k<a;k++){
					for(int l=0;l<a;l++){

						if(b==4){
							if(i != j && i != k && i != l && j != k && j != l && k != l){
							int c = bind(bind(bind(num[i],num[j]),num[k]),num[l]);
							S.insert(c);
							}
						}
						if(b==3){
							if(j != k && j != l && k != l){
							int c = bind(bind(num[j],num[k]),num[l]);
							S.insert(c);
							}
						}
						if(b==2){
							if(k != l){
							int c = bind(num[k],num[l]);
							S.insert(c);
							}
						}
					}
				}
			}
		}
		cout << S.size() <<endl;
		S.clear();
	}
}


#include<stdio.h>
int main() {

	char character1[100];
	char character2[100];

	scanf("%s", character1);
	scanf("%s", character2);
	printf("%s%s", character2, character1);

	return 0;
}

/*
      author : nishi5451
      created: 11.08.2020 22:36:41
*/

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

int main(){
    string s,t;
    cin >> s >> t;
    string ans = t+s;
    cout << ans << endl;
    return 0;
}


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

int main() {
  int N;
  int min;
  int ans = 1;
  cin >> N >> min;

  for(int i=0;i<N-1;++i){
    int s; cin >> s;
    if(s < min){
      ans += 1;
      min = s;
    }
  }
  cout << ans << endl;
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;

int main() {
    int n;
    cin >> n;
    int *p = new int[n];
    for (int i = 0; i < n; i++) {
        cin >> p[i];
    }
    int cnt = 0;
    int min = INT_MAX;
    for (int i = 0; i < n; i++) {
        if (p[i] <= min) {
            min = p[i];
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}


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

int main() {
    long long N;
    cin >> N;
    string res = "";
    while (N) {
        --N;
        res += (char)('a' + (N % 26));
        N /= 26;
    }
    reverse(res.begin(), res.end());
    cout << res << endl;
}

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

int main() {
  string s;
  cin >> s;
  bool flg = false;
  for(int i = 0; i < s.size(); i++){
    if(flg){
      if(s[i] == 'C'){
        cout << "Yes" << endl;
        return 0;
      }else{
        flg =false;
      }
    }else{
      if(s[i] == 'A') flg = true;
    }
  }
  cout << "No" << endl;
  return 0;
}


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

int main() {
  string n;

  while (cin >> n) {

    n += ".";

    int num[] = {1, 5, 10, 50, 100, 500, 1000};
    char ch[] = {'I', 'V', 'X', 'L', 'C', 'D', 'M'};

    int cnt = 0;
    vector<int> a;
    for (int i = 0; i < n.size(); ++i) {
      int x = 0;
      for (int j = 0; j < 7; ++j) {
        if (n[i] == ch[j]) x = num[j];
      }
      cnt += x;
      if (n[i] == n[i + 1]) continue;
      a.push_back(cnt);
      cnt = 0;
    }

    int ans = 0;
    for (int i = 0; i < a.size(); ++i) {
      if (a[i] < a[i + 1]) a[i + 1] -= a[i];
      else ans += a[i];
    }

    cout << ans << endl;
  }
}

#include <iostream>
#include <string>

int main()
{
    unsigned int a = 0, max_num = 11, min_num = 0;

    std::cin >> a;
    if ((min_num < a) && (a < max_num)) {
        a = a + (a * a) + (a * a * a);
        std::cout << a;
    }
    else
    {
        std::cout << "Err a = " << a;
    }

}


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

long long n;
vector<long long> a;

long long solve();

int main() {
  cin >> n;
  a.resize(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  cout << solve() << endl;
  return 0;
}

long long solve() {
  long long res = 0;
  for (int i = 1; i < n; ++i)
    if (a[i] > a[i - 1] + 1) return -1;
  if (a[0] != 0) return -1;
  for (int i = 1; i < n; ++i)
    if (a[i] - 1 == a[i - 1])
      ++res;
    else
      res += a[i];
  return res;
}

//Author:xht37
#include <bits/stdc++.h>

#define ui unsigned int
#define ll long long
#define ul unsigned ll
#define ld long double

#define pi pair <int, int>
#define fi first
#define se second
#define mp make_pair

#define ls (p << 1)
#define rs (ls | 1)
#define md ((t[p].l + t[p].r) >> 1)

#define vi vector <int>
#define pb push_back
#define pq priority_queue

#define dbg(x) cerr << #x" = " << x << endl
#define debug(...) fprintf(stderr, __VA_ARGS__)

#define fl(x) freopen(x".in", "r", stdin), freopen(x".out", "w", stdout)

using namespace std;

namespace io {
	const int SI = 1 << 21 | 1;
	char IB[SI], *IS, *IT, OB[SI], *OS = OB, *OT = OS + SI - 1, c, ch[100];
	int f, t;
	#define gc() (IS == IT ? (IT = (IS = IB) + fread(IB, 1, SI, stdin), IS == IT ? EOF : *IS++) : *IS++)
	inline void flush() {
		fwrite(OB, 1, OS - OB, stdout), OS = OB;
	}
	inline void pc(char x) {
		*OS++ = x;
		if (OS == OT) flush();
	}

	template <class I>
	inline void rd(I &x) {
		for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;
		for (x = 0; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + (c & 15), c = gc());
		x *= f;
	}
	template <class I>
	inline void rd(I &x, I &y) {
		rd(x), rd(y);
	}
	template <class I>
	inline void rd(I &x, I &y, I &z) {
		rd(x), rd(y), rd(z);
	}
	template <class I>
	inline void rda(I *a, int n) {
		for (int i = 1; i <= n; i++) rd(a[i]);
	}
	inline void rdc(char &c) {
		for (c = gc(); c < 33 || c > 126; c = gc());
	}
	inline void rds(char *s, int &n) {
		for (c = gc(); c < 33 || c > 126; c = gc());
		for (n = 0; c >= 33 && c <= 126; s[++n] = c, c = gc());
		s[n+1] = '\0';
	}
	inline void rds(string &s) {
		for (c = gc(); c < 33 || c > 126; c = gc());
		for (s.clear(); c >= 33 && c <= 126; s.pb(c), c = gc());
	}

	template <class I>
	inline void print(I x, char k = '\n') {
		if (!x) pc('0');
		if (x < 0) pc('-'), x = -x;
		while (x) ch[++t] = x % 10 + '0', x /= 10;
		while (t) pc(ch[t--]);
		pc(k);
	}
	template <class I>
	inline void print(I x, I y) {
		print(x, ' '), print(y);
	}
	template <class I>
	inline void print(I x, I y, I z) {
		print(x, ' '), print(y, ' '), print(z);
	}
	template <class I>
	inline void printa(I *a, int n) {
		for (int i = 1; i <= n; i++) print(a[i], " \n"[i==n]);
	}
	inline void printc(char c) {
		pc(c);
	}
	inline void prints(char *s, int n) {
		for (int i = 1; i <= n; i++) pc(s[i]);
		pc('\n');
	}
	inline void prints(string s) {
		int n = s.length();
		while (t < n) pc(s[t++]);
		pc('\n'), t = 0;
	}
	struct Flush {
		~Flush() {
			flush();
		}
	} flusher;
}
using io::rd;
using io::rda;
using io::rdc;
using io::rds;
using io::print;
using io::printa;
using io::printc;
using io::prints;

const int N = 2e5 + 7;
int n, a[N];
ll ans;

int main() {
	rd(n), rda(a, n);
	for (int i = 1; i <= n; i++)
		if (a[i] >= i || a[i] - a[i-1] > 1) return print(-1), 0;
	for (int i = 1; i <= n; i++)
		if (i == n || a[i] != a[i+1] - 1) ans += a[i];
	print(ans);
	return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

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

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main(){
    string s;cin>>s;
    ll n=s.size();
    map<char,ll>a;
    rep(i,s.size()){
        a[s[i]]++;
    }
    sort(all(s));
    s.erase(unique(all(s)),s.end());
    ll ans=n*(n-1)/2+1;
    rep(i,s.size()){
        ans-=a[s[i]]*(a[s[i]]-1)/2;
    }
    cout<<ans<<endl;
}

#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define reps(i,n) for (int i=1;i<=(n);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rreps(i,n) for (int i=(n);i>0;i--)
#define all(v) (v).begin(),(v).end()
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>
template<class T> inline bool chmin(T &a, T b) {if (a>b) {a = b; return 1;} return 0;};
template<class T> inline bool chmax(T &a, T b) {if (a<b) {a = b; return 1;} return 0;};
typedef long long int ll;
const long long INF = 1LL << 60;

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

  vector<string> rec(N);
  int iter = 0;
  int ok = 0, ng = N, mid = 0;
  while (iter<=20){
    cout << mid << endl;
    string s; cin >> s;
    cout.flush();
    if (s=="Vacant") break;
    iter++;
    rec[mid] = s;

    if ((mid-ok)%2 == (rec[ok]!=rec[mid])) ok = mid;
    else ng = mid;

    mid = (ok+ng)/2;
  }

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

  return 0;
}


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

int main() {
    int K, T; cin >> K >> T;
    vector<int> A(T);
    rep(i, T) cin >> A.at(i);
    sort(A.begin(), A.end(), greater<int>());
    if (A[0] < K - A[0]) {
        cout << 0 << endl;
    } else {
        cout << A[0] - (K - A[0]) - 1 << endl;
    }
}

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

int main(){
    int K, T;
    cin >> K >> T;
    vector<int> A(T+1);
    rep(i, T) cin >> A[i];
    vector<int> ans;
    int cnt = 0;
    int pre_idx = -1;
    int now_idx = T;
    rep(i, K){
        rep(j, T){
            if(pre_idx == j) continue;
            if(A[now_idx] < A[j]) now_idx = j;
        }
        if(now_idx == T){
            now_idx = pre_idx;
            cnt += 1;
        }
        A[now_idx] -= 1;
        ans.push_back(now_idx);
        pre_idx = now_idx;
        now_idx = T;

    }
    cout << cnt << endl;
    return 0;
}


//こんなプログラムを組んではいけない(戒め
//マージの仕様が複雑だし、空白マスを引く処理忘れやすいし、ひどいコードだ。
#include<iostream>
#include<queue>
using namespace std;

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

char data[h][w+2];

//データ構造をマージする一般的なテクなし。
class UnionFind {
public:
	int oya[2521], size;
	void ini(int size) { this->size = size; for( int i = 0;i < size; i++ ) oya[i] = i; }
	int root(int x) { if( oya[x] == x ) return x; return (oya[x] = root(oya[x]) ); }
	void marge(int x, int y) { x = root(x); y = root(y); if ( x != y ) { size--; oya[x] = y; } }
}uf;

void bfs(int sy, int sx) {
	queue<int> que;
	que.push(sy*w + sx);

	while( !que.empty() ) {
		int now = que.front();
		que.pop();

		if ( data[now/w][now%w] == '0' )
			continue;
		if ( uf.root(now) != now ) 	//すでに調べている(マージされている)ならcontinue
			continue;

		uf.marge(now, sy*w + sx);	//nowをsy*w + sxにくっつける(逆にしたら無限ループするかも)

		for(int i = 0; i < 4; i++ ) {
			int ny = now/w + dy[i];
			int nx = now%w + dx[i];
			if ( 0 <= ny && ny < h && 0 <= nx && nx < w )
				que.push(ny * w + nx);
		}
	}
}

int main() {
	int i, j;
	while( cin >> data[0] ) {
		for( i = 1; i < h; i++ )
			cin >> data[i];

		uf.ini(h*w);

		int minus = 0;
		for( i = 0; i < h; i++ ) {
			for( j = 0; j < w; j++ ) {
				minus += (data[i][j] == '0');
				bfs(i, j);
			}
		}
		cout << uf.size - minus << endl;
	}
	return 0;
}

#include<cstdio>
#include<iostream>
using namespace std;
char masu[50][50] = {{0}};
void saiki(int x,int y){
    masu[y][x] = '0';

    if(masu[y+1][x] == '1') saiki(x,y+1);
    if(masu[y-1][x] == '1') saiki(x,y-1);
    if(masu[y][x+1] == '1') saiki(x+1,y);
    if(masu[y][x-1] == '1') saiki(x-1,y);
}
int main(){
    while(1){
        int cnt = 0;
        for(int i = 0; i < 12; i++){
            if(scanf("%s",masu[i]) == EOF)goto a;
        }
        for(int i = 0; i < 12; i++){
            for(int j = 0; j < 12; j++){
                if(masu[i][j] == '1'){
                    saiki(j,i);
                    cnt++;
                }
            }
        }
        cout << cnt << endl;
    }
    a:;
    return 0;
}


#pragma region RegionDefs
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define reps(i,l,r) for(int i=(l),i##_len=(r);i<i##_len;++i)
#define all(x) begin(x),end(x)
using namespace std;
typedef long long ll;
const ll INF = 1e9;
template<class T=ll> using V = vector<T>;
template<class T=ll> using PQ = priority_queue<T>;
template<class T=ll> using PQG = priority_queue<T, V<T>, greater<T>>;
const ll MOD = 1000000007LL;
void in() {}
template<class Head, class... Tail>
void in(Head&& head, Tail&&... tail)
{
    cin >> head;
    in(move(tail)...);
}
#define IN(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define INS(T, ...) T __VA_ARGS__; in(__VA_ARGS__)
#define VIN(T, v, n) V<T> v(n); for(auto& _elem:v)cin>>_elem
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 y0 y__0
#define y1 y__1
#define j0 j__0
#define j1 j__1
#define YN(e) cout << ((e) ? "YES" : "NO") << endl
#define yn(e) cout << ((e) ? "Yes" : "No") << endl
#pragma endregion RegionDefs

void solve()
{
    IN(n, k);
    cout << n - k + 1 << endl;
}

int main()
{
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(numeric_limits<double>::max_digits10);

    solve();

    return 0;
}

#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<unordered_map>
#include<array>
#include<map>
#include<bitset>
#include<iomanip>
#include<list>
#include <numeric>
using namespace std;
typedef unsigned long long int ulint;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define RE return 0
//ios::sync_with_stdio(false);
//std::cin.tie(0);
//<< setprecision(20)
const int mod=(int)1000000007;
const llint big=(llint)(2.19e15)+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double ena=2.71828182845904523536;
const long double eps=1e-7;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
template <class T> void soun(T& ar)
{sort(ar.begin(),ar.end());ar.erase(unique(ar.begin(),ar.end()),ar.end());}
llint gcd(llint a,llint b){if(a%b==0){return b;}else{return gcd(b,a%b);}}
llint lcm(llint a,llint b){return a/gcd(a,b) *b;}
template<class T,class U> auto LB(T& ve,U in){return lower_bound(ve.begin(),ve.end(),in);}
template<class T,class U> auto UB(T& ve,U in){return upper_bound(ve.begin(),ve.end(),in);}
template<class T,class U> auto LBI(T& ve,U in){return LB(ve,in)-ve.begin();}
template<class T,class U> auto UBI(T& ve,U in){return UB(ve,in)-ve.begin();}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
using pli=pair<llint,int>;
using daic=priority_queue<pli,vector<pli>,greater<pli>>;
class seg_tree{public:
	//セグ木
	vector<llint>val;
	seg_tree(void){val.res(524288);}
	//両側からアクセスするので、bitテクが使える
	//    1
	// 2     3
	//4  5  6  7

	//偶数ナンバーは、(短縮時間+x) を記録
	//奇数ナンバーは、(短縮時間-x) を記録
	llint que(llint bas,llint mae){
		llint time=-abs(bas-mae);//短縮
		int bi=bas-1+262144;
		while(bi>1){
			if(bi%2==0){maxeq(time,val[bi+1]+bas);}
			bi/=2;
		}
		bi=bas+1+262144;
		while(bi>1){
			if(bi%2==1){maxeq(time,val[bi-1]-bas);}
			bi/=2;
		}
		time+=abs(bas-mae);
		bi=mae+262144;
		while(bi>1){
			if(bi%2==0){maxeq(val[bi],time+mae);}
			if(bi%2==1){maxeq(val[bi],time-mae);}
			bi/=2;
		}
		return time;
	}
};
int main(void){
	seg_tree ki;
	int n,q;cin>>n>>q;
	int A;cin>>A;
	int mae;cin>>mae;
	int bi=A+262144;
	while(bi>1){
		if(bi%2==0){maxeq(ki.val[bi],big+A);}
		if(bi%2==1){maxeq(ki.val[bi],big-A);}
		bi/=2;
	}
	llint ans=0,wa=big;
	while(q--){
		llint x;cin>>x;
		maxeq(ans,ki.que(x,mae));
		wa+=abs(mae-x);
		mae=x;

	}
	cout<<wa-ans<<endl;RE;
}


//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,x;
    cin >> n >> x;
    vll a(n);
    REP(i,n) cin >> a[i];
    ll ans = 0;
    REP(i,n-1){
        ll sum = a[i] + a[i+1];
        ll t = min(a[i+1], max(0LL, sum-x));
        ans += t;
        a[i+1] -= t;
        sum -= t;
        t = min(a[i], max(0LL,sum-x));
        ans += t;
    }
    cout << ans << endl;
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main(){

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

  long long int ans=0;
  long long int a;
  cin>>a;
  for(int i=0; i<n-1; i++){
    long long int b;
    long long int eat=0;
    cin>>b;

    eat=max(a+b-x, eat);
    ans+=eat;

    if(b<=eat) b=0;
    else b=b-eat;
    a=b;
  }

  cout<<ans<<endl;
}


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

int main(){
    int m, n;
    vector<int> a(4);
    for(int i = 0; i < 4; i++){
        cin >> a[i];
    }
    cin >> m >> n;
    sort(a.rbegin(), a.rend());
    int ans = a[0] + a[1] + a[2] + max(m,n);
    cout << ans << endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=1<<18,INF=1<<29;

int main(){
  int a,b,c,d,e,f;cin>>a>>b>>c>>d>>e>>f;
  cout<<a+b+c+d+e+f-min({a,b,c,d})-min(e,f)<<endl;
}


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

int N,M;
int G[15][15];

int dp[15][(1<<15)];
int INF=2e9;

int calc(int bit,int nbit){
  int sum=0;
  for(int i=0;i<N;i++)
    if(nbit>>i&1)
      for(int j=0;j<N;j++)
        if(~bit>>j&1)
          if(~nbit>>j&1)
            sum+=G[i][j];
  return sum;
}

int rec(int pos,int bit){
  static unordered_map< int , int > mem[15];
  if( mem[pos].count(bit) )return mem[pos][bit];

  if(pos==N-1)return 0;
  int res=INF;

  int sup=(1<<(N-1))-1-bit;

  int nbit=sup;
  while(1){

    if(nbit>>pos&1){
      int cost=calc(bit,nbit);
      for(int to=0;to<N;to++){
        if(bit>>to&1)continue;
        if(nbit>>to&1)continue;
        if(G[pos][to]==0)continue;
        res=min(res, rec(to,bit|nbit) + cost - G[pos][to]);
      }
    }
    nbit--;
    nbit&=sup;
    if(nbit==0)break;
  }
  return mem[pos][bit]=res;
}

int main(){
  cin>>N>>M;
  for(int i=0;i<M;i++){
    int a,b,c;
    cin>>a>>b>>c;
    a--,b--;
    G[a][b]=G[b][a]=c;
  }
  cout<< rec(0,0) <<endl;
  return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
template<typename T>inline bool chkmin(T &x,T y){return (y<x)?(x=y,1):0;}
template<typename T>inline bool chkmax(T &x,T y){return (y>x)?(x=y,1):0;}
inline int read(){
	int x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
	return x*f;
}
inline ll readll(){
	ll x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
	return x*f;
}
const int inf=0x3f3f3f3f;
int val[15][15],sum[1<<15],dp[15][1<<15],f[15];
int main(){
	int n=read(),m=read();
	while(m--){
		int x=read()-1,y=read()-1,z=read();
		val[x][y]=z,val[y][x]=z;
		sum[(1<<x)|(1<<y)]=z;
	}
	REP(i,0,n-1) REP(j,0,(1<<n)-1) if((1<<i)&j) sum[j]+=sum[j^(1<<i)];
	REP(i,0,n-1) REP(j,0,(1<<n)-1) dp[i][j]=-inf;
	REP(j,1,(1<<n)-1) if(j&1) dp[0][j]=sum[j];
	REP(i,1,(1<<n)-1){
		REP(j,0,n-1) f[j]=-inf;
		REP(j,0,n-1) if(i&(1<<j)) REP(k,0,n-1) if(val[j][k] && (i&(1<<k))==0) chkmax(f[k],dp[j][i]+val[j][k]);
		REP(j,0,n-1) if((i&(1<<j))==0)
			for(int cur=i|(1<<j),k=cur;k<=iend;k=(k+1)|cur)
				chkmax(dp[j][k],f[j]+sum[k^i]);
	}
	printf("%d\n",sum[(1<<n)-1]-dp[n-1][(1<<n)-1]);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MOD 1000000007

void solve()
{
	double r,g;
	cin>>r>>g;
	cout<<(g*2)-r;
    return;
}

int main()
{
        fast;
        ll q;
        q=1;
        // cin>>q;
        while(q--)
        	solve();

        return 0;
}

#include <bits/stdc++.h>

using namespace std;

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

#define int ll

const ll mod = 1e9 + 7;

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

	cout << (n-2)*180 << endl;

	return 0;
}


#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

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

  if(R < 1200){
    cout << "ABC" << endl;
  } else if(R < 2800){
    cout << "ARC" << endl;
  } else{
    cout << "AGC" << endl;
  }

  return 0;
}

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

// http://www.prefield.com/algorithm/misc/dice.html
enum FACE { TOP, BOTTOM, FRONT, BACK, LEFT, RIGHT };
class dice {
public:
  dice() {
    id[TOP] = 1; id[FRONT] = 2; id[LEFT] = 3;
    id[RIGHT] = 4; id[BACK] = 5; id[BOTTOM] = 6;
  }
  dice(int top,int front,int right,int left,int back,int bottom) {
    id[TOP] = top; id[FRONT] = front; id[LEFT] = right;
    id[RIGHT] = left; id[BACK] = back; id[BOTTOM] = bottom;
  }
  int& operator[] (FACE f) { return id[f]; }
  const int& operator[] (FACE f) const { return id[f]; }
  bool operator==(const dice &b) const {
    const dice &a = *this;
    return a[TOP] == b[TOP] && a[BOTTOM] == b[BOTTOM] &&
           a[FRONT] == b[FRONT] && a[BACK] == b[BACK] &&
           a[LEFT] == b[LEFT] && a[RIGHT] == b[RIGHT];
  }
  void roll_x() { roll(TOP, BACK, BOTTOM, FRONT); }
  void roll_x2() { roll(TOP, FRONT, BOTTOM, BACK); }
  void roll_y() { roll(TOP, LEFT, BOTTOM, RIGHT); }
  void roll_y2() { roll(TOP, RIGHT, BOTTOM, LEFT); }
  void roll_z() { roll(FRONT, RIGHT, BACK, LEFT); }
  void roll_z2() { roll(FRONT, LEFT, BACK, RIGHT); }
  bool equivalent_to(const dice& di) {
    for (int k = 0; k < 6; (k&1?roll_y():roll_x()),++k)
      for (int i = 0; i < 4; roll_z(), ++i)
        if (*this == di) return true;
    return false;
  }
private:
  void roll(FACE a, FACE b, FACE c, FACE d) {
    int tmp = id[a];
    id[a] = id[b]; id[b] = id[c];
    id[c] = id[d]; id[d] = tmp;
  }
  int id[6];
};

int main(){
	int n,d[6];
	cin>>n;
	vector<dice>v(n);
	for(int j=0;j<n;j++){
		for(int i=0;i<6;i++)cin>>d[i];
		v[j]=dice(d[0],d[1],d[2],d[3],d[4],d[5]);
	}
	for(int j=0;j<n-1;j++)for(int i=j+1;i<n;i++)if(v[j].equivalent_to(v[i])){
		cout<<"No"<<endl;
		return 0;
	}
	cout<<"Yes"<<endl;
}


#include <iostream>
#include <stdio.h>
#include <iomanip>
#include <string>

using namespace std;

int main(void){
    int n;
    scanf("%d",&n);
    int* a = new int[n];
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    cout << a[n - 1];
    for (int i = 1; i < n; i++) {
        cout << " " << a[n - i - 1];
    }
    cout << endl;
    delete[] a;
    return 0;
}

#include<iostream>

const static int MIN = -1000000;
const static int MAX = 1000000;

int main(void){
    int k, x;
    std::cin >> k >> x;
    int cmax = std::min(MAX, x + k - 1);
    int cmin = std::max(MIN, x - k + 1);
    for(int i = cmin; i <= cmax; i++){
        std::cout << i << " ";
    }
    std::cout << std::endl;
    return 0;
}


#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
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;
}
void hr() {
   cerr << "--------------" << endl;
}
const int INF = 1001001001;
const int MOD = 1000000007;

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

   int n;
   cin >> n;
   vector<ll> a(n);
   rep(i, 0, n) cin >> a[i];

   ll ans = 0;
   rep(i, 0, 60) {
      ll x = 0;
      rep(j, 0, n) {
         if (a[j] >> i & 1) x++;
      }
      ll now = x * (n - x) % MOD;
      rep(j, 0, i)(now *= 2) %= MOD;
      (ans += now) %= MOD;
   }
   cout << ans << endl;
   return 0;
}

#include <bits/stdc++.h>

using namespace std;

#define fastio cin.tie(NULL); cout.tie(NULL); ios_base::sync_with_stdio(0)
typedef long long ll;
#define int ll
#define swap(x, y)((x)^=(y)^=(x)^=(y))
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> matrix;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(c) c.begin(),c.end()
#define mp make_pair
#define pb push_back
#define f first
#define tcase int _; cin>> _; for( ; _; --_)
#define s second
#define endl '\n'
const int MAX = 1e6+1;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1);
const double DEG = 180/PI;
const int MOD = 1e9+7;
int mod(int x, int m){ if(x >= 0) return x % m; if(-x < m) return m-(-x); return mod(x%m, m);}
int gcd (int a, int b) {while(b){a = mod(a, b); swap(a, b);} return a;}
int lcm (int a, int b) {return a / gcd(a, b) * b;}
int fexp(int base, int exp, int m){
	int total = 1;
	while(exp > 0){
		if(exp % 2 == 1){
			total = mod(((mod(total, m)) * (mod(base, m))), m);
			exp--;
		}
		base= mod((mod(base, m) * mod(base, m)), m);
		exp /= 2;
	}
	return mod(total, m);
}

int n;

void solve(){
	cin>> n;

	vector<ll> cnt(60, 0);

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

		for(int j = 1, k = 0; j <= x; j<<=1LL, ++k) if(j & x) cnt[k]++;
	}

	ll ans = 0LL;

	for(int i = 0; i<60; ++i){
		ll temp = mod(cnt[i] * (n - cnt[i]), MOD);
		ans = mod(ans + mod(temp * mod(1LL << i, MOD), MOD), MOD);
	}
	cout<< ans << endl;
}

int32_t main(){
	fastio;
	solve();
	return 0;
}


/*
ID: anonymo14
TASK: wormhole
LANG: C++
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back
#define REP(i,a,b) for(int i=a; i<=b; i++)
#define MOD 1000000007

void solve(int test_case) {//209
	string s;
	cin>>s;
	int mi = INT_MAX;
	REP(i,0,(int)s.length()-3) {
		mi=min(mi,abs(753-stoi(s.substr(i,3))));
	}
	cout<<mi;
}

int main() {

	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////

	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	//prefill();
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for (ll i=0; i<n; ++i)
#define all(c) begin(c),end(c)
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
/*

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

  ll K; cin>>K;
  ll k = K;
  string S; cin>>S;

  ll i=0;
  while (S[i] && k>0){
    cout<<S[i];
    k--;
    i++;
  }
  if (S.size() > K)
    cout<<"..."<<endl;
  else
    cout<<endl;
}


#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,N) for(int i=0; i<N; i++) ;
int main() {
int N;
cin>>N;
ll answer=0;
for(int i=01; i<N+1; i++){
    if(i%3==0||i%5==0){
    }
    else{
    answer+=i;
    }
}
cout<<answer<<endl;
}

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

long long get_rev(long long x) {
	long long nx = 0;
	while (x) nx = nx * 10 + x % 10, x /= 10;
	return nx;
}

long long get_rev(long long x, int len) {
	long long nx = 0;
	while (len--) nx = nx * 10 + x % 10, x /= 10;
	return nx;
}

int cnt;

long long solve(long long d, long long len) {
	long long tmp = len >> 1, pw = 1;
	while (tmp--) pw *= 10;
	long long ans = 0;
	for (int i = 0; i < pw; i++) {
		long long tmp = (d + i) % pw;
		tmp = get_rev(tmp, len >> 1);
		if (len & 1) tmp = tmp * 10;
		long long n = tmp * pw + i;
		if ((cnt ? get_rev(n, len) : get_rev(n)) == n + d) ans++;
	}
	if (len & 1) ans *= 10;
	return ans;
}

int main () {
	int d; cin >> d;
	cnt = 0;
	while (d % 10 == 0) d /= 10, cnt++;
	int len = 0, D = d;
	while (D) len++, D /= 10;
	long long ans = solve(d, len) + solve(d, len + 1) + solve(d, len + 2) + solve(d, len + 3) + solve(d, len + 4) + solve(d, len + 5) + solve(d, len + 6);
	if (cnt) cnt--, ans *= 9;
	while (cnt--) ans *= 10;
	cout << ans << endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int accum[N], bulbs[N], n, k;
int main() {
    cin >> n >> k;
    k = min(41, k);
    for (int i = 1; i <= n; ++i) cin >> bulbs[i];
    while (k--) {
        memset(accum, 0, sizeof accum);
        for (int i = 1; i <= n; ++i) {
            int l = max(1, i - bulbs[i]);
            int r = min(n, i + bulbs[i]);
            accum[l]++;
            accum[r + 1]--;
        }
        for (int i = 1; i <= n; ++i) {
            accum[i] += accum[i - 1];
        }
        memcpy(bulbs, accum, sizeof accum);
    }
    for (int i = 1; i <= n; ++i) {
        cout << bulbs[i] << " ";
    }
    return 0;
}

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;

struct event{
    int t,id,x;
};

int main(){
    int n,q;
    cin >> n >> q;
    vector<event> events;
    rep(i,n){
        int s,t,x;
        cin >> s >> t >> x;
        events.push_back({s-x,-1,x});
        events.push_back({t-x,0,x});
    }
    map<int,int> ans;
    rep(i,q){
        int d;
        cin >> d;
        ans[d] = -1;
        events.push_back({d,1,0});
    }

    sort(events.begin(),events.end(),[](const event &l,const event &r){
        if(l.t != r.t) return l.t < r.t;
        else return l.id < r.id;
    });

    set<int> st;
    map<int,int> cnt;

    rep(i,2*n+q){
        if(events[i].id == -1){
            st.insert(events[i].x);
            cnt[events[i].x] ++;
        }else if(events[i].id == 0){
            cnt[events[i].x] --;
            if(cnt[events[i].x]==0) st.erase(events[i].x);
        }else{
            if(!st.empty()) ans[events[i].t] = *st.begin();
        }
    }

    for(auto p:ans) cout << p.second << endl;
    return 0;
}


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

struct Problem {

	void Solve() {
		UL N, M; cin >> N >> M;
		vector<vector<UL>> E(N);
		rep(i, M) {
			UL a, b; cin >> a >> b; a--; b--;
			E[a].push_back(b);
			E[b].push_back(a);
		}
		vector<int> F(N);
		ULL z, b, u; z = b = u = 0;
		rep(s, N) {
			if (F[s]) continue;
			F[s] = s + 1;
			if (E[s].size() == 0) {
				z++; F[s] = s + 1; continue;
			}
			queue<UL> Q; Q.push(s);
			bool bok = true;
			while (Q.size()) {
				UL p = Q.front(); Q.pop();
				for (UL e : E[p]) {
					if (F[p] == F[e]) bok = false;
					if (F[e] == 0) {
						F[e] = -F[p];
						Q.push(e);
					}
				}
			}
			if (bok) b++; else u++;
		}
		ULL ans = 0;
		ans += (z * N * 2 - z * z);
		ans += ((b + u) * (b + u) + b * b);
		cout << ans << endl;
	}

	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}

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

typedef long long s64;
s64 C2(int n)
{
	return (s64)n*(n-1)/2;
}
#define rep(i,l,r) for(int i=l;i<=r;++i)
const int N=1e5+5;
int fa[N],sz[N];bool d[N],have[N];
int find(int x)
{
	if(fa[x]==x)return x;
	find(fa[x]);
	d[x]^=d[fa[x]];
	return fa[x]=fa[fa[x]];
}

int main()
{
	//freopen("1.in","r",stdin);
	int n,m;
	cin>>n>>m;
	rep(i,1,n){fa[i]=i;sz[i]=1;}
	while(m--)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		int fx=find(x),fy=find(y);
		if(fx==fy)
		{
			have[fx]|=d[x]==d[y];
			continue;
		}
		fa[fy]=fx;d[fy]=d[x]^1^d[y];
		sz[fx]+=sz[fy];
		have[fx]|=have[fy];
	}
	int cnt1=0,cnt[2]={};
	rep(x,1,n)
	if(fa[x]==x)
	if(sz[x]==1)++cnt1;
	else ++cnt[have[x]];
	cout<<(s64)cnt[1]*cnt[0]*2+(s64)cnt1*(n-cnt1)*2
		+(s64)cnt[1]*cnt[1]+(s64)cnt[0]*cnt[0]*2+(s64)cnt1*cnt1;
}


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

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

	if(a>b){
		cout<<a+(a-1)<<endl;
	}
	else if(a<b){
		cout<<b+(b-1)<<endl;
	}
	else
	cout<<a+b<<endl;

}

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

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#define fo(i, n) for(int i=0; i<n; i++)
#define Fo(i, k, n) for(int i=k; i<n; i++)
#define w(x)  int x; cin>>x; while(x--)
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define watch2(x,y) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<"\n"
#define watch3(x,y,z) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<" and "<<(#z)<<" is "<<(z)<<"\n"
#define watch4(x,y,z,q) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<" and "<<(#z)<<" is "<<(z)<<" and "<<(#q)<<" is "<<(q)<<"\n"
#define MOD 1000000007
#define INF 1000000007;
#define F first
#define S second
#define pb(x) push_back(x);

#define ll  long long
#define all(c) (c).begin(),(c).end()
#define endl "\n"

typedef vector<int> vl;
typedef vector< vl > vvl;
typedef pair< int, int> pll;
typedef map< int, int> mll;

#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

void c_p_c()
{
#ifndef ONLINE_JUDGE
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
void parray(int a[], int n) {
	for (int i = 0; i < n; i++) {
		cout << a[i] << " ";
	}
	cout << endl;
}

int check(int n) {

	int temp = n + 9;

	temp = temp / 10;
	return temp * 10;

}

bool comp(pair<string,pair<int,int>> a , pair<string,pair<int,int>> b) {

	// return a % 10 > b % 10;
	if(a.F!=b.F)
		return a.F<b.F;
	return a.S.F>b.S.F;

}

int main() {
	int i, n, m, k, c = 0;
	c_p_c();
	int l;
	cin>>n>>l;
	int a[n];
	int sm=INF;
	for (int i = 0; i < n; ++i)
	{
		/* code */
		a[i]=(i+l);
		sm=min(sm,abs(a[i]));
		c+=a[i];
	}
	// watch(c+21);
	// parray(a,n);
	if(c>0)
		cout<<c-sm<<endl;
	else
	cout<<c+sm<<endl;
}


#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <math.h> // sqrt
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <iomanip> // setprecision
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<long long>;
using pii = pair<int, int>;
using psi = pair<string, int>;

int main() {
    ll x;
    cin >> x;
    ll ans = floor(x / 11) * 2, a = x % 11;
    if (a > 6) {
        ans += 2;
    }
    else if (a > 0) {
        ans++;
    }
    cout << ans << endl;
}

#include <stdio.h>
#include <math.h>

using namespace std;
typedef long long llong;

#define MAX
const llong mod = 1000000000 + 7;

int main()
{
  double R;
  scanf("%lf", &R);

  printf("%lf", 2.0 * M_PI * R);

  return 0;
}


#include <iostream>
using namespace std;

int main (void){
    string str;
    cin >> str;
    str[3] = '8';
    cout << str << endl;
}

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

int main(){
	double a,b,c,d,e,f,g,h=0;
	cin>>a>>b>>c>>d;
	e=c-a;
	f=d-b;
	g=e*e+f*f;
	h=sqrt(g);
	cout <<setprecision(12)<<h <<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define y1 A2Dalek
#define y0 Cyberman
#define yn RoseTyler
#define j1 JackHarkness
#define fs first
#define sd second
const int N=2e5;
const long long oo=1e16+5;
int du[]={-1,0,0,1};
int dv[]={0,-1,1,0};
const long long mod=1e9+7;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
long long sqr(long long x) {return x*x;}
int getbit(int state, int i) {return ((state>>i)&1);}

int n,nq,A,B,q[N+5];
long long res=oo;
struct IT
{
    long long f[4*N+5];
    long long lz[4*N+5];
    long long a[N+5];
    void build(int id, int l, int r)
    {
        if (l>r) return;
        if (l==r) {f[id]=a[l]; return;}
        int mid=(l+r)/2;
        build(id*2,l,mid); build(id*2+1,mid+1,r);
        f[id]=min(f[id*2],f[id*2+1]);
    }
    void down(int id)
    {
        long long val=lz[id]; lz[id]=0;
        f[id*2]+=val; f[id*2+1]+=val;
        lz[id*2]+=val; lz[id*2+1]+=val;
    }
    void update(int id, int l, int r, int u, long long val)
    {
        if (l>u || r<u || l>r) return;
        if (l==r)
        {
            f[id]=min(f[id],val);
            return;
        }
        int mid=(l+r)/2;
        down(id);
        update(id*2,l,mid,u,val); update(id*2+1,mid+1,r,u,val);
        f[id]=min(f[id*2],f[id*2+1]);
    }
    long long get(int id, int l, int r, int u, int v)
    {
        if (l>r || l>v || r<u) return oo;
        if (u<=l && r<=v) return f[id];
        int mid=(l+r)/2;
        down(id);
        return min(get(id*2,l,mid,u,v),get(id*2+1,mid+1,r,u,v));
    }
} tru,cong;
int main()
{
	//freopen("Many Moves.inp","r",stdin);
	//freopen("Many Moves.out","w",stdout);
	ios_base::sync_with_stdio(false);
    cin>>n>>nq;
    cin>>A>>B;
    for (int i=1;i<=n;i++)
    {
        tru.a[i]=abs(B-i)-i;
        cong.a[i]=abs(B-i)+i;
    }
    tru.build(1,1,n); cong.build(1,1,n);
    q[0]=A;
    for (int i=1;i<=nq;i++)
    {
        cin>>q[i];
        long long val=abs(q[i]-q[i-1]);
        long long now=min(tru.get(1,1,n,1,q[i])+q[i], cong.get(1,1,n,q[i],n)-q[i]);
        tru.f[1]+=val; cong.f[1]+=val;
        tru.lz[1]+=val; cong.lz[1]+=val;
        tru.update(1,1,n,q[i-1],now-q[i-1]);
        cong.update(1,1,n,q[i-1],now+q[i-1]);
    }
    for (int i=1;i<=n;i++)
    {
        res=min(res,tru.get(1,1,n,i,i)+i);
    }
    cout<<res;
	return 0;
}

#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <climits>
#include <cctype>
#include <iostream>
#include <cstring>
#include <algorithm>
#define R register
#define IN inline
#define W while
#define ls (now << 1)
#define rs ((now << 1) | 1)
#define MX 200500
#define gc getchar()
#define ll long long
template <class T>
IN void in(T &x)
{
	x = 0; R char c = gc;
	for (; !isdigit(c); c = gc);
	for (;  isdigit(c); c = gc)
	x = (x << 1) + (x << 3) + c - 48;
}
template <class T> IN T max(T a, T b) {return a > b ? a : b;}
template <class T> IN T min(T a, T b) {return a < b ? a : b;}
template <class T> IN T abs(T a) {return a > 0 ? a : -a;}
int n, q;
struct Node
{
	ll val[3], tag;
	Node(){std::memset(val, 63, sizeof(val));}
}tree[MX << 2];
IN void pushup(R int now)
{
	tree[now].val[0] = min(tree[ls].val[0], tree[rs].val[0]);
	tree[now].val[1] = min(tree[ls].val[1], tree[rs].val[1]);
	tree[now].val[2] = min(tree[ls].val[2], tree[rs].val[2]);
}
IN void pushdown(R int now)
{
	if (tree[now].tag)
	{
		tree[ls].val[0] += tree[now].tag;
		tree[ls].val[1] += tree[now].tag;
		tree[ls].val[2] += tree[now].tag;
		tree[ls].tag	+= tree[now].tag;
		tree[rs].val[0] += tree[now].tag;
		tree[rs].val[1] += tree[now].tag;
		tree[rs].val[2] += tree[now].tag;
		tree[rs].tag	+= tree[now].tag;
		tree[now].tag = 0;
	}
}
void modify(R int now, R int lef, R int rig, R int pos, R ll v)
{
	if (lef == rig)
	{
		tree[now].val[0] = v;
		tree[now].val[1] = v - pos;
		tree[now].val[2] = v + pos;
		return;
	}
	pushdown(now);
	int mid = lef + rig >> 1;
	if (pos <= mid) modify(ls, lef, mid, pos, v);
	else modify(rs, mid + 1, rig, pos, v);
	pushup(now);
}
IN void add(R ll v)
{
	tree[1].tag += v;
	tree[1].val[0] += v;
	tree[1].val[1] += v;
	tree[1].val[2] += v;
}
ll query(R int now, R int lef, R int rig, R int lb, R int rb, R int id)
{
	if (lef >= lb && rig <= rb) return tree[now].val[id];
	pushdown(now);
	int mid = lef + rig >> 1; ll ret = LONG_LONG_MAX;
	if (lb <= mid) ret = query(ls, lef, mid, lb, rb, id);
	if (rb > mid) ret = min(ret, query(rs, mid + 1, rig, lb, rb, id));
	return ret;
}
int main(void)
{
	int a, b, last, cur, del;
	ll res1, res2, res3;
	in(n), in(q), in(a), in(b);
	in(last);
	modify(1, 1, n, b, abs(last - a));
	modify(1, 1, n, a, abs(last - b));
	W (--q)
	{
		in(cur); del = abs(last - cur);
		res1 = query(1, 1, n, cur, cur, 0) + del;
		res2 = query(1, 1, n, 1, cur, 1) + cur;
		res3 = query(1, 1, n, cur + 1, n, 2) - cur;
		res1 = min(res1, min(res2, res3));
		add(del);
		modify(1, 1, n, last, res1);
		last = cur;
	}
	printf("%lld", tree[1].val[0]);
}


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

int main(){
  string s;
  cin >> s;
  int w;
  cin >> w;
  int n=1;
  if(w==1){
    cout << s << endl;
    return 0;
  }
  for(int i=0; i<s.size(); i++){
    if(n%w==1) cout << s[i];
    n++;
  }
  cout << endl;
}

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

#define REP(i, n) for (ll (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n) for (ll (i) = m ; (i) < (ll)(n) ; ++(i))
#define REP_REV(i, n) for (ll (i) = (ll)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (ll (i) = (ll)(n) - 1 ; (i) >= m ; --(i))

#define INF             2e9
#define INF_LL          1LL<<60
#define ll              long long
#define Ceil(x, n)      (((((x))+((n)-1))/n))
#define CeilN(x, n)     (((((x))+((n)-1))/n)*n)
#define FloorN(x, n)    ((x)-(x)%(n))
#define ALL(x)          (x).begin(),(x).end()
typedef pair<ll, ll>    P;

int main() {
    string s;
    int w;
    cin >> s >> w;
    vector<char> ans;
    REP(i, s.size()) {
        if(i % w == 0) {
            ans.push_back(s[i]);
        }
    }

    REP(i, ans.size()) cout << ans[i];
    cout << endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for(ll i = m, i##_len = (n); i < i##_len; ++i)
#define reprev(i, n) for(ll i = (n-1LL); i >= 0; --i)
#define all(x) (x).begin(), (x).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 (b < a) { a = b; return 1; } return 0; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

constexpr int MOD = 1000000007;

// + - * / ^
int mod(int a)
{
	int res = a % MOD;
	if(res < 0) {
		return res + MOD;
	}
	return res;
}
int mul_mod(int a, int b)
{
	ll res = ((ll)a * (ll)b) % MOD;
	return mod((int)res);
}
int pow_mod(int a, int b)
{
	ll res = 1;
	while (b > 0) {
		if(b & 1) {
			res = res * (ll)a % (ll)MOD;
		}
		a = mul_mod(a, a);
		b >>= 1;
	}
	return (int)res;
}
int inv_mod(int a)
{
	return pow_mod(a, MOD - 2);
}
int div_mod(int a, int b)
{
	return mul_mod(a, inv_mod(b));
}

// ! C
constexpr int FAC_MAX = 100000;
ll fac[FAC_MAX], finv[FAC_MAX], inv[FAC_MAX];
void com_init()
{
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < FAC_MAX; i++){
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}
ll com_mod(int a, int b){
	if (a < b) return 0;
	if (a < 0 || b < 0) return 0;
	return fac[a] * (finv[b] * finv[a - b] % MOD) % MOD;
}

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	vector<ll> x(n), y(m);
	rep (i, n) cin >> x[i];
	rep (i, m) cin >> y[i];
	ll a = 0, b = 0;
	rep (i, n - 1) {
		ll tmp = min(i + 1, n - 1 - i);
		// cout << mul_mod((n - (2 * tmp - 1) - 1) + tmp, tmp) << " ";
		a = mod(a + mul_mod(mul_mod((n - (2 * tmp - 1) - 1) + tmp, tmp), x[i + 1] - x[i]));
	}
	rep (i, m - 1) {
		ll tmp = min(i + 1, m - 1 - i);
		b = mod(b + mul_mod(mul_mod((m - (2 * tmp - 1) - 1) + tmp, tmp), y[i + 1] - y[i]));
	}
	// cout << a << " " << b << "\n";
	cout << mul_mod(a, b) << "\n";
	return 0;
}

#include<iostream>
#include<unordered_map>
#include<bitset>
#include<math.h>
#include<vector>
#include<set>
#include<algorithm>
#include<ctype.h>
#include<unordered_set>
#include<string>
#include<iomanip>
#include<queue>
#include<limits>
#include<map>
#include<stack>
#include<iterator>
#include<cstring>

#include<deque>
#define pi 3.141592653589793238
#include<chrono>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define MOD 1000000007
#define INF 999999999999999999
#define pb push_back
#define ff first
#define ss second

#define mt make_tuple
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;

typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
set<ll> s;

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    fast;
    ll T = 1, i, j;

    //cin >> T;
    while (T--) {
        ll calcy = 0;
        ll n, m;
        cin >> n >> m;
        vector<ll> x(n), y(m);
        for(i = 0; i < n; i++){
            cin >> x[i];
        }
        for(i = 0; i < m; i++){
            cin >> y[i];
        }
        sort(x.begin(), x.end());
        sort(y.begin(), y.end());
        vector<ll> dp(n + 1);
        for(i = 0; i < m; i++){
            calcy -= (m - 1 - i) * y[i];
            calcy += i * (y[i]);
            calcy %= MOD;
        }
        ll calcx = 0;
        for(i = 0; i < n; i++){
            calcx -= (n - 1 - i) * x[i];
            calcx += i * (x[i]);
            calcx %= MOD;
        }
        cout << calcy * calcx % MOD;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, a, b) for(int i = a; i < b; i++)
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define pb push_back
#define debug(x) cerr <<__LINE__<< ": " << #x << " = " << x << endl
#define debug_vec(v) cerr<<__LINE__<<": "<<#v<<" = ";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

void solve() {
    int n;
    cin >> n;
    ll ans = 0;
    rep(i, n + 1) {
        if (i % 3 != 0 && i % 5 != 0) ans += i;
    }
    cout << ans << endl;
}

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

#include <bits/stdc++.h>
#include <numeric>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep1(i,n) for (int i = 1; i <= n; ++i)
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
const long long MOD = 1e9+7;
template<typename T> inline void add(T& a, T b) { a += b; if (a >= MOD) a -= MOD; }

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

  string s; cin >> s;
  vector<int> BI(26, -10);
  int n = s.size();
  rep(i, n) {
    if(i - BI[s[i] - 'a'] <= 2) {
      cout << BI[s[i] - 'a'] + 1 << " " << i + 1 << endl;
      return 0;
    }
    BI[s[i] - 'a'] = i;
  }
  cout << "-1 -1" << endl;
  return 0;
}


///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>

#define                           ll                          long long
#define                           int                         ll
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<ll,ll>
#define                           clr(x)                      memset(x,0,sizeof(x));
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           show(x,y)                   cout<<x<<" : ";for(auto z:y)cout<<z<<" ";cout<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

const ll inf=1e18;
const int mod=1e9+7;
const int M=100005;
int n;
string s;
char ses[M];
char fnd(int pos,char cur,char dan)
{
    if(cur=='S')
    {
        if(s[pos]=='o')return dan;
        else
        {
            if(dan=='S')return 'W';
            else return 'S';
        }
    }
    else if(cur=='W')
    {
        if(s[pos]=='x')return dan;
        else
        {
            if(dan=='S')return 'W';
            else return 'S';
        }
    }
}
void chk(char x,char y)
{

    ses[0]=x;
    ses[1]=y;
    ses[n-1]=fnd(0,x,y);
    for(int i=2;i<=n;i++)
    {
        char yo=fnd(i-1,ses[i-1],ses[i-2]);
        if(i==n-1)
        {
            if(yo!=ses[n-1])
            {
                return ;
            }
        }
        else if(i==n)
        {
            if(yo!=ses[0])return ;
            continue;
        }
        ses[i]=yo;
    }
    ses[n]='\0';
    cout<<ses<<endl;
    exit(0);
}
 main()

{
    fast
    cin>>n;
    cin>>s;
    chk('S','W');
    chk('S','S');
    chk('W','S');
    chk('W','W');
    cout<<"-1"<<endl;
    return 0;

}

#include<bits/stdc++.h>
#define maxn 100005
#define endl '\n'
using namespace std;
int arr[maxn],ans[maxn];
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	string s;
	cin >> s;
	for(int i=0;i<n;i++)
		arr[i+1] = (s[i] == 'o' ? 0 : 1);
	for(int i=0;i<=1;i++)
		for(int j=0;j<=1;j++) {
			ans[1] = i;
			ans[2] = j;
			for(int k=3;k<=n;k++)
				ans[k] = (arr[k-1] ^ ans[k-1] ^ ans[k-2]);
			if(arr[n] == (ans[n-1] ^ ans[1] ^ ans[n]) && arr[1] == (ans[n] ^ ans[2] ^ ans[1])) {
				for(int i=1;i<=n;i++)
					cout << (ans[i] == 0 ? 'S' : 'W');
				cout << endl;
				return 0;
			}
		}
	cout << -1 << endl;
	return 0;
}


#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

bool check(vector<P> s){
	int h = 0;
	for(P p : s){
		int b = h + p.first;
		if(b < 0) return false;
		h += p.second;
	}
	return true;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<P> ls, rs;
	int total = 0;
	rep(i,n){
		string s;
		cin >> s;
		int h = 0, b = 0;
		for(char c : s){
			if(c == '(') ++h;
			else --h;
			chmin(b, h);
		}
		if(h > 0) ls.emplace_back(b, h);
		else rs.emplace_back(b-h, -h);
		total += h;
	}
	sort(ls.rbegin(), ls.rend());
	sort(rs.rbegin(), rs.rend());
	if(check(ls) && check(rs) && total == 0) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

#include<iostream>
#include <iomanip>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <cstdlib>

using namespace std;

void roll(int target[], int idx[], int size,  bool rev){
  if(!rev){
    int tmp = target[idx[0]];
    for(int i=0;i<size-1;i++){
      target[idx[i]] = target[idx[i+1]];
    }
    target[idx[size-1]] = tmp;
  }else{
    int tmp = target[idx[size-1]];
    for(int i=size-1;i>0;i--){
      target[idx[i]] = target[idx[i-1]];
    }
    target[idx[0]] = tmp;
  }
}

bool is_match(int x[],int y[],int size){
  for(int i=1;i<size;i++){
    if(x[i] != y[i]) return false;
  }
  return true;
}

void pri(int x[], int size){
  for(int i=1;i<size;i++){
    cout << x[i] << " ";
  }
  cout << endl;
}

int main(){

  static int n = 0;
  cin >> n;

  int x[n][7];

  for(int i=0;i<n;i++){
    for(int j=1;j<7;j++)
      cin >> x[i][j];
  }

  int roll_n[] = {5,1,2,6};
  int roll_e[] = {3,1,4,6};
  int roll_side[] = {3,5,4,2};

  int size = sizeof(x[0])/sizeof(int);
  int size_roll = sizeof(roll_n)/sizeof(int);

  for(int k=0;k<n;k++){
    for(int l=k+1;l<n;l++){

      for(int i=0;i<4;i++){
        roll(x[k], roll_n,size_roll,false);
        ///pri(x,size);
        for(int j=0;j<4;j++){
          roll(x[k], roll_side,size_roll,false);
          if(is_match(x[k],x[l],size)){
            cout << "No" << endl;
            return 0;
          }
        }
      }

      for(int i=0;i<4;i++){
        roll(x[k], roll_e,size_roll, false);
        for(int j=0;j<4;j++){
          roll(x[k], roll_side,size_roll, false);
          if(is_match(x[k],x[l],size)){
            cout << "No" << endl;
            return 0;
          }
        }
      }

    }
  }

  cout << "Yes" << endl;
}


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

int main(){
	int n;
  	cin >> n;
 	long long res = 0;
  	for(int i=0;i<n;i++){
    	int a = i+1;
      	if(a % 3 == 0 || a % 5 == 0) continue;
      	else res += a;
    }
  	cout << res << endl;
}

#include <iostream>
#include <set>
#include <vector>

using namespace std;

int main() {
    string str;
    cin >> str;
    set<char> st;
    for(int i=0; i<str.size(); i++) {
        st.insert(str[i]);
    }

    if(st.size()<26) {
        cout << str;
        for(int i=0; i<26; i++) {
            if(st.find((char)('a'+i))==st.end()) {
                cout << (char)('a'+i) << endl;
                break;
            }
        }
    } else {
        set<char> vec;
        vec.insert(str[25]);
        int i;
        for(i=25; i>=1; i--) {
            if(str[i-1]<str[i]) {
                break;
            }
            vec.insert(str[i-1]);
        }
        if(vec.size()==26) {
            cout << -1 << endl;
        } else if(vec.upper_bound(str[i-1])!=vec.end()) {
            for(int j=0; j<i-1; j++) {
                cout << str[j];
            }
            cout << (*vec.upper_bound(str[i-1])) << endl;
        }
    }

    return 0;

}


#include <bits/stdc++.h>
#define fi first
#define se second
#define MP make_pair
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int N = 1e5 + 5;

int n;
ll a[N], p[62];

void insert(ll x) {
    for(int i = 60; i >= 0; i--) {
        if(x >> i & 1) {
            if(!p[i]) {
                p[i] = x;
                break;
            }
            x ^= p[i];
            //cout<<x<<endl;
        }
    }
}

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    cin >> n;
    ll all = 0;
    for(int i = 1; i <= n; i++) cin >> a[i], all ^= a[i];
    for(int i = 0; i <= 60; i++) {
        if(all >> i & 1) {
            for(int j = 1; j <= n; j++) {
                if(a[j] >> i & 1) a[j] -= (1ll << i);
            }
        }
    }
    for(int i = 1; i <= n; i++) insert(a[i]);//,cout<<a[i]<<endl;;
    ll ans = 0;
    for(int i = 60; i >= 0; i--) {
    	//cout<<i<<" "<<p[i]<<" "<<(ans&(1ll<<i)==0)<<endl;

    	if((p[i]!=0)&&((ans&(1ll<<i))==0))
    	{
    		ans=p[i]^ans;
    		//cout<<ans<<endl;
		}

    }
    //cout<<ans<<endl;
    cout << ans + (ans ^ all);
    return 0;
}

//Be Name Khoda, Besmellah Rahmane Rahim, In The Name Of God;
//#include<bits/stweight++.h>
#include<iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <queue>
#include <deque>
#include <map>
#include <stack>
#include<bitset>
#include<list>
#include<cassert>
#include<numeric>
#include <stdio.h>
#include <string.h>
#include<iomanip>
#include<unordered_map>
#include<unordered_set>
#include <fstream>

using namespace std;
const int N = 1000 + 5;
int a[N];
int n,m;
vector<int> ans;

int main()
{
    cin >> n >> m;
    int cnt = 0;
    for(int i = 1; i <= m; ++i)
    {
        cin >> a[i];
        cnt += a[i] % 2;
    }
    if (cnt > 2)
    {
        cout << "Impossible" << endl;
        return 0;
    }
    for(int i = 2; i < m; i++)
    {
        if (a[i] % 2)
        {
            if (a[1] % 2)
            {
                swap(a[i], a[m]);
            }
            else
            {
                swap(a[i], a[1]);
            }
        }
    }
    for (int i = 1; i <= m; i++)
    {
        cout << a[i] << " ";
    }
    cout << endl;
    if (m == 1 && a[1] == 1)
    {
        ans.push_back(1);
    }
    else
    {
        if (m == 1)
        {
            ans.push_back(a[1] - 1);
            ans.push_back(1);
        }
        else
        {
            if (a[1] != 1)
            {
                ans.push_back(a[1] - 1);
            }
            for (int i = 2; i < m; i++)
            {
                ans.push_back(a[i]);
            }
            ans.push_back(a[m] + 1);
        }
    }
    cout << ans.size() << endl;
    for(int i = 0; i < ans.size(); i++)
    {
        cout << ans[i] << " ";
    }
}


#include<cstdio>
#include<cstring>
char str[305];
int dp[305][305][305],K;
int max(int a,int b){return a>b?a:b;}
int main(){
	scanf("%s%d",str,&K); int lens=strlen(str);
	for(int i=0;i<lens;++i)
		for(int k=0;k<=K;++k)
			dp[i][i][k]=1;
	for(int l=1;l<lens;++l)
		for(int i=0;i+l<lens;++i){
			int j=i+l;
			for(int k=0;k<=K;++k){
				dp[i][j][k]=max(dp[i+1][j][k],dp[i][j-1][k]);
				if(k>0) dp[i][j][k]=max(dp[i+1][j-1][k-1]+2,dp[i][j][k]);
				if(str[i]==str[j]) dp[i][j][k]=max(dp[i+1][j-1][k]+2,dp[i][j][k]);
	        }
	    }
	printf("%d\n",dp[0][lens-1][K]);
}

#include <bits/stdc++.h>
#include <iostream>
typedef long long ll;
#define rep(i,a,b) for(ll i =a ;i <= b;i++)
#define per(i,a,b) for(ll i =a ;i >= b;i--)
using namespace std;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;

int main(int argc, char const *argv[])
{
	//ifstream cin("input.txt");
	int n;
	cin>>n;
	ll sum = 0;
	rep(i,1,n)
	{

		if(i%3 != 0 && i%5 != 0)
			sum+=i;

	}
	cout<<sum;
}


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

typedef long long ll;

int main() {
    int N, Q;
    string S;
    cin >> N >> S >> Q;
    vector<int> k(Q);
    rep(i, Q) cin >> k[i];
    vector<ll> Dsum(N + 1, 0), Msum(N + 1, 0), DM(N + 1, 0);
    rep(i, N) {
        Dsum[i + 1] = Dsum[i];
        if (S[i] == 'D') Dsum[i + 1]++;
        Msum[i + 1] = Msum[i];
        if (S[i] == 'M') Msum[i + 1]++;
    }
    rep(i, Q) {
        ll ans = 0, DM = 0;
        rep(j, N) {
            int j0 = j - k[i];
            if (j0 >= 0 && S[j0] == 'D') DM -= Msum[j + 1] - Msum[j0];
            if (S[j] == 'M') DM += Dsum[j] - Dsum[max(0, j0)];
            if (S[j] == 'C') ans += DM;
        }
        cout << ans << endl;
    }
}

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

using namespace std;

void chmax(string &a, string b) {
  if (a == "-") { a = b; }
  else if (a.size() < b.size()) { a = b; }
  else if (a.size() == b.size()) {
    if (a < b) { a = b; }
  }
}

int main(){
  int match[] = {-1,2,5,5,4,5,6,3,7,6};
  int n, m;
  cin >> n >> m;

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

  vector<string> dp(n+10, "-");
  dp[0] = "";
  for (int i = 0; i < n; i++) {
    if (dp[i] == "-") { continue; }
    for (int j = 0; j < m; j++) {
      chmax(dp[i + match[a[j]]], dp[i] + (char)('0'+a[j]));
    }
  }
  cout << dp[n] << endl;
  return 0;
}