import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int n = in . nextInt ( ) ; String s = in . next ( ) ; char [ ] l = new char [ n ] ; char [ ] r = new char [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { l [ i ] = s . charAt ( i ) ; r [ i ] = s . charAt ( 2 * n - 1 - i ) ; } char [ ] [ ] buf = new char [ 2 ] [ n ] ; long count = 0 ; for ( int i = 0 ; i < ( 1 << n ) ; i ++ ) { int [ ] p = new int [ 2 ] ; for ( int j = 0 ; j < n ; j ++ ) { int k = ( i >> j ) & 1 ; buf [ k ] [ p [ k ] ++ ] = l [ j ] ; } long [ ] [ ] dp = new long [ p [ 0 ] + 1 ] [ p [ 1 ] + 1 ] ; dp [ 0 ] [ 0 ] = 1 ; for ( int x = 0 ; x <= p [ 0 ] ; x ++ ) { for ( int y = 0 ; y <= p [ 1 ] ; y ++ ) { if ( x < p [ 0 ] && r [ x + y ] == buf [ 0 ] [ x ] ) { dp [ x + 1 ] [ y ] += dp [ x ] [ y ] ; } if ( y < p [ 1 ] && r [ x + y ] == buf [ 1 ] [ y ] ) { dp [ x ] [ y + 1 ] += dp [ x ] [ y ] ; } } } count += dp [ p [ 0 ] ] [ p [ 1 ] ] ; } System . out . println ( count ) ; in . close ( ) ; } }

import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; String s = sc . next ( ) ; HashMap < String , Long > h = new HashMap < > ( ) ; for ( int i = 0 ; i < 1 << n ; i ++ ) { String red = " " ; String blue = " " ; for ( int j = 0 ; j < n ; j ++ ) { if ( ( i & ( 1 << j ) ) > 0 ) { red += s . charAt ( j ) ; } else { blue += s . charAt ( j ) ; } } String key = red + " : " + blue ; long tmp = h . getOrDefault ( key , 0L ) ; h . put ( key , tmp + 1 ) ; } long ans = 0 ; for ( int i = 0 ; i < 1 << n ; i ++ ) { String red = " " ; String blue = " " ; for ( int j = 0 ; j < n ; j ++ ) { if ( ( i & ( 1 << j ) ) > 0 ) { red += s . charAt ( 2 * n - 1 - j ) ; } else { blue += s . charAt ( 2 * n - 1 - j ) ; } } String key = red + " : " + blue ; long tmp = h . getOrDefault ( key , 0L ) ; ans += tmp ; } System . out . println ( ans ) ; } }

import java . util . * ; public class Main { public void main ( Scanner sc ) { int n = sc . nextInt ( ) ; String s = sc . next ( ) ; char s1 [ ] = s . substring ( 0 , n ) . toCharArray ( ) ; char s2 [ ] = new StringBuilder ( s . substring ( n , 2 * n ) ) . reverse ( ) . toString ( ) . toCharArray ( ) ; Map < String , Long > map1 = new HashMap < > ( ) ; Map < String , Long > map2 = new HashMap < > ( ) ; for ( int i = 0 ; i < ( 1 << n ) ; i ++ ) { StringBuilder red1 = new StringBuilder ( ) ; StringBuilder blue1 = new StringBuilder ( ) ; StringBuilder red2 = new StringBuilder ( ) ; StringBuilder blue2 = new StringBuilder ( ) ; for ( int j = 0 ; j < n ; j ++ ) { if ( ( i >> j ) % 2 == 1 ) { red1 . append ( s1 [ j ] ) ; blue2 . append ( s2 [ j ] ) ; } else { blue1 . append ( s1 [ j ] ) ; red2 . append ( s2 [ j ] ) ; } } String key1 = red1 . toString ( ) + " : " + blue1 . toString ( ) ; map1 . compute ( key1 , ( k , v ) -> v == null ? 1 : v + 1 ) ; String key2 = red2 . toString ( ) + " : " + blue2 . toString ( ) ; map2 . compute ( key2 , ( k , v ) -> v == null ? 1 : v + 1 ) ; } long sum = 0 ; for ( Map . Entry < String , Long > entry : map1 . entrySet ( ) ) { String key = entry . getKey ( ) ; sum += entry . getValue ( ) * map2 . getOrDefault ( key , 0L ) ; } System . out . println ( sum ) ; } public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; new Main ( ) . main ( sc ) ; sc . close ( ) ; } }

import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; String s = sc . next ( ) ; char [ ] a = new char [ n ] , b = new char [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = s . charAt ( i ) ; b [ i ] = s . charAt ( 2 * n - 1 - i ) ; } HashMap < String , Long > am = get ( a ) , bm = get ( b ) ; Set < String > keyset = am . keySet ( ) ; long res = 0 ; for ( String str : keyset ) { try { long aa = am . get ( str ) , bb = bm . get ( str ) ; res += aa * bb ; } catch ( Exception e ) { } } System . out . println ( res ) ; } static HashMap < String , Long > get ( char [ ] a ) { int n = a . length ; HashMap < String , Long > map = new HashMap < > ( ) ; int jou = 1 << n ; for ( int i = 0 ; i < jou ; i ++ ) { String tane = " " ; String taneb = " " ; for ( int j = 0 ; j < n ; j ++ ) { if ( ( ( i >> j ) & 1 ) == 1 ) { tane += a [ j ] ; } else { taneb += a [ j ] ; } } String key = tane + " : " + taneb ; if ( map . containsKey ( key ) ) { map . put ( key , map . get ( key ) + 1 ) ; } else map . put ( key , 1L ) ; } return map ; } }

n = int ( input ( ) ) NEW_LINE s = input ( ) NEW_LINE sl = s [ : n ] NEW_LINE sr = s [ n : ] [ : : - 1 ] NEW_LINE from collections import Counter NEW_LINE l = Counter ( ) NEW_LINE r = Counter ( ) NEW_LINE from itertools import product NEW_LINE for m in product ( [ False , True ] , repeat = n ) : NEW_LINE INDENT key = [ sl [ i ] for i in range ( n ) if not m [ i ] ] NEW_LINE key += [ ' - ' ] NEW_LINE key += [ sl [ i ] for i in range ( n ) if m [ i ] ] NEW_LINE l [ ' ' . join ( key ) ] += 1 NEW_LINE key = [ sr [ i ] for i in range ( n ) if not m [ i ] ] NEW_LINE key += [ ' - ' ] NEW_LINE key += [ sr [ i ] for i in range ( n ) if m [ i ] ] NEW_LINE r [ ' ' . join ( key ) ] += 1 NEW_LINE DEDENT ans = sum ( l [ lk ] * r [ lk ] for lk in l . keys ( ) ) NEW_LINE print ( ans ) NEW_LINE

import itertools as it NEW_LINE from collections import Counter as c NEW_LINE n = int ( input ( ) ) NEW_LINE a = c ( ) NEW_LINE b = c ( ) NEW_LINE s = input ( ) NEW_LINE q = s [ : n ] NEW_LINE r = s [ n : ] [ : : - 1 ] NEW_LINE for i in it . product ( [ 0 , 1 ] , repeat = n ) : NEW_LINE INDENT d , e , f , g = " " , " " , " " , " " NEW_LINE for j in range ( n ) : NEW_LINE INDENT if i [ j ] == 1 : NEW_LINE INDENT d += q [ j ] NEW_LINE f += r [ j ] NEW_LINE DEDENT else : NEW_LINE INDENT e += q [ j ] NEW_LINE g += r [ j ] NEW_LINE DEDENT DEDENT a [ d , e ] += 1 NEW_LINE b [ f , g ] += 1 NEW_LINE DEDENT print ( sum ( a [ i ] * b [ i ] for i in a . keys ( ) ) ) NEW_LINE

from itertools import product , compress NEW_LINE from collections import Counter NEW_LINE N = int ( input ( ) ) NEW_LINE Ss = input ( ) NEW_LINE S1s = Ss [ : N ] NEW_LINE ptn1s = [ ' ' . join ( compress ( S1s , sels ) ) for sels in product ( range ( 2 ) , repeat = N ) ] NEW_LINE cnt1 = Counter ( [ ( red , blue ) for red , blue in zip ( ptn1s , reversed ( ptn1s ) ) ] ) NEW_LINE S2s = Ss [ N : ] [ : : - 1 ] NEW_LINE ptn2s = [ ' ' . join ( compress ( S2s , sels ) ) for sels in product ( range ( 2 ) , repeat = N ) ] NEW_LINE cnt2 = Counter ( [ ( red , blue ) for red , blue in zip ( ptn2s , reversed ( ptn2s ) ) ] ) NEW_LINE ans = 0 NEW_LINE for ptn1 , num1 in cnt1 . items ( ) : NEW_LINE INDENT ans += num1 * cnt2 [ ptn1 ] NEW_LINE DEDENT print ( ans ) NEW_LINE

def run ( n , s ) : NEW_LINE INDENT sl = s [ 0 : n ] NEW_LINE sr = s [ n : 2 * n ] [ : : - 1 ] NEW_LINE dic = { } NEW_LINE keys = [ ] NEW_LINE cnt = 0 NEW_LINE for i in range ( 2 ** n ) : NEW_LINE INDENT red , blue , red2 , blue2 = ' ' , ' ' , ' ' , ' ' NEW_LINE bits = bin ( 2 ** n + i ) [ 3 : ] NEW_LINE for j in range ( n ) : NEW_LINE INDENT if bits [ j ] == '0' : NEW_LINE INDENT red += sl [ j ] NEW_LINE red2 += sr [ j ] NEW_LINE DEDENT else : NEW_LINE INDENT blue += sl [ j ] NEW_LINE blue2 += sr [ j ] NEW_LINE DEDENT DEDENT keys . append ( red2 + ' - ' + blue2 ) NEW_LINE key = red + ' - ' + blue NEW_LINE if key not in dic . keys ( ) : NEW_LINE INDENT dic [ key ] = 1 NEW_LINE DEDENT else : NEW_LINE INDENT dic [ key ] += 1 NEW_LINE DEDENT DEDENT for key in keys : NEW_LINE INDENT cnt += dic . get ( key , 0 ) NEW_LINE DEDENT return cnt NEW_LINE DEDENT def read_line ( ) : NEW_LINE INDENT n = int ( input ( ) ) NEW_LINE s = input ( ) NEW_LINE return ( n , s ) NEW_LINE DEDENT def main ( ) : NEW_LINE INDENT n , s = read_line ( ) NEW_LINE print ( run ( n , s ) ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT

from itertools import product NEW_LINE from collections import defaultdict NEW_LINE n = int ( input ( ) ) NEW_LINE s = input ( ) NEW_LINE sa , sb = s [ : n ] , s [ n : ] [ : : - 1 ] NEW_LINE a , b , ans = defaultdict ( int ) , defaultdict ( int ) , 0 NEW_LINE for p in product ( range ( 2 ) , repeat = n ) : NEW_LINE INDENT word_a_1 , word_b_1 , word_a_2 , word_b_2 = " " , " " , " " , " " NEW_LINE for j in range ( n ) : NEW_LINE INDENT if p [ j ] : NEW_LINE INDENT word_a_1 += sa [ j ] NEW_LINE word_b_1 += sb [ j ] NEW_LINE DEDENT else : NEW_LINE INDENT word_a_2 += sa [ j ] NEW_LINE word_b_2 += sb [ j ] NEW_LINE DEDENT DEDENT a [ ( word_a_1 , word_a_2 ) ] += 1 NEW_LINE b [ ( word_b_1 , word_b_2 ) ] += 1 NEW_LINE DEDENT while a : NEW_LINE INDENT key , value = a . popitem ( ) NEW_LINE ans += value * b [ key ] NEW_LINE DEDENT print ( ans ) NEW_LINE


import java . io . OutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . PrintWriter ; import java . io . UncheckedIOException ; import java . util . StringTokenizer ; import java . io . IOException ; import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . io . InputStream ; public class Main { public static void main ( String [ ] args ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; LightScanner in = new LightScanner ( 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 , LightScanner in , PrintWriter out ) { out . println ( ( int ) Math . pow ( in . ints ( ) , 0.25 ) ) ; } } static class LightScanner { private BufferedReader reader = null ; private StringTokenizer tokenizer = null ; public LightScanner ( InputStream in ) { reader = new BufferedReader ( new InputStreamReader ( in ) ) ; } public String string ( ) { if ( tokenizer == null || ! tokenizer . hasMoreTokens ( ) ) { try { tokenizer = new StringTokenizer ( reader . readLine ( ) ) ; } catch ( IOException e ) { throw new UncheckedIOException ( e ) ; } } return tokenizer . nextToken ( ) ; } public int ints ( ) { return Integer . parseInt ( string ( ) ) ; } } }

import java . util . Scanner ; class Main { static int n ; static long ans = 1000000000 ; static int [ ] memo ; static int [ ] dp ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; long ans = ( long ) Math . sqrt ( a ) ; ans = ( long ) Math . sqrt ( 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 . io . OutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . PrintWriter ; import java . util . InputMismatchException ; import java . io . IOException ; import java . io . InputStream ; public class Main { public static void main ( String [ ] args ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; FastScanner in = new FastScanner ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; TaskB solver = new TaskB ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class TaskB { public void solve ( int testNumber , FastScanner in , PrintWriter out ) { int n = in . nextInt ( ) ; out . println ( ( int ) Math . sqrt ( Math . sqrt ( n ) ) ) ; } } static class FastScanner { private InputStream in ; private byte [ ] buffer = new byte [ 1024 ] ; private int bufPointer ; private int bufLength ; public FastScanner ( InputStream in ) { this . in = in ; } private int readByte ( ) { if ( bufPointer >= bufLength ) { if ( bufLength == - 1 ) throw new InputMismatchException ( ) ; bufPointer = 0 ; try { bufLength = in . read ( buffer ) ; } catch ( IOException e ) { throw new InputMismatchException ( ) ; } if ( bufLength <= 0 ) return - 1 ; } return buffer [ bufPointer ++ ] ; } private static boolean isSpaceChar ( int c ) { return c == ' ▁ ' || c == ' \n ' || c == ' \r ' || c == ' \t ' || c == - 1 ; } public long nextLong ( ) { long n = 0 ; int b = readByte ( ) ; while ( isSpaceChar ( b ) ) b = readByte ( ) ; boolean minus = ( b == ' - ' ) ; if ( minus ) b = readByte ( ) ; while ( b >= '0' && b <= '9' ) { n *= 10 ; n += b - '0' ; b = readByte ( ) ; } if ( ! isSpaceChar ( b ) ) throw new NumberFormatException ( ) ; return minus ? - n : n ; } public int nextInt ( ) { long n = nextLong ( ) ; if ( n < Integer . MIN_VALUE || n > Integer . MAX_VALUE ) throw new NumberFormatException ( ) ; return ( int ) n ; } } }

import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; double N = sc . nextDouble ( ) ; N = Math . sqrt ( N ) ; N = Math . sqrt ( N ) ; System . out . println ( ( int ) N ) ; } }

import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long x = sc . nextLong ( ) ; int ans = 1 ; for ( int i = 1 ; i < x ; i ++ ) { long tmp = i * i * i * i ; if ( tmp == x ) { ans = i ; break ; } else if ( tmp > x ) break ; } System . out . println ( ans ) ; } }

X = int ( input ( ) ) NEW_LINE tmp = 1 NEW_LINE while 10 ** 9 > tmp : NEW_LINE INDENT if tmp ** 4 == X : NEW_LINE INDENT print ( tmp ) NEW_LINE break NEW_LINE DEDENT else : NEW_LINE INDENT tmp += 1 NEW_LINE DEDENT DEDENT

import math NEW_LINE x = int ( input ( ) ) NEW_LINE print ( int ( math . sqrt ( math . sqrt ( x ) ) ) ) NEW_LINE

def agent_takahashi ( X : int ) -> int : NEW_LINE INDENT for n in range ( 400 ) : NEW_LINE INDENT if n * n * n * n == X : NEW_LINE INDENT return n NEW_LINE DEDENT DEDENT return - 1 NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT X = int ( input ( ) ) NEW_LINE ans = agent_takahashi ( X ) NEW_LINE print ( ans ) NEW_LINE DEDENT

print ( int ( int ( input ( ) ) ** 0.25 ) ) NEW_LINE

x = int ( input ( ) ) NEW_LINE for i in range ( x + 1 ) : NEW_LINE INDENT if i ** 4 == x : NEW_LINE INDENT print ( i ) NEW_LINE exit ( ) NEW_LINE DEDENT DEDENT


import java . util . * ; import java . util . Map . Entry ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; HashMap < Integer , Integer > m = new HashMap < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { int a = sc . nextInt ( ) ; m . put ( a , m . containsKey ( a ) ? m . get ( a ) + 1 : 1 ) ; } int s = 0 ; for ( Entry < Integer , Integer > e : m . entrySet ( ) ) { int k = e . getKey ( ) ; int v = e . getValue ( ) ; if ( k <= v ) { s += v - k ; } else { s += v ; } } System . out . println ( s ) ; } }

import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . Arrays ; import java . util . StringTokenizer ; public class Main { int n ; int [ ] as ; public static void main ( String args [ ] ) { new Main ( ) . run ( ) ; } void run ( ) { FastReader sc = new FastReader ( ) ; n = sc . nextInt ( ) ; as = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { as [ i ] = sc . nextInt ( ) ; } solve ( ) ; } void solve ( ) { Arrays . sort ( as ) ; int ans = 0 ; int count = 0 ; for ( int i = 1 ; i < n ; i ++ ) { count ++ ; if ( as [ i - 1 ] < as [ i ] ) { if ( count < as [ i - 1 ] ) { ans += count ; } else { ans += count - as [ i - 1 ] ; } count = 0 ; } } count ++ ; if ( count < as [ as . length - 1 ] ) { ans += count ; } else { ans += count - as [ as . length - 1 ] ; } 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 . HashMap ; import java . util . Map ; import java . util . Scanner ; import java . util . stream . IntStream ; class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int N = scan . nextInt ( ) ; int [ ] a = IntStream . range ( 0 , N ) . map ( i -> scan . nextInt ( ) ) . toArray ( ) ; Map < Integer , Integer > map = new HashMap < > ( ) ; for ( int i = 0 ; i < N ; ++ i ) { if ( ! map . containsKey ( a [ i ] ) ) { map . put ( a [ i ] , 0 ) ; } map . put ( a [ i ] , map . get ( a [ i ] ) + 1 ) ; } int ans = 0 ; for ( Map . Entry < Integer , Integer > entry : map . entrySet ( ) ) { if ( entry . getKey ( ) > entry . getValue ( ) ) { ans += entry . getValue ( ) ; } else { ans += entry . getValue ( ) - entry . getKey ( ) ; } } System . out . println ( ans ) ; } }

import java . util . ArrayList ; import java . util . Collections ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; ArrayList < Integer > list = new ArrayList < > ( ) ; int num = scanner . nextInt ( ) ; for ( int i = 0 ; i < num ; i ++ ) { list . add ( scanner . nextInt ( ) ) ; } scanner . close ( ) ; Collections . sort ( list ) ; int stock = 0 ; int count = 0 ; int stockNum = 0 ; for ( int i : list ) { if ( stock != i ) { stock = i ; count = i ; } count -- ; if ( count == 0 ) { stockNum += stock ; } } System . out . println ( list . size ( ) - stockNum ) ; } }

import java . util . HashMap ; import java . util . Map ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; while ( sc . hasNextInt ( ) ) { int N = sc . nextInt ( ) ; Map < Integer , Integer > cnt = new HashMap < > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { int x = sc . nextInt ( ) ; int c = 1 ; if ( cnt . containsKey ( x ) ) { c = cnt . get ( x ) + 1 ; } cnt . put ( x , c ) ; } int ans = 0 ; for ( int x : cnt . keySet ( ) ) { int c = cnt . get ( x ) ; if ( c < x ) { ans += c ; } else if ( c > x ) { ans += c - x ; } } System . out . println ( ans ) ; } } }

import collections NEW_LINE n = int ( input ( ) ) NEW_LINE a = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE c = collections . Counter ( a ) NEW_LINE k = 0 NEW_LINE for s , t in c . items ( ) : NEW_LINE INDENT if t < s : NEW_LINE INDENT k += t NEW_LINE DEDENT else : NEW_LINE INDENT k += t - s NEW_LINE DEDENT DEDENT print ( k ) NEW_LINE

from collections import defaultdict NEW_LINE def getN ( ) : NEW_LINE INDENT return int ( input ( ) ) NEW_LINE DEDENT def getMN ( ) : NEW_LINE INDENT a = input ( ) . split ( ) NEW_LINE b = [ int ( i ) for i in a ] NEW_LINE return b [ 0 ] , b [ 1 ] NEW_LINE DEDENT def getlist ( ) : NEW_LINE INDENT a = input ( ) . split ( ) NEW_LINE b = [ int ( i ) for i in a ] NEW_LINE return b NEW_LINE DEDENT n = getN ( ) NEW_LINE nums = getlist ( ) NEW_LINE kazu = defaultdict ( int ) NEW_LINE for i in nums : NEW_LINE INDENT kazu [ i ] += 1 NEW_LINE DEDENT ans = 0 NEW_LINE for x in kazu . keys ( ) : NEW_LINE INDENT if kazu [ x ] >= x : NEW_LINE INDENT ans += kazu [ x ] - x NEW_LINE DEDENT else : NEW_LINE INDENT ans += kazu [ x ] NEW_LINE DEDENT DEDENT print ( ans ) NEW_LINE

import sys NEW_LINE stdin = sys . stdin NEW_LINE sys . setrecursionlimit ( 10 ** 5 ) NEW_LINE def li ( ) : return map ( int , stdin . readline ( ) . split ( ) ) NEW_LINE def li_ ( ) : return map ( lambda x : int ( x ) - 1 , stdin . readline ( ) . split ( ) ) NEW_LINE def lf ( ) : return map ( float , stdin . readline ( ) . split ( ) ) NEW_LINE def ls ( ) : return stdin . readline ( ) . split ( ) NEW_LINE def ns ( ) : return stdin . readline ( ) . rstrip ( ) NEW_LINE def lc ( ) : return list ( ns ( ) ) NEW_LINE def ni ( ) : return int ( stdin . readline ( ) ) NEW_LINE def nf ( ) : return float ( stdin . readline ( ) ) NEW_LINE from collections import Counter NEW_LINE n = ni ( ) NEW_LINE a = list ( li ( ) ) NEW_LINE cnt = Counter ( a ) NEW_LINE ans = 0 NEW_LINE for k , v in cnt . items ( ) : NEW_LINE INDENT if v < k : NEW_LINE INDENT ans += v NEW_LINE DEDENT elif v > k : NEW_LINE INDENT ans += ( v - k ) NEW_LINE DEDENT DEDENT print ( ans ) NEW_LINE

n , * a = map ( int , open ( 0 ) . read ( ) . split ( ) ) NEW_LINE d = { } NEW_LINE for i in a : d [ i ] = d . get ( i , 0 ) + 1 NEW_LINE print ( sum ( d [ i ] - i * ( d [ i ] >= i ) for i in d ) ) NEW_LINE

import collections NEW_LINE def inpl ( ) : return [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE N = int ( input ( ) ) NEW_LINE A = collections . Counter ( inpl ( ) ) NEW_LINE ans = 0 NEW_LINE for i in A . keys ( ) : NEW_LINE INDENT if i > A [ i ] : NEW_LINE INDENT ans += A [ i ] NEW_LINE DEDENT else : NEW_LINE INDENT ans += A [ i ] - i NEW_LINE DEDENT DEDENT print ( ans ) NEW_LINE


import java . io . PrintWriter ; import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; PrintWriter pw = new PrintWriter ( System . out ) ; int N = sc . nextInt ( ) ; int D = sc . nextInt ( ) ; int [ ] x = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) x [ i ] = sc . nextInt ( ) ; int Q = sc . nextInt ( ) ; long [ ] qq = new long [ Q ] ; for ( int i = 0 ; i < Q ; i ++ ) qq [ i ] = ( sc . nextLong ( ) - 1 ) << 30 | i ; Arrays . sort ( qq ) ; int [ ] rest = new int [ N + 1 ] ; rest [ 0 ] = D ; for ( int i = 0 ; i < N ; i ++ ) rest [ i + 1 ] = Math . min ( rest [ i ] , Math . abs ( rest [ i ] - x [ i ] ) ) ; boolean [ ] ans = new boolean [ Q ] ; long range = 0 ; int idx = Q - 1 ; for ( int i = N - 1 ; i >= 0 ; i -- ) { while ( idx >= 0 && ( qq [ idx ] >> 30 ) == i ) { if ( rest [ i ] > range ) { ans [ ( int ) ( qq [ idx ] & ( ( 1 << 30 ) - 1 ) ) ] = true ; } idx -- ; } if ( x [ i ] <= range * 2 + 1 ) { range += x [ i ] ; } } for ( int i = 0 ; i < Q ; i ++ ) pw . println ( ans [ i ] ? " YES " : " NO " ) ; sc . close ( ) ; pw . close ( ) ; } }

N , D = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE d = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE Q = int ( input ( ) ) NEW_LINE q = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE a = [ D for i in range ( N ) ] NEW_LINE b = [ 1 for i in range ( N + 1 ) ] NEW_LINE for i in range ( 1 , N ) : NEW_LINE INDENT a [ i ] = min ( abs ( a [ i - 1 ] - d [ i - 1 ] ) , a [ i - 1 ] ) NEW_LINE DEDENT for i in range ( N ) [ : : - 1 ] : NEW_LINE INDENT if d [ i ] // 2 < b [ i + 1 ] : NEW_LINE INDENT b [ i ] = b [ i + 1 ] + d [ i ] NEW_LINE DEDENT else : NEW_LINE INDENT b [ i ] = b [ i + 1 ] NEW_LINE DEDENT DEDENT res = " " NEW_LINE for i in q : NEW_LINE INDENT if a [ i - 1 ] < b [ i ] : NEW_LINE INDENT res += " NO " NEW_LINE DEDENT else : NEW_LINE INDENT res += " YES " NEW_LINE DEDENT res += " \n " NEW_LINE DEDENT print ( res ) NEW_LINE

import sys NEW_LINE import math NEW_LINE N , D = map ( int , sys . stdin . readline ( ) . rstrip ( ) . split ( ) ) NEW_LINE ds = list ( map ( int , sys . stdin . readline ( ) . rstrip ( ) . split ( ) ) ) NEW_LINE Q , = map ( int , sys . stdin . readline ( ) . rstrip ( ) . split ( ) ) NEW_LINE qs = list ( map ( int , sys . stdin . readline ( ) . rstrip ( ) . split ( ) ) ) NEW_LINE targets = [ 1 ] NEW_LINE for d in reversed ( ds ) : NEW_LINE INDENT if ( d // 2 < targets [ - 1 ] ) : NEW_LINE INDENT targets . append ( targets [ - 1 ] + d ) NEW_LINE DEDENT else : NEW_LINE INDENT targets . append ( targets [ - 1 ] ) NEW_LINE DEDENT DEDENT targets . reverse ( ) NEW_LINE current = D NEW_LINE can_avoids = [ ] NEW_LINE for i in range ( N ) : NEW_LINE INDENT d = ds [ i ] NEW_LINE target = targets [ i + 1 ] NEW_LINE can_avoids . append ( current >= target ) NEW_LINE if d // 2 < current : NEW_LINE INDENT current -= d NEW_LINE current = max ( - current , current ) NEW_LINE DEDENT DEDENT for q in qs : NEW_LINE INDENT if ( can_avoids [ q - 1 ] ) : NEW_LINE INDENT print ( " YES " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " NO " ) NEW_LINE DEDENT DEDENT exit ( 0 ) NEW_LINE

N , start = map ( int , input ( ) . split ( ) ) NEW_LINE D = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE input ( ) NEW_LINE Q = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE Q = [ ( k - 1 , i ) for i , k in enumerate ( Q ) ] NEW_LINE Q . sort ( ) NEW_LINE P = [ start ] NEW_LINE for d in D : NEW_LINE INDENT a = P [ - 1 ] NEW_LINE b = abs ( a - d ) NEW_LINE P . append ( min ( a , b ) ) NEW_LINE DEDENT result = [ None ] * len ( Q ) NEW_LINE x = 1 NEW_LINE for i , d in zip ( reversed ( range ( len ( D ) ) ) , reversed ( D ) ) : NEW_LINE INDENT if Q [ - 1 ] [ 0 ] == i : NEW_LINE INDENT result [ Q [ - 1 ] [ 1 ] ] = P [ i ] >= x NEW_LINE Q . pop ( ) NEW_LINE if not Q : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT if abs ( x - d ) < x : NEW_LINE INDENT x += d NEW_LINE DEDENT DEDENT for r in result : NEW_LINE INDENT print ( ' YES ' if r else ' NO ' ) NEW_LINE DEDENT

N , D = map ( int , input ( ) . split ( ) ) NEW_LINE ds = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE Q = int ( input ( ) ) NEW_LINE querys = list ( map ( lambda x : int ( x ) - 1 , input ( ) . split ( ) ) ) NEW_LINE ps = [ 0 ] * ( N + 1 ) NEW_LINE ps [ 0 ] = D NEW_LINE for i in range ( N ) : NEW_LINE INDENT ps [ i + 1 ] = min ( abs ( ps [ i ] - ds [ i ] ) , ps [ i ] ) NEW_LINE DEDENT if ps [ N ] != 0 : NEW_LINE INDENT print ( ' \n ' . join ( [ ' YES ' ] * Q ) ) NEW_LINE exit ( ) NEW_LINE DEDENT ms = [ 0 ] * ( N + 1 ) NEW_LINE for i in range ( N ) [ : : - 1 ] : NEW_LINE INDENT if ms [ i + 1 ] + 1 >= ds [ i ] - ms [ i + 1 ] : NEW_LINE INDENT ms [ i ] = ms [ i + 1 ] + ds [ i ] NEW_LINE DEDENT else : NEW_LINE INDENT ms [ i ] = ms [ i + 1 ] NEW_LINE DEDENT DEDENT for q in querys : NEW_LINE INDENT if ps [ q ] <= ms [ q + 1 ] : NEW_LINE INDENT print ( ' NO ' ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( ' YES ' ) NEW_LINE DEDENT DEDENT

N , D = map ( int , input ( ) . split ( ) ) NEW_LINE dv = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE Q = int ( input ( ) ) NEW_LINE qv = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE dist_alice = D NEW_LINE dist_alice_list = [ D ] NEW_LINE for i in range ( N ) : NEW_LINE INDENT if dist_alice >= dv [ i ] : NEW_LINE INDENT dist_alice -= dv [ i ] NEW_LINE DEDENT elif 2 * dist_alice >= dv [ i ] : NEW_LINE INDENT dist_alice = dv [ i ] - dist_alice NEW_LINE DEDENT dist_alice_list . append ( dist_alice ) NEW_LINE DEDENT sol_min = [ 1 ] NEW_LINE sol_min_ = 1 NEW_LINE for i in range ( N - 1 , - 1 , - 1 ) : NEW_LINE INDENT if 2 * sol_min_ > dv [ i ] : NEW_LINE INDENT sol_min_ += dv [ i ] NEW_LINE DEDENT sol_min . append ( sol_min_ ) NEW_LINE DEDENT for i in range ( Q ) : NEW_LINE INDENT if dist_alice_list [ qv [ i ] - 1 ] >= sol_min [ N - qv [ i ] ] : NEW_LINE INDENT print ( " YES " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " NO " ) NEW_LINE DEDENT DEDENT


import java . util . * ; 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 ( ) ; int min = a [ 0 ] ; int max = a [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { if ( a [ i ] < min ) min = a [ i ] ; else if ( a [ i ] > max ) max = a [ i ] ; } boolean [ ] hash = new boolean [ max - min + 1 ] ; for ( int i = 0 ; i < hash . length ; i ++ ) hash [ i ] = false ; int identity = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( ! hash [ a [ i ] - min ] ) { identity ++ ; hash [ a [ i ] - min ] = true ; } } System . out . println ( String . valueOf ( identity - ( ( identity + 1 ) % 2 ) ) ) ; } }

import java . util . * ; import java . io . * ; import static java . lang . Math . * ; import static java . util . Arrays . * ; import static java . util . Collections . * ; public class Main { static final long mod = 1000000007 ; public static void main ( String [ ] args ) throws Exception , IOException { Reader sc = new Reader ( System . in ) ; PrintWriter out = new PrintWriter ( System . out ) ; int n = sc . nextInt ( ) ; int a [ ] = new int [ 100001 ] ; int ans = 0 , even = 0 , odd = 0 ; for ( int i = 0 ; i < n ; i ++ ) { a [ sc . nextInt ( ) ] ++ ; } for ( int i = 0 ; i < a . length ; i ++ ) { if ( a [ i ] > 0 ) { if ( a [ i ] % 2 == 0 ) even ++ ; ans ++ ; } } if ( even % 2 == 1 ) ans -- ; out . println ( ans ) ; out . flush ( ) ; } static void db ( Object ... os ) { System . err . println ( Arrays . deepToString ( os ) ) ; } } class P implements Comparable < P > { int id , d ; P ( int id , int d ) { this . id = id ; this . d = d ; } public int compareTo ( P p ) { return d - p . d ; } } class Reader { private BufferedReader x ; private StringTokenizer st ; public Reader ( InputStream in ) { x = new BufferedReader ( new InputStreamReader ( in ) ) ; st = null ; } public String nextString ( ) throws IOException { while ( st == null || ! st . hasMoreTokens ( ) ) st = new StringTokenizer ( x . readLine ( ) ) ; return st . nextToken ( ) ; } public int nextInt ( ) throws IOException { return Integer . parseInt ( nextString ( ) ) ; } public long nextLong ( ) throws IOException { return Long . parseLong ( nextString ( ) ) ; } public double nextDouble ( ) throws IOException { return Double . parseDouble ( nextString ( ) ) ; } }

import java . io . IOException ; import java . util . ArrayList ; import java . util . HashMap ; 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 ) { int N = Integer . parseInt ( inLines . get ( 0 ) ) ; String [ ] strArr = inLines . get ( 1 ) . split ( " ▁ " ) ; HashMap < Integer , Integer > map = new HashMap < Integer , Integer > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { int An = Integer . parseInt ( strArr [ i ] ) ; if ( map . containsKey ( An ) ) map . put ( An , map . get ( An ) + 1 ) ; else map . put ( An , 1 ) ; } int cnt = 0 ; for ( int key : map . keySet ( ) ) { if ( map . get ( key ) % 2 == 0 ) { cnt ++ ; } } if ( cnt % 2 == 0 ) System . out . println ( map . size ( ) ) ; else System . out . println ( map . size ( ) - 1 ) ; } }

import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . * ; public class Main { int n ; int [ ] as ; public static void main ( String args [ ] ) { new Main ( ) . run ( ) ; } void run ( ) { FastReader sc = new FastReader ( ) ; n = sc . nextInt ( ) ; as = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { as [ i ] = sc . nextInt ( ) ; } solve ( ) ; } void solve ( ) { Arrays . sort ( as ) ; Set < Integer > set = new HashSet < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { set . add ( as [ i ] ) ; } if ( set . size ( ) % 2 == 1 ) { System . out . println ( set . size ( ) ) ; } else { System . out . println ( set . size ( ) - 1 ) ; } } 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 . lang . * ; import java . io . * ; class Counter < T > extends HashMap < T , Integer > { public Counter ( ) { super ( ) ; } public Counter ( T [ ] array ) { super ( ) ; for ( int i = 0 ; i < array . length ; i ++ ) add ( array [ i ] ) ; } public Integer get ( Object elm ) { return getOrDefault ( elm , 0 ) ; } public void add ( T elm ) { put ( elm , get ( elm ) + 1 ) ; } } public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; Integer [ ] A = new Integer [ N ] ; for ( int n = 0 ; n < N ; n ++ ) A [ n ] = sc . nextInt ( ) ; Counter < Integer > count = new Counter ( A ) ; if ( ( N - count . size ( ) ) % 2 == 0 ) System . out . println ( count . size ( ) ) ; else System . out . println ( count . size ( ) - 1 ) ; } } Note : . / Main . java uses unchecked or unsafe operations . Note : Recompile with - Xlint : unchecked for details .

n = int ( input ( ) ) NEW_LINE lis = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE ans = set ( ) NEW_LINE for num in lis : ans . add ( num ) NEW_LINE print ( len ( ans ) - ( ( len ( ans ) % 2 ) + 1 ) % 2 ) NEW_LINE

from functools import reduce NEW_LINE import math NEW_LINE def main ( ) : NEW_LINE INDENT N = int ( input ( ) . rstrip ( ) ) NEW_LINE A = list ( int ( _ ) for _ in input ( ) . split ( ) ) NEW_LINE dict = { } NEW_LINE for a in A : NEW_LINE INDENT if a in dict : NEW_LINE INDENT dict [ a ] += 1 NEW_LINE DEDENT else : NEW_LINE INDENT dict [ a ] = 1 NEW_LINE DEDENT DEDENT sum = 0 NEW_LINE for v in dict . values ( ) : NEW_LINE INDENT if v >= 2 : NEW_LINE INDENT sum += v - 1 NEW_LINE DEDENT DEDENT if sum % 2 == 0 : NEW_LINE INDENT ans = len ( dict ) NEW_LINE DEDENT else : NEW_LINE INDENT ans = len ( dict ) - 1 NEW_LINE DEDENT print ( ans ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT

from collections import Counter NEW_LINE def inpl ( ) : NEW_LINE INDENT return list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE DEDENT N = int ( input ( ) ) NEW_LINE A = inpl ( ) NEW_LINE oe = [ 0 , 0 ] NEW_LINE for k , v in Counter ( A ) . items ( ) : NEW_LINE INDENT oe [ v % 2 ] += 1 NEW_LINE DEDENT if oe [ 0 ] % 2 == 0 : NEW_LINE INDENT print ( sum ( oe ) ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( sum ( oe ) - 1 ) NEW_LINE DEDENT

def main ( ) : NEW_LINE INDENT n = int ( input ( ) ) NEW_LINE an = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE k = len ( set ( an ) ) NEW_LINE res = k - 1 if k % 2 == 0 else k NEW_LINE print ( res ) NEW_LINE DEDENT main ( ) NEW_LINE

from collections import Counter NEW_LINE import sys NEW_LINE sys . setrecursionlimit ( 10 ** 9 ) NEW_LINE input = sys . stdin . readline NEW_LINE N = int ( input ( ) ) NEW_LINE Num = list ( input ( ) . split ( ) ) NEW_LINE C = Counter ( Num ) NEW_LINE ans = 0 NEW_LINE l = [ 0 ] NEW_LINE v = len ( C ) NEW_LINE odd = len ( list ( filter ( lambda x : x % 2 == 1 , C . values ( ) ) ) ) NEW_LINE even = v - odd NEW_LINE ans += odd + even // 2 * 2 NEW_LINE print ( ans ) NEW_LINE


import java . util . * ; public class Main { public static void main ( String args [ ] ) { Scanner scanner = new Scanner ( System . in ) ; String name = scanner . next ( ) ; boolean flag = true ; for ( int i = 0 ; i < name . length ( ) / 2 ; i ++ ) { if ( name . charAt ( i ) != name . charAt ( name . length ( ) - 1 - i ) ) { flag = false ; break ; } } if ( flag ) { System . out . println ( " YES " ) ; } else { System . out . println ( " NO " ) ; } } }

import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { new Main ( ) . solveA ( ) ; } private void solveA ( ) { Scanner scanner = null ; char [ ] name = null ; try { scanner = new Scanner ( System . in ) ; name = scanner . next ( ) . toCharArray ( ) ; int half = name . length % 2 == 0 ? name . length / 2 : ( name . length / 2 ) + 1 ; int length = name . length - 1 ; boolean isKaibun = true ; for ( int i = 0 ; i < half ; i ++ ) { if ( name [ i ] != name [ length - i ] ) { isKaibun = false ; } } if ( isKaibun ) { System . out . println ( " YES " ) ; } else { System . out . println ( " NO " ) ; } } finally { if ( scanner != null ) { scanner . close ( ) ; } } } private void solveB ( ) { Scanner scanner = null ; int numN = 0 ; int numK = 0 ; int numS = 0 ; try { scanner = new Scanner ( System . in ) ; numN = scanner . nextInt ( ) ; System . out . println ( " " ) ; } finally { if ( scanner != null ) { scanner . close ( ) ; } } } private void solveC ( ) { Scanner scanner = null ; int numN = 0 ; int numK = 0 ; int numS = 0 ; try { scanner = new Scanner ( System . in ) ; numN = scanner . nextInt ( ) ; System . out . println ( " " ) ; } finally { if ( scanner != null ) { scanner . close ( ) ; } } } private void solveD ( ) { Scanner scanner = null ; int numN = 0 ; int numK = 0 ; int numS = 0 ; try { scanner = new Scanner ( System . in ) ; numN = scanner . nextInt ( ) ; System . out . println ( " " ) ; } finally { if ( scanner != null ) { scanner . close ( ) ; } } } }

import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String name = sc . next ( ) ; String names [ ] = name . split ( " " ) ; String ans = " " ; if ( name . length ( ) % 2 == 0 ) { String a = name . substring ( 0 , name . length ( ) / 2 ) ; String b = name . substring ( ( name . length ( ) / 2 ) , name . length ( ) ) ; String [ ] aa = a . split ( " " ) ; String [ ] bb = b . split ( " " ) ; for ( int i = 0 ; i < a . length ( ) ; i ++ ) { if ( ! aa [ i ] . equals ( bb [ b . length ( ) - ( i + 1 ) ] ) ) { ans = " NO " ; } else { ans = " YES " ; } } } else { int j = name . length ( ) - 1 ; int l = ( j / 2 ) ; String c = name . substring ( 0 , l ) ; String d = name . substring ( l + 1 , name . length ( ) ) ; String [ ] cc = c . split ( " " ) ; String [ ] dd = d . split ( " " ) ; for ( int k = 0 ; k < l ; k ++ ) { if ( ! cc [ k ] . equals ( dd [ d . length ( ) - ( k + 1 ) ] ) ) { ans = " NO " ; } else { ans = " YES " ; } } } System . out . println ( ans ) ; } }

import java . util . Scanner ; public class Main { static Scanner s = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { char [ ] in = s . next ( ) . toCharArray ( ) ; for ( int i = in . length / 2 ; i >= 0 ; i -- ) { if ( in [ in . length - i - 1 ] != in [ i ] ) { System . out . println ( " NO " ) ; return ; } } System . out . println ( " YES " ) ; } }

import java . util . * ; import java . awt . * ; import static java . lang . System . * ; import static java . lang . Math . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( in ) ; String s = sc . next ( ) ; for ( int i = 0 ; i < s . length ( ) / 2 ; i ++ ) { if ( s . charAt ( i ) != s . charAt ( s . length ( ) - 1 - i ) ) { out . println ( " NO " ) ; exit ( 0 ) ; } } out . println ( " YES " ) ; } }

s = input ( ) NEW_LINE n = len ( s ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT if s [ i ] != s [ n - 1 - i ] : NEW_LINE INDENT print ( " NO " ) NEW_LINE exit ( ) NEW_LINE DEDENT DEDENT print ( " YES " ) NEW_LINE

s = str ( input ( ) ) NEW_LINE S = s [ : : - 1 ] NEW_LINE if s == S : NEW_LINE INDENT print ( " YES " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " NO " ) NEW_LINE DEDENT

Name = input ( ) NEW_LINE print ( ' YES ' if all ( [ Name [ k ] == Name [ - 1 - k ] for k in range ( len ( Name ) // 2 ) ] ) else ' NO ' ) NEW_LINE

s = input ( ) NEW_LINE x = len ( s ) NEW_LINE if x % 2 == 1 : NEW_LINE INDENT a = s [ : x // 2 ] NEW_LINE b = s [ x // 2 + 1 : ] [ : : - 1 ] NEW_LINE if a == b : NEW_LINE INDENT print ( " YES " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " NO " ) NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT a = s [ : x // 2 ] NEW_LINE b = s [ x // 2 : ] [ : : - 1 ] NEW_LINE if a == b : NEW_LINE INDENT print ( " YES " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " NO " ) NEW_LINE DEDENT DEDENT

import sys NEW_LINE sys . setrecursionlimit ( 10 ** 9 ) NEW_LINE input = sys . stdin . readline NEW_LINE s = input ( ) NEW_LINE s = s [ : - 1 ] NEW_LINE s_rev = reversed ( s ) NEW_LINE for i , j in zip ( s , s_rev ) : NEW_LINE INDENT if i == j : NEW_LINE INDENT continue NEW_LINE DEDENT else : NEW_LINE INDENT print ( " NO " ) NEW_LINE exit ( ) NEW_LINE DEDENT DEDENT print ( " YES " ) NEW_LINE


import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int M = sc . nextInt ( ) ; int p [ ] = new int [ N + 1 ] ; for ( int i = 1 ; i <= N ; i ++ ) { p [ i ] = sc . nextInt ( ) ; } DS ds = new DS ( N + 1 ) ; for ( int i = 1 ; i <= M ; i ++ ) { ds . union ( sc . nextInt ( ) , sc . nextInt ( ) ) ; } int ans = 0 ; for ( int i = 1 ; i <= N ; i ++ ) { if ( p [ i ] == i ) { ans ++ ; } else if ( ds . root ( i ) == ds . root ( p [ i ] ) ) { ans ++ ; } } System . out . println ( ans ) ; } static class DS { int [ ] parent ; int [ ] counter ; DS ( int n ) { parent = new int [ n ] ; counter = new int [ n ] ; Arrays . fill ( counter , 1 ) ; Arrays . setAll ( parent , i -> i ) ; } int root ( int a ) { int q = a ; while ( q != parent [ q ] ) { q = parent [ q ] ; } while ( a != q ) { int next = parent [ a ] ; parent [ a ] = q ; a = next ; } return q ; } void union ( int i , int j ) { int ri = root ( i ) ; int rj = root ( j ) ; if ( ri == rj ) { return ; } if ( counter [ rj ] < counter [ ri ] ) { int s = ri ; ri = rj ; rj = s ; } parent [ ri ] = rj ; counter [ rj ] += counter [ ri ] ; } } }

import java . util . * ; public class Main { public void main ( Scanner sc ) { int n = sc . nextInt ( ) ; int m = sc . nextInt ( ) ; int p [ ] = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { p [ i ] = sc . nextInt ( ) ; } int data [ ] = new int [ n ] ; init ( n , data ) ; for ( int i = 0 ; i < m ; i ++ ) { link ( sc . nextInt ( ) , sc . nextInt ( ) , data ) ; } int cnt = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( isSame ( i + 1 , p [ i ] , data ) ) { cnt ++ ; } } System . out . println ( cnt ) ; } public void init ( int n , int data [ ] ) { for ( int i = 0 ; i < n ; i ++ ) { data [ i ] = i + 1 ; } } public void link ( int x , int y , int data [ ] ) { data [ root ( x , data ) - 1 ] = root ( y , data ) ; } public boolean isSame ( int x , int y , int data [ ] ) { return root ( x , data ) == root ( y , data ) ; } public int root ( int p , int data [ ] ) { return ( data [ p - 1 ] == p ) ? p : ( data [ p - 1 ] = root ( data [ p - 1 ] , data ) ) ; } public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; new Main ( ) . main ( sc ) ; sc . close ( ) ; } }

import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int N = scanner . nextInt ( ) ; int M = scanner . nextInt ( ) ; int [ ] a = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { a [ i ] = scanner . nextInt ( ) ; } UnionFind uf = new UnionFind ( N + 1 ) ; for ( int i = 0 ; i < M ; i ++ ) { int x = scanner . nextInt ( ) ; int y = scanner . nextInt ( ) ; uf . union ( x , y ) ; } int count = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( uf . find ( i + 1 ) == uf . find ( a [ i ] ) ) count ++ ; } System . out . println ( count ) ; } static class UnionFind { private final int [ ] table ; private final int [ ] ranks ; private final int [ ] sizes ; public UnionFind ( int size ) { this . table = new int [ size ] ; this . ranks = new int [ size ] ; this . sizes = new int [ size ] ; for ( int i = 0 ; i < size ; i ++ ) { table [ i ] = i ; sizes [ i ] = 1 ; } } public int find ( int x ) { if ( table [ x ] != x ) { table [ x ] = find ( table [ x ] ) ; } return table [ x ] ; } public void union ( int x , int y ) { int xRoot = find ( x ) ; int yRoot = find ( y ) ; if ( xRoot == yRoot ) return ; if ( ranks [ xRoot ] < ranks [ yRoot ] ) { int tmp = xRoot ; xRoot = yRoot ; yRoot = tmp ; } table [ yRoot ] = xRoot ; sizes [ xRoot ] += sizes [ yRoot ] ; if ( ranks [ xRoot ] == ranks [ yRoot ] ) ranks [ xRoot ] ++ ; } } }

import java . util . Scanner ; class Pair { int x ; int y ; public Pair ( int x , int y ) { this . x = x ; this . y = y ; } } class UnionFind { int [ ] par ; public UnionFind ( int N ) { par = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) par [ i ] = i ; } int root ( int x ) { if ( par [ x ] == x ) return x ; return par [ x ] = root ( par [ x ] ) ; } void unite ( int x , int y ) { int rx = root ( x ) ; int ry = root ( y ) ; if ( rx == ry ) return ; par [ rx ] = ry ; } boolean same ( int x , int y ) { int rx = root ( x ) ; int ry = root ( y ) ; return rx == ry ; } } public class Main { static int N ; static int M ; static int [ ] p ; static Pair [ ] sw ; static UnionFind uf ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; N = sc . nextInt ( ) ; M = sc . nextInt ( ) ; p = new int [ N + 1 ] ; sw = new Pair [ M + 1 ] ; for ( int i = 1 ; i <= N ; i ++ ) { p [ i ] = sc . nextInt ( ) ; } for ( int i = 1 ; i <= M ; i ++ ) { sw [ i ] = new Pair ( sc . nextInt ( ) , sc . nextInt ( ) ) ; } uf = new UnionFind ( N + 1 ) ; for ( int i = 1 ; i <= M ; i ++ ) { Pair s = sw [ i ] ; uf . unite ( s . x , s . y ) ; } int sum = 0 ; for ( int i = 1 ; i <= N ; i ++ ) { if ( uf . same ( i , p [ i ] ) ) sum ++ ; } System . out . println ( sum ) ; } }

import java . util . * ; public class Main { static int n , m ; static int [ ] p ; static int modP = 1000000007 ; public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; n = in . nextInt ( ) ; m = in . nextInt ( ) ; p = new int [ n ] ; UF uf = new UF ( n ) ; for ( int i = 0 ; i < n ; i ++ ) p [ i ] = in . nextInt ( ) ; for ( int i = 0 ; i < m ; i ++ ) { int x = in . nextInt ( ) - 1 ; int y = in . nextInt ( ) - 1 ; uf . union ( x , y ) ; } int cnt = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( uf . same ( i , p [ i ] - 1 ) ) cnt ++ ; } print ( cnt ) ; } static void print ( String s ) { System . out . println ( s ) ; } static void print ( int i ) { System . out . println ( i ) ; } } class UF { int [ ] table , ranks ; UF ( int s ) { table = new int [ s ] ; ranks = new int [ s ] ; for ( int i = 0 ; i < s ; i ++ ) { table [ i ] = i ; } } public int find ( int x ) { if ( table [ x ] != x ) table [ x ] = find ( table [ x ] ) ; return table [ x ] ; } public void union ( int x , int y ) { int xR = find ( x ) ; int yR = find ( y ) ; if ( xR == yR ) return ; if ( ranks [ xR ] < ranks [ yR ] ) { table [ xR ] = yR ; } else { table [ yR ] = xR ; if ( ranks [ xR ] == ranks [ yR ] ) ranks [ xR ] ++ ; } } public boolean same ( int x , int y ) { return find ( x ) == find ( y ) ; } }

class UnionFind : NEW_LINE INDENT def __init__ ( self , N ) : NEW_LINE INDENT self . parent = [ i for i in range ( N ) ] NEW_LINE self . rank = [ 0 ] * N NEW_LINE DEDENT def find ( self , x ) : NEW_LINE INDENT if self . parent [ x ] == x : NEW_LINE INDENT return x NEW_LINE DEDENT else : NEW_LINE INDENT self . parent [ x ] = self . find ( self . parent [ x ] ) NEW_LINE return self . parent [ x ] NEW_LINE DEDENT DEDENT def same ( self , x , y ) : NEW_LINE INDENT return self . find ( x ) == self . find ( y ) NEW_LINE DEDENT def union ( self , x , y ) : NEW_LINE INDENT x = self . find ( x ) NEW_LINE y = self . find ( y ) NEW_LINE if self . rank [ x ] < self . rank [ y ] : NEW_LINE INDENT self . parent [ x ] = y NEW_LINE DEDENT else : NEW_LINE INDENT self . parent [ y ] = x NEW_LINE if self . rank [ x ] == self . rank [ y ] : NEW_LINE INDENT self . rank [ x ] += 1 NEW_LINE DEDENT DEDENT DEDENT DEDENT N , M = map ( int , input ( ) . split ( ) ) NEW_LINE P = list ( map ( lambda x : int ( x ) - 1 , input ( ) . split ( ) ) ) NEW_LINE UF = UnionFind ( N ) NEW_LINE for _ in range ( M ) : NEW_LINE INDENT x , y = map ( lambda x : int ( x ) - 1 , input ( ) . split ( ) ) NEW_LINE UF . union ( x , y ) NEW_LINE DEDENT ans = 0 NEW_LINE for i in range ( N ) : NEW_LINE INDENT if UF . find ( P [ i ] ) == UF . find ( i ) : NEW_LINE INDENT ans += 1 NEW_LINE DEDENT DEDENT print ( ans ) NEW_LINE

N , M = [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE p_ls = [ int ( i ) - 1 for i in input ( ) . split ( ) ] NEW_LINE par = [ i for i in range ( N ) ] NEW_LINE rank = [ 1 for i in range ( N ) ] NEW_LINE def find ( x ) : NEW_LINE INDENT if par [ x ] == x : NEW_LINE INDENT return x NEW_LINE DEDENT else : NEW_LINE INDENT return find ( par [ x ] ) NEW_LINE DEDENT DEDENT def unite ( x , y ) : NEW_LINE INDENT x = find ( x ) NEW_LINE y = find ( y ) NEW_LINE if x == y : NEW_LINE INDENT pass NEW_LINE DEDENT else : NEW_LINE INDENT if rank [ x ] > rank [ y ] : NEW_LINE INDENT par [ y ] = x NEW_LINE rank [ x ] += rank [ y ] NEW_LINE DEDENT else : NEW_LINE INDENT par [ x ] = par [ y ] NEW_LINE rank [ y ] += rank [ x ] NEW_LINE DEDENT DEDENT DEDENT def is_same ( x , y ) : NEW_LINE INDENT if find ( x ) == find ( y ) : NEW_LINE INDENT return True NEW_LINE DEDENT else : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT data_ls = list ( ) NEW_LINE for i in range ( M ) : NEW_LINE INDENT x , y = [ int ( i ) - 1 for i in input ( ) . split ( ) ] NEW_LINE if is_same ( x , y ) : NEW_LINE INDENT pass NEW_LINE DEDENT else : NEW_LINE INDENT unite ( x , y ) NEW_LINE DEDENT DEDENT cnt = 0 NEW_LINE for i in range ( N ) : NEW_LINE INDENT if is_same ( i , p_ls [ i ] ) : NEW_LINE INDENT cnt += 1 NEW_LINE DEDENT DEDENT print ( cnt ) NEW_LINE

def init ( n ) : NEW_LINE INDENT global par , rank NEW_LINE par = [ i for i in range ( n ) ] NEW_LINE rank = [ 0 ] * n NEW_LINE DEDENT def find ( x ) : NEW_LINE INDENT global par NEW_LINE if par [ x ] == x : NEW_LINE INDENT return x NEW_LINE DEDENT else : NEW_LINE INDENT par [ x ] = find ( par [ x ] ) NEW_LINE return par [ x ] NEW_LINE DEDENT DEDENT def unite ( x , y ) : NEW_LINE INDENT global par , rank NEW_LINE x = find ( x ) NEW_LINE y = find ( y ) NEW_LINE if x == y : NEW_LINE INDENT return NEW_LINE DEDENT if rank [ x ] < rank [ y ] : NEW_LINE INDENT par [ x ] = y NEW_LINE DEDENT else : NEW_LINE INDENT par [ y ] = x NEW_LINE if rank [ x ] == rank [ y ] : NEW_LINE INDENT rank [ x ] += 1 NEW_LINE DEDENT DEDENT DEDENT def same ( x , y ) : NEW_LINE INDENT return find ( x ) == find ( y ) NEW_LINE DEDENT N , M = map ( int , input ( ) . split ( ) ) NEW_LINE init ( N ) NEW_LINE p = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE for _ in range ( M ) : NEW_LINE INDENT x , y = map ( int , input ( ) . split ( ) ) NEW_LINE unite ( x - 1 , y - 1 ) NEW_LINE DEDENT ans = 0 NEW_LINE for i in range ( N ) : NEW_LINE INDENT if same ( i , p [ i ] - 1 ) : NEW_LINE INDENT ans += 1 NEW_LINE DEDENT DEDENT print ( ans ) NEW_LINE

class UnionFind ( ) : NEW_LINE INDENT def __init__ ( self , n ) : NEW_LINE INDENT self . n = n NEW_LINE self . par = [ - 1 for _ in range ( n ) ] NEW_LINE DEDENT def same ( self , x , y ) : NEW_LINE INDENT return self . root ( x ) == self . root ( y ) NEW_LINE DEDENT def root ( self , x ) : NEW_LINE INDENT if self . par [ x ] < 0 : NEW_LINE INDENT return x NEW_LINE DEDENT self . par [ x ] = self . root ( self . par [ x ] ) NEW_LINE return self . par [ x ] NEW_LINE DEDENT def unite ( self , x , y ) : NEW_LINE INDENT x = self . root ( x ) NEW_LINE y = self . root ( y ) NEW_LINE if x == y : NEW_LINE INDENT return NEW_LINE DEDENT if self . par [ x ] > self . par [ y ] : NEW_LINE INDENT x , y = y , x NEW_LINE DEDENT self . par [ x ] += self . par [ y ] NEW_LINE self . par [ y ] = x NEW_LINE DEDENT def size ( self , x ) : NEW_LINE INDENT return - self . par [ self . root ( x ) ] NEW_LINE DEDENT DEDENT n , m = map ( int , input ( ) . split ( ) ) NEW_LINE pl = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE uf = UnionFind ( n + 1 ) NEW_LINE for _ in range ( m ) : NEW_LINE INDENT x , y = map ( int , input ( ) . split ( ) ) NEW_LINE uf . unite ( x , y ) NEW_LINE DEDENT res = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT if uf . same ( i + 1 , pl [ i ] ) : NEW_LINE INDENT res += 1 NEW_LINE DEDENT DEDENT print ( res ) NEW_LINE

n , m = map ( int , input ( ) . split ( ) ) NEW_LINE ps = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE xys = [ tuple ( map ( int , input ( ) . split ( ) ) ) for _ in range ( m ) ] NEW_LINE t = { p : p for p in ps } NEW_LINE def trace ( x ) : NEW_LINE INDENT route = [ x ] NEW_LINE while t [ x ] != x : NEW_LINE INDENT x = t [ x ] NEW_LINE route . append ( x ) NEW_LINE DEDENT for v in route : NEW_LINE INDENT t [ v ] = route [ - 1 ] NEW_LINE DEDENT return route NEW_LINE DEDENT for x , y in xys : NEW_LINE INDENT u = trace ( x ) [ - 1 ] NEW_LINE v = trace ( y ) [ - 1 ] NEW_LINE if u != v : NEW_LINE INDENT t [ u ] = v NEW_LINE DEDENT DEDENT avs = [ p for i , p in enumerate ( ps ) if trace ( i + 1 ) [ - 1 ] == trace ( p ) [ - 1 ] ] NEW_LINE print ( len ( avs ) ) NEW_LINE


import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; double a = sc . nextDouble ( ) ; double b = sc . nextDouble ( ) ; System . out . println ( ( int ) Math . ceil ( ( a + b ) / 2 ) ) ; } }

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

import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { double a ; double b ; double x ; Scanner sc = new Scanner ( System . in ) ; a = sc . nextDouble ( ) ; b = sc . nextDouble ( ) ; x = ( a + b ) / 2 ; x = Math . ceil ( x ) ; System . out . println ( ( int ) x ) ; sc . close ( ) ; } }

import java . util . * ; import java . io . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; double a , b ; a = Double . parseDouble ( sc . next ( ) ) ; b = Double . parseDouble ( sc . next ( ) ) ; int ans = ( int ) Math . ceil ( ( a + b ) / 2 ) ; System . out . println ( ans ) ; sc . close ( ) ; } }

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

a , b = map ( int , input ( ) . split ( ) ) NEW_LINE abr = ( a + b + 1 ) // 2 NEW_LINE print ( abr ) NEW_LINE

import math NEW_LINE work = input ( ) . split ( " ▁ " ) NEW_LINE a = int ( work [ 0 ] ) NEW_LINE b = int ( work [ 1 ] ) NEW_LINE print ( math . ceil ( ( a + b ) / 2 ) ) NEW_LINE

a , b = map ( int , input ( ) . split ( ) ) NEW_LINE x = ( a + b ) / 2 NEW_LINE if x - int ( x ) >= 0.5 : NEW_LINE INDENT print ( int ( x ) + 1 ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( int ( x ) ) NEW_LINE DEDENT

print ( ( sum ( map ( int , input ( ) . split ( ) ) ) + 1 ) // 2 ) NEW_LINE

import math NEW_LINE a , b = map ( int , input ( ) . split ( ) ) NEW_LINE c = math . ceil ( ( a + b ) / 2 ) NEW_LINE print ( " { } " . format ( c ) ) NEW_LINE


import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long n = sc . nextLong ( ) ; long m = sc . nextLong ( ) ; if ( n == 1 && m == 1 ) System . out . println ( 1 ) ; else if ( n == 1 || m == 1 ) System . out . println ( Math . max ( n , m ) - 2 ) ; else System . out . println ( ( n - 2 ) * ( m - 2 ) ) ; } }

import java . util . ArrayList ; import java . util . Arrays ; import java . util . List ; import java . util . Scanner ; import java . util . function . Consumer ; import static java . util . stream . Collectors . toList ; public class Main { private static final Scanner scanner = new Scanner ( System . in ) ; private static final Consumer < List < String > > consumer = solve ( ) ; public static void main ( String [ ] args ) { consumer . accept ( readInput ( ) ) ; } private static List < String > readInput ( ) { final List < String > lineList = new ArrayList < > ( ) ; while ( scanner . hasNextLine ( ) ) { lineList . add ( scanner . nextLine ( ) ) ; } return lineList ; } private static Consumer < List < String > > solve ( ) { return args -> { final List < Long > numList = Arrays . stream ( args . get ( 0 ) . split ( " ▁ " ) ) . map ( Long :: valueOf ) . collect ( toList ( ) ) ; final Long x = numList . get ( 0 ) ; final Long y = numList . get ( 1 ) ; if ( x == 1 ) { if ( y == 1 ) { System . out . println ( 1 ) ; } else { System . out . println ( y - 2 ) ; } } else if ( y == 1 ) { System . out . println ( x - 2 ) ; } else { System . out . println ( ( x - 2 ) * ( y - 2 ) ) ; } } ; } }

import java . io . * ; import java . util . * ; class Main { public static void main ( String [ ] args ) { solve ( ) ; } public static void solve ( ) { Scanner sc = new Scanner ( System . in ) ; long n = sc . nextLong ( ) ; long m = sc . nextLong ( ) ; long count = Math . abs ( ( n - 2 ) * ( m - 2 ) ) ; System . out . println ( count ) ; } }

import java . util . * ; public class Main { private long N ; private long M ; public void inputData ( ) { Scanner sc = new Scanner ( System . in ) ; N = sc . nextLong ( ) ; M = sc . nextLong ( ) ; } public void printAnswer ( ) { if ( N > 1 ) { N -= 2 ; } if ( M > 1 ) { M -= 2 ; } System . out . println ( N * M ) ; } public void run ( ) { inputData ( ) ; printAnswer ( ) ; } public static void main ( String [ ] args ) { ( new Main ( ) ) . run ( ) ; } }

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 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 " ; } public static void main ( String [ ] args ) { int n = nextInt ( ) , m = nextInt ( ) ; long h = min ( n , m ) , w = max ( n , m ) ; long ans = 0 ; if ( h == 1 && w == 1 ) { ans = 1 ; } else if ( h == 1 && w != 1 ) { ans = w - 2 ; } else ans = ( h - 2 ) * ( w - 2 ) ; System . out . println ( ans ) ; } }

N , M = map ( int , input ( ) . strip ( ) . split ( ' ▁ ' ) ) NEW_LINE if N == 1 and M == 1 : NEW_LINE INDENT ans = 1 NEW_LINE DEDENT elif N == 1 : NEW_LINE INDENT ans = M - 2 NEW_LINE DEDENT elif M == 1 : NEW_LINE INDENT ans = N - 2 NEW_LINE DEDENT else : NEW_LINE INDENT ans = ( N - 2 ) * ( M - 2 ) NEW_LINE DEDENT print ( ans ) NEW_LINE

n , m = map ( int , input ( ) . split ( ) ) ; print ( abs ( ( n - 2 ) * ( m - 2 ) ) ) NEW_LINE

def inpl ( ) : return [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE N , M = inpl ( ) NEW_LINE if M < N : NEW_LINE INDENT N , M = M , N NEW_LINE DEDENT if N == 1 : NEW_LINE INDENT if M == 1 : NEW_LINE INDENT print ( 1 ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( M - 2 ) NEW_LINE DEDENT DEDENT elif N == 2 : NEW_LINE INDENT print ( 0 ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( ( N - 2 ) * ( M - 2 ) ) NEW_LINE DEDENT

n , m = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE n , m = max ( n , m ) , min ( n , m ) NEW_LINE if n == 1 and m == 1 : NEW_LINE INDENT print ( 1 ) NEW_LINE DEDENT else : NEW_LINE INDENT a = min ( 2 , n ) NEW_LINE b = max ( 0 , n - 2 ) NEW_LINE c = min ( 2 , m ) NEW_LINE d = max ( 0 , m - 2 ) NEW_LINE if m == 1 : NEW_LINE INDENT print ( b ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( b * d ) NEW_LINE DEDENT DEDENT

N , M = [ int ( x ) for x in input ( ) . split ( ) ] NEW_LINE if N == 1 and M == 1 : NEW_LINE INDENT print ( 1 ) NEW_LINE DEDENT elif N == 1 or M == 1 : NEW_LINE INDENT print ( max ( N , M ) - 2 ) NEW_LINE DEDENT elif N == 2 or M == 2 : NEW_LINE INDENT print ( 0 ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( ( N - 2 ) * ( M - 2 ) ) NEW_LINE DEDENT


import java . util . * ; public class Main { static int res = 0 ; static ArrayList < Integer > [ ] g ; static boolean dfs ( int u , int par , int [ ] h ) { boolean exist = ( h [ u ] == 1 ) ; for ( int v : g [ u ] ) { if ( v == par ) continue ; boolean child = dfs ( v , u , h ) ; if ( child ) res += 2 ; exist |= child ; } return exist ; } public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int k = sc . nextInt ( ) - 1 ; int h [ ] = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { h [ i ] = sc . nextInt ( ) ; } g = new ArrayList [ N ] ; for ( int i = 0 ; i < N ; i ++ ) g [ i ] = new ArrayList < Integer > ( ) ; for ( int i = 0 ; i < N - 1 ; i ++ ) { int a = sc . nextInt ( ) - 1 ; int b = sc . nextInt ( ) - 1 ; g [ a ] . add ( b ) ; g [ b ] . add ( a ) ; } dfs ( k , - 1 , h ) ; System . out . println ( res ) ; } } Note : . / Main . java uses unchecked or unsafe operations . Note : Recompile with - Xlint : unchecked for details .

import java . util . * ; public class Main { static int ret = 0 ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int x = sc . nextInt ( ) - 1 ; int [ ] h = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { h [ i ] = sc . nextInt ( ) ; } ArrayList < Integer > [ ] table = new ArrayList [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { table [ i ] = new ArrayList < > ( ) ; } for ( int i = 0 ; i < n - 1 ; i ++ ) { int a = sc . nextInt ( ) - 1 ; int b = sc . nextInt ( ) - 1 ; table [ a ] . add ( b ) ; table [ b ] . add ( a ) ; } dfs ( x , - 1 , h , table ) ; System . out . println ( ret ) ; } public static boolean dfs ( int now , int parent , int [ ] h , ArrayList < Integer > [ ] table ) { boolean exist = h [ now ] == 1 ; for ( int next : table [ now ] ) { if ( next == parent ) continue ; boolean child = dfs ( next , now , h , table ) ; if ( child ) ret += 2 ; exist |= child ; } return exist ; } } Note : . / Main . java uses unchecked or unsafe operations . Note : Recompile with - Xlint : unchecked for details .

class Node : NEW_LINE INDENT parent = None NEW_LINE children = set ( ) NEW_LINE count = None NEW_LINE DEDENT def main ( ) : NEW_LINE INDENT n , x = map ( int , input ( ) . split ( ) ) NEW_LINE hn = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE ab = [ ] NEW_LINE for i in range ( n - 1 ) : NEW_LINE INDENT a , b = map ( int , input ( ) . split ( ) ) NEW_LINE ab . append ( ( a - 1 , b - 1 ) ) NEW_LINE DEDENT nodes = [ Node ( ) for i in range ( n ) ] NEW_LINE dfs_make_tree ( x - 1 , None , n , ab , nodes ) NEW_LINE dfs_count ( x - 1 , nodes , hn ) NEW_LINE print ( max ( 0 , ( count_nonzero_branches ( nodes ) - 1 ) ) * 2 ) NEW_LINE DEDENT def dfs_make_tree ( my_id , parent_id , n , ab , nodes ) : NEW_LINE INDENT assert my_id != parent_id NEW_LINE node = nodes [ my_id ] NEW_LINE node . parent = parent_id NEW_LINE adjs = set ( ) NEW_LINE for edge in ab : NEW_LINE INDENT if my_id == edge [ 0 ] : NEW_LINE INDENT adjs . add ( edge [ 1 ] ) NEW_LINE DEDENT elif my_id == edge [ 1 ] : NEW_LINE INDENT adjs . add ( edge [ 0 ] ) NEW_LINE DEDENT DEDENT adjs -= { parent_id } NEW_LINE node . children = adjs NEW_LINE for c in node . children : NEW_LINE INDENT dfs_make_tree ( c , my_id , n , ab , nodes ) NEW_LINE DEDENT DEDENT def dfs_count ( my_id , nodes , hn ) : NEW_LINE INDENT node = nodes [ my_id ] NEW_LINE node . count = hn [ my_id ] NEW_LINE for c in node . children : NEW_LINE INDENT node . count += dfs_count ( c , nodes , hn ) NEW_LINE DEDENT return node . count NEW_LINE DEDENT def count_nonzero_branches ( nodes ) : NEW_LINE INDENT cnt = 0 NEW_LINE for nd in nodes : NEW_LINE INDENT if nd . count > 0 : NEW_LINE INDENT cnt += 1 NEW_LINE DEDENT DEDENT return cnt NEW_LINE DEDENT main ( ) NEW_LINE

I = lambda : list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE n , x = I ( ) NEW_LINE r = range ( n + 1 ) NEW_LINE H = [ 0 ] + I ( ) NEW_LINE T = [ [ ] for i in r ] NEW_LINE for i in range ( n - 1 ) : NEW_LINE INDENT a , b = I ( ) NEW_LINE T [ a ] += [ b ] NEW_LINE T [ b ] += [ a ] NEW_LINE DEDENT while 1 : NEW_LINE INDENT f = 1 NEW_LINE for i in r : NEW_LINE INDENT if all ( [ len ( T [ i ] ) == 1 , H [ i ] < 1 , i != x ] ) : NEW_LINE INDENT p = T [ i ] . pop ( ) NEW_LINE T [ p ] . remove ( i ) NEW_LINE f = 0 NEW_LINE DEDENT DEDENT if f : break NEW_LINE DEDENT print ( sum ( len ( t ) for t in T ) ) NEW_LINE

def b_tree ( N , X , H , Edges ) : NEW_LINE INDENT x = X - 1 NEW_LINE graph = [ [ ] for _ in [ 0 ] * N ] NEW_LINE for a , b in Edges : NEW_LINE INDENT a , b = a - 1 , b - 1 NEW_LINE graph [ a ] . append ( b ) NEW_LINE graph [ b ] . append ( a ) NEW_LINE DEDENT is_visited = [ False ] * N NEW_LINE is_exist_treasure = [ True if h == 1 else False for h in H ] NEW_LINE ans = 0 NEW_LINE def dfs ( v ) : NEW_LINE INDENT nonlocal ans NEW_LINE is_visited [ v ] = True NEW_LINE need_reach = is_exist_treasure [ v ] NEW_LINE for target in graph [ v ] : NEW_LINE INDENT if is_visited [ target ] : NEW_LINE INDENT continue NEW_LINE DEDENT if dfs ( target ) : NEW_LINE INDENT ans += 2 NEW_LINE need_reach = True NEW_LINE DEDENT DEDENT return need_reach NEW_LINE DEDENT dfs ( x ) NEW_LINE return ans NEW_LINE DEDENT N , X = [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE H = [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE Edges = [ [ int ( i ) for i in input ( ) . split ( ) ] for j in range ( N - 1 ) ] NEW_LINE print ( b_tree ( N , X , H , Edges ) ) NEW_LINE

import sys NEW_LINE sys . setrecursionlimit ( 10 ** 9 ) NEW_LINE input = sys . stdin . readline NEW_LINE N , x = map ( int , input ( ) . split ( ) ) NEW_LINE L = [ 0 ] + list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE adj = [ [ ] for _ in range ( N + 1 ) ] NEW_LINE for _ in range ( N - 1 ) : NEW_LINE INDENT a , b = map ( lambda x : int ( x ) , input ( ) . split ( ) ) NEW_LINE adj [ a ] . append ( b ) NEW_LINE adj [ b ] . append ( a ) NEW_LINE DEDENT def dfs ( c , p ) : NEW_LINE INDENT if len ( adj [ c ] ) == 1 : NEW_LINE INDENT if L [ c ] : NEW_LINE INDENT return 2 NEW_LINE DEDENT else : NEW_LINE INDENT return 0 NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT ret = 0 NEW_LINE for n in adj [ c ] : NEW_LINE INDENT if n == p : NEW_LINE INDENT continue NEW_LINE DEDENT else : NEW_LINE INDENT ret += dfs ( n , c ) NEW_LINE DEDENT DEDENT if ret == 0 : NEW_LINE INDENT if L [ c ] : NEW_LINE INDENT return 2 NEW_LINE DEDENT else : NEW_LINE INDENT return 0 NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT return ret + 2 NEW_LINE DEDENT DEDENT DEDENT ans = 0 NEW_LINE for n in adj [ x ] : NEW_LINE INDENT ans += dfs ( n , x ) NEW_LINE DEDENT print ( ans ) NEW_LINE

n , x = ( int ( i ) for i in input ( ) . split ( ) ) NEW_LINE h = [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE s , ans = [ [ ] for i in range ( n + 1 ) ] , 0 NEW_LINE for _ in range ( n - 1 ) : NEW_LINE INDENT a , b = ( int ( i ) for i in input ( ) . split ( ) ) NEW_LINE s [ a ] . append ( b ) NEW_LINE s [ b ] . append ( a ) NEW_LINE DEDENT t , q , vis , p = 0 , [ x ] , [ True ] * ( n + 1 ) , [ 0 ] * ( n + 1 ) NEW_LINE while q : NEW_LINE INDENT t2 = q . pop ( ) NEW_LINE while p [ t2 ] != t : NEW_LINE INDENT if h [ t - 1 ] : ans , h [ p [ t ] - 1 ] = ans + 2 , 1 NEW_LINE t = p [ t ] NEW_LINE DEDENT vis [ t ] , t = False , t2 NEW_LINE for i in s [ t ] : NEW_LINE INDENT if vis [ i ] : NEW_LINE INDENT p [ i ] = t NEW_LINE q . append ( i ) NEW_LINE DEDENT DEDENT DEDENT while t != x : NEW_LINE INDENT if h [ t - 1 ] : ans , h [ p [ t ] - 1 ] = ans + 2 , 1 NEW_LINE t = p [ t ] NEW_LINE DEDENT print ( ans ) NEW_LINE


import java . util . * ; public class Main { public static void main ( String args [ ] ) { Scanner sc = new Scanner ( System . in ) ; int N = ( int ) sc . nextInt ( ) ; int a [ ] = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { a [ i ] = sc . nextInt ( ) ; } int ans = 0 ; Map < Integer , Integer > map = new HashMap < Integer , Integer > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { while ( a [ i ] % 2 == 0 ) { a [ i ] /= 2 ; } map . put ( a [ i ] , 1 ) ; } System . out . println ( map . size ( ) ) ; } }

import java . io . OutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . PrintWriter ; import java . util . HashSet ; import java . util . Scanner ; import java . util . Set ; 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 ) ; C solver = new C ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class C { public void solve ( int testNumber , Scanner in , PrintWriter out ) { int n = in . nextInt ( ) ; Set < Integer > set = new HashSet < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { int a = in . nextInt ( ) ; while ( ( a & 1 ) == 0 ) { a = a >> 1 ; } set . add ( a ) ; } out . println ( set . size ( ) ) ; } } }

public class Main { private static java . util . Scanner scanner = new java . util . Scanner ( System . in ) ; public static void main ( String [ ] $ ) { int n = scanner . nextInt ( ) ; java . util . Set < Integer > a = java . util . stream . IntStream . range ( 0 , n ) . map ( i -> scanner . nextInt ( ) ) . boxed ( ) . collect ( java . util . stream . Collectors . toSet ( ) ) ; System . out . println ( a . stream ( ) . filter ( i -> { while ( i % 2 == 0 ) if ( a . contains ( i /= 2 ) ) return false ; return true ; } ) . count ( ) ) ; } }

import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] nums = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { nums [ i ] = sc . nextInt ( ) ; } for ( int i = 0 ; i < n ; i ++ ) { nums [ i ] = nums [ i ] / ( int ) Math . pow ( 2 , dividebyN ( nums [ i ] , 2 ) ) ; } Arrays . sort ( nums ) ; int tmp = 0 ; int output = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( nums [ i ] != tmp ) { tmp = nums [ i ] ; output ++ ; } } System . out . println ( output ) ; } static int dividebyN ( int input , int n ) { int output = 0 ; while ( true ) { if ( input % n == 0 ) { output ++ ; input /= n ; } else { break ; } } return output ; } }

import java . util . * ; import java . awt . * ; import java . awt . geom . * ; import static java . lang . System . * ; import static java . lang . Math . * ; public class Main { public static void main ( String [ ] $ ) { Scanner sc = new Scanner ( in ) ; int n = sc . nextInt ( ) ; int [ ] a = new int [ n ] ; HashSet < Integer > ans = new HashSet < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = sc . nextInt ( ) ; while ( a [ i ] % 2 == 0 ) { a [ i ] /= 2 ; } ans . add ( a [ i ] ) ; } out . println ( ans . size ( ) ) ; } }

_ = int ( input ( ) ) NEW_LINE l = [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE count = 0 NEW_LINE output = [ ] NEW_LINE for num in l : NEW_LINE INDENT while num % 2 == 0 : NEW_LINE INDENT num = num / 2 NEW_LINE DEDENT output . append ( num ) NEW_LINE DEDENT print ( len ( set ( output ) ) ) NEW_LINE

N = int ( input ( ) ) NEW_LINE ans = set ( ) NEW_LINE for a in map ( int , input ( ) . split ( ) ) : NEW_LINE INDENT while True : NEW_LINE INDENT if a % 2 == 1 : NEW_LINE INDENT ans |= { a , } NEW_LINE break NEW_LINE DEDENT else : a //= 2 NEW_LINE DEDENT DEDENT print ( len ( ans ) ) NEW_LINE

import sys NEW_LINE input = sys . stdin . readline NEW_LINE inf = 10 ** 18 NEW_LINE N = int ( input ( ) ) NEW_LINE a = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE a_id = list ( a ) NEW_LINE for i , ai in enumerate ( a ) : NEW_LINE INDENT ai_tmp = ai NEW_LINE while ai_tmp > 0 and ai_tmp & 1 == 0 : ai_tmp = ai_tmp >> 1 NEW_LINE a_id [ i ] = ai_tmp NEW_LINE DEDENT a_id = set ( a_id ) NEW_LINE print ( len ( a_id ) ) NEW_LINE

N = int ( input ( ) ) NEW_LINE a = [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE b = set ( ) NEW_LINE for x in a : NEW_LINE INDENT while 1 : NEW_LINE INDENT if x % 2 == 0 : NEW_LINE INDENT x = x // 2 NEW_LINE DEDENT else : NEW_LINE INDENT b . add ( x ) NEW_LINE break NEW_LINE DEDENT DEDENT DEDENT print ( len ( b ) ) NEW_LINE

from collections import Counter NEW_LINE N = int ( input ( ) ) NEW_LINE an = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE ans = 0 NEW_LINE for i in range ( N ) : NEW_LINE INDENT while ( an [ i ] & 1 ) == 0 : NEW_LINE INDENT an [ i ] = ( an [ i ] >> 1 ) NEW_LINE DEDENT DEDENT ac = Counter ( an ) NEW_LINE print ( len ( ac ) ) NEW_LINE


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 m = sc . nextInt ( ) ; int s [ ] [ ] = new int [ n ] [ m ] ; for ( int i = 0 ; i < n ; i ++ ) { String c = sc . next ( ) ; for ( int j = 0 ; j < m ; j ++ ) if ( c . substring ( j , j + 1 ) . equals ( " # " ) ) s [ i ] [ j ] = - 1 ; } for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < m ; j ++ ) { if ( s [ i ] [ j ] == - 1 ) { for ( int y = i - 1 ; y <= i + 1 ; y ++ ) { for ( int x = j - 1 ; x <= j + 1 ; x ++ ) { if ( y >= 0 && y < n && x >= 0 && x < m ) { if ( s [ y ] [ x ] > - 1 ) s [ y ] [ x ] ++ ; } } } } } } for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < m ; j ++ ) { System . out . print ( s [ i ] [ j ] < 0 ? " # " : s [ i ] [ j ] ) ; } System . out . println ( ) ; } } }

import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int H = sc . nextInt ( ) ; int W = sc . nextInt ( ) ; sc . nextLine ( ) ; String [ ] [ ] S = new String [ H ] [ W ] ; final int height = H ; final int width = W ; int [ ] [ ] number = new int [ H ] [ W ] ; String [ ] tmp = new String [ H ] ; for ( int i = 0 ; i < H ; i ++ ) { tmp [ i ] = sc . nextLine ( ) ; } for ( int i = 0 ; i < H ; i ++ ) { String [ ] str = tmp [ i ] . split ( " " ) ; for ( int j = 0 ; j < W ; j ++ ) { S [ i ] [ j ] = str [ j ] ; } } for ( int i = 0 ; i < H ; i ++ ) { for ( int j = 0 ; j < W ; j ++ ) { if ( S [ i ] [ j ] . equals ( " # " ) ) { System . out . print ( S [ i ] [ j ] ) ; } else { number [ i ] [ j ] = countMine ( i , j , height , width , S ) ; System . out . print ( number [ i ] [ j ] ) ; } } System . out . println ( ) ; } sc . close ( ) ; } public static int countMine ( int h , int w , int height , int width , String [ ] [ ] S ) { int count = 0 ; for ( int i = h - 1 ; i <= h + 1 ; i ++ ) { if ( i < 0 || i >= height ) { continue ; } for ( int j = w - 1 ; j <= w + 1 ; j ++ ) { if ( j < 0 || j >= width ) { continue ; } if ( S [ i ] [ j ] . equals ( " # " ) ) { count ++ ; } } } return count ; } }

import java . util . * ; import java . util . stream . IntStream ; public class Main { public static boolean found = false ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int h = sc . nextInt ( ) ; int w = sc . nextInt ( ) ; char [ ] [ ] board = new char [ h ] [ w ] ; int [ ] [ ] dt = new int [ ] [ ] { new int [ ] { 1 , 0 } , new int [ ] { 1 , 1 } , new int [ ] { 0 , 1 } , new int [ ] { - 1 , 1 } , new int [ ] { - 1 , 0 } , new int [ ] { - 1 , - 1 } , new int [ ] { 0 , - 1 } , new int [ ] { 1 , - 1 } } ; for ( int i = 0 ; i < h ; i ++ ) { String line = sc . next ( ) ; board [ i ] = line . toCharArray ( ) ; } for ( int i = 0 ; i < h ; i ++ ) { for ( int j = 0 ; j < w ; j ++ ) { if ( board [ i ] [ j ] != ' # ' ) { int count = 0 ; for ( int k = 0 ; k < dt . length ; k ++ ) { int x = i + dt [ k ] [ 0 ] ; int y = j + dt [ k ] [ 1 ] ; if ( ( 0 <= x && x < h ) && ( 0 <= y && y < w ) && board [ x ] [ y ] == ' # ' ) { count ++ ; } } board [ i ] [ j ] = ( char ) ( count + '0' ) ; } System . out . print ( board [ i ] [ j ] ) ; } System . out . println ( " " ) ; } } }

import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . StringTokenizer ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader input = new BufferedReader ( new InputStreamReader ( System . in ) ) ; StringTokenizer tokenizer = new StringTokenizer ( input . readLine ( ) ) ; int h = Integer . parseInt ( tokenizer . nextToken ( ) ) ; int w = Integer . parseInt ( tokenizer . nextToken ( ) ) ; char [ ] [ ] letters = new char [ h ] [ ] ; for ( int i = 0 ; i < h ; i ++ ) { letters [ i ] = input . readLine ( ) . toCharArray ( ) ; } int [ ] x = { 1 , 0 , 1 , 0 , - 1 , 1 , - 1 , - 1 } ; int [ ] y = { 1 , 1 , 0 , - 1 , 0 , - 1 , 1 , - 1 } ; int sum ; for ( int i = 0 ; i < h ; i ++ ) { for ( int j = 0 ; j < w ; j ++ ) { if ( letters [ i ] [ j ] == ' . ' ) { sum = 0 ; for ( int k = 0 ; k < 8 ; k ++ ) { if ( check ( h , w , i + x [ k ] , j + y [ k ] ) && letters [ i + x [ k ] ] [ j + y [ k ] ] == ' # ' ) sum ++ ; } letters [ i ] [ j ] = ( char ) ( '0' + sum ) ; } } } StringBuilder out = new StringBuilder ( ) ; StringBuilder row ; for ( int i = 0 ; i < h ; i ++ ) { row = new StringBuilder ( ) ; for ( int j = 0 ; j < w ; j ++ ) { row . append ( letters [ i ] [ j ] ) ; } out . append ( row ) . append ( " \n " ) ; } System . out . print ( out ) ; } public static boolean check ( int x1 , int y1 , int x2 , int y2 ) { return x2 > - 1 && x2 < x1 && y2 > - 1 && y2 < y1 ; } }

import java . util . * ; public class Main { public static void main ( String [ ] args ) { B ( ) ; return ; } public static void A ( ) { Scanner sc = new Scanner ( System . in ) ; int A = sc . nextInt ( ) ; int B = sc . nextInt ( ) ; int C = sc . nextInt ( ) ; if ( A == B ) System . out . println ( C ) ; else if ( B == C ) System . out . println ( A ) ; else System . out . println ( B ) ; } public static void calc8 ( char [ ] [ ] cell , int h , int w ) { if ( cell [ h ] [ w ] == ' # ' ) System . out . print ( ' # ' ) ; else { int [ ] hs = new int [ ] { h - 1 , h , h + 1 } ; int [ ] ws = new int [ ] { w - 1 , w , w + 1 } ; int sum = 0 ; for ( int nh : hs ) { for ( int nw : ws ) { if ( nh < cell . length && nh >= 0 && nw >= 0 && nw < cell [ 0 ] . length ) { if ( cell [ nh ] [ nw ] == ' # ' ) sum ++ ; } } } System . out . print ( sum ) ; } if ( w == cell [ 0 ] . length - 1 ) System . out . println ( " " ) ; } public static void B ( ) { Scanner sc = new Scanner ( System . in ) ; int H = sc . nextInt ( ) ; int W = sc . nextInt ( ) ; char [ ] [ ] cell = new char [ H ] [ W ] ; for ( int i = 0 ; i < H ; i ++ ) { String s = sc . next ( ) ; for ( int j = 0 ; j < W ; j ++ ) { cell [ i ] [ j ] = s . charAt ( j ) ; } } for ( int i = 0 ; i < H ; i ++ ) { for ( int j = 0 ; j < W ; j ++ ) { calc8 ( cell , i , j ) ; } } } }

h , w = [ int ( n ) for n in input ( ) . split ( ) ] NEW_LINE B = [ [ ' . ' ] * ( w + 2 ) ] NEW_LINE for i in range ( h ) : NEW_LINE INDENT s = [ ' . ' ] + list ( input ( ) ) + [ ' . ' ] NEW_LINE B . append ( s ) NEW_LINE DEDENT B . append ( [ ' . ' ] * ( w + 2 ) ) NEW_LINE for i in range ( 1 , h + 1 ) : NEW_LINE INDENT for j in range ( 1 , w + 1 ) : NEW_LINE INDENT if B [ i ] [ j ] == ' # ' : NEW_LINE INDENT continue NEW_LINE DEDENT else : NEW_LINE INDENT B [ i ] [ j ] = str ( ( B [ i - 1 ] [ j - 1 : j + 2 ] + [ B [ i ] [ j - 1 ] ] + [ B [ i ] [ j + 1 ] ] + B [ i + 1 ] [ j - 1 : j + 2 ] ) . count ( ' # ' ) ) NEW_LINE DEDENT DEDENT DEDENT for i in range ( 1 , h + 1 ) : NEW_LINE INDENT print ( ' ' . join ( B [ i ] [ 1 : w + 1 ] ) ) NEW_LINE DEDENT

def count ( i , j ) : NEW_LINE INDENT count = 0 NEW_LINE if list [ i - 1 ] [ j - 1 ] == ' # ' : NEW_LINE INDENT count += 1 NEW_LINE DEDENT if list [ i - 1 ] [ j ] == ' # ' : NEW_LINE INDENT count += 1 NEW_LINE DEDENT if list [ i - 1 ] [ j + 1 ] == ' # ' : NEW_LINE INDENT count += 1 NEW_LINE DEDENT if list [ i ] [ j - 1 ] == ' # ' : NEW_LINE INDENT count += 1 NEW_LINE DEDENT if list [ i ] [ j + 1 ] == ' # ' : NEW_LINE INDENT count += 1 NEW_LINE DEDENT if list [ i + 1 ] [ j - 1 ] == ' # ' : NEW_LINE INDENT count += 1 NEW_LINE DEDENT if list [ i + 1 ] [ j ] == ' # ' : NEW_LINE INDENT count += 1 NEW_LINE DEDENT if list [ i + 1 ] [ j + 1 ] == ' # ' : NEW_LINE INDENT count += 1 NEW_LINE DEDENT return count NEW_LINE DEDENT h , w = map ( int , input ( ) . split ( ) ) NEW_LINE s_init = '0' * ( w + 2 ) NEW_LINE list = [ ] NEW_LINE list . append ( s_init ) NEW_LINE for i in range ( h ) : NEW_LINE INDENT s = str ( input ( ) ) NEW_LINE list . append ( '0' + s + '0' ) NEW_LINE DEDENT list . append ( s_init ) NEW_LINE for i in range ( 1 , h + 1 ) : NEW_LINE INDENT for j in range ( 1 , w + 1 ) : NEW_LINE INDENT if list [ i ] [ j ] == ' . ' : NEW_LINE INDENT list [ i ] = list [ i ] [ : j ] + str ( count ( i , j ) ) + list [ i ] [ j + 1 : ] NEW_LINE DEDENT DEDENT DEDENT for i in range ( h ) : NEW_LINE INDENT print ( list [ i + 1 ] [ 1 : - 1 ] ) NEW_LINE DEDENT

import math NEW_LINE import functools NEW_LINE import itertools NEW_LINE import numpy as np NEW_LINE import sys NEW_LINE MAX_INT = int ( 10e10 ) NEW_LINE MIN_INT = - MAX_INT NEW_LINE mod = 1000000007 NEW_LINE sys . setrecursionlimit ( 1000000 ) NEW_LINE def IL ( ) : return list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE def SL ( ) : return input ( ) . split ( ) NEW_LINE def I ( ) : return int ( sys . stdin . readline ( ) ) NEW_LINE def S ( ) : return input ( ) NEW_LINE def judge ( n , m ) : NEW_LINE INDENT if ( 0 <= n < H ) and ( 0 <= m < W ) and s [ n ] [ m ] == " # " : NEW_LINE INDENT return True NEW_LINE DEDENT DEDENT def cnt ( a , b ) : NEW_LINE INDENT l = [ - 1 , 0 , 1 ] NEW_LINE num = 0 NEW_LINE for i in l : NEW_LINE INDENT for j in l : NEW_LINE INDENT if i == j == 0 : NEW_LINE INDENT continue NEW_LINE DEDENT else : NEW_LINE INDENT if judge ( a + i , b + j ) : NEW_LINE INDENT num += 1 NEW_LINE DEDENT DEDENT DEDENT DEDENT return num NEW_LINE DEDENT H , W = IL ( ) NEW_LINE s = [ [ i for i in S ( ) ] for i in range ( H ) ] NEW_LINE ans = [ [ " # " for i in range ( W ) ] for i in range ( H ) ] NEW_LINE for i in range ( H ) : NEW_LINE INDENT for j in range ( W ) : NEW_LINE INDENT if s [ i ] [ j ] == " . " : NEW_LINE INDENT ans [ i ] [ j ] = cnt ( i , j ) NEW_LINE DEDENT DEDENT DEDENT for i in ans : NEW_LINE INDENT print ( " " . join ( list ( map ( str , i ) ) ) ) NEW_LINE DEDENT

h , w = map ( int , input ( ) . split ( ) ) NEW_LINE S = [ input ( ) for i in range ( h ) ] NEW_LINE def count ( x , y ) : NEW_LINE INDENT p = 0 NEW_LINE if x >= 1 and y >= 1 and S [ x - 1 ] [ y - 1 ] == " # " : NEW_LINE INDENT p += 1 NEW_LINE DEDENT if x >= 1 and S [ x - 1 ] [ y ] == " # " : NEW_LINE INDENT p += 1 NEW_LINE DEDENT if x >= 1 and y <= w - 2 and S [ x - 1 ] [ y + 1 ] == " # " : NEW_LINE INDENT p += 1 NEW_LINE DEDENT if y >= 1 and S [ x ] [ y - 1 ] == " # " : NEW_LINE INDENT p += 1 NEW_LINE DEDENT if y <= w - 2 and S [ x ] [ y + 1 ] == " # " : NEW_LINE INDENT p += 1 NEW_LINE DEDENT if x <= h - 2 and y >= 1 and S [ x + 1 ] [ y - 1 ] == " # " : NEW_LINE INDENT p += 1 NEW_LINE DEDENT if x <= h - 2 and S [ x + 1 ] [ y ] == " # " : NEW_LINE INDENT p += 1 NEW_LINE DEDENT if x <= h - 2 and y <= w - 2 and S [ x + 1 ] [ y + 1 ] == " # " : NEW_LINE INDENT p += 1 NEW_LINE DEDENT p = str ( p ) NEW_LINE return ( p ) NEW_LINE DEDENT for i in range ( h ) : NEW_LINE INDENT ans = " " NEW_LINE for j in range ( w ) : NEW_LINE INDENT if S [ i ] [ j ] == " # " : NEW_LINE INDENT ans += " # " NEW_LINE DEDENT else : NEW_LINE INDENT ans += count ( i , j ) NEW_LINE DEDENT DEDENT print ( ans ) NEW_LINE DEDENT

H , W = map ( int , input ( ) . split ( ) ) NEW_LINE Ss = [ [ " . " ] + [ j for j in input ( ) ] + [ " . " ] for i in range ( H ) ] NEW_LINE Ss . insert ( 0 , [ " . " ] * len ( Ss [ 0 ] ) ) NEW_LINE Ss . append ( [ " . " ] * len ( Ss [ 0 ] ) ) NEW_LINE ans = [ ] NEW_LINE for i in range ( 1 , len ( Ss ) - 1 ) : NEW_LINE INDENT nums = [ ] NEW_LINE for j in range ( 1 , len ( Ss [ i ] ) - 1 ) : NEW_LINE INDENT num = 0 NEW_LINE if Ss [ i ] [ j ] == " . " : NEW_LINE INDENT if Ss [ i + 1 ] [ j ] == " # " : NEW_LINE INDENT num += 1 NEW_LINE DEDENT if Ss [ i + 1 ] [ j + 1 ] == " # " : NEW_LINE INDENT num += 1 NEW_LINE DEDENT if Ss [ i + 1 ] [ j - 1 ] == " # " : NEW_LINE INDENT num += 1 NEW_LINE DEDENT if Ss [ i - 1 ] [ j ] == " # " : NEW_LINE INDENT num += 1 NEW_LINE DEDENT if Ss [ i - 1 ] [ j + 1 ] == " # " : NEW_LINE INDENT num += 1 NEW_LINE DEDENT if Ss [ i - 1 ] [ j - 1 ] == " # " : NEW_LINE INDENT num += 1 NEW_LINE DEDENT if Ss [ i ] [ j + 1 ] == " # " : NEW_LINE INDENT num += 1 NEW_LINE DEDENT if Ss [ i ] [ j - 1 ] == " # " : NEW_LINE INDENT num += 1 NEW_LINE DEDENT nums . append ( str ( num ) ) NEW_LINE DEDENT else : NEW_LINE INDENT nums . append ( " # " ) NEW_LINE DEDENT DEDENT print ( " " . join ( nums ) ) NEW_LINE DEDENT


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

import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int c = sc . nextInt ( ) ; int x3 = Math . abs ( a - b ) ; int x1 = Math . abs ( a - c ) ; int x2 = Math . abs ( b - c ) ; int total = x1 + x2 + x3 ; total = Math . abs ( total - ( Math . max ( x3 , Math . max ( x2 , x1 ) ) ) ) ; System . out . println ( total ) ; } }

import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { new Main ( ) . solveA ( ) ; } private void solveA ( ) { Scanner scanner = null ; int numA1 = 0 ; int numA2 = 0 ; int numA3 = 0 ; try { scanner = new Scanner ( System . in ) ; int [ ] wk = new int [ 3 ] ; for ( int i = 0 ; i < wk . length ; i ++ ) { wk [ i ] = scanner . nextInt ( ) ; } Arrays . sort ( wk ) ; int res = Math . abs ( wk [ 0 ] - wk [ 1 ] ) + Math . abs ( wk [ 1 ] - wk [ 2 ] ) ; System . out . println ( res ) ; } finally { if ( scanner != null ) { scanner . close ( ) ; } } } private void solveB ( ) { Scanner scanner = null ; int numN = 0 ; int numK = 0 ; int numS = 0 ; try { scanner = new Scanner ( System . in ) ; numN = scanner . nextInt ( ) ; System . out . println ( " " ) ; } finally { if ( scanner != null ) { scanner . close ( ) ; } } } private void solveC ( ) { Scanner scanner = null ; int numN = 0 ; int numK = 0 ; int numS = 0 ; try { scanner = new Scanner ( System . in ) ; numN = scanner . nextInt ( ) ; System . out . println ( " " ) ; } finally { if ( scanner != null ) { scanner . close ( ) ; } } } private void solveD ( ) { Scanner scanner = null ; int numN = 0 ; int numK = 0 ; int numS = 0 ; try { scanner = new Scanner ( System . in ) ; numN = scanner . nextInt ( ) ; System . out . println ( " " ) ; } finally { if ( scanner != null ) { scanner . close ( ) ; } } } }

import java . util . ArrayList ; import java . util . Collections ; import java . util . List ; import java . util . Scanner ; import java . util . stream . IntStream ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; List < Integer > a = new ArrayList < > ( ) ; IntStream . range ( 0 , 3 ) . forEach ( i -> a . add ( sc . nextInt ( ) ) ) ; Collections . sort ( a ) ; System . out . println ( Math . abs ( a . get ( 2 ) - a . get ( 1 ) ) + Math . abs ( a . get ( 1 ) - a . get ( 0 ) ) ) ; } }

import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; int [ ] A = { sc . nextInt ( ) , sc . nextInt ( ) , sc . nextInt ( ) } ; int min = Integer . MAX_VALUE ; for ( int i = 0 ; i < 3 ; i ++ ) { for ( int j = 0 ; j < 3 ; j ++ ) { if ( j == i ) continue ; for ( int k = 0 ; k < 3 ; k ++ ) { if ( k == i || k == j ) continue ; int cost = Math . abs ( A [ i ] - A [ j ] ) + Math . abs ( A [ j ] - A [ k ] ) ; if ( min > cost ) min = cost ; } } } System . out . println ( min ) ; } }

List = [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE print ( max ( List ) - min ( List ) ) NEW_LINE

task = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE task = sorted ( task ) NEW_LINE cost = 0 NEW_LINE for i in range ( 2 ) : NEW_LINE INDENT cost += task [ i + 1 ] - task [ i ] NEW_LINE DEDENT print ( cost ) NEW_LINE

a , b , c = map ( int , input ( ) . split ( ) ) NEW_LINE s = abs ( a - b ) + abs ( b - c ) + abs ( c - a ) NEW_LINE m = max ( abs ( a - b ) , abs ( b - c ) , abs ( c - a ) ) NEW_LINE print ( s - m ) NEW_LINE

A = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE A . sort ( ) NEW_LINE ans = 0 NEW_LINE for i in range ( 1 , len ( A ) ) : NEW_LINE INDENT ans += abs ( A [ i ] - A [ i - 1 ] ) NEW_LINE DEDENT print ( ans ) NEW_LINE

A = sorted ( list ( map ( int , input ( ) . split ( ) ) ) , reverse = True ) NEW_LINE print ( abs ( ( A [ 1 ] - A [ 0 ] ) ) + abs ( ( A [ 2 ] - A [ 1 ] ) ) ) NEW_LINE


import java . util . * ; import java . lang . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int k = sc . nextInt ( ) ; long [ ] a = new long [ n ] ; long [ ] sum = new long [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = sc . nextLong ( ) ; } sum [ 0 ] = a [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { sum [ i ] = sum [ i - 1 ] + a [ i ] ; } long su = sum [ k - 1 ] ; for ( int i = k ; i < n ; i ++ ) { su += sum [ i ] - sum [ i - k ] ; } System . out . println ( su ) ; } }

import java . util . * ; import java . awt . * ; import static java . lang . System . * ; import static java . lang . Math . * ; public class Main { public static void main ( String [ ] $ ) { Scanner sc = new Scanner ( in ) ; int n = sc . nextInt ( ) ; int k = sc . nextInt ( ) ; long [ ] a = new long [ n + 1 ] ; for ( int i = 1 ; i <= n ; i ++ ) { a [ i ] = sc . nextLong ( ) ; } long ans = 0 ; for ( int i = 1 ; i <= n - k + 1 ; i ++ ) { for ( int j = 0 ; j < k ; j ++ ) { ans += a [ i + j ] ; } } out . println ( ans ) ; } static long power ( long x , int n ) { long mod = 1000000007 ; long ans = 1 ; while ( n > 0 ) { if ( ( n & 1 ) == 1 ) { ans = ( ans * x ) % mod ; } x = ( x * x ) % mod ; n >>= 1 ; } return ans ; } static int gcd ( int a , int b ) { int temp ; while ( ( temp = a % b ) != 0 ) { a = b ; b = temp ; } return b ; } static class UF { static int size = 51 ; static int [ ] par = new int [ size ] ; static void init ( ) { for ( int i = 1 ; i < size ; i ++ ) { par [ i ] = i ; } } static int root ( int x ) { if ( par [ x ] == x ) { return x ; } else { return par [ x ] = root ( par [ x ] ) ; } } static boolean same ( int x , int y ) { return root ( x ) == root ( y ) ; } static void unite ( int x , int y ) { x = root ( x ) ; y = root ( y ) ; if ( x == y ) return ; par [ x ] = y ; } } }

public class Main { private static java . util . Scanner scanner = new java . util . Scanner ( System . in ) ; public static void main ( String [ ] args ) { int n = scanner . nextInt ( ) , k = scanner . nextInt ( ) ; System . out . println ( java . util . stream . LongStream . range ( 0 , n ) . map ( i -> scanner . nextInt ( ) * Math . min ( Math . min ( Math . min ( i + 1 , n - i ) , k ) , n - k + 1 ) ) . sum ( ) ) ; } }

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 K = sc . nextInt ( ) ; int [ ] a = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { a [ i ] = sc . nextInt ( ) ; } int [ ] cum = new int [ N + 1 ] ; for ( int i = 0 ; i <= N - K ; i ++ ) { cum [ i ] ++ ; cum [ i + K ] -- ; } for ( int i = 1 ; i <= N ; i ++ ) { cum [ i ] += cum [ i - 1 ] ; } long ans = 0 ; for ( int i = 0 ; i < N ; i ++ ) { ans += ( long ) a [ i ] * cum [ i ] ; } out . println ( ans ) ; } }

import java . util . * ; import java . awt . * ; import java . awt . geom . * ; import static java . lang . System . * ; import static java . lang . Math . * ; public class Main { public static void main ( String [ ] $ ) { Scanner sc = new Scanner ( in ) ; int n = sc . nextInt ( ) , k = sc . nextInt ( ) ; long ans = 0 ; long [ ] a = new long [ n + 1 ] ; for ( int i = 1 ; i <= n ; i ++ ) { a [ i ] = sc . nextLong ( ) ; a [ i ] += a [ i - 1 ] ; } for ( int i = k ; i <= n ; i ++ ) { ans += a [ i ] - a [ i - k ] ; } out . println ( ans ) ; } }

N , K = map ( int , input ( ) . split ( ) ) NEW_LINE A = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE ans = sum ( A [ : K ] ) NEW_LINE now = sum ( A [ : K ] ) NEW_LINE for i in range ( N - K ) : NEW_LINE INDENT now -= A [ i ] NEW_LINE now += A [ i + K ] NEW_LINE ans += now NEW_LINE DEDENT print ( ans ) NEW_LINE

from numpy import * NEW_LINE def section_sum ( numbers , separate ) : NEW_LINE INDENT sep1 = array ( numbers [ separate : ] , dtype = int ) NEW_LINE sep2 = array ( numbers [ : - separate ] , dtype = int ) NEW_LINE sep3 = sum ( numbers [ : separate ] ) NEW_LINE return insert ( sep3 + cumsum ( sep1 - sep2 ) , 0 , sep3 ) NEW_LINE DEDENT n , k , * a = map ( int , open ( 0 ) . read ( ) . split ( ) ) NEW_LINE print ( sum ( section_sum ( a , k ) ) ) NEW_LINE

from itertools import accumulate NEW_LINE N , K = map ( int , input ( ) . split ( ) ) NEW_LINE a = [ 0 ] + [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE b = list ( accumulate ( a ) ) NEW_LINE ans = 0 NEW_LINE for x , y in zip ( b , b [ K : ] ) : NEW_LINE INDENT ans += y - x NEW_LINE DEDENT print ( ans ) NEW_LINE

def main ( ) : NEW_LINE INDENT N , K = [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE l = [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE sum_list = getSumList ( l ) NEW_LINE res = 0 NEW_LINE for i in range ( N - K + 1 ) : NEW_LINE INDENT if ( i == 0 ) : NEW_LINE INDENT res += ( sum_list [ i + K - 1 ] - 0 ) NEW_LINE DEDENT else : NEW_LINE INDENT res += ( sum_list [ i + K - 1 ] - sum_list [ i - 1 ] ) NEW_LINE DEDENT DEDENT print ( res ) NEW_LINE DEDENT def getSumList ( li ) : NEW_LINE INDENT sum_list = [ 0 ] NEW_LINE for i in li : NEW_LINE INDENT sum_list . append ( sum_list [ - 1 ] + i ) NEW_LINE DEDENT del sum_list [ 0 ] NEW_LINE return sum_list NEW_LINE DEDENT main ( ) NEW_LINE

from itertools import accumulate as ac NEW_LINE N , K = map ( int , input ( ) . split ( ) ) NEW_LINE lst_a = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE lst_imosu = [ 0 ] * ( N + 1 ) NEW_LINE for l in range ( N - K + 1 ) : NEW_LINE INDENT r = l + K NEW_LINE lst_imosu [ l ] += 1 NEW_LINE lst_imosu [ r ] -= 1 NEW_LINE DEDENT lst_ac = list ( ac ( lst_imosu ) ) [ 0 : N ] NEW_LINE ans = 0 NEW_LINE for a , i_ac in zip ( lst_a , lst_ac ) : NEW_LINE INDENT ans += a * i_ac NEW_LINE DEDENT print ( ans ) NEW_LINE