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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


#include <bits/stdc++.h>   const int inf = 0x3f3f3f3f, Inf = 0x7fffffff;   const long long INF = 0x7fffffffffffffff;   const double eps = 1e-10;   unsigned int seed = 19260817;   const unsigned int _RAND_MAX_ = 4294967295u;   __inline__ __attribute__((always_inline)) unsigned int Rand() {     return seed = seed * 998244353u + 1000000007u;   }   template <typename _Tp>   _Tp gcd(const _Tp &a, const _Tp &b) {     return (!b) ? a : gcd(b, a % b);   }   template <typename _Tp>   __inline__ __attribute__((always_inline)) _Tp abs(const _Tp &a) {     return a > 0 ? a : -a;   }   template <typename _Tp>   __inline__ __attribute__((always_inline)) _Tp max(const _Tp &a, const _Tp &b) {     return a < b ? b : a;   }   template <typename _Tp>   __inline__ __attribute__((always_inline)) _Tp min(const _Tp &a, const _Tp &b) {     return a < b ? a : b;   }   template <typename _Tp>   __inline__ __attribute__((always_inline)) void chmax(_Tp &a, const _Tp &b) {     (a < b) && (a = b);   }   template <typename _Tp>   __inline__ __attribute__((always_inline)) void chmin(_Tp &a, const _Tp &b) {     (a > b) && (a = b);   }   template <typename _Tp>   __inline__ __attribute__((always_inline)) bool _cmp(const _Tp &a,                                                       const _Tp &b) {     return abs(a - b) <= eps;   }   template <typename _Tp>   __inline__ __attribute__((always_inline)) void read(_Tp &x) {     register char ch(getchar());     bool f(false);     while (ch < 48 || ch > 57) f |= ch == 45, ch = getchar();     x = ch & 15, ch = getchar();     while (ch >= 48 && ch <= 57)       x = (((x << 2) + x) << 1) + (ch & 15), ch = getchar();     if (f) x = -x;   }   template <typename _Tp, typename... Args>   __inline__ __attribute__((always_inline)) void read(_Tp &t, Args &...args) {     read(t);     read(args...);   }   __inline__ __attribute__((always_inline)) int read_str(char *s) {     register char ch(getchar());     while (ch ==     || ch ==   r  || ch ==   n ) ch = getchar();     register char *tar = s;     *tar = ch, ch = getchar();     while (ch !=     && ch !=   r  && ch !=   n  && ch != EOF)       *(++tar) = ch, ch = getchar();     return tar - s + 1;   }   const int N = 100005;   int main() {     long long n, p;     read(n, p);     if (p >= n) {       printf( -1 n );       return 0;     }     long long cnt = 0;     while (true) {       long long now = n - cnt * p;       if (now <= 0) break;       long long num = 0, maxx = 0;       for (long long i = 0; i <= 32; ++i) {         if (now & (1ll << i)) {           ++num;           maxx += i + 1;         }       }       if (num <= cnt && maxx >= cnt) {         printf( %lld n , cnt);         return 0;       }       ++cnt;     }     printf( -1 n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2050;   const int inf = 0x3f3f3f3f;   const int mod = 998244353;   long long fpow(long long x, long long y) {     long long ans = 1;     while (y) {       if (y & 1) ans = ans * x % mod;       x = x * x % mod;       y >>= 1;     }     return ans;   }   long long dp[maxn][maxn], a[maxn];   char s[maxn];   int main() {     int i, j, k, m, n;     scanf( %s , s + 1);     n = strlen(s + 1);     for (i = 1; i <= n; i++) a[i] = a[i - 1] + (s[i] ==  ? );     for (k = 2; k <= n; k++)       for (i = 1; i + k - 1 <= n; i++) {         j = i + k - 1;         dp[i][j] = (dp[i][j] + (s[i] !=  (  ? dp[i + 1][j] : 0)) % mod;         dp[i][j] = (dp[i][j] + (s[j] !=  )  ? dp[i][j - 1] : 0)) % mod;         dp[i][j] = (dp[i][j] + mod -                     (s[i] !=  (  && s[j] !=  )  ? dp[i + 1][j - 1] : 0)) %                    mod;         dp[i][j] =             (dp[i][j] + (s[i] !=  )  && s[j] !=  (                               ? (dp[i + 1][j - 1] + fpow(2, a[j - 1] - a[i])) % mod                              : 0)) %             mod;       }     cout << dp[1][n] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10;   long long a[N], b[1050], c[N];   int cnt = 0;   void init() {     cnt = 0;     for (int i = 1; i < N - 50; i++) a[cnt++] = i * i;     cnt = 0;     for (int i = 1; i < 1010; i++) b[cnt++] = i * i * i;     int u = 0, t = 0;     cnt = 0;     while (a[u] && b[t]) {       if (a[u] < b[t]) {         c[cnt++] = a[u++];       } else if (a[u] == b[t]) {         c[cnt++] = a[u++];         t++;       } else         c[cnt++] = b[t++];     }   }   int main() {     init();     int T;     cin >> T;     while (T--) {       int n;       scanf( %d , &n);       int i = 0;       while (c[i] <= n) {         i++;       }       printf( %d n , i);     }     return 0;   }