import java . awt . Point ; import java . util . ArrayDeque ; import java . util . Queue ; import java . util . Scanner ; public class Main { static int INF = 10000 ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; Queue < Point > que = new ArrayDeque < > ( ) ; int dx [ ] = { 1 , 0 , - 1 , 0 } ; int dy [ ] = { 0 , 1 , 0 , - 1 } ; int h = sc . nextInt ( ) ; int w = sc . nextInt ( ) ; int sx = sc . nextInt ( ) - 1 ; int sy = sc . nextInt ( ) - 1 ; int gx = sc . nextInt ( ) - 1 ; int gy = sc . nextInt ( ) - 1 ; char f [ ] [ ] = new char [ h ] [ w ] ; int dist [ ] [ ] = new int [ h ] [ w ] ; for ( int i = 0 ; i < h ; i ++ ) for ( int j = 0 ; j < w ; j ++ ) dist [ i ] [ j ] = INF ; for ( int i = 0 ; i < h ; i ++ ) { f [ i ] = sc . next ( ) . toCharArray ( ) ; } Point start = new Point ( sx , sy ) ; dist [ sx ] [ sy ] = 0 ; que . add ( start ) ; while ( ! que . isEmpty ( ) ) { Point p = que . poll ( ) ; if ( p . x == gx && p . y == gy ) break ; for ( int i = 0 ; i < 4 ; i ++ ) { int nx = p . x + dx [ i ] ; int ny = p . y + dy [ i ] ; if ( f [ nx ] [ ny ] == ' . ' && dist [ nx ] [ ny ] == INF ) { que . add ( new Point ( nx , ny ) ) ; dist [ nx ] [ ny ] = dist [ p . x ] [ p . y ] + 1 ; } } } System . out . println ( dist [ gx ] [ gy ] ) ; } }

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 ) ; int H = sc . nextInt ( ) ; int W = sc . nextInt ( ) ; int sy = sc . nextInt ( ) - 1 , sx = sc . nextInt ( ) - 1 , gy = sc . nextInt ( ) - 1 , gx = sc . nextInt ( ) - 1 ; int [ ] dx = { - 1 , 0 , 1 , 0 } ; int [ ] dy = { 0 , 1 , 0 , - 1 } ; char [ ] [ ] c = new char [ W ] [ H ] ; int [ ] [ ] step = new int [ W ] [ H ] ; for ( int i = 0 ; i < H ; i ++ ) { String s = sc . next ( ) ; for ( int j = 0 ; j < W ; j ++ ) { c [ j ] [ i ] = s . charAt ( j ) ; step [ j ] [ i ] = 100000 ; } } Deque < Point > stack = new ArrayDeque < > ( ) ; step [ sx ] [ sy ] = 0 ; stack . addFirst ( new Point ( sx , sy ) ) ; while ( stack . size ( ) > 0 ) { Point p = stack . pollFirst ( ) ; for ( int i = 0 ; i < 4 ; i ++ ) { int x = p . x + dx [ i ] ; int y = p . y + dy [ i ] ; if ( 0 <= x && x < W && 0 <= y && y < H && c [ x ] [ y ] == ' . ' ) { if ( step [ x ] [ y ] > step [ p . x ] [ p . y ] + 1 ) { stack . addFirst ( new Point ( x , y ) ) ; step [ x ] [ y ] = step [ p . x ] [ p . y ] + 1 ; } } } } out . println ( step [ gx ] [ gy ] ) ; } }

import java . awt . * ; import java . util . * ; import java . util . stream . IntStream ; public class Main { private static Scanner scanner = new Scanner ( System . in ) ; public static void main ( String [ ] $ ) { int r = scanner . nextInt ( ) , c = scanner . nextInt ( ) ; Point start = new Point ( scanner . nextInt ( ) - 1 , scanner . nextInt ( ) - 1 ) ; Point goal = new Point ( scanner . nextInt ( ) - 1 , scanner . nextInt ( ) - 1 ) ; int [ ] [ ] a = IntStream . range ( 0 , r ) . mapToObj ( j -> scanner . next ( ) . chars ( ) . map ( ch -> ch == ' # ' ? - 1 : 0 ) . toArray ( ) ) . toArray ( int [ ] [ ] :: new ) ; Queue < Point > queue = new ArrayDeque < > ( ) ; a [ start . x ] [ start . y ] ++ ; queue . add ( start ) ; while ( ! queue . isEmpty ( ) ) { Point point = queue . poll ( ) ; for ( int i = 0 ; i < 4 ; i ++ ) { try { int x1 = ( new int [ ] { - 1 , 1 , 0 , 0 } ) [ i ] , y1 = ( new int [ ] { 0 , 0 , - 1 , 1 } ) [ i ] ; if ( a [ point . x + x1 ] [ point . y + y1 ] > a [ point . x ] [ point . y ] + 1 || a [ point . x + x1 ] [ point . y + y1 ] == 0 ) { a [ point . x + x1 ] [ point . y + y1 ] = a [ point . x ] [ point . y ] + 1 ; queue . add ( new Point ( point . x + x1 , point . y + y1 ) ) ; } } catch ( ArrayIndexOutOfBoundsException e ) { } } } System . out . println ( a [ goal . x ] [ goal . y ] - 1 ) ; } }

import java . util . * ; import static java . lang . System . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int R = sc . nextInt ( ) ; int C = sc . nextInt ( ) ; int sy = sc . nextInt ( ) - 1 ; int sx = sc . nextInt ( ) - 1 ; int gy = sc . nextInt ( ) - 1 ; int gx = sc . nextInt ( ) - 1 ; String [ ] [ ] c = new String [ R ] [ C ] ; for ( int i = 0 ; i < R ; i ++ ) { c [ i ] = sc . next ( ) . split ( " " ) ; } Queue < Point > points = new ArrayDeque < Point > ( ) ; points . add ( new Point ( sy , sx , 0 ) ) ; c [ sy ] [ sx ] = " ! " ; out . println ( bfs ( c , points , new Point ( gy , gx , - 1 ) ) ) ; } public static int bfs ( String [ ] [ ] cource , Queue < Point > points , Point goal ) { Point point = points . poll ( ) ; int count = point . count ; if ( point . x == goal . x && point . y == goal . y ) { return count ; } int [ ] [ ] move = { { - 1 , 0 } , { 1 , 0 } , { 0 , - 1 } , { 0 , 1 } } ; count ++ ; for ( int i = 0 ; i < move . length ; i ++ ) { Point nextPoint = new Point ( point . y + move [ i ] [ 0 ] , point . x + move [ i ] [ 1 ] , count ) ; if ( cource [ nextPoint . y ] [ nextPoint . x ] . equals ( " . " ) ) { cource [ nextPoint . y ] [ nextPoint . x ] = " ! " ; points . add ( nextPoint ) ; } } return bfs ( cource , points , goal ) ; } } class Point { int y ; int x ; int count ; Point ( int y , int x , int count ) { this . y = y ; this . x = x ; this . count = count ; } }

import java . awt . Point ; import java . util . ArrayDeque ; import java . util . Queue ; import java . util . Scanner ; public class Main { static int INF = 10000 ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; Queue < Point > que = new ArrayDeque < > ( ) ; int dx [ ] = { 1 , 0 , - 1 , 0 } ; int dy [ ] = { 0 , 1 , 0 , - 1 } ; int h = sc . nextInt ( ) ; int w = sc . nextInt ( ) ; int sx = sc . nextInt ( ) - 1 ; int sy = sc . nextInt ( ) - 1 ; int gx = sc . nextInt ( ) - 1 ; int gy = sc . nextInt ( ) - 1 ; int dist [ ] [ ] = new int [ h ] [ w ] ; for ( int i = 0 ; i < h ; i ++ ) for ( int j = 0 ; j < w ; j ++ ) dist [ i ] [ j ] = INF ; char f [ ] [ ] = new char [ h ] [ w ] ; for ( int i = 0 ; i < h ; i ++ ) { f [ i ] = sc . next ( ) . toCharArray ( ) ; } dist [ sx ] [ sy ] = 0 ; que . add ( new Point ( sx , sy ) ) ; while ( ! que . isEmpty ( ) ) { Point p = que . poll ( ) ; if ( p . x == gx && p . y == gy ) break ; for ( int i = 0 ; i < 4 ; i ++ ) { int nx = p . x + dx [ i ] ; int ny = p . y + dy [ i ] ; if ( f [ nx ] [ ny ] == ' . ' && dist [ nx ] [ ny ] == INF ) { que . add ( new Point ( nx , ny ) ) ; dist [ nx ] [ ny ] = dist [ p . x ] [ p . y ] + 1 ; } } } System . out . println ( dist [ gx ] [ gy ] ) ; } }

from queue import Queue NEW_LINE h , w = map ( int , input ( ) . split ( ) ) NEW_LINE sy , sx = map ( int , input ( ) . split ( ) ) NEW_LINE sy -= 1 NEW_LINE sx -= 1 NEW_LINE gy , gx = map ( int , input ( ) . split ( ) ) NEW_LINE gy -= 1 NEW_LINE gx -= 1 NEW_LINE map = [ [ 0 ] for _ in range ( h ) ] NEW_LINE for i in range ( h ) : NEW_LINE INDENT map [ i ] = list ( input ( ) ) NEW_LINE DEDENT que = Queue ( ) NEW_LINE que . put ( [ sx , sy ] ) NEW_LINE checked = [ [ - 1 ] * w for _ in range ( h ) ] NEW_LINE checked [ sy ] [ sx ] = 0 NEW_LINE ans = 0 NEW_LINE def bfs ( ) : NEW_LINE INDENT global que , checked , ans NEW_LINE while not que . empty ( ) : NEW_LINE INDENT xy = que . get ( ) NEW_LINE if xy [ 0 ] == gx and xy [ 1 ] == gy : NEW_LINE INDENT ans = checked [ xy [ 1 ] ] [ xy [ 0 ] ] NEW_LINE DEDENT for i in range ( - 1 , 2 ) : NEW_LINE INDENT for j in range ( - 1 , 2 ) : NEW_LINE INDENT if i == j or i == - j : NEW_LINE INDENT continue NEW_LINE DEDENT if 0 <= xy [ 0 ] + i < w and 0 <= xy [ 1 ] + j < h : NEW_LINE INDENT if map [ xy [ 1 ] + j ] [ xy [ 0 ] + i ] == " . " and checked [ xy [ 1 ] + j ] [ xy [ 0 ] + i ] == - 1 : NEW_LINE INDENT checked [ xy [ 1 ] + j ] [ xy [ 0 ] + i ] = checked [ xy [ 1 ] ] [ xy [ 0 ] ] + 1 NEW_LINE que . put ( [ xy [ 0 ] + i , xy [ 1 ] + j ] ) NEW_LINE DEDENT DEDENT DEDENT DEDENT DEDENT DEDENT bfs ( ) NEW_LINE print ( ans ) NEW_LINE

from collections import deque NEW_LINE R , C = ( int ( _ ) for _ in input ( ) . split ( ) ) NEW_LINE sy , sx = ( int ( _ ) for _ in input ( ) . split ( ) ) NEW_LINE gy , gx = ( int ( _ ) for _ in input ( ) . split ( ) ) NEW_LINE maze = [ list ( input ( ) ) for _ in range ( R ) ] NEW_LINE distance_from_start = [ [ - 1 ] * C for _ in range ( R ) ] NEW_LINE move = [ [ 1 , 0 ] , [ - 1 , 0 ] , [ 0 , 1 ] , [ 0 , - 1 ] ] NEW_LINE que = deque ( ) NEW_LINE que . append ( ( sx , sy ) ) NEW_LINE distance_from_start [ sy - 1 ] [ sx - 1 ] = 0 NEW_LINE def minimum_distance ( ) : NEW_LINE INDENT while len ( que ) != 0 : NEW_LINE INDENT x , y = que . popleft ( ) NEW_LINE for i in range ( 4 ) : NEW_LINE INDENT next_x = x + move [ i ] [ 0 ] NEW_LINE next_y = y + move [ i ] [ 1 ] NEW_LINE if next_x <= 0 or next_x > C or next_y <= 0 or next_y > R or distance_from_start [ next_y - 1 ] [ next_x - 1 ] != - 1 or maze [ next_y - 1 ] [ next_x - 1 ] == " # " : NEW_LINE INDENT continue NEW_LINE DEDENT distance_from_start [ next_y - 1 ] [ next_x - 1 ] = distance_from_start [ y - 1 ] [ x - 1 ] + 1 NEW_LINE que . append ( ( next_x , next_y ) ) NEW_LINE DEDENT DEDENT DEDENT minimum_distance ( ) NEW_LINE print ( distance_from_start [ gy - 1 ] [ gx - 1 ] ) NEW_LINE

from collections import deque NEW_LINE r , c = map ( int , input ( ) . split ( ) ) NEW_LINE root = [ [ None for __ in range ( c ) ] for __ in range ( r ) ] NEW_LINE sx , sy = map ( int , input ( ) . split ( ) ) NEW_LINE gx , gy = map ( int , input ( ) . split ( ) ) NEW_LINE sy -= 1 NEW_LINE sx -= 1 NEW_LINE gy -= 1 NEW_LINE gx -= 1 NEW_LINE m = [ list ( input ( ) ) for __ in range ( r ) ] NEW_LINE root [ sx ] [ sy ] = 0 NEW_LINE celx = deque ( ) NEW_LINE cely = deque ( ) NEW_LINE x = sx NEW_LINE y = sy NEW_LINE while root [ gx ] [ gy ] == None : NEW_LINE INDENT if x != 0 and m [ x - 1 ] [ y ] != ' # ' and root [ x - 1 ] [ y ] == None : NEW_LINE INDENT root [ x - 1 ] [ y ] = root [ x ] [ y ] + 1 NEW_LINE celx . append ( x - 1 ) NEW_LINE cely . append ( y ) NEW_LINE DEDENT if x != r - 1 and m [ x + 1 ] [ y ] != ' # ' and root [ x + 1 ] [ y ] == None : NEW_LINE INDENT root [ x + 1 ] [ y ] = root [ x ] [ y ] + 1 NEW_LINE celx . append ( x + 1 ) NEW_LINE cely . append ( y ) NEW_LINE DEDENT if y != 0 and m [ x ] [ y - 1 ] != ' # ' and root [ x ] [ y - 1 ] == None : NEW_LINE INDENT root [ x ] [ y - 1 ] = root [ x ] [ y ] + 1 NEW_LINE celx . append ( x ) NEW_LINE cely . append ( y - 1 ) NEW_LINE DEDENT if y != c - 1 and m [ x ] [ y + 1 ] != ' # ' and root [ x ] [ y + 1 ] == None : NEW_LINE INDENT root [ x ] [ y + 1 ] = root [ x ] [ y ] + 1 NEW_LINE celx . append ( x ) NEW_LINE cely . append ( y + 1 ) NEW_LINE DEDENT x = celx . popleft ( ) NEW_LINE y = cely . popleft ( ) NEW_LINE DEDENT print ( root [ gx ] [ gy ] ) NEW_LINE

from collections import deque NEW_LINE def bfs ( maze , visited , sy , sx , gy , gx ) : NEW_LINE INDENT queue = deque ( [ [ sy , sx ] ] ) NEW_LINE visited [ sy ] [ sx ] = 0 NEW_LINE while queue : NEW_LINE INDENT y , x = queue . popleft ( ) NEW_LINE if [ y , x ] == [ gy , gx ] : NEW_LINE INDENT return visited [ y ] [ x ] NEW_LINE DEDENT for j , k in ( [ 1 , 0 ] , [ - 1 , 0 ] , [ 0 , 1 ] , [ 0 , - 1 ] ) : NEW_LINE INDENT new_y , new_x = y + j , x + k NEW_LINE if maze [ new_y ] [ new_x ] == " . " and visited [ new_y ] [ new_x ] == - 1 : NEW_LINE INDENT visited [ new_y ] [ new_x ] = visited [ y ] [ x ] + 1 NEW_LINE queue . append ( [ new_y , new_x ] ) NEW_LINE DEDENT DEDENT DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT R , C = map ( int , input ( ) . split ( ) ) NEW_LINE sy , sx = map ( int , input ( ) . split ( ) ) NEW_LINE gy , gx = map ( int , input ( ) . split ( ) ) NEW_LINE sy , sx , gy , gx = sy - 1 , sx - 1 , gy - 1 , gx - 1 NEW_LINE maze = [ input ( ) for i in range ( R ) ] NEW_LINE visited = [ [ - 1 ] * C for j in range ( R ) ] NEW_LINE print ( bfs ( maze , visited , sy , sx , gy , gx ) ) NEW_LINE DEDENT

from collections import deque NEW_LINE R , C = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE sy , sx = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE gy , gx = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE _d = { ' # ' : 1 , ' . ' : 0 } NEW_LINE _map = [ [ _d [ x ] for x in input ( ) ] for _ in range ( R ) ] NEW_LINE moves = [ ( 0 , 1 ) , ( 1 , 0 ) , ( 0 , - 1 ) , ( - 1 , 0 ) ] NEW_LINE dq = deque ( [ ( sy , sx , 0 ) ] ) NEW_LINE visited = set ( [ ( sy , sx ) ] ) NEW_LINE while dq : NEW_LINE INDENT y , x , dist = dq . popleft ( ) NEW_LINE for m in moves : NEW_LINE INDENT next_y = y + m [ 0 ] NEW_LINE next_x = x + m [ 1 ] NEW_LINE if next_y == gy and next_x == gx : NEW_LINE INDENT print ( dist + 1 ) NEW_LINE break NEW_LINE DEDENT if ( next_y , next_x ) not in visited : NEW_LINE INDENT if _map [ next_y - 1 ] [ next_x - 1 ] == 0 : NEW_LINE INDENT dq . append ( ( next_y , next_x , dist + 1 ) ) NEW_LINE visited . add ( ( next_y , next_x ) ) NEW_LINE DEDENT DEDENT DEDENT else : NEW_LINE INDENT continue NEW_LINE DEDENT break NEW_LINE DEDENT else : NEW_LINE INDENT print ( ' Something ▁ wrong ' ) NEW_LINE DEDENT


import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int max = 0 ; int min = 1000000000 ; int [ ] b = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { int a = sc . nextInt ( ) ; b [ i ] = a ; if ( max < b [ i ] ) { max = b [ i ] ; } if ( b [ i ] < min ) { min = b [ i ] ; } } System . out . println ( Math . abs ( max - min ) ) ; } }

import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . util . PriorityQueue ; import java . util . Queue ; public class Main { public static void main ( String args [ ] ) throws Exception { Input input = new Input ( ) ; final Data l = input . readLine ( ) ; final int n = l . col [ 0 ] ; Queue < Integer > q = input . getColQueue ( ) ; input . close ( ) ; int min = q . poll ( ) ; int max = min ; while ( ! q . isEmpty ( ) ) { max = q . poll ( ) ; } System . out . println ( max - min ) ; } static class Input { public BufferedReader input = new BufferedReader ( new InputStreamReader ( System . in ) ) ; public void close ( ) throws Exception { input . close ( ) ; } public Data readLine ( ) throws Exception { return new Data ( input . readLine ( ) . split ( " ▁ " ) ) ; } public Queue < Integer > getColQueue ( ) throws Exception { Data d = readLine ( ) ; PriorityQueue < Integer > q ; q = new PriorityQueue < > ( ( a , b ) -> a - b ) ; for ( int i = 0 ; i < d . col . length ; i ++ ) { q . offer ( d . col [ i ] ) ; } return q ; } } static class Data { public int [ ] col ; public Data ( String [ ] values ) { col = new int [ values . length ] ; for ( int i = 0 ; i < values . length ; i ++ ) { col [ i ] = Integer . parseInt ( values [ i ] ) ; } } } }

import java . io . PrintStream ; import java . util . IntSummaryStatistics ; import java . util . Scanner ; import java . util . stream . IntStream ; public class Main { static void exec ( Scanner in , PrintStream out ) { int N = in . nextInt ( ) ; int [ ] A = new int [ N ] ; for ( int i = 0 ; i < N ; i += 1 ) { A [ i ] = in . nextInt ( ) ; } IntSummaryStatistics s = IntStream . of ( A ) . summaryStatistics ( ) ; out . println ( s . getMax ( ) - s . getMin ( ) ) ; } public static void main ( String [ ] args ) { exec ( new Scanner ( System . in ) , System . out ) ; } }

import java . io . * ; import java . util . Arrays ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader stdin = new BufferedReader ( new InputStreamReader ( System . in ) ) ; stdin . readLine ( ) ; int [ ] nums = Arrays . stream ( stdin . readLine ( ) . split ( " ▁ " ) ) . mapToInt ( Integer :: parseInt ) . toArray ( ) ; Arrays . sort ( nums ) ; System . out . println ( nums [ nums . length - 1 ] - nums [ 0 ] ) ; } }

import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = Integer . parseInt ( sc . next ( ) ) ; long [ ] a = new long [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = Long . parseLong ( sc . next ( ) ) ; } Arrays . sort ( a ) ; System . out . println ( a [ a . length - 1 ] - a [ 0 ] ) ; } }

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

import itertools NEW_LINE N = int ( input ( ) ) NEW_LINE A = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE X = 0 NEW_LINE for v in itertools . combinations ( A , 2 ) : NEW_LINE INDENT if abs ( v [ 0 ] - v [ 1 ] ) > X : NEW_LINE INDENT X = abs ( v [ 0 ] - v [ 1 ] ) NEW_LINE DEDENT DEDENT print ( X ) NEW_LINE

n = int ( input ( ) ) NEW_LINE a = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE minval = 10 ** 10 NEW_LINE maxval = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT if a [ i ] > maxval : NEW_LINE INDENT maxval = a [ i ] NEW_LINE DEDENT if a [ i ] < minval : NEW_LINE INDENT minval = a [ i ] NEW_LINE DEDENT DEDENT print ( abs ( maxval - minval ) ) NEW_LINE

N = int ( input ( ) ) NEW_LINE A = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE ans = 0 NEW_LINE for i in range ( N ) : NEW_LINE INDENT for j in range ( N ) : NEW_LINE INDENT ans = max ( A [ j ] - A [ i ] , ans ) NEW_LINE DEDENT DEDENT print ( ans ) NEW_LINE

n = int ( input ( ) ) NEW_LINE a = sorted ( list ( map ( int , input ( ) . split ( ) ) ) ) NEW_LINE print ( abs ( a [ n - 1 ] - a [ 0 ] ) if len ( a ) >= 2 else 0 ) NEW_LINE


import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int m = sc . nextInt ( ) ; int x = sc . nextInt ( ) ; int y = sc . nextInt ( ) ; int [ ] a = new int [ n ] ; int [ ] b = new int [ m ] ; Pair [ ] pairs = new Pair [ n + m ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = sc . nextInt ( ) ; Pair ps = new Pair ( ) ; ps . start = a [ i ] ; ps . goal = a [ i ] + x ; ps . dir = 1 ; pairs [ i ] = ps ; } for ( int i = 0 ; i < m ; i ++ ) { b [ i ] = sc . nextInt ( ) ; Pair ps = new Pair ( ) ; ps . start = b [ i ] ; ps . goal = b [ i ] + y ; ps . dir = - 1 ; pairs [ i + n ] = ps ; } Arrays . sort ( pairs ) ; int count = 0 ; int t = 0 ; int nowdir = 1 ; for ( int i = 0 ; i < n + m ; i ++ ) { int start = pairs [ i ] . start ; int goal = pairs [ i ] . goal ; int dir = pairs [ i ] . dir ; if ( t <= start && nowdir == dir ) { count ++ ; t = goal ; nowdir *= - 1 ; } } System . out . println ( count / 2 ) ; } } class Pair implements Comparable { int start ; int goal ; int dir ; @ Override public int compareTo ( Object other ) { Pair otherpair = ( Pair ) other ; return goal - otherpair . goal ; } }

import java . util . * ; import static java . lang . System . * ; public class Main { public static void main ( String [ ] $ ) { Scanner sc = new Scanner ( in ) ; int n = sc . nextInt ( ) , m = sc . nextInt ( ) , x = sc . nextInt ( ) , y = sc . nextInt ( ) ; int [ ] a = new int [ n ] ; int [ ] b = new int [ m ] ; for ( int i = 0 ; i < n ; i ++ ) a [ i ] = sc . nextInt ( ) ; for ( int i = 0 ; i < m ; i ++ ) b [ i ] = sc . nextInt ( ) ; solve ( n , m , a , b , x , y ) ; } static int t = 0 , ans = 0 , i = 0 , j = 0 ; static void calc1 ( int n , int m , int [ ] a , int [ ] b , int x , int y ) { boolean f = true ; while ( i < n && j < m ) { if ( f ) { calc2 ( n , a , x , f ) ; f = false ; } else { calc2 ( m , b , y , f ) ; f = true ; } } } static void calc2 ( int n , int [ ] a , int x , boolean f ) { int k = f ? i : j ; if ( t <= a [ k ] ) { t = a [ k ] + x ; k ++ ; ans ++ ; } else { while ( k < n && a [ k ] < t ) k ++ ; if ( k < n ) { t = a [ k ] + x ; ans ++ ; } } if ( f ) i = k ; else j = k ; } static void solve ( int n , int m , int [ ] a , int [ ] b , int x , int y ) { calc1 ( n , m , a , b , x , y ) ; out . println ( ans / 2 ) ; } }

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 M = sc . nextInt ( ) ; int X = sc . nextInt ( ) ; int Y = sc . nextInt ( ) ; int [ ] a = new int [ N ] ; int [ ] b = new int [ M ] ; for ( int i = 0 ; i < N ; i ++ ) { a [ i ] = sc . nextInt ( ) ; } for ( int i = 0 ; i < M ; i ++ ) { b [ i ] = sc . nextInt ( ) ; } int ans = 0 ; int time = 0 ; while ( true ) { int aIndex = binarySearch ( a , time ) ; if ( aIndex >= N ) { break ; } time = a [ aIndex ] + X ; int bIndex = binarySearch ( b , time ) ; if ( bIndex >= M ) { break ; } time = b [ bIndex ] + Y ; ans ++ ; } out . println ( ans ) ; } public static int binarySearch ( int [ ] arr , int num ) { int result = Arrays . binarySearch ( arr , num ) ; return ( result >= 0 ) ? result : ~ result ; } }

public class Main { private static java . util . Scanner scanner = new java . util . Scanner ( System . in ) ; public static void main ( String [ ] $ ) { int n = scanner . nextInt ( ) , m = scanner . nextInt ( ) ; int x = scanner . nextInt ( ) , y = scanner . nextInt ( ) ; int [ ] a = java . util . stream . IntStream . range ( 0 , n ) . map ( i -> scanner . nextInt ( ) ) . toArray ( ) ; int [ ] b = java . util . stream . IntStream . range ( 0 , m ) . map ( i -> scanner . nextInt ( ) ) . toArray ( ) ; int i = 0 , j = 0 , t = 1 , ans = 0 ; loop : while ( i < n && j < m ) { while ( a [ i ] < t ) if ( ++ i == n ) break loop ; t = a [ i ] + x ; while ( b [ j ] < t ) if ( ++ j == m ) break loop ; t = b [ j ] + y ; ans ++ ; } System . out . println ( ans ) ; } }

import java . util . * ; public class Main { static Scanner sc = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { int N = sc . nextInt ( ) ; int M = sc . nextInt ( ) ; long x = sc . nextLong ( ) ; long y = sc . nextLong ( ) ; long [ ] as = new long [ N ] ; long [ ] bs = new long [ M ] ; for ( int i = 0 ; i < N ; i ++ ) { as [ i ] = sc . nextLong ( ) ; } for ( int i = 0 ; i < M ; i ++ ) { bs [ i ] = sc . nextLong ( ) ; } int count = 0 ; int i = 0 ; while ( true ) { if ( i >= as . length ) { break ; } int index = Arrays . binarySearch ( bs , as [ i ] + x ) ; index = ( index >= 0 ) ? index : ~ index ; if ( index >= bs . length ) { break ; } i = Arrays . binarySearch ( as , bs [ index ] + y ) ; i = ( i >= 0 ) ? i : ~ i ; count ++ ; } System . out . println ( count ) ; } }

n , m = map ( int , input ( ) . split ( ) ) NEW_LINE x , y = map ( int , input ( ) . split ( ) ) NEW_LINE a = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE b = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE def binarysearch ( x , line ) : NEW_LINE INDENT ng = - 1 NEW_LINE ok = len ( line ) NEW_LINE while abs ( ok - ng ) > 1 : NEW_LINE INDENT mid = ( ok + ng ) // 2 NEW_LINE if line [ mid ] >= x : NEW_LINE INDENT ok = mid NEW_LINE DEDENT else : NEW_LINE INDENT ng = mid NEW_LINE DEDENT DEDENT return ok NEW_LINE DEDENT ans = 0 NEW_LINE time = 0 NEW_LINE flag = True NEW_LINE while 1 : NEW_LINE INDENT if flag : NEW_LINE INDENT xyz = binarysearch ( time , a ) NEW_LINE if xyz == len ( a ) : NEW_LINE INDENT break NEW_LINE DEDENT time = a [ xyz ] + x NEW_LINE flag = False NEW_LINE DEDENT else : NEW_LINE INDENT xyz = binarysearch ( time , b ) NEW_LINE if xyz == len ( b ) : NEW_LINE INDENT break NEW_LINE DEDENT time = b [ xyz ] + y NEW_LINE ans += 1 NEW_LINE flag = True NEW_LINE DEDENT DEDENT print ( ans ) NEW_LINE

import bisect NEW_LINE N , M = map ( int , input ( ) . split ( ) ) NEW_LINE X , Y = map ( int , input ( ) . split ( ) ) NEW_LINE al = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE bl = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE a , b = 0 , 0 NEW_LINE t = 0 NEW_LINE ans = 0 NEW_LINE while al [ - 1 ] >= t and bl [ - 1 ] >= t : NEW_LINE INDENT a = bisect . bisect_left ( al , t ) NEW_LINE if a >= N - 1 and al [ - 1 ] < t : NEW_LINE INDENT break NEW_LINE DEDENT t = al [ a ] + X NEW_LINE b = bisect . bisect_left ( bl , t ) NEW_LINE if b >= M - 1 and bl [ - 1 ] < t : NEW_LINE INDENT break NEW_LINE DEDENT ans += 1 NEW_LINE t = bl [ b ] + Y NEW_LINE DEDENT print ( ans ) NEW_LINE

import bisect NEW_LINE import sys NEW_LINE sys . setrecursionlimit ( 10 ** 9 + 7 ) NEW_LINE n , m = map ( int , input ( ) . split ( ) ) NEW_LINE x , y = map ( int , input ( ) . split ( ) ) NEW_LINE a = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE b = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE cache = { } NEW_LINE def f ( t , airport ) : NEW_LINE INDENT key = ( t , airport ) NEW_LINE if key in cache : NEW_LINE INDENT return cache [ key ] NEW_LINE DEDENT val = 0 NEW_LINE if airport : NEW_LINE INDENT u = bisect . bisect_left ( a , t ) NEW_LINE if u < n : NEW_LINE INDENT val = max ( val , f ( a [ u ] + x , not airport ) ) NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT u = bisect . bisect_left ( b , t ) NEW_LINE if u < m : NEW_LINE INDENT val = max ( val , f ( b [ u ] + y , not airport ) + 1 ) NEW_LINE DEDENT DEDENT cache [ key ] = val NEW_LINE return val NEW_LINE DEDENT print ( f ( 0 , True ) ) NEW_LINE

def pilot ( N : int , M : int , X : int , Y : int , A : list , B : list ) -> int : NEW_LINE INDENT ai , bi = 0 , 0 NEW_LINE t = 0 NEW_LINE repeat = 0 NEW_LINE while ai < N and bi < M : NEW_LINE INDENT while ai < N and A [ ai ] < t : NEW_LINE INDENT ai += 1 NEW_LINE DEDENT if N <= ai : NEW_LINE INDENT break NEW_LINE DEDENT t = A [ ai ] + X NEW_LINE ai += 1 NEW_LINE while bi < M and B [ bi ] < t : NEW_LINE INDENT bi += 1 NEW_LINE DEDENT if M <= bi : NEW_LINE INDENT break NEW_LINE DEDENT t = B [ bi ] + Y NEW_LINE bi += 1 NEW_LINE repeat += 1 NEW_LINE DEDENT return repeat NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT N , M = map ( int , input ( ) . split ( ) ) NEW_LINE X , Y = map ( int , input ( ) . split ( ) ) NEW_LINE A = [ int ( s ) for s in input ( ) . split ( ) ] NEW_LINE B = [ int ( s ) for s in input ( ) . split ( ) ] NEW_LINE ans = pilot ( N , M , X , Y , A , B ) NEW_LINE print ( ans ) NEW_LINE DEDENT

import math NEW_LINE import copy NEW_LINE from collections import defaultdict , Counter NEW_LINE from itertools import product NEW_LINE from bisect import bisect_left , bisect_right NEW_LINE def s_inpl ( ) : return map ( int , input ( ) . split ( ) ) NEW_LINE def inpl ( ) : return list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE INF = float ( " inf " ) NEW_LINE N , K = s_inpl ( ) NEW_LINE X , Y = s_inpl ( ) NEW_LINE a = inpl ( ) NEW_LINE b = inpl ( ) NEW_LINE t = 0 NEW_LINE ans = 0 NEW_LINE while True : NEW_LINE INDENT next_a = bisect_left ( a , t ) NEW_LINE if next_a == N : NEW_LINE INDENT break NEW_LINE DEDENT t = a [ next_a ] + X NEW_LINE next_b = bisect_left ( b , t ) NEW_LINE if next_b == K : NEW_LINE INDENT break NEW_LINE DEDENT t = b [ next_b ] + Y NEW_LINE ans += 1 NEW_LINE DEDENT print ( ans ) NEW_LINE


import java . util . * ; public class Main { static Scanner s = new Scanner ( System . in ) ; public static void main ( String [ ] $ ) { int n = s . nextInt ( ) ; int [ ] branches = new int [ n ] ; int [ ] parent = new int [ n ] ; int [ ] [ ] childlen = new int [ n ] [ ] ; for ( int i = 1 ; i < n ; ++ i ) ++ branches [ parent [ i ] = s . nextInt ( ) - 1 ] ; for ( int i = 0 ; i < n ; ++ i ) childlen [ i ] = new int [ branches [ i ] ] ; loop : for ( int i = 0 ; i < n ; ++ i ) { int I = i ; while ( true ) { if ( branches [ I ] > 0 ) break ; int r = 0 ; { int [ ] c = childlen [ I ] ; Arrays . sort ( c ) ; for ( int j = 0 , e = c . length ; j < e ; ++ j ) r = Math . max ( r , c [ j ] + e - j ) ; } if ( I == 0 ) { System . out . println ( r ) ; break loop ; } I = parent [ I ] ; childlen [ I ] [ -- branches [ I ] ] = r ; } } } }

import java . util . ArrayList ; import java . util . Collections ; import java . util . Comparator ; import java . util . Scanner ; public class Main { static ArrayList < Integer > [ ] g ; static int n ; static int [ ] deg ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; n = sc . nextInt ( ) ; g = new ArrayList [ n ] ; deg = new int [ n ] ; for ( int i = 0 ; i < n ; ++ i ) { g [ i ] = new ArrayList < > ( ) ; } for ( int i = 1 ; i < n ; ++ i ) { int a = sc . nextInt ( ) - 1 ; g [ a ] . add ( i ) ; g [ i ] . add ( a ) ; } dfs ( 0 , - 1 ) ; System . out . println ( deg [ 0 ] ) ; } static void dfs ( int cur , int par ) { if ( cur != 0 && g [ cur ] . size ( ) == 1 ) { deg [ cur ] = 0 ; return ; } else if ( g [ cur ] . size ( ) == 0 ) { deg [ cur ] = 0 ; return ; } ArrayList < Integer > v = new ArrayList < > ( ) ; for ( int dst : g [ cur ] ) { if ( dst == par ) continue ; dfs ( dst , cur ) ; v . add ( deg [ dst ] ) ; } Collections . sort ( v , new Comparator < Integer > ( ) { @ Override public int compare ( Integer o1 , Integer o2 ) { return - Integer . compare ( o1 , o2 ) ; } } ) ; int max = 0 ; for ( int i = 0 ; i < v . size ( ) ; ++ i ) { max = Math . max ( max , i + v . get ( i ) ) ; } deg [ cur ] = max + 1 ; } } Note : . / Main . java uses unchecked or unsafe operations . Note : Recompile with - Xlint : unchecked for details .

import java . io . * ; import java . util . * ; public class Main { static int dfs ( ArrayList < Integer > list [ ] , int idx , int par ) { int min = 0 ; ArrayList < Integer > node = new ArrayList < > ( ) ; for ( int temp : list [ idx ] ) { if ( temp == par ) continue ; int child = dfs ( list , temp , idx ) ; node . add ( child ) ; } Collections . sort ( node ) ; for ( int temp : node ) { min = Math . max ( temp , min ) + 1 ; } return min ; } public static void main ( String [ ] args ) throws Exception { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; StringTokenizer st = new StringTokenizer ( br . readLine ( ) ) ; int n = Integer . parseInt ( st . nextToken ( ) ) ; ArrayList < Integer > list [ ] = new ArrayList [ n + 1 ] ; for ( int i = 1 ; i <= n ; i ++ ) list [ i ] = new ArrayList < > ( ) ; for ( int i = 2 ; i <= n ; i ++ ) { int temp = Integer . parseInt ( br . readLine ( ) ) ; list [ i ] . add ( temp ) ; list [ temp ] . add ( i ) ; } System . out . println ( dfs ( list , 1 , - 1 ) ) ; } } Note : . / Main . java uses unchecked or unsafe operations . Note : Recompile with - Xlint : unchecked for details .

import java . util . ArrayList ; import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int N = scanner . nextInt ( ) ; ArrayList < Integer > [ ] graph = new ArrayList [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { graph [ i ] = new ArrayList < > ( ) ; } for ( int i = 1 ; i < N ; i ++ ) { int a = scanner . nextInt ( ) - 1 ; graph [ a ] . add ( i ) ; } System . out . println ( dfs ( 0 , graph ) - 1 ) ; } private static int dfs ( int v , ArrayList < Integer > [ ] graph ) { if ( graph [ v ] . isEmpty ( ) ) { return 1 ; } int [ ] tmp = new int [ graph [ v ] . size ( ) ] ; for ( int i = 0 ; i < tmp . length ; i ++ ) { int u = graph [ v ] . get ( i ) ; tmp [ i ] = dfs ( u , graph ) ; } Arrays . sort ( tmp ) ; int max = 0 ; for ( int t : tmp ) { if ( t <= max ) max ++ ; else max = t ; } max ++ ; return max ; } } Note : . / Main . java uses unchecked or unsafe operations . Note : Recompile with - Xlint : unchecked for details .

import java . util . * ; public class Main { public static int [ ] dp ; public static ArrayList < Integer > [ ] win ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] a = new int [ n ] ; a [ 0 ] = 0 ; for ( int i = 1 ; i < n ; i ++ ) { a [ i ] = sc . nextInt ( ) ; } sc . close ( ) ; win = new ArrayList [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { win [ i ] = new ArrayList < Integer > ( ) ; } for ( int i = 1 ; i < n ; i ++ ) { win [ a [ i ] - 1 ] . add ( i ) ; } dp = new int [ n ] ; solve ( 0 ) ; System . out . println ( dp [ 0 ] - 1 ) ; } public static void solve ( int v ) { int size = win [ v ] . size ( ) ; if ( size == 0 ) { dp [ v ] = 1 ; return ; } int [ ] d = new int [ size ] ; for ( int i = 0 ; i < size ; i ++ ) { int t = win [ v ] . get ( i ) ; solve ( t ) ; d [ i ] = dp [ t ] ; } Arrays . sort ( d ) ; int depth = 0 ; for ( int i = 0 ; i < size ; i ++ ) { if ( depth < size - i + d [ i ] ) depth = size - i + d [ i ] ; } dp [ v ] = depth ; } } Note : . / Main . java uses unchecked or unsafe operations . Note : Recompile with - Xlint : unchecked for details .

import sys NEW_LINE sys . setrecursionlimit ( 202020 ) NEW_LINE N = int ( input ( ) ) NEW_LINE won = [ [ ] for i in range ( N ) ] NEW_LINE for i in range ( 1 , N ) : NEW_LINE INDENT a = int ( input ( ) ) - 1 NEW_LINE won [ a ] . append ( i ) NEW_LINE DEDENT def height ( v ) : NEW_LINE INDENT if not won [ v ] : return 0 NEW_LINE hs = [ height ( op ) for op in won [ v ] ] NEW_LINE ret = 0 NEW_LINE for i , h in enumerate ( sorted ( hs ) ) : NEW_LINE INDENT ret = max ( ret , h + len ( hs ) - i ) NEW_LINE DEDENT return ret NEW_LINE DEDENT print ( height ( 0 ) ) NEW_LINE

from sys import stdin , setrecursionlimit NEW_LINE setrecursionlimit ( 10 ** 7 ) NEW_LINE def solve ( ) : NEW_LINE INDENT N = int ( stdin . readline ( ) ) NEW_LINE Adj = [ [ ] for i in range ( N ) ] NEW_LINE for i in range ( N - 1 ) : NEW_LINE INDENT a = int ( stdin . readline ( ) ) - 1 NEW_LINE Adj [ a ] . append ( i + 1 ) NEW_LINE DEDENT ans = dfs ( N , Adj , 0 , - 1 ) NEW_LINE print ( ans ) NEW_LINE DEDENT def dfs ( N , Adj , v , p ) : NEW_LINE INDENT dl = [ ] NEW_LINE for u in Adj [ v ] : NEW_LINE INDENT if u == p : NEW_LINE INDENT continue NEW_LINE DEDENT dl . append ( dfs ( N , Adj , u , v ) ) NEW_LINE DEDENT dl . sort ( reverse = True ) NEW_LINE if not dl : NEW_LINE INDENT return 0 NEW_LINE DEDENT res = max ( dl [ i ] + i + 1 for i in range ( len ( dl ) ) ) NEW_LINE return res NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT solve ( ) NEW_LINE DEDENT

import sys NEW_LINE from heapq import heapify , heappush , heappop NEW_LINE sys . setrecursionlimit ( 10 ** 7 ) NEW_LINE input = sys . stdin . readline NEW_LINE N = int ( input ( ) ) NEW_LINE List = [ [ ] for i in range ( N ) ] NEW_LINE for i in range ( 1 , N ) : NEW_LINE INDENT a = int ( input ( ) ) NEW_LINE List [ a - 1 ] . append ( i ) NEW_LINE DEDENT def f ( x ) : NEW_LINE INDENT if len ( List [ x ] ) == 0 : NEW_LINE INDENT return 0 NEW_LINE DEDENT L = [ ] NEW_LINE heapify ( L ) NEW_LINE for a in List [ x ] : NEW_LINE INDENT heappush ( L , f ( a ) ) NEW_LINE DEDENT n = len ( L ) NEW_LINE res = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT b = heappop ( L ) NEW_LINE res = max ( res , b + n - i ) NEW_LINE DEDENT return res NEW_LINE DEDENT print ( f ( 0 ) ) NEW_LINE

from collections import Counter NEW_LINE n = int ( input ( ) ) NEW_LINE xs = [ None ] + [ int ( input ( ) ) - 1 for _ in range ( n - 1 ) ] NEW_LINE count_win = Counter ( xs ) NEW_LINE q = [ i for i in range ( n ) if not i in count_win ] NEW_LINE children = [ [ ] for i in range ( n ) ] NEW_LINE qi = 0 NEW_LINE while not q [ qi ] == 0 : NEW_LINE INDENT i , qi = q [ qi ] , qi + 1 NEW_LINE children [ i ] . sort ( reverse = True ) NEW_LINE children [ i ] = max ( v + w for v , w in enumerate ( [ 0 ] + children [ i ] ) ) NEW_LINE j = xs [ i ] NEW_LINE children [ j ] . append ( children [ i ] ) NEW_LINE if count_win [ j ] <= 1 : NEW_LINE INDENT q . append ( j ) NEW_LINE DEDENT else : NEW_LINE INDENT count_win [ j ] -= 1 NEW_LINE DEDENT DEDENT children [ 0 ] . sort ( reverse = True ) NEW_LINE children [ 0 ] = max ( v + w for v , w in enumerate ( [ 0 ] + children [ 0 ] ) ) NEW_LINE print ( children [ 0 ] ) NEW_LINE

import sys , math , copy NEW_LINE sys . setrecursionlimit ( 1000000 ) NEW_LINE HUGE = 2147483647 NEW_LINE HUGEL = 9223372036854775807 NEW_LINE ABC = " abcdefghijklmnopqrstuvwxyz " NEW_LINE class Node : NEW_LINE INDENT def __init__ ( self ) : NEW_LINE INDENT self . children0 = [ ] NEW_LINE self . parent0 = - 1 NEW_LINE self . depth = - 1 NEW_LINE DEDENT def get_depth ( self ) : NEW_LINE INDENT if self . depth == - 1 : NEW_LINE INDENT childdepths = sorted ( [ nodes [ ch0 ] . get_depth ( ) for ch0 in self . children0 ] , reverse = True ) NEW_LINE res = 0 NEW_LINE for i0 , cd in enumerate ( childdepths ) : NEW_LINE INDENT res = max ( res , cd + i0 + 1 ) NEW_LINE DEDENT self . depth = res NEW_LINE DEDENT return self . depth NEW_LINE DEDENT DEDENT def main ( ) : NEW_LINE INDENT for i0 in range ( 1 , N ) : NEW_LINE INDENT pa1 = int ( input ( ) ) NEW_LINE assert pa1 >= 1 NEW_LINE pa0 = pa1 - 1 NEW_LINE nodes [ i0 ] . parent0 = pa0 NEW_LINE nodes [ pa0 ] . children0 . append ( i0 ) NEW_LINE DEDENT print ( nodes [ 0 ] . get_depth ( ) ) NEW_LINE DEDENT N = int ( input ( ) ) NEW_LINE nodes = [ Node ( ) for i in range ( N ) ] NEW_LINE main ( ) NEW_LINE


import java . util . Scanner ; import java . util . Map . Entry ; public class Main { static int MAX_FAC = 510000 ; static int MOD = 1000000007 ; static long [ ] fac = new long [ MAX_FAC ] ; static long [ ] finv = new long [ MAX_FAC ] ; static long [ ] inv = new long [ MAX_FAC ] ; public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; long N = in . nextLong ( ) ; long M = in . nextLong ( ) ; long ans = 1 ; initComb ( ) ; long m = M ; for ( int i = 2 ; i * i <= m ; i ++ ) { if ( m % i == 0 ) { int count = 0 ; while ( m % i == 0 ) { m /= i ; count ++ ; } ans = ( ans * comb ( ( int ) N - 1 + count , count ) ) % MOD ; } } if ( m > 1 ) { ans = ( ans * N ) % MOD ; } System . out . println ( ans ) ; } public static void initComb ( ) { fac [ 0 ] = finv [ 0 ] = inv [ 0 ] = fac [ 1 ] = finv [ 1 ] = inv [ 1 ] = 1 ; for ( int i = 2 ; i < MAX_FAC ; ++ i ) { fac [ i ] = fac [ i - 1 ] * i % MOD ; inv [ i ] = MOD - ( MOD / i ) * inv [ ( int ) ( MOD % i ) ] % MOD ; finv [ i ] = finv [ i - 1 ] * inv [ i ] % MOD ; } } public static long comb ( int n , int k ) { return fac [ n ] * finv [ k ] % MOD * finv [ n - k ] % MOD ; } }

import java . util . ArrayList ; import java . util . Scanner ; class Main { static final long MOD = 1000000007 ; static long pow = 1000000007 ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long N = sc . nextLong ( ) ; long M = sc . nextLong ( ) ; ArrayList < Integer > sosu = new ArrayList < Integer > ( ) ; long ans = 1 ; for ( int i = 2 ; i * i <= M ; i ++ ) { if ( M % i == 0 ) { int scount = 0 ; while ( M % i == 0 ) { scount ++ ; M /= i ; } if ( scount != 0 ) { ans *= comb ( scount + N - 1 , scount ) ; ans %= pow ; } } } if ( M != 1 ) { ans *= comb ( 1 + N - 1 , 1 ) ; ans %= pow ; } System . out . println ( ans ) ; } static long comb ( long x , Integer y ) { long ue = 1 ; long sita = 1 ; for ( int i = 0 ; i < y ; i ++ ) { ue *= x - i ; ue %= pow ; sita *= i + 1 ; sita %= pow ; } long ans = ue * modpow ( sita , pow - 2 ) % pow ; return ans ; } static long modpow ( long a , long p ) { if ( p == 0 ) { return 1 ; } if ( p % 2 == 0 ) { long halfp = p / 2 ; long half = modpow ( a , halfp ) ; return half * half % pow ; } else { return a * modpow ( a , p - 1 ) % pow ; } } } class Pair implements Comparable { int from ; int end ; int num ; int bango ; @ Override public int compareTo ( Object other ) { Pair otherpair = ( Pair ) other ; return end - otherpair . end ; } }

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 ) ; int size = 1000000 ; long [ ] fact = new long [ size ] ; long [ ] inv = new long [ size ] ; fact [ 0 ] = 1 ; inv [ 0 ] = 1 ; long mod = 1000000007 ; for ( int i = 1 ; i < size ; i ++ ) { fact [ i ] = ( fact [ i - 1 ] * i ) % mod ; inv [ i ] = power ( fact [ i ] , ( int ) mod - 2 ) % mod ; } int n = sc . nextInt ( ) ; int m = sc . nextInt ( ) ; if ( m == 1 ) { out . println ( 1 ) ; } else { HashMap < Integer , Integer > map = new HashMap < > ( ) ; int stop = ( int ) sqrt ( m ) + 1 ; for ( int i = 2 ; i <= stop ; i ++ ) { while ( m % i == 0 ) { m /= i ; map . put ( i , map . getOrDefault ( i , 0 ) + 1 ) ; } } if ( m != 1 ) map . put ( m , 1 ) ; long ans = 1 ; for ( int k : map . keySet ( ) ) { ans = ( ans % mod * fact [ n - 1 + map . get ( k ) ] % mod * inv [ n - 1 ] % mod * inv [ map . get ( k ) ] % mod ) % mod ; } 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 % mod * x % mod ) % mod ; } x = ( x % mod * x % mod ) % mod ; n >>= 1 ; } return ans ; } }

import java . util . Scanner ; public class Main { static int MOD = 1_000_000_007 ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int M = sc . nextInt ( ) ; int sq = ( int ) Math . ceil ( Math . sqrt ( M ) ) ; int prime = 0 ; long ans = 1 ; Combination comb = new Combination ( N + sq , MOD ) ; for ( int i = 2 ; i <= sq ; i ++ ) { if ( M % i == 0 ) { prime = 0 ; while ( M % i == 0 ) { prime ++ ; M /= i ; } ans = ( ans * comb . comb ( N - 1 + prime , Math . min ( N - 1 , prime ) ) ) % MOD ; } } if ( M > 1 ) ans = ( ans * N ) % MOD ; System . out . println ( ans ) ; sc . close ( ) ; } } class Combination { long fac [ ] ; long inv [ ] ; int MOD ; Combination ( int size , int mod ) { this . fac = new long [ size + 1 ] ; this . inv = new long [ size + 1 ] ; this . MOD = mod ; this . fac [ 0 ] = 1 ; this . inv [ 0 ] = 1 ; for ( int i = 1 ; i <= size ; i ++ ) { fac [ i ] = ( fac [ i - 1 ] * i ) % MOD ; inv [ i ] = modPow ( fac [ i ] , ( int ) MOD - 2 ) % MOD ; } } long comb ( int n , int r ) { return fac [ n ] * inv [ r ] % MOD * inv [ n - r ] % MOD ; } private long modPow ( long base , int exp ) { long ret = 1 ; while ( exp > 0 ) { if ( ( exp & 1 ) == 1 ) { ret = ret * base % MOD ; } base = base * base % MOD ; exp >>= 1 ; } return ret ; } }

import java . util . * ; public class Main { static int modAns = ( int ) Math . pow ( 10 , 9 ) + 7 ; static long fac [ ] = new long [ 1000000 ] ; static long finv [ ] = new long [ 1000000 ] ; static long inv [ ] = new long [ 1000000 ] ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int length = sc . nextInt ( ) ; int multi = sc . nextInt ( ) ; long ans = 1 ; ArrayList < Integer > counts = new ArrayList < Integer > ( ) ; for ( int i = 2 ; i <= multi ; i ++ ) { if ( multi % i == 0 ) { int count = 0 ; while ( multi % i == 0 ) { multi /= i ; count ++ ; } counts . add ( count ) ; } if ( multi == 1 ) { break ; } } COMinit ( ) ; for ( int i = 0 ; i < counts . size ( ) ; i ++ ) { ans *= combi ( counts . get ( i ) + length - 1 , Math . min ( counts . get ( i ) , length - 1 ) ) % modAns ; ans %= modAns ; } System . out . println ( ans ) ; } public static long combi ( int n , int r ) { return fac [ n ] * ( finv [ r ] * finv [ n - r ] % modAns ) % modAns ; } public static void COMinit ( ) { fac [ 0 ] = fac [ 1 ] = 1 ; finv [ 0 ] = finv [ 1 ] = 1 ; inv [ 1 ] = 1 ; for ( int i = 2 ; i < fac . length ; i ++ ) { fac [ i ] = fac [ i - 1 ] * i % modAns ; inv [ i ] = modAns - inv [ modAns % i ] * ( modAns / i ) % modAns ; finv [ i ] = finv [ i - 1 ] * inv [ i ] % modAns ; } } }

N , M = map ( int , input ( ) . split ( ) ) NEW_LINE def factorization ( N ) : NEW_LINE INDENT prime = primelist ( int ( N ** ( 1 / 2 ) ) + 2 ) NEW_LINE factor = [ 0 for i in range ( int ( N ** ( 1 / 2 ) + 2 ) ) ] NEW_LINE isprime = False NEW_LINE for i in prime : NEW_LINE INDENT while N % i == 0 : NEW_LINE INDENT N = N // i NEW_LINE factor [ i ] += 1 NEW_LINE DEDENT DEDENT if sum ( factor ) == 0 : NEW_LINE INDENT isprime = True NEW_LINE DEDENT if N != 1 : NEW_LINE INDENT factor . append ( 1 ) NEW_LINE DEDENT return factor , isprime NEW_LINE DEDENT def primelist ( N ) : NEW_LINE INDENT prime = [ 2 ] NEW_LINE for i in range ( 3 , N + 1 ) : NEW_LINE INDENT flag = 1 NEW_LINE for j in prime : NEW_LINE INDENT if i % j == 0 : NEW_LINE INDENT flag = 0 NEW_LINE break NEW_LINE DEDENT DEDENT if flag == 1 : NEW_LINE INDENT prime . append ( i ) NEW_LINE DEDENT DEDENT return prime NEW_LINE DEDENT def cmb ( n , r ) : NEW_LINE INDENT if n - r < r : r = n - r NEW_LINE if r == 0 : return 1 NEW_LINE if r == 1 : return n NEW_LINE numerator = [ n - r + k + 1 for k in range ( r ) ] NEW_LINE denominator = [ k + 1 for k in range ( r ) ] NEW_LINE for p in range ( 2 , r + 1 ) : NEW_LINE INDENT pivot = denominator [ p - 1 ] NEW_LINE if pivot > 1 : NEW_LINE INDENT offset = ( n - r ) % p NEW_LINE for k in range ( p - 1 , r , p ) : NEW_LINE INDENT numerator [ k - offset ] /= pivot NEW_LINE denominator [ k ] /= pivot NEW_LINE DEDENT DEDENT DEDENT result = 1 NEW_LINE for k in range ( r ) : NEW_LINE INDENT if numerator [ k ] > 1 : NEW_LINE INDENT result *= int ( numerator [ k ] ) NEW_LINE DEDENT DEDENT return result NEW_LINE DEDENT factor = factorization ( M ) [ 0 ] NEW_LINE ans = 1 NEW_LINE for i in factor : NEW_LINE INDENT ans *= cmb ( N + i - 1 , i ) NEW_LINE ans %= 1000000007 NEW_LINE DEDENT print ( ans ) NEW_LINE

import sys NEW_LINE import math NEW_LINE MOD = 1000000007 NEW_LINE def factorization ( n : int ) : NEW_LINE INDENT if n == 1 : NEW_LINE INDENT return [ ] NEW_LINE DEDENT factors = None NEW_LINE for i in range ( 2 , math . ceil ( math . sqrt ( n ) ) + 1 ) : NEW_LINE INDENT if n % i == 0 : NEW_LINE INDENT factors = [ i ] + factorization ( n // i ) NEW_LINE break NEW_LINE DEDENT DEDENT if factors == None : NEW_LINE INDENT return [ n ] NEW_LINE DEDENT else : NEW_LINE INDENT return factors NEW_LINE DEDENT DEDENT def comb ( i : int , j : int ) : NEW_LINE INDENT if j > i - j : NEW_LINE INDENT return comb ( i , i - j ) NEW_LINE DEDENT mul = 1 NEW_LINE for k in range ( i - j + 1 , i + 1 ) : NEW_LINE INDENT mul *= k NEW_LINE DEDENT for k in range ( 2 , j + 1 ) : NEW_LINE INDENT mul //= k NEW_LINE DEDENT return mul NEW_LINE DEDENT def solve ( N : int , M : int ) : NEW_LINE INDENT factor = factorization ( M ) NEW_LINE factorDict = { } NEW_LINE for f in factor : NEW_LINE INDENT if f not in factorDict : NEW_LINE INDENT factorDict [ f ] = 0 NEW_LINE DEDENT factorDict [ f ] += 1 NEW_LINE DEDENT mul = 1 NEW_LINE for k in factorDict : NEW_LINE INDENT mul = ( mul * comb ( factorDict [ k ] + N - 1 , factorDict [ k ] ) ) % MOD NEW_LINE DEDENT print ( mul ) NEW_LINE return NEW_LINE DEDENT def main ( ) : NEW_LINE INDENT def iterate_tokens ( ) : NEW_LINE INDENT for line in sys . stdin : NEW_LINE INDENT for word in line . split ( ) : NEW_LINE INDENT yield word NEW_LINE DEDENT DEDENT DEDENT tokens = iterate_tokens ( ) NEW_LINE N = int ( next ( tokens ) ) NEW_LINE M = int ( next ( tokens ) ) NEW_LINE solve ( N , M ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT

inpl = lambda : list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE MOD = 10 ** 9 + 7 NEW_LINE N , M = inpl ( ) NEW_LINE def factorize ( n ) : NEW_LINE INDENT factorize_list = [ ] NEW_LINE i = 2 NEW_LINE while i * i <= n : NEW_LINE INDENT k = 0 NEW_LINE while n % i == 0 : NEW_LINE INDENT n //= i NEW_LINE k += 1 NEW_LINE DEDENT if k > 0 : NEW_LINE INDENT factorize_list . append ( k ) NEW_LINE DEDENT i += 1 NEW_LINE DEDENT if n > 1 : NEW_LINE INDENT factorize_list . append ( 1 ) NEW_LINE DEDENT return ( factorize_list ) NEW_LINE DEDENT def H ( n , k ) : NEW_LINE INDENT h = 1 NEW_LINE L = n + k - 1 NEW_LINE k = min ( n - 1 , k ) NEW_LINE for j in range ( k ) : NEW_LINE INDENT h *= L - j NEW_LINE DEDENT for j in range ( k ) : NEW_LINE INDENT h //= j + 1 NEW_LINE DEDENT return h NEW_LINE DEDENT ans = 1 NEW_LINE for k in factorize ( M ) : NEW_LINE INDENT ans *= H ( N , k ) % MOD NEW_LINE ans %= MOD NEW_LINE DEDENT print ( ans ) NEW_LINE

MOD = 10 ** 9 + 7 NEW_LINE MAX = 10 ** 6 NEW_LINE fac = [ 0 ] * MAX NEW_LINE finv = [ 0 ] * MAX NEW_LINE inv = [ 0 ] * MAX NEW_LINE def comb_init ( ) : NEW_LINE INDENT global fac , finv , inv NEW_LINE fac [ 0 ] = fac [ 1 ] = 1 NEW_LINE finv [ 0 ] = finv [ 1 ] = 1 NEW_LINE inv [ 1 ] = 1 NEW_LINE for i in range ( 2 , MAX ) : NEW_LINE INDENT fac [ i ] = fac [ i - 1 ] * i % MOD NEW_LINE inv [ i ] = MOD - inv [ MOD % i ] * ( MOD // i ) % MOD NEW_LINE finv [ i ] = finv [ i - 1 ] * inv [ i ] % MOD NEW_LINE DEDENT DEDENT def comb ( n : int , r : int ) -> int : NEW_LINE INDENT global fac , finv NEW_LINE if n < r : return 0 NEW_LINE if n < 0 or r < 0 : return 0 NEW_LINE return fac [ n ] * ( finv [ r ] * finv [ n - r ] % MOD ) % MOD NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT N , M = map ( int , input ( ) . split ( ) ) NEW_LINE ans = 1 NEW_LINE comb_init ( ) NEW_LINE i = 2 NEW_LINE nokori = M NEW_LINE while i * i <= nokori : NEW_LINE INDENT if nokori % i == 0 : NEW_LINE INDENT cnt = 0 NEW_LINE while nokori % i == 0 : NEW_LINE INDENT cnt += 1 NEW_LINE nokori //= i NEW_LINE DEDENT ans *= comb ( N + cnt - 1 , N - 1 ) NEW_LINE ans %= MOD NEW_LINE DEDENT i += 1 NEW_LINE DEDENT if nokori != 1 : NEW_LINE INDENT ans *= comb ( N + 1 - 1 , N - 1 ) NEW_LINE ans %= MOD NEW_LINE DEDENT print ( ans ) NEW_LINE DEDENT

import sys NEW_LINE sys . setrecursionlimit ( 10 ** 7 ) NEW_LINE INF = 10 ** 18 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 II ( ) : return int ( sys . stdin . readline ( ) ) NEW_LINE def SI ( ) : return input ( ) NEW_LINE from collections import Counter NEW_LINE from itertools import product NEW_LINE from math import factorial NEW_LINE primes = list ( range ( int ( 10 ** 5 ) + 1 ) ) NEW_LINE primes [ 1 ] = 0 NEW_LINE for i in range ( 2 , int ( len ( primes ) ** 0.5 ) + 1 ) : NEW_LINE INDENT if primes [ i ] : NEW_LINE INDENT for j in range ( 2 * i , len ( primes ) , i ) : NEW_LINE INDENT primes [ j ] = 0 NEW_LINE DEDENT DEDENT DEDENT def main ( ) : NEW_LINE INDENT N , M = LI ( ) NEW_LINE factors = Counter ( ) NEW_LINE for i in range ( int ( M ** 0.5 ) + 1 ) : NEW_LINE INDENT if primes [ i ] : NEW_LINE INDENT while M % i == 0 : NEW_LINE INDENT factors [ i ] += 1 NEW_LINE M //= i NEW_LINE DEDENT DEDENT if M < i : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT if M != 1 : NEW_LINE INDENT factors [ M ] += 1 NEW_LINE DEDENT ans = 1 NEW_LINE for k in factors . values ( ) : NEW_LINE INDENT a , b = 1 , 1 NEW_LINE for i in range ( 1 , k + 1 ) : NEW_LINE INDENT a *= N + k - i NEW_LINE b *= i NEW_LINE DEDENT ans = ( ans * ( a // b ) ) % MOD NEW_LINE DEDENT return ans % MOD NEW_LINE DEDENT print ( main ( ) ) NEW_LINE


import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; char last = '0' ; int loser = 0 ; HashSet < String > set = new HashSet < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { String s = sc . next ( ) ; if ( i != 0 ) { if ( s . charAt ( 0 ) != last || set . contains ( s ) ) { loser = i ; break ; } } last = s . charAt ( s . length ( ) - 1 ) ; set . add ( s ) ; } if ( loser == 0 ) { System . out . println ( " DRAW " ) ; } else if ( loser % 2 == 0 ) { System . out . println ( " LOSE " ) ; } else { System . out . println ( " WIN " ) ; } } }

import java . util . HashSet ; import java . util . Scanner ; import java . util . function . LongSupplier ; import java . util . stream . IntStream ; public class Main { static final Scanner s = new Scanner ( System . in ) ; static final long [ ] fal_rnd ( long [ ] ar , LongSupplier sp ) { int l = - 1 , r = ar . length ; while ( l + 1 != r ) ar [ Math . random ( ) < 0.5 ? ++ l : -- r ] = sp . getAsLong ( ) ; return ar ; } static final IntStream REPS ( int v ) { return IntStream . range ( 0 , v ) ; } ; public static void main ( String [ ] __ ) { int r = - 1 , n = s . nextInt ( ) ; String in = s . next ( ) ; HashSet < String > set = new HashSet < > ( 100 ) ; set . add ( in ) ; for ( int i = 1 ; i < n ; i ++ ) { String nin = s . next ( ) ; if ( nin . charAt ( 0 ) != in . charAt ( in . length ( ) - 1 ) || set . contains ( nin ) ) { r = i ; break ; } in = nin ; set . add ( in ) ; } System . out . println ( r == - 1 ? " DRAW " : r % 2 == 1 ? " WIN " : " LOSE " ) ; } }

import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; HashSet < String > used = new HashSet < String > ( ) ; int N = sc . nextInt ( ) ; String last = " " ; boolean first = false ; boolean second = false ; boolean flag = false ; for ( int i = 0 ; i < N ; i ++ ) { String W = sc . next ( ) ; if ( i % 2 == 0 ) { if ( used . contains ( W ) ) { if ( ! flag ) { second = true ; flag = true ; } } if ( i != 0 && W . charAt ( 0 ) != last . charAt ( last . length ( ) - 1 ) ) { if ( ! flag ) { second = true ; flag = true ; } } used . add ( W ) ; } else { if ( used . contains ( W ) ) { if ( ! flag ) { first = true ; flag = true ; } } if ( i != 0 && W . charAt ( 0 ) != last . charAt ( last . length ( ) - 1 ) ) { if ( ! flag ) { flag = true ; first = true ; } } used . add ( W ) ; } last = W ; } if ( ! flag ) { System . out . println ( " DRAW " ) ; return ; } if ( first ) { System . out . println ( " WIN " ) ; return ; } else { System . out . println ( " LOSE " ) ; return ; } } }

import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; ArrayList < String > word = new ArrayList < String > ( ) ; String preW = sc . next ( ) ; word . add ( preW ) ; int lose = 0 ; for ( int i = 2 ; i <= N ; i ++ ) { String s = sc . next ( ) ; if ( word . contains ( s ) ) { lose = i ; break ; } if ( preW . charAt ( preW . length ( ) - 1 ) != s . charAt ( 0 ) ) { lose = i ; break ; } preW = s ; word . add ( s ) ; } String ans = " " ; if ( lose == 0 ) { ans = " DRAW " ; } else { if ( lose % 2 == 0 ) { ans = " WIN " ; } else { ans = " LOSE " ; } } System . out . println ( ans ) ; } }

import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; HashSet < String > used = new HashSet < > ( ) ; String a [ ] = new String [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { a [ i ] = sc . next ( ) ; } String prev = a [ 0 ] ; used . add ( prev ) ; for ( int i = 1 ; i < N ; i ++ ) { String current = a [ i ] ; if ( prev . charAt ( prev . length ( ) - 1 ) != current . charAt ( 0 ) || used . contains ( current ) ) { System . out . println ( i % 2 == 0 ? " LOSE " : " WIN " ) ; return ; } used . add ( current ) ; prev = current ; } System . out . println ( " DRAW " ) ; } }

N = int ( input ( ) ) NEW_LINE W = input ( ) NEW_LINE words = set ( [ W ] ) NEW_LINE end = W [ len ( W ) - 1 ] NEW_LINE lose = " * " NEW_LINE for i in range ( 1 , N ) : NEW_LINE INDENT W = input ( ) NEW_LINE if ( ( W in words ) or W [ 0 ] != end ) and lose == " * " : NEW_LINE INDENT if i % 2 == 0 : NEW_LINE INDENT lose = " hiragana " NEW_LINE DEDENT else : NEW_LINE INDENT lose = " katakana " NEW_LINE DEDENT DEDENT end = W [ len ( W ) - 1 ] NEW_LINE words . add ( W ) NEW_LINE DEDENT if lose == " * " : NEW_LINE INDENT print ( " DRAW " ) NEW_LINE DEDENT elif lose == " katakana " : NEW_LINE INDENT print ( " WIN " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " LOSE " ) NEW_LINE DEDENT

s = [ ] NEW_LINE k = [ " LOSE " , " WIN " ] NEW_LINE for i in range ( int ( input ( ) ) ) : NEW_LINE INDENT d = input ( ) NEW_LINE if i == 0 : NEW_LINE INDENT s . append ( d ) NEW_LINE DEDENT elif d in s or s [ - 1 ] [ - 1 ] != d [ 0 ] : NEW_LINE INDENT print ( k [ i % 2 ] ) NEW_LINE break NEW_LINE DEDENT else : NEW_LINE INDENT s . append ( d ) NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT print ( " DRAW " ) NEW_LINE DEDENT

a = [ ] ; s = ' DRAW ' NEW_LINE for i in range ( int ( input ( ) ) ) : NEW_LINE INDENT c = input ( ) NEW_LINE if i and ( b [ - 1 ] != c [ 0 ] or c in a ) : s = ' LWOISNE ' [ i % 2 : : 2 ] ; break NEW_LINE b = c ; a += [ c ] NEW_LINE DEDENT print ( s ) NEW_LINE

import sys NEW_LINE sys . setrecursionlimit ( 10 ** 9 ) NEW_LINE N = int ( input ( ) ) NEW_LINE p = set ( ) NEW_LINE ans = " DRAW " NEW_LINE cnt = 1 NEW_LINE prev = input ( ) NEW_LINE p . add ( prev ) NEW_LINE for _ in range ( N - 1 ) : NEW_LINE INDENT cnt += 1 NEW_LINE s = input ( ) NEW_LINE if s [ 0 ] == prev [ - 1 ] : NEW_LINE INDENT if s in p : NEW_LINE INDENT if cnt % 2 == 1 : NEW_LINE INDENT ans = " LOSE " NEW_LINE DEDENT else : NEW_LINE INDENT ans = " WIN " NEW_LINE DEDENT break NEW_LINE DEDENT else : NEW_LINE INDENT prev = s NEW_LINE p . add ( s ) NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT if cnt % 2 == 1 : NEW_LINE INDENT ans = " LOSE " NEW_LINE DEDENT else : NEW_LINE INDENT ans = " WIN " NEW_LINE DEDENT break NEW_LINE DEDENT DEDENT print ( ans ) NEW_LINE

def b_shiritori ( N , W ) : NEW_LINE INDENT word_said = [ ] NEW_LINE last_word = W [ 0 ] [ 0 ] NEW_LINE ans = ' DRAW ' NEW_LINE for turn , word in enumerate ( W ) : NEW_LINE INDENT if last_word [ - 1 ] != word [ 0 ] or word in word_said : NEW_LINE INDENT ans = ' WIN ' if turn % 2 == 1 else ' LOSE ' NEW_LINE break NEW_LINE DEDENT last_word = word NEW_LINE word_said . append ( word ) NEW_LINE DEDENT return ans NEW_LINE DEDENT N = int ( input ( ) ) NEW_LINE W = [ input ( ) for _ in range ( N ) ] NEW_LINE print ( b_shiritori ( N , W ) ) NEW_LINE


import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; String t = sc . next ( ) ; String [ ] ss = s . split ( " " ) ; String [ ] tt = t . split ( " " ) ; int x = 0 ; int l = ss . length ; boolean e = true ; Arrays . sort ( ss ) ; Arrays . sort ( tt , Collections . reverseOrder ( ) ) ; if ( ss . length > tt . length ) { l = tt . length ; } for ( int i = 0 ; i < l ; i ++ ) { if ( ss [ i ] . compareTo ( tt [ i ] ) != 0 ) { e = false ; x = i ; break ; } } if ( ss . length < tt . length && e == true ) { System . out . println ( " Yes " ) ; } else if ( ss . length >= tt . length && e == true ) { System . out . println ( " No " ) ; } else if ( e == false && ss [ x ] . compareTo ( tt [ x ] ) < 0 ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } sc . close ( ) ; } }

import java . io . PrintStream ; import java . util . ArrayList ; import java . util . Collections ; import java . util . List ; import java . util . Scanner ; public class Main { static void exec ( Scanner in , PrintStream out ) { String s = in . next ( ) ; String t = in . next ( ) ; List < Character > sl = new ArrayList < > ( s . length ( ) ) ; for ( int i = 0 ; i < s . length ( ) ; i += 1 ) { sl . add ( s . charAt ( i ) ) ; } List < Character > tl = new ArrayList < > ( t . length ( ) ) ; for ( int i = 0 ; i < t . length ( ) ; i += 1 ) { tl . add ( t . charAt ( i ) ) ; } sl . sort ( null ) ; tl . sort ( Collections . reverseOrder ( ) ) ; for ( int i = 0 , n = Math . min ( sl . size ( ) , tl . size ( ) ) ; i < n ; i += 1 ) { if ( sl . get ( i ) . charValue ( ) < tl . get ( i ) . charValue ( ) ) { out . println ( " Yes " ) ; return ; } if ( sl . get ( i ) . charValue ( ) > tl . get ( i ) . charValue ( ) ) { out . println ( " No " ) ; return ; } } out . println ( s . length ( ) < t . length ( ) ? " Yes " : " No " ) ; } public static void main ( String [ ] args ) { exec ( new Scanner ( System . in ) , System . out ) ; } }

import java . util . * ; class Main { static Scanner sc = new Scanner ( System . in ) ; static int mod = 1000000007 ; public static void main ( String [ ] args ) { char [ ] s = sc . next ( ) . toCharArray ( ) ; char [ ] t = sc . next ( ) . toCharArray ( ) ; Arrays . sort ( t ) ; String t2 = new StringBuilder ( String . valueOf ( t ) ) . reverse ( ) . toString ( ) ; Arrays . sort ( s ) ; String s2 = String . valueOf ( s ) ; System . out . println ( s2 . compareTo ( t2 ) < 0 ? " Yes " : " No " ) ; } }

import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; String t = sc . next ( ) ; int N = s . length ( ) ; int M = t . length ( ) ; char [ ] S = new char [ N ] ; char [ ] T = new char [ M ] ; for ( int i = 0 ; i < N ; i ++ ) S [ i ] = s . charAt ( i ) ; for ( int i = 0 ; i < M ; i ++ ) T [ i ] = t . charAt ( i ) ; Arrays . sort ( S ) ; Arrays . sort ( T ) ; int loop = 0 ; if ( N <= M ) { loop = N ; } else { loop = M ; } for ( int i = 0 ; i < loop ; i ++ ) { if ( S [ i ] < T [ ( M - 1 ) - i ] ) { System . out . println ( " Yes " ) ; return ; } else if ( S [ i ] > T [ i ] ) { System . out . println ( " No " ) ; return ; } else { continue ; } } System . out . println ( N < M ? " Yes " : " No " ) ; } }

import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . Arrays ; import java . util . Comparator ; import java . util . stream . Collectors ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader stdin = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String word1 = stdin . readLine ( ) ; String word2 = stdin . readLine ( ) ; String sorted1 = Arrays . stream ( word1 . split ( " " ) ) . sorted ( ) . collect ( Collectors . joining ( ) ) ; String sorted2 = Arrays . stream ( word2 . split ( " " ) ) . sorted ( Comparator . reverseOrder ( ) ) . collect ( Collectors . joining ( ) ) ; String answer = sorted2 . compareTo ( sorted1 ) > 0 ? " Yes " : " No " ; System . out . println ( answer ) ; } }

s = input ( ) NEW_LINE t = input ( ) NEW_LINE s = sorted ( s ) NEW_LINE s = ' ' . join ( s ) NEW_LINE t = sorted ( t , reverse = True ) NEW_LINE t = ' ' . join ( t ) NEW_LINE if s < t : NEW_LINE INDENT print ( ' Yes ' ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( ' No ' ) NEW_LINE DEDENT

s = list ( input ( ) ) NEW_LINE t = list ( input ( ) ) NEW_LINE s = ' ' . join ( sorted ( s ) ) NEW_LINE t = ' ' . join ( sorted ( t , reverse = True ) ) NEW_LINE print ( ' Yes ' if s < t else ' No ' ) NEW_LINE

def io_generator ( ) : NEW_LINE INDENT return input ( ) NEW_LINE DEDENT def main ( io ) : NEW_LINE INDENT s = list ( io ( ) ) NEW_LINE s . sort ( ) NEW_LINE t = list ( io ( ) ) NEW_LINE t . sort ( reverse = True ) NEW_LINE return ' Yes ' if s < t else ' No ' NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT io = lambda : io_generator ( ) NEW_LINE print ( main ( io ) ) NEW_LINE DEDENT

s = input ( ) . strip ( ) NEW_LINE t = input ( ) . strip ( ) NEW_LINE s = sorted ( s ) NEW_LINE t = sorted ( t , reverse = True ) NEW_LINE sl = " " . join ( s ) NEW_LINE tl = " " . join ( t ) NEW_LINE if sl < tl : NEW_LINE INDENT print ( " Yes " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) NEW_LINE DEDENT

n = sorted ( list ( input ( ) ) ) NEW_LINE m = sorted ( list ( input ( ) ) ) NEW_LINE m = m [ : : - 1 ] NEW_LINE if m > n : NEW_LINE INDENT print ( " Yes " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) NEW_LINE DEDENT


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 ] ; for ( int i = 0 ; i < N ; i ++ ) { a [ i ] = sc . nextInt ( ) ; } Arrays . sort ( a ) ; int start = a [ 0 ] ; int end = a [ a . length - 1 ] ; int sum = Integer . MAX_VALUE ; for ( int i = start ; i <= end ; i ++ ) { int ans = 0 ; for ( int j = 0 ; j < N ; j ++ ) { ans += ( a [ j ] - i ) * ( a [ j ] - i ) ; } sum = Math . min ( sum , ans ) ; } System . out . println ( sum ) ; } }

import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . StringTokenizer ; public class Main { int n ; int [ ] as ; public static void main ( String args [ ] ) { new Main ( ) . run ( ) ; } void run ( ) { FastReader sc = new FastReader ( ) ; n = sc . nextInt ( ) ; as = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { as [ i ] = sc . nextInt ( ) ; } solve ( ) ; } void solve ( ) { int min = Integer . MAX_VALUE ; for ( int i = - 100 ; i <= 100 ; i ++ ) { int score = 0 ; for ( int j = 0 ; j < n ; j ++ ) { score += ( i - as [ j ] ) * ( i - as [ j ] ) ; } if ( score < min ) { min = score ; } } System . out . println ( min ) ; } 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 . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader r = new BufferedReader ( new InputStreamReader ( System . in ) , 1 ) ; String s = r . readLine ( ) ; int n = Integer . parseInt ( s ) ; s = r . readLine ( ) ; String [ ] sl = s . split ( " [ \\ s ] + " ) ; int a [ ] = new int [ 1000 ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = Integer . parseInt ( sl [ i ] ) ; } int c = 99999999 ; for ( int i = - 100 ; i <= 100 ; i ++ ) { int v = 0 ; for ( int j = 0 ; j < n ; j ++ ) { v += ( i - a [ j ] ) * ( i - a [ j ] ) ; } c = Math . min ( c , v ) ; } System . out . println ( c ) ; } }

import java . util . Scanner ; public class Main { static Scanner in = new Scanner ( System . in ) ; void solve ( ) { int n = in . nextInt ( ) ; int [ ] a = new int [ n ] ; int t = 0 ; boolean f = true ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = in . nextInt ( ) ; if ( i == 0 ) t = a [ i ] ; if ( f && t != a [ i ] ) f = false ; } if ( f ) { System . out . println ( 0 ) ; return ; } int ans = Integer . MAX_VALUE ; for ( int i = - 100 ; i <= 100 ; i ++ ) { int sum = 0 ; for ( int j : a ) { sum += Math . pow ( j - i , 2 ) ; } ans = Math . min ( ans , sum ) ; } System . out . println ( ans ) ; } public static void main ( String [ ] args ) { new Main ( ) . solve ( ) ; } }

import java . util . * ; import java . lang . * ; import java . io . * ; public class Main { public static int maxOfArray ( int [ ] a ) { int ans = a [ 0 ] ; for ( int i = 1 ; i < a . length ; i ++ ) { if ( a [ i ] > ans ) ans = a [ i ] ; } return ans ; } public static int minOfArray ( int [ ] a ) { int ans = a [ 0 ] ; for ( int i = 1 ; i < a . length ; i ++ ) { if ( a [ i ] < ans ) ans = a [ i ] ; } return ans ; } public static int cost ( int [ ] array , int target ) { int ans = 0 ; for ( int n = 0 ; n < array . length ; n ++ ) ans += ( array [ n ] - target ) * ( array [ n ] - target ) ; return ans ; } public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int [ ] a = new int [ N ] ; for ( int n = 0 ; n < N ; n ++ ) a [ n ] = sc . nextInt ( ) ; int min = minOfArray ( a ) ; int max = maxOfArray ( a ) ; int ans = Integer . MAX_VALUE ; for ( int target = min ; target <= max ; target ++ ) { ans = Math . min ( ans , cost ( a , target ) ) ; } System . out . println ( ans ) ; } }

n = int ( input ( ) ) NEW_LINE a = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE m = round ( sum ( a ) / n ) NEW_LINE ans = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT ans += ( a [ i ] - m ) ** 2 NEW_LINE DEDENT print ( ans ) NEW_LINE

import sys NEW_LINE sys . setrecursionlimit ( 10 ** 6 ) NEW_LINE def main ( n ) : NEW_LINE INDENT a = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE ans = 10 ** 8 NEW_LINE for i in range ( - 100 , 101 , 1 ) : NEW_LINE INDENT temp = 0 NEW_LINE for j in a : NEW_LINE INDENT temp += ( i - j ) ** 2 NEW_LINE DEDENT if ans > temp : NEW_LINE INDENT ans = temp NEW_LINE DEDENT DEDENT print ( ans ) NEW_LINE DEDENT main ( int ( input ( ) ) ) NEW_LINE

N = int ( input ( ) ) NEW_LINE a_s = [ int ( x ) for x in input ( ) . split ( ) ] NEW_LINE average = sum ( a_s ) NEW_LINE average /= len ( a_s ) * 1.0 NEW_LINE ans = - 1 NEW_LINE for target in range ( int ( average ) , int ( average ) + 2 ) : NEW_LINE INDENT c = sum ( map ( lambda x : ( x - target ) * ( x - target ) , a_s ) ) NEW_LINE if ans < 0 : NEW_LINE INDENT ans = c NEW_LINE DEDENT else : NEW_LINE INDENT ans = min ( ans , c ) NEW_LINE DEDENT DEDENT print ( ans ) NEW_LINE

def compute_score ( s ) : NEW_LINE INDENT return sum ( [ ( a - s ) ** 2 for a in As ] ) NEW_LINE DEDENT N = int ( input ( ) . strip ( ) ) NEW_LINE As = list ( map ( int , input ( ) . strip ( ) . split ( ) ) ) NEW_LINE s = sum ( As ) / N NEW_LINE ans = 0 NEW_LINE if ( s % 1 == 0 ) : NEW_LINE INDENT ans = compute_score ( s ) NEW_LINE DEDENT else : NEW_LINE INDENT ans = min ( compute_score ( s // 1 ) , compute_score ( s // 1 + 1 ) ) NEW_LINE DEDENT print ( int ( ans ) ) NEW_LINE

N = int ( input ( ) ) NEW_LINE A = [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE ans = ( 200 ** 2 ) * 100 NEW_LINE for i in range ( - 100 , 101 ) : NEW_LINE INDENT tmp = 0 NEW_LINE for j in range ( N ) : NEW_LINE INDENT tmp += ( A [ j ] - i ) ** 2 NEW_LINE DEDENT ans = min ( ans , tmp ) NEW_LINE DEDENT print ( ans ) NEW_LINE


import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int X = sc . nextInt ( ) ; int [ ] m = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { m [ i ] = sc . nextInt ( ) ; } int cnt = 0 ; int sum = 0 ; int min = X ; for ( int i = 0 ; i < N ; i ++ ) { sum += m [ i ] ; cnt ++ ; if ( m [ i ] < min ) min = m [ i ] ; } X -= sum ; while ( X >= min ) { X -= min ; cnt ++ ; } System . out . println ( cnt ) ; sc . close ( ) ; } }

import static java . lang . System . * ; import java . util . * ; public class Main { static Scanner sc = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { int n = sc . nextInt ( ) , x = sc . nextInt ( ) ; int min = Integer . MAX_VALUE ; for ( int i = 0 ; i < n ; i ++ ) { int temp = sc . nextInt ( ) ; min = Math . min ( min , temp ) ; x -= temp ; } out . println ( n + ( x / min ) ) ; } }

import java . io . * ; import java . util . Arrays ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader stdin = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int left_ingredient = Arrays . stream ( stdin . readLine ( ) . split ( " ▁ " ) ) . mapToInt ( Integer :: parseInt ) . toArray ( ) [ 1 ] ; int [ ] need_ingredient = stdin . lines ( ) . mapToInt ( Integer :: parseInt ) . toArray ( ) ; int min = Arrays . stream ( need_ingredient ) . min ( ) . getAsInt ( ) ; int count = 0 ; for ( int gram : need_ingredient ) { left_ingredient -= gram ; count ++ ; } count += Math . floor ( left_ingredient / min ) ; System . out . println ( count ) ; } }

import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = Integer . parseInt ( sc . next ( ) ) ; int kona = Integer . parseInt ( sc . next ( ) ) ; int dounatu [ ] = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { dounatu [ i ] = Integer . parseInt ( sc . next ( ) ) ; kona = kona - dounatu [ i ] ; } Arrays . sort ( dounatu ) ; System . out . print ( N + kona / dounatu [ 0 ] ) ; } }

import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int x = sc . nextInt ( ) ; int [ ] pow = new int [ n ] ; int total = 0 ; int amari = 0 ; int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { pow [ i ] = sc . nextInt ( ) ; total += pow [ i ] ; } Arrays . sort ( pow ) ; amari = x - total ; if ( amari == 0 ) { ans = n ; } else { ans = ( amari / pow [ 0 ] ) + n ; } System . out . println ( ans ) ; } }

N , X = map ( int , input ( ) . split ( ) ) NEW_LINE m_list = [ int ( input ( ) ) for i in range ( N ) ] NEW_LINE ans = 0 NEW_LINE for i in m_list : NEW_LINE INDENT X -= i NEW_LINE ans += 1 NEW_LINE DEDENT ans += X // min ( m_list ) NEW_LINE print ( ans ) NEW_LINE

N , X = [ int ( x ) for x in input ( ) . split ( ) ] NEW_LINE m = [ int ( input ( ) ) for _ in range ( N ) ] NEW_LINE print ( int ( ( X - sum ( m ) ) / min ( m ) ) + N ) NEW_LINE

N , X = map ( int , input ( ) . split ( ) ) NEW_LINE Z = [ ] NEW_LINE ALL = 0 NEW_LINE for i in range ( N ) : NEW_LINE INDENT Y = int ( input ( ) ) NEW_LINE ALL += Y NEW_LINE Z . append ( Y ) NEW_LINE DEDENT ANS = ( X - ALL ) // ( min ( Z ) ) NEW_LINE if ANS == 0 : NEW_LINE INDENT print ( len ( Z ) ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( ANS + len ( Z ) ) NEW_LINE DEDENT

import math NEW_LINE A = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE M = [ 0 ] * A [ 0 ] NEW_LINE for i in range ( A [ 0 ] ) : NEW_LINE INDENT M [ i ] = int ( input ( ) ) NEW_LINE DEDENT S = math . floor ( ( A [ 1 ] - sum ( M ) ) / min ( M ) ) NEW_LINE print ( S + A [ 0 ] ) NEW_LINE

N , X = map ( int , input ( ) . split ( ) ) NEW_LINE m = [ int ( input ( ) ) for _ in range ( N ) ] NEW_LINE count = N NEW_LINE X -= sum ( m ) NEW_LINE while True : NEW_LINE INDENT X -= min ( m ) NEW_LINE if X < 0 : NEW_LINE INDENT break NEW_LINE DEDENT count += 1 NEW_LINE DEDENT print ( count ) NEW_LINE


import java . util . * ; public class Main { private static int H ; private static int W ; private static int C [ ] [ ] ; public static void input ( ) { Scanner scan = new Scanner ( System . in ) ; H = scan . nextInt ( ) ; W = scan . nextInt ( ) ; C = new int [ H ] [ W ] ; for ( int i = 0 ; i < H ; i ++ ) { for ( int j = 0 ; j < W ; j ++ ) { int x = scan . nextInt ( ) ; if ( ( i + j ) % 2 == 0 ) C [ i ] [ j ] = x ; else C [ i ] [ j ] = - x ; } } } public static void main ( String args [ ] ) { input ( ) ; for ( int i = 1 ; i < H ; i ++ ) { for ( int j = 0 ; j < W ; j ++ ) { C [ i ] [ j ] += C [ i - 1 ] [ j ] ; } } for ( int i = 0 ; i < H ; i ++ ) { for ( int j = 1 ; j < W ; j ++ ) { C [ i ] [ j ] += C [ i ] [ j - 1 ] ; } } int ans = 0 ; for ( int i = 0 ; i < H ; i ++ ) { for ( int j = i ; j < H ; j ++ ) { for ( int k = 0 ; k < W ; k ++ ) { for ( int l = k ; l < W ; l ++ ) { int tmp = C [ j ] [ l ] ; if ( i > 0 ) tmp -= C [ i - 1 ] [ l ] ; if ( k > 0 ) tmp -= C [ j ] [ k - 1 ] ; if ( i > 0 && k > 0 ) tmp += C [ i - 1 ] [ k - 1 ] ; if ( tmp == 0 ) ans = Math . max ( ans , ( j - i + 1 ) * ( l - k + 1 ) ) ; } } } } System . out . println ( ans ) ; } }

import java . util . * ; public class Main { Scanner sc = new Scanner ( System . in ) ; void solve ( ) { int H = sc . nextInt ( ) ; int W = sc . nextInt ( ) ; int [ ] [ ] C = new int [ H ] [ W ] ; for ( int i = 0 ; i < H ; i ++ ) { for ( int j = 0 ; j < W ; j ++ ) { int x = sc . nextInt ( ) ; if ( ( i + j ) % 2 == 0 ) C [ i ] [ j ] = x ; else C [ i ] [ j ] = - x ; } } for ( int i = 1 ; i < H ; i ++ ) { for ( int j = 0 ; j < W ; j ++ ) { C [ i ] [ j ] += C [ i - 1 ] [ j ] ; } } for ( int i = 0 ; i < H ; i ++ ) { for ( int j = 1 ; j < W ; j ++ ) { C [ i ] [ j ] += C [ i ] [ j - 1 ] ; } } int ans = 0 ; for ( int i = 0 ; i < H ; i ++ ) { for ( int j = i ; j < H ; j ++ ) { for ( int k = 0 ; k < W ; k ++ ) { for ( int l = k ; l < W ; l ++ ) { int tmp = C [ j ] [ l ] ; if ( i > 0 ) tmp -= C [ i - 1 ] [ l ] ; if ( k > 0 ) tmp -= C [ j ] [ k - 1 ] ; if ( i > 0 && k > 0 ) tmp += C [ i - 1 ] [ k - 1 ] ; if ( tmp == 0 ) { ans = Math . max ( ans , ( j - i + 1 ) * ( l - k + 1 ) ) ; } } } } } System . out . println ( ans ) ; } public static void main ( String [ ] args ) { Scanner s = new Scanner ( System . in ) ; Main main = new Main ( ) ; main . solve ( ) ; } }

def solve ( ) : NEW_LINE INDENT from itertools import product NEW_LINE H , W = map ( int , input ( ) . split ( ) ) NEW_LINE a = [ list ( map ( int , input ( ) . split ( ) ) ) for _ in [ 0 ] * H ] NEW_LINE cumsum = [ [ [ 0 , 0 ] ] * ( W + 1 ) ] + [ [ [ 0 , 0 ] for _ in [ 0 ] * ( W + 1 ) ] for _ in [ 0 ] * H ] NEW_LINE for y , l in enumerate ( a , start = 1 ) : NEW_LINE INDENT cum_b , cum_w = 0 , 0 NEW_LINE for x , ( v , ( up_b , up_w ) ) in enumerate ( zip ( l , cumsum [ y - 1 ] [ 1 : ] ) , start = 1 ) : NEW_LINE INDENT if ( x + y % 2 ) % 2 == 0 : NEW_LINE INDENT cum_b += v NEW_LINE DEDENT else : NEW_LINE INDENT cum_w += v NEW_LINE DEDENT cumsum [ y ] [ x ] = [ up_b + cum_b , up_w + cum_w ] NEW_LINE DEDENT DEDENT result = 0 NEW_LINE for width , height in product ( range ( 1 , W + 1 ) , range ( 1 , H + 1 ) ) : NEW_LINE INDENT if result >= width * height : NEW_LINE INDENT continue NEW_LINE DEDENT for _y , y in zip ( range ( H + 1 ) , range ( height , H + 1 ) ) : NEW_LINE INDENT for ( b1 , w1 ) , ( b2 , w2 ) , ( b3 , w3 ) , ( b4 , w4 ) in zip ( cumsum [ _y ] , cumsum [ _y ] [ width : ] , cumsum [ y ] , cumsum [ y ] [ width : ] ) : NEW_LINE INDENT b = b1 - b2 - b3 + b4 NEW_LINE w = w1 - w2 - w3 + w4 NEW_LINE if b == w : NEW_LINE INDENT result = width * height NEW_LINE DEDENT DEDENT DEDENT DEDENT print ( result ) NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT solve ( ) NEW_LINE DEDENT


import java . util . * ; class Main { public static void main ( String args [ ] ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int x = 800 * n ; int y = n / 15 * 200 ; System . out . println ( x - y ) ; } }

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

import java . 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 ( ) ; out . println ( 800 * N - N / 15 * 200 ) ; } } 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 char nextChar ( ) { return next ( ) . charAt ( 0 ) ; } public int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } public double nextDouble ( ) { return Double . parseDouble ( next ( ) ) ; } } }

import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int x = N * 800 ; int y = N / 15 * 200 ; int ans = x - y ; System . out . print ( ans ) ; } }

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 ( ) ) ; sc . close ( ) ; System . out . println ( ( n * 800 ) - n / 15 * 200 ) ; } }

N = int ( input ( ) ) NEW_LINE print ( N * 800 - N // 15 * 200 ) NEW_LINE

import sys NEW_LINE def main ( ) : NEW_LINE INDENT input = sys . stdin . readline NEW_LINE N = int ( input ( ) ) NEW_LINE x = 800 * N NEW_LINE y = 200 * ( N // 15 ) NEW_LINE return x - y NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT print ( main ( ) ) NEW_LINE DEDENT

N = int ( input ( ) ) NEW_LINE count = 0 NEW_LINE morta = 0 NEW_LINE for i in range ( N ) : NEW_LINE INDENT count += 800 NEW_LINE if ( i + 1 ) % 15 == 0 : NEW_LINE INDENT morta += 200 NEW_LINE DEDENT DEDENT print ( count - morta ) NEW_LINE

from functools import reduce NEW_LINE import math NEW_LINE def main ( ) : NEW_LINE INDENT N = int ( input ( ) . rstrip ( ) ) NEW_LINE print ( N * 800 - ( N // 15 ) * 200 ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT

x = int ( input ( ) ) NEW_LINE ans1 = 800 * x NEW_LINE z = x // 15 NEW_LINE ans2 = ans1 - ( z * 200 ) NEW_LINE print ( ans2 ) NEW_LINE


import java . util . * ; class Main { public static void main ( String args [ ] ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int T = sc . nextInt ( ) ; int A [ ] = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { A [ i ] = sc . nextInt ( ) ; } int min [ ] = new int [ N ] ; min [ 0 ] = A [ 0 ] ; for ( int i = 1 ; i < N ; i ++ ) { if ( A [ i ] < min [ i - 1 ] ) { min [ i ] = A [ i ] ; } else { min [ i ] = min [ i - 1 ] ; } } int max [ ] = new int [ N ] ; max [ N - 1 ] = A [ N - 1 ] ; for ( int i = N - 2 ; i >= 0 ; i -- ) { if ( A [ i ] > max [ i + 1 ] ) { max [ i ] = A [ i ] ; } else { max [ i ] = max [ i + 1 ] ; } } int maxgap = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( maxgap < max [ i ] - min [ i ] ) { maxgap = max [ i ] - min [ i ] ; } } int prevmax = 0 ; int prevmin = 0 ; int count = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( max [ i ] - min [ i ] == maxgap && ( prevmax != max [ i ] || prevmin != min [ i ] ) ) { count ++ ; } prevmax = max [ i ] ; prevmin = min [ i ] ; } System . out . println ( count ) ; } }

import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner input = new Scanner ( System . in ) ; int numTown = input . nextInt ( ) ; input . nextInt ( ) ; int [ ] val = new int [ numTown ] ; for ( int i = 0 ; i < numTown ; i ++ ) { val [ i ] = input . nextInt ( ) ; } int maxdiff = 0 ; int count = 0 ; int [ ] maxright = new int [ numTown ] ; int [ ] minleft = new int [ numTown ] ; maxright [ numTown - 1 ] = val [ numTown - 1 ] ; minleft [ 0 ] = val [ 0 ] ; for ( int i = 1 ; i < numTown ; i ++ ) { minleft [ i ] = Math . min ( minleft [ i - 1 ] , val [ i ] ) ; } for ( int i = numTown - 2 ; i >= 0 ; i -- ) { maxright [ i ] = Math . max ( maxright [ i + 1 ] , val [ i ] ) ; } for ( int i = 0 ; i < numTown ; i ++ ) { if ( maxright [ i ] - minleft [ i ] > maxdiff ) { int mr = maxright [ i ] ; int ml = minleft [ i ] ; maxdiff = maxright [ i ] - minleft [ i ] ; count = 1 ; while ( i < numTown && maxright [ i ] == mr && minleft [ i ] == ml ) { i ++ ; } } else if ( maxright [ i ] - minleft [ i ] == maxdiff ) { count ++ ; int mr = maxright [ i ] ; int ml = minleft [ i ] ; while ( i < numTown && maxright [ i ] == mr && minleft [ i ] == ml ) { i ++ ; } } } System . out . println ( count ) ; } }

import java . io . BufferedReader ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws Exception { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String line = br . readLine ( ) ; String [ ] sp = line . split ( " ▁ " ) ; int n = Integer . parseInt ( sp [ 0 ] ) ; line = br . readLine ( ) ; sp = line . split ( " ▁ " ) ; long [ ] a = new long [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = Long . parseLong ( sp [ i ] ) ; } long min = Integer . MAX_VALUE ; long max = 0 ; int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { min = Math . min ( min , a [ i ] ) ; if ( a [ i ] - min > max ) { max = a [ i ] - min ; count = 1 ; } else if ( a [ i ] - min == max ) { max = a [ i ] - min ; count ++ ; } } System . out . println ( count ) ; } }

import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int T = sc . nextInt ( ) ; int [ ] A = new int [ N + 1 ] ; for ( int i = 1 ; i <= N ; i ++ ) { A [ i ] = sc . nextInt ( ) ; } sc . close ( ) ; A [ 0 ] = Integer . MAX_VALUE ; int max = 0 ; int last_min_i = N ; int max_start_i = N ; int diff_max = 0 ; int cost = 0 ; for ( int i = N ; i >= 0 ; i -- ) { if ( A [ i ] > max ) { if ( diff_max > 0 ) { int cost0 = 0 ; int cost1 = 0 ; for ( int j = i + 1 ; j <= max_start_i ; j ++ ) { if ( A [ j ] == max && j >= last_min_i ) { cost0 ++ ; } else if ( A [ j ] == max - diff_max ) { if ( cost0 > cost1 ) { cost0 = cost1 ; } cost1 ++ ; } } cost += Math . min ( cost0 , cost1 ) ; } max = A [ i ] ; max_start_i = i ; } else if ( A [ i ] == max ) { } else { if ( max - A [ i ] == diff_max ) { last_min_i = i ; } else if ( max - A [ i ] > diff_max ) { diff_max = max - A [ i ] ; last_min_i = i ; cost = 0 ; } } } System . out . println ( cost ) ; } }

import java . util . HashMap ; import java . util . Map ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; while ( sc . hasNextInt ( ) ) { int n = sc . nextInt ( ) ; int t = sc . nextInt ( ) ; long [ ] a = new long [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = sc . nextLong ( ) ; } long maxDiff = 0 ; long min = Long . MAX_VALUE ; for ( int i = 0 ; i < n ; i ++ ) { if ( i != 0 ) { maxDiff = Math . max ( maxDiff , a [ i ] - min ) ; } min = Math . min ( min , a [ i ] ) ; } int ans = 0 ; Map < Long , Long > cnt = new HashMap < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { long target = a [ i ] - maxDiff ; if ( cnt . containsKey ( target ) ) { ans += cnt . get ( target ) ; } Long tmpCnt = cnt . get ( a [ i ] ) ; if ( tmpCnt == null ) { tmpCnt = 0L ; } tmpCnt ++ ; cnt . put ( a [ i ] , tmpCnt ) ; } System . out . println ( ans ) ; } } }

n , t = map ( int , input ( ) . split ( ) ) NEW_LINE alist = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE minal = [ alist [ 0 ] ] NEW_LINE maxal = [ alist [ - 1 ] ] NEW_LINE for a in alist [ 1 : ] : NEW_LINE INDENT if minal [ - 1 ] > a : NEW_LINE INDENT minal . append ( a ) NEW_LINE DEDENT else : NEW_LINE INDENT minal . append ( minal [ - 1 ] ) NEW_LINE DEDENT DEDENT for a in alist [ : : - 1 ] [ 1 : ] : NEW_LINE INDENT if maxal [ - 1 ] < a : NEW_LINE INDENT maxal . append ( a ) NEW_LINE DEDENT else : NEW_LINE INDENT maxal . append ( maxal [ - 1 ] ) NEW_LINE DEDENT DEDENT maxal = maxal [ : : - 1 ] NEW_LINE maxda = 0 NEW_LINE ans = 0 NEW_LINE prevmina , prevmaxa = None , None NEW_LINE for mina , maxa in zip ( minal , maxal ) : NEW_LINE INDENT if prevmina == mina and prevmaxa == maxa : NEW_LINE INDENT continue NEW_LINE DEDENT elif maxa - mina == maxda : NEW_LINE INDENT ans += 1 NEW_LINE DEDENT elif maxa - mina > maxda : NEW_LINE INDENT maxda = maxa - mina NEW_LINE ans = 1 NEW_LINE DEDENT prevmina , prevmaxa = mina , maxa NEW_LINE DEDENT print ( ans ) NEW_LINE

def inpl ( ) : return [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE N , T = inpl ( ) NEW_LINE A = inpl ( ) NEW_LINE minA = [ 0 for _ in range ( N ) ] NEW_LINE minA [ 0 ] = A [ 0 ] NEW_LINE for i in range ( N - 1 ) : NEW_LINE INDENT minA [ i + 1 ] = min ( minA [ i ] , A [ i + 1 ] ) NEW_LINE DEDENT ans = 1 NEW_LINE maxpro = 0 NEW_LINE for i in range ( N - 1 ) : NEW_LINE INDENT if A [ i + 1 ] - minA [ i ] == maxpro : NEW_LINE INDENT ans += 1 NEW_LINE DEDENT if A [ i + 1 ] - minA [ i ] > maxpro : NEW_LINE INDENT ans = 1 NEW_LINE maxpro = A [ i + 1 ] - minA [ i ] NEW_LINE DEDENT DEDENT print ( ans ) NEW_LINE

n , _ , * a = map ( int , open ( 0 ) . read ( ) . split ( ) ) NEW_LINE m = d = c = 0 NEW_LINE for t in a [ : : - 1 ] : NEW_LINE INDENT if t > m : NEW_LINE INDENT m = t NEW_LINE DEDENT if m - t > d : NEW_LINE INDENT d = m - t NEW_LINE c = 1 NEW_LINE DEDENT elif m - t == d : NEW_LINE INDENT c += 1 NEW_LINE DEDENT DEDENT print ( c ) NEW_LINE

import sys , collections NEW_LINE from collections import defaultdict NEW_LINE def update_minA ( minA , t ) : NEW_LINE INDENT if minA > t : NEW_LINE INDENT return t NEW_LINE DEDENT return minA NEW_LINE DEDENT def check_range ( y , x , H , W ) : NEW_LINE INDENT return 0 < x and x < W and 0 < y and y < H NEW_LINE DEDENT def solve ( ) : NEW_LINE INDENT N , T = map ( int , input ( ) . split ( ) ) NEW_LINE A = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE minA = float ( " inf " ) NEW_LINE P = defaultdict ( lambda : 0 ) NEW_LINE for i , v in enumerate ( A ) : NEW_LINE INDENT if i != 0 : NEW_LINE INDENT P [ v - minA ] += 1 NEW_LINE DEDENT minA = update_minA ( minA , v ) NEW_LINE DEDENT print ( P [ max ( P ) ] ) NEW_LINE DEDENT solve ( ) NEW_LINE

def main ( ) : NEW_LINE INDENT buf = input ( ) NEW_LINE buflist = buf . split ( ) NEW_LINE N = int ( buflist [ 0 ] ) NEW_LINE T = int ( buflist [ 1 ] ) NEW_LINE buf = input ( ) NEW_LINE buflist = buf . split ( ) NEW_LINE A = list ( map ( int , buflist ) ) NEW_LINE min_price = A [ 0 ] NEW_LINE max_price_diff = 0 NEW_LINE max_diff_count = 0 NEW_LINE for i in range ( 1 , N ) : NEW_LINE INDENT if A [ i ] < min_price : NEW_LINE INDENT min_price = A [ i ] NEW_LINE DEDENT elif A [ i ] - min_price > max_price_diff : NEW_LINE INDENT max_price_diff = A [ i ] - min_price NEW_LINE max_diff_count = 1 NEW_LINE DEDENT elif A [ i ] - min_price == max_price_diff : NEW_LINE INDENT max_diff_count += 1 NEW_LINE DEDENT DEDENT print ( max_diff_count ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT


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 ( ) ; ArrayDeque < Integer > deque = new ArrayDeque < > ( M ) ; for ( int i = 0 ; i < M ; i ++ ) { deque . addFirst ( sc . nextInt ( ) ) ; } boolean f [ ] = new boolean [ N + 1 ] ; while ( ! deque . isEmpty ( ) ) { int p = deque . poll ( ) ; if ( ! f [ p ] ) { f [ p ] = true ; System . out . println ( p ) ; } } for ( int i = 1 ; i <= N ; i ++ ) { if ( ! f [ i ] ) { System . out . println ( i ) ; } } } }

import java . util . * ; import java . util . stream . * ; public class Main { private static Scanner scanner = new Scanner ( System . in ) ; public static void main ( String [ ] $ ) { int n = scanner . nextInt ( ) , m = scanner . nextInt ( ) ; List < Integer > list = IntStream . range ( 0 , m ) . map ( i -> scanner . nextInt ( ) ) . boxed ( ) . collect ( Collectors . toList ( ) ) ; Collections . reverse ( list ) ; Stream . concat ( list . stream ( ) , IntStream . rangeClosed ( 1 , n ) . boxed ( ) ) . distinct ( ) . forEach ( System . out :: println ) ; } }

import java . util . ArrayDeque ; import java . util . Deque ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int m = sc . nextInt ( ) ; boolean [ ] a = new boolean [ n ] ; Deque < Integer > d = new ArrayDeque < > ( ) ; for ( int i = 0 ; i < m ; i ++ ) { int b = sc . nextInt ( ) ; d . push ( b ) ; } while ( ! d . isEmpty ( ) ) { int c = d . poll ( ) ; if ( ! a [ c - 1 ] ) { a [ c - 1 ] = true ; System . out . println ( c ) ; } } for ( int i = 0 ; i < n ; i ++ ) { if ( ! a [ i ] ) System . out . println ( i + 1 ) ; } } }

import java . util . * ; import static java . lang . System . * ; import static java . lang . Math . * ; public class Main { public static void main ( String [ ] $ ) { Scanner sc = new Scanner ( in ) ; int n = sc . nextInt ( ) , m = sc . nextInt ( ) ; int [ ] a = new int [ m ] ; ArrayDeque < Integer > stack = new ArrayDeque < > ( ) ; for ( int i = n ; i > 0 ; i -- ) { stack . addFirst ( i ) ; } for ( int i = 0 ; i < m ; i ++ ) { a [ i ] = sc . nextInt ( ) ; stack . addFirst ( a [ i ] ) ; } int [ ] used = new int [ n + 1 ] ; while ( stack . size ( ) > 0 ) { int ans = stack . pollFirst ( ) ; if ( used [ ans ] == 0 ) { out . println ( ans ) ; used [ ans ] ++ ; } } } }

import java . util . ArrayDeque ; import java . util . Scanner ; public class Main { static Scanner s = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { int n = s . nextInt ( ) , m = s . nextInt ( ) ; ArrayDeque < Integer > deque = new ArrayDeque < > ( m ) ; boolean f [ ] = new boolean [ n + 1 ] ; for ( int i = 0 ; i < m ; i ++ ) { deque . addFirst ( s . nextInt ( ) ) ; } while ( ! deque . isEmpty ( ) ) { int p = deque . poll ( ) ; if ( ! f [ p ] ) { f [ p ] = true ; System . out . println ( p ) ; } } for ( int i = 1 ; i <= n ; i ++ ) { if ( ! f [ i ] ) { System . out . println ( i ) ; } } } }

N , M = map ( int , input ( ) . split ( ) ) NEW_LINE a = [ int ( input ( ) ) for _ in range ( M ) ] NEW_LINE a = a [ : : - 1 ] + [ int ( i ) for i in range ( 1 , N + 1 ) ] NEW_LINE L = set ( ) NEW_LINE for i in a : NEW_LINE INDENT if i not in L : NEW_LINE INDENT print ( i ) NEW_LINE L . add ( i ) NEW_LINE DEDENT DEDENT

import sys NEW_LINE sys . setrecursionlimit ( 10 ** 9 ) NEW_LINE input = sys . stdin . readline NEW_LINE N , M = map ( int , input ( ) . split ( ) ) NEW_LINE l = [ [ v , i ] for i , v in enumerate ( reversed ( range ( N ) ) ) ] NEW_LINE for _ in range ( M ) : NEW_LINE INDENT N += 1 NEW_LINE n = int ( input ( ) ) - 1 NEW_LINE l [ n ] [ 0 ] = N NEW_LINE DEDENT l = sorted ( l , key = lambda x : x [ 0 ] , reverse = True ) NEW_LINE for v , i in l : NEW_LINE INDENT print ( i + 1 ) NEW_LINE DEDENT

class Node ( object ) : NEW_LINE INDENT def __init__ ( self , value , prev , next ) : NEW_LINE INDENT self . value = value NEW_LINE self . prev = prev NEW_LINE self . next = next NEW_LINE DEDENT DEDENT class Threads ( object ) : NEW_LINE INDENT def __init__ ( self , count ) : NEW_LINE INDENT self . nodes = [ ] NEW_LINE for i in range ( count + 2 ) : NEW_LINE INDENT self . nodes . append ( Node ( i , None , None ) ) NEW_LINE DEDENT for i in range ( count + 1 ) : NEW_LINE INDENT self . nodes [ i ] . next = self . nodes [ i + 1 ] NEW_LINE self . nodes [ i + 1 ] . prev = self . nodes [ i ] NEW_LINE DEDENT DEDENT def move_first ( self , i ) : NEW_LINE INDENT self . nodes [ i ] . prev . next = self . nodes [ i ] . next NEW_LINE self . nodes [ i ] . next . prev = self . nodes [ i ] . prev NEW_LINE self . nodes [ i ] . prev = self . nodes [ 0 ] NEW_LINE self . nodes [ i ] . next = self . nodes [ 0 ] . next NEW_LINE self . nodes [ i ] . prev . next = self . nodes [ i ] NEW_LINE self . nodes [ i ] . next . prev = self . nodes [ i ] NEW_LINE DEDENT DEDENT def main ( ) : NEW_LINE INDENT n , m = map ( int , input ( ) . split ( ) ) NEW_LINE threads = Threads ( n ) NEW_LINE for _ in range ( m ) : NEW_LINE INDENT a = int ( input ( ) ) NEW_LINE threads . move_first ( a ) NEW_LINE DEDENT node = threads . nodes [ 0 ] . next NEW_LINE while node != threads . nodes [ - 1 ] : NEW_LINE INDENT print ( node . value ) NEW_LINE node = node . next NEW_LINE DEDENT DEDENT main ( ) NEW_LINE

def a_bbs ( N , M , A ) : NEW_LINE INDENT written_thread = set ( ) NEW_LINE ans = [ ] NEW_LINE for a in reversed ( A ) : NEW_LINE INDENT if a not in written_thread : NEW_LINE INDENT written_thread . add ( a ) NEW_LINE ans . append ( a ) NEW_LINE DEDENT DEDENT remain_thread = set ( range ( 1 , N + 1 ) ) - written_thread NEW_LINE ans . extend ( sorted ( remain_thread ) ) NEW_LINE ans = ' \n ' . join ( map ( str , ans ) ) NEW_LINE return ans NEW_LINE DEDENT N , M = [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE A = [ int ( input ( ) ) for _ in [ 0 ] * M ] NEW_LINE print ( a_bbs ( N , M , A ) ) NEW_LINE

n , m = map ( int , input ( ) . split ( ) ) NEW_LINE A = [ [ 0 , i + 1 ] for i in range ( n ) ] NEW_LINE for _ in range ( m ) : NEW_LINE INDENT a = int ( input ( ) ) - 1 NEW_LINE A [ a ] [ 0 ] = _ + 1 NEW_LINE DEDENT A . sort ( reverse = True ) NEW_LINE K = [ ] NEW_LINE for j in range ( n ) : NEW_LINE INDENT if A [ j ] [ 0 ] == 0 : NEW_LINE INDENT A = A [ j : : ] NEW_LINE A . sort ( ) NEW_LINE for i in range ( len ( A ) ) : NEW_LINE INDENT K . append ( A [ i ] [ 1 ] ) NEW_LINE DEDENT break NEW_LINE DEDENT else : NEW_LINE INDENT K . append ( A [ j ] [ 1 ] ) NEW_LINE DEDENT DEDENT for i in K : NEW_LINE INDENT print ( i ) NEW_LINE DEDENT