import java . util . * ; public class Main { static Scanner sc = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { char [ ] S = sc . next ( ) . toCharArray ( ) ; char [ ] T = sc . next ( ) . toCharArray ( ) ; int [ ] start = new int [ 26 ] ; int [ ] end = new int [ 26 ] ; Arrays . fill ( start , - 1 ) ; Arrays . fill ( end , - 1 ) ; for ( int i = 0 ; i < S . length ; i ++ ) { int a = S [ i ] - ' a ' ; int b = T [ i ] - ' a ' ; if ( ( start [ a ] != - 1 && end [ b ] != a ) || ( end [ b ] != - 1 && start [ a ] != b ) ) { System . out . println ( " No " ) ; return ; } start [ a ] = b ; end [ b ] = a ; } System . out . println ( " Yes " ) ; } }

import java . util . HashMap ; import java . util . Map ; import java . util . Scanner ; public class Main { public static final String YES = " Yes " ; public static final String NO = " No " ; public static String process ( TestCase testCase ) { final String S = testCase . S ; final String T = testCase . T ; Map < Character , Integer > sCharFreq = countCharFrequencies ( S ) ; Map < Character , Integer > tCharFreq = countCharFrequencies ( T ) ; Map < Integer , Integer > sFreqMap = toFreqMap ( sCharFreq ) ; Map < Integer , Integer > tFreqMap = toFreqMap ( tCharFreq ) ; return sFreqMap . equals ( tFreqMap ) ? YES : NO ; } private static Map < Character , Integer > countCharFrequencies ( String str ) { Map < Character , Integer > map = new HashMap < > ( ) ; str . chars ( ) . mapToObj ( i -> ( char ) i ) . forEach ( c -> { if ( map . containsKey ( c ) ) { map . put ( c , map . get ( c ) + 1 ) ; } else { map . put ( c , 1 ) ; } } ) ; return map ; } private static Map < Integer , Integer > toFreqMap ( Map < Character , Integer > charFreq ) { Map < Integer , Integer > map = new HashMap < > ( ) ; charFreq . values ( ) . forEach ( c -> { if ( map . containsKey ( c ) ) { map . put ( c , map . get ( c ) + 1 ) ; } else { map . put ( c , 1 ) ; } } ) ; return map ; } public static void main ( String [ ] args ) { TestCase testCase = readFromInput ( ) ; final String result = process ( testCase ) ; output ( result ) ; } private static TestCase readFromInput ( ) { Scanner sc = new Scanner ( System . in ) ; String S = sc . next ( ) ; String T = sc . next ( ) ; return new TestCase ( S , T ) ; } private static void output ( String result ) { System . out . println ( result ) ; } public static class TestCase { final String S ; final String T ; public TestCase ( String S , String T ) { this . S = S ; this . T = T ; } } }

import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String [ ] s = new String [ 2 ] ; s [ 0 ] = sc . next ( ) ; s [ 1 ] = sc . next ( ) ; char [ ] c = new char [ ] { ' A ' , ' B ' , ' C ' , ' D ' , ' E ' , ' F ' , ' G ' , ' H ' , ' I ' , ' J ' , ' K ' , ' L ' , ' M ' , ' N ' , ' O ' , ' P ' , ' Q ' , ' R ' , ' S ' , ' T ' , ' U ' , ' V ' , ' W ' , ' X ' , ' Y ' , ' Z ' } ; for ( int j = 0 ; j < 2 ; j ++ ) { int cidx = 0 ; for ( int i = 0 ; i < s [ j ] . length ( ) ; i ++ ) { char sca = s [ j ] . charAt ( i ) ; if ( Character . isLowerCase ( sca ) ) { s [ j ] = s [ j ] . replace ( sca , c [ cidx ++ ] ) ; } } } System . out . println ( s [ 0 ] . equals ( s [ 1 ] ) ? " Yes " : " No " ) ; } }

import java . util . HashMap ; import java . util . Map ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; String t = sc . next ( ) ; sc . close ( ) ; Map < Character , Integer > mapS = new HashMap < Character , Integer > ( ) ; Map < Character , Integer > mapT = new HashMap < Character , Integer > ( ) ; int cnt = 0 ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { char charS = s . charAt ( i ) ; char charT = t . charAt ( i ) ; if ( mapS . containsKey ( charS ) ) { if ( mapT . containsKey ( charT ) ) { if ( ! mapS . get ( charS ) . equals ( mapT . get ( charT ) ) ) { System . out . println ( " No " ) ; return ; } } else { System . out . println ( " No " ) ; return ; } } else { if ( mapT . containsKey ( charT ) ) { System . out . println ( " No " ) ; return ; } cnt ++ ; mapS . put ( charS , cnt ) ; mapT . put ( charT , cnt ) ; } } System . out . println ( " Yes " ) ; } }

import java . io . InputStream ; import java . io . PrintStream ; import java . util . Arrays ; import java . util . Scanner ; public class Main { InputStream in = System . in ; PrintStream out = System . out ; public void _main ( String [ ] args ) { Scanner sc = new Scanner ( in ) ; String S = sc . next ( ) ; String T = sc . next ( ) ; int [ ] ms = new int [ 26 ] ; int [ ] mt = new int [ 26 ] ; Arrays . fill ( ms , - 1 ) ; Arrays . fill ( mt , - 1 ) ; String ans = " Yes " ; for ( int i = 0 ; i < S . length ( ) ; i ++ ) { int ss = S . charAt ( i ) - ' a ' ; int tt = T . charAt ( i ) - ' a ' ; if ( ( ms [ ss ] == - 1 || ms [ ss ] == tt ) && ( mt [ tt ] == - 1 || mt [ tt ] == ss ) ) { ms [ ss ] = tt ; mt [ tt ] = ss ; } else { ans = " No " ; break ; } } out . println ( ans ) ; sc . close ( ) ; } public static void main ( String [ ] args ) { new Main ( ) . _main ( args ) ; } }

prj = { } NEW_LINE prj_inv = { } NEW_LINE s = input ( ) NEW_LINE t = input ( ) NEW_LINE for i , j in zip ( s , t ) : NEW_LINE INDENT if i not in prj and j not in prj_inv : NEW_LINE INDENT prj [ i ] = j NEW_LINE prj_inv [ j ] = i NEW_LINE DEDENT elif i in prj and j in prj_inv : NEW_LINE INDENT if prj [ i ] == j : NEW_LINE INDENT continue NEW_LINE DEDENT else : NEW_LINE INDENT print ( ' No ' ) NEW_LINE break NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT print ( ' No ' ) NEW_LINE break NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT print ( ' Yes ' ) NEW_LINE DEDENT

S = list ( input ( ) ) NEW_LINE T = list ( input ( ) ) NEW_LINE def replacer ( ) : NEW_LINE INDENT m = { } NEW_LINE i = ord ( " A " ) NEW_LINE def replace ( c ) : NEW_LINE INDENT nonlocal i NEW_LINE if c not in m : NEW_LINE INDENT m [ c ] = chr ( i ) NEW_LINE i += 1 NEW_LINE DEDENT return m [ c ] NEW_LINE DEDENT return replace NEW_LINE DEDENT rs = " " . join ( map ( replacer ( ) , S ) ) NEW_LINE rt = " " . join ( map ( replacer ( ) , T ) ) NEW_LINE print ( " Yes " if rs == rt else " No " ) NEW_LINE

import sys NEW_LINE import collections NEW_LINE YES = " Yes " NEW_LINE NO = " No " NEW_LINE def solve ( S : str , T : str ) : NEW_LINE INDENT wcS = collections . defaultdict ( int ) NEW_LINE wcT = collections . defaultdict ( int ) NEW_LINE for c in S : NEW_LINE INDENT wcS [ c ] += 1 NEW_LINE DEDENT for c in T : NEW_LINE INDENT wcT [ c ] += 1 NEW_LINE DEDENT cS = collections . defaultdict ( int ) NEW_LINE cT = collections . defaultdict ( int ) NEW_LINE for key in wcS : NEW_LINE INDENT cS [ wcS [ key ] ] += 1 NEW_LINE DEDENT for key in wcT : NEW_LINE INDENT cT [ wcT [ key ] ] += 1 NEW_LINE DEDENT representable = True NEW_LINE if len ( cT . keys ( ) ) > len ( cS . keys ( ) ) : NEW_LINE INDENT temp = cT NEW_LINE cT = cS NEW_LINE cS = temp NEW_LINE DEDENT for key in cS : NEW_LINE INDENT if cT [ key ] != cS [ key ] : NEW_LINE INDENT representable = False NEW_LINE DEDENT DEDENT print ( YES if representable else NO ) NEW_LINE return NEW_LINE DEDENT def main ( ) : NEW_LINE INDENT def iterate_tokens ( ) : NEW_LINE INDENT for line in sys . stdin : NEW_LINE INDENT for word in line . split ( ) : NEW_LINE INDENT yield word NEW_LINE DEDENT DEDENT DEDENT tokens = iterate_tokens ( ) NEW_LINE S = next ( tokens ) NEW_LINE T = next ( tokens ) NEW_LINE solve ( S , T ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT

def check ( s , t ) : NEW_LINE INDENT from collections import Counter NEW_LINE sc = Counter ( s ) NEW_LINE tc = Counter ( t ) NEW_LINE return sorted ( sc . values ( ) ) == sorted ( tc . values ( ) ) NEW_LINE DEDENT print ( [ ' No ' , ' Yes ' ] [ check ( input ( ) , input ( ) ) ] ) NEW_LINE

S = input ( ) NEW_LINE T = input ( ) NEW_LINE check = { ' A ' , ' B ' , ' C ' , ' D ' , ' E ' , ' F ' , ' G ' , ' H ' , ' I ' , ' J ' , ' K ' , ' L ' , ' M ' , ' N ' , ' O ' , ' P ' , ' Q ' , ' R ' , ' S ' , ' T ' , ' U ' , ' V ' , ' W ' , ' X ' , ' Y ' , ' Z ' } NEW_LINE alll = [ ' A ' , ' B ' , ' C ' , ' D ' , ' E ' , ' F ' , ' G ' , ' H ' , ' I ' , ' J ' , ' K ' , ' L ' , ' M ' , ' N ' , ' O ' , ' P ' , ' Q ' , ' R ' , ' S ' , ' T ' , ' U ' , ' V ' , ' W ' , ' X ' , ' Y ' , ' Z ' ] NEW_LINE alfa = { ' a ' , ' b ' , ' c ' , ' d ' , ' e ' , ' f ' , ' g ' , ' h ' , ' i ' , ' j ' , ' k ' , ' l ' , ' m ' , ' n ' , ' o ' , ' p ' , ' q ' , ' r ' , ' s ' , ' t ' , ' u ' , ' v ' , ' w ' , ' x ' , ' y ' , ' z ' } NEW_LINE count_s = set ( ) NEW_LINE count_t = set ( ) NEW_LINE nums = 0 NEW_LINE numt = 0 NEW_LINE for s in range ( len ( S ) ) : NEW_LINE INDENT if count_s == alfa : NEW_LINE INDENT break NEW_LINE DEDENT if S [ s ] in check : NEW_LINE INDENT continue NEW_LINE DEDENT count_s . add ( S [ s ] ) NEW_LINE S = S . replace ( S [ s ] , str ( alll [ nums ] ) ) NEW_LINE nums += 1 NEW_LINE DEDENT for t in range ( len ( T ) ) : NEW_LINE INDENT if count_t == alfa : NEW_LINE INDENT break NEW_LINE DEDENT if T [ t ] in check : NEW_LINE INDENT continue NEW_LINE DEDENT count_t . add ( T [ t ] ) NEW_LINE T = T . replace ( T [ t ] , str ( alll [ numt ] ) ) NEW_LINE numt += 1 NEW_LINE DEDENT if S == T : NEW_LINE INDENT print ( ' Yes ' ) NEW_LINE DEDENT else : print ( ' No ' ) NEW_LINE


import java . util . Scanner ; class Main { static int max = 100002 ; static int MOD = 1000000007 ; static long [ ] fac = new long [ max ] ; static long [ ] finv = new long [ max ] ; static long [ ] inv = new long [ max ] ; public static void main ( String [ ] args ) { COMinit ( ) ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int k = sc . nextInt ( ) ; long kotae = COM ( n , 1 ) * COM ( k - 1 , 0 ) ; for ( int i = 2 ; i <= Math . min ( n , k ) ; i ++ ) { kotae += COM ( n , i ) * COM ( k - 1 , i - 1 ) % MOD ; kotae %= MOD ; } System . out . println ( kotae ) ; } static void COMinit ( ) { fac [ 0 ] = fac [ 1 ] = 1 ; finv [ 0 ] = finv [ 1 ] = 1 ; inv [ 1 ] = 1 ; for ( int i = 2 ; i < max ; i ++ ) { fac [ i ] = fac [ i - 1 ] * i % MOD ; inv [ i ] = MOD - inv [ MOD % i ] * ( MOD / i ) % MOD ; finv [ i ] = finv [ i - 1 ] * inv [ i ] % MOD ; } } static long COM ( int n , int k ) { if ( n < k ) return 0 ; if ( n < 0 || k < 0 ) return 0 ; return fac [ n ] * ( finv [ k ] * finv [ n - k ] % MOD ) % MOD ; } }

import java . util . * ; import java . awt . * ; import java . awt . geom . * ; import static java . lang . System . * ; import static java . lang . Math . * ; public class Main { public static void main ( String [ ] $ ) { Scanner sc = new Scanner ( in ) ; int n = sc . nextInt ( ) ; int k = sc . nextInt ( ) ; Init ( 1000000 ) ; out . println ( combi ( n - 1 + k , n - 1 ) ) ; } static long power ( long x , int n ) { long mod = 1000000007 ; if ( n == 0 ) return 1 ; if ( n % 2 == 0 ) { long e = power ( x , n / 2 ) % mod ; return ( e * e ) % mod ; } return ( x * power ( x , n - 1 ) ) % mod ; } static int mod = 1000000007 ; static long [ ] fact ; static long [ ] inv ; static void Init ( int n ) { fact = new long [ n ] ; inv = new long [ n ] ; fact [ 0 ] = inv [ 0 ] = 1 ; for ( int i = 1 ; i < n ; i ++ ) { fact [ i ] = ( fact [ i - 1 ] * i ) % mod ; inv [ i ] = power ( fact [ i ] , mod - 2 ) ; } } static long combi ( int n , int k ) { return ( ( fact [ n ] * inv [ n - k ] ) % mod * inv [ k ] ) % mod ; } }

import java . util . * ; public class Main { public static long MOD = 1000000007 ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long n = sc . nextLong ( ) ; long k = sc . nextLong ( ) ; long p1 = 1 ; long p2 = 1 ; long p3 = 1 ; for ( long i = 1 ; i <= n + k - 1 ; i ++ ) { p1 = ( p1 * i ) % MOD ; } for ( long i = 1 ; i <= k ; i ++ ) { p2 = ( p2 * i ) % MOD ; } for ( long i = 1 ; i <= n - 1 ; i ++ ) { p3 = ( p3 * i ) % MOD ; } long p = ( p2 * p3 ) % MOD ; long inv = func ( p , MOD - 2 ) ; System . out . println ( ( p1 * inv ) % MOD ) ; } public static long func ( long a , long x ) { if ( x == 0 ) return 1 ; if ( x % 2 == 0 ) { long t = func ( a , x / 2 ) ; return ( t * t ) % MOD ; } long t = func ( a , ( x - 1 ) / 2 ) ; t = ( t * t ) % MOD ; return ( t * a ) % MOD ; } }

import java . util . Scanner ; public class Main { static final int INF = 1000000007 ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; final int N = sc . nextInt ( ) ; final int K = sc . nextInt ( ) ; sc . close ( ) ; System . out . println ( getHomogeneousCombination ( N , K ) ) ; } private static long getHomogeneousCombination ( int n , int r ) { return getCombination ( n - 1 + r , n - 1 ) ; } private static long getCombination ( int n , int r ) { long [ ] modDp = new long [ n + 1 ] ; long [ ] modInvDp = new long [ n + 1 ] ; modDp [ 0 ] = 1 ; modInvDp [ n ] = 1 ; for ( int i = 1 ; i <= n ; i ++ ) modDp [ i ] = ( modDp [ i - 1 ] * i ) % INF ; long tmp = modDp [ n ] ; long doubling = INF - 2 ; while ( doubling > 0 ) { if ( doubling % 2 == 1 ) modInvDp [ n ] = ( modInvDp [ n ] * tmp ) % INF ; tmp = ( tmp * tmp ) % INF ; doubling /= 2 ; } for ( int i = n ; i > 0 ; i -- ) modInvDp [ i - 1 ] = modInvDp [ i ] * i % INF ; long ans = modDp [ n ] ; ans = ans * modInvDp [ r ] % INF ; ans = ans * modInvDp [ n - r ] % INF ; return ans ; } }

import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int n = scan . nextInt ( ) ; int k = scan . nextInt ( ) ; long INF = 1000000007 ; long ans = 1 ; for ( int i = k + 1 ; i < n + k ; i ++ ) { ans *= i ; ans %= INF ; } long div [ ] = new long [ 31 ] ; div [ 0 ] = 1 ; for ( int i = 1 ; i < n ; i ++ ) { div [ 0 ] *= i ; div [ 0 ] %= INF ; } int [ ] two = new int [ 31 ] ; two [ 0 ] = 1 ; for ( int i = 1 ; i < 31 ; i ++ ) { two [ i ] = two [ i - 1 ] * 2 ; div [ i ] = div [ i - 1 ] * div [ i - 1 ] ; div [ i ] %= INF ; } long mom = 1 ; for ( int i = 0 ; i < 31 ; i ++ ) { if ( ( two [ i ] & ( INF - 2 ) ) > 0 ) { mom *= div [ i ] ; mom %= INF ; } } ans *= mom ; ans %= INF ; System . out . println ( ans ) ; } }

m = 10 ** 9 + 7 NEW_LINE def f ( a , b ) : NEW_LINE INDENT r = 1 NEW_LINE for i in range ( b ) : NEW_LINE INDENT r = r * ( n + k - 1 - i ) * pow ( i + 1 , m - 2 , m ) % m NEW_LINE DEDENT return r NEW_LINE DEDENT n = int ( input ( ) ) NEW_LINE k = int ( input ( ) ) NEW_LINE print ( f ( n , k ) ) NEW_LINE

def get_inverse_element ( x : int , mod : int ) -> int : NEW_LINE INDENT ans = 1 NEW_LINE bit = bin ( mod - 2 ) [ : 1 : - 1 ] NEW_LINE for c in bit : NEW_LINE INDENT if c == "1" : NEW_LINE INDENT ans = ans * x % mod NEW_LINE DEDENT x = x * x % mod NEW_LINE DEDENT return ans NEW_LINE DEDENT n , k , mod = int ( input ( ) ) , int ( input ( ) ) , 10 ** 9 + 7 NEW_LINE n1 , n2 , n3 = 1 , 1 , 1 NEW_LINE _n = 1 NEW_LINE for i in range ( 1 , n + k ) : NEW_LINE INDENT _n = ( _n * i ) % mod NEW_LINE if i == n - 1 + k : NEW_LINE INDENT n1 = _n NEW_LINE DEDENT if i == n - 1 : NEW_LINE INDENT n2 = _n NEW_LINE DEDENT if i == k : NEW_LINE INDENT n3 = _n NEW_LINE DEDENT DEDENT n2 = get_inverse_element ( n2 , mod ) NEW_LINE n3 = get_inverse_element ( n3 , mod ) NEW_LINE print ( ( n1 * n2 * n3 ) % mod ) NEW_LINE

import sys NEW_LINE sys . setrecursionlimit ( 100000 ) NEW_LINE class Mod1000000007 ( ) : NEW_LINE INDENT def __init__ ( self , n ) : NEW_LINE INDENT self . n = n % 1000000007 NEW_LINE DEDENT def plus ( self , m ) : NEW_LINE INDENT self . n = ( self . n + m ) % 1000000007 NEW_LINE return self NEW_LINE DEDENT def minus ( self , m ) : NEW_LINE INDENT self . n = ( self . n - m ) % 1000000007 NEW_LINE return self NEW_LINE DEDENT def times ( self , m ) : NEW_LINE INDENT self . n = ( ( self . n ) * ( m % 1000000007 ) ) % 1000000007 NEW_LINE return self NEW_LINE DEDENT def frac ( self , m ) : NEW_LINE INDENT l = [ 1 , 0 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , 1 , 0 , 1 , 0 , 0 , 1 , 1 , 0 , 1 , 0 , 1 , 1 , 0 , 0 , 1 , 1 , 1 , 0 , 1 , 1 , 1 ] NEW_LINE ans = 1 NEW_LINE pow = m % 1000000007 NEW_LINE for i in range ( len ( l ) ) : NEW_LINE INDENT if l [ i ] == 1 : NEW_LINE INDENT ans = ( ans * pow ) % 1000000007 NEW_LINE DEDENT if i != len ( l ) - 1 : NEW_LINE INDENT pow = ( pow ** 2 ) % 1000000007 NEW_LINE DEDENT DEDENT return self . times ( ans ) NEW_LINE DEDENT DEDENT ( n , k ) = ( int ( input ( ) ) , int ( input ( ) ) ) NEW_LINE ans = Mod1000000007 ( 1 ) NEW_LINE for j in range ( k ) : NEW_LINE INDENT ans . times ( n + j ) . frac ( j + 1 ) NEW_LINE DEDENT print ( ans . n ) NEW_LINE

import math NEW_LINE n = int ( input ( ) ) NEW_LINE k = int ( input ( ) ) NEW_LINE def cmb ( n , r ) : NEW_LINE INDENT if n - r < r : r = n - r NEW_LINE if r == 0 : return 1 NEW_LINE if r == 1 : return n NEW_LINE numerator = [ n - r + k + 1 for k in range ( r ) ] NEW_LINE denominator = [ k + 1 for k in range ( r ) ] NEW_LINE for p in range ( 2 , r + 1 ) : NEW_LINE INDENT pivot = denominator [ p - 1 ] NEW_LINE if pivot > 1 : NEW_LINE INDENT offset = ( n - r ) % p NEW_LINE for k in range ( p - 1 , r , p ) : NEW_LINE INDENT numerator [ k - offset ] /= pivot NEW_LINE denominator [ k ] /= pivot NEW_LINE DEDENT DEDENT DEDENT result = 1 NEW_LINE for k in range ( r ) : NEW_LINE INDENT if numerator [ k ] > 1 : NEW_LINE INDENT result *= int ( numerator [ k ] ) NEW_LINE DEDENT DEDENT return result NEW_LINE DEDENT print ( cmb ( n + k - 1 , n - 1 ) % ( 10 ** 9 + 7 ) ) NEW_LINE

def d_multi_loop ( N , K ) : NEW_LINE INDENT class Combination ( object ) : NEW_LINE INDENT def __init__ ( self , n , mod ) : NEW_LINE INDENT self . mod = mod NEW_LINE self . factorial = [ 1 ] * ( n + 1 ) NEW_LINE for k in range ( 1 , n ) : NEW_LINE INDENT self . factorial [ k + 1 ] = ( self . factorial [ k ] * ( k + 1 ) ) % mod NEW_LINE DEDENT self . fact_inv = [ 1 ] * ( n + 1 ) NEW_LINE self . fact_inv [ n ] = pow ( self . factorial [ n ] , mod - 2 , mod ) NEW_LINE for k in reversed ( range ( 1 , n + 1 ) ) : NEW_LINE INDENT self . fact_inv [ k - 1 ] = ( self . fact_inv [ k ] * k ) % mod NEW_LINE DEDENT DEDENT def comb ( self , n , r ) : NEW_LINE INDENT if n < 0 or r < 0 or n < r : NEW_LINE INDENT return 0 NEW_LINE DEDENT return ( self . factorial [ n ] * self . fact_inv [ r ] * self . fact_inv [ n - r ] ) % self . mod NEW_LINE DEDENT def comb_with_repetition ( self , n , r ) : NEW_LINE INDENT if n == 0 and r > 0 : NEW_LINE INDENT return 0 NEW_LINE DEDENT if n >= 0 and r == 0 : NEW_LINE INDENT return 1 NEW_LINE DEDENT return self . comb ( n + r - 1 , r ) NEW_LINE DEDENT DEDENT ans = Combination ( N + K , 10 ** 9 + 7 ) . comb_with_repetition ( N , K ) NEW_LINE return ans NEW_LINE DEDENT N = int ( input ( ) ) NEW_LINE K = int ( input ( ) ) NEW_LINE print ( d_multi_loop ( N , K ) ) NEW_LINE


import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; String s = scan . next ( ) ; int num = s . length ( ) ; int min = 10 ; int max = 0 ; for ( int i = 0 ; i < num ; i ++ ) { if ( s . charAt ( i ) == ' A ' ) { min = i ; break ; } } for ( int i = 0 ; i < num ; i ++ ) { if ( s . charAt ( i ) == ' Z ' ) { max = i ; } } System . out . print ( max - min + 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 ) { String s = in . next ( ) ; int a = Integer . MAX_VALUE ; int z = 0 ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( s . charAt ( i ) == ' A ' ) { a = Math . min ( a , i ) ; } else if ( s . charAt ( i ) == ' Z ' ) { z = i ; } } out . println ( z - a + 1 ) ; } } 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 ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; int a = s . indexOf ( " A " ) ; int z = s . lastIndexOf ( " Z " ) ; String str = s . substring ( a , z + 1 ) ; sc . close ( ) ; System . out . println ( str . length ( ) ) ; } }

import java . io . * ; import java . util . * ; public class Main { public static void main ( String [ ] args ) { MyScanner sc = new MyScanner ( ) ; String s = sc . next ( ) ; int l = s . length ( ) ; int st = l - 1 ; int en = 0 ; for ( int i = 0 ; i < l ; i ++ ) { if ( s . charAt ( i ) == ' A ' ) { st = Math . min ( i , st ) ; } if ( s . charAt ( i ) == ' Z ' ) { en = Math . max ( i , en ) ; } } System . out . println ( en - st + 1 ) ; } static int l_min ( int [ ] a ) { Arrays . sort ( a ) ; return a [ 0 ] ; } static int l_max ( int [ ] a ) { int l = a . length ; Arrays . sort ( a ) ; return a [ l - 1 ] ; } public static PrintWriter out ; public static class MyScanner { BufferedReader br ; StringTokenizer st ; public MyScanner ( ) { br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; } String next ( ) { while ( st == null || ! st . hasMoreElements ( ) ) { try { st = new StringTokenizer ( br . readLine ( ) ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } return st . nextToken ( ) ; } int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } long nextLong ( ) { return Long . parseLong ( next ( ) ) ; } double nextDouble ( ) { return Double . parseDouble ( next ( ) ) ; } String nextLine ( ) { String str = " " ; try { str = br . readLine ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } return str ; } } }

import java . io . BufferedReader ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws Exception { BufferedReader input = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String word = input . readLine ( ) ; int start = - 1 , end = - 1 ; for ( int i = 0 ; i < word . length ( ) ; i ++ ) { if ( word . charAt ( i ) == ' A ' ) { start = i ; break ; } } for ( int i = word . length ( ) - 1 ; i > 0 ; i -- ) { if ( word . charAt ( i ) == ' Z ' ) { end = i ; break ; } } System . out . println ( end - start + 1 ) ; } }

S = input ( ) NEW_LINE A = 0 NEW_LINE Z = 0 NEW_LINE flg = 0 NEW_LINE for i in range ( len ( S ) ) : NEW_LINE INDENT if S [ i ] == ' A ' and flg == 0 : NEW_LINE INDENT A = i NEW_LINE flg = 1 NEW_LINE DEDENT if S [ i ] == ' Z ' : NEW_LINE INDENT Z = i NEW_LINE DEDENT DEDENT print ( Z - A + 1 ) NEW_LINE

s = input ( ) NEW_LINE print ( len ( s ) - s [ : : - 1 ] . index ( ' Z ' ) - s . index ( ' A ' ) ) NEW_LINE

s = input ( ) NEW_LINE index = [ ] NEW_LINE for i , c in enumerate ( s ) : NEW_LINE INDENT if c == " A " : NEW_LINE INDENT index . append ( i ) NEW_LINE break NEW_LINE DEDENT DEDENT for i , c in enumerate ( reversed ( s ) ) : NEW_LINE INDENT if c == " Z " : NEW_LINE INDENT index . append ( len ( s ) - i ) NEW_LINE break NEW_LINE DEDENT DEDENT count = len ( s [ index [ 0 ] : index [ 1 ] ] ) NEW_LINE print ( count ) NEW_LINE

from functools import reduce NEW_LINE import math NEW_LINE def main ( ) : NEW_LINE INDENT s = list ( _ for _ in input ( ) ) NEW_LINE max_s = 0 NEW_LINE from_i = 0 NEW_LINE to_i = 0 NEW_LINE for i in range ( len ( s ) ) : NEW_LINE INDENT if s [ i ] == ' A ' : NEW_LINE INDENT from_i = i NEW_LINE break NEW_LINE DEDENT DEDENT s = s [ : : - 1 ] NEW_LINE for i in range ( len ( s ) ) : NEW_LINE INDENT if s [ i ] == ' Z ' : NEW_LINE INDENT to_i = i NEW_LINE break NEW_LINE DEDENT DEDENT print ( ( len ( s ) - to_i ) - from_i ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT

s = input ( ) NEW_LINE left = 0 NEW_LINE right = 0 NEW_LINE flag = True NEW_LINE for i in range ( 0 , len ( s ) ) : NEW_LINE INDENT if s [ i ] == " A " and flag : NEW_LINE INDENT left = i NEW_LINE flag = False NEW_LINE DEDENT if s [ i ] == " Z " : NEW_LINE INDENT right = i NEW_LINE DEDENT DEDENT print ( right - left + 1 ) NEW_LINE


import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int N = scanner . nextInt ( ) ; char [ ] s = scanner . next ( ) . toCharArray ( ) ; int left = 0 ; int tmp = 0 ; for ( char ch : s ) { if ( ch == ' ( ' ) tmp -- ; else tmp ++ ; left = Math . max ( left , tmp ) ; } int right = 0 ; tmp = 0 ; for ( int i = N - 1 ; i >= 0 ; i -- ) { char ch = s [ i ] ; if ( ch == ' ) ' ) tmp -- ; else tmp ++ ; right = Math . max ( right , tmp ) ; } StringBuilder sb = new StringBuilder ( ) ; for ( int i = 0 ; i < left ; i ++ ) sb . append ( ' ( ' ) ; sb . append ( s ) ; for ( int i = 0 ; i < right ; i ++ ) sb . append ( ' ) ' ) ; System . out . println ( sb . toString ( ) ) ; } }

import java . util . * ; import java . awt . * ; import java . awt . geom . Point2D ; 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 [ ] c = new int [ n + 1 ] ; String s = sc . next ( ) ; String r = " " ; String l = " " ; int neg = 101 ; for ( int i = 0 ; i < n ; i ++ ) { char a = s . charAt ( i ) ; if ( a == ' ( ' ) c [ i + 1 ] = c [ i ] + 1 ; else c [ i + 1 ] = c [ i ] - 1 ; neg = min ( c [ i + 1 ] , neg ) ; } for ( int i = 0 ; i < - neg ; i ++ ) { l += " ( " ; } s = l + s ; int temp = 0 ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( s . charAt ( i ) == ' ( ' ) temp ++ ; else temp -- ; } for ( int i = 0 ; i < temp ; i ++ ) { r += " ) " ; } out . println ( s + r ) ; } }

import java . util . * ; public class Main { private static final char LEFT = ' ( ' ; private static final char RIGHT = ' ) ' ; public static void main ( String [ ] args ) { new Main ( ) . execute ( ) ; } public void execute ( ) { Scanner sc = new Scanner ( System . in ) ; final int N = sc . nextInt ( ) ; sc . nextLine ( ) ; String s = sc . nextLine ( ) ; int [ ] count = new int [ N ] ; count [ 0 ] = ( s . charAt ( 0 ) == LEFT ) ? 1 : - 1 ; int min = Math . min ( 0 , count [ 0 ] ) ; for ( int i = 1 ; i < N ; i ++ ) { switch ( s . charAt ( i ) ) { case LEFT : count [ i ] = count [ i - 1 ] + 1 ; break ; case RIGHT : count [ i ] = count [ i - 1 ] - 1 ; break ; default : throw new IllegalArgumentException ( ) ; } if ( count [ i ] < 0 ) { min = Math . min ( count [ i ] , min ) ; } } StringBuilder str = new StringBuilder ( ) ; for ( int i = 0 , bound = Math . abs ( min ) ; i < bound ; i ++ ) { str . append ( LEFT ) ; } str . append ( s ) ; for ( int i = 0 , bound = count [ N - 1 ] + Math . abs ( min ) ; i < bound ; i ++ ) { str . append ( RIGHT ) ; } System . out . println ( str . toString ( ) ) ; sc . close ( ) ; } }

import java . util . * ; import java . io . * ; import static java . lang . System . in ; public class Main { public static void main ( String [ ] args ) throws IOException { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; char [ ] s = sc . next ( ) . toCharArray ( ) ; LinkedList < Character > res = new LinkedList < > ( ) ; int right = 0 ; for ( int i = n - 1 ; i >= 0 ; i -- ) { if ( s [ i ] == ' ) ' ) right ++ ; else { if ( right > 0 ) right -- ; else { res . add ( ' ) ' ) ; } } res . addFirst ( s [ i ] ) ; } StringBuilder ans = new StringBuilder ( ) ; for ( int i = 0 ; i < right ; i ++ ) ans . append ( ' ( ' ) ; while ( res . size ( ) > 0 ) ans . append ( res . poll ( ) ) ; System . out . println ( ans . toString ( ) ) ; } }

import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner stdin = new Scanner ( System . in ) ; String x ; int i = 0 , j = 0 ; int a = stdin . nextInt ( ) ; x = stdin . next ( ) ; for ( int k = 1 ; k <= x . length ( ) ; k ++ ) { String xx = x . substring ( k - 1 , k ) ; if ( xx . equals ( " ( " ) ) { i ++ ; } else { i -- ; } if ( i < 0 ) { j ++ ; i = 0 ; } } for ( int f = 0 ; f < j ; f ++ ) System . out . print ( " ( " ) ; System . out . print ( x ) ; for ( int f = 0 ; f < i ; f ++ ) System . out . print ( " ) " ) ; } }

from collections import deque NEW_LINE N = int ( input ( ) ) NEW_LINE S = input ( ) NEW_LINE dq = deque ( ) NEW_LINE ans = deque ( list ( S ) ) NEW_LINE for s in S : NEW_LINE INDENT if not dq : NEW_LINE INDENT dq . append ( s ) NEW_LINE DEDENT else : NEW_LINE INDENT if dq [ - 1 ] == " ( " and s == " ) " : NEW_LINE INDENT dq . pop ( ) NEW_LINE DEDENT else : NEW_LINE INDENT dq . append ( s ) NEW_LINE DEDENT DEDENT DEDENT while dq : NEW_LINE INDENT value = dq . popleft ( ) NEW_LINE if value == " ) " : NEW_LINE INDENT ans . appendleft ( " ( " ) NEW_LINE DEDENT elif value == " ( " : NEW_LINE INDENT ans . append ( " ) " ) NEW_LINE DEDENT DEDENT ans = " " . join ( ans ) NEW_LINE print ( ans ) NEW_LINE

def insertion ( N : int , S : str ) -> str : NEW_LINE INDENT bra , ket = 0 , 0 NEW_LINE for c in S : NEW_LINE INDENT if c == ' ( ' : NEW_LINE INDENT bra += 1 NEW_LINE DEDENT else : NEW_LINE INDENT if bra > 0 : NEW_LINE INDENT bra -= 1 NEW_LINE DEDENT else : NEW_LINE INDENT ket += 1 NEW_LINE DEDENT DEDENT DEDENT ret = ( ' ( ' * ket ) + S NEW_LINE bra , ket = 0 , 0 NEW_LINE for c in reversed ( S ) : NEW_LINE INDENT if c == ' ) ' : NEW_LINE INDENT ket += 1 NEW_LINE DEDENT else : NEW_LINE INDENT if ket > 0 : NEW_LINE INDENT ket -= 1 NEW_LINE DEDENT else : NEW_LINE INDENT bra += 1 NEW_LINE DEDENT DEDENT DEDENT ret = ret + ( ' ) ' * bra ) NEW_LINE return ret NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT N = int ( input ( ) ) NEW_LINE S = input ( ) NEW_LINE ans = insertion ( N , S ) NEW_LINE print ( ans ) NEW_LINE DEDENT

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 = ni ( ) NEW_LINE s = ns ( ) NEW_LINE stack = [ ] NEW_LINE left = 0 NEW_LINE right = 0 NEW_LINE for si in s : NEW_LINE INDENT if si == ' ( ' : NEW_LINE INDENT stack . append ( ' ( ' ) NEW_LINE DEDENT elif si == ' ) ' : NEW_LINE INDENT if stack : NEW_LINE INDENT stack . pop ( ) NEW_LINE DEDENT else : NEW_LINE INDENT left += 1 NEW_LINE DEDENT DEDENT DEDENT right = len ( stack ) NEW_LINE print ( left * ' ( ' + s + right * ' ) ' ) NEW_LINE

N = input ( ) NEW_LINE S = input ( ) NEW_LINE st1 = [ ] NEW_LINE st2 = [ ] NEW_LINE tmp = ' ' NEW_LINE for x in S : NEW_LINE INDENT if x == ' ( ' : NEW_LINE INDENT st1 . append ( S ) NEW_LINE DEDENT elif x == ' ) ' : NEW_LINE INDENT if len ( st1 ) > 0 : NEW_LINE INDENT st1 . pop ( ) NEW_LINE DEDENT else : NEW_LINE INDENT tmp = ' ( ' + tmp NEW_LINE DEDENT DEDENT tmp += x NEW_LINE DEDENT ans = tmp NEW_LINE for x in tmp [ : : - 1 ] : NEW_LINE INDENT if x == ' ) ' : NEW_LINE INDENT st2 . append ( S ) NEW_LINE DEDENT elif x == ' ( ' : NEW_LINE INDENT if len ( st2 ) > 0 : NEW_LINE INDENT st2 . pop ( ) NEW_LINE DEDENT else : NEW_LINE INDENT ans += ' ) ' NEW_LINE DEDENT DEDENT DEDENT print ( ans ) NEW_LINE

n = int ( input ( ) ) NEW_LINE s = list ( input ( ) ) NEW_LINE cnt = 0 NEW_LINE res = ' ' NEW_LINE for i in range ( n ) : NEW_LINE INDENT if s [ i ] == ' ( ' : NEW_LINE INDENT cnt += 1 NEW_LINE DEDENT else : NEW_LINE INDENT if cnt > 0 : NEW_LINE INDENT cnt -= 1 NEW_LINE DEDENT else : NEW_LINE INDENT res = ' ( ' + res NEW_LINE DEDENT DEDENT res += s [ i ] NEW_LINE DEDENT for j in range ( cnt ) : NEW_LINE INDENT res += ' ) ' NEW_LINE DEDENT print ( res ) NEW_LINE


import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; HashSet < Integer > set = new HashSet < > ( ) ; int [ ] arr = new int [ n ] ; int max = 0 ; int start = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int a = sc . nextInt ( ) ; arr [ i ] = a ; if ( set . contains ( a ) ) { while ( arr [ start ] != a ) { set . remove ( arr [ start ] ) ; start ++ ; } start ++ ; } else { set . add ( a ) ; int v = set . size ( ) ; if ( max < v ) { max = v ; } } } System . out . println ( max ) ; } }

import java . util . * ; import java . io . * ; import static java . lang . System . in ; public class Main { static int n ; public static void main ( String [ ] args ) throws IOException { Scanner sc = new Scanner ( System . in ) ; n = sc . nextInt ( ) ; int [ ] A = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) A [ i ] = sc . nextInt ( ) ; int ans = helper ( A ) ; System . out . println ( ans ) ; } static int helper ( int [ ] a ) { HashSet < Integer > vis = new HashSet < > ( ) ; int left = 0 , right = 0 ; int ans = 0 ; while ( left < n ) { while ( right < n && ! vis . contains ( a [ right ] ) ) vis . add ( a [ right ++ ] ) ; if ( right == n ) { ans = Math . max ( ans , right - left ) ; return ans ; } ans = Math . max ( ans , right - left ) ; while ( left < n && a [ left ] != a [ right ] ) { vis . remove ( a [ left ] ) ; left ++ ; } vis . remove ( a [ left ++ ] ) ; } return ans ; } }

import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; int n = Integer . parseInt ( sc . next ( ) ) ; int [ ] a = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = Integer . parseInt ( sc . next ( ) ) - 1 ; } int m = 0 ; for ( int i = 0 ; i < n ; i ++ ) m = Math . max ( m , a [ i ] ) ; boolean [ ] use = new boolean [ m + 1 ] ; int s = 1 ; int t = 0 ; use [ a [ 0 ] ] = true ; long ret = 1 ; while ( s < n ) { while ( t < s && use [ a [ s ] ] ) { use [ a [ t ] ] = false ; t ++ ; } while ( s < n && ! use [ a [ s ] ] ) { use [ a [ s ] ] = true ; s ++ ; } ret = Math . max ( ret , s - t ) ; } System . out . println ( ret ) ; } }

import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int a [ ] = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { a [ i ] = sc . nextInt ( ) ; } TreeSet < Integer > set = new TreeSet < > ( ) ; int s = 0 ; int ans = 1 ; set . add ( a [ 0 ] ) ; for ( int t = 1 ; t < N ; t ++ ) { if ( set . contains ( a [ t ] ) ) { while ( set . contains ( a [ t ] ) ) { set . remove ( a [ s ] ) ; s ++ ; } set . add ( a [ t ] ) ; ans = Math . max ( ans , t - s + 1 ) ; } else { set . add ( a [ t ] ) ; ans = Math . max ( ans , t - s + 1 ) ; } } System . out . println ( ans ) ; } }

import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] a = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = sc . nextInt ( ) ; } Set < Integer > s = new HashSet < > ( ) ; long ans = syakutori ( a , n , s ) ; System . out . println ( ans ) ; } public static long syakutori ( int [ ] a , int n , Set < Integer > s ) { int right = 0 ; long res = 0 ; long sum = 0 ; for ( int left = 0 ; left < n ; left ++ ) { while ( right < n && ! s . contains ( a [ right ] ) ) { s . add ( a [ right ] ) ; right ++ ; } res = Math . max ( res , right - left ) ; if ( left >= right ) { right ++ ; continue ; } s . remove ( a [ left ] ) ; } return res ; } }

N = int ( input ( ) ) NEW_LINE a = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE ans , l , count , _set = 1 , 0 , 1 , { a [ 0 ] } NEW_LINE add , remove = _set . add , _set . remove NEW_LINE for n in a [ 1 : ] : NEW_LINE INDENT while n in _set : NEW_LINE INDENT remove ( a [ l ] ) NEW_LINE count -= 1 NEW_LINE l += 1 NEW_LINE DEDENT add ( n ) NEW_LINE count += 1 NEW_LINE if ans < count : NEW_LINE INDENT ans = count NEW_LINE DEDENT DEDENT print ( ans ) NEW_LINE

def b_candy ( N , A ) : NEW_LINE INDENT right = 0 NEW_LINE ans = 0 NEW_LINE chosen_candy = set ( ) NEW_LINE for left in range ( N ) : NEW_LINE INDENT while right < N and not ( A [ right ] in chosen_candy ) : NEW_LINE INDENT chosen_candy . add ( A [ right ] ) NEW_LINE right += 1 NEW_LINE DEDENT chosen_candy . remove ( A [ left ] ) NEW_LINE ans = max ( right - left , ans ) NEW_LINE DEDENT return ans NEW_LINE DEDENT N = int ( input ( ) ) NEW_LINE A = [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE print ( b_candy ( N , A ) ) NEW_LINE

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 s = set ( ) NEW_LINE le = 0 NEW_LINE ans = 0 NEW_LINE r = 0 NEW_LINE l = 0 NEW_LINE while l < N and r < N : NEW_LINE INDENT if not A [ r ] in s : NEW_LINE INDENT s . add ( A [ r ] ) NEW_LINE r += 1 NEW_LINE DEDENT else : NEW_LINE INDENT s . remove ( A [ l ] ) NEW_LINE ans = max ( ans , r - l ) NEW_LINE l += 1 NEW_LINE DEDENT DEDENT ans = max ( r - l , ans ) NEW_LINE print ( ans ) NEW_LINE

N = int ( input ( ) ) NEW_LINE A = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE bf = [ - 1 for i in range ( 10 ** 5 + 1 ) ] NEW_LINE bfn = 0 NEW_LINE ans = 1 NEW_LINE for i in range ( N ) : NEW_LINE INDENT if bf [ A [ i ] ] == - 1 : NEW_LINE INDENT bf [ A [ i ] ] = i NEW_LINE ans = max ( ans , i - bfn + 1 ) NEW_LINE DEDENT else : NEW_LINE INDENT if ( bfn == 0 ) : NEW_LINE INDENT ans = max ( ans , i - bf [ A [ i ] ] ) NEW_LINE bfn = bf [ A [ i ] ] + 1 NEW_LINE bf [ A [ i ] ] = i NEW_LINE DEDENT else : NEW_LINE INDENT if ( bfn > bf [ A [ i ] ] ) : NEW_LINE INDENT ans = max ( ans , i - bfn + 1 ) NEW_LINE bf [ A [ i ] ] = i NEW_LINE DEDENT elif bfn == bf [ A [ i ] ] : NEW_LINE INDENT ans = max ( ans , i - bfn ) NEW_LINE bfn = bf [ A [ i ] ] + 1 NEW_LINE bf [ A [ i ] ] = i NEW_LINE DEDENT else : NEW_LINE INDENT ans = max ( ans , i - bf [ A [ i ] ] ) NEW_LINE bfn = bf [ A [ i ] ] + 1 NEW_LINE bf [ A [ i ] ] = i NEW_LINE DEDENT DEDENT DEDENT DEDENT print ( ans ) NEW_LINE

def func ( n , a ) : NEW_LINE INDENT table = [ 0 for _ in range ( 10 ** 6 ) ] NEW_LINE under = 0 NEW_LINE top = 0 NEW_LINE length = 0 NEW_LINE while under < len ( a ) and top < len ( a ) : NEW_LINE INDENT while top < len ( a ) and table [ a [ top ] ] == 0 : NEW_LINE INDENT table [ a [ top ] ] = 1 NEW_LINE top += 1 NEW_LINE DEDENT length = max ( length , top - under ) NEW_LINE while under < top < len ( a ) and table [ a [ top ] ] > 0 : NEW_LINE INDENT table [ a [ under ] ] -= 1 NEW_LINE under += 1 NEW_LINE DEDENT DEDENT print ( length ) NEW_LINE DEDENT n = int ( input ( ) ) NEW_LINE a = [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE func ( n , a ) NEW_LINE


import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { new Main ( ) . solve ( ) ; } int n , k ; int [ ] v ; String [ ] w ; int [ ] table ; String [ ] ans ; void solve ( ) { Scanner sc = new Scanner ( System . in ) ; k = sc . nextInt ( ) ; n = sc . nextInt ( ) ; v = new int [ n ] ; w = new String [ n ] ; ans = new String [ k + 1 ] ; for ( int i = 0 ; i < n ; i ++ ) { v [ i ] = sc . nextInt ( ) ; w [ i ] = sc . next ( ) ; } table = new int [ k + 1 ] ; for ( int i = 0 ; i < Math . pow ( 3 , k ) ; i ++ ) { int ni = i ; for ( int j = 0 ; j < k ; j ++ ) { int p = ni % 3 + 1 ; ni /= 3 ; table [ j + 1 ] = p ; } if ( check ( ) ) { for ( int p = 0 ; p < n ; p ++ ) { int count = 0 ; int vp = v [ p ] ; while ( vp > 0 ) { count += table [ vp % 10 ] ; String wi = w [ p ] ; int begin = wi . length ( ) - count ; int end = begin + table [ vp % 10 ] ; ans [ vp % 10 ] = wi . substring ( begin , end ) ; vp /= 10 ; } } for ( int q = 1 ; q <= k ; q ++ ) { System . out . println ( ans [ q ] ) ; } return ; } } } boolean check ( ) { for ( int i = 0 ; i < n ; i ++ ) { int count = 0 ; int vi = v [ i ] ; while ( vi > 0 ) { count += table [ vi % 10 ] ; vi /= 10 ; } if ( count != w [ i ] . length ( ) ) return false ; } return true ; } }

k , n = map ( int , input ( ) . split ( ) ) NEW_LINE vw = [ ] NEW_LINE for _ in range ( n ) : NEW_LINE INDENT a , b = input ( ) . split ( ) NEW_LINE vw . append ( [ list ( map ( lambda x : int ( x ) - 1 , list ( a ) ) ) , list ( b ) ] ) NEW_LINE DEDENT d = [ 0 ] * k NEW_LINE while 1 : NEW_LINE INDENT for i in range ( k - 1 ) : NEW_LINE INDENT if d [ i ] == 3 : NEW_LINE INDENT d [ i ] = 0 NEW_LINE d [ i + 1 ] += 1 NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT if d [ k - 1 ] >= 3 : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT c = [ [ ] for _ in range ( k ) ] NEW_LINE flag = 0 NEW_LINE for v , w in vw : NEW_LINE INDENT p = 0 NEW_LINE for x in v : NEW_LINE INDENT if p + d [ x ] >= len ( w ) : NEW_LINE INDENT flag = 1 NEW_LINE break NEW_LINE DEDENT elif len ( c [ x ] ) > 0 : NEW_LINE INDENT if ' ' . join ( c [ x ] ) != ' ' . join ( w [ p : p + d [ x ] + 1 ] ) : NEW_LINE INDENT flag = 1 NEW_LINE break NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT c [ x ] = [ ] + w [ p : p + d [ x ] + 1 ] NEW_LINE DEDENT p += d [ x ] + 1 NEW_LINE DEDENT if p != len ( w ) : NEW_LINE INDENT flag = 1 NEW_LINE break NEW_LINE DEDENT elif flag == 1 : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT if flag == 0 : NEW_LINE INDENT break NEW_LINE DEDENT d [ 0 ] += 1 NEW_LINE DEDENT for x in c : NEW_LINE INDENT print ( ' ' . join ( x ) ) NEW_LINE DEDENT

def goro_awase ( K : int , N : int , goro : list ) -> list : NEW_LINE INDENT for i in range ( 3 ** K ) : NEW_LINE INDENT d = { } NEW_LINE for k in range ( K ) : NEW_LINE INDENT d [ k + 1 ] = ( i % 3 ) + 1 NEW_LINE i //= 3 NEW_LINE DEDENT for n , w in goro : NEW_LINE INDENT assumpt_len = 0 NEW_LINE while n > 0 : NEW_LINE INDENT assumpt_len += d [ n % 10 ] NEW_LINE n //= 10 NEW_LINE DEDENT if assumpt_len != len ( w ) : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT res = { } NEW_LINE for n , w in goro : NEW_LINE INDENT idx = 0 NEW_LINE digits = [ ] NEW_LINE while n > 0 : NEW_LINE INDENT k = n % 10 NEW_LINE n //= 10 NEW_LINE digits . append ( k ) NEW_LINE DEDENT for k in reversed ( digits ) : NEW_LINE INDENT sk = w [ idx : idx + d [ k ] ] NEW_LINE idx = idx + d [ k ] NEW_LINE if k in res and res [ k ] != sk : NEW_LINE INDENT break NEW_LINE DEDENT res [ k ] = sk NEW_LINE DEDENT else : NEW_LINE INDENT continue NEW_LINE DEDENT break NEW_LINE DEDENT else : NEW_LINE INDENT return res NEW_LINE DEDENT DEDENT DEDENT return None NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT N = 0 NEW_LINE K , N = map ( int , input ( ) . split ( ) ) NEW_LINE goro = [ ] NEW_LINE for _ in range ( N ) : NEW_LINE INDENT v , w = input ( ) . split ( ) NEW_LINE goro . append ( ( int ( v ) , w ) ) NEW_LINE DEDENT ans = goro_awase ( K , N , goro ) NEW_LINE if ans is None : NEW_LINE INDENT raise Exception ( ' error ' ) NEW_LINE DEDENT else : NEW_LINE INDENT for _ , s in sorted ( ans . items ( ) ) : NEW_LINE INDENT print ( s ) NEW_LINE DEDENT DEDENT DEDENT

def dfs ( i , f ) : NEW_LINE INDENT global K , N , vw , num NEW_LINE if i < 10 : NEW_LINE INDENT if not f : NEW_LINE INDENT num [ i ] = 1 NEW_LINE f = dfs ( i + 1 , f ) NEW_LINE DEDENT if not f : NEW_LINE INDENT num [ i ] = 2 NEW_LINE f = dfs ( i + 1 , f ) NEW_LINE DEDENT if not f : NEW_LINE INDENT num [ i ] = 3 NEW_LINE f = dfs ( i + 1 , f ) NEW_LINE DEDENT return f NEW_LINE DEDENT else : NEW_LINE INDENT ans = [ " " for _ in range ( 10 ) ] NEW_LINE for j in range ( N ) : NEW_LINE INDENT s = vw [ j ] [ 1 ] NEW_LINE for k in range ( len ( vw [ j ] [ 0 ] ) ) : NEW_LINE INDENT if len ( s ) < num [ int ( vw [ j ] [ 0 ] [ k ] ) ] : NEW_LINE INDENT return False NEW_LINE DEDENT if ans [ int ( vw [ j ] [ 0 ] [ k ] ) ] == " " : NEW_LINE INDENT ans [ int ( vw [ j ] [ 0 ] [ k ] ) ] = s [ : num [ int ( vw [ j ] [ 0 ] [ k ] ) ] ] NEW_LINE s = s [ num [ int ( vw [ j ] [ 0 ] [ k ] ) ] : ] NEW_LINE DEDENT else : NEW_LINE INDENT if ans [ int ( vw [ j ] [ 0 ] [ k ] ) ] != s [ : num [ int ( vw [ j ] [ 0 ] [ k ] ) ] ] : NEW_LINE INDENT return False NEW_LINE DEDENT s = s [ num [ int ( vw [ j ] [ 0 ] [ k ] ) ] : ] NEW_LINE DEDENT DEDENT if s != " " : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT for j in range ( 1 , K + 1 ) : NEW_LINE INDENT print ( ans [ j ] ) NEW_LINE DEDENT return True NEW_LINE DEDENT DEDENT K , N = map ( int , input ( ) . split ( ) ) NEW_LINE vw = [ input ( ) . split ( ) for _ in range ( N ) ] NEW_LINE num = [ 0 for _ in range ( 10 ) ] NEW_LINE dfs ( 1 , False ) NEW_LINE

K , N = map ( int , input ( ) . split ( ) ) NEW_LINE vs = [ None ] * N NEW_LINE ws = [ None ] * N NEW_LINE num = [ 0 ] * K NEW_LINE def solve ( ) : NEW_LINE INDENT ans = [ None ] * K NEW_LINE for v , w in zip ( vs , ws ) : NEW_LINE INDENT cur = 0 NEW_LINE for n in map ( lambda x : int ( x ) - 1 , v ) : NEW_LINE INDENT if ans [ n ] is not None and ans [ n ] != w [ cur : cur + num [ n ] ] : NEW_LINE INDENT return None NEW_LINE DEDENT ans [ n ] = w [ cur : cur + num [ n ] ] NEW_LINE cur += num [ n ] NEW_LINE DEDENT if cur != len ( w ) : NEW_LINE INDENT return None NEW_LINE DEDENT DEDENT return ans NEW_LINE DEDENT def dfs ( k ) : NEW_LINE INDENT if k == K : NEW_LINE INDENT return solve ( ) NEW_LINE DEDENT for i in range ( 3 ) : NEW_LINE INDENT num [ k ] = i + 1 NEW_LINE ans = dfs ( k + 1 ) NEW_LINE if ans is not None : NEW_LINE INDENT return ans NEW_LINE DEDENT DEDENT DEDENT for i in range ( N ) : NEW_LINE INDENT vs [ i ] , ws [ i ] = input ( ) . split ( ) NEW_LINE DEDENT print ( * dfs ( 0 ) , sep = ' \n ' ) NEW_LINE

from itertools import product NEW_LINE k , n = ( int ( i ) for i in input ( ) . split ( ) ) NEW_LINE x = [ [ i for i in input ( ) . split ( ) ] for i in range ( n ) ] NEW_LINE for i in range ( n ) : NEW_LINE INDENT y = [ ] NEW_LINE for j in x [ i ] [ 0 ] : y . append ( int ( j ) ) NEW_LINE x [ i ] [ 0 ] = y NEW_LINE DEDENT def match ( q ) : NEW_LINE INDENT ans = True NEW_LINE for i , j in x : NEW_LINE INDENT num = 0 NEW_LINE for i2 in i : num += q [ i2 - 1 ] NEW_LINE if len ( j ) != num : NEW_LINE INDENT ans = False NEW_LINE break NEW_LINE DEDENT DEDENT return ans NEW_LINE DEDENT def match2 ( q ) : NEW_LINE INDENT if match ( q ) : NEW_LINE INDENT w = [ " " for i in range ( k ) ] NEW_LINE for i , j in x : NEW_LINE INDENT num = 0 NEW_LINE for i2 in i : NEW_LINE INDENT if w [ i2 - 1 ] == " " or w [ i2 - 1 ] == j [ num : num + q [ i2 - 1 ] ] : NEW_LINE INDENT w [ i2 - 1 ] = j [ num : num + q [ i2 - 1 ] ] NEW_LINE num += q [ i2 - 1 ] NEW_LINE DEDENT else : NEW_LINE INDENT w = [ ] NEW_LINE break NEW_LINE DEDENT DEDENT DEDENT return w NEW_LINE DEDENT else : return False NEW_LINE DEDENT for i in product ( range ( 1 , 4 ) , repeat = k ) : NEW_LINE INDENT m = match2 ( i ) NEW_LINE if m : NEW_LINE INDENT for j in m : print ( j ) NEW_LINE break NEW_LINE DEDENT DEDENT


import java . io . InputStream ; import java . io . PrintStream ; import java . util . Scanner ; public class Main { InputStream in = System . in ; PrintStream out = System . out ; int calcH ( int cx , int cy , int x , int y , int h ) { return h + Math . abs ( cx - x ) + Math . abs ( cy - y ) ; } boolean check ( int cx , int cy , int ch , int x , int y , int h ) { if ( h > 0 ) { return ch == calcH ( cx , cy , x , y , h ) ; } else { return ch <= calcH ( cx , cy , x , y , h ) ; } } public void _main ( String [ ] args ) { Scanner sc = new Scanner ( in ) ; int N = sc . nextInt ( ) ; int [ ] [ ] xyh = new int [ N ] [ 3 ] ; for ( int i = 0 ; i < N ; i ++ ) { xyh [ i ] = new int [ ] { sc . nextInt ( ) , sc . nextInt ( ) , sc . nextInt ( ) } ; } sc . close ( ) ; int p = - 1 ; for ( int i = 0 ; i < N ; i ++ ) { if ( xyh [ i ] [ 2 ] > 0 ) { p = i ; break ; } } for ( int cx = 0 ; cx <= 100 ; cx ++ ) { for ( int cy = 0 ; cy <= 100 ; cy ++ ) next_point : { int H = calcH ( cx , cy , xyh [ p ] [ 0 ] , xyh [ p ] [ 1 ] , xyh [ p ] [ 2 ] ) ; for ( int i = 0 ; i < N ; i ++ ) { if ( ! check ( cx , cy , H , xyh [ i ] [ 0 ] , xyh [ i ] [ 1 ] , xyh [ i ] [ 2 ] ) ) { break next_point ; } } out . println ( cx + " ▁ " + cy + " ▁ " + H ) ; return ; } } } public static void main ( String [ ] args ) { new Main ( ) . _main ( args ) ; } }

import java . util . * ; public class Main { static Scanner sc = new Scanner ( System . in ) ; static long nextLong ( ) { return Long . parseLong ( sc . next ( ) ) ; } public static void main ( String [ ] args ) { int N = sc . nextInt ( ) ; long [ ] [ ] values = new long [ N ] [ 3 ] ; for ( int i = 0 ; i < N ; i ++ ) { values [ i ] = new long [ ] { nextLong ( ) , nextLong ( ) , nextLong ( ) } ; } String ans = null ; for ( int i = 0 ; i <= 100 ; i ++ ) { for ( int j = 0 ; j <= 100 ; j ++ ) { int [ ] centerPosi = new int [ ] { i , j } ; long H = 0 ; for ( int k = 0 ; k < N ; k ++ ) { long x = values [ k ] [ 0 ] ; long y = values [ k ] [ 1 ] ; long h = values [ k ] [ 2 ] ; if ( h != 0 ) { H = h + Math . abs ( centerPosi [ 0 ] - x ) + Math . abs ( centerPosi [ 1 ] - y ) ; break ; } } boolean isOK = true ; for ( int k = 0 ; k < N ; k ++ ) { long x = values [ k ] [ 0 ] ; long y = values [ k ] [ 1 ] ; long h = values [ k ] [ 2 ] ; long estimatedH = Math . max ( ( H - Math . abs ( x - centerPosi [ 0 ] ) - Math . abs ( y - centerPosi [ 1 ] ) ) , 0 ) ; isOK = isOK && ( estimatedH == h ) ; } if ( isOK ) { ans = i + " ▁ " + j + " ▁ " + H ; } } } System . out . println ( ans ) ; } }

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 ( ) ; Point [ ] points = new Point [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { points [ i ] = new Point ( sc . nextInt ( ) , sc . nextInt ( ) , sc . nextInt ( ) ) ; } sc . close ( ) ; int ansX = - 1 ; int ansY = - 1 ; int ansH = - 1 ; label : for ( int x = 0 ; x < 101 ; x ++ ) { for ( int y = 0 ; y < 101 ; y ++ ) { int baseH = - 1 ; boolean flg = true ; for ( int i = 0 ; i < n ; i ++ ) { if ( points [ i ] . h > 0 ) { int h = points [ i ] . h + Math . abs ( x - points [ i ] . x ) + Math . abs ( y - points [ i ] . y ) ; if ( baseH == - 1 ) { baseH = h ; } else if ( baseH != h ) { flg = false ; break ; } } } if ( flg ) { for ( int i = 0 ; i < n ; i ++ ) { if ( points [ i ] . h == 0 ) { if ( baseH > Math . abs ( x - points [ i ] . x ) + Math . abs ( y - points [ i ] . y ) ) { flg = false ; break ; } } } if ( ! flg ) { continue ; } ansX = x ; ansY = y ; ansH = baseH ; break label ; } } } System . out . println ( ansX + " ▁ " + ansY + " ▁ " + ansH ) ; } static class Point { int x ; int y ; int h ; public Point ( int x , int y , int h ) { this . x = x ; this . y = y ; this . h = h ; } } }

import java . util . stream . IntStream ; public class Main { private static java . util . Scanner scanner = new java . util . Scanner ( System . in ) ; public static void main ( String [ ] args ) { int n = scanner . nextInt ( ) ; int [ ] xa = new int [ n ] , ya = new int [ n ] , ha = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { xa [ i ] = scanner . nextInt ( ) ; ya [ i ] = scanner . nextInt ( ) ; ha [ i ] = scanner . nextInt ( ) ; } for ( int x = 0 ; x <= 100 ; x ++ ) { for ( int y = 0 ; y <= 100 ; y ++ ) { int x1 = x , y1 = y , h = IntStream . range ( 0 , n ) . filter ( k -> ha [ k ] != 0 ) . reduce ( 0 , ( l , i ) -> ha [ i ] + Math . abs ( xa [ i ] - x1 ) + Math . abs ( ya [ i ] - y1 ) ) ; if ( IntStream . range ( 0 , n ) . allMatch ( k -> ha [ k ] == Math . max ( h - Math . abs ( xa [ k ] - x1 ) - Math . abs ( ya [ k ] - y1 ) , 0 ) ) ) System . out . printf ( " % s ▁ % s ▁ % s \n " , x , y , h ) ; } } } }

import java . util . * ; import static java . lang . System . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int [ ] x = new int [ N ] ; int [ ] y = new int [ N ] ; int [ ] h = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { x [ i ] = sc . nextInt ( ) ; y [ i ] = sc . nextInt ( ) ; h [ i ] = sc . nextInt ( ) ; } for ( int cx = 0 ; cx <= 100 ; cx ++ ) { for ( int cy = 0 ; cy <= 100 ; cy ++ ) { int H = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( h [ i ] != 0 ) { H = h [ i ] + Math . abs ( x [ i ] - cx ) + Math . abs ( y [ i ] - cy ) ; break ; } } boolean isAns = true ; for ( int i = 0 ; i < N ; i ++ ) { int htmp = Math . max ( H - Math . abs ( x [ i ] - cx ) - Math . abs ( y [ i ] - cy ) , 0 ) ; if ( htmp != h [ i ] ) { isAns = false ; break ; } } if ( isAns ) { out . println ( cx + " ▁ " + cy + " ▁ " + H ) ; return ; } } } } }

import sys NEW_LINE write = sys . stdout . write NEW_LINE def valid ( x , y ) : NEW_LINE INDENT H = info [ nzpoint ] [ 2 ] + abs ( info [ nzpoint ] [ 0 ] - x ) + abs ( info [ nzpoint ] [ 1 ] - y ) NEW_LINE for i in range ( N ) : NEW_LINE INDENT if i == nzpoint : NEW_LINE INDENT continue NEW_LINE DEDENT if max ( 0 , H - abs ( x - info [ i ] [ 0 ] ) - abs ( y - info [ i ] [ 1 ] ) ) != info [ i ] [ 2 ] : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT return True NEW_LINE DEDENT def printheight ( i , j ) : NEW_LINE INDENT write ( str ( info [ nzpoint ] [ 2 ] + abs ( i - info [ nzpoint ] [ 0 ] ) + abs ( j - info [ nzpoint ] [ 1 ] ) ) + " \n " ) NEW_LINE DEDENT N = int ( input ( ) ) NEW_LINE info = [ ] NEW_LINE nzpoint = 0 NEW_LINE for i in range ( N ) : NEW_LINE INDENT info . append ( list ( map ( int , input ( ) . split ( ) ) ) ) NEW_LINE if info [ i ] [ 2 ] > 0 : NEW_LINE INDENT nzpoint = i NEW_LINE DEDENT DEDENT for i in range ( 101 ) : NEW_LINE INDENT for j in range ( 101 ) : NEW_LINE INDENT if valid ( i , j ) : NEW_LINE INDENT write ( str ( i ) + " ▁ " + str ( j ) + " ▁ " ) NEW_LINE printheight ( i , j ) NEW_LINE sys . exit ( ) NEW_LINE DEDENT DEDENT DEDENT

class Info ( ) : NEW_LINE INDENT def __init__ ( self , x , y , h ) : NEW_LINE INDENT self . X = x NEW_LINE self . Y = y NEW_LINE self . H = h NEW_LINE DEDENT DEDENT def main ( ) : NEW_LINE INDENT N = int ( input ( ) ) NEW_LINE infos = [ ] NEW_LINE for i in range ( N ) : NEW_LINE INDENT x , y , h = list ( map ( int , input ( ) . split ( " ▁ " ) ) ) NEW_LINE infos . append ( Info ( x , y , h ) ) NEW_LINE DEDENT MAX = 100 NEW_LINE for posY in range ( 0 , MAX + 1 ) : NEW_LINE INDENT for posX in range ( 0 , MAX + 1 ) : NEW_LINE INDENT ans_h = - 1 NEW_LINE for i in range ( N ) : NEW_LINE INDENT if infos [ i ] . H > 0 : NEW_LINE INDENT H = infos [ i ] . H + abs ( posY - infos [ i ] . Y ) + abs ( posX - infos [ i ] . X ) NEW_LINE if ans_h == - 1 : NEW_LINE INDENT ans_h = H NEW_LINE DEDENT else : NEW_LINE INDENT if ans_h != H : NEW_LINE INDENT ans_h = - 2 NEW_LINE break NEW_LINE DEDENT DEDENT DEDENT DEDENT if ans_h == - 2 : NEW_LINE INDENT continue NEW_LINE DEDENT is_ok = True NEW_LINE for i in range ( N ) : NEW_LINE INDENT if infos [ i ] . H == 0 : NEW_LINE INDENT if ans_h - abs ( posY - infos [ i ] . Y ) - abs ( posX - infos [ i ] . X ) <= 0 : NEW_LINE INDENT continue NEW_LINE DEDENT else : NEW_LINE INDENT is_ok = False NEW_LINE break NEW_LINE DEDENT DEDENT DEDENT if is_ok : NEW_LINE INDENT print ( posX , posY , ans_h ) NEW_LINE return NEW_LINE DEDENT DEDENT DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT

import sys NEW_LINE INF = float ( " inf " ) NEW_LINE def solve ( N : int , x : " List [ int ] " , y : " List [ int ] " , h : " List [ int ] " ) : NEW_LINE INDENT for i in range ( N ) : NEW_LINE INDENT if h [ i ] > 0 : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT cand = [ [ 0 ] * 101 for _ in range ( 101 ) ] NEW_LINE for j in range ( 101 ) : NEW_LINE INDENT for k in range ( 101 ) : NEW_LINE INDENT cand [ j ] [ k ] = h [ i ] + abs ( x [ i ] - k ) + abs ( y [ i ] - j ) NEW_LINE DEDENT DEDENT for i in range ( 101 ) : NEW_LINE INDENT for j in range ( 101 ) : NEW_LINE INDENT flags = [ max ( cand [ i ] [ j ] - abs ( x [ k ] - j ) - abs ( y [ k ] - i ) , 0 ) == h [ k ] for k in range ( N ) ] NEW_LINE if all ( flags ) : NEW_LINE INDENT print ( j , i , cand [ i ] [ j ] ) NEW_LINE return NEW_LINE DEDENT DEDENT DEDENT return NEW_LINE DEDENT def main ( ) : NEW_LINE INDENT def iterate_tokens ( ) : NEW_LINE INDENT for line in sys . stdin : NEW_LINE INDENT for word in line . split ( ) : NEW_LINE INDENT yield word NEW_LINE DEDENT DEDENT DEDENT tokens = iterate_tokens ( ) NEW_LINE N = int ( next ( tokens ) ) NEW_LINE x = [ int ( ) ] * ( N ) NEW_LINE y = [ int ( ) ] * ( N ) NEW_LINE h = [ int ( ) ] * ( N ) NEW_LINE for i in range ( N ) : NEW_LINE INDENT x [ i ] = int ( next ( tokens ) ) NEW_LINE y [ i ] = int ( next ( tokens ) ) NEW_LINE h [ i ] = int ( next ( tokens ) ) NEW_LINE DEDENT solve ( N , x , y , h ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT

A = abs ; p = eval ( ' list ( map ( int , input ( ) . split ( ) ) ) , ' * int ( input ( ) ) ) ; x , y , h = [ x for x in p if x [ 2 ] ] [ 0 ] NEW_LINE for I in range ( 10201 ) : j , i = I // 101 , I % 101 ; H = h + A ( x - j ) + A ( y - i ) ; print ( * ( j , i , H ) * all ( u == max ( H - A ( s - j ) - A ( t - i ) , 0 ) for s , t , u in p ) ) NEW_LINE

from itertools import * NEW_LINE n = int ( input ( ) ) NEW_LINE xyh = [ ] NEW_LINE for i in range ( n ) : NEW_LINE INDENT xyh += [ list ( map ( int , input ( ) . split ( ) ) ) ] NEW_LINE DEDENT xyh . sort ( reverse = True , key = lambda x : x [ 2 ] ) NEW_LINE [ x0 , y0 , h0 ] = xyh [ 0 ] NEW_LINE for x , y in product ( range ( 0 , 101 ) , range ( 0 , 101 ) ) : NEW_LINE INDENT h = h0 + abs ( x - x0 ) + abs ( y - y0 ) NEW_LINE for k in xyh [ 1 : ] : NEW_LINE INDENT if k [ 2 ] != max ( h - abs ( x - k [ 0 ] ) - abs ( y - k [ 1 ] ) , 0 ) : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT print ( x , y , h ) NEW_LINE


import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . util . StringTokenizer ; public class Main { public static void main ( String [ ] args ) throws Exception { BufferedReader input = new BufferedReader ( new InputStreamReader ( System . in ) ) ; StringTokenizer tokenizer = new StringTokenizer ( input . readLine ( ) ) ; int a = Integer . parseInt ( tokenizer . nextToken ( ) ) ; int b = Integer . parseInt ( tokenizer . nextToken ( ) ) ; String word = input . readLine ( ) ; int size = 0 ; boolean correct = true ; boolean foundMinuse = false ; for ( int i = 0 ; i < word . length ( ) ; i ++ ) { if ( Character . isDigit ( word . charAt ( i ) ) ) { size ++ ; } else { if ( size != a ) { correct = false ; break ; } size = 0 ; foundMinuse = true ; } } if ( foundMinuse && size == b ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } }

import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int length = a + b + 1 ; String post = sc . next ( ) ; char c = post . charAt ( a ) ; String start = post . substring ( 0 , a ) ; String end = post . substring ( a + 1 , post . length ( ) ) ; String ans = " " ; if ( post . length ( ) == length ) { if ( c == ' - ' ) { if ( start . contains ( " - " ) || end . contains ( " - " ) ) { ans = " No " ; } else { ans = " Yes " ; } } else { ans = " No " ; } } else { ans = " No " ; } System . out . println ( ans ) ; } }

import java . util . * ; public class Main { public static void main ( String [ ] args ) { boolean j = true ; Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; String s = sc . next ( ) ; String [ ] strArray = s . split ( " " ) ; if ( strArray . length != a + b + 1 ) j = false ; if ( strArray [ a ] . equals ( " - " ) ) { for ( int i = 0 ; i < strArray . length ; i ++ ) { if ( i != a ) { if ( ! ( strArray [ i ] . equals ( " - " ) ) ) { int x = Integer . parseInt ( strArray [ i ] ) ; if ( x >= 10 && x < 0 ) j = false ; } else j = false ; } } } else j = false ; if ( j ) System . out . println ( " Yes " ) ; else if ( ! j ) System . out . println ( " No " ) ; sc . close ( ) ; } }

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

import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; int A = sc . nextInt ( ) ; int B = sc . nextInt ( ) ; String S = sc . next ( ) ; if ( S . substring ( 0 , A ) . contains ( " - " ) ) { System . out . println ( " No " ) ; return ; } if ( ! ( S . substring ( A , A + 1 ) . contains ( " - " ) ) ) { System . out . println ( " No " ) ; return ; } if ( S . substring ( A + 1 , A + B + 1 ) . contains ( " - " ) ) { System . out . println ( " No " ) ; return ; } System . out . println ( " Yes " ) ; } }

n , m = map ( int , input ( ) . split ( ) ) NEW_LINE s = input ( ) NEW_LINE flag = True NEW_LINE if s [ n : n + 1 ] != ' - ' : NEW_LINE INDENT flag = False NEW_LINE DEDENT for i in range ( n ) : NEW_LINE INDENT if s [ i ] == ' - ' : NEW_LINE INDENT flag = False NEW_LINE DEDENT DEDENT for i in range ( n + 1 , len ( s ) ) : NEW_LINE INDENT if s [ i ] == ' - ' : NEW_LINE INDENT flag = False NEW_LINE DEDENT DEDENT if flag : NEW_LINE INDENT print ( ' Yes ' ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( ' No ' ) NEW_LINE DEDENT

a , s = open ( 0 ) ; print ( ' YNeos ' [ s . count ( ' - ' ) != 1 or ' - ' < s [ int ( a [ 0 ] ) ] : : 2 ] ) NEW_LINE

A , B = map ( int , input ( ) . split ( ) ) NEW_LINE S = list ( input ( ) ) NEW_LINE suji = [ str ( i ) for i in range ( 0 , 10 ) ] NEW_LINE try : NEW_LINE INDENT a = int ( " " . join ( S [ : A ] ) ) NEW_LINE b = int ( " " . join ( S [ B : ] ) ) NEW_LINE if ( S [ A ] in suji ) : NEW_LINE INDENT print ( " No " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " Yes " ) NEW_LINE DEDENT DEDENT except : NEW_LINE INDENT print ( " No " ) NEW_LINE DEDENT

import sys NEW_LINE a , b = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE x = input ( ) NEW_LINE if not ( x [ 0 : a ] . isdigit ( ) ) & ( len ( x [ 0 : a ] ) == a ) : NEW_LINE INDENT print ( ' No ' ) NEW_LINE sys . exit ( ) NEW_LINE DEDENT if x [ a ] != ' - ' : NEW_LINE INDENT print ( ' No ' ) NEW_LINE sys . exit ( ) NEW_LINE DEDENT if not ( x [ a + 1 : a + 1 + b ] . isdigit ( ) ) & ( len ( x [ a + 1 : a + 1 + b ] ) == b ) : NEW_LINE INDENT print ( ' No ' ) NEW_LINE sys . exit ( ) NEW_LINE DEDENT print ( ' Yes ' ) NEW_LINE

import re NEW_LINE a , b = [ int ( _ ) for _ in input ( ) . split ( ) ] NEW_LINE s = input ( ) NEW_LINE m = re . match ( ' [ 0-9 ] { { { 0 } } } - [0-9 ] { { { 1 } } } ' . format ( a , b ) , s ) NEW_LINE print ( ' Yes ' if m else ' No ' ) NEW_LINE


import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; for ( int i = 0 ; i < s . length ( ) - 1 ; i ++ ) { if ( s . charAt ( i ) == s . charAt ( i + 1 ) ) { System . out . println ( ( i + 1 ) + " ▁ " + ( i + 2 ) ) ; return ; } } for ( int i = 0 ; i < s . length ( ) - 2 ; i ++ ) { if ( s . charAt ( i ) == s . charAt ( i + 2 ) ) { System . out . println ( ( i + 1 ) + " ▁ " + ( i + 3 ) ) ; return ; } } System . out . println ( " - 1 ▁ - 1" ) ; } }

import java . io . OutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . PrintWriter ; import java . util . StringTokenizer ; import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . io . InputStream ; public class Main { public static void main ( String [ ] args ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; InputReader in = new InputReader ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; TaskD solver = new TaskD ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class TaskD { public void solve ( int testNumber , InputReader in , PrintWriter out ) { String s = in . nextLine ( ) ; if ( s . length ( ) >= 2 ) { for ( int i = 0 ; i < s . length ( ) - 1 ; i ++ ) { if ( s . charAt ( i ) == s . charAt ( i + 1 ) ) { out . println ( ( i + 1 ) + " ▁ " + ( i + 2 ) ) ; return ; } if ( i + 2 < s . length ( ) && s . charAt ( i ) == s . charAt ( i + 2 ) ) { out . println ( ( i + 1 ) + " ▁ " + ( i + 3 ) ) ; return ; } } } out . println ( " - 1 ▁ - 1" ) ; } } static class InputReader { public BufferedReader reader ; public StringTokenizer tokenizer ; public InputReader ( InputStream stream ) { reader = new BufferedReader ( new InputStreamReader ( stream ) , 32768 ) ; tokenizer = null ; } public String nextLine ( ) { try { return reader . readLine ( ) ; } catch ( Exception e ) { throw new RuntimeException ( e ) ; } } } }

import java . util . * ; import java . lang . * ; import java . io . * ; public class Main { public static int maxOfArray ( int [ ] a ) { int ans = a [ 0 ] ; for ( int i = 1 ; i < a . length ; i ++ ) { if ( a [ i ] > ans ) ans = a [ i ] ; } return ans ; } public static int minOfArray ( int [ ] a ) { int ans = a [ 0 ] ; for ( int i = 1 ; i < a . length ; i ++ ) { if ( a [ i ] < ans ) ans = a [ i ] ; } return ans ; } public static boolean unbalanced ( String s ) { int [ ] count = new int [ 26 ] ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { count [ s . charAt ( i ) - ' a ' ] ++ ; } return maxOfArray ( count ) > s . length ( ) / 2 ; } public static String solve ( String s ) { if ( s . length ( ) < 3 ) return ( unbalanced ( s ) ? "1 ▁ 2" : " - 1 ▁ - 1" ) ; for ( int i = 0 ; i < s . length ( ) - 2 ; i ++ ) { if ( unbalanced ( s . substring ( i , i + 3 ) ) ) return ( ( i + 1 ) + " ▁ " + ( i + 3 ) ) ; } return " - 1 ▁ - 1" ; } public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; System . out . println ( solve ( s ) ) ; } }

import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String t = sc . next ( ) ; sc . close ( ) ; int n = t . length ( ) ; if ( n == 2 ) { if ( t . charAt ( 0 ) == t . charAt ( 1 ) ) { System . out . println ( "1 ▁ 2" ) ; } else { System . out . println ( " - 1 ▁ - 1" ) ; } System . exit ( 0 ) ; } for ( int i = 0 ; i < n - 2 ; i ++ ) { char c0 = t . charAt ( i ) ; char c1 = t . charAt ( i + 1 ) ; char c2 = t . charAt ( i + 2 ) ; int [ ] k = new int [ 26 ] ; k [ ( int ) ( c0 - ' a ' ) ] ++ ; k [ ( int ) ( c1 - ' a ' ) ] ++ ; k [ ( int ) ( c2 - ' a ' ) ] ++ ; Arrays . sort ( k ) ; if ( k [ 25 ] == 2 ) { System . out . printf ( " % d ▁ % d \n " , i + 1 , i + 3 ) ; System . exit ( 0 ) ; } } System . out . println ( " - 1 ▁ - 1" ) ; } }

import java . util . * ; public class Main { public void main ( Scanner sc ) { char s [ ] = sc . next ( ) . toCharArray ( ) ; int len = s . length ; int a = - 1 ; int b = - 1 ; for ( int i = 0 ; i < len - 1 ; i ++ ) { if ( s [ i ] == s [ i + 1 ] ) { a = i + 1 ; b = i + 2 ; break ; } if ( i + 2 < len && s [ i ] == s [ i + 2 ] ) { a = i + 1 ; b = i + 3 ; break ; } } System . out . println ( a + " ▁ " + b ) ; } public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; new Main ( ) . main ( sc ) ; sc . close ( ) ; } }

s = input ( ) NEW_LINE if len ( s ) == 2 and s [ 0 ] == s [ 1 ] : print ( 1 , 2 ) NEW_LINE else : NEW_LINE INDENT for i in range ( 3 , len ( s ) + 1 ) : NEW_LINE INDENT a = s [ i - 3 : i ] NEW_LINE if len ( set ( a ) ) != 3 : NEW_LINE INDENT print ( i - 2 , i ) NEW_LINE break NEW_LINE DEDENT DEDENT else : print ( - 1 , - 1 ) NEW_LINE DEDENT

S = input ( ) NEW_LINE c = { } NEW_LINE for i in [ chr ( ord ( ' a ' ) + i ) for i in range ( 26 ) ] : NEW_LINE INDENT c [ i ] = 0 NEW_LINE DEDENT for i in range ( len ( S ) ) : NEW_LINE INDENT if i < 3 : NEW_LINE INDENT c [ S [ i ] ] += 1 NEW_LINE if c [ S [ i ] ] >= 2 : NEW_LINE INDENT print ( 1 , i + 1 ) NEW_LINE exit ( ) NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT c [ S [ i - 3 ] ] -= 1 NEW_LINE c [ S [ i ] ] += 1 NEW_LINE if c [ S [ i ] ] >= 2 : NEW_LINE INDENT print ( i - 1 , i + 1 ) NEW_LINE exit ( ) NEW_LINE DEDENT DEDENT DEDENT print ( - 1 , - 1 ) NEW_LINE

s = input ( ) NEW_LINE k = - 1 NEW_LINE l = - 1 NEW_LINE flag = False NEW_LINE for i in range ( 0 , len ( s ) - 1 ) : NEW_LINE INDENT if s [ i ] == s [ i + 1 ] : NEW_LINE INDENT flag = True NEW_LINE k = i + 1 NEW_LINE l = i + 2 NEW_LINE break NEW_LINE DEDENT DEDENT if not flag : NEW_LINE INDENT if len ( s ) > 2 : NEW_LINE INDENT for j in range ( 0 , len ( s ) - 2 ) : NEW_LINE INDENT if s [ j ] == s [ j + 2 ] : NEW_LINE INDENT flag = True NEW_LINE k = j + 1 NEW_LINE l = j + 3 NEW_LINE break NEW_LINE DEDENT DEDENT DEDENT else : NEW_LINE INDENT None NEW_LINE DEDENT DEDENT print ( k , l ) NEW_LINE

def main ( ) : NEW_LINE INDENT s = input ( ) . strip ( ) NEW_LINE if len ( s ) == 2 : NEW_LINE INDENT return ( "1 ▁ 2" if s [ 0 ] == s [ 1 ] else " - 1 ▁ - 1" ) NEW_LINE DEDENT for i in range ( len ( s ) - 2 ) : NEW_LINE INDENT if len ( set ( s [ i : i + 3 ] ) ) <= 2 : NEW_LINE INDENT return " { } ▁ { } " . format ( i + 1 , i + 3 ) NEW_LINE DEDENT DEDENT return " - 1 ▁ - 1" NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT print ( main ( ) ) NEW_LINE DEDENT

import sys NEW_LINE input = sys . stdin . readline NEW_LINE sys . setrecursionlimit ( 10000 ) NEW_LINE S = input ( ) NEW_LINE for i in range ( len ( S ) ) : NEW_LINE INDENT if i <= len ( S ) - 2 : NEW_LINE INDENT if S [ i ] == S [ i + 1 ] : NEW_LINE INDENT print ( " { } ▁ { } " . format ( i + 1 , i + 2 ) ) NEW_LINE break NEW_LINE DEDENT DEDENT if i <= len ( S ) - 3 : NEW_LINE INDENT if S [ i ] == S [ i + 2 ] : NEW_LINE INDENT print ( " { } ▁ { } " . format ( i + 1 , i + 3 ) ) NEW_LINE break NEW_LINE DEDENT DEDENT DEDENT else : NEW_LINE INDENT print ( " - 1 ▁ - 1" ) NEW_LINE DEDENT


import java . util . Arrays ; import java . util . PriorityQueue ; import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int K = scan . nextInt ( ) ; int [ ] dp = new int [ K ] ; Arrays . fill ( dp , Integer . MAX_VALUE ) ; class Node { int to , cost ; Node ( int to , int cost ) { this . to = to ; this . cost = cost ; } } PriorityQueue < Node > que = new PriorityQueue < > ( ( a , b ) -> a . cost - b . cost ) ; for ( int i = 1 ; i < Math . min ( 10 , K ) ; ++ i ) { dp [ i ] = i ; que . add ( new Node ( i , i ) ) ; } while ( ! que . isEmpty ( ) ) { Node node = que . poll ( ) ; int v = node . to ; int c = node . cost ; if ( c > dp [ v ] ) continue ; for ( int i = 0 ; i < 10 ; ++ i ) { int nextv = ( v * 10 + i ) % K ; int nextc = c + i ; if ( dp [ nextv ] > nextc ) { dp [ nextv ] = nextc ; que . add ( new Node ( nextv , nextc ) ) ; } } } System . out . println ( dp [ 0 ] ) ; } }

import java . util . * ; public class Main { int n ; ArrayList < ArrayList < Edge > > ns ; public static void main ( String [ ] args ) { Main m = new Main ( ) ; m . read ( ) ; m . solve ( ) ; } private void read ( ) { Scanner sc = new Scanner ( System . in ) ; n = sc . nextInt ( ) ; ns = new ArrayList < > ( n + 1 ) ; for ( int i = 0 ; i < n + 1 ; i ++ ) ns . add ( new ArrayList < > ( ) ) ; } private void solve ( ) { for ( int i = 0 ; i < n + 1 ; i ++ ) { int nxt = ( i + 1 ) % n ; int nxt2 = ( i * 10 ) % n ; ns . get ( i ) . add ( new Edge ( i , nxt , 1 ) ) ; ns . get ( i ) . add ( new Edge ( i , nxt2 , 0 ) ) ; } int [ ] ds = new int [ n + 1 ] ; Arrays . fill ( ds , n + 1 ) ; Deque < Edge > deq = new ArrayDeque < > ( ) ; ds [ 1 ] = 1 ; for ( Edge e : ns . get ( 1 ) ) if ( e . c == 0 ) deq . addFirst ( e ) ; else deq . addLast ( e ) ; while ( ! deq . isEmpty ( ) ) { Edge e = deq . pollFirst ( ) ; int dist = ds [ e . cur ] + e . c ; ds [ e . to ] = Math . min ( dist , ds [ e . to ] ) ; for ( Edge nxt : ns . get ( e . to ) ) { if ( ds [ nxt . to ] > ds [ e . to ] + nxt . c ) { if ( nxt . c == 0 ) deq . addFirst ( nxt ) ; else deq . addLast ( nxt ) ; } } } System . out . println ( ds [ 0 ] ) ; } private class Edge { int cur ; int to ; int c ; Edge ( int cur , int to , int c ) { this . cur = cur ; this . to = to ; this . c = c ; } } }

import java . io . * ; import java . util . * ; class Main { public static void main ( String [ ] args ) { solve ( ) ; } public static void solve ( ) { Scanner sc = new Scanner ( System . in ) ; int k = sc . nextInt ( ) ; Deque < Point > dq = new ArrayDeque < Point > ( ) ; boolean [ ] judge = new boolean [ k ] ; Arrays . fill ( judge , true ) ; Point now = new Point ( 1 , 1 ) ; dq . add ( now ) ; while ( ! dq . isEmpty ( ) ) { Point z = dq . removeFirst ( ) ; if ( ! judge [ ( z . x ) ] ) { continue ; } judge [ ( z . x ) ] = false ; if ( z . x == 0 ) { System . out . println ( z . y ) ; break ; } if ( judge [ ( z . x * 10 ) % k ] ) { dq . addFirst ( new Point ( ( z . x * 10 ) % k , z . y ) ) ; } if ( judge [ ( z . x + 1 ) % k ] ) { dq . addLast ( new Point ( ( z . x + 1 ) % k , z . y + 1 ) ) ; } } } } class Point { int x ; int y ; Point ( int x , int y ) { this . x = x ; this . y = y ; } }

import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int k = sc . nextInt ( ) ; int [ ] dist = new int [ k ] ; for ( int i = 0 ; i < k ; i ++ ) { dist [ i ] = Integer . MAX_VALUE ; } dist [ 1 ] = 0 ; Deque < Integer > deque = new ArrayDeque < > ( ) ; deque . addFirst ( 1 ) ; int [ ] visit = new int [ k ] ; visit [ 1 ] = 1 ; while ( deque . size ( ) > 0 ) { int u = deque . pollFirst ( ) ; int v1 = ( 10 * u ) % k ; int v2 = ( u + 1 ) % k ; if ( visit [ v1 ] == 0 ) { dist [ v1 ] = Math . min ( dist [ v1 ] , dist [ u ] ) ; deque . addFirst ( v1 ) ; visit [ v1 ] = 1 ; } else { if ( dist [ v1 ] > dist [ u ] ) { dist [ v1 ] = dist [ u ] ; deque . remove ( v1 ) ; deque . addFirst ( v1 ) ; } } if ( visit [ v2 ] == 0 ) { dist [ v2 ] = Math . min ( dist [ v2 ] , dist [ u ] + 1 ) ; deque . addLast ( v2 ) ; visit [ v2 ] = 1 ; } } System . out . println ( dist [ 0 ] + 1 ) ; } }

import java . util . ArrayDeque ; import java . util . ArrayList ; import java . util . Arrays ; import java . util . Deque ; import java . util . List ; import java . util . PriorityQueue ; import java . util . Queue ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { new Main ( ) . compute ( ) ; } void compute ( ) { Scanner sc = new Scanner ( System . in ) ; int K = sc . nextInt ( ) ; int [ ] one = new int [ K ] ; int [ ] zero = new int [ K ] ; for ( int i = 1 ; i < K ; i ++ ) { one [ i ] = ( i + 1 ) % K ; zero [ i ] = ( i * 10 ) % K ; } Deque < Integer > que = new ArrayDeque < > ( ) ; int [ ] min = new int [ K ] ; for ( int i = 0 ; i < K ; i ++ ) { min [ i ] = Integer . MAX_VALUE ; } que . addLast ( 1 ) ; min [ 1 ] = 1 ; while ( ! que . isEmpty ( ) ) { int cur = que . pollFirst ( ) ; if ( min [ cur ] + 1 < min [ one [ cur ] ] ) { que . addLast ( one [ cur ] ) ; min [ one [ cur ] ] = min [ cur ] + 1 ; } if ( min [ cur ] < min [ zero [ cur ] ] ) { que . addFirst ( zero [ cur ] ) ; min [ zero [ cur ] ] = min [ cur ] ; } } System . out . println ( min [ 0 ] ) ; } }

from collections import deque NEW_LINE def inpl ( ) : return tuple ( map ( int , input ( ) . split ( ) ) ) NEW_LINE K = int ( input ( ) ) NEW_LINE visited = [ False for _ in range ( K ) ] NEW_LINE dq = deque ( [ ( 1 , 1 ) ] ) NEW_LINE while True : NEW_LINE INDENT c , m = dq . popleft ( ) NEW_LINE visited [ m ] = True NEW_LINE if m == 0 : NEW_LINE INDENT print ( c ) NEW_LINE break NEW_LINE DEDENT else : NEW_LINE INDENT if not visited [ ( m * 10 ) % K ] : NEW_LINE INDENT dq . appendleft ( ( c , ( m * 10 ) % K ) ) NEW_LINE DEDENT if not visited [ ( m + 1 ) % K ] : NEW_LINE INDENT dq . append ( ( c + 1 , ( m + 1 ) % K ) ) NEW_LINE DEDENT DEDENT DEDENT

from heapq import heappush , heappop NEW_LINE K = int ( input ( ) ) NEW_LINE table = [ [ ] for i in range ( K ) ] NEW_LINE for i in range ( K ) : NEW_LINE INDENT table [ i ] . append ( [ 1 , ( i + 1 ) % K ] ) NEW_LINE t = ( 10 * i ) % K NEW_LINE if t != i : NEW_LINE INDENT table [ i ] . append ( [ 0 , t ] ) NEW_LINE DEDENT DEDENT dij = [ ] NEW_LINE visit = [ False ] * K NEW_LINE val = [ 10 ** 9 ] * K NEW_LINE val [ 1 ] = 0 NEW_LINE heappush ( dij , [ 0 , 1 ] ) NEW_LINE while dij : NEW_LINE INDENT d , x = heappop ( dij ) NEW_LINE if val [ x ] < d : NEW_LINE INDENT continue NEW_LINE DEDENT for q , y in table [ x ] : NEW_LINE INDENT if val [ y ] > val [ x ] + q : NEW_LINE INDENT val [ y ] = val [ x ] + q NEW_LINE heappush ( dij , [ val [ y ] , y ] ) NEW_LINE DEDENT DEDENT DEDENT print ( val [ 0 ] + 1 ) NEW_LINE

from queue import * NEW_LINE class Edge ( object ) : NEW_LINE INDENT def __init__ ( self , dst , len_ ) : NEW_LINE INDENT self . dst = dst NEW_LINE self . len = len_ NEW_LINE DEDENT DEDENT MAX_K = int ( 1e5 + 5 ) NEW_LINE INF = int ( 1e9 ) NEW_LINE K = 0 NEW_LINE dis = [ INF for i in range ( 0 , MAX_K ) ] NEW_LINE vis = [ False for i in range ( 0 , MAX_K ) ] NEW_LINE edge = [ [ ] for i in range ( 0 , MAX_K ) ] NEW_LINE q = PriorityQueue ( ) NEW_LINE def add ( s , t , d ) : NEW_LINE INDENT edge [ s ] . append ( Edge ( t , d ) ) NEW_LINE DEDENT def build ( ) : NEW_LINE INDENT for i in range ( 1 , K ) : NEW_LINE INDENT add ( i , i * 10 % K , 0 ) NEW_LINE add ( i , ( i + 1 ) % K , 1 ) NEW_LINE DEDENT DEDENT def dij ( s ) : NEW_LINE INDENT dis [ s ] = 0 NEW_LINE q . put ( ( 0 , s ) ) NEW_LINE while not q . empty ( ) : NEW_LINE INDENT x = q . get ( ) [ 1 ] NEW_LINE if vis [ x ] : NEW_LINE INDENT continue NEW_LINE DEDENT vis [ x ] = True NEW_LINE for e in edge [ x ] : NEW_LINE INDENT if dis [ e . dst ] > dis [ x ] + e . len : NEW_LINE INDENT dis [ e . dst ] = dis [ x ] + e . len NEW_LINE q . put ( ( dis [ e . dst ] , e . dst ) ) NEW_LINE DEDENT DEDENT DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT K = int ( input ( ) ) NEW_LINE build ( ) NEW_LINE dij ( 1 ) NEW_LINE print ( dis [ 0 ] + 1 ) NEW_LINE DEDENT

import heapq NEW_LINE k = int ( input ( ) ) NEW_LINE j = [ 0 ] * k NEW_LINE for i in range ( k ) : NEW_LINE INDENT j [ i ] = [ ( tuple ( [ ( i * 10 ) % k , 0 ] ) ) ] NEW_LINE j [ i ] . append ( tuple ( [ ( i + 1 ) % k , 1 ] ) ) NEW_LINE DEDENT min_cost = [ float ( " inf " ) ] * k NEW_LINE def dijkstra ( s ) : NEW_LINE INDENT queue = [ tuple ( [ 1 , s ] ) ] NEW_LINE while queue : NEW_LINE INDENT p = heapq . heappop ( queue ) NEW_LINE for e in j [ p [ 1 ] ] : NEW_LINE INDENT if p [ 0 ] + e [ 1 ] >= min_cost [ e [ 0 ] ] : NEW_LINE INDENT continue NEW_LINE DEDENT min_cost [ e [ 0 ] ] = p [ 0 ] + e [ 1 ] NEW_LINE heapq . heappush ( queue , tuple ( [ min_cost [ e [ 0 ] ] , e [ 0 ] ] ) ) NEW_LINE DEDENT DEDENT DEDENT dijkstra ( 1 ) NEW_LINE print ( min_cost [ 0 ] ) NEW_LINE

from collections import deque NEW_LINE K = int ( input ( ) ) NEW_LINE dp = [ float ( " inf " ) ] * ( K + 1 ) NEW_LINE dq = deque ( [ ( 1 , 1 ) ] ) NEW_LINE popleft , append , append_left = dq . popleft , dq . append , dq . appendleft NEW_LINE while dq : NEW_LINE INDENT v , cost = popleft ( ) NEW_LINE if v == 0 : NEW_LINE INDENT print ( cost ) NEW_LINE exit ( ) NEW_LINE DEDENT if dp [ v ] < cost : NEW_LINE INDENT continue NEW_LINE DEDENT plus_10 , plus_1 = ( v * 10 ) % K , ( v + 1 ) % K NEW_LINE if dp [ plus_10 ] > cost : NEW_LINE INDENT dp [ plus_10 ] = cost NEW_LINE append_left ( ( plus_10 , cost ) ) NEW_LINE DEDENT if dp [ plus_1 ] > cost + 1 : NEW_LINE INDENT dp [ plus_1 ] = cost + 1 NEW_LINE append ( ( plus_1 , cost + 1 ) ) NEW_LINE DEDENT DEDENT


import java . io . OutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . PrintWriter ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; Scanner in = new Scanner ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; ETrBBnsformBBtion solver = new ETrBBnsformBBtion ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class ETrBBnsformBBtion { public void solve ( int testNumber , Scanner in , PrintWriter out ) { String s = in . next ( ) , t = in . next ( ) ; int [ ] cs = new int [ s . length ( ) + 1 ] , ct = new int [ t . length ( ) + 1 ] ; for ( int i = 1 ; i <= s . length ( ) ; i ++ ) { cs [ i ] = cs [ i - 1 ] + s . charAt ( i - 1 ) - ' A ' + 1 ; } for ( int i = 1 ; i <= t . length ( ) ; i ++ ) { ct [ i ] = ct [ i - 1 ] + t . charAt ( i - 1 ) - ' A ' + 1 ; } int q = in . nextInt ( ) ; for ( int i = 0 ; i < q ; i ++ ) { int a = in . nextInt ( ) , b = in . nextInt ( ) , c = in . nextInt ( ) , d = in . nextInt ( ) ; if ( ( cs [ b ] - cs [ a - 1 ] ) % 3 == ( ct [ d ] - ct [ c - 1 ] ) % 3 ) { out . println ( " YES " ) ; } else { out . println ( " NO " ) ; } } } } }

import java . io . * ; import java . util . * ; public class Main { private static int [ ] prep ( String s ) { int [ ] sPre = new int [ s . length ( ) + 1 ] ; for ( int i = 1 ; i <= s . length ( ) ; i ++ ) { char c = s . charAt ( i - 1 ) ; if ( c == ' A ' ) { sPre [ i ] = sPre [ i - 1 ] + 1 ; } else { sPre [ i ] = sPre [ i - 1 ] + 2 ; } } return sPre ; } public static void main ( String [ ] args ) throws IOException { BufferedReader f = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String s = f . readLine ( ) ; String t = f . readLine ( ) ; int [ ] sPre = prep ( s ) ; int [ ] tPre = prep ( t ) ; int q = Integer . parseInt ( f . readLine ( ) ) ; for ( int i = 0 ; i < q ; i ++ ) { StringTokenizer st = new StringTokenizer ( f . readLine ( ) ) ; int a = Integer . parseInt ( st . nextToken ( ) ) ; int b = Integer . parseInt ( st . nextToken ( ) ) ; int c = Integer . parseInt ( st . nextToken ( ) ) ; int d = Integer . parseInt ( st . nextToken ( ) ) ; if ( ( sPre [ b ] - sPre [ a - 1 ] ) % 3 == ( tPre [ d ] - tPre [ c - 1 ] ) % 3 ) { System . out . println ( " YES " ) ; } else { System . out . println ( " NO " ) ; } } } }

import java . util . * ; public class Main { private class Query { int a , b , c , d ; public Query ( int a , int b , int c , int d ) { this . a = a ; this . b = b ; this . c = c ; this . d = d ; } } public void main ( Scanner sc ) { char s [ ] = sc . next ( ) . toCharArray ( ) ; char t [ ] = sc . next ( ) . toCharArray ( ) ; int q = sc . nextInt ( ) ; Query data [ ] = new Query [ q ] ; for ( int i = 0 ; i < q ; i ++ ) { data [ i ] = new Query ( sc . nextInt ( ) , sc . nextInt ( ) , sc . nextInt ( ) , sc . nextInt ( ) ) ; } int sums [ ] = new int [ s . length + 1 ] ; int sumt [ ] = new int [ t . length + 1 ] ; for ( int i = 0 ; i < s . length ; i ++ ) { sums [ i + 1 ] = ( sums [ i ] + ( s [ i ] == ' A ' ? 1 : 2 ) ) % 3 ; } for ( int i = 0 ; i < t . length ; i ++ ) { sumt [ i + 1 ] = ( sumt [ i ] + ( t [ i ] == ' A ' ? 1 : 2 ) ) % 3 ; } int a , b , c , d ; for ( int i = 0 ; i < q ; i ++ ) { a = sums [ data [ i ] . a - 1 ] ; b = sums [ data [ i ] . b ] ; c = sumt [ data [ i ] . c - 1 ] ; d = sumt [ data [ i ] . d ] ; System . out . println ( ( ( 3 + b - a ) % 3 == ( 3 + d - c ) % 3 ) ? " YES " : " NO " ) ; } } public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; new Main ( ) . main ( sc ) ; sc . close ( ) ; } }

import java . util . Arrays ; import java . util . Scanner ; public class Main { static Scanner s = new Scanner ( System . in ) ; public static void main ( String [ ] __ ) { int [ ] from , to ; { String buf = s . next ( ) ; from = new int [ buf . length ( ) + 1 ] ; for ( int i = 0 ; i < buf . length ( ) ; i ++ ) from [ i + 1 ] = buf . charAt ( i ) == ' A ' ? 1 : 2 ; buf = s . next ( ) ; to = new int [ buf . length ( ) + 1 ] ; for ( int i = 0 ; i < buf . length ( ) ; i ++ ) to [ i + 1 ] = buf . charAt ( i ) == ' A ' ? 1 : 2 ; Arrays . parallelPrefix ( from , ( a , b ) -> a + b ) ; Arrays . parallelPrefix ( to , ( a , b ) -> a + b ) ; } for ( int q = s . nextInt ( ) ; q > 0 ; q -- ) { int f = - from [ s . nextInt ( ) - 1 ] + from [ s . nextInt ( ) ] , t = - to [ s . nextInt ( ) - 1 ] + to [ s . nextInt ( ) ] ; System . out . println ( f % 3 == t % 3 ? " YES " : " NO " ) ; } } }

import java . util . * ; public class Main { int ni ( ) { return cin . nextInt ( ) ; } long nl ( ) { return cin . nextLong ( ) ; } String line ( ) { return cin . nextLine ( ) ; } void println ( String str ) { System . out . println ( str ) ; } void print ( String str ) { System . out . print ( str ) ; } static final int MOD = 1000000007 ; Scanner cin = new Scanner ( System . in ) ; String output ; public static void main ( String [ ] args ) { new Main ( ) . run ( ) ; } public void run ( ) { solve ( ) ; } String S ; String T ; int N ; void solve ( ) { S = line ( ) ; T = line ( ) ; int [ ] sums = new int [ S . length ( ) + 1 ] ; int [ ] sumt = new int [ T . length ( ) + 1 ] ; sums [ 1 ] = S . charAt ( 0 ) - ' A ' + 1 ; for ( int i = 1 ; i < S . length ( ) ; i ++ ) { sums [ i + 1 ] = sums [ i ] + S . charAt ( i ) - ' A ' + 1 ; } sumt [ 1 ] = T . charAt ( 0 ) - ' A ' + 1 ; for ( int i = 1 ; i < T . length ( ) ; i ++ ) { sumt [ i + 1 ] = sumt [ i ] + T . charAt ( i ) - ' A ' + 1 ; } N = ni ( ) ; for ( int i = 0 ; i < N ; i ++ ) { int a = ni ( ) ; int b = ni ( ) ; int c = ni ( ) ; int d = ni ( ) ; if ( ( sums [ b ] - sums [ a - 1 ] ) % 3 == ( sumt [ d ] - sumt [ c - 1 ] ) % 3 ) { println ( " YES " ) ; } else { println ( " NO " ) ; } } } }

s = input ( ) NEW_LINE t = input ( ) NEW_LINE q = int ( input ( ) ) NEW_LINE info = [ list ( map ( int , input ( ) . split ( ) ) ) for i in range ( q ) ] NEW_LINE MOD = 3 NEW_LINE memo = { " A " : 1 , " B " : 2 } NEW_LINE s_ruiseki = [ 0 ] * ( len ( s ) + 1 ) NEW_LINE for i in range ( 1 , len ( s ) + 1 ) : NEW_LINE INDENT s_ruiseki [ i ] = ( s_ruiseki [ i - 1 ] + memo [ s [ i - 1 ] ] ) % MOD NEW_LINE DEDENT t_ruiseki = [ 0 ] * ( len ( t ) + 1 ) NEW_LINE for i in range ( 1 , len ( t ) + 1 ) : NEW_LINE INDENT t_ruiseki [ i ] = ( t_ruiseki [ i - 1 ] + memo [ t [ i - 1 ] ] ) % MOD NEW_LINE DEDENT for i in range ( q ) : NEW_LINE INDENT ans1 = ( 2 * s_ruiseki [ info [ i ] [ 0 ] - 1 ] + s_ruiseki [ info [ i ] [ 1 ] ] ) % MOD NEW_LINE ans2 = ( 2 * t_ruiseki [ info [ i ] [ 2 ] - 1 ] + t_ruiseki [ info [ i ] [ 3 ] ] ) % MOD NEW_LINE print ( " YES " if ans1 == ans2 else " NO " ) NEW_LINE DEDENT

def inpl ( ) : return [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE S = input ( ) NEW_LINE T = input ( ) NEW_LINE typeS = [ 0 for _ in range ( 1 + len ( S ) ) ] NEW_LINE typeT = [ 0 for _ in range ( 1 + len ( T ) ) ] NEW_LINE typeS [ 0 ] = typeT [ 0 ] = 0 NEW_LINE for i in range ( len ( S ) ) : NEW_LINE INDENT ctr = 2 NEW_LINE if S [ i ] == ' A ' : NEW_LINE INDENT ctr = 1 NEW_LINE DEDENT typeS [ i + 1 ] = ( typeS [ i ] + ctr ) % 3 NEW_LINE DEDENT for i in range ( len ( T ) ) : NEW_LINE INDENT ctr = 2 NEW_LINE if T [ i ] == ' A ' : NEW_LINE INDENT ctr = 1 NEW_LINE DEDENT typeT [ i + 1 ] = ( typeT [ i ] + ctr ) % 3 NEW_LINE DEDENT Q = int ( input ( ) ) NEW_LINE for _ in range ( Q ) : NEW_LINE INDENT a , b , c , d = inpl ( ) NEW_LINE if ( typeS [ b ] - typeS [ a - 1 ] ) % 3 == ( typeT [ d ] - typeT [ c - 1 ] ) % 3 : NEW_LINE INDENT print ( ' YES ' ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( ' NO ' ) NEW_LINE DEDENT DEDENT

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 s = ns ( ) NEW_LINE t = ns ( ) NEW_LINE q = ni ( ) NEW_LINE sa = [ 0 ] NEW_LINE sb = [ 0 ] NEW_LINE ta = [ 0 ] NEW_LINE tb = [ 0 ] NEW_LINE for si in s : NEW_LINE INDENT if si == " A " : NEW_LINE INDENT sa . append ( sa [ - 1 ] + 1 ) NEW_LINE sb . append ( sb [ - 1 ] ) NEW_LINE DEDENT else : NEW_LINE INDENT sa . append ( sa [ - 1 ] ) NEW_LINE sb . append ( sb [ - 1 ] + 1 ) NEW_LINE DEDENT DEDENT for ti in t : NEW_LINE INDENT if ti == " A " : NEW_LINE INDENT ta . append ( ta [ - 1 ] + 1 ) NEW_LINE tb . append ( tb [ - 1 ] ) NEW_LINE DEDENT else : NEW_LINE INDENT ta . append ( ta [ - 1 ] ) NEW_LINE tb . append ( tb [ - 1 ] + 1 ) NEW_LINE DEDENT DEDENT for _ in range ( q ) : NEW_LINE INDENT a , b , c , d = li ( ) NEW_LINE sanum = sa [ b ] - sa [ a - 1 ] NEW_LINE sbnum = sb [ b ] - sb [ a - 1 ] NEW_LINE tanum = ta [ d ] - ta [ c - 1 ] NEW_LINE tbnum = tb [ d ] - tb [ c - 1 ] NEW_LINE sanum += 2 * sbnum NEW_LINE tanum += 2 * tbnum NEW_LINE if sanum % 3 == tanum % 3 : NEW_LINE INDENT print ( ' YES ' ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( ' NO ' ) NEW_LINE DEDENT DEDENT

def getN ( ) : NEW_LINE INDENT return int ( input ( ) ) NEW_LINE DEDENT def getMN ( ) : NEW_LINE INDENT a = input ( ) . split ( ) NEW_LINE b = [ int ( i ) for i in a ] NEW_LINE return b [ 0 ] , b [ 1 ] NEW_LINE DEDENT def getlist ( ) : NEW_LINE INDENT a = input ( ) . split ( ) NEW_LINE b = [ int ( i ) for i in a ] NEW_LINE return b NEW_LINE DEDENT astr = input ( ) NEW_LINE bstr = input ( ) NEW_LINE n = getN ( ) NEW_LINE queries = [ ] NEW_LINE for i in range ( n ) : NEW_LINE INDENT queries . append ( getlist ( ) ) NEW_LINE DEDENT s1 = 1 if astr [ 0 ] == " A " else 2 NEW_LINE t1 = 1 if bstr [ 0 ] == " A " else 2 NEW_LINE s_acc = [ 0 ] NEW_LINE t_acc = [ 0 ] NEW_LINE tmp = 0 NEW_LINE for s in astr : NEW_LINE INDENT if s == " A " : NEW_LINE INDENT s_acc . append ( s_acc [ - 1 ] + 1 ) NEW_LINE DEDENT else : NEW_LINE INDENT s_acc . append ( s_acc [ - 1 ] + 2 ) NEW_LINE DEDENT DEDENT for s in bstr : NEW_LINE INDENT if s == " A " : NEW_LINE INDENT t_acc . append ( t_acc [ - 1 ] + 1 ) NEW_LINE DEDENT else : NEW_LINE INDENT t_acc . append ( t_acc [ - 1 ] + 2 ) NEW_LINE DEDENT DEDENT for q in queries : NEW_LINE INDENT x , y , z , w = q NEW_LINE if ( s_acc [ y ] - s_acc [ x - 1 ] ) % 3 == ( t_acc [ w ] - t_acc [ z - 1 ] ) % 3 : NEW_LINE INDENT print ( " YES " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " NO " ) NEW_LINE DEDENT DEDENT

S = input ( ) NEW_LINE T = input ( ) NEW_LINE def sign ( s ) : NEW_LINE INDENT if len ( s ) == 1 : NEW_LINE INDENT return s NEW_LINE DEDENT elif s == " AA " : NEW_LINE INDENT return " B " NEW_LINE DEDENT elif s in [ " AB " , " BA " ] : NEW_LINE INDENT return " " NEW_LINE DEDENT elif s == " BB " : NEW_LINE INDENT return " A " NEW_LINE DEDENT DEDENT def diff ( a , b ) : NEW_LINE INDENT if b == " " : NEW_LINE INDENT return a NEW_LINE DEDENT elif b == a : NEW_LINE INDENT return " " NEW_LINE DEDENT elif a == " " : NEW_LINE INDENT if b == " A " : NEW_LINE INDENT return " B " NEW_LINE DEDENT elif b == " B " : NEW_LINE INDENT return " A " NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT return b NEW_LINE DEDENT DEDENT a = " " NEW_LINE Sn = [ " " ] NEW_LINE for s in S : NEW_LINE INDENT a = sign ( a + s ) NEW_LINE Sn . append ( a ) NEW_LINE DEDENT a = " " NEW_LINE Tn = [ " " ] NEW_LINE for t in T : NEW_LINE INDENT a = sign ( a + t ) NEW_LINE Tn . append ( a ) NEW_LINE DEDENT q = int ( input ( ) ) NEW_LINE for i in range ( q ) : NEW_LINE INDENT a , b , c , d = map ( int , input ( ) . split ( ) ) NEW_LINE if diff ( Sn [ b ] , Sn [ a - 1 ] ) == diff ( Tn [ d ] , Tn [ c - 1 ] ) : NEW_LINE INDENT print ( " YES " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " NO " ) NEW_LINE DEDENT DEDENT


import java . util . ArrayList ; import java . util . List ; import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int N = scan . nextInt ( ) ; long [ ] sum = new long [ N ] ; long [ ] a = new long [ N ] ; long [ ] abssum = new long [ N + 1 ] ; List < Integer > minusIndex = new ArrayList < > ( ) ; for ( int i = 0 ; i < N ; ++ i ) { if ( i == 0 ) { a [ i ] = scan . nextLong ( ) ; sum [ i ] = a [ i ] ; } else { boolean minus = ( scan . next ( ) . equals ( " - " ) ) ; a [ i ] = scan . nextLong ( ) ; sum [ i ] = sum [ i - 1 ] + a [ i ] * ( minus ? - 1 : 1 ) ; if ( minus ) minusIndex . add ( i - 1 ) ; } } for ( int i = N - 1 ; i >= 0 ; -- i ) abssum [ i ] = abssum [ i + 1 ] + a [ i ] ; long ans = sum [ N - 1 ] ; for ( int i = 0 ; i < minusIndex . size ( ) - 1 ; ++ i ) { ans = Math . max ( ans , sum [ minusIndex . get ( i ) ] - abssum [ minusIndex . get ( i ) + 1 ] + 2 * abssum [ minusIndex . get ( i + 1 ) + 1 ] ) ; } System . out . println ( ans ) ; } }

import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . io . PrintWriter ; import java . util . StringTokenizer ; public class Main { private void solve ( ) throws IOException { int n = nextInt ( ) ; long [ ] a = new long [ n ] ; char [ ] c = new char [ n ] ; c [ 0 ] = ' + ' ; for ( int i = 0 ; i < n ; i ++ ) { if ( i > 0 ) { c [ i ] = next ( ) . charAt ( 0 ) ; } a [ i ] = nextInt ( ) ; } long s = 0 ; long ss = 0 ; long ans = 0 ; for ( int i = n - 1 ; i >= 0 ; i -- ) { if ( c [ i ] == ' + ' ) { s += a [ i ] ; } else { ans = Math . max ( - a [ i ] + s + ans , - a [ i ] - s + ss ) ; ss += s + a [ i ] ; s = 0 ; } } ans += s ; out . println ( ans ) ; } BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; StringTokenizer st ; PrintWriter out = new PrintWriter ( System . out ) ; String next ( ) throws IOException { while ( st == null || ! st . hasMoreTokens ( ) ) { st = new StringTokenizer ( br . readLine ( ) ) ; } return st . nextToken ( ) ; } int nextInt ( ) throws IOException { return Integer . parseInt ( next ( ) ) ; } public static void main ( String [ ] args ) throws IOException { new Main ( ) . run ( ) ; } private void run ( ) throws IOException { solve ( ) ; out . close ( ) ; } }

import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; long [ ] [ ] dp = new long [ n ] [ 3 ] ; long a0 = sc . nextLong ( ) ; dp [ 0 ] [ 0 ] = a0 ; dp [ 0 ] [ 1 ] = Long . MIN_VALUE / 10 ; dp [ 0 ] [ 2 ] = Long . MIN_VALUE / 10 ; for ( int i = 1 ; i < n ; i ++ ) { String str = sc . next ( ) ; long v = sc . nextLong ( ) ; if ( str . equals ( " + " ) ) { dp [ i ] [ 0 ] = Math . max ( Math . max ( dp [ i - 1 ] [ 0 ] + v , dp [ i - 1 ] [ 1 ] + v ) , dp [ i - 1 ] [ 2 ] + v ) ; dp [ i ] [ 1 ] = Math . max ( dp [ i - 1 ] [ 1 ] - v , dp [ i - 1 ] [ 2 ] + v ) ; dp [ i ] [ 2 ] = dp [ i - 1 ] [ 2 ] + v ; } else { dp [ i ] [ 0 ] = Math . max ( Math . max ( dp [ i - 1 ] [ 0 ] - v , dp [ i - 1 ] [ 1 ] + v ) , dp [ i - 1 ] [ 2 ] + v ) ; dp [ i ] [ 1 ] = Math . max ( Math . max ( dp [ i - 1 ] [ 0 ] - v , dp [ i - 1 ] [ 1 ] + v ) , dp [ i - 1 ] [ 2 ] + v ) ; dp [ i ] [ 2 ] = Math . max ( dp [ i - 1 ] [ 1 ] + v , dp [ i - 1 ] [ 2 ] + v ) ; } } System . out . println ( dp [ n - 1 ] [ 0 ] ) ; } }

input ( ) NEW_LINE sm = de = 0 NEW_LINE ans = 10 ** 15 NEW_LINE for s in ( input ( ) + " - 0" ) . split ( ' - ' ) : NEW_LINE INDENT a = list ( map ( int , s . split ( ' + ' ) ) ) NEW_LINE if sm : NEW_LINE INDENT ans = min ( ans , sum ( a ) + de ) NEW_LINE de += a [ 0 ] NEW_LINE DEDENT sm += sum ( a ) NEW_LINE DEDENT print ( sm - 2 * ans ) NEW_LINE