import java . util . ArrayList ; import java . util . Collections ; import java . util . List ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { new Main ( ) . solveA ( ) ; } private void solveA ( ) { try ( Scanner sc = new Scanner ( System . in ) ; ) { List < Integer > list = new ArrayList < > ( ) ; int N = sc . nextInt ( ) ; for ( int i = 0 ; i < N ; i ++ ) { list . add ( sc . nextInt ( ) ) ; } List < Integer > sortedList = new ArrayList < > ( list ) ; Collections . sort ( sortedList ) ; int median = sortedList . get ( N / 2 ) ; int medianMinus = sortedList . get ( N / 2 - 1 ) ; for ( int i : list ) { if ( i >= median ) { System . out . println ( medianMinus ) ; } else { System . out . println ( median ) ; } } } } }

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 . IOException ; import java . util . InputMismatchException ; 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 ; InputReader in = new InputReader ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; TaskC solver = new TaskC ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class TaskC { public void solve ( int testNumber , InputReader in , PrintWriter out ) { int n = in . nextInt ( ) ; int [ ] a = in . nextIntArray ( n ) ; int [ ] b = a . clone ( ) ; Arrays . sort ( b ) ; int mid = b [ ( b . length - 1 ) / 2 ] ; for ( int i = 0 ; i < n ; i ++ ) { if ( a [ i ] <= mid ) { out . println ( b [ ( b . length + 1 ) / 2 ] ) ; } else { out . println ( mid ) ; } } } } static class InputReader { BufferedReader in ; StringTokenizer tok ; public String nextString ( ) { while ( ! tok . hasMoreTokens ( ) ) { try { tok = new StringTokenizer ( in . readLine ( ) , " ▁ " ) ; } catch ( IOException e ) { throw new InputMismatchException ( ) ; } } return tok . nextToken ( ) ; } public int nextInt ( ) { return Integer . parseInt ( nextString ( ) ) ; } public int [ ] nextIntArray ( int n ) { int [ ] res = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { res [ i ] = nextInt ( ) ; } return res ; } public InputReader ( InputStream inputStream ) { in = new BufferedReader ( new InputStreamReader ( inputStream ) ) ; tok = new StringTokenizer ( " " ) ; } } }

import static java . lang . System . * ; import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( in ) ; int n = sc . nextInt ( ) ; int [ ] num = new int [ n ] ; int [ ] num_org = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) num [ i ] = num_org [ i ] = sc . nextInt ( ) ; Arrays . sort ( num ) ; int mid_s = num [ n / 2 - 1 ] ; int mid_l = num [ n / 2 ] ; for ( int i : num_org ) { if ( i <= mid_s ) out . println ( mid_l ) ; else out . println ( mid_s ) ; } return ; } }

import java . io . BufferedInputStream ; import java . util . ArrayList ; import java . util . Collections ; import java . util . List ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { new Main ( ) . solveA ( ) ; } private void solveB ( ) { try ( Scanner sc = new Scanner ( System . in ) ; ) { } } private void solveA ( ) { try ( Scanner sc = new Scanner ( new BufferedInputStream ( System . in , 8096 ) ) ; ) { List < Integer > list = new ArrayList < > ( ) ; int N = sc . nextInt ( ) ; for ( int i = 0 ; i < N ; i ++ ) { list . add ( sc . nextInt ( ) ) ; } List < Integer > sortedList = new ArrayList < > ( list ) ; Collections . sort ( sortedList ) ; int median = sortedList . get ( N / 2 ) ; int medianMinus = sortedList . get ( N / 2 - 1 ) ; for ( int i : list ) { if ( i >= median ) { System . out . println ( medianMinus ) ; } else { System . out . println ( median ) ; } } } } }

import java . util . * ; import java . io . * ; import static java . lang . System . in ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader reader = new BufferedReader ( new InputStreamReader ( in ) ) ; String temp ; String [ ] buf ; temp = reader . readLine ( ) ; int N = Integer . parseInt ( temp . split ( " ▁ " ) [ 0 ] ) ; int [ ] a = new int [ N ] , sorted = new int [ N ] ; temp = reader . readLine ( ) ; buf = temp . split ( " ▁ " ) ; for ( int i = 0 ; i < N ; i ++ ) { int cur = Integer . parseInt ( buf [ i ] ) ; a [ i ] = cur ; sorted [ i ] = cur ; } Arrays . sort ( sorted ) ; int smaller = sorted [ N / 2 - 1 ] , bigger = sorted [ N / 2 ] ; PrintWriter out = new PrintWriter ( System . out ) ; int ans = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( a [ i ] <= smaller ) ans = bigger ; else ans = smaller ; out . println ( ans ) ; } out . flush ( ) ; } }

from collections import Counter NEW_LINE N = int ( input ( ) ) NEW_LINE X = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE Y = sorted ( X ) NEW_LINE a = Y [ N // 2 ] NEW_LINE b = Y [ N // 2 - 1 ] NEW_LINE for i in X : NEW_LINE INDENT if i <= b : NEW_LINE INDENT print ( a ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( b ) NEW_LINE DEDENT DEDENT

def solve ( N , Xs ) : NEW_LINE INDENT sorted_Xs = sorted ( Xs ) NEW_LINE left = sorted_Xs [ N // 2 - 1 ] NEW_LINE right = sorted_Xs [ N // 2 ] NEW_LINE ans = [ ] NEW_LINE for x in Xs : NEW_LINE INDENT if x <= left : NEW_LINE INDENT ans . append ( right ) NEW_LINE DEDENT else : NEW_LINE INDENT ans . append ( left ) NEW_LINE DEDENT DEDENT return " \n " . join ( str ( i ) for i in ans ) NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT N = int ( input ( ) ) NEW_LINE Xs = list ( map ( int , input ( ) . split ( " ▁ " ) ) ) NEW_LINE print ( solve ( N , Xs ) ) NEW_LINE DEDENT

import bisect NEW_LINE N = int ( input ( ) ) NEW_LINE X = [ int ( x ) for x in input ( ) . split ( ) ] NEW_LINE X2 = sorted ( X ) NEW_LINE for i in range ( 0 , N ) : NEW_LINE INDENT idx = bisect . bisect_left ( X2 , X [ i ] ) NEW_LINE if idx < N // 2 : NEW_LINE INDENT print ( X2 [ N // 2 ] ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( X2 [ N // 2 - 1 ] ) NEW_LINE DEDENT DEDENT

n , * a = map ( int , open ( 0 ) . read ( ) . split ( ) ) NEW_LINE d = 0 NEW_LINE l = [ ] NEW_LINE a = sorted ( enumerate ( a ) , key = lambda x : x [ 1 ] ) NEW_LINE b = a [ n // 2 ] [ 1 ] NEW_LINE c = a [ n // 2 - 1 ] [ 1 ] NEW_LINE for ( k , v ) in a : NEW_LINE INDENT d += 1 NEW_LINE if d < n // 2 + 1 : NEW_LINE INDENT l . append ( ( k , b ) ) NEW_LINE DEDENT else : NEW_LINE INDENT l . append ( ( k , c ) ) NEW_LINE DEDENT DEDENT for ( k , v ) in sorted ( l , key = lambda x : x [ 0 ] ) : NEW_LINE INDENT print ( v ) NEW_LINE DEDENT

n = int ( input ( ) ) NEW_LINE xs = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE ds = sorted ( xs ) NEW_LINE m = n // 2 - 1 NEW_LINE bs = [ ds [ m ] if xs [ i ] > ds [ m ] else ds [ m + 1 ] for i in range ( n ) ] NEW_LINE print ( " \n " . join ( map ( str , bs ) ) ) NEW_LINE


import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String S = sc . next ( ) ; System . out . println ( S . replace ( " O " , "0" ) . replaceAll ( " D " , "0" ) . replaceAll ( " I " , "1" ) . replaceAll ( " Z " , "2" ) . replaceAll ( " S " , "5" ) . replaceAll ( " B " , "8" ) ) ; } }

import java . util . * ; public class Main { private static String s ; public static void input ( ) { Scanner scan = new Scanner ( System . in ) ; s = scan . next ( ) ; } public static void main ( String args [ ] ) { input ( ) ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { switch ( s . charAt ( i ) ) { case ' O ' : s = s . replace ( ' O ' , '0' ) ; break ; case ' D ' : s = s . replace ( ' D ' , '0' ) ; break ; case ' I ' : s = s . replace ( ' I ' , '1' ) ; break ; case ' Z ' : s = s . replace ( ' Z ' , '2' ) ; break ; case ' S ' : s = s . replace ( ' S ' , '5' ) ; break ; case ' B ' : s = s . replace ( ' B ' , '8' ) ; break ; default : break ; } } System . out . println ( s ) ; } }

import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; HashMap < Character , Integer > map = new HashMap < > ( ) ; map . put ( ' O ' , 0 ) ; map . put ( ' D ' , 0 ) ; map . put ( ' I ' , 1 ) ; map . put ( ' Z ' , 2 ) ; map . put ( ' S ' , 5 ) ; map . put ( ' B ' , 8 ) ; String str = in . next ( ) ; for ( char c : str . toCharArray ( ) ) { System . out . print ( map . containsKey ( c ) ? map . get ( c ) . toString ( ) : c ) ; } System . out . println ( ) ; } }

import java . util . Scanner ; import java . util . Arrays ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; String S = scanner . next ( ) ; char [ ] c = new char [ S . length ( ) ] ; for ( int i = 0 ; i < S . length ( ) ; i ++ ) { c [ i ] = S . charAt ( i ) ; if ( c [ i ] == ' O ' ) { System . out . print ( '0' ) ; } else if ( c [ i ] == ' D ' ) { System . out . print ( '0' ) ; } else if ( c [ i ] == ' I ' ) { System . out . print ( '1' ) ; } else if ( c [ i ] == ' Z ' ) { System . out . print ( '2' ) ; } else if ( c [ i ] == ' S ' ) { System . out . print ( '5' ) ; } else if ( c [ i ] == ' B ' ) { System . out . print ( '8' ) ; } else { System . out . print ( c [ i ] ) ; } } System . out . println ( ) ; } }

import java . util . * ; import static java . lang . System . * ; import static java . lang . Math . * ; public class Main { public static void main ( String [ ] $ ) { Scanner sc = new Scanner ( in ) ; String s = sc . next ( ) ; String [ ] b = { " O " , " D " , " I " , " Z " , " S " , " B " } ; String [ ] a = { "0" , "0" , "1" , "2" , "5" , "8" } ; for ( int i = 0 ; i < b . length ; i ++ ) { s = s . replaceAll ( b [ i ] , a [ i ] ) ; } out . println ( s ) ; } }

import sys NEW_LINE sys . setrecursionlimit ( 10 ** 9 ) NEW_LINE input = sys . stdin . readline NEW_LINE d = dict ( ) NEW_LINE d [ ' O ' ] = '0' NEW_LINE d [ ' D ' ] = '0' NEW_LINE d [ ' I ' ] = '1' NEW_LINE d [ ' Z ' ] = '2' NEW_LINE d [ ' S ' ] = '5' NEW_LINE d [ ' B ' ] = '8' NEW_LINE s = input ( ) NEW_LINE ans = ' ' NEW_LINE for c in s [ : - 1 ] : NEW_LINE INDENT if ord ( '0' ) <= ord ( c ) <= ord ( '9' ) : NEW_LINE INDENT ans += c NEW_LINE DEDENT else : NEW_LINE INDENT ans += d [ c ] NEW_LINE DEDENT DEDENT print ( ans ) NEW_LINE

S = str ( input ( ) ) NEW_LINE S = list ( S ) NEW_LINE for i in range ( len ( S ) ) : NEW_LINE INDENT if S [ i ] == " O " or S [ i ] == " D " : NEW_LINE INDENT S [ i ] = '0' NEW_LINE DEDENT elif S [ i ] == " I " : NEW_LINE INDENT S [ i ] = '1' NEW_LINE DEDENT elif S [ i ] == " Z " : NEW_LINE INDENT S [ i ] = '2' NEW_LINE DEDENT elif S [ i ] == " S " : NEW_LINE INDENT S [ i ] = '5' NEW_LINE DEDENT elif S [ i ] == " B " : NEW_LINE INDENT S [ i ] = '8' NEW_LINE DEDENT DEDENT ans = " " NEW_LINE for i in range ( len ( S ) ) : NEW_LINE INDENT ans += S [ i ] NEW_LINE DEDENT print ( ans ) NEW_LINE

def main ( ) : NEW_LINE INDENT chars = { " O " : "0" , " D " : "0" , " I " : "1" , " Z " : "2" , " S " : "5" , " B " : "8" } NEW_LINE s = input ( ) NEW_LINE for k , v in chars . items ( ) : NEW_LINE INDENT s = s . replace ( k , v ) NEW_LINE DEDENT print ( s ) NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT main ( ) NEW_LINE DEDENT

def ans ( ) : NEW_LINE INDENT S = input ( ) NEW_LINE res = " " NEW_LINE for s in S : NEW_LINE INDENT if ( s == " O " or s == " D " ) : NEW_LINE INDENT res += "0" NEW_LINE DEDENT elif ( s == " I " ) : NEW_LINE INDENT res += "1" NEW_LINE DEDENT elif ( s == " Z " ) : NEW_LINE INDENT res += "2" NEW_LINE DEDENT elif ( s == " S " ) : NEW_LINE INDENT res += "5" NEW_LINE DEDENT elif ( s == " B " ) : NEW_LINE INDENT res += "8" NEW_LINE DEDENT else : NEW_LINE INDENT res += s NEW_LINE DEDENT DEDENT print ( res ) NEW_LINE DEDENT ans ( ) NEW_LINE


import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int cnt = 0 ; for ( int i = a ; i <= b ; i ++ ) { int fi = i / 10000 ; int on = i % 10 ; int fo = i / 1000 % 10 ; int tw = i % 100 / 10 ; if ( fi == on && fo == tw ) { cnt ++ ; } } System . out . println ( cnt ) ; } }

import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int s = sc . nextInt ( ) ; int e = sc . nextInt ( ) ; int cnt = 0 ; for ( int i = s ; i <= e ; i ++ ) { int rev = getRev ( i ) ; if ( i == rev ) { cnt ++ ; } } System . out . println ( cnt ) ; } public static int getRev ( int i ) { int ic = 0 ; while ( i > 0 ) { ic = ic * 10 + i % 10 ; i /= 10 ; } return ic ; } }

import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner reader = new Scanner ( System . in ) ; String strA = reader . next ( ) ; int [ ] A = new int [ 5 ] ; String strB = reader . next ( ) ; int [ ] B = new int [ 5 ] ; for ( int i = 0 ; i < 5 ; i ++ ) { A [ i ] = Character . getNumericValue ( strA . charAt ( i ) ) ; B [ i ] = Character . getNumericValue ( strB . charAt ( i ) ) ; } int ans = 0 ; int [ ] C = new int [ 5 ] ; C [ 0 ] = B [ 0 ] - A [ 0 ] ; if ( C [ 0 ] == 0 ) { C [ 1 ] = B [ 1 ] - A [ 1 ] - 1 ; } else { C [ 1 ] = 10 ; } if ( C [ 1 ] == 0 ) { C [ 2 ] = B [ 2 ] - A [ 2 ] - 1 ; } else { C [ 2 ] = 10 ; } ans = C [ 0 ] * C [ 1 ] * C [ 2 ] ; int intA = Integer . parseInt ( strA ) ; int below = 0 ; for ( int i = A [ 0 ] * 10000 ; i < intA ; i ++ ) { int n1 = i / 10000 ; int n2 = i % 10000 / 1000 ; int n4 = i % 100 / 10 ; int n5 = i % 10 ; if ( n1 == n5 && n2 == n4 ) { below ++ ; } } int intB = Integer . parseInt ( strB ) ; int above = 0 ; for ( int i = B [ 0 ] * 10000 ; i <= intB ; i ++ ) { int n1 = i / 10000 ; int n2 = i % 10000 / 1000 ; int n4 = i % 100 / 10 ; int n5 = i % 10 ; if ( n1 == n5 && n2 == n4 ) { above ++ ; } } System . out . println ( ans - below + above ) ; reader . close ( ) ; } }

import java . io . * ; import java . util . * ; import java . util . stream . * ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader stdin = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int [ ] input = Arrays . stream ( stdin . readLine ( ) . split ( " ▁ " ) ) . mapToInt ( Integer :: parseInt ) . toArray ( ) ; long ans = IntStream . rangeClosed ( input [ 0 ] , input [ 1 ] ) . mapToObj ( String :: valueOf ) . filter ( s -> s . equals ( ( new StringBuilder ( s ) ) . reverse ( ) . toString ( ) ) ) . count ( ) ; System . out . println ( ans ) ; } }

import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . util . StringTokenizer ; public class Main { public static void main ( String [ ] args ) throws Exception { BufferedReader input = new BufferedReader ( new InputStreamReader ( System . in ) ) ; StringTokenizer tokenizer = new StringTokenizer ( input . readLine ( ) ) ; int a = Integer . parseInt ( tokenizer . nextToken ( ) ) ; int b = Integer . parseInt ( tokenizer . nextToken ( ) ) ; int count = 0 ; for ( int i = a ; i <= b ; i ++ ) { if ( isBlandrome ( i ) ) count ++ ; } System . out . println ( count ) ; } public static boolean isBlandrome ( int n ) { int copy = n ; int newN = 0 ; while ( n > 9 ) { newN = newN * 10 + ( n % 10 ) ; n /= 10 ; } if ( n > 0 ) { newN = newN * 10 + ( n % 10 ) ; } return newN == copy ; } }

def p ( a , b ) : NEW_LINE INDENT count = 0 NEW_LINE for i in range ( a , b + 1 ) : NEW_LINE INDENT si = str ( i ) NEW_LINE if si [ 0 ] == si [ - 1 ] and si [ 1 ] == si [ - 2 ] : NEW_LINE INDENT count += 1 NEW_LINE DEDENT DEDENT return count NEW_LINE DEDENT n , m = map ( int , input ( ) . split ( ) ) NEW_LINE print ( p ( n , m ) ) NEW_LINE

A , B = map ( int , input ( ) . split ( ) ) NEW_LINE lists = list ( range ( A , B + 1 ) ) NEW_LINE str_lists = list ( str ( lists [ 0 ] ) ) NEW_LINE kaibun_lists = [ ] NEW_LINE for i in range ( len ( lists ) ) : NEW_LINE INDENT for j in range ( len ( list ( str ( lists [ i ] ) ) ) ) : NEW_LINE INDENT kaibun = str ( lists [ i ] ) [ : : - 1 ] NEW_LINE DEDENT if lists [ i ] == int ( kaibun ) : NEW_LINE INDENT kaibun_lists . append ( int ( kaibun ) ) NEW_LINE DEDENT DEDENT print ( len ( kaibun_lists ) ) NEW_LINE

def check ( s ) : NEW_LINE INDENT s = str ( s ) NEW_LINE if s == s [ : : - 1 ] : NEW_LINE INDENT return True NEW_LINE DEDENT else : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT cnt = 0 NEW_LINE a , b = map ( int , input ( ) . split ( ) ) NEW_LINE for i in range ( a , b + 1 ) : NEW_LINE INDENT if check ( i ) : NEW_LINE INDENT cnt += 1 NEW_LINE DEDENT DEDENT print ( cnt ) NEW_LINE

a , b = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE num = [ ] NEW_LINE for n in range ( a , b + 1 ) : NEW_LINE INDENT num . append ( str ( n ) ) NEW_LINE DEDENT count = 0 NEW_LINE for i in range ( len ( num ) ) : NEW_LINE INDENT hantei = 0 NEW_LINE for j in range ( len ( num [ i ] ) // 2 ) : NEW_LINE INDENT if num [ i ] [ j ] == num [ i ] [ - ( j + 1 ) ] : NEW_LINE INDENT hantei += 1 NEW_LINE DEDENT DEDENT if hantei == len ( num [ i ] ) // 2 : NEW_LINE INDENT count += 1 NEW_LINE DEDENT DEDENT print ( count ) NEW_LINE

a , b = map ( int , input ( ) . split ( ) ) NEW_LINE ans = 0 NEW_LINE for i in range ( a , b + 1 ) : NEW_LINE INDENT tmp = str ( i ) NEW_LINE if tmp [ 0 ] == tmp [ - 1 ] and tmp [ 1 ] == tmp [ - 2 ] : NEW_LINE INDENT ans += 1 NEW_LINE DEDENT DEDENT print ( ans ) NEW_LINE


import java . util . * ; import java . lang . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; int k = sc . nextInt ( ) ; Set < String > set = new TreeSet < > ( ) ; for ( int i = 0 ; i + k <= s . length ( ) ; i ++ ) { set . add ( s . substring ( i , i + k ) ) ; } System . out . println ( set . size ( ) ) ; } }

import java . util . * ; class Main { public static void main ( String [ ] args ) { new Main ( ) . main ( ) ; } public void main ( ) { Scanner scanner = new Scanner ( System . in ) ; String s = scanner . nextLine ( ) ; int k = Integer . parseInt ( scanner . nextLine ( ) ) ; String [ ] memory = new String [ s . length ( ) ] ; int memorySize = 0 ; for ( int i = 0 ; i <= s . length ( ) - k ; i ++ ) { String sub = s . substring ( i , i + k ) ; if ( ! this . includes ( memory , memorySize , sub ) ) { memory [ memorySize ] = sub ; memorySize ++ ; } } System . out . println ( memorySize ) ; } private boolean includes ( String [ ] arr , int n , String s ) { for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] . equals ( s ) ) { return true ; } } return false ; } }

import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; int k = sc . nextInt ( ) ; if ( s . length ( ) < k ) { System . out . println ( 0 ) ; return ; } String [ ] words = new String [ s . length ( ) - k + 1 ] ; for ( int i = 0 ; i < words . length ; i ++ ) { words [ i ] = s . substring ( i , i + k ) ; } Arrays . sort ( words ) ; int output = words . length ; for ( int i = 1 ; i < words . length ; i ++ ) { if ( words [ i - 1 ] . equals ( words [ i ] ) ) output -- ; } System . out . println ( output ) ; } }

import java . util . * ; import java . lang . * ; import java . math . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; int len = sc . nextInt ( ) ; List l = new ArrayList < String > ( ) ; for ( int i = 0 ; i + len <= s . length ( ) ; i ++ ) { if ( l . contains ( s . substring ( i , i + len ) ) ) { } else { l . add ( s . substring ( i , i + len ) ) ; } } System . out . println ( l . size ( ) ) ; sc . close ( ) ; } } Note : . / Main . java uses unchecked or unsafe operations . Note : Recompile with - Xlint : unchecked for details .

import java . util . Scanner ; import java . util . ArrayList ; import java . util . List ; public class Main { public static void main ( String args [ ] ) { Scanner scan = new Scanner ( System . in ) ; String s = scan . next ( ) ; int k = scan . nextInt ( ) ; int ans ; if ( k > s . length ( ) ) { ans = 0 ; } else { List < String > list = new ArrayList < String > ( ) ; for ( int i = 0 ; i <= s . length ( ) - k ; i ++ ) { String t = s . substring ( i , i + k ) ; if ( ! list . contains ( t ) ) { list . add ( t ) ; } } ans = list . size ( ) ; } System . out . println ( ans ) ; } }

s = input ( ) NEW_LINE k = int ( input ( ) ) NEW_LINE plist = [ ] NEW_LINE for i in range ( len ( s ) - k + 1 ) : NEW_LINE INDENT tmp = s [ i : i + k ] NEW_LINE if tmp not in plist : NEW_LINE INDENT plist . append ( tmp ) NEW_LINE DEDENT DEDENT print ( len ( plist ) ) NEW_LINE

def getInt ( ) : return int ( input ( ) ) NEW_LINE def getIntList ( ) : return [ int ( x ) for x in input ( ) . split ( ) ] NEW_LINE def zeros ( n ) : return [ 0 ] * n NEW_LINE INF = 10 ** 18 NEW_LINE class Debug ( ) : NEW_LINE INDENT def __init__ ( self ) : NEW_LINE INDENT self . debug = True NEW_LINE DEDENT def off ( self ) : NEW_LINE INDENT self . debug = False NEW_LINE DEDENT def dmp ( self , x , cmt = ' ' ) : NEW_LINE INDENT if self . debug : NEW_LINE INDENT if cmt != ' ' : NEW_LINE INDENT w = cmt + ' : ▁ ' + str ( x ) NEW_LINE DEDENT else : NEW_LINE INDENT w = str ( x ) NEW_LINE DEDENT print ( w ) NEW_LINE DEDENT return x NEW_LINE DEDENT DEDENT def prob ( ) : NEW_LINE INDENT d = Debug ( ) NEW_LINE d . off ( ) NEW_LINE S = input ( ) NEW_LINE K = getInt ( ) NEW_LINE d . dmp ( ( S , K ) , ' S , K ' ) NEW_LINE dic = set ( [ ] ) NEW_LINE for i in range ( len ( S ) - K + 1 ) : NEW_LINE INDENT if S [ i : i + K ] not in dic : NEW_LINE INDENT dic . add ( S [ i : i + K ] ) NEW_LINE DEDENT DEDENT d . dmp ( ( dic ) , ' dic ' ) NEW_LINE return len ( dic ) NEW_LINE DEDENT ans = prob ( ) NEW_LINE print ( ans ) NEW_LINE

def password ( s : str , k : int ) -> int : NEW_LINE INDENT t = set ( ) NEW_LINE for i in range ( len ( s ) - k + 1 ) : NEW_LINE INDENT t . add ( s [ i : i + k ] ) NEW_LINE DEDENT return len ( t ) NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT s = input ( ) NEW_LINE k = int ( input ( ) ) NEW_LINE ans = password ( s , k ) NEW_LINE print ( ans ) NEW_LINE DEDENT

s , k = open ( 0 ) ; k = int ( k ) ; print ( len ( { s [ t : t + k ] for t in range ( len ( s ) - k ) } ) ) NEW_LINE

s = input ( ) NEW_LINE k = int ( input ( ) ) NEW_LINE dict = { } NEW_LINE for l in range ( len ( s ) ) : NEW_LINE INDENT for r in range ( l + 1 , len ( s ) + 1 ) : NEW_LINE INDENT if ( r - l != k ) : NEW_LINE INDENT continue NEW_LINE DEDENT dict [ s [ l : r ] ] = 1 NEW_LINE DEDENT DEDENT ans = len ( dict ) NEW_LINE print ( ans ) NEW_LINE


import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long x = sc . nextLong ( ) ; long ans = x / 11 ; ans += ans ; if ( x % 11 > 6 ) { ans += 2 ; } else if ( x % 11 > 0 ) { ans ++ ; } System . out . println ( ans ) ; } }

import java . io . IOException ; import java . util . ArrayList ; import java . util . Scanner ; class Main { public static void main ( String args [ ] ) throws IOException { @ SuppressWarnings ( " resource " ) Scanner cin = new Scanner ( System . in ) ; ArrayList < String > inLines = new ArrayList < String > ( ) ; for ( ; cin . hasNext ( ) ; ) { inLines . add ( cin . nextLine ( ) ) ; } Solver solver = new Solver ( ) ; solver . solve ( inLines ) ; } } class Solver { public void solve ( ArrayList < String > inLines ) { long x = Long . parseLong ( inLines . get ( 0 ) ) ; long ans = ( x / 11 ) * 2 ; if ( x % 11 != 0 ) { if ( x % 11 <= 6 ) ans += 1 ; else ans += 2 ; } System . out . println ( ans ) ; } }

import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . StringTokenizer ; public class Main { long x ; public static void main ( String args [ ] ) { new Main ( ) . run ( ) ; } void run ( ) { FastReader sc = new FastReader ( ) ; x = sc . nextLong ( ) ; solve ( ) ; } void solve ( ) { long remainder = x % 11 ; long ans = x / 11 * 2 ; if ( remainder > 6 ) { ans += 2 ; } else if ( remainder > 0 ) { ans ++ ; } System . out . println ( ans ) ; } 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 . * ; import java . util . stream . * ; import static java . lang . System . * ; class Main { static Scanner sc = new Scanner ( System . in ) ; static int nextInt ( ) { return Integer . parseInt ( sc . next ( ) ) ; } static long nextLong ( ) { return Long . parseLong ( sc . next ( ) ) ; } static int [ ] nextIntArray ( int n ) { return IntStream . range ( 0 , n ) . map ( i -> nextInt ( ) ) . toArray ( ) ; } static int max ( int ... ar ) { Arrays . sort ( ar ) ; return ar [ ar . length - 1 ] ; } static int min ( int ... ar ) { Arrays . sort ( ar ) ; return ar [ 0 ] ; } static String yesno ( boolean b ) { return b ? " Yes " : " No " ; } static int maxInt = Integer . MAX_VALUE ; static int minInt = Integer . MIN_VALUE ; public static void main ( String [ ] args ) { long n = nextLong ( ) ; if ( n % 11 == 0 ) { System . out . println ( n / 11 * 2 ) ; } else if ( n % 11 <= 6 ) { System . out . println ( n / 11 * 2 + 1 ) ; } else { System . out . println ( n / 11 * 2 + 2 ) ; } } }

import java . io . * ; public class Main { static final int N = 10000 ; public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; long x = Long . parseLong ( br . readLine ( ) ) ; long sum = x / 11 ; long temp = x % 11 ; if ( temp != 0 ) { System . out . println ( ( temp > 6 ) ? sum * 2 + 2 : sum * 2 + 1 ) ; } else { System . out . println ( sum * 2 ) ; } } }

import sys NEW_LINE sys . setrecursionlimit ( 10 ** 7 ) NEW_LINE INF = 10 ** 18 NEW_LINE MOD = 10 ** 9 + 7 NEW_LINE from functools import partial , reduce NEW_LINE from operator import mul NEW_LINE prod = partial ( reduce , mul ) NEW_LINE def LI ( ) : return [ int ( x ) for x in sys . stdin . readline ( ) . split ( ) ] NEW_LINE def LI_ ( ) : return [ int ( x ) - 1 for x in sys . stdin . readline ( ) . split ( ) ] NEW_LINE def LF ( ) : return [ float ( x ) for x in sys . stdin . readline ( ) . split ( ) ] NEW_LINE def LS ( ) : return sys . stdin . readline ( ) . split ( ) NEW_LINE def II ( ) : return int ( sys . stdin . readline ( ) ) NEW_LINE def SI ( ) : return input ( ) NEW_LINE def main ( ) : NEW_LINE INDENT x = II ( ) NEW_LINE ans = x // ( 6 + 5 ) * 2 NEW_LINE x %= ( 6 + 5 ) NEW_LINE if 0 < x <= 6 : NEW_LINE INDENT ans += 1 NEW_LINE DEDENT elif 6 < x <= 11 : NEW_LINE INDENT ans += 2 NEW_LINE DEDENT return ans NEW_LINE DEDENT print ( main ( ) ) NEW_LINE

x = int ( input ( ) ) NEW_LINE print ( ( x // 11 ) * 2 + ( 0 if x % 11 == 0 else ( 1 if x % 11 < 7 else 2 ) ) ) NEW_LINE

def getInt ( ) : return int ( input ( ) ) NEW_LINE def getIntList ( ) : return [ int ( x ) for x in input ( ) . split ( ) ] NEW_LINE def zeros ( n ) : return [ 0 ] * n NEW_LINE def getIntLines ( n ) : return [ int ( input ( ) ) for i in range ( n ) ] NEW_LINE def getIntMat ( n ) : NEW_LINE INDENT mat = [ ] NEW_LINE for i in range ( n ) : NEW_LINE INDENT mat . append ( getIntList ( ) ) NEW_LINE DEDENT return mat NEW_LINE DEDENT def zeros2 ( n , m ) : return [ zeros ( m ) ] * n NEW_LINE ALPHABET = [ chr ( i + ord ( ' a ' ) ) for i in range ( 26 ) ] NEW_LINE DIGIT = [ chr ( i + ord ( '0' ) ) for i in range ( 10 ) ] NEW_LINE N1097 = 10 ** 9 + 7 NEW_LINE def dmp ( x , cmt = ' ' ) : NEW_LINE INDENT global debug NEW_LINE if debug : NEW_LINE INDENT if cmt != ' ' : NEW_LINE INDENT print ( cmt , ' : ▁ ▁ ' , end = ' ' ) NEW_LINE DEDENT print ( x ) NEW_LINE DEDENT return x NEW_LINE DEDENT def probC ( ) : NEW_LINE INDENT N = getInt ( ) NEW_LINE dmp ( N ) NEW_LINE count = N // ( 5 + 6 ) * 2 NEW_LINE rem = N % ( 5 + 6 ) NEW_LINE if rem > 6 : NEW_LINE INDENT count += 2 NEW_LINE DEDENT elif rem > 0 : NEW_LINE INDENT count += 1 NEW_LINE DEDENT return count NEW_LINE DEDENT debug = False NEW_LINE ans = probC ( ) NEW_LINE print ( ans ) NEW_LINE NEW_LINE

x = int ( input ( ) ) NEW_LINE count = 0 NEW_LINE q , mod = divmod ( x , 11 ) NEW_LINE count += q * 2 NEW_LINE if mod > 0 : NEW_LINE INDENT if ( mod <= 6 ) : NEW_LINE INDENT count += 1 NEW_LINE DEDENT else : NEW_LINE INDENT count += 2 NEW_LINE DEDENT DEDENT print ( count ) NEW_LINE

import sys NEW_LINE import collections NEW_LINE ns = lambda : sys . stdin . readline ( ) . rstrip ( ) NEW_LINE ni = lambda : int ( ns ( ) ) NEW_LINE nm = lambda : map ( int , sys . stdin . readline ( ) . split ( ) ) NEW_LINE nl = lambda : list ( nm ( ) ) NEW_LINE nsl = lambda : map ( str , sys . stdin . readline ( ) . split ( ) ) NEW_LINE x = ni ( ) NEW_LINE if x % 11 == 0 : NEW_LINE INDENT print ( x // 11 * 2 ) NEW_LINE DEDENT else : NEW_LINE INDENT if x % 11 <= 6 : NEW_LINE INDENT print ( x // 11 * 2 + 1 ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( x // 11 * 2 + 2 ) NEW_LINE DEDENT DEDENT


import java . util . ArrayList ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; ArrayList < Integer > ai = new ArrayList < > ( ) ; int sum = 0 ; int prev = 0 ; ai . add ( 0 ) ; for ( int i = 0 ; i < N ; i ++ ) { int tmp = sc . nextInt ( ) ; ai . add ( tmp ) ; sum += Math . abs ( tmp - prev ) ; prev = tmp ; } sum += Math . abs ( prev ) ; ai . add ( 0 ) ; for ( int i = 1 ; i <= N ; i ++ ) { int a1 = Math . abs ( ai . get ( i - 1 ) - ai . get ( i ) ) ; int a2 = Math . abs ( ai . get ( i ) - ai . get ( i + 1 ) ) ; int a3 = Math . abs ( ai . get ( i + 1 ) - ai . get ( i - 1 ) ) ; System . out . println ( sum - ( a1 + a2 - a3 ) ) ; } } }

import java . util . * ; import java . util . stream . * ; import static java . lang . System . * ; class Main { static Scanner sc = new Scanner ( System . in ) ; static int nextInt ( ) { return Integer . parseInt ( sc . next ( ) ) ; } static long nextLong ( ) { return Long . parseLong ( sc . next ( ) ) ; } static int [ ] nextIntArray ( int n ) { return IntStream . range ( 0 , n ) . map ( i -> nextInt ( ) ) . toArray ( ) ; } static int max ( int ... ar ) { Arrays . sort ( ar ) ; return ar [ ar . length - 1 ] ; } static int min ( int ... ar ) { Arrays . sort ( ar ) ; return ar [ 0 ] ; } static String yesno ( boolean b ) { return b ? " Yes " : " No " ; } static int maxInt = Integer . MAX_VALUE ; static int minInt = Integer . MIN_VALUE ; public static void main ( String [ ] args ) { int n = nextInt ( ) ; int [ ] ar = new int [ n + 2 ] ; for ( int i = 1 ; i < n + 1 ; i ++ ) { ar [ i ] = nextInt ( ) ; } long sum = 0 ; for ( int i = 1 ; i < n + 2 ; i ++ ) { sum += Math . abs ( ar [ i ] - ar [ i - 1 ] ) ; } for ( int i = 1 ; i < n + 1 ; i ++ ) { System . out . println ( sum + Math . abs ( ar [ i + 1 ] - ar [ i - 1 ] ) - ( Math . abs ( ar [ i + 1 ] - ar [ i ] ) + Math . abs ( ar [ i ] - ar [ i - 1 ] ) ) ) ; } } }

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 . util . InputMismatchException ; 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 ; InputReader in = new InputReader ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; TaskC solver = new TaskC ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class TaskC { public void solve ( int testNumber , InputReader in , PrintWriter out ) { int n = in . nextInt ( ) ; int [ ] x = new int [ n + 2 ] ; for ( int i = 0 ; i < n ; i ++ ) { x [ i + 1 ] = in . nextInt ( ) ; } long sum = 0 ; for ( int i = 0 ; i < n + 1 ; i ++ ) { sum += Math . abs ( x [ i + 1 ] - x [ i ] ) ; } for ( int i = 1 ; i <= n ; i ++ ) { out . println ( sum - Math . abs ( x [ i + 1 ] - x [ i ] ) - Math . abs ( x [ i ] - x [ i - 1 ] ) + Math . abs ( x [ i + 1 ] - x [ i - 1 ] ) ) ; } } } static class InputReader { BufferedReader in ; StringTokenizer tok ; public String nextString ( ) { while ( ! tok . hasMoreTokens ( ) ) { try { tok = new StringTokenizer ( in . readLine ( ) , " ▁ " ) ; } catch ( IOException e ) { throw new InputMismatchException ( ) ; } } return tok . nextToken ( ) ; } public int nextInt ( ) { return Integer . parseInt ( nextString ( ) ) ; } public InputReader ( InputStream inputStream ) { in = new BufferedReader ( new InputStreamReader ( inputStream ) ) ; tok = new StringTokenizer ( " " ) ; } } }

import java . util . * ; public class Main { public static void main ( String [ ] args ) { TravelingPlan ( ) ; } public static void ABC086A ( ) { Scanner scan = new Scanner ( System . in ) ; int a = scan . nextInt ( ) ; int b = scan . nextInt ( ) ; if ( ( a * b ) % 2 == 0 ) { System . out . println ( " Even " ) ; } else { System . out . println ( " Odd " ) ; } } public static void ABC081A ( ) { Scanner scan = new Scanner ( System . in ) ; String str = scan . next ( ) ; char chr [ ] = str . toCharArray ( ) ; int count = 0 ; for ( int i = 0 ; i < 3 ; i ++ ) { if ( chr [ i ] == '1' ) count ++ ; } System . out . println ( count ) ; } public static void TravelingPlan ( ) { Scanner scan = new Scanner ( System . in ) ; int N = scan . nextInt ( ) ; int [ ] A = new int [ N + 2 ] ; for ( int i = 1 ; i < N + 1 ; i ++ ) { A [ i ] = scan . nextInt ( ) ; } A [ 0 ] = 0 ; A [ N + 1 ] = 0 ; int ans = 0 ; for ( int i = 1 ; i < N + 2 ; i ++ ) { ans += Math . abs ( A [ i ] - A [ i - 1 ] ) ; } for ( int i = 1 ; i < N + 1 ; i ++ ) { System . out . println ( ans - Math . abs ( A [ i ] - A [ i - 1 ] ) - Math . abs ( A [ i + 1 ] - A [ i ] ) + Math . abs ( A [ i + 1 ] - A [ i - 1 ] ) ) ; } } }

import java . math . BigInteger ; import java . util . ArrayList ; import java . util . Scanner ; public class Main { static int N ; public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; N = scanner . nextInt ( ) ; long total = 0 ; int [ ] map = new int [ N + 5 ] ; int old = 0 ; int old2 = 0 ; for ( int i = 0 ; i < N ; i ++ ) { int a = scanner . nextInt ( ) ; total += Math . abs ( a - old ) ; if ( i != 0 ) { if ( Math . abs ( a - old ) + Math . abs ( old - old2 ) == Math . abs ( old2 - a ) ) { map [ i - 1 ] = 0 ; } else { map [ i - 1 ] = Math . abs ( a - old ) + Math . abs ( old - old2 ) - Math . abs ( old2 - a ) ; } } old2 = old ; old = a ; } total += Math . abs ( old ) ; if ( Math . abs ( 0 - old ) + Math . abs ( old - old2 ) == Math . abs ( old2 - 0 ) ) { map [ N - 1 ] = 0 ; } else { map [ N - 1 ] = Math . abs ( 0 - old ) + Math . abs ( old - old2 ) - Math . abs ( old2 - 0 ) ; } for ( int i = 0 ; i < N ; i ++ ) { System . out . println ( total - map [ i ] ) ; } } }

N = int ( input ( ) ) NEW_LINE a = list ( map ( int , input ( ) . split ( ) ) ) + [ 0 ] NEW_LINE c = [ 0 ] * ( N + 2 ) NEW_LINE for i in range ( N ) : NEW_LINE INDENT c [ i + 1 ] = abs ( a [ i ] - a [ i - 1 ] ) NEW_LINE DEDENT c [ - 1 ] = abs ( a [ - 2 ] ) NEW_LINE s = sum ( c ) NEW_LINE for i in range ( N ) : NEW_LINE INDENT print ( s - c [ i + 1 ] - c [ i + 2 ] + abs ( a [ i + 1 ] - a [ i - 1 ] ) ) NEW_LINE DEDENT

def inpl ( ) : return [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE N = int ( input ( ) ) NEW_LINE A = [ 0 ] + inpl ( ) + [ 0 ] NEW_LINE sumtr = 0 NEW_LINE for i in range ( N + 1 ) : NEW_LINE INDENT sumtr += abs ( A [ i + 1 ] - A [ i ] ) NEW_LINE DEDENT for i in range ( 1 , N + 1 ) : NEW_LINE INDENT print ( sumtr + abs ( A [ i + 1 ] - A [ i - 1 ] ) - abs ( A [ i ] - A [ i - 1 ] ) - abs ( A [ i + 1 ] - A [ i ] ) ) NEW_LINE DEDENT

N = int ( input ( ) ) NEW_LINE A = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE A . insert ( 0 , 0 ) NEW_LINE A . append ( 0 ) NEW_LINE cost = 0 NEW_LINE for i in range ( N + 1 ) : NEW_LINE INDENT cost += abs ( A [ i + 1 ] - A [ i ] ) NEW_LINE DEDENT for i in range ( 1 , N + 1 ) : NEW_LINE INDENT if A [ i - 1 ] <= A [ i ] <= A [ i + 1 ] or A [ i + 1 ] <= A [ i ] <= A [ i - 1 ] : NEW_LINE INDENT sub = 0 NEW_LINE DEDENT elif A [ i - 1 ] <= A [ i + 1 ] <= A [ i ] : NEW_LINE INDENT sub = 2 * ( A [ i ] - A [ i + 1 ] ) NEW_LINE DEDENT elif A [ i ] <= A [ i - 1 ] <= A [ i + 1 ] : NEW_LINE INDENT sub = 2 * ( A [ i - 1 ] - A [ i ] ) NEW_LINE DEDENT elif A [ i + 1 ] <= A [ i - 1 ] <= A [ i ] : NEW_LINE INDENT sub = 2 * ( A [ i ] - A [ i - 1 ] ) NEW_LINE DEDENT elif A [ i ] <= A [ i + 1 ] <= A [ i - 1 ] : NEW_LINE INDENT sub = 2 * ( A [ i + 1 ] - A [ i ] ) NEW_LINE DEDENT print ( cost - sub ) NEW_LINE DEDENT

N = int ( input ( ) ) NEW_LINE As = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE As . insert ( 0 , 0 ) NEW_LINE As . append ( 0 ) NEW_LINE total = 0 NEW_LINE costs = [ ] NEW_LINE for i in range ( 1 , N + 1 ) : NEW_LINE INDENT total += abs ( As [ i ] - As [ i - 1 ] ) NEW_LINE x1 = As [ i ] - As [ i - 1 ] NEW_LINE x2 = As [ i + 1 ] - As [ i - 1 ] NEW_LINE if x1 * x2 >= 0 and abs ( x1 ) <= abs ( x2 ) : NEW_LINE INDENT costs . append ( 0 ) NEW_LINE DEDENT elif x1 * x2 >= 0 and abs ( x1 ) > abs ( x2 ) : NEW_LINE INDENT costs . append ( 2 * abs ( x2 - x1 ) ) NEW_LINE DEDENT elif x1 * x2 < 0 : NEW_LINE INDENT costs . append ( 2 * abs ( x1 ) ) NEW_LINE DEDENT DEDENT total += abs ( As [ N + 1 ] - As [ N ] ) NEW_LINE for i in range ( N ) : NEW_LINE INDENT print ( total - costs [ i ] ) NEW_LINE DEDENT

II = lambda : int ( input ( ) ) NEW_LINE MI = lambda : map ( int , input ( ) . split ( ) ) NEW_LINE MIL = lambda : list ( MI ( ) ) NEW_LINE MIS = lambda : input ( ) . split ( ) NEW_LINE def main ( ) : NEW_LINE INDENT N = II ( ) NEW_LINE A = [ 0 ] + MIL ( ) + [ 0 ] NEW_LINE d = [ abs ( A [ i ] - A [ i + 1 ] ) for i in range ( N + 1 ) ] NEW_LINE cost = sum ( d ) NEW_LINE for i in range ( 1 , N + 1 ) : NEW_LINE INDENT print ( cost - ( d [ i ] + d [ i - 1 ] ) + abs ( A [ i - 1 ] - A [ i + 1 ] ) ) NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT main ( ) NEW_LINE DEDENT


import java . util . Arrays ; import java . util . Scanner ; public class Main { static int N ; static int M ; static Edge [ ] E ; static final int INF = 10000 ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; N = sc . nextInt ( ) ; M = sc . nextInt ( ) ; E = new Edge [ M ] ; for ( int i = 0 ; i < M ; i ++ ) { E [ i ] = new Edge ( sc . nextInt ( ) - 1 , sc . nextInt ( ) - 1 , sc . nextInt ( ) ) ; } System . out . println ( solve ( ) ) ; } private static long solve ( ) { int [ ] [ ] dist = new int [ N ] [ N ] ; for ( int [ ] array : dist ) { Arrays . fill ( array , INF ) ; } for ( Edge edge : E ) { dist [ edge . a ] [ edge . b ] = edge . cost ; dist [ edge . b ] [ edge . a ] = edge . cost ; } for ( int k = 0 ; k < N ; k ++ ) { for ( int i = 0 ; i < N ; i ++ ) { if ( dist [ i ] [ k ] == INF ) continue ; for ( int j = 0 ; j < N ; j ++ ) { if ( dist [ k ] [ j ] == INF ) continue ; if ( dist [ i ] [ k ] + dist [ k ] [ j ] < dist [ i ] [ j ] ) { dist [ i ] [ j ] = dist [ i ] [ k ] + dist [ k ] [ j ] ; } } } } int ans = 0 ; for ( Edge edge : E ) { if ( dist [ edge . a ] [ edge . b ] < edge . cost ) ans ++ ; } return ans ; } static class Edge { private final int a ; private final int b ; private final int cost ; public Edge ( int a , int b , int cost ) { this . a = a ; this . b = b ; this . cost = cost ; } } }

import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int m = sc . nextInt ( ) ; int [ ] a = new int [ m ] ; int [ ] b = new int [ m ] ; int [ ] c = new int [ m ] ; for ( int i = 0 ; i < m ; i ++ ) { a [ i ] = sc . nextInt ( ) ; b [ i ] = sc . nextInt ( ) ; c [ i ] = sc . nextInt ( ) ; } int [ ] [ ] map = new int [ n + 1 ] [ n + 1 ] ; int inf = 1000000 ; for ( int i = 1 ; i < n + 1 ; i ++ ) { for ( int j = 1 ; j < n + 1 ; j ++ ) { map [ i ] [ j ] = inf ; } } for ( int i = 0 ; i < m ; i ++ ) { map [ a [ i ] ] [ b [ i ] ] = c [ i ] ; map [ b [ i ] ] [ a [ i ] ] = c [ i ] ; } for ( int k = 1 ; k <= n ; k ++ ) { for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = 1 ; j <= n ; j ++ ) { map [ i ] [ j ] = Math . min ( map [ i ] [ j ] , map [ i ] [ k ] + map [ k ] [ j ] ) ; } } } int ans = 0 ; for ( int i = 0 ; i < m ; i ++ ) { if ( map [ a [ i ] ] [ b [ i ] ] != c [ i ] ) { ans ++ ; } } System . out . println ( ans ) ; } } class Pair implements Comparable { int from ; int end ; @ Override public int compareTo ( Object other ) { Pair otherpair = ( Pair ) other ; return end - otherpair . end ; } }

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 [ ] a = new int [ m ] ; int [ ] b = new int [ m ] ; int [ ] c = new int [ m ] ; int [ ] [ ] cost = new int [ n ] [ n ] ; int inf = 1 << 29 ; for ( int i = 0 ; i < n ; i ++ ) Arrays . fill ( cost [ i ] , inf ) ; for ( int i = 0 ; i < n ; i ++ ) cost [ i ] [ i ] = 0 ; for ( int i = 0 ; i < m ; i ++ ) { a [ i ] = in . nextInt ( ) - 1 ; b [ i ] = in . nextInt ( ) - 1 ; c [ i ] = in . nextInt ( ) ; cost [ a [ i ] ] [ b [ i ] ] = c [ i ] ; cost [ b [ i ] ] [ a [ i ] ] = c [ i ] ; } boolean used [ ] = new boolean [ m ] ; for ( int k = 0 ; k < n ; k ++ ) { for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { if ( i == j ) continue ; cost [ i ] [ j ] = Math . min ( cost [ i ] [ k ] + cost [ k ] [ j ] , cost [ i ] [ j ] ) ; } } } int ans = 0 ; for ( int i = 0 ; i < m ; i ++ ) if ( c [ i ] > cost [ a [ i ] ] [ b [ i ] ] ) ans ++ ; System . out . println ( ans ) ; } }

import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int N = scanner . nextInt ( ) ; int M = scanner . nextInt ( ) ; int [ ] [ ] edges = new int [ M ] [ 3 ] ; int [ ] [ ] dist = new int [ N ] [ N ] ; int INF = 100_000_000 ; for ( int i = 0 ; i < N ; i ++ ) for ( int j = 0 ; j < N ; j ++ ) dist [ i ] [ j ] = INF ; for ( int i = 0 ; i < M ; i ++ ) { int a = scanner . nextInt ( ) - 1 ; int b = scanner . nextInt ( ) - 1 ; int c = scanner . nextInt ( ) ; edges [ i ] [ 0 ] = a ; edges [ i ] [ 1 ] = b ; edges [ i ] [ 2 ] = c ; dist [ a ] [ b ] = dist [ b ] [ a ] = c ; } for ( int k = 0 ; k < N ; k ++ ) for ( int i = 0 ; i < N ; i ++ ) for ( int j = 0 ; j < N ; j ++ ) if ( dist [ i ] [ j ] > dist [ i ] [ k ] + dist [ k ] [ j ] ) dist [ i ] [ j ] = dist [ i ] [ k ] + dist [ k ] [ j ] ; int num = 0 ; for ( int i = 0 ; i < M ; i ++ ) { int a = edges [ i ] [ 0 ] ; int b = edges [ i ] [ 1 ] ; int c = edges [ i ] [ 2 ] ; if ( dist [ a ] [ b ] == c ) num ++ ; } System . out . println ( M - num ) ; } }

import java . util . * ; import java . io . * ; import static java . lang . System . in ; public class Main { public static void main ( String [ ] args ) throws IOException { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) , m = sc . nextInt ( ) ; int inf = Integer . MAX_VALUE / 2 - 10 ; int [ ] [ ] dist = new int [ n + 1 ] [ n + 1 ] ; for ( int i = 0 ; i <= n ; i ++ ) Arrays . fill ( dist [ i ] , inf ) ; for ( int i = 0 ; i <= n ; i ++ ) dist [ i ] [ i ] = 0 ; Edge [ ] dic = new Edge [ m ] ; for ( int i = 0 ; i < m ; i ++ ) { int a = sc . nextInt ( ) , b = sc . nextInt ( ) , c = sc . nextInt ( ) ; dic [ i ] = new Edge ( a , b , c ) ; dist [ a ] [ b ] = Math . min ( dist [ a ] [ b ] , c ) ; dist [ b ] [ a ] = Math . min ( dist [ b ] [ a ] , c ) ; } for ( int mid = 1 ; mid <= n ; mid ++ ) { for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = 1 ; j <= n ; j ++ ) dist [ i ] [ j ] = Math . min ( dist [ i ] [ j ] , dist [ i ] [ mid ] + dist [ mid ] [ j ] ) ; } } int ans = 0 ; for ( Edge e : dic ) { if ( dist [ e . left ] [ e . right ] < e . length ) ans ++ ; } System . out . println ( ans ) ; } static class Edge { int left , right , length ; public Edge ( int l , int r , int len ) { left = l ; right = r ; length = len ; } } }

import heapq NEW_LINE n , m = map ( int , input ( ) . split ( ) ) NEW_LINE abc = [ tuple ( int ( x ) - 1 for x in input ( ) . split ( ) ) for _ in range ( m ) ] NEW_LINE dist = [ [ 9999999 for _ in range ( n ) ] for _ in range ( n ) ] NEW_LINE e = [ dict ( ) for _ in range ( n ) ] NEW_LINE for i in range ( m ) : NEW_LINE INDENT a , b , c = abc [ i ] [ 0 ] , abc [ i ] [ 1 ] , abc [ i ] [ 2 ] NEW_LINE e [ a ] [ b ] = c + 1 NEW_LINE e [ b ] [ a ] = c + 1 NEW_LINE DEDENT for i in range ( n ) : NEW_LINE INDENT h = [ ] NEW_LINE heapq . heappush ( h , [ 0 , i ] ) NEW_LINE temp = set ( ) NEW_LINE while len ( temp ) < n : NEW_LINE INDENT d , p = heapq . heappop ( h ) NEW_LINE while p in temp : NEW_LINE INDENT d , p = heapq . heappop ( h ) NEW_LINE DEDENT dist [ i ] [ p ] = d NEW_LINE temp . add ( p ) NEW_LINE for x in e [ p ] . keys ( ) : NEW_LINE INDENT heapq . heappush ( h , [ d + e [ p ] [ x ] , x ] ) NEW_LINE DEDENT DEDENT DEDENT ans = m NEW_LINE for a , b , c in abc : NEW_LINE INDENT for i in range ( n ) : NEW_LINE INDENT if c + 1 == dist [ a ] [ i ] - dist [ b ] [ i ] : NEW_LINE INDENT ans -= 1 NEW_LINE break NEW_LINE DEDENT DEDENT DEDENT print ( ans ) NEW_LINE

from collections import deque NEW_LINE from operator import itemgetter NEW_LINE n , m = map ( int , input ( ) . split ( ) ) NEW_LINE edge = [ list ( map ( int , input ( ) . split ( ) ) ) for i in range ( m ) ] NEW_LINE kyori = [ [ float ( " inf " ) ] * n for i in range ( n ) ] NEW_LINE for i in range ( n ) : NEW_LINE INDENT kyori [ i ] [ i ] = 0 NEW_LINE DEDENT def dfs ( start , goal ) : NEW_LINE INDENT visited_cost = [ float ( " inf " ) ] * n NEW_LINE visited_cost [ start ] = 0 NEW_LINE que = deque ( ) NEW_LINE que . append ( start ) NEW_LINE while que : NEW_LINE INDENT pos = que . pop ( ) NEW_LINE for [ next_pos , cost ] in tree [ pos ] : NEW_LINE INDENT if visited_cost [ next_pos ] > visited_cost [ pos ] + cost : NEW_LINE INDENT visited_cost [ next_pos ] = visited_cost [ pos ] + cost NEW_LINE que . append ( next_pos ) NEW_LINE DEDENT DEDENT DEDENT return visited_cost [ goal ] NEW_LINE DEDENT edge = sorted ( edge , key = itemgetter ( 2 ) ) NEW_LINE tree = [ [ ] for i in range ( n ) ] NEW_LINE ans = m NEW_LINE for [ start , goal , cost ] in edge : NEW_LINE INDENT start -= 1 NEW_LINE goal -= 1 NEW_LINE if cost <= dfs ( start , goal ) : NEW_LINE INDENT tree [ start ] . append ( [ goal , cost ] ) NEW_LINE tree [ goal ] . append ( [ start , cost ] ) NEW_LINE ans -= 1 NEW_LINE DEDENT DEDENT print ( ans ) NEW_LINE

import sys NEW_LINE input = sys . stdin . readline NEW_LINE inf = float ( ' inf ' ) NEW_LINE def warshall_floyd ( dist , n ) : NEW_LINE INDENT for k in range ( n ) : NEW_LINE INDENT for i in range ( n ) : NEW_LINE INDENT for j in range ( n ) : NEW_LINE INDENT if i == j : NEW_LINE INDENT dist [ i ] [ j ] = 0 NEW_LINE DEDENT elif dist [ i ] [ j ] > dist [ i ] [ k ] + dist [ k ] [ j ] : NEW_LINE INDENT dist [ i ] [ j ] = dist [ i ] [ k ] + dist [ k ] [ j ] NEW_LINE DEDENT DEDENT DEDENT DEDENT DEDENT N , M = map ( int , input ( ) . split ( ) ) NEW_LINE edges = [ ] NEW_LINE ad = [ [ inf ] * N for _ in range ( N ) ] NEW_LINE for _ in range ( M ) : NEW_LINE INDENT a , b , c = map ( int , input ( ) . split ( ) ) NEW_LINE a -= 1 ; b -= 1 NEW_LINE edges . append ( ( a , b , c ) ) NEW_LINE ad [ a ] [ b ] = c NEW_LINE ad [ b ] [ a ] = c NEW_LINE DEDENT warshall_floyd ( ad , N ) NEW_LINE ans = M NEW_LINE for a , b , c in edges : NEW_LINE INDENT if a > b : NEW_LINE INDENT a , b = b , a NEW_LINE DEDENT for s in range ( N ) : NEW_LINE INDENT for e in range ( s + 1 , N ) : NEW_LINE INDENT if ad [ s ] [ a ] + c + ad [ b ] [ e ] == ad [ s ] [ e ] : NEW_LINE INDENT ans -= 1 NEW_LINE break NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT continue NEW_LINE DEDENT break NEW_LINE DEDENT DEDENT print ( ans ) NEW_LINE

def candidates_of_no_shortest_paths ( N : int , M : int , edges : list ) -> int : NEW_LINE INDENT INF = float ( ' inf ' ) NEW_LINE d = [ [ 0 if i == j else INF for i in range ( N ) ] for j in range ( N ) ] NEW_LINE for u , v , c in edges : NEW_LINE INDENT d [ u - 1 ] [ v - 1 ] = d [ v - 1 ] [ u - 1 ] = c NEW_LINE DEDENT for k in range ( N ) : NEW_LINE INDENT for u in range ( N ) : NEW_LINE INDENT for v in range ( N ) : NEW_LINE INDENT if d [ u ] [ v ] > d [ u ] [ k ] + d [ k ] [ v ] : NEW_LINE INDENT d [ u ] [ v ] = d [ u ] [ k ] + d [ k ] [ v ] NEW_LINE DEDENT DEDENT DEDENT DEDENT def used ( edge : tuple ) -> bool : NEW_LINE INDENT u , v , c = edge NEW_LINE for s in range ( N ) : NEW_LINE INDENT if d [ s ] [ u - 1 ] + c == d [ s ] [ v - 1 ] : NEW_LINE INDENT return True NEW_LINE DEDENT DEDENT return False NEW_LINE DEDENT return sum ( not used ( edge ) for edge in edges ) NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT M = 0 NEW_LINE N , M = map ( int , input ( ) . split ( ) ) NEW_LINE edges = [ tuple ( int ( s ) for s in input ( ) . split ( ) ) for _ in range ( M ) ] NEW_LINE ans = candidates_of_no_shortest_paths ( N , M , edges ) NEW_LINE print ( ans ) NEW_LINE DEDENT

from copy import deepcopy NEW_LINE N , M = list ( map ( int , input ( ) . strip ( ) . split ( ) ) ) NEW_LINE abc = { } NEW_LINE used = { } NEW_LINE for _ in range ( M ) : NEW_LINE INDENT a , b , c = ( list ( map ( int , input ( ) . strip ( ) . split ( ) ) ) ) NEW_LINE abc [ a , b ] = c NEW_LINE used [ a , b ] = False NEW_LINE DEDENT spth = [ [ float ( " inf " ) ] * ( N + 1 ) for _ in range ( N + 1 ) ] NEW_LINE for i in range ( 1 , N + 1 ) : NEW_LINE INDENT spth [ i ] [ i ] = 0 NEW_LINE DEDENT for ab , c in abc . items ( ) : NEW_LINE INDENT spth [ ab [ 0 ] ] [ ab [ 1 ] ] = c NEW_LINE spth [ ab [ 1 ] ] [ ab [ 0 ] ] = c NEW_LINE DEDENT for k in range ( 1 , N + 1 ) : NEW_LINE INDENT for i in range ( 1 , N + 1 ) : NEW_LINE INDENT for j in range ( 1 , N + 1 ) : NEW_LINE INDENT d = spth [ i ] [ k ] + spth [ k ] [ j ] NEW_LINE if spth [ i ] [ j ] > d : NEW_LINE INDENT spth [ i ] [ j ] = d NEW_LINE DEDENT DEDENT DEDENT DEDENT for ab , c in abc . items ( ) : NEW_LINE INDENT for s in range ( 1 , N + 1 ) : NEW_LINE INDENT if used [ ab ] : break NEW_LINE if spth [ s ] [ ab [ 1 ] ] == spth [ s ] [ ab [ 0 ] ] + c : NEW_LINE INDENT used [ ab ] = True NEW_LINE break NEW_LINE DEDENT DEDENT DEDENT print ( sum ( not i for i in used . values ( ) ) ) NEW_LINE


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

import java . util . Scanner ; import java . util . Arrays ; import java . util . ArrayList ; import java . util . List ; import java . util . Collections ; public class Main { public static void main ( String args [ ] ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] ar = new int [ n ] ; int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { ar [ i ] = sc . nextInt ( ) ; } for ( int i = 0 ; i < n ; i ++ ) { if ( isOdd ( ar [ i ] ) == true ) { count ++ ; } } if ( isOdd ( count ) == true ) { System . out . println ( " NO " ) ; } else { System . out . println ( " YES " ) ; } sc . close ( ) ; } private static boolean isOdd ( int n ) { if ( n % 2 != 0 ) { return true ; } else { return false ; } } }

import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { try ( Scanner sc = new Scanner ( System . in ) ; ) { new Main ( ) . solve ( sc ) ; } } void solve ( Scanner sc ) { int oddCount = 0 ; int n = sc . nextInt ( ) ; for ( int i = 0 ; i < n ; i ++ ) { int a = sc . nextInt ( ) ; if ( a % 2 == 1 ) { oddCount ++ ; } } System . out . println ( oddCount % 2 == 0 ? " YES " : " NO " ) ; } }

import java . util . * ; import static java . lang . System . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int [ ] cnt = new int [ 2 ] ; for ( int i = 0 ; i < N ; i ++ ) { cnt [ ( int ) ( sc . nextLong ( ) % 2 ) ] ++ ; } int restOdd = cnt [ 1 ] % 2 ; cnt [ 0 ] += cnt [ 1 ] / 2 ; if ( ( restOdd == 0 && cnt [ 0 ] > 0 ) || ( restOdd == 1 && cnt [ 0 ] == 0 ) ) { out . println ( " YES " ) ; } else { out . println ( " NO " ) ; } } }

import java . util . Scanner ; import java . util . Collections ; import java . util . ArrayList ; import java . util . Arrays ; import java . util . Queue ; import java . util . ArrayDeque ; import java . util . Deque ; import java . util . PriorityQueue ; import java . util . Set ; import java . util . HashMap ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int n = scanner . nextInt ( ) ; int [ ] a = new int [ n ] ; int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = scanner . nextInt ( ) ; if ( a [ i ] % 2 == 1 ) { count ++ ; } } if ( count % 2 == 1 ) { System . out . println ( " NO " ) ; } else { System . out . println ( " YES " ) ; } } }

input ( ) ; print ( ' YNEOS ' [ sum ( map ( lambda x : int ( x ) % 2 > 0 , input ( ) . split ( ) ) ) % 2 > 0 : : 2 ] ) NEW_LINE

n = int ( input ( ) ) NEW_LINE s = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE evens , odds = 0 , 0 NEW_LINE for i in s : NEW_LINE INDENT if i % 2 == 0 : NEW_LINE INDENT evens += 1 NEW_LINE DEDENT else : NEW_LINE INDENT odds += 1 NEW_LINE DEDENT DEDENT if odds % 2 == 0 : NEW_LINE INDENT ok = True NEW_LINE DEDENT else : NEW_LINE INDENT ok = False NEW_LINE DEDENT print ( ' YES ' if ok else ' NO ' ) NEW_LINE

import sys NEW_LINE input = sys . stdin . readline NEW_LINE N = int ( input ( ) ) NEW_LINE A = [ int ( _ ) for _ in input ( ) . split ( ) ] NEW_LINE oddnum = 0 NEW_LINE for i in A : NEW_LINE INDENT if i % 2 == 1 : NEW_LINE INDENT oddnum += 1 NEW_LINE DEDENT DEDENT print ( " YES " if oddnum % 2 == 0 else " NO " ) NEW_LINE

N = int ( input ( ) ) NEW_LINE A = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE odds = sum ( [ a % 2 for a in A ] ) NEW_LINE evens = sum ( [ ( a + 1 ) % 2 for a in A ] ) NEW_LINE if len ( A ) == 1 : NEW_LINE INDENT print ( ' YES ' ) NEW_LINE exit ( ) NEW_LINE DEDENT if odds % 2 == 0 : NEW_LINE INDENT print ( ' YES ' ) NEW_LINE exit ( ) NEW_LINE DEDENT print ( ' NO ' ) NEW_LINE

n , a = open ( 0 ) ; print ( ' YNEOS ' [ sum ( map ( int , a . split ( ) ) ) % 2 : : 2 ] ) NEW_LINE


import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int N = scanner . nextInt ( ) ; int [ ] a = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) a [ i ] = scanner . nextInt ( ) ; long count = N ; int l = 0 ; while ( l < N ) { int r = l + 1 ; while ( r < N && a [ r ] > a [ r - 1 ] ) { count += r - l ; r ++ ; } l = r ; } System . out . println ( count ) ; } }

import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . lang . reflect . Array ; import java . util . Arrays ; public class Main { private static final int MOD = 1_000_000_007 ; public static void main ( String [ ] args ) { try ( CustomReader in = new CustomReader ( ) ) { new Main ( ) . execute ( in ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } public void execute ( CustomReader in ) throws IOException { final int N = Integer . parseInt ( in . readLine ( ) ) ; int [ ] a = in . readLineAsIntArray ( ) ; long total = 0 ; long subTotal = 1 ; int seq = 1 ; for ( int i = 1 ; i < N ; i ++ ) { if ( a [ i ] > a [ i - 1 ] ) { seq ++ ; subTotal += seq ; } else { total += subTotal ; subTotal = 1 ; seq = 1 ; } } total += subTotal ; System . out . println ( total ) ; } static class CustomReader extends BufferedReader { private static final int DEFAULT_BUF_SIZE = 2048 ; public CustomReader ( ) throws IOException { super ( new InputStreamReader ( System . in ) , DEFAULT_BUF_SIZE ) ; } public int [ ] readLineAsIntArray ( ) throws IOException { String [ ] strArray = this . readLine ( ) . split ( " ▁ " ) ; int [ ] intArray = new int [ strArray . length ] ; for ( int i = 0 , n = strArray . length ; i < n ; i ++ ) { intArray [ i ] = Integer . parseInt ( strArray [ i ] ) ; } return intArray ; } public int [ ] [ ] readAsIntMatrix ( int rows , int columns ) throws IOException { int [ ] [ ] matrix = new int [ rows ] [ columns ] ; for ( int i = 0 ; i < rows ; i ++ ) { String [ ] r = this . readLine ( ) . split ( " ▁ " ) ; for ( int j = 0 ; j < columns ; j ++ ) { matrix [ i ] [ j ] = Integer . parseInt ( r [ j ] ) ; } } return matrix ; } } }

import java . math . BigDecimal ; import java . util . * ; public class Main { static Scanner sc = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { int N = sc . nextInt ( ) ; int [ ] values = new int [ N + 1 ] ; for ( int i = 0 ; i < N ; i ++ ) { values [ i ] = sc . nextInt ( ) ; } values [ N ] = 0 ; long ans = 0 ; long count = 1 ; for ( int i = 0 ; i < N ; i ++ ) { if ( values [ i ] < values [ i + 1 ] ) { count ++ ; } else { ans += ( count * ( count + 1 ) ) / 2 ; count = 1 ; } } System . out . println ( ans ) ; } }

import java . util . * ; import static java . lang . System . * ; public class Main { public static void main ( String [ ] args ) { 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 ( ) ; } long total = 0 ; long subtotal = 1 ; int pre = a [ 0 ] ; for ( int i = 1 ; i < N ; i ++ ) { if ( pre >= a [ i ] ) { total += subtotal ; if ( subtotal > 1 ) { total += subtotal * ( subtotal - 1 ) / 2 ; } subtotal = 1 ; } else { subtotal ++ ; } pre = a [ i ] ; } total += subtotal ; if ( subtotal > 1 ) { total += subtotal * ( subtotal - 1 ) / 2 ; } out . println ( total ) ; } }

public class Main { private static java . util . Scanner s = new java . util . Scanner ( System . in ) ; static long l = 0 , n = s . nextInt ( ) , b = s . nextInt ( ) ; public static void main ( String [ ] args ) { System . out . println ( java . util . stream . LongStream . range ( 1 , n ) . reduce ( n , ( a , i ) -> a + ( ( b < ( b = s . nextInt ( ) ) ) ? i - l : ( l = i ) * 0 ) ) ) ; } }

n = int ( input ( ) ) NEW_LINE a = [ int ( _ ) for _ in input ( ) . split ( ) ] NEW_LINE r = 0 NEW_LINE ans = 0 NEW_LINE for l in range ( n ) : NEW_LINE INDENT while r < n - 1 and a [ r ] < a [ r + 1 ] : NEW_LINE INDENT r += 1 NEW_LINE DEDENT ans += r - l + 1 NEW_LINE if r == l : r += 1 NEW_LINE DEDENT print ( ans ) NEW_LINE

from __future__ import print_function NEW_LINE import sys NEW_LINE def eprint ( * args , ** kwargs ) : NEW_LINE INDENT print ( * args , file = sys . stderr , ** kwargs ) NEW_LINE DEDENT n = int ( input ( ) ) NEW_LINE array = [ 0 ] + list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE right = 1 NEW_LINE left = 1 NEW_LINE length_s = 0 NEW_LINE ans = 0 NEW_LINE cnt = 0 NEW_LINE temp_x = 0 NEW_LINE while True : NEW_LINE INDENT if right == n + 1 and left == n + 1 : NEW_LINE INDENT cnt += int ( length_s * ( length_s + 1 ) / 2 ) NEW_LINE break NEW_LINE DEDENT if right == n + 1 : NEW_LINE INDENT while left < right : NEW_LINE INDENT left += 1 NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT if temp_x < array [ right ] : NEW_LINE INDENT temp_x = array [ right ] NEW_LINE right += 1 NEW_LINE length_s = right - left NEW_LINE DEDENT elif right == left : NEW_LINE INDENT cnt += int ( length_s * ( length_s + 1 ) / 2 ) NEW_LINE temp_x = 0 NEW_LINE DEDENT else : NEW_LINE INDENT left += 1 NEW_LINE DEDENT DEDENT DEDENT print ( cnt ) NEW_LINE NEW_LINE

def simple_incremental ( N : int , A : list ) -> int : NEW_LINE INDENT l , r = 0 , 0 NEW_LINE count = 0 NEW_LINE while r < N : NEW_LINE INDENT while r + 1 < N and A [ r ] < A [ r + 1 ] : NEW_LINE INDENT r = r + 1 NEW_LINE DEDENT count += ( r - l + 1 ) * ( r - l + 2 ) // 2 NEW_LINE l = r = r + 1 NEW_LINE DEDENT return count NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT N = int ( input ( ) ) NEW_LINE A = [ int ( s ) for s in input ( ) . split ( ) ] NEW_LINE ans = simple_incremental ( N , A ) NEW_LINE print ( ans ) NEW_LINE DEDENT

N = int ( input ( ) ) NEW_LINE Ans = N NEW_LINE suu = input ( ) NEW_LINE ListNum = list ( map ( int , suu . split ( ) ) ) NEW_LINE c = 0 NEW_LINE for i in range ( 0 , len ( ListNum ) , 1 ) : NEW_LINE INDENT try : NEW_LINE INDENT if ListNum [ i ] < ListNum [ i + 1 ] : NEW_LINE INDENT c += 1 NEW_LINE DEDENT else : NEW_LINE INDENT b = c * ( C + 1 ) / 2 NEW_LINE Ans += b NEW_LINE c = 0 NEW_LINE continue NEW_LINE DEDENT DEDENT except : NEW_LINE INDENT b = c * ( c + 1 ) / 2 NEW_LINE Ans += b NEW_LINE c = 0 NEW_LINE if i == len ( ListNum ) - 1 : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT DEDENT print ( int ( Ans ) ) NEW_LINE

import sys NEW_LINE input = sys . stdin . readline NEW_LINE N = int ( input ( ) ) NEW_LINE a = [ int ( _ ) for _ in input ( ) . split ( ) ] NEW_LINE left = 0 NEW_LINE right = 0 NEW_LINE ans = 0 NEW_LINE tmp = 0 NEW_LINE while right < N : NEW_LINE INDENT right += 1 NEW_LINE if a [ right - 1 ] > tmp : NEW_LINE INDENT tmp = a [ right - 1 ] NEW_LINE DEDENT else : NEW_LINE INDENT right -= 1 NEW_LINE ans += ( right - left ) * ( right - left + 1 ) // 2 NEW_LINE left = right NEW_LINE tmp = 0 NEW_LINE DEDENT DEDENT ans += ( right - left ) * ( right - left + 1 ) // 2 NEW_LINE print ( ans ) NEW_LINE


import java . util . Deque ; import java . util . Iterator ; import java . util . LinkedList ; import java . util . List ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { try ( Scanner sc = new Scanner ( System . in ) ; ) { new Main ( ) . solve ( sc ) ; } } void solve ( Scanner sc ) { int n = sc . nextInt ( ) ; Deque < String > numDeque = new LinkedList < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( i % 2 == 0 ) { numDeque . addFirst ( sc . next ( ) ) ; } else { numDeque . addLast ( sc . next ( ) ) ; } } Iterator < String > i = n % 2 == 0 ? numDeque . descendingIterator ( ) : numDeque . iterator ( ) ; while ( i . hasNext ( ) ) { System . out . print ( " ▁ " + i . next ( ) ) ; } } }

import java . util . Arrays ; import java . util . Collections ; import java . util . LinkedList ; import java . util . Scanner ; import java . util . stream . Collectors ; public class Main { private static String solve ( Scanner scanner ) { int N = Integer . parseInt ( scanner . nextLine ( ) ) ; String [ ] nums = scanner . nextLine ( ) . split ( " ▁ " ) ; LinkedList < String > result = new LinkedList < > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { if ( i % 2 == 1 ) { result . addLast ( nums [ i ] ) ; } else { result . addFirst ( nums [ i ] ) ; } } if ( N % 2 == 0 ) { Collections . reverse ( result ) ; } return result . stream ( ) . collect ( Collectors . joining ( " ▁ " ) ) ; } private static final String ex1 = "4 \n " + "1 ▁ 2 ▁ 3 ▁ 4" ; private static final String ex2 = "3 \n " + "1 ▁ 2 ▁ 3" ; private static final String ex3 = "1 \n " + "1000000000" ; private static final String ex4 = "6 \n " + "0 ▁ 6 ▁ 7 ▁ 6 ▁ 7 ▁ 0" ; public static void main ( String [ ] args ) { System . out . println ( solve ( new Scanner ( System . in ) ) ) ; } private static int [ ] lineToIntNums ( String line ) { String [ ] strNums = line . split ( " ▁ " ) ; int [ ] ret = new int [ strNums . length ] ; for ( int i = 0 ; i < strNums . length ; i ++ ) { ret [ i ] = Integer . parseInt ( strNums [ i ] ) ; } return ret ; } private static long [ ] lineToLongNums ( String line ) { String [ ] strNums = line . split ( " ▁ " ) ; long [ ] ret = new long [ strNums . length ] ; for ( int i = 0 ; i < strNums . length ; i ++ ) { ret [ i ] = Long . parseLong ( strNums [ i ] ) ; } return ret ; } }

import java . util . * ; public class Main { private static int N ; private static ArrayList < Integer > arrayList = new ArrayList < > ( ) ; public static void input ( ) { Scanner scan = new Scanner ( System . in ) ; N = scan . nextInt ( ) ; for ( int i = 0 ; i < N ; i ++ ) { arrayList . add ( scan . nextInt ( ) ) ; } } public static void main ( String args [ ] ) { input ( ) ; ArrayList < Integer > b = new ArrayList < > ( ) ; if ( N % 2 == 0 ) { for ( int i = N - 1 ; i >= 0 ; i -= 2 ) b . add ( arrayList . get ( i ) ) ; for ( int i = 0 ; i < N ; i += 2 ) b . add ( arrayList . get ( i ) ) ; } else { for ( int i = N - 1 ; i >= 0 ; i -= 2 ) b . add ( arrayList . get ( i ) ) ; for ( int i = 1 ; i < N ; i += 2 ) b . add ( arrayList . get ( i ) ) ; } for ( int i = 0 ; i < N ; i ++ ) { System . out . print ( b . get ( i ) + " ▁ " ) ; } } }

import java . io . * ; import java . util . Deque ; import java . util . * ; public class Main { public static void main ( String [ ] args ) { InputReader inputReader = new InputReader ( System . in ) ; PrintWriter printWriter = new PrintWriter ( System . out ) ; Deque < Integer > deque = new ArrayDeque < > ( ) ; int n ; n = inputReader . nextInt ( ) ; for ( int i = 1 ; i <= n ; i ++ ) { if ( ( i + 1 ) % 2 == 1 ) { deque . addFirst ( inputReader . nextInt ( ) ) ; } else { deque . addLast ( inputReader . nextInt ( ) ) ; } } if ( n % 2 == 0 ) { for ( Integer i : deque ) { System . out . print ( i . toString ( ) + " ▁ " ) ; } } else { for ( int i = 1 ; i <= n ; i ++ ) { System . out . print ( deque . removeLast ( ) . toString ( ) + " ▁ " ) ; } } } static class InputReader { public BufferedReader reader ; public StringTokenizer tokenizer ; public InputReader ( InputStream stream ) { reader = new BufferedReader ( new InputStreamReader ( stream ) , 32768 ) ; tokenizer = null ; } public String next ( ) { while ( tokenizer == null || ! tokenizer . hasMoreTokens ( ) ) { try { tokenizer = new StringTokenizer ( reader . readLine ( ) ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } } return tokenizer . nextToken ( ) ; } public int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } } }

import java . io . OutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . PrintWriter ; import java . util . StringTokenizer ; import java . util . Collection ; import java . io . IOException ; import java . io . BufferedReader ; import java . util . Deque ; import java . util . LinkedList ; 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 ; InputReader in = new InputReader ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; TaskC solver = new TaskC ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class TaskC { public void solve ( int testNumber , InputReader in , PrintWriter out ) { int n = in . nextInt ( ) ; boolean end = true ; Deque < Integer > dq = new LinkedList < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( end ) { dq . addLast ( in . nextInt ( ) ) ; } else dq . addFirst ( in . nextInt ( ) ) ; end = ! end ; } if ( end ) while ( ! dq . isEmpty ( ) ) out . print ( dq . pollFirst ( ) + " ▁ " ) ; else while ( ! dq . isEmpty ( ) ) out . print ( dq . pollLast ( ) + " ▁ " ) ; } } static class InputReader { public BufferedReader reader ; public StringTokenizer tokenizer ; public InputReader ( InputStream stream ) { reader = new BufferedReader ( new InputStreamReader ( stream ) ) ; tokenizer = null ; } public String next ( ) { while ( tokenizer == null || ! tokenizer . hasMoreTokens ( ) ) { try { tokenizer = new StringTokenizer ( reader . readLine ( ) ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } } return tokenizer . nextToken ( ) ; } public int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } } }

from collections import deque NEW_LINE n = int ( input ( ) . strip ( ) ) NEW_LINE a = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE b = deque ( ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT if i % 2 == 0 : NEW_LINE INDENT b . append ( a [ i ] ) NEW_LINE DEDENT else : NEW_LINE INDENT b . appendleft ( a [ i ] ) NEW_LINE DEDENT DEDENT b = list ( b ) NEW_LINE if n % 2 == 1 : NEW_LINE INDENT b = b [ : : - 1 ] NEW_LINE DEDENT print ( ' ▁ ' . join ( map ( str , b ) ) ) NEW_LINE

INF , MOD = float ( " inf " ) , 1e9 + 7 NEW_LINE MAX , MIN = - INF , INF NEW_LINE dx1 , dy1 , dx2 , dy2 = [ - 1 , 0 , 1 , 0 ] , [ 0 , - 1 , 0 , 1 ] , [ - 1 , 0 , 1 , - 1 , 1 , - 1 , 0 , 1 ] , [ - 1 , - 1 , - 1 , 0 , 0 , 1 , 1 , 1 ] NEW_LINE def get_int ( ) : NEW_LINE INDENT return int ( input ( ) ) NEW_LINE DEDENT def get_int_list ( ) : NEW_LINE INDENT return list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE DEDENT def mins ( x , y ) : NEW_LINE INDENT x = min ( x , y ) NEW_LINE DEDENT def maxs ( x , y ) : NEW_LINE INDENT x = max ( x , y ) NEW_LINE DEDENT while ( True ) : NEW_LINE INDENT try : NEW_LINE INDENT n = get_int ( ) NEW_LINE a = get_int_list ( ) NEW_LINE print ( * ( a [ : : - 2 ] + a [ 1 : : 2 ] ) if n % 2 else a [ : : - 2 ] + a [ : : 2 ] ) NEW_LINE DEDENT except EOFError : NEW_LINE INDENT exit ( ) NEW_LINE DEDENT DEDENT

import sys NEW_LINE import collections NEW_LINE import math NEW_LINE n = int ( input ( ) ) NEW_LINE A = [ int ( x ) for x in input ( ) . split ( ) ] NEW_LINE R = [ 0 ] * n NEW_LINE idx = 0 NEW_LINE for i in range ( n - 1 , - 1 , - 2 ) : NEW_LINE INDENT R [ idx ] = A [ i ] NEW_LINE idx += 1 NEW_LINE DEDENT for i in range ( n % 2 , n , + 2 ) : NEW_LINE INDENT R [ idx ] = A [ i ] NEW_LINE idx += 1 NEW_LINE DEDENT print ( " ▁ " . join ( [ str ( i ) for i in R ] ) ) NEW_LINE sys . exit ( 0 ) NEW_LINE

def inpl ( ) : return [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE n = int ( input ( ) ) NEW_LINE a = inpl ( ) NEW_LINE ans = [ 0 for _ in range ( n ) ] NEW_LINE if n % 2 : NEW_LINE INDENT for i , ai in enumerate ( a ) : NEW_LINE INDENT if i % 2 : NEW_LINE INDENT ans [ n // 2 + ( i + 1 ) // 2 ] = ai NEW_LINE DEDENT else : NEW_LINE INDENT ans [ n // 2 - ( i + 1 ) // 2 ] = ai NEW_LINE DEDENT DEDENT DEDENT else : NEW_LINE INDENT for i , ai in enumerate ( a ) : NEW_LINE INDENT if i % 2 : NEW_LINE INDENT ans [ n // 2 - ( i + 1 ) // 2 ] = ai NEW_LINE DEDENT else : NEW_LINE INDENT ans [ n // 2 + ( i + 1 ) // 2 ] = ai NEW_LINE DEDENT DEDENT DEDENT print ( * ans ) NEW_LINE

n = int ( input ( ) ) NEW_LINE A = input ( ) . split ( ' ▁ ' ) NEW_LINE if n == 1 : NEW_LINE INDENT ans = A [ 0 ] NEW_LINE print ( ans ) NEW_LINE exit ( ) NEW_LINE DEDENT else : NEW_LINE INDENT A_odd = A [ : : 2 ] NEW_LINE A_even = A [ 1 : : 2 ] NEW_LINE if n % 2 == 0 : NEW_LINE INDENT ans = A_even [ : : - 1 ] + A_odd NEW_LINE DEDENT else : NEW_LINE INDENT ans = A_odd [ : : - 1 ] + A_even NEW_LINE DEDENT print ( ' ▁ ' . join ( ans ) ) NEW_LINE DEDENT


import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scn = new Scanner ( System . in ) ; int A = scn . nextInt ( ) ; int B = scn . nextInt ( ) ; int ans = 0 ; int DT = Math . abs ( A - B ) ; ans += DT / 10 ; DT %= 10 ; if ( DT < 4 ) { ans += DT ; } else if ( DT > 7 ) { ans ++ ; ans += 10 - DT ; } else { ans ++ ; ans += Math . abs ( DT - 5 ) ; } System . out . println ( ans ) ; } }

import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int bias = 100 ; int A = sc . nextInt ( ) ; int B = sc . nextInt ( ) ; if ( A == B ) { System . out . println ( 0 ) ; System . exit ( 0 ) ; } HashSet < Integer > fixed = new HashSet < > ( ) ; int [ ] dic = new int [ ] { 1 , 5 , 10 , - 1 , - 5 , - 10 } ; B = Math . abs ( B - A ) + bias ; int [ ] dist = new int [ 2 * bias + 1 ] ; Arrays . fill ( dist , Integer . MAX_VALUE ) ; dist [ bias ] = 0 ; myComparator mc = new myComparator ( ) ; PriorityQueue < int [ ] > pq = new PriorityQueue < > ( 10 , mc ) ; pq . add ( new int [ ] { bias , 0 } ) ; while ( ! fixed . contains ( B ) ) { int [ ] cur = pq . poll ( ) ; int now = cur [ 0 ] ; if ( fixed . contains ( now ) ) continue ; fixed . add ( now ) ; dist [ now ] = cur [ 1 ] ; for ( int w : dic ) { if ( ! fixed . contains ( now + w ) ) { if ( now + w > 2 * bias || now + w < 0 ) continue ; if ( dist [ now + w ] > dist [ now ] + 1 ) { dist [ now + w ] = dist [ now ] + 1 ; pq . add ( new int [ ] { now + w , dist [ now ] + 1 } ) ; } } } } int ans = dist [ B ] ; System . out . println ( ans ) ; } static class myComparator implements Comparator < int [ ] > { public int compare ( int [ ] a , int [ ] b ) { return a [ 1 ] - b [ 1 ] ; } } }

import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStream ; import java . io . InputStreamReader ; import java . io . OutputStream ; import java . io . PrintWriter ; import java . util . StringTokenizer ; public class Main { public static void main ( String [ ] args ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; InputReader in = new InputReader ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; Task solver = new Task ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class Task { public void solve ( int testNumber , InputReader in , PrintWriter out ) { int A = in . nextInt ( ) ; int B = in . nextInt ( ) ; int count = 0 ; int dif = A - B ; while ( dif != 0 ) { if ( dif >= 8 ) { dif -= 10 ; } else if ( dif >= 4 ) { dif -= 5 ; } else if ( dif >= 1 ) { dif -- ; } else if ( dif <= - 8 ) { dif += 10 ; } else if ( dif <= - 4 ) { dif += 5 ; } else { dif ++ ; } count ++ ; } out . println ( count ) ; } } static class InputReader { public BufferedReader reader ; public StringTokenizer tokenizer ; public InputReader ( InputStream stream ) { reader = new BufferedReader ( new InputStreamReader ( stream ) , 32768 ) ; tokenizer = null ; } public String next ( ) { while ( tokenizer == null || ! tokenizer . hasMoreTokens ( ) ) { try { tokenizer = new StringTokenizer ( reader . readLine ( ) ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } } return tokenizer . nextToken ( ) ; } public int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } } }

import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int start = sc . nextInt ( ) ; int goal = sc . nextInt ( ) ; int count = 0 ; while ( start != goal ) { if ( start < goal ) { count ++ ; int testA = start + 10 ; int testB = start + 5 ; int testC = start + 1 ; List < Integer > list = Arrays . asList ( testA , testB , testC ) ; start = list . stream ( ) . min ( Comparator . comparing ( ( Integer x ) -> Math . abs ( x - goal ) ) ) . get ( ) ; } else if ( start > goal ) { count ++ ; int testA = start - 10 ; int testB = start - 5 ; int testC = start - 1 ; List < Integer > list = Arrays . asList ( testA , testB , testC ) ; start = list . stream ( ) . min ( Comparator . comparing ( ( Integer x ) -> Math . abs ( x - goal ) ) ) . get ( ) ; } } System . out . println ( count ) ; } }

import java . io . OutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . PrintWriter ; import java . util . Scanner ; 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 ) ; B solver = new B ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class B { public void solve ( int testNumber , Scanner in , PrintWriter out ) { int d = Math . abs ( in . nextInt ( ) - in . nextInt ( ) ) ; int c = 0 ; while ( d > 0 ) { if ( d >= 8 ) { c ++ ; d -= 10 ; d = Math . abs ( d ) ; } else if ( d >= 4 ) { c ++ ; d -= 5 ; d = Math . abs ( d ) ; } else { c += d ; d = 0 ; } } out . println ( c ) ; } } }

A , B = map ( int , input ( ) . split ( ) ) NEW_LINE d = abs ( A - B ) NEW_LINE l = [ 0 , 1 , 2 , 3 , 2 , 1 , 2 , 3 , 3 , 2 ] NEW_LINE c = d // 10 + l [ d % 10 ] NEW_LINE print ( c ) NEW_LINE

from itertools import product NEW_LINE def check ( Qss ) : NEW_LINE INDENT if max ( map ( sum , Qss ) ) > 1 : NEW_LINE INDENT return False NEW_LINE DEDENT if max ( map ( sum , zip ( * Qss ) ) ) > 1 : NEW_LINE INDENT return False NEW_LINE DEDENT if max ( map ( sum , zip ( * [ [ 0 ] * i + Qs + [ 0 ] * ( 7 - i ) for i , Qs in enumerate ( Qss ) ] ) ) ) > 1 : NEW_LINE INDENT return False NEW_LINE DEDENT if max ( map ( sum , zip ( * [ [ 0 ] * ( 7 - i ) + Qs + [ 0 ] * i for i , Qs in enumerate ( Qss ) ] ) ) ) > 1 : NEW_LINE INDENT return False NEW_LINE DEDENT return True NEW_LINE DEDENT css = [ input ( ) for _ in range ( 8 ) ] NEW_LINE Qss = [ [ 1 if c == ' Q ' else 0 for c in cs ] for cs in css ] NEW_LINE rows = [ r for r in range ( 8 ) if sum ( Qss [ r ] ) == 0 ] NEW_LINE for columns in product ( range ( 8 ) , repeat = 5 ) : NEW_LINE INDENT for r , c in zip ( rows , columns ) : NEW_LINE INDENT Qss [ r ] [ c ] = 1 NEW_LINE DEDENT if check ( Qss ) : NEW_LINE INDENT print ( ' \n ' . join ( [ ' ' . join ( [ ' Q ' if Q else ' . ' for Q in Qs ] ) for Qs in Qss ] ) ) NEW_LINE break NEW_LINE DEDENT for r , c in zip ( rows , columns ) : NEW_LINE INDENT Qss [ r ] [ c ] = 0 NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT print ( ' No ▁ Answer ' ) NEW_LINE DEDENT

from collections import defaultdict NEW_LINE from heapq import heappush , heappop NEW_LINE import sys NEW_LINE import math NEW_LINE import bisect NEW_LINE import itertools NEW_LINE def LI ( ) : return list ( map ( int , sys . stdin . readline ( ) . split ( ) ) ) NEW_LINE def I ( ) : return int ( sys . stdin . readline ( ) ) NEW_LINE def LS ( ) : return sys . stdin . readline ( ) . split ( ) NEW_LINE def S ( ) : return list ( sys . stdin . readline ( ) ) NEW_LINE def IR ( n ) : return [ I ( ) for i in range ( n ) ] NEW_LINE def LIR ( n ) : return [ LI ( ) for i in range ( n ) ] NEW_LINE def SR ( n ) : return [ S ( ) for i in range ( n ) ] NEW_LINE def LSR ( n ) : return [ LS ( ) for i in range ( n ) ] NEW_LINE mod = 1000000007 NEW_LINE def A ( ) : NEW_LINE INDENT n = I ( ) NEW_LINE c = S ( ) NEW_LINE minans = float ( " INF " ) NEW_LINE maxans = 0 NEW_LINE for i in range ( 1 , 5 ) : NEW_LINE INDENT minans = min ( minans , c . count ( str ( i ) ) ) NEW_LINE maxans = max ( maxans , c . count ( str ( i ) ) ) NEW_LINE DEDENT print ( maxans , minans ) NEW_LINE DEDENT def B ( ) : NEW_LINE INDENT a , b = LI ( ) NEW_LINE ans = 0 NEW_LINE while a != b : NEW_LINE INDENT if a > b : NEW_LINE INDENT a = a ^ b NEW_LINE b = a ^ b NEW_LINE a = a ^ b NEW_LINE DEDENT ab = b - a NEW_LINE if ab >= 8 : NEW_LINE INDENT a += 10 NEW_LINE DEDENT elif ab >= 3 : NEW_LINE INDENT a += 5 NEW_LINE DEDENT else : NEW_LINE INDENT a += 1 NEW_LINE DEDENT ans += 1 NEW_LINE DEDENT print ( ans ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT B ( ) NEW_LINE DEDENT

N = 8 NEW_LINE row = [ - 1 ] * N NEW_LINE col = [ - 1 ] * N NEW_LINE dpos = [ - 1 ] * ( 2 * N - 1 ) NEW_LINE dneg = [ - 1 ] * ( 2 * N - 1 ) NEW_LINE def solve ( i ) : NEW_LINE INDENT if i == N : NEW_LINE INDENT for i in range ( N ) : NEW_LINE INDENT print ( ' ' . join ( ' . Q ' [ row [ i ] == j ] for j in range ( N ) ) ) NEW_LINE DEDENT exit ( ) NEW_LINE DEDENT if row [ i ] != - 1 : NEW_LINE INDENT solve ( i + 1 ) NEW_LINE return NEW_LINE DEDENT for j in range ( N ) : NEW_LINE INDENT if 1 in ( col [ j ] , dpos [ i + j ] , dneg [ i - j + N - 1 ] ) : NEW_LINE INDENT continue NEW_LINE DEDENT row [ i ] = j ; col [ j ] = dpos [ i + j ] = dneg [ i - j + N - 1 ] = 1 NEW_LINE solve ( i + 1 ) NEW_LINE row [ i ] = col [ j ] = dpos [ i + j ] = dneg [ i - j + N - 1 ] = - 1 NEW_LINE DEDENT DEDENT for i in range ( N ) : NEW_LINE INDENT r = input ( ) NEW_LINE if ' Q ' in r : NEW_LINE INDENT j = r . index ( ' Q ' ) NEW_LINE if r . count ( ' Q ' ) > 1 or 1 in ( col [ j ] , dpos [ i + j ] , dneg [ i - j + N - 1 ] ) : NEW_LINE INDENT print ( ' No ▁ Answer ' ) NEW_LINE exit ( ) NEW_LINE DEDENT row [ i ] = j ; col [ j ] = dpos [ i + j ] = dneg [ i - j + N - 1 ] = 1 NEW_LINE DEDENT DEDENT solve ( 0 ) NEW_LINE print ( ' No ▁ Answer ' ) NEW_LINE

A , B = [ int ( _ ) for _ in input ( ) . split ( ) ] NEW_LINE result = 0 NEW_LINE if A > B : NEW_LINE INDENT A , B = B , A NEW_LINE DEDENT while A != B : NEW_LINE INDENT if B >= A + 10 : NEW_LINE INDENT A += 10 NEW_LINE DEDENT elif B == A + 9 : NEW_LINE INDENT A -= 1 NEW_LINE DEDENT elif B == A + 8 : NEW_LINE INDENT A -= 1 NEW_LINE DEDENT elif B == A + 7 : NEW_LINE INDENT A += 5 NEW_LINE DEDENT elif B == A + 6 : NEW_LINE INDENT A += 5 NEW_LINE DEDENT elif B == A + 5 : NEW_LINE INDENT A += 5 NEW_LINE DEDENT elif B == A + 4 : NEW_LINE INDENT A -= 1 NEW_LINE DEDENT elif B == A + 3 : NEW_LINE INDENT A += 1 NEW_LINE DEDENT elif B == A + 2 : NEW_LINE INDENT A += 1 NEW_LINE DEDENT elif B == A + 1 : NEW_LINE INDENT A += 1 NEW_LINE DEDENT result += 1 NEW_LINE DEDENT print ( result ) NEW_LINE


import java . util . Scanner ; public class Main { private static Scanner sc = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { int a = sc . nextInt ( ) , b = sc . nextInt ( ) , c = sc . nextInt ( ) ; System . out . println ( Math . max ( Math . max ( a * 10 + b + c , a + b * 10 + c ) , a + b + c * 10 ) ) ; } }

import java . util . PriorityQueue ; import java . util . Scanner ; public class Main { public static String process ( TestCase testCase ) { final int A = testCase . A ; final int B = testCase . B ; final int C = testCase . C ; PriorityQueue < Integer > pq = new PriorityQueue < > ( ( a , b ) -> Integer . compare ( b , a ) ) ; pq . add ( A ) ; pq . add ( B ) ; pq . add ( C ) ; int max = noInspectionGet ( pq ) ; final int smaller = noInspectionGet ( pq ) ; final int smallest = noInspectionGet ( pq ) ; return String . valueOf ( max * 10 + smaller + smallest ) ; } private static int noInspectionGet ( PriorityQueue < Integer > pq ) { return pq . poll ( ) ; } public static void main ( String [ ] args ) { TestCase testCase = readFromInput ( ) ; final String result = process ( testCase ) ; output ( result ) ; } private static TestCase readFromInput ( ) { Scanner sc = new Scanner ( System . in ) ; int A = sc . nextInt ( ) ; int B = sc . nextInt ( ) ; int C = sc . nextInt ( ) ; return new TestCase ( A , B , C ) ; } private static void output ( String result ) { System . out . println ( result ) ; } public static class TestCase { final int A ; final int B ; final int C ; public TestCase ( int A , int B , int C ) { this . A = A ; this . B = B ; this . C = C ; } } }

import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . ArrayList ; import java . util . Arrays ; import java . util . Collections ; import java . util . List ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String [ ] abc = br . readLine ( ) . split ( " ▁ " ) ; int a = Integer . parseInt ( abc [ 0 ] ) ; int b = Integer . parseInt ( abc [ 1 ] ) ; int c = Integer . parseInt ( abc [ 2 ] ) ; List < Integer > ans = new ArrayList < Integer > ( Arrays . asList ( a , b , c ) ) ; Collections . sort ( ans ) ; int i = ans . get ( 2 ) * 10 + ans . get ( 1 ) ; System . out . println ( i + ans . get ( 0 ) ) ; } }

import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; int num [ ] = new int [ 3 ] ; for ( int i = 0 ; i < 3 ; i ++ ) num [ i ] = sc . nextInt ( ) ; Arrays . sort ( num ) ; int ans = num [ 2 ] * 10 + num [ 1 ] + num [ 0 ] ; System . out . println ( ans ) ; } }

public class Main { private static java . util . Scanner scanner = new java . util . Scanner ( System . in ) ; public static void main ( String [ ] args ) { int answer , temp ; System . out . println ( Math . max ( Math . max ( ( answer = ( temp = 0 ) + scanner . nextInt ( ) ) - temp , ( answer = ( temp = answer ) + scanner . nextInt ( ) ) - temp ) , ( answer = ( temp = answer ) + scanner . nextInt ( ) ) - temp ) * 9 + answer ) ; } }

a , b , c = sorted ( map ( int , input ( ) . split ( ) ) ) NEW_LINE print ( c * 10 + a + b ) NEW_LINE

a , b , c = map ( int , input ( ) . split ( ) ) NEW_LINE num = [ ] NEW_LINE num . append ( a ) NEW_LINE num . append ( b ) NEW_LINE num . append ( c ) NEW_LINE ookii = num . copy ( ) NEW_LINE ooi = max ( ookii ) NEW_LINE num . remove ( max ( num ) ) NEW_LINE print ( ooi * 10 + num [ 0 ] + num [ 1 ] ) NEW_LINE

l = [ i for i in input ( ) . split ( ) ] NEW_LINE l . sort ( ) NEW_LINE a = int ( l [ - 1 ] + l [ 1 ] ) NEW_LINE print ( a + int ( l [ 0 ] ) ) NEW_LINE

A , B , C = map ( int , input ( ) . split ( ) ) NEW_LINE if B < C : NEW_LINE INDENT tmp = B NEW_LINE B = C NEW_LINE C = tmp NEW_LINE DEDENT if A < B : NEW_LINE INDENT tmp = A NEW_LINE A = B NEW_LINE B = tmp NEW_LINE DEDENT print ( ( A * 10 ) + B + C ) NEW_LINE

abc = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE sorted_list = sorted ( abc , reverse = True ) NEW_LINE print ( sorted_list [ 0 ] * 10 + sorted_list [ 1 ] + sorted_list [ 2 ] ) NEW_LINE


import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int C = sc . nextInt ( ) ; int [ ] [ ] D = new int [ C ] [ C ] ; int [ ] [ ] c = new int [ N ] [ N ] ; for ( int i = 0 ; i < C ; i ++ ) { for ( int j = 0 ; j < C ; j ++ ) { D [ i ] [ j ] = sc . nextInt ( ) ; } } for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) { c [ i ] [ j ] = sc . nextInt ( ) - 1 ; } } sc . close ( ) ; int [ ] [ ] g = new int [ C ] [ 3 ] ; for ( int i = 0 ; i < C ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) { for ( int k = 0 ; k < N ; k ++ ) { if ( c [ j ] [ k ] != i ) { g [ i ] [ ( j + k ) % 3 ] += D [ c [ j ] [ k ] ] [ i ] ; } } } } int min = Integer . MAX_VALUE ; for ( int i = 0 ; i < C ; i ++ ) { for ( int j = 0 ; j < C ; j ++ ) { for ( int k = 0 ; k < C ; k ++ ) { if ( i == j || i == k || j == k ) continue ; min = Math . min ( min , g [ i ] [ 0 ] + g [ j ] [ 1 ] + g [ k ] [ 2 ] ) ; } } } System . out . println ( min ) ; } }

import java . util . Scanner ; public class Main { public static void main ( String args [ ] ) throws Exception { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int C = sc . nextInt ( ) ; int [ ] [ ] D = new int [ C + 1 ] [ C + 1 ] ; int [ ] [ ] c = new int [ N + 1 ] [ N + 1 ] ; int [ ] [ ] table = new int [ 3 ] [ C + 1 ] ; for ( int i = 1 ; i <= C ; i ++ ) { for ( int j = 1 ; j <= C ; j ++ ) { D [ i ] [ j ] = sc . nextInt ( ) ; } } for ( int i = 1 ; i <= N ; i ++ ) { for ( int j = 1 ; j <= N ; j ++ ) { int col = sc . nextInt ( ) ; table [ ( i + j ) % 3 ] [ col ] ++ ; } } int [ ] [ ] costable = new int [ 3 ] [ C + 1 ] ; for ( int i = 0 ; i < 3 ; i ++ ) { for ( int j = 1 ; j <= C ; j ++ ) for ( int k = 1 ; k <= C ; k ++ ) { costable [ i ] [ k ] += D [ j ] [ k ] * table [ i ] [ j ] ; } } int min = 260000000 ; for ( int i = 1 ; i <= C ; i ++ ) { for ( int j = 1 ; j <= C ; j ++ ) { for ( int k = 1 ; k <= C ; k ++ ) { if ( i != j && j != k && k != i ) { min = Math . min ( min , costable [ 0 ] [ i ] + costable [ 1 ] [ j ] + costable [ 2 ] [ k ] ) ; } } } } System . out . println ( min ) ; } }

import java . io . File ; import java . io . IOException ; import java . util . ArrayDeque ; import java . util . ArrayList ; import java . util . Arrays ; import java . util . Collections ; import java . util . Comparator ; import java . util . Deque ; import java . util . HashMap ; import java . util . List ; import java . util . Scanner ; import java . util . Map . Entry ; public class Main { public static void main ( String [ ] args ) throws IOException { Scanner in = new Scanner ( System . in ) ; int N = in . nextInt ( ) ; int C = in . nextInt ( ) ; int [ ] [ ] D = new int [ C ] [ C ] ; long [ ] [ ] d = new long [ 3 ] [ C ] ; for ( int i = 0 ; i < C ; i ++ ) { for ( int j = 0 ; j < C ; j ++ ) D [ i ] [ j ] = in . nextInt ( ) ; } int [ ] [ ] c = new int [ N ] [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) { c [ i ] [ j ] = in . nextInt ( ) ; for ( int k = 1 ; k <= C ; k ++ ) { d [ ( ( i + j ) % 3 ) ] [ k - 1 ] += D [ c [ i ] [ j ] - 1 ] [ k - 1 ] ; } } } long min = Long . MAX_VALUE ; for ( int i = 1 ; i <= C ; i ++ ) { for ( int j = 1 ; j <= C ; j ++ ) { if ( i == j ) continue ; for ( int k = 1 ; k <= C ; k ++ ) { if ( i == k || j == k ) continue ; long cost = 0 ; cost += d [ 0 ] [ i - 1 ] ; cost += d [ 1 ] [ j - 1 ] ; cost += d [ 2 ] [ k - 1 ] ; min = Math . min ( min , cost ) ; } } } System . out . println ( min ) ; } }

import java . util . * ; import static java . lang . System . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int C = sc . nextInt ( ) ; int [ ] [ ] D = new int [ C + 1 ] [ C + 1 ] ; for ( int i = 1 ; i <= C ; i ++ ) { for ( int j = 1 ; j <= C ; j ++ ) { D [ i ] [ j ] = sc . nextInt ( ) ; } } int [ ] [ ] c = new int [ N + 1 ] [ N + 1 ] ; for ( int i = 1 ; i <= N ; i ++ ) { for ( int j = 1 ; j <= N ; j ++ ) { c [ i ] [ j ] = sc . nextInt ( ) ; } } int [ ] [ ] colorNums = new int [ C + 1 ] [ 3 ] ; for ( int i = 1 ; i <= N ; i ++ ) { for ( int j = 1 ; j <= N ; j ++ ) { colorNums [ c [ i ] [ j ] ] [ ( i + j ) % 3 ] ++ ; } } int minDSum = Integer . MAX_VALUE ; for ( int c1 = 1 ; c1 <= C ; c1 ++ ) { for ( int c2 = 1 ; c2 <= C ; c2 ++ ) { if ( c1 == c2 ) { continue ; } for ( int c3 = 1 ; c3 <= C ; c3 ++ ) { if ( c1 == c3 || c2 == c3 ) { continue ; } int tmp = 0 ; for ( int cOrg = 1 ; cOrg <= C ; cOrg ++ ) { tmp += colorNums [ cOrg ] [ 0 ] * D [ cOrg ] [ c1 ] ; tmp += colorNums [ cOrg ] [ 1 ] * D [ cOrg ] [ c2 ] ; tmp += colorNums [ cOrg ] [ 2 ] * D [ cOrg ] [ c3 ] ; } minDSum = Math . min ( minDSum , tmp ) ; } } } out . println ( minDSum ) ; } }

import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; final int C = sc . nextInt ( ) ; int [ ] [ ] A = new int [ 3 ] [ C + 1 ] ; int [ ] [ ] D = new int [ C + 1 ] [ C + 1 ] ; int [ ] [ ] B = new int [ 3 ] [ C + 1 ] ; int ans = Integer . MAX_VALUE ; for ( int i = 1 ; i <= C ; i ++ ) for ( int j = 1 ; j <= C ; j ++ ) D [ i ] [ j ] = sc . nextInt ( ) ; for ( int i = 1 ; i <= N ; i ++ ) { for ( int j = 1 ; j <= N ; j ++ ) { int r = ( i + j ) % 3 ; int cij = sc . nextInt ( ) ; A [ r ] [ cij ] ++ ; } } for ( int i = 0 ; i < 3 ; i ++ ) { for ( int j = 1 ; j <= C ; j ++ ) { for ( int k = 1 ; k <= C ; k ++ ) { B [ i ] [ j ] += D [ k ] [ j ] * A [ i ] [ k ] ; } } } for ( int i = 1 ; i <= C ; i ++ ) { for ( int j = 1 ; j <= C ; j ++ ) { for ( int k = 1 ; k <= C ; k ++ ) { if ( i != j && i != k && j != k ) { ans = Math . min ( ans , B [ 0 ] [ i ] + B [ 1 ] [ j ] + B [ 2 ] [ k ] ) ; } } } } System . out . println ( ans ) ; } }

N , C = map ( int , input ( ) . split ( ) ) NEW_LINE d = [ list ( map ( int , input ( ) . split ( ) ) ) for _ in range ( C ) ] NEW_LINE c = [ list ( map ( int , input ( ) . split ( ) ) ) for _ in range ( N ) ] NEW_LINE c_set = [ [ 0 ] * C for _ in range ( 3 ) ] NEW_LINE for i in range ( N ) : NEW_LINE INDENT for j in range ( N ) : NEW_LINE INDENT c_set [ ( i + j ) % 3 ] [ c [ i ] [ j ] - 1 ] += 1 NEW_LINE DEDENT DEDENT ans = 1e9 NEW_LINE for c_1 in range ( C ) : NEW_LINE INDENT for c_2 in range ( C ) : NEW_LINE INDENT for c_3 in range ( C ) : NEW_LINE INDENT if c_1 == c_2 or c_1 == c_3 or c_2 == c_3 : NEW_LINE INDENT continue NEW_LINE DEDENT c_list = [ c_1 , c_2 , c_3 ] NEW_LINE k = 0 NEW_LINE for i in range ( C ) : NEW_LINE INDENT for j in range ( 3 ) : NEW_LINE INDENT k += d [ i ] [ c_list [ j ] - 1 ] * c_set [ j ] [ i ] NEW_LINE DEDENT DEDENT ans = min ( ans , k ) NEW_LINE DEDENT DEDENT DEDENT print ( ans ) NEW_LINE

n , c = map ( int , input ( ) . split ( ) ) NEW_LINE dmap = [ list ( map ( int , input ( ) . split ( ) ) ) for _ in range ( c ) ] NEW_LINE cmap = [ list ( map ( int , input ( ) . split ( ) ) ) for _ in range ( n ) ] NEW_LINE d1 = { } NEW_LINE d2 = { } NEW_LINE d3 = { } NEW_LINE for i , clist in enumerate ( cmap ) : NEW_LINE INDENT for j , _c in enumerate ( clist ) : NEW_LINE INDENT if ( i + j + 2 ) % 3 == 2 : NEW_LINE INDENT if _c - 1 in d1 : NEW_LINE INDENT d1 [ _c - 1 ] += 1 NEW_LINE DEDENT else : NEW_LINE INDENT d1 [ _c - 1 ] = 1 NEW_LINE DEDENT DEDENT elif ( i + j + 2 ) % 3 == 0 : NEW_LINE INDENT if _c - 1 in d2 : NEW_LINE INDENT d2 [ _c - 1 ] += 1 NEW_LINE DEDENT else : NEW_LINE INDENT d2 [ _c - 1 ] = 1 NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT if _c - 1 in d3 : NEW_LINE INDENT d3 [ _c - 1 ] += 1 NEW_LINE DEDENT else : NEW_LINE INDENT d3 [ _c - 1 ] = 1 NEW_LINE DEDENT DEDENT DEDENT DEDENT minc = None NEW_LINE for c1 in range ( c ) : NEW_LINE INDENT for c2 in range ( c ) : NEW_LINE INDENT for c3 in range ( c ) : NEW_LINE INDENT tmp = 0 NEW_LINE if c1 == c2 or c2 == c3 or c3 == c1 : NEW_LINE INDENT continue NEW_LINE DEDENT for _c , cn in d1 . items ( ) : NEW_LINE INDENT tmp += dmap [ _c ] [ c1 ] * cn NEW_LINE DEDENT for _c , cn in d2 . items ( ) : NEW_LINE INDENT tmp += dmap [ _c ] [ c2 ] * cn NEW_LINE DEDENT for _c , cn in d3 . items ( ) : NEW_LINE INDENT tmp += dmap [ _c ] [ c3 ] * cn NEW_LINE DEDENT if minc is None : NEW_LINE INDENT minc = tmp NEW_LINE DEDENT elif minc > tmp : NEW_LINE INDENT minc = tmp NEW_LINE DEDENT DEDENT DEDENT DEDENT print ( minc ) NEW_LINE

from collections import Counter NEW_LINE from itertools import permutations NEW_LINE N , C = map ( int , input ( ) . split ( ) ) NEW_LINE cost = [ list ( map ( int , input ( ) . split ( ) ) ) for _ in range ( C ) ] NEW_LINE color = [ list ( map ( lambda x : int ( x ) - 1 , input ( ) . split ( ) ) ) for _ in range ( N ) ] NEW_LINE mod3 = { 0 : [ ] , 1 : [ ] , 2 : [ ] } NEW_LINE for i in range ( N ) : NEW_LINE INDENT for j in range ( N ) : NEW_LINE INDENT m = ( i + j ) % 3 NEW_LINE mod3 [ m ] . append ( color [ i ] [ j ] ) NEW_LINE DEDENT DEDENT cnts = [ Counter ( mod3 [ i ] ) for i in range ( 3 ) ] NEW_LINE cost_mod = [ [ - 1 ] * C for _ in range ( 3 ) ] NEW_LINE for i in range ( 3 ) : NEW_LINE INDENT for to_ in range ( C ) : NEW_LINE INDENT cond = 0 NEW_LINE for from_ in cnts [ i ] . keys ( ) : NEW_LINE INDENT cond += cnts [ i ] [ from_ ] * cost [ from_ ] [ to_ ] NEW_LINE DEDENT cost_mod [ i ] [ to_ ] = cond NEW_LINE DEDENT DEDENT ans = float ( ' inf ' ) NEW_LINE for p in permutations ( range ( C ) , 3 ) : NEW_LINE INDENT cond = 0 NEW_LINE for i in range ( 3 ) : NEW_LINE INDENT cond += cost_mod [ i ] [ p [ i ] ] NEW_LINE DEDENT ans = min ( ans , cond ) NEW_LINE DEDENT print ( ans ) NEW_LINE

n , c = [ int ( item ) for item in input ( ) . split ( ) ] NEW_LINE ds = [ [ int ( item ) for item in input ( ) . split ( ) ] for _ in range ( c ) ] NEW_LINE cs = [ [ int ( item ) for item in input ( ) . split ( ) ] for _ in range ( n ) ] NEW_LINE counter = [ [ 0 ] * ( c + 1 ) for _ in range ( 3 ) ] NEW_LINE for i in range ( n ) : NEW_LINE INDENT for j in range ( n ) : NEW_LINE INDENT counter [ ( i + j ) % 3 ] [ cs [ i ] [ j ] ] += 1 NEW_LINE DEDENT DEDENT costs = [ [ 0 ] * ( c + 1 ) for _ in range ( 3 ) ] NEW_LINE for i in range ( 1 , c + 1 ) : NEW_LINE INDENT for j in range ( 3 ) : NEW_LINE INDENT for k , count in enumerate ( counter [ j ] ) : NEW_LINE INDENT if k == 0 : NEW_LINE INDENT continue NEW_LINE DEDENT costs [ j ] [ i ] += ds [ k - 1 ] [ i - 1 ] * count NEW_LINE DEDENT DEDENT DEDENT ans = 500 * 500 * 1000 NEW_LINE for i in range ( c ) : NEW_LINE INDENT for j in range ( c ) : NEW_LINE INDENT for k in range ( c ) : NEW_LINE INDENT if i == j or j == k or k == i : NEW_LINE INDENT continue NEW_LINE DEDENT sol = costs [ 0 ] [ i + 1 ] + costs [ 1 ] [ j + 1 ] + costs [ 2 ] [ k + 1 ] NEW_LINE ans = min ( ans , sol ) NEW_LINE DEDENT DEDENT DEDENT print ( ans ) NEW_LINE

from collections import defaultdict NEW_LINE n , c = map ( int , input ( ) . split ( ) ) NEW_LINE x = [ list ( map ( int , input ( ) . split ( ) ) ) for i in range ( c ) ] NEW_LINE e = [ [ 0 ] * c for i in range ( 3 ) ] NEW_LINE for i in range ( n ) : NEW_LINE INDENT a = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE for j in range ( n ) : NEW_LINE INDENT e [ ( i + j + 2 ) % 3 ] [ a [ j ] - 1 ] += 1 NEW_LINE DEDENT DEDENT p = float ( " inf " ) NEW_LINE for i in range ( c ) : NEW_LINE INDENT for j in range ( c ) : NEW_LINE INDENT if i != j : NEW_LINE INDENT for h in range ( c ) : NEW_LINE INDENT if i != h and j != h : NEW_LINE INDENT p = min ( p , sum ( [ x [ s ] [ i ] * d for s , d in enumerate ( e [ 0 ] ) ] + [ x [ s ] [ j ] * d for s , d in enumerate ( e [ 1 ] ) ] + [ x [ s ] [ h ] * d for s , d in enumerate ( e [ 2 ] ) ] ) ) NEW_LINE DEDENT DEDENT DEDENT DEDENT DEDENT print ( p ) NEW_LINE