import java . util . * ;   public class Berland_National_Library {   static Scanner in = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { int n = in . nextInt ( ) ; boolean [ ] tab = new boolean [ 1000001 ] ; int min = 0 ; int c = 0 ; for ( int i = 0 ; i < n ; i ++ ) { String s = in . next ( ) ; int k = in . nextInt ( ) ; if ( s . charAt ( 0 ) == ' - ' ) { if ( ! tab [ k ] ) min ++ ; else c -- ; } else c ++ ; tab [ k ] = true ; if ( c > min ) min = c ; } System . out . println ( min ) ; } }


n = int ( input ( ) ) a = [ ] for i in range ( n ) : s = input ( ) a . append ( s ) lst = [ 0 ] * 1000000 before = [ ] for i in range ( n ) : sign = a [ i ] [ 0 ] val = int ( a [ i ] [ 2 : ] ) if sign == " + " : lst [ val - 1 ] = 1 else : if not lst [ val - 1 ] : before . append ( val ) mx = len ( before ) ans = mxfor i in range ( n ) : sign = a [ i ] [ 0 ] val = int ( a [ i ] [ 2 : ] ) if sign == " + " : mx += 1 ans = max ( mx , ans ) else : mx -= 1 print ( ans ) NEW_LINE


n , l , m , a = int ( input ( ) ) , [ 0 ] * 1000000 , 0 , [ ] for _ in range ( n ) : a . append ( input ( ) ) for i in range ( n ) : v = int ( a [ i ] [ 2 : ] ) if a [ i ] [ 0 ] == ' + ' : l [ v - 1 ] = 1 elif not l [ v - 1 ] : m += 1 ans = mfor i in range ( n ) : if a [ i ] [ 0 ] == ' + ' : m += 1 ; ans = max ( m , ans ) else : m -= 1 print ( ans ) NEW_LINE


n = int ( input ( ) ) seats = [ False for x in range ( 1 , 1000010 ) ] ans = 0 state = 0 for x in range ( n ) : di , idd = input ( ) . split ( ) idd = int ( idd ) if di == ' + ' : seats [ idd ] = True state += 1 ans = max ( ans , state ) elif di == ' - ' : if seats [ idd ] == False : ans += 1 else : state -= 1 ans = max ( ans , state ) seats [ idd ] = Falseprint ( ans ) NEW_LINE


n = int ( input ( ) ) mp = dict ( ) ans , cur = 0 , 0   for i in range ( n ) : c , x = [ _ for _ in input ( ) . split ( ) ] x = int ( x ) if c == ' - ' : if mp . get ( x ) == True : cur -= 1 mp [ x ] = False elif mp . get ( x ) is None : ans += 1 mp [ x ] = False elif c == ' + ' : cur += 1 mp [ x ] = True ans = max ( ans , cur ) print ( ans ) NEW_LINE


import java . util . Scanner ;   public class Main { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; long num = in . nextLong ( ) ; while ( num % 10 == 0 ) { num /= 10 ; } String str = String . valueOf ( num ) ; for ( int i = 0 ; i < str . length ( ) / 2 ; i ++ ) {

s = input ( ) s = s . strip ( "0" )     NEW_LINE


s = input ( ) s = list ( s ) while s [ - 1 ] == '0' : s . pop ( ) d = s [ : : - 1 ] print ( " YES " if d == s else " NO " ) NEW_LINE


string = input ( ) while string [ - 1 ] == '0' : string = string [ : len ( string ) - 1 ] if string == string [ : : - 1 ] : print ( " YES " ) else : print ( " NO " ) NEW_LINE


import sysx = input ( ) for i in range ( len ( x ) - 1 , - 1 , - 1 ) : if x [ i ] != '0' : new = ( i + 1 ) for j in range ( new // 2 ) : if ( x [ j ] != x [ new - j - 1 ] ) : print ( " NO " ) sys . exit ( 0 ) breakprint ( " YES " ) NEW_LINE


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


import java . util . * ; import java . io . * ;   public class Main { public static void main ( String [ ] args ) throws IOException { FastScanner in = new FastScanner ( System . in ) ; PrintWriter out = new PrintWriter ( System . out ) ; new Main ( ) . run ( in , out ) ; out . close ( ) ; }   public static long mod = 17352642619633L ;   void run ( FastScanner in , PrintWriter out ) {   char [ ] ca = in . next ( ) . toCharArray ( ) ; int N = ca . length ;   for ( int i = 0 ; i <= N ; i ++ ) {   boolean good = true ; for ( int j = 0 ; j < i / 2 ; j ++ ) { if ( ca [ j ] != ca [ i - j - 1 ] ) good = false ; } for ( int j = i ; j < N ; j ++ ) { if ( ca [ j ] != '0' ) good = false ; } if ( good ) { out . println ( " YES " ) ; return ; } } out . println ( " NO " ) ; }    static class FastScanner { BufferedReader br ; StringTokenizer st ;   public FastScanner ( InputStream in ) { br = new BufferedReader ( new InputStreamReader ( in ) ) ; st = null ; }   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 ( ) ) ; } } }


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

n = int ( input ( ) ) a = list ( map ( int , input ( ) . split ( ) ) ) t = [ 0 ] * 2 * ns = 0 for i in range ( n ) : d = a [ i ] - i - 1 s += abs ( d ) if d > 0 : t [ d ] += 1 p = sum ( t ) r = ( s , 0 ) for i in range ( 1 , n ) : d = a [ n - i ] - 1 s += d - p << 1 t [ d + i ] += d > 0 p += ( d > 0 ) - t [ i ] if s < r [ 0 ] : r = ( s , i ) print ( * r ) NEW_LINE


import java . io . BufferedReader ; import java . io . FileNotFoundException ; import java . io . InputStreamReader ; import java . io . PrintWriter ; import java . util . ArrayList ; import java . util . Arrays ; import java . util . StringTokenizer ;   public class B_Round_421_Div1 {   public static long MOD = 1000000007 ;   public static void main ( String [ ] args ) throws FileNotFoundException {


import java . util . * ; import java . util . stream . IntStream ; import java . io . * ; public class MisterBandPRShifts { static int [ ] brute ( int arr [ ] ) { int deviation [ ] = new int [ arr . length ] ; for ( int k = 0 ; k < arr . length ; k ++ ) for ( int i = 0 ; i < arr . length ; i ++ ) deviation [ k ] += Math . abs ( i - arr [ ( i - k + arr . length ) % arr . length ] ) ; return deviation ; } static void rotate ( int arr [ ] , int k ) { int temp [ ] = new int [ arr . length ] ; System . arraycopy ( arr , arr . length - k , temp , 0 , k ) ; System . arraycopy ( arr , 0 , temp , k , arr . length - k ) ; pa ( temp ) ; } static void pa ( int arr [ ] ) { System . out . println ( Arrays . toString ( arr ) ) ; System . out . println ( Arrays . toString ( IntStream . range ( 0 , arr . length ) . toArray ( ) ) ) ; } private static void solve ( ) { int n = nextInt ( ) ; int arr [ ] = Arrays . stream ( nextIntArray ( n ) ) . map ( a -> a - 1 ) . toArray ( ) ; int edgeCase [ ] = new int [ n ] ;


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


import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . io . PrintWriter ; import java . util . ArrayList ; import java . util . Arrays ; import java . util . Random ; import java . util . StringTokenizer ;   public class Solution { public static void main ( String [ ] args ) throws IOException { FastScanner fs = new FastScanner ( ) ; PrintWriter out = new PrintWriter ( System . out ) ; int tt = 1 ; while ( tt -- > 0 ) { int n = fs . nextInt ( ) ; long [ ] [ ] arr = new long [ n ] [ 3 ] ; for ( int i = 0 ; i < n ; i ++ ) { arr [ i ] [ 0 ] = fs . nextLong ( ) ; arr [ i ] [ 1 ] = fs . nextLong ( ) ; arr [ i ] [ 2 ] = fs . nextLong ( ) ; } ArrayList < Integer > list = new ArrayList < Integer > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] [ 2 ] < 0 ) continue ; list . add ( i + 1 ) ; long offcry = arr [ i ] [ 0 ] ; long corcry = 0 ; int ind = 0 ; for ( int j = i + 1 ; j < n ; j ++ ) { if ( arr [ j ] [ 2 ] < 0 ) continue ; arr [ j ] [ 2 ] -= Math . max ( 0 , offcry - ( ind ++ ) ) + corcry ; if ( arr [ j ] [ 2 ] < 0 ) corcry += arr [ j ] [ 1 ] ; } } out . println ( list . size ( ) ) ; for ( int a : list ) out . print ( a + " ▁ " ) ; } out . close ( ) ; } static final Random random = new Random ( ) ; static void ruffleSort ( int [ ] a ) { int n = a . length ;

n = int ( input ( ) ) arr , res = [ ] , [ ] for i in range ( n ) : arr . append ( [ int ( j ) for j in input ( ) . split ( ) ] ) res . append ( 0 ) for i in range ( n ) : if res [ i ] != 0 : continue res [ i ] = 1 v = arr [ i ] [ 0 ] d = 0 for j in range ( i + 1 , n ) : if res [ j ] != 0 : continue arr [ j ] [ 2 ] -= v + d if v >= 1 : v -= 1 if arr [ j ] [ 2 ] < 0 : res [ j ] = - 1 d += arr [ j ] [ 1 ] print ( res . count ( 1 ) , end = ' \n ' ) for i in range ( n ) : if res [ i ] == 1 : print ( i + 1 , end = ' ▁ ' ) NEW_LINE


ans = 0 l = [ ] t = int ( input ( ) ) for i in range ( t ) : n , m , k = map ( int , input ( ) . split ( ) ) l . append ( [ n , m , k ] )   ans = 0 p = [ ] for i in range ( t ) :   if l [ i ] [ 2 ] >= 0 : k = 0 v = 0 for j in range ( i + 1 , t ) : if l [ j ] [ 2 ] >= 0 : l [ j ] [ 2 ] -= ( max ( 0 , l [ i ] [ 0 ] - k ) + v ) if l [ j ] [ 2 ] < 0 : v += l [ j ] [ 1 ] l [ j ] [ 1 ] = 0 k += 1 p . append ( i + 1 ) NEW_LINE


T = int ( input ( ) ) childs = [ ] for i in range ( 1 , T + 1 ) : child = list ( map ( int , input ( ) . split ( ' ▁ ' ) ) ) child . insert ( 0 , i ) childs . append ( child )   c_l = [ ] check = Truewhile check : at_o = childs . pop ( 0 ) c_l . append ( at_o [ 0 ] ) for i in range ( len ( childs ) ) : childs [ i ] [ 3 ] -= at_o [ 1 ] at_o [ 1 ] -= 1 if at_o [ 1 ] <= 0 : break   if len ( childs ) <= 0 : break   i = 0 run = True while run : if childs [ i ] [ 3 ] < 0 : at_h = childs . pop ( i ) for j in range ( i , len ( childs ) ) : childs [ j ] [ 3 ] -= at_h [ 2 ] NEW_LINE


import java . io . * ; import java . math . BigInteger ; import java . util . * ;   public class Main { static int MOD = 1000000007 ;


import java . io . BufferedReader ; import java . io . File ; import java . io . FileWriter ; import java . io . IOException ; import java . io . InputStreamReader ; import java . io . PrintWriter ; import java . math . BigInteger ; import java . util . * ;   public class Main {   public static void main ( String [ ] args ) { FastScanner input = new FastScanner ( ) ; ArrayList < Integer > ans = new ArrayList < > ( ) ; int n = input . nextInt ( ) ; long v [ ] = new long [ n ] ; long d [ ] = new long [ n ] ; long p [ ] = new long [ n ] ; ArrayList < Integer > queue = new ArrayList < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { v [ i ] = input . nextLong ( ) ; d [ i ] = input . nextLong ( ) ; p [ i ] = input . nextLong ( ) ; queue . add ( i ) ; }


import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; System . out . println ( " YES " ) ; for ( int i = 0 ; i < n ; i ++ ) { int x1 = sc . nextInt ( ) ; int y1 = sc . nextInt ( ) ; int x2 = sc . nextInt ( ) ; int y2 = sc . nextInt ( ) ; System . out . println ( ( 12 + 2 * ( x1 % 2 ) + ( y1 % 2 ) ) % 4 + 1 ) ; } } }

print ( ' YES ' ) for i in range ( int ( input ( ) ) ) : x , y , a , b = [ int ( x ) for x in input ( ) . split ( ) ] print ( x % 2 + y % 2 * 2 + 1 ) NEW_LINE


def f ( ) : n = int ( input ( ) ) a = [ 1 , 2 , 3 , 4 ] print ( " YES " ) for i in range ( n ) : x = input ( ) . split ( ) x = [ int ( j ) % 2 for j in x ] print ( a [ x [ 2 ] * 2 + x [ 3 ] ] ) f ( ) NEW_LINE


print ( ' YES ' ) for i in range ( int ( input ( ) ) ) : a , b , c , d = map ( int , input ( ) . split ( ) ) print ( 1 + abs ( a ) % 2 + abs ( b ) % 2 * 2 ) NEW_LINE


import sysv = [ int ( x ) for x in sys . stdin . read ( ) . split ( ) ] print ( " YES " ) for i in range ( v [ 0 ] ) : print ( 1 + ( v [ 4 * i + 1 ] & 1 ) + 2 * ( v [ 4 * i + 2 ] & 1 ) ) NEW_LINE


import mathimport sysn = int ( input ( ) ) color = [ ] for i in range ( n ) : x1 , y1 , x2 , y2 = map ( int , input ( ) . split ( ) ) col = 0 if abs ( x1 ) % 2 == 0 : col += 1 if abs ( y1 ) % 2 == 0 : col += 2 color . append ( str ( col + 1 ) ) print ( ' YES ' ) print ( ' \n ' . join ( color ) ) NEW_LINE


# include < iostream > using namespace std ; template < class T > bool uin ( T & a , T b ) { return a > b ? ( a = b , true ) : false ; } template < class T > bool uax ( T & a , T b ) { return a < b ? ( a = b , true ) : false ; } # define forn ( i , n ) for ( int i = 0 ; i < ( int ) ( n ) ; i ++ ) # define forab ( i , a , b ) for ( int i = ( int ) ( a ) ; i < ( int ) ( b ) ; ++ i ) # define _ cin . tie ( 0 ) ; ios_base :: sync_with_stdio ( 0 ) ; # define i64 long long int main ( ) { int n ; printf ( " YES \n " ) ; scanf ( " % d " , & n ) ; for ( int i = 0 ; i < n ; i ++ ) { int x1 , y1 , x2 , y2 ; scanf ( " % d ▁ % d ▁ % d ▁ % d " , & x1 , & y1 , & x2 , & y2 ) ; printf ( " % d \n " , ( ( 12 + 2 * ( x1 % 2 ) + ( y1 % 2 ) ) % 4 ) + 1 ) ; } return 0 ; }


import java . io . OutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . OutputStream ; import java . io . PrintWriter ; import java . io . BufferedWriter ; import java . io . Writer ; import java . io . OutputStreamWriter ; import java . util . InputMismatchException ; import java . io . IOException ; import java . io . InputStream ;   public class Main { public static void main ( String [ ] args ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; InputReader in = new InputReader ( inputStream ) ; OutputWriter out = new OutputWriter ( outputStream ) ; DTimofeyAndRectangles solver = new DTimofeyAndRectangles ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; }   static class DTimofeyAndRectangles { public void solve ( int testNumber , InputReader in , OutputWriter out ) { int n = in . nextInt ( ) ;   rect [ ] rects = new rect [ n ] ;   out . println ( " YES " ) ; for ( int i = 0 ; i < n ; i ++ ) { int x1 = in . nextInt ( ) ; int y1 = in . nextInt ( ) ; int x2 = in . nextInt ( ) ; int y2 = in . nextInt ( ) ;   x2 += 1000000000 ; y1 += 1000000000 ;   rects [ i ] = new rect ( x1 , y1 , x2 , y2 , i ) ;   int ans = 0 ;   if ( x2 % 2 == 1 ) { ans += 1 ; }   if ( y1 % 2 == 1 ) { ans += 2 ; }   out . println ( ans + 1 ) ; }


import java . util . * ; public class Main { public static void main ( String args [ ] ) { Scanner sc = new Scanner ( System . in ) ; String a = sc . next ( ) ; String b = sc . next ( ) ; StringBuilder ab = new StringBuilder ( ) ; ab . append ( a . charAt ( 0 ) ) ; for ( int i = 1 ; i < a . length ( ) ; i ++ ) { if ( a . charAt ( i ) < b . charAt ( 0 ) ) ab . append ( a . charAt ( i ) ) ; else break ; } ab . append ( b . charAt ( 0 ) ) ; System . out . println ( ab . toString ( ) ) ; } }

import mathfrom math import gcd , floor , sqrt , logdef iin ( ) : return int ( input ( ) ) def sin ( ) : return input ( ) . strip ( ) def listin ( ) : return list ( map ( int , input ( ) . strip ( ) . split ( ) ) ) def liststr ( ) : return list ( map ( str , input ( ) . strip ( ) . split ( ) ) ) def ceill ( x ) : return int ( x ) if ( x == int ( x ) ) else int ( x ) + 1 def ceilldiv ( x , d ) : return x // d if ( x % d == 0 ) else x // d + 1 def LCM ( a , b ) : return ( a * b ) // gcd ( a , b )     s = liststr ( ) x = " zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz " for i in range ( len ( s [ 0 ] ) ) : for j in range ( len ( s [ 1 ] ) ) : temp = s [ 0 ] [ : i + 1 ] + s [ 1 ] [ : j + 1 ] x = min ( x , temp ) print ( x )     NEW_LINE


s = input ( ) . split ( ) s1 = s [ 0 ] [ 1 : ] print ( s [ 0 ] [ 0 ] , end = " " ) for i in s1 : if ( ord ( i ) >= ord ( s [ 1 ] [ 0 ] ) ) : print ( s [ 1 ] [ 0 ] , end = " " ) break else : print ( i , end = " " ) else : print ( s [ 1 ] [ 0 ] , end = " " ) NEW_LINE


a , b = input ( ) . split ( )   ans = " z " * 101     f = " " l = " "   for i in a : f += i l = " " for j in b : l += j ans = min ( ans , f + l )   print ( ans )   NEW_LINE


import mathfrom math import gcd , floor , sqrt , logdef iin ( ) : return int ( input ( ) ) def sin ( ) : return input ( ) . strip ( ) def listin ( ) : return list ( map ( int , input ( ) . strip ( ) . split ( ) ) ) def liststr ( ) : return list ( map ( str , input ( ) . strip ( ) . split ( ) ) ) def ceill ( x ) : return int ( x ) if ( x == int ( x ) ) else int ( x ) + 1 def ceilldiv ( x , d ) : return x // d if ( x % d == 0 ) else x // d + 1 def LCM ( a , b ) : return ( a * b ) // gcd ( a , b )     s = liststr ( ) x = [ ] for i in range ( len ( s [ 0 ] ) ) : for j in range ( len ( s [ 1 ] ) ) : temp = s [ 0 ] [ : i + 1 ] + s [ 1 ] [ : j + 1 ] x . append ( temp ) print ( min ( x ) )     NEW_LINE


import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . StringTokenizer ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { FastScanner fs = new FastScanner ( ) ; int T = 1 ;


import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ;   public class kjhg { public static void main ( String [ ] args ) throws IOException { BufferedReader a = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String f = a . readLine ( ) ; String d [ ] = f . split ( " ▁ " ) ; System . out . print ( d [ 0 ] . charAt ( 0 ) ) ; for ( int i = 1 ; i < d [ 0 ] . length ( ) ; i ++ ) { if ( d [ 0 ] . charAt ( i ) < d [ 1 ] . charAt ( 0 ) ) { System . out . print ( d [ 0 ] . charAt ( i ) ) ; } else { break ; }   } System . out . println ( d [ 1 ] . charAt ( 0 ) ) ; } }


import java . util . * ; import java . io . * ; public final class Codeforces { public static BufferedReader buffer = new BufferedReader ( new InputStreamReader ( System . in ) ) ; public static BufferedWriter logger = new BufferedWriter ( new OutputStreamWriter ( System . out ) ) ; public static void main ( String [ ] args ) { try { args = buffer . readLine ( ) . split ( " ▁ " ) ; String s1 = args [ 0 ] ; String s2 = args [ 1 ] ; String s = s1 . charAt ( 0 ) + " " ; int n = s1 . length ( ) ; for ( int i = 1 ; i < n ; i ++ ) { if ( s1 . charAt ( i ) < s2 . charAt ( 0 ) ) { s += s1 . charAt ( i ) ; } else { break ; } } s += s2 . charAt ( 0 ) ; logger . write ( s ) ; logger . flush ( ) ; } catch ( IOException exc ) { } } }


import java . util . Scanner ;   public class Main { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; String s1 = in . next ( ) ; String s2 = in . next ( ) ; String s = " zzzzzzzz " ; for ( int i = 0 ; i < s1 . length ( ) ; i ++ ) { for ( int j = 0 ; j < s2 . length ( ) ; j ++ ) { String ss = s1 . substring ( 0 , i + 1 ) + s2 . substring ( 0 , j + 1 ) ; s = min ( ss , s ) ; } } System . out . println ( s ) ; } public static String min ( String s1 , String s2 ) { if ( s1 . compareTo ( s2 ) < 0 ) return s1 ; else return s2 ; } }


import java . io . * ; import java . math . BigInteger ; import java . util . * ; public class Main { static InputReader in = new InputReader ( System . in ) ; static PrintWriter out = new PrintWriter ( System . out ) ; static int oo = ( int ) 1e9 ;

def solve ( ls ) :   ls . sort ( key = lambda q : q [ 1 ] - q [ 0 ] )   m = sum ( si for a , b , si in ls )   k = s * ( m // s )   n = m - k   x = y = z = 0   for a , b , si in ls :   if k >= si :   k -= si   z += si * a   elif k :   z += k * a   x = ( si - k ) * a   y = ( si - k ) * b   k = 0   else :   x += si * a   y += si * b   return x , y , z , n       n , s = map ( int , input ( ) . split ( ) )   first = [ ]   second = [ ]   for i in range ( n ) :   si , ai , bi = map ( int , input ( ) . split ( ) )   if ai > bi :   first . append ( ( ai , bi , si ) )   else :   second . append ( ( bi , ai , si ) )   x1 , y1 , z1 , n1 = solve ( first )   x2 , y2 , z2 , n2 = solve ( second )   d = x1 + x2 if n1 + n2 > s else max ( x1 + y2 , x2 + y1 )   print ( z1 + z2 + d )           NEW_LINE


from sys import stdinfrom collections import deque   n , S = [ int ( x ) for x in stdin . readline ( ) . split ( ) ]   ppl = [ ]   base = 0   tSlices = 0   for dude in range ( n ) : s , a , b = [ int ( x ) for x in stdin . readline ( ) . split ( ) ] base += s * a tSlices += s ppl . append ( [ b - a , s ] ) NEW_LINE


import java . util . * ; import java . io . * ;   public class Main { public static void main ( String args [ ] ) { new Main ( ) . run ( ) ; }   FastReader in = new FastReader ( ) ; PrintWriter out = new PrintWriter ( System . out ) ; void run ( ) { work ( ) ; out . flush ( ) ; } long mod = 998244353 ; long gcd ( long a , long b ) { return b == 0 ? a : gcd ( b , a % b ) ; } void work ( ) { int n = in . nextInt ( ) ; long s = in . nextLong ( ) ; long [ ] [ ] A = new long [ n ] [ ] ; long c1 = 0 , c2 = 0 , sum = 0 , ret = 0 ; for ( int i = 0 ; i < n ; i ++ ) { long k = in . nextLong ( ) ; long p1 = in . nextLong ( ) ; long p2 = in . nextLong ( ) ; if ( p1 > p2 ) { c1 += k ; ret += k * p1 ; } else { c2 += k ; ret += k * p2 ; } A [ i ] = new long [ ] { k , p1 , p2 } ; sum += k ; } long r1 = c1 == 0 ? 0 : ( ( c1 - 1 ) / s + 1 ) ; long r2 = c2 == 0 ? 0 : ( ( c2 - 1 ) / s + 1 ) ; if ( r1 + r2 == ( sum - 1 ) / s + 1 ) { out . println ( ret ) ; return ; } long r = 0 ; r = Math . max ( r , find ( c1 - c1 / s * s , A , ret , 1 ) ) ;


import java . util . * ; import java . io . * ;   public class Main { public static void main ( String [ ] args ) throws IOException { FastScanner in = new FastScanner ( System . in ) ; PrintWriter out = new PrintWriter ( System . out ) ; new Main ( ) . run ( in , out ) ; out . close ( ) ; }    int S ; void run ( FastScanner in , PrintWriter out ) {   N = in . nextInt ( ) ; S = in . nextInt ( ) ;   totalSlices = 0 ; p = new long [ N ] [ 3 ] ; for ( int i = 0 ; i < N ; i ++ ) { p [ i ] [ 0 ] = in . nextInt ( ) ; p [ i ] [ 1 ] = in . nextInt ( ) ; p [ i ] [ 2 ] = in . nextInt ( ) ; totalSlices += p [ i ] [ 0 ] ; }   totalPizzas = ( long ) Math . ceil ( ( double ) totalSlices / S ) ; Arrays . sort ( p , ( a , b ) -> Long . compare ( a [ 2 ] - a [ 1 ] , b [ 2 ] - b [ 1 ] ) ) ;


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

n , k = map ( int , input ( ) . split ( ) ) a = list ( map ( int , input ( ) . split ( ) ) ) ans = 0 for b in range ( k ) : e , s = 0 , 0 for i in range ( n ) : if i % k != b : if a [ i ] == 1 : e += 1 else : s += 1 ans = max ( ans , abs ( e - s ) ) print ( ans ) NEW_LINE


n , k = map ( int , input ( ) . split ( ) ) x = list ( map ( int , input ( ) . split ( ) ) )   sumi = 0 maxi = - 10000   for i in range ( n ) : sumi += x [ i ]   for i in range ( k ) : ans = sumi for j in range ( i , n , k ) : ans -= x [ j ] maxi = max ( maxi , abs ( ans ) )     print ( maxi ) NEW_LINE


n , k = map ( int , input ( ) . split ( ) ) l = list ( map ( int , input ( ) . split ( ) ) ) res = 0 for i in range ( k ) : count = 0 for j in range ( n ) : if i != j % k : count += l [ j ] res = max ( res , abs ( count ) ) print ( res ) NEW_LINE


i = lambda : map ( int , input ( ) . split ( ) ) n , k = i ( ) a = * i ( ) , s = sum ( a ) print ( max ( abs ( s - sum ( a [ j : : k ] ) ) for j in range ( k ) ) ) NEW_LINE


import copyn , k = map ( int , input ( ) . split ( ) ) tabs = list ( map ( int , input ( ) . split ( ) ) ) tabs . insert ( 0 , 0 ) max_value = 0   for each_b in range ( 1 , n + 1 ) : temp = copy . deepcopy ( tabs )   i = each_b while i <= n : NEW_LINE


import java . util . Scanner ;   public class RomanBrowser { public static void main ( String [ ] args ) {   Scanner in = new Scanner ( System . in ) ; int n = in . nextInt ( ) , k = in . nextInt ( ) , i , j , a [ ] = new int [ n ] , o = 0 ;   for ( i = 0 ; i < n ; i ++ ) a [ i ] = in . nextInt ( ) ; in . close ( ) ;   for ( i = 0 ; i < k ; i ++ ) { int s = 0 ; for ( j = 0 ; j < n ; j ++ ) { if ( j % k != i ) s += a [ j ] ; } o = Math . max ( o , Math . abs ( s ) ) ; } System . out . println ( o ) ; } }


import java . util . * ; public class Solution { public static void main ( String [ ] args ) { Scanner s = new Scanner ( System . in ) ; int n = s . nextInt ( ) ; int k = s . nextInt ( ) ; int a [ ] = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) a [ i ] = s . nextInt ( ) ; int ans = 0 ; for ( int i = 0 ; i < k ; i ++ ) { int s1 = 0 ; for ( int j = 0 ; j < n ; j ++ ) if ( j % k != i ) s1 += a [ j ] ; ans = Math . max ( ans , Math . abs ( s1 ) ) ; } System . out . println ( ans ) ; } }


import java . util . * ; import java . io . * ;   public class Main { public static void main ( String args [ ] ) { new Main ( ) . run ( ) ; }   FastReader in = new FastReader ( ) ; PrintWriter out = new PrintWriter ( System . out ) ; void run ( ) { work ( ) ; out . flush ( ) ; } long mod = 1000000007 ; long gcd ( long a , long b ) { return a == 0 ? b : gcd ( b % a , a ) ; } void work ( ) { long n = nl ( ) , k = nl ( ) ; int offset = 65 ; long [ ] A = new long [ 130 ] ; long cnt = 0 ; for ( int i = 0 ; i < 63 ; i ++ ) { if ( ( 1L << i & n ) > 0 ) { A [ offset + i ] = 1 ; cnt ++ ; } } if ( cnt > k ) { out . println ( " No " ) ; return ; } k -= cnt ; for ( int i = 127 ; ; i -- ) { long c = A [ i ] ; if ( c > k ) { break ; } else { A [ i - 1 ] += A [ i ] * 2 ; A [ i ] = 0 ; k -= c ; } } int idx = 0 ; for ( int i = 1 ; ; i ++ ) { if ( A [ i ] > 0 ) { idx = i ; break ; } } if ( k > 0 ) { A [ idx ] -- ; } List < Integer > ret = new ArrayList < > ( ) ; for ( int i = 127 ; i >= 0 ; i -- ) { long c = A [ i ] ; for ( int j = 0 ; j < c ; j ++ ) { ret . add ( i - 65 ) ; } } if ( k > 0 ) { idx -- ; while ( k > 0 ) { ret . add ( idx - 65 ) ; k -- ; idx -- ; } ret . add ( idx + 1 - 65 ) ; } out . println ( " Yes " ) ; for ( int r : ret ) { out . print ( r + " ▁ " ) ; } }

n , k = map ( int , input ( ) . split ( ) )   s = list ( ) b = list ( ) base = 0 while n > 0 : s . append ( n % 2 ) b . append ( base ) n //= 2 base += 1 s . reverse ( ) NEW_LINE


import mathx , k = map ( int , input ( ) . split ( ) ) kori = ka = bin ( x )   NEW_LINE


from heapq import heapify , heappop , heappushn , k = map ( int , input ( ) . split ( ) ) heap1 = [ ] heap2 = [ ] MAX = int ( 1e5 ) + 10 s = [ ] heapify ( heap1 ) heapify ( heap2 ) i = 0 cnt = 0 while 1 << i <= n : if 1 << i & n : heappush ( heap1 , - i ) ; heappush ( heap2 , - i ) ; cnt += 1 i += 1 if cnt > k : print ( " NO " ) ; exit ( )   temp = cntwhile temp < k : x = - 1 * heappop ( heap1 ) - 1 heappush ( heap1 , - x ) heappush ( heap1 , - x ) temp += 1 temp = heap1 [ 0 ] * - 1   while cnt < k : if temp == heap2 [ 0 ] * - 1 : break x = heappop ( heap2 ) * - 1 - 1 heappush ( heap2 , - x ) heappush ( heap2 , - x ) cnt += 1   while heap2 : s . append ( heappop ( heap2 ) * - 1 )   while cnt < k : s [ - 1 ] = s [ - 1 ] - 1 s . append ( s [ - 1 ] ) cnt += 1 print ( " YES " ) print ( * s )               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 { long x , y ; Student ( long x , long y ) { this . x = x ; this . y = y ; } } static int prime [ ] ; static void sieveOfEratosthenes ( int n ) {


import java . util . * ; public class square { public static void main ( String ar [ ] ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) , m = sc . nextInt ( ) ; System . out . println ( n + m - 1 ) ; for ( int i = 1 ; i <= m ; i ++ ) System . out . println ( 1 + " ▁ " + i ) ; for ( int j = 2 ; j <= n ; j ++ ) System . out . println ( j + " ▁ " + 1 ) ; } }

import sys , mathsys . setrecursionlimit ( 10 ** 8 ) ''' def ▁ fun ( ) : ▁ ▁ ▁ ▁ for ▁ i ▁ in ▁ range ( 16 ) : ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ for ▁ j ▁ in ▁ range ( 4 ) : ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ if ▁ i & (1 < < j ) : ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ print ( j , end = ' ' ) ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ print ( ) import ▁ binarytreefrom ▁ collections ▁ import ▁ dequebst ▁ = ▁ binarytree . tree ( height = 4 , is _ perfect = True ) print ( bst ) def ▁ s ( bst ) : ▁ ▁ ▁ ▁ if ▁ bst : ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ bst . left , bst . right ▁ = ▁ bst . right , bst . left ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ s ( bst . right ) ▁ ▁ ▁ ▁ ▁ ▁ ▁ ▁ s ( bst . left ) s ( bst ) print ( bst ) ''' n , m = map ( int , input ( ) . split ( ) ) print ( n + m - 1 ) for i in range ( 1 , m + 1 ) : print ( 1 , i ) for i in range ( 2 , n + 1 ) : print ( i , 1 ) NEW_LINE


n , m = [ int ( x ) for x in input ( ) . split ( ) ]   a = min ( n , m ) b = abs ( n - m ) k = 2 * a - 1 + bprint ( k ) if a == 1 : print ( 1 , 1 ) i = 1 else : for i in range ( 1 , a ) : print ( i , i ) print ( i + 1 , i ) print ( i + 1 , i + 1 )   if n < m : for i in range ( a + 1 , m + 1 ) : print ( a , i ) elif n > m : for i in range ( a + 1 , n + 1 ) : print ( i , a ) NEW_LINE


n , m = map ( int , input ( ) . split ( ) ) print ( n + m - 1 ) for i in range ( 1 , m + 1 ) : print ( 1 , i ) for i in range ( 2 , n + 1 ) : print ( i , m ) NEW_LINE


n , m = map ( int , input ( ) . split ( ) ) print ( n + m - 1 ) for i in range ( 1 , m + 1 ) : print ( 1 , i ) for j in range ( 2 , n + 1 ) : print ( j , 1 )   NEW_LINE


a , b = map ( int , input ( ) . split ( ) ) aa = [ ] bb = [ ] ans = [ ] lis = [ ] liss = [ ] for t in range ( 1 , a + 1 ) : aa . append ( t ) for t in range ( 1 , b + 1 ) : bb . append ( t ) for m in range ( len ( aa ) ) : mm = aa [ m ] for n in range ( len ( bb ) ) : nn = bb [ n ] if mm + nn not in ans : ans . append ( mm + nn ) lis . append ( mm ) liss . append ( nn ) print ( len ( ans ) ) for t in range ( len ( lis ) ) : v = lis [ t ] vv = liss [ t ] print ( v , vv ) NEW_LINE


import java . util . * ; import java . util . Scanner ; import java . io . * ; import javax . lang . model . util . ElementScanner6 ;   public class A322 {   public static void main ( String args [ ] ) {   FastReader in = new FastReader ( ) ; PrintWriter pr = new PrintWriter ( new BufferedWriter ( new OutputStreamWriter ( System . out ) ) ) ; int tc = 1 ;


import java . io . * ;   import java . util . * ; public class Test {   public static void main ( String [ ] args ) throws java . lang . Exception { PrintWriter out = new PrintWriter ( new OutputStreamWriter ( System . out ) ) ; BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String str [ ] = br . readLine ( ) . split ( " ▁ " ) ; int n = Integer . parseInt ( str [ 0 ] ) ; int m = Integer . parseInt ( str [ 1 ] ) ; int k = n + m - 1 ; out . println ( k ) ; out . flush ( ) ;


import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . io . PrintWriter ; import java . util . ArrayList ; import java . util . StringTokenizer ;   public class CF322A { public static void main ( String [ ] args ) { FastReader input = new FastReader ( ) ; PrintWriter pw = new PrintWriter ( System . out ) ;   int n = input . nextInt ( ) ; int m = input . nextInt ( ) ;    int pairs = m + ( n - 1 ) ; pw . println ( pairs ) ; for ( int i = 1 ; i <= m ; i ++ ) { pw . println ( 1 + " ▁ " + i ) ; }   for ( int i = 2 ; i <= n ; i ++ ) { pw . println ( i + " ▁ " + 1 ) ; } pw . flush ( ) ; pw . close ( ) ; } 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 ; } } }


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


import com . sun . org . apache . bcel . internal . generic . AALOAD ; import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . io . PrintWriter ; import java . math . BigInteger ; import java . util . * ; import java . util . stream . IntStream ; import javafx . util . Pair ;   public class Main {   static void sort ( int a [ ] ) { Random ran = new Random ( ) ; for ( int i = 0 ; i < a . length ; i ++ ) { int r = ran . nextInt ( a . length ) ; int temp = a [ r ] ; a [ r ] = a [ i ] ; a [ i ] = temp ; }   Arrays . sort ( a ) ; }   public static void main ( String [ ] args ) throws IOException {   Scanner input = new Scanner ( System . in ) ; int n = input . nextInt ( ) ; int a [ ] = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = input . nextInt ( ) ; } sort ( a ) ; int temp = a [ 0 ] ; a [ 0 ] = a [ n - 1 ] ; a [ n - 1 ] = temp ; for ( int i : a ) { System . out . print ( i + " ▁ " ) ; } System . out . println ( " " ) ; }   }

input ( ) a = sorted ( input ( ) . split ( ) , key = int ) print ( a [ - 1 ] , * a [ 1 : - 1 ] , a [ 0 ] ) NEW_LINE


n = int ( input ( ) ) a = input ( ) . split ( ) a_array = [ ] array2 = [ ] for i in range ( n ) : a_array . append ( int ( a [ i ] ) ) a_array = sorted ( a_array ) a = a_array [ 0 ] a_array [ 0 ] = a_array [ len ( a_array ) - 1 ] a_array [ len ( a_array ) - 1 ] = afor i in range ( len ( a_array ) ) : array2 . append ( a_array [ i ] ) print ( array2 [ i ] , end = " ▁ " ) NEW_LINE


n = int ( input ( ) )   a = list ( map ( int , input ( ) . split ( ) ) )   ma = max ( a ) mi = min ( a )   a . remove ( ma ) a . remove ( mi ) NEW_LINE


n = int ( input ( ) ) a = list ( map ( int , input ( ) . split ( ) ) ) b = [ ] a = sorted ( a ) b = [ a [ - 1 ] ] + a [ 1 : ( n - 1 ) ] + [ a [ 0 ] ] print ( * b ) NEW_LINE


import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . Scanner ; import java . util . StringTokenizer ; import java . util . * ; public class c693a {


import java . util . * ; import java . io . * ; import java . lang . * ; public class Codeforces { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; PrintWriter out = new PrintWriter ( System . out ) ; StringTokenizer st = new StringTokenizer ( " " ) ; String next ( ) { if ( ! st . hasMoreTokens ( ) ) { try { st = new StringTokenizer ( br . readLine ( ) ) ; } catch ( Exception e ) {   } } return st . nextToken ( ) ; } int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } public static void main ( String [ ] args ) { new Codeforces ( ) . solve ( ) ; } void solve ( ) { int n = nextInt ( ) ; List < Integer > arr = new ArrayList < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) arr . add ( nextInt ( ) ) ; Collections . sort ( arr ) ; int max = arr . get ( n - 1 ) , min = arr . get ( 0 ) ; arr . remove ( 0 ) ; arr . remove ( n - 2 ) ; out . print ( max + " ▁ " ) ; for ( int i : arr ) out . print ( i + " ▁ " ) ; out . print ( min ) ; out . close ( ) ; } }


import java . lang . * ; import java . util . * ;   public class Abhishek {   public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] a = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = sc . nextInt ( ) ; } Arrays . sort ( a ) ; int m = a [ n - 1 ] ; a [ n - 1 ] = a [ 0 ] ; a [ 0 ] = m ; for ( int i = 0 ; i < n ; i ++ ) { System . out . print ( a [ i ] + " ▁ " ) ; } }   }


import javax . swing . plaf . IconUIResource ; import java . util . * ;

n = int ( input ( ) ) print ( 2 * ( n // 3 ) if n % 3 == 0 else 2 * ( n // 3 ) + 1 ) NEW_LINE


n = int ( input ( ) ) y = ( n // 3 ) * 2 if n % 3 == 0 : print ( y ) else : print ( y + 1 ) NEW_LINE


print ( ( int ( input ( ) ) * 2 + 1 ) // 3 ) NEW_LINE


p = int ( input ( ) ) if p >= 3 : x = ( p // 3 ) * 2   if p % 3 : x += 1 else : x = 1 print ( x ) NEW_LINE


n = int ( input ( ) ) print ( n // 3 * 2 if n % 3 == 0 else n // 3 * 2 + 1 ) NEW_LINE


import java . util . Scanner ;   public class Main {   public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int stonesNum ; int gifts ; stonesNum = sc . nextInt ( ) ; gifts = ( stonesNum / 3 ) * 2 ;   if ( stonesNum % 3 > 0 ) gifts ++ ;   System . out . println ( gifts ) ;   } }


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


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


import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . io . PrintWriter ; import java . util . Arrays ; import java . util . Random ; import java . util . StringTokenizer ;   public class Main implements Runnable {   long INF = ( long ) 1e13 + 7 ;   private void solve ( ) throws IOException { int n = nextInt ( ) ; int k = nextInt ( ) ; long p = nextLong ( ) ; long a [ ] = new long [ n ] ; long b [ ] = new long [ k ] ; for ( int i = 0 ; i < n ; ++ i ) a [ i ] = nextLong ( ) ; for ( int i = 0 ; i < k ; ++ i ) b [ i ] = nextLong ( ) ; Arrays . sort ( a ) ; Arrays . sort ( b ) ; long ans = INF ; for ( int i = 0 ; i <= k - n ; ++ i ) { long cur = 0 ; for ( int j = 0 ; j < n ; ++ j ) { cur = Math . max ( Math . abs ( a [ j ] - b [ i + j ] ) + Math . abs ( b [ i + j ] - p ) , cur ) ; } ans = Math . min ( cur , ans ) ; } pw . println ( ans ) ; }   void test ( ) throws IOException { Random rnd = new Random ( ) ; for ( int i = 0 ; i < 5 ; ++ i ) { int n = rnd . nextInt ( 10 ) + 1 ; int a [ ] = new int [ n ] ; System . err . println ( n ) ; for ( int j = 0 ; j < n ; ++ j ) { a [ j ] = rnd . nextInt ( 20 ) + 1 ; System . err . print ( a [ j ] + " ▁ " ) ; }

pp = list ( map ( int , input ( ) . split ( ) ) ) inf = int ( 1e18 ) n = pp [ 0 ] k = pp [ 1 ] p = pp [ 2 ] a = list ( map ( int , input ( ) . split ( ) ) ) b = list ( map ( int , input ( ) . split ( ) ) ) a . sort ( ) b . sort ( ) dp = [ [ inf for j in range ( 0 , 2011 ) ] for i in range ( 0 , 1011 ) ] for i in range ( 0 , k ) : dp [ 0 ] [ i ] = abs ( a [ 0 ] - b [ i ] ) + abs ( b [ i ] - p ) for i in range ( 1 , n ) : for j in range ( 0 , k ) : dp [ i ] [ j ] = min ( int ( dp [ i ] [ j ] ) , max ( abs ( a [ i ] - b [ j ] ) + abs ( b [ j ] - p ) , int ( dp [ i - 1 ] [ j - 1 ] ) ) ) ans = int ( 1e18 ) for i in range ( 0 , k ) : ans = min ( ans , int ( dp [ n - 1 ] [ i ] ) ) print ( ans ) NEW_LINE


n , k , p = map ( int , input ( ) . split ( ) ) a = sorted ( list ( map ( int , input ( ) . split ( ) ) ) ) b = sorted ( list ( map ( int , input ( ) . split ( ) ) ) )   res = 1e15 for i in range ( k - n + 1 ) : ma = 0 for j in range ( n ) : te = abs ( a [ j ] - b [ i + j ] ) + abs ( b [ i + j ] - p ) ma = max ( ma , te ) res = min ( res , ma ) print ( res ) NEW_LINE


import java . io . * ; import java . util . * ;     public class Main { static Integer [ ] a = new Integer [ 1010 ] ; static Integer [ ] b = new Integer [ 2020 ] ; static int [ ] [ ] dp = new int [ 1010 ] [ 2020 ] ; public static void main ( String args [ ] ) { Scanner in ; PrintStream out ; in = new Scanner ( new BufferedInputStream ( System . in ) ) ; out = System . out ; try { in = new Scanner ( new FileInputStream ( " java . in " ) ) ; out = new PrintStream ( " java . out " ) ; } catch ( FileNotFoundException e ) { } int n = in . nextInt ( ) , k = in . nextInt ( ) , p = in . nextInt ( ) ; for ( int i = 1 ; i <= n ; i ++ ) a [ i ] = in . nextInt ( ) ; for ( int i = 1 ; i <= k ; i ++ ) b [ i ] = in . nextInt ( ) ; Arrays . sort ( a , 1 , n + 1 , new MyCom ( ) ) ; Arrays . sort ( b , 1 , k + 1 , new MyCom ( ) ) ; dp [ 0 ] [ 0 ] = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = i ; j <= k ; j ++ ) { dp [ i ] [ j ] = Math . max ( dp [ i - 1 ] [ j - 1 ] , Math . abs ( a [ i ] - b [ j ] ) + Math . abs ( b [ j ] - p ) ) ; if ( j > i ) dp [ i ] [ j ] = Math . min ( dp [ i ] [ j ] , dp [ i ] [ j - 1 ] ) ; } } out . println ( dp [ n ] [ k ] ) ; } static class MyCom implements Comparator < Integer > { public int compare ( Integer i1 , Integer i2 ) { return i1 - i2 ; } } }


import java . util . Arrays ; import java . util . Scanner ; public class R424D { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int n = scan . nextInt ( ) ; int k = scan . nextInt ( ) ; long p = scan . nextLong ( ) ; long [ ] pos = new long [ n ] ; long [ ] key = new long [ k ] ; for ( int i = 0 ; i < n ; i ++ ) { pos [ i ] = scan . nextLong ( ) ; } for ( int i = 0 ; i < k ; i ++ ) { key [ i ] = scan . nextLong ( ) ; } Arrays . sort ( pos ) ; Arrays . sort ( key ) ; long min = Long . MAX_VALUE ; long [ ] d = new long [ n ] ; int number = k - n + 1 ; long max = 0 ; for ( int i = 0 ; i < n ; i ++ ) { d [ i ] = Math . abs ( pos [ i ] - key [ i ] ) + Math . abs ( key [ i ] - p ) ; max = Math . max ( max , d [ i ] ) ; } min = Math . min ( min , max ) ; for ( int i = 1 ; i < number ; i ++ ) { max = 0 ; for ( int j = 0 ; j < n ; j ++ ) { d [ j ] = Math . abs ( pos [ j ] - key [ i + j ] ) + Math . abs ( key [ i + j ] - p ) ; max = Math . max ( max , d [ j ] ) ; } min = Math . min ( min , max ) ; } System . out . println ( min ) ; } }


import java . util . Scanner ;   public class _0708DetectiveBook {   public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int days = 0 ; int mysteryExplainedOnPage = 0 ; for ( int page = 1 ; page <= n ; page ++ ) { int temp = sc . nextInt ( ) ; mysteryExplainedOnPage = Math . max ( temp , mysteryExplainedOnPage ) ; if ( mysteryExplainedOnPage <= page ) { days ++ ; } else { mysteryExplainedOnPage = Math . max ( mysteryExplainedOnPage , temp ) ; } } System . out . println ( days ) ; }   }

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


n , a = int ( input ( ) ) , [ * map ( int , input ( ) . split ( ) ) ] ans = 0 ; i = 0   while i < n : ans += 1 max_day = a [ i ] while ( i + 1 < max_day ) : i += 1 max_day = max ( max_day , a [ i ] ) i += 1 print ( ans ) NEW_LINE


from sys import stdinn = int ( stdin . readline ( ) ) a = list ( map ( int , stdin . readline ( ) . split ( ) ) ) a = [ i - 1 for i in a ] ans = 0 pos = 0 while pos < n : ans += 1 mx_val = pos while pos < n and pos <= mx_val : mx_val = max ( mx_val , a [ pos ] ) pos += 1   print ( ans ) NEW_LINE


import sys   n = int ( input ( ) ) a = [ int ( i ) for i in input ( ) . split ( ) ] ans = 0 mx = 0 for i in range ( n ) : mx = max ( mx , a [ i ] ) if mx == i + 1 : ans += 1 print ( ans ) NEW_LINE


import sys , collections , math , itertools , random , bisectINF = sys . maxsizedef get_ints ( ) : return map ( int , sys . stdin . readline ( ) . strip ( ) . split ( ) ) def get_array ( ) : return list ( map ( int , sys . stdin . readline ( ) . strip ( ) . split ( ) ) ) def input ( ) : return sys . stdin . readline ( ) . strip ( ) mod = 1000000007   n = int ( input ( ) ) arr = get_array ( ) arr . sort ( ) cnt = 0 for i in range ( n ) : if arr [ i ] == i + 1 : cnt += 1 print ( cnt ) NEW_LINE


import java . util . * ; import java . io . * ; public class EdE { static long [ ] mods = { 1000000007 , 998244353 , 1000000009 } ; static long mod = mods [ 0 ] ; public static MyScanner sc ; public static PrintWriter out ; public static void main ( String [ ] omkar ) throws Exception {


import java . io . * ; import java . math . BigInteger ; import java . util . * ; public class C { static BufferedReader br ; static PrintWriter pr ; static int cin ( ) throws Exception { return Integer . valueOf ( br . readLine ( ) ) ; } static int [ ] split ( ) throws Exception { String [ ] cmd = br . readLine ( ) . split ( " ▁ " ) ; int [ ] ans = new int [ cmd . length ] ; for ( int i = 0 ; i < cmd . length ; i ++ ) { ans [ i ] = Integer . valueOf ( cmd [ i ] ) ; } return ans ; } static long [ ] splitL ( ) throws IOException { String [ ] cmd = br . readLine ( ) . split ( " ▁ " ) ; long [ ] ans = new long [ cmd . length ] ; for ( int i = 0 ; i < cmd . length ; i ++ ) { ans [ i ] = Long . valueOf ( cmd [ i ] ) ; } return ans ; } static long p = 1000000007 ; static long power ( long x , long y ) { long res = 1 ; x = x % p ; if ( x == 0 ) return 0 ; while ( y > 0 ) { if ( ( y & 1 ) == 1 ) res = ( res * x ) % p ; y = y >> 1 ; x = ( x * x ) % p ; } return res ; } public static void main ( String [ ] args ) throws Exception {


import java . util . * ; public class c1 { public static void main ( String [ ] args ) { int n ; Scanner reader = new Scanner ( System . in ) ; n = reader . nextInt ( ) ; int [ ] a = new int [ n ] ; int days , max = 0 , i ; for ( i = 0 ; i < n ; ++ i ) { a [ i ] = reader . nextInt ( ) ; } for ( i = days = 0 ; i < n ; ++ i ) { if ( max < a [ i ] ) max = a [ i ] ; if ( max == i + 1 ) ++ days ; } System . out . println ( days ) ; } }


import java . util . * ;   public class Check2 { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; char [ ] s1 = s . toCharArray ( ) ; long sum = 0 ; boolean check = false ;

s = input ( )     if '1' not in s : print ( " no " )   else : s = s [ s . index ( '1' ) : ] print ( " yes " if s . count ( '0' ) >= 6 else " no " ) NEW_LINE


n = input ( ) if len ( n ) == n . count ( '0' ) : print ( ' NO ' ) else : while n [ 0 ] == "0" : n = n [ 1 : ] if n . count ( '0' ) >= 6 and n [ 0 ] == '1' : print ( ' YES ' ) else : print ( ' NO ' ) NEW_LINE


from collections import Counterc = Counter ( str ( int ( input ( ) ) ) ) if c [ '1' ] >= 1 and c [ '0' ] >= 6 : print ( " yes " ) else : print ( " no " ) NEW_LINE


s = input ( ) i = s . find ( '1' ) if i == - 1 : print ( ' no ' ) else : if s [ i + 1 : ] . count ( '0' ) < 6 : print ( ' no ' ) else : print ( ' yes ' ) NEW_LINE


b = str ( input ( ) ) c = 0 if '1' not in b : print ( ' no ' ) else : for i in range ( len ( b ) ) : if b [ i ] == '1' : idx = i break   for i in range ( idx , len ( b ) ) : if b [ i ] == '0' : c += 1   if c >= 6 : print ( ' yes ' ) else : print ( ' no ' ) NEW_LINE


import java . util . * ; import java . util . jar . JarOutputStream ;   public class Practise {   public static int [ ] [ ] dp ; public static void main ( String [ ] args ) {


import java . util . Scanner ;   public class _0736DivSixFour { static String toBinary ( String s , int n ) { if ( n == 0 ) { return s ; } int val = n % 2 ; s = val + s ; return toBinary ( s , n / 2 ) ; } public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . nextLine ( ) ; if ( s . indexOf ( '1' ) == - 1 ) { System . out . println ( " NO " ) ; } else { int count = 0 ; for ( int i = s . indexOf ( '1' ) + 1 ; i < s . length ( ) ; i ++ ) { if ( s . charAt ( i ) == '0' ) { count ++ ; } if ( count == 6 ) break ; } if ( count == 6 ) { System . out . println ( " YES " ) ; } else { System . out . println ( " NO " ) ; } } }   }


import java . util . HashSet ; import java . util . Scanner ; import java . util . Set ;   public class ExamA3 { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; String s1 = in . next ( ) ; Set < Character > setS1 = new HashSet < > ( ) ; for ( char c : s1 . toCharArray ( ) ) { setS1 . add ( c ) ; } String s2 = in . next ( ) ;   int flag = - 1 ;

def do ( cur ) : if len ( cur ) < len ( pt ) - 1 : return " NO " i = j = 0 while j < len ( cur ) : if pt [ i ] == " ? " : if cur [ j ] not in good : return " NO " elif pt [ i ] == " * " : b = len ( cur ) - len ( pt ) + 1 for x in cur [ j : j + b ] : if x in good : return " NO " i += 1 j += b continue else : if pt [ i ] != cur [ j ] : return " NO " i += 1 j += 1 return " YES "   good = set ( input ( ) ) pt = input ( ) pi = True if " * " not in pt else Falsefor _ in range ( int ( input ( ) ) ) : cur = input ( ) if pi and len ( cur ) != len ( pt ) : print ( " NO " ) else : print ( do ( cur ) ) NEW_LINE


s1 = input ( ) s2 = input ( ) n = int ( input ( ) )   good_words = set ( s1 ) s3_list = [ ] for _ in range ( n ) : s3 = input ( ) s3_list . append ( s3 )   for s3 in s3_list : flag = 1 if " * " not in s2 : if len ( s2 ) != len ( s3 ) : flag = 0 else : for index , value in enumerate ( s2 ) : if value == " ? " : if s3 [ index ] not in good_words : flag = 0 break else : if s3 [ index ] != s2 [ index ] : flag = 0 break else : if len ( s3 ) < len ( s2 ) - 1 : flag = 0 else : idx = s2 . index ( " * " ) s2_1 = s2 [ : idx ] s2_2 = s2 [ idx + 1 : ] NEW_LINE


hor = input ( ) mask = input ( ) lenmask = len ( mask ) for i in range ( int ( input ( ) ) ) : a = input ( ) lena = len ( a ) f = True if lena < lenmask - 1 and ' * ' in mask : print ( ' NO ' ) continue elif lena < lenmask and ' * ' not in mask : print ( ' NO ' ) continue elif lena > lenmask and ' * ' not in mask : print ( ' NO ' ) continue for j in range ( lenmask ) : if mask [ j ] == ' ? ' : if a [ j ] not in hor : f = False break elif mask [ j ] == ' * ' : if lenmask - 1 == lena : a = a [ : j ] + ' j ' + a [ j : ] else : srez = a [ j : j + lena - lenmask + 1 ] for el in srez : if el in hor : f = False break if not f : break a = a [ : j ] + a [ j + lena - lenmask : ] else : if a [ j ] != mask [ j ] : f = False break if f : print ( ' YES ' ) else : print ( ' NO ' ) NEW_LINE


from collections import defaultdict , deque , Counterfrom sys import stdin , stdoutfrom heapq import heappush , heappopimport mathimport ioimport osimport mathimport bisect   NEW_LINE


import java . util . ArrayList ; import java . util . Scanner ;   public class VJ_1011 { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String s1 = sc . next ( ) ; String s2 = sc . next ( ) ; int n = sc . nextInt ( ) ; ArrayList < String > list = new ArrayList < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { list . add ( sc . next ( ) ) ; } boolean contain = false ; int index = - 1 ; if ( s2 . contains ( " * " ) ) { contain = true ; index = s2 . indexOf ( " * " ) ; } ArrayList < String > res = new ArrayList < > ( ) ; for ( String s3 : list ) { if ( contain ) { int minus = s3 . length ( ) - s2 . length ( ) + 1 ;


import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . HashMap ;   public class StringReplace { public static void main ( String [ ] args ) throws IOException {


import java . util . HashSet ; import java . util . Scanner ; import java . util . Set ;   public class Main2020_4_02 { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; String s1 = in . next ( ) ; Set < Character > setS1 = new HashSet < > ( ) ; for ( char c : s1 . toCharArray ( ) ) { setS1 . add ( c ) ; } String s2 = in . next ( ) ;   int flag = - 1 ;


import java . util . ArrayList ; import java . util . Random ; import java . util . Scanner ; public class PetyaAndExam { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) . trim ( ) ; ArrayList < String > ch = new ArrayList < String > ( ) ; for ( int i = 0 ; i < s . length ( ) ; ++ i ) ch . add ( s . substring ( i , i + 1 ) ) ; String p = sc . next ( ) . trim ( ) ; int n = sc . nextInt ( ) ; for ( int i = 0 ; i < n ; ++ i ) { String t = sc . next ( ) . trim ( ) ; int jt = 0 ; int k = p . length ( ) , m = t . length ( ) ; String ans = " " ; for ( int jp = 0 ; jp < k && ans . length ( ) == 0 ; ++ jp ) { String pa = p . substring ( jp , jp + 1 ) ; String ta = jt < m ? t . substring ( jt , jt + 1 ) : " BLERGH " ; if ( pa . equals ( " ? " ) ) { if ( jt < m ) { if ( ! ch . contains ( ta ) ) ans = " NO " ; else { ++ jt ; } } else ans = " NO " ; } else if ( pa . equals ( " * " ) ) { for ( int y = 0 ; y < m - k + 1 ; ++ y ) { if ( ! ch . contains ( t . substring ( jt , jt + 1 ) ) ) ++ jt ; else { ans = " NO " ; } } } else { if ( jt < m ) { if ( ! pa . equals ( ta ) ) ans = " NO " ; else { ++ jt ; } } else ans = " NO " ; } } if ( jt == m && ans . length ( ) == 0 ) ans = " YES " ; else ans = " NO " ; System . out . println ( ans ) ; } sc . close ( ) ; } }


import java . math . * ; import java . util . * ; import java . io . * ;   public class Main {   void solve ( ) throws IOException { int a , b , c , n , res ; a = nextInt ( ) ; b = nextInt ( ) ; c = nextInt ( ) ; n = nextInt ( ) ;   res = n - ( a + b - c ) ; if ( res > 0 && a >= c && b >= c && res <= n ) { res = res ; } else { res = - 1 ; }   System . out . println ( res ) ; }   BufferedReader reader ; StringTokenizer tokenizer ; PrintWriter writer ;   void run ( ) throws IOException { in = new BufferedReader ( new InputStreamReader ( System . in ) ) ; out = new PrintWriter ( System . out ) ; solve ( ) ; out . close ( ) ; }   public static void main ( String [ ] args ) throws IOException { new Main ( ) . run ( ) ; }   BufferedReader in ; StringTokenizer str ; PrintWriter out ;   String next ( ) throws IOException { while ( ( str == null ) || ( ! str . hasMoreTokens ( ) ) ) { str = new StringTokenizer ( in . readLine ( ) ) ; } return str . nextToken ( ) ; }   int nextInt ( ) throws IOException { return Integer . parseInt ( next ( ) ) ; }   }

A , B , C , N = map ( int , input ( ) . strip ( ) . split ( ) )   flag = Trueif C > A or C > B : flag = FalseD = N - ( A - C ) - Bif D >= 1 and flag : print ( D ) else : print ( - 1 ) NEW_LINE


a , b , c , n = map ( int , input ( ) . split ( ) ) s = a + b - cif s >= n or a < c or b < c : print ( - 1 ) else : print ( n - s ) NEW_LINE


A , B , C , N = map ( int , input ( ) . split ( ) ) A -= CB -= CS = A + B + Cif S < N and A + C >= C and B + C >= C : print ( N - S ) else : print ( - 1 ) NEW_LINE


A , B , C , N = map ( int , input ( ) . split ( ) ) ans = N - ( A + B - C ) if A < C or B < C or A > N or B > N or C > N or ans < 1 : print ( - 1 ) else : print ( ans ) NEW_LINE


import java . util . Scanner ;   public class vasya { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int c = sc . nextInt ( ) ; int n = sc . nextInt ( ) ;   if ( a < c || b < c ) { System . out . println ( " - 1" ) ; } else {   int students = ( a - c ) + ( b - c ) + c ; int failed_students = n - students ; if ( failed_students <= 0 ) { System . out . println ( " - 1" ) ; } else { System . out . println ( failed_students ) ; } } } }


import java . io . OutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . PrintWriter ; import java . util . Arrays ; 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 ) ; BLuckyCommonSubsequence solver = new BLuckyCommonSubsequence ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; }   static class BLuckyCommonSubsequence { int [ ] pi ; char [ ] first ; char [ ] second ; char [ ] virus ; StringBuilder sb ; int [ ] [ ] [ ] memo ;   void prefixFunction ( char [ ] s ) { int n = s . length ; pi = new int [ n ] ; for ( int i = 1 , j = 0 ; i < n ; ++ i )

A = input ( ) B = input ( ) virus = input ( )   NEW_LINE


s = input ( ) t = input ( ) u = input ( )   memos = { } def solve ( a , b , c ) : if c == len ( u ) : return 0 if a == len ( s ) or b == len ( t ) : return ' ' if ( a , b , c ) in memos : return memos [ ( a , b , c ) ]   me = s [ a ]   r = solve ( a + 1 , b , c ) try : idx = t [ b : ] . index ( me )   curr = u [ : c ] + me for i in range ( c + 2 ) : if curr [ i : ] == u [ : ( c + 1 - i ) ] : tr = solve ( a + 1 , b + idx + 1 , c + 1 - i ) if tr == 0 : r2 = 0 else : r2 = me + tr break   if r2 == 0 or len ( r ) > len ( r2 ) : k = r else : k = r2 except ValueError : k = r   memos [ ( a , b , c ) ] = k return k   NEW_LINE


a , b , v = input ( ) , input ( ) , input ( )   h = [ [ - 1 ] * len ( b ) for i in range ( len ( a ) ) ]   def f ( ab ) : return ab . count ( v )     def g ( i , j ) : if i < 0 or j < 0 : return " " if h [ i ] [ j ] == - 1 : s = g ( i - 1 , j - 1 ) if ( a [ i ] == b [ j ] ) : s += a [ i ] s1 = g ( i - 1 , j ) s2 = g ( i , j - 1 ) if ( len ( s1 ) - f ( s1 ) > len ( s ) - f ( s ) ) : s = s1 if ( len ( s2 ) - f ( s2 ) > len ( s ) - f ( s ) ) : s = s2 h [ i ] [ j ] = s ; return h [ i ] [ j ]   ss = g ( len ( a ) - 1 , len ( b ) - 1 ) while v in ss : ss1 = ss . replace ( v , v [ : - 1 ] ) ss2 = ss . replace ( v , v [ 1 : ] ) if ( f ( ss1 ) < f ( ss2 ) ) : ss = ss1 else : ss = ss2if len ( ss ) > 0 : print ( ss ) else : print ( 0 ) NEW_LINE


s1 , s2 , virus = [ input ( ) . strip ( ) for _ in range ( 3 ) ]   n , m , v = len ( s1 ) , len ( s2 ) , len ( virus )   NEW_LINE


import java . util . * ; import java . io . * ;   public class Main { public static void main ( String [ ] args ) throws IOException { FastScanner in = new FastScanner ( System . in ) ; PrintWriter out = new PrintWriter ( System . out ) ; new Main ( ) . run ( in , out ) ; out . close ( ) ; }


import java . util . Scanner ;   public class SpiralDown { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ;   int x = scanner . nextInt ( ) ; int y = scanner . nextInt ( ) ; int turn = 0 ;   if ( ( x == 0 || x == 1 ) & y == 0 ) { System . out . println ( 0 ) ; return ; }   if ( y > 0 ) { if ( x >= y ) turn = 4 * x - 3 ; else if ( x + y >= 0 ) turn = 4 * y - 2 ; else turn = - 4 * x - 1 ; } else { if ( x <= y ) turn = - 4 * x - 1 ; else if ( x + 2 * y <= 0 ) turn = - 4 * y ; else turn = 4 * x - 3 ; }   System . out . println ( turn ) ; } }

a , b = map ( int , input ( ) . split ( ) ) count = 0 q , e = 0 , 0 i = 1 flag = 0 while ( q != a or e != b ) : for j in range ( i ) : q += 1 if ( q == a and e == b ) : flag = 1 break if ( flag ) : break count += 1 for j in range ( i ) : e += 1 if ( q == a and e == b ) : flag = 1 break i += 1 if ( flag ) : break count += 1 for j in range ( i ) : q -= 1 if ( q == a and e == b ) : flag = 1 break if ( flag ) : break count += 1 for j in range ( i ) : e -= 1 if ( q == a and e == b ) : flag = 1 break if ( flag ) : break i += 1 count += 1 print ( count ) NEW_LINE


x , y = tuple ( map ( int , input ( ) . split ( ) ) ) if ( x == 0 and y == 0 ) : print ( 0 ) elif ( x >= 0 and y >= - x + 1 and y < x ) : if ( y == - x + 1 ) : print ( 4 * ( x - 1 ) ) else : print ( 4 * ( x - 1 ) + 1 ) elif ( y > 0 and ( x == 0 or ( x <= abs ( y ) and x > - abs ( y ) ) ) ) : if ( y == x ) : print ( 4 * ( abs ( y ) - 1 ) + 1 ) else : print ( 4 * ( abs ( y ) - 1 ) + 2 ) elif ( x <= 0 and y <= - x and y > x ) : if ( y == - x ) : NEW_LINE


l = input ( ) . split ( ' ▁ ' ) x , y = int ( l [ 0 ] ) , int ( l [ 1 ] ) if y <= 0 and x >= 1 + y and x <= 1 - y : print ( ( - y ) * 4 ) elif x > 0 and y >= 2 - x and y <= x : print ( x * 4 - 3 ) elif y > 0 and x >= - y and x <= y - 1 : print ( y * 4 - 2 ) elif x < 0 and y >= x and y <= - 1 - x : print ( ( - x ) * 4 - 1 ) else : print ( 0 ) NEW_LINE


a , b = map ( int , input ( ) . split ( ) ) count = 0 q , e = 0 , 0 i = 1 flag = 0   while ( q != a or e != b ) : for j in range ( i ) : q += 1 if ( q == a and e == b ) : flag = 1 break if ( flag ) : break count += 1 for j in range ( i ) : e += 1 if ( q == a and e == b ) : flag = 1 break i += 1 if ( flag ) : break count += 1 for j in range ( i ) : q -= 1 if ( q == a and e == b ) : flag = 1 break if ( flag ) : break count += 1 for j in range ( i ) : e -= 1 if ( q == a and e == b ) : flag = 1 break if ( flag ) : break i += 1 count += 1 print ( count ) NEW_LINE


import java . util . Scanner ;   public class PointOnSpiral { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int x = sc . nextInt ( ) ; int y = sc . nextInt ( ) ;   int result = 0 ; if ( x > 0 && y >= 2 - x && y <= x ) { result = ( 4 * x ) - 3 ; } else if ( y > 0 && x >= - y && x <= y - 1 ) { result = ( 4 * y ) - 2 ; } else if ( x < 0 && y >= x && y <= - 1 - x ) { result = ( 4 * ( - x ) ) - 1 ; } else if ( y <= 0 && x >= 1 + y && x <= - y + 1 ) { result = 4 * ( - y ) ; } else { result = 0 ; }   System . out . println ( result ) ; } }


import java . util . Scanner ;   public class TestBetter { public static void main ( String [ ] args ) { Scanner input = new Scanner ( System . in ) ;   int x , y ;   x = input . nextInt ( ) ; y = input . nextInt ( ) ;   int box = Math . max ( Math . abs ( x ) , Math . abs ( y ) ) ; int res = ( box - 1 ) * 4 ; if ( y == 0 && ( x == 0 || x == 1 ) ) { res = 0 ; System . out . println ( res ) ; return ; } if ( x == box && y == - ( box - 1 ) ) { System . out . println ( res ) ; return ; } res ++ ; if ( x == box && y > - box ) { System . out . println ( res ) ; return ; } res ++ ; if ( y == box ) { System . out . println ( res ) ; return ; } res ++ ; if ( x == - box ) { System . out . println ( res ) ; return ; } res ++ ;   System . out . println ( res ) ; } }


import java . util . Scanner ;   public class Game { public static void main ( String [ ] args ) { Scanner input = new Scanner ( System . in ) ;   int x = input . nextInt ( ) , y = input . nextInt ( ) , s = 0 ; if ( y > x && x >= - y ) s = - 2 + y * 4 ; if ( y < x && x <= - y + 1 ) s = - y * 4 ; if ( y <= x && x > - y + 1 ) s = - 3 + x * 4 ; if ( y >= x && x < - y ) s = - 1 - 4 * x ; System . out . println ( s ) ;   } }


import java . util . * ; import java . math . * ; import java . lang . * ; import javafx . util . Pair ;   public class gfg { public static void main ( String args [ ] ) { Scanner sc = new Scanner ( System . in ) ; int x = sc . nextInt ( ) ; int y = sc . nextInt ( ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; Map < Pair , Integer > map = new LinkedHashMap < > ( ) ; int sv = 0 , sp = 0 , ev = 0 , ep = 0 ; if ( a > b ) { sv = a ; ev = x ; sp = b ; ep = y ; } else { sv = b + 1 ; ev = x ; sp = b ; ep = y ; } int count = 0 ; for ( int i = sv ; i <= ev ; i ++ ) { for ( int j = sp ; j <= ep ; j ++ ) { if ( j >= i ) break ; Pair p = new Pair ( i , j ) ; map . put ( p , count ++ ) ; } } System . out . println ( count ) ; map . forEach ( ( k , v ) -> System . out . println ( k . getKey ( ) + " ▁ " + k . getValue ( ) ) ) ; } }

x , y , a , b = list ( map ( int , input ( ) . split ( ) ) ) ans = [ ] for i in range ( b , y + 1 ) : for j in range ( a , x + 1 ) : if i < j : ans . append ( [ j , i ] ) print ( len ( ans ) ) ans . sort ( ) for i in ans : print ( * i )   NEW_LINE


def headTails ( x , y , a , b ) : p_a = list ( range ( a , x + 1 ) ) p_b = list ( range ( b , min ( x + 1 , y + 1 ) ) ) arr = [ ] i = 0 j = 0 while i < len ( p_a ) and j < len ( p_b ) : if p_a [ i ] > p_b [ j ] : arr . append ( ( p_a [ i ] , p_b [ j ] ) ) if i < len ( p_a ) : for k in range ( i + 1 , len ( p_a ) ) : arr . append ( ( p_a [ k ] , p_b [ j ] ) ) j += 1 else : i += 1 arr . sort ( key = lambda x : x [ 0 ] ) print ( len ( arr ) ) for i in arr : print ( * i )   x , y , a , b = list ( map ( int , input ( ) . split ( ) ) ) headTails ( x , y , a , b ) NEW_LINE


x , y , a , b = map ( int , input ( ) . split ( ) ) vas , pet = a , bans = [ ] while vas <= x : pet = b while pet < vas and pet <= y : ans . append ( [ vas , pet ] ) pet += 1 vas += 1 print ( len ( ans ) ) for i in range ( len ( ans ) ) : print ( * ans [ i ] ) NEW_LINE


x , y , a , b = map ( int , input ( ) . split ( ) ) if ( a < b and ( x - a ) <= ( b - a ) ) or ( a == b and x < y ) : print ( 0 ) else : c = 0 for i in range ( a , x + 1 ) : for j in range ( b , y + 1 ) : if ( i > j ) : c = c + 1 print ( c ) for i in range ( a , x + 1 ) : for j in range ( b , y + 1 ) : if ( i > j ) : print ( i , j ) NEW_LINE


x , y , a , b = map ( int , input ( ) . split ( ) ) c = 0 xx = [ ] for i in range ( a , x + 1 ) : for j in range ( b , y + 1 ) : if ( i > j ) : c += 1 xx . append ( [ i , j ] ) print ( c ) for i in range ( c ) : print ( xx [ i ] [ 0 ] , xx [ i ] [ 1 ] )     NEW_LINE


import java . awt . Point ; import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStream ; import java . io . InputStreamReader ; import java . io . PrintWriter ; import java . math . BigDecimal ; import java . util . ArrayList ; import java . util . Arrays ; import java . util . Collections ; import java . util . HashSet ; import java . util . Hashtable ; import java . util . LinkedList ; import java . util . Queue ; import java . util . Stack ; import java . util . StringTokenizer ;    public class N700 { static PrintWriter out ; static Scanner sc ; static ArrayList < Integer > q , w ; static ArrayList < Integer > adj [ ] ; static HashSet < Integer > primesH ; static boolean prime [ ] ;


import java . util . * ;   public class Main {   public static void main ( String [ ] args ) { Scanner input = new Scanner ( System . in ) ; int x , y , a , b ; x = input . nextInt ( ) ; y = input . nextInt ( ) ; a = input . nextInt ( ) ; b = input . nextInt ( ) ; if ( x <= b ) { System . out . println ( 0 ) ; return ; } StringBuilder ans = new StringBuilder ( ) ; int count = 0 ; for ( int i = a ; i <= x ; i ++ ) { int j = b ; while ( i > j && y >= j ) { count ++ ; ans . append ( i + " ▁ " + j + " \n " ) ; j ++ ; } } System . out . println ( count ) ; System . out . println ( ans ) ; }   }


import javax . print . DocFlavor ; import javax . swing . * ; import java . awt . image . BandedSampleModel ; import java . util . * ;   public class Example { static long [ ] [ ] dp ;

import sys , mathfrom collections import deque , defaultdictimport operator as opfrom functools import reducefrom itertools import permutations   NEW_LINE


def sort ( s , n ) : for i in range ( 1 , n ) : temp = s [ i ] j = i - 1 while j >= 0 and len ( temp ) < len ( s [ j ] ) : s [ j + 1 ] = s [ j ] j -= 1   s [ j + 1 ] = temp     n = int ( input ( ) ) strings = [ ] for _ in range ( n ) : s = input ( ) strings . append ( s )   check = Truesort ( strings , n ) NEW_LINE


t = int ( input ( ) ) a = sorted ( ( input ( ) for _ in range ( t ) ) , key = lambda res : len ( res ) ) ans = all ( a [ i ] in a [ i + 1 ] for i in range ( t - 1 ) ) print ( ' YES \n ' + " \n " . join ( a ) if ans else ' NO ' ) NEW_LINE


n = int ( input ( ) ) a = [ ] for i in range ( 1 , n + 1 ) : b = input ( ) a . append ( b ) a . sort ( key = len ) t = 0 for i in range ( 1 , n ) : if a [ i - 1 ] in a [ i ] : t = 0 else : t = 1 NEW_LINE


import java . util . Scanner ;    public class SubstringSort {   public static void main ( String [ ] args ) { boolean flag = true ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; String str [ ] = new String [ n + 1 ] ; for ( int i = 0 ; i <= n ; i ++ ) { str [ i ] = sc . nextLine ( ) ; } for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i + 1 ; j <= n ; j ++ ) { if ( str [ i ] . length ( ) > str [ j ] . length ( ) ) { String temp = str [ i ] ; str [ i ] = str [ j ] ; str [ j ] = temp ; } } } for ( int i = 1 ; i <= n ; i ++ ) { if ( ! str [ i ] . contains ( str [ i - 1 ] ) ) { flag = false ; break ; } } if ( flag == true ) { System . out . println ( " YES " ) ; for ( int i = 0 ; i <= n ; i ++ ) { System . out . println ( str [ i ] ) ; } } else { System . out . println ( " NO " ) ; } } }


import java . util . * ; public class Main { public static boolean isSubstring ( String a , String b ) { int a_size = a . length ( ) ; int b_size = b . length ( ) ; for ( int i = 0 ; i < b_size ; i ++ ) { boolean found = true ; if ( i + a_size > b_size ) { break ; } for ( int j = 0 ; j < a_size ; j ++ ) { if ( b . charAt ( i + j ) != a . charAt ( j ) ) { found = false ; break ; } } if ( found ) { return true ; } } return false ; } public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int n = scan . nextInt ( ) ; String str [ ] = new String [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { str [ i ] = scan . next ( ) ; } for ( int i = 0 ; i < n - 1 ; i ++ ) { for ( int j = 0 ; j < n - i - 1 ; j ++ ) { if ( str [ j ] . length ( ) > str [ j + 1 ] . length ( ) ) { String temp = str [ j ] ; str [ j ] = str [ j + 1 ] ; str [ j + 1 ] = temp ; } } } boolean exist = true ; for ( int i = 0 ; i < n - 1 ; i ++ ) { if ( isSubstring ( str [ i ] , str [ i + 1 ] ) == false ) { exist = false ; break ; } } if ( exist ) { System . out . println ( " YES " ) ; for ( int i = 0 ; i < n ; i ++ ) { System . out . println ( str [ i ] ) ; } } else { System . out . println ( " NO " ) ; } } }


import java . util . * ; public class MyClass { public static void main ( String args [ ] ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; String [ ] arr = new String [ n ] ; for ( int i = 0 ; i < n ; i ++ ) arr [ i ] = sc . next ( ) ; for ( int i = 1 ; i < n ; i ++ ) { String temp = arr [ i ] ; int j = i - 1 ; while ( j >= 0 && temp . length ( ) < arr [ j ] . length ( ) ) { arr [ j + 1 ] = arr [ j ] ; j -- ; } arr [ j + 1 ] = temp ; } int c = 1 ; for ( int i = 1 ; i < n ; i ++ ) { if ( arr [ i ] . contains ( arr [ i - 1 ] ) ) c ++ ; } if ( c == n ) { System . out . println ( " YES " ) ; for ( int i = 0 ; i < n ; i ++ ) System . out . println ( arr [ i ] ) ; } else System . out . println ( " NO " ) ; } }


import java . util . * ;   public class Check2 { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; List < String > list = new ArrayList < > ( ) ; int maxl = 0 ; String maxls = " " ; int index = 0 ; Map < Integer , List < String > > map = new HashMap < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { String s = sc . next ( ) ; int l = s . length ( ) ; map . putIfAbsent ( l , new ArrayList < > ( ) ) ; List < String > y = map . get ( l ) ; y . add ( s ) ; map . put ( l , y ) ;


import java . util . * ; import java . lang . * ; import java . io . * ; public class Solution { public static void main ( String [ ] args ) throws java . lang . Exception { Scanner scan = new Scanner ( System . in ) ; String s = scan . next ( ) ; int ca = 0 ; int cb = 0 ; int d = 0 ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( s . charAt ( i ) == '0' ) { cb = 0 ; ca ++ ; if ( ca == 7 ) { d = 1 ; break ; } } else { ca = 0 ; cb ++ ; if ( cb == 7 ) { d = 1 ; break ; } } } if ( d == 1 ) { System . out . println ( " YES " ) ; } else { System . out . println ( " NO " ) ; } } }

s = input ( ) NEW_LINE x = 7 * "1" NEW_LINE y = 7 * "0" NEW_LINE if x in s : NEW_LINE INDENT print ( " YES " ) NEW_LINE DEDENT elif y in s : NEW_LINE INDENT print ( " YES " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " NO " ) NEW_LINE DEDENT


players = input ( ) NEW_LINE number = players [ 0 ] NEW_LINE counter = 0 NEW_LINE for i in players : NEW_LINE INDENT if ( number == i ) : NEW_LINE INDENT counter += 1 NEW_LINE DEDENT else : NEW_LINE INDENT number = i NEW_LINE counter = 1 NEW_LINE DEDENT if ( counter == 7 ) : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT if ( counter == 7 ) : NEW_LINE INDENT print ( " YES " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " NO " ) NEW_LINE DEDENT


n = input ( ) NEW_LINE if '1111111' in n or '0000000' in n : NEW_LINE INDENT print ( ' YES ' ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( ' NO ' ) NEW_LINE DEDENT


pos = input ( ) NEW_LINE if pos . find ( "0000000" ) != - 1 or pos . find ( "1111111" ) != - 1 : NEW_LINE INDENT print ( " YES " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " NO " ) NEW_LINE DEDENT


s = input ( ) NEW_LINE f = 0 NEW_LINE if '0000000' in s : NEW_LINE INDENT print ( ' YES ' ) NEW_LINE f = 1 NEW_LINE DEDENT if '1111111' in s : NEW_LINE INDENT print ( ' YES ' ) NEW_LINE f = 1 NEW_LINE DEDENT if f == 0 : NEW_LINE INDENT print ( ' NO ' ) NEW_LINE DEDENT


import java . util . Scanner ; public class FootBall { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String str = sc . next ( ) ; checkSituation ( str ) ; sc . close ( ) ; } private static void checkSituation ( String str ) { if ( str . contains ( "0000000" ) || str . contains ( "1111111" ) ) { System . out . println ( " YES " ) ; } else { System . out . println ( " NO " ) ; } } }


import java . util . Scanner ; public class Football { public static void main ( String [ ] args ) { try { Scanner sc = new Scanner ( System . in ) ; String str = sc . next ( ) ; sc . close ( ) ; if ( str . length ( ) <= 7 ) System . out . println ( " NO " ) ; else { String check1 = "1111111" ; String check2 = "0000000" ; if ( str . contains ( check1 ) || str . contains ( check2 ) ) System . out . println ( " YES " ) ; else System . out . println ( " NO " ) ; } } catch ( Exception e ) { return ; } } }


import java . util . * ; import java . io . * ; public class A_Football { static class FastReader { BufferedReader br ; StringTokenizer st ; public FastReader ( ) { br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; } String next ( ) { while ( st == null || ! st . hasMoreElements ( ) ) { try { st = new StringTokenizer ( br . readLine ( ) ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } return st . nextToken ( ) ; } int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } long nextLong ( ) { return Long . parseLong ( next ( ) ) ; } double nextDouble ( ) { return Double . parseDouble ( next ( ) ) ; } String nextLine ( ) { String str = " " ; try { str = br . readLine ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } return str ; } } public static void main ( String [ ] args ) { FastReader scan = new FastReader ( ) ; String str = scan . nextLine ( ) ; int countOne = 0 ; int countZero = 0 ; int i = 0 ; String output = " NO " ; while ( i < str . length ( ) ) { char ch = str . charAt ( i ) ; if ( ch == '1' ) { countOne ++ ; countZero = 0 ; if ( countOne == 7 ) { output = " YES " ; } } else { countZero ++ ; countOne = 0 ; if ( countZero == 7 ) { output = " YES " ; } } i ++ ; } System . out . println ( output ) ; } }


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

for t in range ( int ( input ( ) ) ) : n = int ( input ( ) ) NEW_LINE s = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE a = [ 0 ] * 102 NEW_LINE b = [ 0 ] * 102 NEW_LINE s . sort ( ) NEW_LINE for i in s : if NEW_LINE a [ i ] == 0 : a [ i ] += 1 else : b [ i ] += 1 NEW_LINE print ( a . index ( 0 ) + b . index ( 0 ) ) NEW_LINE


for _ in " ▁ " * int ( input ( ) ) : n = int ( input ( ) ) NEW_LINE lst = sorted ( list ( map ( int , input ( ) . split ( ) ) ) ) NEW_LINE a , b = 0 , 0 NEW_LINE for i in lst : if NEW_LINE a == i : a += 1 elif b == i : b += 1 NEW_LINE print ( a + b ) NEW_LINE


t = int ( input ( ) ) NEW_LINE def mex1 ( arr ) : i = 0 NEW_LINE while ( 1 ) : if NEW_LINE i not in arr : NEW_LINE return i else : i += 1 NEW_LINE def mex2 ( arr ) : i = 0 NEW_LINE while ( 1 ) : if NEW_LINE arr . count ( i ) < 2 : NEW_LINE return i else : i += 1   for _ in range ( t ) : n = int ( input ( ) ) NEW_LINE arr = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE if 0 not in arr : NEW_LINE INDENT print ( 0 ) elif arr . count ( 0 ) == 1 : NEW_LINE print ( mex1 ( arr ) ) else : NEW_LINE print ( mex1 ( arr ) + mex2 ( arr ) ) NEW_LINE DEDENT


cases = int ( input ( ) ) NEW_LINE while cases : cases -= 1 NEW_LINE num = int ( input ( ) ) NEW_LINE arr = list ( map ( int , input ( ) . split ( ) ) )   st1 = - 1 NEW_LINE st2 = - 1 NEW_LINE broken = False NEW_LINE for i in range ( 101 ) : if NEW_LINE i not in arr : NEW_LINE break else : if arr . count ( i ) > 1 and not broken : st1 += 1 NEW_LINE st2 += 1 else : st1 += 1 NEW_LINE broken = True   print ( 2 + st1 + st2 ) NEW_LINE


import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . math . BigInteger ; import java . util . * ; public class M { static Scanner scanner = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { int q = scanner . nextInt ( ) ; while ( q -- > 0 ) { int n = scanner . nextInt ( ) ; int a [ ] = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) a [ i ] = scanner . nextInt ( ) ; Arrays . sort ( a ) ; Set < Integer > set = new HashSet < Integer > ( ) ; Set < Integer > set2 = new HashSet < Integer > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( ! set . contains ( a [ i ] ) ) set . add ( a [ i ] ) ; else set2 . add ( a [ i ] ) ; } List < Integer > list = new ArrayList < Integer > ( ) ; list . addAll ( set ) ; Collections . sort ( list ) ; List < Integer > list2 = new ArrayList < Integer > ( ) ; list2 . addAll ( set2 ) ; Collections . sort ( list2 ) ; int x = - 1 , y = - 1 ; for ( int i : list ) { if ( i == x + 1 ) x = i ; else break ; } for ( int i : list2 ) { if ( i == y + 1 ) y = i ; else break ; }


import java . lang . * ; import java . util . * ;   public class Abhishek {   public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; int t = sc . nextInt ( ) ; while ( t -- > 0 ) { int n = sc . nextInt ( ) ; int [ ] a = new int [ 101 ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ sc . nextInt ( ) ] ++ ; } int mexA = - 1 , mexB = - 1 ; for ( int i = 0 ; i < a . length ; i ++ ) { if ( a [ i ] <= 1 && mexA == - 1 ) mexA = i ; if ( a [ i ] == 0 && mexB == - 1 ) mexB = i ; } System . out . println ( mexA + mexB ) ; }   } }


import java . math . BigInteger ; import java . util . * ;   public class Example { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ;   int t = sc . nextInt ( ) ; while ( t > 0 ) { int n = sc . nextInt ( ) ; int [ ] ans = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) {    ans [ i ] = sc . nextInt ( ) ; } int [ ] frq = new int [ 101 ] ; for ( int i = 0 ; i < ans . length ; i ++ ) { frq [ ans [ i ] ] ++ ;   } int c1 = - 1 ; int c2 = - 1 ; int aa = 0 ; boolean onetime = true ; boolean tt = false ; for ( int i = 0 ; i <= 100 ; i ++ ) {   if ( frq [ i ] >= 2 && onetime ) { c1 ++ ; c2 ++ ;    } else if ( frq [ i ] == 0 ) { tt = true ; if ( c1 == c2 ) { aa = 2 * i ; } else { aa = ++ c2 + ++ c1 ; } break ; } else if ( frq [ i ] >= 1 ) { c1 ++ ; onetime = false ; }   } if ( tt ) { System . out . println ( aa ) ; } else { System . out . println ( ++ c1 + ++ c2 ) ; } t -- ; } } }


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


import java . util . ArrayList ; import java . util . Arrays ; import java . util . Collections ; import java . util . List ; import java . util . Scanner ;   public class _0726Emotes {   public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int m = sc . nextInt ( ) ; int k = sc . nextInt ( ) ; List < Long > store = new ArrayList < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { store . add ( sc . nextLong ( ) ) ; } Collections . sort ( store ) ; long first = store . get ( store . size ( ) - 1 ) ; long second = store . get ( store . size ( ) - 2 ) ; System . out . println ( ( m / ( k + 1 ) ) * 1L * ( ( k * first ) + second ) + ( m % ( k + 1 ) * first ) ) ; }   }

n , m , k = map ( int , input ( ) . split ( ) ) r = lambda : list ( map ( int , input ( ) . split ( ) ) ) arr = r ( ) arr . sort ( reverse = True )   base = arr [ 0 ] * k + arr [ 1 ] t = m // ( k + 1 ) base = base * t   t = m % ( k + 1 ) base += t * arr [ 0 ]     print ( int ( base ) ) NEW_LINE


n , m , k = map ( int , input ( ) . split ( ) ) a = list ( map ( int , input ( ) . split ( ) ) ) a . sort ( reverse = True ) p = a [ 0 ] * k + a [ 1 ] ans = p * ( m // ( k + 1 ) ) + a [ 0 ] * ( m % ( k + 1 ) ) print ( ans ) NEW_LINE


n , m , k = map ( int , input ( ) . split ( ) )   emotes = [ int ( bruhh ) for bruhh in input ( ) . split ( ) ]   emotes . sort ( )   cycles = m // ( k + 1 ) leftover = m % ( k + 1 ) res = 0   res += ( ( k ) * emotes [ - 1 ] ) * ( cycles ) res += emotes [ - 2 ] * ( cycles )   res += emotes [ - 1 ] * leftover   print ( res )   NEW_LINE


n , m , k = map ( int , input ( ) . split ( ) ) a = sorted ( list ( map ( int , input ( ) . split ( ) ) ) ) ans = m // ( k + 1 ) * ( a [ - 1 ] * k + a [ - 2 ] ) + m % ( k + 1 ) * a [ - 1 ] print ( ans ) NEW_LINE


import java . util . * ;   public class Main { public static void main ( String [ ] args ) { int dis , step = 0 ; Scanner sc = new Scanner ( System . in ) ; dis = sc . nextInt ( ) ; if ( dis / 5 >= 1 ) { step = dis / 5 ; dis = dis % 5 ; } if ( dis / 4 >= 1 ) { step += dis / 4 ; dis = dis % 4 ; } if ( dis / 3 >= 1 ) { step += dis / 3 ; dis = dis % 3 ; } if ( dis / 2 >= 1 ) { step += dis / 2 ; dis = dis % 2 ; } step += dis ; System . out . println ( step ) ; } }

a = int ( input ( ) ) i = 0 while a > 5 : a = a - 5 i = i + 1 i = i + 1 print ( i ) NEW_LINE


x = int ( input ( ) ) print ( ( x + 4 ) // 5 ) NEW_LINE


a = int ( input ( " " ) ) if a % 5 == 0 : print ( a // 5 ) else : print ( a // 5 + 1 ) NEW_LINE


x = 0 z = int ( input ( ) ) while z > 0 : if z >= 5 : z = z - 5 x += 1 elif z >= 4 : z = z - 4 x += 1 elif z >= 3 : z = z - 3 x += 1 elif z >= 2 : z = z - 2 x += 1 elif z >= 1 : z = z - 1 x += 1 print ( x ) NEW_LINE


a = int ( input ( ) ) i = 0 while a > 5 : a = a - 5 i = i + 1 print ( i + 1 ) NEW_LINE


import java . util . Scanner ; public class Ex {   public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int n = in . nextInt ( ) , count = 0 ; while ( n != 0 ) { if ( n >= 5 ) { n = n - 5 ; count ++ ; } else { n = n - n ; count ++ ; } } System . out . println ( count ) ; } }


import java . util . Scanner ;   public class Elephant { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int n = scanner . nextInt ( ) ;   int res = 0 ; for ( int i = 5 ; i >= 1 ; i -- ) { res += n / i ; n = n % i ; }   System . out . println ( res ) ; } }


import java . util . Scanner ;   public class BigO {   public static void main ( String [ ] args ) { int x ;   Scanner sc = new Scanner ( System . in ) ; x = sc . nextInt ( ) ; int step = 1 ; while ( x > 5 ) { x -= 5 ; step ++ ; } System . out . println ( step ) ; } }


import java . io . OutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . PrintWriter ; import java . util . StringTokenizer ; import java . io . IOException ; 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 ; FastScanner in = new FastScanner ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; AElephant solver = new AElephant ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; }   static class AElephant { public void solve ( int testNumber , FastScanner fs , PrintWriter out ) { int x = fs . nextInt ( ) ; int ans = 0 ; for ( int i = 5 ; i >= 1 ; i -- ) { ans += x / i ; x = x % i ; } out . println ( ans ) ; }   }   static class FastScanner { BufferedReader br ; StringTokenizer st ;   public FastScanner ( InputStream inputStream ) { br = new BufferedReader ( new InputStreamReader ( inputStream ) ) ; }   public String next ( ) { while ( st == null || ! st . hasMoreElements ( ) ) { try { st = new StringTokenizer ( br . readLine ( ) ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } return st . nextToken ( ) ; }   public int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; }   } }


import java . io . BufferedReader ; import java . io . BufferedWriter ; import java . io . IOException ; import java . io . InputStreamReader ; import java . io . OutputStreamWriter ; import java . util . Stack ; import java . util . StringTokenizer ;    public class RedBlueBalls { public static void main ( String [ ] args ) throws IOException { MyScanner s = new MyScanner ( ) ; Print p = new Print ( ) ; int n = s . nextInt ( ) ; char [ ] att = s . nextLine ( ) . toCharArray ( ) ; Stack < Character > st = new Stack < > ( ) ; boolean ins = false ; for ( int i = 0 ; i < att . length ; i ++ ) { char ch = att [ att . length - 1 - i ] ; if ( ch == ' B ' ) ins = true ; if ( ins ) { st . push ( ch ) ; } } n = st . size ( ) ; long count = 0 ; for ( int i = 0 ; i < att . length ; i ++ ) { if ( att [ i ] == ' B ' ) { count += ( long ) Math . pow ( 2 , i ) ; } }

n = int ( input ( ) ) s = input ( ) tot = 0 for i , ball in enumerate ( s ) : if ball == ' B ' : tot += ( 1 << i ) print ( tot )   NEW_LINE


size = int ( input ( ) ) stack = list ( input ( ) )   print ( sum ( [ 2 ** i for i in range ( size ) if stack [ i ] == ' B ' ] ) ) NEW_LINE


length , string = int ( input ( ) ) , input ( ) print ( sum ( [ 2 ** i if string [ i ] == " B " else 0 for i in range ( len ( string ) ) ] ) ) NEW_LINE


input ( ) print ( int ( input ( ) . replace ( ' R ' , '0' ) . replace ( ' B ' , '1' ) [ : : - 1 ] , 2 ) ) NEW_LINE


import java . util . Scanner ;   public class B_RedAndBlueBalls {


import java . util . * ; public class Main { static long count = 0 ; public static void main ( String args [ ] ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; String s = sc . next ( ) ; count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( s . charAt ( i ) == ' B ' ) { count += ( long ) Math . pow ( 2 , i ) ; } } System . out . println ( count ) ; } }


import java . io . File ; import java . io . FileNotFoundException ; import java . io . IOException ; import java . io . PrintWriter ; import java . util . * ;   public class Main { public static void main ( String [ ] args ) { Scanner input = new Scanner ( System . in ) ; double x = input . nextDouble ( ) ; double y = input . nextDouble ( ) ; int n = input . nextInt ( ) ; double ans [ ] = new double [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { double Rr = input . nextDouble ( ) ; double Ry = input . nextDouble ( ) ; double speed = input . nextDouble ( ) ; double distance = Math . sqrt ( Math . pow ( x - Rr , 2 ) + Math . pow ( y - Ry , 2 ) ) ; ans [ i ] = distance / speed ; } Arrays . sort ( ans ) ; System . out . printf ( " % .6f \n " , ans [ 0 ] ) ; } }

import mathx1 , y1 = ( int ( x ) for x in input ( ) . split ( ) ) n = int ( input ( ) ) t = 10 ** 9 + 7 for _ in range ( n ) : x2 , y2 , v = ( int ( x ) for x in input ( ) . split ( ) ) if abs ( math . sqrt ( ( x2 - x1 ) ** 2 + ( y2 - y1 ) ** 2 ) ) / v < t : t = abs ( math . sqrt ( ( x2 - x1 ) ** 2 + ( y2 - y1 ) ** 2 ) ) / vprint ( t ) NEW_LINE


import mathc = input ( ) . split ( ) x1 , y1 = int ( c [ 0 ] ) , int ( c [ 1 ] ) n = int ( input ( ) ) d = [ ] for i in range ( n ) : c = [ int ( i ) for i in input ( ) . split ( ) ] distance = math . sqrt ( ( c [ 0 ] - x1 ) ** 2 + ( c [ 1 ] - y1 ) ** 2 ) / c [ 2 ] d . append ( distance ) print ( min ( d ) ) NEW_LINE


import ioimport osimport mathinput = io . BytesIO ( os . read ( 0 , os . fstat ( 0 ) . st_size ) ) . readline NEW_LINE


if __name__ == " _ _ main _ _ " : x , y = list ( map ( int , input ( ) . split ( ) ) ) n = int ( input ( ) ) m = n result = float ( ' inf ' ) while m : i , j , t = list ( map ( int , input ( ) . split ( ) ) ) result = min ( result , ( ( ( x - i ) ** 2 + ( y - j ) ** 2 ) ** 0.5 ) / t ) m = m - 1 print ( round ( result , 7 ) )         NEW_LINE


import matha , b = ( int ( x ) for x in input ( ) . split ( ) ) best = float ( ' INF ' ) for _ in range ( int ( input ( ) ) ) : x , y , v = ( int ( x ) for x in input ( ) . split ( ) ) best = min ( best , ( math . sqrt ( ( a - x ) ** 2 + ( b - y ) ** 2 ) ) / v ) print ( best ) NEW_LINE


import java . util . Scanner ;   public class BeruTaxi { public static void main ( String [ ] args ) {   Scanner in = new Scanner ( System . in ) ; int a = in . nextInt ( ) , b = in . nextInt ( ) , n = in . nextInt ( ) , i ; double o = Double . MAX_VALUE ;   for ( i = 0 ; i < n ; i ++ ) { int x = in . nextInt ( ) , y = in . nextInt ( ) , v = in . nextInt ( ) ; double d = Math . sqrt ( Math . pow ( x - a , 2 ) + Math . pow ( y - b , 2 ) ) ; o = Math . min ( o , d / v ) ; } in . close ( ) ; System . out . println ( o ) ; } }


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


import java . util . * ; import java . util . stream . * ;   public class Solution { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int a = scan . nextInt ( ) ; int b = scan . nextInt ( ) ; int n = scan . nextInt ( ) ; double minT = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int x = scan . nextInt ( ) ; int y = scan . nextInt ( ) ; int v = scan . nextInt ( ) ; double s = Math . sqrt ( ( x - a ) * ( x - a ) + ( y - b ) * ( y - b ) ) ; double t = s / v ; if ( i == 0 ) { minT = t ; } else { minT = Math . min ( t , minT ) ; } } System . out . println ( minT ) ; } }


import java . util . Scanner ;   public class Main { public static void main ( String [ ] args ) { Scanner x = new Scanner ( System . in ) ; int n = x . nextInt ( ) ; int a = x . nextInt ( ) ; int b = x . nextInt ( ) ; int y = ( ( a - 1 + b ) % n + n ) % n + 1 ; System . out . println ( y ) ; } }

n , a , b = map ( int , input ( ) . split ( ) ) if b < 0 : for x in range ( abs ( b ) ) : if a != 1 : a -= 1 else : a = nelif b >= 0 : for y in range ( b ) : if a == n : a = 1 else : a += 1   print ( a ) NEW_LINE


import mathdef solve ( n , a , b ) : if b < 0 : res = ( n - ( - 1 * b % n ) ) + a else : res = b % n + a return res if res <= n else res - n   def main ( ) : arr = list ( map ( int , input ( ) . split ( ' ▁ ' ) ) ) NEW_LINE


n , a , b = map ( int , input ( ) . split ( ) )   if b > 0 : for i in range ( b ) : a += 1   if a == n + 1 : a = 1 else : for i in range ( abs ( b ) ) : a -= 1   if a == 0 : a = n   print ( a ) NEW_LINE


n , a , b = map ( int , input ( ) . split ( ) )   s = 0 drctn = 1 if b >= 0 else - 1 while s < abs ( b ) : a += 1 * drctn s += 1   if a > n : a = 1 elif a <= 0 : a = n   print ( a ) NEW_LINE


I = lambda : map ( int , input ( ) . split ( ) ) INT = lambda : int ( input ( ) )   NEW_LINE


import java . util . Scanner ;   public class Main { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int n = in . nextInt ( ) ; int a = in . nextInt ( ) ; int b = in . nextInt ( ) ; if ( b > 0 ) { System . out . println ( ( a + b % n - 1 ) % n + 1 ) ; } else { System . out . println ( ( a + n - ( - b % n ) - 1 ) % n + 1 ) ; } } }


import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . StringTokenizer ;   public class RoundHouse { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; StringTokenizer st = new StringTokenizer ( br . readLine ( ) ) ;   int n = Integer . parseInt ( st . nextToken ( ) ) ; int a = Integer . parseInt ( st . nextToken ( ) ) - 1 ; int b = Integer . parseInt ( st . nextToken ( ) ) ;   if ( b < 0 ) { b = Math . abs ( b ) ; b %= n ; a -= b ; if ( a < 0 ) a += n ; } else { b %= n ; a += b ; a %= n ; }   System . out . println ( a + 1 ) ; } }


import java . util . * ;   public class Absolutezero {     public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ;   int c = Math . abs ( b ) ; c = c % n ; if ( b < 0 ) { c = - c ; } if ( c < 0 ) { c = n - Math . abs ( c ) ; int d = a - 1 ; int f = Math . abs ( c ) ; f = f + d + 1 ; if ( f > n ) { f = f - n ; } System . out . println ( f ) ; } else if ( c > 0 ) { int d = a - 1 ; int f = Math . abs ( c ) ; f = f + d + 1 ; if ( f > n ) { f = f - n ; } System . out . println ( f ) ; } else { System . out . println ( a ) ; }   }       }


import java . util . Scanner ;   public class _0671RoundHouse {   public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; System . out . println ( ( ( a - 1 + b ) % n + n ) % n + 1 ) ; }   }


import java . math . BigInteger ; import java . util . Scanner ;   public class Practice { public static void main ( String [ ] args ) { Scanner input = new Scanner ( System . in ) ; int n = input . nextInt ( ) ; BigInteger a = new BigInteger ( "3" ) . pow ( 3 * n ) ; a = a . subtract ( new BigInteger ( "7" ) . pow ( n ) ) ; System . out . println ( a . mod ( new BigInteger ( "1000000007" ) ) ) ; } }

n = int ( input ( ) ) first = 3 ** ( 3 * n ) second = 7 ** nmod = 1000000007 print ( ( first - second ) % mod ) NEW_LINE


from sys import stdin , stdoutnmbr = lambda : int ( input ( ) ) lst = lambda : list ( map ( int , input ( ) . split ( ) ) ) N = 10 ** 5 + 5 M = 10 ** 9 + 7 p3 = [ 1 ] p7 = [ 1 ] for i in range ( 3 * N ) : p3 += [ ( p3 [ - 1 ] * 3 ) % M ] for i in range ( N ) : p7 += [ ( p7 [ - 1 ] * 7 ) % M ] for _ in range ( 1 ) : NEW_LINE


import sysfrom math import * from itertools import product   def ints_input ( ) : return [ int ( i ) for i in sys . stdin . readline ( ) . strip ( " \n " ) . split ( " ▁ " ) ]     def print_list ( arr ) : sys . stdout . writelines ( str ( x ) + " ▁ " for x in arr ) sys . stdout . write ( " \n " )     def fast_input ( type = str ) : return type ( sys . stdin . readline ( ) . strip ( " \n " ) ) n = fast_input ( int ) print ( int ( ( 3 ** ( 3 * n ) - 7 ** n ) % ( 10 ** 9 + 7 ) ) ) NEW_LINE


n = int ( input ( ) ) MOD = 1000000007 print ( ( pow ( 3 , 3 * n ) - pow ( 7 , n ) ) % MOD ) NEW_LINE


import java . util . Scanner ;   public class Practice { public static void main ( String [ ] args ) { Scanner input = new Scanner ( System . in ) ; long n = input . nextLong ( ) ; long a = 1 , b = 1 , mod = ( long ) ( 1E9 ) + 7 ; for ( int i = 0 ; i < 3 * n ; i ++ ) { a = ( a * 3 ) % mod ; } for ( int i = 0 ; i < n ; i ++ ) b = ( b * 7 ) % mod ; System . out . println ( ( a - b + mod ) % mod ) ; } }


import java . util . Scanner ;   public class CF584_D2_B { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int n = scanner . nextInt ( ) * 3 ; long ans = 1 ; for ( int i = 1 ; i <= n ; i ++ ) { ans *= 3 ; ans = ans % 1000000007 ; } long m = 1 ; for ( int i = 0 ; i < n / 3 ; i ++ ) { m *= 7 ; m = m % 1000000007 ; } System . out . println ( ( ans - m + 1000000007 ) % 1000000007 ) ; } }


import java . io . * ; import java . util . * ; import java . lang . * ;   public class Main {   public static void main ( String [ ] args ) { FastReader in = new FastReader ( ) ; PrintWriter out = new PrintWriter ( System . out ) ; int n = in . nextInt ( ) ; int MOD = ( int ) ( 1e9 + 7 ) ; long ans = 1 ; long diff = 1 ; for ( int i = 0 ; i < n ; i ++ ) { ans = ans * 27 ; diff = diff * 7 ; ans = ( ans ) % MOD ; diff = ( diff ) % MOD ; } ans = ans - diff ; if ( ans < 0 ) ans += MOD ; out . println ( ans ) ; out . close ( ) ; }   static final Random random = new Random ( ) ;


import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . * ;   public class CF1422_D2_B { public static void main ( String [ ] args ) { FastScanner scanner = new FastScanner ( ) ; int t = scanner . nextInt ( ) ; for ( int i = 0 ; i < t ; i ++ ) { solve ( scanner ) ; }   }   private static void solve ( FastScanner scanner ) { int n = scanner . nextInt ( ) ; int m = scanner . nextInt ( ) ; int [ ] [ ] matrix = new int [ n ] [ m ] ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < m ; j ++ ) { int x = scanner . nextInt ( ) ; matrix [ i ] [ j ] = x ; } } long count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < m ; j ++ ) { int [ ] arr = { matrix [ i ] [ j ] , matrix [ n - i - 1 ] [ j ] , matrix [ i ] [ m - j - 1 ] , matrix [ n - i - 1 ] [ m - j - 1 ] } ; Arrays . sort ( arr ) ; long mid = 0 ; mid += ( arr [ 1 ] + arr [ 2 ] ) / 2 ; for ( int value : arr ) { count += Math . abs ( mid - value ) ; } } } System . out . println ( count / 4 ) ;

p = lambda : list ( map ( int , input ( ) . split ( ) ) )     T = int ( input ( ) ) NEW_LINE for _ in range ( T ) : N , M = p ( ) ; S = 0 NEW_LINE a = [ p ( ) for _ in range ( N ) ] NEW_LINE for i in range ( N // 2 ) : for NEW_LINE j in range ( M // 2 ) : x , y = N - i - 1 , M - j - 1 NEW_LINE l = sorted ( [ a [ i ] [ j ] , a [ i ] [ y ] , a [ x ] [ j ] , a [ x ] [ y ] ] ) NEW_LINE changeTo = round ( ( l [ 2 ] + l [ 1 ] ) / 2 ) NEW_LINE


for _ in range ( int ( input ( ) ) ) : n , m = map ( int , input ( ) . split ( ) ) NEW_LINE s = [ ] NEW_LINE for x in range ( n ) : k = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE s . append ( k ) NEW_LINE ans = 0 NEW_LINE for i in range ( n ) : for NEW_LINE j in range ( m ) : b = [ ] NEW_LINE b . append ( s [ i ] [ j ] ) NEW_LINE b . append ( s [ n - i - 1 ] [ j ] ) NEW_LINE b . append ( s [ i ] [ m - j - 1 ] ) NEW_LINE b . sort ( ) NEW_LINE s [ i ] [ j ] = s [ n - i - 1 ] [ j ] = s [ i ] [ m - j - 1 ] = b [ 1 ] NEW_LINE ans += int ( b [ 1 ] ) - int ( b [ 0 ] ) NEW_LINE ans += int ( b [ - 1 ] ) - int ( b [ 1 ] ) NEW_LINE print ( ans ) NEW_LINE


t = int ( input ( ) ) NEW_LINE for q in range ( t ) : n , m = map ( int , input ( ) . split ( ) ) NEW_LINE a = n * [ [ 0 for i in range ( m ) ] ] NEW_LINE for i in range ( n ) : a [ i ] = [ int ( x ) for x in input ( ) . split ( ) ] NEW_LINE ans = 0 NEW_LINE for i in range ( ( n + 1 ) // 2 ) : for NEW_LINE j in range ( ( m + 1 ) // 2 ) : NEW_LINE if i == n - 1 - i : NEW_LINE INDENT x = [ a [ i ] [ j ] , a [ i ] [ m - 1 - j ] ] elif j == m - 1 - j : NEW_LINE x = [ a [ i ] [ j ] , a [ n - 1 - i ] [ j ] ] else : NEW_LINE x = [ a [ i ] [ j ] , a [ n - 1 - i ] [ j ] , a [ i ] [ m - 1 - j ] , a [ n - 1 - i ] [ m - 1 - j ] ] NEW_LINE DEDENT x = sorted ( x ) NEW_LINE ans += min ( sum ( [ abs ( v - x [ int ( len ( x ) / 2 ) - 1 ] ) for v in x ] ) , sum ( [ abs ( v - x [ int ( len ( x ) / 2 ) ] ) for v in x ] ) ) NEW_LINE print ( ans ) NEW_LINE


for _ in range ( int ( input ( ) ) ) : n , m = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE mat = [ ] NEW_LINE value = 0 NEW_LINE for i in range ( n ) : mat . append ( list ( map ( int , input ( ) . split ( ) ) ) ) NEW_LINE for i in range ( n ) : for NEW_LINE j in range ( m ) : a = list ( sorted ( [ mat [ i ] [ j ] , mat [ n - i - 1 ] [ j ] , mat [ i ] [ m - j - 1 ] , mat [ n - i - 1 ] [ m - j - 1 ] ] ) ) NEW_LINE value += ( a [ 1 ] - a [ 0 ] ) + ( a [ 2 ] - a [ 1 ] ) + ( a [ 3 ] - a [ 1 ] )     print ( value // 4 ) NEW_LINE