import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; int x = 0 ; int y = 0 ; int uk = 0 ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { switch ( s . substring ( i , i + 1 ) ) { case " R " : x ++ ; break ; case " L " : x -- ; break ; case " D " : y -- ; break ; case " U " : y ++ ; break ; case " ? " : uk ++ ; break ; } } int ans = Math . abs ( x ) + Math . abs ( y ) ; int t = sc . nextInt ( ) ; if ( t == 1 ) System . out . println ( ans + uk ) ; else { if ( ans >= uk ) System . out . println ( ans - uk ) ; else System . out . println ( ( uk - ans ) % 2 ) ; } } }

import java . io . OutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . PrintWriter ; import java . io . UncheckedIOException ; import java . util . StringTokenizer ; import java . io . IOException ; import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . io . InputStream ; public class Main { public static void main ( String [ ] args ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; LightScanner in = new LightScanner ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; B solver = new B ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class B { public void solve ( int testNumber , LightScanner in , PrintWriter out ) { String s = in . string ( ) ; int p = 0 ; int x = 0 , y = 0 ; for ( char c : s . toCharArray ( ) ) { switch ( c ) { case ' L ' : x -- ; break ; case ' R ' : x ++ ; break ; case ' U ' : y ++ ; break ; case ' D ' : y -- ; break ; case ' ? ' : p ++ ; break ; } } int t = in . ints ( ) ; int total = Math . abs ( x ) + Math . abs ( y ) ; if ( t == 2 ) { if ( total > p ) { out . println ( total - p ) ; } else { out . println ( ( p - total ) % 2 ) ; } } else { out . println ( total + p ) ; } } } static class LightScanner { private BufferedReader reader = null ; private StringTokenizer tokenizer = null ; public LightScanner ( InputStream in ) { reader = new BufferedReader ( new InputStreamReader ( in ) ) ; } public String string ( ) { if ( tokenizer == null || ! tokenizer . hasMoreTokens ( ) ) { try { tokenizer = new StringTokenizer ( reader . readLine ( ) ) ; } catch ( IOException e ) { throw new UncheckedIOException ( e ) ; } } return tokenizer . nextToken ( ) ; } public int ints ( ) { return Integer . parseInt ( string ( ) ) ; } } }

import java . util . Scanner ; import java . util . Arrays ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; String S = scanner . next ( ) ; int T = scanner . nextInt ( ) ; int x = 0 ; int y = 0 ; int count = 0 ; for ( int i = 0 ; i < S . length ( ) ; i ++ ) { if ( S . charAt ( i ) == ' L ' ) { x += - 1 ; } if ( S . charAt ( i ) == ' R ' ) { x += 1 ; } if ( S . charAt ( i ) == ' U ' ) { y += 1 ; } if ( S . charAt ( i ) == ' D ' ) { y += - 1 ; } if ( S . charAt ( i ) == ' ? ' ) { count ++ ; } } if ( T == 1 ) { System . out . println ( Math . abs ( x ) + Math . abs ( y ) + count ) ; } if ( T == 2 ) { if ( Math . abs ( x ) + Math . abs ( y ) - count >= 0 ) { System . out . println ( Math . abs ( x ) + Math . abs ( y ) - count ) ; } else if ( Math . abs ( x ) + Math . abs ( y ) - count < 0 && ( Math . abs ( x ) + Math . abs ( y ) ) % 2 == count % 2 ) { System . out . println ( 0 ) ; } else { System . out . println ( 1 ) ; } } } }

import java . util . * ; import java . lang . * ; import java . math . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; int t = sc . nextInt ( ) ; int lr = 0 ; int ud = 0 ; int qc = 0 ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( s . charAt ( i ) == ' L ' ) { lr -- ; } else if ( s . charAt ( i ) == ' R ' ) { lr ++ ; } else if ( s . charAt ( i ) == ' D ' ) { ud -- ; } else if ( s . charAt ( i ) == ' U ' ) { ud ++ ; } else { qc ++ ; } } if ( lr < 0 ) { lr = lr * ( - 1 ) ; } if ( ud < 0 ) { ud = ud * ( - 1 ) ; } if ( t == 1 ) { System . out . println ( lr + ud + qc ) ; } else { if ( qc >= lr + ud ) { System . out . println ( ( qc - ( lr + ud ) ) % 2 ) ; } else { System . out . println ( lr + ud - qc ) ; } } sc . close ( ) ; } }

import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String po = sc . nextLine ( ) ; int n = sc . nextInt ( ) ; int count = 0 ; int x = 0 , y = 0 ; String s [ ] = po . split ( " " , 0 ) ; for ( int i = 0 ; i < s . length ; i ++ ) { if ( s [ i ] . equals ( " U " ) ) y -- ; else if ( s [ i ] . equals ( " D " ) ) y ++ ; else if ( s [ i ] . equals ( " R " ) ) x ++ ; else if ( s [ i ] . equals ( " L " ) ) x -- ; else count ++ ; } int h = Math . abs ( x ) + Math . abs ( y ) ; System . out . println ( ( n == 1 ) ? h + count : ( h < count ) ? ( ( h - count ) % 2 == 0 ) ? 0 : 1 : h - count ) ; } }

import math NEW_LINE def getInt ( ) : return int ( input ( ) ) NEW_LINE def getIntList ( ) : return [ int ( x ) for x in input ( ) . split ( ) ] NEW_LINE def zeros ( n ) : return [ 0 ] * n NEW_LINE def zeros2 ( n , m ) : return [ zeros ( m ) for i in range ( n ) ] NEW_LINE class Debug ( ) : NEW_LINE INDENT def __init__ ( self ) : NEW_LINE INDENT self . debug = True NEW_LINE DEDENT def off ( self ) : NEW_LINE INDENT self . debug = False NEW_LINE DEDENT def dmp ( self , x , cmt = ' ' ) : NEW_LINE INDENT if self . debug : NEW_LINE INDENT if cmt != ' ' : NEW_LINE INDENT w = cmt + ' : ▁ ' + str ( x ) NEW_LINE DEDENT else : NEW_LINE INDENT w = str ( x ) NEW_LINE DEDENT print ( w ) NEW_LINE DEDENT return x NEW_LINE DEDENT DEDENT def prob ( ) : NEW_LINE INDENT d = Debug ( ) NEW_LINE d . off ( ) NEW_LINE S = input ( ) NEW_LINE d . dmp ( ( S ) , ' S ' ) NEW_LINE T = getInt ( ) NEW_LINE d . dmp ( ( T ) , ' T ' ) NEW_LINE x , y , q = 0 , 0 , 0 NEW_LINE for i in range ( len ( S ) ) : NEW_LINE INDENT if S [ i ] == ' R ' : NEW_LINE INDENT x += 1 NEW_LINE DEDENT elif S [ i ] == ' L ' : NEW_LINE INDENT x -= 1 NEW_LINE DEDENT elif S [ i ] == ' U ' : NEW_LINE INDENT y += 1 NEW_LINE DEDENT elif S [ i ] == ' D ' : NEW_LINE INDENT y -= 1 NEW_LINE DEDENT else : NEW_LINE INDENT q += 1 NEW_LINE DEDENT DEDENT val = abs ( x ) + abs ( y ) NEW_LINE if T == 1 : NEW_LINE INDENT val += q NEW_LINE DEDENT else : NEW_LINE INDENT if val >= q : NEW_LINE INDENT val -= q NEW_LINE DEDENT else : NEW_LINE INDENT val = ( q - val ) % 2 NEW_LINE DEDENT DEDENT return val NEW_LINE DEDENT ans = prob ( ) NEW_LINE print ( ans ) NEW_LINE

s = input ( ) NEW_LINE x = abs ( s . count ( ' R ' ) - s . count ( ' L ' ) ) + abs ( s . count ( ' U ' ) - s . count ( ' D ' ) ) NEW_LINE c = s . count ( ' ? ' ) NEW_LINE if int ( input ( ) ) == 1 : NEW_LINE INDENT print ( x + c ) NEW_LINE DEDENT elif c <= x : NEW_LINE INDENT print ( x - c ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( ( x + c ) % 2 ) NEW_LINE DEDENT

s = list ( input ( ) ) NEW_LINE t = int ( input ( ) ) NEW_LINE x = 0 NEW_LINE y = 0 NEW_LINE d = 0 NEW_LINE count = 0 NEW_LINE for i in range ( len ( s ) ) : NEW_LINE INDENT if s [ i ] == ' L ' : NEW_LINE INDENT x -= 1 NEW_LINE DEDENT elif s [ i ] == ' R ' : NEW_LINE INDENT x += 1 NEW_LINE DEDENT elif s [ i ] == ' U ' : NEW_LINE INDENT y += 1 NEW_LINE DEDENT elif s [ i ] == ' D ' : NEW_LINE INDENT y -= 1 NEW_LINE DEDENT elif s [ i ] == ' ? ' : NEW_LINE INDENT count += 1 NEW_LINE DEDENT DEDENT if t == 1 : NEW_LINE INDENT print ( max ( abs ( x + count ) + abs ( y ) , abs ( x ) + abs ( y + count ) , abs ( x - count ) + abs ( y ) , abs ( x ) + abs ( y - count ) ) ) NEW_LINE DEDENT elif t == 2 : NEW_LINE INDENT d = abs ( x ) + abs ( y ) NEW_LINE if d > count : NEW_LINE INDENT print ( d - count ) NEW_LINE DEDENT else : NEW_LINE INDENT if ( d - count ) % 2 == 0 : NEW_LINE INDENT print ( 0 ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( 1 ) NEW_LINE DEDENT DEDENT DEDENT

def drone ( S : int , T : int ) -> int : NEW_LINE INDENT d = { ' L ' : 0 , ' R ' : 0 , ' U ' : 0 , ' D ' : 0 , ' ? ' : 0 } NEW_LINE for c in S : NEW_LINE INDENT d [ c ] += 1 NEW_LINE DEDENT dx = abs ( d [ ' L ' ] - d [ ' R ' ] ) NEW_LINE dy = abs ( d [ ' U ' ] - d [ ' D ' ] ) NEW_LINE if T == 1 : NEW_LINE INDENT return dx + dy + d [ ' ? ' ] NEW_LINE DEDENT min_d = dx + dy - d [ ' ? ' ] NEW_LINE if min_d >= 0 : NEW_LINE INDENT return min_d NEW_LINE DEDENT return ( - min_d ) % 2 NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT S = input ( ) NEW_LINE T = int ( input ( ) ) NEW_LINE ans = drone ( S , T ) NEW_LINE print ( ans ) NEW_LINE DEDENT

s = list ( input ( ) ) NEW_LINE t = int ( input ( ) ) NEW_LINE c = [ 0 , 0 ] NEW_LINE for s_ in s : NEW_LINE INDENT if s_ == " L " : NEW_LINE INDENT c [ 0 ] += - 1 NEW_LINE DEDENT elif s_ == " R " : NEW_LINE INDENT c [ 0 ] += 1 NEW_LINE DEDENT elif s_ == " U " : NEW_LINE INDENT c [ 1 ] += 1 NEW_LINE DEDENT elif s_ == " D " : NEW_LINE INDENT c [ 1 ] += - 1 NEW_LINE DEDENT DEDENT ques = s . count ( " ? " ) NEW_LINE ans = abs ( c [ 0 ] ) + abs ( c [ 1 ] ) NEW_LINE if t == 1 : NEW_LINE INDENT ans += ques NEW_LINE DEDENT else : NEW_LINE INDENT for i in range ( ques ) : NEW_LINE INDENT if ans > 0 : NEW_LINE INDENT ans -= 1 NEW_LINE DEDENT elif ans == 0 : NEW_LINE INDENT ans += 1 NEW_LINE DEDENT DEDENT DEDENT print ( ans ) NEW_LINE


import java . io . * ; import java . util . * ; public class Main { static final Reader in = new Reader ( ) ; static final long M = ( long ) 1e9 + 7 ; public static void main ( String [ ] args ) { int n = in . nextInt ( ) ; long [ ] ps = new long [ n + 1 ] ; long nf = 1 ; for ( int i = 1 ; i <= n ; ++ i ) { ps [ i ] = ( ps [ i - 1 ] + in . nextInt ( ) ) % M ; nf = nf * i % M ; } long ans = nf * ps [ n ] % M , s = 0 ; for ( int i = 1 ; i <= n - 1 ; ++ i ) { s = ( s + ps [ n - i ] - ps [ i ] + M ) % M ; ans = ( ans + nf * modI ( ( long ) ( i + 1 ) * ( i >= n - 1 ? 1 : i + 2 ) , M ) % M * 2 * s + nf * modI ( i + 1 , M ) % M * ( ps [ i ] + ps [ n ] - ps [ n - i ] + M ) ) % M ; } System . out . println ( ans ) ; } static long modI ( long a , long m ) { return ( a %= m ) <= 1 ? 1 : ( 1 - modI ( m % a , a ) * m ) / a + m ; } static class Reader { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; StringTokenizer st ; String next ( ) { while ( st == null || ! st . hasMoreTokens ( ) ) { try { st = new StringTokenizer ( br . readLine ( ) ) ; } catch ( Exception e ) { } } return st . nextToken ( ) ; } int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } } }

import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; final int mod = ( ( int ) 1e9 ) + 7 ; int n = Integer . parseInt ( sc . next ( ) ) ; int [ ] a = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = Integer . parseInt ( sc . next ( ) ) ; } long k = 1 ; for ( int i = 1 ; i <= n ; i ++ ) { k *= i ; k %= mod ; } long [ ] r = new long [ n + 1 ] ; for ( int i = 1 ; i <= n ; i ++ ) { r [ i ] = ( r [ i - 1 ] + mod_pow ( i , mod - 2 , mod ) ) % mod ; } long res = 0L ; for ( int i = 0 ; i < n ; i ++ ) { res += ( r [ i + 1 ] + r [ n - i ] - r [ 1 ] ) * a [ i ] ; res %= mod ; } System . out . println ( res * k % mod ) ; } public static long mod_pow ( long x , long p , long m ) { long a = 1 ; while ( p > 0 ) { if ( p % 2 == 1 ) { a = a * x % m ; } x = x * x % m ; p /= 2 ; } return a ; } }

import java . util . * ; class Main { static long mod = 1000000007 ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; long [ ] a = new long [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = sc . nextLong ( ) ; } long [ ] b = new long [ n + 1 ] ; b [ 0 ] = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { b [ i ] = ( b [ i - 1 ] + pow ( i , mod - 2 ) ) % mod ; } long ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { ans += a [ i ] * ( b [ i + 1 ] + b [ n - i ] - 1 ) ; ans %= mod ; } for ( int i = 1 ; i <= n ; i ++ ) { ans *= i ; ans %= mod ; } System . out . println ( ans ) ; } static long pow ( long a , long p ) { if ( p == 0 ) return 1 ; else if ( p % 2 == 0 ) { long d = pow ( a , p / 2 ) ; return d * d % mod ; } else return pow ( a , p - 1 ) * a % mod ; } }

import java . util . * ; public class Main { public static void main ( String [ ] args ) { final long DIV = 1000000007 ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; long [ ] a = new long [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = sc . nextLong ( ) ; } sc . close ( ) ; long [ ] p = new long [ n ] ; long [ ] sump = new long [ n + 1 ] ; for ( int i = 0 ; i < n ; i ++ ) { p [ i ] = inverseElement ( i + 1 , DIV ) ; sump [ i + 1 ] = sump [ i ] + p [ i ] ; sump [ i + 1 ] %= DIV ; } long ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { ans += a [ i ] * ( sump [ i - 0 + 1 ] + sump [ n - i ] - p [ 0 ] ) ; if ( ans < 0 ) ans += DIV * DIV ; if ( ans > 0 ) ans %= DIV ; } for ( int i = 0 ; i < n ; i ++ ) { ans *= ( i + 1 ) ; ans %= DIV ; } System . out . println ( ans ) ; } public static long inverseElement ( long a , long n ) { long b = n , u = 1 , v = 0 ; while ( b > 0 ) { long t = a / b ; a -= t * b ; u -= t * v ; t = a ; a = b ; b = t ; t = u ; u = v ; v = t ; } u = u % n ; if ( u < 0 ) u += n ; return u ; } }

N = int ( input ( ) ) NEW_LINE A = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE mod = 10 ** 9 + 7 NEW_LINE F = 1 NEW_LINE for i in range ( 2 , N + 1 ) : NEW_LINE INDENT F = F * i % mod NEW_LINE DEDENT D = [ 0 ] NEW_LINE for i in range ( 2 , N + 1 ) : NEW_LINE INDENT D . append ( D [ - 1 ] + pow ( i , mod - 2 , mod ) ) NEW_LINE DEDENT L = [ 0 ] * N NEW_LINE for i in range ( N // 2 + N % 2 ) : NEW_LINE INDENT t = round ( F * ( D [ - 1 - i ] + D [ i ] + 1 ) ) % mod NEW_LINE L [ i ] = t NEW_LINE L [ - 1 - i ] = t NEW_LINE DEDENT Ans = 0 NEW_LINE for i in range ( N ) : NEW_LINE INDENT Ans += L [ i ] * A [ i ] % mod NEW_LINE DEDENT print ( Ans % mod ) NEW_LINE

import sys NEW_LINE fin = sys . stdin . readline NEW_LINE sys . setrecursionlimit ( 200000 ) NEW_LINE def factorial ( n , mod ) : NEW_LINE INDENT if n == 0 : NEW_LINE INDENT return 1 NEW_LINE DEDENT else : NEW_LINE INDENT return n * factorial ( n - 1 , mod ) % mod NEW_LINE DEDENT DEDENT MOD = 10 ** 9 + 7 NEW_LINE N = int ( fin ( ) ) NEW_LINE A_list = [ int ( elem ) for elem in fin ( ) . split ( ) ] NEW_LINE fac_N = factorial ( N , MOD ) NEW_LINE inv_nums = [ fac_N * pow ( i , MOD - 2 , MOD ) % MOD for i in range ( 1 , N + 1 ) ] NEW_LINE cuml_inv_nums = [ inv_nums [ 0 ] ] NEW_LINE for inv_num in inv_nums [ 1 : ] : NEW_LINE INDENT cuml_inv_nums . append ( ( cuml_inv_nums [ - 1 ] + inv_num ) % MOD ) NEW_LINE DEDENT ans = 0 NEW_LINE for i , A in enumerate ( A_list ) : NEW_LINE INDENT ans += A * ( cuml_inv_nums [ i ] + cuml_inv_nums [ N - 1 - i ] - cuml_inv_nums [ 0 ] ) % MOD NEW_LINE ans %= MOD NEW_LINE DEDENT print ( ans ) NEW_LINE

def power ( a , b ) : NEW_LINE INDENT if b == 0 : NEW_LINE INDENT return 1 NEW_LINE DEDENT elif b == 1 : NEW_LINE INDENT return a % 1000000007 NEW_LINE DEDENT elif b % 2 == 0 : NEW_LINE INDENT return ( power ( a , b // 2 ) ** 2 ) % 1000000007 NEW_LINE DEDENT else : NEW_LINE INDENT return ( power ( a , b // 2 ) ** 2 * a ) % 1000000007 NEW_LINE DEDENT DEDENT def divide ( a , b ) : NEW_LINE INDENT return ( a * power ( b , 1000000005 ) ) % 1000000007 NEW_LINE DEDENT N = int ( input ( ) ) NEW_LINE fac_lim = N NEW_LINE fac = [ None ] * ( fac_lim + 1 ) NEW_LINE fac [ 0 ] = 1 NEW_LINE for i in range ( fac_lim ) : NEW_LINE INDENT fac [ i + 1 ] = fac [ i ] * ( i + 1 ) NEW_LINE fac [ i + 1 ] = fac [ i + 1 ] % 1000000007 NEW_LINE DEDENT fs = [ 0 ] * ( N + 1 ) NEW_LINE fs [ 1 ] = fac [ N ] NEW_LINE for i in range ( 1 , N ) : NEW_LINE INDENT fs [ i + 1 ] = fs [ i ] + divide ( fs [ 1 ] , i + 1 ) NEW_LINE fs [ i + 1 ] %= 1000000007 NEW_LINE DEDENT A = [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE ans = 0 NEW_LINE for i in range ( N ) : NEW_LINE INDENT ans += ( fs [ i + 1 ] + fs [ N - i ] - fs [ 1 ] ) * A [ i ] NEW_LINE ans %= 1000000007 NEW_LINE DEDENT print ( ans ) NEW_LINE

def extgcd ( a , b ) : NEW_LINE INDENT r = [ 1 , 0 , a ] NEW_LINE w = [ 0 , 1 , b ] NEW_LINE while w [ 2 ] != 1 : NEW_LINE INDENT q = r [ 2 ] // w [ 2 ] NEW_LINE r2 = w NEW_LINE w2 = [ r [ 0 ] - q * w [ 0 ] , r [ 1 ] - q * w [ 1 ] , r [ 2 ] - q * w [ 2 ] ] NEW_LINE r = r2 NEW_LINE w = w2 NEW_LINE DEDENT return [ w [ 0 ] , w [ 1 ] ] NEW_LINE DEDENT def mod_inv ( a , m ) : NEW_LINE INDENT x = extgcd ( a , m ) [ 0 ] NEW_LINE return ( m + x % m ) % m NEW_LINE DEDENT n = int ( input ( ) ) NEW_LINE a = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE m = 10 ** 9 + 7 NEW_LINE r = [ 0 ] NEW_LINE w = 0 NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT w = ( w + mod_inv ( i , m ) ) % m NEW_LINE r . append ( w ) NEW_LINE DEDENT fact = 1 NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT fact = fact * i % m NEW_LINE DEDENT res = 0 NEW_LINE for j in range ( 1 , n + 1 ) : NEW_LINE INDENT sum_p = ( r [ j ] + r [ n - j + 1 ] - 1 ) % m NEW_LINE res = ( res + a [ j - 1 ] * sum_p * fact ) % m NEW_LINE DEDENT print ( res % m ) NEW_LINE

from math import factorial NEW_LINE MOD = 10 ** 9 + 7 NEW_LINE N = int ( input ( ) ) NEW_LINE A = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE invsum = [ 0 ] * ( N + 1 ) NEW_LINE for i in range ( 1 , N + 1 ) : NEW_LINE INDENT invsum [ i ] = ( invsum [ i - 1 ] + pow ( i , MOD - 2 , MOD ) ) % MOD NEW_LINE DEDENT ans = 0 NEW_LINE for i in range ( 1 , N + 1 ) : NEW_LINE INDENT ans += ( A [ i - 1 ] * ( invsum [ i ] + invsum [ N - i + 1 ] - 1 ) ) % MOD NEW_LINE DEDENT ans *= factorial ( N ) NEW_LINE print ( ans % MOD ) NEW_LINE


import java . util . stream . IntStream ; public class Main { private static java . util . Scanner scanner = new java . util . Scanner ( System . in ) ; private static int mod = 1000000007 ; public static void main ( String [ ] $ ) { int n = scanner . nextInt ( ) , a = scanner . nextInt ( ) - 1 , b = scanner . nextInt ( ) - 1 , m = scanner . nextInt ( ) , aa [ ] [ ] = new int [ n ] [ n ] , ba [ ] [ ] = new int [ n ] [ n ] , ca [ ] [ ] = new int [ n ] [ n ] ; for ( int i = 0 , l , r ; i < m ; i ++ ) aa [ l = scanner . nextInt ( ) - 1 ] [ r = scanner . nextInt ( ) - 1 ] = aa [ r ] [ l ] = ba [ l ] [ r ] = ba [ r ] [ l ] = 1 ; System . out . println ( IntStream . range ( 0 , n ) . reduce ( 0 , ( a1 , b1 ) -> { if ( ba [ a ] [ b ] != 0 ) return ba [ a ] [ b ] ; IntStream . range ( 0 , n ) . forEach ( i -> IntStream . range ( 0 , n ) . forEach ( j -> ca [ i ] [ j ] = IntStream . range ( 0 , n ) . map ( k -> ba [ i ] [ k ] * aa [ k ] [ j ] ) . sum ( ) % mod ) ) ; IntStream . range ( 0 , n ) . forEach ( i -> IntStream . range ( 0 , n ) . forEach ( j -> ba [ i ] [ j ] = ca [ i ] [ j ] ) ) ; return ba [ a ] [ b ] ; } ) ) ; } }

import java . util . * ; import java . awt . * ; import static java . lang . System . * ; import static java . lang . Math . * ; public class Main { public static void main ( String [ ] $ ) { Scanner sc = new Scanner ( in ) ; int N = sc . nextInt ( ) ; int a = sc . nextInt ( ) , b = sc . nextInt ( ) ; int M = sc . nextInt ( ) ; int mod = 1000000007 ; int [ ] min = new int [ N + 1 ] ; min [ a ] = 0 ; long [ ] count = new long [ N + 1 ] ; count [ a ] = 1 ; ArrayList < Integer > [ ] edge = new ArrayList [ N + 1 ] ; for ( int i = 1 ; i <= N ; i ++ ) edge [ i ] = new ArrayList < > ( ) ; for ( int i = 0 ; i < M ; i ++ ) { int x = sc . nextInt ( ) , y = sc . nextInt ( ) ; edge [ x ] . add ( y ) ; edge [ y ] . add ( x ) ; } Queue < Integer > q = new ArrayDeque < > ( ) ; q . add ( a ) ; Queue < Integer > dist = new ArrayDeque < > ( ) ; dist . add ( 0 ) ; while ( ! q . isEmpty ( ) ) { int vertex = q . poll ( ) ; int d = dist . poll ( ) ; for ( Integer child : edge [ vertex ] ) { if ( min [ child ] == 0 ) { q . add ( child ) ; dist . add ( d + 1 ) ; min [ child ] = d + 1 ; count [ child ] = count [ vertex ] ; } else if ( min [ child ] > d + 1 ) { min [ child ] = d + 1 ; count [ child ] = count [ vertex ] ; } else if ( min [ child ] == d + 1 ) { count [ child ] = ( count [ child ] + count [ vertex ] ) % mod ; } } } out . println ( count [ b ] ) ; } } Note : . / Main . java uses unchecked or unsafe operations . Note : Recompile with - Xlint : unchecked for details .

import java . util . * ; import java . awt . * ; import static java . lang . System . * ; import static java . lang . Math . * ; public class Main { public static void main ( String [ ] $ ) { Scanner sc = new Scanner ( in ) ; int N = sc . nextInt ( ) ; int a = sc . nextInt ( ) , b = sc . nextInt ( ) ; int M = sc . nextInt ( ) ; int mod = 1000000007 ; int [ ] node = new int [ N + 1 ] ; node [ a ] = 1 ; long [ ] count = new long [ N + 1 ] ; count [ a ] = 1 ; ArrayList < Integer > [ ] edge = new ArrayList [ N + 1 ] ; for ( int i = 1 ; i <= N ; i ++ ) edge [ i ] = new ArrayList < > ( ) ; for ( int i = 0 ; i < M ; i ++ ) { int x = sc . nextInt ( ) , y = sc . nextInt ( ) ; edge [ x ] . add ( y ) ; edge [ y ] . add ( x ) ; } Queue < Integer > q = new ArrayDeque < > ( ) ; q . add ( a ) ; Queue < Integer > dist = new ArrayDeque < > ( ) ; dist . add ( 0 ) ; while ( ! q . isEmpty ( ) ) { int vertex = q . poll ( ) ; int d = dist . poll ( ) ; for ( Integer child : edge [ vertex ] ) { if ( node [ child ] == 0 ) { q . add ( child ) ; dist . add ( d + 1 ) ; node [ child ] = d + 1 ; } if ( node [ child ] == d + 1 ) count [ child ] = ( count [ child ] + count [ vertex ] ) % mod ; } } out . println ( count [ b ] ) ; } } Note : . / Main . java uses unchecked or unsafe operations . Note : Recompile with - Xlint : unchecked for details .

import java . util . Scanner ; public class Main { static int N ; static int a ; static int b ; static int q = 1000000007 ; public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; N = scan . nextInt ( ) ; a = scan . nextInt ( ) - 1 ; b = scan . nextInt ( ) - 1 ; int M = scan . nextInt ( ) ; int [ ] [ ] A = new int [ N ] [ N ] ; int [ ] [ ] B = new int [ N ] [ N ] ; for ( int i = 0 ; i < M ; i ++ ) { int x = scan . nextInt ( ) - 1 ; int y = scan . nextInt ( ) - 1 ; A [ x ] [ y ] = 1 ; A [ y ] [ x ] = 1 ; B [ x ] [ y ] = 1 ; B [ y ] [ x ] = 1 ; } scan . close ( ) ; int [ ] [ ] C = new int [ N ] [ N ] ; for ( int l = 0 ; l < N ; l ++ ) { if ( B [ a ] [ b ] != 0 ) { System . out . println ( B [ a ] [ b ] ) ; System . exit ( 0 ) ; } for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) { int t = 0 ; for ( int k = 0 ; k < N ; k ++ ) { t += B [ i ] [ k ] * A [ k ] [ j ] ; } t = t % q ; C [ i ] [ j ] = t ; } } for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) { B [ i ] [ j ] = C [ i ] [ j ] ; } } } } }

import java . util . * ; public class Main { static int N ; static int M ; static int a , b ; static ArrayList < Integer > [ ] E ; static int INF = 1 << 30 ; static int MODP = 1000000007 ; public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; N = Integer . parseInt ( in . next ( ) ) ; a = Integer . parseInt ( in . next ( ) ) - 1 ; b = Integer . parseInt ( in . next ( ) ) - 1 ; M = Integer . parseInt ( in . next ( ) ) ; E = new ArrayList [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { E [ i ] = new ArrayList < > ( ) ; } for ( int i = 0 ; i < M ; i ++ ) { int x = Integer . parseInt ( in . next ( ) ) - 1 ; int y = Integer . parseInt ( in . next ( ) ) - 1 ; E [ x ] . add ( y ) ; E [ y ] . add ( x ) ; } long [ ] cost = new long [ N ] ; long [ ] count = new long [ N ] ; boolean [ ] visited = new boolean [ N ] ; Arrays . fill ( cost , INF ) ; Queue < Integer > q = new ArrayDeque < > ( ) ; q . add ( a ) ; cost [ a ] = 0 ; count [ a ] = 1 ; visited [ a ] = true ; while ( ! q . isEmpty ( ) ) { int st = q . remove ( ) ; for ( int adj : E [ st ] ) { if ( cost [ st ] + 1 <= cost [ adj ] ) { cost [ adj ] = cost [ st ] + 1 ; count [ adj ] += count [ st ] ; if ( ! visited [ adj ] ) { q . add ( adj ) ; } visited [ adj ] = true ; } } } System . out . println ( count [ b ] % MODP ) ; } } Note : . / Main . java uses unchecked or unsafe operations . Note : Recompile with - Xlint : unchecked for details .

from collections import deque NEW_LINE def main ( ) : NEW_LINE INDENT n = int ( input ( ) ) NEW_LINE a , b = map ( int , input ( ) . split ( ) ) NEW_LINE a -= 1 NEW_LINE b -= 1 NEW_LINE m = int ( input ( ) ) NEW_LINE adj_mat = [ [ False for j in range ( n ) ] for i in range ( n ) ] NEW_LINE for i in range ( m ) : NEW_LINE INDENT x , y = map ( int , input ( ) . split ( ) ) NEW_LINE adj_mat [ x - 1 ] [ y - 1 ] = True NEW_LINE adj_mat [ y - 1 ] [ x - 1 ] = True NEW_LINE DEDENT queued = [ False for i in range ( n ) ] NEW_LINE shortest_paths = [ 0 for i in range ( n ) ] NEW_LINE shortest_dist = [ 10 ** 9 for i in range ( n ) ] NEW_LINE q = deque ( [ a ] ) NEW_LINE queued [ a ] = True NEW_LINE shortest_paths [ a ] = 1 NEW_LINE shortest_dist [ a ] = 0 NEW_LINE while q : NEW_LINE INDENT st = q . popleft ( ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT if adj_mat [ st ] [ i ] : NEW_LINE INDENT if not queued [ i ] : NEW_LINE INDENT q . append ( i ) NEW_LINE queued [ i ] = True NEW_LINE DEDENT shortest_dist [ i ] = min ( shortest_dist [ i ] , shortest_dist [ st ] + 1 ) NEW_LINE if shortest_dist [ i ] == shortest_dist [ st ] + 1 : NEW_LINE INDENT shortest_paths [ i ] += shortest_paths [ st ] NEW_LINE shortest_paths [ i ] %= 10 ** 9 + 7 NEW_LINE DEDENT DEDENT DEDENT DEDENT print ( shortest_paths [ b ] ) NEW_LINE DEDENT main ( ) NEW_LINE

import numpy as np NEW_LINE N = int ( input ( ) ) NEW_LINE a , b = map ( int , input ( ) . split ( ) ) NEW_LINE M = int ( input ( ) ) NEW_LINE Adjacency = np . zeros ( [ N , N ] ) NEW_LINE for i in range ( M ) : NEW_LINE INDENT x , y = map ( int , input ( ) . split ( ) ) NEW_LINE Adjacency [ x - 1 , y - 1 ] = Adjacency [ y - 1 , x - 1 ] = 1 NEW_LINE DEDENT a , b = a - 1 , b - 1 NEW_LINE walk = np . zeros ( [ N , 1 ] ) NEW_LINE walk [ a ] = 1 NEW_LINE for i in range ( N ) : NEW_LINE INDENT walk = np . dot ( Adjacency , walk ) NEW_LINE if ( walk [ b ] != 0 ) : NEW_LINE INDENT print ( int ( walk [ b ] [ 0 ] % ( 1e9 + 7 ) ) ) NEW_LINE break NEW_LINE DEDENT DEDENT

import heapq NEW_LINE def dijkstra_heap ( s ) : NEW_LINE INDENT d = [ float ( " inf " ) ] * n NEW_LINE used = [ True ] * n NEW_LINE d [ s ] = 0 NEW_LINE used [ s ] = False NEW_LINE edgelist = [ ] NEW_LINE for e in edge [ s ] : NEW_LINE INDENT heapq . heappush ( edgelist , e ) NEW_LINE DEDENT while len ( edgelist ) : NEW_LINE INDENT minedge = heapq . heappop ( edgelist ) NEW_LINE if not used [ minedge [ 1 ] ] : NEW_LINE INDENT continue NEW_LINE DEDENT v = minedge [ 1 ] NEW_LINE d [ v ] = minedge [ 0 ] NEW_LINE used [ v ] = False NEW_LINE for e in edge [ v ] : NEW_LINE INDENT if used [ e [ 1 ] ] : NEW_LINE INDENT heapq . heappush ( edgelist , [ e [ 0 ] + d [ v ] , e [ 1 ] ] ) NEW_LINE DEDENT DEDENT DEDENT return d NEW_LINE DEDENT n = int ( input ( ) ) NEW_LINE a , b = map ( int , input ( ) . split ( ) ) NEW_LINE M = int ( input ( ) ) NEW_LINE edge = [ [ ] for i in range ( n ) ] NEW_LINE for i in range ( M ) : NEW_LINE INDENT x , y = map ( int , input ( ) . split ( ) ) NEW_LINE edge [ x - 1 ] . append ( [ 1 , y - 1 ] ) NEW_LINE edge [ y - 1 ] . append ( [ 1 , x - 1 ] ) NEW_LINE DEDENT L = [ ] NEW_LINE for i in range ( n ) : NEW_LINE INDENT D = dijkstra_heap ( i ) NEW_LINE L . append ( D ) NEW_LINE DEDENT dp = [ 0 ] * n NEW_LINE dp [ a - 1 ] = 1 NEW_LINE for i in range ( n ) : NEW_LINE INDENT for j in range ( n ) : NEW_LINE INDENT if L [ a - 1 ] [ j ] != i : NEW_LINE INDENT continue NEW_LINE DEDENT for k in range ( n ) : NEW_LINE INDENT if L [ a - 1 ] [ k ] == i + 1 and L [ j ] [ k ] == 1 : NEW_LINE INDENT dp [ k ] = ( dp [ k ] + dp [ j ] ) % ( 10 ** 9 + 7 ) NEW_LINE DEDENT DEDENT DEDENT DEDENT print ( dp [ b - 1 ] ) NEW_LINE

import sys NEW_LINE import heapq NEW_LINE input = sys . stdin . readline NEW_LINE inf = 10 ** 18 NEW_LINE N = int ( input ( ) ) NEW_LINE a , b = map ( int , input ( ) . split ( ) ) NEW_LINE M = int ( input ( ) ) NEW_LINE xy = [ list ( map ( int , input ( ) . split ( ) ) ) for i in range ( M ) ] NEW_LINE tab = [ [ ] for i in range ( N ) ] NEW_LINE for xi , yi in xy : NEW_LINE INDENT tab [ xi - 1 ] . append ( yi ) NEW_LINE tab [ yi - 1 ] . append ( xi ) NEW_LINE DEDENT d = [ ( 0 if i == a - 1 else inf ) for i in range ( N ) ] NEW_LINE prev = [ False ] * N NEW_LINE cnt = [ 0 ] * N NEW_LINE q = [ ] NEW_LINE heapq . heappush ( q , ( 0 , a ) ) NEW_LINE while len ( q ) > 0 : NEW_LINE INDENT cost , hi = heapq . heappop ( q ) NEW_LINE if cost >= d [ b - 1 ] : continue NEW_LINE for hj in tab [ hi - 1 ] : NEW_LINE INDENT if hj == prev [ hi - 1 ] : continue NEW_LINE alt = d [ hi - 1 ] + 1 NEW_LINE if alt < d [ hj - 1 ] : NEW_LINE INDENT d [ hj - 1 ] = alt NEW_LINE prev [ hj - 1 ] = hi NEW_LINE heapq . heappush ( q , ( alt , hj ) ) NEW_LINE DEDENT DEDENT DEDENT memo = [ [ None ] * ( d [ b - 1 ] + 1 ) for i in range ( N ) ] NEW_LINE def back ( pos , turn ) : NEW_LINE INDENT if pos == a : return 1 NEW_LINE if memo [ pos - 1 ] [ turn ] != None : return memo [ pos - 1 ] [ turn ] NEW_LINE ret = 0 NEW_LINE for src in tab [ pos - 1 ] : NEW_LINE INDENT if d [ src - 1 ] > turn - 1 : continue NEW_LINE ret += back ( src , turn - 1 ) NEW_LINE DEDENT ret = ret % ( 10 ** 9 + 7 ) NEW_LINE memo [ pos - 1 ] [ turn ] = ret NEW_LINE return ret NEW_LINE DEDENT print ( back ( b , d [ b - 1 ] ) ) NEW_LINE

from collections import deque NEW_LINE MOD = 10 ** 9 + 7 NEW_LINE N = int ( input ( ) ) NEW_LINE a , b = map ( lambda x : int ( x ) - 1 , input ( ) . split ( ) ) NEW_LINE M = int ( input ( ) ) NEW_LINE edges = [ [ ] for _ in range ( N ) ] NEW_LINE for _ in range ( M ) : NEW_LINE INDENT x , y = map ( lambda x : int ( x ) - 1 , input ( ) . split ( ) ) NEW_LINE edges [ x ] . append ( y ) NEW_LINE edges [ y ] . append ( x ) NEW_LINE DEDENT q = deque ( [ a ] ) NEW_LINE visited = [ False ] * N NEW_LINE visited [ a ] = True NEW_LINE depth = [ - 1 ] * N NEW_LINE depth [ a ] = 1 NEW_LINE cnts = [ 0 ] * N NEW_LINE cnts [ a ] = 1 NEW_LINE while q : NEW_LINE INDENT cur = q . popleft ( ) NEW_LINE for nex in edges [ cur ] : NEW_LINE INDENT if not visited [ nex ] : NEW_LINE INDENT q . append ( nex ) NEW_LINE visited [ nex ] = True NEW_LINE DEDENT if depth [ nex ] < 0 : NEW_LINE INDENT depth [ nex ] = depth [ cur ] + 1 NEW_LINE DEDENT if depth [ nex ] == depth [ cur ] + 1 : NEW_LINE INDENT cnts [ nex ] += cnts [ cur ] NEW_LINE cnts [ nex ] %= MOD NEW_LINE DEDENT DEDENT DEDENT print ( cnts [ b ] ) NEW_LINE NEW_LINE


import java . util . * ; public class Main { static long mod = 998244353 ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; long [ ] x = new long [ n ] , y = new long [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { x [ i ] = sc . nextLong ( ) ; y [ i ] = sc . nextLong ( ) ; } long res = modPow ( 2 , n , mod ) - 1 - n ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { int count = 0 ; for ( int k = 0 ; k < n ; k ++ ) { if ( ( ( x [ i ] - x [ k ] ) * ( y [ j ] - y [ k ] ) ) == ( ( x [ j ] - x [ k ] ) * ( y [ i ] - y [ k ] ) ) ) count ++ ; } long kumi = modPow ( 2 , count , mod ) - 1 - count ; kumi = kumi * inv ( count * ( count - 1 ) / 2 , mod ) % mod ; res = ( res - kumi + mod ) % mod ; } } System . out . println ( res ) ; } static long modPow ( long a , long b , long mod ) { long res = 1 ; long c = a ; while ( b > 0 ) { if ( b % 2 == 1 ) res = res * c % mod ; c = c * c % mod ; b /= 2 ; } return res ; } static long inv ( long a , long mod ) { long b = mod ; long p = 1 , q = 0 ; while ( b > 0 ) { long c = a / b ; long d = a ; a = b ; b = d % b ; d = p ; p = q ; q = d - c * q ; } return ( mod + p ) % mod ; } }

def gcd ( a , b ) : NEW_LINE INDENT if b == 0 : NEW_LINE INDENT return a NEW_LINE DEDENT return gcd ( b , a % b ) NEW_LINE DEDENT def inpl ( ) : return [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE from collections import defaultdict NEW_LINE H = defaultdict ( lambda : 0 ) NEW_LINE N = int ( input ( ) ) NEW_LINE dot = [ ( ) ] * N NEW_LINE mod = 998244353 NEW_LINE for i in range ( N ) : NEW_LINE INDENT x , y = inpl ( ) NEW_LINE dot [ i ] = ( x , y ) NEW_LINE DEDENT for i in range ( N ) : NEW_LINE INDENT for j in range ( i + 1 , N ) : NEW_LINE INDENT x1 , y1 = dot [ i ] NEW_LINE x2 , y2 = dot [ j ] NEW_LINE A = y1 - y2 NEW_LINE B = x2 - x1 NEW_LINE C = y1 * x2 - x1 * y2 NEW_LINE if A < 0 : NEW_LINE INDENT A *= - 1 NEW_LINE B *= - 1 NEW_LINE C *= - 1 NEW_LINE DEDENT gcdabc = gcd ( gcd ( A , B ) , C ) NEW_LINE A //= gcdabc NEW_LINE B //= gcdabc NEW_LINE C //= gcdabc NEW_LINE H [ ( A , B , C ) ] += 1 NEW_LINE DEDENT DEDENT ans = ( 2 ** N - N - 1 ) % mod NEW_LINE for i in H . values ( ) : NEW_LINE INDENT i = int ( ( 1 + ( 1 + 8 * i ) ** ( 1 / 2 ) ) / 2 ) NEW_LINE ans -= ( 2 ** i - i - 1 ) % mod NEW_LINE DEDENT print ( ans % mod ) NEW_LINE

def main ( ) : NEW_LINE INDENT N = int ( input ( ) ) NEW_LINE points = [ ] NEW_LINE for i in range ( N ) : NEW_LINE INDENT points . append ( list ( map ( int , input ( ) . split ( ) ) ) ) NEW_LINE DEDENT x = [ p [ 0 ] for p in points ] NEW_LINE y = [ p [ 1 ] for p in points ] NEW_LINE M = 998244353 NEW_LINE c = 1 + N + N * ( N - 1 ) // 2 NEW_LINE for i in range ( N ) : NEW_LINE INDENT xi = x [ i ] NEW_LINE yi = y [ i ] NEW_LINE dx = [ xj - xi for xj in x ] NEW_LINE dy = [ yj - yi for yj in y ] NEW_LINE for j in range ( i + 1 , N ) : NEW_LINE INDENT xj = dx [ j ] NEW_LINE yj = dy [ j ] NEW_LINE cc = 1 NEW_LINE for k in range ( j + 1 , N ) : NEW_LINE INDENT if xj * dy [ k ] - dx [ k ] * yj == 0 : NEW_LINE INDENT cc *= 2 NEW_LINE cc %= M NEW_LINE DEDENT DEDENT c += cc - 1 NEW_LINE DEDENT DEDENT r = 1 NEW_LINE for i in range ( N ) : NEW_LINE INDENT r *= 2 NEW_LINE r %= M NEW_LINE DEDENT r -= c NEW_LINE r %= M NEW_LINE print ( r ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT

from collections import Counter NEW_LINE from fractions import gcd NEW_LINE n = int ( input ( ) ) NEW_LINE xys = [ tuple ( map ( int , input ( ) . split ( ) ) ) for _ in range ( n ) ] NEW_LINE MOD = 998244353 NEW_LINE excludes = 0 NEW_LINE for i , ( x1 , y1 ) in enumerate ( xys ) : NEW_LINE INDENT slopes = [ ] NEW_LINE for x2 , y2 in xys [ i + 1 : ] : NEW_LINE INDENT dx , dy = x2 - x1 , y2 - y1 NEW_LINE if dx == 0 : NEW_LINE INDENT slopes . append ( 1j ) NEW_LINE DEDENT elif dy == 0 : NEW_LINE INDENT slopes . append ( 1 ) NEW_LINE DEDENT else : NEW_LINE INDENT m = gcd ( dx , dy ) NEW_LINE slopes . append ( dx // m + dy // m * 1j ) NEW_LINE DEDENT DEDENT for c in Counter ( slopes ) . values ( ) : NEW_LINE INDENT if c > 1 : NEW_LINE INDENT excludes += 2 ** c - c - 1 NEW_LINE DEDENT DEDENT excludes %= MOD NEW_LINE DEDENT print ( ( pow ( 2 , n , MOD ) - excludes - ( n * ( n - 1 ) // 2 ) - n - 1 ) % MOD ) NEW_LINE

from collections import Counter NEW_LINE if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT N = int ( input ( ) ) NEW_LINE xy_list = [ list ( map ( int , input ( ) . split ( ) ) ) for _ in range ( N ) ] NEW_LINE modulo_num = 998244353 NEW_LINE duplicate_list = [ 0 ] * ( N + 1 ) NEW_LINE for i in range ( N ) : NEW_LINE INDENT xi , yi = xy_list [ i ] NEW_LINE gradient_list = [ ] NEW_LINE for j in range ( N ) : NEW_LINE INDENT xj , yj = xy_list [ j ] NEW_LINE if xi != xj : NEW_LINE INDENT gradient_list . append ( ( yj - yi ) / ( xj - xi ) ) NEW_LINE DEDENT elif yi != yj : NEW_LINE INDENT gradient_list . append ( 100000 ) NEW_LINE DEDENT DEDENT counter = Counter ( gradient_list ) NEW_LINE for k in counter . values ( ) : NEW_LINE INDENT duplicate_list [ k + 1 ] += 1 NEW_LINE DEDENT DEDENT ans = pow ( 2 , N , modulo_num ) NEW_LINE ans -= 1 NEW_LINE ans -= N NEW_LINE for i in range ( 2 , N + 1 ) : NEW_LINE INDENT cnt = duplicate_list [ i ] // i NEW_LINE ans -= cnt * ( pow ( 2 , i , modulo_num ) - i - 1 ) NEW_LINE DEDENT ans = ans % modulo_num NEW_LINE print ( ans ) NEW_LINE DEDENT

N = int ( input ( ) ) NEW_LINE P = [ list ( map ( int , input ( ) . split ( ) ) ) for i in range ( N ) ] NEW_LINE MOD = 998244353 NEW_LINE ans = pow ( 2 , N , MOD ) - 1 - N NEW_LINE u = set ( ) NEW_LINE for i in range ( N ) : NEW_LINE INDENT xi , yi = P [ i ] NEW_LINE for j in range ( i + 1 , N ) : NEW_LINE INDENT xj , yj = P [ j ] NEW_LINE if ( i , j ) in u : NEW_LINE INDENT continue NEW_LINE DEDENT cnt = 0 NEW_LINE Q = { i , j } NEW_LINE for k in range ( N ) : NEW_LINE INDENT xk , yk = P [ k ] NEW_LINE if ( xj - xi ) * ( yk - yi ) == ( xk - xi ) * ( yj - yi ) : NEW_LINE INDENT cnt += 1 NEW_LINE Q . add ( k ) NEW_LINE DEDENT DEDENT for p in Q : NEW_LINE INDENT for q in Q : NEW_LINE INDENT u . add ( ( p , q ) ) NEW_LINE DEDENT DEDENT ans -= pow ( 2 , cnt , MOD ) - cnt - 1 NEW_LINE DEDENT DEDENT print ( ans % MOD ) NEW_LINE


import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String X = sc . next ( ) ; int ngs = X . length ( ) ; if ( ngs == 0 ) { System . out . println ( " YES " ) ; System . exit ( 0 ) ; } int cnt = 0 ; for ( cnt = 0 ; cnt < ngs ; cnt ++ ) { if ( X . charAt ( cnt ) == ' o ' || X . charAt ( cnt ) == ' k ' || X . charAt ( cnt ) == ' u ' ) { } else if ( X . charAt ( cnt ) == ' c ' ) { if ( X . charAt ( cnt + 1 ) == ' h ' ) { cnt ++ ; } else { System . out . println ( " NO " ) ; System . exit ( 0 ) ; } } else { System . out . println ( " NO " ) ; System . exit ( 0 ) ; } } System . out . println ( " YES " ) ; } }

import java . io . IOException ; import java . io . BufferedReader ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws IOException { try ( BufferedReader reader = new BufferedReader ( new InputStreamReader ( System . in ) ) ) { String s = reader . readLine ( ) ; int prelen = s . length ( ) ; boolean flg = true ; while ( 0 < s . length ( ) ) { s = s . replaceAll ( " ch $ " , " " ) ; s = s . replaceAll ( " o $ " , " " ) ; s = s . replaceAll ( " k $ " , " " ) ; s = s . replaceAll ( " u $ " , " " ) ; if ( prelen == s . length ( ) ) { flg = false ; break ; } prelen = s . length ( ) ; } System . out . println ( flg ? " YES " : " NO " ) ; } } }

import java . io . OutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . PrintWriter ; import java . util . InputMismatchException ; import java . io . IOException ; import java . io . InputStream ; public class Main { public static void main ( String [ ] args ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; FastScanner in = new FastScanner ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; TaskB solver = new TaskB ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class TaskB { public void solve ( int testNumber , FastScanner in , PrintWriter out ) { String s = in . next ( ) ; boolean isChoku = true ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { char cc = s . charAt ( i ) ; if ( cc == ' c ' && ++ i < s . length ( ) && s . charAt ( i ) == ' h ' ) continue ; if ( cc == ' o ' || cc == ' k ' || cc == ' u ' ) continue ; isChoku = false ; break ; } out . println ( isChoku ? " YES " : " NO " ) ; } } 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 ; this . bufPointer = 0 ; this . bufLength = 0 ; } 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 isPrintableChar ( int c ) { return c >= 33 && c <= 126 ; } public String next ( ) { StringBuilder sb = new StringBuilder ( ) ; int b = readByte ( ) ; while ( ! isPrintableChar ( b ) ) b = readByte ( ) ; while ( isPrintableChar ( b ) ) { sb . appendCodePoint ( b ) ; b = readByte ( ) ; } return sb . toString ( ) ; } } }

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 ) { String X = in . next ( ) ; String ans = " YES " ; for ( int i = 0 ; i < X . length ( ) ; i ++ ) { char tmp = X . charAt ( i ) ; if ( i != X . length ( ) - 1 && ( tmp == ' c ' && X . charAt ( i + 1 ) == ' h ' ) ) { } else if ( i != 0 && ( tmp == ' h ' && X . charAt ( i - 1 ) == ' c ' ) ) { } else if ( tmp == ' o ' || tmp == ' k ' || tmp == ' u ' ) { } else { ans = " NO " ; break ; } } out . println ( ans ) ; } } 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 long nextLong ( ) { return Long . parseLong ( next ( ) ) ; } public double nextDouble ( ) { return Double . parseDouble ( next ( ) ) ; } } }

import java . util . Scanner ; import java . util . ArrayList ; import java . util . List ; public class Main { public static boolean isChokugo ( String s ) { boolean res = true ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( s . charAt ( i ) == ' c ' && s . charAt ( i + 1 ) == ' h ' ) { i ++ ; } else if ( s . charAt ( i ) != ' o ' && s . charAt ( i ) != ' k ' && s . charAt ( i ) != ' u ' ) { res = false ; break ; } } return res ; } public static void main ( String args [ ] ) { Scanner scan = new Scanner ( System . in ) ; String x = scan . nextLine ( ) ; String ans = ( isChokugo ( x ) ) ? " YES " : " NO " ; System . out . println ( ans ) ; } }

X = input ( ) NEW_LINE X1 = X . split ( " ch " ) NEW_LINE X2 = " " . join ( X1 ) . split ( " o " ) NEW_LINE X3 = " " . join ( X2 ) . split ( " k " ) NEW_LINE X4 = " " . join ( X3 ) . split ( " u " ) NEW_LINE if len ( " " . join ( X4 ) ) == 0 : NEW_LINE INDENT print ( " YES " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " NO " ) NEW_LINE DEDENT

hoge = list ( input ( ) ) NEW_LINE flag = 0 NEW_LINE while 1 : NEW_LINE INDENT if ( len ( hoge ) == 0 and flag == 0 ) : NEW_LINE INDENT print ( " YES " ) NEW_LINE break NEW_LINE DEDENT elif ( len ( hoge ) == 0 and flag == 1 ) : NEW_LINE INDENT print ( " NO " ) NEW_LINE break NEW_LINE DEDENT elif ( hoge [ 0 ] == " o " or hoge [ 0 ] == " k " or hoge [ 0 ] == " u " ) : NEW_LINE INDENT hoge = hoge [ 1 : ] NEW_LINE DEDENT elif ( len ( hoge ) >= 2 ) : NEW_LINE INDENT if ( hoge [ 0 ] == " c " and hoge [ 1 ] == " h " ) : NEW_LINE INDENT hoge = hoge [ 2 : ] NEW_LINE DEDENT else : NEW_LINE INDENT flag = 1 NEW_LINE hoge = [ ] NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT flag = 1 NEW_LINE hoge = [ ] NEW_LINE DEDENT DEDENT

def judge_choku ( str ) : NEW_LINE INDENT isChoku = 1 NEW_LINE while isChoku : NEW_LINE INDENT if ( str == " " ) : NEW_LINE INDENT break NEW_LINE DEDENT elif ( str [ 0 ] == " o " or str [ 0 ] == " k " or str [ 0 ] == " u " ) : NEW_LINE INDENT str = str [ 1 : ] NEW_LINE judge_choku ( str ) NEW_LINE DEDENT elif ( str [ : 2 ] == " ch " ) : NEW_LINE INDENT str = str [ 2 : ] NEW_LINE judge_choku ( str ) NEW_LINE DEDENT else : NEW_LINE INDENT isChoku = 0 NEW_LINE DEDENT DEDENT return isChoku NEW_LINE DEDENT s = input ( ) NEW_LINE print ( " YES " if judge_choku ( s ) == 1 else " NO " ) NEW_LINE

print ( ' YES ' if input ( ) . replace ( ' ch ' , ' ' ) . replace ( ' o ' , ' ' ) . replace ( ' k ' , ' ' ) . replace ( ' u ' , ' ' ) == ' ' else ' NO ' ) NEW_LINE

choku = [ ' ch ' , ' o ' , ' k ' , ' u ' ] NEW_LINE s = input ( ) NEW_LINE def f ( i ) : NEW_LINE INDENT if i == len ( s ) : NEW_LINE INDENT return True NEW_LINE DEDENT elif s [ i ] in choku : NEW_LINE INDENT return f ( i + 1 ) NEW_LINE DEDENT elif s [ i : i + 2 ] in choku : NEW_LINE INDENT return f ( i + 2 ) NEW_LINE DEDENT else : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT print ( ' YES ' if f ( 0 ) else ' NO ' ) NEW_LINE


import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader input = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int n = Integer . parseInt ( input . readLine ( ) ) ; int [ ] positions = new int [ n + 1 ] ; int currentIndex = 1 ; for ( int i = 1 ; i <= n ; i ++ ) { positions [ i ] = Integer . parseInt ( input . readLine ( ) ) ; } int count = 0 ; while ( currentIndex != 2 && positions [ currentIndex ] > 0 ) { int copyCurrentIndex = currentIndex ; currentIndex = positions [ currentIndex ] ; positions [ copyCurrentIndex ] = - 1 ; count ++ ; } System . out . println ( currentIndex == 2 ? count : - 1 ) ; } }

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

import java . util . * ; class Main { static Scanner sc = new Scanner ( System . in ) ; static int mod = 1000000007 ; public static void main ( String [ ] args ) { int n = sc . nextInt ( ) ; Button [ ] buttons = new Button [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { buttons [ i ] = new Button ( sc . nextInt ( ) - 1 , false ) ; } buttons [ 0 ] . light = true ; int ans = - 1 ; int nowLight = 0 ; for ( int i = 0 ; i < n ; i ++ ) { buttons [ nowLight ] . light = false ; nowLight = buttons [ nowLight ] . Push ( ) ; buttons [ nowLight ] . light = true ; if ( nowLight == 1 ) { ans = i + 1 ; break ; } } System . out . println ( ans ) ; } } class Button { int num ; boolean light ; Button ( int n , boolean l ) { num = n ; light = l ; } int Push ( ) { return num ; } }

import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int totalButton = scanner . nextInt ( ) ; Integer [ ] buttonList = new Integer [ totalButton + 1 ] ; for ( int buttonNum = 0 ; buttonNum < totalButton ; buttonNum ++ ) { int temp = scanner . nextInt ( ) ; buttonList [ buttonNum + 1 ] = temp ; } int nowButton = 1 ; boolean flag = false ; int num ; for ( num = 0 ; num < totalButton ; num ++ ) { int temp = buttonList [ nowButton ] ; nowButton = temp ; if ( nowButton == 2 ) { flag = true ; num ++ ; break ; } } if ( flag == true ) { System . out . println ( num ) ; } else { System . out . println ( " - 1" ) ; } } }

import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; boolean [ ] n = new boolean [ N + 1 ] ; boolean isEnd = false ; for ( int i = 1 ; i <= N ; i ++ ) { n [ i ] = false ; } int [ ] a = new int [ N + 1 ] ; for ( int i = 1 ; i <= N ; i ++ ) { a [ i ] = sc . nextInt ( ) ; } sc . close ( ) ; int count = 0 ; int i = 1 ; while ( true ) { if ( n [ i ] == false ) { n [ i ] = true ; count ++ ; if ( a [ i ] == 2 ) { break ; } i = a [ i ] ; } else { count = - 1 ; break ; } } System . out . println ( count ) ; ; } }

n , * a = map ( int , open ( 0 ) ) ; c , s = 1 , a [ 0 ] NEW_LINE while s != 2 and c < n : c += 1 ; s = a [ s - 1 ] NEW_LINE print ( c * ( c < n ) or - 1 ) NEW_LINE

import sys NEW_LINE from collections import deque NEW_LINE def main ( ) : NEW_LINE INDENT input = sys . stdin . readline NEW_LINE N = int ( input ( ) ) NEW_LINE A = [ 0 ] + [ int ( input ( ) ) for _ in range ( N ) ] NEW_LINE cnt = 1 NEW_LINE pushed = set ( [ 1 ] ) NEW_LINE q = deque ( ) NEW_LINE q . append ( 1 ) NEW_LINE while len ( q ) > 0 : NEW_LINE INDENT a = q . popleft ( ) NEW_LINE b = A [ a ] NEW_LINE if b == 2 : NEW_LINE INDENT return cnt NEW_LINE DEDENT elif b in pushed : NEW_LINE INDENT return - 1 NEW_LINE DEDENT else : NEW_LINE INDENT pushed . add ( b ) NEW_LINE cnt += 1 NEW_LINE q . append ( b ) NEW_LINE DEDENT DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT print ( main ( ) ) NEW_LINE DEDENT

n = int ( input ( ) ) NEW_LINE a = [ int ( input ( ) ) for _ in range ( n ) ] NEW_LINE count = 0 NEW_LINE i = 0 NEW_LINE while count <= 10e+5 : NEW_LINE INDENT count += 1 NEW_LINE if a [ i ] == 2 : NEW_LINE INDENT print ( count ) NEW_LINE break NEW_LINE DEDENT else : NEW_LINE INDENT i = a [ i ] - 1 NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT print ( - 1 ) NEW_LINE DEDENT

import sys NEW_LINE ns = lambda : sys . stdin . readline ( ) . rstrip ( ) NEW_LINE ni = lambda : int ( ns ( ) ) NEW_LINE nm = lambda : map ( int , sys . stdin . readline ( ) . split ( ) ) NEW_LINE nl = lambda : list ( nm ( ) ) NEW_LINE n = ni ( ) NEW_LINE a = [ ni ( ) for _ in range ( n ) ] NEW_LINE count = 0 NEW_LINE nexti = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT if nexti == 1 : NEW_LINE INDENT print ( count ) NEW_LINE exit ( ) NEW_LINE DEDENT else : NEW_LINE INDENT nexti = a [ nexti ] - 1 NEW_LINE count += 1 NEW_LINE DEDENT DEDENT print ( - 1 ) NEW_LINE

N = int ( input ( ) ) NEW_LINE A = [ int ( input ( ) ) - 1 for _ in range ( N ) ] NEW_LINE result = [ False ] * N NEW_LINE k = 0 NEW_LINE while 1 : NEW_LINE INDENT newlight = A [ k ] NEW_LINE if k == 1 : NEW_LINE INDENT ans = 0 NEW_LINE break NEW_LINE DEDENT elif result [ k ] : NEW_LINE INDENT ans = 1 NEW_LINE break NEW_LINE DEDENT else : NEW_LINE INDENT result [ k ] = True NEW_LINE k = newlight NEW_LINE DEDENT DEDENT if ans : NEW_LINE INDENT print ( - 1 ) NEW_LINE DEDENT else : print ( sum ( result ) ) NEW_LINE


import java . util . * ; public class Main { int INF = Integer . MAX_VALUE ; public static void main ( String [ ] args ) { new Main ( ) . solve ( ) ; } void solve ( ) { Scanner sc = new Scanner ( System . in ) ; long N = sc . nextInt ( ) ; long A = sc . nextInt ( ) ; long B = sc . nextInt ( ) ; long C = sc . nextInt ( ) ; long D = sc . nextInt ( ) ; for ( int k = 0 ; k <= N ; k ++ ) { if ( ( ( k * C - ( N - 1 - k ) * D ) <= ( B - A ) ) && ( ( B - A ) <= ( k * D - ( N - 1 - k ) * C ) ) ) { System . out . println ( " YES " ) ; return ; } } System . out . println ( " NO " ) ; } }

import java . io . OutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . PrintWriter ; import java . io . UncheckedIOException ; import java . util . StringTokenizer ; import java . io . IOException ; import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . io . InputStream ; public class Main { public static void main ( String [ ] args ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; LightScanner in = new LightScanner ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; BModerateDifferences solver = new BModerateDifferences ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class BModerateDifferences { private static final String YES = " YES " ; private static final String NO = " NO " ; public void solve ( int testNumber , LightScanner in , PrintWriter out ) { int n = in . ints ( ) ; long a = in . longs ( ) , b = in . longs ( ) , c = in . longs ( ) , d = in . longs ( ) ; for ( int i = 0 ; i < n ; i ++ ) { long max = a + d * i - c * ( n - 1 - i ) ; long min = a + c * i - d * ( n - 1 - i ) ; if ( min <= b && b <= max ) { out . println ( YES ) ; return ; } } out . println ( NO ) ; } } static class LightScanner { private BufferedReader reader = null ; private StringTokenizer tokenizer = null ; public LightScanner ( InputStream in ) { reader = new BufferedReader ( new InputStreamReader ( in ) ) ; } public String string ( ) { if ( tokenizer == null || ! tokenizer . hasMoreTokens ( ) ) { try { tokenizer = new StringTokenizer ( reader . readLine ( ) ) ; } catch ( IOException e ) { throw new UncheckedIOException ( e ) ; } } return tokenizer . nextToken ( ) ; } public int ints ( ) { return Integer . parseInt ( string ( ) ) ; } public long longs ( ) { return Long . parseLong ( string ( ) ) ; } } }

import java . util . * ; public class Main { public void main ( Scanner sc ) { long n = sc . nextLong ( ) ; long a = sc . nextLong ( ) ; long b = sc . nextLong ( ) ; long c = sc . nextLong ( ) ; long d = sc . nextLong ( ) ; long dur = a - b ; for ( int up = 0 ; up < n - 1 ; up ++ ) { long max = d * up - c * ( n - 1 - up ) ; long min = c * up - d * ( n - 1 - up ) ; if ( min <= dur && dur <= max ) { System . out . println ( " YES " ) ; return ; } } System . out . println ( " NO " ) ; } public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; new Main ( ) . main ( sc ) ; sc . close ( ) ; } }

import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; long a = sc . nextInt ( ) ; long b = sc . nextInt ( ) ; long c = sc . nextInt ( ) ; long d = sc . nextInt ( ) ; boolean bl = false ; for ( int i = 0 ; i < n ; i ++ ) { if ( a + c * i - d * ( n - i - 1 ) <= b && b <= a + d * i - c * ( n - i - 1 ) ) { bl = true ; } } String ans = ( bl == true ) ? " YES " : " NO " ; System . out . println ( ans ) ; } }

import java . util . * ; import java . io . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; long A = sc . nextLong ( ) ; long B = sc . nextLong ( ) ; long C = sc . nextLong ( ) ; long D = sc . nextLong ( ) ; for ( int plus = 0 ; plus < N ; plus ++ ) { int minus = ( N - 1 ) - plus ; long max = A + D * plus - C * minus ; long min = A + C * plus - D * minus ; if ( min <= B && B <= max ) { System . out . println ( " YES " ) ; return ; } } System . out . println ( " NO " ) ; } }

import sys NEW_LINE stdin = sys . stdin NEW_LINE sys . setrecursionlimit ( 10 ** 5 ) NEW_LINE def li ( ) : return map ( int , stdin . readline ( ) . split ( ) ) NEW_LINE def li_ ( ) : return map ( lambda x : int ( x ) - 1 , stdin . readline ( ) . split ( ) ) NEW_LINE def lf ( ) : return map ( float , stdin . readline ( ) . split ( ) ) NEW_LINE def ls ( ) : return stdin . readline ( ) . split ( ) NEW_LINE def ns ( ) : return stdin . readline ( ) . rstrip ( ) NEW_LINE def lc ( ) : return list ( ns ( ) ) NEW_LINE def ni ( ) : return int ( stdin . readline ( ) ) NEW_LINE def nf ( ) : return float ( stdin . readline ( ) ) NEW_LINE n , a , b , c , d = li ( ) NEW_LINE exist = False NEW_LINE for m in range ( n - 1 ) : NEW_LINE INDENT if - d * m + c * ( n - 1 - m ) <= b - a <= - c * m + d * ( n - 1 - m ) : NEW_LINE INDENT exist = True NEW_LINE DEDENT DEDENT if exist : NEW_LINE INDENT print ( " YES " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " NO " ) NEW_LINE DEDENT

import sys , collections , itertools NEW_LINE def solve ( ) : NEW_LINE INDENT N , A , B , C , D = map ( int , input ( ) . split ( ) ) NEW_LINE chkL = [ B + D , B + C , B - C , B - D ] NEW_LINE for i in range ( N - 2 ) : NEW_LINE INDENT min_v = C * ( N - 2 - i ) - D * i + A NEW_LINE max_v = D * ( N - 2 - i ) - C * i + A NEW_LINE for v in chkL : NEW_LINE INDENT if ( min_v <= v and v <= max_v ) : NEW_LINE INDENT print ( " YES " ) NEW_LINE return NEW_LINE DEDENT DEDENT DEDENT print ( " NO " ) NEW_LINE DEDENT solve ( ) NEW_LINE

def inpl ( ) : return [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE N , A , B , C , D = inpl ( ) NEW_LINE for k in range ( N + 1 ) : NEW_LINE INDENT j = N - 1 - k NEW_LINE if D * k - C * j >= B - A >= C * k - D * j : NEW_LINE INDENT print ( ' YES ' ) NEW_LINE break NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT print ( ' NO ' ) NEW_LINE DEDENT

n , a , b , c , d = map ( int , input ( ) . split ( ) ) NEW_LINE diff_ab = abs ( b - a ) NEW_LINE diff_cd = d - c NEW_LINE mod = c + d NEW_LINE mod_ab = diff_ab % mod NEW_LINE MAX = d * ( n - 1 ) NEW_LINE MAX_mod = MAX % mod NEW_LINE MIN_mod = ( c * ( n - 1 ) ) % mod NEW_LINE if MAX >= diff_ab : NEW_LINE INDENT if diff_cd * ( n - 1 ) + 1 >= mod : NEW_LINE INDENT print ( " YES " ) NEW_LINE DEDENT else : NEW_LINE INDENT if MAX_mod >= MIN_mod : NEW_LINE INDENT if mod_ab <= MAX_mod and mod_ab >= MIN_mod : NEW_LINE INDENT print ( " YES " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " NO " ) NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT if mod_ab >= MIN_mod or mod_ab <= MAX_mod : NEW_LINE INDENT print ( " YES " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " NO " ) NEW_LINE DEDENT DEDENT DEDENT DEDENT else : NEW_LINE INDENT print ( " NO " ) NEW_LINE DEDENT

import math NEW_LINE def solve ( ) : NEW_LINE INDENT n , a , b , c , d = ( int ( i ) for i in input ( ) . split ( ) ) NEW_LINE if a > b : a , b = b , a NEW_LINE ans = ' NO ' NEW_LINE for i in range ( n ) : NEW_LINE INDENT if a + i * c - ( n - i - 1 ) * d <= b <= a + i * d - ( n - i - 1 ) * c : NEW_LINE INDENT ans = ' YES ' NEW_LINE DEDENT DEDENT return ans NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT print ( solve ( ) ) NEW_LINE DEDENT


import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; System . out . println ( n - 1 ) ; } }

import java . util . * ; import java . util . stream . * ; import static java . lang . System . * ; class Main { static Scanner sc = new Scanner ( System . in ) ; static int nextInt ( ) { return Integer . parseInt ( sc . next ( ) ) ; } static int [ ] nextIntArray ( int n ) { return IntStream . range ( 0 , n ) . map ( i -> nextInt ( ) ) . toArray ( ) ; } static int max ( int ... ar ) { Arrays . sort ( ar ) ; return ar [ ar . length - 1 ] ; } static int min ( int ... ar ) { Arrays . sort ( ar ) ; return ar [ 0 ] ; } static int maxInt = Integer . MAX_VALUE ; static int minInt = Integer . MIN_VALUE ; public static void main ( String [ ] args ) { out . println ( nextInt ( ) - 1 ) ; } }

import java . io . * ; import java . util . * ; public class Main { public static void main ( String [ ] args ) { try { Scanner sc = new Scanner ( System . in ) ; int n ; n = Integer . parseInt ( sc . next ( ) ) ; System . out . println ( n - 1 ) ; } catch ( Exception e ) { System . out . println ( " out " ) ; } } }

import java . util . * ; import java . util . List ; import java . util . ArrayList ; import java . math . * ; class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int N = scanner . nextInt ( ) ; System . out . println ( N - 1 ) ; } }

import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String a = sc . nextLine ( ) ; int ans = Integer . parseInt ( Integer . toBinaryString ( Integer . parseInt ( a ) ) , 2 ) - 1 ; System . out . println ( " " + " " + " " + " " + " " + " " + " " + " " + ans ) ; } }

print ( int ( input ( ) ) - 1 ) NEW_LINE

import numpy as np NEW_LINE class Calculator : NEW_LINE INDENT def __init__ ( self ) : NEW_LINE INDENT pass NEW_LINE DEDENT def set_num ( self , N ) : NEW_LINE INDENT self . num = 0 NEW_LINE self . N = N NEW_LINE DEDENT def calc ( self ) : NEW_LINE INDENT self . num = self . N - 1 ; NEW_LINE DEDENT def get_num ( self ) : NEW_LINE INDENT return self . num NEW_LINE DEDENT DEDENT def main ( ) : NEW_LINE INDENT N , = map ( int , input ( ) . split ( ) ) NEW_LINE c = Calculator ( ) NEW_LINE c . set_num ( N ) NEW_LINE c . calc ( ) NEW_LINE ans = c . get_num ( ) NEW_LINE print ( ans ) NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT main ( ) NEW_LINE DEDENT

n = int ( input ( ) ) NEW_LINE print ( n - 1 ) if n != 0 else print ( 0 ) NEW_LINE

from sys import stdin NEW_LINE print ( int ( stdin . readline ( ) . rstrip ( ) ) - 1 ) NEW_LINE

N = int ( input ( ) ) NEW_LINE print ( N - 1 ) NEW_LINE


import java . util . * ; public class Main { public static void main ( String ... args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int m = sc . nextInt ( ) ; int [ ] [ ] times = new int [ n ] [ n ] ; for ( int i = 0 ; i < m ; i ++ ) { int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int t = sc . nextInt ( ) ; times [ a - 1 ] [ b - 1 ] = t ; times [ b - 1 ] [ a - 1 ] = t ; } for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { if ( i != j && times [ i ] [ j ] == 0 ) { times [ i ] [ j ] = 1000000 ; times [ j ] [ i ] = 1000000 ; } } } for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { for ( int k = 0 ; k < n ; k ++ ) { times [ j ] [ k ] = Math . min ( times [ j ] [ k ] , times [ j ] [ i ] + times [ i ] [ k ] ) ; times [ k ] [ j ] = times [ j ] [ k ] ; } } } int min = Integer . MAX_VALUE ; for ( int i = 0 ; i < n ; i ++ ) { int tmpmin = 0 ; for ( int j = 0 ; j < n ; j ++ ) { if ( i != j ) tmpmin = Math . max ( tmpmin , times [ i ] [ j ] ) ; } min = Math . min ( tmpmin , min ) ; } System . out . println ( min ) ; } }

import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] [ ] dist = new int [ n ] [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { Arrays . fill ( dist [ i ] , Integer . MAX_VALUE / 3 ) ; dist [ i ] [ i ] = 0 ; } int m = sc . nextInt ( ) ; for ( int i = 0 ; i < m ; i ++ ) { int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int t = sc . nextInt ( ) ; dist [ a - 1 ] [ b - 1 ] = t ; dist [ b - 1 ] [ a - 1 ] = t ; } for ( int k = 0 ; k < n ; k ++ ) { for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { dist [ i ] [ j ] = Math . min ( dist [ i ] [ j ] , dist [ i ] [ k ] + dist [ k ] [ j ] ) ; dist [ j ] [ i ] = dist [ i ] [ j ] ; } } } int min = Integer . MAX_VALUE ; for ( int i = 0 ; i < n ; i ++ ) { int max = 0 ; for ( int j = 0 ; j < n ; j ++ ) { if ( max < dist [ i ] [ j ] ) { max = dist [ i ] [ j ] ; } } if ( min > max ) { min = max ; } } System . out . println ( min ) ; } }

import java . io . OutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . PrintWriter ; import java . util . stream . IntStream ; import java . util . Arrays ; import java . util . Scanner ; import java . util . OptionalInt ; public class Main { public static void main ( String [ ] args ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; Scanner in = new Scanner ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; D solver = new D ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class D { public void solve ( int testNumber , Scanner in , PrintWriter out ) { int n = in . nextInt ( ) , m = in . nextInt ( ) ; int [ ] [ ] dist = new int [ n ] [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { Arrays . fill ( dist [ i ] , 1000000000 ) ; dist [ i ] [ i ] = 0 ; } for ( int i = 0 ; i < m ; i ++ ) { int a = in . nextInt ( ) - 1 , b = in . nextInt ( ) - 1 , t = in . nextInt ( ) ; dist [ a ] [ b ] = t ; dist [ b ] [ a ] = t ; } for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { for ( int k = 0 ; k < n ; k ++ ) { dist [ j ] [ k ] = Math . min ( dist [ j ] [ k ] , dist [ j ] [ i ] + dist [ i ] [ k ] ) ; } } } int ans = Integer . MAX_VALUE ; for ( int i = 0 ; i < n ; i ++ ) { ans = Math . min ( ans , IntStream . of ( dist [ i ] ) . max ( ) . orElse ( Integer . MAX_VALUE ) ) ; } out . println ( ans ) ; } } }

import java . util . Scanner ; public class Main { static int [ ] [ ] map ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int m = sc . nextInt ( ) ; map = new int [ n ] [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { if ( i != j ) { map [ i ] [ j ] = 1 << 29 ; } } } for ( int i = 0 ; i < m ; i ++ ) { int a = sc . nextInt ( ) - 1 ; int b = sc . nextInt ( ) - 1 ; int t = sc . nextInt ( ) ; map [ a ] [ b ] = t ; map [ b ] [ a ] = t ; } for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { for ( int k = j + 1 ; k < n ; k ++ ) { int a = Math . min ( map [ j ] [ k ] , map [ j ] [ i ] + map [ i ] [ k ] ) ; map [ j ] [ k ] = a ; map [ k ] [ j ] = a ; } } } int min = 1 << 29 ; for ( int i = 0 ; i < n ; i ++ ) { int max = 0 ; for ( int j = 0 ; j < n ; j ++ ) { max = Math . max ( max , map [ i ] [ j ] ) ; } if ( min > max ) { min = max ; } } System . out . println ( min ) ; } }

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 ( ) ; final int INF = 1_000_000_000 ; int [ ] [ ] d = new int [ n ] [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { if ( i != j ) { d [ i ] [ j ] = INF ; } } } for ( int i = 0 ; i < m ; i ++ ) { int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int t = sc . nextInt ( ) ; d [ a - 1 ] [ b - 1 ] = t ; d [ b - 1 ] [ a - 1 ] = t ; } for ( int k = 0 ; k < n ; k ++ ) { for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { if ( d [ i ] [ j ] > d [ i ] [ k ] + d [ k ] [ j ] ) { d [ i ] [ j ] = d [ i ] [ k ] + d [ k ] [ j ] ; } } } } int ans = INF ; for ( int i = 0 ; i < n ; i ++ ) { int max = 0 ; for ( int j = 0 ; j < n ; j ++ ) { max = Math . max ( max , d [ i ] [ j ] ) ; } ans = Math . min ( ans , max ) ; } System . out . println ( ans ) ; } }

import sys NEW_LINE stdin = sys . stdin NEW_LINE sys . setrecursionlimit ( 10 ** 5 ) NEW_LINE def li ( ) : return map ( int , stdin . readline ( ) . split ( ) ) NEW_LINE def li_ ( ) : return map ( lambda x : int ( x ) - 1 , stdin . readline ( ) . split ( ) ) NEW_LINE def lf ( ) : return map ( float , stdin . readline ( ) . split ( ) ) NEW_LINE def ls ( ) : return stdin . readline ( ) . split ( ) NEW_LINE def ns ( ) : return stdin . readline ( ) . rstrip ( ) NEW_LINE def lc ( ) : return list ( ns ( ) ) NEW_LINE def ni ( ) : return int ( stdin . readline ( ) ) NEW_LINE def nf ( ) : return float ( stdin . readline ( ) ) NEW_LINE import numpy as np NEW_LINE from scipy . sparse . csgraph import floyd_warshall NEW_LINE n , m = li ( ) NEW_LINE graph = np . inf * np . ones ( ( n , n ) ) NEW_LINE for i in range ( m ) : NEW_LINE INDENT a , b , t = li ( ) NEW_LINE graph [ a - 1 ] [ b - 1 ] = t NEW_LINE graph [ b - 1 ] [ a - 1 ] = t NEW_LINE DEDENT dist = floyd_warshall ( graph , directed = False ) NEW_LINE ans = 10 ** 18 NEW_LINE for i in range ( n ) : NEW_LINE INDENT ans = min ( ans , max ( dist [ i ] ) ) NEW_LINE DEDENT print ( int ( ans ) ) NEW_LINE

from scipy . sparse import * ; f = lambda * z : map ( int , input ( ) . split ( ) ) ; N , M = f ( ) ; a , b , c = zip ( * map ( f , [ 0 ] * M ) ) ; l = csgraph . dijkstra ( csr_matrix ( ( c , ( a , b ) ) , [ N + 1 ] * 2 ) , 0 ) ; print ( int ( min ( max ( i [ 1 : ] ) for i in l ) ) ) NEW_LINE

import sys NEW_LINE def   ? ( ) : NEW_LINE INDENT input = sys . stdin . readline NEW_LINE N , M = [ int ( _ ) for _ in input ( ) . split ( ) ] NEW_LINE aB = [ list ( map ( int , input ( ) . split ( ) ) ) for i in range ( M ) ] NEW_LINE dT = { } NEW_LINE def addData ( dT : dict , a : int , b : int , t : int ) : NEW_LINE INDENT if a in dT : NEW_LINE INDENT dT [ a ] [ b ] = t NEW_LINE DEDENT else : NEW_LINE INDENT dT [ a ] = { b : t } NEW_LINE DEDENT DEDENT for a , b , t in aB : NEW_LINE INDENT addData ( dT , a , b , t ) NEW_LINE addData ( dT , b , a , t ) NEW_LINE DEDENT for k in range ( 1 , N + 1 ) : NEW_LINE INDENT aK = dT [ k ] . keys ( ) NEW_LINE for i in aK : NEW_LINE INDENT dI = dT [ i ] NEW_LINE dK = dT [ k ] NEW_LINE iRK = dI [ k ] NEW_LINE for j in aK : NEW_LINE INDENT iR = iRK + dK [ j ] NEW_LINE if j in dI : NEW_LINE INDENT if dI [ j ] > iR : NEW_LINE INDENT dI [ j ] = iR NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT dI [ j ] = iR NEW_LINE DEDENT DEDENT DEDENT DEDENT iAns = float ( " inf " ) NEW_LINE for i , dD in dT . items ( ) : NEW_LINE INDENT iD = 0 NEW_LINE for j , v in dD . items ( ) : NEW_LINE INDENT if i == j : NEW_LINE INDENT continue NEW_LINE DEDENT if v > iD : NEW_LINE INDENT iD = v NEW_LINE DEDENT DEDENT if iAns > iD : NEW_LINE INDENT iAns = iD NEW_LINE DEDENT DEDENT print ( iAns ) NEW_LINE DEDENT ? ( ) NEW_LINE

def warshall_floyd ( v_count : int , matrix : list ) -> list : NEW_LINE INDENT for i in range ( v_count ) : NEW_LINE INDENT for j , c2 in enumerate ( row [ i ] for row in matrix ) : NEW_LINE INDENT for k , ( c1 , c3 ) in enumerate ( zip ( matrix [ j ] , matrix [ i ] ) ) : NEW_LINE INDENT if c1 > c2 + c3 : NEW_LINE INDENT matrix [ j ] [ k ] = c2 + c3 NEW_LINE DEDENT DEDENT DEDENT DEDENT return matrix NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT import sys NEW_LINE N , M = map ( int , input ( ) . split ( ) ) NEW_LINE inf = float ( " inf " ) NEW_LINE matrix = [ [ inf ] * N for _ in [ 0 ] * N ] NEW_LINE for i in range ( N ) : NEW_LINE INDENT matrix [ i ] [ i ] = 0 NEW_LINE DEDENT for a , b , t in ( map ( int , l . split ( ) ) for l in sys . stdin ) : NEW_LINE INDENT matrix [ a - 1 ] [ b - 1 ] = matrix [ b - 1 ] [ a - 1 ] = t NEW_LINE DEDENT matrix = warshall_floyd ( N , matrix ) NEW_LINE print ( min ( max ( row ) for row in matrix ) ) NEW_LINE DEDENT

from scipy . sparse . csgraph import floyd_warshall NEW_LINE from scipy . sparse . csgraph import dijkstra NEW_LINE n , m = map ( int , input ( ) . split ( ) ) NEW_LINE dis = [ [ float ( ' inf ' ) for i in range ( n ) ] for j in range ( n ) ] NEW_LINE for i in range ( n ) : NEW_LINE INDENT dis [ i ] [ i ] = 0 NEW_LINE DEDENT for i in range ( m ) : NEW_LINE INDENT a , b , t = map ( int , input ( ) . split ( ) ) NEW_LINE dis [ a - 1 ] [ b - 1 ] = t NEW_LINE dis [ b - 1 ] [ a - 1 ] = t NEW_LINE DEDENT cost = dijkstra ( dis ) NEW_LINE ans = [ max ( cost [ i ] ) for i in range ( n ) ] NEW_LINE print ( int ( min ( ans ) ) ) NEW_LINE


import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { final Scanner sc = new Scanner ( System . in ) ; int h = sc . nextInt ( ) , w = sc . nextInt ( ) ; char [ ] [ ] map = new char [ h ] [ w ] ; for ( int i = 0 ; i < h ; i ++ ) { map [ i ] = sc . next ( ) . toCharArray ( ) ; } char [ ] [ ] red = new char [ h ] [ w ] ; char [ ] [ ] blue = new char [ h ] [ w ] ; for ( int i = 0 ; i < h ; i ++ ) { for ( int j = 0 ; j < w ; j ++ ) { if ( map [ i ] [ j ] == ' # ' ) { red [ i ] [ j ] = blue [ i ] [ j ] = ' # ' ; continue ; } if ( ( i % 2 == 0 && j != w - 1 ) || ( i % 2 == 1 && j == 0 ) ) { red [ i ] [ j ] = ' # ' ; blue [ i ] [ j ] = ' . ' ; } else { red [ i ] [ j ] = ' . ' ; blue [ i ] [ j ] = ' # ' ; } } } printArr ( red ) ; System . out . println ( ) ; printArr ( blue ) ; } static void printArr ( char [ ] [ ] arr ) { for ( char [ ] chars : arr ) { for ( char c : chars ) { System . out . print ( c ) ; } System . out . println ( ) ; } } }

import java . util . * ; class Main { public static void puts ( char [ ] [ ] str ) { for ( int i = 0 ; i < str . length ; i ++ ) { for ( int j = 0 ; j < str [ i ] . length ; j ++ ) { System . out . print ( str [ i ] [ j ] ) ; } System . out . print ( ' \n ' ) ; } return ; } public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int h = sc . nextInt ( ) ; int w = sc . nextInt ( ) ; char [ ] [ ] a = new char [ h ] [ w ] ; for ( int i = 0 ; i < h ; i ++ ) { a [ i ] = ( sc . next ( ) ) . toCharArray ( ) ; } char [ ] [ ] b = new char [ h ] [ w ] ; char [ ] [ ] r = new char [ h ] [ w ] ; for ( int i = 0 ; i < h ; i ++ ) { for ( int j = 0 ; j < w ; j ++ ) { if ( j == 0 ) { b [ i ] [ j ] = ' # ' ; r [ i ] [ j ] = ' . ' ; } else if ( j == w - 1 ) { b [ i ] [ j ] = ' . ' ; r [ i ] [ j ] = ' # ' ; } else { if ( i % 2 == 0 ) { b [ i ] [ j ] = ' . ' ; r [ i ] [ j ] = ' # ' ; } else { b [ i ] [ j ] = ' # ' ; r [ i ] [ j ] = ' . ' ; } } } } for ( int i = 0 ; i < h ; i ++ ) { for ( int j = 0 ; j < w ; j ++ ) { if ( a [ i ] [ j ] == ' # ' ) { r [ i ] [ j ] = ' # ' ; b [ i ] [ j ] = ' # ' ; } } } puts ( b ) ; puts ( r ) ; return ; } }

import java . util . * ; public class Main { int H , W ; boolean [ ] [ ] rg , bg , pg ; void run ( ) { Scanner sc = new Scanner ( System . in ) ; H = sc . nextInt ( ) ; W = sc . nextInt ( ) ; rg = new boolean [ H ] [ W ] ; bg = new boolean [ H ] [ W ] ; pg = new boolean [ H ] [ W ] ; for ( int h = 0 ; h < H ; h ++ ) { if ( h % 2 == 0 ) { for ( int w = 0 ; w < W ; w ++ ) rg [ h ] [ w ] = true ; } else { for ( int w = 0 ; w < W ; w ++ ) bg [ h ] [ w ] = true ; } bg [ h ] [ W - 1 ] = rg [ h ] [ 0 ] = true ; rg [ h ] [ W - 1 ] = bg [ h ] [ 0 ] = false ; } for ( int h = 0 ; h < H ; h ++ ) { String l = sc . next ( ) ; for ( int w = 0 ; w < W ; w ++ ) { if ( l . charAt ( w ) == ' # ' ) bg [ h ] [ w ] = rg [ h ] [ w ] = true ; pg [ h ] [ w ] = bg [ h ] [ w ] & rg [ h ] [ w ] ; } } printBoard ( rg ) ; System . out . println ( ) ; printBoard ( bg ) ; } void printBoard ( boolean [ ] [ ] b ) { for ( int h = 0 ; h < H ; h ++ ) { for ( int w = 0 ; w < W ; w ++ ) System . out . print ( b [ h ] [ w ] ? ' # ' : ' . ' ) ; System . out . println ( ) ; } } void debug ( Object ... os ) { System . err . println ( Arrays . deepToString ( os ) ) ; } public static void main ( String [ ] args ) { new Main ( ) . run ( ) ; } }

import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { try ( Scanner in = new Scanner ( System . in ) ) { new Main ( ) . solve ( in ) ; } } private void solve ( Scanner in ) { int H = in . nextInt ( ) , W = in . nextInt ( ) ; char [ ] [ ] a = new char [ H ] [ W ] ; for ( int i = 0 ; i < H ; i ++ ) { a [ i ] = in . next ( ) . toCharArray ( ) ; } char [ ] [ ] r = new char [ H ] [ W ] ; char [ ] [ ] b = new char [ H ] [ W ] ; for ( int i = 0 ; i < H ; i ++ ) { Arrays . fill ( r [ i ] , DOT ) ; Arrays . fill ( b [ i ] , DOT ) ; r [ i ] [ 0 ] = SHA ; b [ i ] [ W - 1 ] = SHA ; for ( int j = 1 ; j < W - 1 ; j ++ ) { r [ i ] [ j ] = ( i % 2 == 0 ) ? SHA : DOT ; b [ i ] [ j ] = ( i % 2 == 1 ) ? SHA : DOT ; } } for ( int i = 0 ; i < H ; i ++ ) { for ( int j = 0 ; j < W ; j ++ ) { if ( a [ i ] [ j ] == SHA ) { r [ i ] [ j ] = SHA ; b [ i ] [ j ] = SHA ; } } } show ( r ) ; System . out . println ( ) ; show ( b ) ; } private static final char DOT = ' . ' , SHA = ' # ' ; private void show ( char [ ] [ ] cs ) { for ( int i = 0 ; i < cs . length ; i ++ ) { System . out . println ( new String ( cs [ i ] ) ) ; } } }

import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { new Main ( ) . run ( ) ; } public void run ( ) { Scanner sc = new Scanner ( System . in ) ; int H = sc . nextInt ( ) ; int W = sc . nextInt ( ) ; char [ ] [ ] a = new char [ H ] [ W ] ; for ( int i = 0 ; i < H ; ++ i ) { a [ i ] = sc . next ( ) . toCharArray ( ) ; } for ( int i = 0 ; i < H ; ++ i ) { for ( int j = 0 ; j < W ; ++ j ) { if ( j != W - 1 && ( j == 0 || a [ i ] [ j ] == ' # ' || i % 2 == 0 ) ) { System . out . print ( ' # ' ) ; } else { System . out . print ( ' . ' ) ; } } System . out . println ( ) ; } System . out . println ( ) ; for ( int i = 0 ; i < H ; ++ i ) { for ( int j = 0 ; j < W ; ++ j ) { if ( j != 0 && ( j == W - 1 || a [ i ] [ j ] == ' # ' || i % 2 == 1 ) ) { System . out . print ( ' # ' ) ; } else { System . out . print ( ' . ' ) ; } } System . out . println ( ) ; } } void tr ( Object ... objects ) { System . out . println ( Arrays . deepToString ( objects ) ) ; } }

h , w = ( int ( i ) for i in input ( ) . split ( ) ) NEW_LINE a = [ input ( ) for i in range ( h ) ] NEW_LINE r , b = [ [ " # " ] for i in range ( h ) ] , [ [ " . " ] for i in range ( h ) ] NEW_LINE x = [ " # " , " . " ] NEW_LINE for i in range ( h ) : NEW_LINE INDENT for j in range ( 1 , w - 1 ) : NEW_LINE INDENT if a [ i ] [ j ] == " # " : NEW_LINE INDENT r [ i ] . append ( " # " ) NEW_LINE b [ i ] . append ( " # " ) NEW_LINE DEDENT else : NEW_LINE INDENT r [ i ] . append ( x [ i % 2 ] ) NEW_LINE b [ i ] . append ( x [ 1 - i % 2 ] ) NEW_LINE DEDENT DEDENT r [ i ] . append ( " . " ) NEW_LINE b [ i ] . append ( " # " ) NEW_LINE DEDENT for i in range ( h ) : print ( " " . join ( r [ i ] ) ) NEW_LINE print ( ) NEW_LINE for i in range ( h ) : print ( " " . join ( b [ i ] ) ) NEW_LINE

from collections import defaultdict , Counter NEW_LINE from itertools import product , groupby , count , permutations , combinations NEW_LINE from math import pi , sqrt NEW_LINE from collections import deque NEW_LINE from bisect import bisect , bisect_left , bisect_right NEW_LINE INF = 10 ** 10 NEW_LINE def check ( ans1 , ans2 , field ) : NEW_LINE INDENT h , w = len ( ans1 ) , len ( ans1 [ 0 ] ) NEW_LINE ans = [ [ 0 ] * w for _ in range ( h ) ] NEW_LINE for y in range ( h ) : NEW_LINE INDENT for x in range ( w ) : NEW_LINE INDENT c = " # " if ans1 [ y ] [ x ] == ans2 [ y ] [ x ] == " # " else " . " NEW_LINE if field [ y ] [ x ] != c : NEW_LINE INDENT print ( y , x ) NEW_LINE DEDENT DEDENT DEDENT DEDENT def main ( ) : NEW_LINE INDENT H , W = map ( int , input ( ) . split ( ) ) NEW_LINE field = [ ] NEW_LINE for _ in range ( H ) : NEW_LINE INDENT field . append ( input ( ) ) NEW_LINE DEDENT ans1 , ans2 = [ [ " . " ] * W for _ in range ( H ) ] , [ [ " . " ] * W for _ in range ( H ) ] NEW_LINE for i in range ( H ) : NEW_LINE INDENT ans1 [ i ] [ 0 ] = " # " NEW_LINE ans2 [ i ] [ - 1 ] = " # " NEW_LINE if i % 2 == 0 : NEW_LINE INDENT ans1 [ i ] = [ " # " ] * ( W - 1 ) + [ " . " ] NEW_LINE DEDENT else : NEW_LINE INDENT ans2 [ i ] = [ " . " ] + [ " # " ] * ( W - 1 ) NEW_LINE DEDENT DEDENT for y in range ( H ) : NEW_LINE INDENT for x in range ( W ) : NEW_LINE INDENT if field [ y ] [ x ] == " # " : NEW_LINE INDENT if y % 2 == 0 : NEW_LINE INDENT ans2 [ y ] [ x ] = " # " NEW_LINE DEDENT else : NEW_LINE INDENT ans1 [ y ] [ x ] = " # " NEW_LINE DEDENT DEDENT DEDENT DEDENT for line in ans1 : NEW_LINE INDENT print ( " " . join ( line ) ) NEW_LINE DEDENT print ( ) NEW_LINE for line in ans2 : NEW_LINE INDENT print ( " " . join ( line ) ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT

import math , string , itertools , fractions , heapq , collections , re , array , bisect , sys , random , time , copy , functools NEW_LINE sys . setrecursionlimit ( 10 ** 7 ) NEW_LINE inf = 10 ** 20 NEW_LINE eps = 1.0 / 10 ** 10 NEW_LINE mod = 10 ** 9 + 7 NEW_LINE def LI ( ) : return [ int ( x ) for x in sys . stdin . readline ( ) . split ( ) ] NEW_LINE def LI_ ( ) : return [ int ( x ) - 1 for x in sys . stdin . readline ( ) . split ( ) ] NEW_LINE def LF ( ) : return [ float ( x ) for x in sys . stdin . readline ( ) . split ( ) ] NEW_LINE def LS ( ) : return sys . stdin . readline ( ) . split ( ) NEW_LINE def I ( ) : return int ( sys . stdin . readline ( ) ) NEW_LINE def F ( ) : return float ( sys . stdin . readline ( ) ) NEW_LINE def S ( ) : return input ( ) NEW_LINE def main ( ) : NEW_LINE INDENT h , w = LI ( ) NEW_LINE a = [ [ c == ' # ' for c in S ( ) ] for _ in range ( h ) ] NEW_LINE r = [ ' # ' * w ] NEW_LINE for c in a [ 1 : - 1 ] : NEW_LINE INDENT t = ' ' NEW_LINE for i in range ( w ) : NEW_LINE INDENT ci = c [ i ] NEW_LINE if ci or i % 2 == 0 : NEW_LINE INDENT t += ' # ' NEW_LINE DEDENT else : NEW_LINE INDENT t += ' . ' NEW_LINE DEDENT DEDENT r . append ( t ) NEW_LINE DEDENT r . append ( ' . ' * w ) NEW_LINE r . append ( ' ' ) NEW_LINE r . append ( ' . ' * w ) NEW_LINE for c in a [ 1 : - 1 ] : NEW_LINE INDENT t = ' ' NEW_LINE for i in range ( w ) : NEW_LINE INDENT ci = c [ i ] NEW_LINE if ci or i % 2 == 1 : NEW_LINE INDENT t += ' # ' NEW_LINE DEDENT else : NEW_LINE INDENT t += ' . ' NEW_LINE DEDENT DEDENT r . append ( t ) NEW_LINE DEDENT r . append ( ' # ' * w ) NEW_LINE return ' \n ' . join ( r ) NEW_LINE DEDENT print ( main ( ) ) NEW_LINE

import itertools NEW_LINE import random NEW_LINE def genrandom ( h , w ) : NEW_LINE INDENT g = [ [ 0 ] * w for _ in range ( h ) ] NEW_LINE for i in range ( 1 , h - 1 ) : NEW_LINE INDENT for j in range ( 1 , w - 1 ) : NEW_LINE INDENT if random . randint ( 0 , 1 ) : NEW_LINE INDENT g [ i ] [ j ] = 1 NEW_LINE DEDENT DEDENT DEDENT return g NEW_LINE DEDENT def display ( g ) : NEW_LINE INDENT for i in range ( len ( g ) ) : NEW_LINE INDENT print ( ' ' . join ( ' # ' if b else ' . ' for b in g [ i ] ) ) NEW_LINE DEDENT DEDENT h , w = [ int ( s ) for s in input ( ) . split ( ) ] NEW_LINE g = [ [ 0 ] * w for _ in range ( h ) ] NEW_LINE for i in range ( h ) : NEW_LINE INDENT s = input ( ) NEW_LINE for ( j , c ) in enumerate ( s ) : NEW_LINE INDENT if c == ' # ' : NEW_LINE INDENT g [ i ] [ j ] = 1 NEW_LINE DEDENT DEDENT DEDENT red = [ list ( g [ i ] ) for i in range ( h ) ] NEW_LINE blue = [ list ( g [ i ] ) for i in range ( h ) ] NEW_LINE for i in range ( h ) : NEW_LINE INDENT red [ i ] [ - 1 ] = 1 NEW_LINE blue [ i ] [ 0 ] = 1 NEW_LINE if i % 2 == 0 : NEW_LINE INDENT for j in range ( 1 , w - 1 ) : NEW_LINE INDENT red [ i ] [ j ] = 1 NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT for j in range ( 1 , w - 1 ) : NEW_LINE INDENT blue [ i ] [ j ] = 1 NEW_LINE DEDENT DEDENT DEDENT display ( red ) NEW_LINE print ( ) NEW_LINE display ( blue ) NEW_LINE NEW_LINE

import sys NEW_LINE stdin = sys . stdin NEW_LINE readline = sys . stdin . readline NEW_LINE H , W = map ( int , readline ( ) . split ( ) ) NEW_LINE red , blue = [ ] , [ ] NEW_LINE r_append , b_append = red . append , blue . append NEW_LINE for _ in [ None ] * ( H // 2 ) : NEW_LINE INDENT r_append ( list ( " # " * ( W - 1 ) + " . " ) ) NEW_LINE r_append ( list ( " # " + " . " * ( W - 1 ) ) ) NEW_LINE b_append ( list ( " . " * ( W - 1 ) + " # " ) ) NEW_LINE b_append ( list ( " . " + " # " * ( W - 1 ) ) ) NEW_LINE DEDENT if H % 2 : NEW_LINE INDENT r_append ( list ( " # " * ( W - 1 ) + " . " ) ) NEW_LINE b_append ( list ( " . " * ( W - 1 ) + " # " ) ) NEW_LINE DEDENT for y in range ( H ) : NEW_LINE INDENT for x , c in enumerate ( readline ( ) ) : NEW_LINE INDENT if c == " # " : NEW_LINE INDENT if red [ y ] [ x ] == " . " : NEW_LINE INDENT red [ y ] [ x ] = " # " NEW_LINE DEDENT else : NEW_LINE INDENT blue [ y ] [ x ] = " # " NEW_LINE DEDENT DEDENT DEDENT DEDENT join = " " . join NEW_LINE for line in red : NEW_LINE INDENT print ( join ( line ) ) NEW_LINE DEDENT print ( ) NEW_LINE for line in blue : NEW_LINE INDENT print ( join ( line ) ) NEW_LINE DEDENT


import java . util . * ; public class Main { private static int solve ( Scanner scanner ) { int N = Integer . parseInt ( scanner . nextLine ( ) ) ; int [ ] nums = lineToIntNums ( scanner . nextLine ( ) ) ; for ( int i = 0 ; i < N ; i ++ ) { nums [ i ] -- ; } int ret = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( nums [ i ] == i ) { if ( i == N - 1 ) { swap ( i - 1 , i , nums ) ; } else { swap ( i , i + 1 , nums ) ; } ret ++ ; } } return ret ; } private static void swap ( int i , int j , int [ ] nums ) { int tmp = nums [ i ] ; nums [ i ] = nums [ j ] ; nums [ j ] = tmp ; } private static final String ex1 = "5 \n " + "1 ▁ 4 ▁ 3 ▁ 5 ▁ 2" ; private static final String ex2 = "2 \n " + "1 ▁ 2" ; private static final String ex3 = "2 \n " + "2 ▁ 1" ; private static final String ex4 = "9 \n " + "1 ▁ 2 ▁ 4 ▁ 9 ▁ 5 ▁ 8 ▁ 7 ▁ 3 ▁ 6" ; public static void main ( String [ ] args ) { System . out . println ( solve ( new Scanner ( System . in ) ) ) ; } private static int [ ] lineToIntNums ( String line ) { String [ ] strNums = line . split ( " ▁ " ) ; int [ ] ret = new int [ strNums . length ] ; for ( int i = 0 ; i < strNums . length ; i ++ ) { ret [ i ] = Integer . parseInt ( strNums [ i ] ) ; } return ret ; } private static long [ ] lineToLongNums ( String line ) { String [ ] strNums = line . split ( " ▁ " ) ; long [ ] ret = new long [ strNums . length ] ; for ( int i = 0 ; i < strNums . length ; i ++ ) { ret [ i ] = Long . parseLong ( strNums [ i ] ) ; } return ret ; } }

import java . util . ArrayList ; import java . util . Arrays ; import java . util . List ; import java . util . Scanner ; import java . util . function . Consumer ; import java . util . stream . IntStream ; import static java . util . stream . Collectors . toList ; public class Main { private static final Scanner scanner = new Scanner ( System . in ) ; private static final Consumer < List < String > > consumer = solve ( ) ; public static void main ( String [ ] args ) { consumer . accept ( readInput ( ) ) ; } private static List < String > readInput ( ) { final List < String > lineList = new ArrayList < > ( ) ; while ( scanner . hasNextLine ( ) ) { lineList . add ( scanner . nextLine ( ) ) ; } return lineList ; } private static Consumer < List < String > > solve ( ) { return args -> { final List < Integer > numList = Arrays . stream ( args . get ( 1 ) . split ( " ▁ " ) ) . map ( Integer :: valueOf ) . collect ( toList ( ) ) ; final List < Integer > matchedIndexList = IntStream . range ( 0 , numList . size ( ) ) . filter ( x -> numList . get ( x ) . equals ( x + 1 ) ) . boxed ( ) . collect ( toList ( ) ) ; Integer curr = - 1 ; Integer cnt = 0 ; Integer ans = 0 ; for ( final Integer index : matchedIndexList ) { if ( curr == - 1 || curr + 1 == index ) { cnt ++ ; curr = index ; continue ; } ans += Double . valueOf ( Math . ceil ( cnt . doubleValue ( ) / 2 ) ) . intValue ( ) ; cnt = 1 ; curr = index ; } ans += Double . valueOf ( Math . ceil ( cnt . doubleValue ( ) / 2 ) ) . intValue ( ) ; System . out . println ( ans ) ; } ; } }

import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . StringTokenizer ; public class Main { int n ; int [ ] ps ; public static void main ( String args [ ] ) { new Main ( ) . run ( ) ; } void run ( ) { FastReader sc = new FastReader ( ) ; n = sc . nextInt ( ) ; ps = new int [ n + 1 ] ; for ( int i = 1 ; i <= n ; i ++ ) { ps [ i ] = sc . nextInt ( ) ; } solve ( ) ; } void solve ( ) { boolean [ ] bads = new boolean [ n + 1 ] ; for ( int i = 1 ; i <= n ; i ++ ) { if ( ps [ i ] == i ) { bads [ i ] = true ; } } int count = 0 ; for ( int i = 1 ; i < n ; i ++ ) { if ( ps [ i ] == i ) { swap ( ps , i , i + 1 ) ; count ++ ; } } if ( ps [ n ] == n ) { count ++ ; } System . out . println ( count ) ; } void swap ( int [ ] ps , int i , int j ) { int temp = ps [ i ] ; ps [ i ] = ps [ j ] ; ps [ j ] = temp ; } static class FastReader { BufferedReader br ; StringTokenizer st ; public FastReader ( ) { br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; } String next ( ) { while ( st == null || ! st . hasMoreElements ( ) ) { try { st = new StringTokenizer ( br . readLine ( ) ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } return st . nextToken ( ) ; } int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } long nextLong ( ) { return Long . parseLong ( next ( ) ) ; } double nextDouble ( ) { return Double . parseDouble ( next ( ) ) ; } String nextLine ( ) { String str = " " ; try { str = br . readLine ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } return str ; } } }

import java . util . Scanner ; public class Main { public static void main ( String args [ ] ) throws Exception { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int [ ] p = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { p [ i ] = sc . nextInt ( ) - 1 ; } int pos = 0 ; int ans = 0 ; while ( pos < N ) { if ( pos == p [ pos ] ) { if ( pos != N - 1 ) { if ( pos + 1 == p [ pos + 1 ] ) { ans ++ ; pos += 2 ; } else { ans ++ ; pos ++ ; } } else { ans ++ ; pos ++ ; } } else { pos ++ ; } } System . out . println ( ans ) ; } }

import java . util . * ; import java . lang . * ; import java . math . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] num = new int [ n + 1 ] ; int ans = 0 ; int tmp ; num [ 0 ] = 10000000 ; for ( int i = 1 ; i <= n ; i ++ ) { num [ i ] = sc . nextInt ( ) ; } for ( int i = 1 ; i <= n ; i ++ ) { if ( i == n ) { if ( num [ i ] == i ) { tmp = num [ i ] ; num [ i ] = num [ i - 1 ] ; num [ i - 1 ] = tmp ; ans ++ ; } } else { if ( num [ i ] == i ) { tmp = num [ i ] ; num [ i ] = num [ i + 1 ] ; num [ i + 1 ] = tmp ; ans ++ ; } } } System . out . println ( ans ) ; sc . close ( ) ; } }

import sys NEW_LINE sys . setrecursionlimit ( 10 ** 9 ) NEW_LINE input = sys . stdin . readline NEW_LINE N = int ( input ( ) ) NEW_LINE A = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE for i in range ( 1 , N + 1 ) : NEW_LINE INDENT A [ i - 1 ] -= i NEW_LINE DEDENT ans = 0 NEW_LINE if all ( a != 0 for a in A ) : NEW_LINE INDENT ans = 0 NEW_LINE DEDENT else : NEW_LINE INDENT seq = 0 NEW_LINE for i in range ( N ) : NEW_LINE INDENT if A [ i ] == 0 : NEW_LINE INDENT seq += 1 NEW_LINE DEDENT else : NEW_LINE INDENT ans += ( seq + 1 ) // 2 NEW_LINE seq = 0 NEW_LINE DEDENT DEDENT ans += ( seq + 1 ) // 2 NEW_LINE DEDENT print ( ans ) NEW_LINE

def inpl ( ) : return [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE N = int ( input ( ) ) NEW_LINE p = inpl ( ) NEW_LINE H = ' ' NEW_LINE for i in range ( 1 , N + 1 ) : NEW_LINE INDENT if i != p [ i - 1 ] : NEW_LINE INDENT H += '1' NEW_LINE DEDENT else : NEW_LINE INDENT H += '0' NEW_LINE DEDENT DEDENT H = H . replace ( '00' , '1' ) NEW_LINE ans = N - len ( H ) NEW_LINE ans += H . count ( '0' ) NEW_LINE print ( ans ) NEW_LINE

n = int ( input ( ) ) NEW_LINE plist = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE prevp = plist [ 0 ] NEW_LINE swap = 0 NEW_LINE is_swap = False NEW_LINE for i , p in enumerate ( plist [ 1 : ] ) : NEW_LINE INDENT if is_swap : NEW_LINE INDENT is_swap = False NEW_LINE DEDENT elif i + 1 == prevp : NEW_LINE INDENT is_swap = True NEW_LINE swap += 1 NEW_LINE DEDENT prevp = p NEW_LINE DEDENT print ( swap + ( 1 if not is_swap and plist [ - 1 ] == len ( plist ) else 0 ) ) NEW_LINE

from statistics import mean , median , variance , stdev NEW_LINE import numpy as np NEW_LINE import sys NEW_LINE import math NEW_LINE import fractions NEW_LINE import itertools NEW_LINE import copy NEW_LINE from operator import itemgetter NEW_LINE def j ( q ) : NEW_LINE INDENT if q == 1 : print ( " YES " ) NEW_LINE else : print ( " NO " ) NEW_LINE exit ( 0 ) NEW_LINE DEDENT def ct ( x , y ) : NEW_LINE INDENT if ( x > y ) : print ( " + " ) NEW_LINE elif ( x < y ) : print ( " - " ) NEW_LINE else : print ( " ? " ) NEW_LINE DEDENT def ip ( ) : NEW_LINE INDENT return int ( input ( ) ) NEW_LINE DEDENT n = ip ( ) NEW_LINE a = [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE prev = 0 NEW_LINE s = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT if a [ i ] == i + 1 : NEW_LINE INDENT s += 1 NEW_LINE if prev : NEW_LINE INDENT s -= 1 NEW_LINE prev = 0 NEW_LINE DEDENT else : prev = 1 NEW_LINE DEDENT else : prev = 0 NEW_LINE DEDENT print ( s ) NEW_LINE

def main ( ) : NEW_LINE INDENT N = int ( input ( ) ) NEW_LINE p = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE r = 0 NEW_LINE i = 0 NEW_LINE while i < N : NEW_LINE INDENT if p [ i ] == i + 1 : NEW_LINE INDENT r += 1 NEW_LINE i += 1 NEW_LINE DEDENT i += 1 NEW_LINE DEDENT print ( r ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT