#include <cstdlib>
#include <cstdarg>
#include <cassert>
#include <cctype> // tolower
#include <ctime>
#include <cmath>

#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <stdexcept>

#include <map>
#include <tuple>
#include <unordered_map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <vector>
#include <string>

#include <limits>
#include <utility>
#include <memory>

#include <numeric>
#include <iterator>
#include <algorithm>
#include <functional>

/*
 * g++ -g -std=c++11 -DBUG -D_GLIBCXX_DEBUG -Wall -Wfatal-errors -o cforce{,.cpp}
 *
 * TODO:
 *      C++ dataframe
 *      stl11 -> c++11 standard template lib in c++98
 *      overload >> for map and set, using (insert) iterator
 *      chmod:: consider an algorithm stable to int64 overflow
 *      shortest path algorithm
 *      shortest path in a tree
 *      maximum network flow
 *      partial idx/iter sort
 *      a prime number generator which traverses prime numbers w/ ++
 *      a divisor generator which traverses divisors efficiently
 *      Apply1st ?!
 *      Apply2nd and bind2nd ?!
 *          count_if ( a.begin(), a.end(), a.second < x )
 *      Arbitrary-precision arithmetic / Big Integer / Fraction - rational num
 *      tuple class --> cplusplus.com/reference/tuple
 *      get<1>, get<2>, bind2nd ( foo ( get<2> pair ), val )
 *      isin( const T & val, first, last )
 *      fuinction composition in c++
 *          blogea.bureau14.fr/index.php/2012/11/function-composition-in-c11/
 *          cpp-next.com/archive/2010/11/expressive-c-fun-with-function-composition/
 *      TimeWrapper -- accumulate time of a function call
 *          stackoverflow.com/questions/879408
 *      hash map -- possible hash value & obj % some_big_prime [ b272 ]
 *          lower level can be a simple map to resolve hash collisions
 *      add explicit everywhere necessary
 *      bloom filters
 *      heap -> how to update values in place / increase-key or decrease-key ... IterHeap ?!
 *      median maintaince --> max_heap / min_heap
 *      prim's min spaning tree alg. O ( m log n ) using heap contianing V - X vertices
 *      kruskal algorithm minimum cost spanning tree with union find data structure
 *      unique_ptr
 *      hufman codes
 *      simple arithmatic tests
 *      longest common subsequence using seq. alignment type algorithm
 *      longest common substring ( consequative subsequeance )
 *      Graham scan; en.wikipedia.org/wiki/Graham_scan
 *      problem/120/F -- how to extend in order to calculate all-pair distances in a tree
 *      compile time prime number calculator using templates
 *      swith to type_cast < T1, T2 > for val2str & str2val
 *      overload plus<> for two vectors?!
 *      overloading operator << for std::tuple:
 *          stackoverflow.com/questions/9247723
 *      bitmask class with iterator protocol
 *      ??? segment tree +++ interval tree
 *      ??? an lru cache: a heap which maintains last access, an a map which maintains key:value
 */

/*
 * @recepies
 * ----------------------------------------------
 * odd / even
 *      transform ( x.begin(), x.end(), x.begin(), bind2nd( modulus<int>(), 2 ));
 *      count_if ( x.begin(), x.end(), bind2nd( modulus < int > (), 2));
 * Apply2nd
 *      max_element ( m.begin(), m.end(), Apply2nd < string, int , less < int > > )
 *      sort ( a.begin(), a.end(), Apply2nd < char, int , greater< int > > )
 *      count_if ( m.begin(), m.end(), Apply2nd < string, int, modulus < int > > )
 *      accumulate ( m.begin(), m.end(), 0.0, Apply2nd < int, double, plus < double > > )
 *      accumulate ( m.begin( ), m.end( ), pair < int, double> ( 0 , 0.0 ) , operator+ < int, double > )
 * abs_diff
 *      adjacent_difference ( a.begin(), a.end(), adj_diff.begin( ), abs_diff < int > ( ) )
 *      accumulate ( a.begin(), a.end(), 0, abs_diff < int > ( ) )
 * erase
 *      a.erase ( remove_if ( a.begin( ), a.end( ), bind2nd ( less < int >( ), 0 ) ), a.end( ) )
 *      a.erase ( remove ( a.begin( ), a.end( ), b.begin( ), b.end( ) ), a.end ( ) )
 * binding
 *      bind2nd ( mem_fun_ref (& ClassName::m_func ), arg )  // binds the argument of the object
 * iterator generators
 *      generate_n ( back_inserter ( a ), n, rand );  // calls push_back
 *      generate_n ( inserter( a, a.begin( ) + 5 ), 10, RandInt( 0 , 100 ) )  // calls insert
 *      copy ( foo.begin( ), foo.end( ), insert_iterator < std::list < double > > ( bar, bar.begin( ) + 5 ))
 * copy ( a.begin( ), a.end( ), ostream_iterator < double > ( cout, ", " ))
 * accumulate ( m.begin( ), m.end( ), pair < int, double> ( 0 , 0.0 ) , operator+ < int, double > )
 * transform (numbers.begin(), numbers.end(), lengths.begin(), mem_fun_ref(&string::length));
 */

/*
 * @good read
 * ----------------------------------------------
 *  [ partial ] template specialization
 *      cprogramming.com/tutorial/template_specialization.html
 *  function composition
 *      cpp-next.com/archive/2010/11/expressive-c-fun-with-function-composition
 */

/*
 * @prob set
 * ----------------------------------------------
 *  purification --> c330
 */

/*
 * @limits
 * ----------------------------------------------
 * int                  31    2.14e+09
 * long int             31    2.14e+09
 * unsigned             32    4.29e+09
 * long unsigned        32    4.29e+09
 * size_t               32    4.29e+09
 * long long int        63    9.22e+18
 * long long unsigned   64    1.84e+19
 */

/*
 * issues
 * ----------------------------------------------
 * stackoverflow.com/questions/10281809
 * mem_fun -> func_obj ( pointer to instance, origanal argument )
 * bind1st ( mem_fun ( & ClassName::m_func ), this )    // binds obj of the class
 * bind1st takes 'const T &' as the first argument
 */

/*
 *  typedef / define
 * ----------------------------------------------
 */

typedef          long long int  int64;
typedef unsigned long long int uint64;

#ifndef M_PI
#define M_PI 3.14159265358979323846L
#endif

#define DOUBLE_INF std::numeric_limits< double >::infinity()
#define DOUBLE_NAN std::numeric_limits< double >::quiet_NaN()

#define __STR__(a) #a
#define STR(a) __STR__(a)

#define ASSERT(expr, msg) \
    if (!( expr )) \
        throw std::runtime_error(__FILE__ ":" STR(__LINE__) " - " msg);

#define DECLARE( X ) \
    typedef       std::shared_ptr < X >  X ## _shared_ptr; \
    typedef const std::shared_ptr < X >  X ## _const_shared_ptr;

#ifdef BUG
    #define DEBUG(var) { std::cout << #var << ": " << (var) << std::endl; }
    #define COND_DEBUG(expr, var) if (expr) \
        { std::cout << #var << ": " << (var) << std::endl; }
    #define EXPECT(expr) if ( ! (expr) ) std::cerr << "Assertion " \
        << #expr " failed at " << __FILE__ << ":" << __LINE__ << std::endl;
#else
    #define DEBUG(var)
    #define COND_DEBUG(expr, var)
    #define EXPECT(expr)
#endif

#define DBG(v) std::copy( v.begin(), v.end(), std::ostream_iterator < typeof( *v.begin() )> ( std::cout, " " ) )

#if __cplusplus < 201100
    #define move( var ) var
#endif

/*
 * http://rootdirectory.de/wiki/SSTR()
 * usage:
 *      SSTR( "x^2: " << x*x )
 */
#define SSTR( val ) dynamic_cast< std::ostringstream & >( std::ostringstream() << std::dec << val ).str()

/* https://www.quora.com/C++-programming-language/What-are-some-cool-C++-tricks */
// template <typename T, size_t N>
// char (&ArraySizeHelper(T (&array)[N]))[N];
// #define arraysize(array) (sizeof(ArraySizeHelper(array)))

/*
 * forward decleration
 * ----------------------------------------------
 */
class ScopeTimer;

/*
 *  functional utils
 * ----------------------------------------------
 */

template < typename T >
struct abs_diff : std::binary_function < T, T, T >
{
    typedef T value_type;

    inline value_type operator( ) ( const value_type & x, const value_type & y ) const
    {
        return std::abs( x - y );
    }
};

// template < class InputIterator, class T >
// class isin : public std::binary_function < InputIterator, InputIterator, bool >
// {
//     public:
//         typedef T value_type;
//
//         isin ( const InputIterator & first, const InputIterator & last ):
//             m_first ( first ), m_last ( last ) { }
//
//         bool operator ( ) ( const value_type & val ) const
//         {
//             return std::find ( m_first, m_last, val ) != m_last;
//         }
//     private:
//         const InputIterator m_first, m_last;
// }

template < typename value_type, typename cont_type >
class isin : public std::unary_function < value_type, bool >
{
    public:
        isin( const cont_type & vals ): m_vals ( vals ) { };

        bool operator ( ) ( const value_type & x ) const
        {
            return std::find ( m_vals.begin( ), m_vals.end( ), x ) != m_vals.end( );
        }

    private:
        const cont_type m_vals;
};

/*
 * max_element, min_element, count_if ... on the 2nd element
 * eg: max_element ( m.begin(), m.end(), Apply2nd < string, int , less < int > > )
 */
template < class T1, class T2, class BinaryOperation >
class Apply2nd : std::binary_function < typename std::pair < T1, T2 >,
                                        typename std::pair < T1, T2 >,
                                        typename BinaryOperation::result_type >
{
    public:
        typedef T1 first_type;
        typedef T2 second_type;

        typedef typename BinaryOperation::result_type result_type;
        typedef typename std::pair < first_type, second_type > value_type;

        inline result_type operator( ) ( const value_type & x, const value_type & y ) const
        {
            return binary_op ( x.second , y.second );
        }
    private:
        BinaryOperation binary_op;
};

/*
 * algo utils
 * ----------------------------------------------
 */

/**
 * count the number of inversions in a permutation; i.e. how many
 * times two adjacent elements need to be swaped to sort the list;
 * 3 5 2 4 1  -->  7
 */
template < class InputIterator >
typename std::iterator_traits<InputIterator>::difference_type
count_inv ( InputIterator first, InputIterator last )
{
    typedef typename std::iterator_traits<InputIterator>::difference_type difference_type;
    typedef typename std::iterator_traits<InputIterator>::value_type value_type;

    std::list < value_type > l; /* list of sorted values */
    difference_type cnt = 0;

    for ( difference_type n = 0; first != last; ++first, ++n )
    {
        /* count how many elements larger than *first appear before *first */
        typename std::list < value_type >::iterator iter = l.begin( );
        cnt += n;

        for ( ; iter != l.end( ) && * iter <= * first; ++ iter, -- cnt )
            ;
        l.insert( iter, * first );
    }

    return cnt;
}

template < class ForwardIterator, class T >
inline void fill_inc_seq ( ForwardIterator first, ForwardIterator last, T val )
{
    for ( ; first != last; ++first, ++val )
        * first = val;
}

template <class ForwardIterator, class InputIterator >
ForwardIterator remove ( ForwardIterator first, ForwardIterator last, InputIterator begin, InputIterator end )
{
    ForwardIterator result = first;

    for ( ; first != last; ++ first )
        if ( find ( begin, end, *first ) == end )
        {
            *result = *first;
            ++result;
        }

    return result;
}

/* stackoverflow.com/questions/1577475 */
template < class RAIter, class Compare >
class ArgSortComp
{
    public:
        ArgSortComp ( const RAIter & first, Compare comp ):  m_first ( first ), m_comp( comp ) { }
        inline bool operator() ( const size_t & i, const size_t & j ) const
        {
            return m_comp (  m_first[ i ] ,  m_first[ j ] );
        }
    private:
        const RAIter & m_first;
        const Compare m_comp;
};

/*!
 * usage:
 *      vector < size_t > idx;
 *      argsort ( a.begin( ), a.end( ), idx, less < Type > ( ) );
 */
template < class RAIter, class Compare=std::less< typename RAIter::value_type > >
void argsort( const RAIter & first,
              const RAIter & last,
              std::vector < size_t > & idx,
              Compare comp = Compare()) // std::less< typename RAIter::value_type >() )
{
    const size_t n = last - first;
    idx.resize ( n );

    for ( size_t j = 0; j < n; ++ j )
        idx[ j ] = j ;

    std::stable_sort( idx.begin(), idx.end(), ArgSortComp< RAIter, Compare >( first, comp ));
}

template < class RAIter, class Compare >
class IterSortComp
{
    public:
        IterSortComp ( Compare comp ): m_comp ( comp ) { }
        inline bool operator( ) ( const RAIter & i, const RAIter & j ) const
        {
            return m_comp ( * i, * j );
        }
    private:
        const Compare m_comp;
};

/*!
 * usage:
 *      vector < list < Type >::const_iterator > idx;
 *      itersort ( a.begin( ), a.end( ), idx, less < Type > ( ) );
 */
template <class INIter, class RAIter, class Compare>
void itersort ( INIter first, INIter last, std::vector < RAIter > & idx, Compare comp )
{
    /* alternatively: stackoverflow.com/questions/4307271 */
    idx.resize ( std::distance ( first, last ) );
    for ( typename std::vector < RAIter >::iterator j = idx.begin( ); first != last; ++ j, ++ first )
        * j = first;

    std::sort ( idx.begin( ), idx.end( ), IterSortComp< RAIter, Compare > (comp ) );
}

/*
 *  string utils
 * ----------------------------------------------
 */

inline void erase ( std::string & str, const char & ch )
{
    std::binder2nd < std::equal_to < char > > isch ( std::equal_to < char > ( ), ch );
    std::string::iterator iter = std::remove_if ( str.begin(), str.end(), isch );
    str.erase ( iter, str.end() );
}

inline void erase ( std::string & str, const std::string & chrs )
{
    isin < char, std::string > isin_chrs ( chrs );
    std::string::iterator iter = std::remove_if ( str.begin(), str.end(), isin_chrs );
    str.erase ( iter, str.end() );
}

template < typename value_type>
inline std::string val2str ( const value_type & x )
{
    std::ostringstream sout ( std::ios_base::out );
    sout << x;
    return sout.str();
}

template < typename value_type>
inline value_type str2val ( const std::string & str )
{
    std::istringstream iss ( str, std::ios_base::in );
    value_type val;

    iss >> val;
    return val;
}

std::vector< std::string > tokenize ( const std::string & str, const char & sep )
{
    /*!
     * outputs empty tokens and assumes str does not start with sep
     * corner cases:
     *      empty string, one char string,
     *      string starting/ending with sep, all sep, end with two sep
     */

    std::vector < std::string > res;
    std::string::const_iterator follow = str.begin(),
                                lead   = str.begin();

    while ( true )
    {
        while ( lead != str.end() && * lead != sep )
            ++ lead;

        res.push_back ( std::string( follow, lead ) );

        if ( lead != str.end () )
            follow = 1 + lead ++ ;
        else
            break;
    }

    return res;
}

/*!
 * chunk a string into strings of size [ at most ] k
 */
void chunk ( const std::string::const_iterator first,
             const std::string::const_iterator last,
             const size_t k,
             const bool right_to_left,
             std::list < std::string > & str_list )
{
    str_list.clear( );

    if ( right_to_left )
        /* chunk from the end of the string */
        for ( std::string::const_iterator i, j = last; j != first; j = i )
        {
            i = first + k < j ? j - k : first;
            str_list.push_back ( std::string ( i, j ) );
        }
    else
        /* chunk from the begining of the string */
        for ( std::string::const_iterator i = first, j; i != last; i = j )
        {
            j = i + k < last ? i + k : last;
            str_list.push_back ( std::string ( i, j ) );
        }
}

/*!
 * next lexicographically smallest string
 * within char set a..z
 */
std::string & operator++( std::string & s )
{
    /* find the first char from right less than 'z' */
    std::string::reverse_iterator j = find_if( s.rbegin( ), s.rend( ),
            std::bind2nd( std::less < char > ( ), 'z' ));

    if ( j != s.rend( ))
    {
        ++ *j;
        std::fill( s.rbegin( ), j, 'a' );
    }
    else
        s.assign( s.length( ) + 1, 'a' );

    return s;
}

/*!
 * getline ( cin, str )
 *      requires ctrl-D
 *      cin >> str; does not pass after space char
 */

/*
 *  number utils
 * ----------------------------------------------
 */

class BigInteger
{
#if ULONG_MAX <= 1 << 32
    typedef long long unsigned val_type;
#else
    typedef long unsigned val_type;
#endif
    const static int WSIZE = 32;
    const static val_type BASE = 1LL << WSIZE;
    public:
    private:
        std::list < val_type > val;  /* val[ 0 ] is most significant */
        bool pos;                    /* true if sign is positive     */
};

/**
 * greatest common divisor - Euclid's alg.
 */
template < typename value_type > inline
value_type gcd ( value_type a, value_type b )
{
    return ! b ? a : gcd( b, a % b );
}

/**
 * prime factorization
 */
template < class T >
void prime_factors( T n, std::map < T, size_t > & fac )
{
    for ( T k = 2; n > 1; ++ k )
        if ( ! ( n % k ) )
        {
            size_t & ref = fac[ k ];
            while ( ! ( n % k ) )
            {
                ++ ref;
                n /= k;
            }
        }
}

/* abs diff - safe for unsigned types */
template < class T >
inline T absdiff( T a, T b )
{
    return a < b ? b - a : a - b;
}

namespace
{
    template < class T >
    std::pair < T, T > __extgcd ( const T & x0, const T & y0,
                                  const T & x1, const T & y1,
                                  const T & r0, const T & r1 )
    {
        const T q  = r0 / r1;
        const T r2 = r0 % r1;

        if ( ! ( r1 % r2 ) )
            return std::make_pair < T, T > ( x0 - q * x1, y0 - q * y1 );

        const T x2 = x0 - q * x1;
        const T y2 = y0 - q * y1;

        return __extgcd ( x1, y1, x2, y2, r1, r2 );
    }
}

/**
 * extended euclidean algorithm: a x  +  b y = gcd( a, b)
 * en.wikipedia.org/wiki/Extended_Euclidean_algorithm
 */
template < class value_type > inline
std::pair < value_type, value_type > extgcd ( value_type a, value_type b )
{
    return a % b
        ? __extgcd < value_type > ( 1, 0, 0, 1, a, b )
        : std::make_pair < value_type, value_type > ( 0, 1 );
}

/**
 * modular multiplicative inverse
 * en.wikipedia.org/wiki/Modular_multiplicative_inverse
 */
template < class value_type > inline
value_type modinv ( value_type a, value_type m )
{
    const std::pair < value_type, value_type > coef ( extgcd( a, m ) );

    /* a needs to be coprime to the modulus, or the inverse won't exist */
    if ( a * coef.first + m * coef.second != 1 )
        throw std::runtime_error ( val2str( a ) + " is not coprime to " + val2str( m ));

    /* return a pos num between 1 & m-1 */
    return ( m + coef.first % m ) % m;
}

inline bool isnan ( const double & a )
{
    return ! ( a == a );
}

template < typename value_type >
inline value_type mini ( int n, ... )
{
    va_list vl;
    va_start (vl, n);
    value_type res = va_arg ( vl, value_type );

    for ( int i = 1; i < n; ++i ) {
        const value_type val = va_arg ( vl, value_type );
        res = std::min ( res, val );
    }

    va_end( vl );
    return res;
}

template < typename value_type >
inline value_type maxi ( int n, ... )
{
    va_list vl;
    va_start (vl, n);
    value_type res = va_arg ( vl, value_type );

    for ( int i = 1; i < n; ++i ) {
        const value_type val = va_arg ( vl, value_type );
        res = std::max ( res, val );
    }

    va_end( vl );
    return res;
}

// XXX look this up how is this implemented
template < class T >
inline int sign ( const T & x )
{
    if ( x == T() )
        return 0;
    else if ( x < T() )
        return -1;
    else
        return 1;
}

/*
 * change moduluos from n to m
 */
std::string chmod ( std::string num, const unsigned n, const unsigned m )
{
    const char * digit = "0123456789abcdefghijklmnopqrstuvwxyz";
    std::transform ( num.begin(), num.end(), num.begin(), tolower );

    isin < char, std::string > is_alpha_num ( digit );
    assert ( find_if ( num.begin( ), num.end( ), std::not1 ( is_alpha_num ) ) == num.end( ));

    unsigned long long int val ( 0 );

    if ( n == 10U )
    {
        std::istringstream iss ( num, std::ios_base::in );
        iss >> val;
    }
    else
        for ( std::string::const_iterator iter = num.begin( ); iter != num.end( ); ++ iter )
            val = val * n + ( 'a' <= *iter ? *iter - 'a' + 10U : *iter - '0');

    if ( m == 10U )
    {
        std::ostringstream sout ( std::ios_base::out );
        sout << val;
        return sout.str ( );
    }
    else
    {
        std::string res;
        for ( ; val ; val /= m )
            res.push_back( digit [ val % m ] );

        return res.length( ) ? std::string( res.rbegin( ), res.rend( )) : "0";
    }
}

template < class value_type >  /* a^n mod m */
value_type powmod ( value_type a, const value_type & n, const value_type & m )
{
    if ( a == 1 || ! n )
        return m != 1 ? 1 : 0;

    value_type res = 1;
    for ( value_type k = 1; k <= n; a = a * a % m, k = k << 1 )
        if ( k & n )
            res =  ( res * a ) % m;

    return res;
}

template < class T >
inline T atan(const T & x, const T & y) { return std::atan( y / x ) + ( x < 0 ) * M_PI; }

/*
 * Fermat pseudoprime test
 * www.math.umbc.edu/~campbell/Computers/Python/numbthy.py
 * NOTE: since return type is bool, and powmod may break for ints,
 *       the argument is always casted to long long
 */
inline bool is_pseudo_prime ( const long long & a )
{
    /* all the primes less than 1000 ( 168 primes )*/
    const long long p [ ] = { 2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,
                              79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,
                              163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,
                              241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,
                              337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,
                              431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,
                              521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,
                              617,619,631,641,643,647,653,659,661,673,677,683,691,701,709,
                              719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,
                              823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,
                              929,937,941,947,953,967,971,977,983,991,997 };

    const size_t n = sizeof( p ) / sizeof ( p[ 0 ] );

    if ( a < p[ n - 1 ] + 1)
        return std::binary_search ( p, p + n , a );

    if ( std::find_if ( p, p + n, std::not1 ( std::bind1st ( std::modulus< long long >( ), a ))) != p + n )
        return false;

    const size_t k = a <    9006401LL ? 3 :
                     a <   10403641LL ? 4 :
                     a <   42702661LL ? 5 :
                     a < 1112103541LL ? 6 : 7;

    for ( size_t j = 0; j < k; ++ j )
        if ( powmod ( p[ j ], a - 1, a ) != 1 )
            return false;

    return true;
}

/*
 * returns a sorted vector of all primes less than or equal to n
 * maximum adj diff of all primes less than 1e5 is 72 ( 114 for 1e6 )
 */
template < typename value_type >
std::vector < value_type > get_primes ( const value_type n )
{
#ifdef BUG
    ScopeTimer scope_timer ( "std::vector < value_type > get_primes ( const value_type n )" );
#endif

    // typedef typename std::vector < value_type >::iterator iterator;
    std::vector < value_type > primes;

    for ( value_type k = 2 ; k <= n; ++ k )
        if ( is_pseudo_prime ( k ) )
        {
            // FIXME this is very stupid
            // const value_type sqrt_k = 1 + static_cast < value_type > ( sqrt ( k + 1 ) );
            // iterator iend = upper_bound ( primes.begin( ), primes.end( ), sqrt_k );

            // if ( find_if ( primes.begin( ), iend, std::not1 ( std::bind1st ( std::modulus< value_type >( ), k ) ) ) != iend )
            //     continue;

            primes.push_back ( k );
        }

    return primes;
}

template < class T >
inline std::vector < std::pair < T, size_t > > get_prime_fact( T a )
{
    std::vector< std::pair < T, size_t > >fac;

    for ( T k = 2; a > 1; ++ k )
        if ( ! ( a % k ) )  // no need to check if k is prime
        {
            size_t m = 0;
            for ( ; ! ( a % k ) ; ++m, a/= k )
                ;

            fac.push_back ( std::pair < T, size_t > ( k, m ) );
        }
    return fac;
}

template < class T >  /* prime factorization */
std::vector < std::pair < T, size_t > > get_prime_fac( T a )
{
    std::vector < std::pair < T, size_t > > fac;

    size_t k = 0;
    while (!(a % 2)) { a /= 2; ++ k; }
    if ( k != 0 ) fac.push_back( std::make_pair(2, k));

    k = 0;
    while (!(a % 3)) { a /= 3; ++ k; }
    if ( k != 0 ) fac.push_back( std::make_pair(3, k));

    for ( T j = 5; j * j < a + 1 && a > 1 && j < a + 1; j += 4 )
    {
        size_t k = 0;
        while (!(a % j)) { a /= j; ++ k; }
        if ( k != 0 ) fac.push_back( std::make_pair(j, k));

        j += 2; k = 0;
        while (!(a % j)) { a /= j; ++ k; }
        if ( k != 0 ) fac.push_back( std::make_pair(j, k));
    }

    if ( a > 1 ) fac.push_back( std::make_pair(a, 1));
    return fac;
}

template < class T > /* generates all divisors from vector of prime factorization */
void gen_div( T a, std::vector < T > & divs,
        typename std::vector < std::pair < T, size_t > >::const_iterator iter,
        typename std::vector < std::pair < T, size_t > >::const_iterator last )
{
    if ( iter != last )
    {
        auto next = iter + 1;
        const auto k = iter->second + 1;
        const auto prime = iter->first;
        for ( size_t j = 0; j < k; ++ j )
        {
            gen_div(a, divs, next, last);
            a *= prime;
        }
    }
    else
        divs.push_back( a );
}

template < class T >
T n_choose_k ( T n, T k )
{
    if ( k > n )
        return 0;

    const T lb = std::min ( k, n - k ) + 1;
    const T ub = n - lb + 1;

    T res = 1, j = 2;
    while ( n > ub && j < lb)
    {
        res *= n--;
        while ( j < lb and ! (res % j) )
            res /= j++;
    }

    while ( n > ub )
        res *= n--;

    return res;
}

/**
 * median calculator, using two heaps
 */
template < class InputIter >
inline std::pair < typename InputIter::value_type, typename InputIter::value_type >
median ( InputIter first, InputIter last )
{
    typedef typename InputIter::value_type      value_type;
    typedef std::pair< value_type, value_type > result_type;

    /*
     * max_heap:
     *      - the lower half of the elements
     *      - the biggest of such elements is on the top
     */
    std::vector < value_type > max_heap, min_heap;

    /*
     * comp argument to heap algorithm should provide
     * 'strict weak ordering'; in particular
     *      std::not2 ( std::less < value_type > )
     * does not have such a strict weak ordering;
     */
    std::less    < value_type > max_heap_comp;
    std::greater < value_type > min_heap_comp;

    if ( first == last )  /* corner case: empty vector */
        throw std::runtime_error ( "median of an empty vector is undefined!" );

    InputIter iter = first;
    max_heap.push_back ( * iter );

    for ( ++iter ; iter != last; ++ iter )
        if ( * iter < max_heap.front() )
        {
            max_heap.push_back ( * iter );
            std::push_heap ( max_heap.begin(), max_heap.end(), max_heap_comp );

            if ( min_heap.size() + 1 < max_heap.size() )
            {
                /* max_heap has got too large */
                min_heap.push_back( max_heap.front() );
                std::push_heap( min_heap.begin(), min_heap.end(), min_heap_comp );

                std::pop_heap( max_heap.begin(), max_heap.end(), max_heap_comp );
                max_heap.pop_back();
            }
        }
        else
        {
            min_heap.push_back ( * iter );
            std::push_heap ( min_heap.begin(), min_heap.end(), min_heap_comp );

            if ( max_heap.size() + 1 < min_heap.size() )
            {
                /* min_heap has got too large */
                max_heap.push_back( min_heap.front() );
                std::push_heap( max_heap.begin(), max_heap.end(), max_heap_comp );

                std::pop_heap( min_heap.begin(), min_heap.end(), min_heap_comp );
                min_heap.pop_back();
            }
        }

    DEBUG( max_heap );
    DEBUG( min_heap );

    return min_heap.empty( )  /* corner case: ++first = last */
        ? result_type ( *first, *first )
        : result_type ( max_heap.size() < min_heap.size() ? min_heap.front() : max_heap.front(),
                        min_heap.size() < max_heap.size() ? max_heap.front() : min_heap.front() );
}

/*
 * geometry util
 * ----------------------------------------------
 */

struct xyPoint
{
    double x, y;
    xyPoint( const double & a = .0, const double & b = .0 ): x ( a ), y( b ) { };
};

struct xyCircle
{
    xyPoint center;
    double radius;
};

std::ostream & operator<< ( std::ostream & out, const xyPoint & p )
{
    out << '(' << p.x << ", " << p.y << ')';
    return out;
}

std::istream & operator>> ( std::istream & ist, xyPoint & p )
{
    ist >> p.x >> p.y;
    return ist;
}

std::ostream & operator<< ( std::ostream & out, const xyCircle & o )
{
    out << "{(" << o.center.x << ", " << o.center.y << ") " << o.radius << '}';
    return out;
}

std::istream & operator>> ( std::istream & ist, xyCircle & o )
{
    ist >> o.center.x >> o.center.y >> o.radius;
    return ist;
}

inline double cartesian_dist ( const xyPoint & a, const xyPoint & b )
{
    const double d = a.x - b.x;
    const double e = a.y - b.y;
    return std::sqrt ( d * d + e * e );
}

class xyLine
{
    public:
        xyLine ( const xyPoint & , const xyPoint & );
        xyLine ( const double slope, const double intercept );

        /*
         * 'signed' orthogonal distance; the sign is useful
         * to compare which side of the line the point is
         */
        inline double orth_dist ( const xyPoint & ) const;
    private:
        double m_slope;
        double m_intercept;
        double m_normfac;   /* normalization factor for orth_dist calc */

        bool   m_vertical;  /* if the line is verticcal                */
        double m_xcross;    /* x axis cross point for vertical line    */
};

xyLine::xyLine ( const xyPoint & a, const xyPoint & b )
{
    if ( a.x == b.x )  /* vertical line */
    {
        m_vertical  = true;
        m_xcross    = a.x;

        m_intercept = DOUBLE_NAN;
        m_slope     = DOUBLE_INF;
        m_normfac   = DOUBLE_NAN;
    }
    else
    {
        m_vertical  = false;
        m_xcross    = DOUBLE_NAN;

        m_slope     = ( b.y - a.y ) / ( b.x - a.x );
        m_intercept = a.y - m_slope * a.x;
        m_normfac   = std::sqrt ( m_slope * m_slope + 1.0 );
    }
}

xyLine::xyLine ( const double slope, const double intercept ):
    m_slope ( slope ),  m_intercept ( intercept )
{
     m_vertical = false;
     m_xcross   = DOUBLE_NAN;
     m_normfac  = std::sqrt ( m_slope * m_slope + 1.0 );
}

double xyLine::orth_dist ( const xyPoint & o ) const /* 'signed' orthogonal distance */
{
    if ( m_vertical )
        return o.x - m_xcross;
    else
        return ( m_slope * o.x - o.y + m_intercept ) / m_normfac;
}

inline double triangle_area ( const xyPoint & a, const xyPoint & b, const xyPoint & c )
{
    const xyLine l ( a, b );
    const double h = std::abs ( l.orth_dist ( c ) );
    const double e = cartesian_dist ( a, b );
    return h * e;
}

/*
 *  operator<< overrides
 * ----------------------------------------------
 */

namespace
{
    /* helper function to output containers */
    template < typename T >
    std::ostream & __output ( std::ostream & out, const T & a )
    {
        typedef typename T::const_iterator const_iterator;
        out << "{ ";

        // does not work for 'pair' value type
        // std::copy ( a.begin( ), a.end( ), std::ostream_iterator < typename T::value_type > ( std::cout, ", " ));

        for ( const_iterator iter = a.begin(); iter != a.end(); ++ iter )
             out << ( iter != a.begin( ) ? ", " : "" ) << *iter ;

        return out << " }";
    }
}

template < typename key_type, typename value_type >
std::ostream & operator<< ( std::ostream & out, const std::pair < key_type, value_type > & p)
{
    out << "(" << p.first << ", " << p.second << ")";
    return out;
}

template < typename T0, typename T1, typename T2 >
std::ostream & operator<< ( std::ostream & out, const std::tuple < T0, T1, T2 > & t )
{
    out << "(" << std::get<0>(t) << ", " << std::get<1>(t) << ", " << std::get<2>(t) << ")";
    return out;
}

template < typename key_type, typename value_type, typename comp >
std::ostream & operator<< ( std::ostream & out, const std::map < key_type, value_type, comp > & m )
{
    return __output ( out, m );
}

template < typename value_type, typename comp >
std::ostream & operator<< ( std::ostream & out, const std::set < value_type, comp > & s )
{
    return __output ( out, s );
}

template < typename value_type >
std::ostream & operator<< ( std::ostream & out, const std::vector < value_type > & a )
{
    return __output ( out, a );
}

template < typename value_type >
std::ostream & operator<< ( std::ostream & out, const std::list < value_type > & a )
{
    return __output ( out, a );
}

template < typename value_type >
std::ostream & operator<< ( std::ostream & out, const std::vector < std::vector < value_type > > & a )
{
    typedef typename std::vector < std::vector < value_type > >::const_iterator const_iterator;

    for ( const_iterator iter = a.begin( ); iter != a.end( ); ++ iter )
        out << '\n' << *iter ;

    return out;
}

/*
 *  operator>> overrides
 * ----------------------------------------------
 */

template < typename key_type, typename value_type >
std::istream & operator>> ( std::istream & in, std::pair < key_type, value_type > & p)
{
    in >> p.first >> p.second;
    return in;
}

template < typename T0, typename T1, typename T2 >
std::istream & operator>> ( std::istream & fin, std::tuple < T0, T1, T2 > & t )
{
    fin >> std::get<0>(t) >> std::get<1>(t) >> std::get<2>(t);
    return fin;
}

template < typename value_type >
std::istream & operator>> ( std::istream & in, std::vector < value_type > & a )
{
    typedef typename std::vector < value_type >::iterator iterator;

    if ( ! a.size( ) )
    {
        size_t n;
        in >> n;
        a.resize( n );
    }

    for ( iterator iter = a.begin(); iter != a.end(); ++ iter )
        in >> * iter;

    return in;
}

/*
 *  readin quick utilities
 * ----------------------------------------------
 */

// template < typename value_type >
// inline void readin ( std::vector < value_type > & a, size_t n = 0, std::istream & in = std::cin )
// {
//     // if ( ! n ) std::cin >> n;
//     if ( ! n ) in >> n ;
//     a.resize ( n );
//     // std::cin >> a;
//     in >> a;
// }

// XXX consider removing
// template < typename key_type, typename value_type >
// inline void readin (std::vector < std::pair < key_type , value_type > > & a, size_t n = 0 )
// {
//     if ( !n ) std::cin >> n;
//     a.resize( n );
//     std::cin >> a;
// }

/*
 *  pair utility
 * ----------------------------------------------
 */

/*
 * accumulate ( m.begin( ), m.end( ), pair < int, double> ( 0 , 0.0 ) , operator+ < int, double > );
 * stackoverflow.com/questions/18640152
 */
template < typename T1, typename T2 >
inline std::pair < T1, T2 > operator+ ( const std::pair < T1, T2 > & a, const std::pair < T1, T2 > & b )
{
    return std::make_pair < T1, T2 > ( a.first + b.first, a.second + b.second );
}

template < typename T1, typename T2 >
inline std::pair < T1, T2 > operator- ( const std::pair < T1, T2 > & a, const std::pair < T1, T2 > & b )
{
    return std::make_pair < T1, T2 > ( a.first - b.first, a.second - b.second );
}

// template < class T1, class T2, class BinaryOperation >
// class Apply2nd : std::binary_function < typename std::pair < T1, T2 >,
//                                         typename std::pair < T1, T2 >,
//                                         typename BinaryOperation::result_type >

namespace
{
    /*!
     * helper template to do the work
     */
    template < size_t J, class T1, class T2 >
    struct Get;

    template < class T1, class T2 >
    struct Get < 0, T1, T2 >
    {
        typedef typename std::pair < T1, T2 >::first_type result_type;

        static       result_type & elm (       std::pair < T1, T2 > & pr ) { return pr.first; }
        static const result_type & elm ( const std::pair < T1, T2 > & pr ) { return pr.first; }
    };

    template < class T1, class T2 >
    struct Get < 1, T1, T2 >
    {
        typedef typename std::pair < T1, T2 >::second_type result_type;

        static       result_type & elm (       std::pair < T1, T2 > & pr ) { return pr.second; }
        static const result_type & elm ( const std::pair < T1, T2 > & pr ) { return pr.second; }
    };
}

template < size_t J, class T1, class T2 >
typename Get< J, T1, T2 >::result_type & get ( std::pair< T1, T2 > & pr )
{
    return Get < J, T1, T2 >::elm( pr );
}

template < size_t J, class T1, class T2 >
const typename Get< J, T1, T2 >::result_type & get ( const std::pair< T1, T2 > & pr )
{
    return Get < J, T1, T2 >::elm( pr );
}

/*
 * graph utils
 * ----------------------------------------------
 */

/*
 * Dijkstra :: single-source shortest path problem for
 * a graph with non-negative edge path costs, producing
 * a shortest path tree
 * en.wikipedia.org/wiki/Dijkstra's_algorithm
 */
template < typename DistType >
void Dijekstra ( const size_t & source,
                 const std::vector < std::list < size_t > > & adj,          // adjacency list
                 const std::vector < std::vector < DistType > > & edge_len, // pair-wise distance for adjacent nodes
                 std::vector < DistType > & dist,  // distance from the source
                 std::vector < size_t > prev )     // previous node in the shortest path tree
{
    // TODO
}

// TODO http://en.wikipedia.org/wiki/Shortest_path_problem
// TODO Graph class, Weighted graph, ...

/*
 *  maximum cardinality matching in a bipartite graph
 *        G = G1 ∪ G2 ∪ {NIL}
 *  where G1 and G2 are partition of graph and NIL is a special null vertex
 *  https://en.wikipedia.org/wiki/Hopcroft-Karp_algorithm
 */
class HopcroftKarp
{
    public:
        HopcroftKarp ( const std::vector < std::list < size_t > > & adj,
                       const std::vector < bool > & tag );

        size_t get_npair ( ) { return npair; };
        std::map < size_t, size_t > get_map ( );

    private:
        bool mf_breadth_first_search ( );  // breadth first search from unpaired nodes in G1
        bool mf_depth_first_search ( const size_t v ); // dfs w/ toggeling augmenting paths

        const std::vector < std::list < size_t > > & m_adj;  // adjacency list for each node
        const std::vector < bool > & m_tag;  // binary tag distinguishing partitions

        size_t npair;
        const size_t NIL;  // special null vertex
        const size_t INF;  // practically infinity distance

        std::vector < size_t > m_g1;    // set of nodes with tag = true
        std::vector < size_t > m_dist;  // dist from unpaired vertices in G1
        std::vector < size_t > m_pair;
};

std::map < size_t, size_t > HopcroftKarp::get_map ( )
{
    std::map < size_t, size_t > m;

    for ( size_t j = 0; j < m_pair.size( ); ++ j )
        if ( m_pair[ j ] != NIL  && m_tag[ j ])
            m[ j ] = m_pair[ j ];

    return m;
}

HopcroftKarp::HopcroftKarp ( const std::vector < std::list < size_t > > & adj,
                             const std::vector < bool > & tag ):
    m_adj ( adj ),
    m_tag ( tag ),
    npair ( 0 ),
    NIL ( adj.size( )),
    INF ( adj.size( ) + 1 ),
    m_dist ( std::vector < size_t > ( adj.size( ) + 1, INF)),
    m_pair ( std::vector < size_t > ( adj.size( ), NIL ))  // initially everything is paired with nil
{
    assert ( m_adj.size() == m_tag.size() );

    for ( size_t j = 0; j < tag.size( ); ++ j )
        if ( tag[ j ] )
            m_g1.push_back ( j );

    while ( mf_breadth_first_search ( ) )
        for ( std::vector < size_t >::const_iterator v = m_g1.begin( ); v != m_g1.end( ); ++ v )
            if ( m_pair[ *v ] == NIL && mf_depth_first_search ( *v ) )
                ++ npair;
}

bool HopcroftKarp::mf_breadth_first_search( )
{
    /* only nodes from g1 are queued */
    std::queue < size_t > bfs_queue;

    /* initialize queue with all unpaired nodes from g1 */
    for ( std::vector < size_t >::const_iterator v = m_g1.begin( ); v != m_g1.end( ); ++v )
        if ( m_pair[ *v ] == NIL )
        {
            m_dist[ *v ] = 0;
            bfs_queue.push ( *v );
        }
        else
            m_dist[ *v ] = INF;

    m_dist[ NIL ] = INF;

    /* find all the shortest augmenting paths to node nil */
    while ( ! bfs_queue.empty() )
    {
        const size_t v = bfs_queue.front( );
        bfs_queue.pop ( );

        if ( m_dist[ v ] < m_dist[ NIL ] )
            for ( std::list < size_t >::const_iterator u = m_adj[ v ].begin( ); u != m_adj[ v ].end( ); ++ u )
                if ( m_dist[ m_pair[ * u ] ] == INF )
                {
                    m_dist[ m_pair[ * u ] ] = m_dist[ v ] + 1;
                    bfs_queue.push ( m_pair[ * u ] );
                }
    }

    return m_dist[ NIL ] != INF;
}

bool HopcroftKarp::mf_depth_first_search( const size_t v )
{
    if ( v == NIL )
        return true;
    else
    {
        for ( std::list < size_t >::const_iterator u = m_adj[ v ].begin( ); u != m_adj[ v ].end( ); ++ u )
            if ( m_dist[ m_pair[ *u ] ] == m_dist[ v ] + 1  && mf_depth_first_search( m_pair[ *u ] ))
            {
                /*
                 * there is an augmenting path to nil from m_pair[ *u ]
                 * and hence there is an augmenting path from v to u and
                 * u to to nil; therefore v and u can be paired together
                 */
                m_pair [ *u ] = v;
                m_pair [  v ] = *u;
                return true;
            }
        m_dist[ v ] = INF;
        return false;
    }
}

/**
 * lazy all pairs shortest path in a tree with only one BFS
 * test case: 'book of evil'
 *      codeforces.com/problemset/problem/337/D
 */
class All_Pairs_Tree_Shortest_Path
{
    public:
        All_Pairs_Tree_Shortest_Path( const std::vector< std::list < size_t > > & adj ):
            n( adj.size( ) ),
            depth( std::vector < size_t > ( n, All_Pairs_Tree_Shortest_Path::INF ) ),
            parent( std::vector < size_t > ( n ) ),
            dist( std::vector < std::vector < unsigned short > > ( n ) )
        {

            /* perform bfs from root node '0' and assign depth to each node */
            /* XXX probably would be worth to set the root as node with highest degree */
            std::queue< size_t > bfs_queue;
            bfs_queue.push( 0 );
            depth[ 0 ]  = 0;
            parent[ 0 ] = 0;

            while ( ! bfs_queue.empty( ) )
            {
                const size_t u = bfs_queue.front( );
                bfs_queue.pop( );

                for ( std::list< size_t >::const_iterator j = adj[ u ].begin( ); j != adj[ u ].end( ); ++ j )
                    if ( depth[ u ] + 1 < depth[ *j ] )
                    {
                        depth[ *j ]  = depth[ u ] + 1;
                        parent[ *j ] = u;
                        bfs_queue.push( *j );
                    }
            }

            /* adjust pair-wise distance to zero along the diagonal */
            for ( size_t j = 1; j < n; ++ j )
                dist[ j ].resize( j, All_Pairs_Tree_Shortest_Path::INF );
        }

        /* interface object function as to lazily look-up distances */
        size_t operator( )( const size_t u, const size_t v )
        {
            if ( u == v )
                return 0;
            else if ( u < v)
                return (*this)( v, u );
            else if ( dist[ u ][ v ] == All_Pairs_Tree_Shortest_Path::INF )
            {
                if ( depth[ u ] < depth[ v ] )
                    /* u is in a lower level than v */
                    dist[ u ][ v ] = 1 + (*this)( u, parent[ v ]);
                else if ( depth[ v ] < depth[ u ] )
                    /* v is in a lower level than u */
                    dist[ u ][ v ] = 1 + (*this)( parent[ u ], v );
                else
                    /* u and v are at the same depth */
                    dist[ u ][ v ] = 2 + (*this)( parent[ u ], parent[ v ] );
           }
            return dist[ u ][ v ];
        }

        /* TODO populate; a method which populates pair-wise distances
         * and returns the matrix */

    private:
            /*
             * constant infinity value for initializing distances
             * even though this is private it will be assigned outside of the class
             */
            static const unsigned short INF;

            const size_t n;                 /* numbert of nodes in the tree */
            std::vector < size_t > depth;   /* distance to root node '0' */
            std::vector < size_t > parent;  /* parent of each node with root node '0' */
            std::vector < std::vector < unsigned short > > dist; /* pair-wise shortest path distance */
};

const unsigned short All_Pairs_Tree_Shortest_Path::INF = std::numeric_limits< unsigned short >::max( );

/*
 *  data-structure utility
 * ----------------------------------------------
 */

template < class T, class Comp = std::less< T > >
class Heap  /* less< T > --> max-heap */
{
    typedef T value_type;
    typedef typename std::vector < value_type >::size_type size_type;
    public:
        /*
         * stackoverflow.com/questions/10387751
         * possible work-around: a memebr pointer to m_val
         * TODO static/friend heapify ( val, & heap )  XXX O( n ) ?!
         * TODO implement insert iterator
         */
        Heap(): m_val( std::vector < value_type >() ), m_comp( Comp() ) {}

        template < class InputIter >
        Heap ( InputIter first, InputIter last ):
            m_val ( std::vector < value_type > ( ) ), m_comp( Comp( ) )
        {
            for ( ; first != last ; ++ first )
                m_val.push_back ( * first );

            std::make_heap( m_val.begin( ), m_val.end( ), m_comp );
        }

        /*!
         * to avoid destroying heap property, front( )
         * should always return a 'const' reference
         */
        inline const value_type & front( ) const { return m_val.front( ); }
        inline bool empty( ) const { return m_val.empty( ); }
        inline size_type size( ) const { return m_val.size( );  }

        inline void push ( const value_type & a )
        {
            m_val.push_back( a );
            std::push_heap( m_val.begin( ), m_val.end( ), m_comp );
        }
        inline void pop( )
        {
            std::pop_heap ( m_val.begin( ), m_val.end( ), m_comp );
            m_val.pop_back( );
        }

        // inline void swap( Heap< T, Comp> & other ) { m_val.swap( other.m_val ) };
        // void sort( ) { std::sort_heap ( m_val.begin( ), m_val.end( ), m_comp ); }
        // template < class X, class Y >
        // friend std::ostream & operator<<( std::ostream & out, const Heap < X, Y> & heap );
    private:
        std::vector < value_type > m_val;
        const Comp m_comp;
};

/*
 * boost.org/doc/libs/1_54_0/libs/smart_ptr/shared_ptr.htm
 */
#if 1 < 0
template < class Type >
class shared_ptr
{
    typedef Type value_type;
    public:
        explicit shared_ptr ( value_type * p = NULL ) : ptr ( p ), count ( new size_t ( 1U ) ) { }
        shared_ptr ( const shared_ptr < value_type > & sp ): ptr ( sp.ptr ), count ( sp.count ) { ++ * count; }
        ~ shared_ptr ( ) { release( ); }

        bool operator== ( const shared_ptr < value_type > & sp ) { return ptr == sp.ptr; }
        bool operator!= ( const shared_ptr < value_type > & sp ) { return ptr != sp.ptr; }

        shared_ptr < value_type > & operator= ( const shared_ptr < value_type > & sp )
        {
            if ( this != & sp && ptr != sp.ptr )
            {
                release( );
                ptr   = sp.ptr;
                count = sp.count;
                ++ * count;
            }
            return * this;
        }

        value_type * operator-> ( ) { return ptr ; }
        value_type & operator* ( ) { return *ptr ; }
        const value_type * operator-> ( ) const { return ptr ; }
        const value_type & operator* ( ) const { return *ptr; }

        void swap ( shared_ptr < value_type > & sp )
        {
            if ( this != &sp && ptr != sp.ptr )
            {
                std::swap ( ptr, sp.ptr );
                std::swap ( count, sp.count );
            }
        }

    private:
        void release ( )
        {
            /* stackoverflow.com/questions/615355 */
            -- * count;
            if ( ! * count )
            {
                delete count;
                delete ptr;
                count = NULL;
                ptr   = NULL;
            }
        }
        value_type * ptr;
        size_t     * count;
};
#endif

/*!
 * union find data structure with
 *      - lazy unions
 *      - union by rank
 *      - path compression
 */
class UnionFind
{
    public:
        UnionFind( const size_t n ):
            parent ( std::vector < size_t > ( n ) ),   /* initialize each node as its own   */
            rank   ( std::vector < size_t > ( n, 0 ))  /* parent and set all the ranks to 0 */
        {
            for ( size_t j = 0; j < n; ++ j )
                parent[ j ] = j ;
        }

        inline size_t find( const size_t s )
        {
            /*
             * perform path compresion and add shortcut
             * if parent[ s ] is not a root node
             */
            const size_t p = parent[ s ];
            return parent[ p ] == p ? p : parent[ s ] = find( p ) ;
        }

        inline void lazy_union ( size_t i, size_t j )
        {
            /* unions should be done on root nodes */
            i = find( i );
            j = find( j );

            if ( i != j )
            {
                if ( rank [ i ] < rank[ j ] )
                    parent[ i ] = j;
                else
                {
                    parent[ j ] = i;
                    rank[ i ]  += rank[ i ] == rank[ j ];
                }
            }
        }
    private:
        std::vector < size_t > parent;
        std::vector < size_t > rank;
};

// TODO XXX
// template < class NumType >
// unsigned num_hash_func ( const NumType & a )
// {
//     // XXX what will happen in case of overflow?
//     return static_cast < unsigned > ( a % 9973 ) % 9973 ;
// }

/*
 * XXX: HashMap: map< Key, T > data [ 9973 ]
 * data [ num_hash_func ( key ) ][ key ]
 */

/*
 *  testing util
 * ----------------------------------------------
 */

// TODO add a preprocessor which automatically includes the funciton name, or __line__
// and disables if not in debug mode
/* prints the life length of the object when it goes out of scope */
class ScopeTimer
{
    public:
        ScopeTimer ( const std::string & msg = "" ): tic ( clock ( )), m_msg( msg ) { };

        ~ ScopeTimer ( )
        {
            const clock_t toc = clock();
            const uint64 dt   = 1000L * ( toc - tic ) / CLOCKS_PER_SEC;

            const uint64 mil = dt % 1000L;
            const uint64 sec = ( dt / 1000L ) % 60L;
            const uint64 min = ( dt / 60000L ) % 60L;
            const uint64 hrs = ( dt / 3600000L );

            std::cout << '\n' << m_msg << "\n\telapsed time: ";

            if ( hrs )  std::cout << hrs << " hrs, ";
            if ( min )  std::cout << min << " min, ";
            if ( sec )  std::cout << sec << " sec, ";
            std::cout << mil << " mil-sec\n";
        }

    private:
        typedef unsigned long long int  uint64;
        const clock_t tic;
        const std::string m_msg;
};

class RandInt
{
    public:
        RandInt ( int a = 0, int b = 100 ): m ( a ), f ( static_cast < double > ( b - a ) / RAND_MAX ) { }
        inline int operator() ( ) { return m + std::ceil ( f * rand( ) ); }
    private:
        const int m;
        const double f;
};

class RandDouble
{
    public:
        RandDouble ( double a = 0.0, double b = 1.0 ): m ( a ), f ( ( b - a ) / RAND_MAX ) { }
        inline double operator() ( ) { return m + f * rand( ); }
    private:
        const double m, f;
};

class Noisy
{
    public:
        Noisy ( std::string str ): msg ( str )
        {
            std::cout << " Noisy ( " << msg << " )\t@ " << this << std::endl;
        }
        ~Noisy ( )
        {
            std::cout << "~Noisy ( " << msg << " )\t@ " << this << std::endl;
        }
        void beep ( )
        {
            std::cout << " beep ( " << msg << " )\t@ " << this << std::endl;
        }
        void beep ( ) const
        {
            std::cout << " const beep ( " << msg << " )\t@ " << this << std::endl;
        }
    private:
        const std::string msg;
};

DECLARE ( Noisy );

/*
 * ----------------------------------------------
 * ----------------------------------------------
 */

/*
 * -- @@@ -------------------------------------------------
 */

using namespace std;

// struct Comp
// {
//     // bool operator() ( const pair < int, int > & x, const pair < int, int > & y )
//     // {
//     //     return abs( x.first ) + abs( x.second ) < abs( y.first ) + abs( y.second );
//     // }
//
//     // bool operator( ) ( const xyCircle & a, const xyCircle & b )
//     // {
//     //     return a.radius < b.radius;
//     // }
//     //
//     bool operator( ) ( const pair < size_t, size_t > & pr, const size_t & x )
//     {
//         return pr.second < x;
//     }
// };

inline int get_gain( const vector < int > & xs, const size_t l, const size_t r )
{
    const size_t len = xs.size() - l - r;
    return len & 1 ? xs[ l + len / 2 ] : 0;
}

void c388()
{
    size_t n;
    cin >> n;
    vector < vector < int > > xs( n );
    cin >> xs;

    const size_t k = accumulate( begin(xs), end(xs), 0,
            []( const size_t acc, const vector < int > & row )
            {
                return acc + row.size();
            });
    DEBUG( k );

    const int acc = accumulate( begin(xs), end(xs), 0,
            []( const int acc, const vector < int > & a )
            {
                return accumulate(begin(a), end(a), acc);
            });

    DEBUG( acc );
    // how much has it been taken from left & right
    vector < size_t > left( n, 0 ), right( n, 0 );

    int left_acc = 0;

    for ( size_t j = 0; j < k; ++ j )
    {
        size_t imax = 0;
        while ( xs[imax].size() == left[imax] + right[imax] )
            ++ imax;

        int val = get_gain( xs[imax], left[imax], right[imax] );

        for ( size_t i = imax + 1; i < n; ++ i )
            if ( left[ i ] + right[ i ] < xs[ i ].size() )
            {
                const auto g = get_gain( xs[i], left[i], right[i] );
                if ( val < g )
                {
                    val = g;
                    imax = i;
                }
            }

        if ( j & 1 ) // from right
            ++ right[ imax ];
        else
            left_acc += xs[ imax ][ left[ imax ] ++ ];
    }

    cout << left_acc << ' ' << acc - left_acc;
}

void c20()
{
    size_t n, m;
    cin >> n >> m;

    typedef tuple< size_t, int64 > edge_type;

    // const auto make_edge = tuple< size_t , int64 >;

    vector < vector < edge_type > > adj( n );
    for ( size_t j = 0; j < m; ++ j )
    {
        size_t u, v;
        int64 w;
        cin >> u >> v >> w;
        -- u; -- v;

        adj[ u ].push_back( edge_type( v, w ));
        adj[ v ].push_back( edge_type( u, w ));
    }

    const int64 INF = numeric_limits< int64 >::max();
    vector < int64 > dist( n, INF );

    typedef tuple< int64, size_t > value_type;
    Heap < value_type, greater< value_type > > heap;

    dist[ 0 ] = 0;
    heap.push( make_tuple< int64, size_t >( 0, 0 ) );

    while ( ! heap.empty() )
    {
        const size_t u = get< 1 >( heap.front() );
        const int64 d = get< 0 >( heap.front() );
        heap.pop();

        if ( dist[ u ] == d )
            for ( const auto & e : adj[ u ] )
                if ( d + get< 1 >( e ) < dist[ get< 0 >( e ) ] )
                {
                    dist[ get< 0 >( e ) ] = d + get< 1 >( e );
                    heap.push( make_tuple( dist[ get< 0 >( e ) ], get< 0 >( e ) ));
                }
    }

    if ( dist[ n - 1 ] != INF )
    {
        vector < size_t > path;
        size_t u = n - 1;

        const auto pred = [&dist, &u](const edge_type & e){ return dist[get<0>(e)] + get<1>(e) == dist[u]; };

        do
        {
            path.push_back( u );
            const auto iter = find_if(begin(adj[u]), end(adj[u]), pred);
            u = get<0>(*iter);
        } while ( u != 0 );

        path.push_back( 0 );

        transform( path.rbegin(), path.rend(),
                ostream_iterator< size_t >( cout, " " ),
                bind( plus< size_t >(), placeholders::_1, 1 ));
    }
    else
        cout << -1;

}

size_t b319()
{
    vector < size_t > xs;
    cin >> xs;
    const size_t n = xs.size();

    map < size_t, size_t > m; // value | time
    m[ xs[0] ] = 0;
    size_t val = 0;

    for ( size_t j = 1; j < n ; ++ j )
    {
        auto iter = m.lower_bound( xs[ j ] );
        if ( iter != end( m ) )
        {
            ++ iter->second;
            auto next = iter;
            ++ next;
            if ( next != end( m ) && iter->second == next->second )
                m.erase(begin(m), next);
            else
                m.erase(begin(m), iter);
        }
        else
        {
            val = max(val, m.rbegin()->second);
            m.clear();
        }
        m[ xs[ j ] ] = 0;
        DEBUG( m );
    }

    val = max(val, m.rbegin()->second);

    return val;
}

size_t b41()
{
    size_t n, b;
    cin >> n >> b;

    vector < size_t > a( n );
    cin >> a;

    vector < size_t > m( n );
    const auto f = []( const size_t & a, const size_t & b) { return max(a, b); };
    partial_sum( a.rbegin(), a.rend(), m.rbegin(), f );
    DEBUG( m );

    size_t val = b;
    for ( size_t j = 0; j < n ; ++ j )
        val = max(val, b % a[ j ] + b / a[ j ] * m[ j ] );

    return val;
}

string b99()
{
    vector< size_t > xs;
    cin >> xs;

    const auto i = min_element(begin(xs), end(xs));
    const auto j = max_element(begin(xs), end(xs));

    if ( *i == *j )
        return "Exemplary pages.";
    else if ( (*i + *j) & 1 )
        return "Unrecoverable configuration.";
    else
    {
        const auto v = ( *j - *i ) / 2;
        *i += v;
        *j -= v;

        if( *min_element(begin(xs), end(xs)) == *max_element(begin(xs), end(xs)) )
            return  val2str(v) + " ml. from cup #"
                + val2str(i - begin(xs) + 1 )
                + " to cup #"
                + val2str(j - begin(xs) + 1 )
                + ".";
        else
            return "Unrecoverable configuration.";
    }
}

void b70()
{
    size_t n;
    cin >> n;

    string str;
    getline(cin, str);
    getline(cin, str);
    DEBUG( str );

    vector < size_t > xs;
    auto i = begin(str);

    while ( i != end(str) )
    {
        while ( i != end(str ) && *i == ' ' )
            ++ i;

        auto j = i;
        while ( j != end(str) && *j != '.' && *j != '?' && *j != '!' )
            ++ j;

        if ( j != end(str) )
            ++ j;

        if ( j != i )
            xs.push_back( j - i );

        i = j;
    }

    DEBUG( xs );
    const auto pred = bind(less<size_t>(), n, placeholders::_1);
    if ( find_if(begin(xs), end(xs), pred) != end(xs) )
        cout << "Impossible";
    else
    {
        size_t k = 0;
        auto i = begin(xs);

        while ( i != end(xs) )
        {
            ++ k;
            size_t len = *i++;

            while ( i != end(xs) && len + *i < n )
                len += 1 + *i++;

            DEBUG( len );
        }
        cout << k;
    }
}

size_t count_unique( const vector < string > & xs, const size_t k )
{
    set < char > s;
    for ( const auto & a: xs )
        s.insert( a[ k ] );

    return s.size();
}

inline size_t count_bars( size_t a )
{
    size_t k = 0;
    for ( ; a > 0; a >>= 1 )
        k += a & 1;
    return k;
}

size_t a442()
{
    vector < string > cards;
    cin >> cards;

    const size_t cnt_unq_char = count_unique(cards, 0);
    const size_t cnt_unq_digit = count_unique(cards, 1);

    DEBUG( cnt_unq_char );
    DEBUG( cnt_unq_digit );

    map < char, size_t > char_map;
    char_map['R'] = 0;
    char_map['G'] = 1;
    char_map['B'] = 2;
    char_map['Y'] = 3;
    char_map['W'] = 4;

    typedef tuple< size_t, size_t > card_type;
    vector < card_type > xs;
    for ( const auto & a: cards )
        xs.push_back( card_type( 1 << char_map[a[0]], 1 << (a[1] - '0' )));

    // if knowing char, identifies digit

    // DEBUG( card_type );
    size_t val = cnt_unq_char + cnt_unq_digit - 2;
        //numeric_limits< size_t >::max();

    for( size_t i = 0; i < ( 1 << 6 ) - 1; ++ i )
    {
        const auto icnt = count_bars( i );
        if ( icnt < val )
            for ( size_t j = 0; j < ( 1 << 6 ) - 1; ++ j )
            {
                const auto jcnt = count_bars( j );
                if ( icnt + jcnt < val )
                {
                    bool flag = true;

                    for ( const auto & a: xs )
                    {
                        for ( const auto & b: xs )
                            if ( a != b )
                            {
                                const auto u = get<0>(a) == get<0>(b)
                                    || icnt + 1 < cnt_unq_char && ! ( get<0>( a ) & i ) && ! ( get<0>( b ) & i );

                                const auto v = get<1>(a) == get<1>(b)
                                    || jcnt + 1 < cnt_unq_digit && ! ( get<1>( a ) & j ) && ! ( get<1>( b ) & j );

                                if (  v && u )
                                {
                                    flag = false;
                                    break;
                                }
                            }
                    }
                    if ( flag )
                        val = icnt + jcnt;
                }
            }
    }

    return val;
}

int main( const int argc, char * argv [])
{
    cout << a442();
    // cout << setprecision( 15 ) << b68();

    return EXIT_SUCCESS;
}

/**
 * mislav.uniqpath.com/2011/12/vim-revisited/
 * set encoding=utf-8
 * %s/\(.\{60,70\}\) /\1\r/gc
 * %s/ / /gc
 * %s/10\([0-9]\{1,2\}\)/10^\1/gc
 */


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

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

    ll b;
    cin >> b;

    if (b == 1){
        cout << 1;
        return 0;
    }

    ll answer = 0;

    for (ll i = 1; i <= sqrt(b); ++i){
        if (b % i == 0){
            answer+=2;
        }
        if (i * i == b){
            answer-=1;
        }
    }
    cout << answer;
}


#include<iostream>
using namespace std;
int main()
{
    int a,b,c,d,i;
    cin>>a>>b;
    c=a;
if(a<=1000&&b<=1000){
    for(i=0;i<=1000;i++){
        if(a>=b){
            d=a/b;
            c+=d;
            a=d+a%b;
        }
        else
            break;
    }
cout<<c;
}

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,j,n,x[1005],y[1005],c,sum,f=0;
    while(cin>>n)
    {
        f=0;
        for(i=0;i<7;i++)
        {
            cin>>x[i];
        }
        sum=n,c=1,i=0;
        while(n>0)
         {
             i%=7;
             sum-=x[i];
             if(sum<=0)
             {
                 c=i+1;
                 break;
             }
            i++;

        }

        cout<<c<<endl;
    }
    return 0;
}


#include<stdio.h>
int  main()
{
	int a,b,k,i;
	scanf("%d%d%d",&k,&a,&b);
	if(a<k && b<k || a%k!=0 && b<k || b%k!=0 && a<k)
	{
		printf("-1\n");
		return 0;
	}
	printf("%d\n",a/k+b/k);
}


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

using namespace std;

int main(){
	int n;
	scanf("%d", &n);
	if(n%2==0)
	{
		printf("2");
	}
	else
	{
		printf("1");
	}
    printf("\n");
}
// 1500319658578


#include <bits/stdc++.h>

using namespace std;

int main()
{
    long long x,y;
    cin >> x >> y;
    if (x == y)
		cout << "=";
    else
	if (x == 1)
		cout << "<";
    else
	if (y == 1)
		cout << ">";
    else
	if (x + y == 6)
		cout << "=";
    else
	if (x == 3)
		cout << ">";
    else
	if (y == 3)
		cout << "<";
    else
	if (x < y)
		cout << ">";
	else
		cout << "<";
}


#include<cstdio>
#include<cstring>
#include<cassert>
#include<vector>
#include<list>
#include<queue>
#include<map>
#include<set>
#include<deque>
#include<stack>
#include<bitset>
#include<algorithm>
#include<functional>
#include<numeric>
#include<utility>
#include<sstream>
#include<iostream>
#include<iomanip>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<fstream>
#include<typeinfo>
#include<locale>
#include<iterator>
#include<valarray>
#include<complex>
#include<climits>

using namespace std;

#define xx         first
#define yy         second
#define pb         push_back
#define mp         make_pair
#define LL         long long
#define inf        INT_MAX/3
#define mod        1000000007ll
#define PI         acos(-1.0)
#define linf       (1ll<<60)-1
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define REP(I,N)   FOR(I,0,N)
#define ALL(A)     ((A).begin(), (A).end())
#define set0(ar)   memset(ar,0,sizeof ar)
#define vsort(v)   sort(v.begin(),v.end())
#define setinf(ar) memset(ar,126,sizeof ar)

//cout << fixed << setprecision(20) << p << endl;

template <class T> inline T bigmod(T p,T e,T M){
    LL ret = 1;
    for(; e > 0; e >>= 1){
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    } return (T)ret;
}
template <class T> inline T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}

vector < int > vc[1000001];
LL ar[1000001], mob[1000001], isp[1000001], val[1000001];
LL tmp[1000001], pre[1000001];

LL fact[1000001], inv[1000001];
LL ncr(int n, int r){
    if(n < r) return 0;
    LL ret = (fact[n] * inv[r]) % mod;
    return (ret * inv[n-r]) % mod;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    for(int i = 1; i <= 1000000; i++){
        for(int j = i; j <= 1000000; j += i) vc[j].pb(i);
    }

    FOR(i, 1, 1000001) mob[i] = 1;
    for(int i = 2; i <= 1000000; i++){
        if(isp[i] == 0){
            for(int j = i; j <= 1000000; j += i){
                mob[j] *= -1;
                if(i <= 1000 && (j % (i*i)) == 0) mob[j] = 0;
                isp[j] = 1;
            }
        }
    }

    FOR(i, 1, 1000001) mob[i] = (mob[i] + mod) % mod;

    for(int i = 1; i <= 1000000; i++){
        for(int j = 0; j < vc[i].size(); j++){
            pre[i] = (pre[i] + mob[i/vc[i][j]] * (LL)vc[i][j]) % mod;
        }
    }

    fact[0] = 1;
    for(LL i = 1; i <= 1000000; i++) fact[i] = (fact[i - 1] * i) % mod;
    REP(i, 1000001) inv[i] = modinverse(fact[i], mod);

    int n, K, q; cin >> n >> K >> q;
    for(int i = 1; i <= n; i++) {
        int x; cin >> x;
        tmp[x]++;
    }

    LL sum = 0;
    for(int i = 1000000; i >= 1; i--){
        for(int j = i; j <= 1000000; j += i) val[i] += tmp[j];
        for(int j = i; j <= 1000000; j += i){
            ar[i] = (ar[i] + ncr(val[j], K) * mob[j/i]) % mod;
        }
        sum = (sum + ar[i] * (LL)i) % mod;
    }

    while(q--){
        int v; cin >> v;
        for(int i = vc[v].size() - 1; i >= 0; i--){
            int x = vc[v][i];
            LL p = (ncr(val[x]+1, K) + mod - ncr(val[x], K)) % mod;
            sum = (sum + p * pre[x]) % mod;
            val[x]++;
        }

        cout << sum << endl;
    }
}


//https://codeforces.com/contest/1286/problem/A
//A. Garland
#include <bits/stdc++.h>
using namespace std;
#define oo 0x3f3f3f3f
#define ooLL 0x3f3f3f3f3f3f3f3f
#define fastio() ios_base::sync_with_stdio(false); cin.tie(NULL)
const int mod = 1e9+7;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> ii;

int main(){
    int n;
    scanf("%d", &n);
    vector<int> v(n+1);
    for(int i = 1; i <= n ; ++i) scanf("%d", &v[i]);
    vector<vector<vector<int>>> dp(n+1, vector<vector<int>>(n/2+1, vector<int>(2,oo)));
    dp[0][0][0] = dp[0][0][1] = 0;
    for(int i = 1; i <= n ; ++i){
        for(int j = 0; j <= n/2 ; ++j){
            if(v[i] == 0 || v[i] % 2) dp[i][j][1] = min(dp[i-1][j][1], 1+dp[i-1][j][0]);
            if(v[i] % 2 == 0 && j) dp[i][j][0] = min(dp[i-1][j-1][0], 1+dp[i-1][j-1][1]);
        }
    }
    printf("%d\n", min(dp[n][n/2][0], dp[n][n/2][1]));
    return 0;
}


#include <iostream>
using namespace std;
int min1(int a,int b,int c)
{if(a<b && a<c) return a;
if(b<a && b<c) return b;
return c;
  }
int min2(int a,int b)
{if(a<b) return a; return b;}
	int main()
{ int x1,x2,x3,d1,d2,d3;
cin>>x1>>x2>>x3;
d1=abs(x2-x1) + abs(x3-x1);
d2=abs(x2-x1) + abs(x3-x2);
d3=abs(x3-x1) + abs(x3-x2);
cout<<min1(d1,d2,d3)<<endl;
//cout<<min2(min2(d1,d2),d3)<<endl;

return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n;
int mx = 0, sum = 0;

int main(){
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i){
		int a;	scanf("%d", &a);
		mx = max(mx, a);
		sum += a;
	}

	sum *= 2;
	sum += n;
	sum /= n;

	printf("%d", max(sum, mx));
	return 0;
}


#include <bits/stdc++.h>

#define       pb                 push_back
#define       sf                 scanf
#define       pf                 printf
#define       sz                 100005
#define       MOD                1000000007
#define       optimize           ios::sync_with_stdio(0);cin.tie(0);
#define       inf                0x3f3f3f3f
#define       READ               freopen("in.txt", "r", stdin);
#define       WRITE              freopen("out.txt", "w", stdout);

using namespace std;

typedef       long long int      ll;
typedef       vector<int>        vi;

int dx[] = {0, 0, +1, -1};
int dy[] = {+1,-1, 0,  0};
/*============GRAPH MOVES==================*/
//const int fx[] = {1, -1, 0, 0};
//const int fy[] = {0, 0, 1, -1};
const int fx[] = {1, -1, -1, 1, -1, 1};  // Kings move
const int fy[] = {0, 0, 1, 1, -1, -1};  // Kings move
//const int fx[] = {-2, -2, -1, -1, 1, 1, 2, 2}; // Knights move
//const int fy[] = {-1, 1, -2, 2, -2, 2, -1, 1}; // Knights move
/*=========================================*/

inline bool isLeapYear(ll year) { return (year%400==0) | (year%4==0 && year%100!=0); }
inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }
inline ll mod(ll a, ll m){ if(a<0) return m-(abs(a)%m); else if(a<m) return a; else return (a%m); }
inline string tstring(ll a) {stringstream ss; ss << a; string str = ss.str(); return str; }

inline bool Equal(double a, double b) { return fabs(a-b) < 1e-9;} ///x==y
inline bool Greater(double x, double y) { return x-1e-9>y;} ///x>y
inline bool Lesser(double x, double y) { return x+1e-9<y;} ///x<y

int main()
{
    // READ
    optimize

    int tc;

    cin >> tc;

    while(tc--)
    {
    	int n, k;

    	cin >> n >> k;

    	cout << modPow(n, k) << '\n';
    }

    return 0;
}

// https://vjudge.net/contest/480401#problem/I


#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#define LL long long
using namespace std;
LL n,m;
struct node{
	LL x,y;
}R[15],B[15];
struct line{
	node p1,p2;
}a[15];
LL multi(node p1,node p2,node p0)
{
    LL x1=p1.x-p0.x,x2=p2.x-p0.x;
    LL y1=p1.y-p0.y,y2=p2.y-p0.y;
    return x1*y2-x2*y1;
}
bool check(line l1,line l2)
{
    if(multi(l2.p1,l1.p2,l1.p1)*multi(l1.p2,l2.p2,l1.p1)>0&&multi(l1.p1,l2.p2,l2.p1)*multi(l2.p2,l1.p2,l2.p1)>0) return true;
    if(multi(l1.p1,l2.p1,l2.p2)==0&&min(l2.p1.x,l2.p2.x)<=l1.p1.x&&l1.p1.x<=max(l2.p1.x,l2.p2.x)) return true;
    if(multi(l1.p2,l2.p1,l2.p2)==0&&min(l2.p1.x,l2.p2.x)<=l1.p2.x&&l1.p2.x<=max(l2.p1.x,l2.p2.x)) return true;
    if(multi(l2.p1,l1.p1,l1.p2)==0&&min(l1.p1.x,l1.p2.x)<=l2.p1.x&&l2.p1.x<=max(l1.p1.x,l1.p2.x)) return true;
    if(multi(l2.p2,l1.p1,l1.p2)==0&&min(l1.p1.x,l1.p2.x)<=l2.p2.x&&l2.p2.x<=max(l1.p1.x,l1.p2.x)) return true;
    return false;
}
LL c[15];
bool solve(LL k)
{
	for(LL i=1;i<k;i++) if(check(a[i],a[k])) return false;
	return true;
}
void dfs(LL x)
{
	if(x>n) {printf("Yes");exit(0);}
	for(LL i=1;i<=m;i++)
	{
		if(c[i]) continue;
		a[x].p1=R[x];a[x].p2=B[i];
		if(!solve(x)) continue;
		c[i]=1;dfs(x+1);c[i]=0;
	}
}
int main()
{
	scanf("%lld %lld",&n,&m);
	if(n!=m) return puts("No"),0;
	for(LL i=1;i<=n;i++) scanf("%lld %lld",&R[i].x,&R[i].y);
	for(LL i=1;i<=m;i++) scanf("%lld %lld",&B[i].x,&B[i].y);
	memset(c,0,sizeof(c));
	dfs(1);
	printf("No\n");
}


#include<bits/stdc++.h>
using namespace std;
char a[101];
int n;
int main()
{
	cin>>a;
	for(int i=0;i<=strlen(a);i++)
		if(a[i]=='H'||a[i]=='Q'||a[i]=='9'){
			cout<<"YES";
			return 0;
		}
	cout<<"NO";
    return 0;
}


#include<iostream>
#include<string>
#include<map>
#include<algorithm>
using namespace std;
int main()
{
	int n,c=0;
	string s;
	cin >> n >> s;
	for (int i = 0; i < s.size() - 1; i++)
		if ((s[i] == 'U' && s[i + 1] == 'R') || (s[i] == 'R' && s[i+1] == 'U'))
		{
			c++;
			i++;
		}

	cout << s.size() - c;
	return 0;
}


#include <cstdio>

int main() {
    int n, k;
    scanf("%d %d", &n, &k);
    printf("%d", 3 * n - k > 0 ? 3 * n - k : 0);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int x,k,p;
double dp[210][2100];
void init()
{
    memset(dp,0,sizeof(dp));
    for(int i=0 ; i<=k ; i++)
    {
        int T=x+i;
        while(T)
        {
            if(T&1) break;
            dp[0][i]++;
            T/=2;
        }
    }
}
int main()
{

    while(~scanf("%d%d%d",&x,&k,&p))
    {
        double winp=p*1.0/100;
        double sp=1-winp;
        init();

        for(int i=0 ; i<=k ; i++)
        {
            for(int j=2000 ; j>=0 ; j--)
            {
                dp[i+1][j]+=dp[i][j+1]*sp;
                if(2*j<=k)
                dp[i+1][j*2]+=(dp[i][j]+1)*winp;

            }
        }

        printf("%.7lf\n",dp[k][0]);
    }
}


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

// #define multitest 1
#ifdef Debug
#define db(...) ZZ(#__VA_ARGS__, __VA_ARGS__);
template <typename Arg1>
void ZZ(const char *name, Arg1 &&arg1)
{
	std::cerr << name << " = " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void ZZ(const char *names, Arg1 &&arg1, Args &&... args)
{
	const char *comma = strchr(names + 1, ',');
	std::cerr.write(names, comma - names) << " = " << arg1;
	ZZ(comma, args...);
}
#else
#define db(...)
#endif

using ll = long long;
#define f first
#define s second
#define pb push_back
const long long mod = 1000000007;
auto TimeStart = chrono::steady_clock::now();

const int nax = 1e6 + 10;
int n, dp[nax][20][2];

int power(int base, int index)
{
	if (index == 0)
		return 1;
	ll temp = power(base, index / 2);
	temp *= temp;
	if (index & 1)
		return temp * base;
	return temp;
}
int f(int x, int y)
{
	return n / (1 << x) / (y == 0 ? 1 : 3);
}

int mul(int a, int b)
{
	return (ll)a * b % mod;
}

void add_self(int &a, int b)
{
	a += b;
	if (a >= mod)
		a -= mod;
}

void solve()
{
	cin >> n;
	int x1 = log2l(n);
	db(log2l(n));
	dp[1][x1][0] = 1;
	if ((1 << (x1 - 1)) * 3 <= n)
		dp[1][x1 - 1][1] = 1;
	for (int i = 1; i < n; ++i)
	{
		for (int x = 0; x <= x1; ++x)
			for (int y = 0; y <= 1; ++y)
			{
				add_self(dp[i + 1][x][y], mul(dp[i][x][y], f(x, y) - i));
				if (x > 0)
					add_self(dp[i + 1][x - 1][y], mul(dp[i][x][y], f(x - 1, y) - f(x, y)));
				if (y > 0)
					add_self(dp[i + 1][x][y - 1], mul(dp[i][x][y], f(x, y - 1) - f(x, y)));
			}
	}
	cout << dp[n][0][0] << '\n';
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int t = 1;
#ifdef multitest
	cin >> t;
#endif
	while (t--)
		solve();
#ifdef TIME
	cerr << "\n\nTime elapsed: " << chrono::duration<double>(chrono::steady_clock::now() - TimeStart).count() << " seconds.\n";
#endif
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define PB push_back
#define PF push_front
#define MK make_pair
#define MT make_tuple
#define REP(i, a, b) for (int i = a; i <= b; i++)
#define MOD 1000000007
#define DEB(x) cout << #x << "=" << x << endl
#define DEB2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl

int gcd(int a, int b) {
  while (b) {
    a %= b;
    swap(a, b);
  }
  return a;
}
int gcd1(int a, int b, int &x, int &y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  }
  int x1, y1;
  int d = gcd1(b, a % b, x1, y1);
  x = y1;
  y = x1 - y1 * (a / b);
  return d;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int T = 1;
  while (T--) {
    int a, b, c, g, x, y;
    cin >> a >> b >> c;
    g = gcd1(a, b, x, y); // a*x+by = 1
    if (c % g == 0) {
      a /= g;
      b /= g;
      c /= g;
      if (c >= a * b - a - b + 1)
        cout << "YES\n";
      else {
        x = x * c;
        y = y * c;
        while (x >= b) {
          x -= b;
          y += a;
        }
        while (x < 0) {
          x += b;
          y -= a;
        }
        if (y >= 0)
          cout << "YES\n";
        else
          cout << "NO\n";
      }
    } else {
      cout << "NO\n";
    }
  }

  return 0;
}


#include<iostream>
#include<sstream>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

int n, a[23], dp[1 << 23], p[23][23];

int main(){
	cin >> n;
	rep(i, n) cin >> a[i];
	rep(i, 1 << n) dp[i] = inf;
	dp[1] = 1;

	memset(p, -1, sizeof(p));
	rep(i, n) rep(j, n) rep(k, n) if(a[k] == a[i] + a[j]) p[k][i] = j;

	for(int i = 1; i < n; i++) rep(j, 1 << i) if((j & 1 << i - 1) && dp[j] < inf){
		bool ok = 0;
		rep(k, i) if(j & 1 << k){
			int t = p[i][k];
			if(t >= 0 && (j & 1 << t)){
				ok = 1;
				break;
			}
		}
		if(!ok) continue;
		dp[j ^ 1 << i] = min(dp[j ^ 1 << i], dp[j] + 1);
		rep(k, i) if(j & 1 << k) dp[j ^ 1 << i ^ 1 << k] = min(dp[j ^ 1 << i ^ 1 << k], dp[j]);
	}
	int ans = inf;
	rep(i, 1 << n) if(i & 1 << (n - 1)) ans = min(ans, dp[i]);
	cout << (ans == inf ? -1 : ans) << endl;

	return 0;
}


/*****
  sometime small optimiztion or small proof leads great work and save us from writing comlex code
***/

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define Khela ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define llu long long unsigned int
#define pf printf
#define sf scanf
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define pii pair<int ,int>
#define PII pair<ll ,ll>

int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};

typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
int Set(int N,int pos){return N=N | (1<<pos);}
int reset(int N,int pos){return N= N & ~(1<<pos);}
bool check(int N,int pos){return (bool)(N & (1<<pos));}
const int Max=1e9+100;
const ll  MAX=1e18+500;
const int sz=1e3+100;

int main()
{
    Khela
    ll a,b,c,i,j,k,q,p,x,y,ct,ct1,m,l,r,x1,y1,mn,h,sum1,in,z,mid,n,mx;
    char ch;
    double d;
    string str1,str2,str;
    bool bl,bl1;
    int t,cs=1;
    vector<ll> ne,de,test;
    while(cin>>x>>y>>l>>r)
    {
        ne.clear(),de.clear();
        ne.push_back(1ll),de.push_back(1ll);
        ll temp=x;
        ne.push_back(x),de.push_back(y);
        while(temp<=(MAX/x)) {
            temp*=x;
            ne.push_back(temp);
        }
        temp=y;
        while(temp<=(MAX/y)){
            temp*=y;
            de.push_back(temp);
        }

        test.clear();
        for(auto xx: de) {
            for(auto yy: ne){
                ll p=(xx+yy);
                if(l<=p && p<=r) test.pb(p);
            }
        }
        ll mx=0;
        sort(test.begin(),test.end());
        ll siz=test.size();
        if(siz>0) mx=test[0]-l;

        for(i=1;i<siz;i++) mx=max(mx,test[i]-test[i-1]-1);
        if(siz>0) mx=max(mx,r-test[siz-1]);
        if(test.empty()) mx=max(mx,r-l+1);
        cout<<mx<<endl;

    }

}


#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#define ll long long
using namespace std;

int main()
{
	int n, l, x;
	cin >> n >> l;
	set<int>A, B, C;
	for (int i = 0; i < n; i++)
		cin >> x, A.insert(x);
	for (int i = 0; i < n; i++)
		cin >> x, B.insert(x);
	C = B;
	for (int i = 1; i <= l; i++)
	{
		if (A == C)
		{
			cout << "YES";
			return 0;
		}
		else
			C.clear();
		for (auto it = B.begin(); it != B.end(); it++)
			C.insert((*it + i) % l);
	}
	cout << "NO";
	return 0;
}


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

using namespace std;

string str;
char res[20];

int main()
{
	cin >> str;
	int count = 0;
	res[count++] = str[str.length() - 1];
	char max = res[0];
	for (int i = str.length() - 2; i >= 0; i--) {
		if (str[i] >= max){
			res[count++] = str[i];
            max = str[i];
        }
	}

	char c = res[count - 1];
	for (int i = count - 1; i >= 0; i--) {
		if (res[i] == c)
			cout << res[i];
		else
			break;
	}
	cout << endl;

	return 0;
}


#include <iostream>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORD(i,a,b) for(int i=(a);i>(b);--i)
#define REP(i,n) FOR(i,0,n)
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define MOD 1000000007LL

int main()
{
  long long n, d, ans = 1;
  cin >> n >> d;
  FORE(i,2,d) ans *= d,ans%=MOD;
  FORE(i,d+1,n) ans *= (n-d),ans%=MOD;
  cout << ans << endl;
  return 0;
}


/*
 *    author:  gantheory
 *    created: 2018-06-17 00:53:38
 */
#include <bits/stdc++.h>

using namespace std;

pair<int, int> a[4], b[4];
set<pair<int, int>> st;
int dxs[] = {1, 1, -1, -1};
int dys[] = {1, -1, -1, 1};
int lx = INT_MAX, rx = INT_MIN, ly = INT_MAX, ry = INT_MIN;

void build() {
  for (int i = 0; i < 4; ++i) {
    int x = a[i].first, y = a[i].second;
    lx = min(lx, x), rx = max(rx, x);
    ly = min(ly, y), ry = max(ry, y);
  }
  for (int i = lx; i < rx; ++i)
    for (int j = ly; j < ry; ++j) {
      st.insert({i, j});
    }
}
bool go(int idx, int aa, int bb) {
  int dx = dxs[idx], dy = dys[idx];
  int ax = b[aa].first, ay = b[aa].second;
  int bx = b[bb].first, by = b[bb].second;
  while (ax != bx and ay != by) {
    if (st.count({ax, ay})) return true;
    ax += dx, ay += dy;
  }
  return false;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.setf(ios::fixed), cout.precision(9);
  for (int i = 0; i < 4; ++i) cin >> a[i].first >> a[i].second;
  for (int i = 0; i < 4; ++i) cin >> b[i].first >> b[i].second;

  build();
  sort(b, b + 4);
  int sx = b[1].first;
  int my = (b[1].second + b[2].second) / 2;
  for (int j = b[1].second; j < my; ++j) {
    int h = j - b[1].second;
    for (int i = sx - h - 1; i <= sx + h; ++i) {
      if (st.count({i, j})) {
        cout << "YES" << '\n';
        return 0;
      }
    }
  }
  for (int j = my; j < b[2].second; ++j) {
    int h = b[2].second - j;
    for (int i = sx - h; i < sx + h; ++i) {
      if (st.count({i, j})) {
        cout << "YES" << '\n';
        return 0;
      }
    }
  }

  for (int i = lx; i <= rx; ++i)
    for (int j = ly; j <= ry; ++j) {
      st.insert({i, j});
    }
  if (go(0, 0, 2) or go(1, 2, 3) or go(2, 3, 1) or go(3, 1, 0)) {
    cout << "YES" << '\n';
  } else {
    cout << "NO" << '\n';
  }
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

ll ans = 1e18 + 7;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  ll a, b;
  cin >> a >> b;
  set <pair <ll, ll> > da, db;
  for (ll i = 1; i * i <= a; i++) {
    if (a % i) continue;
    da.insert({i, a / i});
    da.insert({a / i, i});
  }
  for (ll i = 1; i * i <= b; i++) {
    if (b % i) continue;
    db.insert({i, b / i});
    db.insert({b / i, i});
  }
  ll n = a + b;
  set <ll> kek, orz;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i) continue;
    {
      ll x = i, y = n / i;
      auto it = da.upper_bound({x, -1});
      if (it != da.begin()) --it;
      if (it->first <= x && it->second <= y) {
        ans = min(ans, 2 * x + 2 * y);
      }
      it = db.upper_bound({x, -1});
      if (it != db.begin()) --it;
      if (it->first <= x && it->second <= y) {
        ans = min(ans, 2 * x + 2 * y);
      }
    }
    {
      ll x = n / i, y = i;
      auto it = da.upper_bound({x, -1});
      if (it != da.begin()) --it;
      if (it->first <= x && it->second <= y) {
        ans = min(ans, 2 * x + 2 * y);
      }
      it = db.upper_bound({x, -1});
      if (it != db.begin()) --it;
      if (it->first <= x && it->second <= y) {
        ans = min(ans, 2 * x + 2 * y);
      }
    }
  }
  cout << ans << '\n';
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
long long n,m,k;
long long n1,m1,k1;
long long ans=1,ans1=1;
int main()
{
    cin>>n>>m>>k;
    n1=n;
    m1=m;
    k1=k;
    if(k>n+m-2)
    {
        cout<<-1;
        return 0;
    }
    if(k>n-1)
    {
        ans=1;
        k=k-n+1;
    }
    else
    {
        ans=n/(k+1);
        ans=(n/(k+1))*m;
        goto ss;
    }
    ans*=(m/(k+1));
ss:
    ;
    if(k1>m1-1)
    {
        ans1=1;
        k1=k1-m1+1;
    }
    else
    {
        ans1=m1/(k1+1);
        ans1=(m1/(k1+1))*n1;
        goto nn;
    }
    ans1*=(n1/(k1+1));
nn:
    ;
    cout<<max(ans,ans1);
}


#include<iostream>
using namespace std;
int main ()
{
    int n,m,k; char s;
    cin>>n>>m>>k;
    if(k%2==0) s='R';
    else s='L';
    k--;
    int r=(k/(2*m))+1;
    int d=(k%(2*m)/2)+1;
    cout<<r<<" "<<d<<" "<<s<<"\n";
    return 0 ;
}


#include<cstdio>
typedef long long ll;
int main()
{
    ll n,m;
    scanf("%lld%lld",&n,&m);
    ll minn,maxn;

    if(n-m*2<=0) minn=0;
    else minn=n-m*2;

    ll i=0;
    while(m>0)
    {
        m-=i;i++;
    }
    maxn=n-i;

    printf("%lld %lld\n",minn,maxn);
    return 0;
}


/*
 * new
 *
 *  Created on: Dec 9, 2015
 *      Author: AbdullaAshraf
 */
#include<bits/stdc++.h>
using namespace std;

int main() {
	int k,a,b,v,cnt=0;
	cin >> k >> a >> b >> v;
	while(b > 0){
		cnt++;
		a-= v*min(k,b+1);
		b -= k-1;
		if (a<=0){
			cout << cnt << endl;
			return 0;
		}
	}
	cout << (a+v-1)/v+cnt << endl;
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include<algorithm>
#include<iostream>
#include<vector>
#include<cmath>
#include<string>
#include<iomanip>
#include<deque>
#include<set>
using namespace std;
typedef long long ll;
const ll INF = 1000000000;
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int nt;
	cin >> nt;
	cout << nt % 2;
	return 0;
}


#include<iostream>
#include<algorithm>
#include <vector>
#include <string>
using namespace std;
int main()
{
	int c = 0;
	string a, b;
	cin >> a;
	for (int i = 0; i < 5; i++)
	{
		cin >> b;
		if (a[1] == b[1] || a[0] == b[0])
		{
			c++;
		}
	}
	if (c >= 1)
	{
		cout << "YES";
		return 0;
	}
	cout << "NO";
	return 0;
}


#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<memory.h>
using namespace std;

int can[600002];
int n, d;
set<int> v;
int c[51];
int main(){

    cin >> n >> d;
    for(int i = 0; i < n; i++){
        cin >> c[i];
    }
    memset(can, 0, sizeof can);
    int mx = 0;
    sort(c, c + n);
    can[0] = 1;
    for(int i = 0; i < n; i++){
        for(int j = mx; j >= 0; j--){
            if(can[j]){
                can[j + c[i]] = 1;
                mx = max(mx, j + c[i]);
            }
        }
    }
    for(int i = 1; i <= mx; i++)
        if(can[i]){
            v.insert(i);
        }
    int ans = 0, day = 0;
    while(true){
        int k = ans + d;
        set<int>::iterator it = v.upper_bound(k);
        if(it == v.begin())
            break;
        it--;
        k = *it;
        if(k > ans)
            ans = k;
        else
            break;
        day++;
    }
    cout << ans << " ";
    cout << day << endl;

    return 0;
}


//
//  main.cpp
//  A
//
//  Created by nicomazz on 24/06/15.
//  Copyright (c) 2015 nicomazz. All rights reserved.
//

#include <cstdlib>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <iostream>
#include <cstring>
#include <climits>
#include <cmath>
#include <algorithm>
#include <utility>
#include <numeric>
#include <queue>
#include <deque>
#include <vector>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <bitset>

using namespace std;

#define TEST
#define MAXN 100010

typedef pair<int, int> pi;
typedef pair<int,pi> pii;
typedef vector<int> vi;
typedef unsigned long long ull;
typedef  long long ll;

#define Foreach(i, c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define For(i,a,b) for(int (i)=(a);(i) < (b); ++(i))

#define iOS ios_base::sync_with_stdio(false)
#define error(x) cerr << #x << " = " << (x) <<endl
#define all(x) (x).begin(), (x).end()
template <class T>  inline void smax(T &x,T y){ x = max((x), (y));}
template <class T>  inline void smin(T &x,T y){ x = min((x), (y));}

#define gc getchar
inline void scanInt(int &x)
{
    register char c=gc();
    x = 0;
    bool neg = false;
    while( c<48 || c>57) {if (c == '-')neg = true; c=gc();}
    for(;c>47 && c<58;c = gc()){x = (x<<1) + (x<<3) + c - 48;}
    if (neg) x*=-1;
}

int lati[6];
ll pot(int b, int e)
{
    if ( b == 1) return 1;
    if ( e == 0) return 1;
    if ( e == 1) return b;
    if ( e % 2)
    {
        ll ris = pot(b, e/2);
        return ris*ris+ris;
    }

    ll ris =  pot(b,e/2);
    return ris*ris;
}
int main(int argc, const char * argv[])
{
#ifndef TEST
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif

    int a,b,c,d,e,f;
    cin>>a>>b>>c>>d>>e>>f;
    cout<<pot(a+b+c,2)-pot(a,2)-pot(c, 2)-pot(e,2);
    return 0;
    for (int i = 0; i < 6; i++)
        scanInt(lati[i]);

    ull tot_tr = 0;
    while ( true)
    {
        int cnt = 0;
        bool max_1 = true;
        bool tutti_1 = true;
        int div_0 = 0;
        for (int i = 0; i < 6; i++)
        {
            if ( lati[i] ) div_0++;
            if ( lati[i] != 1) tutti_1 =false;
            if ( lati[i] != 1 && lati[i] != 0) max_1 = false;
        }
        bool div_0_uguali = true;
        if (div_0 == 3)
        {
            int a = -1;
            for (int i = 0; i < 6; i++)
                if ( lati[i])
                {
                    if ( a == -1) a = lati[i];
                    if ( lati[i] != a) div_0_uguali = false;
                }
            if ( div_0_uguali)
            {
                while ( a != 0)
                {
                    tot_tr+= (a*2)-1;
                    a--;
                }
            }
            cout<<tot_tr; return 0;
        }
        if ( tutti_1) {tot_tr+= 6; cout<<tot_tr; return 0;}

        if ( max_1) {tot_tr++; cout<<tot_tr; return 0;}
        for (int i = 0; i < 6; i++)
            if ( lati[i])
            {
                    tot_tr+= lati[i]*2-1;
                lati[i]--;
                if (lati[i])cnt++;
            }
        if ( cnt  < 3) {cout<<tot_tr; return 0;}
    //    cout<<"tmp: "<<tot_tr<<endl;

    }
    return 0;
}


#include<iostream>
#include<algorithm>

using namespace std;

long long n, m, j, k, p, t, b[1111], x, nsz, msz, prevp, prevt;

long long proc(int l, int r)
{
    long long res=0;
    for (int i=l;i<r;i++)
    {
        res*=7;
        res+=b[i];
    }
    return res;
}

int main()
{
    cin >> n >> m;
    for (j=0;j<7;j++)
        b[j]=j;
    x=max((long long)1,n-1);
    while (x)
    {
        nsz++;
        x/=7;
    }
    x=max((long long)1,m-1);
    while (x)
    {
        msz++;
        x/=7;
    }
    if (nsz+msz>7)
    {
        cout << 0;
        return 0;
    }
    do
    {
        p=proc(0,nsz);
        t=proc(nsz,nsz+msz);
        if (p<n && t<m && (prevp!=p || prevt!=t))
        {
            prevp=p;
            prevt=t;
            k++;
        }
    }while(next_permutation(b,b+7));
    cout << k;
    return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
int n,a[105]={-1},cnt=1,ans=1;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)cin>>a[i];
    sort(a+1,a+n+1);
    for(int i=1;i<=n;i++)
    {
        if(a[i-1]==a[i])cnt++;
        else cnt=1;
        ans=max(ans,cnt);
    }
    cout<<ans;
    return 0;
}


#include<bits/stdc++.h>

using namespace std;
char nc()
{
	static char buf[1048576], *p1 = buf, *p2 = buf;
	if(p1 == p2){
		p1 = buf;
		p2 = buf + fread(buf, 1, 1048576, stdin);
	}
	return *p1++;
}
int scan()
{
	int sig = 1, sum = 0;
	char f = nc();
	while((f < '0' || f > '9')&&f != '-')f = nc();
	if(f == '-')
	{
		sig = -1;
		f = nc();
	}
	while(f >='0' && f <= '9'){
		sum = sum * 10 + f - '0';
		f = nc();
	}
	sum *= sig;
	return sum;
}

int n,k,x,a[200],b[200],f,cnt,ans,now,t1,t2,fa,ba;
int s(int x,int m){
	int cc=0;
	for(int i=x;a[i]==m&&i<=n;++i) ++cc;
	return cc;
}
int bi(int x,int m){
	int cc=0;
	for(int i=x;a[i]==m&&i>=1;--i) ++cc;
	return cc;
}
int main(){
	n=scan();k=scan();x=scan();
	for(int i=1;i<=n;++i) {
		a[i]=scan();
		if(f==0&&a[i]==x){
			++cnt;
			b[cnt]=i;
			f=1;
		}
		else if(a[i]!=x) f=0;
	}
	for(int i=1;i<=cnt;++i){
		now=s(b[i],x);
		if(now<2) continue;
		t1=s(b[i]+now,a[b[i]+now]);
		fa=now+t1;
		t2=bi(b[i]-1,a[b[i]-1]);
		ba=t2;
		if(a[b[i]+now]==a[b[i]-1])
		while(t1+t2>=3){
			now+=t1+t2;
			t1=s(b[i]+fa,a[b[i]+fa]);
			t2=bi(b[i]-ba-1,a[b[i]-ba-1]);
			if(a[b[i]+fa]!=a[b[i]-ba-1]) break;
			fa+=t1;
			ba+=t2;
		}
		ans=max(ans,now);
	}
	printf("%d",ans);
	return 0;
}


#include<bits/stdc++.h>
#include<bitset>
#define ll long long int
#define ld double
#define fi first
#define se second
#define pb push_back
#define pob pop_back
#define W while
#define fn(i,x) for(ll i=0;i<x;i++)
#define fs(i,s,x) for(int i=s;i<x;i++)
#define fr(i,x) for(int i=x;i>=0;i--)
#define fit(it,s) for(auto it=s.begin();it!=s.end();it++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define srt(vec) sort(vec.begin(),vec.end())
#define MAX 100005
#define M 32
#define endl "\n"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<pii , null_type, less< pii >, rb_tree_tag, tree_order_statistics_node_update>
using namespace std;
using namespace __gnu_pbds;
ll mod =1000000007;
ll pow1(ll a,ll b){if(b==0) return 1; ll p=pow1(a,b/2);if(b%2) return ((p*p))*a;return (p*p);}
ll pow2(ll a,ll b){if(b==0) return 1; ll p=pow2(a,b/2);if(b%2) return (((p*p)%mod)*a)%mod;return (p*p)%mod;}
ll gcd(ll a,ll b){if(a==0) return b;return gcd(b%a,a);}
int find1(int i,int dsu[]){if(dsu[i]==i) return i; dsu[i]=dsu[dsu[i]]; return find1(dsu[i],dsu);}
void union1(int i,int j,int dsu[]) {dsu[j]=find1(i,dsu);}
ll inv(ll a){ return pow2(a,mod-2);}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll bin(ll start,ll end,ll val)
{
    while(start<end)
    {
        if(start+1==end)
        {
            if((end*(end+1))/2<val)
                return end;
            else
                return start;
        }
        ll mid=(start+end)/2;
        if((mid*(mid+1))/2<val)
            start=mid;
        else end=mid-1;
    }
    return start;
}
ll fact[1000005];
void precomputefact(){fact[0]=1; fs(i,1,1000005) fact[i]=(fact[i-1]*i)%mod;}
ll com(ll a,ll b){if(b>a) return 0; return ((fact[a]*inv(fact[a-b]))%mod*inv(fact[b]))%mod;}
ll tree1[1300005][4];
void build(int start,int end,int node,ll a[])
{
    if(start==end)
    {

        return;
    }
    int mid=(start+end)/2;
    build(start,mid,2*node,a);
    build(mid+1,end,2*node+1,a);
}
void update(int start,int end,int node,int r,int val)
{
    if(start==end)
    {
        return;
    }
    int mid=(start+end)/2;
    if(r>mid)
        update(mid+1,end,2*node+1,r,val);
    else
        update(start,mid,2*node,r,val);
}
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
int main()
{
    IOS
    int t=1;
    //cin>>t;
    fn(z,t)
    {
        int n;
        cin>>n;
        ll a[3],b[3];
        fn(i,3)
        cin>>a[i];
        fn(i,3)
        cin>>b[i];
        ll ans2=0;
        fn(i,3)
        ans2+=min(a[i],b[(i+1)%3]);
        ll ans1=INT_MAX;
        int r=3;
        ll a1[3]={a[0],a[1],a[2]},b1[3]={b[0],b[1],b[2]};
        while(r--)
        {
            ll temp=min(b[0],a[1]);
        b[0]-=temp;
        a[1]-=temp;
        temp=min(b[0],a[0]);
        b[0]-=temp;
        a[0]-=temp;
        temp=min(b[1],a[1]);
        b[1]-=temp;
        a[1]-=temp;
        temp=min(b[1],a[2]);
        b[1]-=temp;
        a[2]-=temp;
        b[2]-=min(b[2],a[0]+a[2]);
        ans1=min(ans1,b[0]+b[1]+b[2]);
        fn(i,3)
        {
            a[i]=a1[(i+1)%3];
            b[i]=b1[(i+1)%3];
        }
        fn(i,3)
        {
            a1[i]=a[i];
            b1[i]=b[i];
        }
       }
        cout<<ans1<<" "<<ans2;
    }
}