import java . util . * ; import java . util . Scanner ; import java . io . * ; import javax . lang . model . util . ElementScanner6 ; import static java . lang . System . out ; import java . util . Stack ; import java . util . Queue ; import java . util . LinkedList ;   public class B451M2 {   static int mod = ( int ) ( 1e9 + 7 ) ; static long MOD = ( long ) ( 1e9 + 7 ) ; static FastReader in = new FastReader ( ) ; static PrintWriter pr = new PrintWriter ( new BufferedWriter ( new OutputStreamWriter ( System . out ) ) ) ; public static void main ( String args [ ] ) {   int tc = 1 ;

import java . util . * ; import java . math . * ; public class SortTheArray { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int dexA = - 1 ; int dexB = - 1 ; int count = 0 ; boolean hit = false ; int temp = sc . nextInt ( ) ; int [ ] arr = new int [ n ] ; arr [ 0 ] = temp ; for ( int i = 1 ; i < n ; i ++ ) { int num = sc . nextInt ( ) ; arr [ i ] = num ; if ( temp >= num ) { if ( ! hit ) { count ++ ; dexA = i - 1 ; hit = true ; } } else { if ( hit ) { hit = false ; dexB = i - 1 ; } }   temp = num ;   } if ( dexB == - 1 ) dexB = n - 1 ; if ( count == 0 ) { System . out . println ( " yes " ) ; System . out . println ( 1 + " ▁ " + 1 ) ; } else { if ( count > 1 ) { System . out . println ( " no " ) ; } else { Arrays . sort ( arr , dexA , dexB + 1 ) ; boolean k = false ; for ( int i = 0 ; i < n - 1 ; i ++ ) { if ( arr [ i ] > arr [ i + 1 ] ) { System . out . println ( " no " ) ; k = true ; break ; } } if ( ! k ) { System . out . println ( " yes " ) ; dexA ++ ; dexB ++ ; System . out . println ( dexA + " ▁ " + dexB ) ; } } } } }

import java . util . Scanner ;   public class sortt {   public static void main ( String [ ] args ) { Scanner scn = new Scanner ( System . in ) ; int n = scn . nextInt ( ) ; int arr [ ] = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { arr [ i ] = scn . nextInt ( ) ; } sortt ( arr , n ) ;   } public static void sortt ( int arr [ ] , int n ) { int prefix [ ] = new int [ n ] ; prefix [ 0 ] = arr [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { prefix [ i ] = Math . max ( prefix [ i - 1 ] , arr [ i ] ) ; } int q = 1 ; int count = 1 ; int l = 1 , r = 1 ; while ( q < n ) { if ( prefix [ q ] == prefix [ q - 1 ] ) { l = q ; count -- ; while ( q < n && prefix [ q ] == prefix [ q - 1 ] ) { if ( arr [ q ] > arr [ q - 1 ] ) { System . out . println ( " no " ) ; return ; } else { q ++ ; } } r = q ; } else { q ++ ; } } if ( count >= 0 ) { if ( ( l - 2 ) >= 0 && arr [ r - 1 ] < arr [ l - 2 ] ) { System . out . println ( " no " ) ; } else { System . out . println ( " yes " ) ; System . out . println ( l + " ▁ " + r ) ; } } else { System . out . println ( " no " ) ; } }   }

n = int ( input ( ) ) arr = list ( map ( int , input ( ) . split ( ) ) ) p = sorted ( arr ) if ( p == arr ) : print ( ' yes ' ) print ( 1 , 1 ) else : flag = 1 flag1 = 0 i = 0 while ( i < n - 1 and arr [ i ] < arr [ i + 1 ] ) : i += 1 continue j = n - 1 while ( j > 0 and arr [ j ] > arr [ j - 1 ] ) : j -= 1 continue f = [ ] for k in range ( i ) : f . append ( arr [ k ] ) for k in range ( j , i - 1 , - 1 ) : f . append ( arr [ k ] ) for k in range ( j + 1 , len ( arr ) ) : f . append ( arr [ k ] ) arr . sort ( ) if ( f == arr ) : print ( " yes " ) print ( i + 1 , j + 1 ) else : print ( " no " ) NEW_LINE

def last_smaller ( xs , i ) : val = xs [ i ] res = i - 1 while res >= 0 and xs [ res ] == xs [ res + 1 ] : res -= 1 assert xs [ res ] <= xs [ i ] return res   def solve ( xs , n ) : xs = [ - float ( ' inf ' ) ] + xs + [ float ( ' inf ' ) ] increasing = 1 decreasing = 0 i0 , i1 , i2 = None , None , None for i in range ( n + 1 ) : if xs [ i ] > xs [ i + 1 ] : if increasing == 2 : print ( ' no ' ) return if decreasing == 0 : i0 = last_smaller ( xs , i ) i1 = i decreasing += 1 if xs [ i0 ] > xs [ i + 1 ] : print ( ' no ' ) return elif xs [ i ] < xs [ i + 1 ] : if decreasing == 1 and increasing == 1 : increasing += 1 if xs [ i + 1 ] < xs [ i1 ] : print ( ' no ' ) return i2 = i if i1 is None : i1 = i if i2 is None : i2 = i print ( ' yes \n { } ▁ { } ' . format ( i1 , i2 ) )   def main ( ) : n = int ( input ( ) ) xs = list ( map ( int , input ( ) . split ( ) ) ) solve ( xs , n )   if __name__ == ' _ _ main _ _ ' : main ( ) NEW_LINE

a = int ( input ( ) ) l = list ( map ( int , input ( ) . split ( ) ) ) turn = Falsep = [ ] for i in range ( a - 1 ) : if turn : if l [ i + 1 ] > l [ i ] : p . append ( i ) break else : if l [ i ] > l [ i + 1 ] : p . append ( i ) turn = Trueif len ( p ) == 0 : print ( " yes " ) print ( 1 , 1 ) else : t1 = sorted ( l ) if len ( p ) == 1 : p . append ( a - 1 ) l [ p [ 0 ] : p [ 1 ] + 1 ] = l [ p [ 0 ] : p [ 1 ] + 1 ] [ : : - 1 ] if t1 == l : print ( " yes " ) print ( p [ 0 ] + 1 , p [ 1 ] + 1 ) else : print ( " no " ) NEW_LINE

t = int ( input ( ) )   arr = list ( map ( int , input ( ) . split ( ) ) )   sarr = sorted ( arr )   def binary ( sarr , target ) : start = 0 end = len ( sarr ) - 1   while start <= end : mid = ( start + end ) // 2   if sarr [ mid ] == target : return mid elif sarr [ mid ] > target : end = mid - 1 else : start = mid + 1   return - 1         if arr == sarr : print ( " yes " ) print ( 1 , 1 ) else : for i in range ( len ( sarr ) - 1 ) : if arr [ i ] > arr [ i + 1 ] :       a = binary ( sarr , arr [ i ] )   newarr = arr [ : i ] + arr [ i : a + 1 ] [ : : - 1 ] + arr [ a + 1 : ]     if newarr == sarr : print ( " yes " ) print ( i + 1 , a + 1 ) break else : print ( " no " ) break           NEW_LINE

n = int ( input ( ) ) arr = [ int ( x ) for x in input ( ) . split ( ) ] srted = Truecansort = Falsedescending = Falseidx1 = 0 idx2 = 0   for i , val in enumerate ( arr [ : - 1 ] ) : if val > arr [ i + 1 ] and not descending : if srted and not cansort : cansort = True else : cansort = False break srted = False descending = True idx1 = i + 1 elif val < arr [ i + 1 ] and descending : descending = False idx2 = i + 1   if ( not descending and n >= idx2 + 1 and arr [ idx1 - 1 ] > arr [ idx2 ] ) or ( idx1 >= 2 and arr [ idx2 - 1 ] < arr [ idx1 - 2 ] ) : cansort = False   if not cansort and not srted : print ( ' no ' ) else : print ( ' yes ' ) if srted : print ( '1 ▁ 1' ) elif descending : print ( f ' { idx1 } ▁ { n } ' ) else : print ( f ' { idx1 } ▁ { idx2 } ' ) NEW_LINE


import java . io . IOException ; import java . util . * ; import java . util . Arrays ; import java . util . Scanner ;   public class Bit_year { static List < Integer > ans ; public static void process ( int [ ] ar ) { } public static void main ( String [ ] args ) throws IOException { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; String s = sc . next ( ) ; String t = sc . next ( ) ; int [ ] ar = new int [ 10 ] ; int [ ] br = new int [ 10 ] ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { ar [ Character . getNumericValue ( s . charAt ( i ) ) ] ++ ; } for ( int i = 0 ; i < s . length ( ) ; i ++ ) { br [ Character . getNumericValue ( t . charAt ( i ) ) ] ++ ; } System . out . println ( less ( ar . clone ( ) , br . clone ( ) ) ) ;

import java . io . * ; import java . util . * ; public class Asd { static PrintWriter w = new PrintWriter ( System . out ) ; static FastScanner s = new FastScanner ( ) ; static HashSet < Long > list = new HashSet < > ( ) ; public static void main ( String [ ] args ) { int t = 1 ;

import java . util . * ; import java . io . * ; import java . math . * ;   public class First {   public static void process ( ) throws IOException { int n = ni ( ) ; String s1 = nln ( ) ; String s2 = nln ( ) ; int s [ ] = new int [ n ] ; int m [ ] = new int [ n ] ;   for ( int i = 0 ; i < n ; i ++ ) { s [ i ] = Integer . parseInt ( String . valueOf ( s1 . charAt ( i ) ) ) ; m [ i ] = Integer . parseInt ( String . valueOf ( s2 . charAt ( i ) ) ) ; } Arrays . sort ( s ) ; Arrays . sort ( m ) ; int min = 0 , max = n ;   int i = 0 ; int j = 0 ; while ( i < n && j < n ) { if ( s [ i ] <= m [ j ] ) { i ++ ; } j ++ ; } if ( i < n ) { min = ( n - i ) ; } i = 0 ; j = 0 ; while ( i < n && j < n ) { if ( s [ i ] < m [ j ] ) { i ++ ; } j ++ ; } if ( i < n ) { max = i ; } pn ( min ) ; pn ( max ) ; }     static AnotherReader sc ; static PrintWriter out ; public static void main ( String [ ] args ) throws IOException { out = new PrintWriter ( System . out ) ; sc = new AnotherReader ( ) ; boolean oj = true ;

import sysimport itertoolsimport collections   def rs ( x = ' ' ) : return sys . stdin . readline ( ) . strip ( ) if len ( x ) == 0 else input ( x ) . strip ( ) def ri ( x = ' ' ) : return int ( rs ( x ) ) def rm ( x = ' ' ) : return map ( str , rs ( x ) . split ( ) ) def rl ( x = ' ' ) : return rs ( x ) . split ( ) def rmi ( x = ' ' ) : return map ( int , rs ( x ) . split ( ) ) def rli ( x = ' ' ) : return [ int ( x ) for x in rs ( x ) . split ( ) ] def println ( val ) : sys . stdout . write ( str ( val ) + ' \n ' )   def solve ( testCase ) : n = ri ( ) sher , mor = list ( rs ( ) ) , list ( rs ( ) ) sher = list ( map ( int , sher ) ) mor = list ( map ( int , mor ) ) sher . sort ( ) mor . sort ( ) i , j = 0 , 0 while i < n and j < n : if sher [ i ] > mor [ j ] : j += 1 else : i += 1 j += 1 minFlicks = n - i i , j = 0 , 0 while i < n and j < n : if sher [ i ] >= mor [ j ] : j += 1 else : i += 1 j += 1 maxFlicks = i print ( minFlicks ) print ( maxFlicks )   for _ in range ( ri ( ) if 0 else 1 ) : solve ( _ + 1 ) NEW_LINE

n = int ( input ( ) ) s1 = input ( ) s2 = input ( ) dp1 = [ 0 ] * 10 ; dp2 = [ 0 ] * 10 for i in s1 : dp1 [ int ( i ) ] += 1 for i in s2 : dp2 [ int ( i ) ] += 1 NEW_LINE

n = int ( input ( ) ) str_sher = str ( input ( ) ) str_mor = str ( input ( ) )   num_sher = [ 0 ] * 10 num_mor = [ 0 ] * 10 num_sher . append ( - 1 ) num_mor . append ( - 1 )   for s in str_sher : num_sher [ ord ( s ) - ord ( '0' ) ] += 1   for s in str_mor : num_mor [ ord ( s ) - ord ( '0' ) ] += 1   def next_value ( nums , p ) : if ( p > 10 ) : return p while ( nums [ p ] == 0 ) : p += 1 nums [ p ] -= 1 return p   def calc_hits ( num_sher , num_mor , is_min_strategy ) : shift = 0 if ( not is_min_strategy ) : shift = 1 p_sher = 0 num = 0 p_sher = next_value ( num_sher , p_sher ) p_mor = next_value ( num_mor , p_sher + shift )   while ( p_sher < 10 and p_mor < 10 ) : num += ( p_sher <= p_mor ) p_sher = next_value ( num_sher , p_sher ) p_mor = next_value ( num_mor , p_sher + shift )   if ( is_min_strategy ) : return n - num else : return num   print ( calc_hits ( num_sher . copy ( ) , num_mor . copy ( ) , True ) ) print ( calc_hits ( num_sher . copy ( ) , num_mor . copy ( ) , False ) ) NEW_LINE

n = int ( input ( ) ) s = list ( input ( ) ) t = list ( input ( ) ) for i in range ( n ) : s [ i ] = int ( s [ i ] ) t [ i ] = int ( t [ i ] ) s . sort ( ) t . sort ( ) c1 = 0 idx = 0 for i in range ( n ) : while idx < n and s [ i ] > t [ idx ] : idx += 1 if idx < n : c1 += 1 idx += 1 ans1 = n - c1c2 = 0 idx = 0 for i in range ( n ) : while idx < n and s [ i ] >= t [ idx ] : idx += 1 if idx < n : c2 += 1 idx += 1 ans2 = c2print ( ans1 ) print ( ans2 ) NEW_LINE


import java . util . * ;   public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int r = scan . nextInt ( ) ; int g = scan . nextInt ( ) ; int b = scan . nextInt ( ) ; int time = 0 ; while ( r > 0 || g > 0 || b > 0 ) { if ( time % 3 == 0 ) r -= 2 ; else if ( time % 3 == 1 ) g -= 2 ; else if ( time % 3 == 2 ) b -= 2 ; time ++ ; } time += 30 - 1 ; System . out . println ( time ) ; } }

import java . util . Scanner ;   public class Main {   public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ;   int r = sc . nextInt ( ) ; int g = sc . nextInt ( ) ; int b = sc . nextInt ( ) ;   System . out . println ( Math . max ( calculateTime ( r ) , Math . max ( 1 + calculateTime ( g ) , 2 + calculateTime ( b ) ) ) ) ; }   private static int calculateTime ( int x ) { if ( x == 0 ) { return 0 ; }   return 30 + ( ( x - 1 ) / 2 ) * 3 ; } }

import java . io . * ; import java . util . * ;   public class Cableway { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; StringTokenizer st = new StringTokenizer ( br . readLine ( ) ) ; int r = Integer . parseInt ( st . nextToken ( ) ) ; int g = Integer . parseInt ( st . nextToken ( ) ) ; int b = Integer . parseInt ( st . nextToken ( ) ) ; int max1 = Math . max ( ( r + 1 ) / 2 * 3 + 27 , ( g + 1 ) / 2 * 3 + 28 ) ; int max2 = Math . max ( ( g + 1 ) / 2 * 3 + 28 , ( b + 1 ) / 2 * 3 + 29 ) ; int max3 = Math . max ( ( r + 1 ) / 2 * 3 + 27 , ( b + 1 ) / 2 * 3 + 29 ) ; int time = Math . max ( max1 , Math . max ( max2 , max3 ) ) ; System . out . println ( time ) ; } }

import java . util . * ; import java . lang . Math ; public class test4 { public static void main ( String [ ] args ) { Scanner s = new Scanner ( System . in ) ; int r = s . nextInt ( ) ; int g = s . nextInt ( ) ; int b = s . nextInt ( ) ; int t = 29 ; int check = 0 ; while ( check == 0 ) { if ( r <= 0 && g <= 0 && b <= 0 ) { check = 1 ; } if ( check == 0 ) { r -= 2 ; t ++ ; } if ( r <= 0 && g <= 0 && b <= 0 ) { check = 1 ; } if ( check == 0 ) { g -= 2 ; t ++ ; } if ( r <= 0 && g <= 0 && b <= 0 ) { check = 1 ; } if ( check == 0 ) { b -= 2 ; t ++ ; } } System . out . println ( t ) ; } }

import java . util . * ;   public class CodeForces90A { public static void main ( String [ ] args ) { Scanner input = new Scanner ( System . in ) ; int r = input . nextInt ( ) ; int g = input . nextInt ( ) ; int b = input . nextInt ( ) ;   int [ ] a = new int [ 3 ] ; a [ 0 ] = ( r + 1 ) / 2 ; a [ 1 ] = ( g + 1 ) / 2 ; a [ 2 ] = ( b + 1 ) / 2 ; int max = 0 ; int index = 0 ; for ( int i = 0 ; i < 3 ; i ++ ) { if ( max <= a [ i ] ) { max = a [ i ] ; index = i ; } }   System . out . println ( ( ( max - 1 ) * 3 ) + index + 1 + 29 ) ; } }

r = lambda : list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE arr = r ( ) NEW_LINE c = 0 NEW_LINE i = 0 NEW_LINE while arr . count ( 0 ) != 3 : arr [ i % 3 ] = max ( 0 , arr [ i % 3 ] - 2 ) NEW_LINE c += 1 NEW_LINE i += 1   print ( 29 + c ) NEW_LINE

rgb = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE ans = 0 NEW_LINE for i in range ( 3 ) : temp = ( rgb [ i ] - 1 ) // 2 * 3 + 30 + i NEW_LINE ans = max ( temp , ans ) NEW_LINE print ( ans ) NEW_LINE

r , g , b = map ( int , input ( ) . split ( ) ) NEW_LINE x = 0 NEW_LINE while True : if NEW_LINE r > 0 : r -= 2 NEW_LINE r = max ( 0 , r ) NEW_LINE if r == g and g == b and g == 0 : break NEW_LINE x += 1 else : x += 1 NEW_LINE if g > 0 : g -= 2 NEW_LINE g = max ( 0 , g ) NEW_LINE if r == g and g == b and g == 0 : break NEW_LINE x += 1 else : x += 1 NEW_LINE if b > 0 : b -= 2 NEW_LINE b = max ( 0 , b ) NEW_LINE if r == g and g == b and g == 0 : break NEW_LINE x += 1 else : x += 1 NEW_LINE print ( x + 30 ) NEW_LINE

from math import ceilr , g , b = map ( int , input ( ) . split ( ) ) NEW_LINE r1 = 30 + ( ceil ( r / 2 ) - 1 ) * 3 NEW_LINE g1 = ( ceil ( g / 2 ) - 1 ) * 3 + 1 + 30 NEW_LINE b1 = ( ceil ( b / 2 ) - 1 ) * 3 + 2 + 30 NEW_LINE print ( max ( r1 , g1 , b1 ) ) NEW_LINE


import java . util . * ; import java . io . * ; public class A { static FastReader in = new FastReader ( ) ; static final Random random = new Random ( ) ; static long mod = 1000000007L ;   public static void main ( String args [ ] ) throws IOException { int t = 1 ;

import java . util . * ;   public class CodeForces304A { public static void main ( String [ ] args ) { Scanner input = new Scanner ( System . in ) ; int n = input . nextInt ( ) ; int a = 0 ; int b = 0 ; int c = 0 ; int count = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { a = i ; for ( int j = i ; j <= n ; j ++ ) { b = j ; c = ( int ) Math . sqrt ( ( a * a ) + ( b * b ) ) ; if ( a * a + b * b == c * c && c <= n ) { count ++ ; } } } System . out . println ( count ) ; } }

import java . util . Scanner ;   public class PythogoreanTriplets { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ;   int n = scan . nextInt ( ) ; int count = 0 ;   for ( int a = 2 ; a < n ; a ++ ) { for ( int b = 1 ; b < a ; b ++ ) { double c = Math . sqrt ( a * a + b * b ) ; if ( c - ( int ) c == 0.0 && c <= n ) count ++ ; } } System . out . println ( count ) ; } }

import java . util . * ;      public class geek {    public static void main ( String [ ] args ) { Scanner s = new Scanner ( System . in ) ; try { StringBuffer sb = new StringBuffer ( ) ; int n = s . nextInt ( ) ; int ans = 0 ;   for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = i ; j <= n ; j ++ ) {   double sqrt = Math . sqrt ( ( i * i ) + ( j * j ) ) ; if ( sqrt % 1 == 0 && sqrt <= n ) { ans ++ ; } } } sb . append ( ans + " \n " ) ;         System . out . println ( sb ) ;

import mathn = int ( input ( ) ) cnt = 0 for i in range ( 1 , n ) : for j in range ( 1 , i + 1 ) : c2 = int ( ( i * i ) + ( j * j ) ) NEW_LINE

from math import gcd , sqrtn = int ( input ( ) ) ; ans = 0 for i in range ( 5 , n + 1 ) : for j in range ( 1 , i ) : k = i ** 2 - j ** 2 if int ( sqrt ( k ) ) == sqrt ( k ) : ans += 1 print ( ans // 2 ) NEW_LINE

from math import gcd , sqrtn = int ( input ( ) ) ; ans = 0 ; sett = set ( ) for i in range ( 3 , n + 1 ) : for j in range ( i , n + 1 ) : k = i ** 2 + j ** 2 if int ( sqrt ( k ) ) == sqrt ( k ) and sqrt ( k ) <= n : ans += 1 print ( ans ) NEW_LINE

from math import sqrtn = int ( input ( ) ) count = 0 for i in range ( 1 , n + 1 ) : for j in range ( i , n + 1 ) : c = i ** 2 + j ** 2 if sqrt ( c ) == int ( sqrt ( c ) ) and sqrt ( c ) <= n : count += 1 print ( count ) NEW_LINE


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 ;

import java . util . HashSet ; import java . util . Scanner ;   public class Sasha_and_One_More_Name {   public static void main ( String [ ] args ) {   Scanner scn = new Scanner ( System . in ) ; String s = scn . next ( ) ; long [ ] hash = new long [ s . length ( ) ] ; long p = 1 ; long mod = 1000000007 ; long [ ] pp = new long [ s . length ( ) ] ; long [ ] hashs = new long [ s . length ( ) ] ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { long val = ( ( i > 0 ? hash [ i - 1 ] : 0 ) + ( ( s . charAt ( i ) - ' a ' + 1 ) * p ) % mod ) % mod ; long pre = ( ( i > 0 ? hashs [ i - 1 ] : 0 ) * 7919 ) % mod ; long sv = ( pre + ( s . charAt ( i ) - ' a ' + 1 ) ) % mod ; hash [ i ] = val ; hashs [ i ] = sv ; pp [ i ] = p ; p = ( p * 7919 ) % mod ;   } int n = s . length ( ) ; if ( hashs [ n - 1 ] != hash [ n - 1 ] ) { System . out . println ( " Impossible " ) ; } else {   if ( n % 2 == 0 ) { if ( s . chars ( ) . distinct ( ) . count ( ) == 1 ) { System . out . println ( " Impossible " ) ; } else { boolean got = false ; while ( n > 1 ) { if ( n % 2 == 1 ) { System . out . println ( 2 ) ; return ; } else { if ( hash [ n / 2 - 1 ] != hashs [ n / 2 - 1 ] ) { System . out . println ( 1 ) ; return ; } } n /= 2 ; } System . out . println ( 2 ) ; } return ; }

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

import sysfrom math import * from fractions import gcdreadints = lambda : map ( int , input ( ) . strip ( ' \n ' ) . split ( ) ) def ispal ( s ) : n = len ( s ) for i in range ( n // 2 ) : if s [ i ] != s [ n - i - 1 ] : return False return True s = input ( ) n = len ( s ) for i in range ( 1 , n ) : a , b = s [ : i ] , s [ i : ] t = b + a if t != s and ispal ( t ) : print ( 1 ) sys . exit ( 0 ) k = n / 2 if n % 2 == 1 : k = ceil ( k ) k = int ( k ) for i in range ( 1 , k ) : a , b , c = s [ : i ] , s [ i : - i ] , s [ - i : ] t = c + b + a if t != s and ispal ( t ) : print ( 2 ) sys . exit ( 0 ) print ( " Impossible " ) NEW_LINE


import java . util . * ;   public class questionCF {   public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int r = ( int ) Math . sqrt ( n ) ; for ( int i = r ; i >= 1 ; i -- ) { if ( n % i == 0 ) { System . out . println ( i + " ▁ " + n / i ) ; break ; } } } }

import java . util . * ;   public class Main { public static void main ( String [ ] args ) { Scanner input = new Scanner ( System . in ) ; int a = input . nextInt ( ) ; int ans1 = 0 , ans2 = 0 , minn = Integer . MAX_VALUE ; for ( int i = 1 ; i <= a ; i ++ ) { if ( a % i == 0 ) { int temp1 = i , temp2 = a / i ; if ( Math . abs ( temp2 - temp1 ) < minn ) { minn = Math . abs ( temp2 - temp1 ) ; ans1 = Math . min ( temp1 , temp2 ) ; ans2 = Math . max ( temp1 , temp2 ) ; } } } System . out . println ( ans1 + " ▁ " + ans2 ) ; }   public static int minCost ( int [ ] array ) { int len = array . length ; if ( len == 0 || len == 1 ) { return 0 ; } int sum = 0 ; LinkedList < Integer > queue = new LinkedList < > ( ) ; Arrays . sort ( array ) ; queue . offer ( array [ 0 ] ) ; for ( int i = 1 ; i < len ; i ++ ) { int temp = queue . getLast ( ) ; if ( array [ i ] <= temp ) { sum += temp - array [ i ] + 1 ; queue . addLast ( temp + 1 ) ; } else { queue . addLast ( temp ) ; } } return sum ; }   public static int mixx ( int a , int b , int c ) { return Math . min ( Math . min ( a , b ) , c ) ; } }

import java . util . * ;   public class Main {   public static void main ( String [ ] args ) { Main main = new Main ( ) ; Scanner scanner = new Scanner ( System . in ) ; int n = scanner . nextInt ( ) ; int num1 = 0 ; int num2 = 0 ; for ( int i = 1 ; i * i <= n ; i ++ ) { if ( n % i == 0 ) { num1 = i ; num2 = n / i ; } } System . out . println ( num1 + " ▁ " + num2 ) ; } }

import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int n = scan . nextInt ( ) ; int m = n ; int z = 1 ; for ( int i = 1 ; i < n ; i ++ ) { if ( n % i == 0 ) if ( Math . abs ( n / i - i ) < Math . abs ( m - z ) ) { m = i ; z = n / i ; } } if ( z > m ) { int temp = z ; z = m ; m = temp ; } System . out . println ( z + " ▁ " + m ) ;

import java . io . OutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . PrintWriter ; import java . util . StringTokenizer ; import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . io . InputStream ;   public class Main { public static void main ( String [ ] args ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; Scanner in = new Scanner ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; ADisplaySize solver = new ADisplaySize ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; }   static class ADisplaySize { int n ;   public void readInput ( Scanner sc ) { n = sc . nextInt ( ) ; }   public void solve ( int testNumber , Scanner sc , PrintWriter pw ) { int q = 1 ; while ( q -- > 0 ) { readInput ( sc ) ; String ans = "1 ▁ " + n ; for ( int i = 1 ; i * i <= n ; i ++ ) { if ( n % i == 0 ) { ans = i + " ▁ " + n / i ; } } pw . println ( ans ) ; } }   }   static class Scanner { StringTokenizer st ; BufferedReader br ;   public Scanner ( InputStream s ) { br = new BufferedReader ( new InputStreamReader ( s ) ) ; }   public String next ( ) { try { while ( st == null || ! st . hasMoreTokens ( ) ) st = new StringTokenizer ( br . readLine ( ) ) ; return st . nextToken ( ) ; } catch ( Exception e ) { throw new RuntimeException ( e ) ; } }   public int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; }   } }

def factors ( n ) : return [ ( i , int ( n / i ) ) for i in range ( 1 , int ( n ** 0.5 ) + 1 ) if n % i == 0 ] NEW_LINE

n = int ( input ( ) ) a = int ( n ** .5 ) while n % a : a -= 1 print ( a , n // a ) NEW_LINE

n = int ( input ( ) ) a = int ( n ** 0.5 ) while n % a : a -= 1 print ( a , n // a ) NEW_LINE

c = [ ] import mathn = int ( input ( ) ) for i in range ( 1 , n + 1 ) : if n % i == 0 : c . append ( i ) min = 9999999 a = b = int ( math . sqrt ( n ) ) for i in range ( 1 , len ( c ) ) : m = c [ i ] - c [ i - 1 ] if m < min and c [ i ] * c [ i - 1 ] == n : a = c [ i ] b = c [ i - 1 ] min = mprint ( b , a ) NEW_LINE

import mathn = int ( input ( ) ) a = int ( math . sqrt ( n ) ) while ( n % a != 0 ) : a = a - 1 print ( a , n // a ) NEW_LINE


import java . io . * ; import java . util . * ; import java . math . * ; import java . math . BigInteger ;    public final class A { static StringBuilder ans = new StringBuilder ( ) ; static FastReader in = new FastReader ( ) ; static ArrayList < ArrayList < Integer > > g , tg ; static long mod = 998244353 ; static boolean set [ ] , nodes [ ] ; static int par [ ] , col [ ] ; static char G [ ] [ ] ; static int dp [ ] [ ] ;

import java . util . * ; import java . io . * ;   public class Dynasty_Puzzles { 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 ) { int n = Integer . parseInt ( br . readLine ( ) ) ;   long dp [ ] [ ] = new long [ 26 ] [ 26 ] ; for ( int i = 0 ; i < n ; i ++ ) { String x = br . readLine ( ) . trim ( ) ; int a = x . charAt ( 0 ) - ' a ' ; int b = x . charAt ( x . length ( ) - 1 ) - ' a ' ;   for ( int j = 0 ; j < 26 ; j ++ ) { if ( dp [ j ] [ a ] == 0 ) continue ; dp [ j ] [ b ] = Math . max ( dp [ j ] [ b ] , dp [ j ] [ a ] + x . length ( ) ) ; }   dp [ a ] [ b ] = Math . max ( dp [ a ] [ b ] , x . length ( ) ) ; } long ans = 0 ; for ( int i = 0 ; i < 26 ; i ++ ) { ans = Math . max ( ans , dp [ i ] [ i ] ) ; }   pw . println ( ans ) ; } pw . flush ( ) ; }   }

import java . io . * ; import java . util . * ;   public class Main { private static InputReader in ; private static PrintWriter out ;   public static void main ( String [ ] args ) { in = new InputReader ( ) ; out = new PrintWriter ( System . out ) ; int t = 1 ;

import java . util . * ; public class CF { private static void sport ( String [ ] a ) { int [ ] [ ] dp = new int [ 26 ] [ 26 ] ; boolean [ ] [ ] can = new boolean [ 26 ] [ 26 ] ; int ans = 0 ; for ( String s : a ) { int l = s . charAt ( 0 ) - ' a ' ; int r = s . charAt ( s . length ( ) - 1 ) - ' a ' ; for ( int i = 0 ; i < 26 ; i ++ ) { if ( can [ i ] [ l ] ) { can [ i ] [ r ] = true ; dp [ i ] [ r ] = Math . max ( dp [ i ] [ r ] , dp [ i ] [ l ] + s . length ( ) ) ; } } can [ l ] [ r ] = true ; dp [ l ] [ r ] = Math . max ( dp [ l ] [ r ] , s . length ( ) ) ; } for ( int i = 0 ; i < 26 ; i ++ ) { ans = Math . max ( ans , dp [ i ] [ i ] ) ; } System . out . println ( ans ) ; }   public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; String [ ] a = new String [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = sc . next ( ) ; } sport ( a ) ; } }

import java . util . * ; public class CF { private static void sport ( String [ ] a ) { int [ ] [ ] dp = new int [ 26 ] [ 26 ] ; boolean [ ] [ ] can = new boolean [ 26 ] [ 26 ] ; int ans = 0 ; for ( String s : a ) { int l = s . charAt ( 0 ) - ' a ' ; int r = s . charAt ( s . length ( ) - 1 ) - ' a ' ; for ( int i = 0 ; i < 26 ; i + + ) { if ( can [ i ] [ l ] ) { can [ i ] [ r ] = true ; dp [ i ] [ r ] = Math . max ( dp [ i ] [ r ] , dp [ i ] [ l ] + s . length ( ) ) ; } } can [ l ] [ r ] = true ; dp [ l ] [ r ] = Math . max ( dp [ l ] [ r ] , s . length ( ) ) ; } for ( int i = 0 ; i < 26 ; i + + ) { ans = Math . max ( ans , dp [ i ] [ i ] ) ; } System . out . println ( ans ) ; }   public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; String [ ] a = new String [ n ] ; for ( int i = 0 ; i < n ; i + + ) { a [ i ] = sc . next ( ) ; } sport ( a ) ; } } NEW_LINE

from sys import stdinn = int ( stdin . readline ( ) . strip ( ) ) l = [ stdin . readline ( ) . strip ( ) for i in range ( n ) ] dp = [ ] for i in range ( 26 ) : dp . append ( [ - 999999999 ] * 26 ) ans = 0 for i in range ( 26 ) : dp [ i ] [ i ] = 0 for j in range ( n ) : first = ord ( l [ j ] [ 0 ] ) - 97 ln = len ( l [ j ] ) last = ord ( l [ j ] [ ln - 1 ] ) - 97 dp [ i ] [ last ] = max ( dp [ i ] [ last ] , dp [ i ] [ first ] + ln ) ans = max ( ans , dp [ i ] [ i ] ) print ( ans ) NEW_LINE

from sys import stdinn = int ( stdin . readline ( ) ) l = [ [ 0 for i in range ( 26 ) ] for i in range ( 26 ) ] for i in range ( n ) : s = stdin . readline ( ) . strip ( ) NEW_LINE

from sys import stdininput = stdin . readlinen = int ( input ( ) ) s = list ( input ( ) . strip ( ) for _ in range ( n ) ) dp = [ [ 0 for i in range ( 28 ) ] for j in range ( 28 ) ] for i in range ( n ) : a , b = ord ( s [ i ] [ 0 ] ) - ord ( ' a ' ) , ord ( s [ i ] [ - 1 ] ) - ord ( ' a ' ) for j in range ( 26 ) : if dp [ j ] [ a ] > 0 : dp [ j ] [ b ] = max ( dp [ j ] [ b ] , dp [ j ] [ a ] + len ( s [ i ] ) ) dp [ a ] [ b ] = max ( dp [ a ] [ b ] , len ( s [ i ] ) ) res = 0 for i in range ( 26 ) : res = max ( res , dp [ i ] [ i ] ) print ( res ) NEW_LINE


import java . util . Scanner ;   public class MaximumInTable { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int n = scanner . nextInt ( ) ;   int [ ] [ ] arr = new int [ n ] [ n ] ;    for ( int i = 0 ; i < n ; i ++ ) { arr [ 0 ] [ i ] = 1 ; }   for ( int i = 0 ; i < n ; i ++ ) { arr [ i ] [ 0 ] = 1 ; }   int res = calculateValue ( n - 1 , n - 1 , arr ) ; System . out . println ( res ) ;   }   private static int calculateValue ( int i , int j , int [ ] [ ] arr ) { if ( arr [ i ] [ j ] != 0 ) { return arr [ i ] [ j ] ; }   int result = calculateValue ( i - 1 , j , arr ) + calculateValue ( i , j - 1 , arr ) ;   arr [ i ] [ j ] = result ; return result ; } }

import java . util . Scanner ;    public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] [ ] a = new int [ n + 1 ] [ n + 1 ] ; for ( int i = 1 ; i <= n ; i ++ ) { a [ i ] [ 1 ] = 1 ; for ( int j = 1 ; j <= n ; j ++ ) { a [ 1 ] [ j ] = 1 ; a [ i ] [ j ] = a [ i - 1 ] [ j ] + a [ i ] [ j - 1 ] ; } } if ( n == 1 ) { System . out . println ( 1 ) ; } else System . out . println ( a [ n ] [ n ] ) ; } }

import java . util . * ;   public class maxVal { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] [ ] a = new int [ n ] [ n ] ; for ( int i = 0 ; i < n ; ++ i ) { if ( i == 0 ) { for ( int j = 0 ; j < n ; ++ j ) { a [ i ] [ j ] = 1 ; a [ j ] [ i ] = 1 ; } } else { for ( int j = 1 ; j < n ; ++ j ) a [ i ] [ j ] = a [ i - 1 ] [ j ] + a [ i ] [ j - 1 ] ; } } System . out . println ( a [ n - 1 ] [ n - 1 ] ) ; } }

import java . util . Scanner ;   public class Main {   public static void main ( String [ ] args ) { Scanner input = new Scanner ( System . in ) ; int n = input . nextInt ( ) ; int t [ ] [ ] = new int [ n + 1 ] [ n + 1 ] ; for ( int i = 1 ; i <= n ; i ++ ) { t [ i ] [ 1 ] = 1 ; } for ( int i = 1 ; i <= n ; i ++ ) { t [ 1 ] [ i ] = 1 ; } for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = 1 ; j <= n ; j ++ ) { if ( i <= 1 || j <= 1 ) { continue ; } t [ i ] [ j ] = t [ i - 1 ] [ j ] + t [ i ] [ j - 1 ] ; } } int max = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = 1 ; j <= n ; j ++ ) { max = Math . max ( max , t [ i ] [ j ] ) ; } } System . out . println ( max ) ; }   }

import java . util . Scanner ;   public class Codeforces {   public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int size = sc . nextInt ( ) ; int [ ] ans = new int [ size ] ; for ( int i = 0 ; i < size ; i ++ ) { for ( int j = 0 ; j < size ; j ++ ) { if ( j == 0 ) { ans [ j ] = 1 ; } else { ans [ j ] += ans [ j - 1 ] ; } } } System . out . println ( ans [ size - 1 ] ) ; } }

size_of_table = int ( input ( ) ) mat = [ [ 1 for x in range ( size_of_table ) ] for y in range ( size_of_table ) ] for i in range ( 1 , size_of_table ) : for j in range ( 1 , size_of_table ) : mat [ i ] [ j ] = mat [ i - 1 ] [ j ] + mat [ i ] [ j - 1 ] print ( mat [ size_of_table - 1 ] [ size_of_table - 1 ] ) NEW_LINE

n = int ( input ( ) ) matrix = [ [ 1 for i in range ( n ) ] for j in range ( n ) ] for i in range ( 1 , n ) : for j in range ( 1 , n ) : matrix [ i ] [ j ] = matrix [ i - 1 ] [ j ] + matrix [ i ] [ j - 1 ] print ( matrix [ n - 1 ] [ n - 1 ] ) NEW_LINE

n = int ( input ( ) ) l = [ [ 0 for i in range ( n ) ] for i in range ( n ) ] s = [ ] for i in range ( n ) : for j in range ( n ) : if ( i == 0 or j == 0 ) : l [ i ] [ j ] = 1 s . append ( l [ i ] [ j ] ) else : l [ i ] [ j ] = l [ i - 1 ] [ j ] + l [ i ] [ j - 1 ] s . append ( l [ i ] [ j ] ) print ( max ( s ) ) NEW_LINE


import java . util . * ; public class Solution { public static void main ( String [ ] args ) { Scanner s = new Scanner ( System . in ) ; int n = s . nextInt ( ) ; int a = s . nextInt ( ) ; int b = s . nextInt ( ) ; int d [ ] = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) d [ i ] = s . nextInt ( ) ; int min = Math . min ( a , b ) ; int j = 0 , k = n - 1 , ans = 0 ; while ( j <= k ) { boolean v = check ( d , j , k ) ; boolean v1 = check1 ( d , j , k ) ; if ( v == false ) { ans = - 1 ; break ; } else if ( v1 == true ) { if ( d [ j ] == d [ k ] && d [ k ] == 2 ) { if ( j == k ) ans = ans + min ; else if ( j < k ) ans = ans + min * 2 ; } else { if ( d [ j ] == 0 || d [ k ] == 0 ) ans = ans + a ; else if ( d [ j ] == 1 || d [ k ] == 1 ) ans = ans + b ; } } j ++ ; k -- ; } System . out . println ( ans ) ; } public static boolean check ( int [ ] d , int j , int k ) { boolean v = true ; if ( ( d [ j ] == 0 && d [ k ] == 1 ) || ( d [ j ] == 1 && d [ k ] == 0 ) ) { v = false ; } return v ; } public static boolean check1 ( int [ ] d , int j , int k ) { boolean v = true ; if ( ( d [ j ] == 0 && d [ k ] == 0 ) || ( d [ j ] == 1 && d [ k ] == 1 ) ) { v = false ; } return v ; } }

import java . util . * ;     public class geek {   public static int gcd ( int a , int b ) { if ( b == 0 ) { return a ; } return gcd ( b , a % b ) ; }    public static void main ( String [ ] args ) { try { Scanner s = new Scanner ( System . in ) ;   int n = s . nextInt ( ) ; int x = s . nextInt ( ) ; int y = s . nextInt ( ) ; int min = Math . min ( x , y ) ; int a [ ] = new int [ n ] ;

def solve ( ) : n , a , b = map ( int , input ( ) . split ( ) ) c = list ( map ( int , input ( ) . split ( ) ) ) i , j = 0 , n - 1 prices = [ a , b ] ans = 0 while i < j : if c [ i ] == c [ j ] : if c [ i ] == 2 : ans += 2 * min ( prices ) else : cc = sorted ( [ c [ i ] , c [ j ] ] ) if cc [ 1 ] == 2 : ans += prices [ cc [ 0 ] ] else : return - 1 i += 1 j -= 1 if n % 2 == 1 and c [ n // 2 ] == 2 : ans += min ( prices ) return ans   print ( solve ( ) ) NEW_LINE

n , a , b = list ( map ( int , input ( ) . split ( ) ) ) s = list ( map ( int , input ( ) . split ( ) ) ) ans = 0 for i in range ( n ) : if s [ i ] == 2 : if s [ n - 1 - i ] == 2 : ans = ans + min ( a , b ) elif s [ n - 1 - i ] == 0 : ans = ans + a else : ans = ans + b else : if s [ n - 1 - i ] != 2 and s [ n - 1 - i ] != s [ i ] : print ( " - 1" ) exit ( ) print ( ans ) NEW_LINE

n , a , b = list ( map ( int , input ( ) . split ( ) ) ) s = list ( map ( int , input ( ) . split ( ) ) ) c = 0 possible = Trueif s . count ( 2 ) == 0 : if s == s [ : : - 1 ] : c = 0 else : possible = Falseelse : if s == s [ : : - 1 ] : c = min ( a , b ) * ( s . count ( 2 ) ) else : for i in range ( 0 , n // 2 ) : if s [ i ] == s [ ( i * ( - 1 ) ) - 1 ] : if s [ i ] == 2 : c += min ( a , b ) * 2 continue else : if s [ i ] != 2 and s [ ( i * ( - 1 ) ) - 1 ] != 2 : possible = False break else : if s [ i ] == 0 or s [ ( i * ( - 1 ) ) - 1 ] == 0 : c += a else : c += b if n % 2 != 0 and s [ n // 2 ] == 2 : c += min ( a , b ) print ( c if possible else - 1 ) NEW_LINE

import mathno_of_dancers , cost_of_white , cost_of_black = map ( int , input ( ) . split ( ) ) costume = list ( map ( int , input ( ) . split ( ) ) )   cost = 0 flag = 1   for i in range ( 0 , math . ceil ( no_of_dancers / 2 ) ) : flag = 0 if ( costume [ i ] == 2 or costume [ - i - 1 ] == 2 ) : flag = 1 if ( costume [ i ] == 2 and costume [ - i - 1 ] == 2 ) : cost += 2 * min ( cost_of_black , cost_of_white ) if ( i == math . floor ( no_of_dancers / 2 ) ) : cost -= min ( cost_of_black , cost_of_white ) elif ( costume [ i ] == 2 and costume [ - i - 1 ] != 2 ) : if ( costume [ - i - 1 ] == 1 ) : cost += cost_of_black else : cost += cost_of_white elif ( costume [ i ] != 2 and costume [ - i - 1 ] == 2 ) : if ( costume [ i ] == 1 ) : cost += cost_of_black else : cost += cost_of_white elif ( costume [ i ] == costume [ - i - 1 ] ) : flag = 1 pass else : break                       if ( flag == 0 ) : print ( - 1 ) else : print ( cost )     NEW_LINE

def solve ( ) : n , a , b = map ( int , input ( ) . split ( ) ) c = list ( map ( int , input ( ) . split ( ) ) ) i , j = 0 , n - 1 prices = [ a , b ] ans = 0 while i < j : if c [ i ] == c [ j ] : if c [ i ] == 2 : ans += 2 * min ( prices ) else : if c [ i ] == 2 : ans += prices [ c [ j ] ] elif c [ j ] == 2 : ans += prices [ c [ i ] ] else : return - 1 i += 1 j -= 1 if n % 2 == 1 and c [ n // 2 ] == 2 : ans += min ( prices ) return ans   print ( solve ( ) ) NEW_LINE


import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . StringTokenizer ;   public class World_Cup { 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 ( ) ) ; } String nextLine ( ) { String str = " " ; try { str = br . readLine ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } return str ; } double nextDouble ( ) { return Double . parseDouble ( next ( ) ) ; } }   public static void main ( String [ ] args ) { FastReader in = new FastReader ( ) ; int n = in . nextInt ( ) ; int arr [ ] = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { arr [ i ] = in . nextInt ( ) ; } int brr [ ] = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { brr [ i ] += arr [ i ] / n ; if ( i >= ( arr [ i ] % n ) ) { brr [ i ] += 1 ; } else { brr [ i ] += 2 ; } } int ans = brr [ 0 ] ; int ind = 0 ; for ( int i = 1 ; i < n ; i ++ ) { if ( ans > brr [ i ] ) { ans = brr [ i ] ; ind = i ; } } ind ++ ; System . out . println ( ind ) ; } }

import java . util . Scanner ; public class BREAK { public static void main ( String [ ] args ) { Scanner obj = new Scanner ( System . in ) ; int n = obj . nextInt ( ) ; int [ ] arr = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { arr [ i ] = obj . nextInt ( ) ; } int k = 0 ; for ( int i = 0 ; ; i ++ ) { if ( i == n ) i = 0 ; if ( arr [ i ] - k <= 0 ) { System . out . println ( i + 1 ) ; break ; } k ++ ; } } }

import java . io . * ; import java . util . * ;   public class B { public static void main ( String [ ] args ) { FastScanner sc = new FastScanner ( ) ; int t = 1 ;

def STR ( ) : return list ( input ( ) ) def INT ( ) : return int ( input ( ) ) def MAP ( ) : return map ( int , input ( ) . split ( ) ) def MAP2 ( ) : return map ( float , input ( ) . split ( ) ) def LIST ( ) : return list ( map ( int , input ( ) . split ( ) ) ) def STRING ( ) : return input ( ) import stringimport sysfrom heapq import heappop , heappushfrom bisect import * from collections import deque , Counter , defaultdictfrom math import * from itertools import permutations , accumulatedx = [ - 1 , 1 , 0 , 0 ] dy = [ 0 , 0 , 1 , - 1 ] NEW_LINE

import mathn = int ( input ( ) ) a = list ( map ( int , input ( ) . split ( ) ) ) k = [ ] mn = 10000000000 for i in range ( n ) : sm = math . ceil ( ( a [ i ] - i ) / n ) if sm < mn : mn = sm ind = iprint ( ind + 1 ) NEW_LINE

from math import ceil   for u in range ( 1 ) : n = int ( input ( ) ) x = [ int ( w ) for w in input ( ) . split ( ) ] ans = [ ] for i in range ( n ) : if ( i + 1 >= x [ i ] + 1 ) : ans . append ( i + 1 ) else : t = ceil ( ( x [ i ] + 1 - ( i + 1 ) ) / n ) ans . append ( i + 1 + t * n ) a = min ( ans ) print ( ans . index ( a ) + 1 ) NEW_LINE


import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . StringTokenizer ;   public class Solution { public static void main ( String [ ] args ) throws IOException { BufferedReader reader = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int n = Integer . parseInt ( reader . readLine ( ) ) ; int [ ] arr = new int [ 1000001 ] ; StringTokenizer sToken = new StringTokenizer ( reader . readLine ( ) ) ; for ( int i = 0 ; i < n ; i ++ ) { arr [ Integer . parseInt ( sToken . nextToken ( ) ) ] ++ ; } int rest = 0 ; int res = 0 ; for ( int i = 0 ; i <= 1000000 ; i ++ ) { res += ( ( rest + arr [ i ] ) % 2 ) ; rest = ( rest + arr [ i ] ) / 2 ; } for ( int i = 0 ; i < 40 ; i ++ ) { res += ( rest % 2 ) ; rest = rest / 2 ; } System . out . println ( res ) ; } }

import java . io . * ; import java . math . * ; import java . util . * ;     public class Main {   private static int dx [ ] = { 1 , 0 , - 1 , 0 } ; private static int dy [ ] = { 0 , - 1 , 0 , 1 } ;   private static final long INF = ( long ) Math . pow ( 10 , 16 ) ; private static final int INT_INF = Integer . MAX_VALUE ; private static final long NEG_INF = Long . MIN_VALUE ; private static final int NEG_INT_INF = Integer . MIN_VALUE ; private static final double EPSILON = 1e-10 ;   private static final long MAX = ( long ) 1e12 ; private static final long MOD = 1000000007 ;   private static final int MAXN = 200001 ; private static final int MAXA = 1000007 ; private static final int MAXLOG = 22 ; private static final double PI = Math . acos ( - 1 ) ; public static void main ( String [ ] args ) throws IOException {   InputReader in = new InputReader ( System . in ) ;

import java . util . * ; import java . io . * ; import java . math . BigInteger ; import java . text . * ; public class Main { static long mod = 1000_000_007 ; static long mod1 = 998244353 ; static boolean fileIO = true ; static boolean memory = true ; static FastScanner f ; static PrintWriter pw ; static double eps = ( double ) 1e-6 ; static int oo = ( int ) 2e9 ;

n = int ( input ( ) ) l = list ( map ( int , input ( ) . split ( ) ) ) cnt = [ 0 ] * ( 10 ** 6 + 100 ) for i in l : cnt [ i ] += 1 s = 0 ans = 0 for i in cnt : s += i ans += s % 2 s //= 2 print ( ans ) NEW_LINE

import sysreadline = sys . stdin . readline   N = int ( readline ( ) ) A = list ( map ( int , readline ( ) . split ( ) ) ) K = 100 + max ( A ) L = [ 0 ] * Kfor a in A : L [ a ] += 1   for i in range ( K ) : if L [ i ] > 1 : L [ i + 1 ] += L [ i ] // 2 L [ i ] = L [ i ] % 2 print ( sum ( L ) ) 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


import java . util . * ; public class Solution { static Scanner sc = new Scanner ( System . in ) ; public static void main ( String args [ ] ) { int n = sc . nextInt ( ) ; int a = n / 2 ; int b = n / 2 + ( n % 2 ) ; int ans = ( a + 1 ) * ( b + 1 ) ; if ( n % 2 != 0 ) ans *= 2 ; System . out . println ( ans ) ; } }

import java . util . Scanner ;   public class T0406 {   public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int n = scanner . nextInt ( ) ; System . out . println ( f ( n ) ) ;   }   private static int f ( int n ) { if ( n == 1 ) { return 4 ; } if ( n == 2 ) { return 4 ; } if ( n == 3 ) { return 12 ; } if ( n % 2 == 0 ) { return ( n / 2 + 1 ) * ( n / 2 + 1 ) ; } else { return ( n / 2 + 2 ) * ( n / 2 + 1 ) * 2 ; } }   }

import java . util . Scanner ; public class suanfa5 { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int m = 0 ; if ( n % 2 == 0 ) { int res = ( n / 2 + 1 ) ; m = res * res ; } else { m = ( n + 3 ) * ( n + 1 ) / 2 ; } System . out . println ( m ) ; } }

import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . StringTokenizer ;   public class Main { public static void main ( String [ ] args ) throws IOException { int n = Reader . nextInt ( ) ; int res = 4 ; if ( ( n & 1 ) == 0 ) { while ( n > 2 ) { res += n + 1 ; n -= 2 ; } } else { while ( n > 1 ) { res += 2 * ( n + 1 ) ; n -= 2 ; } } System . out . println ( res ) ; }   static class Reader { static BufferedReader reader = new BufferedReader ( new InputStreamReader ( System . in ) ) ; static StringTokenizer tokenizer = new StringTokenizer ( " " ) ;   static String next ( ) throws IOException { while ( ! tokenizer . hasMoreTokens ( ) ) { tokenizer = new StringTokenizer ( reader . readLine ( ) ) ; } return tokenizer . nextToken ( ) ; }   static int nextInt ( ) throws IOException { return Integer . parseInt ( next ( ) ) ; } } }

import java . util . Scanner ;   public class B1459 {   public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int N = in . nextInt ( ) ; int answer ; if ( N % 2 == 0 ) { answer = ( N / 2 + 1 ) * ( N / 2 + 1 ) ; } else { answer = ( N + 2 ) * ( N + 2 ) / 2 ; } System . out . println ( answer ) ; }   }

n = int ( input ( ) ) NEW_LINE if ( n % 2 == 0 ) : NEW_LINE INDENT print ( int ( ( n / 2 + 1 ) ** 2 ) ) else : NEW_LINE n = ( n + 1 ) / 2 NEW_LINE DEDENT print ( int ( 4 + ( ( n - 1 ) * ( 2 * 8 + ( n - 2 ) * 4 ) ) / 2 ) ) NEW_LINE

n = int ( input ( ) ) NEW_LINE m = n // 2 l = n - mans = ( m + 1 ) * ( l + 1 ) NEW_LINE if n % 2 == 1 : ans *= 2 NEW_LINE print ( ans ) NEW_LINE

n = int ( input ( ) ) NEW_LINE res = 0 NEW_LINE if n % 2 : NEW_LINE INDENT res = ( 2 + n // 2 ) * ( n + 1 ) else : NEW_LINE res = ( 1 + n // 2 ) ** 2 NEW_LINE DEDENT print ( res ) NEW_LINE

n = int ( input ( ) )   if n % 2 == 0 : NEW_LINE INDENT print ( int ( ( ( n / 2 ) + 1 ) * ( ( n / 2 ) + 1 ) ) ) else : NEW_LINE print ( int ( ( 2 + ( n - 1 ) / 2 ) * ( 2 * ( ( n - 1 ) / 2 + 1 ) ) ) ) NEW_LINE DEDENT


import java . io . FileInputStream ; import java . io . FileNotFoundException ; import java . io . IOException ; import java . io . PrintWriter ; import java . util . Arrays ; import java . util . Collection ; import java . util . List ; import java . util . Scanner ; import java . util . function . Function ; import java . util . stream . Collectors ; public class _p000624A { static public void main ( final String [ ] args ) throws IOException { p000624A . _main ( args ) ; }

import java . util . * ; public class Code { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int d = in . nextInt ( ) ; int L = in . nextInt ( ) ; int v1 = in . nextInt ( ) ; int v2 = in . nextInt ( ) ; System . out . println ( ( double ) ( L - d ) / ( v1 + v2 ) ) ; } }

import java . util . * ; import java . io . * ;   public class HelloWorld {   public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; double n1 = ( double ) scanner . nextInt ( ) ; int n2 = scanner . nextInt ( ) ; int n3 = scanner . nextInt ( ) ; int n4 = scanner . nextInt ( ) ; double ans = ( n2 - n1 ) / ( n3 + n4 ) ; System . out . println ( ans ) ; } }

import java . util . Scanner ;     public class submission { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int d = in . nextInt ( ) ; int l = in . nextInt ( ) ; int v1 = in . nextInt ( ) ; int v2 = in . nextInt ( ) ; double distance = l - d ; double v = v1 + v2 ; double t = distance / v ; System . out . println ( t ) ; } }

import java . util . Scanner ;   public class SaveLuke { public static void main ( String [ ] args ) {   Scanner in = new Scanner ( System . in ) ; double d = in . nextDouble ( ) , l = in . nextDouble ( ) , v1 = in . nextDouble ( ) , v2 = in . nextDouble ( ) ;   in . close ( ) ; System . out . println ( ( l - d ) / ( v1 + v2 ) ) ; } }

d , L , v1 , v2 = map ( int , input ( ) . split ( ) ) ans = float ( ( L - d ) / ( v1 + v2 ) ) print ( ans ) NEW_LINE

d , l , v1 , v2 = map ( int , input ( ) . split ( ) ) print ( ( l - d ) / ( v1 + v2 ) ) NEW_LINE

d , l , v1 , v2 = list ( map ( int , input ( ) . split ( ) ) ) print ( ( l - d ) / ( v1 + v2 ) ) NEW_LINE

d , l , v1 , v2 = map ( int , ( input ( ) . split ( ) ) )   ans = ( l - d ) / ( v1 + v2 )   print ( ans ) NEW_LINE

d , L , v1 , v2 = map ( int , input ( ) . split ( ) ) print ( ( L - d ) / ( v1 + v2 ) ) NEW_LINE


import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; double a = ( Math . sqrt ( 8 * sc . nextInt ( ) + 1 ) - 1 ) / 2 ; if ( a == ( int ) a ) System . out . println ( " YES " ) ; else System . out . println ( " NO " ) ; } }

import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; check ( n ) ; } public static void check ( int n ) { int t = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { t += i ; if ( t == n ) { System . out . println ( " YES " ) ; return ; } } System . out . println ( " NO " ) ; } }

n = int ( input ( ) ) encontrado = Falsenum = n * 2 a = 0 b = 1   while a * b <= num : if a * b == num : encontrado = True break a = a + 1 b = b + 1   if encontrado : print ( ' YES ' ) else : print ( ' NO ' ) NEW_LINE

n = int ( input ( ) ) f = False   for i in range ( 32 ) : if i * ( i + 1 ) / 2 == n : f = True break print ( ' YES ' if f else ' NO ' ) NEW_LINE

n = int ( input ( ) )   def tri_nums ( ) : arr = [ 0 ] a = 1 for i in range ( 31 ) : arr . append ( arr [ i ] + a ) a += 1 return ( arr )   tri_num = tri_nums ( )   if ( n in tri_num ) : print ( ' YES ' ) else : print ( ' NO ' ) NEW_LINE


import java . io . * ; import java . util . * ; public class Main { 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 ; } } static FastReader sc = new FastReader ( ) ; static long mod = ( long ) ( 1e9 + 7 ) ; public static void main ( String [ ] args ) throws Exception { PrintWriter out = new PrintWriter ( System . out ) ; int t = 1 ;

import java . util . * ;   public class A_Mafia { public static void main ( String args [ ] ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int i = 0 ; long ar [ ] = new long [ n ] ; long max = 0 ; long s = 0 ; for ( i = 0 ; i < n ; i ++ ) { ar [ i ] = sc . nextLong ( ) ; s += ar [ i ] ; max = Math . max ( max , ar [ i ] ) ; } long ans = Math . max ( ( ( s - 1 ) / ( n - 1 ) ) + 1 , max ) ; System . out . println ( ans ) ; } }

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

n = int ( input ( ) )   import sysdef get_ints ( ) : return list ( map ( int , sys . stdin . readline ( ) . strip ( ) . split ( ) ) )   arr = get_ints ( )   arr = sorted ( arr ) arr = arr [ : : - 1 ] maxs = arr [ 0 ] times = 0 for index , elem in enumerate ( arr ) : if index == n - 1 : break times += maxs - elem     lastelem = arr [ - 1 ] NEW_LINE

def binSearch ( ) : l , r = max_ , min_ + max_ while l < r : games = l + ( r - l ) // 2 if games * n - total > games : r = games elif games * n - total < games : l = games + 1 else : return games return l     n = int ( input ( ) ) rounds = list ( map ( int , input ( ) . split ( ) ) ) max_ , min_ , total = 0 , float ( ' inf ' ) , 0 for i in range ( n ) : max_ = max ( max_ , rounds [ i ] ) min_ = min ( min_ , rounds [ i ] ) total += rounds [ i ]   print ( binSearch ( ) ) NEW_LINE

n = int ( input ( ) ) l = list ( map ( int , input ( ) . split ( ) ) ) s = sum ( l ) q = s // ( n - 1 ) r = s % ( n - 1 ) if ( r ) : q += 1 print ( max ( max ( l ) , q ) ) NEW_LINE

import sys , os , ioimport math , bisect , operatorinf , mod = float ( ' inf ' ) , 10 ** 9 + 7 NEW_LINE

import math , sys , bisect , heapq , osfrom collections import defaultdict , Counter , dequefrom itertools import groupby , accumulatefrom functools import lru_cache NEW_LINE


import java . util . Scanner ;   public class TestBetter { public static void main ( String [ ] args ) { Scanner input = new Scanner ( System . in ) ;   int [ ] freqX = new int [ 109 ] , freqY = new int [ 109 ] ; int n ; n = input . nextInt ( ) ; for ( int i = 0 ; i < n ; i ++ ) { int x , y ; x = input . nextInt ( ) ; y = input . nextInt ( ) ; freqX [ x ] ++ ; freqY [ y ] ++ ; } int cntX = 0 ; int cntY = 0 ; for ( int i = 0 ; i <= 100 ; i ++ ) cntX += Boolean . compare ( ( freqX [ i ] > 0 ) , false ) ; for ( int i = 0 ; i <= 100 ; i ++ ) cntY += Boolean . compare ( ( freqY [ i ] > 0 ) , false ) ; System . out . println ( Math . min ( cntX , cntY ) ) ; } }

import java . util . HashSet ; import java . util . Scanner ;   public class InnaandAlarmClock {   public static void main ( String args [ ] ) { Scanner scan = new Scanner ( System . in ) ; int n = scan . nextInt ( ) ; HashSet < Integer > a = new HashSet < Integer > ( ) ; HashSet < Integer > b = new HashSet < Integer > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { a . add ( scan . nextInt ( ) ) ; b . add ( scan . nextInt ( ) ) ; } System . out . println ( Math . min ( a . size ( ) , b . size ( ) ) ) ; }   }

import java . io . * ; import java . util . * ;   public class Test { static BufferedReader reader ; static StringTokenizer tokenizer ; static PrintWriter writer ;   static int nextInt ( ) throws IOException { return Integer . parseInt ( nextToken ( ) ) ; }   static long nextLong ( ) throws IOException { return Long . parseLong ( nextToken ( ) ) ; }   static double nextDouble ( ) throws IOException { return Double . parseDouble ( nextToken ( ) ) ; }   static String nextToken ( ) throws IOException { while ( tokenizer == null || ! tokenizer . hasMoreTokens ( ) ) { tokenizer = new StringTokenizer ( reader . readLine ( ) ) ; } return tokenizer . nextToken ( ) ; } static String nexts ( ) throws IOException { tokenizer = new StringTokenizer ( reader . readLine ( ) ) ; String s = " " ; while ( tokenizer . hasMoreTokens ( ) ) { s += tokenizer . nextElement ( ) + " ▁ " ; } return s ; }

import java . util . HashSet ; import java . util . Scanner ; import java . util . Set ; import java . util . ArrayList ; import java . util . Collections ; import java . lang . Math ;   public class Lo { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; Set < Integer > X = new HashSet < Integer > ( ) ; Set < Integer > Y = new HashSet < Integer > ( ) ; int n = sc . nextInt ( ) ; for ( int i = 0 ; i < n ; i ++ ) { X . add ( sc . nextInt ( ) ) ; Y . add ( sc . nextInt ( ) ) ; } System . out . println ( Math . min ( X . size ( ) , Y . size ( ) ) ) ; } }

import java . util . * ; public class asd { static Scanner s = new Scanner ( System . in ) ; public static void main ( String args [ ] ) { int t = 1 ; while ( t -- > 0 ) { solve ( ) ; } } public static void solve ( ) { int n = s . nextInt ( ) ; HashMap < Integer , Integer > map1 = new HashMap < > ( ) ; HashMap < Integer , Integer > map2 = new HashMap < > ( ) ; while ( n -- > 0 ) { int a = s . nextInt ( ) ; int b = s . nextInt ( ) ; if ( map1 . containsKey ( a ) ) { map1 . replace ( a , 1 ) ; } else map1 . put ( a , 1 ) ;   if ( map2 . containsKey ( b ) ) { map2 . replace ( b , 1 ) ; } else map2 . put ( b , 1 ) ; } System . out . println ( Math . min ( map1 . size ( ) , map2 . size ( ) ) ) ;   } }

n = int ( input ( ) ) x = [ ] y = [ ] for i in range ( n ) : xt , yt = list ( map ( int , input ( ) . split ( ) ) ) x . append ( xt ) y . append ( yt ) x = list ( set ( x ) ) y = list ( set ( y ) )   print ( min ( len ( x ) , len ( y ) ) ) NEW_LINE

a = int ( input ( ) ) b = [ ] c = [ ] for i in range ( a ) : x , y = map ( int , input ( ) . split ( ) ) b . append ( x ) c . append ( y ) print ( min ( len ( set ( b ) ) , len ( set ( c ) ) ) ) NEW_LINE

n = int ( input ( ) ) x = { } y = { } for i in range ( n ) : a , b = [ int ( i ) for i in input ( ) . split ( ) ] x [ a ] = 0 y [ b ] = 0 print ( len ( x ) if len ( x ) <= len ( y ) else len ( y ) ) NEW_LINE

n = int ( input ( ) ) dr = { } dc = { } for i in range ( n ) : li = [ int ( x ) for x in input ( ) . split ( ) ] x , y = li [ 0 ] , li [ 1 ] if ( x in dr ) : dr [ x ] += 1 else : dr [ x ] = 1 if ( y in dc ) : dc [ y ] += 1 else : dc [ y ] = 1 print ( min ( len ( dr ) , len ( dc ) ) ) NEW_LINE

n = int ( input ( ) ) row = set ( ) col = set ( ) for _ in range ( n ) : a , b = list ( map ( int , input ( ) . split ( ) ) ) row . add ( a ) col . add ( b ) print ( min ( len ( row ) , len ( col ) ) ) NEW_LINE


import java . util . * ;   public class Solution {   static class Node { int x , y ;   Node ( int p ) { x = p ; y = p ; }   Node ( int p , int q ) { x = p ; y = q ; } }   public static long sum ( Queue < Node > queue , int x ) { long result = 0 ; boolean isRobotShutdown = false ; while ( ! queue . isEmpty ( ) ) { Node currNode = queue . remove ( ) ; if ( isRobotShutdown ) { result += currNode . y ; continue ; } if ( currNode . x % x == 0 ) { result += currNode . y ; currNode . x /= x ; queue . add ( currNode ) ; } else { result += currNode . y ; isRobotShutdown = true ; } } return result ; }   public static void main ( String args [ ] ) { Scanner in = new Scanner ( System . in ) ; int testCases = in . nextInt ( ) ; in . nextLine ( ) ; for ( int i = 0 ; i < testCases ; i ++ ) { int n = in . nextInt ( ) ; int x = in . nextInt ( ) ; in . nextLine ( ) ; Queue < Node > input = new LinkedList < Node > ( ) ; for ( int j = 0 ; j < n ; j ++ ) { input . add ( new Node ( in . nextInt ( ) ) ) ; } in . nextLine ( ) ; System . out . println ( sum ( input , x ) ) ; } } }

import java . util . Scanner ;   public class B1471 {   public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int T = in . nextInt ( ) ; for ( int t = 0 ; t < T ; t ++ ) { int N = in . nextInt ( ) ; int X = in . nextInt ( ) ; int [ ] A = new int [ N ] ; for ( int n = 0 ; n < N ; n ++ ) { A [ n ] = in . nextInt ( ) ; } long sum = 0 ; long factor = 1 ; main : while ( true ) { for ( int n = 0 ; n < N ; n ++ ) { if ( A [ n ] % factor == 0 ) { sum += A [ n ] ; } else { break main ; } } factor *= X ; } System . out . println ( sum ) ; } }   }

from collections import Countert = int ( input ( ) ) NEW_LINE for _ in range ( t ) : n , x = map ( int , input ( ) . split ( ) ) NEW_LINE ali = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE li = ali . copy ( ) NEW_LINE ans = sum ( ali ) NEW_LINE i = 0 NEW_LINE while ( ali [ i ] % x == 0 ) : ali [ i ] = ali [ i ] // x NEW_LINE ans += li [ i ] NEW_LINE i = ( i + 1 ) % n NEW_LINE

def strange_list ( arr , n , x ) : S = 0 NEW_LINE   minK = mk ( arr [ 0 ] , x ) NEW_LINE minKInd = 0   for i in range ( n ) : k = mk ( arr [ i ] , x ) NEW_LINE if k < minK : minK = k NEW_LINE minKInd = i   for i in range ( n ) : qmk = minK + 1 if i < minKInd else minK NEW_LINE S += arr [ i ] * ( qmk + 1 )   return S   NEW_LINE def mk ( q , x ) : k = 0 NEW_LINE while q % x == 0 : k += 1 NEW_LINE q = q / x NEW_LINE return k   if __name__ == " _ _ main _ _ " : t = int ( input ( ) ) NEW_LINE for i in range ( t ) : inps = input ( ) . split ( " ▁ " ) NEW_LINE n = int ( inps [ 0 ] ) NEW_LINE x = int ( inps [ 1 ] )   arr = list ( map ( lambda x : int ( x ) , input ( ) . split ( " ▁ " ) ) )   print ( " { 0 } " . format ( int ( strange_list ( arr , n , x ) ) ) )   NEW_LINE


import java . util . * ;   public class codechef {   public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int t = scanner . nextInt ( ) ; while ( t -- > 0 ) { int d = scanner . nextInt ( ) ; int k1 = scanner . nextInt ( ) ; int k2 = scanner . nextInt ( ) ;   int a [ ] = new int [ k1 ] ; int [ ] b = new int [ k2 ] ; for ( int i = 0 ; i < k1 ; i ++ ) a [ i ] = scanner . nextInt ( ) ; for ( int i = 0 ; i < k2 ; i ++ ) b [ i ] = scanner . nextInt ( ) ;   Arrays . sort ( a ) ; Arrays . sort ( b ) ; if ( a [ a . length - 1 ] > b [ b . length - 1 ] ) System . out . println ( " YES " ) ; else System . out . println ( " NO " ) ; } } }

import java . io . * ; import java . util . * ;   public class bacteria { public static void main ( String args [ ] ) { FScanner in = new FScanner ( ) ; PrintWriter out = new PrintWriter ( System . out ) ; int t = in . nextInt ( ) ; while ( t -- > 0 ) { int n = in . nextInt ( ) ; int k1 = in . nextInt ( ) ; int k2 = in . nextInt ( ) ; int a [ ] = in . readArray ( k1 ) ; int b [ ] = in . readArray ( k2 ) ; int max1 = Integer . MIN_VALUE ; int max2 = Integer . MIN_VALUE ; for ( int i = 0 ; i < k1 ; i ++ ) { if ( a [ i ] > max1 ) max1 = a [ i ] ;   } for ( int i = 0 ; i < k2 ; i ++ ) { if ( b [ i ] > max2 ) max2 = b [ i ] ;   } if ( max1 > max2 ) out . println ( " YES " ) ; else out . println ( " NO " ) ; } out . close ( ) ; }   static class FScanner { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; StringTokenizer sb = new StringTokenizer ( " " ) ; String next ( ) { while ( ! sb . hasMoreTokens ( ) ) { try { sb = new StringTokenizer ( br . readLine ( ) ) ; } catch ( IOException e ) { } } return sb . nextToken ( ) ; } String nextLine ( ) { try { return br . readLine ( ) ; } catch ( IOException e ) { } return " " ; } int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } long nextLong ( ) { return Long . parseLong ( next ( ) ) ; } int [ ] readArray ( int n ) { int a [ ] = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) a [ i ] = nextInt ( ) ; return a ; } float nextFloat ( ) { return Float . parseFloat ( next ( ) ) ; } double nextDouble ( ) { return Double . parseDouble ( next ( ) ) ; } } }

import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . io . PrintWriter ; import java . util . * ; public class C { static class FastScanner { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; StringTokenizer st = new StringTokenizer ( " " ) ;   String next ( ) { while ( ! st . hasMoreTokens ( ) ) try { st = new StringTokenizer ( br . readLine ( ) ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } return st . nextToken ( ) ; }   int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; }   int [ ] nextArray ( int n ) { int [ ] a = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) a [ i ] = nextInt ( ) ; return a ; }   long nextLong ( ) { return Long . parseLong ( next ( ) ) ; } } static class FastWriter extends PrintWriter { FastWriter ( ) { super ( System . out ) ; }   void println ( int [ ] array ) { for ( int i = 0 ; i < array . length ; i ++ ) { print ( array [ i ] + " ▁ " ) ; } println ( ) ; }   void println ( long [ ] array ) { for ( int i = 0 ; i < array . length ; i ++ ) { print ( array [ i ] + " ▁ " ) ; } println ( ) ; } } public static void main ( String [ ] args ) {

t = int ( input ( ) ) for i in range ( t ) : temp = [ int ( x ) for x in input ( ) . split ( ) ] n = temp [ 0 ] k1 = temp [ 1 ] k2 = temp [ 2 ] a = [ int ( x ) for x in input ( ) . split ( ) ] b = [ int ( x ) for x in input ( ) . split ( ) ] if max ( a ) > max ( b ) : print ( ' yes ' ) else : print ( ' no ' ) NEW_LINE

for _ in range ( int ( input ( ) ) ) : n , k1 , k2 = map ( int , input ( ) . split ( ) ) fir = sorted ( [ int ( i ) for i in input ( ) . split ( ) ] , reverse = True ) sec = sorted ( [ int ( i ) for i in input ( ) . split ( ) ] , reverse = True ) print ( ' YES ' if fir [ 0 ] > sec [ 0 ] else ' NO ' ) NEW_LINE

import sys   def main ( ) : l = sys . stdin . read ( ) . strip ( ) . split ( ' \n ' ) out = [ ] for i in range ( 2 , len ( l ) , 3 ) : m1 = max ( map ( int , l [ i ] . split ( ) ) ) m2 = max ( map ( int , l [ i + 1 ] . split ( ) ) ) out . append ( ( ' NO ' , ' YES ' ) [ m1 > m2 ] ) return out   print ( * main ( ) , sep = ' \n ' ) NEW_LINE

t = int ( input ( ) ) for i in range ( t ) : n , k1 , k2 = map ( str , input ( ) . split ( ) ) s1 , s2 = input ( ) . split ( ) , input ( ) . split ( ) if n in s1 : print ( " Yes " ) else : print ( " No " ) NEW_LINE


import java . io . * ; import java . lang . ref . SoftReference ; import java . math . BigInteger ; import java . util . * ;

import java . util . * ; public class NewColony {   public static void main ( String [ ] args ) {

import java . util . Scanner ;   public class B1481 {   public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int T = in . nextInt ( ) ; for ( int t = 0 ; t < T ; t ++ ) { int N = in . nextInt ( ) ; int K = in . nextInt ( ) ; int [ ] H = new int [ N ] ; for ( int n = 0 ; n < N ; n ++ ) { H [ n ] = in . nextInt ( ) ; } int pos = - 1 ; main : for ( int k = 0 ; k < K ; k ++ ) { pos = 0 ; while ( true ) { if ( pos == N - 1 ) { pos = - 1 ; break main ;

t = int ( input ( ) ) NEW_LINE for _ in range ( t ) : n , k = map ( int , input ( ) . split ( ) ) NEW_LINE ali = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE ans = - 1 NEW_LINE for i in range ( k ) : flag = 0 NEW_LINE for j in range ( n - 1 ) : if NEW_LINE INDENT ( ali [ j ] < ali [ j + 1 ] ) : ali [ j ] = ali [ j ] + 1 NEW_LINE DEDENT ans = j NEW_LINE flag = 1 NEW_LINE break NEW_LINE

t = int ( input ( ) ) NEW_LINE for _ in range ( t ) : n , k = [ int ( s ) for s in input ( ) . split ( " ▁ " ) ] NEW_LINE a = [ int ( s ) for s in input ( ) . split ( " ▁ " ) ] NEW_LINE mx = max ( a ) NEW_LINE if mx * n < k : NEW_LINE INDENT ans = - 1 else : NEW_LINE ans = n + 1 NEW_LINE DEDENT for i in range ( k ) : pos = - 2 NEW_LINE for i in range ( n - 1 ) : if NEW_LINE a [ i ] < a [ i + 1 ] : pos = i NEW_LINE break NEW_LINE ans = pos + 1 NEW_LINE if pos == - 2 : break NEW_LINE a [ pos ] += 1 NEW_LINE print ( ans ) NEW_LINE

t = int ( input ( ) ) NEW_LINE for i in range ( t ) : n , K = map ( int , input ( ) . split ( ) ) NEW_LINE arr = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE if n == 1 : print ( - 1 ) NEW_LINE continue NEW_LINE ans = 0 NEW_LINE for j in range ( K ) : k = 0 NEW_LINE while k < n - 1 : if NEW_LINE arr [ k ] < arr [ k + 1 ] : arr [ k ] += 1 NEW_LINE ans = k NEW_LINE break NEW_LINE k += 1 NEW_LINE if k == n - 1 : print ( - 1 ) NEW_LINE break NEW_LINE if k != n - 1 : print ( ans + 1 )   NEW_LINE

t = int ( input ( ) ) NEW_LINE for _ in range ( t ) : a , b = [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE c = [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE ans = 0 NEW_LINE flag = 0 NEW_LINE for i in range ( 0 , len ( c ) - 1 ) : if NEW_LINE INDENT ( c [ i ] >= c [ i + 1 ] ) : NEW_LINE DEDENT pass else : flag = 1 NEW_LINE if ( flag == 0 ) : NEW_LINE INDENT print ( - 1 ) else : NEW_LINE for NEW_LINE DEDENT j in range ( b ) : s = 0 NEW_LINE for k in range ( 0 , len ( c ) - 1 ) : if NEW_LINE INDENT ( c [ k ] >= c [ k + 1 ] ) : s += 1 else : c [ k ] += 1 NEW_LINE DEDENT ans = k + 1 NEW_LINE break NEW_LINE if ( s == a - 1 ) : break NEW_LINE if ( j <= b - 1 and s == a - 1 ) : NEW_LINE INDENT print ( - 1 ) else : NEW_LINE print ( ans ) NEW_LINE DEDENT


import java . math . BigInteger ; import java . util . * ;   public class Main {   static Scanner input = new Scanner ( System . in ) ;   public static void main ( String [ ] args ) { String s = input . next ( ) ; long len = s . length ( ) ; long res = Long . parseLong ( s ) ; long sumofDigits = getSum ( res ) ; for ( int i = 0 ; i < len - 1 ; i ++ ) { if ( s . charAt ( i ) == '0' ) continue ; long number = Long . parseLong ( s ) ; number -= Long . parseLong ( s . substring ( i + 1 ) ) + 1 ; if ( getSum ( number ) == sumofDigits && number > res || ( getSum ( number ) ) > sumofDigits ) { res = number ; sumofDigits = getSum ( number ) ; } } System . out . println ( res ) ; }   private static long getSum ( long number ) { long sum = 0 ; while ( number != 0 ) { sum += number % 10 ; number /= 10 ; } return sum ; }   }

import java . math . BigInteger ; import java . util . * ;   public class Main {   static Scanner input = new Scanner ( System . in ) ;   public static void main ( String [ ] args ) { String s = input . next ( ) ; long len = s . length ( ) ; long res = Long . parseLong ( s ) ; long sum = getSum ( res ) ; for ( int i = 0 ; i < len - 1 ; i ++ ) { if ( s . charAt ( i ) == '0' ) continue ; long number = Long . parseLong ( s ) ; number = number - ( Long . parseLong ( s . substring ( i + 1 ) ) + 1 ) ; if ( getSum ( number ) == sum && number > res || ( getSum ( number ) > sum ) ) { res = number ; sum = getSum ( number ) ; } } System . out . println ( res ) ; }   private static long getSum ( long number ) { long sum = 0 ; while ( number != 0 ) { sum += number % 10 ; number /= 10 ; } return sum ; }   }

import java . io . * ; import java . util . * ; public class Main {   public static long sod ( String num ) { long sum = 0 ; char [ ] arr = num . toCharArray ( ) ; for ( char i : arr ) sum += Character . getNumericValue ( i ) ; return sum ; }    public static void main ( String [ ] args ) { InputReader sc = new InputReader ( System . in ) ; PrintWriter pw = new PrintWriter ( System . out ) ; Random gen = new Random ( ) ; int test = 1 ;

import java . util . * ; import java . math . * ; import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . StringTokenizer ;

x = input ( ) n = len ( x ) if n == 1 : print ( x ) exit ( 0 ) ans = " " s = 0 ps = 0 pn = " " for i in range ( n ) : ts = ps + int ( x [ i ] ) - 1 + 9 * ( n - i - 1 ) if ts >= s : ans = pn + str ( int ( x [ i ] ) - 1 ) + "9" * ( n - i - 1 ) s = ts ps += int ( x [ i ] ) pn += x [ i ] if ps >= s : ans = pnprint ( int ( ans ) ) NEW_LINE

def f ( z ) : return sum ( int ( i ) for i in z )     x = input ( ) k = len ( x ) m = f ( x ) ans = - 1 for i in range ( 1 , k + 1 ) : a = int ( x [ : i ] ) b = x [ i : ] if not all ( j == "9" for j in b ) : a -= 1 b = "9" * len ( b ) w = str ( a ) + b if f ( w ) >= m : m = f ( w ) ans = str ( a ) + bprint ( int ( ans ) ) NEW_LINE

a = input ( ) ans = [ sum ( map ( int , a ) ) , a ] for i in range ( len ( a ) - 1 , - 1 , - 1 ) : b = a [ : i ] + str ( int ( a [ i ] ) - 1 ) + '9' * len ( a [ i + 1 : ] ) if a [ i ] != '0' and sum ( map ( int , b ) ) > ans [ 0 ] : ans = [ sum ( map ( int , b ) ) , b ] print ( ans [ 1 ] . strip ( '0' ) ) NEW_LINE


import java . util . * ; import java . io . * ;   public class P297A {   private static void solve ( ) { char [ ] c1 = next ( ) . toCharArray ( ) ; char [ ] c2 = next ( ) . toCharArray ( ) ;   int cnt1 = 0 ; for ( int i = 0 ; i < c1 . length ; i ++ ) { if ( c1 [ i ] == '1' ) cnt1 ++ ; }   int cnt2 = 0 ; for ( int i = 0 ; i < c2 . length ; i ++ ) { if ( c2 [ i ] == '1' ) cnt2 ++ ; }   if ( ( cnt1 % 2 == 0 && cnt2 > cnt1 ) || ( cnt1 % 2 != 0 && cnt2 > cnt1 + 1 ) ) { System . out . println ( " NO " ) ; } else { System . out . println ( " YES " ) ; } }   private static void run ( ) { br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; out = new PrintWriter ( System . out ) ;   solve ( ) ;   out . close ( ) ; }   private static StringTokenizer st ; private static BufferedReader br ; private static PrintWriter out ;   private static String next ( ) { while ( st == null || ! st . hasMoreElements ( ) ) { String s ; try { s = br . readLine ( ) ; } catch ( IOException e ) { return null ; } st = new StringTokenizer ( s ) ; } return st . nextToken ( ) ; }   private static int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; }   private static long nextLong ( ) { return Long . parseLong ( next ( ) ) ; }   public static void main ( String [ ] args ) { run ( ) ; } }

import java . io . BufferedReader ; import java . io . File ; import java . io . FileInputStream ; import java . io . FileNotFoundException ; import java . io . FileOutputStream ; import java . io . InputStreamReader ; import java . io . PrintWriter ; import java . math . BigInteger ; import java . util . ArrayList ; import java . util . Arrays ; import java . util . BitSet ; import java . util . Calendar ; import java . util . Collections ; import java . util . Comparator ; import java . util . HashMap ; import java . util . HashSet ; import java . util . LinkedList ; import java . util . PriorityQueue ; import java . util . SortedSet ; import java . util . Stack ; import java . util . StringTokenizer ; import java . util . TreeMap ; import java . util . TreeSet ;   public class A_Round_180_Div1 {   public static long MOD = 998244353 ; static long [ ] [ ] [ ] dp ;   public static void main ( String [ ] args ) throws FileNotFoundException {

def play ( s , t ) : count1 , count2 = 0 , 0 for elem in s : if elem == '1' : count1 += 1 for elem in t : if elem == '1' : count2 += 1 if count2 - count1 > 1 or ( count2 - count1 == 1 and count1 % 2 == 0 ) : return " NO " return " YES "     a = input ( ) b = input ( ) print ( play ( a , b ) ) NEW_LINE

A = list ( input ( ) ) B = list ( input ( ) )   zA = A . count ( '1' ) zA += zA & 1   if zA >= B . count ( '1' ) : print ( " YES " ) else : print ( " NO " ) NEW_LINE

alice = input ( ) bob = input ( )   a = alice . count ( '1' ) b = bob . count ( '1' ) a += ( a % 2 ) NEW_LINE

a = input ( ) b = input ( ) x = a . count ( '1' ) x = x + x % 2 x -= b . count ( '1' ) print ( " NO " if x < 0 else " YES " ) NEW_LINE


import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . StringTokenizer ;   public class Test20200817 {   public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String [ ] paras = br . readLine ( ) . split ( " ▁ " ) ; String [ ] nums = br . readLine ( ) . split ( " ▁ " ) ; int temp = Integer . parseInt ( paras [ 0 ] ) ; int num = Integer . parseInt ( paras [ 1 ] ) ; int result = 0 ; boolean mark = false ; for ( int i = 0 ; i < temp ; i ++ ) { if ( Integer . parseInt ( nums [ i ] ) < num ) { result ++ ; } if ( Integer . parseInt ( nums [ i ] ) == num ) { mark = true ; } }   result = num - result ; result = mark ? result + 1 : result ; System . out . println ( result ) ; } }

import java . util . Arrays ; import java . util . Scanner ;   public class Exam9 { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int n = scan . nextInt ( ) ; int x = scan . nextInt ( ) ; int count = 0 , flag = 0 ;   for ( int i = 0 ; i < n ; i ++ ) { int t = scan . nextInt ( ) ; if ( t <= x ) { if ( t == x ) flag = 1 ; count ++ ; } }   if ( count != 0 ) { if ( flag == 0 ) { System . out . println ( x - count ) ; } else System . out . println ( x - count + 2 ) ; } else { if ( flag == 0 ) System . out . println ( x ) ; else System . out . println ( x + 1 ) ; } } }

import java . util . Scanner ;   public class MahmoudEhabMEX { public static void main ( String [ ] args ) {   Scanner in = new Scanner ( System . in ) ; int n = in . nextInt ( ) , x = in . nextInt ( ) , i , j = 0 , a [ ] = new int [ 101 ] , c = 0 ;   for ( i = 0 ; i < n ; i ++ ) a [ in . nextInt ( ) ] ++ ; in . close ( ) ;   for ( i = 0 ; i < x ; i ++ ) c += a [ i ] ; System . out . println ( a [ x ] == 1 ? x - c + 1 : x - c ) ; } }

n , x = map ( int , input ( ) . split ( ) ) a = list ( map ( int , input ( ) . split ( ) ) ) exist = [ False ] * 101 for e in a : exist [ e ] = Trueans = 0 if exist [ x ] : ans += 1 for i in range ( x ) : if not exist [ i ] : ans += 1 print ( ans ) NEW_LINE

from sys import stdinn , x = map ( int , stdin . readline ( ) . split ( ) ) a = list ( map ( int , stdin . readline ( ) . split ( ) ) ) d = [ 0 ] * 101 for i in a : d [ i ] = 1 print ( x - sum ( d [ : x ] ) + d [ x ] ) NEW_LINE

try : n , x = map ( int , input ( ) . split ( ) ) a = list ( map ( int , input ( ) . split ( ) ) ) a . sort ( ) z = 0 if a . __contains__ ( x ) : z += 1 for i in range ( x ) : if not a . __contains__ ( i ) : z += 1 print ( z ) except : pass NEW_LINE

n , x = map ( int , input ( ) . split ( ' ▁ ' ) ) evil = list ( map ( int , input ( ) . split ( ' ▁ ' ) ) ) current = ans = 0 for i in range ( x ) : if i not in evil : ans += 1 ans += 1 if x in evil else 0 print ( ans ) NEW_LINE

n , x = map ( int , input ( ) . split ( ) ) a = list ( map ( int , input ( ) . split ( ) ) ) ans = 0 if x in a : ans += 1 for i in range ( x ) : if i not in a : ans += 1 print ( ans ) NEW_LINE


import java . util . * ; import java . lang . * ; import java . io . * ; public class Main { PrintWriter out ; FastReader sc ; long mod = ( long ) ( 1e9 + 7 ) ; long maxlong = Long . MAX_VALUE ; long minlong = Long . MIN_VALUE ; public void sol ( ) { int n = ni ( ) ; int [ ] c = new int [ n ] , d = new int [ n ] ;

import java . util . Scanner ; public class B { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) , a [ ] = new int [ n ] , b [ ] = new int [ n + 1 ] , x = - 1 , c = 0 ; for ( int i = 0 ; i < n ; i ++ ) a [ i ] = sc . nextInt ( ) ; for ( int i = 0 ; i < n ; i ++ ) b [ sc . nextInt ( ) ] = i + 1 ; for ( int i : a ) if ( x == ( x = Math . max ( x , b [ i ] ) ) ) c ++ ; System . out . println ( c ) ; } }

import java . awt . * ; import java . io . * ; import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ;

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 ; } }

n = int ( input ( ) ) ent = list ( map ( int , input ( ) . strip ( ) . split ( ) ) ) [ : n ] sai = list ( map ( int , input ( ) . strip ( ) . split ( ) ) ) [ : n ]   res = 0   i = 0j = 0   ver = [ ]   for k in range ( 0 , n ) : ver . append ( 0 )   while i < n and j < n : if ver [ ent [ i ] - 1 ] == 1 : i += 1   elif ent [ i ] == sai [ j ] : ver [ ent [ i ] - 1 ] = 1 i += 1 j += 1   else : ver [ sai [ j ] - 1 ] = 1 res += 1 j += 1                                   print ( res ) NEW_LINE

n = int ( input ( ) ) a = list ( map ( int , input ( ) . split ( ) ) ) b = list ( map ( int , input ( ) . split ( ) ) ) entered , left = [ ] , [ ] j , l , count = 0 , 0 , 0 for _ in range ( n ) : left . append ( 0 ) for i in range ( n ) : entered . append ( a [ i ] ) while left [ entered [ j ] - 1 ] == 1 : j = j + 1 if entered [ j ] == b [ i ] : j = j + 1 else : count = count + 1 left [ b [ i ] - 1 ] = 1 print ( count )   NEW_LINE

numCars = int ( input ( ) ) tEntrance = [ int ( num ) for num in input ( ) . split ( ) ] tExit = [ int ( num ) for num in input ( ) . split ( ) ]   fines = 0j = 0 occurred = set ( ) for i in range ( numCars ) : if tEntrance [ i ] in occurred : continue while tExit [ j ] != tEntrance [ i ] : occurred . add ( tExit [ j ] ) fines += 1 j += 1 occurred . add ( tExit [ j ] ) j += 1 print ( fines ) NEW_LINE

n = int ( input ( ) ) before = input ( ) . split ( ) after = input ( ) . split ( ) finedCars = 0 removedCar = - 1 positions = { } for i in range ( len ( before ) ) : positions [ before [ i ] ] = iindex = 0 for i in range ( n ) : for j in range ( index , n ) : if ( before [ j ] ) == - 1 : index = j + 1 elif ( after [ i ] != before [ j ] ) : finedCars += 1 before [ positions [ after [ i ] ] ] = - 1 break else : index = j + 1 breakprint ( finedCars ) NEW_LINE

n = int ( input ( ) ) first = list ( input ( ) . strip ( ) . split ( ) ) second = list ( input ( ) . strip ( ) . split ( ) ) toDict = dict ( zip ( second , range ( n ) ) ) bef , aft = 0 , 0 for item in first : if toDict . get ( item ) >= aft : aft = toDict . get ( item ) continue bef += 1   print ( bef ) NEW_LINE


import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . * ;   public class Practice {   public static void main ( String [ ] args ) { Scanner s = new Scanner ( System . in ) ; int t = s . nextInt ( ) ; while ( t -- > 0 ) { int n = s . nextInt ( ) ; int [ ] [ ] arr = new int [ n ] [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { String str = s . next ( ) ; for ( int j = 0 ; j < n ; j ++ ) { arr [ i ] [ j ] = str . charAt ( j ) ; } } getAns ( n , arr ) ; } }   private static void getAns ( int n , int [ ] [ ] arr ) {

import matht = int ( input ( ) ) NEW_LINE for _ in range ( t ) : n = int ( input ( ) ) NEW_LINE li = [ ] NEW_LINE for i in range ( n ) : ali = input ( ) NEW_LINE ali = list ( ali ) NEW_LINE li . append ( ali ) NEW_LINE

import reimport NEW_LINE sysexit = sys . exitfrom NEW_LINE bisect NEW_LINE import bisect_left as bsl , bisect_right as bsrfrom NEW_LINE collections NEW_LINE import Counter , defaultdict as ddict , dequefrom NEW_LINE functools NEW_LINE import lru_cachecache = lru_cache ( None ) NEW_LINE from heapq import * NEW_LINE from itertools import * NEW_LINE from math import inffrom NEW_LINE pprint NEW_LINE import pprint as ppenum = enumerateri = lambda : int ( rln ( ) ) NEW_LINE ris = lambda : list ( map ( int , rfs ( ) ) ) NEW_LINE rln = sys . stdin . readlinerl = lambda : rln ( ) . rstrip ( ' \n ' ) NEW_LINE rfs = lambda : rln ( ) . split ( ) NEW_LINE mod = 1000000007 NEW_LINE d4 = [ ( 0 , - 1 ) , ( 1 , 0 ) , ( 0 , 1 ) , ( - 1 , 0 ) ] NEW_LINE d8 = [ ( - 1 , - 1 ) , ( 0 , - 1 ) , ( 1 , - 1 ) , ( - 1 , 0 ) , ( 1 , 0 ) , ( - 1 , 1 ) , ( 0 , 1 ) , ( 1 , 1 ) ] NEW_LINE

t = int ( input ( ) ) NEW_LINE while t > 0 : n = int ( input ( ) ) NEW_LINE grid = [ ] NEW_LINE for i in range ( n ) : a = input ( ) NEW_LINE grid . append ( a ) NEW_LINE lol = [ grid [ 0 ] [ 1 ] , grid [ 0 ] [ 2 ] , grid [ 1 ] [ 0 ] , grid [ 2 ] [ 0 ] , grid [ 1 ] [ 1 ] ] NEW_LINE ans1 = [ '0' , '1' , '0' , '1' , '1' ] NEW_LINE ans2 = [ '1' , '0' , '1' , '0' , '0' ] NEW_LINE count = 0 NEW_LINE l = [ ] NEW_LINE for i in range ( 5 ) : if NEW_LINE ans1 [ i ] == lol [ i ] : l . append ( '0' ) else : count += 1 NEW_LINE l . append ( '1' )   if count < 3 : print ( count ) NEW_LINE if l [ 0 ] == '1' : print ( "1 ▁ 2" ) NEW_LINE if l [ 1 ] == '1' : print ( "1 ▁ 3" ) NEW_LINE if l [ 2 ] == '1' : print ( "2 ▁ 1" ) NEW_LINE if l [ 3 ] == '1' : print ( "3 ▁ 1" ) NEW_LINE if l [ 4 ] == '1' : NEW_LINE INDENT print ( "2 ▁ 2" ) else : NEW_LINE print ( 5 - count ) NEW_LINE DEDENT if l [ 0 ] == '0' : print ( "1 ▁ 2" ) NEW_LINE if l [ 1 ] == '0' : print ( "1 ▁ 3" ) NEW_LINE if l [ 2 ] == '0' : print ( "2 ▁ 1" ) NEW_LINE if l [ 3 ] == '0' : print ( "3 ▁ 1" ) NEW_LINE if l [ 4 ] == '0' : print ( "2 ▁ 2" ) NEW_LINE t -= 1 NEW_LINE

import sys , functools , collections , bisect , math , NEW_LINE INDENT heapqinput = sys . stdin . readline NEW_LINE DEDENT

for _ in range ( int ( input ( ) ) ) : n = int ( input ( ) ) NEW_LINE mat = [ ] NEW_LINE for i in range ( n ) : mat . append ( input ( ) ) NEW_LINE s1 = mat [ 0 ] [ 1 ] NEW_LINE s2 = mat [ 1 ] [ 0 ] NEW_LINE s3 = mat [ - 2 ] [ - 1 ] NEW_LINE s4 = mat [ - 1 ] [ - 2 ] NEW_LINE if s1 == s2 == s3 == s4 : print ( 2 ) NEW_LINE print ( 1 , 2 ) NEW_LINE print ( 2 , 1 ) elif s1 == s2 == s3 : print ( 1 ) NEW_LINE print ( n - 1 , n ) elif s1 == s2 == s4 : print ( 1 ) NEW_LINE print ( n , n - 1 ) elif s1 == s4 == s3 : print ( 1 ) NEW_LINE print ( 1 , 2 ) elif s4 == s2 == s3 : print ( 1 ) NEW_LINE print ( 2 , 1 ) elif s1 == s3 : print ( 2 ) NEW_LINE print ( 1 , 2 ) NEW_LINE print ( n , n - 1 ) elif s1 == s4 : print ( 2 ) NEW_LINE print ( 1 , 2 ) NEW_LINE print ( n - 1 , n ) else : print ( 0 ) NEW_LINE


import java . awt . Point ; import java . io . File ; import java . io . IOException ; import java . io . PrintWriter ; import java . util . * ; import java . util . Map . Entry ;   public class Main {      public static void main ( String [ ] args ) { Scanner input = new Scanner ( System . in ) ;   int n = input . nextInt ( ) ; HashMap < Point , Integer > same = new HashMap < Point , Integer > ( ) ; TreeMap < Integer , Integer > mapx = new TreeMap < > ( ) ; TreeMap < Integer , Integer > mapy = new TreeMap < > ( ) ; int count = 0 , extra = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int x = input . nextInt ( ) ; int y = input . nextInt ( ) ; Point p = new Point ( x , y ) ; same . put ( p , same . getOrDefault ( p , 0 ) + 1 ) ; mapx . put ( x , mapx . getOrDefault ( x , 0 ) + 1 ) ; mapy . put ( y , mapy . getOrDefault ( y , 0 ) + 1 ) ;    }

import java . awt . Point ; import java . util . HashMap ; import java . util . Scanner ;   public class B {    public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; HashMap < Point , Integer > ps = new HashMap < Point , Integer > ( ) ; HashMap < Integer , Integer > xs = new HashMap < Integer , Integer > ( ) ; HashMap < Integer , Integer > ys = new HashMap < Integer , Integer > ( ) ; long sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int x = sc . nextInt ( ) ; int y = sc . nextInt ( ) ; Point p = new Point ( x , y ) ; if ( ps . containsKey ( p ) ) { sum -= ps . get ( p ) ; ps . put ( p , ps . get ( p ) + 1 ) ; } else { ps . put ( p , 1 ) ; } if ( xs . containsKey ( x ) ) { sum += xs . get ( x ) ; xs . put ( x , xs . get ( x ) + 1 ) ; } else { xs . put ( x , 1 ) ; } if ( ys . containsKey ( y ) ) { sum += ys . get ( y ) ; ys . put ( y , ys . get ( y ) + 1 ) ; } else { ys . put ( y , 1 ) ; } } System . out . println ( sum ) ; } }

# include < cmath > # include < cstdio > # include < cstdlib > # include < cassert > # include < cstring > # include < set > # include < map > # include < list > # include < queue > # include < string > # include < iostream > # include < algorithm > # include < functional > # include < stack > using namespace std ; typedef long long ll ; # define T int t_ ; Read ( t_ ) ; while ( t_ -- ) # define dight ( chr ) ( chr >= '0' && chr <= '9' ) # define alpha ( chr ) ( chr >= ' a ' && chr <= ' z ' ) # define INF ( 0x3f3f3f3f ) # define maxn ( 200005 ) # define hashmod 100000007 # define ull unsigned long long # define repne ( x , y , i ) for ( i = x ; i < y ; ++ i ) # define repe ( x , y , i ) for ( i = x ; i <= y ; ++ i ) # define ri register intvoid Read ( int & n ) { char chr = getchar ( ) , sign = 1 ; for ( ; ! dight ( chr ) ; chr = getchar ( ) ) if ( chr == ' - ' ) sign = - 1 ; for ( n = 0 ; dight ( chr ) ; chr = getchar ( ) ) n = n * 10 + chr - '0' ; n *= sign ; } void Read ( ll & n ) { char chr = getchar ( ) , sign = 1 ; for ( ; ! dight ( chr ) ; chr = getchar ( ) ) if ( chr == ' - ' ) sign = - 1 ; for ( n = 0 ; dight ( chr ) ; chr = getchar ( ) ) n = n * 10 + chr - '0' ; n *= sign ; } int x [ maxn ] , y [ maxn ] , n ; map < pair < int , int > , int > ma ; pair < int , int > pa ; int main ( ) {

n = int ( input ( ) ) fx , fy = { } , { } f = { } for i in range ( n ) : x , y = map ( int , input ( ) . split ( ) ) fx [ x ] = fx . get ( x , 0 ) + 1 fy [ y ] = fy . get ( y , 0 ) + 1 pt = ( x , y ) f [ pt ] = f . get ( pt , 0 ) + 1 res = 0 for k , v in fx . items ( ) : res += v * ( v - 1 ) // 2 for k , v in fy . items ( ) : res += v * ( v - 1 ) // 2 for k , v in f . items ( ) : res -= v * ( v - 1 ) // 2 print ( res ) NEW_LINE

from math import * from sys import stdininput = stdin . readlineli1 = { } ; li2 = { } ; li3 = { } for _ in range ( int ( input ( ) ) ) : x , y = map ( int , input ( ) . split ( ) ) li1 [ x ] = li1 . get ( x , 0 ) + 1 li2 [ y ] = li2 . get ( y , 0 ) + 1 li3 [ ( x , y ) ] = li3 . get ( ( x , y ) , 0 ) + 1 sum = 0 for x in [ * li1 . values ( ) ] + [ * li2 . values ( ) ] : sum += ( x * ( x - 1 ) ) // 2 for x in [ * li3 . values ( ) ] : sum -= ( x * ( x - 1 ) ) // 2 print ( sum ) NEW_LINE


import java . util . * ; public class Main { static char a [ ] [ ] ; static int t [ ] [ ] ; static int n ; static int k ; static int w = 1 ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; n = sc . nextInt ( ) ; k = sc . nextInt ( ) ; a = new char [ 2 ] [ n + k + 10 ] ; t = new int [ 2 ] [ n + k + 10 ] ; for ( int i = 0 ; i < 2 ; i ++ ) { char c [ ] = sc . next ( ) . toCharArray ( ) ; a [ i ] [ 0 ] = ' X ' ; for ( int j = 0 ; j < c . length ; j ++ ) { a [ i ] [ j + 1 ] = c [ j ] ; } }

import java . util . * ; public class Main { static boolean [ ] [ ] r ; static int h , j ; static boolean b = false ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; h = sc . nextInt ( ) ; j = sc . nextInt ( ) ; r = new boolean [ 2 ] [ h ] ; for ( int i = 0 ; i < 2 ; i ++ ) { String s = sc . next ( ) ; for ( int j = 0 ; j < h ; j ++ ) { if ( s . charAt ( j ) == ' X ' ) r [ i ] [ j ] = false ; else r [ i ] [ j ] = true ; } }

n , k = map ( int , input ( ) . split ( ) ) l = input ( ) r = input ( ) data = [ 0 , ' ▁ ' + l , ' ▁ ' + r ] dist = [ [ 1000000 ] * 100005 for _ in range ( 3 ) ] visited = [ [ False ] * 100005 for _ in range ( 3 ) ] dist [ 1 ] [ 1 ] = 0 visited [ 1 ] [ 1 ] = Trueqx , qy = [ 1 ] , [ 1 ] while qy : x , y = qx . pop ( ) , qy . pop ( ) if dist [ x ] [ y ] >= y : continue if x == 1 : poss = [ [ 1 , y + 1 ] , [ 1 , y - 1 ] , [ 2 , y + k ] ] else : poss = [ [ 2 , y + 1 ] , [ 2 , y - 1 ] , [ 1 , y + k ] ] for i , e in enumerate ( poss ) : newx , newy = e [ 0 ] , e [ 1 ] if newy > n : print ( ' YES ' ) from sys import exit exit ( ) if 0 < newy <= n and not visited [ newx ] [ newy ] and data [ newx ] [ newy ] == ' - ' : visited [ newx ] [ newy ] = True dist [ newx ] [ newy ] = dist [ x ] [ y ] + 1 qx = [ newx ] + qx qy = [ newy ] + qyprint ( ' NO ' ) NEW_LINE

def bfs ( n ) : visited = [ False ] * ( 2 * n ) queue = [ ] queue2 = [ ] queue . append ( 0 ) queue2 . append ( 0 ) visited [ 0 ] = True flag = True water = 0 while queue and flag : s = queue . pop ( 0 ) water = queue2 . pop ( 0 ) for i in graph [ s ] : if not visited [ i ] : a = 0 NEW_LINE


import java . util . ArrayList ; import java . util . Arrays ; import java . util . HashMap ; import java . util . LinkedHashMap ; import java . util . Map ; import java . util . Scanner ; import java . util . * ; import java . util . stream . Collectors ;   public class absolute {   public static void main ( String [ ] args ) {

import java . util . Scanner ; import java . util . Arrays ; import java . util . Vector ; import java . util . Collections ;    public class Problem_Solving1 { public static long fac ( long n ) { long f = 1 ; for ( int i = 2 ; i <= n ; i ++ ) { f *= i ; } return f ; }   public static void main ( String [ ] args ) {

import java . io . * ;   public class A {   static BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ;   public static void main ( String [ ] args ) throws IOException {   int a , b ; String [ ] input = new String [ 2 ] ; input = br . readLine ( ) . split ( " ▁ " ) ; a = Integer . parseInt ( input [ 0 ] ) ; b = Integer . parseInt ( input [ 1 ] ) ; int min = Math . min ( a , b ) ; int ans = 1 ; for ( int i = 1 ; i <= min ; i ++ ) { ans = ans * i ; } System . out . println ( ans ) ; } }

import java . io . * ; import java . util . * ;   public class A_822 { static PrintWriter pw = new PrintWriter ( System . out ) ;   public static void main ( String arg [ ] ) throws IOException { InputStreamReader isr = new InputStreamReader ( System . in ) ; BufferedReader br = new BufferedReader ( isr ) ; StringTokenizer token = new StringTokenizer ( " ▁ " ) ;   int n = 0 ; int m = 0 ;   token = new StringTokenizer ( br . readLine ( ) ) ;   m = Integer . parseInt ( token . nextToken ( ) ) ; n = Integer . parseInt ( token . nextToken ( ) ) ;    pw . println ( getResult ( m , n ) ) ;   pw . close ( ) ;   }   private static long getResult ( int m , int n ) {   return getFactorial ( Math . min ( m , n ) ) ;   }   private static long getFactorial ( int n ) { int i = 0 ; long fact = 1 ;   for ( i = 1 ; i <= n ; i ++ ) fact = fact * i ;   return fact ; } }

import java . util . * ;   public class Main {   public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; long a = scanner . nextLong ( ) , b = scanner . nextLong ( ) ; long min = Math . min ( a , b ) ; long ans = 1 ; for ( long i = 1 ; i <= min ; i ++ ) { ans *= i ; } System . out . println ( ans ) ; } }

def fact ( x ) : if ( x == 1 ) : return ( 1 ) else : return ( fact ( x - 1 ) * x ) a , b = [ int ( x ) for x in input ( ) . split ( ' ▁ ' ) ] print ( fact ( min ( a , b ) ) ) NEW_LINE

import sys , math   a , b = list ( map ( int , sys . stdin . readline ( ) . rstrip ( ) . split ( ) ) ) print ( math . factorial ( min ( a , b ) ) ) NEW_LINE

from math import factorial   A , B = map ( int , input ( ) . split ( ) ) print ( factorial ( min ( A , B ) ) )     NEW_LINE

import mathprint ( math . factorial ( min ( map ( int , input ( ) . split ( ) ) ) ) ) NEW_LINE

import mathn , m = map ( int , input ( ) . split ( ) ) fac1 = 1 fac2 = 1 i1 = 1 i2 = 1 while ( i1 <= n and i2 <= m ) : fac1 = fac1 * i1 fac2 = fac2 * i2 i1 = i1 + 1 i2 = i2 + 1   print ( math . gcd ( fac1 , fac2 ) ) NEW_LINE


import java . util . * ; public class Main { final static int maxn = ( int ) 1e5 + 10 ; static int b [ ] = new int [ maxn ] ; static int g [ ] = new int [ maxn ] ; public static void main ( String args [ ] ) {

# include < iostream > # include < cstdio > # include < cstdlib > # include < cstring > # include < string > # include < stack > # include < map > # include < queue > # include < algorithm > # include < cmath > typedef long long LL ; using namespace std ;  # define MAX 100000 + 10   int n , m ; LL ans ;   LL a [ MAX ] , b [ MAX ] ;   bool cmp ( LL a , LL b ) { return a > b ; }   int main ( ) { cin >> n >> m ;   for ( int i = 0 ; i < n ; i ++ ) scanf ( " % lld " , a + i ) ; for ( int i = 0 ; i < m ; i ++ ) scanf ( " % lld " , b + i ) ;   sort ( a , a + n , cmp ) ; sort ( b , b + m , cmp ) ;   if ( a [ 0 ] > b [ m - 1 ] ) cout << - 1 << endl ; else { int flag = 0 ; ans += a [ 0 ] ; for ( int i = 0 ; i < m - 1 ; i ++ ) ans += b [ i ] ;   if ( b [ m - 1 ] == a [ 0 ] ) flag = 1 ;   if ( flag ) { for ( int i = 1 ; i < n ; i ++ ) ans += a [ i ] * m ; } else { for ( int i = 1 ; i < n ; i ++ ) ans += a [ i ] * m ;   ans += b [ m - 1 ] - a [ 1 ] ; }   cout << ans << endl ; }   return 0 ; }

I = lambda : map ( int , input ( ) . split ( ) ) n , m = I ( ) a , b = sorted ( I ( ) , reverse = 1 ) , sorted ( I ( ) ) s = sum ( b ) for i in range ( 1 , n ) : s += a [ i ] * mif a [ 0 ] > b [ 0 ] : s = - 1 elif a [ 0 ] != b [ 0 ] : s += a [ 0 ] - a [ 1 ] print ( s ) NEW_LINE

nBoys , nGirls = map ( int , input ( ) . split ( ) ) boys = sorted ( map ( int , input ( ) . split ( ) ) , reverse = True ) girls = sorted ( map ( int , input ( ) . split ( ) ) ) if boys [ 0 ] > girls [ 0 ] : print ( - 1 ) exit ( ) ret = sum ( girls ) for i in range ( 1 , nBoys ) : ret += boys [ i ] * nGirlsif boys [ 0 ] != girls [ 0 ] : ret -= girls [ 0 ] - boys [ 0 ] ret += girls [ 0 ] - boys [ 1 ] print ( ret ) NEW_LINE

import sysinput = sys . stdin . readline   n , m = map ( int , input ( ) . split ( ) ) b = list ( map ( int , input ( ) . split ( ) ) ) g = list ( map ( int , input ( ) . split ( ) ) ) b . sort ( ) g . sort ( )   if b [ - 1 ] > g [ 0 ] : print ( - 1 ) exit ( )   if b [ - 1 ] == g [ 0 ] : ans = 0 for i in range ( n - 1 ) : ans += b [ i ] * m ans += sum ( g ) print ( ans ) else : ans = 0 for i in range ( n - 2 ) : ans += b [ i ] * m ans += g [ 0 ] + b [ n - 2 ] * ( m - 1 ) ans += b [ - 1 ] + sum ( g [ 1 : ] )   print ( ans ) NEW_LINE

I = lambda : map ( int , input ( ) . split ( ) ) n , m = I ( ) a , b = sorted ( I ( ) , reverse = 1 ) , sorted ( I ( ) ) s = sum ( b ) for i in range ( 1 , n ) : s += a [ i ] * mif a [ 0 ] > min ( b ) : s = - 1 elif a [ 0 ] != b [ 0 ] : s += a [ 0 ] - a [ 1 ] print ( s ) NEW_LINE