import java . io . * ; import java . util . * ;   public class B { static int [ ] valid = new int [ ] { 0 , 1 , 5 , - 1 , - 1 , 2 , - 1 , - 1 , 8 , - 1 } ; public static int reverse ( int time ) { int reversed = 0 ; for ( int i = 0 ; i < 2 ; i ++ ) { int dig = time % 10 ; if ( valid [ dig ] == - 1 ) { return - 1 ; } reversed = reversed * 10 + valid [ dig ] ; time /= 10 ; } return reversed ; } public static void main ( String [ ] args ) {


p = { '5' : '2' , '2' : '5' , '1' : '1' , '0' : '0' , '8' : '8' } NEW_LINE for _ in range ( int ( input ( ) ) ) : h , m = [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE a , b = input ( ) . split ( " : " ) NEW_LINE for _ in range ( 50000 ) : if NEW_LINE any ( e not in p for e in a + b ) : NEW_LINE if int ( b ) == m - 1 : if NEW_LINE int ( a ) != h - 1 : a = '0' * ( a [ 0 ] == '0' ) * ( a [ 1 ] < '9' ) + str ( int ( a ) + 1 ) NEW_LINE b = '00' NEW_LINE continue else : a = '00' NEW_LINE b = '00' NEW_LINE continue else : b = '0' * ( b [ 0 ] == '0' ) * ( b [ 1 ] < '9' ) + str ( int ( b ) + 1 ) NEW_LINE continue else : if int ( p [ b [ 1 ] ] + p [ b [ 0 ] ] ) < h and int ( p [ a [ 1 ] ] + p [ a [ 0 ] ] ) < m : print ( a + " : " + b ) NEW_LINE break else : if int ( b ) == m - 1 : if NEW_LINE int ( a ) != h - 1 : a = '0' * ( a [ 0 ] == '0' ) * ( a [ 1 ] < '9' ) + str ( int ( a ) + 1 ) NEW_LINE b = '00' NEW_LINE continue else : a = '00' NEW_LINE b = '00' NEW_LINE continue else : b = '0' * ( b [ 0 ] == '0' ) * ( b [ 1 ] < '9' ) + str ( int ( b ) + 1 ) NEW_LINE continue NEW_LINE


import sysimport NEW_LINE itertoolsimport NEW_LINE collections   NEW_LINE def rs ( x = ' ' ) : if NEW_LINE len ( x ) == 0 : NEW_LINE return sys . stdin . readline ( ) . strip ( ) NEW_LINE return input ( x ) . strip ( )   NEW_LINE def ri ( x = ' ' ) : return int ( rs ( x ) ) NEW_LINE def rm ( x = ' ' ) : return map ( str , rs ( x ) . split ( ) ) NEW_LINE def rl ( x = ' ' ) : return rs ( x ) . split ( ) NEW_LINE def rmi ( x = ' ' ) : return map ( int , rl ( x ) ) NEW_LINE def rli ( x = ' ' ) : return [ int ( val ) for val in rl ( x ) ] NEW_LINE def println ( val ) : sys . stdout . write ( str ( val ) + ' \n ' ) NEW_LINE   NEW_LINE def mirror ( val ) : mirrored = [ 0 , 1 , 5 , - 1 , - 1 , 2 , - 1 , - 1 , 8 , - 1 ] NEW_LINE a , b = val // 10 , val % 10 NEW_LINE if mirrored [ a ] == - 1 or mirrored [ b ] == - 1 : return - 1 NEW_LINE return mirrored [ b ] * 10 + mirrored [ a ]   NEW_LINE def solve ( testCase ) : h , m = rmi ( ) NEW_LINE time = rs ( ) NEW_LINE hour , minute = time [ : 2 ] , time [ 3 : ] NEW_LINE hour = int ( hour ) * m + int ( minute ) NEW_LINE while True : h2 , m2 = mirror ( hour // m % h ) , mirror ( hour % m ) NEW_LINE h2 , m2 = m2 , h2 NEW_LINE if h2 >= 0 and m2 >= 0 and h2 < h and m2 < m : break NEW_LINE hour += 1 NEW_LINE h = hour // m % h NEW_LINE m = hour % m NEW_LINE ans = [ ] NEW_LINE if h < 10 : ans += [ '0' ] NEW_LINE ans += [ str ( h ) , ' : ' ] NEW_LINE if m < 10 : ans += [ '0' ] NEW_LINE ans += [ str ( m ) ] NEW_LINE


import sys , mathimport NEW_LINE heapq   from collections import NEW_LINE INDENT dequeinput = sys . stdin . readline   NEW_LINE DEDENT


def inpl ( ) : return list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE   NEW_LINE def inpi ( ) : return int ( input ( ) ) NEW_LINE   r = { '0' : '0' , '1' : '1' , '2' : '5' , '5' : '2' , '8' : '8' , ' : ' : ' : ' } NEW_LINE def refl ( d ) : if NEW_LINE d in r : NEW_LINE return r [ d ] else : return ' x '   NEW_LINE def to_h ( h , m ) : rr = '0' if h < 10 else ' ' NEW_LINE rr += str ( h ) NEW_LINE rr += ' : ' NEW_LINE rr += '0' if m < 10 else ' ' NEW_LINE rr += str ( m ) NEW_LINE return rr   NEW_LINE def from_h ( h ) : return list ( map ( int , h . split ( ' : ' ) ) ) NEW_LINE   NEW_LINE def mirror ( h ) : return ' ' . join ( [ refl ( d ) for d in h [ : : - 1 ] ] ) NEW_LINE   NEW_LINE def is_mirror ( h ) : return mirror ( h ) == h NEW_LINE   NEW_LINE def is_legal ( ch , cm , h , m ) : return ch < h and cm < m NEW_LINE   NEW_LINE def inc ( ch , cm , h , m ) : cm += 1 NEW_LINE ch += cm // m NEW_LINE cm = cm % m NEW_LINE ch = ch % h NEW_LINE return ch , cm   NEW_LINE def f ( ) : h , m = inpl ( ) NEW_LINE sh , sm = list ( map ( int , input ( ) . split ( ' : ' ) ) ) NEW_LINE while True : st = to_h ( sh , sm ) NEW_LINE mt = mirror ( st ) NEW_LINE


import java . util . * ; import java . math . * ; public class SortTheArray { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int runs = sc . nextInt ( ) ; while ( runs -- > 0 ) { int h = sc . nextInt ( ) ; int m = sc . nextInt ( ) ; String [ ] in = sc . next ( ) . split ( " : " ) ; int hour = Integer . parseInt ( in [ 0 ] ) ; int minute = Integer . parseInt ( in [ 1 ] ) ; while ( true ) { if ( works ( h , m , hour , minute ) ) break ; minute ++ ; if ( minute == m ) { minute = 0 ; hour ++ ; } if ( hour == h ) hour = 0 ; } if ( hour < 10 ) System . out . print ( "0" + hour ) ; else System . out . print ( hour ) ; System . out . print ( " : " ) ; if ( minute < 10 ) System . out . print ( "0" + minute ) ; else System . out . print ( minute ) ; System . out . println ( ) ;

def check ( curr ) : ones , tens = curr % 10 , curr // 10 NEW_LINE if ones in d and tens in d : return d [ ones ] * 10 + d [ tens ] NEW_LINE return 10 ** 5 NEW_LINE d = { 1 : 1 , 2 : 5 , 5 : 2 , 8 : 8 , 0 : 0 } NEW_LINE for _ in range ( int ( input ( ) ) ) : h , m = map ( int , input ( ) . split ( ) ) NEW_LINE x , y = map ( int , input ( ) . split ( " : " ) ) NEW_LINE while True : if NEW_LINE check ( x ) < m and check ( y ) < h : NEW_LINE break NEW_LINE y += 1 NEW_LINE if y == m : y = 0 NEW_LINE x = ( x + 1 ) % h NEW_LINE print ( str ( x ) . rjust ( 2 , "0" ) + " : " + str ( y ) . rjust ( 2 , "0" ) ) NEW_LINE


import java . util . * ; import java . io . * ; import java . text . DecimalFormat ;    public class pplanet {    static DecimalFormat df1 = new DecimalFormat ( " # .000000" ) ; static DecimalFormat df = new DecimalFormat ( " # . # # # # # # " ) ; static boolean printing = false ;   static int N ;   static int total = 0 ;    public static void main ( String [ ] args ) throws Exception { BufferedReader in = new BufferedReader ( new InputStreamReader ( System . in ) ) ;


import java . io . * ; import java . util . * ; import java . util . stream . Stream ;    public class A { static final int INF = ( int ) 1e9 + 9 ; static final int MAXN = ( int ) 1e5 + 5 ; static final int MAXLOG = ( int ) ( Math . log ( MAXN ) / Math . log ( 2 ) + 1e-10 ) + 1 ; static final int MOD = 1_000_000_007 ;   static BufferedWriter out = new BufferedWriter ( new OutputStreamWriter ( System . out ) ) ; static Reader in = new Reader ( ) ;   static List < Character > validRef = Arrays . asList ( '0' , '1' , '2' , '5' , '8' ) ;   public static void main ( String [ ] args ) throws IOException { Scanner in = new Scanner ( System . in ) ;


import java . util . Scanner ;   public class BitPlusPlus {   public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int am = scanner . nextInt ( ) ; int x = 0 ; for ( int i = 0 ; i < am ; i ++ ) { String line = scanner . next ( ) ; if ( line . contains ( " + + " ) ) x ++ ; else x -- ; } System . out . println ( x ) ; }   }

test = int ( input ( ) ) total = 0 for i in range ( test ) : s = input ( ) if s . count ( " + " ) == 2 : total += 1 elif s . count ( " - " ) == 2 : total -= 1 print ( total ) NEW_LINE


n = int ( input ( ) ) count = 0 while ( n > 0 ) : n -= 1 strr = str ( input ( ) ) if ( ' - - ' in strr ) : count -= 1 else : count += 1 print ( count ) NEW_LINE


n = int ( input ( ) ) x = 0 for i in range ( n ) : bit_operation = input ( ) if bit_operation == " X + + " or bit_operation == " + + X " : x = x + 1 elif bit_operation == " X - - " or bit_operation == " - - X " : x = x - 1 print ( x ) NEW_LINE


import java . util . Scanner ;   public class BitPlusPlus { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int n = scanner . nextInt ( ) ; scanner . nextLine ( ) ; int res = 0 ; for ( int i = 0 ; i < n ; i ++ ) { String line = scanner . nextLine ( ) ; if ( line . contains ( " + " ) ) { res ++ ; } else { res -- ; } }   System . out . println ( res ) ; } }


import java . io . * ; import java . util . * ; import java . lang . * ; public class Solution { public static void main ( String args [ ] ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int c = 0 ; while ( n -- > 0 ) { String s = sc . next ( ) ; if ( s . contains ( " + " ) ) c ++ ; else c -- ; } System . out . println ( c ) ; } }


import java . util . Scanner ;   public class Bit { public static void main ( String [ ] args ) { Scanner s = new Scanner ( System . in ) ; int n = s . nextInt ( ) ; int result = 0 ; for ( int i = 0 ; i < n ; i ++ ) { String str = s . next ( ) ; if ( str . equals ( " X + + " ) || str . equals ( " + + X " ) ) { result = result + 1 ; } else { result = result - 1 ; } } System . out . println ( result ) ; } }


import java . io . * ; import java . util . * ; import java . lang . * ; import java . util . Random ; public class Main { public static void main ( String [ ] args ) throws java . lang . Exception { Scanner scan = new Scanner ( System . in ) ; int repeat = scan . nextInt ( ) ; int val = 0 ; while ( repeat -- > 0 ) { String test = scan . next ( ) . trim ( ) ; if ( test . equals ( " + + X " ) || test . equals ( " X + + " ) ) val ++ ; else if ( test . equals ( " - - X " ) || test . equals ( " X - - " ) ) val -- ; } System . out . println ( val ) ; } }


import java . io . * ; import java . util . * ; public class asd {   public static void main ( String args [ ] ) throws Exception { PrintWriter output = new PrintWriter ( " output . txt " ) ; Scanner s = new Scanner ( new File ( " input . txt " ) ) ; int ball = s . nextInt ( ) ; int i = 3 ; while ( i -- > 0 ) { int a = s . nextInt ( ) ; int b = s . nextInt ( ) ; if ( a == ball ) { ball = b ; } else if ( b == ball ) { ball = a ; } } output . println ( ball ) ; output . flush ( ) ; } }

import syssys . stdin = open ( " input . txt " , " r " ) sys . stdout = open ( " output . txt " , " w " ) n = int ( input ( ) ) for i in range ( 3 ) : u , v = map ( int , input ( ) . split ( ) ) if ( u == n ) : n = v elif ( v == n ) : n = uprint ( n ) NEW_LINE


rfile = open ( ' input . txt ' , ' r ' ) maintxt = rfile . read ( ) . split ( ' \n ' ) rfile . close ( ) pos = int ( maintxt [ 0 ] ) for i in range ( 1 , 4 ) : temp = maintxt [ i ] . split ( ' ▁ ' ) cup1 , cup2 = int ( temp [ 0 ] ) , int ( temp [ 1 ] ) if pos == cup1 : pos = cup2 elif pos == cup2 : pos = cup1wfile = open ( ' output . txt ' , ' w ' ) wfile . write ( str ( pos ) )         NEW_LINE


rfile = open ( ' input . txt ' , ' r ' ) maintxt = rfile . read ( ) . split ( ' \n ' ) rfile . close ( ) pos = int ( maintxt [ 0 ] ) for i in range ( 1 , 4 ) : temp = maintxt [ i ] . split ( ' ▁ ' ) cup1 , cup2 = int ( temp [ 0 ] ) , int ( temp [ 1 ] ) if pos == cup1 : pos = cup2 elif pos == cup2 : pos = cup1wfile = open ( ' output . txt ' , ' w ' ) wfile . write ( str ( pos ) ) NEW_LINE


reFile = open ( ' input . txt ' , ' r ' ) pos = int ( reFile . readline ( ) )   for i in range ( 3 ) : cup1 , cup2 = [ int ( item ) for item in reFile . readline ( ) . split ( ' ▁ ' ) ] if cup1 == pos : pos = cup2 elif cup2 == pos : pos = cup1reFile . close ( )   wFile = open ( ' output . txt ' , ' w ' ) wFile . write ( str ( pos ) ) wFile . close ( ) NEW_LINE


import java . io . File ; import java . io . FileNotFoundException ; import java . io . PrintWriter ; import java . util . Arrays ; import java . util . Scanner ; import java . util . Stack ;   public class test {   public static void main ( String [ ] args ) throws FileNotFoundException {


import java . io . File ; import java . io . FileNotFoundException ; import java . io . FileWriter ; import java . io . IOException ; import java . util . Scanner ;   public class codeforces { public static void main ( String [ ] args ) throws FileNotFoundException { Scanner in = new Scanner ( new File ( " input . txt " ) ) ; int res = in . nextInt ( ) ; in . nextLine ( ) ; for ( int i = 0 ; i < 3 ; i ++ ) { int a = in . nextInt ( ) ; int b = in . nextInt ( ) ; in . nextLine ( ) ; if ( a == res ) { res = b ; } else if ( b == res ) { res = a ; } } System . out . println ( res ) ; try { FileWriter myWriter = new FileWriter ( " output . txt " ) ; myWriter . write ( String . valueOf ( res ) ) ; myWriter . close ( ) ; } catch ( IOException e ) { System . out . println ( " An ▁ error ▁ occurred . " ) ; e . printStackTrace ( ) ; } } }


import java . io . * ; import java . util . * ; public class B { public static void main ( String [ ] args ) throws Throwable { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; PrintWriter pw = new PrintWriter ( System . out , true ) ; Scanner sc = new Scanner ( System . in ) ; int t = sc . nextInt ( ) ; while ( t -- > 0 ) { int n = sc . nextInt ( ) ; int min = 1 , max = n ; if ( n > 1 ) { pw . printf ( " ? ▁ % d ▁ % d \n " , 1 , n ) ; pw . flush ( ) ; char c = sc . next ( ) . charAt ( 0 ) ; if ( c == ' > ' ) { min = n ; max = 1 ; } int s = 2 , e = n - 1 ; while ( s <= e ) { int min1 = s , max1 = e ; if ( s != e ) { pw . printf ( " ? ▁ % d ▁ % d \n " , s , e ) ; pw . flush ( ) ; c = sc . next ( ) . charAt ( 0 ) ; if ( c == ' > ' ) { min1 = e ; max1 = s ; } } pw . printf ( " ? ▁ % d ▁ % d \n " , min1 , min ) ; pw . flush ( ) ; c = sc . next ( ) . charAt ( 0 ) ; if ( c == ' < ' ) min = min1 ; pw . printf ( " ? ▁ % d ▁ % d \n " , max1 , max ) ; pw . flush ( ) ; c = sc . next ( ) . charAt ( 0 ) ; if ( c == ' > ' ) max = max1 ; s ++ ; e -- ; } } pw . printf ( " ! ▁ % d ▁ % d \n " , min , max ) ; pw . flush ( ) ; } pw . flush ( ) ; pw . close ( ) ; } }

from collections import defaultdictfor ik in range ( int ( input ( ) ) ) : n = int ( input ( ) ) d = defaultdict ( str ) if n == 1 : print ( " ! ▁ 1 ▁ 1" , flush = True ) continue elif n == 2 : print ( " ? ▁ 1 ▁ 2" , flush = True ) s = input ( ) if s == " > " : print ( " ! ▁ 2 ▁ 1" , flush = True ) else : print ( " ! ▁ 1 ▁ 2" , flush = True ) continue last = [ i for i in range ( 1 , n + 1 ) ] res = [ ] while ( len ( last ) != 1 ) : for i in range ( len ( last ) // 2 ) : print ( " ? " , last [ 2 * i ] , last [ 2 * i + 1 ] , flush = True ) r = input ( ) d [ ( last [ 2 * i ] , last [ 2 * i + 1 ] ) ] = r if r == ' > ' : res . append ( last [ 2 * i ] ) else : res . append ( last [ 2 * i + 1 ] ) if len ( last ) % 2 == 1 : res . append ( last [ - 1 ] ) last = res + [ ] res = [ ] max = last [ 0 ] NEW_LINE


import sysT = int ( input ( ) ) def compare ( l , r , arr ) : print ( ' ? ' , a [ l ] + 1 , a [ r ] + 1 ) sys . stdout . flush ( ) res = input ( ) if ( res == ' > ' ) : return 1 ; else : return 0 ;   while ( T > 0 ) : T -= 1 Max_a = [ ] Min_a = [ ] n = int ( input ( ) ) a = range ( n ) for i in range ( int ( n / 2 ) ) : if ( compare ( i * 2 , i * 2 + 1 , a ) > 0 ) : Max_a . append ( i * 2 ) Min_a . append ( i * 2 + 1 ) else : Max_a . append ( i * 2 + 1 ) Min_a . append ( i * 2 ) if ( n % 2 == 1 ) : Max_a . append ( n - 1 ) Min_a . append ( n - 1 ) Max_index = Max_a [ - 1 ] Min_index = Min_a [ - 1 ] for i in range ( len ( Max_a ) - 1 ) : if ( compare ( Max_a [ i ] , Max_index , a ) > 0 ) : Max_index = Max_a [ i ] for i in range ( len ( Min_a ) - 1 ) : if ( compare ( Min_a [ i ] , Min_index , a ) == 0 ) : Min_index = Min_a [ i ] print ( ' ! ' , Min_index + 1 , Max_index + 1 ) sys . stdout . flush ( )               NEW_LINE


from sys import *   def f ( t ) : n = len ( t ) k = n >> 1 u , v = [ ] , [ ] if n & 1 : u , v = [ t [ - 1 ] ] , [ t [ - 1 ] ] for i in range ( k ) : print ( ' ? ' , t [ i ] , t [ k + i ] ) stdout . flush ( ) q = k * ( input ( ) == ' < ' ) u . append ( t [ k - q + i ] ) v . append ( t [ q + i ] ) return u , v   for i in range ( int ( input ( ) ) ) : u , v = f ( range ( 1 , int ( input ( ) ) + 1 ) ) while len ( u ) > 1 : u = f ( u ) [ 0 ] while len ( v ) > 1 : v = f ( v ) [ 1 ] print ( ' ! ' , u [ 0 ] , v [ 0 ] ) stdout . flush ( ) NEW_LINE


import sys   def f ( arr ) : mn , mx = [ ] , [ ] for i in range ( len ( arr ) // 2 ) : print ( ' ? ' , arr [ 2 * i ] , arr [ 2 * i + 1 ] ) sys . stdout . flush ( ) if input ( ) == ' > ' : mn . append ( arr [ 2 * i + 1 ] ) mx . append ( arr [ 2 * i ] ) else : mn . append ( arr [ 2 * i ] ) mx . append ( arr [ 2 * i + 1 ] ) if len ( arr ) % 2 == 1 : mn . append ( arr [ - 1 ] ) mx . append ( arr [ - 1 ] ) return ( mn , mx )     for _ in range ( int ( input ( ) ) ) : n = int ( input ( ) ) arr = range ( 1 , n + 1 ) mn , mx = f ( arr ) while len ( mn ) > 1 : mn = f ( mn ) [ 0 ] while len ( mx ) > 1 : mx = f ( mx ) [ 1 ] print ( ' ! ' , mn [ 0 ] , mx [ 0 ] ) sys . stdout . flush ( )         NEW_LINE


from sys import stdin , stdoutfrom math import sin , tan , cos     def ask ( i , j ) : stdout . write ( ' ? ▁ ' + str ( i ) + ' ▁ ' + str ( j ) + ' \n ' ) stdout . flush ( ) return stdin . readline ( ) . strip ( )     T = int ( stdin . readline ( ) ) for t in range ( T ) : n = int ( stdin . readline ( ) ) if n == 1 : stdout . write ( ' ! ▁ 1 ▁ 1 \n ' ) stdout . flush ( ) continue l , r = 1 , 2 if ask ( l , r ) == ' > ' : l , r = r , l for i in range ( 3 , n + 1 , 2 ) : if i == n : s = ask ( l , i ) f = ask ( r , i ) if s == ' > ' : l = i if f == ' < ' : r = i continue lb , rb = i , i + 1 if ask ( lb , rb ) == ' > ' : lb , rb = rb , lb if ask ( lb , l ) == ' < ' : l = lb if ask ( rb , r ) == ' > ' : r = rb   stdout . write ( ' ! ▁ ' + str ( l ) + ' ▁ ' + str ( r ) + ' \n ' ) stdout . flush ( ) NEW_LINE


import java . io . File ; import java . io . IOException ; import java . io . PrintWriter ; import java . util . Scanner ;   public class B120 {   public static void main ( String [ ] args ) throws IOException { Scanner in = new Scanner ( new File ( " input . txt " ) ) ; PrintWriter out = new PrintWriter ( new File ( " output . txt " ) ) ; int N = in . nextInt ( ) ; int K = in . nextInt ( ) - 1 ; int [ ] A = new int [ N ] ; for ( int n = 0 ; n < N ; n ++ ) { A [ n ] = in . nextInt ( ) ; } while ( A [ K ] == 0 ) { K = ( K + 1 ) % N ; } out . println ( K + 1 ) ; out . close ( ) ; }   }

if __name__ == ' _ _ main _ _ ' : cin = open ( " input . txt " , " r " ) cout = open ( " output . txt " , " w " ) n , k = map ( int , cin . readline ( ) . split ( ) ) a = [ int ( i ) for i in cin . readline ( ) . split ( ) ] a = [ i + 1 for i in range ( n ) if a [ i ] ]   for i , v in enumerate ( a ) : if k <= v : cout . write ( str ( v ) ) break else : cout . write ( str ( a [ 0 ] ) ) NEW_LINE


import sys   sys . stdin = open ( r ' input . txt ' , ' r ' ) sys . stdout = open ( r ' output . txt ' , ' w ' )   n , k = map ( int , input ( ) . split ( ) ) a = list ( map ( int , input ( ) . split ( ) ) )   i = k - 1 ; while ( True ) : if i == n : i = 0 continue   if a [ i ] == 1 : print ( i + 1 ) break   i += 1 NEW_LINE


import syssys . stdin = open ( r ' input . txt ' , ' r ' ) sys . stdout = open ( r ' output . txt ' , ' w ' ) n , k = map ( int , input ( ) . split ( ) ) a = list ( map ( int , input ( ) . split ( ) ) ) i = k - 1 ; while ( True ) : if i == n : i = 0 continue if a [ i ] == 1 : print ( i + 1 ) break i += 1 NEW_LINE


input_file = open ( " input . txt " , " r " ) n , k = tuple ( [ int ( num ) for num in input_file . readline ( ) [ : - 1 ] . split ( ) ] ) arr = [ int ( num ) for num in input_file . readline ( ) [ : - 1 ] . split ( ) ] print ( n ) print ( k ) print ( arr ) k = k - 1 while ( arr [ k ] == 0 ) : k = ( k + 1 ) % noutput_file = open ( " output . txt " , " w " ) output_file . write ( " % d " % ( k + 1 ) ) NEW_LINE


import syssys . stdin = open ( r ' input . txt ' , ' r ' ) sys . stdout = open ( r ' output . txt ' , ' w ' ) n , k = map ( int , input ( ) . split ( ) ) arr = list ( map ( int , input ( ) . split ( ) ) ) for i in range ( k - 1 , 2 * n ) : pos = i % n if arr [ pos ] == 1 : print ( pos + 1 ) break NEW_LINE


import java . io . * ; import java . util . * ; public class kuchBhi { public static void main ( String [ ] args ) throws Throwable {


import java . io . File ; import java . io . PrintWriter ; import java . lang . * ; import java . util . * ;   public class Abhishek {   public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( new File ( " input . txt " ) ) ; PrintWriter out = new PrintWriter ( new File ( " output . txt " ) ) ; int n = sc . nextInt ( ) ; int k = sc . nextInt ( ) ; int [ ] a = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = sc . nextInt ( ) ; } k -- ; while ( a [ k ] != 1 ) { k ++ ; k %= n ; } out . println ( k + 1 ) ; out . close ( ) ; }   }


import java . util . Scanner ;   public class P221A { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; System . out . print ( n + " ▁ " ) ; for ( int i = 1 ; i < n ; i ++ ) { System . out . print ( i + " ▁ " ) ; } System . out . println ( ) ; } }

n = int ( input ( ) ) arr = list ( range ( 1 , n ) ) print ( n , * arr ) NEW_LINE


N = int ( input ( ) ) print ( N , * range ( 1 , N ) ) NEW_LINE


import java . util . * ;    public class dummycodes {   public static void main ( String args [ ] ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; System . out . print ( n + " ▁ " ) ; for ( int i = 1 ; i <= n - 1 ; i ++ ) { System . out . print ( i + " ▁ " ) ; } } }


import java . util . Arrays ; import java . util . Scanner ;   public class _0733LittleElephantandFunction {   public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] arr = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { arr [ i ] = i + 1 ; } for ( int i = n - 1 ; i > 0 ; i -- ) { int temp = arr [ i ] ; arr [ i ] = arr [ i - 1 ] ; arr [ i - 1 ] = temp ; } for ( int i = 0 ; i < n ; i ++ ) { System . out . print ( arr [ i ] + " ▁ " ) ; } }   }


import java . math . BigInteger ; import java . util . * ; import java . util . Comparator ; import java . lang . * ; import java . util . Arrays ;      public class geek { static class comp { int a , b ; public comp ( ) { } public comp ( int a , int b ) { this . a = a ; this . b = b ; }   } static boolean check ( long x ) { if ( x == 1 || x == 0 ) return false ; for ( long i = 2 ; i <= Math . sqrt ( x ) ; i ++ ) { if ( x % i == 0 ) { return false ; } } return true ; }    public static void main ( String [ ] args ) { Scanner s = new Scanner ( System . in ) ; try { StringBuffer sb = new StringBuffer ( ) ; int n = s . nextInt ( ) ; sb . append ( n + " ▁ " ) ; if ( n > 1 ) { for ( int i = 1 ; i < n ; i ++ ) { sb . append ( i + " ▁ " ) ; } }     System . out . println ( sb ) ;


import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . * ;   public class experiment { static int M = 1_000_000_007 ; static int INF = Integer . MAX_VALUE ; static final FastScanner fs = new FastScanner ( ) ;


import java . util . * ;   public class questionCF {   public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int a [ ] = new int [ 3 ] ; for ( int i = 0 ; i < 3 ; i ++ ) a [ i ] = sc . nextInt ( ) ; Arrays . sort ( a ) ; System . out . println ( Math . max ( 0 , a [ 2 ] - a [ 1 ] - a [ 0 ] + 1 ) ) ;   } }

a , b , c = ( int ( x ) for x in input ( ) . strip ( ) . split ( ' ▁ ' ) ) if a < b : max = b b = a a = maxif a < c : max = c c = a a = max   if a < b + c : time = 0 else : time = a - ( b + c ) + 1   print ( time ) NEW_LINE


import sys   def main ( ) : a , b , c = sorted ( map ( int , sys . stdin . read ( ) . strip ( ) . split ( ) ) ) return max ( c + 1 - a - b , 0 )   print ( main ( ) ) NEW_LINE


a , b , c = sorted ( map ( int , input ( ) . split ( ) ) ) print ( max ( 0 , c - a - b + 1 ) ) NEW_LINE


a , b , c = map ( int , input ( ) . split ( ) ) if ( a < b ) : max = b b = a a = maxif ( a < c ) : max = c c = a a = maxk = 0 if a >= b + c : k = a - ( b + c ) + 1 else : k = 0 print ( k ) NEW_LINE


import java . util . * ;   public class Test { public static void main ( String [ ] args ) { Scanner input = new Scanner ( System . in ) ; int [ ] a = { input . nextInt ( ) , input . nextInt ( ) , input . nextInt ( ) } ; Arrays . sort ( a ) ; int res = a [ 2 ] + 1 - a [ 0 ] - a [ 1 ] ; System . out . println ( res < 0 ? 0 : res ) ; } }


import java . io . * ; import java . util . * ; import java . text . * ; import java . math . * ; import java . util . regex . * ; public class Main { public static void main ( String [ ] args ) { Scanner s = new Scanner ( System . in ) ; int ans = 0 ; int [ ] a = new int [ 3 ] ; for ( int i = 0 ; i <= 2 ; i ++ ) a [ i ] = s . nextInt ( ) ; Arrays . sort ( a ) ; if ( a [ 0 ] + a [ 1 ] > a [ 2 ] ) ans = 0 ; else ans = a [ 2 ] - a [ 1 ] - a [ 0 ] + 1 ; System . out . println ( ans ) ; } }


import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ;   public class BinarySearchAdv {   public static void main ( String [ ] args ) throws NumberFormatException , IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; StringBuilder sb = new StringBuilder ( ) ; String s [ ] ; s = br . readLine ( ) . split ( " ▁ " ) ; long n = Long . parseLong ( s [ 0 ] ) ; long k = Long . parseLong ( s [ 1 ] ) ; long sum = ( k * k - k ) / 2 + 1 ;

def suma ( n ) : return n * ( n + 1 ) // 2   def sumaij ( i , j ) : if i <= 1 : return suma ( j ) return suma ( j ) - suma ( i - 1 )   def bin_search_solution ( n , k ) : st , end = 1 , k while st < end : mid = ( st + end ) // 2 s = sumaij ( mid , k ) if s == n : return k - mid + 1 if s > n : st = mid + 1 else : end = mid return k - st + 2                           def solve ( ) : n , k = map ( int , input ( ) . split ( ) ) if n == 1 : print ( 0 ) elif k >= n : print ( 1 ) else : n -= 1 k -= 1 if suma ( k ) < n : print ( - 1 ) else : res = bin_search_solution ( n , k ) print ( res )   if __name__ == ' _ _ main _ _ ' : solve ( ) NEW_LINE


def bs ( n , k , lo , hi ) : while lo <= hi : mid = ( hi + lo ) // 2 summ = ( ( k * ( k + 1 ) ) // 2 - 1 ) - ( ( ( mid - 1 ) * ( mid ) ) // 2 - 1 ) - ( k - 2 ) if summ == n : return k - mid + 1 elif summ > n : lo = mid + 1 elif summ < n : hi = mid - 1 if summ > n : mid += 1 return k - mid + 1     def solve ( ) : n , k = map ( int , input ( ) . split ( ) ) if n == 1 : return 0 elif ( k * ( k + 1 ) // 2 ) - ( k - 2 ) <= n : return - 1 elif k >= n : return 1 else : return bs ( n , k , 2 , k )   print ( solve ( ) ) NEW_LINE


def main ( ) : n , k = map ( int , input ( ) . split ( ) ) n -= 1 k -= 1 if n == 0 : minSplitters = 0 elif n <= k : minSplitters = 1 elif n > sum_consecutive ( k ) : minSplitters = - 1 else : minSplitters = min_splitters ( n , k )   print ( minSplitters )     def min_splitters ( n , k ) : low , high = 1 , k while low < high : mid = ( low + high ) // 2 summation = sum_consecutive2 ( mid , k ) if summation == n : return k - mid + 1 elif summation > n : low = mid + 1 else : high = mid   return k - low + 2     def sum_consecutive ( num ) : return int ( 0.5 * num * ( num + 1 ) )     def sum_consecutive2 ( num1 , num2 ) : return sum_consecutive ( num2 ) - sum_consecutive ( num1 - 1 )     if __name__ == ' _ _ main _ _ ' : main ( ) NEW_LINE


import mathn , k = map ( int , input ( ) . split ( ) ) n -= 1 k -= 1 if n > ( k * ( k + 1 ) ) // 2 : print ( - 1 ) else : l = - 1 r = k + 1 while r > l + 1 : m = ( l + r ) // 2 if n > ( m * ( 2 * k - m + 1 ) ) // 2 : l = m else : r = m print ( r ) NEW_LINE


import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . io . PrintWriter ;   public class Main { public static int mod = 1000000007 ; public static int [ ] [ ] [ ] dp ; public static int MAX_VAL ; public static PrintWriter out ; public static int num = 0 ;   public static void main ( String [ ] args ) throws IOException {


import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . io . PrintWriter ; import java . math . BigInteger ;   public class Pipeline_CodeForces {   public static BigInteger sumSuffix ( long idx , int k ) { BigInteger t2 = new BigInteger ( 2 + " " ) ; BigInteger tIDX = new BigInteger ( idx + " " ) ; BigInteger k1 = new BigInteger ( k + " " ) ; BigInteger k2 = new BigInteger ( ( k + 1 ) + " " ) ; BigInteger n1 = ( k1 . multiply ( k2 ) ) . divide ( t2 ) ;   BigInteger idx1 = new BigInteger ( idx + " " ) ; BigInteger idx2 = new BigInteger ( ( idx + 1 ) + " " ) ; BigInteger n2 = ( idx1 . multiply ( idx2 ) ) . divide ( t2 ) ;   return n1 . subtract ( n2 ) . add ( tIDX ) ; } public static long BSfindfirstSmaller ( BigInteger N , int k ) { long start = 1 ; long end = k ; long mid = 0 ; while ( start < end ) { mid = start + ( end - start ) / 2 ;


import java . io . File ; import java . io . FileInputStream ; import java . io . FileNotFoundException ; import java . io . IOException ; import java . nio . file . Paths ; import java . util . InputMismatchException ;   public class Main {   public Main ( ) throws FileNotFoundException {


import java . util . Scanner ;   public class IlyaColorWalk { public static void main ( String [ ] args ) {   Scanner in = new Scanner ( System . in ) ; int n = in . nextInt ( ) , i , l = 0 , r = n - 1 , c [ ] = new int [ n ] ;   for ( i = 0 ; i < n ; i ++ ) c [ i ] = in . nextInt ( ) ; in . close ( ) ;   while ( c [ l ] == c [ n - 1 ] ) l ++ ; while ( c [ r ] == c [ 0 ] ) r -- ; System . out . println ( Math . max ( n - l - 1 , r ) ) ; } }

try : n = int ( input ( ) ) c = list ( map ( int , input ( ) . split ( ) ) ) z = [ ] i = n - 1 while i > 0 : if not c [ i ] == c [ 0 ] : z . append ( i ) break else : i = i - 1 i = 0 while i < n - 1 : if not c [ i ] == c [ n - 1 ] : z . append ( n - 1 - i ) break else : i = i + 1 print ( max ( z ) ) except : pass NEW_LINE


n = int ( input ( ) ) l = list ( map ( int , input ( ) . split ( ) ) ) for i in range ( n - 1 ) : if l [ i ] != l [ - 1 ] : distance = n - i - 1 breakfor j in range ( n - 1 , 0 , - 1 ) : if l [ j ] != l [ 0 ] : if j > distance : distance = j breakprint ( distance ) NEW_LINE


n = int ( input ( ) ) c = list ( map ( int , input ( ) . split ( ) ) ) i = 0j = n - 1 ans1 = 0 ans2 = 0 while i < n - 1 and j > 0 : if c [ j ] != c [ 0 ] : ans1 = j break else : j -= 1 if c [ i ] != c [ n - 1 ] : ans2 = n - 1 - i break else : i += 1   print ( max ( ans1 , ans2 ) ) NEW_LINE


def mex ( a ) : a . sort ( ) f = 0 for i in range ( len ( a ) ) : if a [ i ] != i : f = 1 return i if f == 0 : return max ( a ) + 1 import math   n = int ( input ( ) ) a = list ( map ( int , input ( ) . split ( ) ) ) i = 0j = n - 1 while a [ i ] == a [ j ] : i += 1 ans1 = j - ii = 0 while a [ i ] == a [ j ] : j -= 1 ans = max ( ans1 , j ) print ( ans ) NEW_LINE


import java . io . PrintWriter ; import java . util . Scanner ;   public class ColorfulWalk1100 { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; PrintWriter out = new PrintWriter ( System . out ) ;   int houses = in . nextInt ( ) ; int [ ] colors = new int [ houses ] ; for ( int i = 0 ; i < houses ; i ++ ) colors [ i ] = in . nextInt ( ) ; int distanceEnd = 0 ; for ( int i = 0 ; i < houses - 1 ; i ++ ) { if ( colors [ i ] != colors [ houses - 1 ] ) { distanceEnd = Math . abs ( ( houses - 1 ) - i ) ; break ; } } int distanceBeg = 0 ; for ( int i = houses - 1 ; i > - 1 ; i -- ) { if ( colors [ i ] != colors [ 0 ] ) { distanceBeg = Math . abs ( i ) ; break ; } } out . print ( Math . max ( distanceBeg , distanceEnd ) ) ; out . close ( ) ; } }


import java . io . * ; import java . util . * ; public class Main { public static void main ( String [ ] args ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; InputReader in = new InputReader ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; TaskA solver = new TaskA ( ) ; solver . solve ( in , out ) ; out . close ( ) ; } static class TaskA { public void solve ( InputReader in , PrintWriter out ) { int n = in . nextInt ( ) ; int [ ] a = new int [ n + 1 ] ; for ( int i = 1 ; i <= n ; i ++ ) a [ i ] = in . nextInt ( ) ; int ans = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { if ( a [ i ] != a [ n ] ) { ans = n - i ; break ; } } for ( int i = n ; i >= 1 ; i -- ) { if ( a [ 1 ] != a [ i ] ) { if ( ( i - 1 ) > ans ) ans = i - 1 ; break ; } } out . println ( ans ) ; } } static class InputReader { public BufferedReader reader ; public StringTokenizer tokenizer ; public InputReader ( InputStream stream ) { reader = new BufferedReader ( new InputStreamReader ( stream ) , 32768 ) ; tokenizer = null ; } public String next ( ) { while ( tokenizer == null || ! tokenizer . hasMoreElements ( ) ) { try { tokenizer = new StringTokenizer ( reader . readLine ( ) ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } } return tokenizer . nextToken ( ) ; } public int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } } }


import java . util . Scanner ;   public class Solution { public static void main ( String [ ] args ) { Scanner s = new Scanner ( System . in ) ; int n = s . nextInt ( ) , m = s . nextInt ( ) , k = s . nextInt ( ) ; String str = s . next ( ) ; str = s . next ( ) ; char [ ] array = s . next ( ) . toCharArray ( ) ; int i = 1 ; for ( char item : array ) { if ( item == '0' ) { if ( m < k ) m = Math . max ( 1 , m - 1 ) ; else m = Math . min ( n , m + 1 ) ; if ( str . equals ( " head " ) ) k -- ; else k ++ ; } else { if ( str . equals ( " head " ) ) k -- ; else k ++ ; if ( str . equals ( " head " ) ) m = n ; else m = 1 ; } if ( k == n ) str = " head " ; else if ( k == 1 ) str = " tail " ; if ( m == k ) { System . out . println ( " Controller ▁ " + i ) ; System . exit ( 0 ) ; } i ++ ; } System . out . println ( " Stowaway " ) ; } }

J = lambda : map ( int , input ( ) . split ( ) ) NEW_LINE v , y , z = J ( ) NEW_LINE dir = ' to ▁ tail ' == input ( ) NEW_LINE for t , x in enumerate ( map ( int , input ( ) ) ) : if NEW_LINE z == 1 : dir = 1 elif z == v : dir = 0 NEW_LINE if not x : NEW_LINE INDENT y = min ( v , y + 1 ) if z < y else max ( 1 , y - 1 ) else : NEW_LINE y = 1 if dir else v NEW_LINE DEDENT z = z + 1 if dir else z - 1 NEW_LINE if y == z : print ( ' Controller ▁ ' + str ( t + 1 ) ) NEW_LINE exit ( 0 ) NEW_LINE print ( ' Stowaway ' ) NEW_LINE


from sys import stdin , stdout , exit NEW_LINE n , m , k = map ( int , stdin . readline ( ) . split ( ) ) NEW_LINE d = 1 if stdin . readline ( ) [ 6 ] == ' l ' else - 1 NEW_LINE m = 1 if m < k else n NEW_LINE for i , c in enumerate ( stdin . readline ( ) , 1 ) : if NEW_LINE c == '0' : NEW_LINE if k == 1 : NEW_LINE INDENT k , d = 2 , 1 elif k == n : NEW_LINE k , d = n - 1 , - 1 else : NEW_LINE k += d NEW_LINE DEDENT if m == k : stdout . write ( ' Controller ▁ ' + str ( i ) ) NEW_LINE exit ( 0 ) else : if k == 1 : NEW_LINE INDENT k , d , m = 2 , 1 , 1 elif k == n : NEW_LINE k , d , m = n - 1 , - 1 , n elif d == 1 : NEW_LINE k += 1 NEW_LINE DEDENT m = 1 else : k -= 1 NEW_LINE m = n NEW_LINE stdout . write ( ' Stowaway ' ) NEW_LINE


from sys import stdin , stdout , exit NEW_LINE n , m , k = map ( int , stdin . readline ( ) . split ( ) ) NEW_LINE d = 1 if stdin . readline ( ) [ 6 ] == ' l ' else - 1 NEW_LINE m = 1 if m < k else nfor NEW_LINE i in range ( 5 ) : passfor NEW_LINE i , c in enumerate ( stdin . readline ( ) , 1 ) : NEW_LINE if c == '0' : if NEW_LINE k == 1 : k , d = 2 , 1 elif k == n : k , d = n - 1 , - 1 else : k += d NEW_LINE if m == k : stdout . write ( ' Controller ▁ ' + str ( i ) ) NEW_LINE exit ( 0 ) else : if k == 1 : NEW_LINE INDENT k , d , m = 2 , 1 , 1 elif k == n : NEW_LINE k , d , m = n - 1 , - 1 , n elif d == 1 : NEW_LINE k += 1 NEW_LINE DEDENT m = 1 else : k -= 1 NEW_LINE m = n NEW_LINE stdout . write ( ' Stowaway ' ) NEW_LINE


import java . util . Scanner ;   public class B74 { public static void main ( String [ ] args ) { new B74 ( ) . run ( ) ; }   public void run ( ) { Scanner scanner = new Scanner ( System . in ) ; int n = scanner . nextInt ( ) ; int m = scanner . nextInt ( ) ; int k = scanner . nextInt ( ) ; scanner . nextLine ( ) ; String di = scanner . nextLine ( ) ; String time = scanner . nextLine ( ) ; char [ ] ts = time . toCharArray ( ) ; for ( int i = 0 ; i < ts . length ; ++ i ) {


import java . util . * ; import java . io . * ;   public class Train { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; PrintWriter pw = new PrintWriter ( System . out ) ;   int t = 1 ;   while ( t -- > 0 ) {   String str [ ] = br . readLine ( ) . trim ( ) . split ( " ▁ " ) ; int n = Integer . parseInt ( str [ 0 ] ) ; int m = Integer . parseInt ( str [ 1 ] ) ; int k = Integer . parseInt ( str [ 2 ] ) ;   boolean tohead = false ; str = br . readLine ( ) . trim ( ) . split ( " ▁ " ) ; if ( str [ 1 ] . equals ( " head " ) ) tohead = true ; else tohead = false ;   char a [ ] = br . readLine ( ) . trim ( ) . toCharArray ( ) ; int time = a . length ; for ( int i = 0 ; i < time ; i ++ ) { if ( a [ i ] == '0' ) {   if ( m != 1 && m != n ) { int x = Math . abs ( k - ( m + 1 ) ) ; int y = Math . abs ( k - ( m - 1 ) ) ; if ( x > y ) { m ++ ; } else { m -- ; } }   if ( tohead ) k -- ; else k ++ ; if ( k == 1 || k == n ) { tohead = ! tohead ; } } else { if ( tohead ) k -- ; else k ++ ; if ( k == 1 || k == n ) { tohead = ! tohead ; }   if ( k == 1 ) { m = n ; } else if ( k == n ) { m = 1 ; } else { if ( tohead ) m = n ; else m = 1 ; } }


import java . io . * ; import java . util . * ;   public class MainB { static final StdIn in = new StdIn ( ) ; static final PrintWriter out = new PrintWriter ( System . out ) ; static final long M = ( long ) 1e9 + 7 ; public static void main ( String [ ] args ) { int n = in . nextInt ( ) ; long [ ] a = in . readLongArray ( n ) ; if ( n % 2 == 1 ) { -- n ; for ( int i = 0 ; i < n ; ++ i ) { if ( i % 2 == 0 ) a [ i ] = a [ i ] + a [ i + 1 ] ; else { a [ i ] = a [ i ] - a [ i + 1 ] + M ; if ( a [ i ] < 0 ) a [ i ] += M ; } } } long ans = 0 , nck = 1 ; int s = n / 2 % 2 == 0 ? - 1 : 1 ; for ( int i = 0 ; i < n / 2 ; ++ i ) { ans = ( nck * ( a [ 2 * i ] + s * a [ 2 * i + 1 ] ) + ans ) % M ; nck = nck * ( n / 2 - 1 - i ) % M * modI ( i + 1 , M ) % M ;

import sys   def CreateFact ( n , mod ) : cant = n + 1 factorials = [ 1 ] * cant   for x in range ( 1 , cant ) : val = factorials [ x - 1 ] * x % mod factorials [ x ] = val inv_factorial = [ 1 ] * cant inv_factorial [ n ] = pow ( factorials [ - 1 ] , mod - 2 , mod ) for x in reversed ( range ( 0 , n ) ) : val = inv_factorial [ x + 1 ] * ( x + 1 ) % mod inv_factorial [ x ] = val return factorials , inv_factorial           def CalculateNPairsCoef ( n , mod ) : factorial , inv_factorial = CreateFact ( n , mod ) coef = [ 1 ] * n middle = int ( ( n + 1 ) / 2 ) last = n - 1 for x in range ( 1 , middle ) : o = factorial [ n - 1 ] * inv_factorial [ n - 1 - x ] % mod * inv_factorial [ x ] % mod coef [ x ] = o coef [ last - x ] = o return coef   def KarenAdTest ( ) : n = int ( sys . stdin . readline ( ) ) line = sys . stdin . readline ( ) . split ( ) i = 0 while i < n : x = int ( line [ i ] ) line [ i ] = x i += 1 mod = 1000000007           if n == 1 : val = line [ 0 ] % mod print ( val ) return if n == 2 : val = ( line [ 0 ] + line [ 1 ] ) % mod print ( val ) return if n == 3 : val = ( line [ 0 ] + 2 * line [ 1 ] - line [ 2 ] ) % mod print ( val ) return if n == 4 : val = ( line [ 0 ] - line [ 1 ] + line [ 2 ] - line [ 3 ] ) % mod print ( val ) return if n == 5 : val = ( line [ 0 ] + 2 * line [ 2 ] + line [ 4 ] ) % mod print ( val ) return NEW_LINE


import java . io . * ; import java . util . * ;   import static java . math . BigDecimal . valueOf ;   public class Solution { static MyScanner sc ; private static PrintWriter out ; static long M2 = 1_000_000_000L + 7 ;   public static void main ( String [ ] s ) throws Exception { StringBuilder stringBuilder = new StringBuilder ( ) ;


import java . util . * ; import java . io . * ; import static java . lang . Math . * ;   public class PracticeProblem { public static class FastReader { BufferedReader br ; StringTokenizer st ;   public FastReader ( ) { br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; }   String next ( ) { while ( st == null || ! st . hasMoreElements ( ) ) { try { st = new StringTokenizer ( br . readLine ( ) ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } return st . nextToken ( ) ; }   int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; }   long nextLong ( ) { return Long . parseLong ( next ( ) ) ; }   double nextDouble ( ) { return Double . parseDouble ( next ( ) ) ; }   String nextLine ( ) { String str = " " ; try { str = br . readLine ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } return str ; } }   public static FastReader in = new FastReader ( ) ; public static PrintWriter out = new PrintWriter ( System . out ) ; public static StringBuilder answer = new StringBuilder ( ) ;   public static void main ( String [ ] args ) { solve ( ) ; out . close ( ) ; }   private static void solve ( ) { char [ ] s = in . nextLine ( ) . toCharArray ( ) ; int n = s . length ;   if ( n < 4 ) { out . println ( " YES " ) ; out . println ( new String ( s ) ) ; return ; }   int [ ] charCount = new int [ 26 ] ;   for ( char c : s ) charCount [ c - ' a ' ] ++ ;


p = [ 1 ] * 1001 for i in range ( 2 , 1001 ) : if p [ i ] : for j in range ( i , 1001 , i ) : p [ j ] = 0 p [ i ] = 1 a = input ( ) z = len ( a ) l = [ 0 ] * 26 for i in a : l [ ord ( i ) - 97 ] += 1 gh = 0 for i in range ( z // 2 + 1 , z + 1 ) : gh += p [ i ] if max ( l ) < z - 1 - gh : exit ( print ( " NO " ) ) ans = [ ' ' ] * ( z + 1 ) t = l . index ( max ( l ) ) for i in range ( 2 , 1 + ( z // 2 ) ) : ans [ i ] = chr ( t + 97 ) ; l [ t ] -= 1 for i in range ( 1 + ( z // 2 ) , z + 1 ) : if p [ i ] == 0 : ans [ i ] = chr ( t + 97 ) ; l [ t ] -= 1j = 0 for i in range ( 1 , z + 1 ) : if ans [ i ] == ' ' : while l [ j ] <= 0 : j += 1 ans [ i ] = chr ( j + 97 ) ; l [ j ] -= 1 print ( " YES " ) print ( ' ' . join ( ans [ 1 : : ] ) ) NEW_LINE


import java . util . * ; import java . io . * ; import java . text . * ;   public class B482 {   static class SegmentTree {

import sys   input = sys . stdin . readline   n , m = map ( int , input ( ) . split ( ) ) a = [ ] for _ in range ( m ) : l , r , q = map ( int , input ( ) . split ( ) ) l -= 1 r -= 1 a . append ( ( l , r , q ) ) res = [ 0 ] * nbad = Falsefor i in range ( 30 ) : events = [ 0 ] * ( n + 1 ) for l , r , q in a : if q & ( 1 << i ) : events [ l ] += 1 events [ r + 1 ] -= 1 c = 0 for j in range ( n ) : c += events [ j ] if c > 0 : res [ j ] |= ( 1 << i ) s = [ 0 ] * ( n + 1 ) for j in range ( n ) : s [ j + 1 ] = s [ j ] + ( ( res [ j ] >> i ) & 1 ) for l , r , q in a : if q & ( 1 << i ) == 0 : if s [ r + 1 ] - s [ l ] == r - l + 1 : bad = True breakif bad : print ( " NO " ) else : print ( " YES " ) print ( * res ) NEW_LINE


import java . util . * ; import java . io . * ; public class Solution { public static void main ( String [ ] args ) throws IOException , InterruptedException { Scanner sc = new Scanner ( System . in ) ; PrintWriter pw = new PrintWriter ( System . out ) ; int n = sc . nextInt ( ) ; int m = sc . nextInt ( ) ; int N = 1 ; while ( N < n ) { N *= 2 ; } int [ ] arr = new int [ N + 1 ] ; SegmentTree sg = new SegmentTree ( arr ) ; int l [ ] = new int [ m + 1 ] ; int r [ ] = new int [ m + 1 ] ; int q [ ] = new int [ m + 1 ] ;   for ( int i = 1 ; i <= m ; i ++ ) { l [ i ] = sc . nextInt ( ) ; r [ i ] = sc . nextInt ( ) ; q [ i ] = sc . nextInt ( ) ; sg . updateRange ( l [ i ] , r [ i ] , q [ i ] ) ; } for ( int i = 1 ; i <= m ; i ++ ) { if ( sg . query ( l [ i ] , r [ i ] ) != q [ i ] ) { System . out . println ( " NO " ) ; return ; } } System . out . println ( " YES " ) ; for ( int i = 1 ; i <= n ; i ++ ) { System . out . print ( sg . query ( i , i ) + " ▁ " ) ; } } static class SegmentTree { int [ ] sTree , array , lazy ; int N ; public SegmentTree ( int [ ] array ) { this . array = array ; N = array . length - 1 ;


import java . awt . Desktop ;    import java . io . BufferedReader ;    import java . io . IOException ; import java . io . InputStreamReader ; import java . io . PrintWriter ; import java . net . URI ; import java . net . URISyntaxException ; import java . sql . Array ; import java . util . ArrayList ; import java . util . Arrays ; import java . util . Collections ; import java . util . Comparator ; import java . util . HashMap ; import java . util . HashSet ; import java . util . Iterator ; import java . util . LinkedHashMap ; import java . util . LinkedHashSet ; import java . util . LinkedList ; import java . util . List ; import java . util . Map ; import java . util . PriorityQueue ; import java . util . Queue ; import java . util . Scanner ; import java . util . Set ; import java . util . Stack ; import java . util . StringTokenizer ; import java . util . TreeSet ; import java . util . Vector ;     public class codechef3 { static class comp implements Comparator < Integer > {   @ Override public int compare ( Integer o1 , Integer o2 ) { if ( Math . abs ( o1 ) > Math . abs ( o2 ) ) return - 1 ; else return 1 ; } }

import matht = int ( input ( ) ) for _ in range ( t ) : n = int ( input ( ) ) a , b , c = map ( int , input ( ) . split ( ) ) st = input ( ) ans = 0 st1 = " " for x in st : if ( x == " R " and b > 0 ) : ans += 1 b -= 1 st1 += " P " elif ( x == " S " and a > 0 ) : ans += 1 a -= 1 st1 += " R " elif ( x == " P " and c > 0 ) : ans += 1 c -= 1 st1 += " S " else : st1 += " * "   ans_str = " " for x in st1 : if ( x == ' * ' ) : if ( a > 0 ) : ans_str += " R " a -= 1 elif ( b > 0 ) : ans_str += " P " b -= 1 elif ( c > 0 ) : ans_str += " S " c -= 1 else : ans_str += x if ( ans >= math . ceil ( n / 2 ) ) : print ( " YES " ) print ( ans_str ) else : print ( " NO " )                                           NEW_LINE


import mathdef main ( ) : cases = int ( input ( ) ) for _ in range ( cases ) : dic = { ' R ' : 0 , ' P ' : 0 , ' S ' : 0 } seq = [ ] n = int ( input ( ) ) R , P , S = [ int ( i ) for i in input ( ) . split ( " ▁ " ) ] for ele in list ( input ( ) ) : dic [ ele ] += 1 seq . append ( ele ) win = True qtd_fail = 0 if dic [ ' R ' ] > P : qtd_fail += dic [ ' R ' ] - P if dic [ ' P ' ] > S : qtd_fail += dic [ ' P ' ] - S if dic [ ' S ' ] > R : qtd_fail += dic [ ' S ' ] - R w = n - qtd_fail k = math . ceil ( n / 2 ) NEW_LINE


from math import ceilfor _ in range ( int ( input ( ) ) ) : n = int ( input ( ) ) a , b , c = map ( int , input ( ) . split ( ) ) s = input ( ) d = { ' R ' : 0 , ' P ' : 0 , ' S ' : 0 } for i in s : d [ i ] += 1 wins = min ( b , d [ ' R ' ] ) + min ( d [ ' P ' ] , c ) + min ( d [ ' S ' ] , a ) if wins >= ceil ( n / 2 ) : print ( " YES " ) ans = [ ' ' ] * n for i in range ( n ) : if s [ i ] == ' R ' and b > 0 : ans [ i ] = ' P ' b -= 1 elif s [ i ] == ' P ' and c > 0 : ans [ i ] = ' S ' c -= 1 elif s [ i ] == ' S ' and a > 0 : ans [ i ] = ' R ' a -= 1 for i in range ( n ) : if ( a + b + c ) == 0 : break if ans [ i ] == ' ' : if a != 0 : ans [ i ] = ' R ' a -= 1 elif b != 0 : ans [ i ] = ' P ' b -= 1 elif c != 0 : ans [ i ] = ' S ' c -= 1 out = ' ' for an in ans : out += an print ( out ) else : print ( " NO " ) NEW_LINE


t = int ( input ( ) ) for _ in range ( t ) : n = int ( input ( ) ) a , b , c = map ( int , input ( ) . split ( ) ) s = input ( ) ans = [ ] cnt = 0 for i in range ( n ) : if a > 0 and s [ i ] == " S " : a -= 1 cnt += 1 ans . append ( " R " ) elif b > 0 and s [ i ] == " R " : b -= 1 cnt += 1 ans . append ( " P " ) elif c > 0 and s [ i ] == " P " : c -= 1 cnt += 1 ans . append ( " S " ) else : ans . append ( " ? " ) for i in range ( n ) : if ans [ i ] == " ? " : if a > 0 : ans [ i ] = " R " a -= 1 elif b > 0 : ans [ i ] = " P " b -= 1 else : ans [ i ] = " S " c -= 1 if cnt >= ( n + 1 ) // 2 : print ( " YES " ) print ( " " . join ( ans ) ) else : print ( " NO " ) NEW_LINE


import java . io . * ; import java . util . * ; import java . math . * ; import java . math . BigInteger ;

from collections import defaultdictn , m = map ( int , input ( ) . split ( ) ) a = [ ] graph = defaultdict ( list ) coun0 = 0 for i in range ( n ) : a . append ( list ( map ( int , input ( ) . split ( ) ) ) ) if a [ i ] [ 0 ] == 0 : coun0 += 1 if coun0 == len ( a ) : print ( len ( a ) ) else : for i in range ( n ) : for j in range ( n ) : if i != j : for k in range ( 1 , a [ i ] [ 0 ] + 1 ) : for l in range ( 1 , a [ j ] [ 0 ] + 1 ) : if a [ i ] [ k ] == a [ j ] [ l ] : graph [ i ] . append ( j ) def dfs ( n ) : vis [ n ] = 1 for i in graph [ n ] : if not vis [ i ] : dfs ( i ) vis = [ 0 ] * n ans = - 1 for i in range ( n ) : if not vis [ i ] : ans += 1 dfs ( i ) print ( ans ) NEW_LINE


from sys import stdin , stdoutinput = stdin . readline def main ( ) : n , m = map ( int , input ( ) . split ( ) ) sets = list ( range ( n + 1 + m ) ) sizes = [ 1 ] * ( n + 1 + m ) def get ( a ) : if sets [ a ] != a : sets [ a ] = get ( sets [ a ] ) return sets [ a ] def union ( a , b ) : a = get ( a ) b = get ( b ) if a == b : return if sizes [ a ] > sizes [ b ] : a , b = b , a sets [ a ] = b sizes [ b ] += sizes [ a ] flags = [ 1 ] * n for i in range ( n ) : nums = list ( map ( int , input ( ) . split ( ) ) ) for j in range ( 1 , nums [ 0 ] + 1 ) : union ( i , nums [ j ] - 1 + n ) flags [ i ] = nums [ 0 ] ans = 0 s = set ( ) for i in range ( n ) : if flags [ i ] == 0 : ans += 1 continue s . add ( get ( i ) ) print ( max ( 0 , len ( s ) - 1 ) + ans ) main ( ) NEW_LINE


from sys import stdininput = stdin . readlinen , m = map ( int , input ( ) . split ( ) ) l = [ ] cnt = 0 for _ in range ( n ) : a = set ( list ( map ( int , input ( ) . split ( ) ) ) [ 1 : ] ) if len ( a ) == 0 : cnt += 1 continue li = [ ] for s in l : if a & s : a |= s else : li . append ( s ) li . append ( a ) l = liprint ( cnt + max ( 0 , len ( l ) - 1 ) ) NEW_LINE


import java . io . * ; import java . util . * ;   public class TWO77A { private int adj [ ] [ ] ; private boolean visited [ ] ; private int n , m ; private boolean allNone = true ; public static void main ( String args [ ] ) { TWO77A t = new TWO77A ( ) ; t . process ( ) ; } public void process ( ) { Scanner s = new Scanner ( System . in ) ; n = s . nextInt ( ) ; m = s . nextInt ( ) ; adj = new int [ n ] [ n ] ; ArrayList < Employee > employees = new ArrayList < Employee > ( ) ; visited = new boolean [ n ] ; Arrays . fill ( visited , false ) ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { adj [ i ] [ j ] = 0 ; } } for ( int i = 0 ; i < n ; i ++ ) { int numLanguage = s . nextInt ( ) ; if ( numLanguage != 0 ) { allNone = false ; } Employee e = new Employee ( ) ; for ( int j = 0 ; j < numLanguage ; j ++ ) { e . languages . add ( s . nextInt ( ) ) ; } employees . add ( e ) ; } for ( int emp1 = 0 ; emp1 < n ; emp1 ++ ) { for ( int emp2 = emp1 + 1 ; emp2 < n ; emp2 ++ ) { Employee e1 = employees . get ( emp1 ) ; Employee e2 = employees . get ( emp2 ) ; for ( int lang : e2 . languages ) { if ( e1 . languages . contains ( lang ) ) { adj [ emp1 ] [ emp2 ] = adj [ emp2 ] [ emp1 ] = 1 ; } } } }


import java . util . * ; import java . util . Scanner ; import java . io . * ; import javax . lang . model . util . ElementScanner6 ; import static java . lang . System . out ;    public class A277 { static class weightedQU { int [ ] id ; int [ ] size ; public weightedQU ( int n ) { id = new int [ n ] ; size = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { size [ i ] = i ; id [ i ] = i ; } } public int root ( int i ) { while ( i != id [ i ] ) { id [ i ] = id [ id [ i ] ] ; i = id [ i ] ; } return i ; } public boolean connected ( int p , int q ) { return root ( p ) == root ( q ) ; } public void union ( int p , int q ) { int i = root ( p ) ; ; int j = root ( q ) ; if ( size [ i ] < size [ j ] ) { id [ i ] = j ; size [ j ] += size [ j ] ; } else { id [ j ] = i ; size [ i ] += size [ j ] ; } } } public static void main ( String args [ ] ) {   FastReader in = new FastReader ( ) ; PrintWriter pr = new PrintWriter ( new BufferedWriter ( new OutputStreamWriter ( System . out ) ) ) ; int tc = 1 ;


import java . io . * ; import java . util . * ; public class Mishka_and_trip { static class FastReader { BufferedReader br ; StringTokenizer st ; public FastReader ( ) { br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; } String next ( ) { while ( st == null || ! st . hasMoreElements ( ) ) { try { st = new StringTokenizer ( br . readLine ( ) ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } return st . nextToken ( ) ; } int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } long nextLong ( ) { return Long . parseLong ( next ( ) ) ; } double nextDouble ( ) { return Double . parseDouble ( next ( ) ) ; } String nextLine ( ) { String str = " " ; try { str = br . readLine ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } return str ; } } public static void main ( String [ ] args ) { FastReader sc = new FastReader ( ) ; PrintWriter pw = new PrintWriter ( System . out ) ;   int n = sc . nextInt ( ) ; int m = sc . nextInt ( ) ;   long arr [ ] = new long [ n + 1 ] ; long sum = 0 ; for ( int i = 1 ; i < n + 1 ; i ++ ) { arr [ i ] = sc . nextInt ( ) ; sum += arr [ i ] ; } boolean capital [ ] = new boolean [ n + 1 ] ; long ans = 0 ; for ( int i = 0 ; i < m ; i ++ ) { int x = sc . nextInt ( ) ; capital [ x ] = true ; sum -= arr [ x ] ;   ans += ( sum * arr [ x ] ) ; }

n , k = map ( int , input ( ) . split ( ) ) v = list ( map ( int , input ( ) . split ( ) ) ) c = set ( i - 1 for i in map ( int , input ( ) . split ( ) ) )   prefix_all = [ 0 ] * nprefix_cap = [ 0 ] * n   for i in range ( n ) : if i > 0 : prefix_all [ i ] += prefix_all [ i - 1 ] prefix_cap [ i ] += prefix_cap [ i - 1 ] prefix_all [ i ] += v [ i ] if i in c : prefix_cap [ i ] += v [ i ]   res = 0 for i in range ( n ) : if i in c : res += v [ i ] * ( prefix_all [ n - 1 ] - prefix_all [ i ] ) else : res += v [ i ] * ( prefix_cap [ n - 1 ] - prefix_cap [ i ] ) if i + 1 < n and i + 1 not in c : res += v [ i ] * v [ i + 1 ] if i == 0 and n - 1 not in c : res += v [ 0 ] * v [ n - 1 ] print ( res )   NEW_LINE


n , k = map ( int , input ( ) . split ( ) ) C = list ( map ( int , input ( ) . split ( ) ) ) S = list ( map ( int , input ( ) . split ( ) ) ) G = set ( S ) ans = 0 sus = sum ( C ) stos = 0 for x in G : stos += C [ x - 1 ] for j in S : ans += C [ j - 1 ] * ( sus - C [ j - 1 ] ) for i in range ( n ) : if i + 1 not in G and ( i + 1 ) % n + 1 not in G : ans += C [ i ] * C [ ( i + 1 ) % n ] s2 = 0 for v in G : s2 += C [ v - 1 ] * C [ v - 1 ] print ( ans - ( stos * stos - s2 ) // 2 ) NEW_LINE


n , k = map ( int , input ( ) . split ( ) ) l = list ( map ( int , input ( ) . split ( ) ) ) cit = list ( map ( int , input ( ) . split ( ) ) ) ''' # ▁ a ▁ good ▁ approach ▁ but ▁ not ▁ sufficient ▁ for ▁ the ▁ time ▁ limitans ▁ = ▁ 0ans _ set ▁ = ▁ set ( ) for ▁ i ▁ in ▁ range ( n ▁ - ▁ 1 ) : TABSYMBOL ans _ set . add ( ( i , ▁ i ▁ + ▁ 1 ) )  ans _ set . add ( (0 , ▁ n ▁ - ▁ 1 ) )  for ▁ i ▁ in ▁ range ( k ) : TABSYMBOL bfc ▁ = ▁ cit [ i ] ▁ - ▁ 1 TABSYMBOL for ▁ ii ▁ in ▁ range ( n ) : TABSYMBOL TABSYMBOL if ▁ ii ▁ = = ▁ bfc : TABSYMBOL TABSYMBOL TABSYMBOL continue TABSYMBOL TABSYMBOL else : TABSYMBOL TABSYMBOL TABSYMBOL ans _ set . add ( ( min ( bfc , ▁ ii ) , ▁ max ( bfc , ▁ ii ) ) )  for ▁ i ▁ in ▁ ans _ set : TABSYMBOL ii , ▁ jj ▁ = ▁ i TABSYMBOL ans ▁ + = ▁ l [ ii ] ▁ * ▁ l [ jj ]  print ( ans ) ''' ans = 0 sum_ = sum ( l ) for i in range ( k ) : sum_ -= l [ cit [ i ] - 1 ] ans += sum_ * l [ cit [ i ] - 1 ]   cit = set ( cit ) for i in range ( n - 1 ) : if ( i + 1 ) not in cit and ( i + 2 ) not in cit : ans += l [ i ] * l [ i + 1 ]   if 1 not in cit and n not in cit : ans += l [ 0 ] * l [ - 1 ]     print ( ans ) NEW_LINE


from collections import * n , k = map ( int , input ( ) . split ( ) ) a = list ( map ( int , input ( ) . split ( ) ) ) cap = [ 0 for i in range ( n ) ] c = list ( map ( int , input ( ) . split ( ) ) ) for i in c : cap [ i - 1 ] = 1 s = sum ( a ) ans = 0 for i in range ( n ) : if ( cap [ i ] == 1 ) : ans += a [ i ] * ( s - a [ i ] ) s -= a [ i ] elif ( cap [ i - 1 ] != 1 ) : ans += a [ i ] * a [ i - 1 ] print ( ans ) NEW_LINE


import java . io . * ; import java . util . * ;   public class CF { public static void main ( String [ ] args ) throws IOException {


import java . io . * ; import java . util . * ; import java . util . regex . * ; public class vk18 { public static void main ( String [ ] stp ) throws Exception { Scanner scan = new Scanner ( System . in ) ; PrintWriter pw = new PrintWriter ( System . out ) ; BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; StringTokenizer st = new StringTokenizer ( br . readLine ( ) ) ; int n = Integer . parseInt ( st . nextToken ( ) ) , k = Integer . parseInt ( st . nextToken ( ) ) , i , p = 0 ; ; Integer a [ ] = new Integer [ n ] ; st = new StringTokenizer ( br . readLine ( ) ) ; long sum = 0 , ans = 0 ; for ( i = 0 ; i < n ; i ++ ) { a [ i ] = Integer . parseInt ( st . nextToken ( ) ) ; sum += a [ i ] ; } st = new StringTokenizer ( br . readLine ( ) ) ; for ( i = 0 ; i < k ; i ++ ) { p = Integer . parseInt ( st . nextToken ( ) ) - 1 ; sum -= a [ p ] ; ans += sum * a [ p ] ; a [ p ] = 0 ; } for ( i = 1 ; i < n ; i ++ ) { ans += a [ i ] * a [ i - 1 ] ; } ans += a [ 0 ] * a [ n - 1 ] ; pw . println ( ans ) ; pw . flush ( ) ; } }


import java . util . * ;   public class Main { static void sort ( int a [ ] ) { Random ran = new Random ( ) ; for ( int i = 0 ; i < a . length ; i ++ ) { int r = ran . nextInt ( a . length ) ; int temp = a [ r ] ; a [ r ] = a [ i ] ; a [ i ] = temp ; } Arrays . sort ( a ) ; }   public static void main ( String [ ] args ) { Scanner input = new Scanner ( System . in ) ; int n = input . nextInt ( ) ; int k = input . nextInt ( ) ; int a [ ] = new int [ n ] ; int c [ ] = new int [ k ] ; long total = 0 ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = input . nextInt ( ) ; total += a [ i ] ; } long ans = 0 ; for ( int i = 0 ; i < k ; i ++ ) { c [ i ] = input . nextInt ( ) - 1 ; total -= a [ c [ i ] ] ; ans += total * a [ c [ i ] ] ; a [ c [ i ] ] = 0 ; } for ( int i = 0 ; i < n ; i ++ ) { ans += ( a [ i ] * a [ ( i + 1 ) % n ] ) ; } System . out . println ( ans ) ; }       }


import java . util . Scanner ;   public class P743A { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; String s = sc . next ( ) ; System . out . println ( s . charAt ( a - 1 ) == s . charAt ( b - 1 ) ? 0 : 1 ) ; } }

n , a , b = map ( int , input ( ) . split ( ) ) s = str ( input ( ) ) if s [ a - 1 ] == s [ b - 1 ] : print ( 0 ) else : print ( abs ( int ( s [ a - 1 ] ) - int ( s [ b - 1 ] ) ) ) NEW_LINE


if __name__ == ' _ _ main _ _ ' : n , a , b = map ( int , input ( ) . split ( ) ) s = input ( ) f = a - 1 t = b - 1 if a > b : f , t = t , f if a == b or s [ a - 1 ] == s [ b - 1 ] : print ( 0 ) else : print ( 1 ) NEW_LINE


if __name__ == " _ _ main _ _ " : n , a , b = map ( int , input ( ) . split ( ) ) s = input ( ) if s [ a - 1 ] == s [ b - 1 ] : print ( 0 ) else : print ( 1 ) NEW_LINE


n , a , b = map ( int , input ( ) . split ( ) ) s = input ( ) if ( s [ a - 1 ] == s [ b - 1 ] ) : NEW_LINE


import sysfrom os import pathif ( path . exists ( ' input . txt ' ) and path . exists ( ' output . txt ' ) ) : sys . stdout = open ( ' output . txt ' , ' w ' ) sys . stdin = open ( ' input . txt ' , ' r ' )   def main ( ) : n , a , b = ( int ( i ) for i in input ( ) . split ( ) ) a -= 1 b -= 1 s = input ( ) if s [ a ] == s [ b ] : print ( 0 ) else : ans = 1e6 i = 0 while i < n : if ans == 1 : break if s [ i ] == s [ a ] : for j in range ( i + 1 , n ) : if s [ j ] == s [ b ] : ans = min ( ans , abs ( i - j ) ) break if s [ i ] == s [ b ] : for j in range ( i + 1 , n ) : if s [ j ] == s [ a ] : ans = min ( ans , abs ( i - j ) ) break i += 1 print ( ans )     main ( ) NEW_LINE


import java . io . * ; import java . util . * ; import java . math . * ;   public class Main { static final Random random = new Random ( ) ; static PrintWriter out = new PrintWriter ( ( System . out ) ) ; static Reader sc = new Reader ( ) ;   public static void main ( String args [ ] ) throws IOException {


import java . util . Scanner ;   public class VladikFlights { public static void main ( String [ ] args ) {   Scanner in = new Scanner ( System . in ) ; int n = in . nextInt ( ) , a = in . nextInt ( ) - 1 , b = in . nextInt ( ) - 1 ; String s = in . next ( ) ;   in . close ( ) ; System . out . println ( s . charAt ( a ) == s . charAt ( b ) ? 0 : 1 ) ; } }


import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . io . PrintWriter ; import java . util . * ; import java . util . stream . IntStream ;   public class Main { public static void main ( String [ ] args ) throws IOException { Scanner input = new Scanner ( System . in ) ; int n = input . nextInt ( ) ; int a = input . nextInt ( ) - 1 ; int b = input . nextInt ( ) - 1 ; String s = input . next ( ) ; if ( s . charAt ( b ) == s . charAt ( a ) ) { System . out . println ( "0" ) ; } else { int min = Math . min ( a , b ) ; int max = Math . max ( a , b ) ; String sub = s . substring ( min + 1 , max ) ; int first = ( min + 1 ) + sub . indexOf ( ( s . charAt ( max ) == '1' ) ? "1" : "0" ) ; if ( first < 0 ) { System . out . println ( Math . abs ( min - max ) ) ; return ; } else System . out . println ( "1" ) ; } } }


import java . util . Arrays ; import java . util . Scanner ; import java . util . stream . IntStream ;   public class EqualRectangles { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; String testCase = scanner . nextLine ( ) ; int t = Integer . parseInt ( testCase ) ; String [ ] n = new String [ t ] ; String [ ] sticks = new String [ t ] ;    for ( int i = 0 ; i < t ; i ++ ) { n [ i ] = scanner . nextLine ( ) ; sticks [ i ] = scanner . nextLine ( ) ; } for ( int i = 0 ; i < t ; i ++ ) { solve ( n [ i ] , sticks [ i ] ) ; } }    public static void solve ( String n , String sticks ) { int r = Integer . parseInt ( n ) ; int [ ] s = Arrays . stream ( sticks . split ( " ▁ " ) ) . mapToInt ( Integer :: parseInt ) . sorted ( ) . toArray ( ) ; boolean helper = false ; boolean helper1 = false ;   int area = s [ 0 ] * s [ 4 * r - 1 ] ;    for ( int i = 0 ; i < 4 * r - 1 ; i = i + 2 ) { if ( s [ i ] == s [ i + 1 ] ) helper = true ; else { helper = false ; break ; } }   if ( ! helper ) System . out . println ( " NO " ) ; else { for ( int i = 1 ; i < 2 * r ; i = i + 2 ) { if ( s [ i ] * s [ 4 * r - i ] == area ) helper1 = true ; else { helper1 = false ; break ; } }   if ( helper1 ) System . out . println ( " YES " ) ; else System . out . println ( " NO " ) ;   } } }

import sys , math , itertoolsfrom collections import Counter , deque , defaultdictfrom bisect import bisect_left , bisect_right from heapq import heappop , heappush , heapifymod = 10 ** 9 + 7 INF = float ( ' inf ' ) def inp ( ) : return int ( sys . stdin . readline ( ) ) def inpl ( ) : return list ( map ( int , sys . stdin . readline ( ) . split ( ) ) ) def inpl_1 ( ) : return list ( map ( lambda x : int ( x ) - 1 , sys . stdin . readline ( ) . split ( ) ) ) def inps ( ) : return sys . stdin . readline ( ) def inpsl ( x ) : tmp = sys . stdin . readline ( ) ; return list ( tmp [ : x ] ) def err ( x ) : print ( x ) ; exit ( )   for _ in range ( inp ( ) ) : n = inp ( ) a = inpl ( ) c = Counter ( a ) res = 1 b = [ ] for key , va in c . items ( ) : if va % 2 : res = 0 for i in range ( va // 2 ) : b . append ( key ) if res == 0 : print ( ' NO ' ) ; continue b . sort ( ) se = set ( ) for i in range ( n * 2 ) : se . add ( b [ i ] * b [ - 1 - i ] ) print ( ' YES ' if len ( se ) == 1 else ' NO ' ) NEW_LINE


for _ in range ( int ( input ( ) ) ) : n = int ( input ( ) ) count = 0 a = list ( map ( int , input ( ) . split ( ) ) ) a . sort ( ) f = 0 p = a [ 0 ] * a [ 4 * n - 1 ] for i in range ( 0 , 4 * n , 2 ) : if a [ i ] * a [ 4 * n - 1 - i ] != p or a [ i ] != a [ i + 1 ] : f = 1   if f == 0 : print ( " YES " ) else : print ( " NO " ) NEW_LINE


from math import *   a = int ( input ( ) ) for x in range ( a ) : b = int ( input ( ) ) c = list ( map ( int , input ( ) . split ( ) ) ) c . sort ( ) t = 0 m = 0 for y in range ( 0 , ( 4 * b ) // 2 , 2 ) : if y == 0 : if ( c [ y ] == c [ y + 1 ] ) and ( c [ ( 4 * b ) - y - 1 ] == c [ ( 4 * b ) - y - 2 ] ) : t = c [ y ] * c [ ( 4 * b ) - y - 1 ] else : m = - 1 break   else : if ( c [ y ] * c [ ( 4 * b ) - y - 1 ] != t ) or ( c [ y ] != c [ y + 1 ] ) or ( c [ ( 4 * b ) - y - 1 ] != c [ ( 4 * b ) - y - 2 ] ) : m = - 1 break   if m == - 1 : print ( " NO " ) else : print ( " YES " ) NEW_LINE


t = int ( input ( ) ) for _ in range ( t ) :   n = int ( input ( ) ) li = list ( map ( int , input ( ) . split ( " ▁ " ) ) )   li . sort ( )   i = 0 j = len ( li ) - 1 area = li [ i ] * li [ j ] res = " YES " while i < j : if li [ i ] != li [ i + 1 ] or li [ j ] != li [ j - 1 ] or li [ i ] * li [ j ] != area : res = " NO " break   i += 2 j -= 2 print ( res )     NEW_LINE


import java . util . Arrays ; import java . util . Scanner ;   public class EqualRectangles { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int q = scanner . nextInt ( ) ;   while ( q -- != 0 ) { int n = scanner . nextInt ( ) ; int [ ] sides = new int [ ( 4 * n ) ] ;   for ( int i = 0 ; i < sides . length ; i ++ ) { sides [ i ] = scanner . nextInt ( ) ; } System . out . println ( solve ( sides , n ) ) ; } }   public static String solve ( int [ ] sides , int n ) { Arrays . sort ( sides ) ;   boolean ans = true ; int y = sides [ 0 ] * sides [ sides . length - 1 ] ; int j = sides . length - 1 ; for ( int i = 0 ; i < sides . length / 2 ; i += 2 , j -= 2 ) { if ( sides [ i ] == sides [ i + 1 ] && ( sides [ j ] == sides [ ( j - 1 ) ] ) && sides [ i ] * sides [ j ] == y ) { } else { ans = false ; break ; } }   if ( ans ) { return " YES " ; } else { return " NO " ; } } }


import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . io . PrintWriter ; import java . util . * ; import java . math . * ; public class code { static int dp [ ] [ ] ; static boolean visited [ ] ; static int ans = 0 ; public static void main ( String [ ] args ) throws IOException { FastReader sc = new FastReader ( ) ; PrintWriter pw = new PrintWriter ( System . out ) ; int t = sc . nextInt ( ) ; while ( t -- > 0 ) { int n = sc . nextInt ( ) ; int arr [ ] = new int [ 4 * n ] ; for ( int i = 0 ; i < 4 * n ; i ++ ) { arr [ i ] = sc . nextInt ( ) ; } Arrays . sort ( arr ) ; ArrayList < Integer > list = new ArrayList < > ( ) ; boolean flg = true ; n = 4 * n ; for ( int i = 0 ; i < n - 1 ; i += 2 ) { if ( arr [ i ] == arr [ i + 1 ] ) list . add ( arr [ i ] ) ; else { flg = false ; break ; } }


import java . util . * ;   public class EqualRectangles { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int cases = scanner . nextInt ( ) ; while ( ( cases -- ) != 0 ) { int n = scanner . nextInt ( ) ; ArrayList < Integer > list = new ArrayList < > ( ) ; int temp = n * 4 ; while ( ( temp -- ) != 0 ) { list . add ( scanner . nextInt ( ) ) ; } list . sort ( Comparator . comparingInt ( o -> o ) ) ; boolean state = true ; for ( int i = 0 ; i < list . size ( ) - 1 ; i += 2 ) { if ( ! list . get ( i ) . equals ( list . get ( i + 1 ) ) ) { state = false ; System . out . println ( " NO " ) ; break ; } } if ( state ) { int lastIndex = list . size ( ) - 1 ; TreeSet < Integer > couple = new TreeSet < > ( ) ; for ( int j = 0 ; j < list . size ( ) / 2 ; j ++ ) { couple . add ( list . get ( j ) * list . get ( lastIndex -- ) ) ; } if ( couple . size ( ) == 1 ) { System . out . println ( " YES " ) ; } else { System . out . println ( " NO " ) ; } } } } }


import java . util . Scanner ;   public class BadUglyNumbers { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int t = scanner . nextInt ( ) ; int [ ] array = new int [ t ] ;   for ( int i = 0 ; i < t ; i ++ ) { array [ i ] = scanner . nextInt ( ) ; }   for ( int i = 0 ; i < array . length ; i ++ ) solve ( array [ i ] ) ;    }   public static void solve ( int n ) { if ( n == 1 ) System . out . println ( - 1 ) ; else { System . out . print ( 2 ) ; for ( int i = 0 ; i < n - 1 ; i ++ ) { System . out . print ( 3 ) ; } System . out . println ( " ▁ " ) ; } } }

for _ in range ( int ( input ( ) ) ) : n = int ( input ( ) ) if n == 1 : print ( - 1 ) else : res = [ 3 ] * ( n - 1 ) res . insert ( 0 , 2 ) print ( * res , sep = ' ' ) NEW_LINE


for t in range ( int ( input ( ) ) ) : n = int ( input ( ) ) if n == 1 : print ( - 1 ) else : ans = "2" + ( "3" * ( n - 1 ) ) print ( ans ) NEW_LINE


def bad_ugly ( ) : for i in range ( int ( input ( ) ) ) : x = int ( input ( ) ) if ( x < 2 ) : print ( " - 1" ) else : print ( "5" + "7" * ( x - 1 ) )           bad_ugly ( )       NEW_LINE


def func ( s ) : for i in range ( s ) : n = int ( input ( ) ) if n == 1 : print ( ' - 1' ) else : ans = '2' + ( '3' * ( n - 1 ) ) print ( ans )   s = int ( input ( ) ) func ( s ) NEW_LINE


t = int ( input ( ) ) for i in range ( t ) : n = int ( input ( ) ) if n == 1 : print ( - 1 ) else : print ( '5' + '7' * ( n - 1 ) ) NEW_LINE


import java . util . Arrays ; import java . util . Scanner ;   public class BadUglyNumbers { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int testCases = scanner . nextInt ( ) ;   while ( testCases -- != 0 ) { int n = scanner . nextInt ( ) ; System . out . println ( solve ( n ) ) ; } }   public static String solve ( int n ) { if ( n == 1 ) { return " - 1" ; } String str = "2" ;   char [ ] chars = new char [ n - 1 ] ; Arrays . fill ( chars , '3' ) ; str = str + new String ( chars ) ; return str ; } }


import java . util . Scanner ;   public class task2 { static Scanner scanner = new Scanner ( System . in ) ;   public static void main ( String [ ] args ) { long a = scanner . nextInt ( ) ; for ( int i = 0 ; i < a ; i ++ ) { long num = scanner . nextInt ( ) ; for ( long j = 0 ; j < num ; j ++ ) { if ( num > 1 ) { if ( j == 0 ) System . out . print ( 2 ) ; else System . out . print ( 3 ) ; } else System . out . print ( - 1 ) ; } System . out . println ( ) ; }   } }


import java . io . * ; import java . util . StringTokenizer ;


import java . io . * ; import java . util . * ;   public class A { static ArrayList < Integer > g [ ] ; static int [ ] vis , cc ; public static void main ( String [ ] args ) throws IOException { FastReader f = new FastReader ( ) ; StringBuffer sb = new StringBuffer ( ) ; int n = f . nextInt ( ) ; int m = f . nextInt ( ) ; int k = f . nextInt ( ) ; Set < Integer > cap = new HashSet < > ( ) ; for ( int i = 0 ; i < k ; i ++ ) cap . add ( f . nextInt ( ) ) ; g = new ArrayList [ n + 1 ] ; for ( int i = 0 ; i <= n ; i ++ ) g [ i ] = new ArrayList < > ( ) ; vis = new int [ n + 1 ] ; cc = new int [ n + 1 ] ; List < String > list = new ArrayList < > ( ) ; for ( int i = 0 ; i < m ; i ++ ) { int x = f . nextInt ( ) ; int y = f . nextInt ( ) ; g [ x ] . add ( y ) ; g [ y ] . add ( x ) ; list . add ( x + " ▁ " + y ) ; } int c = 1 ; for ( int x : cap ) { dfs ( x , c ) ; c ++ ; }

import sysinput = sys . stdin . readline   class Unionfind : def __init__ ( self , n ) : self . par = [ - 1 ] * n self . rank = [ 1 ] * n def root ( self , x ) : r = x while not self . par [ r ] < 0 : r = self . par [ r ] t = x while t != r : tmp = t t = self . par [ t ] self . par [ tmp ] = r return r def unite ( self , x , y ) : rx = self . root ( x ) ry = self . root ( y ) if rx == ry : return if self . rank [ rx ] <= self . rank [ ry ] : self . par [ ry ] += self . par [ rx ] self . par [ rx ] = ry if self . rank [ rx ] == self . rank [ ry ] : self . rank [ ry ] += 1 else : self . par [ rx ] += self . par [ ry ] self . par [ ry ] = rx def is_same ( self , x , y ) : return self . root ( x ) == self . root ( y ) def count ( self , x ) : return - self . par [ self . root ( x ) ]   n , m , k = map ( int , input ( ) . split ( ) ) c = list ( map ( int , input ( ) . split ( ) ) ) uf = Unionfind ( n )   for _ in range ( m ) : u , v = map ( int , input ( ) . split ( ) ) uf . unite ( u - 1 , v - 1 )   sizes = [ uf . count ( ci - 1 ) for ci in c ] sizes . sort ( ) sizes [ - 1 ] += n - sum ( sizes ) ans = 0   for size in sizes : ans += size * ( size - 1 ) // 2   ans -= m   print ( ans ) NEW_LINE


import osimport sysfrom io import BytesIO , IOBaseBUFSIZE = 8192 class FastIO ( IOBase ) : newlines = 0 def __init__ ( self , file ) : self . _fd = file . fileno ( ) self . buffer = BytesIO ( ) self . writable = " x " in file . mode or " r " not in file . mode self . write = self . buffer . write if self . writable else None def read ( self ) : while True : b = os . read ( self . _fd , max ( os . fstat ( self . _fd ) . st_size , BUFSIZE ) ) if not b : break ptr = self . buffer . tell ( ) self . buffer . seek ( 0 , 2 ) , self . buffer . write ( b ) , self . buffer . seek ( ptr ) self . newlines = 0 return self . buffer . read ( ) def readline ( self ) : while self . newlines == 0 : b = os . read ( self . _fd , max ( os . fstat ( self . _fd ) . st_size , BUFSIZE ) ) self . newlines = b . count ( b " \n " ) + ( not b ) ptr = self . buffer . tell ( ) self . buffer . seek ( 0 , 2 ) , self . buffer . write ( b ) , self . buffer . seek ( ptr ) self . newlines -= 1 return self . buffer . readline ( ) def flush ( self ) : if self . writable : os . write ( self . _fd , self . buffer . getvalue ( ) ) self . buffer . truncate ( 0 ) , self . buffer . seek ( 0 ) class IOWrapper ( IOBase ) : def __init__ ( self , file ) : self . buffer = FastIO ( file ) self . flush = self . buffer . flush self . writable = self . buffer . writable self . write = lambda s : self . buffer . write ( s . encode ( " ascii " ) ) self . read = lambda : self . buffer . read ( ) . decode ( " ascii " ) self . readline = lambda : self . buffer . readline ( ) . decode ( " ascii " )     sys . stdin , sys . stdout = IOWrapper ( sys . stdin ) , IOWrapper ( sys . stdout ) input = lambda : sys . stdin . readline ( ) . rstrip ( " \n " ) NEW_LINE


from queue import Queue   n , m , k = [ int ( i ) for i in input ( ) . split ( ) ] govt = [ 0 for i in range ( n ) ] l = [ int ( i ) for i in input ( ) . split ( ) ] for i in l : govt [ i - 1 ] = 1 edges = [ ] adj = [ [ ] for i in range ( n ) ] for i in range ( m ) : x = [ int ( i ) for i in input ( ) . split ( ) ] adj [ x [ 0 ] - 1 ] . append ( x [ 1 ] - 1 ) adj [ x [ 1 ] - 1 ] . append ( x [ 0 ] - 1 ) parent = [ - 1 for i in range ( n ) ] mx = 0 ans = 0 visited = [ 0 for i in range ( n ) ] total_no_gov_nodes = 0 extra = 0 for i in range ( n ) : num_edges = 0 back = 0 num_nodes = 0 gov_exist = 0 if ( visited [ i ] == 0 ) : q = Queue ( ) q . put ( i ) visited [ i ] = 1 while ( q . empty ( ) != True ) : num_nodes += 1 tmp = q . get ( ) if ( govt [ tmp ] == 1 ) : gov_exist = 1 for child in adj [ tmp ] : if ( visited [ child ] == 0 ) : num_edges += 1 q . put ( child ) visited [ child ] = 1 parent [ child ] = tmp elif ( parent [ tmp ] != child ) : back += 1 num_edges += ( back / 2 ) num_edges = int ( num_edges ) if ( gov_exist == 1 ) : mx = max ( mx , num_nodes ) add = int ( ( num_nodes * ( num_nodes - 1 ) ) / 2 ) ans += ( add - num_edges ) if ( gov_exist == 0 ) : if ( total_no_gov_nodes == 0 ) : total_no_gov_nodes = num_nodes else : extra += ( total_no_gov_nodes * num_nodes ) total_no_gov_nodes += num_nodesans += extraans += ( mx * total_no_gov_nodes ) print ( ans ) NEW_LINE


from sys import stdin , stdout   def find ( node ) : x = [ ] while dsu [ node ] > 0 : x . append ( node ) node = dsu [ node ] for i in x : dsu [ i ] = node return node   def union ( node1 , node2 ) : if node1 != node2 : if dsu [ node1 ] > dsu [ node2 ] : node1 , node2 = node2 , node1 dsu [ node1 ] += dsu [ node2 ] dsu [ node2 ] = node1 edges [ node1 ] += edges [ node2 ] + 1 else : edges [ node1 ] += 1   n , m , k = map ( int , stdin . readline ( ) . strip ( ) . split ( ) ) arr = [ int ( num ) for num in stdin . readline ( ) . strip ( ) . split ( ) ] edges = [ 0 ] * ( n + 1 ) dsu = [ - 1 ] * ( n + 1 ) maxm = 1 maxm_e = 0 maxm_p = Nonefor __ in range ( m ) : a , b = map ( int , stdin . readline ( ) . strip ( ) . split ( ) ) union ( find ( a ) , find ( b ) ) req = set ( ) for i in arr : p_i = find ( i ) r_e = ( dsu [ p_i ] * ( dsu [ p_i ] + 1 ) ) // 2 maxm_e += r_e - edges [ p_i ] if abs ( dsu [ p_i ] ) >= maxm : maxm = max ( maxm , abs ( dsu [ p_i ] ) ) maxm_p = p_i req . add ( p_i )   for i in range ( 1 , n + 1 ) : if dsu [ i ] < 0 : p_i = find ( i ) if p_i not in req : r_e = ( dsu [ p_i ] * ( dsu [ p_i ] + 1 ) ) // 2 maxm_e += r_e - edges [ p_i ] maxm_e += dsu [ maxm_p ] * dsu [ p_i ] dsu [ maxm_p ] += dsu [ p_i ] stdout . write ( f ' { maxm _ e } ' ) NEW_LINE


n , m , k = map ( int , input ( ) . split ( ) )   a = set ( map ( int , input ( ) . split ( ) ) )   A = [ [ 0 for i in range ( n + 1 ) ] for i in range ( n + 1 ) ] visited = [ 0 for i in range ( n + 1 ) ]   for i in range ( m ) : u , v = map ( int , input ( ) . split ( ) ) A [ u ] [ v ] = 1 A [ v ] [ u ] = 1   e = 0   def dfs ( u ) : global e global v visited [ u ] = 1 e += 1 for i in range ( 1 , n + 1 ) : if A [ u ] [ i ] == 1 and visited [ i ] == 0 : dfs ( i )   return   max_e = 0 ans = 0   for u in a : e = 0 dfs ( u ) ans += e * ( e - 1 ) // 2 max_e = max ( max_e , e ) k = 0 for i in range ( 1 , n + 1 ) : if visited [ i ] == 0 : e = 0 dfs ( i ) k += e ans += ( max_e * k + k * ( k - 1 ) // 2 ) ans -= m   print ( max ( ans , 0 ) ) NEW_LINE


import java . util . * ; import java . io . * ; public class gfg { public static void main ( String [ ] args ) throws IOException {


import java . util . * ; import java . io . * ; public class Main { static PrintWriter w = new PrintWriter ( System . out ) ; public static void main ( String [ ] args ) { Scanner s = new Scanner ( System . in ) ; int n = s . nextInt ( ) ; if ( n > 36 ) w . println ( - 1 ) ; else { for ( int i = 1 ; i <= n / 2 ; i ++ ) w . print ( "8" ) ; if ( n % 2 == 1 ) w . print ( "4" ) ; } w . close ( ) ; } }

k = int ( input ( ) ) s = " " if k > 36 : print ( - 1 ) else : while k > 0 : if k >= 2 : s = s + "8" k = k - 2 else : s = s + "4" k = k - 1 print ( s ) NEW_LINE


import sysdef input ( ) : return sys . stdin . readline ( ) . strip ( ) def iinput ( ) : return int ( input ( ) ) def minput ( ) : return map ( int , input ( ) . split ( ) ) def listinput ( ) : return list ( map ( int , input ( ) . split ( ) ) ) n = iinput ( ) if n > 36 : print ( - 1 ) else : print ( "8" * ( n // 2 ) + "4" * ( n % 2 ) ) NEW_LINE


n = int ( input ( ) ) if ( n > 36 ) : print ( - 1 ) exit ( ) if ( n % 2 == 0 ) : for i in range ( n // 2 ) : print ( 8 , end = " " ) else : for i in range ( n // 2 ) : print ( 8 , end = " " ) print ( 4 , end = " " ) NEW_LINE


k = int ( input ( ) )   if k > 36 : print ( - 1 ) exit ( )   res = " "   res = res + "8" * ( k // 2 )   res = res + "9" * ( k % 2 )   print ( res )   NEW_LINE


import java . util . * ; public class contest10 { static Scanner scn = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { int k = scn . nextInt ( ) ; StringBuilder ans = new StringBuilder ( ) ; int lenCheck = 18 ; while ( k > 1 && ans . length ( ) < 20 ) { ans . append ( 8 ) ; k -= 2 ; } if ( k == 1 ) { ans . append ( 4 ) ; } if ( ans . length ( ) > 18 ) System . out . println ( " - 1" ) ; else System . out . println ( ans ) ; } }


import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int k = sc . nextInt ( ) ; if ( k > 36 ) { System . out . print ( " - 1" ) ; return ; } while ( k >= 2 ) { k -= 2 ; System . out . print ( "8" ) ; } if ( k == 1 ) { System . out . print ( "6" ) ; } } }


import java . util . * ; import java . util . stream . * ; public class Solution { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int n = scan . nextInt ( ) ; int next ; int aSum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { next = scan . nextInt ( ) ; aSum |= next ; } int bSum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { next = scan . nextInt ( ) ; bSum |= next ; } System . out . println ( aSum + bSum ) ; } }

from functools import reducedef solve ( n , a , b ) : return reduce ( lambda x , y : x | y , a ) + reduce ( lambda x , y : x | y , b )                         def main ( ) : NEW_LINE


n = int ( input ( ) ) a = list ( map ( int , input ( ) . split ( ) ) ) b = list ( map ( int , input ( ) . split ( ) ) )   def f ( x , l , r ) : t = 0 for i in x [ l : r ] : t |= i   return t   ms = 0 for s in range ( n , 0 , - 1 ) : for l in range ( 0 , s ) : r = l + s if r > n : break else : if ( f ( a , l , r ) + f ( b , l , r ) ) > ms : ms = f ( a , l , r ) + f ( b , l , r )   print ( ms ) 	 	 	   NEW_LINE


n = int ( input ( ) ) a = [ int ( x ) for x in input ( ) . split ( ) ] b = [ int ( x ) for x in input ( ) . split ( ) ] mxa = 0 for i in range ( n ) : cur = a [ i ] for j in range ( i , n ) : cur |= a [ j ] mxa = max ( mxa , cur ) mxb = 0 for i in range ( n ) : cur = b [ i ] for j in range ( i , n ) : cur |= b [ j ] mxb = max ( mxb , cur ) print ( mxa + mxb ) NEW_LINE


a = int ( input ( ) ) x1 = list ( map ( int , input ( ) . split ( ) ) ) x2 = list ( map ( int , input ( ) . split ( ) ) ) y1 = 0 y2 = 0 for i in range ( a ) : y1 |= x1 [ i ] y2 |= x2 [ i ] print ( y1 + y2 ) NEW_LINE


import sys     n = int ( sys . stdin . readline ( ) ) a = [ int ( x ) for x in sys . stdin . readline ( ) . strip ( ) . split ( ) ] b = [ int ( x ) for x in sys . stdin . readline ( ) . strip ( ) . split ( ) ] A = a [ 0 ] for x in a : A |= xB = b [ 0 ] for x in b : B |= x   print ( A + B ) NEW_LINE


import java . util . * ; public class Main { public static void main ( String args [ ] ) { Scanner in = new Scanner ( System . in ) ; int n = in . nextInt ( ) ; int a [ ] = new int [ n + 1 ] ; int b [ ] = new int [ n + 1 ] ; for ( int i = 1 ; i <= n ; i ++ ) a [ i ] = in . nextInt ( ) ; for ( int i = 1 ; i <= n ; i ++ ) b [ i ] = in . nextInt ( ) ; long a1 = 0 , b1 = 0 , ans = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { a1 = a1 | a [ i ] ; b1 = b1 | b [ i ] ; if ( a1 + b1 > ans ) ans = a1 + b1 ; } System . out . println ( ans ) ; } }


import java . util . Scanner ;   public class _0591Interview { static long XOR ( int i , int j , int [ ] a , int [ ] b ) { long XorA = 0 ; long XorB = 0 ; for ( int x = i ; x <= j ; x ++ ) { XorA = XorA | a [ x ] ; XorB = XorB | b [ x ] ; } return XorA + XorB ; }   public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] a = new int [ n ] ; int [ ] b = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = sc . nextInt ( ) ; } for ( int i = 0 ; i < n ; i ++ ) { b [ i ] = sc . nextInt ( ) ; } long max = - 1 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i ; j < n ; j ++ ) { max = Math . max ( max , XOR ( i , j , a , b ) ) ; } } System . out . println ( max ) ; }   }


import java . util . * ; import java . util . stream . Collectors ; import java . lang . * ; import java . io . * ; public class Problem { public static void main ( String [ ] args ) throws java . lang . Exception { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; System . out . println ( find ( s ) ) ; } public static String find ( String s ) { char [ ] ch = s . toCharArray ( ) ; char [ ] ar = new char [ 26 ] ; int i = 0 , j = 0 , ques = 0 ; Set < Character > set = new HashSet < Character > ( ) ; while ( j < s . length ( ) ) { if ( j >= 26 ) { if ( ch [ i ] == ' ? ' ) ques -- ; else { ar [ ch [ i ] - ' A ' ] -- ; if ( ar [ ch [ i ] - ' A ' ] == 0 ) set . remove ( ch [ i ] ) ; } i ++ ; } if ( ch [ j ] == ' ? ' ) ques ++ ; else { ar [ ch [ j ] - ' A ' ] ++ ; set . add ( ch [ j ] ) ; } if ( set . size ( ) + ques == 26 ) { String ans = process ( ch , i , j , set ) ; if ( ans . equals ( " - 1" ) ) return ans ; else { for ( int x = 0 ; x < ch . length ; x ++ ) { if ( ch [ x ] == ' ? ' ) ch [ x ] = ' A ' ; } return new String ( ch ) ; } } j ++ ; } return " - 1" ; } public static String process ( char [ ] ch , int i , int j , Set < Character > set ) { for ( char p = ' A ' ; p <= ' Z ' ; p ++ ) { if ( set . contains ( p ) ) set . remove ( p ) ; else set . add ( p ) ; }

word = input ( ) . lower ( )   if len ( word ) < 26 : print ( - 1 ) exit ( )   alpha = [ ' q ' , ' w ' , ' e ' , ' r ' , ' t ' , ' y ' , ' u ' , ' i ' , ' o ' , ' p ' , ' a ' , ' s ' , ' d ' , ' f ' , ' g ' , ' h ' , ' j ' , ' k ' , ' l ' , ' z ' , ' x ' , ' c ' , ' v ' , ' b ' , ' n ' , ' m ' ]   for i in range ( len ( word ) - 26 + 1 ) : cnt = 0 used = [ ] for char in alpha :   if word [ i : i + 26 ] . count ( char ) == 1 : used . append ( char )   if word [ i : i + 26 ] . count ( char ) < 2 : cnt += 1   if word [ i : i + 26 ] . count ( char ) >= 2 : cnt -= 500000 break   cnt -= 1   if cnt == 0 :   NEW_LINE


import collections   s = input ( ) n = len ( s ) if n < 26 : print ( - 1 ) exit ( ) d = [ 0 ] * 26 for i in range ( 25 ) : if s [ i ] != ' ? ' : d [ ord ( s [ i ] ) - ord ( ' A ' ) ] += 1   def check ( ) : return all ( d [ i ] <= 1 for i in range ( 26 ) )   b = Falsefor i in range ( 25 , n ) : if s [ i ] != ' ? ' : d [ ord ( s [ i ] ) - ord ( ' A ' ) ] += 1 if i >= 26 : if s [ i - 26 ] != ' ? ' : d [ ord ( s [ i - 26 ] ) - ord ( ' A ' ) ] -= 1 if check ( ) : for j in range ( n ) : if s [ j ] != ' ? ' : print ( s [ j ] , end = " " ) else : if j < i - 25 or j > i : print ( ' A ' , end = " " ) else : for k in range ( 26 ) : if d [ k ] == 0 : print ( chr ( ord ( ' A ' ) + k ) , end = " " ) d [ k ] = 1 break exit ( ) print ( - 1 ) NEW_LINE


import sysfrom math import * from string import ascii_uppercase   def ints_input ( ) : return [ int ( i ) for i in sys . stdin . readline ( ) . strip ( " \n " ) . split ( " ▁ " ) ]             def print_list ( arr ) : sys . stdout . writelines ( str ( x ) + " ▁ " for x in arr ) sys . stdout . write ( " \n " )     def fast_input ( type = str ) : return type ( sys . stdin . readline ( ) . strip ( " \n " ) )     s = fast_input ( ) if len ( s ) < 26 : print ( - 1 ) exit ( )   r , j = 0 , 25 found = Falsewhile not found and j < len ( s ) : sl = s [ r : j + 1 ] q = sl . count ( ' ? ' ) if len ( set ( sl ) ) + q - 1 == 26 or len ( set ( sl ) ) == 26 : found = True else : r += 1 j += 1 if not found : print ( - 1 ) exit ( ) d = { } for i in ascii_uppercase + ' ? ' : d [ i ] = 0   for i in sl : d [ i ] += 1 d . pop ( ' ? ' ) zz = list ( filter ( lambda x : not x [ 1 ] , d . items ( ) ) ) k = 0 s = list ( s ) for i in range ( len ( s ) ) : if s [ i ] == ' ? ' : if r <= i <= j : s [ i ] = zz [ k ] [ 0 ] k += 1 else : s [ i ] = ' A ' print ( " " . join ( s ) ) NEW_LINE


s = [ i for i in input ( ) ] ; n = len ( s ) NEW_LINE


import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . io . IOException ;   public class CompleteTheWord { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String s = br . readLine ( ) ; if ( s . length ( ) < 26 ) { System . out . println ( - 1 ) ; } else { boolean possible = true ; int left = 0 ; int right = 25 ; int [ ] count = new int [ 26 ] ; int counter = 0 ; for ( int i = 0 ; i <= 25 ; i ++ ) {


import java . util . * ; import java . io . * ; import java . math . * ; public class B372 {   public static void main ( String args [ ] ) { FastReader sc = new FastReader ( ) ; StringBuilder sb = new StringBuilder ( ) ; int t , i , n ; t = 1 ; while ( t -- > 0 ) { char s [ ] = sc . next ( ) . toCharArray ( ) ; n = s . length ; if ( n < 26 ) { sb . append ( - 1 ) . append ( ' \n ' ) ; continue ; } int j ; HashSet < Character > set = new HashSet < > ( ) ; boolean flag = false ; for ( i = 0 ; i < n ; i ++ ) { int count = 0 ; set . clear ( ) ; for ( j = i ; j <= i + 25 && i + 25 < n ; j ++ ) { if ( s [ j ] != ' ? ' ) set . add ( s [ j ] ) ; else count ++ ;


import java . util . ArrayList ; import java . util . HashSet ; import java . util . Scanner ;   public class CF716_D2_B { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; String s = scanner . next ( ) ; HashSet < Character > set = new HashSet < > ( ) ; int q = 0 ; char [ ] alphabet = " abcdefghijklmnopqrstuvwxyz " . toUpperCase ( ) . toCharArray ( ) ; int start = - 1 ; for ( int i = 0 ; i <= s . length ( ) - 26 ; i ++ ) {   for ( int j = 0 ; j < 26 ; j ++ ) { if ( Character . isAlphabetic ( s . charAt ( i + j ) ) ) { set . add ( s . charAt ( i + j ) ) ; } else if ( s . charAt ( i + j ) == ' ? ' ) { q ++ ; } } if ( set . size ( ) + q == 26 ) { start = i ; break ; } else { set = new HashSet < > ( ) ; q = 0 ; } } if ( start == - 1 ) { System . out . println ( - 1 ) ; } else { ArrayList < Character > missing = new ArrayList < > ( ) ; for ( char c : alphabet ) { if ( ! set . contains ( c ) ) { missing . add ( c ) ; } } StringBuilder builder = new StringBuilder ( ) ; builder . append ( s . substring ( 0 , start ) . replace ( ' ? ' , ' A ' ) ) ; int j = 0 ; for ( int i = 0 ; i < 26 ; i ++ ) { if ( s . charAt ( start + i ) == ' ? ' ) { builder . append ( missing . get ( j ++ ) ) ; } else { builder . append ( s . charAt ( start + i ) ) ; } } builder . append ( s . substring ( start + 26 ) . replace ( ' ? ' , ' A ' ) ) ; System . out . println ( builder . toString ( ) ) ;   }   } }


import java . io . BufferedWriter ; import java . io . ByteArrayInputStream ; import java . io . FileInputStream ; import java . io . FileWriter ; import java . io . IOException ; import java . io . InputStream ; import java . io . PrintWriter ; import java . util . ArrayList ; import java . util . Arrays ; import java . util . HashSet ; import java . util . InputMismatchException ; import java . util . List ; import java . util . Set ;   public class Main { private static final long MOD = ( long ) 1e9 + 7 ; static InputStream is ; static PrintWriter out ; static String INPUT = " " ; static int lenbuf = 0 , ptrbuf = 0 ; private static byte [ ] inbuf = new byte [ 1024 ] ; static boolean readFile = false ;


import java . io . BufferedReader ; import java . io . FileReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . Scanner ; import java . util . StringTokenizer ; import java . util . * ; import java . io . * ; public class codeforces { static class Student { int x , y ; Student ( int x , int y ) { this . x = x ; this . y = y ; } } static int sieveOfEratosthenes ( int n ) {

from math import ceilfor _ in range ( int ( input ( ) ) ) : x , y , p , q = map ( int , input ( ) . split ( ) ) if p == q and x != y : print ( - 1 ) elif p == q : print ( 0 ) elif p == 0 and x == 0 : print ( 0 ) elif p == 0 : print ( - 1 ) else : a = y // q r = y % q g1 = ( x - p * a + p - 1 ) // p g2 = ceil ( ( x - r - p * a ) / ( p - q ) ) print ( max ( g1 , g2 ) * q - r ) NEW_LINE


import java . util . * ; public class A0773_SuccessRate { public static void main ( String [ ] args ) {   Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; for ( int i = 0 ; i < n ; i ++ ) { long x = sc . nextInt ( ) ; long y = sc . nextInt ( ) ; long p = sc . nextInt ( ) ; long q = sc . nextInt ( ) ; if ( ! works ( x , y , p , q , 1000000000 ) ) { System . out . println ( - 1 ) ; continue ; } long l = 0 ; long r = 1000000000 ; while ( r > l ) { long mid = ( r + l ) / 2 ; if ( works ( x , y , p , q , mid ) ) r = mid ; else l = mid + 1 ; } System . out . println ( r * q - y ) ; } sc . close ( ) ; } public static boolean works ( long x , long y , long p , long q , long mid ) { if ( p * mid >= x && q * mid - p * mid >= y - x ) return true ; return false ; } }


import java . lang . * ; import java . util . * ;   public final class Solution { public static void main ( String [ ] args ) { Solution p = new Solution ( ) ; p . run ( ) ; } private void run ( ) { Scanner sc = new Scanner ( System . in ) ; int t = sc . nextInt ( ) ; for ( int i = 0 ; i < t ; i ++ ) { int x = sc . nextInt ( ) ; int y = sc . nextInt ( ) ; int p = sc . nextInt ( ) ; int q = sc . nextInt ( ) ; System . out . println ( solve ( x , y , p , q ) ) ; } } private long solve ( int x , int y , int p , int q ) { if ( p == 0 ) { if ( x != 0 ) { return - 1 ; } else { return 0 ; } } if ( p == q ) { if ( x != y ) { return - 1 ; } else { return 0 ; } } long k = ( long ) Math . ceil ( Math . max ( x * 1.0 / p , ( ( y - x ) * 1.0 / ( q - p ) ) ) ) ;   return ( ( k * q ) - y ) ; } }


# include < bits / stdc ++ . h > using namespace std ; # define int long long # define FAST ios_base :: sync_with_stdio ( false ) ; cin . tie ( 0 ) ; cout . tie ( 0 ) ;


import java . util . Scanner ;   public class B242 { public static void main ( String [ ] args ) { Scanner s = new Scanner ( System . in ) ; int n = s . nextInt ( ) ; int min = Integer . MAX_VALUE ; int max = Integer . MIN_VALUE ; int [ ] firsts = new int [ n ] ; int [ ] seconds = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { int first = s . nextInt ( ) ; int second = s . nextInt ( ) ; if ( first < min ) { min = first ; } if ( second > max ) { max = second ; } firsts [ i ] = first ; seconds [ i ] = second ; } boolean found = false ; for ( int i = 0 ; i < n ; i ++ ) { if ( firsts [ i ] == min && seconds [ i ] == max ) { System . out . println ( i + 1 ) ; found = true ; break ; } } if ( ! found ) { System . out . println ( - 1 ) ; } } }

def solution ( ) : n = int ( input ( ) ) k = [ ] mn = float ( ' Inf ' )   mx = float ( ' - Inf ' ) for i in range ( n ) : l , r = map ( int , input ( ) . split ( ) ) k . append ( ( l , r ) ) mn = min ( l , mn ) mx = max ( r , mx )   for i in range ( n ) : if k [ i ] [ 0 ] == mn and k [ i ] [ 1 ] == mx : print ( i + 1 ) return print ( - 1 ) return     solution ( ) NEW_LINE


def find_cover_all_seg ( n , l , r ) : min = l [ 0 ] index_min = [ ] max = r [ 0 ] index_max = [ ] for i in range ( n ) : if min >= l [ i ] : min = l [ i ] index_min . append ( i ) if max <= r [ i ] : max = r [ i ] index_max . append ( i ) common_index_list = list ( set ( index_min ) . intersection ( index_max ) ) NEW_LINE


l = list ( list ( map ( int , input ( ) . split ( ) ) ) for _ in range ( int ( input ( ) ) ) ) x = min ( i [ 0 ] for i in l ) y = max ( i [ 1 ] for i in l ) if [ x , y ] in l : print ( l . index ( [ x , y ] ) + 1 ) else : print ( " - 1" ) NEW_LINE


n = int ( input ( ) ) l = [ ] r = [ ] for i in range ( n ) : s , e = map ( int , input ( ) . split ( ) ) l . append ( s ) r . append ( e ) mn = l [ 0 ] mx = r [ 0 ]   for i in range ( n ) : if ( l [ i ] < mn ) : mn = l [ i ] if r [ i ] > mx : mx = r [ i ] flag = 1 p = 0 for i in range ( n ) : if l [ i ] <= mn and r [ i ] >= mx : p = i + 1 flag = 0 if flag == 0 : print ( p ) else : print ( - 1 ) NEW_LINE


n = int ( input ( ) ) p = [ ] al = [ ] bl = [ ] while n > 0 : n -= 1 a , b = map ( int , input ( ) . split ( ) ) p . append ( [ a , b ] ) al . append ( a ) bl . append ( b ) t1 = min ( al ) t2 = max ( bl ) if [ t1 , t2 ] in p : print ( p . index ( [ t1 , t2 ] ) + 1 ) else : print ( - 1 ) NEW_LINE


import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . * ;   public class experiment { static int M = 1_000_000_007 ; static int INF = Integer . MAX_VALUE ; static final FastScanner fs = new FastScanner ( ) ;


import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int T = sc . nextInt ( ) ; int min = Integer . MAX_VALUE ; int max = Integer . MIN_VALUE ; int ar [ ] [ ] = new int [ 2 ] [ T ] ; int result = - 1 ; for ( int i = 0 ; i < T ; i ++ ) { int first = sc . nextInt ( ) ; int second = sc . nextInt ( ) ; min = Math . min ( min , first ) ; max = Math . max ( max , second ) ; ar [ 0 ] [ i ] = first ; ar [ 1 ] [ i ] = second ; } for ( int i = 0 ; i < T ; i ++ ) { if ( ar [ 0 ] [ i ] == min && ar [ 1 ] [ i ] == max ) { result = i + 1 ; break ; } } System . out . println ( result ) ; } }


import java . util . * ;    public class dummycodes {   public static class Pair { int l ; int r ; int index ; public Pair ( int x , int y , int i ) { l = x ; r = y ; index = i ; } } public static class sortByL implements Comparator < Pair > { @ Override public int compare ( Pair o1 , Pair o2 ) { return ( o1 . l == o2 . l ) ? o2 . r - o1 . r : o1 . l - o2 . l ; }   }   public static void solve ( ArrayList < Pair > arr , int sze , int maxR ) { Collections . sort ( arr , new sortByL ( ) ) ; Pair P = arr . get ( 0 ) ; int a = P . l ; int b = P . r ;   if ( a <= b && b >= maxR ) System . out . println ( P . index + 1 ) ; else System . out . println ( " - 1" ) ; }   public static void main ( String args [ ] ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; ArrayList < Pair > arr = new ArrayList < > ( ) ; int max = - 1 ; for ( int i = 0 ; i < n ; i ++ ) { Pair p = new Pair ( sc . nextInt ( ) , sc . nextInt ( ) , i ) ; arr . add ( p ) ; if ( p . r > max ) max = p . r ; } solve ( arr , n , max ) ; } }


import java . io . * ; import java . util . * ; public class B { public static void main ( String [ ] args ) throws IOException { Scanner in = new Scanner ( System . in ) ; PrintWriter pw = new PrintWriter ( System . out ) ; int n = in . nextInt ( ) ; Long [ ] arr = new Long [ n ] ; for ( int i = 0 ; i < n ; i ++ ) arr [ i ] = in . nextLong ( ) ; pw . println ( solve ( arr , n ) ) ; pw . close ( ) ; } static long solve ( Long [ ] arr , int n ) { Arrays . sort ( arr ) ; long reng = ( long ) 1e15 ; long ans = ( long ) 1e15 ; boolean finished = false ; for ( long C = 1 ; ; C ++ ) { long res = 0 ; for ( long i = 0 , pw = 1 ; i < n ; i ++ , pw *= C ) { if ( pw >= reng ) { finished = true ; break ; } res += Math . abs ( ( arr [ ( int ) i ] - pw ) ) ; } if ( finished ) break ; ans = Math . min ( ans , res ) ; } return ans ; } static void debug ( Object ... obj ) { System . err . println ( Arrays . deepToString ( obj ) ) ; } }

import sys NEW_LINE input = sys . stdin . readline NEW_LINE import math NEW_LINE n = int ( input ( ) ) NEW_LINE a = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE a . sort ( ) NEW_LINE j = a [ 0 ] NEW_LINE c = 1 NEW_LINE mn = 10 ** 18 NEW_LINE inf = 10 ** 18 NEW_LINE if n <= 2 : NEW_LINE INDENT print ( a [ 0 ] - 1 ) NEW_LINE DEDENT else : NEW_LINE INDENT while c <= 10 ** 9 : NEW_LINE INDENT cnt = 0 NEW_LINE ok = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT k = c ** i - a [ i ] NEW_LINE cnt += abs ( k ) NEW_LINE if c ** i > inf : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT if cnt < mn : NEW_LINE INDENT mn = cnt NEW_LINE DEDENT if c ** ( n - 1 ) > mn + a [ - 1 ] : NEW_LINE INDENT break NEW_LINE DEDENT c += 1 NEW_LINE DEDENT print ( mn ) NEW_LINE DEDENT


n , s = open ( 0 ) ; NEW_LINE print ( min ( sum ( abs ( x - c ** i ) for i , x in enumerate ( sorted ( map ( int , s . split ( ) ) ) ) ) for c in range ( 2 + 9 ** 6 // int ( n ) ** 2 ) ) ) NEW_LINE