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


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

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


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 .


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

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 . 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 " ) ; } }


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

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 . * ; 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 ) ; } }


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

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 . * ; 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 ) ; } }


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

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


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 .

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 { 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 .


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

_ = 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 . 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 ( ) ) ; } }


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

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


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

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


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

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


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


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

n = int ( input ( ) ) NEW_LINE l_i = 0 NEW_LINE l_i_1 = 1 NEW_LINE l_i_2 = 2 NEW_LINE if n == 1 : NEW_LINE INDENT print ( "1" ) NEW_LINE DEDENT else : NEW_LINE INDENT for i in range ( n - 1 ) : NEW_LINE INDENT l_i = 0 NEW_LINE l_i = l_i_1 + l_i_2 NEW_LINE l_i_2 = l_i_1 NEW_LINE l_i_1 = l_i NEW_LINE DEDENT print ( l_i ) NEW_LINE DEDENT


from functools import lru_cache NEW_LINE @ lru_cache ( maxsize = 1000 ) NEW_LINE def lucas ( i ) : NEW_LINE INDENT if i == 0 : NEW_LINE INDENT return 2 NEW_LINE DEDENT if i == 1 : NEW_LINE INDENT return 1 NEW_LINE DEDENT return lucas ( i - 1 ) + lucas ( i - 2 ) NEW_LINE DEDENT print ( lucas ( int ( input ( ) ) ) ) NEW_LINE


N = int ( input ( ) ) NEW_LINE ryukasu = [ 2 , 1 ] NEW_LINE for i in range ( 2 , N + 1 ) : NEW_LINE INDENT ryukasu . append ( ryukasu [ i - 1 ] + ryukasu [ i - 2 ] ) NEW_LINE DEDENT print ( ryukasu [ - 1 ] ) NEW_LINE


N = int ( input ( ) ) NEW_LINE L0 = 2 NEW_LINE L1 = 1 NEW_LINE i = N NEW_LINE while i - 1 > 0 : NEW_LINE INDENT Ln = L0 + L1 NEW_LINE i -= 1 NEW_LINE L0 = L1 NEW_LINE L1 = Ln NEW_LINE DEDENT if N == 0 : NEW_LINE INDENT print ( 2 ) NEW_LINE DEDENT elif N == 1 : NEW_LINE INDENT print ( 1 ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( Ln ) NEW_LINE DEDENT


N = int ( input ( ) ) NEW_LINE luca = [ 2 , 1 ] NEW_LINE while len ( luca ) <= N : NEW_LINE INDENT luca . append ( luca [ - 2 ] + luca [ - 1 ] ) NEW_LINE DEDENT print ( luca [ N ] ) NEW_LINE


import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStream ; import java . io . InputStreamReader ; import java . io . OutputStream ; import java . io . PrintWriter ; import java . util . StringTokenizer ; public class Main { public static void main ( String [ ] args ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; InputReader in = new InputReader ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; Task solver = new Task ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class Task { public void solve ( int testNumber , InputReader in , PrintWriter out ) { int N = in . nextInt ( ) ; long [ ] L = new long [ 87 ] ; L [ 0 ] = 2 ; L [ 1 ] = 1 ; for ( int i = 2 ; i < L . length ; i ++ ) { L [ i ] = L [ i - 1 ] + L [ i - 2 ] ; } out . println ( L [ N ] ) ; } } static class InputReader { public BufferedReader reader ; public StringTokenizer tokenizer ; public InputReader ( InputStream stream ) { reader = new BufferedReader ( new InputStreamReader ( stream ) , 32768 ) ; tokenizer = null ; } public String next ( ) { while ( tokenizer == null || ! tokenizer . hasMoreTokens ( ) ) { try { tokenizer = new StringTokenizer ( reader . readLine ( ) ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } } return tokenizer . nextToken ( ) ; } public int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } } }


import java . util . ArrayList ; import java . util . List ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; List < Long > lucas = new ArrayList < > ( ) ; lucas . add ( 2L ) ; lucas . add ( 1L ) ; for ( int i = 2 ; i <= n ; i ++ ) { lucas . add ( lucas . get ( i - 1 ) + lucas . get ( i - 2 ) ) ; } System . out . println ( lucas . get ( n ) ) ; } }


import java . util . * ; public class Main { public static void main ( String [ ] args ) { B ( ) ; } public static void A ( ) { Scanner sc = new Scanner ( System . in ) ; Integer n = sc . nextInt ( ) ; sc . close ( ) ; String num = n . toString ( ) ; if ( num . charAt ( 1 ) != num . charAt ( 2 ) ) { System . out . println ( " No " ) ; return ; } char mid = num . charAt ( 1 ) ; if ( mid == num . charAt ( 0 ) || mid == num . charAt ( 3 ) ) { System . out . println ( " Yes " ) ; } else System . out . println ( " No " ) ; } public static void B ( ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; if ( N == 1 ) { System . out . println ( 1 ) ; return ; } sc . close ( ) ; long Li = 2 ; long Lj = 1 ; long temp ; for ( int i = 2 ; i < N + 1 ; i ++ ) { temp = Lj ; Lj = Li + Lj ; Li = temp ; } System . out . println ( Lj ) ; } }


import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader input = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int n = Integer . parseInt ( input . readLine ( ) ) ; long [ ] nValues = new long [ n + 1 ] ; nValues [ 0 ] = 2 ; nValues [ 1 ] = 1 ; for ( int i = 2 ; i <= n ; i ++ ) { nValues [ i ] = nValues [ i - 1 ] + nValues [ i - 2 ] ; } System . out . println ( nValues [ n ] ) ; } }


import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int x = sc . nextInt ( ) ; int [ ] nums = new int [ n ] ; int output = 0 ; for ( int i = 0 ; i < n ; i ++ ) { nums [ i ] = sc . nextInt ( ) ; } for ( int i = 0 ; i < n ; i ++ ) { if ( x % Math . pow ( 2 , i + 1 ) - x % Math . pow ( 2 , i ) != 0 ) { output += nums [ i ] ; } } System . out . println ( output ) ; } }

n , x = map ( int , input ( ) . split ( ) ) NEW_LINE a = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE y = format ( x , " b " ) NEW_LINE y = list ( y ) [ : : - 1 ] NEW_LINE res = 0 NEW_LINE for i in range ( len ( y ) ) : NEW_LINE INDENT if y [ i ] == "1" : NEW_LINE INDENT res += a [ i ] NEW_LINE DEDENT DEDENT print ( res ) NEW_LINE


N , K = [ int ( _ ) for _ in input ( ) . split ( ) ] NEW_LINE A = [ int ( _ ) for _ in input ( ) . split ( ) ] NEW_LINE res = 0 NEW_LINE for i in range ( N ) : NEW_LINE INDENT if ( K >> i ) & 1 == 1 : NEW_LINE INDENT res += A [ i ] NEW_LINE DEDENT DEDENT print ( res ) NEW_LINE


n , X = map ( int , input ( ) . split ( ) ) NEW_LINE price = [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE X_bin = format ( X , '0' + str ( n ) + ' b ' ) NEW_LINE ans = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT if X_bin [ i ] == '1' : NEW_LINE INDENT ans += price [ n - 1 - i ] NEW_LINE DEDENT DEDENT print ( ans ) NEW_LINE


list = input ( ) . split ( " ▁ " ) NEW_LINE a = input ( ) . split ( " ▁ " ) NEW_LINE b = int ( list [ 1 ] ) NEW_LINE sum = 0 NEW_LINE for i in range ( int ( list [ 0 ] ) ) : NEW_LINE INDENT if b % 2 == 1 : NEW_LINE INDENT sum += int ( a [ i ] ) NEW_LINE DEDENT b = b // 2 NEW_LINE DEDENT print ( sum ) NEW_LINE


n , X = map ( int , input ( ) . split ( ) ) NEW_LINE a = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE bX = bin ( X ) [ 2 : ] NEW_LINE bX = '0' * ( n - len ( bX ) ) + bX NEW_LINE print ( sum ( [ e for e , _ in zip ( reversed ( a ) , list ( bX ) ) if _ == '1' ] ) ) NEW_LINE


import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; String nx = scanner . nextLine ( ) ; String price = scanner . nextLine ( ) ; scanner . close ( ) ; int n = Integer . parseInt ( nx . split ( " ▁ " ) [ 0 ] ) ; int x = Integer . parseInt ( nx . split ( " ▁ " ) [ 1 ] ) ; String [ ] prices = price . split ( " ▁ " ) ; String bitX = Integer . toBinaryString ( x ) ; int toAddZero = n - bitX . length ( ) ; for ( int i = 0 ; i < toAddZero ; i ++ ) { bitX = "0" + bitX ; } boolean [ ] shouldAdd = new boolean [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { String bit = bitX . substring ( bitX . length ( ) - 1 - i , bitX . length ( ) - i ) ; shouldAdd [ i ] = bit . equals ( "1" ) ; } int sumPrice = 0 ; for ( int i = 0 ; i < shouldAdd . length ; i ++ ) { if ( shouldAdd [ i ] ) { sumPrice += Integer . parseInt ( prices [ i ] ) ; } } System . out . println ( sumPrice ) ; } }


import java . util . ArrayList ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { ArrayList < Long > mo = new ArrayList < Long > ( ) ; long answer = 0 ; Scanner sc = new Scanner ( System . in ) ; int num = sc . nextInt ( ) ; int du = sc . nextInt ( ) ; String d = Integer . toBinaryString ( du ) ; for ( int i = 0 ; i != d . length ( ) ; i ++ ) { int c = sc . nextInt ( ) ; if ( d . charAt ( d . length ( ) - 1 - i ) == '1' ) { answer += c ; } } System . out . println ( + answer ) ; } }


import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; long x = sc . nextLong ( ) ; char [ ] _list = Long . toBinaryString ( x ) . toCharArray ( ) ; char [ ] list = new char [ n ] ; for ( int i = 0 ; i < _list . length ; i ++ ) { list [ i ] = _list [ _list . length - i - 1 ] ; } int totalPrice = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int price = sc . nextInt ( ) ; if ( list [ i ] == '1' ) { totalPrice += price ; } } System . out . println ( totalPrice ) ; } }


import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; String [ ] line = scanner . nextLine ( ) . split ( " ▁ " , 2 ) ; int n = Integer . parseInt ( line [ 0 ] ) ; int x = Integer . parseInt ( line [ 1 ] ) ; int result = 0 ; line = scanner . nextLine ( ) . split ( " ▁ " , n ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( ( x & ( 1 << i ) ) != 0 ) { result += Integer . parseInt ( line [ i ] ) ; } } System . out . println ( result ) ; } }


import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long n = sc . nextLong ( ) , k = sc . nextLong ( ) ; long [ ] divs = divs ( n ) ; int nd = divs . length ; long mod = 1000000007 ; HashMap < Long , Long > map = new HashMap < > ( ) ; long res = 0 ; for ( int i = 0 ; i < nd ; i ++ ) { long div = divs [ i ] ; long [ ] dd = divs ( div ) ; long nama = modPow ( k , ( div + 1 ) / 2 , mod ) ; for ( int j = 0 ; j < dd . length - 1 ; j ++ ) { nama = ( nama - map . get ( dd [ j ] ) + mod ) % mod ; } map . put ( div , nama ) ; long coef = ( div % 2 == 1 ? div : div / 2 ) ; res = ( res + nama * coef % mod ) % mod ; } System . out . println ( res ) ; } static long modPow ( long a , long b , long mod ) { long res = 1 ; long c = a ; while ( b > 0 ) { if ( b % 2 == 1 ) res = res * c % mod ; c = c * c % mod ; b /= 2 ; } return res ; } static long [ ] divs ( long x ) { long [ ] res = new long [ ( int ) ( Math . sqrt ( x ) + 2 ) * 2 ] ; int size = 0 ; long i = 1 ; for ( ; i * i < x ; i ++ ) { if ( x % i > 0 ) continue ; res [ size ++ ] = i ; } if ( i * i == x ) res [ size ++ ] = i ; i -- ; for ( ; i > 0 ; i -- ) { if ( x % i > 0 ) continue ; res [ size ++ ] = x / i ; } return Arrays . copyOf ( res , size ) ; } }

N , K = map ( int , input ( ) . split ( ) ) NEW_LINE S = [ ] ; T = [ ] NEW_LINE for x in range ( 1 , int ( N ** .5 ) + 1 ) : NEW_LINE INDENT if N % x == 0 : NEW_LINE INDENT S . append ( x ) NEW_LINE if x * x < N : NEW_LINE INDENT T . append ( N // x ) NEW_LINE DEDENT DEDENT DEDENT T . reverse ( ) NEW_LINE S += T NEW_LINE M = len ( S ) NEW_LINE U = [ ] NEW_LINE MOD = 10 ** 9 + 7 NEW_LINE ans = 0 NEW_LINE v = 0 NEW_LINE for i in range ( M ) : NEW_LINE INDENT x = S [ i ] NEW_LINE v = pow ( K , ( x + 1 ) // 2 , MOD ) NEW_LINE for j in range ( i ) : NEW_LINE INDENT y = S [ j ] NEW_LINE if x % y == 0 : NEW_LINE INDENT v -= U [ j ] NEW_LINE DEDENT DEDENT U . append ( v % MOD ) NEW_LINE ans = ( ans + ( v * x if x & 1 else v * ( x // 2 ) ) ) % MOD NEW_LINE DEDENT print ( ans ) NEW_LINE


import java . util . * ; public class Main { final static long MODULO = 1_000_000_000 + 7 ; static ArrayList < Integer > divs ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; long K = sc . nextLong ( ) ; divs = new ArrayList < > ( ) ; for ( int i = 1 ; i * i <= N ; ++ i ) { if ( N % i == 0 ) { divs . add ( i ) ; if ( i * i != N ) { divs . add ( N / i ) ; } } } Collections . sort ( divs ) ; HashMap < Integer , Long > dp = new HashMap < > ( ) ; for ( int d : divs ) { dp . put ( d , pow ( K , ( d + 1 ) / 2 ) ) ; for ( int i = 0 ; divs . get ( i ) < d ; ++ i ) { if ( d % divs . get ( i ) == 0 ) dp . put ( d , ( dp . get ( d ) - dp . get ( divs . get ( i ) ) + MODULO ) % MODULO ) ; } } long ans = 0 ; for ( int d : divs ) { ans = ( ans + dp . get ( d ) * ( d % 2 == 0 ? d / 2 : d ) ) % MODULO ; } System . out . println ( ans ) ; } static class Div { int div ; int num ; public Div ( int div , int num ) { this . div = div ; this . num = num ; } } static long pow ( long a , long n ) { long ret = 1 ; for ( ; n > 0 ; n >>= 1 , a = ( a * a ) % MODULO ) { if ( n % 2 == 1 ) { ret = ( ret * a ) % MODULO ; } } return ret ; } }


import java . util . ArrayList ; import java . util . Collections ; import java . util . HashMap ; import java . util . Scanner ; public class Main { static Scanner sc = new Scanner ( System . in ) ; static final long MOD = 1_000_000_007 ; public static void main ( String [ ] args ) { long N = sc . nextInt ( ) ; long K = sc . nextInt ( ) ; if ( N == 1 ) { System . out . println ( K ) ; return ; } ArrayList < Long > divisor = new ArrayList < > ( ) ; for ( long i = 2 ; i * i <= N ; i ++ ) { if ( N % i != 0 ) continue ; divisor . add ( i ) ; if ( i * i != N ) { divisor . add ( N / i ) ; } } divisor . add ( N ) ; Collections . sort ( divisor ) ; HashMap < Long , Long > map = new HashMap < > ( ) ; map . put ( 1L , K ) ; for ( long d : divisor ) { long add = pow ( K , ( d + 1 ) / 2 ) - K ; for ( long i = 2 ; i * i <= d ; i ++ ) { if ( d % i != 0 ) continue ; add += MOD - map . get ( i ) ; if ( i * i != d ) add += MOD - map . get ( d / i ) ; } map . put ( d , add % MOD ) ; } long ans = 0 ; for ( long k : map . keySet ( ) ) { ans += ( k % 2 == 0 ? k / 2 : k ) * map . get ( k ) ; } System . out . println ( ans % MOD ) ; } static long pow ( long base , long p ) { if ( p == 0 ) return 1 ; if ( p == 1 ) return base ; long ret = pow ( base , p / 2 ) ; ret = ret * ret % MOD ; if ( p % 2 == 1 ) { ret = ret * base % MOD ; } return ret ; } }


import java . util . ArrayList ; import java . util . List ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Main main = new Main ( ) ; main . solve ( ) ; } void solve ( ) { Scanner sc = new Scanner ( System . in ) ; int n = Integer . parseInt ( sc . next ( ) ) ; List < Integer > list = new ArrayList < Integer > ( ) ; for ( int i = 0 ; i < n ; i ++ ) list . add ( Integer . parseInt ( sc . next ( ) ) ) ; sc . close ( ) ; List < Integer > res = new ArrayList < Integer > ( ) ; for ( int i = n - 1 ; i >= 0 ; i -- ) { for ( int j = i ; j >= 0 ; j -- ) { if ( list . get ( j ) == j + 1 ) { res . add ( j + 1 ) ; list . remove ( j ) ; break ; } } } if ( res . size ( ) == n ) for ( int i = n - 1 ; i >= 0 ; i -- ) System . out . println ( res . get ( i ) ) ; else System . out . println ( - 1 ) ; } }

import sys NEW_LINE N = int ( input ( ) ) NEW_LINE b = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE ans = [ ] NEW_LINE while len ( b ) > 0 : NEW_LINE INDENT poped = False NEW_LINE for i in range ( len ( b ) - 1 , - 1 , - 1 ) : NEW_LINE INDENT if i + 1 == b [ i ] : NEW_LINE INDENT ans . append ( b . pop ( i ) ) NEW_LINE poped = True NEW_LINE break NEW_LINE DEDENT DEDENT if not poped : NEW_LINE INDENT print ( - 1 ) NEW_LINE sys . exit ( ) NEW_LINE DEDENT DEDENT ans . reverse ( ) NEW_LINE for a in ans : NEW_LINE INDENT print ( a ) NEW_LINE DEDENT


_ , s = open ( 0 ) ; a = [ ' ' ] NEW_LINE for i in s . split ( ) : a . insert ( int ( i ) - 1 , i ) NEW_LINE print ( * a [ - 1 ] and [ - 1 ] or a ) NEW_LINE


listOutput = list ( ) NEW_LINE listInput = list ( ) NEW_LINE nNum = int ( input ( ) ) NEW_LINE strInput = input ( ) NEW_LINE listInput = strInput . split ( ) NEW_LINE while ( len ( listInput ) > 0 ) and ( ( nNum - 1 ) >= 0 ) : NEW_LINE INDENT if int ( listInput [ nNum - 1 ] ) == nNum : NEW_LINE INDENT listOutput . insert ( 0 , nNum ) NEW_LINE del listInput [ nNum - 1 ] NEW_LINE nNum = len ( listInput ) NEW_LINE continue NEW_LINE DEDENT nNum -= 1 NEW_LINE DEDENT if len ( listInput ) == 0 : NEW_LINE INDENT while ( len ( listOutput ) > 0 ) : NEW_LINE INDENT print ( listOutput . pop ( 0 ) ) NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT print ( ' - 1' ) NEW_LINE DEDENT


N = int ( input ( ) ) NEW_LINE b = [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE a = [ 0 for i in range ( N ) ] NEW_LINE number = [ ] NEW_LINE for j in range ( N ) : NEW_LINE INDENT for i in range ( len ( b ) - 1 , - 1 , - 1 ) : NEW_LINE INDENT if ( i + 1 == b [ i ] and a [ i ] == 0 ) : NEW_LINE INDENT del a [ i ] NEW_LINE number . append ( b [ i ] ) NEW_LINE del b [ i ] NEW_LINE break NEW_LINE DEDENT DEDENT DEDENT if ( not a ) : NEW_LINE INDENT for i in range ( N ) : NEW_LINE INDENT print ( number . pop ( ) ) NEW_LINE DEDENT DEDENT if ( a ) : NEW_LINE INDENT print ( - 1 ) NEW_LINE DEDENT


a = [ ] NEW_LINE num_len = int ( input ( ) ) NEW_LINE b = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE N = 100 NEW_LINE for i in range ( num_len ) : NEW_LINE INDENT if b [ i ] - 1 <= len ( a ) : NEW_LINE INDENT a . insert ( b [ i ] - 1 , b [ i ] ) NEW_LINE flag = True NEW_LINE DEDENT else : NEW_LINE INDENT flag = False NEW_LINE break NEW_LINE DEDENT DEDENT if flag : NEW_LINE INDENT for i in a : NEW_LINE INDENT print ( i ) NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT print ( - 1 ) NEW_LINE DEDENT


import java . util . * ; import java . io . * ; import java . awt . * ; import java . awt . geom . Point2D ; import static java . lang . Math . * ; public class Main { public static void main ( String [ ] $ ) { int n = sc . nextInt ( ) ; ArrayList < Integer > list = new ArrayList < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { list . add ( sc . nextInt ( ) ) ; } ArrayDeque < Integer > ans = new ArrayDeque < > ( ) ; int c = 1 ; while ( c == 1 && ! list . isEmpty ( ) ) { for ( int i = list . size ( ) - 1 ; i > - 1 ; i -- ) { if ( list . get ( i ) == i + 1 ) { ans . push ( list . get ( i ) ) ; list . remove ( i ) ; c = 1 ; break ; } else c = 0 ; } } if ( list . size ( ) > 0 ) { out . println ( - 1 ) ; } else { while ( ! ans . isEmpty ( ) ) { out . println ( ans . pop ( ) ) ; } } out . close ( ) ; } static PrintWriter out = new PrintWriter ( System . out ) ; static class sc { static Scanner s = new Scanner ( System . in ) ; static String next ( ) { return s . next ( ) ; } static int nextInt ( ) { return Integer . parseInt ( s . next ( ) ) ; } static long nextLong ( ) { return Long . parseLong ( s . next ( ) ) ; } static double nextDouble ( ) { return Double . parseDouble ( s . next ( ) ) ; } } }


import java . util . * ; import static java . lang . System . * ; public class Main { static Scanner sc = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { int N = ni ( ) ; List < Integer > b = new ArrayList < > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { b . add ( sc . nextInt ( ) ) ; } List < Integer > seq = new ArrayList < > ( ) ; boolean canPick = true ; while ( canPick ) { canPick = false ; for ( int i = b . size ( ) - 1 ; i >= 0 ; i -- ) { if ( b . get ( i ) == i + 1 ) { b . remove ( i ) ; seq . add ( i + 1 ) ; canPick = true ; break ; } } } if ( b . isEmpty ( ) ) { Collections . reverse ( seq ) ; for ( int s : seq ) { out . println ( s ) ; } } else { out . println ( - 1 ) ; } } static int ni ( ) { return sc . nextInt ( ) ; } static long nl ( ) { return sc . nextLong ( ) ; } static String ns ( ) { return sc . next ( ) ; } static int [ ] niarr ( int N ) { int [ ] a = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { a [ i ] = sc . nextInt ( ) ; } return a ; } static long [ ] nlarr ( int N ) { long [ ] a = new long [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { a [ i ] = sc . nextLong ( ) ; } return a ; } }


import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; boolean flag = false , imposible = false ; ArrayList < Integer > a = new ArrayList < Integer > ( ) ; ArrayList < Integer > b = new ArrayList < Integer > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { b . add ( sc . nextInt ( ) ) ; } for ( int i = 0 ; i < n ; i ++ ) { for ( int j = b . size ( ) - 1 ; 0 <= j ; j -- ) { if ( b . get ( j ) == j + 1 ) { a . add ( j + 1 ) ; b . remove ( j ) ; flag = true ; break ; } } if ( flag == false ) { imposible = true ; break ; } else { flag = false ; } } if ( imposible == true ) { System . out . println ( - 1 ) ; } else { for ( int i = a . size ( ) - 1 ; 0 <= i ; i -- ) { System . out . println ( a . get ( i ) ) ; } } } }


import java . util . * ; import java . io . * ; import static java . lang . System . in ; public class Main { static int n , k ; static long mod = 1000000000 + 7 ; static long [ ] fac , inv ; static int [ ] id , size ; static ArrayList < Integer > ans = new ArrayList < > ( ) ; static boolean flag = true ; public static void main ( String [ ] args ) throws IOException { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; ArrayList < Integer > rec = new ArrayList < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) rec . add ( sc . nextInt ( ) ) ; LinkedList < Integer > ans = new LinkedList < > ( ) ; while ( rec . size ( ) > 0 ) { int idx = - 1 ; for ( int i = rec . size ( ) - 1 ; i >= 0 ; i -- ) { if ( rec . get ( i ) == i + 1 ) { idx = i ; break ; } } if ( idx == - 1 ) break ; ans . addFirst ( rec . get ( idx ) ) ; rec . remove ( idx ) ; } if ( ans . size ( ) != n ) System . out . println ( - 1 ) ; else { for ( int w : ans ) System . out . println ( w ) ; } } }


import java . util . Map ; import java . util . Scanner ; import java . util . TreeMap ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; long [ ] A = new long [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { A [ i ] = sc . nextLong ( ) ; } sc . close ( ) ; long [ ] b = new long [ N + 1 ] ; for ( int i = 0 ; i < N ; i ++ ) { b [ i + 1 ] = b [ i ] + A [ i ] ; } Map < Long , Long > m = new TreeMap < Long , Long > ( ) ; for ( int i = 1 ; i <= N ; i ++ ) { m . merge ( b [ i ] , 1l , ( v1 , v2 ) -> ( v1 + v2 ) ) ; } long ans = 0 ; for ( long k : m . keySet ( ) ) { if ( k == 0 ) { long t = m . get ( k ) ; ans += t * ( t + 1 ) / 2 ; } else { long t = m . get ( k ) ; ans += t * ( t - 1 ) / 2 ; } } System . out . println ( ans ) ; } }

n = int ( input ( ) ) NEW_LINE a = list ( int ( i ) for i in input ( ) . split ( ) ) NEW_LINE sa = [ 0 ] * ( n + 1 ) NEW_LINE num_cnt = { } NEW_LINE for i in range ( n ) : NEW_LINE INDENT sa [ i + 1 ] = sa [ i ] + a [ i ] NEW_LINE DEDENT for num in sa : NEW_LINE INDENT if num in num_cnt : NEW_LINE INDENT num_cnt [ num ] += 1 NEW_LINE DEDENT else : NEW_LINE INDENT num_cnt [ num ] = 1 NEW_LINE DEDENT DEDENT res = 0 NEW_LINE for cnt in num_cnt . values ( ) : NEW_LINE INDENT res += cnt * ( cnt - 1 ) // 2 NEW_LINE DEDENT print ( res ) NEW_LINE


import collections , itertools ; input ( ) ; print ( sum ( ( s * ( s - 1 ) ) // 2 for s in collections . Counter ( ( i for i in itertools . accumulate ( [ 0 ] + [ int ( i ) for i in input ( ) . split ( ) ] ) ) ) . values ( ) ) ) NEW_LINE


from itertools import * NEW_LINE from operator import mul NEW_LINE from functools import reduce NEW_LINE from collections import * NEW_LINE n , * a = map ( int , open ( 0 ) . read ( ) . split ( ) ) NEW_LINE def cmb ( n , r ) : NEW_LINE INDENT r = min ( n - r , r ) NEW_LINE if r == 0 : return 1 NEW_LINE over = reduce ( mul , range ( n , n - r , - 1 ) ) NEW_LINE under = reduce ( mul , range ( 1 , r + 1 ) ) NEW_LINE return over // under NEW_LINE DEDENT b = list ( accumulate ( a ) ) NEW_LINE print ( sum ( cmb ( v , 2 ) for k , v in Counter ( b ) . items ( ) if v > 1 ) + b . count ( 0 ) ) NEW_LINE


import sys NEW_LINE def main ( ) : NEW_LINE INDENT N = int ( input ( ) ) NEW_LINE A = input ( ) . split ( " ▁ " ) NEW_LINE A = [ int ( s ) for s in A ] NEW_LINE maps = [ 0 ] * ( len ( A ) ) NEW_LINE for i , val in enumerate ( A ) : NEW_LINE INDENT maps [ i ] = maps [ i - 1 ] + val NEW_LINE DEDENT maps . append ( 0 ) NEW_LINE counts = { } NEW_LINE for i , val in enumerate ( maps ) : NEW_LINE INDENT if val in counts : NEW_LINE INDENT counts [ val ] += 1 NEW_LINE DEDENT else : NEW_LINE INDENT counts [ val ] = 1 NEW_LINE DEDENT DEDENT ans = 0 NEW_LINE for key , val in counts . items ( ) : NEW_LINE INDENT if val == 1 : NEW_LINE INDENT continue NEW_LINE DEDENT for i in range ( val - 1 , 0 , - 1 ) : NEW_LINE INDENT ans += i NEW_LINE DEDENT DEDENT print ( ans ) NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT main ( ) NEW_LINE DEDENT


from collections import defaultdict NEW_LINE N = int ( input ( ) ) NEW_LINE A = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE dp = defaultdict ( int , { 0 : 1 } ) NEW_LINE s = 0 NEW_LINE ans = 0 NEW_LINE for a in A : NEW_LINE INDENT s += a NEW_LINE ans += dp [ s ] NEW_LINE dp [ s ] += 1 NEW_LINE DEDENT print ( ans ) NEW_LINE


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 ( ) ; long [ ] a = new long [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { a [ i ] = sc . nextLong ( ) ; } long [ ] acc = new long [ N + 1 ] ; for ( int i = 0 ; i < N ; i ++ ) { acc [ i + 1 ] = acc [ i ] + a [ i ] ; } Map < Long , Integer > cnts = new HashMap < > ( ) ; for ( int i = 0 ; i <= N ; i ++ ) { int cnt = cnts . containsKey ( acc [ i ] ) ? cnts . get ( acc [ i ] ) : 0 ; cnts . put ( acc [ i ] , ++ cnt ) ; } long ans = 0 ; for ( Map . Entry e : cnts . entrySet ( ) ) { int num = ( int ) e . getValue ( ) ; ans += ( long ) num * ( num - 1 ) / 2 ; } out . println ( ans ) ; } }


import java . util . ArrayList ; import java . util . Arrays ; import java . util . Collections ; import java . util . PriorityQueue ; import java . util . Scanner ; import java . util . TreeSet ; import org . omg . Messaging . SyncScopeHelper ; import org . omg . PortableInterceptor . SYSTEM_EXCEPTION ; public class Main { Scanner sc = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { new Main ( ) ; } public Main ( ) { new Test_200 ( ) . doIt ( ) ; } class Test_200 { void doIt ( ) { int N = sc . nextInt ( ) ; long S [ ] = new long [ N + 1 ] ; S [ 0 ] = 0 ; for ( int i = 1 ; i < N + 1 ; i ++ ) { S [ i ] = S [ i - 1 ] + sc . nextLong ( ) ; } Arrays . sort ( S ) ; long ans = 0 ; long cnt = 0 ; for ( int i = 1 ; i < N + 1 ; i ++ ) { if ( S [ i ] == S [ i - 1 ] ) { cnt ++ ; ans = ans + cnt ; } else cnt = 0 ; } System . out . println ( ans ) ; } } }


import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . HashMap ; public class Main { static long t [ ] ; static long l [ ] ; static long h [ ] ; public static void main ( String [ ] args ) throws IOException { BufferedReader r = new BufferedReader ( new InputStreamReader ( System . in ) , 1 ) ; String s ; String sl [ ] ; s = r . readLine ( ) ; int n = Integer . parseInt ( s ) ; HashMap < Long , Long > m = new HashMap < > ( ) ; m . put ( 0L , 1L ) ; long a = 0 ; long v = 0 ; s = r . readLine ( ) ; sl = s . split ( " ▁ " ) ; for ( int i = 0 ; i < n ; i ++ ) { v += Long . parseLong ( sl [ i ] ) ; Long z = m . get ( v ) ; if ( z != null && z > 0 ) { a += z ; } z = m . getOrDefault ( v , 0L ) ; m . put ( v , z + 1 ) ; } System . out . println ( a ) ; } }


import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) + 1 ; long [ ] nums = new long [ n ] ; nums [ 0 ] = 0 ; long output = 0 ; for ( int i = 1 ; i < n ; i ++ ) { nums [ i ] = sc . nextInt ( ) ; } for ( int i = 1 ; i < n ; i ++ ) { nums [ i ] += nums [ i - 1 ] ; } Arrays . sort ( nums ) ; long tmp = Integer . MIN_VALUE ; int outtmp = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( tmp == nums [ i ] ) { outtmp ++ ; if ( i == n - 1 ) { i -- ; tmp = Integer . MIN_VALUE ; } } else { if ( outtmp > 1 ) { output += nc2 ( outtmp ) ; } tmp = nums [ i ] ; outtmp = 1 ; } } System . out . println ( output ) ; } static long nc2 ( long input ) { long output = 1 ; output = input * ( input - 1 ) / 2 ; return output ; } }


import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] a = new int [ n ] ; int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = sc . nextInt ( ) ; sum += a [ i ] ; } BitSet bs = new BitSet ( sum + 1 ) ; bs . set ( sum ) ; for ( int i = 0 ; i < n ; i ++ ) { BitSet cur = bs . get ( a [ i ] , sum + 1 ) ; bs . or ( cur ) ; } int ini = sum % 2 == 0 ? sum / 2 : ( sum + 1 ) / 2 ; for ( int i = ini ; i <= sum ; i ++ ) { if ( bs . get ( i ) ) { System . out . println ( i ) ; break ; } } } }

from collections import defaultdict , deque NEW_LINE import sys , heapq , bisect , math , itertools , string , queue , datetime NEW_LINE sys . setrecursionlimit ( 10 ** 8 ) NEW_LINE INF = float ( ' inf ' ) NEW_LINE mod = 10 ** 9 + 7 NEW_LINE eps = 10 ** - 7 NEW_LINE def inpl ( ) : return list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE def inpl_s ( ) : return list ( input ( ) . split ( ) ) NEW_LINE N = int ( input ( ) ) NEW_LINE aa = inpl ( ) NEW_LINE b = 1 NEW_LINE for a in aa : NEW_LINE INDENT b |= b << a NEW_LINE DEDENT S = sum ( aa ) NEW_LINE half = ( S + 1 ) // 2 NEW_LINE b >>= half NEW_LINE print ( ( b & - b ) . bit_length ( ) + half - 1 ) NEW_LINE


import math , string , itertools , fractions , heapq , collections , re , array , bisect , sys , random , time , copy , functools NEW_LINE sys . setrecursionlimit ( 10 ** 7 ) NEW_LINE inf = 10 ** 20 NEW_LINE eps = 1.0 / 10 ** 15 NEW_LINE mod = 10 ** 9 + 7 NEW_LINE def LI ( ) : return [ int ( x ) for x in sys . stdin . readline ( ) . split ( ) ] NEW_LINE def LI_ ( ) : return [ int ( x ) - 1 for x in sys . stdin . readline ( ) . split ( ) ] NEW_LINE def LF ( ) : return [ float ( x ) for x in sys . stdin . readline ( ) . split ( ) ] NEW_LINE def LS ( ) : return sys . stdin . readline ( ) . split ( ) NEW_LINE def I ( ) : return int ( sys . stdin . readline ( ) ) NEW_LINE def F ( ) : return float ( sys . stdin . readline ( ) ) NEW_LINE def S ( ) : return input ( ) NEW_LINE def pf ( s ) : return print ( s , flush = True ) NEW_LINE def main ( ) : NEW_LINE INDENT n = I ( ) NEW_LINE a = LI ( ) NEW_LINE s = sum ( a ) NEW_LINE t = 1 NEW_LINE m = 2 ** ( s // 2 + 1 ) - 1 NEW_LINE for c in a : NEW_LINE INDENT t |= t << c NEW_LINE DEDENT t &= m NEW_LINE return s - ( t . bit_length ( ) - 1 ) NEW_LINE DEDENT print ( main ( ) ) NEW_LINE


import math NEW_LINE N = int ( input ( ) ) NEW_LINE A = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE sumA = sum ( A ) NEW_LINE halfA = math . ceil ( sumA / 2 ) NEW_LINE bitset = 1 NEW_LINE for a in A : bitset |= bitset << a NEW_LINE bitset >>= halfA NEW_LINE i = 0 NEW_LINE while 1 : NEW_LINE INDENT if bitset & 1 : NEW_LINE INDENT print ( i + halfA ) NEW_LINE exit ( ) NEW_LINE DEDENT bitset >>= 1 NEW_LINE i += 1 NEW_LINE DEDENT


import numpy NEW_LINE n = int ( input ( ) ) NEW_LINE a = [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE dp = 1 NEW_LINE for i in range ( 0 , len ( a ) ) : NEW_LINE INDENT dp = ( dp | ( dp << a [ i ] ) ) NEW_LINE DEDENT asum = 0 NEW_LINE for i in range ( 0 , len ( a ) ) : NEW_LINE INDENT asum += a [ i ] NEW_LINE DEDENT for i in range ( int ( ( asum + 1 ) / 2 ) , asum + 1 ) : NEW_LINE INDENT if ( dp >> i ) & 1 : NEW_LINE INDENT print ( i ) NEW_LINE break NEW_LINE DEDENT DEDENT


input ( ) NEW_LINE a = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE dp = 1 NEW_LINE for x in a : NEW_LINE INDENT dp |= dp << x NEW_LINE DEDENT s = sum ( a ) NEW_LINE dp >>= ( s + 1 ) // 2 NEW_LINE dp <<= ( s + 1 ) // 2 NEW_LINE dp = bin ( dp ) NEW_LINE print ( len ( dp ) - len ( dp . rstrip ( '0' ) ) ) NEW_LINE