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

 char Str[1000005];
 vector<int> SegTree[2000011];

 void Build_Segment_Tree( int Node , int low , int high ){
     if( low == high ){
         if( Str[low] == '(' )
          SegTree[Node][1] = 1;
         else
          SegTree[Node][2] = 1;
    }
     else{
      int Min , middle = ( low + high ) / 2;
      Build_Segment_Tree( 2 * Node , low , middle );
      Build_Segment_Tree( 2 * Node + 1 , middle + 1 , high );
      Min = min( SegTree[2 * Node][1] , SegTree[2 * Node + 1][2] );
      SegTree[Node][0] = SegTree[2 * Node][0] + SegTree[2 * Node + 1][0] + Min * 2;
      SegTree[Node][1] = SegTree[2 * Node + 1][1] + SegTree[2 * Node][1] - Min;
      SegTree[Node][2] = SegTree[2 * Node + 1][2] + SegTree[2 * Node][2] - Min;
    }
}

 vector<int> query( int Node , int low , int high , int l , int r ){
     if( r < low || l > high )
      return vector<int>(3,0);
     else if( l <= low && r >= high )
      return SegTree[Node];
    else{
      int middle , Min;
      vector<int> v1 , v2 , v3(3,0);
      middle = ( low + high ) / 2;
      v1 = query( 2 * Node , low , middle , l , r );
      v2 = query( 2 * Node + 1 , middle + 1 , high , l , r );
      Min = min( v1[1] , v2[2] );
      v3[0] = v1[0] + v2[0] + 2 * Min;
      v3[1] = v1[1] + v2[1] - Min;
      v3[2] = v1[2] + v2[2] - Min;
      return v3;
    }
}

 int main(){
  int N , m , i , l , r;
  char ch;
  scanf( "%c" , &ch );
  i = 0;

     while( ch == '(' || ch == ')' ){
      i++;
      Str[i] = ch;
      scanf( "%c" , &ch );
    }

  N = i;
  scanf( "%d" , &m );
  fill( SegTree , SegTree + ( 2 * N ) + 10 , vector<int>( 3 , 0) );
  Build_Segment_Tree( 1 , 1 , N );

     for( i = 1 ; i <= m ; i++ ){
      scanf( "%d%d" , &l , &r );
      printf( "%d\n" , query( 1 , 1 , N , l , r )[0] );
    }

  return 0;
}


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

 vector<int> SegTree[4000005] , zero(3,0);
 string Str;

 vector<int> combine( vector<int> v1 , vector<int> v2 ){
  vector<int> v3(3);
  int Min = min( v1[1] , v2[2] );
  v3[0] = v1[0] + v2[0] + ( 2 * Min );
  v3[1] = v1[1] + v2[1] - Min;
  v3[2] = v1[2] + v2[2] - Min;

  return v3;
}

 void Build_Segment_Tree( int Node , int low , int high ){
     if( low == high ){
      SegTree[Node].emplace_back( 0 );
      //SegTree[Node][0] = 0;

         if( Str[low] == '(' ){
          //SegTree[Node][1] = 1;
          //SegTree[Node][2] = 0;
          SegTree[Node].emplace_back( 1 );
          SegTree[Node].emplace_back( 0 );
        }
         else{
          //SegTree[Node][1] = 0;
          //SegTree[Node][2] = 1;
          SegTree[Node].emplace_back( 0 );
          SegTree[Node].emplace_back( 1 );
        }
    }
     else{
      int Min , middle = ( low + high ) / 2;
      Build_Segment_Tree( 2 * Node , low , middle );
      Build_Segment_Tree( 2 * Node + 1 , middle + 1 , high );
      Min = min( SegTree[2 * Node][1] , SegTree[2 * Node + 1][2] );
      SegTree[Node].emplace_back( SegTree[2 * Node][0] + SegTree[2 * Node + 1][0] + Min * 2 );
      SegTree[Node].emplace_back( SegTree[2 * Node + 1][1] + SegTree[2 * Node][1] - Min );
      SegTree[Node].emplace_back( SegTree[2 * Node + 1][2] + SegTree[2 * Node][2] - Min );
      //SegTree[Node][0] = SegTree[2 * Node][0] + SegTree[2 * Node + 1][0] + Min * 2;
      //SegTree[Node][1] = SegTree[2 * Node + 1][1] + SegTree[2 * Node][1] - Min;
      //SegTree[Node][2] = SegTree[2 * Node + 1][2] + SegTree[2 * Node][2] - Min;
    }
}

 vector<int> query( int Node , int low , int high , int l , int r ){
     if( r < low || l > high )
      return zero;
     else if( l <= low && r >= high )
      return SegTree[Node];
    else{
      int middle = ( low + high ) / 2;
      return combine( query( 2 * Node , low , middle , l , r ) , query( 2 * Node + 1 , middle + 1 , high , l , r ) );
    }
}

 int main(){
  int N , m , i , l , r;
  cin >> Str;
  N = Str.size();
  scanf( "%d" , &m );
  //fill( SegTree , SegTree + 4 * N , vector<int>(3) );
  Build_Segment_Tree( 1 , 0 , N - 1 );

     for( i = 1 ; i <= m ; i++ ){
      scanf( "%d%d" , &l , &r );
      printf( "%d\n" , query( 1 , 0 , N - 1 , l - 1 , r - 1 )[0] );
    }

  return 0;
}


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

 vector<int> SegTree[4000005];
 string Str;

 void Build_Segment_Tree( int Node , int low , int high ){
     if( low == high ){
      SegTree[Node][0] = 0;

         if( Str[low] == '(' ){
          SegTree[Node][1] = 1;
          SegTree[Node][2] = 0;
        }
         else{
          SegTree[Node][1] = 0;
          SegTree[Node][2] = 1;
        }
    }
     else{
      int Min , middle = ( low + high ) / 2;
      Build_Segment_Tree( 2 * Node , low , middle );
      Build_Segment_Tree( 2 * Node + 1 , middle + 1 , high );
      Min = min( SegTree[2 * Node][1] , SegTree[2 * Node + 1][2] );
      SegTree[Node][0] = SegTree[2 * Node][0] + SegTree[2 * Node + 1][0] + Min * 2;
      SegTree[Node][1] = SegTree[2 * Node + 1][1] + SegTree[2 * Node][1] - Min;
      SegTree[Node][2] = SegTree[2 * Node + 1][2] + SegTree[2 * Node][2] - Min;
    }
}

 vector<int> query( int Node , int low , int high , int l , int r ){
     if( r < low || l > high )
      return vector<int>(3,0);
     else if( l <= low && r >= high )
      return SegTree[Node];
    else{
      int middle , Min;
      vector<int> v1 , v2;
      middle = ( low + high ) / 2;
      v1 = query( 2 * Node , low , middle , l , r );
      v2 = query( 2 * Node + 1 , middle + 1 , high , l , r );
      Min = min( v1[1] , v2[2] );
      v1[0] += v2[0] + 2 * Min;
      v1[1] += v2[1] - Min;
      v1[2] += v2[2] - Min;
      return v1;
    }
}

 int main(){
  int N , m , i , l , r;
  cin >> Str;
  N = Str.size();
  scanf( "%d" , &m );
  fill( SegTree , SegTree + 4 * N , vector<int>(3) );
  Build_Segment_Tree( 1 , 0 , N - 1 );

     for( i = 1 ; i <= m ; i++ ){
      scanf( "%d%d" , &l , &r );
      printf( "%d\n" , query( 1 , 0 , N - 1 , l - 1 , r - 1 )[0] );
    }

  return 0;
}


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

 vector<int> SegTree[4000005] , v3(3,0);
 char Str[1000005];

 void Build_Segment_Tree( int Node , int low , int high ){
     if( low == high ){
      SegTree[Node].emplace_back( 0 );
      //SegTree[Node][0] = 0;

         if( Str[low] == '(' ){
          //SegTree[Node][1] = 1;
          //SegTree[Node][2] = 0;
          SegTree[Node].emplace_back( 1 );
          SegTree[Node].emplace_back( 0 );
        }
         else{
          //SegTree[Node][1] = 0;
          //SegTree[Node][2] = 1;
          SegTree[Node].emplace_back( 0 );
          SegTree[Node].emplace_back( 1 );
        }
    }
     else{
      int Min , middle = ( low + high ) / 2;
      Build_Segment_Tree( 2 * Node , low , middle );
      Build_Segment_Tree( 2 * Node + 1 , middle + 1 , high );
      Min = min( SegTree[2 * Node][1] , SegTree[2 * Node + 1][2] );
      SegTree[Node].emplace_back( SegTree[2 * Node][0] + SegTree[2 * Node + 1][0] + Min * 2 );
      SegTree[Node].emplace_back( SegTree[2 * Node + 1][1] + SegTree[2 * Node][1] - Min );
      SegTree[Node].emplace_back( SegTree[2 * Node + 1][2] + SegTree[2 * Node][2] - Min );
      //SegTree[Node][0] = SegTree[2 * Node][0] + SegTree[2 * Node + 1][0] + Min * 2;
      //SegTree[Node][1] = SegTree[2 * Node + 1][1] + SegTree[2 * Node][1] - Min;
      //SegTree[Node][2] = SegTree[2 * Node + 1][2] + SegTree[2 * Node][2] - Min;
    }
}

 vector<int> query( int Node , int low , int high , int l , int r ){
     if( r < low || l > high )
      return v3;
     else if( l <= low && r >= high )
      return SegTree[Node];
    else{
      int middle , Min;
      vector<int> v1 , v2;
      middle = ( low + high ) / 2;
      v1 = query( 2 * Node , low , middle , l , r );
      v2 = query( 2 * Node + 1 , middle + 1 , high , l , r );
      Min = min( v1[1] , v2[2] );
      v1[0] += v2[0] + 2 * Min;
      v1[1] += v2[1] - Min;
      v1[2] += v2[2] - Min;
      return v1;
    }
}

 int main(){
  int N , m , i , l , r;
  scanf( "%s" , Str );
  N = strlen( Str );
  scanf( "%d" , &m );
  //fill( SegTree , SegTree + 4 * N , vector<int>(3) );
  Build_Segment_Tree( 1 , 0 , N - 1 );

     for( i = 1 ; i <= m ; i++ ){
      scanf( "%d%d" , &l , &r );
      printf( "%d\n" , query( 1 , 0 , N - 1 , l - 1 , r - 1 )[0] );
    }

  return 0;
}


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

 vector<int> SegTree[4000005] , v3(3,0);
 string Str;

 void Build_Segment_Tree( int Node , int low , int high ){
     if( low == high ){
      SegTree[Node].emplace_back( 0 );
      //SegTree[Node][0] = 0;

         if( Str[low] == '(' ){
          //SegTree[Node][1] = 1;
          //SegTree[Node][2] = 0;
          SegTree[Node].emplace_back( 1 );
          SegTree[Node].emplace_back( 0 );
        }
         else{
          //SegTree[Node][1] = 0;
          //SegTree[Node][2] = 1;
          SegTree[Node].emplace_back( 0 );
          SegTree[Node].emplace_back( 1 );
        }
    }
     else{
      int Min , middle = ( low + high ) / 2;
      Build_Segment_Tree( 2 * Node , low , middle );
      Build_Segment_Tree( 2 * Node + 1 , middle + 1 , high );
      Min = min( SegTree[2 * Node][1] , SegTree[2 * Node + 1][2] );
      SegTree[Node].emplace_back( SegTree[2 * Node][0] + SegTree[2 * Node + 1][0] + Min * 2 );
      SegTree[Node].emplace_back( SegTree[2 * Node + 1][1] + SegTree[2 * Node][1] - Min );
      SegTree[Node].emplace_back( SegTree[2 * Node + 1][2] + SegTree[2 * Node][2] - Min );
      //SegTree[Node][0] = SegTree[2 * Node][0] + SegTree[2 * Node + 1][0] + Min * 2;
      //SegTree[Node][1] = SegTree[2 * Node + 1][1] + SegTree[2 * Node][1] - Min;
      //SegTree[Node][2] = SegTree[2 * Node + 1][2] + SegTree[2 * Node][2] - Min;
    }
}

 vector<int> query( int Node , int low , int high , int l , int r ){
     if( r < low || l > high )
      return v3;
     else if( l <= low && r >= high )
      return SegTree[Node];
    else{
      int middle , Min;
      vector<int> v1 , v2;
      middle = ( low + high ) / 2;
      v1 = query( 2 * Node , low , middle , l , r );
      v2 = query( 2 * Node + 1 , middle + 1 , high , l , r );
      Min = min( v1[1] , v2[2] );
      v1[0] += v2[0] + 2 * Min;
      v1[1] += v2[1] - Min;
      v1[2] += v2[2] - Min;
      return v1;
    }
}

 int main(){
  int N , m , i , l , r;
  cin >> Str;
  N = Str.size();
  scanf( "%d" , &m );
  //fill( SegTree , SegTree + 4 * N , vector<int>(3) );
  Build_Segment_Tree( 1 , 0 , N - 1 );

     for( i = 1 ; i <= m ; i++ ){
      scanf( "%d%d" , &l , &r );
      printf( "%d\n" , query( 1 , 0 , N - 1 , l - 1 , r - 1 )[0] );
    }

  return 0;
}


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

 struct Inf{
  int Ans;
  int Open;
  int Close;

     Inf(){
      Ans = 0;
      Open = 0;
      Close = 0;
    }
};

 Inf SegTree[4000005];
 char Str[1000005];

 void Build_Segment_Tree( int Node , int low , int high ){
     if( low == high ){
         if( Str[low] == '(' )
          SegTree[Node].Open = 1;
         else
          SegTree[Node].Close = 1;

    }
     else{
      int Min , Temp1 , Temp2 , middle = ( low + high ) >> 1;
      Temp1 = 2 * Node;
      Temp2 = Temp1 + 1;
      Build_Segment_Tree( Temp1 , low , middle );
      Build_Segment_Tree( Temp2 , middle + 1 , high );
      Min = min( SegTree[Temp1].Open , SegTree[Temp2].Close );
      SegTree[Node].Ans = SegTree[Temp1].Ans + SegTree[Temp2].Ans + Min * 2;
      SegTree[Node].Open = SegTree[Temp2].Open + SegTree[Temp1].Open - Min;
      SegTree[Node].Close = SegTree[Temp1].Close + SegTree[Temp2].Close - Min;
    }
}

 Inf query( int Node , int low , int high , int l , int r ){
     if( r < low || l > high )
      return Inf();
     else if( l <= low && r >= high )
      return SegTree[Node];
    else{
      int middle , Min;
      Inf v1 , v2;
      middle = ( low + high ) / 2;
      v1 = query( 2 * Node , low , middle , l , r );
      v2 = query( 2 * Node + 1 , middle + 1 , high , l , r );
      Min = min( v1.Open , v2.Close );
      v1.Ans += v2.Ans + 2 * Min;
      v1.Open += v2.Open - Min;
      v1.Close += v2.Close - Min;
      return v1;
    }
}

 int main(){
  int N , m , i , l , r;
  scanf( "%s" , Str );
  N = strlen( Str );
  scanf( "%d" , &m );
  Build_Segment_Tree( 1 , 0 , N - 1 );

     for( i = 1 ; i <= m ; i++ ){
      scanf( "%d%d" , &l , &r );
      printf( "%d\n" , query( 1 , 0 , N - 1 , l - 1 , r - 1 ).Ans );
    }

  return 0;
}


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

 char Str[1000005];
 vector<int> SegTree[4000011];

 void Build_Segment_Tree( int Node , int low , int high ){
     if( low == high ){
         if( Str[low] == '(' )
          SegTree[Node][1] = 1;
         else
          SegTree[Node][2] = 1;
    }
     else{
      int Min , middle = ( low + high ) / 2;
      Build_Segment_Tree( 2 * Node , low , middle );
      Build_Segment_Tree( 2 * Node + 1 , middle + 1 , high );
      Min = min( SegTree[2 * Node][1] , SegTree[2 * Node + 1][2] );
      SegTree[Node][0] = SegTree[2 * Node][0] + SegTree[2 * Node + 1][0] + Min * 2;
      SegTree[Node][1] = SegTree[2 * Node + 1][1] + SegTree[2 * Node][1] - Min;
      SegTree[Node][2] = SegTree[2 * Node + 1][2] + SegTree[2 * Node][2] - Min;
    }
}

 vector<int> query( int Node , int low , int high , int l , int r ){
     if( r < low || l > high )
      return vector<int>(3,0);
     else if( l <= low && r >= high )
      return SegTree[Node];
    else{
      int middle , Min;
      vector<int> v1 , v2 , v3(3,0);
      middle = ( low + high ) / 2;
      v1 = query( 2 * Node , low , middle , l , r );
      v2 = query( 2 * Node + 1 , middle + 1 , high , l , r );
      Min = min( v1[1] , v2[2] );
      v3[0] = v1[0] + v2[0] + 2 * Min;
      v3[1] = v1[1] + v2[1] - Min;
      v3[2] = v1[2] + v2[2] - Min;
      return v3;
    }
}

 int main(){
  int N , m , i , l , r;
  char ch;
  scanf( "%c" , &ch );
  i = 0;

     while( ch == '(' || ch == ')' ){
      i++;
      Str[i] = ch;
      scanf( "%c" , &ch );
    }

  N = i;
  scanf( "%d" , &m );
  fill( SegTree , SegTree + ( 4 * N ) + 10 , vector<int>( 3 , 0) );
  Build_Segment_Tree( 1 , 1 , N );

     for( i = 1 ; i <= m ; i++ ){
      scanf( "%d%d" , &l , &r );
      printf( "%d\n" , query( 1 , 1 , N , l , r )[0] );
    }

  return 0;
}


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

 char Str[1000005];
 vector<int> SegTree[2000111];

 void Build_Segment_Tree( int Node , int low , int high ){
     if( low == high ){
         if( Str[low] == '(' )
          SegTree[Node][1] = 1;
         else
          SegTree[Node][2] = 1;
    }
     else{
      int Min , middle = ( low + high ) / 2;
      Build_Segment_Tree( 2 * Node , low , middle );
      Build_Segment_Tree( 2 * Node + 1 , middle + 1 , high );
      Min = min( SegTree[2 * Node][1] , SegTree[2 * Node + 1][2] );
      SegTree[Node][0] = SegTree[2 * Node][0] + SegTree[2 * Node + 1][0] + Min * 2;
      SegTree[Node][1] = SegTree[2 * Node + 1][1] + SegTree[2 * Node][1] - Min;
      SegTree[Node][2] = SegTree[2 * Node + 1][2] + SegTree[2 * Node][2] - Min;
    }
}

 vector<int> query( int Node , int low , int high , int l , int r ){
     if( r < low || l > high )
      return vector<int>(3,0);
     else if( l <= low && r >= high )
      return SegTree[Node];
    else{
      int middle , Min;
      vector<int> v1 , v2 , v3(3,0);
      middle = ( low + high ) / 2;
      v1 = query( 2 * Node , low , middle , l , r );
      v2 = query( 2 * Node + 1 , middle + 1 , high , l , r );
      Min = min( v1[1] , v2[2] );
      v3[0] = v1[0] + v2[0] + 2 * Min;
      v3[1] = v1[1] + v2[1] - Min;
      v3[2] = v1[2] + v2[2] - Min;
      return v3;
    }
}

 int main(){
  int N , m , i , l , r;
  char ch;
  scanf( "%c" , &ch );
  i = 0;

     while( ch == '(' || ch == ')' ){
      i++;
      Str[i] = ch;
      scanf( "%c" , &ch );
    }

  N = i;
  scanf( "%d" , &m );
  fill( SegTree , SegTree + ( 2 * N ) + 100 , vector<int>( 3 , 0) );
  Build_Segment_Tree( 1 , 1 , N );

     for( i = 1 ; i <= m ; i++ ){
      scanf( "%d%d" , &l , &r );
      printf( "%d\n" , query( 1 , 1 , N , l , r )[0] );
    }

  return 0;
}


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

 vector<int> SegTree[4000005];
 string Str;

 void Build_Segment_Tree( int Node , int low , int high ){
     if( low == high ){
      SegTree[Node].emplace_back( 0 );
      //SegTree[Node][0] = 0;

         if( Str[low] == '(' ){
          //SegTree[Node][1] = 1;
          //SegTree[Node][2] = 0;
          SegTree[Node].emplace_back( 1 );
          SegTree[Node].emplace_back( 0 );
        }
         else{
          //SegTree[Node][1] = 0;
          //SegTree[Node][2] = 1;
          SegTree[Node].emplace_back( 0 );
          SegTree[Node].emplace_back( 1 );
        }
    }
     else{
      int Min , middle = ( low + high ) / 2;
      Build_Segment_Tree( 2 * Node , low , middle );
      Build_Segment_Tree( 2 * Node + 1 , middle + 1 , high );
      Min = min( SegTree[2 * Node][1] , SegTree[2 * Node + 1][2] );
      SegTree[Node].emplace_back( SegTree[2 * Node][0] + SegTree[2 * Node + 1][0] + Min * 2 );
      SegTree[Node].emplace_back( SegTree[2 * Node + 1][1] + SegTree[2 * Node][1] - Min );
      SegTree[Node].emplace_back( SegTree[2 * Node + 1][2] + SegTree[2 * Node][2] - Min );
      //SegTree[Node][0] = SegTree[2 * Node][0] + SegTree[2 * Node + 1][0] + Min * 2;
      //SegTree[Node][1] = SegTree[2 * Node + 1][1] + SegTree[2 * Node][1] - Min;
      //SegTree[Node][2] = SegTree[2 * Node + 1][2] + SegTree[2 * Node][2] - Min;
    }
}

 vector<int> query( int Node , int low , int high , int l , int r ){
     if( r < low || l > high )
      return vector<int>(3,0);
     else if( l <= low && r >= high )
      return SegTree[Node];
    else{
      int middle , Min;
      vector<int> v1 , v2;
      middle = ( low + high ) / 2;
      v1 = query( 2 * Node , low , middle , l , r );
      v2 = query( 2 * Node + 1 , middle + 1 , high , l , r );
      Min = min( v1[1] , v2[2] );
      v1[0] += v2[0] + 2 * Min;
      v1[1] += v2[1] - Min;
      v1[2] += v2[2] - Min;
      return v1;
    }
}

 int main(){
  int N , m , i , l , r;
  cin >> Str;
  N = Str.size();
  scanf( "%d" , &m );
  //fill( SegTree , SegTree + 4 * N , vector<int>(3) );
  Build_Segment_Tree( 1 , 0 , N - 1 );

     for( i = 1 ; i <= m ; i++ ){
      scanf( "%d%d" , &l , &r );
      printf( "%d\n" , query( 1 , 0 , N - 1 , l - 1 , r - 1 )[0] );
    }

  return 0;
}


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

 char Str[1000005];
 vector<int> SegTree[400011];

 void Build_Segment_Tree( int Node , int low , int high ){
     if( low == high ){
         if( Str[low] == '(' )
          SegTree[Node][1] = 1;
         else
          SegTree[Node][2] = 1;
    }
     else{
      int Min , middle = ( low + high ) / 2;
      Build_Segment_Tree( 2 * Node , low , middle );
      Build_Segment_Tree( 2 * Node + 1 , middle + 1 , high );
      Min = min( SegTree[2 * Node][1] , SegTree[2 * Node + 1][2] );
      SegTree[Node][0] = SegTree[2 * Node][0] + SegTree[2 * Node + 1][0] + Min * 2;
      SegTree[Node][1] = SegTree[2 * Node + 1][1] + SegTree[2 * Node][1] - Min;
      SegTree[Node][2] = SegTree[2 * Node + 1][2] + SegTree[2 * Node][2] - Min;
    }
}

 vector<int> query( int Node , int low , int high , int l , int r ){
     if( r < low || l > high )
      return vector<int>(3,0);
     else if( l <= low && r >= high )
      return SegTree[Node];
    else{
      int middle , Min;
      vector<int> v1 , v2 , v3(3,0);
      middle = ( low + high ) / 2;
      v1 = query( 2 * Node , low , middle , l , r );
      v2 = query( 2 * Node + 1 , middle + 1 , high , l , r );
      Min = min( v1[1] , v2[2] );
      v3[0] = v1[0] + v2[0] + 2 * Min;
      v3[1] = v1[1] + v2[1] - Min;
      v3[2] = v1[2] + v2[2] - Min;
      return v3;
    }
}

 int main(){
  int N , m , i , l , r;
  char ch;
  scanf( "%c" , &ch );
  i = 0;

     while( ch == '(' || ch == ')' ){
      i++;
      Str[i] = ch;
      scanf( "%c" , &ch );
    }

  N = i;
  scanf( "%d" , &m );
  fill( SegTree , SegTree + ( 4 * N ) + 10 , vector<int>( 3 , 0) );
  Build_Segment_Tree( 1 , 1 , N );

     for( i = 1 ; i <= m ; i++ ){
      scanf( "%d%d" , &l , &r );
      printf( "%d\n" , query( 1 , 1 , N , l , r )[0] );
    }

  return 0;
}


#include<bits/stdc++.h>
#define int long long
#define ld long double
using namespace std;

const int N = 3e5 + 5, M = 60;

int n;
pair < int, int > a[N];

main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> a[i].first;
        a[i].second = i;
    }
    sort(a + 1, a + n + 1);
    reverse(a + 1, a + n + 1);
    set < int > q;
    set < int > :: iterator it;
    ld ans = 0;
    q.insert(0);
    q.insert(n + 1);
    for(int i = 1; i <= n; i++){
        int j = a[i].second;
        ld l = 0, r = 0;
        q.insert(j);
        it = q.find(j);
        for(int k = 1, pos = j; ++it != q.end() && k <= M; k++){
            r += (*it - pos) / (ld)(1LL << k);
            pos = *it;
        }
        it = q.find(j);
        for(int k = 1, pos = j; it-- != q.begin() && k <= M; k++){
            l += (pos - *it) / (ld)(1LL << k);
            pos = *it;
        }
        //cout << a[i].first << " " << a[i].second << " " << l << " " << r << "\n";
        ans += a[i].first * l * r * 2;
    }
    cout << fixed << setprecision(10) << ans / n / n;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <cmath>
#include <set>
#include <map>
#include <cstdio>
#include <stdlib.h>
#include <stack>
#include <numeric>
#include <bitset>
#include <cctype>
#include <list>
#include <assert.h>
#include <random>
typedef long long ll;
#define MAX 300105
using namespace std;
#define INF 2147483647
#define infL (1LL<<60)
#define inf (1e8)
#define MOD 1000000007
#define EPS 1e-9
#define Gr 9.8
#define PI acos(-1)
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define REQ(i,n) for(int (i)=1;(i)<=(int)(n);(i)++)
#define lch (rt<<1)
#define rch (rt<<1|1)
bool debug = 1;
int n,m, k;
int dx[4] = {0,1,0,-1}, dy[4] = {1,0,-1,0};
ll ln, lk, lm;

pair<int, int> a[MAX];
int pre[MAX], nxt[MAX];
double ans;
int main(){
    scanf("%d", &n);
    REQ(i,n) {
        scanf("%d", &a[i].first); a[i].second=i;
        pre[i]=i-1; nxt[i]=i+1;
    }
    sort(a+1,a+1+n);
    REQ(i,n) {
        int pos = a[i].second, val = a[i].first;
        int lp=pos,rp=pos;
        double l=0,r=0,mi=1;
        REP(j,50) {
            mi *= .5;
            if (lp) {
                l+= mi * (lp-pre[lp]); lp=pre[lp];
            }
            if (rp<=n) {
                r += mi *(nxt[rp]-rp); rp=nxt[rp];
            }
        }
        ans += 2 * val * l*r;
        pre[nxt[pos]]=pre[pos];
        nxt[pre[pos]]=nxt[pos];
    }
    printf("%.10lf\n", ans/n/n);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int T=55;
int n,b[300010],nxt[300010],pre[300010];
pair<int,int> v[300010];
double ans=0;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&b[i]),v[i]=make_pair(b[i],i);
	sort(v+1,v+n+1);
	for(int i=1;i<=n;i++)
	{
		pre[i]=i-1;
		nxt[i]=i+1;
	}
	for(int i=1;i<=n;i++)
	{
		int p=v[i].second;
		double L=0,R=0,pw=1;
		int lc=p,rc=p;
		for(int j=1;j<=T;j++)
		{
			if(lc)L+=pw*(lc-pre[lc]),lc=pre[lc];
			if(rc<=n)R+=pw*(nxt[rc]-rc),rc=nxt[rc];
			pw/=2;
		}
		ans+=v[i].first*L*R;
		pre[nxt[p]]=pre[p];
		nxt[pre[p]]=nxt[p];
	}
	printf("%.10lf\n",ans/n/n/2);
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i, a, b) for (int (i) = (a); (i) <= (b); (i)++)
#define ROF(i, a, b) for (int (i) = (a); (i) >= (b); (i)--)
#define REP(i, n) FOR(i, 0, (n)-1)
#define sqr(x) ((x) * (x))
#define all(x) (x).begin(), (x).end()
#define reset(x, y) memset(x, y, sizeof(x))
#define uni(x) (x).erase(unique(all(x)), (x).end())
#define BUG(x) cerr << #x << " = " << (x) << endl
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define _1 first
#define _2 second
#define chkmin(a, b) a = min(a, b)
#define chkmax(a, b) a = max(a, b)

const int maxn = 312345;

pii b[maxn];
int n, pre[maxn], nxt[maxn];

int main() {
  scanf("%d", &n);
  FOR(i, 1, n) {
    scanf("%d", &b[i]._1);
    b[i]._2 = i;
  }
  sort(b + 1, b + n + 1);
  FOR(i, 1, n) nxt[i] = i + 1, pre[i] = i - 1;
  double ans = 0;
  FOR(i, 1, n) {
    int id = b[i]._2, lo = id, hi = id;
    double l = 0, r = 0, f = 1;
    REP(j, 60) {
      f /= 2;
      if (lo) {
        l += f * (lo - pre[lo]);
        lo = pre[lo];
      }
      if (hi <= n) {
        r += f * (nxt[hi] - hi);
        hi = nxt[hi];
      }
    }
    ans += 2 * b[i]._1 * l * r;
    nxt[pre[id]] = nxt[id];
    pre[nxt[id]] = pre[id];
  }
  printf("%.10lf", ans / sqr(double(n)));
}


#pragma GCC optimize("Ofast")
#pragma GCC target("sse3","sse2","sse")
#pragma GCC target("avx","sse4","sse4.1","sse4.2","ssse3")
#pragma GCC target("f16c")
#pragma GCC optimize("inline","fast-math","unroll-loops","no-stack-protector")
#include<bits/stdc++.h>
using namespace std;
#define int lld
typedef int64_t lld;
typedef pair<int,int> pii;
#define ff first
#define ss second
#define pb push_back
#define all(x) (x).begin(),(x).end()
//#define endl '\n'
#define jizz cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);

template<typename Iter>
ostream& _out(ostream &s, Iter b, Iter e) {
    s<<"[";
    for ( auto it=b; it!=e; it++ ) s<<(it==b?"":" ")<<*it;
    s<<"]";
    return s;
}
template<class T1,class T2>
ostream& operator<<(ostream& out, pair<T1,T2> p) {
    return out << '(' << p.first << ", " << p.second << ')';
}
template<class T1,class T2>
istream& operator>>(istream& in, pair<T1,T2>& p) {
    return in >> p.ff >> p.ss;
}
template<typename T>
ostream& operator <<( ostream &s, const vector<T> &c ) {
     return _out(s,c.begin(),c.end());
}
template<typename T, size_t N>
ostream& operator <<( ostream &s, const array<T, N> &c ) {
     return _out(s,c.begin(),c.end());
}
inline char readchar() {
    const int S = 1<<20; // buffer size
    static char buf[S], *p = buf, *q = buf;
    if(p == q && (q = (p=buf)+fread(buf,1,S,stdin)) == buf) return EOF;
    return *p++;
}
inline void input(int &_x){
    _x = 0;
    int _tmp = 1; char _tc = readchar();
    while(_tc < '0' || _tc > '9') _tc = readchar();
    while(_tc >= '0' && _tc <= '9') _x = (_x<<1)+(_x<<3)+(_tc-48), _tc = readchar();
}
inline void output(int _x){
    char _buff[20]; int _f = 0;
    if(_x == 0) putchar('0');
    while(_x > 0){
            _buff[_f++] = _x%10+'0';
            _x /= 10;
    }
    for(_f-=1; _f >= 0; _f--)
            putchar(_buff[_f]);
  putchar('\n');
}
typedef long double ld;
struct Q{
    ld man = 1; int ex = 0; // man * 2^{-ex}
    Q(ld i, int j = 0){ ex = i?-(int)log2(i):0, man = i*pow(2, ex); ex += j; }
    friend Q operator+(const Q a, const Q b){
        return Q(a.man*pow(0.5, a.ex-min(a.ex, b.ex))+b.man*pow(0.5, b.ex-min(a.ex, b.ex)), min(a.ex, b.ex));
    }
    friend Q operator*(const Q a, const Q b){
        return Q(a.man*b.man, a.ex+b.ex);
    }
    operator ld(){
        return man*pow(0.5, ex);
    }
};
struct node{
    node *L ,*R;
    int l, r, mid;
    Q sum = 1;
    int lt = 0;
    node(int a, int b){ l = a, r = b, mid = l+r>>1; if(l != r)L = new node(l, mid), R = new node(mid+1, r), up(); }
    void upd(int x){lt+=x, sum.ex+=x; }
    void down(){ L->upd(lt), R->upd(lt), lt = 0; }
    void up(){ sum = L->sum + R->sum; }
    void update(int ll, int rr){
        if(ll <= l && rr >= r)return upd(1);
        if(ll > r || rr < l)return;
        down();
        L->update(ll, rr);
        R->update(ll, rr);
        up();
    }
    Q query(int ll, int rr){
        if(ll <= l && rr >= r)return sum;
        if(ll > r || rr < l)return 0;
        down();
        return L->query(ll, rr)+R->query(ll, rr);
    }
    int getLT(int i){
        if(l == r)return lt;
        return down(), (i <= mid?L:R)->getLT(i);
    }
} *rootl, *rootr;
vector<int> v;
vector<pii> evts;
signed main(){jizz;
    #ifdef LOCAL
    freopen("test.in", "r", stdin);
    #endif
    int n;
    cin >> n;
    v.resize(n+1);
    for(int i = 1; i <= n; i++)cin >> v[i], evts.pb({v[i], i});
    rootl = new node(1, n); rootr = new node(1, n);
    sort(all(evts)); reverse(all(evts));
    ld ans = 0;
    for(auto [x, pos]: evts){
        ans += rootl->query(1, pos)*rootr->query(pos, n)*Q(1, -rootl->getLT(pos)-rootr->getLT(pos)+1)/n/n*x;
        //cout << (ld)rootl->query(1, pos) << " " << (ld)rootr->query(pos, n) << " " << (ld)Q(1, -rootl->getLT(pos)-rootr->getLT(pos)+1) << endl;

        rootl->update(1, pos), rootr->update(pos, n);
    }
    cout << setprecision(20) << fixed << ans << endl;
}


#include<bits/stdc++.h>
using namespace std;
#define int lld
typedef int64_t lld;
typedef pair<int,int> pii;
#define ff first
#define ss second
#define pb push_back
#define all(x) (x).begin(),(x).end()
//#define endl '\n'
#define jizz cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);

template<typename Iter>
ostream& _out(ostream &s, Iter b, Iter e) {
    s<<"[";
    for ( auto it=b; it!=e; it++ ) s<<(it==b?"":" ")<<*it;
    s<<"]";
    return s;
}
template<class T1,class T2>
ostream& operator<<(ostream& out, pair<T1,T2> p) {
    return out << '(' << p.first << ", " << p.second << ')';
}
template<class T1,class T2>
istream& operator>>(istream& in, pair<T1,T2>& p) {
    return in >> p.ff >> p.ss;
}
template<typename T>
ostream& operator <<( ostream &s, const vector<T> &c ) {
     return _out(s,c.begin(),c.end());
}
template<typename T, size_t N>
ostream& operator <<( ostream &s, const array<T, N> &c ) {
     return _out(s,c.begin(),c.end());
}
inline char readchar() {
    const int S = 1<<20; // buffer size
    static char buf[S], *p = buf, *q = buf;
    if(p == q && (q = (p=buf)+fread(buf,1,S,stdin)) == buf) return EOF;
    return *p++;
}
inline void input(int &_x){
    _x = 0;
    int _tmp = 1; char _tc = readchar();
    while(_tc < '0' || _tc > '9') _tc = readchar();
    while(_tc >= '0' && _tc <= '9') _x = (_x<<1)+(_x<<3)+(_tc-48), _tc = readchar();
}
inline void output(int _x){
    char _buff[20]; int _f = 0;
    if(_x == 0) putchar('0');
    while(_x > 0){
            _buff[_f++] = _x%10+'0';
            _x /= 10;
    }
    for(_f-=1; _f >= 0; _f--)
            putchar(_buff[_f]);
  putchar('\n');
}
typedef long double ld;
struct Q{
    ld man = 1; int ex = 0; // man * 2^{-ex}
    Q(ld i, int j = 0){ /*ex = i?-(int)log2(i):0, man = i*pow(2, ex);*/ man = i, ex += j; }
    friend Q operator+(const Q a, const Q b){
        return Q(a.man*pow(0.5, a.ex-min(a.ex, b.ex))+b.man*pow(0.5, b.ex-min(a.ex, b.ex)), min(a.ex, b.ex));
    }
    friend Q operator*(const Q a, const Q b){
        return Q(a.man*b.man, a.ex+b.ex);
    }
    operator ld(){
        return man*pow(0.5, ex);
    }
};
struct node{
    node *L ,*R;
    int l, r, mid;
    Q sum = 1;
    int lt = 0;
    node(int a, int b){ l = a, r = b, mid = l+r>>1; if(l != r)L = new node(l, mid), R = new node(mid+1, r), up(); }
    void upd(int x){lt+=x, sum.ex+=x; }
    void down(){ L->upd(lt), R->upd(lt), lt = 0; }
    void up(){ sum = L->sum + R->sum; }
    void update(int ll, int rr){
        if(ll <= l && rr >= r)return upd(1);
        if(ll > r || rr < l)return;
        down();
        L->update(ll, rr);
        R->update(ll, rr);
        up();
    }
    Q query(int ll, int rr){
        if(ll <= l && rr >= r)return sum;
        if(ll > r || rr < l)return 0;
        down();
        return L->query(ll, rr)+R->query(ll, rr);
    }
    int getLT(int i){
        if(l == r)return lt;
        return down(), (i <= mid?L:R)->getLT(i);
    }
} *rootl, *rootr;
vector<int> v;
vector<pii> evts;
signed main(){jizz;
    #ifdef LOCAL
    freopen("test.in", "r", stdin);
    #endif
    int n;
    cin >> n;
    v.resize(n+1);
    for(int i = 1; i <= n; i++)cin >> v[i], evts.pb({v[i], i});
    rootl = new node(1, n); rootr = new node(1, n);
    sort(all(evts)); reverse(all(evts));
    ld ans = 0;
    for(auto [x, pos]: evts){
        ans += rootl->query(1, pos)*rootr->query(pos, n)*Q(1, -rootl->getLT(pos)-rootr->getLT(pos)+1)/n/n*x;
        //cout << (ld)rootl->query(1, pos) << " " << (ld)rootr->query(pos, n) << " " << (ld)Q(1, -rootl->getLT(pos)-rootr->getLT(pos)+1) << endl;

        rootl->update(1, pos), rootr->update(pos, n);
    }
    cout << setprecision(20) << fixed << ans << endl;
}


#pragma GCC optimize("Ofast")
#pragma GCC target("sse3","sse2","sse")
#pragma GCC target("avx","sse4","sse4.1","sse4.2","ssse3")
#pragma GCC target("f16c")
#pragma GCC optimize("inline","fast-math","unroll-loops","no-stack-protector")
#include<bits/stdc++.h>
using namespace std;
#define int lld
typedef int64_t lld;
typedef pair<int,int> pii;
#define ff first
#define ss second
#define pb push_back
#define all(x) (x).begin(),(x).end()
//#define endl '\n'
#define jizz cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);

template<typename Iter>
ostream& _out(ostream &s, Iter b, Iter e) {
    s<<"[";
    for ( auto it=b; it!=e; it++ ) s<<(it==b?"":" ")<<*it;
    s<<"]";
    return s;
}
template<class T1,class T2>
ostream& operator<<(ostream& out, pair<T1,T2> p) {
    return out << '(' << p.first << ", " << p.second << ')';
}
template<class T1,class T2>
istream& operator>>(istream& in, pair<T1,T2>& p) {
    return in >> p.ff >> p.ss;
}
template<typename T>
ostream& operator <<( ostream &s, const vector<T> &c ) {
     return _out(s,c.begin(),c.end());
}
template<typename T, size_t N>
ostream& operator <<( ostream &s, const array<T, N> &c ) {
     return _out(s,c.begin(),c.end());
}
inline char readchar() {
    const int S = 1<<20; // buffer size
    static char buf[S], *p = buf, *q = buf;
    if(p == q && (q = (p=buf)+fread(buf,1,S,stdin)) == buf) return EOF;
    return *p++;
}
inline void input(int &_x){
    _x = 0;
    int _tmp = 1; char _tc = readchar();
    while(_tc < '0' || _tc > '9') _tc = readchar();
    while(_tc >= '0' && _tc <= '9') _x = (_x<<1)+(_x<<3)+(_tc-48), _tc = readchar();
}
inline void output(int _x){
    char _buff[20]; int _f = 0;
    if(_x == 0) putchar('0');
    while(_x > 0){
            _buff[_f++] = _x%10+'0';
            _x /= 10;
    }
    for(_f-=1; _f >= 0; _f--)
            putchar(_buff[_f]);
  putchar('\n');
}
typedef long double ld;
struct Q{
    ld man = 1; int ex = 0; // man * 2^{-ex}
    Q(ld i, int j = 0){ man = i; ex = j; }
    friend Q operator+(const Q a, const Q b){
        return Q(a.man*pow(0.5, a.ex-min(a.ex, b.ex))+b.man*pow(0.5, b.ex-min(a.ex, b.ex)), min(a.ex, b.ex));
    }
    operator ld(){
        return man*pow(0.5, ex);
    }
};
struct node{
    node *L ,*R;
    int l, r, mid;
    Q sum = 1;
    int lt = 0;
    node(int a, int b){ l = a, r = b, mid = l+r>>1; if(l != r)L = new node(l, mid), R = new node(mid+1, r), up(); }
    void upd(int x){lt+=x, sum.ex+=x; }
    void down(){ L->upd(lt), R->upd(lt), lt = 0; }
    void up(){ sum = L->sum + R->sum; }
    void update(int ll, int rr){
        if(ll <= l && rr >= r)return upd(1);
        if(ll > r || rr < l)return;
        down();
        L->update(ll, rr);
        R->update(ll, rr);
        up();
    }
    Q query(int ll, int rr){
        if(ll <= l && rr >= r)return sum;
        if(ll > r || rr < l)return 0;
        down();
        return L->query(ll, rr)+R->query(ll, rr);
    }
    int getLT(int i){
        if(l == r)return lt;
        return down(), (i <= mid?L:R)->getLT(i);
    }
} *rootl, *rootr;
vector<int> v;
vector<pii> evts;
signed main(){jizz;
    #ifdef LOCAL
    freopen("test.in", "r", stdin);
    #endif
    int n;
    cin >> n;
    v.resize(n+1);
    for(int i = 1; i <= n; i++)cin >> v[i], evts.pb({v[i], i});
    rootl = new node(1, n); rootr = new node(1, n);
    sort(all(evts)); reverse(all(evts));
    ld ans = 0;
    for(auto [x, pos]: evts){
        ans += (ld)(rootl->query(1, pos)*rootr->query(pos, n)*Q(1, -rootl->getLT(pos)-rootr->getLT(pos)+1))/n/n*x;
        //cout << (ld)rootl->query(1, pos) << " " << (ld)rootr->query(pos, n) << " " << (ld)Q(1, -rootl->getLT(pos)-rootr->getLT(pos)+1) << endl;

        rootl->update(1, pos), rootr->update(pos, n);
    }
    cout << setprecision(20) << fixed << ans << endl;
}


#pragma GCC optimize("Ofast")
#pragma GCC target("sse3","sse2","sse")
#pragma GCC target("avx","sse4","sse4.1","sse4.2","ssse3")
#pragma GCC target("f16c")
#pragma GCC optimize("inline","fast-math","unroll-loops","no-stack-protector")
#include<bits/stdc++.h>
using namespace std;
#define int lld
typedef int64_t lld;
typedef pair<int,int> pii;
#define ff first
#define ss second
#define pb push_back
#define all(x) (x).begin(),(x).end()
//#define endl '\n'
#define jizz cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);

template<typename Iter>
ostream& _out(ostream &s, Iter b, Iter e) {
    s<<"[";
    for ( auto it=b; it!=e; it++ ) s<<(it==b?"":" ")<<*it;
    s<<"]";
    return s;
}
template<class T1,class T2>
ostream& operator<<(ostream& out, pair<T1,T2> p) {
    return out << '(' << p.first << ", " << p.second << ')';
}
template<class T1,class T2>
istream& operator>>(istream& in, pair<T1,T2>& p) {
    return in >> p.ff >> p.ss;
}
template<typename T>
ostream& operator <<( ostream &s, const vector<T> &c ) {
     return _out(s,c.begin(),c.end());
}
template<typename T, size_t N>
ostream& operator <<( ostream &s, const array<T, N> &c ) {
     return _out(s,c.begin(),c.end());
}
inline char readchar() {
    const int S = 1<<20; // buffer size
    static char buf[S], *p = buf, *q = buf;
    if(p == q && (q = (p=buf)+fread(buf,1,S,stdin)) == buf) return EOF;
    return *p++;
}
inline void input(int &_x){
    _x = 0;
    int _tmp = 1; char _tc = readchar();
    while(_tc < '0' || _tc > '9') _tc = readchar();
    while(_tc >= '0' && _tc <= '9') _x = (_x<<1)+(_x<<3)+(_tc-48), _tc = readchar();
}
inline void output(int _x){
    char _buff[20]; int _f = 0;
    if(_x == 0) putchar('0');
    while(_x > 0){
            _buff[_f++] = _x%10+'0';
            _x /= 10;
    }
    for(_f-=1; _f >= 0; _f--)
            putchar(_buff[_f]);
  putchar('\n');
}
typedef long double ld;
struct Q{
    ld man = 1; int ex = 0; // man * 2^{-ex}
    Q(ld i, int j = 0){ ex = i?-(int)log2(i):0, man = i*pow(2, ex); ex += j; }
    friend Q operator+(const Q a, const Q b){
        return Q(a.man*pow(0.5, a.ex-min(a.ex, b.ex))+b.man*pow(0.5, b.ex-min(a.ex, b.ex)), min(a.ex, b.ex));
    }
    operator ld(){
        return man*pow(0.5, ex);
    }
};
struct node{
    node *L ,*R;
    int l, r, mid;
    Q sum = 1;
    int lt = 0;
    node(int a, int b){ l = a, r = b, mid = l+r>>1; if(l != r)L = new node(l, mid), R = new node(mid+1, r), up(); }
    void upd(int x){lt+=x, sum.ex+=x; }
    void down(){ L->upd(lt), R->upd(lt), lt = 0; }
    void up(){ sum = L->sum + R->sum; }
    void update(int ll, int rr){
        if(ll <= l && rr >= r)return upd(1);
        if(ll > r || rr < l)return;
        down();
        L->update(ll, rr);
        R->update(ll, rr);
        up();
    }
    Q query(int ll, int rr){
        if(ll <= l && rr >= r)return sum;
        if(ll > r || rr < l)return 0;
        down();
        return L->query(ll, rr)+R->query(ll, rr);
    }
    int getLT(int i){
        if(l == r)return lt;
        return down(), (i <= mid?L:R)->getLT(i);
    }
} *rootl, *rootr;
vector<int> v;
vector<pii> evts;
signed main(){jizz;
    #ifdef LOCAL
    freopen("test.in", "r", stdin);
    #endif
    int n;
    cin >> n;
    v.resize(n+1);
    for(int i = 1; i <= n; i++)cin >> v[i], evts.pb({v[i], i});
    rootl = new node(1, n); rootr = new node(1, n);
    sort(all(evts)); reverse(all(evts));
    ld ans = 0;
    for(auto [x, pos]: evts){
        ans += (ld)(rootl->query(1, pos)*rootr->query(pos, n)*Q(1, -rootl->getLT(pos)-rootr->getLT(pos)+1))/n/n*x;
        //cout << (ld)rootl->query(1, pos) << " " << (ld)rootr->query(pos, n) << " " << (ld)Q(1, -rootl->getLT(pos)-rootr->getLT(pos)+1) << endl;

        rootl->update(1, pos), rootr->update(pos, n);
    }
    cout << setprecision(20) << fixed << ans << endl;
}


#pragma GCC optimize("Ofast")
#pragma GCC target("sse3","sse2","sse")
#pragma GCC target("avx","sse4","sse4.1","sse4.2","ssse3")
#pragma GCC target("f16c")
#pragma GCC optimize("inline","fast-math","unroll-loops","no-stack-protector")
#include<bits/stdc++.h>
using namespace std;
#define int lld
typedef int64_t lld;
typedef pair<int,int> pii;
#define ff first
#define ss second
#define pb push_back
#define all(x) (x).begin(),(x).end()
//#define endl '\n'
#define jizz cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);

template<typename Iter>
ostream& _out(ostream &s, Iter b, Iter e) {
    s<<"[";
    for ( auto it=b; it!=e; it++ ) s<<(it==b?"":" ")<<*it;
    s<<"]";
    return s;
}
template<class T1,class T2>
ostream& operator<<(ostream& out, pair<T1,T2> p) {
    return out << '(' << p.first << ", " << p.second << ')';
}
template<class T1,class T2>
istream& operator>>(istream& in, pair<T1,T2>& p) {
    return in >> p.ff >> p.ss;
}
template<typename T>
ostream& operator <<( ostream &s, const vector<T> &c ) {
     return _out(s,c.begin(),c.end());
}
template<typename T, size_t N>
ostream& operator <<( ostream &s, const array<T, N> &c ) {
     return _out(s,c.begin(),c.end());
}
inline char readchar() {
    const int S = 1<<20; // buffer size
    static char buf[S], *p = buf, *q = buf;
    if(p == q && (q = (p=buf)+fread(buf,1,S,stdin)) == buf) return EOF;
    return *p++;
}
inline void input(int &_x){
    _x = 0;
    int _tmp = 1; char _tc = readchar();
    while(_tc < '0' || _tc > '9') _tc = readchar();
    while(_tc >= '0' && _tc <= '9') _x = (_x<<1)+(_x<<3)+(_tc-48), _tc = readchar();
}
inline void output(int _x){
    char _buff[20]; int _f = 0;
    if(_x == 0) putchar('0');
    while(_x > 0){
            _buff[_f++] = _x%10+'0';
            _x /= 10;
    }
    for(_f-=1; _f >= 0; _f--)
            putchar(_buff[_f]);
  putchar('\n');
}
typedef long double ld;
struct Q{
    ld man = 1; int ex = 0; // man * 2^{-ex}
    Q(ld i, int j = 0){ assert(abs(i)<=1e-7 || i >= 1-1e-7);man = i, ex += j; }
    friend Q operator+(const Q a, const Q b){
        if(abs(a.man)<=1e-7)return b;
        if(abs(b.man)<=1e-7)return a;
        return Q(a.man*pow(0.5, a.ex-min(a.ex, b.ex))+b.man*pow(0.5, b.ex-min(a.ex, b.ex)), min(a.ex, b.ex));
    }
    friend Q operator*(const Q a, const Q b){
        return Q(a.man*b.man, a.ex+b.ex);
    }
    operator ld(){
        return man*pow(0.5, ex);
    }
};
struct node{
    node *L ,*R;
    int l, r, mid;
    Q sum = 1;
    int lt = 0;
    node(int a, int b){ l = a, r = b, mid = l+r>>1; if(l != r)L = new node(l, mid), R = new node(mid+1, r), up(); }
    void upd(int x){lt+=x, sum.ex+=x; }
    void down(){ L->upd(lt), R->upd(lt), lt = 0; }
    void up(){ sum = L->sum + R->sum; }
    void update(int ll, int rr){
        if(ll <= l && rr >= r)return upd(1);
        if(ll > r || rr < l)return;
        down();
        L->update(ll, rr);
        R->update(ll, rr);
        up();
    }
    Q query(int ll, int rr){
        if(ll <= l && rr >= r)return sum;
        if(ll > r || rr < l)return 0;
        down();
        return L->query(ll, rr)+R->query(ll, rr);
    }
    int getLT(int i){
        if(l == r)return lt;
        return down(), (i <= mid?L:R)->getLT(i);
    }
} *rootl, *rootr;
vector<int> v;
vector<pii> evts;
signed main(){jizz;
    #ifdef LOCAL
    freopen("test.in", "r", stdin);
    #endif
    int n;
    cin >> n;
    v.resize(n+1);
    for(int i = 1; i <= n; i++)cin >> v[i], evts.pb({v[i], i});
    rootl = new node(1, n); rootr = new node(1, n);
    sort(all(evts)); reverse(all(evts));
    ld ans = 0;
    for(auto [x, pos]: evts){
        ans += rootl->query(1, pos)*rootr->query(pos, n)*Q(1, -rootl->getLT(pos)-rootr->getLT(pos)+1)/n/n*x;
        //cout << (ld)rootl->query(1, pos) << " " << (ld)rootr->query(pos, n) << " " << (ld)Q(1, -rootl->getLT(pos)-rootr->getLT(pos)+1) << endl;

        rootl->update(1, pos), rootr->update(pos, n);
    }
    cout << setprecision(20) << fixed << ans << endl;
}


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

typedef pair <int, int> ii;
typedef long double ld;

const int Maxn = 300005;
const int Maxd = 30;

ld pw2[Maxd];
int n;
int a[Maxn];
vector <ii> seq;
set <int> S;
ld res;

int main()
{
    pw2[0] = 1;
    for (int i = 1; i < Maxd; i++)
        pw2[i] = 2.0l * pw2[i - 1];
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
        seq.push_back(ii(a[i], i));
    }
    sort(seq.rbegin(), seq.rend());
    S.insert(-1);
    S.insert(n);
    for (int i = 0; i < seq.size(); i++) {
        int ind = seq[i].second;
        set <int>::iterator it = S.insert(ind).first;
        int cnt = 0;
        set <int>::iterator lef = it;
        while (lef != S.begin() && cnt + 1 < Maxd) {
            cnt++;
            int rig1 = *lef;
            lef--;
            int lef1 = *lef;
            set <int>::iterator rig = it;
            int ncnt = cnt;
            while (*rig < n && ncnt < Maxd) {
                int lef2 = *rig;
                rig++;
                int rig2 = *rig;
                res += ld(rig1 - lef1) / ld(n) * ld(rig2 - lef2) / ld(n) * seq[i].first / pw2[ncnt];
                ncnt++;
            }
        }
    }
    cout << fixed << setprecision(16) << res << endl;
    return 0;
}


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

typedef pair <int, int> ii;
typedef long double ld;

const int Maxn = 300005;
const int Maxd = 40;

ld pw2[Maxd];
int n;
int a[Maxn];
vector <ii> seq;
set <int> S;
ld res;

int main()
{
    pw2[0] = 1;
    for (int i = 1; i < Maxd; i++)
        pw2[i] = 2.0l * pw2[i - 1];
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
        seq.push_back(ii(a[i], i));
    }
    sort(seq.rbegin(), seq.rend());
    S.insert(-1);
    S.insert(n);
    for (int i = 0; i < seq.size(); i++) {
        int ind = seq[i].second;
        set <int>::iterator it = S.insert(ind).first;
        int cnt = 0;
        set <int>::iterator lef = it;
        while (lef != S.begin() && cnt + 1 < Maxd) {
            cnt++;
            int rig1 = *lef;
            lef--;
            int lef1 = *lef;
            set <int>::iterator rig = it;
            int ncnt = cnt;
            while (*rig < n && ncnt < Maxd) {
                int lef2 = *rig;
                rig++;
                int rig2 = *rig;
                res += ld(rig1 - lef1) / ld(n) * ld(rig2 - lef2) / ld(n) * seq[i].first / pw2[ncnt];
                ncnt++;
            }
        }
    }
    cout << fixed << setprecision(16) << res << endl;
    return 0;
}


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

typedef pair <int, int> ii;
typedef long double ld;

const int Maxn = 300005;
const int Maxd = 25;

ld pw2[Maxd];
int n;
int a[Maxn];
vector <ii> seq;
set <int> S;
ld res;

int main()
{
    pw2[0] = 1;
    for (int i = 1; i < Maxd; i++)
        pw2[i] = 2.0l * pw2[i - 1];
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
        seq.push_back(ii(a[i], i));
    }
    sort(seq.rbegin(), seq.rend());
    S.insert(-1);
    S.insert(n);
    for (int i = 0; i < seq.size(); i++) {
        int ind = seq[i].second;
        set <int>::iterator it = S.insert(ind).first;
        int cnt = 0;
        set <int>::iterator lef = it;
        while (lef != S.begin() && cnt + 1 < Maxd) {
            cnt++;
            int rig1 = *lef;
            lef--;
            int lef1 = *lef;
            set <int>::iterator rig = it;
            int ncnt = cnt;
            while (*rig < n && ncnt < Maxd) {
                int lef2 = *rig;
                rig++;
                int rig2 = *rig;
                res += ld(rig1 - lef1) / ld(n) * ld(rig2 - lef2) / ld(n) * seq[i].first / pw2[ncnt];
                ncnt++;
            }
        }
    }
    cout << fixed << setprecision(16) << res << endl;
    return 0;
}


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

typedef pair <int, int> ii;
typedef double ld;

const int Maxn = 300005;
const int Maxd = 40;

ld pw2[Maxd];
int n;
int a[Maxn];
vector <ii> seq;
set <int> S;
ld res;

int main()
{
    pw2[0] = 1;
    for (int i = 1; i < Maxd; i++)
        pw2[i] = 2.0l * pw2[i - 1];
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
        seq.push_back(ii(a[i], i));
    }
    sort(seq.rbegin(), seq.rend());
    S.insert(-1);
    S.insert(n);
    for (int i = 0; i < seq.size(); i++) {
        int ind = seq[i].second;
        set <int>::iterator it = S.insert(ind).first;
        int cnt = 0;
        set <int>::iterator lef = it;
        while (lef != S.begin() && cnt + 1 < Maxd) {
            cnt++;
            int rig1 = *lef;
            lef--;
            int lef1 = *lef;
            set <int>::iterator rig = it;
            int ncnt = cnt;
            while (*rig < n && ncnt < Maxd) {
                int lef2 = *rig;
                rig++;
                int rig2 = *rig;
                res += ld(rig1 - lef1) / ld(n) * ld(rig2 - lef2) / ld(n) * seq[i].first / pw2[ncnt];
                ncnt++;
            }
        }
    }
    cout << fixed << setprecision(16) << res << endl;
    return 0;
}


//
// Created by Ильдар Ялалов on 14.01.2020.
//
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf_int = 1e9 + 100;
const ll inf_ll = 1e18;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef double dbl;
typedef unsigned int uint;
#define pb push_back
#define eb emplace_back
const double pi = 3.1415926535898;
#define dout if(debug) cout
#define fi first
#define se second
#define sp setprecision
#define sz(a) (int(a.size()))
#define mp make_pair
#define all(a) a.begin(),a.end()

#ifdef zxc

#include "debug.h"

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

bool debug = 0;
const int MAXN = (1e6) + 100;
const int LOG = 21;
const int mod = 1e9 + 7;
const int MX = (2e6 + 100);

int a[MAXN];
dbl pw[100];

void solve() {
    int n;
    cin >> n;
    vector<pii> c;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
        c.pb({a[i], i});
    }
    sort(all(c));
    reverse(all(c));
    set<int> ss;
    ss.insert(0);
    ss.insert(n + 1);
    double ans = 0;

    for (int i = 1; i <= 62; ++i) {
        pw[i] = 1.0;
        pw[i] = pw[i] / (1ll << i);
    }
    for (auto x : c) {
        ss.insert(x.se);
        auto it = ss.lower_bound(x.se);
        vector<int> bef;
        vector<int> after;

        auto it1 = it;
        it1--;
        while (sz(bef) < 60) {
            bef.pb(*it1);
            if (it1 == ss.begin())
                break;
            it1--;
        }

        auto it2 = it;
        it2++;
        while (sz(after) < 60) {
            after.pb(*it2);
            it2++;
            if (it2 == ss.end())
                break;
        }

        debug(x.se, bef, after);
        reverse(all(bef));

        for (int i = 0; i < sz(bef); ++i) {
            for (int j = 0; j < sz(after); ++j) {
                int cnt1 = sz(bef) - i - 1;
                int cnt2 = j;
                int k = cnt1 + cnt2;

                if (k <= 60) {
                    ll total = 1;
                    if (i + 1 == sz(bef)) {
                        total *= (x.se - bef[i]);
                    } else {
                        total *= (bef[i + 1] - bef[i]);
                    }

                    if (j - 1 >= 0) {
                        total *= after[j] - after[j - 1];
                    } else {
                        total *= after[j] - x.se;
                    }

                    debug(i, j, x, k, total);

                    ans += pw[k + 1] * total * x.fi;
                }

            }
        }

    }
    ans = ans / (1ll * n * n);
    cout << ans << "\n";

}

// CHECK LIMITS (n <= 10^5)
// CHECK CORNER CASES ( n==1)
signed main() {

#ifdef zxc
    freopen("../output.txt", "r", stdin);
    //  freopen("../output.txt", "w", stdout);
#else
#endif //zxc
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout.setf(ios::fixed);
    cout.precision(15);

    int t = 1;
    while (t--) {
        solve();
    }
    debug(1.0 * clock() / CLOCKS_PER_SEC);
}


//
// Created by Ильдар Ялалов on 14.01.2020.
//
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf_int = 1e9 + 100;
const ll inf_ll = 1e18;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef double dbl;
typedef unsigned int uint;
#define pb push_back
#define eb emplace_back
const double pi = 3.1415926535898;
#define dout if(debug) cout
#define fi first
#define se second
#define sp setprecision
#define sz(a) (int(a.size()))
#define mp make_pair
#define all(a) a.begin(),a.end()

#ifdef zxc

#include "debug.h"

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

bool debug = 0;
const int MAXN = (1e6) + 100;
const int LOG = 21;
const int mod = 1e9 + 7;
const int MX = (2e6 + 100);

int a[MAXN];
dbl pw[100];

void solve() {
    int n;
    cin >> n;
    vector<pii> c;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
        c.pb({a[i], i});
    }
    sort(all(c));
    reverse(all(c));
    set<int> ss;
    ss.insert(0);
    ss.insert(n + 1);
    double ans = 0;

    for (int i = 1; i <= 62; ++i) {
        pw[i] = 1.0;
        pw[i] = pw[i] / (1ll << i);
    }
    for (auto x : c) {
        ss.insert(x.se);
        auto it = ss.lower_bound(x.se);
        vector<int> bef;
        vector<int> after;

        auto it1 = it;
        it1--;
        while (sz(bef) < 50) {
            bef.pb(*it1);
            if (it1 == ss.begin())
                break;
            it1--;
        }

        auto it2 = it;
        it2++;
        while (sz(after) < 50) {
            after.pb(*it2);
            it2++;
            if (it2 == ss.end())
                break;
        }

        debug(x.se, bef, after);
        reverse(all(bef));

        for (int i = 0; i < sz(bef); ++i) {
            for (int j = 0; j < sz(after); ++j) {
                int cnt1 = sz(bef) - i - 1;
                int cnt2 = j;
                int k = cnt1 + cnt2;

                if (k <= 50) {
                    ll total = 1;
                    if (i + 1 == sz(bef)) {
                        total *= (x.se - bef[i]);
                    } else {
                        total *= (bef[i + 1] - bef[i]);
                    }

                    if (j - 1 >= 0) {
                        total *= after[j] - after[j - 1];
                    } else {
                        total *= after[j] - x.se;
                    }

                    debug(i, j, x, k, total);

                    ans += pw[k + 1] * total * x.fi;
                }

            }
        }

    }
    ans = ans / (1ll * n * n);
    cout << ans << "\n";

}

// CHECK LIMITS (n <= 10^5)
// CHECK CORNER CASES ( n==1)
signed main() {

#ifdef zxc
    freopen("../output.txt", "r", stdin);
    //  freopen("../output.txt", "w", stdout);
#else
#endif //zxc
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout.setf(ios::fixed);
    cout.precision(15);

    int t = 1;
    while (t--) {
        solve();
    }
    debug(1.0 * clock() / CLOCKS_PER_SEC);
}


//
// Created by Ильдар Ялалов on 14.01.2020.
//
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf_int = 1e9 + 100;
const ll inf_ll = 1e18;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef double dbl;
typedef unsigned int uint;
#define pb push_back
#define eb emplace_back
const double pi = 3.1415926535898;
#define dout if(debug) cout
#define fi first
#define se second
#define sp setprecision
#define sz(a) (int(a.size()))
#define mp make_pair
#define all(a) a.begin(),a.end()

#ifdef zxc

#include "debug.h"

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

bool debug = 0;
const int MAXN = (1e6) + 100;
const int LOG = 21;
const int mod = 1e9 + 7;
const int MX = (2e6 + 100);

int a[MAXN];
dbl pw[100];

void solve() {
    int n;
    cin >> n;
    vector<pii> c;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
        c.pb({a[i], i});
    }
    sort(all(c));
    reverse(all(c));
    set<int> ss;
    ss.insert(0);
    ss.insert(n + 1);
    double ans = 0;

    for (int i = 1; i <= 62; ++i) {
        pw[i] = 1.0;
        pw[i] = pw[i] / (1ll << i);
    }
    for (auto x : c) {
        ss.insert(x.se);
        auto it = ss.lower_bound(x.se);
        vector<int> bef;
        vector<int> after;

        auto it1 = it;
        it1--;
        while (sz(bef) < 40) {
            bef.pb(*it1);
            if (it1 == ss.begin())
                break;
            it1--;
        }

        auto it2 = it;
        it2++;
        while (sz(after) < 40) {
            after.pb(*it2);
            it2++;
            if (it2 == ss.end())
                break;
        }

        debug(x.se, bef, after);
        reverse(all(bef));

        for (int i = 0; i < sz(bef); ++i) {
            for (int j = 0; j < sz(after); ++j) {
                int cnt1 = sz(bef) - i - 1;
                int cnt2 = j;
                int k = cnt1 + cnt2;

                if (k <= 60) {
                    ll total = 1;
                    if (i + 1 == sz(bef)) {
                        total *= (x.se - bef[i]);
                    } else {
                        total *= (bef[i + 1] - bef[i]);
                    }

                    if (j - 1 >= 0) {
                        total *= after[j] - after[j - 1];
                    } else {
                        total *= after[j] - x.se;
                    }

                    debug(i, j, x, k, total);

                    ans += pw[k + 1] * total * x.fi;
                }

            }
        }

    }
    ans = ans / (1ll * n * n);
    cout << ans << "\n";

}

// CHECK LIMITS (n <= 10^5)
// CHECK CORNER CASES ( n==1)
signed main() {

#ifdef zxc
    freopen("../output.txt", "r", stdin);
    //  freopen("../output.txt", "w", stdout);
#else
#endif //zxc
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout.setf(ios::fixed);
    cout.precision(15);

    int t = 1;
    while (t--) {
        solve();
    }
    debug(1.0 * clock() / CLOCKS_PER_SEC);
}


//
// Created by Ильдар Ялалов on 14.01.2020.
//
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf_int = 1e9 + 100;
const ll inf_ll = 1e18;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef double dbl;
typedef unsigned int uint;
#define pb push_back
#define eb emplace_back
const double pi = 3.1415926535898;
#define dout if(debug) cout
#define fi first
#define se second
#define sp setprecision
#define sz(a) (int(a.size()))
#define mp make_pair
#define all(a) a.begin(),a.end()

#ifdef zxc

#include "debug.h"

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

bool debug = 0;
const int MAXN = (1e6) + 100;
const int LOG = 21;
const int mod = 1e9 + 7;
const int MX = (2e6 + 100);

int a[MAXN];
dbl pw[100];

void solve() {
    int n;
    cin >> n;
    vector<pii> c;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
        c.pb({a[i], i});
    }
    sort(all(c));
    reverse(all(c));
    set<int> ss;
    ss.insert(0);
    ss.insert(n + 1);
    double ans = 0;

    for (int i = 1; i <= 62; ++i) {
        pw[i] = 1.0;
        pw[i] = pw[i] / (1ll << i);
    }
    for (auto x : c) {
        ss.insert(x.se);
        auto it = ss.lower_bound(x.se);
        vector<int> bef;
        vector<int> after;

        auto it1 = it;
        it1--;
        while (sz(bef) < 60) {
            bef.pb(*it1);
            if (it1 == ss.begin())
                break;
            it1--;
        }

        auto it2 = it;
        it2++;
        while (sz(after) < 60) {
            after.pb(*it2);
            it2++;
            if (it2 == ss.end())
                break;
        }

        debug(x.se, bef, after);
        reverse(all(bef));

        for (int i = 0; i < sz(bef); ++i) {
            for (int j = 0; j < sz(after); ++j) {
                int cnt1 = sz(bef) - i - 1;
                int cnt2 = j;
                int k = cnt1 + cnt2;

                if (k <= 60) {
                    ll total = 1;
                    if (i + 1 == sz(bef)) {
                        total *= (x.se - bef[i]);
                    } else {
                        total *= (bef[i + 1] - bef[i]);
                    }

                    if (j - 1 >= 0) {
                        total *= after[j] - after[j - 1];
                    } else {
                        total *= after[j] - x.se;
                    }

                    debug(i, j, x, k, total);

                    ans += pw[k + 1] * total * x.fi;
                }

            }
        }

    }
    ans = ans / (1ll * n * n);
    cout << ans << "\n";

}

// CHECK LIMITS (n <= 10^5)
// CHECK CORNER CASES ( n==1)
signed main() {

#ifdef zxc
    freopen("../output.txt", "r", stdin);
    //  freopen("../output.txt", "w", stdout);
#else
#endif //zxc
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout.setf(ios::fixed);
    cout.precision(15);

    int t = 1;
    while (t--) {
        solve();
    }
    debug(1.0 * clock() / CLOCKS_PER_SEC);
}


//
// Created by Ильдар Ялалов on 14.01.2020.
//
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf_int = 1e9 + 100;
const ll inf_ll = 1e18;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef double dbl;
typedef unsigned int uint;
#define pb push_back
#define eb emplace_back
const double pi = 3.1415926535898;
#define dout if(debug) cout
#define fi first
#define se second
#define sp setprecision
#define sz(a) (int(a.size()))
#define mp make_pair
#define all(a) a.begin(),a.end()

#ifdef zxc

#include "debug.h"

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

bool debug = 0;
const int MAXN = (1e6) + 100;
const int LOG = 21;
const int mod = 1e9 + 7;
const int MX = (2e6 + 100);

int a[MAXN];
dbl pw[100];

void solve() {
    int n;
    cin >> n;
    vector<pii> c;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
        c.pb({a[i], i});
    }
    sort(all(c));
    reverse(all(c));
    set<int> ss;
    ss.insert(0);
    ss.insert(n + 1);
    double ans = 0;

    for (int i = 1; i <= 62; ++i) {
        pw[i] = 1.0;
        pw[i] = pw[i] / (1ll << i);
    }
    vector<int> bef;
    vector<int> after;
    for (auto x : c) {
        ss.insert(x.se);
        auto it = ss.lower_bound(x.se);
        bef.clear();
        after.clear();

        auto it1 = it;
        it1--;
        while (sz(bef) < 40) {
            bef.pb(*it1);
            if (it1 == ss.begin())
                break;
            it1--;
        }

        auto it2 = it;
        it2++;
        while (sz(after) < 40) {
            after.pb(*it2);
            it2++;
            if (it2 == ss.end())
                break;
        }

        debug(x.se, bef, after);
        reverse(all(bef));

        for (int i = 0; i < sz(bef); ++i) {
            for (int j = 0; j < sz(after); ++j) {
                int cnt1 = sz(bef) - i - 1;
                int cnt2 = j;
                int k = cnt1 + cnt2;

                if (k <= 60) {
                    ll total = 1;
                    if (i + 1 == sz(bef)) {
                        total *= (x.se - bef[i]);
                    } else {
                        total *= (bef[i + 1] - bef[i]);
                    }

                    if (j - 1 >= 0) {
                        total *= after[j] - after[j - 1];
                    } else {
                        total *= after[j] - x.se;
                    }

                    debug(i, j, x, k, total);

                    ans += pw[k + 1] * total * x.fi;
                }

            }
        }

    }
    ans = ans / (1ll * n * n);
    cout << ans << "\n";

}

// CHECK LIMITS (n <= 10^5)
// CHECK CORNER CASES ( n==1)
signed main() {

#ifdef zxc
    freopen("../output.txt", "r", stdin);
    //  freopen("../output.txt", "w", stdout);
#else
#endif //zxc
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout.setf(ios::fixed);
    cout.precision(15);

    int t = 1;
    while (t--) {
        solve();
    }
    debug(1.0 * clock() / CLOCKS_PER_SEC);
}


#ifdef ONPC
# define _GLIBCXX_DEBUG
#define deb(a) cerr << "nu smotri pidor " << #a << " = " << a << endl;
#else
#define deb(a)
#endif
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;

typedef int ll;
typedef long double ld;
ll MOD = 1e9 + 7;

const int N = 500000;

const int B = 60;

set<ll> sk;

ld pw2[3 * B];

ld solve(ll id){
    sk.insert(id);
    vector<ll> lf;
    vector<ll> rt;
    rt.push_back(0);
    lf.push_back(0);

    auto it = sk.find(id);
    it++;
    while (it != sk.end() && rt.size() < B){
        rt.push_back(*it - id);
        it++;
    }
    auto iter = set<ll>::reverse_iterator(sk.find(id));
    for (; (int)lf.size() <= B && iter != sk.rend(); iter++)
        lf.push_back(id - *iter);
    ld an1 = 0, an2 = 0, an3 = 0;
    for (int i = 1; i < rt.size(); i++){
        an1 += (ld)(rt[i] - rt[i - 1]) * pw2[i - 1];
    }
    for (int i = 1; i < lf.size(); i++){
        an2 += (ld)(lf[i] - lf[i - 1]) * pw2[i - 1];
    }
    an3 = an1 * an2;
    return an3;
}

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0), cout << fixed << setprecision(20);

    pw2[0] = 1;
    for (int i = 1; i < 3 * B; i++){
        pw2[i] = pw2[i - 1] / 2.0;
    }
    ll n;
    cin >> n;
    vector<pair<ll, ll> > a(n);
    for (int i =0 ; i < n; i++){
        cin >> a[i].first;
        a[i].second = i;
    }
    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());
    ld ans = 0;
    sk.insert(-1);
    sk.insert(n);
    for (int i = 0; i < n; i++){
        ans += (ld)a[i].first * solve(a[i].second) / (ld) n / (ld) n;
    }
    cout << ans / 2.0;

#ifdef ONPC
    cerr << endl << "finished in " << clock() * 1.0 / CLOCKS_PER_SEC << " sec" << endl;
#endif
}
//egor lox


/*input
1
1

*/

/*
                                                    ______________
                                                          |       )
                                                          |   )   /
                                                          |______/
                                                    |     |      \
                                                    |     |   )   \
                                                    |_____|_______)

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

using namespace std;

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

#define pb push_back
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
int mod = 1000000007;
const int inf = 1034567891;
const ll LL_INF = 1234567890123456789ll;
#define PI 3.14159265
#define endl '\n'
#define F first
#define S second
#define debug(x) cout << #x << " = " << x << endl;
#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

#define out(container) for (auto it : container) cout << it << " "; cout << endl;

template < typename T > T GCD(T a, T b)            { ll t; while(a) { t = a; a = b % a; b = t; } return b; }
template < typename T > string toString(T a)       { return to_string(a); }
template < typename T > void toInt(string s, T &x) { stringstream str(s); str >> x;}
inline int add(int x, int y){ x += y; if(x >= mod) x -= mod; return x;}
inline int sub(int x, int y){ x -= y; if(x < 0) x += mod; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % mod;}
inline int powr(int a, ll b){
  int x = 1 % mod;
  while(b){
    if(b & 1) x = mul(x, a);
    a = mul(a, a);
    b >>= 1;
  }
  return x;
}
inline int inv(int a){ return powr(a, mod - 2);}

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

  int n, k;
  cin >> n >> k;
  string str;
  cin >> str;
  int maxMove = 0, r = 0;
  for (int i = 0; i < n; i++) {
    if (str[i] == 'L')
      maxMove += r;
    r += (str[i] == 'R');
  }
  if (k > maxMove) {
    cout << -1 << endl;
    return 0;
  }
  vector<int> curPossible;
  for (int i = 0; i < n - 1; i++) {
    if (str[i] == 'R' && str[i + 1] == 'L') {
      curPossible.pb(i);
    }
  }
  vector<vector<int>> ans;
  int done = 0;
  bool ok = false;
  while (1) {
    int m = curPossible.size();
    if (m == 0) break;
    maxMove -= m;
    k--;
    if (!ok && maxMove <= k) {
      int ex = k - maxMove;
      for (int i = 0; i < ex; i++)
        curPossible.pop_back();
      ok = true;
    }
    for (auto it : curPossible) {
      swap(str[it], str[it + 1]);
    }
    vector<int> temp;
    for (int i = 0; i < n - 1; i++) {
      if (str[i] == 'R' && str[i + 1] == 'L') {
        temp.pb(i);
        if (ok) break;
      }
    }
    ans.pb(curPossible);
    curPossible = temp;
  }
  if (k) {
    cout << -1 << endl;
    return 0;
  }
  for (auto it : ans) {
    cout << it.size() << " ";
    for (auto x : it)
      cout << x + 1 << " ";
    cout << endl;
  }

  return 0;
}


/*input
1
1

*/

/*
                                                    ______________
                                                          |       )
                                                          |   )   /
                                                          |______/
                                                    |     |      \
                                                    |     |   )   \
                                                    |_____|_______)

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

using namespace std;

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

#define pb push_back
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
int mod = 1000000007;
const int inf = 1034567891;
const ll LL_INF = 1234567890123456789ll;
#define PI 3.14159265
#define endl '\n'
#define F first
#define S second
#define debug(x) cout << #x << " = " << x << endl;
#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

#define out(container) for (auto it : container) cout << it << " "; cout << endl;

template < typename T > T GCD(T a, T b)            { ll t; while(a) { t = a; a = b % a; b = t; } return b; }
template < typename T > string toString(T a)       { return to_string(a); }
template < typename T > void toInt(string s, T &x) { stringstream str(s); str >> x;}
inline int add(int x, int y){ x += y; if(x >= mod) x -= mod; return x;}
inline int sub(int x, int y){ x -= y; if(x < 0) x += mod; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % mod;}
inline int powr(int a, ll b){
  int x = 1 % mod;
  while(b){
    if(b & 1) x = mul(x, a);
    a = mul(a, a);
    b >>= 1;
  }
  return x;
}
inline int inv(int a){ return powr(a, mod - 2);}

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

  int n, k;
  cin >> n >> k;
  string str;
  cin >> str;
  int maxMove = 0, r = 0;
  for (int i = 0; i < n; i++) {
    if (str[i] == 'L')
      maxMove += r;
    r += (str[i] == 'R');
  }
  if (k > maxMove) {
    cout << -1 << endl;
    return 0;
  }
  vector<int> curPossible;
  for (int i = 0; i < n - 1; i++) {
    if (str[i] == 'R' && str[i + 1] == 'L') {
      curPossible.pb(i);
    }
  }
  vector<vector<int>> ans;
  int done = 0;
  bool ok = false;
  while (1) {
    int m = curPossible.size();
    if (m == 0) break;
    maxMove -= m;
    k--;
    if (maxMove <= k) {
      int ex = k - maxMove;
      for (int i = 0; i < ex && curPossible.size() > 1; i++)
        curPossible.pop_back();
      ok = true;
      for (auto it : curPossible) {
        swap(str[it], str[it + 1]);
      }
      ans.pb(curPossible);
      vector<int> vec;
      for (int i = 0; i < n; i++) {
        if (str[i] == 'L') {
          for (int j = vec.size() - 1; j >= 0; j--) {
            auto &it = vec[j];
            assert(str[it] == 'R');
            ans.pb({it});
            k--;
            swap(str[vec[j]], str[vec[j] + 1]);
            it++;
          }
          if (vec.size()) vec.erase(vec.begin()), vec.pb(i);
        } else {
          vec.pb(i);
        }
      }
      break;
    }
    for (auto it : curPossible) {
      swap(str[it], str[it + 1]);
    }
    vector<int> temp;
    for (int i = 0; i < n - 1; i++) {
      if (str[i] == 'R' && str[i + 1] == 'L') {
        temp.pb(i);
      }
    }
    ans.pb(curPossible);
    curPossible = temp;
  }
  if (k) {
    cout << -1 << endl;
    return 0;
  }
  for (auto it : ans) {
    cout << it.size() << " ";
    for (auto x : it)
      cout << x + 1 << " ";
    cout << endl;
  }

  return 0;
}


/*input
1
1

*/

/*
                                                    ______________
                                                          |       )
                                                          |   )   /
                                                          |______/
                                                    |     |      \
                                                    |     |   )   \
                                                    |_____|_______)

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

using namespace std;

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

#define pb push_back
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
int mod = 1000000007;
const int inf = 1034567891;
const ll LL_INF = 1234567890123456789ll;
#define PI 3.14159265
#define endl '\n'
#define F first
#define S second
#define debug(x) cout << #x << " = " << x << endl;
#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

#define out(container) for (auto it : container) cout << it << " "; cout << endl;

template < typename T > T GCD(T a, T b)            { ll t; while(a) { t = a; a = b % a; b = t; } return b; }
template < typename T > string toString(T a)       { return to_string(a); }
template < typename T > void toInt(string s, T &x) { stringstream str(s); str >> x;}
inline int add(int x, int y){ x += y; if(x >= mod) x -= mod; return x;}
inline int sub(int x, int y){ x -= y; if(x < 0) x += mod; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % mod;}
inline int powr(int a, ll b){
  int x = 1 % mod;
  while(b){
    if(b & 1) x = mul(x, a);
    a = mul(a, a);
    b >>= 1;
  }
  return x;
}
inline int inv(int a){ return powr(a, mod - 2);}

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

  int n, k;
  cin >> n >> k;
  string str;
  cin >> str;
  int maxMove = 0, r = 0;
  for (int i = 0; i < n; i++) {
    if (str[i] == 'L')
      maxMove += r;
    r += (str[i] == 'R');
  }
  if (k > maxMove) {
    cout << -1 << endl;
    return 0;
  }
  vector<int> curPossible;
  for (int i = 0; i < n - 1; i++) {
    if (str[i] == 'R' && str[i + 1] == 'L') {
      curPossible.pb(i);
    }
  }
  vector<vector<int>> ans;
  int done = 0;
  bool ok = false;
  while (1) {
    int m = curPossible.size();
    if (m == 0) break;
    maxMove -= m;
    k--;
    if (!ok && maxMove <= k) {
      int ex = k - maxMove;
      for (int i = 0; i < ex; i++)
        curPossible.pop_back();
      ok = true;
    }
    for (auto it : curPossible) {
      swap(str[it], str[it + 1]);
    }
    vector<int> temp;
    for (auto i : curPossible) {
      if (str[i] == 'R' && str[i + 1] == 'L') {
        temp.pb(i);
        if (ok) break;
      }
    }
    if (temp.size() == 0) {
      for (int i = 0; i < n - 1; i++) {
        if (str[i] == 'R' && str[i + 1] == 'L') {
          temp.pb(i);
          if (ok) break;
        }
      }
    }
    ans.pb(curPossible);
    curPossible = temp;
  }
  if (k) {
    cout << -1 << endl;
    return 0;
  }
  for (auto it : ans) {
    cout << it.size() << " ";
    for (auto x : it)
      cout << x + 1 << " ";
    cout << endl;
  }

  return 0;
}


/*input
1
1

*/

/*
                                                    ______________
                                                          |       )
                                                          |   )   /
                                                          |______/
                                                    |     |      \
                                                    |     |   )   \
                                                    |_____|_______)

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

using namespace std;

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

#define pb push_back
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
int mod = 1000000007;
const int inf = 1034567891;
const ll LL_INF = 1234567890123456789ll;
#define PI 3.14159265
#define endl '\n'
#define F first
#define S second
#define debug(x) cout << #x << " = " << x << endl;
#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

#define out(container) for (auto it : container) cout << it << " "; cout << endl;

template < typename T > T GCD(T a, T b)            { ll t; while(a) { t = a; a = b % a; b = t; } return b; }
template < typename T > string toString(T a)       { return to_string(a); }
template < typename T > void toInt(string s, T &x) { stringstream str(s); str >> x;}
inline int add(int x, int y){ x += y; if(x >= mod) x -= mod; return x;}
inline int sub(int x, int y){ x -= y; if(x < 0) x += mod; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % mod;}
inline int powr(int a, ll b){
  int x = 1 % mod;
  while(b){
    if(b & 1) x = mul(x, a);
    a = mul(a, a);
    b >>= 1;
  }
  return x;
}
inline int inv(int a){ return powr(a, mod - 2);}

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

  int n, k;
  cin >> n >> k;
  string str;
  cin >> str;
  int maxMove = 0, r = 0;
  for (int i = 0; i < n; i++) {
    if (str[i] == 'L')
      maxMove += r;
    r += (str[i] == 'R');
  }
  if (k > maxMove) {
    cout << -1 << endl;
    return 0;
  }
  vector<int> curPossible;
  for (int i = 0; i < n - 1; i++) {
    if (str[i] == 'R' && str[i + 1] == 'L') {
      curPossible.pb(i);
    }
  }
  vector<vector<int>> ans;
  int done = 0;
  bool ok = false;
  while (1) {
    int m = curPossible.size();
    if (m == 0) break;
    maxMove -= m;
    k--;
    if (!ok && maxMove <= k) {
      int ex = k - maxMove;
      for (int i = 0; i < ex; i++)
        curPossible.pop_back();
      ok = true;
      for (auto it : curPossible) {
        swap(str[it], str[it + 1]);
      }
      ans.pb(curPossible);
      vector<int> vec;
      for (int i = 0; i < n; i++) {
        if (str[i] == 'L') {
          for (auto &it : vec) {
            ans.pb({it});
            it++;
          }
          if (vec.size()) vec.erase(vec.begin()), vec.pb(i);
        } else {
          vec.pb(i);
        }
      }
      k = 0;
      break;
    }
    for (auto it : curPossible) {
      swap(str[it], str[it + 1]);
    }
    vector<int> temp;
    for (auto i : curPossible) {
      if (str[i] == 'R' && str[i + 1] == 'L') {
        temp.pb(i);
      }
    }
    ans.pb(curPossible);
    curPossible = temp;
  }
  if (k) {
    cout << -1 << endl;
    return 0;
  }
  for (auto it : ans) {
    cout << it.size() << " ";
    for (auto x : it)
      cout << x + 1 << " ";
    cout << endl;
  }

  return 0;
}


/*input
1
1

*/

/*
                                                    ______________
                                                          |       )
                                                          |   )   /
                                                          |______/
                                                    |     |      \
                                                    |     |   )   \
                                                    |_____|_______)

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

using namespace std;

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

#define pb push_back
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
int mod = 1000000007;
const int inf = 1034567891;
const ll LL_INF = 1234567890123456789ll;
#define PI 3.14159265
#define endl '\n'
#define F first
#define S second
#define debug(x) cout << #x << " = " << x << endl;
#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

#define out(container) for (auto it : container) cout << it << " "; cout << endl;

template < typename T > T GCD(T a, T b)            { ll t; while(a) { t = a; a = b % a; b = t; } return b; }
template < typename T > string toString(T a)       { return to_string(a); }
template < typename T > void toInt(string s, T &x) { stringstream str(s); str >> x;}
inline int add(int x, int y){ x += y; if(x >= mod) x -= mod; return x;}
inline int sub(int x, int y){ x -= y; if(x < 0) x += mod; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % mod;}
inline int powr(int a, ll b){
  int x = 1 % mod;
  while(b){
    if(b & 1) x = mul(x, a);
    a = mul(a, a);
    b >>= 1;
  }
  return x;
}
inline int inv(int a){ return powr(a, mod - 2);}

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

  int n, k;
  cin >> n >> k;
  string str;
  cin >> str;
  int maxMove = 0, r = 0;
  for (int i = 0; i < n; i++) {
    if (str[i] == 'L')
      maxMove += r;
    r += (str[i] == 'R');
  }
  if (k > maxMove) {
    cout << -1 << endl;
    return 0;
  }
  vector<int> curPossible;
  for (int i = 0; i < n - 1; i++) {
    if (str[i] == 'R' && str[i + 1] == 'L') {
      curPossible.pb(i);
    }
  }
  vector<vector<int>> ans;
  int done = 0;
  bool ok = false;
  while (1) {
    int m = curPossible.size();
    if (m == 0) break;
    maxMove -= m;
    k--;
    if (maxMove <= k) {
      int ex = k - maxMove;
      for (int i = 0; i < ex && curPossible.size() > 1; i++)
        curPossible.pop_back();
      ok = true;
      for (auto it : curPossible) {
        swap(str[it], str[it + 1]);
      }
      ans.pb(curPossible);
      vector<int> vec;
      for (int i = 0; i < n; i++) {
        if (str[i] == 'L') {
          for (int j = vec.size() - 1; j >= 0; j--) {
            auto &it = vec[j];
            ans.pb({it});
            k--;
            swap(str[vec[j]], str[vec[j] + 1]);
            it++;
          }
        } else {
          vec.pb(i);
        }
      }
      break;
    }
    for (auto it : curPossible) {
      swap(str[it], str[it + 1]);
    }
    vector<int> temp;
    for (int i = 0; i < n - 1; i++) {
      if (str[i] == 'R' && str[i + 1] == 'L') {
        temp.pb(i);
      }
    }
    ans.pb(curPossible);
    curPossible = temp;
  }
  if (k) {
    cout << -1 << endl;
    return 0;
  }
  for (auto it : ans) {
    cout << it.size() << " ";
    for (auto x : it)
      cout << x + 1 << " ";
    cout << endl;
  }

  return 0;
}


/*input
1
1

*/

/*
                                                    ______________
                                                          |       )
                                                          |   )   /
                                                          |______/
                                                    |     |      \
                                                    |     |   )   \
                                                    |_____|_______)

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

using namespace std;

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

#define pb push_back
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
int mod = 1000000007;
const int inf = 1034567891;
const ll LL_INF = 1234567890123456789ll;
#define PI 3.14159265
#define endl '\n'
#define F first
#define S second
#define debug(x) cout << #x << " = " << x << endl;
#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

#define out(container) for (auto it : container) cout << it << " "; cout << endl;

template < typename T > T GCD(T a, T b)            { ll t; while(a) { t = a; a = b % a; b = t; } return b; }
template < typename T > string toString(T a)       { return to_string(a); }
template < typename T > void toInt(string s, T &x) { stringstream str(s); str >> x;}
inline int add(int x, int y){ x += y; if(x >= mod) x -= mod; return x;}
inline int sub(int x, int y){ x -= y; if(x < 0) x += mod; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % mod;}
inline int powr(int a, ll b){
  int x = 1 % mod;
  while(b){
    if(b & 1) x = mul(x, a);
    a = mul(a, a);
    b >>= 1;
  }
  return x;
}
inline int inv(int a){ return powr(a, mod - 2);}

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

  int n, k;
  cin >> n >> k;
  string str;
  cin >> str;
  int maxMove = 0, r = 0;
  for (int i = 0; i < n; i++) {
    if (str[i] == 'L')
      maxMove += r;
    r += (str[i] == 'R');
  }
  if (k > maxMove) {
    cout << -1 << endl;
    return 0;
  }
  vector<int> curPossible;
  for (int i = 0; i < n - 1; i++) {
    if (str[i] == 'R' && str[i + 1] == 'L') {
      curPossible.pb(i);
    }
  }
  vector<vector<int>> ans;
  int done = 0;
  bool ok = false;
  while (1) {
    int m = curPossible.size();
    if (m == 0) break;
    maxMove -= m;
    k--;
    if (!ok && maxMove <= k) {
      int ex = k - maxMove;
      for (int i = 0; i < ex; i++)
        curPossible.pop_back();
      ok = true;
      for (auto it : curPossible) {
        swap(str[it], str[it + 1]);
      }
      ans.pb(curPossible);
      vector<int> vec;
      for (int i = 0; i < n; i++) {
        if (str[i] == 'L') {
          for (auto &it : vec) {
            ans.pb({it});
            k--;
            it++;
          }
          if (vec.size()) vec.erase(vec.begin()), vec.pb(i);
        } else {
          vec.pb(i);
        }
      }
      break;
    }
    for (auto it : curPossible) {
      swap(str[it], str[it + 1]);
    }
    vector<int> temp;
    for (auto i : curPossible) {
      i--;
      if (i >= 0 && str[i] == 'R' && str[i + 1] == 'L') {
        temp.pb(i);
      }
      i += 2;
      if (i >= 0 && str[i] == 'R' && str[i + 1] == 'L') {
        temp.pb(i);
      }
    }
    ans.pb(curPossible);
    curPossible = temp;
  }
  if (k) {
    cout << -1 << endl;
    return 0;
  }
  for (auto it : ans) {
    cout << it.size() << " ";
    for (auto x : it)
      cout << x + 1 << " ";
    cout << endl;
  }

  return 0;
}


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

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    vector<vector<int>> ans;
    int maxmoves = 0;
    while (true)
    {
        ans.push_back(vector<int>());
        for (int i = 0; i < n - 1; i++)
        {
            if (s[i + 1] == 'L' && s[i] == 'R')
            {
                s[i] = 'L';
                s[i + 1] = 'R';
                ans.back().push_back(i);
                i++;
            }
        }
        maxmoves += ans.back().size();
        if (ans.back().empty())
        {
            ans.pop_back();
            break;
        }
    }
    if (k < ans.size() || k > maxmoves)
    {
        cout << -1 << endl;
        return 0;
    }
    int minmoves = ans.size();

    for (auto i : ans)
    {
        vector<int> temp;
        for (int j : i)
        {
            if (minmoves < k)
            {
                cout << 1 << " " << j + 1 << endl;
                minmoves++;
            }
            else
                temp.push_back(j);
        }
        if (!temp.empty())
        {
            cout << temp.size() << " ";
            for (int j : temp)
            {
                cout << j + 1 << " ";
            }
            cout << endl;
        }
        else
            minmoves--;
    }
}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
typedef long double ld;
#define N 3005
#define mp make_pair
#define v vector
#define pb push_back
#define fi first
#define se second
#define ALL(v) v.begin(), v.end()
#define UN(v) sort((v).begin(), (v).end()), v.erase(unique(v.begin(), v.end()), v.end())
string s;
ll n, k;
v<v<ll>> ans;
signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> k;
    cin >> s;
    ll maxmoves = 0;
    while (true)
    {
        ans.pb(v<ll>());
        for (ll i = 1; i < n; i++)
        {
            if (s[i] == 'L' && s[i - 1] == 'R')
            {
                s[i - 1] = 'L';
                s[i] = 'R';
                ans.back().pb(i - 1);
                i++;
            }
        }
        maxmoves += ans.back().size();
        if (ans.back().empty())
        {
            ans.pop_back();
            break;
        }
    }
    ll minmoves = ans.size();
    if (k < minmoves || k > maxmoves)
    {
        cout << -1 << endl;
        return 0;
    }
    for (auto i : ans)
    {
        v<ll> temp;
        for (auto j : i)
        {
            if (minmoves < k)
            {
                cout << 1 << " " << j + 1 << endl;
                minmoves++;
            }
            else
                temp.pb(j);
        }
        if (!temp.empty())
        {
            cout << temp.size() << " ";
            for (auto j : temp)
            {
                cout << j + 1 << " ";
            }
            cout << endl;
        }
        else
            minmoves--;
    }
}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
typedef long double ld;
#define N 3005
#define mp make_pair
#define v vector
#define pb push_back
#define fi first
#define se second
#define ALL(v) v.begin(), v.end()
#define UN(v) sort((v).begin(), (v).end()), v.erase(unique(v.begin(), v.end()), v.end())
string s;
ll n, k;
v<v<ll>> ans(3000004);
v<ll> ind(N);
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> n >> k;
    cin >> s;
    ll temp1 = k;
    ll counter = 0, c1 = 0;
    ll maxmoves = 0, minmoves = 0, lastind = 0, moves = 0;
    for (ll i = 0; i < n; i++)
    {
        if (s[i] == 'L')
        {
            counter++;
            maxmoves += i - counter + 1;
            if (i != counter - 1)
            {
                ind[i] = counter - 1;
                minmoves = max(minmoves + 1, i - counter + 1);
                lastind = i;
            }
        }
    }
    // cout << maxmoves << " " << minmoves << endl;

    if (k < minmoves || k > maxmoves)
    {
        cout << -1 << endl;
        return 0;
    }
    for (ll i = 1; i < n; i++)
    {
        if (s[i] == 'L' && s[i - 1] == 'R')
        {
            c1++;
        }
    }
    while (maxmoves != k)
    {
        moves++;
        k--;
        string s1 = s;
        if (maxmoves - c1 > k)
        {
            ans[moves].pb(c1);
            for (ll i = 1; i < n; i++)
            {
                if (s1[i] == 'L' && s1[i - 1] == 'R')
                {
                    ans[moves].pb(i - 1);
                    s[i] = 'R';
                    s[i - 1] = 'L';
                }
            }
            maxmoves -= c1;
        }
        else
        {
            ans[moves].pb(maxmoves - k);
            ll c2 = 0;
            for (ll i = 1; i < n && (c2 < maxmoves - k); i++)
            {
                if (s1[i] == 'L' && s1[i - 1] == 'R')
                {
                    ans[moves].pb(i - 1);
                    s[i] = 'R';
                    s[i - 1] = 'L';
                    c2++;
                }
            }
            maxmoves = k;
            break;
        }
        c1 = 0;
        for (ll i = 1; i < n; i++)
        {
            if (s[i] == 'L' && s[i - 1] == 'R')
            {
                c1++;
            }
        }
        // cout << s << endl;
    }
    counter = s[0] == 'L' ? 1 : 0;
    for (ll i = 1; i < n; i++)
    {
        if (s[i] == 'L')
            counter++;
        if (s[i] == 'L' && s[i - 1] == 'R')
        {
            ll temp = counter;
            s[i] = 'R';
            s[temp - 1] = 'L';
            for (ll j = i - 1; j >= temp - 1; j--)
            {
                ans[++moves].pb(1);
                ans[moves].pb(j);
                // cout << j << " " << moves << endl;
            }
        }
    }
    // cout << s<<endl;
    for (ll i = 1; i <= temp1; i++)
    {
        // cout << i << " ";
        for (ll j = 0; j < ans[i].size(); j++)
        {
            if (j >= 1)
                cout << ans[i][j] + 1 << " ";
            else
                cout << ans[i][j] << " ";
        }
        cout << endl;
    }
}


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

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    vector<vector<int>> res;
    int sum = 0;
    while (true)
    {
        res.push_back(vector<int>());
        for (int i = 0; i < n - 1; i++)
        {
            if (s[i + 1] == 'L' && s[i] == 'R')
            {
                s[i] = 'L';
                s[i + 1] = 'R';
                res.back().push_back(i);
                i++;
            }
        }
        sum += res.back().size();
        if (res.back().empty())
        {
            res.pop_back();
            break;
        }
    }
    if (k < res.size() || k > sum)
    {
        cout << -1 << endl;
        return 0;
    }
    int cur = res.size();

    for (auto &i : res)
    {
        vector<int> last;
        for (int j : i)
        {
            if (cur < k)
            {
                cout << 1 << " " << j + 1 << endl;
                cur++;
            }
            else
                last.push_back(j);
        }
        if (!last.empty())
        {
            cout << last.size() << " ";
            for (int j : last)
            {
                cout << j + 1 << " ";
            }
            cout << endl;
        }
        else
            cur--;
    }
}