#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using i64=int_least64_t;

namespace std
{
    // hash
    template <class T> size_t hash_combine(size_t seed, T const &key) { return seed ^ (hash<T>()(key) + 0x9e3779b9 + (seed << 6) + (seed >> 2)); }
    template <class T, class U> struct hash<pair<T, U>> { size_t operator()(pair<T, U> const &pr) const { return hash_combine(hash_combine(0, pr.first), pr.second); } };
    template <class tuple_t, size_t index = tuple_size<tuple_t>::value - 1> struct tuple_hash_calc { static size_t apply(size_t seed, tuple_t const &t) { return hash_combine(tuple_hash_calc<tuple_t, index - 1>::apply(seed, t), get<index>(t)); } };
    template <class tuple_t> struct tuple_hash_calc<tuple_t, 0> { static size_t apply(size_t seed, tuple_t const &t) { return hash_combine(seed, get<0>(t)); } };
    template <class... T> struct hash<tuple<T...>> { size_t operator()(tuple<T...> const &t) const { return tuple_hash_calc<tuple<T...>>::apply(0, t); } };
    // iostream
    template <class T, class U> istream &operator>>(istream &is, pair<T, U> &p) { return is >> p.first >> p.second; }
    template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { return os << p.first << ' ' << p.second; }
    template <class tuple_t, size_t index> struct tupleis { static istream &apply(istream &is, tuple_t &t) { tupleis<tuple_t, index - 1>::apply(is, t); return is >> get<index>(t); } };
    template <class tuple_t> struct tupleis<tuple_t, SIZE_MAX> { static istream &apply(istream &is, tuple_t &t) { return is; } };
    template <class... T> istream &operator>>(istream &is, tuple<T...> &t) { return tupleis<tuple<T...>, tuple_size<tuple<T...>>::value - 1>::apply(is, t); }
    template <> istream &operator>>(istream &is, tuple<> &t) { return is; }
    template <class tuple_t, size_t index> struct tupleos { static ostream &apply(ostream &os, const tuple_t &t) { tupleos<tuple_t, index - 1>::apply(os, t); return os << ' ' << get<index>(t); } };
    template <class tuple_t> struct tupleos<tuple_t, 0> { static ostream &apply(ostream &os, const tuple_t &t) { return os << get<0>(t); } };
    template <class... T> ostream &operator<<(ostream &os, const tuple<T...> &t) { return tupleos<tuple<T...>, tuple_size<tuple<T...>>::value - 1>::apply(os, t); }
    template <> ostream &operator<<(ostream &os, const tuple<> &t) { return os; }
    template <class Container, typename Value = typename Container::value_type, enable_if_t<!is_same<decay_t<Container>, string>::value, nullptr_t> = nullptr>
    istream& operator>>(istream& is, Container &cont) { for(auto&& e : cont) is >> e; return is; }
    template <class Container, typename Value = typename Container::value_type, enable_if_t<!is_same<decay_t<Container>, string>::value, nullptr_t> = nullptr>
    ostream& operator<<(ostream& os, const Container &cont) { bool flag = 1; for(auto&& e : cont) flag ? flag = 0 : (os << ' ', 0), os << e; return os; }
} // namespace std

#include <cassert>
#include <list>
#include <vector>

// Base class of flow algorithms
template <class cap_t, class cost_t>
struct flow_base
{
    class adj_type;

    class edge_t
    {
        friend flow_base;
        friend class adj_type;
        edge_t *link;
        friend void advance(edge_t* &ptr) { ptr = ptr->link; }
    public:
        size_t src, dst;
        cap_t cap; cost_t cost;
        edge_t *rev;
        edge_t() : link() {}
        edge_t(edge_t *link, const edge_t &edge) : edge_t(edge), link(link) {}
        edge_t(edge_t *link, size_t src, size_t dst, cap_t cap, cost_t cost, edge_t *rev)
            : link(link), src(src), dst(dst), cap(cap), cost(cost), rev(rev) {}
    }; // struct edge_t

    class adj_type
    {
        friend flow_base;
        edge_t *_head, *_next, *_last;
        size_t _len;

        template <class ...Args>
        edge_t *emplace(Args&&... args)
        {
            if(_next == _last)
            {
                _len <<= 1;
                _next = new edge_t[_len];
                _last = _next + _len;
            }
            *_next = edge_t(_head, args...);
            _head = _next;
            ++_next;
            return _head;
        }

    public:
        adj_type() : _head(), _next(new edge_t[1]), _last(_next + 1), _len(1) {}
        ~adj_type()
        {
            --_last, --_len;
            for(edge_t *_p; _len; _last = _p, _len >>= 1)
            {
                _last -= _len;
                _p = _last->link;
                delete[] _last;
            }
        }

        class iterator
        {
            edge_t *ptr;
        public:
            iterator(edge_t *ptr = nullptr) : ptr(ptr) {}
            iterator operator++() { ptr = ptr->link; return *this; }
            bool operator!=(const iterator &other) const { return ptr != other.ptr; }
            edge_t &operator*() const { return *ptr; }
        };

        iterator begin() const { return iterator(_head); }
        iterator end() const { return iterator(); }
    };

protected:
    std::vector<adj_type> adjs;

public:
    flow_base(size_t _n = 0) : adjs(_n) {}

    flow_base(const flow_base& other) : adjs(other.size())
    {
        for(size_t node{}; node != size(); ++node)
        {
            for(const edge_t &e : other[node])
            {
                if(e.src == node)
                {
                    edge_t *ref = adjs[src].emplace(e);
                    edge_t *rref = adjs[dst].emplace(*e.rev);
                    ref->rev = rref;
                    rref->rev = ref;
                    e.rev->src = -1;
                }
                else
                {
                    e.rev->rev->src = node;
                }
            }
        }
    }

    flow_base &operator=(const flow_base &other)
    {
        if(this != &other)
        {
            flow_base cop(other);
            std::swap(adjs, cop.adjs);
        }
        return *this;
    }

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

    typename decltype(adjs)::reference operator[](size_t node) { assert(node < size()); return adjs[node]; }
    typename decltype(adjs)::const_reference operator[](size_t node) const { assert(node < size()); return adjs[node]; }

    void add_edge(size_t src, size_t dst, cap_t cap, cost_t cost)
    {
        assert(src < size()); assert(dst < size());
        if(!(cap > 0)) return;
        edge_t *ref = adjs[src].emplace(src, dst, cap, cost, nullptr);
        ref->rev = adjs[dst].emplace(dst, src, 0, -cost, ref);
    }
}; // struct flow_base

template <class cap_t, class cost_t>
class min_cost_flow : public flow_base<cap_t, cost_t>
{
    using base = flow_base<cap_t, cost_t>;
    using edge_t = typename base::edge_t;
    using base::adjs;
    using base::size;

    cost_t min_cost, total_cost;
    std::vector<cap_t> supp;
    std::vector<cost_t> ptnl;

    void copy_member(const min_cost_flow &other)
    {
        min_cost = other.min_cost;
        total_cost = other.total_cost;
        supp = other.supp;
        ptnl = other.ptnl;
    }

    void Dijkstra(std::vector<edge_t*> &last)
    {
        const cost_t infty(total_cost + 1);
        std::vector<cost_t> dist(size(), infty);
        //*/ // O((V + E)logV)
        std::priority_queue<std::pair<cost_t, size_t>> que;
        for(size_t node{}; node != size(); ++node)
        {
            if(supp[node] > static_cast<cap_t>(0))
            {
                dist[node] = 0;
                que.emplace(0, node);
            }
        }
        while(!que.empty())
        {
            auto [nsp, node] = que.top();
            que.pop();
            if(-nsp != dist[node]) continue;
            ptnl[node] -= nsp;
            if(ptnl[node] > infty) ptnl[node] = infty;
            dist[node] = -1;
            for(edge_t &e : adjs[node])
            {
                if(dist[e.dst] == static_cast<cost_t>(-1) || e.cap == static_cast<cap_t>(0)) continue;
                if(dist[e.dst] + ptnl[e.dst] > ptnl[node] + e.cost)
                {
                    dist[e.dst] = ptnl[node] + e.cost - ptnl[e.dst];
                    last[e.dst] = &e;
                    que.emplace(-dist[e.dst], e.dst);
                }
            }
        }
        /*/ // O(V^2)
        size_t src(-1);
        for(size_t node{}; node != size(); ++node)
        {
            if(supp[node] > static_cast<cap_t>(0))
            {
                dist[node] = 0;
                src = node;
            }
        }
        while(src != static_cast<size_t>(-1))
        {
            ptnl[src] += dist[src];
            dist[src] = -1;
            for(edge_t &e : adjs[src])
            {
                if(dist[e.dst] == static_cast<cost_t>(-1) || e.cap == static_cast<cap_t>(0)) continue;
                if(dist[e.dst] + ptnl[e.dst] > ptnl[src] + e.cost)
                {
                    dist[e.dst] = ptnl[src] + e.cost - ptnl[e.dst];
                    last[e.dst] = &e;
                }
            }
            src = -1;
            cost_t nsp{infty};
            for(size_t node{}; node != size(); ++node)
            {
                if(dist[node] == static_cast<cost_t>(-1)) continue;
                if(nsp > dist[node])
                {
                    nsp = dist[node];
                    src = node;
                }
            }
        }
        //*/
    }

public:
    min_cost_flow(size_t _n = 0) : base::flow_base(_n), min_cost(0), total_cost(0), supp(_n), ptnl(_n)  {}

    min_cost_flow(const min_cost_flow &other) : base::flow_base(other)
    {
        copy_member(other);
    }

    min_cost_flow &operator=(const min_cost_flow &other)
    {
        base::operator=(other);
        copy_member(other);
        return *this;
    }

    void add_edge(size_t src, size_t dst, cap_t cap, cost_t cost)
    {
        assert(src != dst);
        if(cap <= static_cast<cap_t>(0)) return;
        if(cost < static_cast<cost_t>(0))
        {
            supp[src] -= cap;
            supp[dst] += cap;
            min_cost += cap * cost;
            total_cost -= cap * cost;
            base::add_edge(dst, src, cap, -cost);
        }
        else
        {
            total_cost += cap * cost;
            base::add_edge(src, dst, cap, cost);
        }
    }

    void supply(size_t node, cap_t vol) { assert(node < size()); supp[node] += vol; }

    bool flow()
    {
        std::vector<edge_t*> last(size());
        std::vector<bool> shut(size());
        for(bool aug = true; aug; fill(last.begin(), last.end(), nullptr), fill(shut.begin(), shut.end(), false))
        {
            aug = false;
            Dijkstra(last);
            for(size_t dst{}; dst != size(); ++dst)
            {
                if(supp[dst] < static_cast<cap_t>(0) and last[dst])
                {
                    cap_t resid{-supp[dst]};
                    size_t src{dst}, block(-1);
                    while(last[src] && !shut[src])
                    {
                        if(resid >= last[src]->cap) resid = last[block = src]->cap;
                        src = last[src]->src;
                    }
                    if(shut[src]) block = src;
                    else
                    {
                        if(resid >= supp[src])
                        {
                            resid = supp[src];
                            block = src;
                        }
                        for(edge_t *e{last[dst]}; e; e = last[e->src])
                        {
                            e->cap -= resid;
                            e->rev->cap += resid;
                        }
                        supp[src] -= resid;
                        supp[dst] += resid;
                        min_cost += ptnl[dst] * resid;
                        aug = true;
                    }
                    if(block != size_t(-1))
                    {
                        for(size_t node{dst}; node != block; node = last[node]->src) shut[node] = true;
                        shut[block] = true;
                    }
                }
            }
        }
        for(cap_t s : supp) if(s > static_cast<cap_t>(0)) return false;
        return true;
    }

    cost_t optimal() { assert(flow()); return min_cost; }
};

main()
{
    min_cost_flow<int,i64> mcf(6100);
    int n,m,k,c,d; cin>>n>>m>>k>>c>>d;
    const int tlim=105;
    for(int i=0; i<k; ++i)
    {
        int j; cin>>j; j--;
        mcf.supply(j,1);
    }
    for(int i=0; i<m; ++i)
    {
        int u,v; cin>>u>>v; --u,--v;
        for(int t=0; t<tlim; ++t)
        {
            int nu=u+n;
            int nv=v+n;
            for(int x=0; x<k; ++x)
            {
                mcf.add_edge(u,nv,1,c+d*(x*2+1));
                mcf.add_edge(v,nu,1,c+d*(x*2+1));
            }
            u=nu;
            v=nv;
        }
    }
    for(int i=1; i<n; ++i)
    {
        for(int t=0; t<tlim; t++)
        {
            mcf.add_edge(n*t+i,n*(t+1)+i,k,c);
        }
    }
    const int dst=mcf.size()-1;
    mcf.supply(dst,-k);
    for(int t=0; t<=tlim; ++t) mcf.add_edge(t*n,dst,k,0);
    cout << mcf.optimal() << "\n";
}


#include <iostream>
#include <vector>
#include <queue>
using namespace std;
const int INF = 1e9+7;
const int N = 6005;
struct Edge
{
    int from,to,cap,flow,cost;
    Edge(int u,int v,int ca,int f,int co):from(u),to(v),cap(ca),flow(f),cost(co){};
};
struct MCMF
{
    int n,m,s,t;
    vector<Edge> edges;
    vector<int> G[N];
    int inq[N];//是否在队列中
    int d[N];//距离
    int p[N];//上一条弧
    int a[N];//可改进量

    void init(int n)//初始化
    {
        this->n=n;
        for(int i=0;i<n;i++)
            G[i].clear();
        edges.clear();
    }

    void addedge(int from,int to,int cap,int cost)//加边
    {
        //printf("add %d %d %d %d\n", from,to,cap,cost);
        edges.push_back(Edge(from,to,cap,0,cost));
        edges.push_back(Edge(to,from,0,0,-cost));
        int m=edges.size();
        G[from].push_back(m-2);
        G[to].push_back(m-1);
    }

    bool SPFA(int s,int t,int &flow,int &cost)//寻找最小费用的增广路，使用引用同时修改原flow,cost
    {
        for(int i=0;i<n;i++)
            d[i]=INF;
        memset(inq,0,sizeof(inq));
        d[s]=0;inq[s]=1;p[s]=0;a[s]=INF;
        queue<int> Q;
        Q.push(s);
        while(!Q.empty())
        {
            int u=Q.front();
            Q.pop();
            inq[u]--;
            for(int i=0;i<G[u].size();i++)
            {
                Edge& e=edges[G[u][i]];
                if(e.cap>e.flow && d[e.to]>d[u]+e.cost)//满足可增广且可变短
                {
                    d[e.to]=d[u]+e.cost;
                    p[e.to]=G[u][i];
                    a[e.to]=min(a[u],e.cap-e.flow);
                    if(!inq[e.to])
                    {
                        inq[e.to]++;
                        Q.push(e.to);
                    }
                }
            }
        }
        if(d[t]==INF) return false;//汇点不可达则退出
        flow+=a[t];
        cost+=d[t]*a[t];
        int u=t;
        while(u!=s)//更新正向边和反向边
        {
            edges[p[u]].flow+=a[t];
            edges[p[u]^1].flow-=a[t];
            u=edges[p[u]].from;
        }
        return true;
    }

    int MincotMaxflow(int s,int t)
    {
        int flow=0,cost=0;
        while(SPFA(s,t,flow,cost));
        //printf("flow = %d\n", flow);
        return cost;
    }
} G;
int n,m,k,c,d;
int a[52],has[52][52];
pair<int,int> e[N];
int id(int x,int t) {
    return x*102+t;
}
void build() {
    int S=id(k,102)+1,T=S+1;
    G.init(T+1);
    for(int i=1;i<=k;i++){
        G.addedge(S,id(a[i],0),1,0);
    }
    for(int i=1;i<=k;i++){
        for(int t=0;t<101;t++){
            for(int j=1;j<=k;j++){
                //if(t>=80) continue;
                if(j==i) G.addedge(id(i,t),id(i,t+1),k,0);
                else {
                    if(has[i][j]==0) continue;
                    for(int x=1;x<=k;x++) G.addedge(id(i,t),id(j,t+1),1,(2*x-1)*d);
                }
            }
        }
    }
    for(int i=1;i<101;i++){
        //if(i>=80) continue;
        G.addedge(id(1,i),T,1,i*c);
    }
    cout << G.MincotMaxflow(S,T) << endl;
}
int main() {
    scanf("%d%d%d%d%d",&n,&m,&k,&c,&d);
    for(int i=1;i<=k;i++) {
        scanf("%d",&a[i]);
    }
    for(int i=1;i<=m;i++) {
        int u,v; scanf("%d%d",&u,&v);
        has[u][v]=has[v][u]=1;
    }
    build();
}


// while (clock()<=69*CLOCKS_PER_SEC)
// #pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define pb push_back
#define SZ(x) ((int)(x).size())
#define ALL(x) x.begin(),x.end()
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define _upgrade ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define erase_duplicates(x) sort(all(x)); (x).resize(distance((x).begin(), unique(all(x))));

using namespace std;
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<
T,
null_type,
less<T>,
rb_tree_tag,
tree_order_statistics_node_update>;

//X.find_by_order(k); - zwraca iterator na k-ty element (numeracja od zerowego)
//X.order_of_key(k); - zwraca liczbę elementów ostro mniejszych niż k

typedef long long LL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
typedef vector<PII> VPII;
typedef vector<PLL> VPLL;
typedef vector<LL> VLL;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef long double LD;
typedef pair<LD,LD> PLD;
typedef vector<LD> VLD;
typedef vector<PLD> VPLD;

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<" = "<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;
  cerr<<" = "<<h<<", "; _dbg(sdbg+1, a...);
}

#ifdef LOCAL
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define dbg(...)
#define cerr if(0)cout
#endif

const int maxn = (1e6)+7;
const int maxk = 20;
const int inf = (1e9)+7;
const LL LLinf = ((LL)1e18)+7LL;
const LD eps = 1e-9;
const LL mod = 1e9+7;

// ***************************** CODE ***************************** //
#define FOR(i, n) for(int i = 0;i < n;i++)
#define REMIN(a, b) a = min(a, b);

namespace MCF {
   #define MAXN 100010
   #define MAXM 100010
   #define wint LL
   #define cint LL
   const wint wEPS = 0;
   const wint wINF = 1001001001;
   const cint cEPS = 0;
   const cint cINF = 1001001001;
   int n, m, ptr[MAXN], nxt[MAXM], zu[MAXM];
   wint capa[MAXM], tof;
   cint cost[MAXM], toc, d[MAXN], pot[MAXN];
   int vis[MAXN], pree[MAXN];
   void init(int _n) {
      n = _n+2; // na wszelki wypadek
      m = 0;
      memset(ptr, ~0, n << 2);
   }
   void ae(int u, int v, wint w, cint c) {
      nxt[m] = ptr[u]; ptr[u] = m; zu[m] = v; capa[m] = w; cost[m] = +c; ++m;
      nxt[m] = ptr[v]; ptr[v] = m; zu[m] = u; capa[m] = 0; cost[m] = -c; ++m;
   }
   bool spRep(int src, int ink, wint flo = wINF) { // wynik to (tof,toc)
      wint f;
      cint c, cc;
      int i, v;
      memset(pot, 0, n * sizeof(cint));
   //*
      for (bool cont = 1; cont; ) {
         cont = 0;
         FOR(u,n) for (i = ptr[u]; ~i; i = nxt[i]) if (capa[i] > wEPS) {
            if (pot[zu[i]] > pot[u] + cost[i] + cEPS) {
               pot[zu[i]] = pot[u] + cost[i]; cont = 1;
            }
         }
      }
   //*/
      for (toc = 0, tof = 0; tof + wEPS < flo; ) {
         typedef pair<cint,int> node;
         priority_queue< node,vector<node>,greater<node> > q;
         FOR(u,n) { d[u] = cINF; vis[u] = 0; }
         for (q.push(mp(d[src] = 0, src)); !q.empty(); ) {
            c = q.top().first; int u = q.top().second; q.pop();
            if (vis[u]++) continue;
            for (i = ptr[u]; ~i; i = nxt[i]) if (capa[i] > wEPS) {
               cc = c + cost[i] + pot[u] - pot[v = zu[i]];
               if (d[v] > cc) { q.push(mp(d[v] = cc, v)); pree[v] = i; }
            }
         }
         if (!vis[ink]) return 0;
         f = flo - tof;
         for (v = ink; v != src; v = zu[i ^ 1]) { i = pree[v];
              REMIN(f, capa[i]); }
         for (v = ink; v != src; v = zu[i ^ 1]) { i = pree[v];
              capa[i] -= f; capa[i ^ 1] += f; }
         tof += f;
         toc += f * (d[ink] - pot[src] + pot[ink]);
         FOR(u,n) pot[u] += d[u];
      }
      return 1;
   }
}

int pocz[maxn];

int main()
{
	_upgrade
  int n, m, k, c, d;
  cin>>n>>m>>k>>c>>d;
  for(int i = 1;i <= k;i++)
    cin>>pocz[i];
  VPII wek;
  for(int i = 1;i <= m;i++)
  {
    int a, b;
    cin>>a>>b;
    wek.pb({a, b});
    wek.pb({b, a});
  }
  MCF::init(n);
  int cur = 1;
  for(int i = 1;i <= k;i++)
    MCF::ae(0, pocz[i] + 1, 1, 0);
  int stala = 100;
  for(int ii = 1;ii <= stala;ii++)
  {
    for(auto s : wek)
      for(int i = 1;i <= 2 * n;i += 2)
        MCF::ae(cur + s.fi, cur + n + s.se, 1, d * i);
    for(int i = 1;i <= n;i++)
      MCF::ae(cur + i, cur + n + i, n, 0);
    MCF::ae(cur + 1, 1, n, 0);
    cur += n;
  }
  MCF::spRep(0, 1);
  cout<<MCF::toc;

	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
void Solve(); int main() { Solve(); }
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <iomanip>
#include <bitset>

using namespace std;
#define int long long
#define endl '\n'
#define fib(i, n) for (int i = n; i >= 0; i--)
#define fi(i,a,b) for(int i = (a); i < (b); i++)
#define MAX 1 << 10
#define pb push_back
const int N = 1e5 + 10;
int n, m, p[100005], ans;
int t[200005], lis[100005], lds[100005];
void modify(int P, int val) {
	for (t[P += m + 1] = val; P>1; P >>= 1) t[P >> 1] = max(t[P], t[P ^ 1]);
}
int query(int l, int r) {
	int res = 0;
	for (l += m + 1, r += m + 2; l<r; l >>= 1, r >>= 1) {
		if (l & 1) res = max(res, t[l++]);
		if (r & 1) res = max(res, t[--r]);
	}
	return res;
}
void Solve() {
	cin >> n >> m;
	fi(i, 0, n) {
		int L, R;
		cin >> L >> R;
		p[L]++;
		p[R + 1]--;
	}
	fi(i, 1, m + 1) {
		p[i] += p[i - 1];
	}
	for (int i = m; i >= 1; i--) {
		int h = query(p[i], m) + 1;
		modify(p[i], h);
		lis[i] = h;
	}
	memset(t, 0, sizeof t);
	fi(i, 1, m + 1) {
		int h = query(0, p[i]) + 1;
		modify(p[i], h);
		lds[i] = h;
	}
	fi(i, 1, m + 1) {
		ans = max(ans, lis[i] + lds[i] - 1);
	}
	cout << ans << endl;
}


#include <bits/stdc++.h>

//#define int long long

using namespace std;

int INF = int(2e9), n, m, l, r, k = 0, maxk = 0;

vector < int > calc(vector < int > &a)
{
    vector < int > d(m + 1, INF), ans(m, 0);
    d[0] = -INF;
    for(int i = 0; i < m; i++)
    {
        int j = int(upper_bound(d.begin(), d.end(), a[i]) - d.begin());
        d[j] = a[i];
        ans[i] = j;
    }
    return ans;
}
vector < int > rev_calc(vector < int > &a)
{
    vector < int > b = a;
    reverse(a.begin(), a.end());
    b = calc(b);
    reverse(b.begin(), b.end());
    return b;
}

signed main()
{
    cin >> n >> m;
    vector < pair < int, int > > lr(m + 1, {0, 0});
    for(int i = 0; i < n; i++)
    {
        cin >> l >> r;
        lr[l - 1].first++;
        lr[r - 1].second++;
    }
    vector < int > a(m, 0);
    for(int i = 0; i < m; i++)
    {
        k += lr[i].first;
        a[i] = k;
        k -= lr[i].second;;
    }
    vector < int > d1 = calc(a), d2 = rev_calc(a);
    for(int i = 0; i < m; i++)
        maxk = max(d1[i] + d2[i], maxk);
    cout << maxk - 1;
    return 0;


#define _CRT_SECURE_NO_WARNINGS
void Solve(); int main() { Solve(); }
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <iomanip>
#include <bitset>

using namespace std;
#define int long long
#define endl '\n'
#define fib(i, n) for (int i = n; i >= 0; i--)
#define fi(i,a,b) for(int i = (a); i < (b); i++)
#define MAX 1 << 10
#define pb push_back

const int MAXN = 100007;
int a[MAXN], addmark[MAXN], dp[MAXN], lis[2][MAXN], slis[MAXN];
int cnt = 0;
void Solve() {
	int n, m;
	cin >> n >> m;
	for (int i = 0; i<n; i++) {
		int l, r;
		cin >> l >> r;

		addmark[l]++;
		addmark[r + 1]--;
	}
	int sum = 0;
	for (int i = 1; i <= m; i++) {
		sum += addmark[i];
		a[i] = sum;
	}

	memset(dp, 63, sizeof(dp));
	for (int i = 1; i <= m; i++) {
		int pos = upper_bound(dp, dp + i, a[i]) - dp;
		dp[pos] = a[i];
		lis[0][i] = pos + 1;
	}
	memset(dp, 63, sizeof(dp));
	for (int i = m; i >= 1; i--) {
		int pos = upper_bound(dp, dp + m - i + 1, a[i]) - dp;
		dp[pos] = a[i];
		lis[1][i] = pos + 1;
		slis[i] = max(slis[i + 1], pos + 1);
	}
	int ans = 0;
	for (int i = 1; i <= m; i++) {
		ans = max(ans, lis[0][i] + slis[i + 1]);
	}
	cout << ans << endl;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>

using namespace std;

uint32_t next(uint32_t x) {
    --x;
    x |= x >> 1;
    x |= x >> 2;
    x |= x >> 4;
    x |= x >> 8;
    x |= x >> 16;
    return x + 1;
}
class ST
{
    private:
        int n;
        vector<int> t;
    public:
        ST(int N) {
            n = next(N);
            t.resize(2*n, 0);
        }
    int get_max(int l, int r) {
        int ans = 0;
        l += n, r += n;
        while (l <= r) {
            if (l & 1)
                ans = max(ans, t[l]);
            if (!(r & 1))
                ans = max(ans, t[r]);
            l = (l + 1) / 2, r = (r - 1) / 2;
        }
        return ans;
    }
    void update(int i, int x) {
        int j = i + n;
        t[j] = x;
        while (j /= 2)
            t[j] = max(t[2*j], t[2*j+1]);
    }
};
int n, m;
vector<int> dp(vector<int> a) {
    vector<int> d(m);
    ST Myst(n+1);
    for (int i = 0; i < m; ++i) {
        d[i] = Myst.get_max(0, a[i])+1;
        Myst.update(a[i], d[i]);
    }
    return d;
}

int main()
{
    ios::sync_with_stdio(0); cin.tie(nullptr);
    int l, r;
    cin >> n >> m;
    STsum SUM(m);
    vector<int> used(m, 0);
    for (int i = 0; i < n; ++i) {
        cin >> l >> r;
        --l, --r;
        ++used[l];
        if (r < m-1) --used[r+1];
    }
    vector<int> a(m);
    for (int i = 0; i < m; ++i)
        if (i)
            a[i] = a[i-1]+used[i];
        else
            a[i] = used[i];
    vector<int> dp_1 = dp(a);
    reverse(a.begin(), a.end());
    vector<int> dp_2 = dp(a);
    int sum = 0;
    for (int i = 0; i < m; ++i) {
        sum = max(sum, dp_1[i]+dp_2[m-i-1]-1);
    }
    cout << sum;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int c[101],a[101];
int k,n,x,maxn=0;
int main(){
 	cin>>n>>k;
 	for(int i=1;i<=n;i++){
 		cin>>a[i];
 		c[i%k]+=a[i];
 		c[k]+=a[i];
	}
	abs(c[k]);
	for(i=0;i<k;i++) maxn=max(maxn,abs(c[k]-c[i%k]));
	cout<<maxn;
 	return 0;
}


#include <iostream> int main() { hoge; }


import sublime
import sublime_plugin
import os
import sys
import time

''' Change this directory name by your python directory '''
pathToPython = "/home/light/.local/lib/python3.6/site-packages/"
sys.path.append(pathToPython)

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys

def process(string):

	# Get active file name
	filename = sublime.active_window().active_view().file_name()
	contestid, problem = string.strip().split()

	# Change executor_url according to your preference
	executor_url = "127.0.0.1:9222" # change 9222 to the port you have used.
	url = "codeforces.com/contest/" + contestid + "/problem/" + problem

	_chrome_options = Options()
	_chrome_options.add_argument('disable-infobars')
	_chrome_options.add_argument("--start-maximized")
	_chrome_options.add_experimental_option("debuggerAddress", executor_url)
	try:
		driver = webdriver.Chrome(chrome_options = _chrome_options)
		driver.implicitly_wait(30)

		try:
			driver.get("http://" + url.rstrip())
			driver.find_element_by_name("sourceFile")
			driver.find_element_by_css_selector('input[type="file"]').clear()
			driver.find_element_by_css_selector('input[type="file"]').send_keys(filename.rstrip()) # Send File to Codeforces
			driver.find_element_by_class_name("submit").click() # Click on submit button
		except Exception as e:
			''' In case Codeforces is too busy or File is untitled.'''
			sublime.error_message('Either Codeforces is too busy or File is Untitled.')
	except Exception as e:
		''' In case Server is not active. '''
		sublime.error_message('Server is not active.')
class SolveItCommand(sublime_plugin.TextCommand):
	def run(self, edit):
		window = self.view.window()
		''' Input Panel to get Contest ID and Problem Id from the user '''
		window.show_input_panel("Enter ContestID & ProblemID : ", "", self.on_done, self.on_change, self.on_cancel)

	def on_done(self, input_data):
		process(input_data)
		pass

	def on_change(self, input_data):
		pass

	def on_cancel(self):
		pass


#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#define REP(i,n) for(int(i)=0;(i)<(int)(n);(i)++)
#define REPN(i,n) for((i)=1;(i)<(int)(n);(i)++)
#define _abs(x) ((x)>0?(x):-(x))
#define ll  long long
using namespace std;
int main()
{
    int sum=0,ans=0,n,k,e,s;
    cin>>n>>k;
    int a[n];
    REP(i,n)
    {
        cin>>a[i];
        if(a[i]==1)
        {
                sum++;
        }
        else
        {
                ans++;
        }
    }
    //cout<<sum<<" "<<ans<<endl;
    if(sum>ans)
    {
        cout<<sum-ans<<endl;
    }
    else
    {
        cout<<ans<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#define MAX 1000000000 ;
using namespace std ;
int n;
int main (){
     int k,cnt=0,dp[n];
     cin>>n>>k ;
     int in[n];
     for (int i=0 ; i<n ;i++)cin>>in[i];
        int ans=MAX ;
        for (int i=0 ; i<n ;i++)
         ans=min(ans , in[i]/k) ;
         cout<<ans<<endl;

    return 0 ;


#include <bits/stdc++.h>
using namespace std;
int n,k,i,min=10000,ans=0,t;
int main()
{
    cin>>n>>k;
    for(i=0;i<n;i++)
    {
        cin>>t;
        if(k%t==0)
        {
            ans=k/t;
            if(ans<min) min=ans;
        }
    }
    cout<<min;
    return 0;
}


#include <algorithm>
#include <iostream>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cstdio>
#include <string>
#include <vector>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;

int __gcd(int x, int y) { if(!y) return x; return __gcd(y, x % y); }

#define foreach(i,x) for(type(x)i=x.begin();i!=x.end();i++)
#define FOR(ii,aa,bb) for(int ii=aa;ii<=bb;ii++)
#define ROF(ii,aa,bb) for(int ii=aa;ii>=bb;ii--)

#define sag (k + k + 1)
#define sol (k + k)

#define type(x) __typeof(x.begin())

#define orta ((bas + son) >> 1)
#define sag (k + k + 1)
#define sol (k + k)

#define pb push_back
#define mp make_pair

#define nd second
#define st first

#define endl '\n'

typedef pair < int ,int > pii;

typedef long long ll;

const long long linf = 1e18+5;
int mod = (int) 1e9 + 7;
const int logN = 18;
const int inf = 1e9 + 9;

const int N = 4e5 + 6;

int main() {
	int n, k, ans = inf;
	scanf("%d %d", &n, &k);
	FOR(i, 1, n) {
		scanf("%d", &x);
		if(n % x == 0)
			ans = min(ans, k / x);
	}
	cout << ans;

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
struct ss
{
	long long aa,ab;
};
void srt(const ss &lhs, const ss &rhs)
{
	return lhs.aa<rhs.aa;
}
int main()
{
	int n,k;
	cin>>n>>k;
	int sum=INT_MAX;int x;
	for(int i=0;i<n;i++)
	{
		cin>>x;
		if(k%x==0)
		{
			if((k/x)<sum)
			sum=(k/x);
		}
	}
	cout<<sum<<endl;
}


#include<iostream>

using namespace std;

long long pow(int x, int y) {
    if(y == 0)
        return 1;
    long long res = pow(x, y/2);
    if(y%2)
        return res*res*a;
    else
        return res*res;
}

int main()  {
    long long n;
    cin >> n;
    cout << 4*(n-1)*pow(3, n-2);
    return 0;
}


#include <bits/stdc++.h>
//#include "Header.h"

#define pi 3.14159265358979323846264

#define ll long long
#define fori(n) for(long long i=0;i<n;i++)
#define forj(n) for(long long j=0;j<n;j++)

#define sp(n) setprecision(n)

using namespace std;

int isPrime(long long k){
    if(k<=1){
        return 0;
    }
    if(k==2){
        return 1;
    }
    if(k%2==0){
        return 0;
    }
    long long i = 3;

    while (i*i <= k) {
        if (k % i == 0) {
            return 0;
        }
        i += 2;
    }
return 1;
}

ll binomialCoeff(ll n, ll k)
{
    ll C[n + 1][k + 1];
    ll i, j;
    for (i = 0; i <= n; i++)
    {
        for (j = 0; j <= min(i, k); j++)
        {if (j == 0 || j == i)
                C[i][j] = 1;
            else
                C[i][j] = C[i - 1][j - 1] +
                          C[i - 1][j];
        }
    }
    return C[n][k];
 }

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

int main(int argc, const char * argv[]) {
 //cout<<"Om\n";
 //Praise to Lord
 //make cin/cout faster
 ios_base::sync_with_stdio(false);
 cin.tie(NULL);
 //code now

    ll n;
    cin>>n;
    if(n==3){cout<<24;
    }
    else {cout<<(3*(3n-1)*((ll)pow((double)4,n-3)));}

    return 0;
}


#include <iostream>
using namespace std;
int main() {
  int x;
  cin >> x;
  int total = 2*x-2, fact=1;
  for (int i=1;i=<x-2;i++)
    fact*=i;
  cout << (x-3)*3*4*fact;
  return 0;
}


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

int main(){
#pragma warning(disable : 4996)
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
    double n;
    cin>>n;
    n=24*((long long int)2<<(2*n-6))+(n-3)*4*9*((long long int)2<<(2*n-8));
    cout<<n;

return 0;
}


#include<bits/stdc++.h>
#include<iostream>
#define pb push_back
#define ll long long
#define ff first
#define ss second
#define endl "\n"
#define mod 1000000007
#define MAX 2001
using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	ll int m;
	cin>>m;
	for(int i=1; i<=100000; i+=5) {
		ll int ans = 0;
		ll int j = 1;
		while((i/pow(5, j)) > 0) {
			ans += i/pow(5, j);
			j++;
		}
		if(ans > m)
			break;
		if(ans == m){
			flag = 1;
			cout<<5<<endl;
			cout<<i<<" "<<i+1<<" "<<i+2<<" "<<i+3<<" "<<i+4<<endl;
			break;
		}
	}
	if(!flag)
		cout<<0<<endl;
	return 0;
}


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

using namespace std;

#define pt pair<double, double>
#define X first
#define Y second

const int NMAX = 100 + 10;

long long cntZero(long long x) {
	long long ans = 0;
	while (x % 10 == 0) {
		ans++;
		x /= 10;
	}
	return ans;
}

long long pow5(long long x) {
	long long st = 1;
	long long y = 5;
	while (y < x) {
		st++;
		y *= 5;
	}
	if (y > x) {
		st = 1;
	}
	return st;
}

long long m;
long long st = -1, end = -1;

long long n = 0;
long long zero = 0;

int main() {

	cin >> m;

	while (true) {
		n += 5;
		if (n % 10 == 5) {
			zero += pow5(n);
		} else {
			zero += cntZero(n);
		}
		if (zero == m) {
			st = n;
		}
		if (zero > m) {
			end = n;
			break;
		}
	}
	if (st == -1) {
		cout << 0;
	} else {
		cout << end - st << endl;
		for (int i = st; i < end; ++i) {
			cout << i << " ";
		}
	}
	cout << endl;

	printf("\n");
	return 0;
}


#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
inline int zero(int n){
	int a=0;
	while(n!=0){
		a+=n/5;
		n/=5;
	}
	return a;
}
int main(){
	int m;
	vector<int> v;
	cin>>m;
	for(int i=1;i<5*m+5;i++){
		if(zeros(i)==m){
			v.push_back(i);
		}
	}
	cout<<v.size()<<endl;
	for(int i=0;i<v.size();i++){
		cout<<v[i]<<" ";
	}
	return 0;
}


#include<bits/stdc++.h>
using namespaces std;
int main()
{
    unsigned long long i,j,n,m,count=0;;
    cin>>m;

    for(i=5;;i+=5)
    {
        j=i;
        n=5;
        count=0;
        while(j/n)
        {
            count++;
            n*=5;
        }
        if(count==m)
         {
             for(int k=0;k<5;k++)
               cout<<j<<" ";
         }
    }

}


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

int a,b,c;

int SumHalf(int n)
{
    if(2*n>a)
        return 0;
    else return 1;
}

int SumOne(int n)
{
    int sum=0;
    for(int i=0; i<b && n>=0; i++, n--)
        sum+=SumHalf(n);
    return sum
}

int SumTwo(int n)
{
    int sum=0;
    for(int i=0; i<c && n>=0; i++, n--)
        sum+=SumOne(n);
    return sum;
}

int main()
{
    int n;
    cin>>n>>a>>b>>c;
    cout<<SumTwo(n);
}


#include <iostream>
using namespace std;
int main()
{
	int t=0,n,i,j,k,a,b,c;
	t=0;
	cin>>n>>a>>b>>c;
	for(i=0;i<=a;i+=2)
	for(j=0;j<=b;j++)
	for(k=0;k<=c;k++)
	{
		if(i/2+j+2*k==n) t++,break;
	}
	cout<<t<<endl;
	return 0;
}


//package school2;

import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

public class B {
	Scanner in;
	PrintWriter out;
//	String INPUT = "10000 5000 5000 5000";
	String INPUT = "";

	void solve()
	{
		int n = ni();
		int a = ni();
		int b = ni();
		int c = ni();

		int[] dp = new int[2*n+1];
		dp[0] = 1;
		int[] dpa = new int[2*n+1];
		for(int i = 0;i <= 2 * n;i++){
			for(int j = 0;j <= a && i + j <= 2 * n;j++){
				dpa[i + j] += dp[i];
			}
		}
		int[] dpb = new int[2*n+1];
		for(int i = 0;i <= 2 * n;i++){
			for(int j = 0;j <= b && i + 2 * j <= 2 * n;j++){
				dpb[i + 2 * j] += dpa[i];
			}
		}
		int[] dpc = new int[2*n+1];
		for(int i = 0;i <= 2 * n;i++){
			for(int j = 0;j <= c && i + 4 * j <= 2 * n;j++){
				dpc[i + 4 * j] += dpb[i];
			}
		}

		out.println(dpc[2*n]);
	}

	void run() throws Exception
	{
		in = INPUT.isEmpty() ? new Scanner(System.in) : new Scanner(INPUT);
		out = new PrintWriter(System.out);

		solve();
		out.flush();
	}

	public static void main(String[] args) throws Exception
	{
		new B().run();
	}

	int ni() { return Integer.parseInt(in.next()); }
	void tr(Object... o) { if(INPUT.length() != 0)System.out.println(o.length > 1 || o[0].getClass().isArray() ? Arrays.deepToString(o) : o[0]); }
}


#include <iostream>
#include <string>
#include <set>
#include <algorithm>
#include <stdlib.h>
#include <stdio.h>
#include <cctype>
#include <map>
#include <vector>
#include <string>
using namespace std;

int main() {
    int n,a,b,c;
    cin>>n>>a>>b>>c;
    c /= 2;
    long long ans = 0;
   // cout<<a<<" "<<b<<" "<<c<<endl;
    int last = 0;
    for (int i = 0; i <= min(a, n / 2); i++)
    {
        for (int j = 0; j <= (n - 2 * i); j++)
        {
            int tmp = (n - (2 * i + j));
            if (tmp <= c && j <= b)  ans++;
            if (tmp <= b && j <= c)  ans++;
            /*if (last != ans) {
                cout << i << " " << j << " " << tmp << endl;
                last = ans;
            }*/

        }
    }
    cout<<max(ans / 2, 1)<<endl;
    return 0;
}


#include<bits/stdc++.h>

using namespace std;
long long n,x,y;
bool check;

void input()
{
	cin>>n>>x>>y;
}

void fix (long long a,long long b)
{
	if (a >= b)
	{
		int temp = a;
		a = b;
		b = temp;
	}
}

void fin()
{
	fix (x,y);
	int w=0,b=0;
	w = y - 1;
	b = n - x;
	cout<<w<<endl<<b<<endl;
	if (w <= b) check = true;
	else check =  false;
}

void output()
{
	if (a >= 0 && b >= 0)
	{
		if (check) cout<<"White";
		else cout<<"Black";
	}
	else
	{
		if (check) cout<<"Black";
		else cout<<"White";
	}

}
main()
{
	input();
	fin();
	output();
	return 0;
}


#include <iostream>

using namespace std;

bool compareD(int y, int x, int n)
{
	float d1 = sqrt((x - 1)*(x - 1) + (y - 1)*(y - 1));
	float d2 = sqrt((n - x)*(n - x) + (n - y)*(n - y));
	return d1 >= d2;
}

int main()
{
	int n, x, y;
	cin >> n;
	cin >> x >> y;
	if (compareD(x, y, n))
		cout << "White";
	else
		cout << "Black";
	return 0;
}


#include<iostream>
#include<bits/stdc++.h>
#define max *maximum_element
namespace std
int main(){
int n,x,y; cin>>n>>x>>y;
if(max(x,y)<=max(n-x,n-y)) cout<<"White\n";
else cout<<"Black\n";
}


#include<iostream>
using namespace std;

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

    int B = n-a < n-b? n-a:n-b;
    int W = a-1 < b-1? a-1:b-1;

    cout << W <= B? "White":"Black";

    return 0;
}


#define N 205
#define M 100005
#define maxn 205
#define MOD 1000000000000000007
int t,s,q;
int main()
{
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
     while(S2(t,s)!=EOF)
    {
        S(q);
        int ans = 0;
        while(s < t){
            s = s * q;
            ans++;
        }
        printf("%d\n",ans);
    }
    //fclose(stdin);
    //fclose(stdout);
    return 0;
}


#include <iostream>
using namespace std;

int main()
{
    int  t, s, q, x=0 ;
    cin >> t >> s >> q;

    int x=0;
    while( s < t )
    {
        x++ ;
        s = s * q ;
        // s * = q ;
    }
        cout << x ;
}


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

int main()
{
    double t,s,q;
    cin >> t >> s >> q;

    double v = q-1/q;
    int ans=0;
    double total = 0;
    do{
        ans++;
        total += (1-v)*total;
    }while(total < t)

    cout << ans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    //freopen("inp.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    ios_base::sync_with_stdio(false);

    LL t,s,q;
    LL ans = 1;

    cin>>t>>s>>q;

    while( ( s + (s*(q-1)) ) < t )
    {
        ans++;
        s += (s*(q-1));
    }

    cout<<ans<<endl;

return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define db long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define IT iterator

#define PB push_back
#define MK make_pair
#define LB lower_bound
#define UB upper_bound
#define EB emplace_back
#define fi first
#define se second

#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define UPD(x,y) (((x)+=(y))>=mo?x-=mo:233)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));

#define LS3 k*2,l,mid
#define RS3 k*2+1,mid+1,r
#define LS5 k*2,l,mid,x,y
#define RS5 k*2+1,mid+1,r,x,y
#define GET pushdown(k);int mid=(l+r)/2

#define inf 1<<30
#define sqr(x) ((x)*(x))
using namespace std;
const int N=100005;
int inv[N],n,k,mo,ans;
map<int,int> mp;
void get(int n,int k){
	if (k==1||n==1) mp[n]++;
	else get(n/2,k-1),get(n-n/2,k-1);
}
int calc(int x,int y){
	int ans=1ll*x*y%mo*(mo+1)/2%mo;
	For(i,1,y) ans=(ans+mo+1ll*inv[i]-inv[i+x])%mo;
	return ans;
}
int main(){
	scanf("%d%d%d",&n,&k,&mo);
	inv[0]=inv[1]=1;
	For(i,2,n) inv[i]=1ll*inv[mo%i]*(mo-mo/i)%mo;
	For(i,1,n) inv[i]=(inv[i]+inv[i-1])%mo;
	get(n,k);
	for (auto a:mp){
		ans=(ans+1ll*a.fi*(a.fi-1)/2%mo*(mo+1)/2%mo*a.se)%mo;
		ans=(ans+1ll*a.se*(a.se-1)/2%mo*calc(a.fi,a.fi))%mo;
		for (auto b:mp) if (a.fi<b.fi)
			ans=(ans+1ll*calc(a.fi,b.fi)*a.se%mo*b.se)%mo;
	}
	printf("%d",ans);
}


.#include<bits/stdc++.h>
using namespace std;
const int N=1e5+7;
int n,k,p,cnt[N]; long long ifac[N];
inline void solve(int l,int r,int t){
	if(t==1||l==r) {cnt[r-l+1]++; return;}
	int d=(l+r)>>1; solve(l,d,t-1),solve(d+1,r,t-1);
}
inline long long getans(int a,int b){
	long long sum=(p+1)/2,ans=sum*a%p*b%p;
	for(int i=1;i<=a;i++) ans=(ans-ifac[i+b]+ifac[i])%p;
	return (ans+p)%p;
}
int main(){
	cin>>n>>k>>p,ifac[0]=ifac[1]=1;
	for(int i=2;i<=n;i++) ifac[i]=ifac[p%i]*(p-p/i)%p;
	for(int i=1;i<=n;i++) ifac[i]=(ifac[i]+ifac[i-1])%p;
	solve(1,n,k); int a=0,b=0;
	for(int i=1;i<=n;i++) if(cnt[i]&&!a) a=i; else if(cnt[i]) b=i;
	long long s=getans(a,a)*((1ll*cnt[a]*(cnt[a]-1)/2)%p)%p;
	s=(s+getans(b,b)*((1ll*cnt[b]*(cnt[b]-1)/2)%p))%p;
	s=(s+getans(a,b)*cnt[a]%p*cnt[b]%p)%p;
	s=(s+(1ll*a*(a-1)/2*cnt[a]%p+1ll*b*(b-1)/2*cnt[b]%p)%p*((p+1)/2))%p;
	cout<<s<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
template<class t> inline t read(t &x){
	char c=getchar();bool f=0;x=0;
	while(!isdigit(c)) f|=c=='-',c=getchar();
	while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
	if(f) x=-x;return x;
}
template<class t,class ...A> inline void read(t &x,A &...a){
	read(x);read(a...);
}
template<class t> inline void write(t x){
	if(x<0) putchar('-'),write(-x);
	else{if(x>9) write(x/10);putchar('0'+x%10);}
}

#define int long long

const int N=1e5+5;
int ans,a1,a2,b1,b2,n,k,inv[N<<1],mod;

int fpow(int x,int y){
	int res=1;
	for(;y;y>>=1,x=x*x%mod) if(y&1) res=res*x%mod;
	return res;
}

void dico(int l,int r,int h){
	if(h==1||l==r){
		l=r-l+1;
		if(!a1) a1=l,b1=1;
		else if(a1==l) b1++;
		else a2=l,b2++;
		return ;
	}
	int mid=l+r>>1;
	dico(l,mid,h-1);
	dico(mid+1,r,h-1);
}

int calc(int n,int m){
	int res=0;
	for(int i=2;i<=n+m;i++) res=(res+inv[i]*min(i-1,n+m-i+1)%mod)%mod;
	return mod-res;
}

void init(int n){
	inv[1]=1;for(int i=2;i<=n;i++) inv[i]=(mod-mod/i)*inv[mod%i]%mod;
}

signed main(){
	read(n,k,mod);ans=n*(n-1)/2*(mod+1>>1))%mod;
	init(n<<1);
	dico(1,n,k);
	ans=(ans+b1*(b1-1)/2*calc(a1,a1)%mod)%mod;
	if(a2){
		ans=(ans+b2*(b2-1)/2*calc(a2,a2)%mod)%mod;
		ans=(ans+b1*b2%mod*calc(a1,a2)%mod)%mod;
	}
	write(ans);
}


#include <bits/stdc++.h>
using namespace std;
template<class t> inline t read(t &x){
	char c=getchar();bool f=0;x=0;
	while(!isdigit(c)) f|=c=='-',c=getchar();
	while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
	if(f) x=-x;return x;
}
template<class t,class ...A> inline void read(t &x,A &...a){
	read(x);read(a...);
}
template<class t> inline void write(t x){
	if(x<0) putchar('-'),write(-x);
	else{if(x>9) write(x/10);putchar('0'+x%10);}
}

#define int long long

const int N=1e5+5,i2=mod+1>>1;
int ans,a1,a2,b1,b2,n,k,inv[N<<1],mod;

int fpow(int x,int y){
	int res=1;
	for(;y;y>>=1,x=x*x%mod) if(y&1) res=res*x%mod;
	return res;
}

void dico(int l,int r,int h){
	if(h==1||l==r){
		l=r-l+1;
		if(!a1) a1=l,b1=1;
		else if(a1==l) b1++;
		else a2=l,b2++;
		return ;
	}
	int mid=l+r>>1;
	dico(l,mid,h-1);
	dico(mid+1,r,h-1);
}

int calc(int n,int m){
	int res=0;
	for(int i=2;i<=n+m;i++) res=(res+inv[i]*min(i-1,n+m-i+1)%mod)%mod;
	return mod-res;
}

void init(int n){
	inv[1]=1;for(int i=2;i<=n;i++) inv[i]=(mod-mod/i)*inv[mod%i]%mod;
}

signed main(){
	read(n,k,mod);ans=n*(n-1)/2*i2%mod;
	init(n<<1);
	dico(1,n,k);
	ans=(ans+b1*(b1-1)/2*calc(a1,a1)%mod)%mod;
	if(a2){
		ans=(ans+b2*(b2-1)/2*calc(a2,a2)%mod)%mod;
		ans=(ans+b1*b2%mod*calc(a1,a2)%mod)%mod;
	}
	write(ans);
}


#include<iostream>
using namespace std;
main()
{
	int n;
	int a[30];
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	sort(a,a+n);
if(a[n-1]>25)	cout<<a[n-1]-25<<endl;
else cout<<'0'<<endl;
}


#include<bits/stdc++.h>

using namespace std;

int main(){
 int  a,f=0;
 cin>>a;
 int n[a];
 for(int  i=0;i<a;i++){
 	cin>>n[i];
 	if(n[i]>=25){
 		f++;
	 }
	 cout<<f;
 }


#include <iostream>
using namespace std;
int i, amax, k;
main () {
	cin>>k;
	for(i=1; i<=k; i++)
	cin>>a[i];

	amax=a[i];
	for(i=1; i<=k; i++)
	if(a[i]>amax) amax=a[i];
	if(amax>25)

	cout<<amax-25<<endl;
	else cout<<0<<endl;
}


#include<its/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll int n;
    cin>>n;
    l int a[n],max=-1;
    for(ll int i=0;i<n;i++)
    {
        cin>>a[i];
        if(max<a[i])
        max=a[i];
    }
    if(max<=25)
    cout<<"0";
    else
    cout<<max-25;
}


#include <cstdio>
#include <map>
#include <iostream>
#include<cstring>
#include<bits/stdc++.h>
#define ll long long int
#define M 6
using namespace std;
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
int moth[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int dir[4][2]={1,0 ,0,1 ,-1,0 ,0,-1};
int dirs[8][2]={1,0 ,0,1 ,-1,0 ,0,-1, -1,-1 ,-1,1 ,1,-1 ,1,1};
const int inf=0x3f3f3f3f;
const ll mod=1e9+7;
ll l,r;
int bits[20];
ll dp[20][3000][50];
int hash[3000];
void init(){
	memset(dp,-1,sizeof(dp));
	int cnt=0;
	for(int i=1;i<=2520;i++){
		if(2520%i==0) hash[i]=cnt++;
	}
}
ll dfs(int len,int num,int mo,bool ismax){
	if(!len)
	return num%mo==0;
	if(!ismax&&dp[len][num][hash[mo]]>=0)
	return dp[len][num][hash[mo]];
	ll cnt=0;
	int up=ismax?bits[len]:9;
	for(int i=0;i<=up;i++){
		if(i==0) cnt+=dfs(len-1,(num*10+i)%2520,mo,ismax&&i==up);
		else cnt+=dfs(len-1,(num*10+i)%2520,lcm(mo,i),ismax&&i==up);
	}
	if(!ismax) dp[len][num][hash[mo]]=cnt;
	return cnt;
}
ll solve(ll x){
	int pos=0;
	while(x){
		bits[++pos]=x%10;
		x/=10;
	}
	return dfs(pos,0,1,true);
}
int main(){
	ios::sync_with_stdio(false);
	int t;
	cin>>t;
	init();
	while(t--){
		cin>>l>>r;
		cout<<solve(r)-solve(l-1)<<endl;
	}
	return 0;
}


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

using namespace std;

typedef long long LL;

LL dp[20][50][3000];
int d[20],hash[3000];
const int mod = 2520;

int gcd ( int a ,int b )
{
    return !b?a:gcd(b,a%b);
}

void init ( )
{
    memset ( dp , -1 , sizeof ( dp ) );
    int cc = 0;
    for ( int i = 1 ; i <= 8 ; i *= 2 )
        for ( int j = 1; j <= 9 ; j*= 3 )
            for ( int k = 1 ; k <= 5 ; k *= 5 )
                for ( int t = 1; t <= 7 ; t *= 7 )
                    hash[i*j*k*t] = ++cc;
}

LL dfs ( int n , int lcm , int f , int r )
{
    if ( !n ) return r%lcm==0;
    int ll = hash[lcm];
    if ( f && dp[n][ll][r] != -1 )
        return dp[n][ll][r];
    int x = f?9:d[n];
    LL ret = 0;
    for ( int i = 0 ; i <= x ;i++ )
        ret += dfs ( n-1 , i==0?lcm:lcm*i/gcd(lcm,i) , i==x?f:1 , (r*10+i)%mod );
    return f? dp[n][ll][r] = ret : ret;
}

LL solve ( LL x )
{
    int cc = 0;
    while ( x )
    {
        d[++cc] = x%10;
        x /= 10;
    }
    return dfs ( cc , 1 , 0 , 0 );
}

int main ( )
{
    int t;
    LL a,b;
    scanf ( "%d" , &t );
    init ( );
    while ( t-- )
    {
        scanf ( "%lld%lld" , &a , &b );
        printf ( "%lld\n" , solve ( b ) - solve ( a-1 ) );
    }
}


#define Tokisaki return  //¿ñÈýÎÒÀÏÆÅ£¡£¡£¡
#define Kurumi 0;      //¿ñÈýÈü¸ß£¡£¡£¡
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>

using namespace std;

const long long P=2520;
long long T,rnk[P+1];
vector <long long> nums;
long long l,r,f[25][P+1][50];   //ÌØ±ð×¢Òâ£ºDPÊý×éÒ»¶¨Òª¿ªlong longÀàÐÍ£¬²»È»»áÕ¨

inline long long GCD (long long x,long long y) //gcdº¯Êý£¬ËäÈ»STLÀïÃæ×Ô´ø£¨Îª__gcd£©£¬µ«»¹ÊÇ×Ô¼ºÊÖÐ´ÁËÒ»¸ö
{
    if(x>y) swap(x,y);
    if(y%x==0) return x;
    return GCD(x,y%x);
}

inline long long LCM (long long x,long long y)  //lcmº¯Êý£¬Çó×îÐ¡¹«Ô¼Êý
{
    return x*y/GCD(x,y);
}

inline void pre()         //³õÊ¼»¯ÓÃµÄº¯Êý
{
    memset(f,-1,sizeof(f));  //½«DPÊý×é³õÊ¼»¯
    int pos=0;
    for(int i=1;i<=P;i++)   //ÀëÉ¢»¯£¬½«2520µÄÒòÊýÃÇ´Ó1¿ªÊ¼±ê¼Ç
    {
        if(P%i==0)
        {
            pos++;
            rnk[i]=pos;
        }
    }
}

long long dfs(long long pos,long long he,long long lcm,long long sp)  //ÊýÎ»DPÖ÷ÒªÄÚÈÝ
//pos:µ±Ç°´¦Àíµ½µÚ¼¸Î»£»
//he£ºposÎ»Ö®Ç°µÄÊý%2520£»
//lcm£ºposÎ»Ö®Ç°µÄÊýµÄÃ¿Ò»Î»ÊýµÄ×îÐ¡¹«±¶Êý£»
//sp£ºÌØÅÐµ±Ç°ÊÇ·ñÎª·¶Î§ÄÚµÄ×î´óÖµ
{
    if(pos==-1) return he%lcm==0;    //Èç¹û´¦ÀíÍêÁË×îºóÒ»Î»£¬ÊýÈç¹ûÂú×ãÌõ¼þ£¬·µ»Ø1£¬·ñÔò·µ»Ø0
    if(sp==0&&f[pos][he][rnk[lcm]]!=-1) return f[pos][he][rnk[lcm]];      //Èç¹û²»ÊÇ×î´óÖµµÄÇé¿ö£¬²¢ÇÒµ±Ç°Çé¿öÒÔ´¦Àí¹ý£¬Ö±½Ó·µ»ØÖµ
    long long ans=0;
    long long MAX=sp==1?nums[pos]:9;  //Èç¹ûÇ°¼¸Î»ÊÇ×î´óÖµÇé¿ö£¬ÄÇÃ´µ±Ç°Î»×î´óÖµÎªÕâÒ»Î»µÄÊý£¬·ñÔòÎª9
    for(int i=0;i<=MAX;i++)  //´Ó0Ã¶¾Ù
    {
        long long next_he=(he*10+i)%P;  //¼ÆËã°üº¬µ±Ç°Î»Ê±ÊýµÄÖµ
        long long next_lcm=lcm;
        if(i)
        {
            next_lcm=LCM(next_lcm,i);//¼ÆËã°üº¬µ±Ç°Î»Ê±ËùÓÐÎ»ÉÏµÄÊýµÄ×îÐ¡¹«±¶Êý£¨µ±Ç°Î»ËùÑ¡Êý²»Îª0£¬Èç¹ûÎªÁã¾ÍÊÇÔÊý£©
        }
        ans+=dfs(pos-1,next_he,next_lcm,sp&&i==MAX); //ÏòÏÂËÑË÷£¬Èç¹ûÇ°¼¸Î»ÊÇ×î´óÖµÇé¿ö£¬²¢ÇÒµ±Ç°Î»Îª×î´óÖµÊ±£¬sp=1
    }
    if(sp==0)   //Èç¹û²»ÊÇ×î´óÖµÇé¿ö£¬¼ÇÂ¼ÔËËã½á¹û
    {
        f[pos][he][rnk[lcm]]=ans;
    }
    return ans;
}

inline long long solve (long long n)   //´¦ÀíÊý¾Ý¼ÓÇóÖµº¯Êý
{

    nums.clear();     //Ò»¶¨Òª¼ÇµÃÇå¿Õ
    while(n)       //½«ÊýÖµ°´Îª´æÈë
    {
        nums.push_back(n%10);
        n/=10;
    }
    return dfs(nums.size()-1,0,1,1); //´Ó×î¸ßÎ»¿ªÊ¼ËÑË÷
}

long long main ()
{
    pre();  //³õÊ¼»¯
    cin>>T;
    for(long long i=1;i<=T;i++)
    {
        cin>>l>>r;
        cout<<solve(r)-solve(l-1)<<endl;
    }
    Tokisaki Kurumi   //¿ñÈýÎÒÀÏÆÅ£¬²»·þ±ï×Å
}


<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
	<FileVersion major="1" minor="6" />
	<Project>
		<Option title="D" />
		<Option pch_mode="2" />
		<Option compiler="gcc" />
		<Build>
			<Target title="Debug">
				<Option output="bin/Debug/D" prefix_auto="1" extension_auto="1" />
				<Option object_output="obj/Debug/" />
				<Option type="1" />
				<Option compiler="gcc" />
				<Compiler>
					<Add option="-g" />
				</Compiler>
			</Target>
			<Target title="Release">
				<Option output="bin/Release/D" prefix_auto="1" extension_auto="1" />
				<Option object_output="obj/Release/" />
				<Option type="1" />
				<Option compiler="gcc" />
				<Compiler>
					<Add option="-O2" />
				</Compiler>
				<Linker>
					<Add option="-s" />
				</Linker>
			</Target>
		</Build>
		<Compiler>
			<Add option="-Wall" />
			<Add option="-fexceptions" />
		</Compiler>
		<Unit filename="main.cpp" />
		<Extensions>
			<code_completion />
			<envvars />
			<debugger />
			<lib_finder disable_auto="1" />
		</Extensions>
	</Project>
</CodeBlocks_project_file>


//#pragma comment(linker, "/STACK:206777216")
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <queue>
#include <fstream>

typedef long long ll;

using namespace std;
inline ll MAX(ll a, ll b) { return (a > b) ? (a) : (b); }
inline ll MIN(ll a, ll b) { return (a < b) ? (a) : (b); }

#define rep(i,a,b) for(i=a; i<=b; i++)
#define brep(i,b,a) for(i=b; i>=a; i--)
#define repitv(it,s)  for (std::vector<ll>::iterator it = s.begin(); it != s.end(); it++)
#define repitm(it,s)  for (std::map<ll,ll>::iterator it = s.begin(); it != s.end(); it++)
#define repitmp(it,s)  for (std::map<pair<ll,ll>,ll>::iterator it = s.begin(); it != s.end(); it++)
#define repits(it,s)  for (std::set<ll>::iterator it = s.begin(); it != s.end(); it++)
#define repitsp(it,s)  for (std::set<pair<ll,ll>>::iterator it = s.begin(); it != s.end(); it++)

//stack<pair<int, int> > s;

const int mod = 1e9+7;
const ll sz = 5e3;
ll sbeg[sz] = {}, sbegmin[sz] = {}, send[sz] = {}, sendmin[sz] = {};

//

void prep(string s2)
{
	ll i;
	sbeg[sz] = {}; send[sz] = {};

	ll l = s2.length();

	sbegmin[0] = 10000;

	rep(i, 0, l - 1)
	{
		sbeg[i] = (i > 0 ? sbeg[i - 1] : 0);

		if (s2[i] == '(')
			sbeg[i] += 1;
		else
			sbeg[i] -= 1;

		sbegmin[i] = (i>0? MIN(sbeg[i], sbegmin[i - 1]): sbeg[i]);

	}

	brep(i, l - 1, 0)
	{
		send[i] = send[i + 1];

		if (s2[i] == '(')
			send[i] += 1;
		else
			send[i] -= 1;

		sendmin[i] = (i<l-1? MIN(send[i], sbegmin[i + 1]): send[l-1]);

	}

}

int main()
{

	ll i, j, val, a, b, c, q[sz], t, m, r, cnt, k, g, sum = 0, block[sz], n, mm, mina = 1e18, minj, data[sz + 1][3], x[sz], y[sz], l;
	ofstream f;

	string s;

	f.open("test.txt");

	cin >> l;

	cin >> s;

	string s2;
	char temp;
	ll maxcnt = -1, maxi, maxj;

	rep(i, 0, l - 1)
	{
		rep(j, i, l - 1)
		{
			cnt = 0;

			s2 = s;

			temp = s2[i];
			s2[i] = s2[j];
			s2[j] = temp;

			prep(s2);

			rep(k, 0, l - 1)
			{
				if (sendmin[k] >= 0 && send[k] + (k > 0 ? sbegmin[k - 1] : 0) >= 0)
					cnt++;

			}

			if (cnt > maxcnt)
			{
				maxcnt = cnt;
				maxi = i; maxj = j;
			}

		}

	}

	cout << maxcnt<<"\n"<<maxi+1<<" "<<maxj+1;

	return 0;
}


#include <bits/stdc++.h>
#define pi acos(-1.0)
#define ll long long
#define lf double
#define ull unsigned long long
#define esp 1e-9
#define inf 0x3f3f3f3f
#define inff 0x3f3f3f3f3f3f3f3f
#define Pair pair<ll, ll>
#define It set<ll>::iterator

using namespace std;

const ll N = 1e5+5, mod = 1e9+7;
ll n;
string str;

int main(){
    ios::sync_with_stdio(false);
    cin>>n>>str;
    ll a = 0, b = 0;
    ll l = 1, r = 1, ans = 0;
    for (ll i = 0; i < n; i++){
    	if (str[i] == '('){
    		a++;
		}
		else{
			b++;
		}
	}
	if (a == b){
		for (ll i = 0; i < n; i++){
			ll tmp = 0, s;
			for (ll k = 0; k < n; k++){
				if (str[k] == '('){
					s = k; break;
				}
			}
			ll t = 0;
			stack<char> stk;
			for (ll cnt = 0; cnt < n; cnt++){
				ll pos = (s+cnt)%n;
				if (str[pos] == '('){
					stk.push('(');
				}
				else{
					if (!stk.empty()){
						t++; stk.pop();
						if (stk.empty()){
							tmp++;
						}
					}
				}
			}
			if (2*t == n){
				if (tmp > ans){
					ans = tmp;
					l = i+1; r = j+1;
				}
			}
			for (ll j = i+1; j < n; j++){
				if (str[i] != str[j]){
					swap(str[i], str[j]);
					ll tmp = 0, s;
					for (ll k = 0; k < n; k++){
						if (str[k] == '('){
							s = k; break;
						}
					}
					ll t = 0;
					stack<char> stk;
					for (ll cnt = 0; cnt < n; cnt++){
						ll pos = (s+cnt)%n;
						if (str[pos] == '('){
							stk.push('(');
						}
						else{
							if (!stk.empty()){
								t++; stk.pop();
								if (stk.empty()){
									tmp++;
								}
							}
						}
					}
					if (2*t == n){
						if (tmp > ans){
							ans = tmp;
							l = i+1; r = j+1;
						}
					}
					swap(str[i], str[j]);
				}
			}
		}
	}
	cout<<ans<<endl;
	cout<<l<<" "<<r<<endl;

    return 0;
}


#include<bits/stdc++.h>
#include<time.h>
#include<stdlib.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC target("sse4")
#define pb push_back
#define mp make_pair
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define pll pair<ll,ll>
#define vll vector<ll,ll>
#define all(a) (a).begin(),(a).end()
#define ff first
#define ss second
#define sz(x) (ll)x.size()
#define hell 1000000007
#define repf(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>b;i--)
#define lbnd lower_bound
#define ubnd upper_bound
#define bs binary_search
#define gcd(a,b) __gcd((a),(b))
#define EPS 1e-12
#define lcm(a,b) ((a)*(b))/__gcd((a),(b))
#define sqrt sqrtl
#define mod 1000000007
#define cbrt cbrtl
using namespace __gnu_pbds;
using namespace std;
ll l,maxi,posl,posr;
string s;
void check(ll l,ll r)
{
	ll i;
	int ans=0;
	int cnt=0
	for(i=0;i<l;i++)
	{
		if(s[i]=='(')cnt++;
		else
			cnt--;
		if(cnt<0)
			return;
	}
	if(cnt!=0)
		return 0;
	if(s[0]=='(')
		cnt++;
	else
		cnt--;
	for(i=1;i<l;i++)
	{
		if(s[i]=='(')
			cnt++;
		else
			cnt--;
		if(cnt==0)
			ans++;
	}
	if(ans>maxi)
	{
		maxi=ans;
		posl=l;
		posr=r;
	}
}
int main()
{
  IOS
  cin>>l;
  ll i,j;
  maxi=0;
  posl=-1;posr=-1;
  for(i=0;i<l;i++)
  	for(j=i+1;j<l;j++)
  	{
  		swap(s[i],s[j]);
  		check(i,j);
  	}
  	if(posl==-1)
  	{
  		posl=0;
  		posr=0;
  	}
  	cout<<maxi<<"\n"<<posl<<" "<<posr<<"\n";
  return 0;

}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=150005;
int n,m,k,in[maxn],dep[maxn],fa[maxn][19],st[maxn],ed[maxn],tim,sta[maxn],top;
int rt[maxn],ls[maxn*40],rs[maxn*40],sum[maxn*40][2],sz; ll ans;
vector<int> g[maxn],gson[maxn];
struct path { int x,y,z,a,b; } e[maxn];
vector<path> h[maxn];
struct chain { int x,y,b; };
vector<chain> w[maxn],t[maxn];
void dfs1(int x,int ff)
{
	fa[x][0]=ff,dep[x]=dep[ff]+1,st[x]=++tim;
	for(int i=1;i<=18;i++) fa[x][i]=fa[fa[x][i-1]][i-1];
	for(int i=0;i<(int)g[x].size();i++)
		if(g[x][i]!=ff) dfs1(g[x][i],x);
	ed[x]=tim;
}
inline void add_path(int x,int y,int &z,int &a,int &b)
{
	if(dep[x]<dep[y]) swap(x,y);
	for(int i=18;i>=0;i--)
		if(dep[fa[x][i]]>dep[y]) x=fa[x][i];
	if(fa[x][0]==y) { z=y,a=x,b=0; return; }
	if(dep[x]>dep[y]) x=fa[x][0];
	for(int i=18;i>=0;i--)
		if(fa[x][i]!=fa[y][i]) x=fa[x][i],y=fa[y][i];
	z=fa[x][0],a=x,b=y;
}
inline int LCA(int x,int y)
{
	if(dep[x]<dep[y]) swap(x,y);
	for(int i=18;i>=0;i--)
		if(dep[fa[x][i]]>=dep[y]) x=fa[x][i];
	if(x==y) return x;
	for(int i=18;i>=0;i--)
		if(fa[x][i]!=fa[y][i]) x=fa[x][i],y=fa[y][i];
	return fa[x][0];
}
void update(int &rt,int l,int r,int u,int v,int z)
{
//	printf("%d %d\n",u,v);
	if(!rt) rt=++sz,ls[rt]=rs[rt]=sum[rt][0]=sum[rt][1]=0;
	sum[rt][z]+=v;
	if(l==r) return;
	int mid=(l+r)>>1;
	if(u<=mid) update(ls[rt],l,mid,u,v,z);
	else update(rs[rt],mid+1,r,u,v,z);
}
int query(int rt,int l,int r,int x,int y,int z)
{
	if(!rt) return 0;
	if(x<=l && r<=y) return sum[rt][z];
	int mid=(l+r)>>1,ans=0;
	if(x<=mid) ans+=query(ls[rt],l,mid,x,y,z);
	if(y>mid) ans+=query(rs[rt],mid+1,r,x,y,z);
	return ans;
}
int merge(int x,int y)
{
	if(!x || !y) return x|y;
	sum[x][0]+=sum[y][0];
	sum[x][1]+=sum[y][1];
	ls[x]=merge(ls[x],ls[y]);
	rs[x]=merge(rs[x],rs[y]);
	return x;
}
inline int jump(int x,int k)
{
	k=dep[x]-k;
	for(int i=18;i>=0;i--)
		if(dep[fa[x][i]]>=k) x=fa[x][i];
	return x;
}
inline void calc(int x,int k,int rt)
{
	if(k<0) return;
	int a=jump(x,k);
	ans+=query(rt,1,n,st[a],ed[a],0);
}
void dfs2(int x)
{
//	printf("dfs2 %d\n",x);
	for(int i=0,y;i<(int)g[x].size();i++)
		if(g[x][i]!=fa[x][0]) y=g[x][i],dfs2(y),rt[x]=merge(rt[x],rt[y]);
	vector<path>::iterator it;
	for(it=h[x].begin();it!=h[x].end();it++)
	{
		update(rt[x],1,n,st[it->x],-1,0);
		if(it->y!=x) update(rt[x],1,n,st[it->y],-1,0);
	}
	for(it=h[x].begin();it!=h[x].end();it++)
	{
		calc(it->x,dep[it->x]-dep[x]-k,rt[x]);
		if(it->y>0) calc(it->y,dep[it->y]-dep[x]-k,rt[x]);
	}
	if(in[x]) update(rt[x],1,n,st[x],in[x],0);
}
void dfs3(int x,int anc)
{
	vector<chain>::iterator it;
	if(dep[x]-dep[anc]>=k)
	{
		ans+=(ll)t[x].size()*((ll)t[x].size()-1)/2;
		int sz=0;
		for(it=t[x].begin();it!=t[x].end();it++)
		{
			update(rt[x],1,n,st[it->y],1,0);
			ans+=sz-(it->b?query(rt[x],1,n,it->b,it->b,1):0);
			if(it->b) update(rt[x],1,n,it->b,1,1);
			sz++;
		}
	}
	else
	{
		for(it=t[x].begin();it!=t[x].end();it++)
			calc(it->y,dep[it->y]-dep[anc]-(k-(dep[x]-dep[anc])),rt[x]),update(rt[x],1,n,st[it->y],1,0);
	}
	for(int i=0;i<(int)gson[x].size();i++)
	{
		int y=gson[x][i]; dfs3(y,anc);
		if((int)t[x].size()<(int)t[y].size()) swap(t[x],t[y]),swap(rt[x],rt[y]);
		if(dep[x]-dep[anc]>=k)
		{
			ans+=(ll)t[x].size()*(ll)t[y].size();
			for(it=t[y].begin();it!=t[y].end();it++)
				ans+=((ll)t[x].size()-(it->b?query(rt[x],1,n,it->b,it->b,1):0));
		}
		else
		{
			for(it=t[y].begin();it!=t[y].end();it++)
				calc(it->y,dep[it->y]-dep[anc]-(k-(dep[x]-dep[anc])),rt[x]);
		}
		rt[x]=merge(rt[x],rt[y]);
		for(it=t[y].begin();it!=t[y].end();it++)
			t[x].push_back(*it);
		rt[y]=0;
		vector<chain>().swap(t[y]);
		map<int,int>().swap(mp[y]);
	}
	vector<int>().swap(gson[x]);
//	printf("dfs3 %d %lld\n",x,ans);
}
inline bool cmp(const int &x,const int &y) { return st[x]<st[y]; }
inline void solve(int x,int anc)
{
	if((int)w[x].size()<=1) return;
//	cout<<"solve "<<x<<endl;
	sta[top=1]=x;
	vector<chain>::iterator it;
	static int q[maxn]; int tot=0;
	for(it=w[x].begin();it!=w[x].end();it++) q[++tot]=it->x;
	sort(q+1,q+tot+1,cmp);
	for(int i=1;i<=tot;i++)
	{
		int lca=LCA(sta[top],q[i]);
		while(dep[lca]<dep[sta[top]])
		{
			if(dep[sta[top-1]]<=dep[lca])
			{
				gson[lca].push_back(sta[top]),top--;
				if(sta[top]!=lca) sta[++top]=lca;
				break;
			}
			gson[sta[top-1]].push_back(sta[top]),top--;
		}
		if(sta[top]!=q[i]) sta[++top]=q[i];
	}
	while(--top) gson[sta[top]].push_back(sta[top+1]);
	for(it=w[x].begin();it!=w[x].end();it++) t[it->x].push_back(*it);
	sz=0,dfs3(x,anc),rt[x]=0;
	vector<chain>().swap(t[x]);
	map<int,int>().swap(mp[x]);
//	cout<<ans<<endl;
}
int main()
{
//	freopen("data.in","r",stdin);
//	freopen("czx.out","w",stdout);
	scanf("%d%d%d",&n,&m,&k);
	int x,y;
	for(int i=1;i<n;i++)
	{
		scanf("%d%d",&x,&y);
		g[x].push_back(y);
		g[y].push_back(x);
	}
	for(int i=1;i<=n;i++) sort(g[i].begin(),g[i].end());
	dfs1(1,0);
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d",&e[i].x,&e[i].y);
		if(dep[e[i].x]<dep[e[i].y]) swap(e[i].x,e[i].y);
		add_path(e[i].x,e[i].y,e[i].z,e[i].a,e[i].b);
		in[e[i].x]++;
		if(e[i].y!=e[i].z) in[e[i].y]++;
		h[e[i].z].push_back(e[i]);
	}
	dfs2(1),ans*=2;
//	cout<<ans<<endl;
	for(int i=1;i<=n;i++) rt[i]=0;
	for(int i=1;i<=n;i++)
	{
		for(vector<path>::iterator it=
		h[i].begin();it!=h[i].end();it++)
		{
			if(!it->b) w[it->a].push_back((chain){it->x,it->y,0});
			else w[it->a].push_back((chain){it->x,it->y,it->b}),w[it->b].push_back((chain){it->y,it->x,it->a});
		}
		for(int j=0;j<(int)g[i].size();j++)
			if(g[i][j]!=fa[i][0]) solve(g[i][j],i);
	}
	printf("%lld\n",ans/2);
	return 0;
}
/*
7 2 4
1 2
2 3
1 4
4 5
1 6
6 7
5 1
5 2
*/


#include <cstdio>
#include <cassert>
#include <vector>
#include <algorithm>

using ll = long long;

const int MN=1.5e5+10;
const int MS=3e7;
int N, M, K, d[MN], p[MN][20], vp[MN], pre[MN], post[MN], rm[MN], top, nd[MN], ctr, tot, t[MN], e[MN];
std::vector<int> up[MN], a[MN], b[MN], c[MN], pts, g[MN];
ll ans1, ans2, ans3;
struct QRY{public: int a, b;};
std::vector<QRY> q[MN];

void dfs(int n=1)
{
	pre[n] = ctr++;
	for(int i=0;p[n][i]&&p[p[n][i]][i];++i)
		p[n][i+1]=p[p[n][i]][i];
	for(int x:a[n])
		if(x!=p[n][0])
			p[x][0]=n,d[x]=d[n]+1,dfs(x);
	post[n] = ctr;
}
int mu(int x, int d)
{
	for(int i=0;d;d>>=1,++i)
		if(d&1)
			x=p[x][i];
	return x;
}
int lca(int x, int y)
{
	if(d[y]<d[x]) std::swap(x,y);
	if(d[y]!=d[x]) y=mu(y, d[y]-d[x]);
	if(x==y) return x;
	for(int i=19;i>=0;--i)
		if(p[x][i]!=p[y][i])
			x=p[x][i],y=p[y][i];
	return p[x][0];
}
bool anc(int x, int y) {return pre[x]<=pre[y] && post[y]<=post[x];}
int bit[MN];
void chg(int x, int v)
{
	for(++x;x<=N;x+=-x&x)
		bit[x-1]+=v;
	tot+=v;
}
int cnt(int x)
{
	int f=0;
	for(++x;x>0;x-=-x&x)
		f+=bit[x-1];
	return f;
}
int cnt2(int x) {return cnt(x)-cnt(x-1);}
void dfs1(int n=1)
{
	if(d[n]>=K)
		for(int x:up[n])
			ans1 += tot-cnt(x-1), chg(d[n]-K, 1);
	for(int x:a[n])
		if(x!=p[n][0])
			dfs1(x);
	if(d[n]>=K)
	{
		int vk = cnt2(d[n]-K);
		chg(d[n]-K, -vk);
		vk -= rm[n];
		assert(vk >= 0);
		if(d[n]==K) assert(!vk);
		if(vk) chg(d[n]-K-1, vk);
	}
}
struct stn
{
public:
	int c[2], v;
	stn() {c[0]=c[1]=-1; v=0;}
} st[MS];
int X;
void upd(int *n, int l, int r, int q, int v)
{
	if(!~*n) *n=X++;
	if(r-l>1)
	{
		int m=l+(r-l)/2;
		if(q<m) upd(st[*n].c, l, m, q, v);
		else upd(st[*n].c+1, m, r, q, v);
		st[*n].v=st[st[*n].c[0]].v+st[st[*n].c[1]].v;
	}
	else
		st[*n].v+=v;
}
int qry(int n, int l, int r, int ql, int qr)
{
	if(!~n) return 0;
	if(ql <= l&&r <= qr) return st[n].v;
	else
	{
		int m=l+(r-l)/2, f=0;
		if(ql < m) f+=qry(st[n].c[0], l, m, ql, qr);
		if(m < qr) f+=qry(st[n].c[1], m, r, ql, qr);
		return f;
	}
}
void dfs2(int n)
{
	for(int x:c[n])
	{
		if(d[x]==top) continue;
		if(d[x]+d[n]-2*top < K) continue;
		int o;
		if(d[x]-top >= K) o=mu(x, d[x]-top-1);
		else o=mu(x, d[x]+d[n]-2*top-K);
		ans2 += qry(nd[n], 0, N, pre[o], post[o]);
		upd(nd+n, 0, N, pre[x], 1);
		g[n].push_back(x);
	}
	for(int y:b[n])
	{
		t[y]=t[n];
		dfs2(y);
		if(g[n].size()<g[y].size())
			std::swap(g[n], g[y]), std::swap(nd[n], nd[y]);
		for(int x:g[y])
		{
			if(d[x]+d[n]-2*top < K) continue;
			int o;
			if(d[x]-top >= K) o=mu(x, d[x]-top-1);
			else o=mu(x, d[x]+d[n]-2*top-K);
			ans2 += qry(nd[n], 0, N, pre[o], post[o]);
			upd(nd+n, 0, N, pre[x], 1);
			g[n].push_back(x);
		}
		g[y].clear(), nd[y]=-1;
	}
}
void dfs3(int n)
{
	if(d[n]-top>=K)
		for(int x:c[n])
		{
			int o=mu(n, d[n]-top-K);//can be optimized but at this point its not the bottleneck
			ans3 += qry(e[0], 0, N, pre[o], post[o]), upd(e, 0, N, pre[n], 1);
			if(t[x]) ans3 -= qry(e[t[x]], 0, N, pre[o], post[o]), upd(e+t[x], 0, N, pre[n], 1);
		}
	for(int x:b[n])
		dfs3(x);
}
int main(void)
{
	memset(nd, -1, sizeof nd);
	memset(e, -1, sizeof e);
	scanf("%d%d%d", &N, &M, &K);
	for(int i=0,x,y;i+1<N;++i)
		scanf("%d%d", &x, &y), a[x].push_back(y), a[y].push_back(x);
	dfs();
	for(int i=0,x,y;i<M;++i)
	{
		scanf("%d%d", &x, &y);
		int z=lca(x,y);
		//printf("LCA(%d, %d) = %d\n", x, y, z);
		if(d[x]+d[y]-2*d[z]<K) continue;
		if(d[x]-d[z]>=K) up[x].push_back(d[z]), ++rm[mu(x, d[x]-d[z]-K)];
		if(d[y]-d[z]>=K) up[y].push_back(d[z]), ++rm[mu(y, d[y]-d[z]-K)];
		q[z].push_back({x,y});
	}
	dfs1();
	for(int i=1;i<=N;++i) ans1 -= (ll)rm[i]*(rm[i]-1)/2;
	//printf("STRAIGHT (not counting same lca): %lld\n", ans1);
	for(int i=1;i<=N;++i)
		if(!q[i].empty())
		{
			top=d[i];
			for(auto x:q[i])
				pts.push_back(x.a), pts.push_back(x.b);
			std::sort(pts.begin(), pts.end(), [](int a, int b){return pre[a]<pre[b];});
			pts.resize(std::distance(pts.begin(), std::unique(pts.begin(), pts.end())));
			for(int i=pts.size()-1;i>0;--i)
				pts.push_back(lca(pts[i-1], pts[i]));
			std::sort(pts.begin(), pts.end(), [](int a, int b){return pre[a]<pre[b];});
			pts.resize(std::distance(pts.begin(), std::unique(pts.begin(), pts.end())));

			int j=-1;
			assert(pts[0] == i);
			for(int x:pts)
				if(!~j) j=x;
				else
				{
					while(!anc(j, x)) j = vp[j];
					vp[x]=j, b[j].push_back(x);
					j=x;
				}
			for(auto x:q[i])
				c[x.a].push_back(x.b), c[x.b].push_back(x.a);
			j=1;
			for(int x:b[i])
			{
				t[x]=j++;
				dfs2(x);
				g[x].clear(), nd[x]=-1;
			}
			dfs3(i);
			for(int x:pts)
			{
				if(d[x]-top>=K)
					for(int y:c[x])
					{
						upd(e, 0, N, pre[x], -1);
						if(t[y]) upd(e+t[y], 0, N, pre[x], -1);
					}
				b[x].clear(), c[x].clear(), vp[x]=0;
			}
			for(int x:pts) t[x]=0;
			pts.clear();
		}
	//printf("Breakdown: %lld %lld/2 %lld\n", ans1, ans2, ans3);
	printf("%lld\n", ans1+ans2/2+ans3);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N=2e5+7,M=20,K=1e7+7; long long ans,sum; vector<int>v[N],qt[N],vw[N],vt[N];
int n,m,k,kt,rt,opt,tot,fa[N],ft[N],dep[N],siz[N],rq[N],dfa[N],dfb[N],res[N],e[N][M],pt[N<<1],gt[N],ch[K][2],va[K];
struct query {int u,v,t;}f[N];
inline void dfs(int u){
	e[u][0]=fa[u],dfa[u]=dfb[u]=++opt,ft[opt]=u;
	for(int i=1;i<=18;i++) e[u][i]=e[e[u][i-1]][i-1];
	for(int i=0;i<v[u].size();i++){
		int x=v[u][i]; if(fa[u]==x) continue;
		fa[x]=u,dep[x]=dep[u]+1,dfs(x),dfb[u]=dfb[x];
	}
}
inline int lca(int u,int t){
	if(dep[u]<dep[t]) swap(u,t); int z=dep[u]-dep[t];
	for(int i=18;i>=0;i--) if((1<<i)&z) u=e[u][i]; if(u==t) return u;
	for(int i=18;i>=0;i--) if(e[u][i]!=e[t][i]) u=e[u][i],t=e[t][i]; return fa[u];
}
inline int jmp(int u,int t){
	for(int i=18;i>=0;i--) if((1<<i)&t) u=e[u][i]; return u;
}
inline int lowbit(int u){
	return (u&(-u));
}
inline void adds(int u,int c){
	while(u<=n) res[u]+=c,u+=lowbit(u);
}
inline long long getsum(int u){
	long long ans=0; while(u>0) ans+=res[u],u-=lowbit(u); return ans;
}
inline bool cmp(query a,query b){
	return dfa[a.t]<dfa[b.t];
}
inline bool tmp(int a,int b){
	return dfa[a]<dfa[b];
}
inline int merge(int u,int t,int l,int r){
	if(!u||!t) return (u+t);
	if(l==r) {va[u]+=va[t]; return u;}
	int d=(l+r)>>1;
	ch[u][0]=merge(ch[u][0],ch[t][0],l,d);
	ch[u][1]=merge(ch[u][1],ch[t][1],d+1,r);
	va[u]=va[ch[u][0]]+va[ch[u][1]]; return u;
}
inline int getans(int l,int r,int t,int ql,int qr){
	if(l==ql&&r==qr) return va[t]; int d=(l+r)>>1; int sum=0;
	if(ql<=d&&ch[t][0]) sum+=getans(l,d,ch[t][0],ql,min(d,qr));
	if(d+1<=qr&&ch[t][1]) sum+=getans(d+1,r,ch[t][1],max(d+1,ql),qr);
	return sum;
}
inline void getval(int u,int t,int l,int r){
	if(l==r){
		int z=u; u=ft[l];
		if(dep[u]-dep[rt]>=kt){
			u=jmp(u,dep[u]-dep[rt]-kt);
			sum=sum+1ll*getans(1,n,t,dfa[u],dfb[u])*va[z];
		}
		return;
	}
	int d=(l+r)>>1;
	if(ch[u][0]) getval(ch[u][0],t,l,d);
	if(ch[u][1]) getval(ch[u][1],t,d+1,r);
}
inline void addx(int l,int r,int t,int s){
	if(l==r){
		va[t]++; return;
	}
	int d=(l+r)>>1;
	if(s<=d){
		if(!ch[t][0]) ch[t][0]=++tot;
		addx(l,d,ch[t][0],s);
	}
	else{
		if(!ch[t][1]) ch[t][1]=++tot;
		addx(d+1,r,ch[t][1],s);
	}
	va[t]=va[ch[t][0]]+va[ch[t][1]];
}
inline void dft(int u){
//	if(rt==11) cout<<u<<"wwwww"<<endl;
	rq[u]=0;
	for(int i=0;i<vw[u].size();i++){
		int x=vw[u][i]; dft(x); kt=max(k-(dep[u]-dep[rt]),0);
		if(siz[x]>siz[u]) swap(siz[u],siz[x]),swap(rq[u],rq[x]);
//		cout<<u<<":"<<endl;
		getval(rq[x],rq[u],1,n),rq[u]=merge(rq[u],rq[x],1,n),siz[u]+=siz[x];
	}
	kt=max(k-(dep[u]-dep[rt]),0);
	for(int i=0;i<vt[u].size();i++){
		int x=vt[u][i];
		if(dep[x]-dep[rt]>=kt){
			int z=jmp(x,dep[x]-dep[rt]-kt);
//			cout<<u<<":"<<endl;
			sum=sum+getans(1,n,rq[u],dfa[z],dfb[z]);
		}
		if(!rq[u]) rq[u]=++tot;
		addx(1,n,rq[u],dfa[x]);
	}
//	cout<<u<<" "<<sum<<"wwwww"<<endl;
}
signed main(){
	cin>>n>>m>>k; int u,t;
	for(int i=1;i<n;i++) scanf("%d%d",&u,&t),v[u].push_back(t),v[t].push_back(u); dfs(1);
	for(int i=1;i<=m;i++) scanf("%d%d",&f[i].u,&f[i].v),f[i].t=lca(f[i].u,f[i].v);
    sort(f+1,f+m+1,cmp);
    for(int i=1;i<=m;i++){
//    	cout<<f[i].t<<":"<<endl;
    	int l=1,r=m,pos=0;
    	while(l<=r){
    		int d=(l+r)>>1;
    		if(dfa[f[d].t]<dfa[f[i].t]) pos=d,l=d+1; else r=d-1;
		}
		qt[pos].push_back(i);
//		cout<<pos<<"a"<<endl;
		l=1,r=m,pos=0;
		while(l<=r){
    		int d=(l+r)>>1;
    		if(dfa[f[d].t]<=dfb[f[i].t]) pos=d,l=d+1; else r=d-1;
		}
//		cout<<pos<<"b"<<endl;
		qt[pos].push_back(i);
	}
	for(int i=1;i<=m;i++){
		adds(dfa[f[i].u],1),adds(dfa[f[i].v],1);
//		cout<<f[i].u<<" "<<f[i].v<<"+"<<endl;
		for(int x=0;x<qt[i].size();x++){
			int c=qt[i][x];
			if(dfa[f[i].t]<dfa[f[c].t]){
				if(dep[f[c].u]-dep[f[c].t]>=k){
					int z=jmp(f[c].u,dep[f[c].u]-dep[f[c].t]-k);
//					cout<<z<<"+"<<endl;
					ans=ans+(getsum(dfb[z])-getsum(dfa[z]-1));
//					cout<<ans<<endl;
				}
				if(dep[f[c].v]-dep[f[c].t]>=k){
					int z=jmp(f[c].v,dep[f[c].v]-dep[f[c].t]-k);
//					cout<<z<<"+"<<endl;
					ans=ans+(getsum(dfb[z])-getsum(dfa[z]-1));
//					cout<<ans<<endl;
				}
			}
			else{
				if(dep[f[c].u]-dep[f[c].t]>=k){
					int z=jmp(f[c].u,dep[f[c].u]-dep[f[c].t]-k);
//					cout<<z<<"-"<<endl;
					ans=ans-(getsum(dfb[z])-getsum(dfa[z]-1));
//					cout<<ans<<endl;
				}
				if(dep[f[c].v]-dep[f[c].t]>=k){
					int z=jmp(f[c].v,dep[f[c].v]-dep[f[c].t]-k);
//					cout<<z<<"-"<<endl;
					ans=ans-(getsum(dfb[z])-getsum(dfa[z]-1));
//					cout<<ans<<endl;
				}
			}
		}
	}
//	cout<<ans<<"wwwww"<<endl;
	for(int c=1;c<=m;c++){
		if(dep[f[c].u]-dep[f[c].t]>=k){
			int z=jmp(f[c].u,dep[f[c].u]-dep[f[c].t]-k);
//			cout<<z<<"+"<<endl;
			ans=ans+(getsum(dfb[z])-getsum(dfa[z]-1));
//			cout<<ans<<endl;
		}
		if(dep[f[c].v]-dep[f[c].t]>=k){
			int z=jmp(f[c].v,dep[f[c].v]-dep[f[c].t]-k);
//			cout<<z<<"+"<<endl;
			ans=ans+(getsum(dfb[z])-getsum(dfa[z]-1));
//			cout<<ans<<endl;
		}
	}
	for(int i=1;i<=m;i++){
		int x=i; while(f[i].t==f[x+1].t) x++; pt[pt[0]=1]=f[i].t;
		for(int z=i;z<=x;z++) pt[++pt[0]]=f[z].u,pt[++pt[0]]=f[z].v;
		sort(pt+1,pt+pt[0]+1,tmp);
		for(int z=1;z<=pt[0];z++) vw[pt[z]].resize(0),vt[pt[z]].resize(0); int len=0;
		for(int z=i;z<=x;z++) vt[f[z].u].push_back(f[z].v),vt[f[z].v].push_back(f[z].u);
		gt[len=1]=pt[1];
//		for(int z=1;z<=pt[0];z++) cout<<pt[z]<<":"; cout<<endl;
		for(int z=2;z<=pt[0];z++){
			if(pt[z]==gt[len]) continue;
			if(len==1) {gt[++len]=pt[z]; continue;}
//			cout<<pt[z]<<"xxxx"<<endl;
			int c=lca(pt[z],gt[len]);
			while(dep[c]<dep[gt[len]]){
				if(dep[gt[len-1]]>=dep[c]){
					vw[gt[len-1]].push_back(gt[len]);
//					cout<<gt[len-1]<<" "<<gt[len]<<endl;
					len--;
				}
				else{
					vw[c].resize(0);
					vw[c].push_back(gt[len]);
					gt[len]=c; break;
				}
			}
			if(pt[z]==gt[len]) continue; gt[++len]=pt[z];
		}
		for(int z=1;z<len;z++)
			vw[gt[z]].push_back(gt[z+1]);
		rt=f[i].t,dft(rt);
//		cout<<rt<<" "<<sum<<endl;
		i=x;
	}
//	cout<<ans<<" "<<sum<<endl;
	cout<<ans+sum/2<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=150005;
int n,m,k,in[maxn],dep[maxn],fa[maxn][19],st[maxn],ed[maxn],tim,sta[maxn],top;
int rt[maxn],ls[maxn*20],rs[maxn*20],sum[maxn*20],sz; ll ans;
vector<int> g[maxn],gson[maxn];
struct path { int x,y,z,a,b; } e[maxn];
vector<path> h[maxn];
struct chain { int x,y,b; };
vector<chain> w[maxn],t[maxn];
map<int,int> mp[maxn];
void dfs1(int x,int ff)
{
	fa[x][0]=ff,dep[x]=dep[ff]+1,st[x]=++tim;
	for(int i=1;i<=18;i++) fa[x][i]=fa[fa[x][i-1]][i-1];
	for(int i=0;i<(int)g[x].size();i++)
		if(g[x][i]!=ff) dfs1(g[x][i],x);
	ed[x]=tim;
}
inline void add_path(int x,int y,int &z,int &a,int &b)
{
	if(dep[x]<dep[y]) swap(x,y);
	for(int i=18;i>=0;i--)
		if(dep[fa[x][i]]>dep[y]) x=fa[x][i];
	if(fa[x][0]==y) { z=y,a=x,b=0; return; }
	if(dep[x]>dep[y]) x=fa[x][0];
	for(int i=18;i>=0;i--)
		if(fa[x][i]!=fa[y][i]) x=fa[x][i],y=fa[y][i];
	z=fa[x][0],a=x,b=y;
}
inline int LCA(int x,int y)
{
	if(dep[x]<dep[y]) swap(x,y);
	for(int i=18;i>=0;i--)
		if(dep[fa[x][i]]>=dep[y]) x=fa[x][i];
	if(x==y) return x;
	for(int i=18;i>=0;i--)
		if(fa[x][i]!=fa[y][i]) x=fa[x][i],y=fa[y][i];
	return fa[x][0];
}
void update(int &rt,int l,int r,int u,int v)
{
//	printf("%d %d\n",u,v);
	if(!rt) rt=++sz,ls[rt]=rs[rt]=sum[rt]=0;
	sum[rt]+=v;
	if(l==r) return;
	int mid=(l+r)>>1;
	if(u<=mid) update(ls[rt],l,mid,u,v);
	else update(rs[rt],mid+1,r,u,v);
}
int query(int rt,int l,int r,int x,int y)
{
	if(!rt) return 0;
	if(x<=l && r<=y) return sum[rt];
	int mid=(l+r)>>1,ans=0;
	if(x<=mid) ans+=query(ls[rt],l,mid,x,y);
	if(y>mid) ans+=query(rs[rt],mid+1,r,x,y);
	return ans;
}
int merge(int x,int y)
{
	if(!x || !y) return x|y;
	sum[x]+=sum[y];
	ls[x]=merge(ls[x],ls[y]);
	rs[x]=merge(rs[x],rs[y]);
	return x;
}
inline int jump(int x,int k)
{
	k=dep[x]-k;
	for(int i=18;i>=0;i--)
		if(dep[fa[x][i]]>=k) x=fa[x][i];
	return x;
}
inline void calc(int x,int k,int rt)
{
	if(k<0) return;
	int a=jump(x,k);
	ans+=query(rt,1,n,st[a],ed[a]);
}
void dfs2(int x)
{
//	printf("dfs2 %d\n",x);
	for(int i=0,y;i<(int)g[x].size();i++)
		if(g[x][i]!=fa[x][0]) y=g[x][i],dfs2(y),rt[x]=merge(rt[x],rt[y]);
	vector<path>::iterator it;
	for(it=h[x].begin();it!=h[x].end();it++)
	{
		update(rt[x],1,n,st[it->x],-1);
		if(it->y!=x) update(rt[x],1,n,st[it->y],-1);
	}
	for(it=h[x].begin();it!=h[x].end();it++)
	{
		calc(it->x,dep[it->x]-dep[x]-k,rt[x]);
		if(it->y>0) calc(it->y,dep[it->y]-dep[x]-k,rt[x]);
	}
	if(in[x]) update(rt[x],1,n,st[x],in[x]);
}
void dfs3(int x,int anc)
{
	vector<chain>::iterator it;
	if(dep[x]-dep[anc]>=k)
	{
		ans+=(ll)t[x].size()*((ll)t[x].size()-1)/2;
		int sz=0;
		for(it=t[x].begin();it!=t[x].end();it++)
		{
			update(rt[x],1,n,st[it->y],1);
			ans+=sz-(it->b?mp[x][it->b]:0),mp[x][it->b]++,sz++;
		}
	}
	else
	{
		for(it=t[x].begin();it!=t[x].end();it++)
			calc(it->y,dep[it->y]-dep[anc]-(k-(dep[x]-dep[anc])),rt[x]),update(rt[x],1,n,st[it->y],1);
	}
	for(int i=0;i<(int)gson[x].size();i++)
	{
		int y=gson[x][i]; dfs3(y,anc);
		if(dep[x]-dep[anc]>=k)
		{
			ans+=(ll)t[x].size()*(ll)t[y].size();
//			cout<<x<<' '<<ans<<endl;
			if((int)mp[x].size()<(int)mp[y].size()) swap(mp[x],mp[y]),swap(t[x],t[y]),swap(rt[x],rt[y]);
			for(map<int,int>::iterator it=mp[y].begin();it!=mp[y].end();it++)
				ans+=(ll)it->second*((ll)t[x].size()-(it->first?mp[x][it->first]:0));
//				cout<<ans<<endl;
			for(map<int,int>::iterator it=mp[y].begin();it!=mp[y].end();it++)
				mp[x][it->first]+=it->second;
		}
		else
		{
			if((int)t[x].size()<(int)t[y].size()) swap(t[x],t[y]),swap(rt[x],rt[y]);
			for(it=t[y].begin();it!=t[y].end();it++)
				calc(it->y,dep[it->y]-dep[anc]-(k-(dep[x]-dep[anc])),rt[x]);
		}
		rt[x]=merge(rt[x],rt[y]);
		for(it=t[y].begin();it!=t[y].end();it++)
			t[x].push_back(*it);
		rt[y]=0,t[y].clear(),mp[y].clear();
	}
	gson[x].clear();
//	printf("dfs3 %d %lld\n",x,ans);
}
inline bool cmp(const int &x,const int &y) { return st[x]<st[y]; }
inline void solve(int x,int anc)
{
	if((int)w[x].size()<=1) return;
//	cout<<"solve "<<x<<endl;
	sta[top=1]=x;
	vector<chain>::iterator it;
	static int q[maxn]; int tot=0;
	for(it=w[x].begin();it!=w[x].end();it++) q[++tot]=it->x;
	sort(q+1,q+tot+1,cmp);
	for(int i=1;i<=tot;i++)
	{
		int lca=LCA(sta[top],q[i]);
		while(dep[lca]<dep[sta[top]])
		{
			if(dep[sta[top-1]]<=dep[lca])
			{
				gson[lca].push_back(sta[top]),top--;
				if(sta[top]!=lca) sta[++top]=lca;
				break;
			}
			gson[sta[top-1]].push_back(sta[top]),top--;
		}
		if(sta[top]!=q[i]) sta[++top]=q[i];
	}
	while(--top) gson[sta[top]].push_back(sta[top+1]);
	for(it=w[x].begin();it!=w[x].end();it++) t[it->x].push_back(*it);
	sz=0,dfs3(x,anc),rt[x]=0,t[x].clear(),mp[x].clear();
//	cout<<ans<<endl;
}
int main()
{
//	freopen("data.in","r",stdin);
//	freopen("czx.out","w",stdout);
	scanf("%d%d%d",&n,&m,&k);
	int x,y;
	for(int i=1;i<n;i++)
	{
		scanf("%d%d",&x,&y);
		g[x].push_back(y);
		g[y].push_back(x);
	}
	for(int i=1;i<=n;i++) sort(g[i].begin(),g[i].end());
	dfs1(1,0);
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d",&e[i].x,&e[i].y);
		if(dep[e[i].x]<dep[e[i].y]) swap(e[i].x,e[i].y);
		add_path(e[i].x,e[i].y,e[i].z,e[i].a,e[i].b);
		in[e[i].x]++;
		if(e[i].y!=e[i].z) in[e[i].y]++;
		h[e[i].z].push_back(e[i]);
	}
	dfs2(1),ans*=2;
//	cout<<ans<<endl;
	for(int i=1;i<=n;i++) rt[i]=0;
	for(int i=1;i<=n;i++)
	{
		for(vector<path>::iterator it=
		h[i].begin();it!=h[i].end();it++)
		{
			if(!it->b) w[it->a].push_back((chain){it->x,it->y,0});
			else w[it->a].push_back((chain){it->x,it->y,it->b}),w[it->b].push_back((chain){it->y,it->x,it->a});
		}
		for(int j=0;j<(int)g[i].size();j++)
			if(g[i][j]!=fa[i][0]) solve(g[i][j],i);
	}
	printf("%lld\n",ans/2);
	return 0;
}
/*
7 2 4
1 2
2 3
1 4
4 5
1 6
6 7
5 1
5 2
*/


#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,m[3],x;
	memset(m,0,sizeof(m));
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>x;
		m[i%3]+=x;//对于数组我们可以做的有很多运算
    cout<<(m[0]>m[1]&&m[0]>m[2]?"chest":m[1]>m[2]?"biceps":"back")<<"\n";
    return 0;
}
  /*if(a[0]>a[1]&&a[0]>a[2])
		cout<<"chest";
	else if(a[1]>a[2]&&a[1]>a[0])
		cout<<"biceps";
	else
		cout<<"back";


#include<iostream>
using namespace std;
int main()
{
    int n, s1 = 0, s2 = 0, s3 = 0, mn = 0, mx = 0;
    cin >> n;
    int a[n];
    for(int i = 1; i <= n; ++i)
        cin >> a[i];
    for(int i = 1; i <= n; ++i){
        if (i % 3 == 1)
            s1 += a[i];
        if (i % 3 == 2)
            s2 += a[i];
        if (i % 3 == 0)
            s3 += a[i];
    }
    mx = max({s1, s2, s3});
    if (mx == s1)
        cout << "chest" << " "; else
    if (mx == s2)
        cout << "biceps" << " "; else
        cout << "back" << " ";
    return 0;
}


#include <iostream>
using namespace std;

int Max(long long Arr[], int size = 3)
{
	long max = 0;
	long long saver = 0;
	for (size_t i = 0; i < size; i++)
	{
		if (max < Arr[i])
		{
			max = Arr[i];
			saver = i;
		}
	}

	return saver;

}

void Answ(long long *Arr, long long number, long long ArrayOfSum[])
{
	long long SumBic = 0;
	long long SumChest = 0;
	long long SumBack = 0;
	for (size_t i = 0; i < number; i++)
	{
		if (i == 0 || i % 3 == 0)
			SumChest = SumChest + *(Arr + i);
		if (i == 1 || i % 3 == 1)
			SumBic = SumBic + *(Arr + i);
		if (i == 3 || i % 3 == 2)
			SumBack = SumBack + *(Arr + i);
	}

	ArrayOfSum[0] = SumChest;
	ArrayOfSum[1] = SumBic;
	ArrayOfSum[2] = SumBack;

	long long max = Max(ArrayOfSum);

	if (max == 0)
		cout << "chest";
	else if (max == 1)
		cout << "biceps";
	else
		cout << "back";
}

void FillArr(long long *Arr, long long size)
{
	for (size_t i = 0; i < size; i++)
	{
		cin >> *(Arr + i);
	}
}

int main()
{
	long long number;
	cin >> number;
	if (number == 0)
		return 1;

	long int *Array = long int[number];

	FillArr(Array, number);

	const int size = 3;
	long int sumof[size];
	Answ(Array, number, sumof);

	cin.get();
	cin.get();

	return 0;
}


#include<iostream>
using namespace std;
int n,a;
int b[101];
inr main(){
	cin>>n:
		for(int i=1;i<=n;i++){
			cin>>a;
			for(int i=1;i<=a;i++){
				b[a%3+1]++;
			}
		}
		cout<<max(b[1],max(b[2],b[3]));
}


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

#define forn(i, n) for(int i = 0; i < int(n); ++i)
#define forv(i, v) forn(i, v.size())

vector<string> ans;
const int N = 6;
int a[N][N];

enum Orientation{Vertical, Horizontal};
enum Direction{Forward, Backward};

void addAnswer(int pos, char dir)
{
    ans.push_back(string(1,dir) + string(1,'0'+pos+1));
}

void rotateyf(int y)
{
    int t = a[N-1][y];
    for(int i = N - 1; i > 0; --i) a[i][y] = a[i - 1][y];
    a[0][y] = t;
}

void rotateyb(int y)
{
    int t = a[0][y];
    for(int i = 0; i < N - 1; ++i) a[i][y] = a[i + 1][y];
    a[N - 1][y] = t;
}

void rotatexf(int x)
{
    int t = a[x][N-1];
    for(int i = N-1; i > 0; --i) a[x][i] = a[x][i-1];
    a[x][0] = t;
}

void rotatexb(int x)
{
    int t = a[x][0];
    for(int i = 0; i < N-1; ++i) a[x][i] = a[x][i+1];
    a[x][N-1] = t;
}

void rotate(int x, int y, Orientation o, Direction d)
{
    if (o == Vertical) {
        if (d == Forward) {
            rotateyf(y);
            addAnswer(y, 'D');
        }
        else {
            rotateyb(y);
            addAnswer(y, 'U');
        }
    }
    else {
        if (d == Forward) {
            rotatexf(x);
            addAnswer(x, 'R');
        }
        else {
            rotatexb(x);
            addAnswer(x, 'L');
        }
    }
}

void rotate(int x, int y, int i, int j)
{
    if (x == i) {
        Direction d = Forward;
        if (y > j) d = Backward;
        for(int it = 0; it < abs(y - j); ++it) {
            rotate(x, y, Horizontal, d);
        }
    }
    else {
        assert(y == j);
        Direction d = Forward;
        if (x > i) d = Backward;
        for(int it = 0; it < abs(x - i); ++it) {
            rotate(x, y, Vertical, d);
        }
    }
}

void read()
{
 //   freopen("input.txt", "rt", stdin);
    for(int i = 0; i < 6; ++i) {
        string s; cin >> s;
        for(size_t j = 0; j < s.size(); ++j) {
            if (isdigit(s[j])) a[i][j] = s[j] - '0';
            else a[i][j] = s[j] - 'A' + 10;
        }
    }
}

void print()
{
    forn(i, N) {
        forn(j, N) {
            cout << a[i][j];
            if (j < N-1) cout << ",";
        }
        cout << endl;
    }
}

void rotatecw(int y)
{
    rotate(N-1, y+1, Vertical, Forward);
    rotate(N-1, y, Horizontal, Forward);
    rotate(N-1, y+1, Vertical, Backward);
    rotate(N-1, y, Horizontal, Backward);
}

void rotatecc(int y)
{
    rotate(N-1, y, Vertical, Forward);
    rotate(N-1, y, Horizontal, Backward);
    rotate(N-1, y, Vertical, Backward);
    rotate(N-1, y, Horizontal, Forward);
}

void rotate(int y)
{
    rotatecw(y);
    rotatecw(y);
    rotatecc(y+1);
    rotatecw(y);
}

void find(int val, int& x, int& y)
{
    forn(i, N) forn(j, N) if (a[i][j] == val) {
        x = i;
        y = j;
        return;
    }
}

int find(int val)
{
    forn(j, N) if (a[N-1][j] == val) return j;
    assert(false);
}

int main()
{
//    forn(i, N) forn(j, N) a[i][j] = i * N + j;
    read();
    forn(i, N-1) {
        forn(j, N) {
            int x, y;
            find(i*N+j, x, y);
            if (x == i) {
                rotate(x, y, Vertical, Forward);
                rotate(x+1, y, Horizontal, Forward);
                rotate(x, y, Vertical, Backward);
                ++x;
                y = (y + 1) % N;
            }
            rotate(x, y, i+1, (j+1)%N);
            rotate(i, j, Vertical, Forward);
            rotate(i+1, j, Horizontal, Backward);
            rotate(i, j, Vertical, Backward);
        }
    }

    while (true) {
    forn(y, N - 2) {
        int t = find((N-1)*N+y);
        while (y + 2 < t) {
            rotate(t-1);
            --t;
        }
        forn(it, t - y) {
            rotate(y);
        }
    }
    if (a[N-1][N-1] == N * N - 1) break;
    rotate(N-1, 0, Horizontal, Backward);
    }

//    print();
    forv(i, ans) cout << ans[i] << endl;
    return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <cmath>
using namespace std;

#define forn(i, n) for(int i = 0; i < int(n); ++i)
#define forv(i, v) forn(i, v.size())

vector<string> ans;
const int N = 6;
vector<vector<int> > a(N, vector<int>(N));

enum Orientation{Vertical, Horizontal};
enum Direction{Forward, Backward};

void addAnswer(int pos, char dir)
{
    ans.push_back(string(1,dir) + string(1,'0'+pos+1));
}

void rotateyf(int y)
{
    int t = a[N-1][y];
    for(int i = N - 1; i > 0; --i) a[i][y] = a[i - 1][y];
    a[0][y] = t;
}

void rotateyb(int y)
{
    int t = a[0][y];
    for(int i = 0; i < N - 1; ++i) a[i][y] = a[i + 1][y];
    a[N - 1][y] = t;
}

void rotatexf(int x)
{
    int t = a[x][N-1];
    for(int i = N-1; i > 0; --i) a[x][i] = a[x][i-1];
    a[x][0] = t;
}

void rotatexb(int x)
{
    int t = a[x][0];
    for(int i = 0; i < N-1; ++i) a[x][i] = a[x][i+1];
    a[x][N-1] = t;
}

void rotate(int x, int y, Orientation o, Direction d)
{
    if (o == Vertical) {
        if (d == Forward) {
            rotateyf(y);
            addAnswer(y, 'D');
        }
        else {
            rotateyb(y);
            addAnswer(y, 'U');
        }
    }
    else {
        if (d == Forward) {
            rotatexf(x);
            addAnswer(x, 'R');
        }
        else {
            rotatexb(x);
            addAnswer(x, 'L');
        }
    }
}

void rotate(int x, int y, int i, int j)
{
    if (x == i) {
        Direction d = Forward;
        if (y > j) d = Backward;
        for(int it = 0; it < abs(y - j); ++it) {
            rotate(x, y, Horizontal, d);
        }
    }
    else {
        assert(y == j);
        Direction d = Forward;
        if (x > i) d = Backward;
        for(int it = 0; it < abs(x - i); ++it) {
            rotate(x, y, Vertical, d);
        }
    }
}

void read()
{
    freopen("input.txt", "rt", stdin);
    for(int i = 0; i < 6; ++i) {
        string s; cin >> s;
        for(size_t j = 0; j < s.size(); ++j) {
            if (isdigit(s[j])) a[i][j] = s[j] - '0';
            else a[i][j] = s[j] - 'A' + 10;
        }
    }
}

void print()
{
    forn(i, N) {
        forn(j, N) {
            cout << a[i][j];
            if (j < N-1) cout << ",";
        }
        cout << endl;
    }
}

void rotatecw(int y)
{
    rotate(N-1, y+1, Vertical, Forward);
    rotate(N-1, y, Horizontal, Forward);
    rotate(N-1, y+1, Vertical, Backward);
    rotate(N-1, y, Horizontal, Backward);
}

void rotatecc(int y)
{
    rotate(N-1, y, Vertical, Forward);
    rotate(N-1, y, Horizontal, Backward);
    rotate(N-1, y, Vertical, Backward);
    rotate(N-1, y, Horizontal, Forward);
}

void rotate(int y)
{
    rotatecw(y);
    rotatecw(y);
    rotatecc(y+1);
    rotatecw(y);
}

void find(int val, int& x, int& y)
{
    forn(i, N) forn(j, N) if (a[i][j] == val) {
        x = i;
        y = j;
        return;
    }
}

int find(int val)
{
    forn(j, N) if (a[N-1][j] == val) return j;
    assert(false);
}

int main()
{
//    forn(i, N) forn(j, N) a[i][j] = i * N + j;
    read();
    forn(i, N-1) {
        forn(j, N) {
            int x, y;
            find(i*N+j, x, y);
            if (x == i) {
                rotate(x, y, Vertical, Forward);
                rotate(x+1, y, Horizontal, Forward);
                rotate(x, y, Vertical, Backward);
                ++x;
                y = (y + 1) % N;
            }
            rotate(x, y, x, (j+1)%N);
            rotate(i, j, x, j);
            rotate(x, (j+1)%N, x, j);
            rotate(x, j, i, j);
        }
    }

    while (true) {
    forn(y, N - 2) {
        int t = find((N-1)*N+y);
        while (y + 2 < t) {
            rotate(t-1);
            --t;
        }
        forn(it, t - y) {
            rotate(y);
        }
    }
    if (a[N-1][N-1] == N * N - 1) break;
    rotate(N-1, 0, Horizontal, Backward);
    }

    //print();
    forv(i, ans) cout << ans[i] << endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
typedef pair<char, int> pii;
const int N = 6;
string s[N], t = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
vector<pii> ans;
void add(int x, int y, char a, char b, char c) {
        if (a == 'D')
                swap(s[x][y], s[x + 1][y]);
        if (a == 'U')
                swap(s[x][y], s[x - 1][y]);
        if (a == 'L')
                swap(s[x][y], s[x][y + 1]);
        if (a == 'R')
                swap(s[x][y], s[x][y - 1]);
        if (a == 'U' || a == 'D')
                swap(x, y);
        ans.push_back(pii(c, y));
        ans.push_back(pii(b, x));
        ans.push_back(pii(c, y));
        ans.push_back(pii(a, x));
        ans.push_back(pii(c, y));
        ans.push_back(pii(b, x));
        ans.push_back(pii(c, y));
        ans.push_back(pii(a, x));
        ans.push_back(pii(c, y));
        ans.push_back(pii(b, x));
        ans.push_back(pii(c, y));
        ans.push_back(pii(a, x));
        ans.push_back(pii(c, y));
}

void move(int x, int y, int _x, int _y) {
        while (x < _x)
                add(x++, y, 'D', 'U', 'L');
        while (y < _y)
                add(x, y++, 'L', 'R', 'U');
        while (x > _x)
                add(x--, y, 'U', 'D', 'L');
        while (y > _y)
                add(x, y--, 'R', 'L', 'U');
}

int main() {
        ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
        for (int i = 0; i < N; i++)
                cin >> s[i];
        for (int k = 0; k < N * N; k++) {
                int x = -1, y = -1;
                for (int i = 0; i < N; i++)
                        for (int j = 0; j < N; j++)
                                if (s[i][j] == t[k]) {
                                        x = i;
                                        y = j;
                                }
                move(x, y, k / N, k % N);
        }
        cout << ans.size() << "\n";
        for (auto i: ans)
                cout << ans[i].ff << ans[i].ss + 1 << "\n";
        return 0;
}


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

#define pb push_back
#define ff first
#define ss second

vector <string> ans;
int i, j, x, y;
char c[8][8];

void Find(char op, int &x, int &y){
	for(x = 0; x < 6; x++)
		for(y = 0; y < 6; y++)
		    if(c[x][y] == op)
		        return;
}

void go(int x,int y,int flag){
	string v;
	for(int i = 0; i < 13; i++){
		if(!flag) {
			if(i & 1){
				if(i / 2 &1)
				    v = "D";
				else
				    v = "U";
				v += char(y + 49);
			}
			else {
			    v = "R";
			    v += char(x + 49);
			}
		}
		else{
			if(i & 1){
				if(i / 2 & 1)
				    v = "R";
				else
				    v = "L";
				v += char(x + 49);
			}
			else {
			    v = "D";
			    v += char(y + 49);
			}
		}
		ans.pb(v);
	}
	if(flag)
	    swap(c[x][y], c[x][y + 1]);
	else
	    swap(c[x][y], c[x + 1][y]);
}

int main(){
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    string s;
	for(i = 0; i < 6; i++) {
	    cin >> s;
	    for (int j = 0; j < 6; j++)
	        c[i][j] = s[j];
	}

	for(i = 0; i < 6; i++)
		for(j = 0; j < 6; j++){
			char op = i * 6 + j;
			if(op <= 9)
			    op = char(op + 48);
			else
			    op = char(op - 10 + 65);
			Find(op, x, y);
			while(y > j) {
			    work(x, y - 1, 1);
			    y--;
			}
			while(y < j) {
			    work(x, y, 1);
			    y++;
			}
			while(x > i) {
			    work(x - 1, y, 0);
			    x--;
			}
		}

	cout << ans.size() << '\n';
	for(auto y: ans)
	    cout << y << '\n';
	return 0;
}


#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <sstream>
#include <ctime>
#include <set>
#include <map>
#include <queue>
#include <memory.h>
#include <iomanip>
#define EPS 1e-7
#define INF (int)(1e+9)
#define LINF (long long)(1e+18)
#define PI acos(-1)
#define mp make_pair
#define MOD 1000000007

using namespace std;

#define NAME "test"
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

void solve(int test_number);

void pre() {
    cout.setf(ios::fixed);
    cout.precision(20);
    cerr.setf(ios::fixed);
    cerr.precision(3);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

void post() {
    printf("\n");
    fprintf(stderr, "Execution time: %Lf", (ld) clock());
}

const int MAXN = 100100;

inline void solve(int test_number) {
	string s;
	cin >> s;
	int i;
	string s1;
	s1 = "";
	int c1 = 0;
	for (i = 0; i < s.size(); i++) {
		if (s[i] == '/' && c1 != -1) {
			c1 = -1;
			s1 += s[i];
		}
		if (s[i] != '/') {
			s1 += s[i];
			c1 = 0;
		}
	}
	int cnt = 0;
	i = s.size() - 1;
	while (i >= 0) {
		if (s[i] != '/') {
			break;
		}
		else {
			cnt++;
		}
		i--;
	}
	if (i == -1) {
		cout << '/' << endl;
		return;
	}
	if (cnt != 0) s1.pop_back();
	}
	cout << s1 << endl;
	return;

}

int main()
{
#ifdef DEBUG
    freopen(NAME ".in", "r", stdin);
    freopen(NAME ".out", "w", stdout);
#endif
    //freopen(NAME ".in", "r", stdin);
    //freopen(NAME ".out", "w", stdout);
    pre();

    int n = 1;
    for (int i = 0; i < n; i++) {
            solve(i + 1);
    }

    post();
    return 0;
}


#include<iostream>
#include<string>
using namespace std;
int main()
{
    string a;
    cin>>a;
    for(int i=0;i<=a.size();i++)
    {
        if(a[i]=='/'&&a[i+1]=='/')
        { a.erase(i,1);i--;}
    }
    long i=a.size()-1;
    while(a[i]=='/'&&a.size>1)
    {
    	a.erase(i,1);
	}
	cout<<a;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int n=0;
    for(int i=1;s.length();i++)
	{
        if(!(s[i]==s[i-1]&&s[i]=='/')){++n;cout<<s[i-1];}
    }
    if(s[s.length()-1]!='/'||n==0)cout<<s[length()-1];
}


/************************************************************
* Problem:
* Link:
* Verdict:
* Date:
*
* Coder:     Md. Shahidul Islam
* Dept. :    Computer Science and Engineering
* Institute: Begum Rokeya University, Rangpur, Bangladesh
*
*************************************************************/

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

#define mem(a, b) memset(a, (b), sizeof(a))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(X) ( (X) > 0 ? (X) : ( -(X) ) )
#define S(X) ( (X) * (X) )
#define FORN(i, n) for(i = 0; i < n; i++)
#define FORAB(i, a, b) for(i = a; i <= b; i++)
#define IN(A, B, C)  ((B) <= (A) && (A) <= (C))
#define in freopen("in.txt", "r", stdin)
#define out freopen("out.txt", "w", stdout)
#define clr(arr, key) memset(arr, key, sizeof arr)
#define pb push_back
#define mp(a, b) make_pair(a, b)
#define inf (1 << 28)
#define ll long long
#define PI acos(-1)
#define gcd(a, b) __gcd(a, b)
#define fast ios_base::sync_with_stdio(0);cin.tie(0)
#define lcm(a, b) ((a)*((b)/gcd(a,b)))
#define no_of_ones __builtin_popcount // __builtin_popcountll for LL
#define SZ(v) (int)(v.size())
#define eps 1e-7
#define ppb pop_back
#define all(x) x.begin(),x.end()
#define AIN(A, B, C) assert(IN(A, B, C))
#define INF 1000000000
int dr[]={0, 0, 1, -1, 1, 1, -1, -1};
int dc[]={1, -1, 0, 0, 1, -1, 1, -1};

typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef vector<int> vi;
typedef vector<pii> vpi;

int main()
{
    fast;
    //in;
    //out;
    char str[102];
    cin>>str;
    int n=strlen(str);
    for(int i=0;i<len;i++)
    {
        if(str[i]!='/')
            cout<<str[i];
        else
        {
            cout<<str[i];
            while(i+1<len && str[i+1]=='/')
                i++;
        }
    }
    cout << "\n";
    return 0;
}