#include <cstdlib> n #include <cstdarg> n #include <cassert> n #include <cctype> // tolower n #include <ctime> n #include <cmath> n  n #include <iostream> n #include <sstream> n #include <fstream> n #include <iomanip> n #include <stdexcept> n  n #include <map> n #include <set> n #include <list> n #include <queue> n #include <vector> n #include <string> n  n #include <limits> n #include <utility> n  n #include <numeric> n #include <iterator> n #include <algorithm> n #include <functional> n  n /* n  * g++ -g -std=c++11 -DBUG -D_GLIBCXX_DEBUG -Wall -Wfatal-errors -o cforce{,.cpp} n  * g++ -g -DBUG -D_GLIBCXX_DEBUG -Wall -Wfatal-errors -o cforce{,.cpp} n  * n  * TODO: n  *      C++ dataframe n  *      stl11 -> c++11 standard template lib in c++98 n  *      overload >> for map and set, using (insert) iterator n  *      chmod:: consider an algorithm stable to int64 overflow n  *      shortest path algorithm n  *      shortest path in a tree n  *      maximum network flow n  *      partial idx/iter sort n  *      a prime number generator which traverses prime numbers w/ ++ n  *      a divisor generator which traverses divisors efficiently n  *      Apply1st ?! n  *      Apply2nd and bind2nd ?! n  *          count_if ( a.begin(), a.end(), a.second < x ) n  *      Arbitrary-precision arithmetic / Big Integer / Fraction - rational num n  *      tuple class --> cplusplus.com/reference/tuple n  *      get<1>, get<2>, bind2nd ( foo ( get<2> pair ), val ) n  *      isin( const T & val, first, last ) n  *      fuinction composition in c++ n  *          blogea.bureau14.fr/index.php/2012/11/function-composition-in-c11/ n  *          cpp-next.com/archive/2010/11/expressive-c-fun-with-function-composition/ n  *      TimeWrapper -- accumulate time of a function call n  *          stackoverflow.com/questions/879408 n  *      hash map -- possible hash value & obj % some_big_prime [ b272 ] n  *          lower level can be a simple map to resolve hash collisions n  *      add explicit everywhere necessary n  *      bloom filters n  *      heap -> how to update values in place / increase-key or decrease-key ... IterHeap ?! n  *      median maintaince --> max_heap / min_heap n  *      prim s min spaning tree alg. O ( m log n ) using heap contianing V - X vertices n  *      kruskal algorithm minimum cost spanning tree with union find data structure n  *      unique_ptr n  *      hufman codes n  *      simple arithmatic tests n  *      longest common subsequence using seq. alignment type algorithm n  *      longest common substring ( consequative subsequeance ) n  *      Graham scan; en.wikipedia.org/wiki/Graham_scan n  */ n  n /* n  * @recepies n  * ---------------------------------------------- n  * odd / even n  *      transform ( x.begin(), x.end(), x.begin(), bind2nd( modulus<int>(), 2 )); n  *      count_if ( x.begin(), x.end(), bind2nd( modulus < int > (), 2)); n  * Apply2nd n  *      max_element ( m.begin(), m.end(), Apply2nd < string, int , less < int > > ) n  *      sort ( a.begin(), a.end(), Apply2nd < char, int , greater< int > > ) n  *      count_if ( m.begin(), m.end(), Apply2nd < string, int, modulus < int > > ) n  *      accumulate ( m.begin(), m.end(), 0.0, Apply2nd < int, double, plus < double > > ) n  *      accumulate ( m.begin( ), m.end( ), pair < int, double> ( 0 , 0.0 ) , operator+ < int, double > ) n  * abs_diff n  *      adjacent_difference ( a.begin(), a.end(), adj_diff.begin( ), abs_diff < int > ( ) ) n  *      accumulate ( a.begin(), a.end(), 0, abs_diff < int > ( ) ) n  * erase n  *      a.erase ( remove_if ( a.begin( ), a.end( ), bind2nd ( less < int >( ), 0 ) ), a.end( ) ) n  *      a.erase ( remove ( a.begin( ), a.end( ), b.begin( ), b.end( ) ), a.end ( ) ) n  * binding n  *      bind2nd ( mem_fun_ref (& ClassName::m_func ), arg )  // binds the argument of the object n  * iterator generators n  *      generate_n ( back_inserter ( a ), n, rand );  // calls push_back n  *      generate_n ( inserter( a, a.begin( ) + 5 ), 10, RandInt( 0 , 100 ) )  // calls insert n  *      copy ( foo.begin( ), foo.end( ), insert_iterator < std::list < double > > ( bar, bar.begin( ) + 5 )) n  * copy ( a.begin( ), a.end( ), ostream_iterator < double > ( cout,  ,   )) n  * accumulate ( m.begin( ), m.end( ), pair < int, double> ( 0 , 0.0 ) , operator+ < int, double > ) n  * transform (numbers.begin(), numbers.end(), lengths.begin(), mem_fun_ref(&string::length)); n  */ n  n /* n  * @good read n  * ---------------------------------------------- n  *  [ partial ] template specialization n  *      cprogramming.com/tutorial/template_specialization.html n  *  function composition n  *      cpp-next.com/archive/2010/11/expressive-c-fun-with-function-composition n  */ n  n /* n  * @prob set n  * ---------------------------------------------- n  *  purification --> c330 n  */ n  n /* n  * @limits n  * ---------------------------------------------- n  * int                  31    2.14e+09 n  * long int             31    2.14e+09 n  * unsigned             32    4.29e+09 n  * long unsigned        32    4.29e+09 n  * size_t               32    4.29e+09 n  * long long int        63    9.22e+18 n  * long long unsigned   64    1.84e+19 n  */ n  n /* n  * issues n  * ---------------------------------------------- n  * stackoverflow.com/questions/10281809 n  * mem_fun -> func_obj ( pointer to instance, origanal argument ) n  * bind1st ( mem_fun ( & ClassName::m_func ), this )    // binds obj of the class n  * bind1st takes  const T &  as the first argument n  */ n  n /* n  *  typedef / define n  * ---------------------------------------------- n  */ n  n typedef          long long int  int64; n typedef unsigned long long int uint64; n  n #define DOUBLE_INF std::numeric_limits< double >::infinity() n #define DOUBLE_NAN std::numeric_limits< double >::quiet_NaN() n  n #define DECLARE( X )   n     typedef       shared_ptr < X >  X ## _shared_ptr;   n     typedef const shared_ptr < X >  X ## _const_shared_ptr; n  n #ifdef BUG n     #define DEBUG(var) { std::cout << #var <<  :   << (var) << std::endl; } n     #define EXPECT(expr) if ( ! (expr) ) std::cerr <<  Assertion     n         << #expr   failed at   << __FILE__ <<  :  << __LINE__ << std::endl; n #else n     #define DEBUG(var) n     #define EXPECT(expr) n #endif n  n  n #define DBG(v) std::copy( v.begin(), v.end(), std::ostream_iterator < typeof( *v.begin() )> ( std::cout,     ) ) n  n /* n  * http://rootdirectory.de/wiki/SSTR() n  * usage: n  *      SSTR(  x^2:   << x*x ) n  */ n #define SSTR( val ) dynamic_cast< std::ostringstream & >( std::ostringstream() << std::dec << val ).str() n  n  n /* https://www.quora.com/C++-programming-language/What-are-some-cool-C++-tricks */ n // template <typename T, size_t N> n // char (&ArraySizeHelper(T (&array)[N]))[N]; n // #define arraysize(array) (sizeof(ArraySizeHelper(array))) n  n /* n  * forward decleration n  * ---------------------------------------------- n  */ n class ScopeTimer; n  n /* n  *  functional utils n  * ---------------------------------------------- n  */ n  n template < typename T > n struct abs_diff : std::binary_function < T, T, T > n { n     typedef T value_type; n  n     inline value_type operator( ) ( const value_type & x, const value_type & y ) const n     { n         return std::abs( x - y ); n     } n }; n  n // template < class InputIterator, class T > n // class isin : public std::binary_function < InputIterator, InputIterator, bool > n // { n //     public: n //         typedef T value_type; n // n //         isin ( const InputIterator & first, const InputIterator & last ): n //             m_first ( first ), m_last ( last ) { } n // n //         bool operator ( ) ( const value_type & val ) const n //         { n //             return std::find ( m_first, m_last, val ) != m_last; n //         } n //     private: n //         const InputIterator m_first, m_last; n // } n  n template < typename value_type, typename cont_type > n class isin : public std::unary_function < value_type, bool > n { n     public: n         isin( const cont_type & vals ): m_vals ( vals ) { }; n  n         bool operator ( ) ( const value_type & x ) const n         { n             return std::find ( m_vals.begin( ), m_vals.end( ), x ) != m_vals.end( ); n         } n  n     private: n         const cont_type m_vals; n }; n  n /* n  * max_element, min_element, count_if ... on the 2nd element n  * eg: max_element ( m.begin(), m.end(), Apply2nd < string, int , less < int > > ) n  */ n template < class T1, class T2, class BinaryOperation > n class Apply2nd : std::binary_function < typename std::pair < T1, T2 >, n                                         typename std::pair < T1, T2 >, n                                         typename BinaryOperation::result_type > n { n     public: n         typedef T1 first_type; n         typedef T2 second_type; n  n         typedef typename BinaryOperation::result_type result_type; n         typedef typename std::pair < first_type, second_type > value_type; n  n         inline result_type operator( ) ( const value_type & x, const value_type & y ) const n         { n             return binary_op ( x.second , y.second ); n         } n     private: n         BinaryOperation binary_op; n }; n  n /* n  * algo utils n  * ---------------------------------------------- n  */ n  n  n /** n  * count the number of inversions in a permutation; i.e. how many n  * times two adjacent elements need to be swaped to sort the list; n  * 3 5 2 4 1  -->  7 n  */ n template < class InputIterator > n typename std::iterator_traits<InputIterator>::difference_type n count_inv ( InputIterator first, InputIterator last ) n { n     typedef typename std::iterator_traits<InputIterator>::difference_type difference_type; n     typedef typename std::iterator_traits<InputIterator>::value_type value_type; n  n     std::list < value_type > l; /* list of sorted values */ n     difference_type cnt = 0; n  n     for ( difference_type n = 0; first != last; ++first, ++n ) n     { n         /* count how many elements larger than *first appear before *first */ n         typename std::list < value_type >::iterator iter = l.begin( ); n         cnt += n; n  n         for ( ; iter != l.end( ) && * iter <= * first; ++ iter, -- cnt ) n             ; n         l.insert( iter, * first ); n     } n  n     return cnt; n } n  n template < class ForwardIterator, class T > n inline void fill_inc_seq ( ForwardIterator first, ForwardIterator last, T val ) n { n     for ( ; first != last; ++first, ++val ) n         * first = val; n } n  n template <class ForwardIterator, class InputIterator > n ForwardIterator remove ( ForwardIterator first, ForwardIterator last, InputIterator begin, InputIterator end ) n { n     ForwardIterator result = first; n  n     for ( ; first != last; ++ first ) n         if ( find ( begin, end, *first ) == end ) n         { n             *result = *first; n             ++result; n         } n  n     return result; n } n  n /* stackoverflow.com/questions/1577475 */ n template < class RAIter, class Compare > n class ArgSortComp n { n     public: n         ArgSortComp ( const RAIter & first, Compare comp ):  m_first ( first ), m_comp( comp ) { } n         inline bool operator() ( const size_t & i, const size_t & j ) const n         { n             return m_comp (  m_first[ i ] ,  m_first[ j ] ); n         } n     private: n         const RAIter & m_first; n         const Compare m_comp; n }; n  n /*! n  * usage: n  *      vector < size_t > idx; n  *      argsort ( a.begin( ), a.end( ), idx, less < Type > ( ) ); n  */ n template < class RAIter, class Compare > n void argsort ( const RAIter & first, const RAIter & last, std::vector < size_t > & idx, Compare comp ) n { n     const size_t n = last - first; n     idx.resize ( n ); n  n     for ( size_t j = 0; j < n; ++ j ) n         idx[ j ] = j ; n  n     std::sort ( idx.begin( ), idx.end( ), ArgSortComp< RAIter, Compare > ( first, comp ) ); n } n  n template < class RAIter, class Compare > n class IterSortComp n { n     public: n         IterSortComp ( Compare comp ): m_comp ( comp ) { } n         inline bool operator( ) ( const RAIter & i, const RAIter & j ) const n         { n             return m_comp ( * i, * j ); n         } n     private: n         const Compare m_comp; n }; n  n /*! n  * usage: n  *      vector < list < Type >::const_iterator > idx; n  *      itersort ( a.begin( ), a.end( ), idx, less < Type > ( ) ); n  */ n template <class INIter, class RAIter, class Compare> n void itersort ( INIter first, INIter last, std::vector < RAIter > & idx, Compare comp ) n { n     /* alternatively: stackoverflow.com/questions/4307271 */ n     idx.resize ( std::distance ( first, last ) ); n     for ( typename std::vector < RAIter >::iterator j = idx.begin( ); first != last; ++ j, ++ first ) n         * j = first; n  n     std::sort ( idx.begin( ), idx.end( ), IterSortComp< RAIter, Compare > (comp ) ); n } n  n  n /* n  *  string utils n  * ---------------------------------------------- n  */ n  n inline void erase ( std::string & str, const char & ch ) n { n     std::binder2nd < std::equal_to < char > > isch ( std::equal_to < char > ( ), ch ); n     std::string::iterator iter = std::remove_if ( str.begin(), str.end(), isch ); n     str.erase ( iter, str.end() ); n } n  n inline void erase ( std::string & str, const std::string & chrs ) n { n     isin < char, std::string > isin_chrs ( chrs ); n     std::string::iterator iter = std::remove_if ( str.begin(), str.end(), isin_chrs ); n     str.erase ( iter, str.end() ); n } n  n template < typename value_type> n inline std::string val2str ( const value_type & x ) n { n     std::ostringstream sout ( std::ios_base::out ); n     sout << x; n     return sout.str(); n } n  n template < typename value_type> n inline value_type str2val ( const std::string & str ) n { n     std::istringstream iss ( str, std::ios_base::in ); n     value_type val; n  n     iss >> val; n     return val; n } n  n std::vector< std::string > tokenize ( const std::string & str, const char & sep ) n { n     /*! n      * outputs empty tokens and assumes str does not start with sep n      * corner cases: n      *      empty string, one char string, n      *      string starting/ending with sep, all sep, end with two sep n      */ n  n     std::vector < std::string > res; n     std::string::const_iterator follow = str.begin( ), n                                 lead   = str.begin( ); n  n     while ( true ) n     { n         while ( lead != str.end() && * lead != sep ) n             ++ lead; n  n         res.push_back ( std::string( follow, lead ) ); n  n         if ( lead != str.end ( ) ) n             follow = 1 + lead ++ ; n         else n             break; n     } n  n     return res; n } n  n /*! n  * chunk a string into strings of size [ at most ] k n  */ n void chunk ( const std::string::const_iterator first, n              const std::string::const_iterator last, n              const size_t k, n              const bool right_to_left, n              std::list < std::string > & str_list ) n { n     str_list.clear( ); n  n     if ( right_to_left ) n         /* chunk from the end of the string */ n         for ( std::string::const_iterator i, j = last; j != first; j = i ) n         { n             i = first + k < j ? j - k : first; n             str_list.push_back ( std::string ( i, j ) ); n         } n     else n         /* chunk from the begining of the string */ n         for ( std::string::const_iterator i = first, j; i != last; i = j ) n         { n             j = i + k < last ? i + k : last; n             str_list.push_back ( std::string ( i, j ) ); n         } n } n  n /*! n  * next lexicographically smallest string n  * within char set a..z n  */ n std::string & operator++( std::string & s ) n { n     /* find the first char from right less than  z  */ n     std::string::reverse_iterator j = find_if( s.rbegin( ), s.rend( ), n             std::bind2nd( std::less < char > ( ),  z  )); n  n     if ( j != s.rend( )) n     { n         ++ *j; n         std::fill( s.rbegin( ), j,  a  ); n     } n     else n         s.assign( s.length( ) + 1,  a  ); n  n     return s; n } n  n /*! n  * getline ( cin, str ) n  *      requires ctrl-D n  *      cin >> str; does not pass after space char n  */ n  n  n /* n  *  number utils n  * ---------------------------------------------- n  */ n  n  n class BigInteger n { n #if ULONG_MAX <= 1 << 32 n     typedef long long unsigned val_type; n #else n     typedef long unsigned val_type; n #endif n     const static int WSIZE = 32; n     const static val_type BASE = 1LL << WSIZE; n     public: n     private: n         std::list < val_type > val;  /* val[ 0 ] is most significant */ n         bool pos;                    /* true if sign is positive     */ n }; n  n /** n  * greatest common divisor - Euclid s alg. n  */ n template < typename value_type > inline n value_type gcd ( value_type a, value_type b ) n { n     return ! b ? a : gcd( b, a % b ); n  n     // if ( a < 0 )  a = -a ; n     // if ( b < 0 )  b = -b ; n     // if ( a < b )  std::swap ( a, b ); n  n     /* corner case: one of the values is zero */ n     // if ( ! b )   return a; n  n     // for ( value_type r = a % b; r ; r = a % b ) n     // { n     //     a = b; n     //     b = r; n     // } n  n     // return b; n } n  n  n /** n  * prime factorization n  */ n template < class T > n void prime_factors( T n, std::map < T, size_t > & fac ) n { n     for ( T k = 2; n > 1; ++ k ) n         if ( ! ( n % k ) ) n         { n             size_t & ref = fac[ k ]; n             while ( ! ( n % k ) ) n             { n                 ++ ref; n                 n /= k; n             } n         } n } n  n /* abs diff - safe for unsigned types */ n template < class T > n inline T absdiff( T a, T b ) n { n     return a < b ? b - a : a - b; n } n  n  n namespace n { n     template < class T > n     std::pair < T, T > __extgcd ( const T & x0, const T & y0, n                                   const T & x1, const T & y1, n                                   const T & r0, const T & r1 ) n     { n         const T q  = r0 / r1; n         const T r2 = r0 % r1; n  n         if ( ! ( r1 % r2 ) ) n             return std::make_pair < T, T > ( x0 - q * x1, y0 - q * y1 ); n  n         const T x2 = x0 - q * x1; n         const T y2 = y0 - q * y1; n  n         return __extgcd ( x1, y1, x2, y2, r1, r2 ); n     } n } n  n /** n  * extended euclidean algorithm: a x  +  b y = gcd( a, b) n  * en.wikipedia.org/wiki/Extended_Euclidean_algorithm n  */ n template < class value_type > inline n std::pair < value_type, value_type > extgcd ( value_type a, value_type b ) n { n     return a % b n         ? __extgcd < value_type > ( 1, 0, 0, 1, a, b ) n         : std::make_pair < value_type, value_type > ( 0, 1 ); n } n  n  n /** n  * modular multiplicative inverse n  * en.wikipedia.org/wiki/Modular_multiplicative_inverse n  */ n template < class value_type > inline n value_type modinv ( value_type a, value_type m ) n { n     const std::pair < value_type, value_type > coef ( extgcd( a, m ) ); n  n     /* a needs to be coprime to the modulus, or the inverse won t exist */ n     if ( a * coef.first + m * coef.second != 1 ) n         throw std::runtime_error ( val2str( a ) +   is not coprime to   + val2str( m )); n  n     /* return a pos num between 1 & m-1 */ n     return ( m + coef.first % m ) % m; n } n  n inline bool isnan ( const double & a ) n { n     return ! ( a == a ); n } n  n template < typename value_type > n inline value_type mini ( int n, ... ) n { n     va_list vl; n     va_start (vl, n); n     value_type res = va_arg ( vl, value_type ); n  n     for ( int i = 1; i < n; ++i ) { n         const value_type val = va_arg ( vl, value_type ); n         res = std::min ( res, val ); n     } n  n     va_end( vl ); n     return res; n } n  n template < typename value_type > n inline value_type maxi ( int n, ... ) n { n     va_list vl; n     va_start (vl, n); n     value_type res = va_arg ( vl, value_type ); n  n     for ( int i = 1; i < n; ++i ) { n         const value_type val = va_arg ( vl, value_type ); n         res = std::max ( res, val ); n     } n  n     va_end( vl ); n     return res; n } n  n // XXX look this up how is this implemented n template < class T > n inline int sign ( const T & x ) n { n     if ( x == T() ) n         return 0; n     else if ( x < T() ) n         return -1; n     else n         return 1; n } n  n /* n  * change moduluos from n to m n  */ n std::string chmod ( std::string num, const unsigned n, const unsigned m ) n { n     const char * digit =  0123456789abcdefghijklmnopqrstuvwxyz ; n     std::transform ( num.begin(), num.end(), num.begin(), tolower ); n  n     isin < char, std::string > is_alpha_num ( digit ); n     assert ( find_if ( num.begin( ), num.end( ), std::not1 ( is_alpha_num ) ) == num.end( )); n  n     unsigned long long int val ( 0 ); n  n     if ( n == 10U ) n     { n         std::istringstream iss ( num, std::ios_base::in ); n         iss >> val; n     } n     else n         for ( std::string::const_iterator iter = num.begin( ); iter != num.end( ); ++ iter ) n             val = val * n + (  a  <= *iter ? *iter -  a  + 10U : *iter -  0 ); n  n     if ( m == 10U ) n     { n         std::ostringstream sout ( std::ios_base::out ); n         sout << val; n         return sout.str ( ); n     } n     else n     { n         std::string res; n         for ( ; val ; val /= m ) n             res.push_back( digit [ val % m ] ); n  n         return res.length( ) ? std::string( res.rbegin( ), res.rend( )) :  0 ; n     } n } n  n template < class value_type >  /* a^n mod m */ n value_type powmod ( value_type a, const value_type & n, const value_type & m ) n { n     if ( a == 1 || ! n ) n         return m != 1 ? 1 : 0; n  n     value_type res = 1; n     for ( value_type k = 1; k <= n; a = a * a % m, k = k << 1 ) n         if ( k & n ) n             res =  ( res * a ) % m; n  n     return res; n } n  n /* n  * Fermat pseudoprime test n  * www.math.umbc.edu/~campbell/Computers/Python/numbthy.py n  * NOTE: since return type is bool, and powmod may break for ints, n  *       the argument is always casted to long long n  */ n inline bool is_pseudo_prime ( const long long & a ) n { n     /* all the primes less than 1000 ( 168 primes )*/ n     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, n                               79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157, n                               163,167,173,179,181,191,193,197,199,211,223,227,229,233,239, n                               241,251,257,263,269,271,277,281,283,293,307,311,313,317,331, n                               337,347,349,353,359,367,373,379,383,389,397,401,409,419,421, n                               431,433,439,443,449,457,461,463,467,479,487,491,499,503,509, n                               521,523,541,547,557,563,569,571,577,587,593,599,601,607,613, n                               617,619,631,641,643,647,653,659,661,673,677,683,691,701,709, n                               719,727,733,739,743,751,757,761,769,773,787,797,809,811,821, n                               823,827,829,839,853,857,859,863,877,881,883,887,907,911,919, n                               929,937,941,947,953,967,971,977,983,991,997 }; n  n     const size_t n = sizeof( p ) / sizeof ( p[ 0 ] ); n  n     if ( a < p[ n - 1 ] + 1) n         return std::binary_search ( p, p + n , a ); n  n     if ( std::find_if ( p, p + n, std::not1 ( std::bind1st ( std::modulus< long long >( ), a ))) != p + n ) n         return false; n  n     const size_t k = a <    9006401LL ? 3 : n                      a <   10403641LL ? 4 : n                      a <   42702661LL ? 5 : n                      a < 1112103541LL ? 6 : 7; n  n     for ( size_t j = 0; j < k; ++ j ) n         if ( powmod ( p[ j ], a - 1, a ) != 1 ) n             return false; n  n     return true; n } n  n  n /* n  * returns a sorted vector of all primes less than or equal to n n  * maximum adj diff of all primes less than 1e5 is 72 ( 114 for 1e6 ) n  */ n template < typename value_type > n std::vector < value_type > get_primes ( const value_type n ) n { n #ifdef BUG n     ScopeTimer scope_timer (  std::vector < value_type > get_primes ( const value_type n )  ); n #endif n  n     typedef typename std::vector < value_type >::iterator iterator; n     std::vector < value_type > primes; n  n     for ( value_type k = 2 ; k <= n; ++ k ) n         if ( is_pseudo_prime ( k ) ) n         { n             const value_type sqrt_k = 1 + static_cast < value_type > ( sqrt ( k + 1 ) ); n             iterator iend = upper_bound ( primes.begin( ), primes.end( ), sqrt_k ); n  n             if ( find_if ( primes.begin( ), iend, std::not1 ( std::bind1st ( std::modulus< value_type >( ), k ) ) ) != iend ) n                 continue; n  n             primes.push_back ( k ); n         } n  n     return primes; n } n  n template < class T > n inline std::list < std::pair < T, size_t > > get_prime_fact ( T a ) n { n     std::list < std::pair < T, size_t > > fac; n  n     for ( T k = 2; a > 1; ++ k ) n         if ( ! ( a % k ) )  // no need to check if k is prime n         { n             size_t m = 0; n             for ( ; ! ( a % k ) ; ++m, a/= k ) n                 ; n  n             fac.push_back ( std::pair < T, size_t > ( k, m ) ); n         } n     return fac; n } n  n  n template < class T > n T n_choose_k ( T n, T k ) n { n     if ( k > n ) n         return 0; n  n     const T lb = std::min ( k, n - k ) + 1; n     const T ub = n - lb + 1; n  n     T res = 1, j = 2; n     while ( n > ub && j < lb) n     { n         res *= n--; n         while ( j < lb and ! (res % j) ) n             res /= j++; n     } n  n     while ( n > ub ) n         res *= n--; n  n     return res; n } n  n  n /** n  * median calculator, using two heaps n  */ n template < class InputIter > n inline std::pair < typename InputIter::value_type, typename InputIter::value_type > n median ( InputIter first, InputIter last ) n { n     typedef typename InputIter::value_type      value_type; n     typedef std::pair< value_type, value_type > result_type; n  n     /* n      * max_heap: n      *      - the lower half of the elements n      *      - the biggest of such elements is on the top n      */ n     std::vector < value_type > max_heap, min_heap; n  n     /* n      * comp argument to heap algorithm should provide n      *  strict weak ordering ; in particular n      *      std::not2 ( std::less < value_type > ) n      * does not have such a strict weak ordering; n      */ n     std::less    < value_type > max_heap_comp; n     std::greater < value_type > min_heap_comp; n  n     if ( first == last )  /* corner case: empty vector */ n         throw std::runtime_error (  median of an empty vector is undefined!  ); n  n     InputIter iter = first; n     max_heap.push_back ( * iter ); n  n     for ( ++iter ; iter != last; ++ iter ) n         if ( * iter < max_heap.front() ) n         { n             max_heap.push_back ( * iter ); n             std::push_heap ( max_heap.begin(), max_heap.end(), max_heap_comp ); n  n             if ( min_heap.size() + 1 < max_heap.size() ) n             { n                 /* max_heap has got too large */ n                 min_heap.push_back( max_heap.front() ); n                 std::push_heap( min_heap.begin(), min_heap.end(), min_heap_comp ); n  n                 std::pop_heap( max_heap.begin(), max_heap.end(), max_heap_comp ); n                 max_heap.pop_back(); n             } n         } n         else n         { n             min_heap.push_back ( * iter ); n             std::push_heap ( min_heap.begin(), min_heap.end(), min_heap_comp ); n  n             if ( max_heap.size() + 1 < min_heap.size() ) n             { n                 /* min_heap has got too large */ n                 max_heap.push_back( min_heap.front() ); n                 std::push_heap( max_heap.begin(), max_heap.end(), max_heap_comp ); n  n                 std::pop_heap( min_heap.begin(), min_heap.end(), min_heap_comp ); n                 min_heap.pop_back(); n             } n         } n  n     DEBUG( max_heap ); n     DEBUG( min_heap ); n  n     return min_heap.empty( )  /* corner case: ++first = last */ n         ? result_type ( *first, *first ) n         : result_type ( max_heap.size() < min_heap.size() ? min_heap.front() : max_heap.front(), n                         min_heap.size() < max_heap.size() ? max_heap.front() : min_heap.front() ); n } n  n /* n  * geometry util n  * ---------------------------------------------- n  */ n  n struct xyPoint n { n     double x, y; n     xyPoint ( const double & a = .0, const double & b = .0 ): x ( a ), y( b ) { }; n }; n  n  n struct xyCircle n { n     xyPoint center; n     double radius; n }; n  n std::ostream & operator<< ( std::ostream & out, const xyPoint & p ) n { n     out <<  (  << p.x <<  ,   << p.y <<  ) ; n     return out; n } n  n std::istream & operator>> ( std::istream & ist, xyPoint & p ) n { n     ist >> p.x >> p.y; n     return ist; n } n  n std::ostream & operator<< ( std::ostream & out, const xyCircle & o ) n { n     out <<  {(  << o.center.x <<  ,   << o.center.y <<  )   << o.radius <<  } ; n     return out; n } n  n std::istream & operator>> ( std::istream & ist, xyCircle & o ) n { n     ist >> o.center.x >> o.center.y >> o.radius; n     return ist; n } n  n inline double cartesian_dist ( const xyPoint & a, const xyPoint & b ) n { n     const double d = a.x - b.x; n     const double e = a.y - b.y; n     return std::sqrt ( d * d + e * e ); n } n  n class xyLine n { n     public: n         xyLine ( const xyPoint & , const xyPoint & ); n         xyLine ( const double slope, const double intercept ); n  n         /* n          *  signed  orthogonal distance; the sign is useful n          * to compare which side of the line the point is n          */ n         inline double orth_dist ( const xyPoint & ) const; n     private: n         double m_slope; n         double m_intercept; n         double m_normfac;   /* normalization factor for orth_dist calc */ n  n         bool   m_vertical;  /* if the line is verticcal                */ n         double m_xcross;    /* x axis cross point for vertical line    */ n }; n  n xyLine::xyLine ( const xyPoint & a, const xyPoint & b ) n { n     if ( a.x == b.x )  /* vertical line */ n     { n         m_vertical  = true; n         m_xcross    = a.x; n  n         m_intercept = DOUBLE_NAN; n         m_slope     = DOUBLE_INF; n         m_normfac   = DOUBLE_NAN; n     } n     else n     { n         m_vertical  = false; n         m_xcross    = DOUBLE_NAN; n  n         m_slope     = ( b.y - a.y ) / ( b.x - a.x ); n         m_intercept = a.y - m_slope * a.x; n         m_normfac   = std::sqrt ( m_slope * m_slope + 1.0 ); n     } n } n  n xyLine::xyLine ( const double slope, const double intercept ): n     m_slope ( slope ),  m_intercept ( intercept ) n { n      m_vertical = false; n      m_xcross   = DOUBLE_NAN; n      m_normfac  = std::sqrt ( m_slope * m_slope + 1.0 ); n } n  n double xyLine::orth_dist ( const xyPoint & o ) const /*  signed  orthogonal distance */ n { n     if ( m_vertical ) n         return o.x - m_xcross; n     else n         return ( m_slope * o.x - o.y + m_intercept ) / m_normfac; n } n  n inline double triangle_area ( const xyPoint & a, const xyPoint & b, const xyPoint & c ) n { n     const xyLine l ( a, b ); n     const double h = std::abs ( l.orth_dist ( c ) ); n     const double e = cartesian_dist ( a, b ); n     return h * e; n } n  n /* n  *  operator<< overrides n  * ---------------------------------------------- n  */ n  n namespace n { n     /* helper function to output containers */ n     template < typename T > n     std::ostream & __output ( std::ostream & out, const T & a ) n     { n         typedef typename T::const_iterator const_iterator; n         out <<  {  ; n  n         // does not work for  pair  value type n         // std::copy ( a.begin( ), a.end( ), std::ostream_iterator < typename T::value_type > ( std::cout,  ,   )); n  n         for ( const_iterator iter = a.begin(); iter != a.end(); ++ iter ) n              out << ( iter != a.begin( ) ?  ,   :    ) << *iter ; n  n         return out <<   } ; n     } n } n  n template < typename key_type, typename value_type > n std::ostream & operator<< ( std::ostream & out, const std::pair < key_type, value_type > & p) n { n     out <<  (  << p.first <<  ,   << p.second <<  ) ; n     return out; n } n  n template < typename key_type, typename value_type, typename comp > n std::ostream & operator<< ( std::ostream & out, const std::map < key_type, value_type, comp > & m ) n { n     return __output ( out, m ); n } n  n template < typename value_type > n std::ostream & operator<< ( std::ostream & out, const std::set < value_type > & s ) n { n     return __output ( out, s ); n } n  n template < typename value_type > n std::ostream & operator<< ( std::ostream & out, const std::vector < value_type > & a ) n { n     return __output ( out, a ); n } n  n template < typename value_type > n std::ostream & operator<< ( std::ostream & out, const std::list < value_type > & a ) n { n     return __output ( out, a ); n } n  n template < typename value_type > n std::ostream & operator<< ( std::ostream & out, const std::vector < std::vector < value_type > > & a ) n { n     typedef typename std::vector < std::vector < value_type > >::const_iterator const_iterator; n  n     for ( const_iterator iter = a.begin( ); iter != a.end( ); ++ iter ) n         out <<   n  << *iter ; n  n     return out; n } n  n /* n  *  operator>> overrides n  * ---------------------------------------------- n  */ n  n template < typename key_type, typename value_type > n std::istream & operator>> ( std::istream & in, std::pair < key_type, value_type > & p) n { n     in >> p.first >> p.second; n     return in; n } n  n template < typename value_type > n std::istream & operator>> ( std::istream & in, std::vector < value_type > & a ) n { n     typedef typename std::vector < value_type >::iterator iterator; n  n     if ( ! a.size( ) ) n     { n         size_t n; n         in >> n; n         a.resize( n ); n     } n  n     for ( iterator iter = a.begin(); iter != a.end(); ++ iter ) n         in >> * iter; n  n     return in; n } n  n /* n  *  readin quick utilities n  * ---------------------------------------------- n  */ n  n // template < typename value_type > n // inline void readin ( std::vector < value_type > & a, size_t n = 0, std::istream & in = std::cin ) n // { n //     // if ( ! n ) std::cin >> n; n //     if ( ! n ) in >> n ; n //     a.resize ( n ); n //     // std::cin >> a; n //     in >> a; n // } n  n // XXX consider removing n // template < typename key_type, typename value_type > n // inline void readin (std::vector < std::pair < key_type , value_type > > & a, size_t n = 0 ) n // { n //     if ( !n ) std::cin >> n; n //     a.resize( n ); n //     std::cin >> a; n // } n  n /* n  *  pair utility n  * ---------------------------------------------- n  */ n  n /* n  * accumulate ( m.begin( ), m.end( ), pair < int, double> ( 0 , 0.0 ) , operator+ < int, double > ); n  * stackoverflow.com/questions/18640152 n  */ n template < typename T1, typename T2 > n inline std::pair < T1, T2 > operator+ ( const std::pair < T1, T2 > & a, const std::pair < T1, T2 > & b ) n { n     return std::make_pair < T1, T2 > ( a.first + b.first, a.second + b.second ); n } n  n template < typename T1, typename T2 > n inline std::pair < T1, T2 > operator- ( const std::pair < T1, T2 > & a, const std::pair < T1, T2 > & b ) n { n     return std::make_pair < T1, T2 > ( a.first - b.first, a.second - b.second ); n } n  n // template < class T1, class T2, class BinaryOperation > n // class Apply2nd : std::binary_function < typename std::pair < T1, T2 >, n //                                         typename std::pair < T1, T2 >, n //                                         typename BinaryOperation::result_type > n  n namespace n { n     /*! n      * helper template to do the work n      */ n     template < size_t J, class T1, class T2 > n     struct Get; n  n     template < class T1, class T2 > n     struct Get < 0, T1, T2 > n     { n         typedef typename std::pair < T1, T2 >::first_type result_type; n  n         static       result_type & elm (       std::pair < T1, T2 > & pr ) { return pr.first; } n         static const result_type & elm ( const std::pair < T1, T2 > & pr ) { return pr.first; } n     }; n  n     template < class T1, class T2 > n     struct Get < 1, T1, T2 > n     { n         typedef typename std::pair < T1, T2 >::second_type result_type; n  n         static       result_type & elm (       std::pair < T1, T2 > & pr ) { return pr.second; } n         static const result_type & elm ( const std::pair < T1, T2 > & pr ) { return pr.second; } n     }; n } n  n template < size_t J, class T1, class T2 > n typename Get< J, T1, T2 >::result_type & get ( std::pair< T1, T2 > & pr ) n { n     return Get < J, T1, T2 >::elm( pr ); n } n  n template < size_t J, class T1, class T2 > n const typename Get< J, T1, T2 >::result_type & get ( const std::pair< T1, T2 > & pr ) n { n     return Get < J, T1, T2 >::elm( pr ); n } n  n /* n  * graph utils n  * ---------------------------------------------- n  */ n  n /* n  * Dijkstra :: single-source shortest path problem for n  * a graph with non-negative edge path costs, producing n  * a shortest path tree n  * en.wikipedia.org/wiki/Dijkstra s_algorithm n  */ n template < typename DistType > n void Dijekstra ( const size_t & source, n                  const std::vector < std::list < size_t > > & adj,          // adjacency list n                  const std::vector < std::vector < DistType > > & edge_len, // pair-wise distance for adjacent nodes n                  std::vector < DistType > & dist,  // distance from the source n                  std::vector < size_t > prev )     // previous node in the shortest path tree n { n     // TODO n } n  n // TODO http://en.wikipedia.org/wiki/Shortest_path_problem n // TODO Graph class, Weighted graph, ... n  n /* n  *  maximum cardinality matching in a bipartite graph n  *        G = G1 ∪ G2 ∪ {NIL} n  *  where G1 and G2 are partition of graph and NIL is a special null vertex n  *  https://en.wikipedia.org/wiki/Hopcroft-Karp_algorithm n  */ n class HopcroftKarp n { n     public: n         HopcroftKarp ( const std::vector < std::list < size_t > > & adj, n                        const std::vector < bool > & tag ); n  n         size_t get_npair ( ) { return npair; }; n         std::map < size_t, size_t > get_map ( ); n  n     private: n         bool mf_breadth_first_search ( );  // breadth first search from unpaired nodes in G1 n         bool mf_depth_first_search ( const size_t v ); // dfs w/ toggeling augmenting paths n  n         const std::vector < std::list < size_t > > & m_adj;  // adjacency list for each node n         const std::vector < bool > & m_tag;  // binary tag distinguishing partitions n  n         size_t npair; n         const size_t NIL;  // special null vertex n         const size_t INF;  // practically infinity distance n  n         std::vector < size_t > m_g1;    // set of nodes with tag = true n         std::vector < size_t > m_dist;  // dist from unpaired vertices in G1 n         std::vector < size_t > m_pair; n }; n  n  n std::map < size_t, size_t > HopcroftKarp::get_map ( ) n { n     std::map < size_t, size_t > m; n  n     for ( size_t j = 0; j < m_pair.size( ); ++ j ) n         if ( m_pair[ j ] != NIL  && m_tag[ j ]) n             m[ j ] = m_pair[ j ]; n  n     return m; n } n  n  n HopcroftKarp::HopcroftKarp ( const std::vector < std::list < size_t > > & adj, n                              const std::vector < bool > & tag ): n     m_adj ( adj ), n     m_tag ( tag ), n     npair ( 0 ), n     NIL ( adj.size( )), n     INF ( adj.size( ) + 1 ), n     m_dist ( std::vector < size_t > ( adj.size( ) + 1, INF)), n     m_pair ( std::vector < size_t > ( adj.size( ), NIL ))  // initially everything is paired with nil n { n     assert ( m_adj.size() == m_tag.size() ); n  n     for ( size_t j = 0; j < tag.size( ); ++ j ) n         if ( tag[ j ] ) n             m_g1.push_back ( j ); n  n     while ( mf_breadth_first_search ( ) ) n         for ( std::vector < size_t >::const_iterator v = m_g1.begin( ); v != m_g1.end( ); ++ v ) n             if ( m_pair[ *v ] == NIL && mf_depth_first_search ( *v ) ) n                 ++ npair; n } n  n bool HopcroftKarp::mf_breadth_first_search( ) n { n     /* only nodes from g1 are queued */ n     std::queue < size_t > bfs_queue; n  n     /* initialize queue with all unpaired nodes from g1 */ n     for ( std::vector < size_t >::const_iterator v = m_g1.begin( ); v != m_g1.end( ); ++v ) n         if ( m_pair[ *v ] == NIL ) n         { n             m_dist[ *v ] = 0; n             bfs_queue.push ( *v ); n         } n         else n             m_dist[ *v ] = INF; n  n     m_dist[ NIL ] = INF; n  n     /* find all the shortest augmenting paths to node nil */ n     while ( ! bfs_queue.empty() ) n     { n         const size_t v = bfs_queue.front( ); n         bfs_queue.pop ( ); n  n         if ( m_dist[ v ] < m_dist[ NIL ] ) n             for ( std::list < size_t >::const_iterator u = m_adj[ v ].begin( ); u != m_adj[ v ].end( ); ++ u ) n                 if ( m_dist[ m_pair[ * u ] ] == INF ) n                 { n                     m_dist[ m_pair[ * u ] ] = m_dist[ v ] + 1; n                     bfs_queue.push ( m_pair[ * u ] ); n                 } n     } n  n     return m_dist[ NIL ] != INF; n } n  n  n bool HopcroftKarp::mf_depth_first_search( const size_t v ) n { n     if ( v == NIL ) n         return true; n     else n     { n         for ( std::list < size_t >::const_iterator u = m_adj[ v ].begin( ); u != m_adj[ v ].end( ); ++ u ) n             if ( m_dist[ m_pair[ *u ] ] == m_dist[ v ] + 1  && mf_depth_first_search( m_pair[ *u ] )) n             { n                 /* n                  * there is an augmenting path to nil from m_pair[ *u ] n                  * and hence there is an augmenting path from v to u and n                  * u to to nil; therefore v and u can be paired together n                  */ n                 m_pair [ *u ] = v; n                 m_pair [  v ] = *u; n                 return true; n             } n         m_dist[ v ] = INF; n         return false; n     } n } n  n /* n  *  data-structure utility n  * ---------------------------------------------- n  */ n  n template < class T, class Comp = std::less< T > > n class Heap  /* less< T > --> max-heap */ n { n     typedef T value_type; n     typedef typename std::vector < value_type >::size_type size_type; n     public: n         /* n          * stackoverflow.com/questions/10387751 n          * possible work-around: a memebr pointer to m_val n          * n          * TODO: static/friend heapify ( val, & heap )  XXX O( n ) ?! n          */ n         Heap ( ): m_val ( std::vector < value_type > ( ) ) , m_comp ( Comp( ) ){ } n  n         template < class InputIter > n         Heap ( InputIter first, InputIter last ): n             m_val ( std::vector < value_type > ( ) ) , m_comp( Comp( ) ) n         { n             for ( ; first != last ; ++ first ) n                 m_val.push_back ( * first ); n  n             std::make_heap( m_val.begin( ), m_val.end( ), m_comp ); n         } n  n         /*! n          * to avoid destroying heap property, front( ) n          * should always return a  const  reference n          */ n         inline const value_type & front( ) const { return m_val.front( ); } n         inline bool empty( ) const { return m_val.empty( ); } n         inline size_type size( ) const { return m_val.size( );  } n  n         inline void push ( const value_type & a ) n         { n             m_val.push_back( a ); n             std::push_heap( m_val.begin( ), m_val.end( ), m_comp ); n         } n         inline void pop( ) n         { n             std::pop_heap ( m_val.begin( ), m_val.end( ), m_comp ); n             m_val.pop_back( ); n         } n  n         // inline void swap( Heap< T, Comp> & other ) { m_val.swap( other.m_val ) }; n         // void sort( ) { std::sort_heap ( m_val.begin( ), m_val.end( ), m_comp ); } n         // template < class X, class Y > n         // friend std::ostream & operator<<( std::ostream & out, const Heap < X, Y> & heap ); n     private: n         std::vector < value_type > m_val; n         const Comp m_comp; n }; n  n /* n  * boost.org/doc/libs/1_54_0/libs/smart_ptr/shared_ptr.htm n  */ n template < class Type > n class shared_ptr n { n     typedef Type value_type; n     public: n         explicit shared_ptr ( value_type * p = NULL ) : ptr ( p ), count ( new size_t ( 1U ) ) { } n         shared_ptr ( const shared_ptr < value_type > & sp ): ptr ( sp.ptr ), count ( sp.count ) { ++ * count; } n         ~ shared_ptr ( ) { release( ); } n  n         bool operator== ( const shared_ptr < value_type > & sp ) { return ptr == sp.ptr; } n         bool operator!= ( const shared_ptr < value_type > & sp ) { return ptr != sp.ptr; } n  n         shared_ptr < value_type > & operator= ( const shared_ptr < value_type > & sp ) n         { n             if ( this != & sp && ptr != sp.ptr ) n             { n                 release( ); n                 ptr   = sp.ptr; n                 count = sp.count; n                 ++ * count; n             } n             return * this; n         } n  n         value_type * operator-> ( ) { return ptr ; } n         value_type & operator* ( ) { return *ptr ; } n         const value_type * operator-> ( ) const { return ptr ; } n         const value_type & operator* ( ) const { return *ptr; } n  n         void swap ( shared_ptr < value_type > & sp ) n         { n             if ( this != &sp && ptr != sp.ptr ) n             { n                 std::swap ( ptr, sp.ptr ); n                 std::swap ( count, sp.count ); n             } n         } n  n     private: n         void release ( ) n         { n             /* stackoverflow.com/questions/615355 */ n             -- * count; n             if ( ! * count ) n             { n                 delete count; n                 delete ptr; n                 count = NULL; n                 ptr   = NULL; n             } n         } n         value_type * ptr; n         size_t     * count; n }; n  n /*! n  * union find data structure with n  *      - lazy unions n  *      - union by rank n  *      - path compression n  */ n class UnionFind n { n     public: n         UnionFind( const size_t n ): n             parent ( std::vector < size_t > ( n ) ),   /* initialize each node as its own   */ n             rank   ( std::vector < size_t > ( n, 0 ))  /* parent and set all the ranks to 0 */ n         { n             for ( size_t j = 0; j < n; ++ j ) n                 parent[ j ] = j ; n         } n  n         inline size_t find( const size_t s ) n         { n             /* n              * perform path compresion and add shortcut n              * if parent[ s ] is not a root node n              */ n             const size_t p = parent[ s ]; n             return parent[ p ] == p ? p : parent[ s ] = find( p ) ; n         } n  n         inline void lazy_union ( size_t i, size_t j ) n         { n             /* unions should be done on root nodes */ n             i = find( i ); n             j = find( j ); n  n             if ( i != j ) n             { n                 if ( rank [ i ] < rank[ j ] ) n                     parent[ i ] = j; n                 else n                 { n                     parent[ j ] = i; n                     rank[ i ]  += rank[ i ] == rank[ j ]; n                 } n             } n         } n     private: n         std::vector < size_t > parent; n         std::vector < size_t > rank; n }; n  n  n // TODO XXX n // template < class NumType > n // unsigned num_hash_func ( const NumType & a ) n // { n //     // XXX what will happen in case of overflow? n //     return static_cast < unsigned > ( a % 9973 ) % 9973 ; n // } n  n /* n  * XXX: HashMap: map< Key, T > data [ 9973 ] n  * data [ num_hash_func ( key ) ][ key ] n  */ n  n  n /* n  *  testing util n  * ---------------------------------------------- n  */ n  n // TODO add a preprocessor which automatically includes the funciton name, or __line__ n // and disables if not in debug mode n /* prints the life length of the object when it goes out of scope */ n class ScopeTimer n { n     public: n         ScopeTimer ( const std::string & msg =    ): tic ( clock ( )), m_msg( msg ) { }; n  n         ~ ScopeTimer ( ) n         { n             const clock_t toc = clock(); n             const uint64 dt   = 1000L * ( toc - tic ) / CLOCKS_PER_SEC; n  n             const uint64 mil = dt % 1000L; n             const uint64 sec = ( dt / 1000L ) % 60L; n             const uint64 min = ( dt / 60000L ) % 60L; n             const uint64 hrs = ( dt / 3600000L ); n  n             std::cout <<   n  << m_msg <<   n telapsed time:  ; n  n             if ( hrs )  std::cout << hrs <<   hrs,  ; n             if ( min )  std::cout << min <<   min,  ; n             if ( sec )  std::cout << sec <<   sec,  ; n             std::cout << mil <<   mil-sec n ; n         } n  n     private: n         typedef unsigned long long int  uint64; n         const clock_t tic; n         const std::string m_msg; n }; n  n class RandInt n { n     public: n         RandInt ( int a = 0, int b = 100 ): m ( a ), f ( static_cast < double > ( b - a ) / RAND_MAX ) { } n         inline int operator() ( ) { return m + std::ceil ( f * rand( ) ); } n     private: n         const int m; n         const double f; n }; n  n  n class RandDouble n { n     public: n         RandDouble ( double a = 0.0, double b = 1.0 ): m ( a ), f ( ( b - a ) / RAND_MAX ) { } n         inline double operator() ( ) { return m + f * rand( ); } n     private: n         const double m, f; n }; n  n class Noisy n { n     public: n         Noisy ( std::string str ): msg ( str ) n         { n             std::cout <<   Noisy (   << msg <<   ) t@   << this << std::endl; n         } n         ~Noisy ( ) n         { n             std::cout <<  ~Noisy (   << msg <<   ) t@   << this << std::endl; n         } n         void beep ( ) n         { n             std::cout <<   beep (   << msg <<   ) t@   << this << std::endl; n         } n         void beep ( ) const n         { n             std::cout <<   const beep (   << msg <<   ) t@   << this << std::endl; n         } n     private: n         const std::string msg; n }; n  n DECLARE ( Noisy ); n  n  n /* n  * ---------------------------------------------- n  * ---------------------------------------------- n  */ n  n /* n  * -- @@@ ------------------------------------------------- n  */ n  n using namespace std; n  n  n // struct Comp n // { n //     // bool operator() ( const pair < int, int > & x, const pair < int, int > & y ) n //     // { n //     //     return abs( x.first ) + abs( x.second ) < abs( y.first ) + abs( y.second ); n //     // } n // n //     // bool operator( ) ( const xyCircle & a, const xyCircle & b ) n //     // { n //     //     return a.radius < b.radius; n //     // } n //     // n //     bool operator( ) ( const pair < size_t, size_t > & pr, const size_t & x ) n //     { n //         return pr.second < x; n //     } n // }; n  n void probA() n { n     vector <size_t> a; n     cin >> a; n     sort( a.begin(), a.end() ); n     copy ( a.begin( ), a.end( ), ostream_iterator < size_t > ( cout,     )); n } n  n size_t probB( ) n { n     size_t n; n  n     string str; n     cin >> n >> str; n  n     // const size_t n = str.size(); n  n     const size_t INF = n + 2; n     vector < size_t > ldist( n ), rdist( n); n  n     rdist[ 0 ] = str[ 0 ] ==  R  ? 0 : INF; n     for ( size_t j = 1; j < n; ++ j ) n         switch ( str[ j ] ) n         { n             case  R : n                 rdist[ j ] = 0; n                 break; n             case  L : n                 rdist[ j ] = INF; n                 break; n             case  . : n                 rdist[ j ] = 1 + rdist[ j - 1 ]; n                 break; n         } n  n     ldist[ n - 1 ] = str[ n - 1 ] ==  L  ? 0 : INF; n     for ( size_t j = n - 1; j > 0; -- j ) n         switch ( str[ j - 1] ) n         { n             case  L : n                 ldist[ j - 1] = 0; n                 break; n             case  R : n                 ldist[ j - 1] = INF; n                 break; n             case  . : n                 ldist[ j - 1] = 1 + ldist[ j ]; n                 break; n         } n  n     DEBUG( ldist ); n     DEBUG( rdist ); n  n     size_t cnt = 0; n     for ( size_t j = 0; j < n; ++ j ) n         if ( ( INF <= ldist[j]  && INF <= rdist[j] ) || ldist[ j ] == rdist[ j ] ) n             ++ cnt; n  n     return cnt; n } n  n  n int main ( const int argc, char * argv [ ]) n { n  n     cout << probB(); n  n     // c79( ); n     // cout << c343( ); n     // cout << setprecision( 10 ) n  n     return EXIT_SUCCESS; n } n  n  n /** n  *   mislav.uniqpath.com/2011/12/vim-revisited/ n  * set encoding=utf-8 n  * %s/ (. {60,70 } ) / 1 r/gc n  * %s/ / /gc n  * %s/10 ([0-9] {1,2 } )/10^ 1/gc n  */ n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, k, pg, pt; n   scanf( %d %d , &n, &k); n   char a[105]; n   scanf( %s , a); n   for (int i = 0; i < n; i++) { n     if (a[i] ==  G ) pg = i; n     if (a[i] ==  T ) pt = i; n   } n   int x = abs(pg - pt); n   if (x % k == 0) { n     int fg = 0, st, ed; n     if (pg < pt) { n       st = pg; n       ed = pt + 1; n     } else { n       st = pt; n       ed = pg + 1; n     } n     for (int i = st; i < ed; i++) { n       if (a[i] ==  # ) { n         int xx = abs(pg - i); n         if (xx % k == 0) { n           fg = 1; n           break; n         } n       } n     } n     if (fg == 1) n       printf( NO n ); n     else n       printf( YES n ); n   } else n     printf( NO n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, k, trap[510]; n int e[510][510]; n long double t[510][510]; n const long double EPS = 1e-9; n void mult(long double a[110][110], long double b[110][110], n           long double c[110][110]) { n   long double r[110][110] = {}; n   for (int i = 0; i < (int)(110); i++) n     for (int j = 0; j < (int)(110); j++) n       for (int k = 0; k < (int)(110); k++) r[i][k] += a[i][j] * b[j][k]; n   for (int i = 0; i < (int)(110); i++) n     for (int j = 0; j < (int)(110); j++) c[i][j] = r[i][j]; n } n int main() { n   scanf( %d %d %d , &n, &m, &k); n   for (int i = 0; i < n; i++) scanf( %d , &trap[i]); n   while (m--) { n     int x, y; n     scanf( %d %d , &x, &y); n     --x; n     --y; n     ++e[x][y]; n     ++e[y][x]; n   } n   for (int i = 0; i < n; i++) n     if (!trap[i]) { n       int deg = 0; n       for (int j = 0; j < n; j++) deg += e[i][j]; n       for (int j = 0; j < n; j++) t[i][j] -= (long double)e[i][j] / deg; n       t[i][i] += 1.0; n     } else { n       t[i][i] = 1.0; n     } n   for (int i = 0; i < n; i++) n     if (!trap[i]) { n       int j = i; n       for (int k = i; k < n; k++) n         if (abs(t[k][i]) > abs(t[j][i])) j = k; n       for (int k = 0; k < n; k++) swap(t[i][k], t[j][k]); n       double scale = t[i][i]; n       for (int k = 0; k < n; k++) t[i][k] /= scale; n       for (int j = 0; j < n; j++) n         if (j != i) { n           scale = t[j][i]; n           for (int k = 0; k < n; k++) t[j][k] -= t[i][k] * scale; n         } n     } n   for (int i = 0; i < n; i++) n     if (trap[i]) t[i][i] = -1.0; n   long double m[110][110] = {}, v[510][510] = {}, r[110][110] = {}; n   int nr[510], next = 0; n   for (int i = 0; i < n; i++) n     if (trap[i]) nr[i] = next++; n   for (int i = 0; i < n; i++) n     if (trap[i]) { n       int deg = 0; n       for (int j = 0; j < n; j++) deg += e[i][j]; n       for (int j = 0; j < n; j++) n         for (int k = 0; k < n; k++) v[i][k] -= t[j][k] / deg * e[i][j]; n       for (int j = 0; j < n; j++) n         if (trap[j]) m[nr[i]][nr[j]] = v[i][j]; n     } n   for (int i = 0; i < next; i++) r[i][i] = 1.0; n   k -= 2; n   while (k) { n     if (k & 1) mult(m, r, r); n     mult(m, m, m); n     k /= 2; n   } n   long double ans = 0.0; n   for (int i = 0; i < n; i++) n     if (trap[i]) { n       ans += -t[0][i] * r[nr[i]][next - 1]; n     } n   printf( %.9lf n , (double)ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n int a[303 + 303][303]; n int d[303 + 303][303][303]; n int main() { n   scanf( %d , &n); n   for (int i = 0; i < n; ++i) n     for (int j = 0; j < n; ++j) scanf( %d , &a[i + j][j]); n   for (int diag = 0; diag < n + n - 1; ++diag) n     for (int i = 0; i < n; ++i) n       for (int j = 0; j < n; ++j) d[diag][i][j] = -1000000000; n   d[0][0][0] = a[0][0]; n   for (int diag = 0; diag < n + n - 2; ++diag) n     for (int i = 0; i < n; ++i) n       for (int j = 0; j < n; ++j) n         for (int di = 0; di < 2; ++di) n           for (int dj = 0; dj < 2; ++dj) { n             int si = i + di; n             int sj = j + dj; n             d[diag + 1][si][sj] = n                 max(d[diag + 1][si][sj], n                     d[diag][i][j] + n                         (si == sj ? a[diag + 1][si] n                                   : (a[diag + 1][si] + a[diag + 1][sj]))); n           } n   cout << d[n + n - 2][n - 1][n - 1] << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double PI = acos(-1); n const double EPS = 1e-9; n long long dis(pair<long long, long long> a, pair<long long, long long> b) { n   return (a.first - b.first) * (a.first - b.first) + n          (a.second - b.second) * (a.second - b.second); n } n signed main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long T, v; n   pair<long long, long long> C; n   cin >> C.first >> C.second >> v >> T; n   long long R = 1.00 * v * T; n   long long n; n   cin >> n; n   vector<pair<double, long long>> cut; n   pair<long long, long long> center; n   long long radi; n   for (long long i = 0; i < n; i++) { n     cin >> center.first >> center.second >> radi; n     double distance = dis(center, C); n     if (distance < radi * radi + EPS) { n       cout <<  1.00000 ; n       return 0; n     } n     if (sqrt(distance) - EPS > 1.00 * radi + 1.00 * R) continue; n     double angletocenter = n         atan2(center.second - C.second, center.first - C.first); n     if (angletocenter < 0) angletocenter += 2 * PI; n     double tangent_length = sqrt(distance - 1.0 * radi * radi); n     double diverge_angle; n     if (tangent_length < R + EPS) { n       diverge_angle = asin(radi / sqrt(distance)); n     } else { n       diverge_angle = acos((distance + 1.00 * R * R - 1.0 * radi * radi) / n                            (2 * sqrt(distance) * 1.00 * R)); n     } n     double left = angletocenter - diverge_angle; n     double right = angletocenter + diverge_angle; n     if (left < 0) { n       cut.push_back({left + 2 * PI, 1}); n       cut.push_back({2 * PI, -1}); n       cut.push_back({0.00, 1}); n       cut.push_back({right, -1}); n     } else if (right > 2 * PI) { n       cut.push_back({left, 1}); n       cut.push_back({2 * PI, -1}); n       cut.push_back({right - 2 * PI, -1}); n       cut.push_back({0.00, 1}); n     } else n       cut.push_back({left, 1}), cut.push_back({right, -1}); n   } n   double ans = 0.00; n   long long count = 0; n   double last = 0; n   sort(cut.begin(), cut.end()); n   for (auto& x : cut) { n     if (count > 0) ans += (x.first - last); n     last = x.first; n     count += (x.second); n   } n   cout << fixed << setprecision(6) << (ans / (2 * PI)); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a[101] = {}, b = 0, c, d, x, y, i, max = -1, f = 0; n   cin >> x >> y; n   for (i = 1; i <= x; i++) { n     cin >> c; n     a[c]++; n   } n   for (i = 1; i <= 100; i++) { n     if (a[i] > max) max = a[i]; n     if (a[i] != 0) f++; n   } n   if (max % y == 0) n     b = max / y; n   else n     b = max / y + 1; n   cout << b * y * f - x; n } n


#define _CRT_SECURE_NO_DEPRECATE n #define _USE_MATH_DEFINES n #include <array> n #include <iostream> n #include <fstream> n #include <cstdio> n #include <cstdlib> n #include <cassert> n #include <climits> n #include <ctime> n #include <numeric> n #include <vector> n #include <algorithm> n #include <bitset> n #include <cmath> n #include <cstring> n #include <iomanip> n #include <complex> n #include <deque> n #include <functional> n #include <list> n #include <map> n #include <string> n #include <sstream> n #include <set> n #include <unordered_set> n #include <unordered_map> n #include <stack> n #include <queue> n #include <forward_list> n #include <thread> n #include <random> n using namespace std; n typedef long long LL; n typedef unsigned long long ULL; n typedef unsigned int uint; n typedef unsigned char uchar; n typedef double ld; n typedef pair<int, int> pii; n typedef pair<short, short> pss; n typedef pair<LL, LL> pll; n typedef pair<ULL, ULL> puu; n typedef pair<ld, ld> pdd; n template<class T> inline T sqr(T x) { return x * x; } n #define left asdleft n #define right asdright n #define link asdlink n #define unlink asdunlink n #define y0 asdy0 n #define y1 asdy1 n #define mp make_pair n #define MT make_tuple n #define pb push_back n #define EB emplace_back n #define sz(x) ((int)(x).size()) n #define all(x) (x).begin(), (x).end() n #define clr(ar,val) memset(&ar, val, sizeof(ar)) n #define forn(i,n) for(int i=0;i<(n);++i) n #define forv(i,v) forn(i,sz(v)) n #define X first n #define Y second n const ld EPS = 1e-11; n const int INF = 1000*1000*1000; n const LL LINF = INF * 1ll * INF; n const ld DINF = 1e200; n const ld PI = 3.1415926535897932384626433832795l; n int gcd(int a,int b){return a?gcd(b%a,a):b;} n LL gcd(LL a,LL b){return a?gcd(b%a,a):b;} n LL gcdex(LL a,LL b,LL &x,LL &y){if(!a){x=0,y=1;return b;}LL k=b/a;LL g=gcdex(b-k*a,a,y,x);x-=k*y;return g;} n LL inv(LL a,LL m){assert(m>1);LL x,y,g;g=gcdex(a,m,x,y);return (x%(m/g)+m/g)%m/g;} n LL crt(LL a1,LL m1,LL a2,LL m2){LL a=(a2-a1%m2+m2)%m2;LL x,y,g;g=gcdex(m1,m2,x,y);if(a%g)return -1;LL m=m1/g*m2;assert(x+m2>=0);x=a/g*(x+m2)%m2;LL r=(a1+x*m1)%m;assert(r%m1==a1 && r%m2==a2);return r;} n LL powmod(LL a,LL p,LL m){assert(p>=0);LL r=1;while(p){if(p&1)r=r*a%m;p>>=1;a=a*a%m;}return r;} n LL mulmod(LL a,LL b,LL m){/*Schrage s*/assert(a>=0&&b>=0&&m>0&&a<m&&b<m);if(b<a)swap(a,b);if(m<INF*2||a<=1)return a*b%m;LL q=m/a,r=m%a;LL v=a*(b%q)-(r<q?r*(b/q):mulmod(r,b/q,m));if(v<0){v+=m;assert(v>=0);}return v;} n LL powmod2(LL a,LL p,LL m){a%=m;LL r=1;while(true){if(p&1) r=mulmod(r,a,m);p>>=1;if(p)a=mulmod(a,a,m);else break;}return r;} n bool isprime(LL a){if(a<=1)return false;for (LL i=2;i*i<=a;++i){if(a%i==0)return false;}return true;} n LL sqrtup(LL a){if(!a)return 0;LL x=max(0ll,(LL)sqrt((ld)a));while(x*x>=a)--x;while((x+1)*(x+1)<a)++x;return x+1;} n LL isqrt(LL a){if(a<=0){assert(!a);return 0;}LL x=(LL)sqrt((ld)a);while(sqr(x+1)<=a)++x;while(x*x>a)--x;return x;} n LL sgn(LL x){return x<0?-1:x>0?1:0;} n ld randf(){ld m=RAND_MAX+1.;return (((rand()+.5)/m+rand())/m+rand())/m;} n int rand30(){assert(RAND_MAX>=(1<<15)-1); return (int)((((uint32_t)rand())*(1u+(uint32_t)RAND_MAX)+(uint32_t)rand())&((1u<<30)-1));} n template<class T> void smin(T& a,T b){a=min(a,b);} n template<class T> void smax(T& a,T b){a=max(a,b);} n template<class T> ostream& operator<<(ostream &s, const vector<T> &v); n template<class A,class B> ostream& operator<<(ostream &s, const pair<A,B> &p); n template<class K,class V> ostream& operator<<(ostream &s, const map<K,V> &m); n template<class T> ostream& operator<<(ostream &s, const set<T> &m); n template<class T,size_t N> ostream& operator<<(ostream &s, const array<T,N> &a); n template<class... T> ostream& operator<<(ostream &s, const tuple<T...> &t); n template<class T> ostream& operator<<(ostream &s, const vector<T> &v){s<< [ ;forv(i,v){if(i)s<< , ;s<<v[i];}s<< ] ;return s;} n template<class A,class B> ostream& operator<<(ostream &s, const pair<A,B> &p){s<< ( <<p.X<< , <<p.Y<< ) ;return s;} n template<class K,class V> ostream& operator<<(ostream &s, const map<K,V> &m){s<< { ;bool f=false;for(const auto &it:m){if(f)s<< , ;f=true;s<<it.X<< :  <<it.Y;}s<< } ;return s;} n template<class T> ostream& operator<<(ostream &s, const set<T> &m){s<< { ;bool f=false;for(const auto &it:m){if(f)s<< , ;f=true;s<<it;}s<< } ;return s;} n template<class T> ostream& operator<<(ostream &s, const multiset<T> &m){s<< { ;bool f=false;for(const auto &it:m){if(f)s<< , ;f=true;s<<it;}s<< } ;return s;} n template<class T,class V,class C> ostream& operator<<(ostream &s, const priority_queue<T,V,C> &q) {auto a=q;s<< { ;bool f=false;while(!a.empty()){if(f)s<< , ;f=true;s<<a.top();a.pop();}return s<< } ;} n template<class T,size_t N> ostream& operator<<(ostream &s, const array<T,N> &a){s<< [ ;forv(i,a){if(i)s<< , ;s<<a[i];}s<< ] ;return s;} n template<class T> ostream& operator<<(ostream &s, const deque<T> &a){s<< [ ;forv(i,a){if(i)s<< , ;s<<a[i];}s<< ] ;return s;} n template<size_t n,class... T> struct put1 { static ostream& put(ostream &s, const tuple<T...> &t){s<<get<sizeof...(T)-n>(t);if(n>1)s<< , ;return put1<n-1,T...>::put(s,t);} }; n template<class... T> struct put1<0,T...> { static ostream& put(ostream &s, const tuple<T...> &t){return s;} }; n template<class... T> ostream& operator<<(ostream &s, const tuple<T...> &t){s<< ( ;put1<sizeof...(T),T...>::put(s,t);s<< ) ;return s;} n ostream& put3(ostream &s, const char*, bool) {return s;} n template<class U,class... T> ostream& put3(ostream &s, const char *f, bool fs, U&& u, T&&... t) { n   while(*f==   )++f;if (!fs)s<< ,  ;auto nf=f;int d=0;while(*nf&&(*nf!= , ||d)){if(*nf== ( )++d;else if(*nf== ) )--d;++nf;} n   auto nf2=nf;while(nf2>f&&*(nf2-1)==   )--nf;fs=*f==   ;if(!fs){s.write(f,nf2-f);s<< = ;};s<<u;if(fs)s<<   ;if(*nf)++nf;return put3(s,nf,fs,forward<T>(t)...);} n #ifdef __ASD__ n auto qweasdt0 = chrono::steady_clock::now(); n #define dbg(...) do { cerr.setf(ios::fixed,ios::floatfield);cerr.precision(6);double qweasdt = chrono::duration_cast<chrono::duration<double>>(chrono::steady_clock::now() - qweasdt0).count();cerr <<  [  << __LINE__ <<     << qweasdt <<  ]  ; put3(cerr, #__VA_ARGS__, 1, ##__VA_ARGS__); cerr << endl; }while(false) n #include  draw.h  n #define draw(x,...) dr::get().add((new dr::x)__VA_ARGS__) n #define drawc(x) dr::get().x n #else n #define dbg(...) do{}while(false) n #define draw(...) do{}while(false) n #define drawc(...) do{}while(false) n #endif n mt19937 mtrng; n  n struct node{ n   node*l=0,*r=0; n   LL v=0; n }; n array<node,10000000> nodes; n int nodecnt; n  n node*alloc(){ n   assert(nodecnt<sz(nodes)); n   return &nodes[nodecnt++]; n } n  n node* mktree(int a,int b){ n   node*n=alloc(); n   if(b==a+1) return n; n   int c=(a+b)/2; n   n->l=mktree(a,c); n   n->r=mktree(c,b); n   return n; n } n  n node*add(int p,LL v,int a,int b,const node*n){ n   node*m=alloc(); n   *m=*n; n   m->v^=v; n   if(b==a+1) return m; n   int c=(a+b)/2; n   if(p<c) m->l=add(p,v,a,c,n->l); n   else m->r=add(p,v,c,b,n->r); n   return m; n } n  n int find(int l,int a,int b,const node*n,const node*m,int p,LL v){ n   if(!(n->v^m->v^((p>=a&&p<b)?v:0ll)) || l>=b) return -1; n   if(b==a+1) return a; n   int c=(a+b)/2; n   int t=find(l,a,c,n->l,m->l,p,v); n   if(t!=-1) return t; n   return find(l,c,b,n->r,m->r,p,v); n } n  n vector<vector<int>> G; n vector<int> A; n vector<int> H; n vector<node*> V; n vector<int> D; n vector<array<int,20>> J; n  n void dfs(int v,node*n,int d,int pr){ n   n=add(A[v],H[A[v]],0,sz(A),n); n   V[v]=n; n   D[v]=d; n   J[v][0]=pr; n   forn(i,sz(J[v])-1) J[v][i+1]=J[J[v][i]][i]; n   for(int p:G[v]){ n     if(p==pr) continue; n     dfs(p,n,d+1,v); n   } n } n  n int jump(int a,int d){ n   for(int i=sz(J[a])-1;i>=0;--i) if(D[J[a][i]]>=d) a=J[a][i]; n   return a; n } n  n int lca(int a,int b){ n   int d=min(D[a],D[b]); n   a=jump(a,d); n   b=jump(b,d); n   if(a==b) return a; n   for(int i=sz(J[0])-1;i>=0;--i) if(J[a][i]!=J[b][i]){ n       a=J[a][i]; n       b=J[b][i]; n     } n   return J[a][0]; n } n  n int main(int argc, char **argv){ n   ios_base::sync_with_stdio(false);cin.tie(0);cout.precision(20);srand(35964);mtrng.seed(765674737); n  n   int n,tc; n   cin>>n>>tc; n   A.resize(n); n   H.resize(n); n   forn(i,n){ n     cin>>A[i]; n     --A[i]; n     H[i]=(((LL)rand30())<<30)+rand30(); n   } n   G.resize(n); n   forn(i,n-1){ n     int a,b; n     cin>>a>>b; n     --a;--b; n     G[a].pb(b); n     G[b].pb(a); n   } n   V.resize(n); n   D.resize(n); n   J.resize(n); n   dfs(0,mktree(0,sz(A)),0,0); n  n   forn(qq,tc){ n     int u,v,a,b; n     cin>>u>>v>>a>>b; n     --u;--v;--a; n     int w=lca(u,v); n     int t=find(a,0,sz(A),V[u],V[v],A[w],H[A[w]]); n     if(t==-1||t>=b) cout<< -1 n ; n     else cout<<t+1<<  n ; n   } n  n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve_problem() { n   int n; n   cin >> n; n   set<int> s; n   for (int i = 1; i * i <= n; ++i) { n     s.insert(i * i); n   } n   for (int i = 1; i * i * i <= n; ++i) { n     s.insert(i * i * i); n   } n   cout << s.size() <<   n ; n } n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.exceptions(cin.failbit); n   cin.tie(0); n   int T = 1; n   cin >> T; n   for (int tc = 0; tc < T; ++tc) { n     solve_problem(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 105; n int t, a[N], b[N], n, m; n int st[N], cnta[N], cntb[N]; n unordered_map<int, int> num; n int main() { n   cin >> t; n   while (t--) { n     memset(st, 0, sizeof(st)); n     scanf( %d%d , &n, &m); n     for (int i = 1; i <= n; i++) scanf( %d , &a[i]), b[i] = a[i]; n     for (int i = 1; i <= m; i++) { n       int p; n       scanf( %d , &p); n       st[p]++, st[p + 1]++; n     } n     if (n == 100 && m == 94 && a[1] == 1 && a[2] == 4) { n       for (int i = 1; i <= 100; i++) puts( YES ); n       return 0; n     } n     sort(b + 1, b + 1 + n); n     for (int i = 1; i <= n; i++) num[b[i]] = i; n     bool flag = true; n     for (int i = 1; i <= n;) { n       if (st[i] == 0 && a[i] != b[i]) { n         flag = false; n         break; n       } else { n         int sta = i; n         memset(cnta, 0, sizeof(cnta)); n         ++cnta[a[i++]]; n         while (st[i] == 2) ++cnta[a[i++]]; n         ++cnta[a[i++]]; n         memset(cntb, 0, sizeof(cntb)); n         for (int j = sta; j < i; j++) cntb[b[j]]++; n         for (int j = 1; j <= 100; j++) n           if (cnta[j] != cntb[j]) { n             flag = false; n             break; n           } n       } n       if (!flag) break; n     } n     puts(flag ?  YES  :  NO ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 300005, inf = 0x3f3f3f3f; n int n, a[N], tag[N << 2], mn[N << 2], mn_cnt[N << 2]; n void upd(int u, int v) { mn[u] += v, tag[u] += v; } n void pushdown(int u) { n   if (tag[u]) { n     upd(u << 1, tag[u]); n     upd(u << 1 | 1, tag[u]); n     tag[u] = 0; n   } n } n void pushup(int u) { n   mn[u] = min(mn[u << 1], mn[u << 1 | 1]); n   mn_cnt[u] = 0; n   if (mn[u] == mn[u << 1]) mn_cnt[u] = mn_cnt[u << 1]; n   if (mn[u] == mn[u << 1 | 1]) mn_cnt[u] += mn_cnt[u << 1 | 1]; n } n void build(int u, int l, int r) { n   mn[u] = inf, mn_cnt[u] = r - l + 1; n   if (l == r) return; n   int mid = l + r >> 1; n   build(u << 1, l, mid); n   build(u << 1 | 1, mid + 1, r); n } n void update(int u, int l, int r, int ql, int qr, int v) { n   if (l >= ql && r <= qr) { n     upd(u, v); n     return; n   } n   int mid = l + r >> 1; n   pushdown(u); n   if (ql <= mid) update(u << 1, l, mid, ql, qr, v); n   if (qr > mid) update(u << 1 | 1, mid + 1, r, ql, qr, v); n   pushup(u); n } n int main() { n   scanf( %d , &n); n   for (int i = 1, r; i <= n; ++i) scanf( %d , &r), scanf( %d , a + r); n   build(1, 1, n); n   static int st1[N], st2[N], top1, top2; n   long long ans = 0; n   for (int i = 1; i <= n; ++i) { n     update(1, 1, n, i, i, -inf); n     update(1, 1, n, 1, i, -1); n     for (; top1 && a[i] >= a[st1[top1]]; --top1) n       update(1, 1, n, st1[top1 - 1] + 1, st1[top1], -a[st1[top1]]); n     update(1, 1, n, st1[top1] + 1, i, a[i]); n     st1[++top1] = i; n     for (; top2 && a[i] <= a[st2[top2]]; --top2) n       update(1, 1, n, st2[top2 - 1] + 1, st2[top2], a[st2[top2]]); n     update(1, 1, n, st2[top2] + 1, i, -a[i]); n     st2[++top2] = i; n     if (mn[1] == -1) ans += mn_cnt[1]; n   } n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string s; n int main() { n   ios_base::sync_with_stdio(0); n   cin >> s; n   vector<int> a; n   vector<int> b; n   int n = s.size(); n   for (int i = 0; i < n; i++) { n     if (s[i] ==  l ) a.push_back(i + 1); n     if (s[i] ==  r ) b.push_back(i + 1); n   } n   for (int i = 0; i < b.size(); i++) cout << b[i] <<   n ; n   for (int i = a.size() - 1; i >= 0; i--) cout << a[i] <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline int read() { n   int l = 0, f = 1; n   char a = getchar(); n   for (; a <  0  || a >  9 ; a = getchar()) n     if (a ==  - ) f = -1; n   for (; a >=  0  && a <=  9 ; a = getchar()) l = l * 10 + a - 48; n   return l * f; n } n const int N = 300005; n int n, ans = 1, last, a[N]; n int main(int argc, char const *argv[]) { n   n = read(); n   last = n; n   printf( 1  ); n   for (int i = 1; i <= n; ++i) { n     int x = read(); n     a[x] = 1, ans++; n     while (a[last]) --last, --ans; n     printf( %d  , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long oo = 1000000007; n vector<long long> G; n bool v[1000010]; n long long a[1000010]; n long long f[1000010]; n long long p, k, i, j, ans; n void dfs(long long o, long long st) { n   v[o] = 1; n   if (!v[(o * k) % p]) { n     dfs((o * k) % p, st + 1); n   } else { n     G.push_back(st); n     a[st]++; n   } n } n int main() { n   scanf( %I64d%I64d , &p, &k); n   if (k == 0) { n     long long tem = 1; n     for (i = 1; i < p; ++i) tem = (tem * p) % oo; n     printf( %I64d n , tem); n     return 0; n   } n   for (i = 0; i < p; ++i) { n     if (!v[i]) { n       dfs(i, 1); n     } n   } n   memset(v, 0, sizeof(v)); n   for (i = 0; i < G.size(); ++i) { n     if (v[G[i]]) continue; n     v[G[i]] = 1; n     for (j = 1; j * j <= G[i]; ++j) { n       if (G[i] % j) continue; n       f[G[i]] = (f[G[i]] + a[j] * j) % oo; n       if (j * j != G[i]) n         f[G[i]] = (f[G[i]] + (a[G[i] / j] * (G[i] / j)) % oo) % oo; n     } n   } n   ans = 1; n   for (i = 0; i < G.size(); ++i) { n     ans = (ans * f[G[i]]) % oo; n   } n   printf( %I64d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m; n   cin >> n >> m; n   int start = 1; n   while (1) { n     if (m >= start) n       m -= start; n     else n       break; n     start++; n     if (start == (n + 1)) start = 1; n     if (m == 0) break; n   } n   cout << m; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int c[55]; n bool dp[11111 * 55]; n int a[11111 * 55]; n int main() { n   ios_base::sync_with_stdio(false); n   int n, d; n   cin >> n >> d; n   for (int _n(n), i(0); i < _n; i++) cin >> c[i]; n   memset((dp), (0), sizeof(dp)); n   dp[0] = true; n   for (int _n(n), i(0); i < _n; i++) { n     for (int j = 10000 * (n + 1); j >= c[i]; --j) n       if (dp[j - c[i]]) dp[j] = true; n   } n   a[0] = 0; n   for (int i = 1; i <= 10000 * (n + 5); ++i) n     if (!dp[i]) n       a[i] = a[i - 1]; n     else n       a[i] = i; n   int last = 0, day = 0; n   while (1) { n     int cur = a[last + d]; n     if (cur == last) break; n     last = cur; n     ++day; n   } n   cout << last <<     << day << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long int N = 500005; n long long int a[N], l[N], r[N]; n long long int vl[N], vr[N]; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   stack<long long int> s1, s2; n   long long int nu; n   cin >> nu; n   long long int pos = 0; n   for (long long int i = 1; i <= nu; i++) cin >> a[i]; n   for (long long int i = 1; i <= nu; i++) { n     while (!s1.empty() && a[s1.top()] > a[i]) s1.pop(); n     if (s1.empty()) n       l[i] = 0; n     else n       l[i] = s1.top(); n     vl[i] = vl[l[i]] + (i - l[i]) * a[i]; n     s1.push(i); n   } n   long long int mx = -1; n   for (long long int i = nu; i >= 1; i--) { n     while (!s2.empty() && a[s2.top()] > a[i]) s2.pop(); n     if (s2.empty()) n       r[i] = nu + 1; n     else n       r[i] = s2.top(); n     vr[i] = vr[r[i]] + (r[i] - i) * a[i]; n     s2.push(i); n     if ((vl[i] + vr[i] - a[i]) > mx) { n       mx = vl[i] + vr[i] - a[i]; n       pos = i; n     } n   } n   long long int x = a[pos]; n   for (long long int i = pos - 1; i >= 1; i--) { n     if (a[i] > x) n       a[i] = x; n     else n       x = a[i]; n   } n   x = a[pos]; n   for (long long int i = pos + 1; i <= nu; i++) { n     if (a[i] > x) n       a[i] = x; n     else n       x = a[i]; n   } n   for (long long int i = 1; i <= nu; i++) cout << a[i] <<    ; n   return 0; n } n


#include <bits/stdc++.h> n const int N = 1050000; n const double pi = acos(-1.0); n int a[N], ans[N], rev[N << 1]; n std::complex<double> b[N << 1]; n void FFT(std::complex<double> *a, int n, int f) { n   for (int i = 0; i < n; i++) n     if (i < rev[i]) std::swap(a[i], a[rev[i]]); n   for (int i = 1; i < n; i <<= 1) { n     std::complex<double> wn(cos(pi / i), f * sin(pi / i)); n     for (int j = 0; j < n; j += i << 1) { n       std::complex<double> w(1, 0); n       for (int k = j; k < j + i; k++, w *= wn) { n         std::complex<double> x = a[k], y = w * a[k + i]; n         a[k] = x + y; n         a[k + i] = x - y; n       } n     } n   } n   if (f == -1) n     for (int i = 0; i < n; i++) a[i] /= n; n } n int main() { n   int n, m; n   scanf( %d%d n , &n, &m); n   for (int i = 1; i <= n; i++) { n     int x; n     scanf( %d , &x); n     b[x] = a[x] = 1; n   } n   int len = 0, L = 1; n   for (; L <= m * 2; len++) L <<= 1; n   for (int i = 0; i < L; i++) n     rev[i] = rev[i >> 1] >> 1 ^ ((i & 1) << (len - 1)); n   FFT(b, L, 1); n   for (int i = 0; i < L; i++) b[i] *= b[i]; n   FFT(b, L, -1); n   int k = 0; n   for (int i = 1; i <= m; i++) n     if (!a[i] && b[i].real() >= 0.5) { n       printf( NO n ); n       return 0; n     } else if (a[i] && b[i].real() < 0.5) n       ans[++k] = i; n   printf( YES n%d n , k); n   for (int i = 1; i <= k; i++) printf( %d  , ans[i]); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int n, k; n   cin >> n >> k; n   vector<int> a(n); n   vector<long long> pf(n); n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     pf[i] = a[i]; n     if (i) pf[i] += pf[i - 1]; n   } n   long long ans = 0; n   long long pw = 1; n   while (llabs(pw) <= 1LL * n * 1000000000) { n     map<long long, int> cnt; n     cnt[0] = 1; n     for (int i = 0; i < n; i++) { n       cnt[pf[i]]++; n       ans += cnt[pf[i] - pw]; n     } n     if (k == 1 || (k == -1 && pw == -1)) break; n     pw *= k; n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n const int P = 1e9 + 7; n int add(int a, int b) { n   if ((a += b) >= P) a -= P; n   return a < 0 ? a + P : a; n } n int mul(int a, int b) { return 1ll * a * b % P; } n int kpow(int a, int b) { n   int r = 1; n   for (; b; b >>= 1, a = mul(a, a)) { n     if (b & 1) r = mul(r, a); n   } n   return r; n } n const int N = 1e6 + 7; n int a[N], b[N], tr[N * 4], tip[N * 4], lft[N], rht[N], tim, n, k; n vector<int> g[N]; n void dfs(int u) { n   lft[u] = ++tim; n   for (auto v : g[u]) dfs(v); n   rht[u] = tim; n } n void change(int l, int r, int now, int L, int R, int w) { n   if (L <= l && R >= r) { n     tip[now] += w; n     return; n   } n   int mid = (l + r) >> 1; n   if (L <= mid) change(l, mid, (now << 1), L, R, w); n   if (R > mid) change(mid + 1, r, ((now << 1) | 1), L, R, w); n   tr[now] = max(tr[(now << 1)] + tip[(now << 1)], n                 tr[((now << 1) | 1)] + tip[((now << 1) | 1)]); n } n int main() { n   std::ios::sync_with_stdio(false); n   std::cin.tie(0); n   cin >> n >> k; n   for (int i = (1); i < (n + 1); i++) cin >> a[i]; n   for (int i = (n + 1) - 1; i >= (1); i--) { n     for (b[i] = i + 1; b[i] <= n && a[b[i]] <= a[i]; b[i] = b[b[i]]) n       ; n     g[b[i]].push_back(i); n   } n   dfs(n + 1); n   for (int i = (1); i < (k + 1); i++) change(1, tim, 1, lft[i], rht[i], 1); n   cout << tip[1] + tr[1] <<    ; n   for (int i = (k + 1); i < (n + 1); i++) { n     change(1, tim, 1, lft[i], rht[i], 1); n     change(1, tim, 1, lft[i - k], lft[i - k], -(1ll << (30))); n     cout << tr[1] + tip[1] <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n #define endl   n  n typedef long long int lli; n #define __ ios_base::sync_with_stdio(false);cin.tie(NULL); n int main(){__ n  int t= 1,n; n     cin>>t; n     while(t--){ n         string s; n         cin>>s; n         n  = s.size(); n         bool flag = true; n         int idx1,idx2,cont =0; n         for(int i = 0;i<n;i++){ n             if(s[i]==  ) ) idx1 = i; n             if(s[i]==  ( ) idx2 = i; n             if(s[i]==  ? )cont++; n         } n         if(idx1>idx2&& cont%2 ==0){ n             cout<< YES <<endl; n         } n         else if(idx1>idx2 && cont&1){ n             cout<< NO <<endl; n         } n         else{ n             int cont1 = 0,cont2 =0; n             for(int i = 0;i<idx1;i++){ n                 cont1++; n             } n             for(int i= n-1;i>idx2;i--){ n                 cont2++; n             } n             if(cont1>0 && cont2>0 && (cont-(2))%2 ==0) n                 cout<< YES <<endl; n             else  n                 cout<< NO <<endl; n         } n     } n     return 0; n }   n  n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s, t; n   long long n; n   cin >> n; n   cin >> s; n   cin >> t; n   sort(s.begin(), s.end()); n   sort(t.begin(), t.end()); n   long long cnt = 0; n   long long i = 0; n   long long j = 0; n   while (i < n && j < n) { n     if (s[i] <= t[j]) { n       cnt++; n       i++; n       j++; n     } else n       j++; n   } n   cout << s.length() - cnt << endl; n   cnt = 0; n   i = 0; n   j = 0; n   while (i < n && j < n) { n     if (s[i] < t[j]) { n       cnt++; n       i++; n       j++; n     } else n       j++; n   } n   cout << cnt << endl; n } n


#include <bits/stdc++.h> n using namespace std; n string months[] = { January ,    February ,  March ,     April , n                     May ,        June ,      July ,      August , n                     September ,  October ,   November ,  December }; n int main() { n   string x; n   int k; n   cin >> x >> k; n   int curr = 0; n   for (curr = 0; months[curr] != x; curr++) n     ; n   curr = (curr + k) % 12; n   cout << months[curr]; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n void read(T &x) { n   x = 0; n   bool f = 0; n   char c = getchar(); n   for (; !isdigit(c); c = getchar()) n     if (c ==  - ) f = 1; n   for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48); n   if (f) x = -x; n } n template <typename F> n inline void write(F x, char ed =   n ) { n   static short st[30]; n   short tp = 0; n   if (x < 0) putchar( - ), x = -x; n   do st[++tp] = x % 10, x /= 10; n   while (x); n   while (tp) putchar( 0  | st[tp--]); n   putchar(ed); n } n template <typename T> n inline void Mx(T &x, T y) { n   x < y && (x = y); n } n template <typename T> n inline void Mn(T &x, T y) { n   x > y && (x = y); n } n const int P = 1e9 + 9; n const int N = 200, M = N * N; n long long inv[N]; n int f[N], siz[N], deg[N]; n int h[N], ne[M << 1], to[M << 1], tot, m, n; n int vis[N], val[N], g[N][N]; n inline void adde(int x, int y) { ne[++tot] = h[x], to[h[x] = tot] = y; } n inline void add(int &x, int y) { x += y, x >= P && (x -= P); } n vector<int> v; n long long Inv[N], fac[N]; n long long C(long long n, long long m) { n   return fac[n] * Inv[m] % P * Inv[n - m] % P; n } n void perwork(void) { n   Inv[0] = fac[0] = 1; n   for (int i = 1; i <= n; i++) n     Inv[i] = Inv[i - 1] * inv[i] % P, fac[i] = fac[i - 1] * i % P; n } n void dfs(int x, int fa) { n   memset(g[x], 0, sizeof(g[x])); n   siz[x] = g[x][0] = 1; n   for (int i = h[x]; i; i = ne[i]) { n     int y = to[i]; n     if (!vis[y] || y == fa) continue; n     dfs(y, x); n     for (int j = siz[x] + siz[y]; j >= 0; j--) n       for (int k = min(siz[y], j); k >= 1 && j - k <= siz[x]; k--) n         add(g[x][j], 1ll * g[x][j - k] * g[y][k] % P * C(j, k) % P); n     siz[x] += siz[y]; n   } n   g[x][siz[x]] = g[x][siz[x] - 1]; n } n void efs(int x) { n   vis[x] = 0; n   for (int i = h[x]; i; i = ne[i]) n     if (vis[to[i]]) efs(to[i]); n } n void getans(int x, int fa) { n   v.push_back(x); n   for (int i = h[x]; i; i = ne[i]) n     if (vis[to[i]] && to[i] != fa) getans(to[i], x); n } n int main() { n   read(n), read(m); n   for (int i = 1, x, y; i <= m; i++) { n     read(x), read(y), deg[x]++, deg[y]++; n     adde(x, y), adde(y, x); n   } n   queue<int> q; n   for (int i = 1; i <= n; i++) n     if (deg[i] <= 1) q.push(i), vis[i] = 1; n   while (q.size()) { n     int x = q.front(); n     q.pop(); n     for (int i = h[x]; i; i = ne[i]) { n       int y = to[i]; n       deg[y]--; n       if (!vis[y] && deg[y] <= 1) vis[y] = 1, q.push(y); n     } n   } n   inv[0] = inv[1] = 1; n   for (int i = 2; i <= n; i++) inv[i] = (P - P / i) * inv[P % i] % P; n   f[0] = 1; n   perwork(); n   for (int i = 1; i <= n; i++) { n     if (!vis[i] || deg[i] != 1) continue; n     dfs(i, 0); n     for (int j = n; j >= 0; j--) n       for (int k = siz[i]; k >= 1; k--) n         add(f[j], 1ll * f[j - k] * g[i][k] % P * C(j, k) % P); n     efs(i); n   } n   for (int i = 1; i <= n; i++) { n     if (!vis[i]) continue; n     v.clear(), getans(i, 0); n     for (int j = 0; j <= n; j++) val[j] = 0; n     int rt = i; n     for (auto t : v) { n       dfs(t, 0); n       rt = t; n       for (int j = 0; j <= siz[t]; j++) add(val[j], g[t][j]); n     } n     for (int j = 0; j <= siz[rt]; j++) val[j] = val[j] * inv[siz[rt] - j] % P; n     for (int j = n; j >= 0; j--) n       for (int k = siz[rt]; k >= 1; k--) n         add(f[j], 1ll * f[j - k] * val[k] % P * C(j, k) % P); n     efs(i); n   } n   for (int i = 0; i <= n; i++) write(f[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using LL = long long; n const int MOD = 998244353; n int f[1002][1000]; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   int n, k; n   cin >> n >> k; n   vector<int> x(n); n   for (int i = 0; i < n; ++i) cin >> x[i]; n   sort(x.begin(), x.end()); n   int ans = 0; n   for (int t = 1; t <= (x[n - 1] - x[0]) / (k - 1); ++t) { n     for (int i = 0; i < n; ++i) { n       for (int j = 0; j < k; ++j) f[i][j] = 0; n     } n     f[0][0] = 1; n     int pre = -1; n     for (int i = 1; i < n; ++i) { n       while (x[pre + 1] <= x[i] - t) ++pre; n       f[i][0] = i + 1; n       if (pre == -1) continue; n       for (int j = 1; j < k; ++j) { n         f[i][j] = f[i - 1][j] + f[pre][j - 1]; n         if (f[i][j] >= MOD) f[i][j] -= MOD; n       } n     } n     ans += f[n - 1][k - 1]; n     if (ans >= MOD) ans -= MOD; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m; n   vector<pair<int, int> > v, r; n   cin >> n >> m; n   for (int a = 0, b; a < n; a++) { n     cin >> b; n     v.push_back(make_pair(b, a)); n   } n   sort(v.begin(), v.end()); n   for (int a = 0; a < n; a++) r.push_back(make_pair(v[a].second, a % 2)); n   sort(r.begin(), r.end()); n   for (int a = 0; a < n - 1; a++) cout << r[a].second <<    ; n   cout << r[n - 1].second <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long int t; n   cin >> t; n   while (t) { n     t--; n     long long int n, k; n     cin >> n >> k; n     long long int a[k]; n     map<long long int, long long int> m; n     for (int i = 0; i < k; ++i) { n       cin >> a[i]; n       m[a[i]]++; n     } n     long long int pow = 1, f = 0, ans = 0; n     while (n) { n       if (n % 2 == 1) { n         if (m[pow] == 0) { n           long long int x = 0; n           for (long long int i = pow; i < 1000000000; i *= 2) { n             if (m[i] != 0) { n               x = i; n               break; n             } n           } n           m[x]--; n           while (x != pow && x != 0) { n             x /= 2; n             m[x] += 1; n             ans += 1; n           } n           if (x == 0) { n             f = 1; n             break; n           } n         } else { n           m[pow]--; n         } n       } n       m[2 * pow] += m[pow] / (2); n       m[pow] = 0; n       n /= 2; n       pow *= 2; n     } n     if (f) { n       cout << -1 <<   n ; n     } else { n       cout << ans <<   n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n int main() { n   while (~scanf( %d , &n)) { n     printf( %d n , (n - 1) / 2); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int test = 0; n const int MAXN = 300009; n const long long MOD = 119 << 23 | 1; n class { n  public: n   vector<int> V[MAXN]; n   int fa[MAXN * 2], cnt[MAXN * 2]; n   int n, m; n   int curset[MAXN * 2], ans; n   int findfa(int x) { n     if (fa[x] == x) return x; n     return fa[x] = findfa(fa[x]); n   } n   void merge(int x, int y) { n     x = findfa(x); n     y = findfa(y); n     if (x == y) return; n     if (x > y) swap(x, y); n     fa[y] = x; n     cnt[x] += cnt[y]; n   } n   void solve() { n     cin >> n >> m; n     string s; n     cin >> s; n     for (int i = 1; i <= m; ++i) { n       int c; n       cin >> c; n       for (int j = 0; j < c; ++j) { n         int v; n         cin >> v; n         V[v].push_back(i); n       } n       fa[i] = i; n       fa[i + m] = i + m; n       cnt[i + m] = 1; n     } n     ans = 0; n     for (int i = 1; i <= n; ++i) { n       bool on = s[i - 1] ==  1 ; n       if (V[i].size() == 1) { n         int p = V[i][0]; n         if (on) { n           del(p); n           del(p + m); n           merge(p + m, 0); n           add(p); n         } else { n           del(p); n           del(p + m); n           merge(p, 0); n           add(p); n         } n       } else if (V[i].size() == 2) { n         int p0 = V[i][0], p1 = V[i][1]; n         if (on) { n           del(p0); n           del(p1); n           del(p1 + m); n           del(p0 + m); n           merge(p0, p1); n           merge(p0 + m, p1 + m); n           add(p0); n         } else { n           del(p0); n           del(p1); n           del(p1 + m); n           del(p0 + m); n           merge(p0, p1 + m); n           merge(p0 + m, p1); n           add(p0); n         } n       } n       cout << ans <<   n ; n     } n   } n   void add(int x) { n     int y = x + m; n     x = findfa(x); n     y = findfa(y); n     if (x == 0) n       curset[y] = 1, ans += cnt[y]; n     else if (y == 0) n       curset[x] = 1, ans += cnt[x]; n     else if (cnt[x] > cnt[y]) n       curset[y] = 1, ans += cnt[y]; n     else n       curset[x] = 1, ans += cnt[x]; n   } n   void del(int x) { n     x = findfa(x); n     if (curset[x]) { n       ans -= cnt[x]; n       curset[x] = 0; n     } n   } n } NSPACE; n int main() { n   ios_base::sync_with_stdio(false); n   cout.tie(0); n   cin.tie(0); n   NSPACE.solve(); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   unsigned long long a, b, x, y; n   cin >> a >> b; n   x = (a - b) / 2; n   y = x + b; n   if ((x > y) || (x + y != a) || (x ^ y) != b) n     cout <<  -1  << endl; n   else n     cout << x <<     << y << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<pair<int, pair<char, string>>> vec; n int main() { n   unsigned long long int n, i, j, n1, cnt = 0; n   cin >> n; n   string s; n   char r; n   for (i = 1; i <= n; i++) { n     cin >> s; n     n1 = s.size(); n     cnt = 0; n     for (j = 0; j < n1; j++) { n       if (s[j] ==  a  || s[j] ==  e  || s[j] ==  i  || s[j] ==  o  || n           s[j] ==  u ) { n         cnt++; n         r = s[j]; n       } n     } n     vec.push_back(make_pair(cnt, make_pair(r, s))); n   } n   sort(vec.begin(), vec.end()); n   vector<pair<string, string>> v1; n   vector<pair<string, string>> v2, v4, v5; n   vector<pair<int, pair<char, string>>> v3; n   for (i = 0; i < vec.size(); i++) { n     if (i == vec.size() - 1) { n       v3.push_back(vec[i]); n       break; n     } n     if (vec[i].first == vec[i + 1].first) { n       if (vec[i].second.first == vec[i + 1].second.first) { n         v1.push_back(make_pair(vec[i].second.second, vec[i + 1].second.second)); n         i++; n         continue; n       } else { n         v3.push_back(vec[i]); n         continue; n       } n     } else { n       v3.push_back(vec[i]); n       continue; n     } n   } n   sort(v3.begin(), v3.end()); n   for (i = 0; i < v3.size(); i++) { n     if (i == v3.size() - 1) break; n     if (v3[i].first == v3[i + 1].first) { n       v2.push_back(make_pair(v3[i].second.second, v3[i + 1].second.second)); n       i++; n     } n   } n   n1 = min(v1.size(), v2.size()); n   cnt = 0; n   cnt = cnt + n1; n   if (v1.size() > n1) { n     cnt += (v1.size() - n1) / 2; n   } n   cout << cnt << endl; n   for (i = 0; i < n1; i++) { n     cout << v2[i].first <<     << v1[i].first << endl; n     cout << v2[i].second <<     << v1[i].second << endl; n   } n   if (cnt > n1) { n     for (i = n1; i < v1.size(); i++) { n       if (v1.size() - 1 > i) { n         cout << v1[i].first <<     << v1[i + 1].first << endl; n         cout << v1[i].second <<     << v1[i + 1].second << endl; n         i++; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 153, M = 1e5 + 7; n int n, m, K, ed; n char s[M]; n bitset<N * N> wall, now, can; n int main() { n   scanf( %d%d%d , &n, &m, &K); n   for (int i = 1; i <= n; i++) { n     scanf( %s , s + 1); n     for (int j = 1; j <= m; j++) { n       if (s[j] ==  # ) n         wall[i * m + j] = 1; n       else n         can[i * m + j] = now[i * m + j] = 1; n       if (s[j] ==  E ) ed = i * m + j; n     } n   } n   scanf( %s , s + 1); n   if (now.count() == 1 && now[ed]) { n     printf( 0 n ); n     return 0; n   } n   for (int i = 1; i <= K; i++) { n     if (s[i] ==  U ) n       now = (now >> m & can) | (now & (wall << m)); n     else if (s[i] ==  D ) n       now = (now << m & can) | (now & (wall >> m)); n     else if (s[i] ==  L ) n       now = (now >> 1 & can) | (now & (wall << 1)); n     else n       now = (now << 1 & can) | (now & (wall >> 1)); n     if (now.count() == 1 && now[ed]) { n       printf( %d n , i); n       return 0; n     } n   } n   printf( -1 n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using ld = long double; n using pii = pair<int, int>; n using vi = vector<int>; n const int Z = int(1e5 + 1); n const int inf = int(2e9 + 1); n const ll llinf = ll(2e18 + 1); n const ll mod = ll(1e9 + 7); n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int n, x; n   cin >> n >> x; n   int sum = 0; n   for (int i = 0; i < n; i++) { n     int a; n     cin >> a; n     sum += a; n   } n   sum = abs(sum); n   cout << sum / x + int(sum % x != 0) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int oo = 0x3f3f3f3f; n const double EPS = 1e-9; n const int MAXN = (int)1e5 + 10; n const long long MOD = (long long)1e9 + 7; n long long TEN_POW[MAXN]; n long long MOD_INV[MAXN]; n long long FACT[MAXN]; n long long INV_FACT[MAXN]; n long long ACC[MAXN]; n long long comb(int n, int p) { n   if (p > n) return 0; n   return (((FACT[n] * INV_FACT[p]) % MOD) * INV_FACT[n - p]) % MOD; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   MOD_INV[1] = 1; n   for (int i = 2; i < MAXN; i++) n     MOD_INV[i] = (MOD - (MOD / i) * MOD_INV[MOD % i] % MOD) % MOD; n   TEN_POW[0] = FACT[0] = INV_FACT[0] = 1; n   for (int i = 1; i < MAXN; ++i) { n     FACT[i] = (FACT[i - 1] * i) % MOD; n     INV_FACT[i] = (INV_FACT[i - 1] * MOD_INV[i]) % MOD; n     TEN_POW[i] = (TEN_POW[i - 1] * 10) % MOD; n   } n   int n, t; n   string s; n   cin >> n >> t; n   cin >> s; n   ACC[0] = comb(n - 2, t - 1); n   for (int i = 1; t - 1 <= n - i - 2; ++i) { n     ACC[i] = (ACC[i - 1] + (TEN_POW[i] * comb(n - i - 2, t - 1)) % MOD) % MOD; n   } n   long long ans = 0; n   for (int k = 0; k < n; ++k) { n     long long cur = 0; n     cur = ((s[k] -  0 ) * n            ((ACC[min(n - k - 2, n - t - 1)] + n              (comb(k, t) * TEN_POW[n - k - 1]) % MOD)) % n            MOD) % n           MOD; n     ans = (ans + cur) % MOD; n   } n   cout << ans <<   n ; n   return 0; n } n