diff --git "a/codenet_4000_scope_error/java/input.in" "b/codenet_4000_scope_error/java/input.in" new file mode 100644--- /dev/null +++ "b/codenet_4000_scope_error/java/input.in" @@ -0,0 +1,3296 @@ +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int hp1 = sc . nextInt ( ) ; int attack1 = sc . nextInt ( ) ; int hp2 = sc . nextInt ( ) ; int attack2 = sc . nextInt ( ) ; while ( hp1 > 0 && hp2 > 0 ) { int attack2 = sc . nextInt ( ) ; hp2 -= attack1 ; if ( hp2 <= 0 ) { System . out . println ( " Yes " ) ; continue ; } hp1 -= attack2 ; if ( hp1 <= 0 ) { System . out . println ( " No " ) ; continue ; } } } } +import java . util . Arrays ; import java . util . Scanner ; class Main { public static void main ( final String [ ] args ) { int i = 1 ; Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; String [ ] S = new String [ N ] ; int ans = 1 ; for ( int i = 0 ; i < N ; i ++ ) { S [ i ] = sc . next ( ) ; } Arrays . sort ( S ) ; for ( int i = 1 ; i < N ; i ++ ) { if ( ! S [ i - 1 ] . equals ( S [ i ] ) ) { ans ++ ; } } System . out . print ( ans ) ; } } +import java . util . * ; import java . text . * ; class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; Comparator < String > cs = new Comparator < String > ( ) { public int compare ( String s1 , String s2 ) { int l1 = s1 . length ( ) ; int l2 = s2 . length ( ) ; int l = Math . min ( l1 , l2 ) ; for ( int i = 0 ; i < l ; i ++ ) { int d = s1 . charAt ( i ) - s2 . charAt ( i ) ; if ( d != 0 ) return d ; } return l1 - l2 ; } public boolean equals ( Object o ) { return o == this ; } } ; int n = sc . nextInt ( ) ; int c1 = 0 , c2 = 0 ; while ( n -- > 0 ) { String x = sc . next ( ) ; String y = sc . next ( ) ; int c = cs . compare ( x , y ) ; if ( c < 0 ) { c2 += 3 ; } else if ( c > 0 ) { c1 += 3 ; } else { int c1 = 0 , c2 = 0 ; c2 ++ ; c1 ++ ; } } System . out . println ( " " + c1 + " " + c2 ) ; } } +import java . io . IOException ; import java . util . ArrayList ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws IOException { ArrayList < Integer > list = new ArrayList < Integer > ( ) ; Scanner sc = new Scanner ( System . in ) ; ArrayList < Integer > list = new ArrayList < Integer > ( ) ; while ( sc . hasNextLine ( ) ) { String str = sc . nextLine ( ) ; if ( " " . equals ( str ) ) { break ; } list . add ( Integer . parseInt ( str ) ) ; } int A = list . get ( 0 ) ; int B = list . get ( 1 ) ; if ( ( A == 1 && B == 2 ) || ( A == 2 && B == 1 ) ) System . out . println ( 3 ) ; else if ( ( A == 1 && B == 3 ) || ( A == 3 && B == 1 ) ) System . out . println ( 2 ) ; else if ( ( A == 2 && B == 3 ) || ( A == 3 && B == 2 ) ) System . out . println ( 1 ) ; } } +import java . util . * ; public class Main { public static void main ( String ... args ) { int ans = 0 ; Scanner sc = new Scanner ( System . in ) ; int A = sc . nextInt ( ) ; int B = sc . nextInt ( ) ; int C = sc . nextInt ( ) ; int D = sc . nextInt ( ) ; sc . close ( ) ; int ans = 0 ; if ( B <= C || D <= A ) { } else if ( ( B > C ) && ( A < C ) ) { ans = B <= D ? B - C : D - C ; } else { ans = D <= B ? D - A : B - A ; } System . out . println ( ans ) ; } } +import java . util . Scanner ; import java . lang . Math ; public class Main { public static void main ( String [ ] args ) { double deg = Math . abs ( degOfHour - degOfMin ) ; Scanner sc = new Scanner ( System . in ) ; int num1 = sc . nextInt ( ) ; int num2 = sc . nextInt ( ) ; int hour = sc . nextInt ( ) ; int min = sc . nextInt ( ) ; double degOfMin = min * 6 ; double degOfHour = hour * 30 + degOfMin / 12 ; double deg = Math . abs ( degOfHour - degOfMin ) ; if ( deg > 180 ) { deg = 360 - deg ; } double rad = Math . toRadians ( deg ) ; double num3 = ( num1 * num1 ) + ( num2 * num2 ) - ( 2 * num1 * num2 * Math . cos ( rad ) ) ; System . out . print ( Math . sqrt ( num3 ) ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int x = sc . nextInt ( ) ; int res = 1 ; for ( int i = 2 ; i * i <= x ; i ++ ) { int p = i * i ; while ( p <= x ) { int p = i * i ; res = Math . max ( res , p ) ; p *= i ; } } System . out . println ( res ) ; sc . close ( ) ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { int count = 1 , x = 1 ; Scanner scanner = new Scanner ( System . in ) ; int count = 1 , x = 1 ; while ( x > 0 ) { x = scanner . nextInt ( ) ; if ( x == 0 ) { break ; } System . out . println ( " Case " + count + " : " + x ) ; count ++ ; } } } +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 . ArrayList ; import java . util . Arrays ; import java . util . List ; import java . util . StringTokenizer ; public class Main { public static void main ( String [ ] args ) { String q = in . next ( ) ; if ( q . charAt ( 0 ) == q . charAt ( 1 ) && q . charAt ( 1 ) == q . charAt ( 2 ) ) { out . println ( " No " ) ; } else { out . println ( " Yes " ) ; } out . close ( ) ; } static InputStream inputStream = System . in ; static OutputStream outputStream = System . out ; static InputReader in = new InputReader ( inputStream ) ; static PrintWriter out = new PrintWriter ( outputStream ) ; static class InputReader { public BufferedReader reader ; public StringTokenizer tokenizer ; public InputReader ( InputStream stream ) { reader = new BufferedReader ( new InputStreamReader ( stream ) , 32768 ) ; tokenizer = null ; } public String next ( ) { while ( tokenizer == null || ! tokenizer . hasMoreTokens ( ) ) { try { tokenizer = new StringTokenizer ( reader . readLine ( ) ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } } return tokenizer . nextToken ( ) ; } public int NI ( ) { return Integer . parseInt ( next ( ) ) ; } public long NL ( ) { return Long . parseLong ( next ( ) ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int m = sc . nextInt ( ) ; int [ ] a = new int [ n + 1 ] ; for ( int i = 0 ; i < m ; i ++ ) { a [ sc . nextInt ( ) ] ++ ; } long [ ] cmb = new long [ n + 1 ] ; cmb [ 0 ] = 1 ; cmb [ 1 ] = a [ 1 ] ^ 1 ; final long mod = 1_000_000_007 ; for ( int i = 2 ; i <= n ; i ++ ) { int i = 2 ; cmb [ i ] = ( a [ i ] ^ 1 ) * ( cmb [ i - 2 ] + cmb [ i - 1 ] ) % mod ; } System . out . println ( cmb [ n ] ) ; } } +import java . util . Scanner ; import java . util . Arrays ; public class Main { public static void main ( String [ ] args ) { Scanner cin = new Scanner ( System . in ) ; int n , t ; int [ ] data = new int [ 3 ] ; n = cin . nextInt ( ) ; while ( n -- > 0 ) { int i = 0 ; for ( int i = 0 ; i < 3 ; i ++ ) { t = cin . nextInt ( ) ; data [ i ] = t * t ; } Arrays . sort ( data ) ; if ( data [ 0 ] + data [ 1 ] == data [ 2 ] ) { System . out . println ( " YES " ) ; } else { System . out . println ( " NO " ) ; } } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int x = 0 ; while ( true ) { int x = 0 ; if ( n <= 1000 ) { x = 1000 - n ; break ; } else { n = n - 1000 ; } } System . out . println ( x ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int numRow = sc . nextInt ( ) ; int numCol = sc . nextInt ( ) ; int [ ] [ ] mat = new int [ numRow ] [ numCol ] ; int [ ] vecIn = new int [ numCol ] ; int [ ] vecOut = new int [ numRow ] ; int i , j ; for ( i = 0 ; i < numRow ; i ++ ) { int i , j ; for ( j = 0 ; j < numCol ; j ++ ) { mat [ i ] [ j ] = sc . nextInt ( ) ; } } for ( j = 0 ; j < numCol ; j ++ ) vecIn [ j ] = sc . nextInt ( ) ; for ( i = 0 ; i < numRow ; i ++ ) { for ( j = 0 ; j < numCol ; j ++ ) { vecOut [ i ] += mat [ i ] [ j ] * vecIn [ j ] ; } System . out . println ( vecOut [ i ] ) ; } } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; double area = 0.f ; double sum ; double sta ; double dev ; double dev_w ; double dev_sum ; double ave ; double var ; boolean Judge = true ; while ( Judge ) { int stu_num = scanner . nextInt ( ) ; if ( stu_num == 0 ) { break ; } double [ ] stu = new double [ stu_num ] ; sum = 0 ; dev_sum = 0 ; dev_w = 0 ; for ( int i = 0 ; i < stu_num ; i ++ ) { stu [ i ] = scanner . nextDouble ( ) ; sum += stu [ i ] ; } ave = sum / stu_num ; for ( int i = 0 ; i < stu_num ; i ++ ) { dev = ave - stu [ i ] ; dev_w = dev * dev ; dev_sum += dev_w ; } if ( dev_sum != 0 ) { int i = 0 ; var = dev_sum / stu_num ; } else { var = 0 ; } sta = Math . sqrt ( var ) ; System . out . println ( sta ) ; } scanner . close ( ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int i = 1 ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; String [ ] a = new String [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = sc . next ( ) ; } sc . close ( ) ; Arrays . sort ( a ) ; int yono = 1 ; for ( int i = 1 ; i < n ; i ++ ) { if ( ! a [ i - 1 ] . equals ( a [ i ] ) ) yono ++ ; } System . out . println ( yono ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int i = 2 ; Scanner scan = new Scanner ( System . in ) ; int x = scan . nextInt ( ) ; for ( int i = x ; i <= Math . pow ( 10 , 9 ) ; i ++ ) { if ( isPrime ( i ) ) { System . out . println ( i ) ; return ; } } scan . close ( ) ; } public static boolean isPrime ( int n ) { for ( int i = 2 ; i <= Math . sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) return false ; } return true ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; Scanner sc = new Scanner ( System . in ) ; while ( sc . hasNext ( ) ) { int a = sc . nextInt ( ) ; String strA = sc . next ( ) ; int b = sc . nextInt ( ) ; if ( strA == " ? " ) { break ; } switch ( strA ) { case " + " : System . out . println ( a + b ) ; break ; case " - " : System . out . println ( a - b ) ; break ; case " * " : System . out . println ( a * b ) ; break ; case " / " : System . out . println ( a / b ) ; break ; } } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int k = sc . nextInt ( ) ; char [ ] s = sc . next ( ) . toCharArray ( ) ; if ( k >= s . length ) { for ( int i = 0 ; i < s . length ; i ++ ) { System . out . print ( s [ i ] ) ; } } else { for ( int i = 0 ; i < k ; i ++ ) { int i = 0 ; System . out . print ( s [ i ] ) ; } System . out . print ( " ... " ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; double T = sc . nextDouble ( ) ; int A = sc . nextInt ( ) ; double [ ] H = new double [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { H [ i ] = sc . nextInt ( ) ; } double tmp = 2000000000 ; double ans = 2000000000 ; int res = 0 ; for ( int i = 0 ; i < N ; i ++ ) { tmp = T - H [ i ] * 0.006 ; if ( Math . abs ( tmp - A ) < ans ) { int i = 0 ; ans = Math . abs ( tmp - A ) ; res = i ; } } System . out . println ( res + 1 ) ; } } +import java . util . * ; import java . util . stream . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long h = sc . nextLong ( ) ; long ans = 1 ; long count = 1 ; while ( h > 1 ) { long count = 1 ; h = h / 2 ; ans += Math . pow ( 2 , count ) ; count ++ ; } System . out . println ( ans ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; String S = scanner . next ( ) ; int first2 = Integer . parseInt ( S . substring ( 0 , 2 ) ) ; int last2 = Integer . parseInt ( S . substring ( 2 , 4 ) ) ; String result = " " ; if ( 1 <= first2 && first2 <= 12 ) { if ( 1 <= last2 && last2 <= 12 ) { result = " AMBIGUOUS " ; } else { result = " MMYY " ; } } else { if ( 1 <= last2 && last2 <= 12 ) { String result = " " ; result = " YYMM " ; } else { result = " NA " ; } } System . out . println ( result ) ; } } +import java . io . BufferedReader ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws Exception { int i = 0 ; BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String line = br . readLine ( ) ; String [ ] boxstr = new String [ line . length ( ) ] ; int [ ] box = new int [ line . length ( ) ] ; int answw = Integer . parseInt ( line ) ; int ans = 0 ; for ( int i = 0 ; i < line . length ( ) ; i ++ ) { boxstr [ i ] = String . valueOf ( line . charAt ( i ) ) ; box [ i ] = Integer . parseInt ( boxstr [ i ] ) ; ans += box [ i ] ; } if ( answw % ans == 0 ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner stdIn = new Scanner ( System . in ) ; int n = stdIn . nextInt ( ) ; int [ ] a = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = stdIn . nextInt ( ) ; } int max = 0 ; int max2 = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( a [ i ] > max ) { max2 = max ; max = a [ i ] ; } else if ( a [ i ] > max2 ) { max2 = a [ i ] ; } } for ( int i = 0 ; i < n ; i ++ ) { int i = 0 ; if ( a [ i ] < max ) { System . out . println ( max ) ; } else { System . out . println ( max2 ) ; } } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; String s = sc . next ( ) ; String t = sc . next ( ) ; String ans = " " ; for ( int i = 0 ; i < n ; i ++ ) { String s1 = String . valueOf ( s . charAt ( i ) ) ; String s2 = String . valueOf ( t . charAt ( i ) ) ; ans += s1 ; ans += s2 ; } System . out . println ( ans ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int health = Integer . parseInt ( scan . next ( ) ) ; int varN = Integer . parseInt ( scan . next ( ) ) ; ArrayList < Integer > attack = new ArrayList < Integer > ( ) ; for ( int i = 0 ; i < varN ; i ++ ) { attack . add ( Integer . parseInt ( scan . next ( ) ) ) ; } boolean flag = false ; for ( int i = 0 ; i < varN ; i ++ ) { health -= attack . remove ( 0 ) ; if ( health <= 0 ) { flag = true ; break ; } } if ( flag ) { System . out . println ( " Yes " ) ; } else { boolean flag = false ; System . out . println ( " No " ) ; } } } +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 ) ; Task solver = new Task ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class Task { public void solve ( int testNumber , Scanner in , PrintWriter out ) { int n = in . next ( ) . length ( ) ; String s = " " ; for ( int i = 0 ; i < n ; i ++ ) { String s = " " ; s += 'x' ; } out . print ( s ) ; } } } +import java . util . * ; import java . lang . * ; import java . io . * ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner scan = new Scanner ( System . in ) ; int [ ] [ ] arr = new int [ 3 ] [ ] ; for ( int i = 0 ; i < 3 ; i ++ ) arr [ i ] = new int [ 3 ] ; for ( int i = 0 ; i < 3 ; i ++ ) { for ( int j = 0 ; j < 3 ; j ++ ) arr [ i ] [ j ] = scan . nextInt ( ) ; } int [ ] diff = new int [ 9 ] ; for ( int i = 0 ; i < 3 ; i ++ ) { for ( int j = 0 ; j < 3 ; j ++ ) diff [ i * 3 + j ] = arr [ i ] [ j ] - arr [ i ] [ ( j + 1 ) % 3 ] ; } for ( int i = 0 ; i < 3 ; i ++ ) { if ( diff [ i ] != diff [ i + 3 ] || diff [ i + 3 ] != diff [ i + 6 ] ) { System . out . println ( " No " ) ; return ; } } System . out . println ( " Yes " ) ; } } +import java . util . ArrayDeque ; import java . util . Scanner ; public class Main { static final Scanner s = new Scanner ( System . in ) ; public static void main ( String [ ] __ ) { D [ ] deques = new D [ 3 ] ; for ( int i = 0 ; i < 3 ; i ++ ) { deques [ i ] = new D ( ) ; for ( char c : s . next ( ) . toCharArray ( ) ) deques [ i ] . add ( c ) ; } char next = 'a' ; while ( ! deques [ next - 'a' ] . isEmpty ( ) ) { char next = 'a' ; next = deques [ next - 'a' ] . poll ( ) ; } System . out . println ( Character . toUpperCase ( next ) ) ; } static class D extends ArrayDeque < Character > { } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long N = sc . nextLong ( ) ; long A = 1 ; for ( long i = 1 ; i * i <= N ; i ++ ) { if ( N % i == 0 && i > A ) { long i = 1 ; A = i ; } } long B = N / A ; System . out . println ( A + B - 2 ) ; sc . close ( ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int t = sc . nextInt ( ) ; int a = sc . nextInt ( ) ; double ans = 100001.0 ; double bef ; int answer = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int i = 0 ; bef = ans ; ans = Math . min ( ans , Math . abs ( a - ( t - sc . nextInt ( ) * 0.006 ) ) ) ; if ( bef != ans ) answer = i + 1 ; } System . out . println ( answer ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . HashMap ; import java . util . Map ; public class Main { public static void main ( String [ ] args ) { new Main ( ) . run ( ) ; } public void run ( ) { BufferedReader reader = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String inputData ; Map < String , String > cardMap = new HashMap < String , String > ( ) ; String [ ] typeArray = { " S " , " H " , " C " , " D " } ; try { int cardNum = Integer . parseInt ( reader . readLine ( ) ) ; int cnt = 0 ; while ( true ) { inputData = reader . readLine ( ) ; cardMap . put ( String . valueOf ( cnt ) , inputData ) ; cnt ++ ; if ( cnt == cardNum ) { String checkString = typeArray [ j ] + " " + i ; break ; } } for ( int j = 0 ; j < typeArray . length ; j ++ ) { for ( int i = 1 ; i < 14 ; i ++ ) { String checkString = typeArray [ j ] + " " + i ; if ( ! cardMap . containsValue ( checkString ) ) { System . out . println ( checkString ) ; } } } } catch ( IOException e ) { e . printStackTrace ( ) ; } } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) { try { BufferedReader reader = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String a = reader . readLine ( ) ; String [ ] b = a . split ( " " ) ; int c = Integer . parseInt ( b [ 0 ] ) ; int d = Integer . parseInt ( b [ 1 ] ) ; String [ ] e = new String [ d ] ; int [ ] [ ] f = new int [ c ] [ d ] ; for ( int g = 0 ; g < c ; g ++ ) { a = reader . readLine ( ) ; e = a . split ( " " ) ; for ( int h = 0 ; h < d ; h ++ ) { f [ g ] [ h ] = Integer . parseInt ( e [ h ] ) ; } } int [ ] i = new int [ d ] ; for ( int j = 0 ; j < d ; j ++ ) { a = reader . readLine ( ) ; i [ j ] = Integer . parseInt ( a ) ; } int k = 0 ; for ( int l = 0 ; l < c ; l ++ ) { for ( int m = 0 ; m < d ; m ++ ) { k += f [ l ] [ m ] * i [ m ] ; } System . out . println ( k ) ; k = 0 ; } } catch ( IOException e ) { int m = 0 ; e . printStackTrace ( ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner scan = new Scanner ( System . in ) ; String s = scan . next ( ) ; String a = " " ; String okikae = " " ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { okikae = s . substring ( i , i + 1 ) ; okikae = " x " ; a = a + okikae ; } System . out . println ( a ) ; scan . close ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int l = sc . nextInt ( ) ; int sum = l * n ; int [ ] aji = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { int sa = Math . abs ( sum - apple_pie ) ; sum += i ; aji [ i ] = l + i ; } int min = Integer . MAX_VALUE / 2 ; int aji2 = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int apple_pie = sum - aji [ i ] ; int sa = Math . abs ( sum - apple_pie ) ; if ( min > sa ) { aji2 = apple_pie ; min = sa ; } } sc . close ( ) ; System . out . println ( aji2 ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int M = sc . nextInt ( ) ; int X = sc . nextInt ( ) ; int [ ] a = new int [ N ] ; int migi = 0 ; int hidari = 0 ; for ( int i = 0 ; i < M ; i ++ ) { a [ i ] = sc . nextInt ( ) ; if ( a [ i ] < X ) { int i = 0 ; hidari ++ ; } else { migi ++ ; } } System . out . println ( Math . min ( migi , hidari ) ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String S = sc . next ( ) ; String T = sc . next ( ) ; int A = sc . nextInt ( ) ; int B = sc . nextInt ( ) ; String U = sc . next ( ) ; if ( U . equals ( S ) ) { System . out . printf ( " %d %d " , A - 1 , B ) ; } else { int B = sc . nextInt ( ) ; System . out . printf ( " %d %d " , A , B - 1 ) ; } } } +import java . util . Arrays ; import java . util . Collections ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; Integer [ ] a = new Integer [ 10 ] ; for ( int i = 0 ; i < 10 ; i ++ ) { a [ i ] = sc . nextInt ( ) ; } sc . close ( ) ; Arrays . sort ( a , Collections . reverseOrder ( ) ) ; for ( int i = 0 ; i < 3 ; i ++ ) { int i = 0 ; System . out . println ( a [ i ] ) ; } } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { int n ; int i , j ; int v ; Scanner scan = new Scanner ( System . in ) ; String str = new String ( ) ; n = scan . nextInt ( ) ; int [ ] A = new int [ n ] ; for ( i = 0 ; i < n ; i ++ ) A [ i ] = scan . nextInt ( ) ; for ( i = 0 ; i < n ; i ++ ) { v = A [ i ] ; j = i - 1 ; while ( j >= 0 && A [ j ] > v ) { int [ ] A = new int [ n ] ; A [ j + 1 ] = A [ j ] ; j -- ; } A [ j + 1 ] = v ; str = Arrays . toString ( A ) ; str = str . replaceAll ( " \\ [| \\ ]|, " , " " ) ; System . out . println ( str ) ; } return ; } } +import java . util . ArrayList ; import java . util . Arrays ; import java . util . HashSet ; import java . util . List ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; String w = scan . nextLine ( ) ; String [ ] wArray = new String [ w . length ( ) ] ; for ( int i = 0 ; i < w . length ( ) ; i ++ ) { int j = 0 ; wArray [ i ] = w . substring ( i , i + 1 ) ; } List < String > wList = new ArrayList < String > ( Arrays . asList ( wArray ) ) ; List < String > wHashList = new ArrayList < String > ( new HashSet < > ( wList ) ) ; int sum = 0 ; for ( int i = 0 ; i < wHashList . size ( ) ; i ++ ) { for ( int j = 0 ; j < w . length ( ) ; j ++ ) { if ( wHashList . get ( i ) . equals ( w . substring ( j , j + 1 ) ) ) { sum ++ ; } } if ( sum % 2 == 1 ) { break ; } else { sum = 0 ; } } if ( sum % 2 == 1 ) { System . out . println ( " No " ) ; } else { System . out . println ( " Yes " ) ; } scan . close ( ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] argv ) { Scanner sc = new Scanner ( System . in ) ; boolean flag = false ; for ( int i = 0 ; i < 2 ; i ++ ) { int x = sc . nextInt ( ) ; if ( ( x % 2 ) == 0 ) { flag = true ; } } sc . close ( ) ; if ( flag == true ) { boolean flag = false ; System . out . println ( " Even " ) ; } else { System . out . println ( " Odd " ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; String str = sc . nextLine ( ) ; char [ ] ca = str . toCharArray ( ) ; for ( int i = 0 ; i < ca . length ; i ++ ) { System . out . print ( ca [ ca . length - 1 - i ] ) ; } System . out . println ( ) ; } } +import java . util . * ; import java . util . Arrays ; public class Main { public static void main ( String [ ] args ) { int j = 1 ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int result = 0 ; for ( int i = 1 ; i <= n ; i = i + 2 ) { int count = 0 ; for ( int j = 1 ; j <= i ; j ++ ) { if ( i % j == 0 ) { count ++ ; } if ( count == 8 ) { result ++ ; } } } System . out . println ( result ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner keyboard = new Scanner ( System . in ) ; int X = keyboard . nextInt ( ) ; int Y = keyboard . nextInt ( ) ; int turu = 2 ; int kame = 4 ; String ans = " No " ; for ( int i = 0 ; i < X + 1 ; i ++ ) { if ( i * turu + ( X - i ) * kame == Y ) { ans = " Yes " ; } } System . out . println ( ans ) ; keyboard . close ( ) ; } } +import java . util . ArrayList ; import java . util . Scanner ; public class Main { public static void main ( String ... args ) { Scanner scanner = new Scanner ( System . in ) ; int N = scanner . nextInt ( ) ; ArrayList < Integer > list = new ArrayList < > ( ) ; int cnt = 1 ; for ( int i = 0 ; i < N ; i ++ ) { int sc = scanner . nextInt ( ) ; if ( sc == cnt ) { int cnt = 1 ; list . add ( cnt ++ ) ; } } int rst = N - list . size ( ) ; System . out . println ( rst == N ? - 1 : rst ) ; } } +import java . io . * ; import java . util . * ; import java . util . function . * ; final class Solver { static final Solver INSTANCE = new Solver ( ) ; void solve ( Supplier < String > sc ) { String S = sc . get ( ) ; int left = Integer . parseInt ( S . substring ( 0 , 2 ) , 10 ) ; int right = Integer . parseInt ( S . substring ( 2 ) , 10 ) ; if ( isYear ( left ) && isYear ( right ) ) { System . out . println ( " NA " ) ; } else if ( isYear ( left ) ) { System . out . println ( " YYMM " ) ; } else if ( isYear ( right ) ) { System . out . println ( " MMYY " ) ; } else { System . out . println ( " AMBIGUOUS " ) ; } } boolean isYear ( int n ) { return n > 12 || n <= 0 ; } } class Main { public static void main ( String ... args ) { BufferedReader reader = new BufferedReader ( new InputStreamReader ( System . in ) ) ; Solver . INSTANCE . solve ( new Supplier < String > ( ) { StringTokenizer line ; public String get ( ) { try { return ( line = line != null && line . hasMoreTokens ( ) ? line : new StringTokenizer ( reader . readLine ( ) ) ) . nextToken ( ) ; } catch ( IOException e ) { throw new UncheckedIOException ( e ) ; } } } ) ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; double a = sc . nextDouble ( ) ; double b = sc . nextDouble ( ) ; int h = sc . nextInt ( ) ; int m = sc . nextInt ( ) ; int time = h * 60 + m ; double len = 0 ; double rad = 0 ; double hh = 0 ; double mm = 0 ; for ( int i = 0 ; i < time ; i ++ ) { double mm = 0 ; hh += 0.5 ; mm += 6 ; } hh = hh % 360 ; mm = mm % 360 ; rad = Math . abs ( hh - mm ) ; len = Math . sqrt ( Math . pow ( a , 2 ) + Math . pow ( b , 2 ) - 2 * a * b * Math . cos ( Math . toRadians ( rad ) ) ) ; System . out . println ( len ) ; } } +import java . io . * ; import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner s = new Scanner ( System . in ) ; int k = s . nextInt ( ) ; int n = s . nextInt ( ) ; int [ ] arr = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { arr [ i ] = s . nextInt ( ) ; } int maxdiff = 0 ; for ( int i = 1 ; i < n ; i ++ ) { if ( maxdiff < arr [ i ] - arr [ i - 1 ] ) maxdiff = arr [ i ] - arr [ i - 1 ] ; } if ( maxdiff < k - arr [ n - 1 ] + arr [ 0 ] ) { System . out . println ( k - ( k - arr [ n - 1 ] + arr [ 0 ] ) ) ; } else { int i = 1 ; System . out . println ( k - maxdiff ) ; } } } +import java . util . * ; import java . lang . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int M = sc . nextInt ( ) ; String [ ] ac = new String [ N + 1 ] ; int [ ] wa = new int [ N + 1 ] ; for ( int i = 0 ; i < N + 1 ; i ++ ) { ac [ i ] = " Q " ; } int count1 = 0 ; for ( int i = 0 ; i < M ; i ++ ) { int a = sc . nextInt ( ) ; String ss = sc . next ( ) ; if ( ss . equals ( " AC " ) ) { ac [ a ] = " AC " ; } else { if ( ac [ a ] . equals ( " Q " ) ) { wa [ a ] ++ ; } } } int count2 = 0 ; for ( int i = 0 ; i < N + 1 ; i ++ ) { if ( ac [ i ] . equals ( " AC " ) ) { count1 ++ ; } else { int i = 0 ; wa [ i ] = 0 ; } count2 += wa [ i ] ; } System . out . println ( count1 + " " + count2 ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int n = Integer . valueOf ( br . readLine ( ) ) ; int z = Integer . valueOf ( br . readLine ( ) ) ; if ( n == 1 ) { if ( z == 2 ) { System . out . print ( " 3 " ) ; } else if ( z == 3 ) { System . out . print ( " 2 " ) ; } } else if ( n == 2 ) { int z = Integer . valueOf ( br . readLine ( ) ) ; if ( z == 1 ) { System . out . print ( " 3 " ) ; } else if ( z == 3 ) { System . out . print ( " 1 " ) ; } } else if ( n == 3 ) { if ( z == 1 ) { System . out . print ( " 2 " ) ; } else if ( z == 2 ) { System . out . print ( " 1 " ) ; } } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws Exception { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int [ ] h = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { h [ i ] = sc . nextInt ( ) ; } int max = h [ 0 ] ; boolean b = true ; for ( int i = 0 ; i < N ; i ++ ) { if ( h [ i ] < max - 1 ) { b = false ; break ; } if ( h [ i ] > max ) { max = h [ i ] ; } } System . out . println ( b ? " Yes " : " No " ) ; } } +import java . util . * ; import java . io . * ; import java . awt . geom . * ; public class Main { public static void main ( String [ ] args ) throws IOException { int i = 0 ; BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; StringBuilder sb = new StringBuilder ( ) ; int n = Integer . parseInt ( br . readLine ( ) ) ; int [ ] arr = new int [ n - 1 ] ; String [ ] s = br . readLine ( ) . split ( " " ) ; int prev = 987654321 ; long sum = 0 ; for ( int i = 0 ; i < n - 1 ; i ++ ) { int curr = Integer . parseInt ( s [ i ] ) ; sum += ( long ) Math . min ( prev , curr ) ; prev = curr ; } sum += prev ; System . out . println ( sum ) ; } } +import java . io . BufferedReader ; import java . io . * ; import java . util . * ; import java . util . ArrayList ; import java . util . Iterator ; import java . util . List ; import java . util . Collections ; public class Main { public static void main ( final String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; String s = sc . next ( ) ; int count = 0 ; if ( n % 2 == 1 ) { count ++ ; } char [ ] work = new char [ s . length ( ) ] ; for ( int i = 0 ; i < n ; i ++ ) { work [ i ] = s . charAt ( i ) ; } for ( int i = 0 ; i < n / 2 ; i ++ ) { if ( work [ i ] == work [ i + n / 2 ] ) { } else { count ++ ; } } if ( count == 0 ) { int i = 0 ; 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 n = sc . nextInt ( ) ; String s = sc . next ( ) ; sc . close ( ) ; if ( ( n + 2 ) % 2 != 0 ) { System . out . println ( " No " ) ; return ; } if ( n == 2 ) { String s = sc . next ( ) ; System . out . println ( s . charAt ( 0 ) == s . charAt ( 1 ) ? " Yes " : " No " ) ; return ; } System . out . println ( s . substring ( 0 , n / 2 - 1 ) . equals ( s . substring ( n / 2 , n - 1 ) ) ? " Yes " : " No " ) ; } } +import java . util . * ; import java . lang . * ; import java . io . * ; public final class Main { public static void main ( String [ ] args ) throws java . lang . Exception { Scanner in = new Scanner ( System . in ) ; int n = in . nextInt ( ) ; int m = in . nextInt ( ) ; int sum = 0 ; for ( int i = 0 ; i < m ; i ++ ) sum += in . nextInt ( ) ; int re = n - sum ; if ( re < 0 ) { int re = n - sum ; System . out . println ( - 1 ) ; } else { System . out . println ( re ) ; } } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int X = sc . nextInt ( ) ; int [ ] L = new int [ N ] ; int [ ] D = new int [ N + 1 ] ; D [ 0 ] = 0 ; for ( int i = 0 ; i < N ; i ++ ) { int i = 1 ; L [ i ] = sc . nextInt ( ) ; } int ans = 1 ; for ( int i = 1 ; i <= N ; i ++ ) { D [ i ] = D [ i - 1 ] + L [ i - 1 ] ; if ( D [ i ] <= X ) { ans += 1 ; } } System . out . println ( ans ) ; } } +import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int [ ] n = new int [ 3 ] ; for ( int i = 0 ; i < 3 ; i ++ ) { int i = 0 ; n [ i ] = scan . nextInt ( ) ; } int k = scan . nextInt ( ) ; Arrays . sort ( n ) ; for ( int i = 0 ; i < k ; i ++ ) { n [ 2 ] *= 2 ; } int a = 0 ; for ( int i = 0 ; i < 3 ; i ++ ) { a += n [ i ] ; } System . out . println ( a ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int digit = sc . nextInt ( ) ; Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int min = Integer . MAX_VALUE ; int ans = 0 ; for ( int i = 0 ; i < N ; i ++ ) { int digit = sc . nextInt ( ) ; if ( min > digit ) { min = digit ; ans ++ ; } } System . out . println ( ans ) ; sc . close ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; int w = sc . nextInt ( ) ; int n = sc . nextInt ( ) ; int [ ] lot = new int [ w ] ; String bar ; String [ ] s ; int a ; int b ; int save ; for ( int i = 0 ; i < w ; i ++ ) { lot [ i ] = i + 1 ; } for ( int i = 0 ; i < n ; i ++ ) { bar = sc . next ( ) ; s = bar . split ( " , " ) ; a = Integer . parseInt ( s [ 0 ] ) ; b = Integer . parseInt ( s [ 1 ] ) ; save = lot [ b - 1 ] ; lot [ b - 1 ] = lot [ a - 1 ] ; lot [ a - 1 ] = save ; } for ( int i = 0 ; i < w ; i ++ ) { System . out . println ( " " + lot [ i ] ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { int ans2 = 0 ; Scanner scn = new Scanner ( System . in ) ; int a = scn . nextInt ( ) ; int b = scn . nextInt ( ) ; int ans = a * b ; int ans2 = 0 ; for ( int i = 0 ; i < b ; i ++ ) { ans2 += a ; } System . out . println ( ans2 ) ; } } +import java . io . IOException ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws IOException { Scanner scanner = new Scanner ( System . in ) ; int a = scanner . nextInt ( ) ; for ( int i = 3 ; i <= a ; i ++ ) { int i = 3 ; if ( i % 3 == 0 || String . valueOf ( i ) . contains ( " 3 " ) ) System . out . print ( " " + i ) ; } System . out . println ( ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int i = A ; Scanner sc = new Scanner ( System . in ) ; int A = sc . nextInt ( ) ; int B = sc . nextInt ( ) ; int count = 0 ; for ( int i = A ; i <= B ; i ++ ) { int a = i / 10000 ; int b = i % 10 ; int c = i / 10 % 10 ; int d = i / 1000 % 10 ; if ( a == b && c == d ) { count ++ ; } } System . out . println ( count ) ; } } +import java . util . ArrayList ; import java . util . List ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int N = Integer . parseInt ( scanner . nextLine ( ) ) ; String line = scanner . nextLine ( ) ; String [ ] split = line . split ( " " ) ; List < Integer > intList = new ArrayList < Integer > ( ) ; for ( String s : split ) { intList . add ( Integer . parseInt ( s ) ) ; } int cnt = 1 ; int min = intList . get ( 0 ) ; for ( int i = 1 ; i < intList . size ( ) ; i ++ ) { int target = intList . get ( i ) ; if ( target <= min ) { int target = intList . get ( i ) ; cnt ++ ; min = target ; } } int result = cnt ; System . out . println ( result ) ; } } +import java . util . * ; public class Main { Scanner sc = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { new Main ( ) . run ( ) ; } private void run ( ) { int a ; int N = sc . nextInt ( ) ; int [ ] A = new int [ N ] ; for ( int i = 0 ; i < N - 1 ; i ++ ) { A [ sc . nextInt ( ) - 1 ] ++ ; } for ( int a : A ) { System . out . println ( a ) ; } sc . close ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( final String [ ] args ) { int k = Integer . parseInt ( sc . next ( ) ) ; Scanner sc = new Scanner ( System . in ) ; int a = Integer . parseInt ( sc . next ( ) ) ; int b = Integer . parseInt ( sc . next ( ) ) ; int c = Integer . parseInt ( sc . next ( ) ) ; int k = Integer . parseInt ( sc . next ( ) ) ; if ( k <= a + b ) { if ( k >= a ) { System . out . println ( a ) ; } else { System . out . println ( k ) ; } } else { System . out . println ( a - ( k - a - b ) ) ; } sc . close ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; boolean flg = true ; for ( int i = 0 ; i < n ; i ++ ) { int a = sc . nextInt ( ) ; if ( a % 2 == 0 ) { int a = sc . nextInt ( ) ; if ( ! ( a % 3 == 0 || a % 5 == 0 ) ) { flg = false ; } } } System . out . println ( flg ? " APPROVED " : " DENIED " ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int times ; Scanner scan = new Scanner ( System . in ) ; String n = scan . next ( ) ; String x = scan . next ( ) ; String t = scan . next ( ) ; int nn = Integer . parseInt ( n ) ; int xx = Integer . parseInt ( x ) ; int tt = Integer . parseInt ( t ) ; int times ; if ( nn % xx == 0 ) { times = nn / xx ; } else { times = ( nn / xx ) + 1 ; } int answer = tt * times ; System . out . println ( answer ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; HashMap < String , Integer > map = new HashMap < String , Integer > ( ) ; long ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { String s2 = new String ( c ) ; String s = sc . next ( ) ; char [ ] c = s . toCharArray ( ) ; Arrays . sort ( c ) ; String s2 = new String ( c ) ; if ( map . containsKey ( s2 ) ) { ans += ( long ) map . get ( s2 ) ; map . put ( s2 , map . get ( s2 ) + 1 ) ; } else { map . put ( s2 , 1 ) ; } } System . out . println ( ans ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; char [ ] s = sc . next ( ) . toCharArray ( ) ; char [ ] t = sc . next ( ) . toCharArray ( ) ; for ( int i = 0 ; i < n ; i ++ ) { int i = 0 ; System . out . print ( s [ i ] ) ; System . out . print ( t [ i ] ) ; } sc . close ( ) ; } } +import java . util . * ; import java . io . * ; public class Main { public static void main ( String [ ] args ) throws Exception { int total = 0 ; BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; PrintWriter out = new PrintWriter ( new OutputStreamWriter ( System . out ) ) ; String [ ] input = br . readLine ( ) . split ( " " ) ; int n = Integer . parseInt ( input [ 0 ] ) ; int a = Integer . parseInt ( input [ 1 ] ) ; int b = Integer . parseInt ( input [ 2 ] ) ; int ans = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { int num = i ; int total = 0 ; while ( num > 0 ) { total += num % 10 ; num /= 10 ; } if ( a <= total && total <= b ) { ans += i ; } } out . println ( ans ) ; out . close ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int ans = 0 ; try ( Scanner scanner = new Scanner ( System . in ) ) { int x = scanner . nextInt ( ) ; int ans = 0 ; if ( x == 0 ) { ans = 1 ; } System . out . println ( ans ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; int A = sc . nextInt ( ) ; int B = sc . nextInt ( ) ; int C = sc . nextInt ( ) ; int K = sc . nextInt ( ) ; int ans ; if ( K <= A ) { ans = K ; } else if ( K <= A + B ) { int ans ; ans = A ; } else { ans = A - ( K - ( A + B ) ) ; } System . out . println ( ans ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; String N = sc . nextLine ( ) ; sc . close ( ) ; String [ ] a = new String [ 3 ] ; a [ 0 ] = N . substring ( 0 , 1 ) ; a [ 1 ] = N . substring ( 1 , 2 ) ; a [ 2 ] = N . substring ( 2 , 3 ) ; for ( int i = 0 ; i < 3 ; i ++ ) { if ( a [ i ] . equals ( " 1 " ) ) { a [ i ] = " 9 " ; } else if ( a [ i ] . equals ( " 9 " ) ) { a [ i ] = " 1 " ; } } System . out . println ( a [ 0 ] + a [ 1 ] + a [ 2 ] ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int n = in . nextInt ( ) ; int ac = 0 ; int wa = 0 ; int tle = 0 ; int re = 0 ; for ( int i = 0 ; i <= n ; ++ i ) { int re = 0 ; String curr = in . nextLine ( ) ; if ( curr . equals ( " AC " ) ) ++ ac ; if ( curr . equals ( " WA " ) ) ++ wa ; if ( curr . equals ( " TLE " ) ) ++ tle ; if ( curr . equals ( " RE " ) ) ++ re ; } System . out . println ( " AC x " + ac ) ; System . out . println ( " WA x " + wa ) ; System . out . println ( " TLE x " + tle ) ; System . out . println ( " RE x " + re ) ; } } +import java . math . BigInteger ; import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; BigInteger N = scanner . nextBigInteger ( ) ; BigInteger K = scanner . nextBigInteger ( ) ; scanner . close ( ) ; BigInteger a = N . remainder ( K ) ; if ( a . compareTo ( K . subtract ( a ) ) > 0 ) { BigInteger a = N . remainder ( K ) ; System . out . println ( K . subtract ( a ) ) ; } else { System . out . println ( a ) ; } } } +import java . util . * ; import java . io . * ; public class Main { public static void main ( String [ ] args ) throws Exception { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; PrintWriter out = new PrintWriter ( new OutputStreamWriter ( System . out ) ) ; String [ ] input1 = br . readLine ( ) . split ( " " ) ; int n = Integer . parseInt ( input1 [ 0 ] ) ; int k = Integer . parseInt ( input1 [ 1 ] ) ; String [ ] input2 = br . readLine ( ) . split ( " " ) ; int [ ] numbers = new int [ n ] ; int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int i = 0 ; numbers [ i ] = Integer . parseInt ( input2 [ i ] ) ; if ( numbers [ i ] >= k ) { ans ++ ; } } out . println ( ans ) ; out . close ( ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . HashSet ; import java . util . Set ; public class Main { public static void main ( String [ ] args ) { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; Set < Integer > set = new HashSet ( ) ; int a = getInput ( ) ; do { set . add ( a ) ; a = f ( a ) ; } while ( ! set . contains ( a ) ) ; System . out . println ( set . size ( ) + 1 ) ; return ; } private static int f ( int n ) { if ( n % 2 == 0 ) { return n / 2 ; } else { return 3 * n + 1 ; } } private static int getInput ( ) { int ret = 0 ; BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; try { ret = Integer . parseInt ( br . readLine ( ) . trim ( ) ) ; } catch ( IOException e ) { System . err . println ( e . getMessage ( ) ) ; } return ret ; } } +import java . util . ArrayList ; import java . util . Arrays ; import java . util . HashMap ; import java . util . List ; import java . util . Map ; import java . util . Map . Entry ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int n = Integer . parseInt ( scanner . nextLine ( ) ) ; String [ ] tmp = scanner . nextLine ( ) . split ( " " ) ; int [ ] list = new int [ n ] ; int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { list [ i ] = Integer . parseInt ( tmp [ i ] ) ; } for ( int i = 0 ; i < n ; i ++ ) { int k = i ; int r = i ; int min = Integer . MAX_VALUE ; while ( list [ i ] != 0 ) { while ( r < n && list [ r ] != 0 ) { min = Math . min ( min , list [ r ] ) ; r ++ ; } for ( int k = i ; k < r ; k ++ ) { list [ k ] -= min ; } ans += min ; r = i ; } } System . out . println ( ans ) ; } } +import java . util . Scanner ; public class Main { static int N ; static int [ ] w ; public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; N = scanner . nextInt ( ) ; w = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { w [ i ] = scanner . nextInt ( ) ; } scanner . close ( ) ; int ans = Integer . MAX_VALUE ; int s1 = 0 ; for ( int i = 0 ; i < N - 1 ; i ++ ) { int j = N - 1 ; int s2 = 0 ; for ( int j = N - 1 ; i + 1 <= j ; j -- ) { s2 += w [ j ] ; } s1 += w [ i ] ; ans = Math . min ( ans , Math . abs ( s1 - s2 ) ) ; } System . out . println ( ans ) ; } } +import java . util . * ; import java . lang . * ; import java . math . * ; public class Main { Scanner sc = new Scanner ( System . in ) ; void run ( ) { int i = 1 ; int w = sc . nextInt ( ) ; int n = sc . nextInt ( ) ; int [ ] ret = new int [ w + 1 ] ; for ( int i = 0 ; i < w + 1 ; i ++ ) ret [ i ] = i ; for ( int k = 0 ; k < n ; k ++ ) { String ts = sc . next ( ) ; ts = ts . replace ( ',' , ' ' ) ; Scanner str = new Scanner ( ts ) ; int d1 = str . nextInt ( ) ; int d2 = str . nextInt ( ) ; int temp = ret [ d1 ] ; ret [ d1 ] = ret [ d2 ] ; ret [ d2 ] = temp ; } for ( int i = 1 ; i < w + 1 ; i ++ ) { System . out . println ( ret [ i ] ) ; } } public static void main ( String [ ] args ) { Main m = new Main ( ) ; m . run ( ) ; } } +import java . io . * ; public class Main { public static void main ( String [ ] args ) throws Exception { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int n = Integer . parseInt ( br . readLine ( ) ) ; String [ ] S = br . readLine ( ) . split ( " " ) ; int q = Integer . parseInt ( br . readLine ( ) ) ; String [ ] T = br . readLine ( ) . split ( " " ) ; int count = 0 ; for ( int i = 0 ; i < q ; i ++ ) { if ( binarysarch ( S , T [ i ] ) != - 1 ) count ++ ; } System . out . println ( count ) ; } public static int binarysarch ( String [ ] S , String x ) { int lx = 0 , rx = S . length - 1 ; while ( lx <= rx ) { int c = ( lx + rx ) / 2 ; if ( Integer . parseInt ( S [ c ] ) == Integer . parseInt ( x ) ) { int c = ( lx + rx ) / 2 ; return c ; } else if ( Integer . parseInt ( S [ c ] ) < Integer . parseInt ( x ) ) { lx = c + 1 ; } else { rx = c - 1 ; } } return - 1 ; } } +import java . util . ArrayList ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int a , b ; Scanner s = new Scanner ( System . in ) ; int a , b ; ArrayList < String > str = new ArrayList < String > ( ) ; String [ ] result ; while ( s . hasNext ( ) ) { a = s . nextInt ( ) ; b = s . nextInt ( ) ; System . out . println ( String . valueOf ( a + b ) . length ( ) ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int [ ] k = new int [ N ] ; Boolean allZero = false ; int count = 0 ; for ( int i = 0 ; i < N ; i ++ ) { k [ i ] = sc . nextInt ( ) ; } while ( ! allZero ) { allZero = true ; int now = 0 ; Boolean isZero = true ; while ( now < N ) { Boolean isZero = true ; if ( k [ now ] > 0 ) { k [ now ] -= 1 ; isZero = false ; allZero = false ; } else if ( k [ now ] <= 0 && isZero ) { } else { count ++ ; isZero = true ; } now ++ ; } if ( ! isZero ) { count ++ ; } } sc . close ( ) ; System . out . println ( count ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int s = h / a ; Scanner sc = new Scanner ( System . in ) ; int h = sc . nextInt ( ) ; int a = sc . nextInt ( ) ; int s = h / a ; if ( h % a != 0 ) { s ++ ; } System . out . println ( s ) ; sc . close ( ) ; } } +import java . util . HashSet ; import java . util . Scanner ; import java . util . Set ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; Set < String > used = new HashSet < String > ( ) ; String s = sc . next ( ) ; used . add ( s ) ; for ( int i = 1 ; i < N ; i ++ ) { String t = sc . next ( ) ; String t = sc . next ( ) ; if ( used . contains ( t ) ) { System . out . println ( " No " ) ; break ; } else { used . add ( t ) ; } if ( s . charAt ( s . length ( ) - 1 ) != t . charAt ( 0 ) ) { System . out . println ( " No " ) ; break ; } if ( i == N - 1 ) { System . out . println ( " Yes " ) ; } s = t ; } } } +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 ( ) ; String s = sc . next ( ) ; if ( s . charAt ( A ) != '-' ) { System . out . println ( " No " ) ; return ; } for ( int i = 0 ; i < s . length ( ) ; i ++ ) { int i = 0 ; if ( i != A ) { if ( s . charAt ( i ) < '0' || s . charAt ( i ) > '9' ) { System . out . println ( " No " ) ; return ; } } } System . out . println ( " Yes " ) ; return ; } } +import java . util . * ; public class Main { public static Scanner scanner = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { int n = scanner . nextInt ( ) ; int k = scanner . nextInt ( ) ; int [ ] stones = new int [ n + 1 ] ; int [ ] dp = new int [ n + 1 ] ; for ( int i = 1 ; i <= n ; i ++ ) { stones [ i ] = scanner . nextInt ( ) ; } System . out . println ( solve ( stones , dp , n , k ) ) ; } public static int solve ( int [ ] stones , int [ ] dp , int n , int k ) { if ( n <= 1 ) { int j = i - 1 ; return 0 ; } for ( int i = 2 ; i <= n ; i ++ ) { dp [ i ] = Integer . MAX_VALUE ; for ( int j = i - 1 ; j >= 1 && ( i - j ) <= k ; j -- ) { dp [ i ] = Math . min ( dp [ i ] , Math . abs ( stones [ i ] - stones [ j ] ) + dp [ j ] ) ; } } return dp [ n ] ; } } +import java . util . * ; import java . math . * ; public class Main { public static void main ( String [ ] args ) { int j = 0 ; Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int K = sc . nextInt ( ) ; List < Integer > a = new ArrayList < > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { int d = sc . nextInt ( ) ; a . add ( d ) ; } Collections . sort ( a ) ; int price = 0 ; for ( int j = 0 ; j < K ; j ++ ) { price += a . get ( j ) ; } System . out . println ( price ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new java . util . Scanner ( System . in ) ; int n = scan . nextInt ( ) ; int [ ] p = new int [ n ] ; int a = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int i = 1 ; p [ i ] = scan . nextInt ( ) ; } for ( int i = 1 ; i < n - 1 ; i ++ ) { if ( p [ i - 1 ] < p [ i ] && p [ i ] < p [ i + 1 ] || p [ i - 1 ] > p [ i ] && p [ i ] > p [ i + 1 ] ) { a ++ ; } } System . out . println ( a ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner kbd = new Scanner ( System . in ) ; int n = kbd . nextInt ( ) ; int d = kbd . nextInt ( ) ; int num = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int num = 0 ; long x = kbd . nextInt ( ) ; long y = kbd . nextInt ( ) ; if ( Math . sqrt ( x * x + y * y ) <= d ) { num ++ ; } } System . out . println ( num ) ; } } +import java . util . * ; import java . io . * ; public class Main { public static void main ( String [ ] args ) throws Exception { InputStreamReader r = new InputStreamReader ( System . in ) ; long A = nextInt ( r ) ; long B = nextInt ( r ) ; long ans = A > B ? calcLCM ( A , B ) : calcLCM ( B , A ) ; System . out . println ( ans ) ; } public static int nextInt ( InputStreamReader r ) throws Exception { String str = " " ; while ( true ) { long tmp = small ; int c = r . read ( ) ; if ( c == 32 || c == 10 || c == - 1 ) { break ; } str += ( char ) c ; } return Integer . parseInt ( str ) ; } public static long calcLCM ( long large , long small ) { long result = 0 ; long tmp = small ; while ( true ) { if ( small % large == 0 ) { result = small ; break ; } else { small += tmp ; } } return result ; } } +import java . util . Scanner ; public class Main { public static void main ( String ... args ) { try ( Scanner sc = new Scanner ( System . in ) ) { int n = sc . nextInt ( ) ; int k = sc . nextInt ( ) ; int [ ] h = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { h [ i ] = sc . nextInt ( ) ; } int [ ] dp = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { if ( i == 0 ) dp [ i ] = 0 ; else dp [ i ] = Integer . MAX_VALUE ; for ( int j = 1 ; j <= k ; j ++ ) { if ( i >= j ) dp [ i ] = mindp ( dp [ i ] , dp [ i - j ] + Math . abs ( h [ i ] - h [ i - j ] ) ) ; } } System . out . println ( dp [ n - 1 ] ) ; } } public static int mindp ( int a , int b ) { if ( a > b ) { int j = 1 ; a = b ; } return a ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int totalFlower = scanner . nextInt ( ) ; int [ ] flowersHeight = new int [ totalFlower ] ; int maxFlowerHeight = 0 ; for ( int i = 0 ; i < totalFlower ; ++ i ) { flowersHeight [ i ] = scanner . nextInt ( ) ; maxFlowerHeight = Math . max ( maxFlowerHeight , flowersHeight [ i ] ) ; } int wateringTimes = 0 ; loop : while ( true ) { boolean start = false ; for ( int i = 0 , j = 0 ; i < totalFlower ; ++ i ) { if ( ! start && ( flowersHeight [ i ] != 0 ) ) { int i = 0 , j = 0 ; -- flowersHeight [ i ] ; start = true ; } else if ( start && ( flowersHeight [ i ] != 0 ) ) { -- flowersHeight [ i ] ; } else if ( start && ( flowersHeight [ i ] == 0 ) ) { break ; } else { if ( ++ j == totalFlower ) break loop ; } } ++ wateringTimes ; } System . out . print ( wateringTimes ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws Exception { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; Main m = new Main ( sc ) ; m . show ( m . solve ( ) ) ; sc . close ( ) ; } Scanner sc ; int [ ] x ; Main ( Scanner sc ) { this . sc = sc ; this . x = new int [ 5 ] ; } private int solve ( ) { int answer = 0 ; for ( int i = 0 ; i < 5 ; i ++ ) { x [ i ] = sc . nextInt ( ) ; if ( x [ i ] == 0 ) { answer = i + 1 ; } } return answer ; } public void show ( int answer ) { System . out . println ( answer ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int i = 1 ; Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; double [ ] v = new double [ N ] ; for ( int i = 0 ; i < v . length ; i ++ ) { v [ i ] = sc . nextDouble ( ) ; } Arrays . sort ( v ) ; double res = v [ 0 ] ; for ( int i = 1 ; i < v . length ; i ++ ) { res = ( res + v [ i ] ) / 2 ; } System . out . println ( res ) ; sc . close ( ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int A = sc . nextInt ( ) ; int B = sc . nextInt ( ) ; int C = sc . nextInt ( ) ; int D = sc . nextInt ( ) ; if ( A <= C && B <= C ) { System . out . println ( " 0 " ) ; } else if ( A <= C && B <= D ) { int D = sc . nextInt ( ) ; System . out . println ( B - C ) ; } else if ( A <= C && B > D ) { System . out . println ( D - C ) ; } else if ( A > C && D <= A ) { System . out . println ( " 0 " ) ; } else if ( A > C && B >= D ) { System . out . println ( D - A ) ; } else { System . out . println ( B - A ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { String a = String . valueOf ( s . charAt ( i ) ) ; Scanner sc = new Scanner ( System . in ) ; int n = Integer . parseInt ( sc . next ( ) ) ; int k = Integer . parseInt ( sc . next ( ) ) ; String s = sc . next ( ) ; StringBuilder answer = new StringBuilder ( ) ; for ( int i = 0 ; i < n ; i ++ ) { String a = String . valueOf ( s . charAt ( i ) ) ; if ( ( i + 1 ) == k ) { a = a . toLowerCase ( ) ; } answer . append ( a ) ; } System . out . println ( answer ) ; sc . close ( ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws IOException { int [ ] data = new int [ 10 ] ; final String BR = System . getProperty ( " line.separator " ) ; int first = 0 , second = 0 , third = 0 ; BufferedReader in = new BufferedReader ( new InputStreamReader ( System . in ) ) ; for ( int i = 0 ; i < 10 ; i ++ ) { data [ i ] = Integer . parseInt ( in . readLine ( ) ) ; } for ( int datum : data ) { int temp1 = 0 , temp2 = 0 ; if ( first < datum ) { temp1 = first ; temp2 = second ; first = datum ; second = temp1 ; third = temp2 ; } else if ( second < datum ) { temp2 = second ; second = datum ; third = temp2 ; } else if ( third < datum ) { int temp1 = 0 , temp2 = 0 ; third = datum ; } } System . out . println ( first + BR + second + BR + third ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws NumberFormatException , IOException { BufferedReader in = new BufferedReader ( new InputStreamReader ( System . in ) ) ; byte arrayLength = Byte . parseByte ( in . readLine ( ) ) ; byte [ ] array = new byte [ arrayLength ] ; short count = 0 ; String [ ] strData = in . readLine ( ) . split ( " " ) ; for ( byte i = 0 ; i < arrayLength ; i ++ ) { array [ i ] = Byte . parseByte ( strData [ i ] ) ; } for ( int x = 0 ; x < arrayLength ; x ++ ) { for ( byte y = ( byte ) ( arrayLength - 1 ) ; y > x ; y -- ) { if ( array [ y ] < array [ y - 1 ] ) { byte temp = array [ y ] ; array [ y ] = array [ y - 1 ] ; array [ y - 1 ] = temp ; count ++ ; } } } for ( int z = 0 ; z < arrayLength ; z ++ ) { if ( z == arrayLength - 1 ) { int z = 0 ; System . out . println ( array [ z ] ) ; } else { System . out . print ( array [ z ] + " " ) ; } } System . out . println ( count ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; while ( true ) { int H = sc . nextInt ( ) ; int W = sc . nextInt ( ) ; if ( H == 0 && W == 0 ) break ; for ( int i = 1 ; i <= H ; i ++ ) { if ( i == 1 || i == H ) { int j = 1 ; for ( int j = 1 ; j <= W ; j ++ ) { System . out . print ( " # " ) ; } } else { for ( int j = 1 ; j <= W ; j ++ ) { if ( j == 1 || j == W ) System . out . print ( " # " ) ; else System . out . print ( " . " ) ; } } System . out . println ( ) ; } System . out . println ( ) ; } } } +import java . util . Scanner ; class Main { public static void main ( String [ ] arg ) { int i = 0 ; String input ; Scanner in = new Scanner ( System . in ) ; while ( true ) { input = in . nextLine ( ) ; if ( input . equals ( " 0 " ) ) break ; int tmp = 0 ; for ( int i = 0 ; i < input . length ( ) ; ++ i ) { char ch = input . charAt ( i ) ; tmp += Character . getNumericValue ( ch ) ; } System . out . println ( tmp ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; char [ ] n = sc . nextLine ( ) . toCharArray ( ) ; int sum = 0 ; for ( char c : n ) { sum += Character . getNumericValue ( c ) ; } if ( sum % 9 == 0 ) { char c ; System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } } +import java . io . * ; class Main { public static void main ( String [ ] args ) throws IOException { int i = n ; BufferedReader input = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String str = input . readLine ( ) ; int m = 0 , n = str . length ( ) - 1 ; char [ ] ch = str . toCharArray ( ) ; for ( int i = n ; i >= 0 ; i -- ) { System . out . print ( ch [ i ] ) ; } System . out . println ( ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; int n = 5 ; int [ ] array = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { int i = 0 ; array [ i ] = sc . nextInt ( ) ; } int tmp = 0 ; int tmp2 = 10 - ( array [ 0 ] % 10 ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( array [ i ] % 10 == 0 ) continue ; if ( tmp2 < 10 - ( array [ i ] % 10 ) ) { tmp2 = 10 - ( array [ i ] % 10 ) ; tmp = i ; } } int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( tmp == i ) continue ; if ( array [ i ] % 10 != 0 ) { array [ i ] += 10 - ( array [ i ] % 10 ) ; } count += array [ i ] ; } count += array [ tmp ] ; System . out . println ( count ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int k = sc . nextInt ( ) ; int [ ] arr = new int [ 101 ] ; for ( int i = 1 ; i <= 100 ; i ++ ) { if ( ( a % i == 0 ) && ( b % i == 0 ) ) { arr [ i ] = i ; } } int count = 0 ; for ( int i = 100 ; i >= 0 ; i -- ) { int i = 100 ; if ( arr [ i ] > 0 ) { count ++ ; } if ( count == k ) { System . out . println ( i ) ; break ; } } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int t = sc . nextInt ( ) ; int tmp = 9999 ; int min = 9999 ; int [ ] ci = new int [ n ] ; int [ ] ti = new int [ n ] ; int i = 0 ; for ( i = 0 ; i < n ; i ++ ) { ci [ i ] = sc . nextInt ( ) ; ti [ i ] = sc . nextInt ( ) ; if ( ti [ i ] <= t ) { tmp = ci [ i ] ; if ( min > tmp ) { min = tmp ; } } } if ( min < 9999 ) { System . out . println ( min ) ; } else { System . out . println ( " TLE " ) ; } } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int A = sc . nextInt ( ) ; int B = sc . nextInt ( ) ; int C = sc . nextInt ( ) ; int D = sc . nextInt ( ) ; while ( true ) { C -= B ; if ( C <= 0 ) { int D = sc . nextInt ( ) ; System . out . println ( " Yes " ) ; break ; } A -= D ; if ( A <= 0 ) { System . out . println ( " No " ) ; break ; } } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int N = scan . nextInt ( ) ; int sum = N / 1000 ; if ( N % 1000 == 0 ) { int sum = N / 1000 ; System . out . println ( 0 ) ; } else { sum += 1 ; int goukei = ( 1000 * sum ) - N ; System . out . println ( goukei ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int length = sc . nextInt ( ) ; sc . nextLine ( ) ; String [ ] array = new String [ length ] ; for ( int i = 0 ; i < length ; i ++ ) { array [ i ] = sc . nextLine ( ) ; if ( i == 0 ) { int j = i + 1 ; continue ; } if ( ! ( array [ i ] . substring ( 0 , 1 ) ) . equals ( array [ i - 1 ] . substring ( array [ i - 1 ] . length ( ) - 1 ) ) ) { System . out . println ( " No " ) ; return ; } } for ( int i = 0 ; i < length - 1 ; i ++ ) { for ( int j = i + 1 ; j < length ; j ++ ) { if ( array [ i ] . equals ( array [ j ] ) ) { System . out . println ( " No " ) ; return ; } } } System . out . println ( " Yes " ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int sum = 100000 ; for ( int i = 0 ; i < n ; i ++ ) { sum += Main . DeptMaker ( sum ) ; } System . out . println ( sum ) ; } private static int DeptMaker ( int sum ) { int sum = 100000 ; int dept = ( int ) Math . ceil ( ( sum * 0.05 ) / 1000 ) * 1000 ; return dept ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int n = scan . nextInt ( ) ; int [ ] array = new int [ n + 1 ] ; for ( int i = 1 ; i <= n ; i ++ ) { int i = 1 ; array [ i ] = scan . nextInt ( ) ; } int [ ] result = new int [ n + 1 ] ; for ( int i = 1 ; i <= n ; i ++ ) { result [ array [ i ] ] = i ; } for ( int i = 1 ; i <= n ; i ++ ) { if ( i != n ) { System . out . print ( result [ i ] + " " ) ; } else { System . out . print ( result [ i ] ) ; } } } } +import java . util . Scanner ; import java . lang . Math ; public class Main { public static void main ( String [ ] args ) { int n ; double sum = 0.0 , m , v , t = 0.0 ; Scanner sc = new Scanner ( System . in ) ; while ( true ) { n = sc . nextInt ( ) ; if ( n == 0 ) break ; double [ ] A = new double [ n ] ; for ( int i = 0 ; i < A . length ; i ++ ) { A [ i ] = ( double ) sc . nextInt ( ) ; sum += A [ i ] ; } m = sum / ( double ) A . length ; for ( int i = 0 ; i < A . length ; i ++ ) { int i = 0 ; t += ( A [ i ] - m ) * ( A [ i ] - m ) ; } v = t / ( double ) A . length ; System . out . println ( Math . sqrt ( v ) ) ; sum = 0.0 ; t = 0.0 ; } } } +import java . util . * ; import java . io . * ; import java . nio . charset . StandardCharsets ; public class Main { public static void main ( String [ ] args ) throws IOException { int i = 0 ; InputStreamReader reader = new InputStreamReader ( System . in , StandardCharsets . UTF_8 ) ; BufferedReader in = new BufferedReader ( reader ) ; String [ ] tokens = in . readLine ( ) . split ( " " ) ; int A = Integer . parseInt ( tokens [ 0 ] ) ; int B = Integer . parseInt ( tokens [ 1 ] ) ; String S = in . readLine ( ) ; Set < Character > numbers = new HashSet < > ( ) ; for ( int i = 0 ; i < 10 ; ++ i ) { numbers . add ( Integer . toString ( i ) . charAt ( 0 ) ) ; } boolean valid = isValid ( S , numbers , A ) ; String str = valid ? " Yes " : " No " ; System . out . println ( str ) ; } static boolean isValid ( String S , Set < Character > numbers , int A ) { for ( int i = 0 ; i < S . length ( ) ; ++ i ) { if ( i == A ) { if ( S . charAt ( i ) != '-' ) { return false ; } } else { if ( ! numbers . contains ( S . charAt ( i ) ) ) { return false ; } } } return true ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; int k = sc . nextInt ( ) ; int s = sc . nextInt ( ) ; int z ; int count = 0 ; for ( int x = 0 ; x <= k ; x ++ ) { for ( int y = 0 ; y <= k ; y ++ ) { z = s - x - y ; if ( 0 <= z && z <= k ) { int y = 0 ; count += 1 ; } } } System . out . println ( count ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] h = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { h [ i ] = sc . nextInt ( ) ; } int cnt = 0 ; while ( true ) { int l = n ; int r = n - 1 ; for ( int i = 0 ; i < n ; i ++ ) { if ( h [ i ] > 0 ) { l = Math . min ( l , i ) ; } else if ( l < i ) { r = i - 1 ; break ; } } if ( l == n ) break ; int min = 110 ; for ( int i = l ; i <= r ; i ++ ) { min = Math . min ( min , h [ i ] ) ; } for ( int i = l ; i <= r ; i ++ ) { int i = l ; h [ i ] -= min ; } cnt += min ; } System . out . println ( cnt ) ; } } +import java . util . Scanner ; public class Main { private static Scanner scanner ; public static void main ( String [ ] args ) { scanner = new Scanner ( System . in ) ; int S ; while ( 0 > ( S = scanner . nextInt ( ) ) || S >= 86400 ) ; int hour = S / 3600 ; int minute = ( S - hour * 3600 ) / 60 ; int second = ( S - hour * 3600 - minute * 60 ) ; System . out . println ( hour + " : " + minute + " : " + second ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int i = 1 ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] d = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { d [ i ] = sc . nextInt ( ) ; } Arrays . sort ( d ) ; int ans = 1 ; for ( int i = 1 ; i < n ; i ++ ) { if ( d [ i - 1 ] != d [ i ] ) { ans ++ ; } } System . out . println ( ans ) ; } } +import java . util . * ; import java . util . Collections ; import java . util . ArrayList ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; String n = sc . next ( ) ; String ans = " " ; String x = " 1 " ; for ( int i = 0 ; i < 3 ; i ++ ) { if ( n . charAt ( i ) == x . charAt ( 0 ) ) { ans += " 9 " ; } else { ans += " 1 " ; } } System . out . println ( ans ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int seven = 0 ; int five = 0 ; while ( sc . hasNext ( ) ) { int num = sc . nextInt ( ) ; if ( num == 7 ) { seven ++ ; } else if ( num == 5 ) { five ++ ; } } if ( seven == 1 && five == 2 ) { System . out . println ( " YES " ) ; } else { int five = 0 ; System . out . println ( " NO " ) ; } } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { 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 ( ) ) ; } int count = 0 ; uncode : while ( true ) { int i = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( a [ i ] % 2 != 0 ) { break uncode ; } a [ i ] = a [ i ] / 2 ; } count ++ ; } System . out . println ( count ) ; } } +import java . util . Scanner ; import java . util . Arrays ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int N = scan . nextInt ( ) ; int [ ] costs = new int [ N ] ; int [ ] cache = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { costs [ i ] = scan . nextInt ( ) ; cache [ i ] = 2147483647 ; } cache [ 0 ] = 0 ; cache [ 1 ] = Math . abs ( costs [ 1 ] - costs [ 0 ] ) ; System . out . println ( jump ( costs , 2 , cache ) ) ; return ; } private static int jump ( int [ ] costs , int k , int [ ] cache ) { for ( int i = 2 ; i < costs . length ; i ++ ) { for ( int j = k ; j > 0 ; j -- ) { int j = k ; cache [ i ] = Math . min ( cache [ i ] , cache [ i - j ] + ( Math . abs ( costs [ i ] - costs [ i - j ] ) ) ) ; } } return cache [ costs . length - 1 ] ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = Integer . parseInt ( sc . next ( ) ) ; int [ ] p = new int [ n ] ; int idx ; for ( idx = 0 ; idx < n ; idx ++ ) { p [ idx ] = Integer . parseInt ( sc . next ( ) ) ; } int cnt = 0 ; for ( idx = 1 ; idx < n - 1 ; idx ++ ) { if ( p [ idx ] <= p [ idx - 1 ] ) { int cnt = 0 ; if ( p [ idx ] > p [ idx + 1 ] ) { ++ cnt ; } } else { if ( p [ idx ] <= p [ idx + 1 ] ) { ++ cnt ; } } } System . out . println ( cnt ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; String str = scan . nextLine ( ) ; int n1 = Integer . parseInt ( str ) ; for ( int i = 1 ; i < 10 ; i ++ ) { int i = 1 ; if ( n1 % i == 0 & n1 / i < 10 ) { System . out . println ( " Yes " ) ; return ; } } System . out . println ( " No " ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int ci = sc . nextInt ( ) ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int t = sc . nextInt ( ) ; int res = 9999 ; for ( int i = 0 ; i < n ; i ++ ) { int ci = sc . nextInt ( ) ; int ti = sc . nextInt ( ) ; if ( ti <= t && ci < res ) { res = ci ; } } if ( res != 9999 ) { System . out . println ( res ) ; } else { System . out . println ( " TLE " ) ; } } } +import java . util . Arrays ; import java . util . HashMap ; import java . util . Scanner ; public class Main { public static boolean debug = true ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; HashMap < String , Long > map = new HashMap < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { char [ ] array = sc . next ( ) . toCharArray ( ) ; Arrays . sort ( array ) ; String result = new String ( array ) ; long temp = 0 ; if ( map . containsKey ( result ) ) { temp = map . get ( result ) ; } map . put ( result , temp + 1 ) ; } long count = 0 ; for ( long c : map . values ( ) ) { long c ; count += c * ( c - 1 ) / 2 ; } System . out . println ( count ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = Integer . parseInt ( sc . next ( ) ) ; int D = Integer . parseInt ( sc . next ( ) ) ; int [ ] [ ] arrayTwoDimension = new int [ N ] [ D ] ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < D ; j ++ ) { int k = 0 ; arrayTwoDimension [ i ] [ j ] = sc . nextInt ( ) ; } } sc . close ( ) ; int count = 0 ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = i + 1 ; j < N ; j ++ ) { double squareValue = 0 ; for ( int k = 0 ; k < D ; k ++ ) { double value = Math . abs ( arrayTwoDimension [ i ] [ k ] - arrayTwoDimension [ j ] [ k ] ) ; double square = value * value ; squareValue = squareValue + square ; } double judge = Math . sqrt ( squareValue ) ; if ( judge == Math . floor ( judge ) ) { count ++ ; } } } System . out . println ( count ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader in = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String word ; int count = 0 ; word = in . readLine ( ) ; while ( true ) { String [ ] text ; text = in . readLine ( ) . split ( " " ) ; if ( text [ 0 ] . equals ( " END_OF_TEXT " ) ) { break ; } for ( String str : text ) { String str ; str = str . toLowerCase ( ) ; if ( str . matches ( word ) ) { count ++ ; } else { continue ; } } } System . out . println ( count ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int x = sc . nextInt ( ) ; int y = x ; if ( x == 2 ) { System . out . println ( 2 ) ; System . exit ( 0 ) ; } else if ( x == 3 ) { System . out . println ( 3 ) ; System . exit ( 0 ) ; } if ( y % 2 == 0 ) { y ++ ; } int n = 3 ; while ( n <= x ) { int i = 3 ; boolean b = true ; for ( int i = 3 ; i * i < y ; i += 2 ) { if ( y % i == 0 ) { b = false ; break ; } } if ( b ) { System . out . println ( y ) ; System . exit ( 0 ) ; } y += 2 ; } sc . close ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int t = sc . nextInt ( ) ; int a = sc . nextInt ( ) ; int [ ] h = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { double diff = Math . abs ( t - h [ i ] * 0.006 - a ) ; h [ i ] = sc . nextInt ( ) ; } double ansDiff = 1000000 ; int ansNum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { double diff = Math . abs ( t - h [ i ] * 0.006 - a ) ; if ( diff < ansDiff ) { ansDiff = diff ; ansNum = i + 1 ; } } System . out . println ( ansNum ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; int n = Integer . parseInt ( sc . next ( ) ) ; int cnt = 0 ; ArrayList < Integer > list = new ArrayList < > ( ) ; for ( int i = 1 ; i <= n ; i ++ ) { if ( i % 2 != 0 ) { for ( int j = 1 ; j <= n ; j ++ ) { int j = 1 ; if ( i % j == 0 ) { cnt ++ ; } } if ( cnt == 8 ) list . add ( 1 ) ; } cnt = 0 ; } System . out . println ( list . size ( ) ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 1 ; Scanner sc = new Scanner ( System . in ) ; int A = sc . nextInt ( ) ; int B = sc . nextInt ( ) ; int s = ( A >= B ) ? A : B ; int f = ( A >= B ) ? B : A ; long ans = s ; for ( int i = 1 ; i <= f ; i ++ ) { ans *= i ; if ( ans % f == 0 ) { System . out . println ( ans ) ; return ; } ans /= i ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; final String S = sc . next ( ) ; int n ; if ( " RRR " . equals ( S ) ) { n = 3 ; } else if ( " RRS " . equals ( S ) || " SRR " . equals ( S ) ) { int n ; n = 2 ; } else if ( S . contains ( " R " ) ) { n = 1 ; } else { n = 0 ; } System . out . println ( n ) ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int A = sc . nextInt ( ) ; int B = sc . nextInt ( ) ; int C = sc . nextInt ( ) ; int X = sc . nextInt ( ) ; int Y = sc . nextInt ( ) ; int price1 ; int price2 ; if ( X > Y ) { int price2 ; price1 = ( C * 2 * Y ) + ( A * ( X - Y ) ) ; price2 = C * 2 * X ; } else { price1 = ( C * 2 * X ) + ( B * ( Y - X ) ) ; price2 = C * 2 * Y ; } int price3 = A * X + B * Y ; int ans = Math . min ( price1 , price2 ) ; ans = Math . min ( ans , price3 ) ; System . out . println ( + ans ) ; } } +import java . util . Arrays ; import java . util . Scanner ; public class Main { static Scanner scanner ; public static void main ( String [ ] args ) { scanner = new Scanner ( System . in ) ; int n = gi ( ) ; int [ ] A = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { A [ i ] = gi ( ) ; } Arrays . parallelSort ( A ) ; System . out . println ( A [ A . length - 1 ] - A [ 0 ] ) ; } public static int s ( int n ) { String S = String . valueOf ( n ) ; int c = 0 ; for ( int i = 0 ; i < S . length ( ) ; i ++ ) { int k = Integer . parseInt ( S . substring ( i , i + 1 ) ) ; c += k ; } return c ; } public static long d ( long n ) { String a = String . valueOf ( n ) ; return ( long ) a . length ( ) ; } public static String gs ( ) { return scanner . next ( ) ; } public static int gi ( ) { int i = 0 ; return Integer . parseInt ( scanner . next ( ) ) ; } public static long gl ( ) { return Long . parseLong ( scanner . next ( ) ) ; } public static double gd ( ) { return Double . parseDouble ( scanner . next ( ) ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int [ ] num = new int [ 3000 ] ; int [ ] num2 = new int [ 3000 ] ; for ( int i = 0 ; i < 3000 ; i ++ ) { String line = sc . nextLine ( ) ; String [ ] ss = line . split ( " " ) ; num [ i ] = Integer . parseInt ( ss [ 0 ] ) ; num2 [ i ] = Integer . parseInt ( ss [ 1 ] ) ; if ( num [ i ] == 0 && num2 [ i ] == 0 ) { break ; } } for ( int i = 0 ; i < num . length ; i ++ ) { if ( num [ i ] == 0 && num2 [ i ] == 0 ) { break ; } if ( num [ i ] < num2 [ i ] ) { int i = 0 ; System . out . println ( num [ i ] + " " + num2 [ i ] ) ; } if ( num [ i ] > num2 [ i ] ) { System . out . println ( num2 [ i ] + " " + num [ i ] ) ; } if ( num [ i ] == num2 [ i ] ) { System . out . println ( num [ i ] + " " + num2 [ i ] ) ; } } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int X = sc . nextInt ( ) ; int N = sc . nextInt ( ) ; int [ ] p = new int [ N ] ; int [ ] q = new int [ 102 ] ; for ( int i = 0 ; i < N ; i ++ ) { p [ i ] = sc . nextInt ( ) ; q [ p [ i ] ] = 1 ; } int minDif = 1000 ; int ans = X ; for ( int i = 0 ; i <= 101 ; i ++ ) { if ( q [ i ] == 0 ) { int i = 0 ; if ( Math . abs ( X - i ) < minDif ) { ans = i ; minDif = Math . abs ( X - i ) ; } } } System . out . println ( ans ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scn = new Scanner ( System . in ) ; int N = scn . nextInt ( ) ; int [ ] A1 = new int [ N + 1 ] , A2 = new int [ N + 1 ] ; for ( int i = 1 ; i < N + 1 ; i ++ ) { A1 [ i ] = A1 [ i - 1 ] + scn . nextInt ( ) ; } for ( int i = 1 ; i < N + 1 ; i ++ ) { int i = 0 ; A2 [ i ] = A2 [ i - 1 ] + scn . nextInt ( ) ; } int ans = 0 ; for ( int i = 0 ; i < N ; i ++ ) { ans = Math . max ( ans , A1 [ i + 1 ] - A1 [ 0 ] + A2 [ N ] - A2 [ i ] ) ; } System . out . println ( ans ) ; } } +import java . util . Scanner ; public class Main { static char [ ] k = { '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' } ; public static void main ( String [ ] args ) { Scanner stdIn = new Scanner ( System . in ) ; String W = stdIn . next ( ) ; W = W . toLowerCase ( ) ; int k = 0 ; while ( true ) { int k = 0 ; String T = stdIn . next ( ) ; if ( T . equals ( " END_OF_TEXT " ) ) { break ; } T = T . toLowerCase ( ) ; if ( T . equals ( W ) ) { k ++ ; } } System . out . println ( k ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int multi ; Scanner sc = new Scanner ( System . in ) ; long w = sc . nextInt ( ) ; long h = sc . nextInt ( ) ; long x = sc . nextInt ( ) ; long y = sc . nextInt ( ) ; long area = w * h ; int multi ; if ( w / 2.0 == x && h / 2.0 == y ) { multi = 1 ; } else { multi = 0 ; } System . out . println ( area / 2.0 ) ; System . out . println ( multi ) ; } } +import java . io . BufferedReader ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws Exception { BufferedReader reader = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String [ ] str = reader . readLine ( ) . split ( " " ) ; int A = Integer . parseInt ( str [ 0 ] ) ; int B = Integer . parseInt ( str [ 1 ] ) ; if ( 1 <= A && A <= 9 && 1 <= B && B <= 9 ) { int B = Integer . parseInt ( str [ 1 ] ) ; System . out . println ( A * B ) ; } else { System . out . println ( " -1 " ) ; } } } +import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; long [ ] nums = new long [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { nums [ i ] = sc . nextLong ( ) ; } Arrays . sort ( nums ) ; long ans = nums [ 0 ] ; if ( ans == 0 ) { System . out . println ( 0 ) ; } else { boolean over = false ; for ( int i = 1 ; i < N ; i ++ ) { ans *= nums [ i ] ; if ( 1000000000000000000L < ans || ans <= 0 ) { System . out . println ( - 1 ) ; over = true ; break ; } } if ( ! over ) { int i = 1 ; System . out . println ( ans ) ; } } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int c = sc . nextInt ( ) ; int min = 0 ; int min2 = 0 ; if ( a < b ) { min = a ; if ( b < c ) { min2 = b ; } else { min2 = c ; } } else { int min2 = 0 ; min = b ; if ( a < c ) { min2 = a ; } else { min2 = c ; } } System . out . println ( min + min2 ) ; } } +import static java . lang . Math . log10 ; import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int sum = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { int temp = i ; int count = 0 ; while ( temp != 0 ) { int count = 0 ; temp = temp / 10 ; count ++ ; } if ( count % 2 == 1 ) { sum ++ ; } } System . out . println ( sum ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; while ( true ) { int middle = in . nextInt ( ) ; int term_end = in . nextInt ( ) ; int retest = in . nextInt ( ) ; int sum = middle + term_end ; if ( middle == - 1 && term_end == - 1 && retest == - 1 ) { break ; } else if ( middle == - 1 || term_end == - 1 ) { System . out . println ( " F " ) ; } else if ( sum >= 80 ) { System . out . println ( " A " ) ; } else if ( sum < 80 && sum >= 65 ) { int retest = in . nextInt ( ) ; System . out . println ( " B " ) ; } else if ( sum < 65 && sum >= 50 ) { System . out . println ( " C " ) ; } else if ( sum < 50 && sum >= 30 ) { if ( retest >= 50 ) { System . out . println ( " C " ) ; } else { System . out . println ( " D " ) ; } } else if ( sum < 30 ) { System . out . println ( " F " ) ; } } } } +import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int maxPotision = 0 ; int maxValue = 0 ; int secondValue = 0 ; boolean maxDup = false ; for ( int i = 0 ; i < N ; i ++ ) { int i = 0 ; int tmp = sc . nextInt ( ) ; if ( tmp == maxValue ) { maxDup = true ; } else if ( tmp > maxValue ) { secondValue = maxValue ; maxValue = tmp ; maxPotision = i ; maxDup = false ; } else if ( tmp > secondValue ) { secondValue = tmp ; } } if ( maxDup ) { for ( int i = 0 ; i < N ; i ++ ) { System . out . println ( maxValue ) ; } } else { for ( int i = 0 ; i < N ; i ++ ) { if ( i == maxPotision ) { System . out . println ( secondValue ) ; } else { System . out . println ( maxValue ) ; } } } } } +import java . util . ArrayList ; import java . util . List ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; List < Integer > list = new ArrayList < Integer > ( ) ; int i = 0 ; while ( i == 0 ) { String line = sc . nextLine ( ) ; String [ ] x = line . split ( " " ) ; int a = Integer . parseInt ( x [ 0 ] ) ; int b = Integer . parseInt ( x [ 2 ] ) ; String op = x [ 1 ] ; if ( op . equals ( " + " ) ) { Integer integer ; list . add ( a + b ) ; } if ( op . equals ( " - " ) ) { list . add ( a - b ) ; } if ( op . equals ( " * " ) ) { list . add ( a * b ) ; } if ( op . equals ( " / " ) ) { list . add ( a / b ) ; } if ( op . equals ( " ? " ) ) { break ; } } for ( Integer integer : list ) { System . out . println ( integer ) ; } } } +import java . util . Scanner ; class Main { private static int gcd ( int a , int b ) { while ( b != 0 ) { int k = 1 ; int r = a % b ; a = b ; b = r ; } return a ; } public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long N = sc . nextLong ( ) ; int res = 0 ; int temp = 0 ; for ( int i = 1 ; i < N + 1 ; i ++ ) { for ( int j = 1 ; j < N + 1 ; j ++ ) { temp = gcd ( i , j ) ; for ( int k = 1 ; k < N + 1 ; k ++ ) { res += gcd ( k , temp ) ; } } } System . out . println ( res ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = a ; Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int cnt = 0 ; for ( int i = a ; i <= b ; i ++ ) { int num = i ; int dig1 = num % 10 ; int dig2 = ( num / 10 ) % 10 ; int dig4 = ( num / 1000 ) % 10 ; int dig5 = num / 10000 ; if ( dig1 == dig5 && dig2 == dig4 ) cnt ++ ; } System . out . println ( cnt ) ; } } +import java . io . * ; import java . util . * ; class Main { public static void main ( String [ ] args ) { int i = 0 ; 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 ( ) ) ; } double sum = 0 ; for ( int i = 0 ; i < N ; i ++ ) { sum += ( 1.0 / A [ i ] ) ; } System . out . println ( 1.0 / sum ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; double A = sc . nextDouble ( ) ; double B = sc . nextDouble ( ) ; double rA = 0.08 ; double rB = 0.1 ; for ( int i = 12 ; i < 1001 ; i ++ ) { int i = 12 ; if ( Math . floor ( i * rA ) == A && Math . floor ( i * rB ) == B ) { System . out . println ( i ) ; return ; } } System . out . println ( - 1 ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) , M = sc . nextInt ( ) ; int min = 0 , max = 100000 ; for ( int i = 0 ; i < M ; i ++ ) { int min = 0 , max = 100000 ; int l = sc . nextInt ( ) , r = sc . nextInt ( ) ; min = Math . max ( min , l ) ; max = Math . min ( max , r ) ; } int ans = Math . max ( max - min + 1 , 0 ) ; System . out . println ( ans ) ; } } +import java . util . ArrayList ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int N = scanner . nextInt ( ) ; int K = scanner . nextInt ( ) ; int d = 0 ; ArrayList < ArrayList < Integer > > arraylist = new ArrayList < ArrayList < Integer > > ( N ) ; for ( int i = 0 ; i < N ; i ++ ) { arraylist . add ( new ArrayList < Integer > ( ) ) ; } for ( int i = 0 ; i < ( 2 * K ) ; i ++ ) { if ( i % 2 == 0 ) { d = scanner . nextInt ( ) ; } else { for ( int s = 0 ; s < d ; s ++ ) { arraylist . get ( scanner . nextInt ( ) - 1 ) . add ( i ) ; } } } int count = 0 ; for ( int i = 0 ; i < N ; i ++ ) { int i = 0 ; if ( arraylist . get ( i ) . size ( ) == 0 ) { count += 1 ; } } System . out . println ( count ) ; } } +import java . io . * ; class Main { public static void main ( String [ ] args ) { try { int i = 0 , p = 0 ; BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String [ ] cmd = br . readLine ( ) . split ( " " , 0 ) ; int [ ] S = new int [ 100 ] ; for ( int i = 0 , p = 0 ; i < cmd . length ; i ++ ) { if ( cmd [ i ] . equals ( " + " ) ) { p -- ; S [ p - 1 ] += S [ p ] ; } else if ( cmd [ i ] . equals ( " - " ) ) { p -- ; S [ p - 1 ] -= S [ p ] ; } else if ( cmd [ i ] . equals ( " * " ) ) { p -- ; S [ p - 1 ] *= S [ p ] ; } else { S [ p ] = Integer . parseInt ( " " + cmd [ i ] ) ; p ++ ; } } System . out . println ( S [ 0 ] ) ; } catch ( IOException e ) { System . out . println ( " Exception : " + e ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int M = sc . nextInt ( ) ; int C = sc . nextInt ( ) ; int [ ] B = new int [ M ] ; for ( int i = 0 ; i < M ; i ++ ) { B [ i ] = sc . nextInt ( ) ; } int num = 0 ; for ( int i = 0 ; i < N ; i ++ ) { int j = 0 ; int sum = C ; for ( int j = 0 ; j < M ; j ++ ) { sum += B [ j ] * sc . nextInt ( ) ; } if ( sum > 0 ) num ++ ; } System . out . println ( num ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; boolean cantReducedAnyMore = false ; int previous = sc . nextInt ( ) ; int current ; String result = " Yes " ; while ( sc . hasNext ( ) ) { current = sc . nextInt ( ) ; int diff = current - previous ; if ( diff > 0 ) { cantReducedAnyMore = false ; } else if ( diff == - 1 ) { if ( cantReducedAnyMore ) { result = " No " ; break ; } else { cantReducedAnyMore = true ; } } else if ( diff < - 1 ) { String result = " Yes " ; result = " No " ; break ; } previous = current ; } System . out . println ( result ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scn = new Scanner ( System . in ) ; int N = scn . nextInt ( ) ; int a = N / 100 ; int b = ( N % 100 ) / 10 ; int c = N % 10 ; int ans = 0 ; if ( a == 9 ) { ans += 100 ; } else if ( a == 1 ) { ans += 900 ; } else { int ans = 0 ; ans += 100 * a ; } if ( b == 9 ) { ans += 10 ; } else if ( b == 1 ) { ans += 90 ; } else { ans += 10 * b ; } if ( c == 9 ) { ans += 1 ; } else if ( c == 1 ) { ans += 9 ; } else { ans += 1 * c ; } 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 + 1 ] ; for ( int i = 0 ; i < n + 1 ; i ++ ) { int i = 0 ; a [ i ] = sc . nextInt ( ) ; } long sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int b = sc . nextInt ( ) ; int buster = Math . min ( a [ i ] , b ) ; int secondBuster = Math . min ( a [ i + 1 ] , b - buster ) ; a [ i + 1 ] -= secondBuster ; sum += buster + secondBuster ; } System . out . println ( sum ) ; } } +import java . io . * ; import java . util . Scanner ; public class Main { public static boolean range ( int a , int b , int c ) { if ( a >= b ) return false ; if ( b >= c ) return false ; return true ; } public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int c = sc . nextInt ( ) ; if ( range ( a , b , c ) ) { System . out . println ( " Yes " ) ; } else { int c = sc . nextInt ( ) ; System . out . println ( " No " ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int a1 = sc . nextInt ( ) ; int a2 = sc . nextInt ( ) ; int a3 = sc . nextInt ( ) ; if ( a1 + a2 + a3 >= 22 ) System . out . println ( " bust " ) ; else System . out . println ( " win " ) ; } public static int lcm ( int x , int y ) { return x * y / gcd ( x , y ) ; } public static int gcd ( int x , int y ) { if ( x < y ) return gcd ( y , x ) ; if ( y == 0 ) return x ; return gcd ( y , x % y ) ; } } class Pair { int a , b ; Pair ( int a , int b ) { this . a = a ; this . b = b ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int ans = 0 ; int [ ] array = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { int i = 0 ; array [ i ] = Integer . parseInt ( sc . next ( ) ) ; if ( i == 0 || i == 1 ) { continue ; } int a = array [ i - 2 ] ; int b = array [ i - 1 ] ; int c = array [ i ] ; if ( a == b && b == c ) { continue ; } int diff = ( a - b ) * ( b - c ) ; if ( diff >= 0 ) { ans ++ ; } } sc . close ( ) ; System . out . println ( ans ) ; } } +import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int [ ] a = new int [ 3 ] ; for ( int i = 0 ; i < 3 ; i ++ ) { int i = 0 ; a [ i ] = Integer . parseInt ( sc . next ( ) ) ; } Arrays . sort ( a ) ; int cost = 0 ; for ( int i = 0 ; i < 3 ; i ++ ) { if ( i != 0 ) { cost += a [ i ] - a [ i - 1 ] ; } } System . out . println ( cost ) ; } } +import java . util . * ; import static java . lang . Math . * ; import java . math . BigInteger ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int result = 0 ; for ( int i = a ; i < b + 1 ; i ++ ) { String s = String . valueOf ( i ) ; boolean chk = true ; for ( int j = 0 ; j < s . length ( ) / 2 ; j ++ ) { if ( s . charAt ( j ) != s . charAt ( s . length ( ) - j - 1 ) ) { int j = 0 ; chk = false ; break ; } } if ( chk ) result ++ ; } System . out . println ( result ) ; } } +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 ] ; List < Integer > list = new ArrayList < > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { A [ i ] = sc . nextInt ( ) ; list . add ( A [ i ] ) ; } Collections . sort ( list ) ; for ( int i = 0 ; i < N ; i ++ ) { if ( A [ i ] == list . get ( N - 1 ) ) { int i = 0 ; System . out . println ( list . get ( N - 2 ) ) ; } else { System . out . println ( list . get ( N - 1 ) ) ; } } } } +import java . util . Scanner ; public class Main { public void run ( ) { Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int c = sc . nextInt ( ) ; int x = sc . nextInt ( ) ; int count = 0 ; for ( int i = 0 ; i <= a ; i ++ ) { if ( x < 500 * i ) { continue ; } for ( int j = 0 ; j <= b ; j ++ ) { int remain = x - ( 500 * i + 100 * j ) ; if ( remain < 0 ) { continue ; } if ( remain / 50 <= c ) { count ++ ; } } } System . out . println ( count ) ; } public static void main ( String [ ] args ) { int j = 0 ; new Main ( ) . run ( ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] age ) throws IOException { int W = Integer . parseInt ( input [ 1 ] ) ; BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int i = 1 ; int j = 0 ; while ( true ) { String [ ] input = br . readLine ( ) . split ( " " ) ; int H = Integer . parseInt ( input [ 0 ] ) ; int W = Integer . parseInt ( input [ 1 ] ) ; if ( H == 0 && W == 0 ) break ; for ( i = 1 ; i <= H ; i ++ ) { for ( j = 1 ; j <= W ; j ++ ) { if ( i % 2 == 1 ) { if ( j % 2 == 1 ) { System . out . print ( " # " ) ; } else { System . out . print ( " . " ) ; } } else { if ( j % 2 == 1 ) { System . out . print ( " . " ) ; } else { System . out . print ( " # " ) ; } } } System . out . print ( " \n " ) ; } System . out . print ( " \n " ) ; } } } +import java . util . Scanner ; public class Main { static Scanner scan ; static int count = 0 ; public static void main ( String [ ] args ) { scan = new Scanner ( System . in ) ; final int slen = scan . nextInt ( ) ; int [ ] s = new int [ slen ] ; for ( int i = 0 ; i < slen ; i ++ ) { s [ i ] = scan . nextInt ( ) ; } final int tlen = scan . nextInt ( ) ; int [ ] t = new int [ tlen ] ; for ( int i = 0 ; i < tlen ; i ++ ) { t [ i ] = scan . nextInt ( ) ; } for ( int i = 0 ; i < tlen ; i ++ ) { binarySearch ( s , t [ i ] ) ; } System . out . println ( count ) ; } public static void binarySearch ( int [ ] s , int t ) { int hi = 0 ; int ti = s . length - 1 ; int p ; while ( hi <= ti ) { int p ; p = ( hi + ti ) / 2 ; if ( s [ p ] == t ) { count ++ ; break ; } else if ( s [ p ] < t ) { hi = p + 1 ; continue ; } else { ti = p - 1 ; continue ; } } return ; } } +import java . util . * ; import java . io . * ; import java . nio . charset . StandardCharsets ; public class Main { public static void main ( String [ ] args ) throws IOException { InputStreamReader reader = new InputStreamReader ( System . in , StandardCharsets . UTF_8 ) ; BufferedReader in = new BufferedReader ( reader ) ; Main ins = new Main ( in ) ; ins . calc ( ) ; ins . showResult ( ) ; } Main ( BufferedReader in ) throws IOException { BufferedReader in = new BufferedReader ( reader ) ; String [ ] tok = in . readLine ( ) . split ( " " ) ; int A = Integer . parseInt ( tok [ 0 ] ) ; int B = Integer . parseInt ( tok [ 1 ] ) ; System . out . println ( A * B ) ; } void calc ( ) { } void showResult ( ) { } } +import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = n - 1 ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; long [ ] a = new long [ n ] ; boolean isZero = false ; for ( int i = 0 ; i < n ; i ++ ) { long tmp = sc . nextLong ( ) ; if ( tmp == 0 ) { isZero = true ; break ; } a [ i ] = tmp ; } sc . close ( ) ; long ans = 1 ; long max = ( long ) Math . pow ( 10 , 9 ) ; int count = 0 ; boolean isLarge = false ; Arrays . sort ( a ) ; for ( int i = n - 1 ; i >= 0 ; i -- ) { ans *= a [ i ] ; if ( a [ i ] > max ) { count ++ ; } if ( count == 2 || ans > max * max ) { isLarge = true ; break ; } } if ( isZero ) { System . out . println ( 0 ) ; } else if ( isLarge ) { System . out . println ( - 1 ) ; } else { System . out . println ( ans ) ; } } } +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 ) ; Multiplication3 solver = new Multiplication3 ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class Multiplication3 { public void solve ( int testNumber , Scanner in , PrintWriter out ) { PrintWriter out = new PrintWriter ( outputStream ) ; String [ ] inputs = in . nextLine ( ) . split ( " " ) ; long a = Long . parseLong ( inputs [ 0 ] ) ; long b = Long . parseLong ( inputs [ 1 ] . replaceAll ( " \\ . " , " " ) ) ; out . append ( String . valueOf ( a * b / 100 ) ) ; } } } +import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] arg ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; double [ ] v = new double [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { int i = 2 ; v [ i ] = sc . nextDouble ( ) ; } sc . close ( ) ; Arrays . sort ( v ) ; double s = ( v [ 0 ] + v [ 1 ] ) / 2 ; if ( n >= 3 ) { for ( int i = 2 ; i < n ; i ++ ) { s = ( s + v [ i ] ) / 2 ; } } System . out . println ( s ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int input = scan . nextInt ( ) ; int [ ] num = new int [ input ] ; int count ; for ( int c = 0 ; c < input ; c ++ ) { num [ c ] = scan . nextInt ( ) ; } count = bubbleSort ( num , input ) ; for ( int i = 0 ; i < input ; i ++ ) { if ( i != input - 1 ) { System . out . print ( num [ i ] + " " ) ; } else { System . out . println ( num [ i ] ) ; } } System . out . println ( count ) ; } static int bubbleSort ( int [ ] data , int n ) { int j = n - 1 ; int temp ; int c = 0 ; for ( int i = 0 ; i < n - 1 ; i ++ ) { for ( int j = n - 1 ; j > i ; j -- ) { if ( data [ j - 1 ] > data [ j ] ) { temp = data [ j ] ; data [ j ] = data [ j - 1 ] ; data [ j - 1 ] = temp ; c ++ ; } } } return c ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int x = sc . nextInt ( ) ; int [ ] m = new int [ n ] ; int min = Integer . MAX_VALUE ; for ( int i = 0 ; i < n ; i ++ ) { m [ i ] = sc . nextInt ( ) ; x -= m [ i ] ; if ( min > m [ i ] ) { int count = m . length ; min = m [ i ] ; } } int count = m . length ; while ( x >= 0 ) { x -= min ; count ++ ; } System . out . println ( count - 1 ) ; sc . close ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int a = 0 ; int b = 0 ; int c = 0 ; int n = scanner . nextInt ( ) ; for ( int i = 0 ; i < n ; i ++ ) { a = scanner . nextInt ( ) ; b = scanner . nextInt ( ) ; c = scanner . nextInt ( ) ; if ( c * c == a * a + b * b || b * b == a * a + c * c || a * a == b * b + c * c ) { int c = 0 ; System . out . println ( " YES " ) ; } else { System . out . println ( " NO " ) ; } } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 1 ; Scanner scan = new Scanner ( System . in ) ; int num = 0 ; int ans = 0 ; for ( int i = 1 ; i < 6 ; i ++ ) { num = scan . nextInt ( ) ; if ( num == 0 ) { ans = i ; } } System . out . println ( ans ) ; } } +import java . util . HashSet ; import java . util . Scanner ; import java . util . Set ; public class Main { void run ( ) { Set < Integer > used = new HashSet < > ( ) ; Scanner sc = new Scanner ( System . in ) ; int s = sc . nextInt ( ) ; int m = 1 ; Set < Integer > used = new HashSet < > ( ) ; for ( ; ! used . contains ( s ) ; m ++ ) { used . add ( s ) ; if ( s % 2 == 0 ) { s /= 2 ; } else { s = s * 3 + 1 ; } } System . out . println ( m ) ; } public static void main ( String [ ] args ) { new Main ( ) . run ( ) ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String ns = sc . next ( ) ; String [ ] s = ns . split ( " " ) ; int count = 0 ; for ( int i = 0 ; i < s . length ; i ++ ) { if ( Integer . parseInt ( s [ i ] ) == 1 ) { int i = 0 ; count ++ ; } } System . out . println ( count ) ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) throws java . lang . Exception { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; double [ ] v = new double [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { int i = 0 ; v [ i ] = sc . nextDouble ( ) ; } Arrays . sort ( v ) ; for ( int i = 0 ; i < n - 1 ; i ++ ) { v [ i + 1 ] = ( v [ i ] + v [ i + 1 ] ) / 2d ; } System . out . println ( v [ n - 1 ] ) ; sc . close ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; int [ ] a = new int [ 3 ] ; for ( int i = 0 ; i < 3 ; i ++ ) { a [ i ] = sc . nextInt ( ) ; } if ( a [ 0 ] <= a [ 1 ] * a [ 2 ] ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { long ans = xymin * Math . min ( a + b , c * 2 ) ; Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int c = sc . nextInt ( ) ; int x = sc . nextInt ( ) ; int y = sc . nextInt ( ) ; int xymin = Math . min ( x , y ) ; long ans = xymin * Math . min ( a + b , c * 2 ) ; x -= xymin ; y -= xymin ; if ( x == 0 ) { ans += y * Math . min ( b , c * 2 ) ; } else { ans += x * Math . min ( a , c * 2 ) ; } System . out . println ( ans ) ; } } +import java . util . * ; import javax . swing . text . AbstractDocument . BranchElement ; import com . sun . org . apache . xpath . internal . SourceTree ; public class Main { public static void main ( String [ ] args ) { Integer val2 ; Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int k = sc . nextInt ( ) ; Set < Integer > ans1 = new TreeSet < > ( ) ; for ( int i = 1 ; i <= a ; i ++ ) { if ( a % i == 0 ) { ans1 . add ( i ) ; } } Set < Integer > ans2 = new TreeSet < > ( ) ; for ( int i = 1 ; i <= b ; i ++ ) { if ( b % i == 0 ) { ans2 . add ( i ) ; } } List < Integer > result = new ArrayList < > ( ) ; for ( Integer val1 : ans1 ) { for ( Integer val2 : ans2 ) { if ( val1 == val2 ) { result . add ( val1 ) ; } if ( val1 <= val2 ) { break ; } } } System . out . println ( result . get ( result . size ( ) - k ) ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] ag ) { int i = a . length ( ) - 1 ; Scanner sc = new Scanner ( System . in ) ; String a = sc . next ( ) ; int st = 0 ; int gl = a . length ( ) - 1 ; for ( int i = 0 ; i < a . length ( ) ; i ++ ) { if ( a . charAt ( i ) == 'A' ) { st = i + 1 ; break ; } } for ( int i = a . length ( ) - 1 ; i >= 0 ; i -- ) { if ( a . charAt ( i ) == 'Z' ) { gl = i + 1 ; break ; } } System . out . println ( gl - st + 1 ) ; } } +import java . io . * ; import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { BufferedReader input = new BufferedReader ( new InputStreamReader ( System . in ) ) ; PrintWriter output = new PrintWriter ( System . out ) ; StringTokenizer st = new StringTokenizer ( input . readLine ( ) ) ; int N = Integer . parseInt ( st . nextToken ( ) ) ; int K = Integer . parseInt ( st . nextToken ( ) ) ; st = new StringTokenizer ( input . readLine ( ) ) ; int [ ] arr = new int [ N ] ; int [ ] dp = new int [ N + 1 ] ; Arrays . fill ( dp , Integer . MAX_VALUE ) ; dp [ 0 ] = 0 ; for ( int i = 0 ; i < N ; i ++ ) { arr [ i ] = Integer . parseInt ( st . nextToken ( ) ) ; } for ( int i = 0 ; i < N ; i ++ ) { for ( int k = 1 ; k < K + 1 ; k ++ ) { int k = 1 ; if ( i + k < N ) dp [ i + k ] = Math . min ( dp [ i + k ] , dp [ i ] + Math . abs ( arr [ i ] - arr [ i + k ] ) ) ; } } output . println ( dp [ N - 1 ] ) ; output . close ( ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . StringTokenizer ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String W = br . readLine ( ) . toLowerCase ( ) ; int ans = 0 ; String line ; while ( ! ( ( line = br . readLine ( ) ) . equals ( " END_OF_TEXT " ) ) ) { line = line . toLowerCase ( ) ; StringTokenizer st = new StringTokenizer ( line , " " ) ; while ( st . hasMoreTokens ( ) ) { StringTokenizer st = new StringTokenizer ( line , " " ) ; if ( st . nextToken ( ) . equals ( W ) ) ans ++ ; } } System . out . println ( ans ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; int [ ] a = new int [ 3 ] ; for ( int i = 0 ; i < 3 ; i ++ ) a [ i ] = sc . nextInt ( ) ; int [ ] b = new int [ 3 ] ; for ( int i = 0 ; i < 3 ; i ++ ) { b [ i ] = a [ ( i + 2 ) % 3 ] ; System . out . print ( b [ i ] + " " ) ; } } } +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 ) ; GrandGarden solver = new GrandGarden ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class GrandGarden { public void solve ( int testNumber , Scanner in , PrintWriter out ) { int n = in . nextInt ( ) ; int [ ] h = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { h [ i ] = in . nextInt ( ) ; } long result = 0 ; int i = 0 ; while ( i < n ) { if ( h [ i ] == 0 ) { i ++ ; continue ; } int v = 1 ; result += 1 ; h [ i ] -= v ; for ( int j = i + 1 ; j < n ; j ++ ) { int j = i + 1 ; if ( h [ j ] > 0 ) { h [ j ] = ( h [ j ] >= v ) ? h [ j ] - v : 0 ; } else { break ; } } } out . print ( result ) ; } } } +import java . io . * ; import java . util . * ; import java . math . * ; import java . util . regex . Pattern ; class Main { public static void main ( String [ ] args ) { int a , b , i , small , sum = 0 ; String s = " " ; Scanner sc = new Scanner ( System . in ) ; a = sc . nextInt ( ) ; b = sc . nextInt ( ) ; if ( a < b ) { String s = " " ; small = a ; for ( i = b - 1 ; i >= 0 ; i -- ) { sum = sum + ( int ) Math . pow ( 10 , i ) ; } small = a * sum ; s = " " + small ; } else { small = b ; for ( i = a - 1 ; i >= 0 ; i -- ) { sum = sum + ( int ) Math . pow ( 10 , i ) ; } small = b * sum ; s = " " + small ; } System . out . println ( s ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner scn = new Scanner ( System . in ) ; int n = scn . nextInt ( ) ; int d = scn . nextInt ( ) ; int [ ] [ ] dot = new int [ n ] [ d ] ; int answer = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < d ; j ++ ) { int k = 0 ; dot [ i ] [ j ] = scn . nextInt ( ) ; } } for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { double check = 0 ; for ( int k = 0 ; k < d ; k ++ ) { check += ( dot [ i ] [ k ] - dot [ j ] [ k ] ) * ( dot [ i ] [ k ] - dot [ j ] [ k ] ) ; } check = Math . sqrt ( check ) ; if ( check == ( int ) check ) { answer ++ ; } } } System . out . println ( answer ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int [ ] values = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { values [ i ] = sc . nextInt ( ) ; } int count = 0 ; hoge : while ( true ) { for ( int i = 0 ; i < N ; i ++ ) { if ( values [ i ] % 2 != 0 ) { break hoge ; } values [ i ] = values [ i ] / 2 ; } count ++ ; } System . out . println ( count ) ; } } +import java . util . Scanner ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 1 ; Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; boolean flg = false ; for ( int i = 0 ; i < s . length ( ) ; i = i + 2 ) { if ( ! ( s . charAt ( i ) == 'R' || s . charAt ( i ) == 'U' || s . charAt ( i ) == 'D' ) ) { flg = true ; break ; } } for ( int i = 1 ; i < s . length ( ) ; i = i + 2 ) { if ( ! ( s . charAt ( i ) == 'L' || s . charAt ( i ) == 'U' || s . charAt ( i ) == 'D' ) ) { flg = true ; break ; } } if ( flg ) { System . out . println ( " No " ) ; } else { System . out . println ( " Yes " ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int [ ] c = new int [ 9 ] ; for ( int i = 0 ; i < N ; i ++ ) { int tmp = sc . nextInt ( ) / 400 ; if ( tmp > 8 ) tmp = 8 ; c [ tmp ] ++ ; } int max , min = 0 ; for ( int i = 0 ; i < 8 ; i ++ ) { if ( c [ i ] != 0 ) min ++ ; } if ( min == 0 ) { min = 1 ; max = c [ 8 ] ; } else { int i = 0 ; max = min + c [ 8 ] ; } System . out . println ( min + " " + max ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws IOException { try ( BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ) { int n = Integer . parseInt ( br . readLine ( ) ) ; String [ ] line = br . readLine ( ) . split ( " " ) ; int [ ] a = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = Integer . parseInt ( line [ i ] ) ; } insertionSort ( a , n ) ; } } public static void insertionSort ( int [ ] a , int max ) { for ( int i = 0 , j = 0 , v = 0 ; i < max ; i ++ ) { for ( j = i - 1 , v = a [ i ] ; j >= 0 && a [ j ] > v ; j -- ) { a [ j + 1 ] = a [ j ] ; } a [ j + 1 ] = v ; dispIntArray ( a ) ; } } public static void dispIntArray ( int [ ] a ) { StringBuilder line = new StringBuilder ( a . length * 2 ) ; for ( int i = 0 , max = a . length - 1 ; i < max ; i ++ ) { int i = 0 , max = a . length - 1 ; line . append ( a [ i ] + " " ) ; } System . out . println ( line . append ( a [ a . length - 1 ] ) ) ; } } +import java . io . OutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . PrintWriter ; import java . util . StringTokenizer ; import java . io . IOException ; import java . util . InputMismatchException ; 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 ) ; TaskA solver = new TaskA ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class TaskA { public void solve ( int testNumber , InputReader in , PrintWriter out ) { int a = in . nextInt ( ) ; int b = in . nextInt ( ) ; out . println ( a * b % 2 == 1 ? " Odd " : " Even " ) ; } } static class InputReader { BufferedReader br ; StringTokenizer st ; public InputReader ( InputStream inputStream ) { br = new BufferedReader ( new InputStreamReader ( inputStream ) ) ; st = new StringTokenizer ( " " ) ; } public String nextString ( ) { while ( ! st . hasMoreTokens ( ) ) { try { st = new StringTokenizer ( br . readLine ( ) , " " ) ; } catch ( IOException e ) { throw new InputMismatchException ( ) ; } } return st . nextToken ( ) ; } public int nextInt ( ) { return Integer . parseInt ( nextString ( ) ) ; } } } +import java . util . HashMap ; import java . util . Map ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Character c ; Scanner sc = new Scanner ( System . in ) ; String w = sc . next ( ) ; sc . close ( ) ; Map < Character , Integer > map = new HashMap < > ( ) ; for ( int i = 0 ; i < w . length ( ) ; ++ i ) { if ( map . containsKey ( w . charAt ( i ) ) ) { Integer cap = map . get ( w . charAt ( i ) ) ; map . remove ( w . charAt ( i ) ) ; map . put ( w . charAt ( i ) , cap + 1 ) ; } else { map . put ( w . charAt ( i ) , 1 ) ; } } boolean flag = true ; for ( Character c : map . keySet ( ) ) { if ( map . get ( c ) % 2 != 0 ) { flag = false ; break ; } } if ( flag ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner s = new Scanner ( System . in ) ; String [ ] x = s . nextLine ( ) . split ( " " ) ; int a = Integer . parseInt ( x [ 0 ] ) ; int b = Integer . parseInt ( x [ 1 ] ) ; int c = Integer . parseInt ( x [ 2 ] ) ; int d = Integer . parseInt ( x [ 3 ] ) ; int diff1 = ( int ) a / d ; if ( a % d != 0 ) { diff1 = diff1 + 1 ; } int diff2 = ( int ) c / b ; if ( c % b != 0 ) { int diff2 = ( int ) c / b ; diff2 = diff2 + 1 ; } boolean g = diff1 >= diff2 ; if ( g ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } } +import java . io . OutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . PrintWriter ; import java . util . StringTokenizer ; import java . io . IOException ; import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . io . InputStream ; public class Main { public static void main ( String [ ] args ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; InputReader in = new InputReader ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; AProduct solver = new AProduct ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class AProduct { public void solve ( int testNumber , InputReader in , PrintWriter out ) { int a = in . nextInt ( ) ; int b = in . nextInt ( ) ; out . print ( a * b % 2 == 0 ? " Even " : " Odd " ) ; } } static class InputReader implements AutoCloseable { public BufferedReader reader ; public StringTokenizer tokenizer ; public InputReader ( InputStream stream ) { reader = new BufferedReader ( new InputStreamReader ( stream ) , 32768 ) ; tokenizer = null ; } public String next ( ) { while ( tokenizer == null || ! tokenizer . hasMoreTokens ( ) ) { try { tokenizer = new StringTokenizer ( reader . readLine ( ) ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } } return tokenizer . nextToken ( ) ; } public int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } public void close ( ) { } } } +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 ) ; BMaximumDifference solver = new BMaximumDifference ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class BMaximumDifference { public void solve ( int testNumber , Scanner in , PrintWriter out ) { int n = in . nextInt ( ) ; int min = Integer . MAX_VALUE , max = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int min = Integer . MAX_VALUE , max = 0 ; int a = in . nextInt ( ) ; min = Math . min ( min , a ) ; max = Math . max ( max , a ) ; } out . println ( max - min ) ; } } } +import java . util . * ; public class Main { static int modAns = ( int ) Math . pow ( 10 , 9 ) + 7 ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int a1 = sc . nextInt ( ) ; int a = a1 ; int count = 0 ; int [ ] bucket = new int [ 1000010 ] ; while ( true ) { int [ ] bucket = new int [ 1000010 ] ; count ++ ; if ( bucket [ a ] > 0 ) { break ; } bucket [ a ] ++ ; a = func ( a ) ; } System . out . println ( count ) ; } public static int func ( int n ) { return n % 2 == 0 ? n / 2 : n * 3 + 1 ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int a , b ; Scanner sc = new Scanner ( System . in ) ; do { a = sc . nextInt ( ) ; } while ( ! ( ( a >= 1 ) && ( a <= 20 ) ) ) ; do { b = sc . nextInt ( ) ; } while ( ! ( ( b >= 1 ) && ( b <= 20 ) ) ) ; if ( ( a >= 1 && a <= 9 ) && ( b >= 1 && b <= 9 ) ) { Scanner sc = new Scanner ( System . in ) ; System . out . println ( a * b ) ; } else { System . out . println ( - 1 ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; String ans = " APPROVED " ; for ( int i = 0 ; i < N ; i ++ ) { String ans = " APPROVED " ; int A = sc . nextInt ( ) ; if ( A % 2 == 0 && A % 3 != 0 && A % 5 != 0 ) ans = " DENIED " ; } System . out . println ( ans ) ; } } +import java . util . * ; import java . text . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int num = sc . nextInt ( ) ; int count = 0 ; int a = 0 ; for ( int i = 1 ; i <= num ; i ++ ) { int i = 1 ; a = i % 2 ; if ( a == 1 ) { count += 1 ; } } double prob = ( double ) count / num ; System . out . println ( prob ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; String t = sc . next ( ) ; char [ ] a = s . toCharArray ( ) ; char [ ] b = t . toCharArray ( ) ; boolean ok = true ; int n = s . length ( ) ; for ( int i = 0 ; i < n ; i ++ ) { ok = true ; for ( int j = 0 ; j < n - i ; j ++ ) { if ( a [ j ] != b [ j + i ] ) { int j = n - i ; ok = false ; break ; } } for ( int j = n - i ; j < n ; j ++ ) { if ( a [ j ] != b [ j - n + i ] ) { ok = false ; break ; } } if ( ok ) break ; } System . out . println ( ok ? " Yes " : " No " ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int ans = Math . min ( x , y ) * ab ; Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int c = sc . nextInt ( ) ; int x = sc . nextInt ( ) ; int y = sc . nextInt ( ) ; int ab = Math . min ( a + b , c * 2 ) ; int ans = Math . min ( x , y ) * ab ; if ( x > y ) { ans += ( x - y ) * Math . min ( a , c * 2 ) ; } else { ans += ( y - x ) * Math . min ( b , c * 2 ) ; } System . out . println ( ans ) ; } } +import java . util . Scanner ; public class Main { static int count = 1 ; public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; long h = Long . parseLong ( scan . nextLine ( ) ) ; test ( h ) ; System . out . println ( ( long ) Math . pow ( 2 , count ) - 1 ) ; } public static void test ( long hp ) { hp = hp / 2 ; if ( hp == 0 ) return ; count ++ ; test ( hp ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStream ; import java . io . InputStreamReader ; import java . io . PrintStream ; class Main { public static void main ( String [ ] args ) throws IOException { int i = 0 ; doit ( args , System . in , System . out ) ; } static void doit ( String [ ] args , InputStream in , PrintStream out ) throws IOException { BufferedReader reader = new BufferedReader ( new InputStreamReader ( in ) ) ; int w = Integer . parseInt ( reader . readLine ( ) ) ; int n = Integer . parseInt ( reader . readLine ( ) ) ; int [ ] numbers = new int [ w ] ; for ( int i = 0 ; i < w ; i ++ ) { numbers [ i ] = i + 1 ; } for ( int i = 0 ; i < n ; i ++ ) { String [ ] values = reader . readLine ( ) . split ( " , " ) ; int a = Integer . parseInt ( values [ 0 ] ) ; int b = Integer . parseInt ( values [ 1 ] ) ; int tmp = numbers [ a - 1 ] ; numbers [ a - 1 ] = numbers [ b - 1 ] ; numbers [ b - 1 ] = tmp ; } for ( int i = 0 ; i < w ; i ++ ) { out . println ( numbers [ i ] ) ; } } } +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 ( ) ; boolean [ ] judge = new boolean [ n ] ; for ( int i = 0 ; i < k ; i ++ ) { int d = scan . nextInt ( ) ; for ( int j = 0 ; j < d ; j ++ ) { int a = scan . nextInt ( ) ; judge [ a - 1 ] = true ; } } int ans = 0 ; for ( int i = 0 ; i < judge . length ; i ++ ) { int i = 0 ; if ( judge [ i ] == false ) { ans ++ ; } } System . out . print ( ans ) ; } } +import java . util . * ; import java . io . * ; import java . math . BigDecimal ; public class Main { public static void main ( String [ ] args ) { FastScanner fs = new FastScanner ( ) ; int L = fs . nextInt ( ) ; double y = ( double ) L / 3 ; BigDecimal x = BigDecimal . valueOf ( y ) ; BigDecimal ans = x . multiply ( x ) ; ans = ans . multiply ( x ) ; System . out . printf ( " %.12f " , ans ) ; } static class FastScanner { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; StringTokenizer st = new StringTokenizer ( " " ) ; public String next ( ) { while ( ! st . hasMoreElements ( ) ) try { st = new StringTokenizer ( br . readLine ( ) ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } return st . nextToken ( ) ; } public int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } public long nextLong ( ) { return Long . parseLong ( next ( ) ) ; } public int [ ] readArray ( int n ) { int [ ] a = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = nextInt ( ) ; } return a ; } public double nextDouble ( ) { int i = 0 ; return Double . parseDouble ( next ( ) ) ; } } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStream ; import java . io . InputStreamReader ; import java . util . StringTokenizer ; public class Main { public static void main ( String [ ] args ) { FastScanner sc = new FastScanner ( System . in ) ; int a = sc . nextInt ( ) ; int ans = 0 ; ans = a + ( int ) Math . pow ( a , 2 ) + ( int ) Math . pow ( a , 3 ) ; System . out . println ( ans ) ; } private static class FastScanner { private BufferedReader reader = null ; private StringTokenizer tokenizer = null ; public FastScanner ( InputStream in ) { reader = new BufferedReader ( new InputStreamReader ( in ) ) ; tokenizer = null ; } public String next ( ) { if ( tokenizer == null || ! tokenizer . hasMoreTokens ( ) ) { try { tokenizer = new StringTokenizer ( reader . readLine ( ) ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } } return tokenizer . nextToken ( ) ; } public int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } } } +import java . io . BufferedReader ; import java . io . InputStreamReader ; public class Main { private static int prime ( int a ) { if ( a == 2 || a == 3 ) return 1 ; for ( int i = 2 ; i < Math . sqrt ( a ) + 1 ; i ++ ) { if ( a % i == 0 ) { return 0 ; } } return 1 ; } public static void main ( String [ ] args ) throws Exception { try ( BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ) { boolean first = true ; String line ; int n = 0 , j = 0 , store = 0 ; boolean first = true ; while ( ( line = br . readLine ( ) ) != null ) { if ( first ) { n = Integer . parseInt ( line ) ; first = false ; } else { store += prime ( Integer . parseInt ( line ) ) ; j ++ ; if ( j == n ) { break ; } } } System . out . println ( store ) ; } } } +import java . io . * ; import java . util . * ; public class Main { public static void main ( String [ ] args ) { int n , q , time = 0 ; Queue < String > queueName = new ArrayDeque < String > ( ) ; Queue < Integer > queueTime = new ArrayDeque < Integer > ( ) ; Scanner sc = new Scanner ( System . in ) ; n = sc . nextInt ( ) ; q = sc . nextInt ( ) ; sc . nextLine ( ) ; for ( int i = 0 ; i < n ; i ++ ) { String [ ] s = sc . nextLine ( ) . split ( " " ) ; queueName . add ( s [ 0 ] ) ; queueTime . add ( Integer . parseInt ( s [ 1 ] ) ) ; } while ( ! queueName . isEmpty ( ) ) { String qn = queueName . poll ( ) ; int t = queueTime . poll ( ) ; time += ( t > q ) ? q : t ; if ( t > q ) { queueTime . add ( t - q ) ; queueName . add ( qn ) ; } else { int t = queueTime . poll ( ) ; System . out . println ( qn + " " + time ) ; } } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int A = sc . nextInt ( ) ; int B = sc . nextInt ( ) ; int c = 0 ; int x , y , z , w ; for ( int i = A ; i <= B ; i ++ ) { int i = A ; x = i / 10000 ; y = i % 10 ; z = i / 1000 - x * 10 ; w = ( i % 100 - y ) / 10 ; if ( x == y && z == w ) { c ++ ; } } System . out . println ( c ) ; sc . close ( ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { String [ ] lines = getStdin ( ) ; String str1 = lines [ 0 ] ; int mult = Integer . parseInt ( str1 ) ; String str2 = lines [ 1 ] ; String [ ] str21 = str2 . split ( " " ) ; int from = Integer . parseInt ( str21 [ 0 ] ) ; int till = Integer . parseInt ( str21 [ 1 ] ) ; for ( int i = 1 ; i <= 1000 ; i ++ ) { int multiple = mult * i ; if ( multiple >= from && multiple <= till ) { System . out . println ( " OK " ) ; return ; } else { multiple = mult ; } } System . out . println ( " NG " ) ; } private static String [ ] getStdin ( ) { Scanner scanner = new Scanner ( System . in ) ; ArrayList < String > lines = new ArrayList < > ( ) ; while ( scanner . hasNext ( ) ) { ArrayList < String > lines = new ArrayList < > ( ) ; lines . add ( scanner . nextLine ( ) ) ; } return lines . toArray ( new String [ lines . size ( ) ] ) ; } } +import java . io . * ; class Main { public static void main ( String [ ] args ) { int i = 0 ; try { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String str = br . readLine ( ) ; char c ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { c = str . charAt ( i ) ; if ( Character . isUpperCase ( c ) ) c = Character . toLowerCase ( c ) ; else if ( Character . isLowerCase ( c ) ) c = Character . toUpperCase ( c ) ; System . out . print ( c ) ; } System . out . println ( ) ; } catch ( IOException e ) { System . out . println ( " Exception : " + e ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int N = scanner . nextInt ( ) ; Integer [ ] d = new Integer [ N ] ; int s = 1 ; for ( int i = 0 ; i < N ; i ++ ) { d [ i ] = scanner . nextInt ( ) ; } Arrays . sort ( d , Comparator . reverseOrder ( ) ) ; for ( int i = 0 ; i < N - 1 ; i ++ ) { int i = 0 ; if ( d [ i ] > d [ i + 1 ] ) s ++ ; } System . out . println ( s ) ; } } +import java . util . Scanner ; public class Main { static int N ; static int [ ] a ; private static void init ( ) { Scanner scanner = new Scanner ( System . in ) ; N = scanner . nextInt ( ) ; a = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) a [ i ] = scanner . nextInt ( ) ; scanner . close ( ) ; } private static boolean check ( ) { boolean ok = true ; for ( int i = 0 ; i < N ; i ++ ) { int j = 0 ; if ( a [ i ] % 2 != 0 ) { ok = false ; break ; } } return ok ; } public static void main ( String [ ] args ) { init ( ) ; int count = 0 ; while ( true ) { if ( check ( ) ) { count ++ ; for ( int j = 0 ; j < N ; j ++ ) { a [ j ] = a [ j ] / 2 ; } } else { break ; } } System . out . println ( count ) ; } } +import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner reader = new Scanner ( System . in ) ; int N = reader . nextInt ( ) ; int [ ] arr = new int [ N ] ; int a = 0 ; int b = 0 ; for ( int i = 0 ; i < N ; i ++ ) { arr [ i ] = reader . nextInt ( ) ; } Arrays . sort ( arr ) ; for ( int i = N - 1 ; i >= 0 ; i -= 2 ) { a += arr [ i ] ; if ( i > 0 ) { int i = N - 1 ; b += arr [ i - 1 ] ; } } System . out . print ( a - b ) ; reader . close ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { try ( Scanner sc = new Scanner ( System . in ) ) { String [ ] input = sc . nextLine ( ) . split ( " " ) ; Result r = renzokuNum ( input ) ; switch ( r ) { case Good : System . out . println ( " Good " ) ; break ; default : System . out . println ( " Bad " ) ; break ; } } } private static Result renzokuNum ( String [ ] input ) { for ( int i = 0 ; i < input . length - 1 ; i ++ ) { if ( input [ i ] . equals ( input [ i + 1 ] ) ) { int i = 0 ; return Result . Bad ; } } return Result . Good ; } enum Result { Good , Bad } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws IOException { try ( BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ) { int mid ; int n = Integer . parseInt ( br . readLine ( ) ) ; int [ ] seqS = new int [ n ] ; String [ ] line = br . readLine ( ) . split ( " " ) ; for ( int i = 0 ; i < n ; i ++ ) seqS [ i ] = Integer . parseInt ( line [ i ] ) ; int q = Integer . parseInt ( br . readLine ( ) ) ; line = br . readLine ( ) . split ( " " ) ; int cnt = 0 ; for ( String ref : line ) { if ( isExistSeachByBinary ( seqS , Integer . parseInt ( ref ) ) ) cnt ++ ; } System . out . println ( cnt ) ; } } static boolean isExistSeachByBinary ( int [ ] tar , int ref ) { int left = 0 ; int right = tar . length ; int mid ; while ( left < right ) { mid = ( left + right ) / 2 ; if ( tar [ mid ] == ref ) return true ; else if ( tar [ mid ] > ref ) right = mid ; else left = mid + 1 ; } return false ; } } +import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner tan = new Scanner ( System . in ) ; while ( tan . hasNext ( ) ) { int n , k , sum = 0 ; n = tan . nextInt ( ) ; k = tan . nextInt ( ) ; int [ ] a = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = tan . nextInt ( ) ; } Arrays . sort ( a ) ; for ( int i = 0 ; i < k ; i ++ ) { int i = 0 ; sum = sum + a [ i ] ; } System . out . println ( sum ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner stdin = new Scanner ( System . in ) ; int N = stdin . nextInt ( ) ; String S = stdin . next ( ) ; String copy = S . substring ( 0 , 1 ) ; int cnt = 1 ; for ( int i = 1 ; i < S . length ( ) ; i ++ ) { if ( ! ( copy . equals ( S . substring ( i , i + 1 ) ) ) ) { int i = 1 ; copy = S . substring ( i , i + 1 ) ; cnt += 1 ; } } System . out . println ( cnt ) ; } } +import java . util . Scanner ; import java . util . Arrays ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner scan = new Scanner ( System . in ) ; int size = scan . nextInt ( ) ; int [ ] arr = new int [ size ] ; for ( int i = 0 ; i < size ; i ++ ) arr [ i ] = scan . nextInt ( ) ; for ( int i = 0 ; i < size ; i ++ ) { int tmp = arr [ i ] , j = i ; for ( ; 0 < j && tmp <= arr [ j - 1 ] ; j -- ) arr [ j ] = arr [ j - 1 ] ; arr [ j ] = tmp ; for ( j = 0 ; j < size ; j ++ ) System . out . print ( ( j == 0 ? " " : " " ) + arr [ j ] ) ; System . out . println ( ) ; } } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; String nn = String . valueOf ( n ) ; int [ ] nnn = new int [ 3 ] ; for ( int i = 0 ; i <= 2 ; i ++ ) { int i = 0 ; if ( nn . charAt ( i ) == '1' ) { nnn [ i ] = 9 ; } else { nnn [ i ] = 1 ; } } for ( int i = 0 ; i <= 2 ; i ++ ) { System . out . print ( nnn [ i ] ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner scn = new Scanner ( System . in ) ; int k = scn . nextInt ( ) ; int a = scn . nextInt ( ) ; int b = scn . nextInt ( ) ; for ( ; a <= b ; a ++ ) { if ( a % k == 0 ) { int a = scn . nextInt ( ) ; System . out . printf ( " OK \n " ) ; return ; } } System . out . printf ( " NG \n " ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) { BufferedReader in = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String x = " " ; try { x = in . readLine ( ) ; } catch ( NumberFormatException e ) { String x = " " ; e . printStackTrace ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } String [ ] ab = x . split ( " " ) ; int a = Integer . parseInt ( ab [ 0 ] ) ; int b = Integer . parseInt ( ab [ 1 ] ) ; if ( a < b ) System . out . println ( " a < b " ) ; if ( a > b ) System . out . println ( " a > b " ) ; if ( a == b ) System . out . println ( " a == b " ) ; } } +import java . util . * ; import java . lang . * ; import java . io . * ; class Main { public static void main ( String [ ] args ) throws java . lang . Exception { String s = sc . next ( ) ; try { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; String s = sc . next ( ) ; if ( n >= s . length ( ) ) { System . out . println ( s ) ; } else { System . out . println ( s . substring ( 0 , n ) + " ... " ) ; } } catch ( Exception e ) { } finally { } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; String s_a = in . nextLine ( ) ; String s_b = in . nextLine ( ) ; String s_c = in . nextLine ( ) ; int a = 0 ; int b = 0 ; int c = 0 ; char currentChar = 'a' ; while ( true ) { if ( currentChar == 'a' ) { if ( a == s_a . length ( ) ) { System . out . println ( 'A' ) ; break ; } currentChar = s_a . charAt ( a ) ; a ++ ; } else if ( currentChar == 'b' ) { if ( b == s_b . length ( ) ) { char currentChar = 'a' ; System . out . println ( 'B' ) ; break ; } currentChar = s_b . charAt ( b ) ; b ++ ; } else if ( currentChar == 'c' ) { if ( c == s_c . length ( ) ) { System . out . println ( 'C' ) ; break ; } currentChar = s_c . charAt ( c ) ; c ++ ; } } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { String s ; Scanner sc = new Scanner ( System . in ) ; String [ ] array = sc . nextLine ( ) . split ( " " ) ; int sum = 0 ; for ( String s : array ) { if ( Integer . parseInt ( s ) == 1 ) { sum ++ ; } } System . out . println ( sum ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { int y = sc . nextInt ( ) ; Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int c = sc . nextInt ( ) ; int x = sc . nextInt ( ) ; int y = sc . nextInt ( ) ; if ( a + b <= c * 2 ) { System . out . println ( a * x + b * y ) ; return ; } int tmp = Math . min ( x , y ) ; int tmp2 = c * tmp * 2 ; int tmp3 = a * ( x - tmp ) ; int tmp4 = b * ( y - tmp ) ; int tmp5 = Math . max ( x , y ) * c * 2 ; int ans = Math . min ( tmp5 , tmp2 + tmp3 + tmp4 ) ; System . out . println ( ans ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int judge = 0 ; Scanner sc = new Scanner ( System . in ) ; int X = sc . nextInt ( ) ; int Y = sc . nextInt ( ) ; int judge = 0 ; while ( X >= 0 && Y >= 0 ) { if ( Y / 4 == X && Y % 4 == 0 ) { judge = 1 ; break ; } X = X - 1 ; Y = Y - 2 ; } if ( judge == 1 ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } } +import java . awt . * ; import java . awt . geom . * ; import java . io . * ; import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; Scanner sc = new Scanner ( System . in ) ; while ( true ) { int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; if ( a == 0 && b == 0 ) break ; System . out . println ( ( a < b ) ? ( a + " " + b ) : ( b + " " + a ) ) ; } } } +import java . util . * ; public class Main { static Scanner sc = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { boolean flag = true ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; if ( a >= b ) { flag = false ; } int c = sc . nextInt ( ) ; if ( b >= c ) { boolean flag = true ; flag = false ; } System . out . println ( flag == true ? " Yes " : " No " ) ; } } +import java . util . Scanner ; import java . util . Arrays ; class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; while ( true ) { String str = sc . nextLine ( ) ; String [ ] str2 = str . split ( " " ) ; int [ ] x = new int [ 2 ] ; for ( int i = 0 ; i < 2 ; i ++ ) { x [ i ] = Integer . parseInt ( str2 [ i ] ) ; } if ( x [ 0 ] == 0 && x [ 1 ] == 0 ) { break ; } Arrays . sort ( x ) ; System . out . println ( x [ 0 ] + " " + x [ 1 ] ) ; } } } +import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int [ ] n = new int [ a ] ; for ( int i = 0 ; i < a ; i ++ ) { n [ i ] = sc . nextInt ( ) ; } Arrays . sort ( n ) ; int sum = 0 ; for ( int i = 0 ; i < a - 1 ; i ++ ) { sum += n [ i ] ; } if ( n [ a - 1 ] < sum ) { System . out . println ( " Yes " ) ; } else { int i = 0 ; System . out . println ( " No " ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; String S = sc . next ( ) ; int s = S . length ( ) ; String [ ] P = S . split ( " " ) ; String [ ] Q = { " 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 " } ; String [ ] R = new String [ s + 1 ] ; R [ 0 ] = " " ; for ( int i = 0 ; i < s ; i ++ ) { int j = 0 ; for ( int j = 0 ; j < 26 ; j ++ ) { if ( P [ i ] . equals ( Q [ j ] ) ) { R [ i + 1 ] = R [ i ] + Q [ ( j + N ) % 26 ] ; } } } System . out . println ( R [ s ] ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { double p = i ; Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int K = sc . nextInt ( ) ; sc . close ( ) ; double ans = 0.0 ; for ( int i = 1 ; i <= N ; i ++ ) { int cnt = 0 ; double p = i ; while ( p < K ) { cnt ++ ; p *= 2.0 ; } ans += 1.0 / N * Math . pow ( 0.5 , cnt ) ; } System . out . println ( ans ) ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int K = sc . nextInt ( ) ; int [ ] A = new int [ N ] ; for ( int i = 0 ; i < K ; i ++ ) { int r ; int d = sc . nextInt ( ) ; for ( int j = 0 ; j < d ; j ++ ) { A [ sc . nextInt ( ) - 1 ] ++ ; } } int count = 0 ; for ( int r : A ) { if ( r == 0 ) { count ++ ; } } System . out . print ( count ) ; } } +import java . io . * ; import java . util . * ; public class Main { public static void main ( String [ ] args ) throws IOException { Scanner scn = new Scanner ( System . in ) ; int n = scn . nextInt ( ) ; long ans = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { if ( i % 3 != 0 && i % 5 != 0 ) ans += i ; } System . out . println ( ans ) ; } static class Scanner { StringTokenizer st ; BufferedReader br ; public Scanner ( InputStream s ) { br = new BufferedReader ( new InputStreamReader ( s ) ) ; } public String next ( ) throws IOException { while ( st == null || ! st . hasMoreTokens ( ) ) st = new StringTokenizer ( br . readLine ( ) ) ; return st . nextToken ( ) ; } public int nextInt ( ) throws IOException { return Integer . parseInt ( next ( ) ) ; } public long nextLong ( ) throws IOException { return Long . parseLong ( next ( ) ) ; } } } +import java . io . IOException ; import java . io . InputStreamReader ; import java . io . BufferedReader ; public class Main { public static void main ( String [ ] args ) throws IOException { int i ; BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int w = Integer . parseInt ( br . readLine ( ) ) ; int n = Integer . parseInt ( br . readLine ( ) ) ; int [ ] array = new int [ w ] ; for ( int i = 0 ; i < w ; i ++ ) { array [ i ] = i + 1 ; } for ( int i = 0 ; i < n ; i ++ ) { String [ ] input = br . readLine ( ) . split ( " , " ) ; int a = Integer . parseInt ( input [ 0 ] ) ; int b = Integer . parseInt ( input [ 1 ] ) ; int tmp = array [ a - 1 ] ; array [ a - 1 ] = array [ b - 1 ] ; array [ b - 1 ] = tmp ; } for ( int i : array ) { System . out . println ( i ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int count = 0 ; int valLen = String . valueOf ( a ) . length ( ) ; for ( int i = valLen ; i > 0 ; i -- ) { if ( i % 2 == 1 ) { if ( i == valLen ) { count += a % Math . pow ( 10 , i - 1 ) + 1 ; count += ( ( a / ( int ) Math . pow ( 10 , i - 1 ) ) - 1 ) * ( int ) Math . pow ( 10 , i - 1 ) ; } else if ( i == 1 ) { int i = valLen ; count += 9 ; } else { count += 9 * ( int ) Math . pow ( 10 , i - 1 ) ; } } } System . out . println ( count ) ; } } +import java . util . Scanner ; public class Main { void run ( ) { Scanner scan = new Scanner ( System . in ) ; int n = scan . nextInt ( ) ; int [ ] a = new int [ 100 ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = scan . nextInt ( ) ; } System . out . print ( a [ n - 1 ] ) ; for ( int i = n - 2 ; i >= 0 ; i -- ) { int i = n - 2 ; System . out . print ( " " + a [ i ] ) ; } System . out . println ( ) ; } public static void main ( String [ ] args ) { Main m = new Main ( ) ; m . run ( ) ; } } +import java . util . Arrays ; import java . util . Collections ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; Integer [ ] a = new Integer [ n ] ; Integer [ ] tmpA = new Integer [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { int i = 0 ; a [ i ] = sc . nextInt ( ) ; tmpA [ i ] = a [ i ] ; } Arrays . sort ( tmpA , Collections . reverseOrder ( ) ) ; int first = tmpA [ 0 ] ; int second = tmpA [ 1 ] ; for ( int i = 0 ; i < n ; i ++ ) { if ( a [ i ] == first ) { System . out . println ( second ) ; } else { System . out . println ( first ) ; } } sc . close ( ) ; } } +import java . awt . Point ; import java . util . ArrayDeque ; import java . util . Scanner ; import java . util . * ; import java . util . Arrays ; import java . util . ArrayList ; import java . util . Set ; import java . util . HashSet ; import java . util . Collection ; public class Main { static final Scanner sc = new Scanner ( System . in ) ; static int N = sc . nextInt ( ) ; static long [ ] a = new long [ N ] ; public static void main ( String [ ] args ) { int sum = 0 ; for ( int i = 0 ; i < N ; i ++ ) { a [ i ] = sc . nextLong ( ) ; } long x = 0 ; for ( int i = 0 ; i < N ; i ++ ) { x = a [ i ] ; for ( ; ; ) { int i = 0 ; if ( x % 2 == 0 ) { sum ++ ; x = x / 2 ; } else { break ; } } } System . out . println ( sum ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int tmp ; Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; String ans = " APPROVED " ; int tmp ; for ( int i = 0 ; i < N ; i ++ ) { tmp = sc . nextInt ( ) ; if ( tmp % 2 == 0 ) { if ( tmp % 3 != 0 && tmp % 5 != 0 ) { ans = " DENIED " ; } } } System . out . println ( ans ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; int num = sc . nextInt ( ) ; int leg = sc . nextInt ( ) ; for ( int i = 0 ; i < num + 1 ; i ++ ) { if ( ( i * 2 + ( num - i ) * 4 ) == leg ) { int i = 0 ; System . out . println ( " Yes " ) ; System . exit ( 0 ) ; } } System . out . println ( " No " ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) throws NumberFormatException { Scanner sc = new Scanner ( System . in ) ; String S = sc . nextLine ( ) . trim ( ) ; String [ ] segments = S . split ( " " ) ; int N = Integer . parseInt ( segments [ 0 ] ) ; int K = Integer . parseInt ( segments [ 1 ] ) ; double result = 0 ; double np = ( double ) 1.0 / N ; for ( int i = 1 ; i <= N ; i ++ ) { result += np * calcP ( i , K ) ; } System . out . println ( result ) ; } private static double calcP ( int n , int k ) { int cnt = 0 ; int score = n ; int cnt = 0 ; while ( score < k ) { cnt ++ ; score *= 2 ; } if ( cnt > 0 ) { return Math . pow ( ( double ) 0.5 , cnt ) ; } else { return 1 ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String nyu = sc . next ( ) ; int cnt = 0 , mem = 0 , leng ; leng = nyu . length ( ) ; for ( int i = 0 ; i < leng ; i ++ ) { char top = nyu . charAt ( i ) ; switch ( top ) { case 'A' : cnt += 1 ; break ; case 'C' : cnt += 1 ; break ; case 'G' : cnt += 1 ; break ; case 'T' : cnt += 1 ; break ; default : if ( cnt > mem ) { mem = cnt ; cnt = 0 ; } } } if ( cnt > mem ) { int i = 0 ; mem = cnt ; } System . out . println ( mem ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int n = in . nextInt ( ) ; StringBuilder ans ; int cnt = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { ans = new StringBuilder ( " " + i ) ; if ( ans . length ( ) % 2 != 0 ) { int i = 1 ; cnt ++ ; } } System . out . println ( cnt ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int n = scan . nextInt ( ) ; boolean f = false ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { if ( ( 4 * i ) + ( 7 * j ) == n ) { int j = 0 ; f = true ; System . out . println ( " Yes " ) ; return ; } } } System . out . println ( " No " ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int debt = 100000 ; int n = Integer . parseInt ( br . readLine ( ) ) ; for ( int i = 0 ; i < n ; i ++ ) { int debt = 100000 ; debt *= 1.05 ; if ( ( debt - ( ( debt / 1000 ) * 1000 ) ) != 0 ) { debt = ( debt / 1000 ) * 1000 + 1000 ; } else { debt = ( debt / 1000 ) * 1000 ; } } System . out . println ( debt ) ; } } +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 ( ) ; } long [ ] L = new long [ N ] ; for ( int i = 1 ; i < N ; i ++ ) { if ( A [ i ] < A [ i - 1 ] ) { L [ i ] = A [ i - 1 ] - A [ i ] ; A [ i ] = A [ i - 1 ] ; } else { L [ i ] = 0 ; } } long S ; S = 0 ; for ( int i = 1 ; i < N ; i ++ ) { int i = 1 ; S = S + L [ i ] ; } System . out . println ( S ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int i = nums . length - 1 ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] nums = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { nums [ i ] = sc . nextInt ( ) ; } Arrays . sort ( nums ) ; int aliceSum = 0 ; int bobSum = 0 ; boolean isAliceTurn = true ; for ( int i = nums . length - 1 ; i >= 0 ; i -- ) { if ( isAliceTurn ) { aliceSum += nums [ i ] ; isAliceTurn = false ; } else { bobSum += nums [ i ] ; isAliceTurn = true ; } } System . out . println ( aliceSum - bobSum ) ; } } +import java . util . * ; public class Main { static Scanner scanner = new Scanner ( System . in ) ; public static void main ( String [ ] $ ) { int a = scanner . nextInt ( ) ; int b = scanner . nextInt ( ) ; System . out . println ( scanner . next ( ) . matches ( String . format ( " \\ d { %d } - \\ d { %d } " , a , b ) ) ? " Yes " : " No " ) ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int count = 1 ; int Answer = 0 ; for ( int i = 0 ; i < N ; i ++ ) { int Answer = 0 ; if ( sc . nextInt ( ) == count ) { count ++ ; } else { Answer ++ ; } } if ( Answer == N ) { Answer = - 1 ; } System . out . println ( Answer ) ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int Y = sc . nextInt ( ) ; for ( int i = 0 ; i <= N ; i ++ ) { int x = i * 10000 ; if ( x > Y ) break ; for ( int j = 0 ; j <= N - i ; j ++ ) { int y = j * 5000 ; if ( ( x + y ) > Y ) break ; if ( ( Y - x - y ) / 1000 == ( N - i - j ) ) { int y = j * 5000 ; System . out . println ( i + " " + j + " " + ( Y - x - y ) / 1000 ) ; return ; } } } System . out . println ( " -1 -1 -1 " ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String line = sc . nextLine ( ) ; String [ ] lines = line . split ( " " ) ; boolean flag = true ; int before = Integer . parseInt ( lines [ 0 ] ) ; for ( int i = 1 ; i < lines . length ; i ++ ) { int after = Integer . parseInt ( lines [ i ] ) ; if ( before == after ) { flag = false ; break ; } before = after ; } if ( flag ) { int i = 1 ; System . out . println ( " Good " ) ; } else { System . out . println ( " Bad " ) ; } } } +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 ) ; abc155_b solver = new abc155_b ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class abc155_b { public void solve ( int testNumber , Scanner in , PrintWriter out ) { int a = in . nextInt ( ) ; int N = in . nextInt ( ) ; boolean ret = true ; for ( int i = 0 ; i < N ; i ++ ) { int a = in . nextInt ( ) ; if ( ( a % 2 ) == 0 ) { if ( ( a % 3 ) == 0 || ( a % 5 ) == 0 ) { ret = true ; } else { ret = false ; break ; } } } if ( ret ) { out . println ( " APPROVED " ) ; } else { out . println ( " DENIED " ) ; } } } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; String num = scan . nextLine ( ) ; int count = 0 ; for ( int i = 0 ; i < 3 ; i ++ ) { int i = 0 ; char c = num . charAt ( i ) ; if ( c == '1' ) { count ++ ; } } System . out . println ( count ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . HashSet ; import java . util . Set ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader input = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int n = Integer . parseInt ( input . readLine ( ) ) ; Set < String > set = new HashSet < > ( ) ; String value = input . readLine ( ) ; char lastChar = value . charAt ( value . length ( ) - 1 ) ; set . add ( value ) ; for ( int i = 1 ; i < n ; i ++ ) { char lastChar = value . charAt ( value . length ( ) - 1 ) ; value = input . readLine ( ) ; if ( set . contains ( value ) || lastChar != value . charAt ( 0 ) ) { System . out . println ( " No " ) ; return ; } set . add ( value ) ; lastChar = value . charAt ( value . length ( ) - 1 ) ; } System . out . println ( " Yes " ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int l = sc . nextInt ( ) ; int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { sum += l + i ; } if ( n + l <= 0 ) { System . out . println ( sum - ( n + l - 1 ) ) ; } else if ( l < 0 ) { int i = 0 ; System . out . println ( sum ) ; } else { System . out . println ( sum - l ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long [ ] dd = new long [ 10000 ] ; int x = 9 ; long r = 0 ; long su ; for ( int i = 0 ; x == 9 ; i ++ ) { su = sc . nextInt ( ) ; if ( su != 0 ) { dd [ i ] = su ; } if ( su == 0 ) { int y = 0 ; r = i ; break ; } } for ( int y = 0 ; y < r ; y ++ ) { int l = y + 1 ; System . out . println ( " Case " + l + " : " + dd [ y ] ) ; } } } +import java . util . * ; class Main { final Scanner sc = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { new Main ( ) . run ( ) ; } private void run ( ) { int i = 0 ; int n = sc . nextInt ( ) ; if ( n % 2 == 1 ) { System . out . println ( " No " ) ; return ; } String s = sc . next ( ) ; int l = ( int ) ( n / 2 ) ; for ( int i = 0 ; i < l ; i ++ ) { if ( s . charAt ( i ) != s . charAt ( l + i ) ) { System . out . println ( " No " ) ; return ; } } System . out . println ( " Yes " ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String S = sc . next ( ) ; String ans = " " ; for ( char c : S . toCharArray ( ) ) { char c ; if ( c == '0' ) { ans += " 0 " ; } else if ( c == '1' ) { ans += " 1 " ; } else if ( c == 'B' && ans . length ( ) == 0 ) { continue ; } else { ans = ans . substring ( 0 , ans . length ( ) - 1 ) ; } } System . out . println ( ans ) ; } } +import java . io . * ; class Main { public static void main ( String [ ] args ) throws IOException { InputStreamReader isr = new InputStreamReader ( System . in ) ; BufferedReader br = new BufferedReader ( isr ) ; String str = br . readLine ( ) ; char [ ] ch = str . toCharArray ( ) ; for ( int i = 0 ; i < ch . length ; i ++ ) { int i = 0 ; if ( Character . isUpperCase ( ch [ i ] ) ) { ch [ i ] = Character . toLowerCase ( ch [ i ] ) ; } else ch [ i ] = Character . toUpperCase ( ch [ i ] ) ; } for ( int i = 0 ; i < ch . length ; i ++ ) { System . out . print ( ch [ i ] ) ; } System . out . println ( ) ; } } +import java . io . * ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String str ; while ( ( str = br . readLine ( ) ) != null ) { String str ; String [ ] str2 = str . split ( " " ) ; int a = Integer . parseInt ( str2 [ 0 ] ) ; int b = Integer . parseInt ( str2 [ 1 ] ) ; int digits = Integer . toString ( a + b ) . length ( ) ; System . out . println ( digits ) ; } } } +import java . io . * ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int paper ; try { int page ; int paper ; Scanner scan = new Scanner ( System . in ) ; String N = scan . next ( ) ; page = Integer . parseInt ( N ) ; if ( page % 2 == 0 ) { paper = page / 2 ; } else { paper = page / 2 + 1 ; } System . out . println ( paper ) ; } catch ( Exception e ) { System . out . println ( " error " ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; String str = sc . next ( ) ; int sn = 0 ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { sn += str . charAt ( i ) - '0' ; } System . out . println ( Integer . parseInt ( str ) % sn == 0 ? " Yes " : " No " ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] r = new int [ n ] ; int maxv = - 999999999 ; for ( int i = 0 ; i < r . length ; i ++ ) { r [ i ] = sc . nextInt ( ) ; } int minv = r [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { int i = 1 ; maxv = r [ i ] - minv > maxv ? r [ i ] - minv : maxv ; minv = minv > r [ i ] ? r [ i ] : minv ; } System . out . println ( maxv ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Main2 cc = new Main2 ( ) ; cc . yesNo ( ) ; } } class Main2 { public void yesNo ( ) { int i = 0 ; Scanner scan = new Scanner ( System . in ) ; int [ ] abc = new int [ 3 ] ; for ( int i = 0 ; i < 3 ; i ++ ) { abc [ i ] = scan . nextInt ( ) ; } if ( abc [ 0 ] < abc [ 1 ] && abc [ 1 ] < abc [ 2 ] ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; char [ ] nChar = String . valueOf ( n ) . toCharArray ( ) ; int sn = 0 ; for ( int i = 0 ; i < nChar . length ; i ++ ) { sn += Integer . parseInt ( String . valueOf ( nChar [ i ] ) ) ; } if ( n % sn == 0 ) { int i = 0 ; System . out . println ( " Yes " ) ; return ; } System . out . println ( " No " ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; String s = scan . nextLine ( ) ; String p = scan . nextLine ( ) ; if ( match ( s , p ) ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } public static boolean match ( String s , String p ) { int pLength = p . length ( ) ; String doubleS = s + s ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { int i = 0 ; String word = doubleS . substring ( i , i + pLength ) ; if ( word . equals ( p ) ) { return true ; } } return false ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int h = sc . nextInt ( ) ; int n = sc . nextInt ( ) ; int [ ] a = new int [ n ] ; for ( int i = 0 ; i < n ; ++ i ) { a [ i ] = sc . nextInt ( ) ; } int count = 0 ; for ( int i = 0 ; i < n ; ++ i ) { int i = 0 ; count += a [ i ] ; } if ( count >= h ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } } +import java . util . Scanner ; import java . util . Map ; import java . util . TreeMap ; import java . util . Iterator ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = Integer . parseInt ( sc . next ( ) ) ; TreeMap < String , Integer > S = new TreeMap < String , Integer > ( ) ; String tmp ; int max = 1 ; int count ; for ( int i = 0 ; i < N ; i ++ ) { tmp = sc . next ( ) ; if ( S . containsKey ( tmp ) ) { count = S . get ( tmp ) + 1 ; if ( max < count ) { max = count ; } S . put ( tmp , count ) ; } else { String result = it . next ( ) ; S . put ( tmp , 1 ) ; } } for ( Iterator < String > it = S . keySet ( ) . iterator ( ) ; it . hasNext ( ) ; ) { String result = it . next ( ) ; if ( S . get ( result ) == max ) { System . out . println ( result ) ; } } } } +import java . io . BufferedReader ; import java . io . InputStreamReader ; public class Main { static BufferedReader reader ; public static void main ( String [ ] args ) { reader = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String [ ] strings = readLine ( ) ; int H = Integer . parseInt ( strings [ 0 ] ) ; int A = Integer . parseInt ( strings [ 1 ] ) ; print ( ( H + A - 1 ) / A ) ; } private static String [ ] readLine ( ) { try { return reader . readLine ( ) . split ( " " ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; return new String [ ] { e . getMessage ( ) } ; } } private static void print ( Object o ) { System . out . println ( o ) ; } private static void print ( ) { System . out . println ( ) ; } } +import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . io . IOException ; import java . util . Arrays ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader in = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String [ ] str = in . readLine ( ) . split ( " " ) ; int n = Integer . parseInt ( str [ 0 ] ) ; int l = Integer . parseInt ( str [ 1 ] ) ; String [ ] s = new String [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { s [ i ] = in . readLine ( ) ; } Arrays . sort ( s ) ; for ( int i = 0 ; i < n ; i ++ ) { int i = 0 ; System . out . print ( s [ i ] ) ; } System . out . println ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int K = sc . nextInt ( ) ; String s = sc . next ( ) ; for ( int i = 0 ; i < N ; i ++ ) { if ( i == K - 1 ) { System . out . print ( ( char ) ( s . charAt ( i ) - 'A' + 'a' ) ) ; } else { System . out . print ( s . charAt ( i ) ) ; } } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; char [ ] s = sc . next ( ) . toCharArray ( ) ; int count = 0 ; for ( int i = 0 ; i < 3 ; i ++ ) { int i = 0 ; if ( s [ i ] - '0' == 1 ) count ++ ; } System . out . println ( count ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; while ( true ) { String s1 = sc . next ( ) ; int H = Integer . parseInt ( s1 ) ; String s2 = sc . next ( ) ; int W = Integer . parseInt ( s2 ) ; if ( H <= 300 && W <= 300 ) { if ( H == 0 && W == 0 ) { break ; } for ( int i = 1 ; i <= H ; i ++ ) { int j = 1 ; if ( i == 1 || i == H ) { for ( int j = 1 ; j <= W ; j ++ ) { System . out . print ( " # " ) ; } } else { for ( int j = 1 ; j <= W ; j ++ ) { if ( j == 1 || j == W ) { System . out . print ( " # " ) ; } else { System . out . print ( " . " ) ; } } } System . out . println ( " " ) ; } System . out . println ( " " ) ; } } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int M = sc . nextInt ( ) ; int [ ] arr = new int [ N ] ; Arrays . fill ( arr , 0 ) ; for ( int i = 0 ; i < 2 * M ; i ++ ) { int a = sc . nextInt ( ) ; for ( int j = 1 ; j <= N ; j ++ ) { int i = 0 ; if ( a == j ) { arr [ j - 1 ] ++ ; } } } for ( int i = 0 ; i < N ; i ++ ) { System . out . println ( arr [ i ] ) ; } } } +import java . util . ArrayList ; import static java . util . Collections . reverse ; import java . util . List ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int n = scanner . nextInt ( ) ; List < Integer > list = new ArrayList < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { int a = scanner . nextInt ( ) ; list . add ( a ) ; } reverse ( list ) ; for ( int i = 0 ; i < list . size ( ) ; i ++ ) { Integer get = list . get ( i ) ; if ( i == list . size ( ) - 1 ) { Integer get = list . get ( i ) ; System . out . print ( get ) ; } else { System . out . print ( get + " " ) ; } } System . out . println ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String t ; String h ; int t_point = 0 ; int h_point = 0 ; int n = sc . nextInt ( ) ; for ( int i = 0 ; i < n ; i ++ ) { int h_point = 0 ; t = sc . next ( ) ; h = sc . next ( ) ; if ( t . compareTo ( h ) > 0 ) { t_point += 3 ; } else if ( t . compareTo ( h ) < 0 ) { h_point += 3 ; } else { t_point += 1 ; h_point += 1 ; } } System . out . println ( t_point + " " + h_point ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int len = String . valueOf ( n ) . length ( ) ; int res = 0 ; for ( int i = 1 ; i < len ; i += 2 ) { res += 9 * ( int ) Math . pow ( 10 , i - 1 ) ; } if ( len % 2 == 1 ) { int i = 1 ; res += n - ( int ) Math . pow ( 10 , len - 1 ) + 1 ; } System . out . println ( res ) ; } } +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 ) ; A solver = new A ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class A { public void solve ( int testNumber , Scanner in , PrintWriter out ) { PrintWriter out = new PrintWriter ( outputStream ) ; String s = in . next ( ) ; int a = s . charAt ( 0 ) ; char ans = ( char ) ++ a ; 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 m = sc . nextInt ( ) ; int x = sc . nextInt ( ) ; int [ ] arr = new int [ m ] ; for ( int i = 0 ; i < arr . length ; i ++ ) { int i = x + 1 ; arr [ i ] = sc . nextInt ( ) ; } int [ ] flag = new int [ n ] ; for ( int i = 0 ; i < flag . length ; i ++ ) { flag [ i ] = 0 ; } for ( int i = 0 ; i < flag . length ; i ++ ) { for ( int j = 0 ; j < arr . length ; j ++ ) { if ( arr [ j ] == i ) { flag [ i ] = 1 ; } } } int leftResult = 0 ; int rightResult = 0 ; for ( int i = x ; i >= 0 ; i -- ) { leftResult = leftResult + flag [ i ] ; } for ( int i = x + 1 ; i < n ; i ++ ) { rightResult = rightResult + flag [ i ] ; } if ( leftResult < rightResult ) { System . out . println ( leftResult ) ; } else { System . out . println ( rightResult ) ; } } } +import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; final int n = sc . nextInt ( ) , d [ ] = new int [ n + 1 ] ; for ( int i = 0 ; i < n ; ++ i ) d [ i ] = sc . nextInt ( ) ; sc . close ( ) ; d [ n ] = 1000 ; Arrays . sort ( d ) ; int ans = 0 ; for ( int i = 0 ; i < n ; ++ i ) { int i = 0 ; if ( d [ i ] != d [ i + 1 ] ) ++ ans ; } System . out . println ( ans ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = Integer . parseInt ( sc . next ( ) ) ; Map < Integer , Integer > map = new HashMap < > ( ) ; for ( int i = 1 ; i <= N ; i ++ ) { int i = 1 ; map . put ( Integer . parseInt ( sc . next ( ) ) , i ) ; } StringBuilder builder = new StringBuilder ( ) ; for ( int i = 1 ; i <= N ; i ++ ) { builder . append ( map . get ( i ) ) . append ( " " ) ; } System . out . println ( builder . toString ( ) ) ; } } +import java . io . InputStream ; import java . io . PrintStream ; import java . util . * ; public class Main { public static void main ( String [ ] args ) { solve ( System . in , System . out ) ; } static void solve ( InputStream is , PrintStream os ) { int ans = 0 ; Scanner sc = new Scanner ( is ) ; int n = sc . nextInt ( ) ; int k = sc . nextInt ( ) ; int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int h = sc . nextInt ( ) ; if ( k <= h ) ans ++ ; } os . println ( ans ) ; } } +import java . util . * ; import java . io . * ; public class Main { public static void main ( String [ ] args ) throws IOException { int ans = 0 ; BufferedReader in = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int x = Integer . parseInt ( in . readLine ( ) ) ; int ans = 0 ; while ( x >= 5 ) { if ( x >= 500 ) { ans += 1000 * ( x / 500 ) ; x %= 500 ; } else { ans += 5 * ( x / 5 ) ; x %= 5 ; } } System . out . println ( ans ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int k = sc . nextInt ( ) ; int s = sc . nextInt ( ) ; int x = 0 ; int count = 0 ; int y = 0 ; int z = 0 ; Set < Integer > al = new HashSet < > ( ) ; for ( int i = 0 ; i <= k ; i ++ ) { int j = 0 ; al . add ( i ) ; } for ( int i = 0 ; i <= k ; i ++ ) { for ( int j = 0 ; j <= k ; j ++ ) { if ( al . contains ( s - i - j ) ) { count ++ ; } } } System . out . println ( count ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; while ( true ) { int n = sc . nextInt ( ) ; if ( n == 0 ) { break ; } int [ ] scores = new int [ n ] ; for ( int i = 0 ; i < scores . length ; i ++ ) { scores [ i ] = sc . nextInt ( ) ; } double average = 0 , variance = 0 ; for ( int i = 0 ; i < scores . length ; i ++ ) { int i = 0 ; average += ( double ) scores [ i ] / n ; } for ( int i = 0 ; i < scores . length ; i ++ ) { variance += ( double ) ( scores [ i ] - average ) * ( scores [ i ] - average ) / n ; } System . out . println ( Math . sqrt ( variance ) ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner std = new Scanner ( System . in ) ; int a = std . nextInt ( ) ; int b = std . nextInt ( ) ; if ( a >= 13 ) { System . out . println ( b ) ; } else if ( a <= 5 ) { int b = std . nextInt ( ) ; System . out . println ( " 0 " ) ; } else { System . out . println ( b / 2 ) ; } } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int num = sc . nextInt ( ) ; int [ ] cities = new int [ num + 1 ] ; int [ ] savers = new int [ num ] ; for ( int i = 0 ; i <= num ; i ++ ) cities [ i ] = sc . nextInt ( ) ; for ( int i = 0 ; i < num ; i ++ ) savers [ i ] = sc . nextInt ( ) ; double ans = 0 ; for ( int i = 0 ; i < num ; i ++ ) { if ( savers [ i ] <= cities [ i ] ) { ans += savers [ i ] ; savers [ i ] = 0 ; continue ; } else { ans += cities [ i ] ; savers [ i ] -= cities [ i ] ; } if ( savers [ i ] <= cities [ i + 1 ] ) { int i = 0 ; ans += savers [ i ] ; cities [ i + 1 ] -= savers [ i ] ; } else { ans += cities [ i + 1 ] ; cities [ i + 1 ] = 0 ; } } System . out . printf ( " %.0f \n " , ans ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { String ans = " No " ; Scanner sc = new Scanner ( System . in ) ; String strn = sc . next ( ) ; sc . close ( ) ; String [ ] str = strn . split ( " " ) ; int sum = 0 ; for ( int i = 0 ; i < strn . length ( ) ; i ++ ) { sum += Integer . parseInt ( str [ i ] ) ; } String ans = " No " ; if ( sum % 9 == 0 ) { ans = " Yes " ; } System . out . println ( ans ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner input = new Scanner ( System . in ) ; int a , b , c ; while ( true ) { a = input . nextInt ( ) ; b = input . nextInt ( ) ; c = input . nextInt ( ) ; if ( a == - 1 && b == - 1 && c == - 1 ) break ; else { if ( a == - 1 || b == - 1 ) System . out . println ( " F " ) ; else if ( a + b < 30 ) System . out . println ( " F " ) ; else if ( a + b < 50 ) { if ( c == - 1 ) { int a , b , c ; System . out . println ( " D " ) ; } else { if ( c >= 50 ) System . out . println ( " C " ) ; else System . out . println ( " D " ) ; } } else if ( a + b < 65 ) System . out . println ( " C " ) ; else if ( a + b < 80 ) System . out . println ( " B " ) ; else if ( a + b >= 80 ) System . out . println ( " A " ) ; } } } } +import java . io . BufferedReader ; import java . io . * ; import java . io . InputStreamReader ; import java . util . Scanner ; import java . util . StringTokenizer ; import java . util . * ; import java . math . * ; public class Main { static class FastReader { BufferedReader br ; StringTokenizer st ; public FastReader ( ) { br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; } String next ( ) { while ( st == null || ! st . hasMoreElements ( ) ) { try { st = new StringTokenizer ( br . readLine ( ) ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } return st . nextToken ( ) ; } int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } long nextLong ( ) { return Long . parseLong ( next ( ) ) ; } double nextDouble ( ) { return Double . parseDouble ( next ( ) ) ; } String nextLine ( ) { String str = " " ; try { str = br . readLine ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } return str ; } } public static void main ( String [ ] args ) { String w ; FastReader sc = new FastReader ( ) ; PrintWriter pw = new PrintWriter ( System . out ) ; int t = 1 ; while ( t -- > 0 ) { String [ ] s = sc . next ( ) . split ( " S " ) ; int max = 0 ; for ( String w : s ) { max = Math . max ( w . length ( ) , max ) ; } pw . println ( max ) ; } pw . close ( ) ; } } +import java . util . Scanner ; public class Main { final static String [ ] suits = { " S " , " H " , " C " , " D " } ; final static int [ ] ranks = { 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 } ; public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; boolean [ ] [ ] exist = new boolean [ suits . length ] [ ranks . length ] ; int n = scan . nextInt ( ) ; for ( int i = 0 ; i < n ; i ++ ) { String suit = scan . next ( ) ; int rank = scan . nextInt ( ) ; for ( int j = 0 ; j < suits . length ; j ++ ) { if ( suits [ j ] . equals ( suit ) ) { exist [ j ] [ rank - 1 ] = true ; } } } for ( int i = 0 ; i < suits . length ; i ++ ) { int j = 0 ; for ( int j = 0 ; j < ranks . length ; j ++ ) { if ( ! exist [ i ] [ j ] ) { System . out . println ( suits [ i ] + " " + ranks [ j ] ) ; } } } scan . close ( ) ; } } +import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner ob = new Scanner ( System . in ) ; char [ ] c = ob . next ( ) . toCharArray ( ) ; int sum = 0 ; for ( int i = 0 ; i < c . length ; i ++ ) { sum = sum + Character . getNumericValue ( c [ i ] ) ; } if ( sum % 9 == 0 ) { System . out . println ( " Yes " ) ; } else { int i = 0 ; System . out . println ( " No " ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; try { int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; System . out . println ( " a " + ( a == b ? " == " : ( a < b ? " < " : " > " ) ) + " b " ) ; } finally { Scanner sc = new Scanner ( System . in ) ; sc . close ( ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int a = sc . nextInt ( ) ; int taxi = sc . nextInt ( ) ; int train , ans ; train = n * a ; if ( train >= taxi ) { int train , ans ; System . out . println ( taxi ) ; } else { System . out . println ( train ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner s = new Scanner ( System . in ) ; double h = s . nextDouble ( ) ; double n = s . nextDouble ( ) ; double m = 0 ; for ( int i = 0 ; i < n ; i ++ ) { m += s . nextDouble ( ) ; } if ( m >= h ) { System . out . print ( " Yes " ) ; } else { double m = 0 ; System . out . print ( " No " ) ; } } } +import java . util . Scanner ; import java . util . HashMap ; import java . util . TreeMap ; import java . util . Arrays ; import java . util . Stack ; public class Main { static Scanner scn = new Scanner ( System . in ) ; static long count = 0 , max = 0 ; public static void main ( String [ ] args ) { long n = scn . nextLong ( ) ; long min = Long . MAX_VALUE , a , b ; for ( long i = 1 ; i * i <= n ; i ++ ) { if ( n % i == 0 ) { a = i ; b = n / i ; if ( ( a + b - 2 ) < min ) min = a + b - 2 ; } } System . out . println ( min ) ; } public static void coin ( int [ ] arr , int sum , int n , int prev ) { if ( sum == n ) { count ++ ; return ; } if ( sum > n ) return ; for ( int i = prev ; i < arr . length ; i ++ ) { int i = prev ; coin ( arr , sum + arr [ i ] , n , i ) ; } } } +import java . io . PrintWriter ; import java . util . Arrays ; import java . util . Map ; import java . util . Scanner ; import java . util . TreeMap ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; PrintWriter printWriter = new PrintWriter ( System . out ) ; if ( scanner . nextLine ( ) . equals ( " ABC " ) ) { printWriter . println ( " ARC " ) ; } else { PrintWriter printWriter = new PrintWriter ( System . out ) ; printWriter . println ( " ABC " ) ; } printWriter . flush ( ) ; } } +import java . util . * ; public class Main { private static final Scanner sc = new Scanner ( System . in ) ; private void solve ( ) { int N = sc . nextInt ( ) ; Set < String > set = new HashSet < > ( ) ; for ( int i = 0 ; i < N ; ++ i ) { Set < String > set = new HashSet < > ( ) ; set . add ( sc . next ( ) ) ; } System . out . println ( set . size ( ) ) ; } public static void main ( String [ ] args ) { new Main ( ) . solve ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; String str = scan . next ( ) ; int min1 = 0 ; int min2 = 0 ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { int i = 0 ; if ( i % 2 == Character . getNumericValue ( str . charAt ( i ) ) ) { min1 += 1 ; } else { min2 += 1 ; } } System . out . println ( Math . min ( min1 , min2 ) ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int N ; try ( Scanner sc = new Scanner ( System . in ) ) { int answer = 0 ; N = sc . nextInt ( ) ; } int maxKeta = ( int ) Math . floor ( Math . log10 ( ( double ) N ) + 1 ) ; int answer = 0 ; if ( maxKeta >= 2 ) { int n = ( int ) Math . floor ( ( maxKeta - 2 ) / 2 ) ; int M = 2 * n + 1 ; answer += ( ( int ) ( Math . pow ( - 10 , ( M + 1 ) ) ) - 1 ) / 11 ; } if ( maxKeta % 2 == 1 ) { answer += N - ( int ) ( Math . pow ( 10 , maxKeta - 1 ) ) + 1 ; } System . out . println ( answer ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int R = sc . nextInt ( ) ; Scanner sc = new Scanner ( System . in ) ; int P = sc . nextInt ( ) ; int Q = sc . nextInt ( ) ; int R = sc . nextInt ( ) ; System . out . println ( solve ( P , Q , R ) ) ; sc . close ( ) ; } static int solve ( int P , int Q , int R ) { return P + Q + R - Math . max ( Math . max ( P , Q ) , R ) ; } } +import java . util . Arrays ; import java . util . Scanner ; public class Main { static Scanner s = new Scanner ( System . in ) ; public static void main ( String [ ] __ ) { while ( true ) { input ( ) ; if ( in . charAt ( 0 ) == '0' ) return ; solve ( ) ; } } static String in ; private static void input ( ) { in = s . next ( ) ; } private static void solve ( ) { int [ ] x = new int [ in . length ( ) ] ; for ( int i = 0 ; i < in . length ( ) ; i ++ ) x [ i ] = in . charAt ( i ) - '0' ; System . out . println ( Arrays . stream ( x ) . parallel ( ) . sum ( ) ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int n = scan . nextInt ( ) ; int m = scan . nextInt ( ) ; int l = scan . nextInt ( ) ; int [ ] [ ] vectorA = new int [ n ] [ m ] ; int [ ] [ ] vectorB = new int [ m ] [ l ] ; long [ ] [ ] vectorC = new long [ n ] [ l ] ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < m ; j ++ ) { int elm = scan . nextInt ( ) ; vectorA [ i ] [ j ] = elm ; } } for ( int i = 0 ; i < m ; i ++ ) { for ( int j = 0 ; j < l ; j ++ ) { int k = 0 ; int elm = scan . nextInt ( ) ; vectorB [ i ] [ j ] = elm ; } } for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < l ; j ++ ) { long ans = 0 ; for ( int k = 0 ; k < m ; k ++ ) { ans += ( long ) vectorA [ i ] [ k ] * ( long ) vectorB [ k ] [ j ] ; } vectorC [ i ] [ j ] = ans ; System . out . printf ( j != l - 1 ? " %d " : " %d \n " , vectorC [ i ] [ j ] ) ; } } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int z = N - x - y ; Scanner scanner = new Scanner ( System . in ) ; int N = Integer . parseInt ( scanner . next ( ) ) ; int Y = Integer . parseInt ( scanner . next ( ) ) ; scanner . close ( ) ; for ( int x = 0 ; x <= N ; x ++ ) { for ( int y = 0 ; y <= N ; y ++ ) { int z = N - x - y ; if ( z < 0 ) continue ; if ( ( x * 10000 + y * 5000 + z * 1000 ) == Y ) { System . out . println ( String . format ( " %d %d %d " , x , y , z ) ) ; return ; } } } System . out . println ( " -1 -1 -1 " ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . StringTokenizer ; public class Main { public static void main ( String [ ] args ) { FastReader in = new FastReader ( ) ; boolean exist = false ; int num = in . nextInt ( ) ; int max = in . nextInt ( ) ; int cost = Integer . MAX_VALUE ; for ( int i = 0 ; i < num ; i ++ ) { int c = in . nextInt ( ) ; int t = in . nextInt ( ) ; if ( c < cost && t <= max ) { cost = c ; exist = true ; } } if ( exist ) System . out . println ( cost ) ; else System . out . println ( " TLE " ) ; } static class FastReader { BufferedReader br ; StringTokenizer st ; public FastReader ( ) { br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; } String next ( ) { while ( st == null || ! st . hasMoreElements ( ) ) { try { String str = " " ; st = new StringTokenizer ( br . readLine ( ) ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } return st . nextToken ( ) ; } int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } long nextLong ( ) { return Long . parseLong ( next ( ) ) ; } double nextDouble ( ) { return Double . parseDouble ( next ( ) ) ; } String nextLine ( ) { String str = " " ; try { str = br . readLine ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } return str ; } } } +import java . util . * ; import java . io . * ; public class Main { public static void main ( String [ ] args ) { FastScanner scanner = new FastScanner ( ) ; PrintWriter out = new PrintWriter ( System . out ) ; int a = scanner . nextInt ( ) ; int b = scanner . nextInt ( ) ; int c = scanner . nextInt ( ) ; out . println ( Math . max ( c - ( a - b ) , 0 ) ) ; out . flush ( ) ; } public static class FastScanner { BufferedReader br ; StringTokenizer st ; public FastScanner ( Reader in ) { br = new BufferedReader ( in ) ; } public FastScanner ( ) { this ( 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 readNextLine ( ) { String str = " " ; try { String str = " " ; str = br . readLine ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } return str ; } } } +import java . io . * ; import java . util . * ; 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 ) ; Unstoppable solver = new Unstoppable ( ) ; solver . solve ( in , out ) ; out . close ( ) ; } static class Unstoppable { public void solve ( InputReader in , PrintWriter out ) { int n = in . nextInt ( ) ; int [ ] a = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) a [ i ] = in . nextInt ( ) ; int sum = 0 ; for ( int i = 0 ; i < n - 1 ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { int mul = a [ i ] * a [ j ] ; sum += mul ; } } out . println ( sum ) ; } } static class InputReader { public BufferedReader reader ; public StringTokenizer tokenizer ; public InputReader ( InputStream stream ) { reader = new BufferedReader ( new InputStreamReader ( stream ) , 32768 ) ; tokenizer = null ; } public String next ( ) { while ( tokenizer == null || ! tokenizer . hasMoreTokens ( ) ) { try { tokenizer = new StringTokenizer ( reader . readLine ( ) ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } } return tokenizer . nextToken ( ) ; } public int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; ArrayList < String > list = new ArrayList < String > ( ) ; char last = 'X' ; boolean flag = true ; for ( int i = 0 ; i < n ; i ++ ) { String s = sc . next ( ) ; if ( list . contains ( s ) ) { flag = false ; break ; } else { list . add ( s ) ; } if ( i != 0 && s . charAt ( 0 ) != last ) { String s = sc . next ( ) ; flag = false ; break ; } last = s . charAt ( s . length ( ) - 1 ) ; } if ( flag ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } } +import java . io . InputStream ; import java . io . PrintStream ; import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { solve ( System . in , System . out ) ; } static void solve ( InputStream is , PrintStream os ) { Scanner scan = new Scanner ( is ) ; long H = scan . nextLong ( ) ; int N = scan . nextInt ( ) ; int [ ] A = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) A [ i ] = scan . nextInt ( ) ; Arrays . sort ( A ) ; for ( int i = N - 1 ; i >= 0 ; i -- ) { int i = N - 1 ; H -= A [ i ] ; if ( H <= 0 ) break ; } if ( H <= 0 ) os . println ( " Yes " ) ; else os . println ( " No " ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner scanner = new Scanner ( System . in ) ; String numbers = " 1 " ; int sum ; while ( true ) { numbers = scanner . nextLine ( ) ; if ( numbers . equals ( " 0 " ) ) break ; sum = 0 ; for ( int i = 0 ; i < numbers . length ( ) ; ++ i ) { sum += Character . getNumericValue ( numbers . charAt ( i ) ) ; } System . out . println ( sum ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String S = sc . next ( ) ; String ans = " " ; if ( S . equals ( " ABC " ) ) { ans = " ARC " ; } else { String ans = " " ; ans = " ABC " ; } System . out . println ( ans ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . nextLine ( ) ; char c ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { int i = 0 ; c = s . charAt ( i ) ; if ( c >= 'A' && c <= 'Z' ) { c += 'a' - 'A' ; } else if ( c >= 'a' && c <= 'z' ) { c += 'A' - 'a' ; } System . out . print ( c ) ; } System . out . println ( " " ) ; sc . close ( ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int i ; Scanner sc = new Scanner ( System . in ) ; int n = Integer . parseInt ( sc . next ( ) ) ; ArrayList < Integer > a = new ArrayList < > ( ) ; for ( i = 0 ; i < n ; i ++ ) { int ans = 0 ; a . add ( Integer . parseInt ( sc . next ( ) ) ) ; } sc . close ( ) ; Collections . sort ( a , Comparator . reverseOrder ( ) ) ; int ans = 0 ; for ( i = 0 ; i < n ; i ++ ) { if ( i % 2 == 0 ) ans += a . get ( i ) ; else ans -= a . get ( i ) ; } System . out . println ( ans ) ; } } +import java . io . BufferedReader ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws Exception { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String [ ] ar = br . readLine ( ) . split ( " " ) ; int row = Integer . parseInt ( ar [ 0 ] ) ; int col = Integer . parseInt ( ar [ 1 ] ) ; int [ ] [ ] a = new int [ row ] [ col ] ; int [ ] b = new int [ col ] ; for ( int i = 0 ; i < a . length ; i ++ ) { ar = br . readLine ( ) . split ( " " ) ; for ( int n = 0 ; n < a [ i ] . length ; n ++ ) { int n = 0 ; a [ i ] [ n ] = Integer . parseInt ( ar [ n ] ) ; } } for ( int i = 0 ; i < b . length ; i ++ ) { b [ i ] = Integer . parseInt ( br . readLine ( ) ) ; } for ( int i = 0 ; i < a . length ; i ++ ) { int ans = 0 ; for ( int n = 0 ; n < a [ i ] . length ; n ++ ) { ans += a [ i ] [ n ] * b [ n ] ; } System . out . println ( ans ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int j = 1 ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int ans = 0 ; int count = 0 ; if ( n < 105 ) { System . out . println ( 0 ) ; return ; } for ( int i = 105 ; i <= n ; i ++ ) { if ( i % 2 == 0 ) { continue ; } count = 0 ; for ( int j = 1 ; j <= i ; j ++ ) { if ( i % j == 0 ) { count ++ ; } } if ( count == 8 ) { ans ++ ; } } System . out . println ( ans ) ; } } +import java . util . ArrayList ; import java . util . Collections ; import java . util . HashMap ; import java . util . List ; import java . util . Map ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; Map < String , Integer > map = new HashMap < > ( ) ; int max = 0 ; for ( int i = 0 ; i < N ; i ++ ) { String S = sc . next ( ) ; if ( map . containsKey ( S ) ) { map . put ( S , map . get ( S ) + 1 ) ; } else { map . put ( S , 1 ) ; } max = Math . max ( max , map . get ( S ) ) ; } List < String > list = new ArrayList < String > ( ) ; for ( Map . Entry < String , Integer > key : map . entrySet ( ) ) { if ( key . getValue ( ) == max ) { String S ; list . add ( key . getKey ( ) ) ; } } Collections . sort ( list ) ; for ( String S : list ) { System . out . println ( S ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; int max = 0 ; int tmp = 0 ; for ( int i = 0 ; i < s . length ( ) ; ++ i ) { char ch = s . charAt ( i ) ; if ( ch == 'A' || ch == 'C' || ch == 'G' || ch == 'T' ) ++ tmp ; else tmp = 0 ; if ( tmp > max ) max = tmp ; } System . out . println ( max ) ; } } +import java . io . IOException ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws IOException { Scanner sc = new Scanner ( System . in ) ; int s = 0 ; String n = sc . next ( ) ; for ( char ch : n . toCharArray ( ) ) { s += ch - '0' ; s %= 9 ; } if ( s == 0 ) { char ch ; System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } } +import java . util . ArrayList ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int numPi = Integer . parseInt ( scan . next ( ) ) ; Scanner scan = new Scanner ( System . in ) ; int n = Integer . parseInt ( scan . next ( ) ) ; int counter = 0 ; int min = Integer . MAX_VALUE ; ArrayList < Integer > pi = new ArrayList < Integer > ( ) ; for ( int i = 0 ; i < n ; ++ i ) { int numPi = Integer . parseInt ( scan . next ( ) ) ; if ( i == 0 ) { counter ++ ; } else { if ( numPi <= min ) { counter ++ ; } } if ( min > numPi ) { min = numPi ; } } System . out . println ( counter ) ; } } +import java . util . ArrayList ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scn = new Scanner ( System . in ) ; int N = Integer . parseInt ( scn . nextLine ( ) ) ; String name = scn . nextLine ( ) ; char [ ] original = name . toCharArray ( ) ; ArrayList < Character > result = new ArrayList < > ( ) ; result . add ( original [ 0 ] ) ; for ( int i = 1 ; i < N ; i ++ ) { int i = 1 ; if ( result . get ( result . size ( ) - 1 ) == original [ i ] ) { continue ; } else result . add ( original [ i ] ) ; } System . out . println ( result . size ( ) ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int l = sc . nextInt ( ) ; int r = sc . nextInt ( ) ; int count = 0 ; for ( int a = 1 ; a < 10 ; a ++ ) { int c = 0 ; for ( int b = 0 ; b < 10 ; b ++ ) { for ( int c = 0 ; c < 10 ; c ++ ) { int temp = ( 10001 * a ) + ( 1010 * b ) + ( 100 * c ) ; if ( temp >= l && temp <= r ) { count ++ ; } } } } System . out . println ( count ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int n = scanner . nextInt ( ) ; int [ ] a = new int [ 10000 ] ; int max = - 1000000 ; int min = 1000000 ; long sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = scanner . nextInt ( ) ; if ( i == 0 ) { max = a [ 0 ] ; min = a [ 0 ] ; } else { if ( a [ i ] > max ) { int i = 0 ; max = a [ i ] ; } else if ( a [ i ] < min ) { min = a [ i ] ; } } sum += a [ i ] ; } System . out . printf ( " %1$d %2$d %3$d \n " , min , max , sum ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; String [ ] str = new String [ 2 ] ; int count = 0 ; while ( in . hasNext ( ) ) { String buf = in . nextLine ( ) ; str [ count ] = buf ; } String [ ] split = str [ 0 ] . split ( " " ) ; int [ ] facter ; facter = new int [ split . length ] ; for ( int i = 0 ; i < split . length ; i ++ ) { facter [ i ] = Integer . parseInt ( split [ i ] ) ; } if ( facter [ 0 ] < facter [ 1 ] ) { int y = facter [ 1 ] ; int temp = facter [ 0 ] ; facter [ 0 ] = facter [ 1 ] ; facter [ 1 ] = temp ; } int r = 0 ; int x = facter [ 0 ] ; int y = facter [ 1 ] ; while ( y > 0 ) { r = x % y ; x = y ; y = r ; } System . out . println ( x ) ; } } +import java . util . * ; public class Main { Scanner sc = new Scanner ( System . in ) ; final int MOD = 1000000007 ; final int MAX = Integer . MAX_VALUE ; final long LMAX = Long . MAX_VALUE ; int LEN = 0 ; void doIt ( ) { char [ ] s = sc . next ( ) . toCharArray ( ) ; int cnt = 0 ; for ( int i = 0 ; i < s . length / 2 ; i ++ ) { if ( s [ i ] != s [ s . length - 1 - i ] ) cnt ++ ; } System . out . println ( cnt ) ; } public static void main ( String [ ] args ) { int i = 0 ; new Main ( ) . doIt ( ) ; } } +import java . util . Arrays ; import java . util . HashMap ; import java . util . Map ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int n = scanner . nextInt ( ) ; Map < String , Long > counts = new HashMap < > ( ) ; for ( int i = 0 ; i < n ; ++ i ) { String s = scanner . next ( ) ; char [ ] tmp = s . toCharArray ( ) ; Arrays . sort ( tmp ) ; s = new String ( tmp ) ; long count = counts . getOrDefault ( s , 0L ) ; counts . put ( s , count + 1L ) ; } long pairs = 0 ; for ( long count : counts . values ( ) ) { long count ; pairs += ( count * ( count - 1L ) / 2 ) ; } System . out . println ( pairs ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int sn = 0 ; long n = sc . nextLong ( ) ; String str = String . valueOf ( n ) ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { char a = str . charAt ( i ) ; int b = a - '0' ; sn = sn + b ; } if ( n % sn == 0 ) { int i = 0 ; System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } } +import java . io . IOException ; import java . util . Arrays ; import java . util . OptionalLong ; import java . util . Scanner ; import java . util . stream . LongStream ; class Main { public static void main ( String [ ] args ) throws IOException { Scanner scane = new Scanner ( System . in ) ; int n = scane . nextInt ( ) ; long [ ] nums = new long [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { int i = 0 ; nums [ i ] = scane . nextInt ( ) ; } LongStream stream = Arrays . stream ( nums ) ; LongStream stream2 = Arrays . stream ( nums ) ; LongStream stream3 = Arrays . stream ( nums ) ; OptionalLong min = stream . min ( ) ; OptionalLong max = stream2 . max ( ) ; long total = stream3 . sum ( ) ; System . out . println ( min . getAsLong ( ) + " " + max . getAsLong ( ) + " " + total ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int M = sc . nextInt ( ) ; int [ ] ave = new int [ N ] ; for ( int i = 0 ; i < M ; i ++ ) { ave [ sc . nextInt ( ) - 1 ] ++ ; ave [ sc . nextInt ( ) - 1 ] ++ ; } for ( int i = 0 ; i < ave . length ; i ++ ) { int i = 0 ; System . out . println ( ave [ i ] ) ; } sc . close ( ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; try ( BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ) { char [ ] charStr = br . readLine ( ) . toCharArray ( ) ; StringBuilder rvsStr = new StringBuilder ( ) ; for ( int i = charStr . length - 1 ; i > - 1 ; i -- ) rvsStr . append ( charStr [ i ] ) ; System . out . println ( rvsStr ) ; } } } +import java . io . IOException ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws IOException { Scanner sc = new Scanner ( System . in ) ; StringBuilder sb = new StringBuilder ( ) ; while ( true ) { final String [ ] data = sc . nextLine ( ) . split ( " " ) ; final int n = Integer . parseInt ( data [ 0 ] ) ; final int x = Integer . parseInt ( data [ 1 ] ) ; if ( n == 0 && x == 0 ) break ; int count = 0 ; for ( int i = 1 ; i <= n - 2 ; i ++ ) { for ( int j = i + 1 ; j <= n - 1 ; j ++ ) { for ( int k = j + 1 ; k <= n ; k ++ ) { int k = j + 1 ; if ( ( i + j + k ) == x ) count ++ ; } } } System . out . println ( count ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int nowY = 0 ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; String ans = " Yes " ; int nowT = 0 ; int nowX = 0 ; int nowY = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int t = sc . nextInt ( ) ; int x = sc . nextInt ( ) ; int y = sc . nextInt ( ) ; int vGap = Math . abs ( x - nowX ) + Math . abs ( y - nowY ) ; int tGap = t - nowT ; if ( vGap > t - nowT ) { ans = " No " ; break ; } else if ( vGap % 2 != tGap % 2 ) { ans = " No " ; break ; } } System . out . println ( ans ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; boolean flg = false ; int cnt = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int cnt = 0 ; sc . nextLine ( ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; if ( a == b ) { cnt ++ ; if ( cnt == 3 ) { flg = true ; } } else { cnt = 0 ; } } String ans = flg ? " Yes " : " No " ; System . out . println ( ans ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; 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 . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner scn = new Scanner ( System . in ) ; int n = scn . nextInt ( ) ; int k = scn . nextInt ( ) ; int [ ] h = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { int i = 0 ; h [ i ] = scn . nextInt ( ) ; } Arrays . sort ( h ) ; long att = 0 ; for ( int i = 0 ; i < n - k ; i ++ ) { att = att + h [ i ] ; } System . out . println ( att ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int ans = 0 ; double wk = 0 ; int wk1 = 0 ; int N = sc . nextInt ( ) ; int D = sc . nextInt ( ) ; int [ ] [ ] X = new int [ N ] [ D ] ; for ( int i = 1 ; i <= N ; i ++ ) { for ( int j = 1 ; j <= D ; j ++ ) { X [ i - 1 ] [ j - 1 ] = sc . nextInt ( ) ; } } for ( int i = 1 ; i < N ; i ++ ) { int k = 1 ; for ( int j = i + 1 ; j <= N ; j ++ ) { for ( int k = 1 ; k <= D ; k ++ ) { wk = ( X [ i - 1 ] [ k - 1 ] - X [ j - 1 ] [ k - 1 ] ) * ( X [ i - 1 ] [ k - 1 ] - X [ j - 1 ] [ k - 1 ] ) + wk ; } wk = Math . sqrt ( wk ) ; if ( wk == Math . ceil ( wk ) ) { ans = ans + 1 ; } wk = 0 ; } } System . out . println ( ans ) ; } } +import java . math . BigDecimal ; import java . util . Arrays ; import java . util . HashMap ; import java . util . Map ; import java . util . Objects ; import java . util . Scanner ; import java . util . StringJoiner ; import java . util . stream . Stream ; public class Main { public static void main ( final String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int [ ] [ ] route = new int [ 2 ] [ N ] ; for ( int i = 0 ; i < 2 ; i ++ ) { route [ i ] = new int [ N ] ; for ( int j = 0 ; j < N ; j ++ ) { route [ i ] [ j ] = sc . nextInt ( ) ; } } int maxCandy = Integer . MIN_VALUE ; for ( int i = 0 ; i < N ; i ++ ) { int j = 0 ; int tmp = 0 ; int h = 0 ; for ( int j = 0 ; j < N ; j ++ ) { tmp += route [ h ] [ j ] ; if ( i == j ) { h ++ ; tmp += route [ h ] [ j ] ; } } maxCandy = Math . max ( maxCandy , tmp ) ; } System . out . println ( maxCandy ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int x , y ; Scanner Ahmad = new Scanner ( System . in ) ; int x , y ; x = Ahmad . nextInt ( ) ; y = Ahmad . nextInt ( ) ; if ( ( x + y ) % 2 == 0 ) { System . out . println ( ( x + y ) / 2 ) ; } else { System . out . println ( " IMPOSSIBLE " ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; String S = sc . next ( ) ; String S1 = S . substring ( N / 2 ) ; String S2 = S . substring ( 0 , N / 2 ) ; String S3 = S1 + S2 ; sc . close ( ) ; if ( N % 2 == 1 ) { System . out . println ( " No " ) ; } else { if ( S . equals ( S3 ) ) { System . out . println ( " Yes " ) ; } else { String S3 = S1 + S2 ; System . out . println ( " No " ) ; } } } } +import java . util . Scanner ; public class Main { public static void main ( String ... args ) { Scanner scan = new Scanner ( System . in ) ; String answer = " " ; final int num = scan . nextInt ( ) ; int len = scan . nextInt ( ) ; String [ ] words = new String [ num ] ; for ( int i = 0 ; i < num ; i ++ ) { int i = 0 ; words [ i ] = scan . next ( ) ; } for ( int i = 1 ; i < num ; i ++ ) { String temp = words [ i ] ; int j = i - 1 ; while ( j >= 0 && words [ j ] . compareTo ( temp ) > 0 ) { words [ j + 1 ] = words [ j ] ; j -- ; } words [ j + 1 ] = temp ; } for ( int i = 0 ; i < num ; i ++ ) { answer = answer . concat ( words [ i ] ) ; } System . out . println ( answer ) ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { int year = 0 ; Scanner sc = new Scanner ( System . in ) ; long X = sc . nextLong ( ) ; long money = 100 ; int year = 0 ; while ( money < X ) { money *= 1.01 ; year ++ ; } System . out . println ( year ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int a = scan . nextInt ( ) ; int b = scan . nextInt ( ) ; int s = 0 ; for ( int i = 0 ; i < 2 ; i ++ ) { int s = 0 ; if ( a > b ) { s += a -- ; } else { s += b -- ; } } System . out . print ( s ) ; } } +import java . util . LinkedList ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { solve ( ) ; } private static void solve ( ) { Scanner sc = new Scanner ( System . in ) ; String line = sc . nextLine ( ) ; sc . close ( ) ; String [ ] items = line . split ( " " ) ; Stack stack = new Stack ( ) ; int op1 ; int op2 ; for ( String item : items ) { switch ( item ) { case " + " : op2 = stack . pop ( ) ; op1 = stack . pop ( ) ; stack . push ( op1 + op2 ) ; break ; case " - " : op2 = stack . pop ( ) ; op1 = stack . pop ( ) ; stack . push ( op1 - op2 ) ; break ; case " * " : op2 = stack . pop ( ) ; op1 = stack . pop ( ) ; stack . push ( op1 * op2 ) ; break ; default : stack . push ( Integer . parseInt ( item ) ) ; } } System . out . println ( stack . pop ( ) ) ; } } class Stack { private LinkedList < Integer > stack ; public Stack ( ) { stack = new LinkedList < Integer > ( ) ; } public void push ( int item ) { stack . addLast ( item ) ; } public int pop ( ) { int ret = stack . getLast ( ) ; stack . removeLast ( ) ; return ret ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String str1 = sc . nextLine ( ) ; String str2 = sc . nextLine ( ) ; boolean flag = false ; for ( int i = 0 ; i < str1 . length ( ) ; ++ i ) { int i = 0 ; String sufStr = str1 . substring ( str1 . length ( ) - i , str1 . length ( ) ) ; String preStr = str1 . substring ( 0 , str1 . length ( ) - i ) ; String compareStr = sufStr + preStr ; if ( compareStr . equals ( str2 ) ) flag = true ; } if ( flag ) 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 x = sc . nextInt ( ) ; for ( ; x > 1 ; x -- ) { for ( int i = 2 ; i < x ; i ++ ) { int n = i * i ; if ( n > x ) break ; while ( n <= x ) { int n = i * i ; if ( n == x ) { System . out . println ( x ) ; return ; } n *= i ; } } } System . out . println ( x ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { String [ ] input = new String [ 4 ] ; Scanner sc = new Scanner ( System . in ) ; int n , b , f , r , v ; int [ ] [ ] [ ] house = new int [ 4 ] [ 3 ] [ 10 ] ; String output ; String [ ] input = new String [ 4 ] ; n = Integer . parseInt ( sc . nextLine ( ) ) ; for ( int i = 0 ; i < n ; i ++ ) { input = sc . nextLine ( ) . split ( " [ \\ s]+ " ) ; b = Integer . parseInt ( input [ 0 ] ) ; f = Integer . parseInt ( input [ 1 ] ) ; r = Integer . parseInt ( input [ 2 ] ) ; v = Integer . parseInt ( input [ 3 ] ) ; house [ b - 1 ] [ f - 1 ] [ r - 1 ] += v ; } for ( b = 0 ; b < 4 ; b ++ ) { for ( f = 0 ; f < 3 ; f ++ ) { output = " " ; for ( r = 0 ; r < 10 ; r ++ ) { output += " " + house [ b ] [ f ] [ r ] ; } System . out . println ( output ) ; } if ( b < 3 ) { System . out . println ( " #################### " ) ; } } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; String Sa = scanner . next ( ) ; String Sb = scanner . next ( ) ; String Sc = scanner . next ( ) ; char [ ] [ ] C = new char [ 3 ] [ 100 ] ; C [ 0 ] = Sa . toCharArray ( ) ; C [ 1 ] = Sb . toCharArray ( ) ; C [ 2 ] = Sc . toCharArray ( ) ; int [ ] t = new int [ 3 ] ; int now = 0 ; String ans = " " ; while ( true ) { switch ( C [ now ] [ t [ now ] ] ) { case 'a' : t [ now ] ++ ; now = 0 ; break ; case 'b' : t [ now ] ++ ; now = 1 ; break ; case 'c' : t [ now ] ++ ; now = 2 ; break ; } if ( t [ 0 ] == Sa . length ( ) && now == 0 ) { ans = " A " ; break ; } if ( t [ 1 ] == Sb . length ( ) && now == 1 ) { ans = " B " ; break ; } if ( t [ 2 ] == Sc . length ( ) && now == 2 ) { String ans = " " ; ans = " C " ; break ; } } System . out . println ( ans ) ; scanner . close ( ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner stdIn = new Scanner ( System . in ) ; int N = stdIn . nextInt ( ) ; int [ ] flag = new int [ 101 ] ; Arrays . fill ( flag , 0 ) ; for ( int i = 0 ; i < N ; i ++ ) { int i = 0 ; int d = stdIn . nextInt ( ) ; flag [ d ] = 1 ; } int ans = 0 ; for ( int i = 0 ; i < 101 ; i ++ ) { ans += flag [ i ] ; } System . out . println ( ans ) ; } } +import javax . print . DocFlavor ; import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader reader = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int N = Integer . parseInt ( reader . readLine ( ) ) ; String [ ] l = reader . readLine ( ) . split ( " " ) ; int s = 0 ; int sumsq = 0 ; for ( String t : l ) { String t ; int y = Integer . parseInt ( t ) ; s = s + y ; sumsq += y * y ; } int p = ( s / N ) ; System . out . println ( Math . min ( ( N * p * p - 2 * p * s + sumsq ) , ( N * ( p + 1 ) * ( p + 1 ) - 2 * ( p + 1 ) * s + sumsq ) ) ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; long n = scan . nextLong ( ) ; long ans = 0 ; for ( int i = 1 ; i < n + 1 ; i ++ ) { if ( ( i % 3 ) == 0 || ( i % 5 ) == 0 ) { ans += 0 ; } else { int i = 1 ; ans += i ; } } System . out . println ( ans ) ; } } +import java . io . * ; class Main { public static void main ( String [ ] args ) throws Exception { int y = Integer . parseInt ( a [ 1 ] ) ; BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; StringBuilder sb = new StringBuilder ( ) ; while ( true ) { String [ ] a = br . readLine ( ) . split ( " " ) ; if ( a [ 0 ] . equals ( " 0 " ) && a [ 1 ] . equals ( " 0 " ) ) break ; int x = Integer . parseInt ( a [ 0 ] ) ; int y = Integer . parseInt ( a [ 1 ] ) ; if ( x > y ) { sb . append ( y + " " + x + " \n " ) ; } else { sb . append ( x + " " + y + " \n " ) ; } } System . out . print ( sb ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = Integer . parseInt ( sc . next ( ) ) ; int [ ] A = new int [ N ] ; int [ ] B = new int [ N - 1 ] ; for ( int i = 0 ; i < N - 1 ; i ++ ) { int i = 1 ; B [ i ] = Integer . parseInt ( sc . next ( ) ) ; } int sum = 0 ; if ( B . length == 1 ) { System . out . println ( B [ 0 ] * 2 ) ; return ; } else { sum = B [ 0 ] ; for ( int i = 1 ; i < N - 1 ; i ++ ) { sum += Math . min ( B [ i ] , B [ i - 1 ] ) ; } } sum += B [ N - 2 ] ; System . out . println ( sum ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; char [ ] list = sc . next ( ) . toCharArray ( ) ; boolean flag = false ; int max = 0 ; int tmp = 0 ; for ( int i = 0 ; i < list . length ; i ++ ) { int i = 0 ; if ( list [ i ] == 'A' || list [ i ] == 'T' || list [ i ] == 'C' || list [ i ] == 'G' ) { if ( ! flag ) { flag = true ; tmp = 0 ; } tmp ++ ; } else { if ( flag ) { flag = false ; max = Math . max ( max , tmp ) ; } } } System . out . println ( Math . max ( max , tmp ) ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; long k = sc . nextLong ( ) ; int ans = 0 ; for ( int i = 0 ; i < k ; i ++ ) { int i = 0 ; if ( s . charAt ( i ) == '1' ) { if ( i + 1 == k ) { ans = i ; break ; } } else { ans = i ; break ; } } System . out . println ( s . charAt ( ans ) ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int o = 0 ; int [ ] a = new int [ n ] ; PriorityQueue < Integer > num = new PriorityQueue < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { int c = sc . nextInt ( ) ; a [ i ] = sc . nextInt ( ) ; if ( i > 0 && a [ i ] == a [ i - 1 ] + 1 ) { num . add ( a [ i - 1 ] - 1 ) ; } } for ( int i = 0 ; i < n ; i ++ ) { int b = sc . nextInt ( ) ; o += b ; } for ( int i = 0 ; i < n - 1 ; i ++ ) { int c = sc . nextInt ( ) ; if ( num . peek ( ) != null && i == num . peek ( ) ) { o += c ; num . poll ( ) ; } } System . out . println ( o ) ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = Integer . parseInt ( sc . next ( ) ) ; int M = Integer . parseInt ( sc . next ( ) ) ; int [ ] l = new int [ M + 1 ] ; int [ ] r = new int [ M + 1 ] ; l [ 0 ] = Integer . parseInt ( sc . next ( ) ) ; r [ 0 ] = Integer . parseInt ( sc . next ( ) ) ; int max = r [ 0 ] ; int min = l [ 0 ] ; for ( int i = 1 ; i < M ; i ++ ) { l [ i ] = Integer . parseInt ( sc . next ( ) ) ; r [ i ] = Integer . parseInt ( sc . next ( ) ) ; if ( l [ i ] > min ) { int i = 1 ; min = l [ i ] ; } if ( r [ i ] < max ) { max = r [ i ] ; } if ( max - min < 0 ) { max = - 1 ; min = 0 ; break ; } } System . out . println ( max - min + 1 ) ; } } +import java . util . Scanner ; import java . util . Arrays ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int [ ] b = new int [ a ] ; for ( int i = 0 ; i < b . length ; i ++ ) { int j = 2 ; b [ i ] = sc . nextInt ( ) ; } Arrays . sort ( b ) ; double c = ( double ) ( b [ 0 ] + b [ 1 ] ) / 2 ; for ( int j = 2 ; j < b . length ; j ++ ) { c = ( double ) ( c + b [ j ] ) / 2 ; } System . out . println ( c ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; boolean hasNextInt = scanner . hasNextInt ( ) ; int n = scanner . nextInt ( ) ; long sum = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { if ( i % 3 != 0 && i % 5 != 0 ) { sum += i ; } if ( i == n ) { int i = 1 ; System . out . println ( sum ) ; break ; } } scanner . close ( ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; double min = Math . pow ( 10 , 10 ) ; double max = 0 ; for ( int i = 0 ; i < n ; i ++ ) { double target = sc . nextInt ( ) ; double target = sc . nextInt ( ) ; if ( min > target ) { min = target ; } if ( max < target ) { max = target ; } } System . out . println ( ( int ) ( max - min ) ) ; } } +import java . io . InputStream ; import java . io . PrintStream ; 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 ) ; int L = sc . nextInt ( ) ; int R = sc . nextInt ( ) ; sc . close ( ) ; R = Math . min ( L + 2019 , R ) ; int ans = Integer . MAX_VALUE ; for ( int x = L ; x < R ; x ++ ) { for ( int y = x + 1 ; y <= R ; y ++ ) { int y = x + 1 ; if ( x == y ) continue ; int m = ( int ) ( ( ( long ) x * y ) % 2019 ) ; ans = Math . min ( ans , m ) ; } } out . println ( ans ) ; } public static void main ( String [ ] args ) { new Main ( ) . _main ( args ) ; } } +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 ( ) ; if ( a < 10 ) { int b = sc . nextInt ( ) ; if ( b < 10 ) { System . out . println ( a * b ) ; } else { System . out . println ( - 1 ) ; } } else { System . out . println ( - 1 ) ; } } } +import java . io . * ; class Sta { int [ ] s ; int top ; Sta ( ) { s = new int [ 1000 ] ; top = 0 ; } void push ( int x ) { top ++ ; s [ top ] = x ; } int pop ( ) { top -- ; return s [ top + 1 ] ; } } public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader din = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String line = din . readLine ( ) ; String [ ] tokens = line . split ( " " ) ; Sta stack = new Sta ( ) ; for ( int i = 0 ; i < tokens . length ; i ++ ) { String x = tokens [ i ] ; if ( x . equals ( " + " ) ) { stack . push ( stack . pop ( ) + stack . pop ( ) ) ; } else if ( x . equals ( " - " ) ) { stack . push ( - stack . pop ( ) + stack . pop ( ) ) ; } else if ( x . equals ( " * " ) ) { stack . push ( stack . pop ( ) * stack . pop ( ) ) ; } else { String x = tokens [ i ] ; int t = Integer . parseInt ( x ) ; stack . push ( t ) ; } } System . out . println ( stack . pop ( ) ) ; } } +import java . util . ArrayList ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner scan = new Scanner ( System . in ) ; String s = scan . next ( ) ; ArrayList < Character > c = new ArrayList < Character > ( ) ; char [ ] C = new char [ s . length ( ) ] ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { C [ i ] = s . charAt ( i ) ; } for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( C [ i ] == '1' ) { c . add ( '1' ) ; } if ( C [ i ] == '0' ) { c . add ( '0' ) ; } if ( C [ i ] == 'B' && c . size ( ) > 0 ) { c . remove ( c . size ( ) - 1 ) ; } } for ( int i = 0 ; i < c . size ( ) ; i ++ ) { System . out . print ( c . get ( i ) ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; String s = sc . next ( ) ; int count = 0 ; for ( int i = 0 ; i < n - 2 ; i ++ ) { char first = s . charAt ( i ) ; char second = s . charAt ( i + 1 ) ; char third = s . charAt ( i + 2 ) ; if ( first == 'A' && second == 'B' && third == 'C' ) { count ++ ; } } print ( count ) ; sc . close ( ) ; } public static void print ( Object obj ) { int i = 0 ; System . out . println ( obj ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int [ ] data = new int [ 10 ] ; for ( int i = 0 ; i < 10 ; i ++ ) { int i = 1 ; data [ i ] = scan . nextInt ( ) ; } int afterData , beforeIndex ; for ( int i = 1 ; i < 10 ; i ++ ) { afterData = data [ i ] ; beforeIndex = i - 1 ; while ( beforeIndex >= 0 && data [ beforeIndex ] > afterData ) { data [ beforeIndex + 1 ] = data [ beforeIndex ] ; beforeIndex -- ; } data [ beforeIndex + 1 ] = afterData ; } System . out . println ( data [ 9 ] ) ; System . out . println ( data [ 8 ] ) ; System . out . println ( data [ 7 ] ) ; scan . close ( ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int i = Lmax ; Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int M = sc . nextInt ( ) ; int [ ] L = new int [ M ] ; int [ ] R = new int [ M ] ; int cnt = 0 ; int Lmax = 0 ; int Rmin = 100000 ; for ( int i = 0 ; i < M ; i ++ ) { L [ i ] = sc . nextInt ( ) ; if ( L [ i ] > Lmax ) Lmax = L [ i ] ; R [ i ] = sc . nextInt ( ) ; if ( R [ i ] < Rmin ) Rmin = R [ i ] ; } for ( int i = Lmax ; i <= Rmin ; i ++ ) { cnt ++ ; } System . out . println ( cnt ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . PrintWriter ; import java . util . StringTokenizer ; public class Main { public static void main ( String [ ] args ) throws IOException { int ac = 0 , wa = 0 , tle = 0 , re = 0 ; BufferedReader br = new BufferedReader ( new java . io . InputStreamReader ( System . in ) ) ; PrintWriter pw = new PrintWriter ( System . out ) ; StringTokenizer st = new StringTokenizer ( br . readLine ( ) ) ; int N = Integer . parseInt ( st . nextToken ( ) ) ; int ac = 0 , wa = 0 , tle = 0 , re = 0 ; for ( int i = 0 ; i < N ; i ++ ) { st = new StringTokenizer ( br . readLine ( ) ) ; String target = st . nextToken ( ) ; switch ( target ) { case " AC " : ac ++ ; break ; case " WA " : wa ++ ; break ; case " TLE " : tle ++ ; break ; case " RE " : re ++ ; break ; } } pw . println ( " AC x " + ac ) ; pw . println ( " WA x " + wa ) ; pw . println ( " TLE x " + tle ) ; pw . println ( " RE x " + re ) ; br . close ( ) ; pw . close ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int w = sc . nextInt ( ) ; int n = sc . nextInt ( ) ; int [ ] array = new int [ w ] ; int swap1 , swap2 ; byte garbage ; for ( int i = 0 ; i < w ; i ++ ) array [ i ] = i + 1 ; for ( int i = 0 ; i < n ; i ++ ) { int i = 0 ; String [ ] swaps = sc . next ( ) . split ( " , " , 0 ) ; swap1 = Integer . parseInt ( swaps [ 0 ] ) - 1 ; swap2 = Integer . parseInt ( swaps [ 1 ] ) - 1 ; int temp = array [ swap1 ] ; array [ swap1 ] = array [ swap2 ] ; array [ swap2 ] = temp ; } for ( int i = 0 ; i < w ; i ++ ) { System . out . println ( array [ i ] ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int ninzuu = 0 ; Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int D = sc . nextInt ( ) ; int ninzuu = 0 ; D = D * 2 + 1 ; do { N = N - D ; ninzuu ++ ; } while ( N > 0 ) ; System . out . println ( ninzuu ) ; sc . close ( ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int a = scan . nextInt ( ) ; int b = scan . nextInt ( ) ; int c = scan . nextInt ( ) ; int d = scan . nextInt ( ) ; int sum = 0 ; if ( d <= a ) { System . out . println ( d ) ; return ; } sum = a ; d -= a ; if ( d <= b ) { int sum = 0 ; System . out . println ( sum ) ; return ; } d -= b ; sum -= d ; System . out . println ( sum ) ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int k = sc . nextInt ( ) ; int [ ] a = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = sc . nextInt ( ) ; } Arrays . sort ( a ) ; int sum = 0 ; int j = 0 ; while ( k -- > 0 ) { int j = 0 ; sum += a [ j ] ; j ++ ; } System . out . println ( sum ) ; } } +import java . util . * ; public class Main { final static int MOD = 1000000007 ; final static int INF = 1000000000 ; public static void main ( String [ ] args ) { Deque < Integer > S = new ArrayDeque < Integer > ( ) ; Scanner sc = new Scanner ( System . in ) ; String line = sc . nextLine ( ) ; String [ ] str = line . split ( " " ) ; for ( String s : str ) { if ( s . equals ( " " ) ) break ; if ( s . equals ( " + " ) ) { int b = S . pop ( ) ; int a = S . pop ( ) ; S . push ( a + b ) ; } else if ( s . equals ( " - " ) ) { int a = S . pop ( ) ; int b = S . pop ( ) ; int a = S . pop ( ) ; S . push ( a - b ) ; } else if ( s . equals ( " * " ) ) { int b = S . pop ( ) ; int a = S . pop ( ) ; S . push ( a * b ) ; } else { S . push ( Integer . parseInt ( s ) ) ; } } sc . close ( ) ; System . out . println ( S . getFirst ( ) . intValue ( ) ) ; } } +import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int X = sc . nextInt ( ) ; int [ ] A = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { A [ i ] = sc . nextInt ( ) ; } Arrays . parallelSort ( A ) ; for ( int i = 0 ; i < N ; i ++ ) { X -= A [ i ] ; } System . out . println ( N + X / A [ 0 ] ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; char [ ] a = new char [ 10 ] ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { a [ i ] = s . charAt ( i ) ; } a [ 3 ] = '8' ; for ( int i = 0 ; i < a . length ; i ++ ) { System . out . print ( a [ i ] ) ; } } } +import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . util . Arrays ; import java . util . Collections ; import java . util . ArrayList ; import java . util . List ; import java . util . HashSet ; public class Main { static BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; static int [ ] inputval ( ) throws Exception { String [ ] strarray = br . readLine ( ) . trim ( ) . split ( " " ) ; int [ ] intarray = new int [ strarray . length ] ; for ( int i = 0 ; i < intarray . length ; i ++ ) { int i = 0 ; intarray [ i ] = Integer . parseInt ( strarray [ i ] ) ; } return intarray ; } static Integer [ ] inputvalInteger ( ) throws Exception { String [ ] strarray = br . readLine ( ) . trim ( ) . split ( " " ) ; Integer [ ] intarray = new Integer [ strarray . length ] ; for ( int i = 0 ; i < intarray . length ; i ++ ) { intarray [ i ] = Integer . parseInt ( strarray [ i ] ) ; } return intarray ; } public static void main ( String [ ] args ) throws Exception { int n = Integer . parseInt ( br . readLine ( ) . trim ( ) ) ; HashSet < Integer > st = new HashSet < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { int d = Integer . parseInt ( br . readLine ( ) . trim ( ) ) ; st . add ( d ) ; } System . out . println ( st . size ( ) ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int N = scanner . nextInt ( ) ; int D = scanner . nextInt ( ) ; int [ ] [ ] X = new int [ N ] [ D ] ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < D ; j ++ ) { X [ i ] [ j ] = scanner . nextInt ( ) ; } } int resultNumber = 0 ; int temp = 0 ; for ( int i = 0 ; i < N - 1 ; i ++ ) { for ( int j = i + 1 ; j < N ; j ++ ) { for ( int k = 0 ; k < D ; k ++ ) { temp += Math . pow ( ( X [ i ] [ k ] - X [ j ] [ k ] ) , 2 ) ; if ( k == D - 1 ) { int k = 0 ; if ( Math . sqrt ( temp ) == ( int ) Math . sqrt ( temp ) ) { resultNumber ++ ; } temp = 0 ; } } } } System . out . println ( resultNumber ) ; scanner . close ( ) ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { long a = 1 ; Scanner sc = new Scanner ( System . in ) ; long N = sc . nextLong ( ) ; long min = Integer . MAX_VALUE ; for ( long a = 1 ; a <= Math . sqrt ( ( double ) N ) ; a ++ ) { if ( N % a == 0 ) { long b = N / a ; int f = Math . max ( String . valueOf ( a ) . length ( ) , String . valueOf ( b ) . length ( ) ) ; if ( f < min ) min = f ; } } System . out . println ( min ) ; } } +import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . util . HashMap ; public class Main { public static void main ( String [ ] args ) throws Exception { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String line = " " ; HashMap < String , Integer > ans = new HashMap < String , Integer > ( ) ; while ( ( line = br . readLine ( ) ) != null ) { for ( int i = 0 ; i < line . length ( ) ; i ++ ) { String str = Character . toString ( line . charAt ( i ) ) . toLowerCase ( ) ; if ( ans . containsKey ( str ) ) { ans . put ( str , ans . get ( str ) + 1 ) ; } else { ans . put ( str , 1 ) ; } } } StringBuilder sb = new StringBuilder ( ) ; for ( char c = 'a' ; c <= 'z' ; c ++ ) { sb . append ( c ) . append ( " : " ) ; String keyChar = Character . toString ( c ) ; if ( ans . containsKey ( keyChar ) ) { sb . append ( ans . get ( keyChar ) ) ; } else { String keyChar = Character . toString ( c ) ; sb . append ( " 0 " ) ; } sb . append ( " \n " ) ; } System . out . print ( sb . toString ( ) ) ; } } +import java . util . Scanner ; import java . util . Stack ; public class Main { Scanner sc = new Scanner ( System . in ) ; void solve ( ) { String [ ] rawInputs = sc . nextLine ( ) . split ( " " ) ; Stack < String > stack = new Stack < > ( ) ; for ( String input : rawInputs ) { switch ( input ) { case " + " : { Integer opl = Integer . valueOf ( stack . pop ( ) ) ; Integer opr = Integer . valueOf ( stack . pop ( ) ) ; Integer result = opr + opl ; stack . push ( String . valueOf ( result ) ) ; break ; } case " - " : { String result = stack . pop ( ) ; Integer opl = Integer . valueOf ( stack . pop ( ) ) ; Integer opr = Integer . valueOf ( stack . pop ( ) ) ; Integer result = opr - opl ; stack . push ( String . valueOf ( result ) ) ; break ; } case " * " : { Integer opl = Integer . valueOf ( stack . pop ( ) ) ; Integer opr = Integer . valueOf ( stack . pop ( ) ) ; Integer result = opr * opl ; stack . push ( String . valueOf ( result ) ) ; break ; } default : { stack . push ( input ) ; } } } String result = stack . pop ( ) ; System . out . println ( result ) ; } public static void main ( String [ ] args ) { new Main ( ) . solve ( ) ; } } +import java . util . Arrays ; import java . util . Collections ; import java . util . LinkedList ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int health1 = sc . nextInt ( ) ; int strength1 = sc . nextInt ( ) ; int health2 = sc . nextInt ( ) ; int strength2 = sc . nextInt ( ) ; while ( true ) { health2 -= strength1 ; if ( health2 <= 0 ) break ; health1 -= strength2 ; if ( health1 <= 0 ) break ; } if ( health1 > health2 ) { System . out . println ( " Yes " ) ; } else { int strength2 = sc . nextInt ( ) ; System . out . println ( " No " ) ; } } } +import java . util . * ; class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; Scanner sc = new Scanner ( System . in ) ; for ( ; ; ) { int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; if ( a == 0 && b == 0 ) break ; System . out . println ( " " + Math . min ( a , b ) + " " + Math . max ( a , b ) ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int K = sc . nextInt ( ) ; sc . nextLine ( ) ; String str = sc . nextLine ( ) ; if ( str . length ( ) <= K ) { String str = sc . nextLine ( ) ; System . out . println ( str ) ; return ; } String str2 = str . substring ( 0 , K ) + " ... " ; System . out . println ( str2 ) ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int x = sc . nextInt ( ) ; int d = x % 10 ; int c = x / 10 % 10 ; int b = x / 10 / 10 % 10 ; int a = x / 10 / 10 / 10 % 10 ; for ( int i = 0 ; i < 8 ; i ++ ) { int number = i ; int cnt = 0 ; int [ ] abcd = { a , b , c , d } ; char [ ] symbol = { 0 , 0 , 0 } ; while ( cnt < 3 ) { symbol [ cnt ] = ( number % 2 == 0 ) ? '+' : '-' ; number = number / 2 ; cnt ++ ; } int result = abcd [ 0 ] ; for ( int j = 0 ; j < 3 ; j ++ ) { if ( symbol [ j ] == '+' ) { result += abcd [ j + 1 ] ; } else { int j = 0 ; result -= abcd [ j + 1 ] ; } } if ( result == 7 ) { System . out . println ( a + " " + symbol [ 0 ] + " " + b + " " + symbol [ 1 ] + " " + c + " " + symbol [ 2 ] + " " + d + " =7 " ) ; return ; } } } } +import java . io . * ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String s = br . readLine ( ) ; String p = br . readLine ( ) ; int cnt = 0 ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { cnt = 0 ; for ( int j = 0 ; j < p . length ( ) ; j ++ ) { if ( s . charAt ( ( i + j ) % s . length ( ) ) == p . charAt ( j ) ) { int j = 0 ; cnt ++ ; } else { break ; } } if ( cnt == p . length ( ) ) { break ; } } if ( cnt == p . length ( ) ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } } +import java . util . Scanner ; public class Main { static Scanner sc = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { int b = sc . nextInt ( ) ; while ( sc . hasNext ( ) ) { int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; System . out . println ( digit ( a , b ) ) ; } } private static int digit ( int a , int b ) { int dg = Integer . toString ( a + b ) . length ( ) ; return dg ; } } +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 ( ) ; int result2 = N ; int result = 0 ; do { int result = 0 ; result2 = result2 / K ; result ++ ; } while ( result2 != 0 ) ; System . out . println ( result ) ; } } +import java . util . Scanner ; public class Main { static String a ; public static void main ( String [ ] args ) { Scanner stdIn = new Scanner ( System . in ) ; int n = stdIn . nextInt ( ) ; int count = 0 ; IN : for ( int i = 0 ; i < n ; i ++ ) { int j = 2 ; int x = stdIn . nextInt ( ) ; for ( int j = 2 ; j * j <= x ; j ++ ) { if ( x % j == 0 ) continue IN ; } count ++ ; } System . out . println ( count ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner s = new Scanner ( System . in ) ; String st = s . nextLine ( ) ; int cnt = 0 ; for ( int i = 0 ; i < st . length ( ) ; i ++ ) { int i = 0 ; if ( st . charAt ( i ) == 'R' ) cnt += 1 ; else if ( cnt != 0 ) break ; } System . out . println ( cnt ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String S = sc . next ( ) ; sc . close ( ) ; int i = 0 ; for ( int j = 0 ; j < 3 ; j ++ ) { for ( int k = j + 1 ; k < S . length ( ) ; k ++ ) { int k = j + 1 ; if ( S . charAt ( j ) == S . charAt ( k ) ) { i ++ ; } } } if ( i == 2 ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } } +import java . util . Arrays ; import java . util . HashMap ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; HashMap < String , Long > map = new HashMap < > ( ) ; for ( int i = 0 ; i < a ; i ++ ) { Long l ; String s = sc . next ( ) ; char [ ] c = s . toCharArray ( ) ; Arrays . sort ( c ) ; s = new String ( c ) ; Long cnt = ( map . containsKey ( s ) ? map . get ( s ) + 1 : 1 ) ; map . put ( s , cnt ) ; } long count = 0 ; for ( Long l : map . values ( ) ) { count = count + ( l * ( l - 1 ) / 2 ) ; } System . out . print ( count ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long n = sc . nextLong ( ) ; long k = sc . nextLong ( ) ; if ( n > k ) { long k = sc . nextLong ( ) ; n -= k * ( n / k ) ; if ( k - n < n ) { System . out . println ( k - n ) ; } else { System . out . println ( n ) ; } } else { if ( k - n < n ) { System . out . println ( k - n ) ; } else { System . out . println ( n ) ; } } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; char [ ] str = sc . next ( ) . toCharArray ( ) ; int count = 0 ; int tmpCount = 0 ; for ( int i = 0 ; i < str . length ; i ++ ) { if ( ( i % 2 == 0 && str [ i ] == '0' ) || ( i % 2 == 1 && str [ i ] == '1' ) ) { count ++ ; } } for ( int i = 0 ; i < str . length ; i ++ ) { if ( ( i % 2 == 1 && str [ i ] == '0' ) || ( i % 2 == 0 && str [ i ] == '1' ) ) { tmpCount ++ ; } } System . out . println ( Math . min ( count , tmpCount ) ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int j = tr ; Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) , b = sc . nextInt ( ) ; int c = sc . nextInt ( ) , x = sc . nextInt ( ) ; sc . close ( ) ; int tmpa = a , tmpb = b , tmpc = c , tmpx = x / 50 ; int r = tmpx % 2 ; int ans = 0 ; for ( int i = r ; i <= x ; i += 2 ) { if ( i > tmpc ) break ; int tmp = ( tmpx - i ) / 2 ; int tr = tmp % 5 ; for ( int j = tr ; j <= tmp ; j += 5 ) { if ( j > tmpb ) break ; int tmp2 = ( tmp - j ) / 5 ; if ( tmp2 <= a && tmp >= 0 ) ++ ans ; } } System . out . println ( ans ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int j = 0 ; Scanner s = new Scanner ( System . in ) ; int n = s . nextInt ( ) ; int [ ] ds = new int [ n ] ; int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { ds [ i ] = s . nextInt ( ) ; for ( int j = 0 ; j < i ; j ++ ) { sum += ds [ j ] * ds [ i ] ; } } System . out . println ( sum ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int c = 0 ; int prev = 0 ; int max = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int max = 0 ; int b = sc . nextInt ( ) ; if ( prev >= b ) { c ++ ; max = Math . max ( c , max ) ; } else { c = 0 ; } prev = b ; } System . out . println ( max ) ; } } +import java . util . * ; import java . io . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] a = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) a [ i ] = sc . nextInt ( ) ; int [ ] dp = new int [ n + 1 ] ; for ( int i = 2 ; i <= n ; i ++ ) { int i = 2 ; dp [ i ] = dp [ i - 1 ] + Math . abs ( a [ i - 1 ] - a [ i - 2 ] ) ; if ( i >= 3 ) dp [ i ] = Math . min ( dp [ i ] , dp [ i - 2 ] + Math . abs ( a [ i - 3 ] - a [ i - 1 ] ) ) ; } System . out . println ( dp [ n ] ) ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int n = in . nextInt ( ) ; int [ ] s = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { s [ i ] = in . nextInt ( ) ; } int q = in . nextInt ( ) ; int [ ] t = new int [ q ] ; for ( int i = 0 ; i < q ; i ++ ) { t [ i ] = in . nextInt ( ) ; } int count = 0 ; for ( int i = 0 ; i < q ; i ++ ) { int ul = s . length ; int ll = - 1 ; boolean flag = false ; while ( ll + 1 < ul ) { int mid = ( ll + ul ) / 2 ; if ( s [ mid ] == t [ i ] ) { int mid = ( ll + ul ) / 2 ; flag = true ; break ; } else if ( s [ mid ] < t [ i ] ) { ll = mid ; } else { ul = mid ; } } if ( flag ) { count ++ ; } } System . out . println ( count ) ; } } +import java . util . * ; import java . io . * ; public class Main { static StringTokenizer st ; static BufferedReader br ; static PrintWriter out ; public static void main ( String [ ] args ) throws IOException { br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int K = nextInt ( ) ; int N = nextInt ( ) ; int [ ] input = new int [ N ] ; for ( int x = 0 ; x < N ; x ++ ) { input [ x ] = nextInt ( ) ; } Arrays . sort ( input ) ; int max = Integer . MIN_VALUE ; for ( int x = 1 ; x < N ; x ++ ) { int tmp = input [ x ] - input [ x - 1 ] ; max = Math . max ( tmp , max ) ; } max = Math . max ( K - input [ N - 1 ] + input [ 0 ] , max ) ; System . out . println ( K - max ) ; } public static int nextInt ( ) throws IOException { return Integer . parseInt ( next ( ) ) ; } public static long nextLong ( ) throws IOException { return Long . parseLong ( next ( ) ) ; } public static double nextDouble ( ) throws IOException { return Double . parseDouble ( next ( ) ) ; } static String next ( ) throws IOException { int x = 1 ; while ( st == null || ! st . hasMoreTokens ( ) ) st = new StringTokenizer ( br . readLine ( ) . trim ( ) ) ; return st . nextToken ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; sc . close ( ) ; if ( s . charAt ( 0 ) != 'A' ) { System . out . println ( " WA " ) ; return ; } int count = 0 ; for ( int i = 2 ; i < s . length ( ) - 1 ; i ++ ) { if ( s . charAt ( i ) == 'C' ) { int i = 1 ; count ++ ; } } if ( count != 1 ) { System . out . println ( " WA " ) ; return ; } for ( int i = 1 ; i < s . length ( ) ; i ++ ) { if ( Character . isUpperCase ( s . charAt ( i ) ) && s . charAt ( i ) != 'C' ) { System . out . println ( " WA " ) ; return ; } } System . out . println ( " AC " ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int L = sc . nextInt ( ) ; int min = 300 , total = 0 ; for ( int i = 1 ; i <= N ; i ++ ) { total += L + i - 1 ; } if ( L >= 0 ) { System . out . println ( total - L ) ; } else if ( L < 0 ) { if ( L + N > 0 ) { int i = 1 ; System . out . println ( total ) ; } else { System . out . println ( total - ( L + N - 1 ) ) ; } } } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws NumberFormatException , IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int n = Integer . parseInt ( br . readLine ( ) ) ; StringBuilder sb = new StringBuilder ( ) ; String [ ] s ; int a , b , c ; for ( int i = 0 ; i < n ; ++ i ) { int a , b , c ; s = br . readLine ( ) . split ( " " ) ; a = Integer . parseInt ( s [ 0 ] ) ; b = Integer . parseInt ( s [ 1 ] ) ; c = Integer . parseInt ( s [ 2 ] ) ; if ( a * a == b * b + c * c || b * b == c * c + a * a || c * c == a * a + b * b ) { sb . append ( " YES \n " ) ; } else { sb . append ( " NO \n " ) ; } } System . out . print ( sb ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int min = 1000000000 ; int max = - 1000000000 ; for ( int i = 0 ; i < n ; i ++ ) { int r = sc . nextInt ( ) ; if ( i == 0 ) { min = r ; } else { int r = sc . nextInt ( ) ; max = Math . max ( max , r - min ) ; min = Math . min ( min , r ) ; } } System . out . println ( max ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int day = 0 ; Scanner scan = new Scanner ( System . in ) ; int N = scan . nextInt ( ) ; int M = scan . nextInt ( ) ; int day = 0 ; for ( int i = 0 ; i < M ; i ++ ) { day += scan . nextInt ( ) ; } if ( day > N ) { System . out . println ( - 1 ) ; } else { System . out . println ( N - day ) ; } } } +import java . io . BufferedReader ; import java . io . InputStreamReader ; public class Main { static int height = 0 ; static int weight = 0 ; public static void main ( String [ ] args ) throws Exception { boolean zeroFlag = true ; BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String line = br . readLine ( ) ; while ( zeroFlag ) { String [ ] nyuryokuStr = line . split ( " [ \\ s]+ " ) ; height = Integer . parseInt ( nyuryokuStr [ 0 ] ) ; weight = Integer . parseInt ( nyuryokuStr [ 1 ] ) ; if ( height == 0 && weight == 0 ) { zeroFlag = false ; } else { for ( int h = 0 ; h < height ; h ++ ) { for ( int w = 0 ; w < weight ; w ++ ) { String line = br . readLine ( ) ; System . out . print ( " # " ) ; } System . out . println ( ) ; } System . out . println ( ) ; } line = br . readLine ( ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner stdIn = new Scanner ( System . in ) ; int n = stdIn . nextInt ( ) ; int [ ] a = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = stdIn . nextInt ( ) ; } long ans = 0 ; for ( int i = 1 ; i < n ; i ++ ) { if ( a [ i - 1 ] > a [ i ] ) { int i = 1 ; ans += a [ i - 1 ] - a [ i ] ; a [ i ] = a [ i - 1 ] ; } } System . out . println ( ans ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { int t = s . nextInt ( ) ; Scanner s = new Scanner ( System . in ) ; long ans , max ; int i , j , a [ ] [ ] ; int t = s . nextInt ( ) ; a = new int [ t ] [ 2 ] ; for ( j = 0 ; j < 2 ; j ++ ) { for ( i = 0 ; i < t ; i ++ ) a [ i ] [ j ] = s . nextInt ( ) ; } ans = a [ 0 ] [ 0 ] ; for ( i = 0 ; i < t ; i ++ ) ans = ans + a [ i ] [ 1 ] ; max = ans ; for ( i = 1 ; i < t ; i ++ ) { ans = ans - a [ i - 1 ] [ 1 ] + a [ i ] [ 0 ] ; if ( ans > max ) max = ans ; } System . out . println ( max ) ; } } +import java . util . ArrayList ; import java . util . Arrays ; import java . util . HashSet ; import java . util . List ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; List < String > list = new ArrayList < String > ( ) ; for ( int i = 0 ; n > i ; i ++ ) { String s = sc . next ( ) ; list . add ( s ) ; } List < String > listB = new ArrayList < String > ( new HashSet < > ( list ) ) ; if ( listB . size ( ) != list . size ( ) ) { String s = list . get ( i ) ; System . out . println ( " No " ) ; System . exit ( 0 ) ; } for ( int i = 0 ; list . size ( ) - 1 > i ; i ++ ) { String s = list . get ( i ) ; String t = list . get ( i + 1 ) ; List < String > list_s = new ArrayList < String > ( Arrays . asList ( s . split ( " " ) ) ) ; List < String > list_t = new ArrayList < String > ( Arrays . asList ( t . split ( " " ) ) ) ; s = list_s . get ( list_s . size ( ) - 1 ) ; t = list_t . get ( 0 ) ; if ( ! s . equals ( t ) ) { System . out . println ( " No " ) ; System . exit ( 0 ) ; } } System . out . println ( " Yes " ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int K = scanner . nextInt ( ) ; String S = scanner . next ( ) ; String [ ] S1 = S . split ( " " ) ; if ( K >= S1 . length ) { int j = 0 ; for ( int j = 0 ; j < S1 . length ; j ++ ) { System . out . print ( S1 [ j ] ) ; } } else { for ( int j = 0 ; j < K ; j ++ ) { System . out . print ( S1 [ j ] ) ; } System . out . println ( " ... " ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner scanner = new Scanner ( System . in ) ; long N = scanner . nextLong ( ) ; scanner . nextLine ( ) ; String S = scanner . nextLine ( ) ; long ans = 0 ; char prev = ',' ; for ( int i = 0 ; i < S . length ( ) ; i ++ ) { char cur = S . charAt ( i ) ; if ( prev != cur ) ans ++ ; prev = cur ; } System . out . println ( ans ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int [ ] H = new int [ N ] ; int [ ] Hmax = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { H [ i ] = sc . nextInt ( ) ; if ( i >= 1 ) { int i = 0 ; Hmax [ i ] = Math . max ( H [ i ] , Hmax [ i - 1 ] ) ; } else { Hmax [ i ] = H [ i ] ; } } int sum = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( H [ i ] >= Hmax [ i ] ) { sum ++ ; } } System . out . println ( sum ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] h = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { h [ i ] = sc . nextInt ( ) ; } for ( int i = 0 ; i < ( n - 1 ) ; i ++ ) { if ( ( h [ i + 1 ] - h [ i ] ) < 0 ) { int i = 0 ; System . out . println ( " No " ) ; return ; } else if ( h [ i + 1 ] > h [ i ] ) { h [ i + 1 ] -- ; } } System . out . println ( " Yes " ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int [ ] v = new int [ 3 ] ; Scanner sc = new Scanner ( System . in ) ; int [ ] v = new int [ 3 ] ; v [ 0 ] = Integer . parseInt ( sc . next ( ) ) ; v [ 1 ] = Integer . parseInt ( sc . next ( ) ) ; v [ 2 ] = Integer . parseInt ( sc . next ( ) ) ; int K = Integer . parseInt ( sc . next ( ) ) ; Arrays . sort ( v ) ; for ( int i = 0 ; i < K ; i ++ ) { v [ 2 ] *= 2 ; } System . out . println ( v [ 0 ] + v [ 1 ] + v [ 2 ] ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int [ ] array = new int [ N ] ; int sum = 0 ; for ( int i = 0 ; i < N ; i ++ ) { array [ i ] = sc . nextInt ( ) ; sum += array [ i ] ; } int sum2 = 0 ; int dif = 0 ; int min = 10000 ; for ( int i = 0 ; i < N ; i ++ ) { int i = 0 ; sum -= array [ i ] ; sum2 += array [ i ] ; dif = Math . abs ( sum - sum2 ) ; if ( min > dif ) { min = dif ; } } System . out . println ( min ) ; } } +import java . io . * ; class Main { public static void main ( String [ ] arg ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String keyword = br . readLine ( ) ; int cnt = 0 ; String str ; while ( ( str = br . readLine ( ) ) != null ) { int i = 0 ; if ( str . equals ( " END_OF_TEXT " ) ) { break ; } String [ ] w = str . split ( " " ) ; for ( int i = 0 ; i < w . length ; i ++ ) { if ( w [ i ] . equalsIgnoreCase ( keyword ) ) { cnt ++ ; } } } System . out . println ( cnt ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { String result = " No " ; @ SuppressWarnings ( " resource " ) Scanner stdin = new Scanner ( System . in ) ; int [ ] [ ] c = new int [ 3 ] [ ] ; for ( int i = 0 ; i < 3 ; i ++ ) { c [ i ] = new int [ 3 ] ; for ( int j = 0 ; j < 3 ; j ++ ) { c [ i ] [ j ] = stdin . nextInt ( ) ; } } String result = " No " ; int a2 = c [ 1 ] [ 0 ] - c [ 0 ] [ 0 ] ; int a3 = c [ 2 ] [ 0 ] - c [ 0 ] [ 0 ] ; if ( ( c [ 1 ] [ 1 ] == ( a2 + c [ 0 ] [ 1 ] ) ) && ( c [ 1 ] [ 2 ] == ( a2 + c [ 0 ] [ 2 ] ) ) && ( c [ 2 ] [ 1 ] == ( a3 + c [ 0 ] [ 1 ] ) ) && ( c [ 2 ] [ 2 ] == ( a3 + c [ 0 ] [ 2 ] ) ) ) { result = " Yes " ; } System . out . println ( result ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner scanner = new Scanner ( System . in ) ; Integer x = scanner . nextInt ( ) ; Integer y = scanner . nextInt ( ) ; String ans = " No " ; for ( int i = 0 ; i < x + 1 ; i ++ ) { Integer sum = 2 * i + 4 * ( x - i ) ; if ( sum == y ) ans = " Yes " ; } System . out . println ( ans ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int m = sc . nextInt ( ) ; int l = sc . nextInt ( ) ; int [ ] [ ] nm = new int [ n ] [ m ] ; int [ ] [ ] ml = new int [ m ] [ l ] ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < m ; j ++ ) { nm [ i ] [ j ] = sc . nextInt ( ) ; } } for ( int i = 0 ; i < m ; i ++ ) { for ( int j = 0 ; j < l ; j ++ ) { ml [ i ] [ j ] = sc . nextInt ( ) ; } } long ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < l ; j ++ ) { int k = 0 ; ans = 0 ; for ( int k = 0 ; k < m ; k ++ ) { ans += nm [ i ] [ k ] * ml [ k ] [ j ] ; } if ( j != l - 1 ) { System . out . print ( ans + " " ) ; } else { System . out . print ( ans ) ; } } System . out . println ( ) ; } } } +import java . util . * ; import static java . lang . Math . * ; import java . math . BigInteger ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String n = sc . next ( ) ; for ( int i = 0 ; i < n . length ( ) ; i ++ ) { int i = 0 ; if ( n . charAt ( i ) == '1' ) System . out . print ( 9 ) ; if ( n . charAt ( i ) == '9' ) System . out . print ( 1 ) ; } } } +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 ans = new Main ( ) . gcd ( Math . max ( a , b ) , Math . min ( a , b ) ) ; System . out . println ( ans ) ; } public int gcd ( int b , int l ) { int b = sc . nextInt ( ) ; if ( l == 0 ) return b ; if ( l == 1 ) return l ; return gcd ( l , b % l ) ; } } +import java . io . * ; import java . util . StringTokenizer ; class Main { public static void main ( String [ ] args ) { long m = Integer . parseInt ( st . nextToken ( ) ) ; InputStreamReader isr = new InputStreamReader ( System . in ) ; BufferedReader br = new BufferedReader ( isr ) ; String buf ; try { while ( ( buf = br . readLine ( ) ) != null ) { StringTokenizer st = new StringTokenizer ( buf ) ; long n = Integer . parseInt ( st . nextToken ( ) ) ; long m = Integer . parseInt ( st . nextToken ( ) ) ; long gcd ; long lcm = n * m ; while ( n % m != 0 ) { long t = m ; m = n % m ; n = t ; } gcd = m ; lcm = lcm / gcd ; System . out . println ( gcd + " " + lcm ) ; } } catch ( Exception e ) { System . out . println ( " Exception! " ) ; } } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String str = br . readLine ( ) ; char chr ; StringBuilder build = new StringBuilder ( ) ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { chr = str . charAt ( i ) ; if ( Character . isLowerCase ( chr ) ) { build . append ( Character . toUpperCase ( chr ) ) ; } else { int i = 0 ; build . append ( Character . toLowerCase ( chr ) ) ; } } System . out . print ( build . toString ( ) + " \n " ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { int i = 1 ; Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; long A = ( long ) ( Math . pow ( 10 , 18 ) ) ; long [ ] B = new long [ N ] ; boolean chk_0 = false ; for ( int i = 0 ; i < N ; i ++ ) { B [ i ] = sc . nextLong ( ) ; if ( B [ i ] == 0 ) { chk_0 = true ; } } long C = 0L ; boolean chk = true ; if ( ! chk_0 ) { C = B [ 0 ] ; for ( int i = 1 ; i < B . length ; i ++ ) { try { C = Math . multiplyExact ( C , B [ i ] ) ; } catch ( ArithmeticException e ) { chk = false ; break ; } } } if ( ! chk || A < C ) { System . out . println ( - 1 ) ; } else { System . out . println ( C ) ; } } } +import java . util . Collections ; import java . util . LinkedList ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; LinkedList < Integer > inputs = new LinkedList < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { inputs . add ( sc . nextInt ( ) ) ; } Collections . sort ( inputs ) ; double beforeParam = inputs . pop ( ) ; for ( int i = 0 ; i < n - 1 ; i ++ ) { double beforeParam = inputs . pop ( ) ; beforeParam = ( beforeParam + inputs . pop ( ) ) / 2 ; } System . out . println ( beforeParam ) ; } } +import java . util . Scanner ; import java . util . Arrays ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner in = new Scanner ( System . in ) ; while ( in . hasNext ( ) ) { int N = in . nextInt ( ) ; int [ ] d = new int [ N ] ; for ( int i = 0 ; i < d . length ; ++ i ) { d [ i ] = in . nextInt ( ) ; } Arrays . sort ( d ) ; int mid1 = d [ N / 2 - 1 ] ; int mid2 = d [ N / 2 ] ; System . out . println ( mid2 - mid1 ) ; } } } +import java . util . ArrayDeque ; import java . util . ArrayList ; import java . util . Arrays ; import java . util . Comparator ; import java . util . Deque ; import java . util . HashMap ; import java . util . HashSet ; import java . util . List ; import java . util . Map ; import java . util . Queue ; import java . util . Scanner ; import java . util . Set ; public class Main { public static void main ( String [ ] args ) { execute16_4 ( ) ; } private static void execute16_4 ( ) { try ( Scanner sc = new Scanner ( System . in ) ) { Scanner sc = new Scanner ( System . in ) ; int s = sc . nextInt ( ) ; System . out . println ( s + s * s + s * s * s ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int k = sc . nextInt ( ) ; int res = 0 ; ArrayList < Integer > list = new ArrayList < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { list . add ( sc . nextInt ( ) ) ; } list . sort ( Comparator . naturalOrder ( ) ) ; for ( int i = 0 ; i < k ; i ++ ) { res += list . get ( i ) ; } System . out . println ( res ) ; sc . close ( ) ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { int i = 0 ; int x = 0 ; Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; String S = sc . next ( ) ; for ( int i = 0 ; i < ( N - 2 ) ; i ++ ) { if ( S . charAt ( i ) == 'A' && S . charAt ( i + 1 ) == 'B' ) { if ( S . charAt ( i + 2 ) == 'C' ) { x += 1 ; } } } System . out . println ( x ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int i = 2 ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] h = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { h [ i ] = sc . nextInt ( ) ; } sc . close ( ) ; int [ ] q = new int [ n ] ; Arrays . fill ( q , 0 ) ; q [ 1 ] = Math . abs ( h [ 1 ] - h [ 0 ] ) ; for ( int i = 2 ; i < n ; i ++ ) { q [ i ] = Math . min ( q [ i - 1 ] + Math . abs ( h [ i - 1 ] - h [ i ] ) , q [ i - 2 ] + Math . abs ( h [ i - 2 ] - Math . abs ( h [ i ] ) ) ) ; } System . out . println ( q [ n - 1 ] ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { try ( Scanner sc = new Scanner ( System . in ) ) { int result = 0 ; int d = sc . nextInt ( ) ; int n = sc . nextInt ( ) ; int result = 0 ; switch ( d ) { case 0 : if ( n == 100 ) { result = 101 ; } else { result = n ; } break ; case 1 : if ( n == 100 ) { result = 10100 ; } else { result = 100 * n ; } break ; case 2 : if ( n == 100 ) { result = 1010000 ; } else { result = 10000 * n ; } break ; } System . out . println ( result ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int M = sc . nextInt ( ) ; int C = sc . nextInt ( ) ; int [ ] A = new int [ M ] ; int cnt = 0 ; int [ ] B = new int [ M ] ; for ( int i = 0 ; i < M ; i ++ ) { B [ i ] = sc . nextInt ( ) ; } for ( int i = 0 ; i < N ; i ++ ) { int det = 0 ; for ( int j = 0 ; j < M ; j ++ ) { int j = 0 ; det += B [ j ] * sc . nextInt ( ) ; } det += C ; if ( det > 0 ) { cnt ++ ; } } System . out . println ( cnt ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int A = scanner . nextInt ( ) ; int B = scanner . nextInt ( ) ; int total = 0 ; for ( int i = A ; i <= B ; i ++ ) { String s = String . valueOf ( i ) ; StringBuffer sb = new StringBuffer ( s ) ; String r = new String ( sb . reverse ( ) ) ; if ( s . equals ( r ) ) { int i = A ; total ++ ; } } System . out . println ( total ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int X = sc . nextInt ( ) ; int T = sc . nextInt ( ) ; int n = N / X ; if ( N % X > 0 ) { int n = N / X ; n ++ ; } int result = n * T ; System . out . println ( result ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int X = sc . nextInt ( ) ; int Y = sc . nextInt ( ) ; String S = " " ; if ( 2 * X <= Y && Y <= 4 * X && Y % 2 == 0 ) { String S = " " ; S = " Yes " ; } else { S = " No " ; } System . out . println ( S ) ; } } +import java . math . BigDecimal ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long N = sc . nextLong ( ) ; BigDecimal ans = new BigDecimal ( 1 ) ; BigDecimal over = new BigDecimal ( 1000000000000000000L ) ; boolean ov = false ; boolean ze = false ; for ( int i = 0 ; i < N ; i ++ ) { long Ai = sc . nextLong ( ) ; if ( ! ze ) { if ( Ai == 0 ) { ze = true ; } if ( ! ov ) { BigDecimal bd = new BigDecimal ( Ai ) ; ans = ans . multiply ( bd ) ; int ju = ans . compareTo ( over ) ; if ( ju == 1 ) { long Ai = sc . nextLong ( ) ; ov = true ; } } } } if ( ze ) { System . out . println ( 0 ) ; } else if ( ov ) { System . out . println ( - 1 ) ; } else { System . out . println ( ans ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Main main = new Main ( ) ; main . solveB ( ) ; } private void solveA ( ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; int top = 0 ; for ( int i = 0 ; i < 3 ; i ++ ) { if ( s . charAt ( i ) == 'o' ) top += 100 ; } System . out . println ( 700 + top ) ; } private void solveB ( ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int x = sc . nextInt ( ) ; int cnt = 0 ; int [ ] m = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { m [ i ] = sc . nextInt ( ) ; } Arrays . sort ( m ) ; for ( int i = 0 ; i < n ; i ++ ) { x -= m [ i ] ; cnt ++ ; } System . out . println ( cnt + x / m [ 0 ] ) ; } } +import java . io . InputStreamReader ; import java . io . BufferedReader ; import java . io . IOException ; class Main { public static void main ( String [ ] args ) throws IOException { InputStreamReader is = new InputStreamReader ( System . in ) ; BufferedReader bf = new BufferedReader ( is ) ; while ( true ) { String [ ] strAry = bf . readLine ( ) . split ( " " ) ; int h = Integer . parseInt ( strAry [ 0 ] ) ; int w = Integer . parseInt ( strAry [ 1 ] ) ; if ( h == 0 && w == 0 ) { break ; } for ( int i = 1 ; i <= h ; i ++ ) { if ( i % 2 != 0 ) { for ( int j = 1 ; j <= w ; j ++ ) { int k = 1 ; if ( j % 2 != 0 ) System . out . print ( " # " ) ; else if ( j % 2 == 0 ) System . out . print ( " . " ) ; } } else if ( i % 2 == 0 ) { for ( int k = 1 ; k <= w ; k ++ ) { if ( k % 2 != 0 ) System . out . print ( " . " ) ; else if ( k % 2 == 0 ) System . out . print ( " # " ) ; } } System . out . println ( ) ; } System . out . println ( ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int t = P + Q ; Scanner scanner = new Scanner ( System . in ) ; int P = scanner . nextInt ( ) ; int Q = scanner . nextInt ( ) ; int R = scanner . nextInt ( ) ; int t = P + Q ; if ( t > R + P ) { t = R + P ; } if ( t > Q + R ) { t = Q + R ; } System . out . println ( t ) ; } } +import java . util . * ; import java . io . * ; import static java . lang . Character . isUpperCase ; public class Main { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int N = in . nextInt ( ) ; int K = in . nextInt ( ) ; int [ ] h = new int [ N ] ; int count = 0 ; for ( int i = 0 ; i < N ; i ++ ) { int i = 0 ; h [ i ] = in . nextInt ( ) ; if ( h [ i ] >= K ) { count ++ ; } } System . out . println ( count ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int n = scan . nextInt ( ) ; long ans = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { int i = 1 ; if ( i % 3 == 0 || i % 5 == 0 ) { continue ; } else { ans = ans + i ; } } System . out . println ( ans ) ; } } +import java . util . Scanner ; public class Main { public static char abc_ans ( String str_a , String str_b , String str_c ) { char [ ] a = str_a . toCharArray ( ) ; char [ ] b = str_b . toCharArray ( ) ; char [ ] c = str_c . toCharArray ( ) ; int a_count = a . length ; int b_count = b . length ; int c_count = c . length ; int a_number = 0 ; int b_number = 0 ; int c_number = 0 ; char x = a [ a_number ] ; while ( true ) { switch ( x ) { case 'a' : if ( a_number >= a . length ) { return ( 'A' ) ; } x = a [ a_number ] ; a_number ++ ; break ; case 'b' : if ( b_number >= b . length ) { String str_c = scan . next ( ) ; return ( 'B' ) ; } x = b [ b_number ] ; b_number ++ ; break ; case 'c' : if ( c_number >= c . length ) { return ( 'C' ) ; } x = c [ c_number ] ; c_number ++ ; break ; } } } public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; String str_a = scan . next ( ) ; String str_b = scan . next ( ) ; String str_c = scan . next ( ) ; System . out . println ( abc_ans ( str_a , str_b , str_c ) ) ; } } +import java . util . Scanner ; public class Main { @ SuppressWarnings ( " resource " ) public static void main ( String [ ] args ) { int val = 0 ; Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int val = 0 ; if ( N != 0 ) { val = ( N / 500 ) * 1000 ; val += ( N % 500 ) / 5 * 5 ; } System . out . println ( val ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int [ ] ABC = new int [ 3 ] ; for ( int i = 0 ; i < 3 ; i ++ ) { ABC [ i ] = sc . nextInt ( ) ; } Arrays . sort ( ABC ) ; boolean flg = false ; if ( ABC [ 0 ] == 5 ) { if ( ABC [ 1 ] == 5 ) { if ( ABC [ 2 ] == 7 ) { flg = true ; } } } if ( flg ) { System . out . println ( " YES " ) ; } else { boolean flg = false ; System . out . println ( " NO " ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int k = sc . nextInt ( ) ; int x = sc . nextInt ( ) ; int min = x - k + 1 ; int max = x + k - 1 ; StringBuilder sb = new StringBuilder ( ) ; for ( int i = min ; i <= max ; i ++ ) { if ( i > 1000000 || i < - 1000000 ) { int i = min ; break ; } if ( i == min ) { sb . append ( i ) ; } else { sb . append ( " " + i ) ; } } System . out . println ( sb . toString ( ) ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] monsters = new int [ n + 1 ] ; int [ ] heroes = new int [ n ] ; for ( int i = 0 ; i < n + 1 ; i ++ ) monsters [ i ] = sc . nextInt ( ) ; for ( int i = 0 ; i < n ; i ++ ) heroes [ i ] = sc . nextInt ( ) ; int rem = 0 ; long totalKilled = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int i = 0 ; int killedPrev = Math . min ( rem , monsters [ i ] ) ; int killedNow = Math . min ( monsters [ i ] - killedPrev , heroes [ i ] ) ; totalKilled += killedPrev + killedNow ; rem = Math . max ( heroes [ i ] - killedNow , 0 ) ; } totalKilled += Math . min ( rem , monsters [ n ] ) ; System . out . println ( totalKilled ) ; } } +import java . util . Scanner ; import java . io . PrintWriter ; class Main { static String blackjack ( int a1 , int a2 , int a3 ) { if ( a1 + a2 + a3 <= 21 ) { return " win " ; } return " bust " ; } public static void main ( String [ ] args ) { int a3 = Integer . parseInt ( sc . next ( ) ) ; Scanner sc = new Scanner ( System . in ) ; PrintWriter out = new PrintWriter ( System . out ) ; int a1 = Integer . parseInt ( sc . next ( ) ) ; int a2 = Integer . parseInt ( sc . next ( ) ) ; int a3 = Integer . parseInt ( sc . next ( ) ) ; out . println ( blackjack ( a1 , a2 , a3 ) ) ; out . flush ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int [ ] a = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { a [ i ] = sc . nextInt ( ) ; } int t ; int j = 1 ; for ( int i = 0 ; i < N ; i ++ ) { for ( int k = 0 ; k < N ; k ++ ) { if ( a [ i ] > a [ k ] ) { t = a [ i ] ; a [ i ] = a [ k ] ; a [ k ] = t ; } } } int max = a [ 0 ] ; for ( int i = 0 ; i < N ; i ++ ) { if ( max > a [ i ] ) { j ++ ; max = a [ i ] ; } } System . out . println ( j ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int x = sc . nextInt ( ) ; int [ ] arr = new int [ x ] ; for ( int i = 0 ; i < x ; i ++ ) arr [ i ] = sc . nextInt ( ) ; int [ ] dp = new int [ x ] ; if ( x == 1 ) System . out . println ( arr [ 0 ] ) ; for ( int i = 1 ; i < x ; i ++ ) { int abs1 = Math . abs ( arr [ i ] - arr [ i - 1 ] ) ; if ( i == 1 ) { int abs = abs1 ; dp [ i ] = abs ; } else { int abs1 = Math . abs ( arr [ i ] - arr [ i - 1 ] ) ; dp [ i ] = Math . min ( abs1 + dp [ i - 1 ] , Math . abs ( arr [ i ] - arr [ i - 2 ] ) + dp [ i - 2 ] ) ; } } System . out . println ( dp [ x - 1 ] ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] d = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { d [ i ] = sc . nextInt ( ) ; } Arrays . sort ( d ) ; int count = 0 ; for ( int i = 1 ; i < n ; i ++ ) { int i = 1 ; if ( d [ i ] == d [ i - 1 ] ) count ++ ; } System . out . println ( n - count ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int N = scan . nextInt ( ) ; int alpha = 0 ; int sum = 0 ; for ( int i = 1 ; i <= N ; i ++ ) { for ( int j = 1 ; j <= N ; j ++ ) { for ( int k = 1 ; k <= N ; k ++ ) { alpha = gcd ( i , j ) ; sum += gcd ( alpha , k ) ; } } } System . out . println ( sum ) ; } public static int fac ( int N ) { if ( N == 1 ) { return 1 ; } else { return fac ( N - 1 ) * N ; } } public static int pow ( int N ) { return N * N * N ; } public static int gcd ( int a , int b ) { int c = a % b ; if ( c == 0 ) { return b ; } else { int c = a % b ; return gcd ( b , c ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String S = sc . nextLine ( ) ; sc . close ( ) ; int length = S . length ( ) ; boolean flag = true ; for ( int i = 1 ; i <= length ; i ++ ) { String firstS = S . substring ( 0 , 1 ) ; int index = i % 2 ; String firstS = S . substring ( 0 , 1 ) ; if ( index == 1 ) { if ( firstS . equals ( " L " ) ) { flag = false ; break ; } } else if ( index == 0 ) { if ( firstS . equals ( " R " ) ) { flag = false ; break ; } } S = S . substring ( 1 ) ; } if ( flag ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { double debt = 100000 ; Scanner scan = new Scanner ( System . in ) ; int week = scan . nextInt ( ) ; double debt = 100000 ; for ( int i = 0 ; i < week ; i ++ ) { debt = debt * 1.05 / 1000 ; debt = Math . ceil ( debt ) ; debt = debt * 1000 ; } int ans = ( int ) debt ; System . out . println ( ans ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int x = sc . nextInt ( ) ; int y = sc . nextInt ( ) ; int [ ] [ ] table = new int [ x + 1 ] [ y + 1 ] ; for ( int i = 0 ; i < x ; i ++ ) { for ( int j = 0 ; j < y ; j ++ ) { table [ i ] [ j ] = sc . nextInt ( ) ; table [ i ] [ y ] += table [ i ] [ j ] ; table [ x ] [ j ] += table [ i ] [ j ] ; table [ x ] [ y ] += table [ i ] [ j ] ; } } for ( int i = 0 ; i < x + 1 ; i ++ ) { for ( int j = 0 ; j < y + 1 ; j ++ ) { System . out . print ( table [ i ] [ j ] ) ; if ( j != y ) { int j = 0 ; System . out . print ( " " ) ; } } System . out . println ( ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int [ ] res = new int [ N ] ; for ( int i = 0 ; i < res . length - 1 ; i ++ ) { int index = sc . nextInt ( ) - 1 ; res [ index ] ++ ; } for ( int i : res ) { int i ; System . out . println ( i ) ; } sc . close ( ) ; } } +import java . util . HashSet ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; HashSet < Long > hs = new HashSet < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { hs . add ( sc . nextLong ( ) ) ; } String ans = hs . size ( ) == n ? " YES " : " NO " ; out ( ans ) ; } static long gcd ( long a , long b ) { return ( b == 0 ) ? a : gcd ( b , a % b ) ; } static int gcd ( int a , int b ) { return ( b == 0 ) ? a : gcd ( b , a % b ) ; } static void out ( String info ) { HashSet < Long > hs = new HashSet < > ( ) ; System . out . println ( info ) ; } static void out ( int info ) { System . out . println ( info ) ; } static void out ( double info ) { System . out . println ( info ) ; } static void out ( long info ) { System . out . println ( info ) ; } } +import java . util . ArrayList ; import java . util . Collections ; import java . util . List ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { List < Integer > A = new ArrayList < Integer > ( ) ; Scanner sc = new Scanner ( System . in ) ; List < Integer > A = new ArrayList < Integer > ( ) ; for ( int i = 0 ; i < 3 ; i ++ ) { A . add ( Integer . parseInt ( sc . next ( ) ) ) ; } Collections . sort ( A ) ; System . out . println ( A . get ( 2 ) - A . get ( 0 ) ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int count = 0 ; int maxCount = 0 ; int N = in . nextInt ( ) ; int actual = in . nextInt ( ) ; for ( int i = 1 ; i < N ; i ++ ) { int siguiente = in . nextInt ( ) ; if ( actual >= siguiente ) { count ++ ; } else { if ( maxCount < count ) { maxCount = count ; } count = 0 ; } actual = siguiente ; } if ( maxCount < count ) { int actual = in . nextInt ( ) ; maxCount = count ; } System . out . println ( maxCount ) ; } } +import java . util . Scanner ; public class Main { public static int cost ( int a , int b , int c ) { int cost = 0 ; cost = cost + Math . abs ( b - a ) + Math . abs ( c - b ) ; return ( cost ) ; } public static void main ( String [ ] args ) { int i = 0 ; int A = 0 ; int B = 0 ; int C = 0 ; Scanner in = new Scanner ( System . in ) ; A = Integer . parseInt ( in . next ( ) ) ; B = Integer . parseInt ( in . next ( ) ) ; C = Integer . parseInt ( in . next ( ) ) ; in . close ( ) ; int [ ] costSum = new int [ 6 ] ; costSum [ 0 ] = cost ( A , B , C ) ; costSum [ 1 ] = cost ( A , C , B ) ; costSum [ 2 ] = cost ( B , A , C ) ; costSum [ 3 ] = cost ( B , C , A ) ; costSum [ 4 ] = cost ( C , A , B ) ; costSum [ 5 ] = cost ( C , B , A ) ; int min = costSum [ 0 ] ; for ( int i = 0 ; i < costSum . length ; i ++ ) { if ( min > costSum [ i ] ) { min = costSum [ i ] ; } } System . out . println ( min ) ; } } +import java . util . * ; class Main { public static void main ( String [ ] $ ) { Scanner s = new Scanner ( System . in ) ; int n = s . nextInt ( ) ; String a = s . next ( ) , b = s . next ( ) ; char [ ] c = new char [ n * 2 ] ; for ( int i = 0 ; i < n ; ++ i ) { int i = 0 ; c [ i * 2 ] = a . charAt ( i ) ; c [ i * 2 + 1 ] = b . charAt ( i ) ; } System . out . println ( c ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 1 ; Scanner sc = new Scanner ( System . in ) ; long n = sc . nextLong ( ) ; int ans = ( int ) Math . log10 ( n ) + 1 ; for ( int i = 1 ; i <= Math . sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) ans = ( int ) Math . min ( ans , Math . log10 ( n / i ) + 1 ) ; } System . out . println ( ans ) ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; String [ ] ab = scanner . nextLine ( ) . split ( " " , 2 ) ; int a = Integer . parseInt ( ab [ 0 ] ) ; int b = Integer . parseInt ( ab [ 1 ] ) ; String s = scanner . nextLine ( ) ; if ( a + b + 1 != s . length ( ) ) { System . out . println ( " No " ) ; return ; } for ( int i = 0 ; i <= a + b ; i ++ ) { char ch = s . charAt ( i ) ; if ( i == a ) { char ch = s . charAt ( i ) ; if ( ch != '-' ) { System . out . println ( " No " ) ; return ; } } else { if ( ! ( '0' <= ch && ch <= '9' ) ) { System . out . println ( " No " ) ; return ; } } } System . out . println ( " Yes " ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; class Main { public static void main ( String [ ] args ) throws IOException { int r = x % y ; BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String [ ] string = br . readLine ( ) . split ( " " ) ; int x = Integer . parseInt ( string [ 0 ] ) ; int y = Integer . parseInt ( string [ 1 ] ) ; int tmp ; if ( x < y ) { tmp = x ; x = y ; y = tmp ; } int r = x % y ; while ( r != 0 ) { x = y ; y = r ; r = x % y ; } System . out . println ( y ) ; } } +import java . io . BufferedReader ; import java . io . InputStreamReader ; public class Main { private final static String SPACE = " " ; public static void main ( String [ ] args ) { try { BufferedReader stdReader = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String sStr ; while ( ( sStr = stdReader . readLine ( ) ) != null ) { String [ ] inputs = sStr . split ( " " ) ; int a = Integer . valueOf ( inputs [ 0 ] ) ; int b = Integer . valueOf ( inputs [ 1 ] ) ; int c = Integer . valueOf ( inputs [ 2 ] ) ; int count = 0 ; if ( b < c ) { for ( int x = a ; x <= b ; x ++ ) { if ( c % x == 0 ) { count ++ ; } } } else { for ( int x = a ; x <= c ; x ++ ) { if ( c % x == 0 ) { count ++ ; } } } System . out . println ( count ) ; } stdReader . close ( ) ; } catch ( Exception e ) { int x = a ; System . exit ( - 1 ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner scan = new Scanner ( System . in ) ; String s = scan . next ( ) ; int n = s . length ( ) ; int sum1 = 0 ; int sum2 = 0 ; sum1 = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( s . charAt ( i ) == '0' ) { if ( i % 2 == 1 ) { sum1 += 1 ; } } else { if ( i % 2 == 0 ) { sum1 += 1 ; } } } sum2 = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( s . charAt ( i ) == '0' ) { if ( i % 2 == 0 ) { sum2 += 1 ; } } else { if ( i % 2 == 1 ) { sum2 += 1 ; } } } System . out . println ( Math . min ( sum1 , sum2 ) ) ; } } +import java . util . HashMap ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws Exception { int i = 1 ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; HashMap < Integer , Integer > map = new HashMap < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { map . put ( sc . nextInt ( ) , i + 1 ) ; } for ( int i = 1 ; i <= n ; i ++ ) { if ( i != 1 ) { System . out . print ( " " ) ; } System . out . print ( map . get ( i ) ) ; } sc . close ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; long num = 0 ; long answer = 0 ; double limit = 0.0 ; num = scan . nextLong ( ) ; answer = num ; limit = Math . sqrt ( num ) ; for ( int i = 1 ; i <= limit ; i ++ ) { if ( num % i == 0 && ( num / i ) + i - 2 < answer ) { int i = 1 ; answer = ( num / i ) + i - 2 ; } } System . out . println ( answer ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc1 = new Scanner ( System . in ) ; int a = sc1 . nextInt ( ) ; int b = sc1 . nextInt ( ) ; int max = a + b ; if ( max < a - b ) { max = a - b ; } if ( max < a * b ) { int max = a + b ; max = a * b ; } System . out . print ( max ) ; } } +import java . io . FileNotFoundException ; import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws FileNotFoundException { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int K = sc . nextInt ( ) ; int Q = sc . nextInt ( ) ; int [ ] p = new int [ N + 1 ] ; Arrays . fill ( p , K ) ; int border = 0 ; for ( int i = 0 ; i < Q ; i ++ ) { int i = 1 ; int x = sc . nextInt ( ) ; p [ x ] ++ ; border ++ ; } for ( int i = 1 ; i <= N ; i ++ ) { if ( p [ i ] > border ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; ArrayList < Integer > list = new ArrayList < > ( ) ; int count = 1 ; int ans = 0 ; for ( int i = 0 ; i < N ; i ++ ) { int tmp = sc . nextInt ( ) ; if ( tmp == count ) { ans ++ ; count ++ ; } list . add ( tmp ) ; } if ( ans == 0 ) { System . out . println ( " -1 " ) ; } else { int ans = 0 ; System . out . println ( N - ans ) ; } } } +import java . util . ArrayList ; import java . util . Arrays ; import java . util . List ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; String [ ] array = new String [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { array [ i ] = sc . next ( ) ; } Arrays . sort ( array ) ; List < String > answerList = new ArrayList < String > ( ) ; int count = 1 ; int maxCount = 1 ; for ( int i = 1 ; i < n ; i ++ ) { if ( array [ i - 1 ] . equals ( array [ i ] ) ) { count ++ ; } else { if ( count > maxCount ) { String answer ; answerList . clear ( ) ; answerList . add ( array [ i - 1 ] ) ; maxCount = count ; count = 1 ; } else if ( count == maxCount ) { answerList . add ( array [ i - 1 ] ) ; count = 1 ; } else { count = 1 ; } } if ( i == n - 1 ) { if ( count > maxCount ) { answerList . clear ( ) ; answerList . add ( array [ i ] ) ; } else if ( count == maxCount ) { answerList . add ( array [ i ] ) ; } } } for ( String answer : answerList ) { System . out . println ( answer ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int k = sc . nextInt ( ) ; long p = 1 ; int r = 0 ; while ( p <= n ) { int r = 0 ; p *= k ; r ++ ; } System . out . println ( r ) ; } } +import java . util . ArrayList ; import java . util . Collections ; import java . util . List ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int n = in . nextInt ( ) ; int m = in . nextInt ( ) ; int c = in . nextInt ( ) ; int [ ] b = new int [ m ] ; int ret = 0 ; for ( int i = 0 ; i < m ; i ++ ) { b [ i ] = in . nextInt ( ) ; } for ( int j = 0 ; j < n ; j ++ ) { int sum = 0 ; for ( int i = 0 ; i < m ; i ++ ) { int i = 0 ; int a = in . nextInt ( ) ; sum += a * b [ i ] ; } if ( sum + c > 0 ) { ret ++ ; } } System . out . println ( ret ) ; } } +import java . io . OutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . PrintWriter ; import java . util . StringTokenizer ; import java . io . IOException ; import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . io . InputStream ; public class Main { public static void main ( String [ ] args ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; MyScanner in = new MyScanner ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; A solver = new A ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class A { public void solve ( int testNumber , MyScanner in , PrintWriter out ) { int N = in . Int ( ) ; out . println ( ( 1000 - ( N % 1000 ) ) % 1000 ) ; } } static class MyScanner { private BufferedReader in ; private StringTokenizer st ; public MyScanner ( InputStream stream ) { in = new BufferedReader ( new InputStreamReader ( stream ) ) ; } public String next ( ) { while ( st == null || ! st . hasMoreTokens ( ) ) { try { String rl = in . readLine ( ) ; if ( rl == null ) { return null ; } st = new StringTokenizer ( rl ) ; } catch ( IOException e ) { return null ; } } return st . nextToken ( ) ; } public int Int ( ) { return Integer . parseInt ( next ( ) ) ; } } } +import java . util . Scanner ; class Main { static Scanner sc = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { int n , a , b ; n = sc . nextInt ( ) ; a = sc . nextInt ( ) ; b = sc . nextInt ( ) ; int sum = 0 , ans = 0 ; for ( int i = 0 ; i <= n ; i ++ ) { String x = Integer . toString ( i ) ; sum = 0 ; for ( int j = 0 ; j < x . length ( ) ; j ++ ) { sum += x . charAt ( j ) - '0' ; } if ( a <= sum && sum <= b ) { int j = 0 ; ans += i ; } } System . out . println ( ans ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner s = new Scanner ( System . in ) ; String str = s . next ( ) ; char [ ] alphabet = new char [ 26 ] ; char c = 'a' ; for ( int i = 0 ; i < 26 ; i ++ ) { alphabet [ i ] = c ++ ; long count = Main . split ( str , alphabet [ i ] ) ; if ( count % 2 != 0 ) { System . out . println ( " No " ) ; return ; } } System . out . println ( " Yes " ) ; } public static int split ( String str , char target ) { int count = 0 ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { int i = 0 ; if ( str . charAt ( i ) == target ) count ++ ; } return count ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { BufferedReader inMsg = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String line = " " ; try { while ( ( line = inMsg . readLine ( ) ) != null ) { String [ ] ab = line . split ( " " ) ; Integer a = 0 ; Integer b = 0 ; Integer sqr = 0 ; Integer liner = 0 ; a = Integer . parseInt ( ab [ 0 ] ) ; b = Integer . parseInt ( ab [ 1 ] ) ; sqr = a * b ; liner = a * 2 + b * 2 ; System . out . println ( sqr + " " + liner ) ; } } catch ( IOException e ) { String line = " " ; e . printStackTrace ( ) ; } } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; class Main { public static final int MAX = 200000 ; public static void main ( String [ ] args ) throws IOException { int i = 1 ; int [ ] Nums = new int [ MAX ] ; BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String n = br . readLine ( ) ; for ( int i = 0 ; i < Integer . parseInt ( n ) ; i ++ ) { Nums [ i ] = Integer . parseInt ( br . readLine ( ) ) ; } int max = - 2000000000 ; int min = Nums [ 0 ] ; for ( int i = 1 ; i < Integer . parseInt ( n ) ; i ++ ) { max = Math . max ( max , Nums [ i ] - min ) ; min = Math . min ( min , Nums [ i ] ) ; } System . out . println ( max ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int y = sc . nextInt ( ) ; int a = - 1 ; int b = - 1 ; int c = - 1 ; for ( int i = 0 ; i <= n ; i ++ ) { int j = 0 ; for ( int j = 0 ; j <= n ; j ++ ) { if ( y / 1000 - 10 * i - 5 * j == n - j - i && n - j - i >= 0 ) { a = i ; b = j ; c = n - i - j ; break ; } } } System . out . println ( a + " " + b + " " + c ) ; } } +import java . io . * ; import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = Integer . parseInt ( sc . next ( ) ) ; int [ ] d = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { d [ i ] = Integer . parseInt ( sc . next ( ) ) ; } int sum = 0 ; for ( int i = 0 ; i < N - 1 ; i ++ ) { for ( int j = i + 1 ; j < N ; j ++ ) { int j = i + 1 ; sum += d [ i ] * d [ j ] ; } } System . out . println ( sum ) ; } } +import java . util . * ; import java . io . * ; class Main { void solve ( ) { char [ ] a = incharar ( ) ; int cost = 0 ; for ( int i = 0 ; i < a . length / 2 ; i ++ ) { if ( a [ i ] != a [ a . length - i - 1 ] ) cost ++ ; } out . println ( cost ) ; } public static Scanner in = new Scanner ( System . in ) ; public static PrintWriter out = new PrintWriter ( System . out ) ; public static void main ( String [ ] args ) { new Main ( ) . solve ( ) ; out . flush ( ) ; } public int inint ( ) { return in . nextInt ( ) ; } public long inlong ( ) { int i = 0 ; return in . nextLong ( ) ; } public String instr ( ) { return in . next ( ) ; } public int [ ] inintar ( int num ) { int [ ] a = new int [ num ] ; for ( int i = 0 ; i < num ; i ++ ) { a [ i ] = in . nextInt ( ) ; } return a ; } public char [ ] incharar ( ) { return in . next ( ) . toCharArray ( ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int n = scan . nextInt ( ) ; int [ ] a = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { int i = 0 ; a [ i ] = scan . nextInt ( ) ; } boolean flag = true ; int swap ; int count = 0 ; int min ; for ( int i = 0 ; i < n ; i ++ ) { min = i ; for ( int j = i ; j < n ; j ++ ) { if ( a [ j ] < a [ min ] ) { min = j ; } } if ( a [ i ] != a [ min ] ) { swap = a [ i ] ; a [ i ] = a [ min ] ; a [ min ] = swap ; count ++ ; } } for ( int i = 0 ; i < n ; i ++ ) { System . out . print ( a [ i ] ) ; if ( i != n - 1 ) System . out . print ( " " ) ; } System . out . println ( ) ; System . out . println ( count ) ; } } +import java . util . * ; import java . io . * ; import static java . lang . Math . * ; public class Main { static PrintWriter out = new PrintWriter ( System . out ) ; public static void main ( String [ ] $ ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) , q = sc . nextInt ( ) ; String s = sc . next ( ) ; int [ ] AC = new int [ n + 1 ] ; for ( int i = 1 ; i < n ; i ++ ) { if ( s . charAt ( i - 1 ) == 'A' && s . charAt ( i ) == 'C' ) { AC [ i ] = 1 ; } } for ( int i = 1 ; i < n + 1 ; i ++ ) { int i = 0 ; AC [ i ] += AC [ i - 1 ] ; } for ( int i = 0 ; i < q ; i ++ ) { int l = sc . nextInt ( ) , r = sc . nextInt ( ) ; int k = 0 ; if ( r < n && s . charAt ( r - 1 ) == 'A' && s . charAt ( r ) == 'C' ) k ++ ; out . println ( max ( 0 , AC [ r ] - AC [ l - 1 ] - k ) ) ; } out . close ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { try ( Scanner in = new Scanner ( System . in ) ) { Scanner in = new Scanner ( System . in ) ; int A = in . nextInt ( ) ; int B = in . nextInt ( ) ; int C = in . nextInt ( ) ; int K = in . nextInt ( ) ; int sum = A + B + C ; int max = Math . max ( A , Math . max ( B , C ) ) ; sum += - max + ( max << K ) ; System . out . println ( sum ) ; } } } +import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int [ ] A = new int [ 3 ] ; for ( int i = 0 ; i < 3 ; i ++ ) { int i = 0 ; A [ i ] = sc . nextInt ( ) ; } Arrays . parallelSort ( A ) ; if ( A [ 0 ] == A [ 1 ] && A [ 1 ] == 5 && A [ 2 ] == 7 ) { System . out . println ( " YES " ) ; } else { System . out . println ( " NO " ) ; } } } +import java . io . * ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int j ; Scanner in = new Scanner ( System . in ) ; int [ ] height = new int [ 10 ] ; int i ; int x ; for ( i = 0 ; i < 10 ; i ++ ) { height [ i ] = in . nextInt ( ) ; } for ( i = 0 ; i < 10 ; i ++ ) { int i ; for ( j = i + 1 ; j < 10 ; j ++ ) if ( height [ i ] > height [ j ] ) { int temp = height [ i ] ; height [ i ] = height [ j ] ; height [ j ] = temp ; } } for ( i = 9 ; i > 6 ; i -- ) { System . out . println ( height [ i ] ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner inp = new Scanner ( System . in ) ; int rows = inp . nextInt ( ) ; int cols = inp . nextInt ( ) ; int [ ] [ ] aMatrix = new int [ rows ] [ cols ] ; int [ ] [ ] bMatrix = new int [ cols ] [ 1 ] ; for ( int k = 0 ; k < rows ; k ++ ) { for ( int j = 0 ; j < cols ; j ++ ) { aMatrix [ k ] [ j ] = inp . nextInt ( ) ; } } for ( int j = 0 ; j < cols ; j ++ ) { int j = 0 ; bMatrix [ j ] [ 0 ] = inp . nextInt ( ) ; } int [ ] [ ] total = matrixCalc ( aMatrix , bMatrix , rows , cols ) ; for ( int [ ] item : total ) { for ( int secondItem : item ) { System . out . println ( secondItem ) ; } } } public static int [ ] [ ] matrixCalc ( int [ ] [ ] aMatrix , int [ ] [ ] bMatrix , int rows , int cols ) { int [ ] [ ] totals = new int [ rows ] [ 1 ] ; for ( int k = 0 ; k < rows ; k ++ ) { int total = 0 ; for ( int j = 0 ; j < cols ; j ++ ) { total += aMatrix [ k ] [ j ] * bMatrix [ j ] [ 0 ] ; } totals [ k ] [ 0 ] = total ; } return totals ; } } +import java . io . * ; import java . util . * ; public class Main { private static Scanner sc ; private static Printer pr ; private static void solve ( ) { int n = sc . nextInt ( ) ; for ( int i = 0 ; 4 * i <= 100 ; i ++ ) { for ( int j = 0 ; 4 * i + 7 * j <= 100 ; j ++ ) { if ( 4 * i + 7 * j == n ) { pr . println ( " Yes " ) ; return ; } } } pr . println ( " No " ) ; } public static void main ( String [ ] args ) { sc = new Scanner ( INPUT == null ? System . in : new ByteArrayInputStream ( INPUT . getBytes ( ) ) ) ; pr = new Printer ( System . out ) ; solve ( ) ; pr . flush ( ) ; } static String INPUT = null ; private static class Printer extends PrintWriter { Printer ( OutputStream out ) { super ( out ) ; } } } +import java . io . BufferedReader ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws Exception { try { long sum = 0 ; int min = 1000000 ; int max = - 1000000 ; BufferedReader buf = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String input1 = buf . readLine ( ) ; int count = Integer . parseInt ( input1 ) ; String input2 = buf . readLine ( ) ; String [ ] strAry = input2 . split ( " " ) ; for ( int i = 0 ; i < count ; i ++ ) { int x = Integer . parseInt ( strAry [ i ] ) ; sum = sum + x ; if ( x < min ) { min = x ; } if ( x > max ) { int x = Integer . parseInt ( strAry [ i ] ) ; max = x ; } } System . out . println ( min + " " + max + " " + sum ) ; } catch ( Exception e ) { System . out . println ( " ???????????? " ) ; } } } +import java . text . * ; import java . util . * ; public class Main { public static void main ( String [ ] args ) { String a = sc . next ( ) ; Scanner sc = new Scanner ( System . in ) ; String a = sc . next ( ) ; try { DateFormat sdf = new SimpleDateFormat ( " yyyy/MM/dd " ) ; Date date1 = sdf . parse ( a ) ; Date date2 = sdf . parse ( " 2019/04/30 " ) ; int diff = date1 . compareTo ( date2 ) ; if ( diff > 0 ) { System . out . println ( " TBD " ) ; } else { System . out . println ( " Heisei " ) ; } } catch ( ParseException e ) { e . printStackTrace ( ) ; } } } +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 ( ) ; sc . close ( ) ; int C = 1 ; int D = 0 ; while ( B > C ) { int D = 0 ; C += A - 1 ; D ++ ; } System . out . println ( D ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int x = sc . nextInt ( ) ; for ( ; ; x ++ ) { if ( isPrime ( x ) ) break ; } System . out . println ( x ) ; } public static boolean isPrime ( int x ) { int i = 3 ; if ( ( x % 2 == 0 && x != 2 || x == 1 ) ) return false ; for ( int i = 3 ; i <= Math . sqrt ( x ) ; i += 2 ) { if ( x % i == 0 ) return false ; } return true ; } } +import java . util . * ; public class Main { Scanner sc = new Scanner ( System . in ) ; final int MOD = ( int ) 1e9 + 7 ; final int MAX = Integer . MAX_VALUE ; final long LMAX = Long . MAX_VALUE ; int len = ( int ) 1e7 ; void doIt ( ) { int N = sc . nextInt ( ) ; Map < String , Integer > map = new HashMap < > ( ) ; map . put ( " AC " , 0 ) ; map . put ( " WA " , 0 ) ; map . put ( " TLE " , 0 ) ; map . put ( " RE " , 0 ) ; for ( int i = 0 ; i < N ; i ++ ) { Map < String , Integer > map = new HashMap < > ( ) ; String S = sc . next ( ) ; map . put ( S , map . get ( S ) + 1 ) ; } System . out . println ( " AC x " + map . get ( " AC " ) ) ; System . out . println ( " WA x " + map . get ( " WA " ) ) ; System . out . println ( " TLE x " + map . get ( " TLE " ) ) ; System . out . println ( " RE x " + map . get ( " RE " ) ) ; } public static void main ( String [ ] args ) { new Main ( ) . doIt ( ) ; } } +import java . util . Scanner ; class Main { static Scanner scan = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { String S = scan . next ( ) ; String T = scan . next ( ) ; int i = 0 ; int j = 0 ; int count = 0 ; while ( i < S . length ( ) && j < T . length ( ) ) { int count = 0 ; if ( S . charAt ( i ) != T . charAt ( j ) ) { count ++ ; } i ++ ; j ++ ; } System . out . println ( count ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int n = scan . nextInt ( ) ; int [ ] a = new int [ n ] ; int max = Integer . MIN_VALUE ; int subMax = Integer . MIN_VALUE ; for ( int i = 0 ; i < n ; i ++ ) { int temp = scan . nextInt ( ) ; a [ i ] = temp ; if ( temp >= max ) { int i = 0 ; subMax = max ; max = temp ; } else if ( temp >= subMax ) { subMax = temp ; } } for ( int i = 0 ; i < n ; i ++ ) { if ( a [ i ] == max ) { System . out . println ( subMax ) ; } else { System . out . println ( max ) ; } } } } +import java . util . ArrayList ; import java . util . List ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; int s = Integer . parseInt ( sc . next ( ) ) ; List < Integer > a = new ArrayList < > ( ) ; a . add ( s ) ; int ans = 0 ; for ( int i = 0 ; i < 1000000 ; i ++ ) { int ai = a . get ( i ) % 2 == 0 ? a . get ( i ) / 2 : 3 * a . get ( i ) + 1 ; if ( a . contains ( ai ) ) { int i = 0 ; ans = i + 2 ; break ; } a . add ( ai ) ; } System . out . println ( ans ) ; sc . close ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Main mainObj = new Main ( ) ; mainObj . solve ( ) ; } public void solve ( ) { Scanner sc = new Scanner ( System . in ) ; int n = Integer . parseInt ( sc . nextLine ( ) ) ; String [ ] heightStrArr = sc . nextLine ( ) . split ( " " ) ; sc . close ( ) ; int [ ] heightArr = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { heightArr [ i ] = Integer . parseInt ( heightStrArr [ i ] ) ; } if ( heightArr [ 0 ] > 0 ) { heightArr [ 0 ] = heightArr [ 0 ] - 1 ; } for ( int i = 1 ; i < n ; i ++ ) { if ( heightArr [ i ] > heightArr [ i - 1 ] ) { int i = 1 ; heightArr [ i ] = heightArr [ i ] - 1 ; } if ( heightArr [ i ] < heightArr [ i - 1 ] ) { System . out . println ( " No " ) ; return ; } } System . out . println ( " Yes " ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { long e = 0 ; Scanner scanner = new Scanner ( System . in ) ; int a = scanner . nextInt ( ) ; int [ ] b = new int [ a ] ; int c = Integer . MAX_VALUE ; int d = Integer . MIN_VALUE ; long e = 0 ; for ( int i = 0 ; i < a ; i ++ ) { int f = scanner . nextInt ( ) ; c = Math . min ( c , f ) ; d = Math . max ( d , f ) ; e += f ; } System . out . println ( String . format ( " %d %d %d " , c , d , e ) ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int [ ] d = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { d [ i ] = sc . nextInt ( ) ; } sc . close ( ) ; Arrays . sort ( d ) ; int [ ] a = new int [ N / 2 ] ; int [ ] b = new int [ N / 2 ] ; for ( int i = 0 ; i < N / 2 ; i ++ ) { a [ i ] = d [ i ] ; } int j = 0 ; for ( int i = N / 2 ; i < N ; i ++ ) { b [ j ] = d [ i ] ; j ++ ; } int count = 0 ; if ( a [ N / 2 - 1 ] < b [ 0 ] ) { int count = 0 ; count = b [ 0 ] - a [ N / 2 - 1 ] ; } System . out . println ( count ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int max_first = 0 ; int max_second = 0 ; int [ ] a = new int [ n ] ; for ( int i = 0 ; i < n ; ++ i ) { a [ i ] = sc . nextInt ( ) ; if ( max_first <= a [ i ] ) { int ii ; max_second = max_first ; max_first = a [ i ] ; } if ( max_first > a [ i ] && max_second <= a [ i ] ) { max_second = a [ i ] ; } } for ( int ii : a ) { if ( ii != max_first ) System . out . println ( max_first ) ; else if ( ii != 0 ) System . out . println ( max_second ) ; } } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . StringTokenizer ; public class Main { int k , s ; public static void main ( String [ ] args ) { new Main ( ) . run ( ) ; } void run ( ) { String str = " " ; FastReader sc = new FastReader ( ) ; k = sc . nextInt ( ) ; s = sc . nextInt ( ) ; solve ( ) ; } void solve ( ) { long count = 0 ; for ( int x = 0 ; x <= k ; x ++ ) { for ( int y = 0 ; y <= k ; y ++ ) { int z = s - x - y ; if ( z >= 0 && z <= k ) { count ++ ; } } } System . out . println ( count ) ; } static class FastReader { BufferedReader br ; StringTokenizer st ; public FastReader ( ) { br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; } String next ( ) { while ( st == null || ! st . hasMoreElements ( ) ) { try { st = new StringTokenizer ( br . readLine ( ) ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } return st . nextToken ( ) ; } int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } long nextLong ( ) { return Long . parseLong ( next ( ) ) ; } double nextDouble ( ) { return Double . parseDouble ( next ( ) ) ; } String nextLine ( ) { String str = " " ; try { str = br . readLine ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } return str ; } } } +import java . util . * ; public class Main { static void swap ( int [ ] A , int i , int j ) { int tmp = A [ i ] ; A [ i ] = A [ j ] ; A [ j ] = tmp ; } static int selectionSort ( int [ ] A , int N ) { int count = 0 ; for ( int i = 0 ; i < N ; i ++ ) { int minj = i ; for ( int j = i ; j < N ; j ++ ) { if ( A [ j ] < A [ minj ] ) minj = j ; } if ( i != minj ) { int i = 1 ; swap ( A , i , minj ) ; count ++ ; } } return count ; } public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] a = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) a [ i ] = sc . nextInt ( ) ; int c = selectionSort ( a , n ) ; System . out . print ( a [ 0 ] ) ; for ( int i = 1 ; i < n ; i ++ ) System . out . print ( " " + a [ i ] ) ; System . out . println ( ) ; System . out . println ( c ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . nextLine ( ) ; sc . close ( ) ; String [ ] S = s . split ( " " ) ; int a = Integer . parseInt ( S [ 0 ] ) ; int b = Integer . parseInt ( S [ 1 ] ) ; int count = 0 ; for ( int i = 0 ; i < 2 ; i ++ ) { int count = 0 ; if ( a > b ) { count += a ; a -- ; } else { count += b ; b -- ; } } System . out . println ( count ) ; } } +import java . util . * ; class Main { public static int getCvalue ( int n , int m ) { if ( n < 2 ) { return 0 ; } else { int k = n - m ; int a = 1 ; while ( n > k ) { int m = sc . nextInt ( ) ; a *= ( n -- ) ; } return a / 2 ; } } public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int m = sc . nextInt ( ) ; int res = 0 ; res += getCvalue ( n , 2 ) ; res += getCvalue ( m , 2 ) ; System . out . println ( res ) ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner scan = new Scanner ( System . in ) ; int N = scan . nextInt ( ) ; String [ ] S = new String [ N + 1 ] ; int [ ] C = { 0 , 0 , 0 , 0 } ; for ( int i = 0 ; i < N + 1 ; i ++ ) { S [ i ] = scan . nextLine ( ) ; } for ( int i = 0 ; i < N + 1 ; i ++ ) { switch ( S [ i ] ) { case " AC " : C [ 0 ] += 1 ; break ; case " WA " : C [ 1 ] += 1 ; break ; case " TLE " : C [ 2 ] += 1 ; break ; case " RE " : C [ 3 ] += 1 ; break ; default : } } System . out . println ( " AC x " + C [ 0 ] + " \n " + " WA x " + C [ 1 ] + " \n " + " TLE x " + C [ 2 ] + " \n " + " RE x " + C [ 3 ] ) ; scan . close ( ) ; } } +import java . util . * ; import java . io . * ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int n , x , t = 0 ; String [ ] brr = br . readLine ( ) . split ( " " ) ; n = Integer . parseInt ( brr [ 0 ] ) ; x = Integer . parseInt ( brr [ 1 ] ) ; t = Integer . parseInt ( brr [ 2 ] ) ; long ans = 0 ; while ( n > 0 ) { long ans = 0 ; ans += t ; n -= x ; } System . out . println ( ans ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int y = 0 ; Scanner stdIn = new Scanner ( System . in ) ; int m = stdIn . nextInt ( ) ; int n = stdIn . nextInt ( ) ; int [ ] [ ] a = new int [ m ] [ n ] ; int [ ] b = new int [ n ] ; int ans ; for ( int i = 0 ; i < m ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { a [ i ] [ j ] = stdIn . nextInt ( ) ; } } for ( int k = 0 ; k < n ; k ++ ) { b [ k ] = stdIn . nextInt ( ) ; } stdIn . close ( ) ; for ( int x = 0 ; x < m ; x ++ ) { ans = 0 ; for ( int y = 0 ; y < n ; y ++ ) { ans += a [ x ] [ y ] * b [ y ] ; } System . out . println ( ans ) ; } } } +import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . util . ArrayList ; import java . util . List ; public class Main { public static void main ( String [ ] args ) throws Exception { InputStreamReader is = new InputStreamReader ( System . in ) ; BufferedReader reader = new BufferedReader ( is ) ; List < String > mylist = new ArrayList < > ( ) ; String strinput = reader . readLine ( ) ; while ( strinput != null ) { mylist . add ( strinput ) ; strinput = reader . readLine ( ) ; } String [ ] arr01 = mylist . get ( 0 ) . split ( " " ) ; String [ ] arr02 = mylist . get ( 1 ) . split ( " " ) ; int n = Integer . valueOf ( arr01 [ 0 ] ) ; Boolean chkflg = true ; for ( int i = 0 ; i < n - 2 ; i ++ ) { int temp1 = Integer . valueOf ( arr02 [ i ] ) ; int temp2 = Integer . valueOf ( arr02 [ i + 1 ] ) ; int temp3 = Integer . valueOf ( arr02 [ i + 2 ] ) ; if ( temp1 < temp2 ) { temp2 -= 1 ; arr02 [ i + 1 ] = String . valueOf ( temp2 ) ; if ( temp2 > temp3 ) { int temp3 = Integer . valueOf ( arr02 [ i + 2 ] ) ; chkflg = false ; break ; } } else if ( temp1 == temp2 ) { if ( temp2 > temp3 ) { chkflg = false ; break ; } } else { chkflg = false ; break ; } } System . out . println ( chkflg ? " Yes " : " No " ) ; } } +import java . util . Scanner ; import java . util . Arrays ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int [ ] num = new int [ 3 ] ; for ( int i = 0 ; i < 3 ; i ++ ) { num [ i ] = scan . nextInt ( ) ; } int k = scan . nextInt ( ) ; Arrays . sort ( num ) ; for ( int i = 1 ; i <= k ; i ++ ) { int i = 0 ; num [ 2 ] *= 2 ; } int sum = 0 ; for ( int i = 0 ; i < 3 ; i ++ ) { sum += num [ i ] ; } System . out . println ( sum ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner stdIn = new Scanner ( System . in ) ; String input = stdIn . nextLine ( ) ; String [ ] a = input . split ( " " ) ; int x = Integer . parseInt ( a [ 0 ] ) ; int y = Integer . parseInt ( a [ 1 ] ) ; if ( x > 0 && x < 101 && y > 0 && y < 101 ) { int ans = y - x * 2 ; if ( ans == 0 ) { System . out . println ( " Yes " ) ; } else if ( ans > 0 && ( ans % 2 ) == 0 ) { for ( int i = 0 ; i < x ; i ++ ) { ans = ans - 2 ; if ( ans == 0 ) { System . out . println ( " Yes " ) ; break ; } } if ( ans != 0 ) { int ans = y - x * 2 ; System . out . println ( " No " ) ; } } else { System . out . println ( " No " ) ; } } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner scanner = new Scanner ( System . in ) ; String S = scanner . next ( ) ; String T = scanner . next ( ) ; int count = 0 ; for ( int i = 0 ; i < S . length ( ) ; i ++ ) { if ( S . charAt ( i ) == T . charAt ( i ) ) continue ; count ++ ; } System . out . println ( count ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String n = sc . next ( ) ; boolean big = false ; for ( int i = 1 ; i < n . length ( ) ; i ++ ) { if ( n . charAt ( i ) > n . charAt ( 0 ) ) { big = true ; break ; } } String ans = " " ; if ( big ) { int i = 0 ; for ( int i = 0 ; i < n . length ( ) ; i ++ ) { ans += ( char ) ( n . charAt ( 0 ) + 1 ) ; } } else { for ( int i = 0 ; i < n . length ( ) ; i ++ ) { ans += n . charAt ( 0 ) ; } } System . out . println ( ans ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int length = sc . nextInt ( ) ; int lowPos = sc . nextInt ( ) ; String str = sc . next ( ) ; String [ ] ary = str . split ( " " , 0 ) ; for ( int i = 0 ; i < length ; i ++ ) { int i = 0 ; if ( i == lowPos - 1 ) ary [ i ] = ary [ i ] . toLowerCase ( ) ; System . out . print ( ary [ i ] ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String buff = " " ; int m = sc . nextInt ( ) ; long count = 0 , flag = 0 ; long count1 = 0 , count2 = 0 ; int count3 = 0 ; int [ ] array = new int [ 100 ] ; for ( int i = 0 ; i < m ; i ++ ) { int j = i + 1 ; array [ i ] = sc . nextInt ( ) ; } for ( int i = 0 ; i < m - 1 ; i ++ ) { for ( int j = i + 1 ; j < m ; j ++ ) { count += array [ i ] * array [ j ] ; } } System . out . println ( count ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . ArrayList ; import java . util . Collections ; import java . util . StringTokenizer ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; try { ArrayList < Integer > side ; String line = br . readLine ( ) ; int x = Integer . parseInt ( line ) ; StringTokenizer tokens ; for ( int i = 0 ; i < x ; i ++ ) { line = br . readLine ( ) ; tokens = new StringTokenizer ( line ) ; side = new ArrayList < > ( ) ; side . add ( Integer . parseInt ( tokens . nextToken ( ) ) ) ; side . add ( Integer . parseInt ( tokens . nextToken ( ) ) ) ; side . add ( Integer . parseInt ( tokens . nextToken ( ) ) ) ; Collections . sort ( side ) ; if ( side . get ( 0 ) * side . get ( 0 ) + side . get ( 1 ) * side . get ( 1 ) == side . get ( 2 ) * side . get ( 2 ) ) { StringTokenizer tokens ; System . out . println ( " YES " ) ; } else { System . out . println ( " NO " ) ; } } } catch ( Exception e ) { System . out . println ( e ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int N ; Scanner in = new Scanner ( System . in ) ; N = Integer . parseInt ( in . next ( ) ) ; int cnt ; int ans = 0 ; for ( int i = 1 ; i <= N ; i += 2 ) { int j = 1 ; cnt = 0 ; for ( int j = 1 ; j * j <= i ; j ++ ) { if ( i % j == 0 ) { if ( j * j == i ) { cnt ++ ; } else { cnt += 2 ; } } } if ( cnt == 8 ) { ans ++ ; } } System . out . println ( ans ) ; } } +import java . util . Scanner ; public class Main { static Scanner scanner ; public static void main ( String [ ] args ) { scanner = new Scanner ( System . in ) ; int N = gi ( ) ; int [ ] A = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { int i = 0 ; A [ i ] = gi ( ) ; } int max = 0 ; int t = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( max <= A [ i ] ) { t ++ ; max = A [ i ] ; } } System . out . print ( t ) ; } public static String gs ( ) { return scanner . next ( ) ; } public static int gi ( ) { return Integer . parseInt ( scanner . next ( ) ) ; } public static long gl ( ) { return Long . parseLong ( scanner . next ( ) ) ; } public static double gd ( ) { return Double . parseDouble ( scanner . next ( ) ) ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int k = sc . nextInt ( ) ; int count = 0 ; while ( n > 0 ) { int count = 0 ; n /= k ; count ++ ; } System . out . println ( count ) ; } } +import java . io . IOException ; import java . util . ArrayList ; import java . util . Collections ; import java . util . List ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws NumberFormatException , IOException { int i = 0 ; try ( Scanner sc = new Scanner ( System . in ) ) { int n = Integer . parseInt ( sc . nextLine ( ) ) ; String a = sc . nextLine ( ) ; String [ ] b = a . split ( " " ) ; List < Integer > list = new ArrayList < > ( ) ; for ( int i = 0 ; i < b . length ; i ++ ) { list . add ( Integer . parseInt ( b [ i ] ) ) ; } Collections . sort ( list ) ; System . out . println ( list . get ( list . size ( ) - 1 ) - list . get ( 0 ) ) ; } } } +import java . util . * ; import java . io . * ; class Main { static int n , arr [ ] , k ; static long [ ] dp ; public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int t = 1 ; StringBuilder printans = new StringBuilder ( ) ; while ( t -- > 0 ) { int j = i - k ; StringTokenizer tok = new StringTokenizer ( br . readLine ( ) , " " ) ; n = Integer . parseInt ( tok . nextToken ( ) ) ; k = Integer . parseInt ( tok . nextToken ( ) ) ; arr = new int [ n ] ; tok = new StringTokenizer ( br . readLine ( ) , " " ) ; for ( int i = 0 ; i < n ; i ++ ) { arr [ i ] = Integer . parseInt ( tok . nextToken ( ) ) ; } dp = new long [ n ] ; printans . append ( call ( ) ) ; } System . out . println ( printans ) ; } static long call ( ) { dp [ 0 ] = 0 ; dp [ 1 ] = Math . abs ( arr [ 1 ] - arr [ 0 ] ) ; for ( int i = 2 ; i < n ; i ++ ) { long temp = Integer . MAX_VALUE ; for ( int j = i - k ; j < i ; j ++ ) { if ( j >= 0 ) { temp = Math . min ( temp , dp [ j ] + Math . abs ( arr [ i ] - arr [ j ] ) ) ; } } dp [ i ] = temp ; } return dp [ dp . length - 1 ] ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int [ ] youso1 = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { int i = 0 ; youso1 [ i ] = sc . nextInt ( ) ; } int [ ] youso2 = youso1 . clone ( ) ; Arrays . sort ( youso2 ) ; for ( int i = 0 ; i < N ; i ++ ) { if ( youso1 [ i ] < youso2 [ N - 1 ] ) { System . out . println ( youso2 [ N - 1 ] ) ; } else { System . out . println ( youso2 [ N - 2 ] ) ; } } } } +import java . util . Scanner ; public class Main { public static void main ( final String ... args ) { final int res = calc ( r ) ; final String mode = " b " ; if ( mode . equals ( " a " ) ) { A . solve ( ) ; } else if ( mode . equals ( " b " ) ) { B . solve ( ) ; } } } class B { static void solve ( ) { final Scanner sc = new Scanner ( System . in ) ; final int n = sc . nextInt ( ) ; final int d = sc . nextInt ( ) ; final int res = calc ( n , d ) ; System . out . println ( res ) ; } static int calc ( final int n , final int d ) { final int max = ( 2 * d + 1 ) ; int res = n / max ; if ( n % max != 0 ) { res += 1 ; } return res ; } } class A { static void solve ( ) { final Scanner sc = new Scanner ( System . in ) ; final int r = sc . nextInt ( ) ; final int res = calc ( r ) ; System . out . println ( res ) ; } static int calc ( final int r ) { return 3 * r * r ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner inp = new Scanner ( System . in ) ; Scanner inp = new Scanner ( System . in ) ; do_ ( inp ) ; inp . close ( ) ; } public static void do_ ( Scanner inp ) { char [ ] s = inp . next ( ) . toCharArray ( ) ; Arrays . sort ( s ) ; if ( s [ 0 ] == s [ 1 ] && s [ 1 ] != s [ 2 ] && s [ 2 ] == s [ 3 ] ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } } +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 ( ) ; int q = scan . nextInt ( ) ; int [ ] a = new int [ n + 1 ] ; int i ; for ( i = 0 ; i < q ; i ++ ) a [ scan . nextInt ( ) ] ++ ; int border = q - k ; for ( i = 1 ; i <= n ; i ++ ) { int border = q - k ; if ( a [ i ] > border ) { 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 ) ; String s = sc . next ( ) ; if ( s . charAt ( 0 ) != 'A' ) { System . out . println ( " WA " ) ; return ; } int cCnt = 0 ; int cIndex = 0 ; for ( int i = 2 ; i < s . length ( ) - 1 ; i ++ ) { char c = s . charAt ( i ) ; if ( c == 'C' ) { cCnt ++ ; cIndex = i ; } } if ( cCnt != 1 ) { int i = 1 ; System . out . println ( " WA " ) ; return ; } for ( int i = 1 ; i < s . length ( ) ; i ++ ) { if ( i != cIndex ) { if ( ! Character . isLowerCase ( s . charAt ( i ) ) ) { System . out . println ( " WA " ) ; return ; } } } System . out . println ( " AC " ) ; } } +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 c = sc . nextInt ( ) ; int sum = 0 ; for ( int x = a ; x <= b ; x ++ ) { int x = a ; if ( c % x == 0 ) { sum ++ ; } } System . out . println ( sum ) ; sc . close ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int n = scanner . nextInt ( ) ; int result = 0 ; int max = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int a = scanner . nextInt ( ) ; if ( a >= max ) { int a = scanner . nextInt ( ) ; max = a ; result ++ ; } } System . out . println ( result ) ; } } +import java . util . HashSet ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { try ( Scanner sc = new Scanner ( System . in ) ) { int N = sc . nextInt ( ) ; String [ ] S = new String [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { S [ i ] = sc . next ( ) ; } HashSet < String > set = new HashSet < String > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { int i = 0 ; set . add ( S [ i ] ) ; } System . out . println ( set . size ( ) ) ; } } } +import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner in = new Scanner ( new BufferedReader ( new InputStreamReader ( System . in ) ) ) ; int n = in . nextInt ( ) ; int k = in . nextInt ( ) ; System . out . println ( solve ( n , k ) ) ; in . close ( ) ; } private static double solve ( int n , int k ) { double r = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { int p = i ; double x = 1 ; x /= n ; while ( p < k ) { double x = 1 ; p *= 2 ; x /= 2 ; } r += x ; } return r ; } } +import java . util . ArrayList ; import java . util . List ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int A = Integer . parseInt ( sc . next ( ) ) ; int B = Integer . parseInt ( sc . next ( ) ) ; int K = Integer . parseInt ( sc . next ( ) ) ; int len = ( A < B ) ? A : B ; List r = new ArrayList < Integer > ( ) ; for ( int i = 1 ; i <= len ; i ++ ) { int i = 1 ; if ( A % i == 0 && B % i == 0 ) r . add ( i ) ; } System . out . println ( r . get ( r . size ( ) - K ) ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int n , x , x1 , x2 , x3 ; int counter ; while ( true ) { int k = j + 1 ; counter = 0 ; n = scanner . nextInt ( ) ; x = scanner . nextInt ( ) ; if ( n == 0 && x == 0 ) break ; for ( int i = 1 ; i <= n ; i ++ ) { x1 = x ; x1 -= i ; if ( x1 > 1 ) { for ( int j = i + 1 ; j <= n ; j ++ ) { x2 = x1 ; x2 -= j ; if ( x2 > 0 ) { for ( int k = j + 1 ; k <= n ; k ++ ) { x3 = x2 ; x3 -= k ; if ( x3 == 0 ) counter ++ ; } } } } } System . out . println ( counter ) ; } } } +import java . util . ArrayList ; import java . util . Arrays ; import java . util . LinkedHashSet ; import java . util . List ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; List < String > box = new ArrayList < > ( ) ; int amount = sc . nextInt ( ) ; String each = null ; for ( int i = 0 ; i < amount ; i ++ ) { List < String > box = new ArrayList < > ( ) ; box . add ( sc . next ( ) ) ; } List < String > list = new ArrayList < String > ( new LinkedHashSet < > ( box ) ) ; System . out . println ( list . size ( ) ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader reader = new BufferedReader ( new InputStreamReader ( System . in ) ) ; StringBuilder sb = new StringBuilder ( ) ; String [ ] items = reader . readLine ( ) . split ( " " ) ; int a = Integer . parseInt ( items [ 0 ] ) ; int b = Integer . parseInt ( items [ 1 ] ) ; int c = Integer . parseInt ( items [ 2 ] ) ; int counter = 0 ; for ( int i = a ; i <= b ; i ++ ) { int i = a ; if ( c % i == 0 ) { counter ++ ; } } System . out . println ( counter ) ; } } +import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int [ ] H = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { H [ i ] = sc . nextInt ( ) ; } for ( int i = 1 ; i < N ; i ++ ) { int i = 1 ; if ( i == 1 ) { H [ 0 ] -- ; } else { if ( H [ i - 1 ] - 1 >= H [ i - 2 ] ) { H [ i - 1 ] -- ; } } } int [ ] H1 = H . clone ( ) ; Arrays . sort ( H ) ; if ( Arrays . equals ( H , H1 ) ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner scan = new Scanner ( System . in ) ; int n = scan . nextInt ( ) ; int m = scan . nextInt ( ) ; int [ ] a = new int [ m ] ; int [ ] b = new int [ m ] ; for ( int i = 0 ; i < a . length ; i ++ ) { a [ i ] = scan . nextInt ( ) ; b [ i ] = scan . nextInt ( ) ; } int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int j = 0 ; count = 0 ; for ( int j = 0 ; j < a . length ; j ++ ) { if ( a [ j ] == i + 1 ) { count ++ ; } if ( b [ j ] == i + 1 ) { count ++ ; } } System . out . println ( count ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int j = 0 ; Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int Y = sc . nextInt ( ) ; int a = - 1 ; int b = - 1 ; int c = - 1 ; for ( int i = 0 ; i <= N ; i ++ ) { for ( int j = 0 ; j <= N - i ; j ++ ) { if ( Y == ( 10000 * i + 5000 * j + 1000 * ( N - i - j ) ) ) { a = i ; b = j ; c = N - i - j ; } } } System . out . print ( a + " " ) ; System . out . print ( b + " " ) ; System . out . print ( c ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; StringBuilder out ; int n = sc . nextInt ( ) ; int [ ] a = new int [ n ] ; for ( int i = 0 ; i < a . length ; i ++ ) { a [ i ] = sc . nextInt ( ) ; } sort ( a ) ; } static void sort ( int [ ] a ) { int i = 0 ; printArray ( a ) ; for ( int i = 1 ; i < a . length ; i ++ ) { int v = a [ i ] ; int j = i - 1 ; while ( j >= 0 && a [ j ] > v ) { a [ j + 1 ] = a [ j ] ; j -- ; } a [ j + 1 ] = v ; printArray ( a ) ; } } static void printArray ( int [ ] a ) { for ( int i = 0 ; i < a . length - 1 ; i ++ ) { System . out . print ( a [ i ] + " " ) ; } System . out . println ( a [ a . length - 1 ] ) ; } } +import java . io . IOException ; import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] s = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { s [ i ] = sc . nextInt ( ) ; } int q = sc . nextInt ( ) ; int count = 0 ; int left , right , mid , t ; for ( int i = 0 ; i < q ; i ++ ) { left = 0 ; right = n - 1 ; t = sc . nextInt ( ) ; while ( left <= right ) { mid = ( left + right ) / 2 ; if ( s [ mid ] < t ) { left = mid + 1 ; } else if ( s [ mid ] > t ) { int i = 0 ; right = mid - 1 ; } else { count ++ ; break ; } } } System . out . println ( count ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int sum = 0 ; Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int sum = 0 ; sum = a / 2 ; if ( a % 2 == 0 ) { System . out . print ( a / 2 ) ; } else { sum = a / 2 ; System . out . print ( sum + 1 ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int n = scanner . nextInt ( ) ; int tarop = 0 ; int hanakop = 0 ; String tarow ; String hanakow ; for ( int i = 0 ; i < n ; i ++ ) { tarow = scanner . next ( ) ; hanakow = scanner . next ( ) ; if ( tarow . compareTo ( hanakow ) < 0 ) { String hanakow ; hanakop = hanakop + 3 ; } else if ( tarow . compareTo ( hanakow ) > 0 ) tarop = tarop + 3 ; else { hanakop = hanakop + 1 ; tarop = tarop + 1 ; } } System . out . println ( tarop + " " + hanakop ) ; } } +import java . util . * ; import java . io . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int d = sc . nextInt ( ) ; int ans = 0 ; int able = 2 * d + 1 ; for ( int i = 1 ; i < 20 ; i ++ ) { int i = 1 ; if ( i * able >= n ) { ans = i ; break ; } } System . out . println ( ans ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int x = a ; Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int c = sc . nextInt ( ) ; int y = 0 ; for ( int x = a ; x <= b ; x ++ ) { if ( c % x == 0 ) { y ++ ; } } System . out . println ( y ) ; } } +import java . util . HashSet ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int n = scanner . nextInt ( ) ; int next = 1 ; int [ ] a = new int [ n ] ; HashSet < Integer > hSet = new HashSet < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = scanner . nextInt ( ) ; } for ( int i = 0 ; i < n ; i ++ ) { int i = 0 ; next = a [ next - 1 ] ; if ( next == 2 ) { System . out . println ( i + 1 ) ; return ; } if ( hSet . contains ( next ) ) { System . out . println ( - 1 ) ; return ; } else { hSet . add ( next ) ; } } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = null ; sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; sc . close ( ) ; String before = " " ; int ans = 0 ; for ( int i = 0 ; i < 3 ; i ++ ) { if ( i == 0 ) { if ( s . substring ( 0 , 1 ) . equals ( " R " ) ) { ans = 1 ; } before = s . substring ( 0 , 1 ) ; } else { if ( s . substring ( i , i + 1 ) . equals ( " R " ) && before . equals ( " R " ) ) { ans += 1 ; } else if ( s . substring ( i , i + 1 ) . equals ( " R " ) && before . equals ( " S " ) ) { ans = 1 ; } before = s . substring ( i , i + 1 ) ; } } System . out . println ( ans ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 1 ; Scanner scan = new Scanner ( System . in ) ; int seisu = scan . nextInt ( ) ; int count = 0 ; for ( int i = 1 ; i <= seisu ; i ++ ) { String mozi = String . valueOf ( i ) ; if ( mozi . length ( ) % 2 == 1 ) { count ++ ; } } System . out . println ( count ) ; scan . close ( ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int count = 0 ; Scanner sc = new Scanner ( System . in ) ; int n = Integer . parseInt ( sc . next ( ) ) ; int d = Integer . parseInt ( sc . next ( ) ) ; int x , y ; for ( int i = 0 ; i < n ; i ++ ) { int x , y ; x = Integer . parseInt ( sc . next ( ) ) ; y = Integer . parseInt ( sc . next ( ) ) ; if ( d >= Math . sqrt ( Math . pow ( x , 2 ) + Math . pow ( y , 2 ) ) ) count ++ ; } System . out . println ( count ) ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] param = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { param [ i ] = sc . nextInt ( ) ; } Arrays . sort ( param ) ; int alice = 0 ; int bob = 0 ; if ( n % 2 == 0 ) { for ( int i = 0 ; i < n ; i ++ ) { if ( i % 2 == 0 ) { bob += param [ i ] ; } else { alice += param [ i ] ; } } } else { for ( int i = 0 ; i < n ; i ++ ) { if ( i % 2 == 0 ) { alice += param [ i ] ; } else { bob += param [ i ] ; } } } int total = alice - bob ; System . out . println ( total ) ; } } +import java . util . * ; public class Main { void solve ( ) { Scanner scan = new Scanner ( System . in ) ; int n = scan . nextInt ( ) ; int k = scan . nextInt ( ) ; int [ ] h = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) h [ i ] = scan . nextInt ( ) ; int [ ] dp = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) dp [ i ] = Integer . MAX_VALUE ; dp [ 0 ] = 0 ; dp [ 1 ] = Math . abs ( h [ 1 ] - h [ 0 ] ) ; for ( int i = 0 ; i < n ; i ++ ) { int j = 1 ; for ( int j = 1 ; j <= k ; j ++ ) { if ( i - j >= 0 ) dp [ i ] = Math . min ( dp [ i ] , dp [ i - j ] + Math . abs ( h [ i - j ] - h [ i ] ) ) ; } } System . out . println ( dp [ n - 1 ] ) ; scan . close ( ) ; } public static void main ( String [ ] args ) { new Main ( ) . solve ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int count = sc . nextInt ( ) ; int [ ] array = new int [ count ] ; for ( int i = 0 ; i < count ; i ++ ) { array [ i ] = sc . nextInt ( ) ; } long min = 1000001 ; for ( int i = 0 ; i < count ; i ++ ) { if ( min > array [ i ] ) { min = array [ i ] ; } } long max = - 1000001 ; for ( int i = 0 ; i < count ; i ++ ) { int i = 0 ; if ( max < array [ i ] ) { max = array [ i ] ; } } long sum = 0 ; for ( int i = 0 ; i < count ; i ++ ) { sum += array [ i ] ; } System . out . println ( min + " " + max + " " + sum ) ; } } +import java . util . HashMap ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; String [ ] s = new String [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { s [ i ] = sc . next ( ) ; } HashMap < String , Integer > map = new HashMap < String , Integer > ( ) ; map . put ( s [ 0 ] , 1 ) ; int ans = 1 ; for ( int i = 1 ; i < n ; i ++ ) { if ( ! map . containsKey ( s [ i ] ) ) { int i = 1 ; ans ++ ; map . put ( s [ i ] , 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 m = sc . nextInt ( ) ; int [ ] num = new int [ m ] ; String [ ] s = new String [ m ] ; for ( int i = 0 ; i < m ; i ++ ) { num [ i ] = sc . nextInt ( ) ; s [ i ] = sc . next ( ) ; } int [ ] cnt = new int [ n ] ; int [ ] wa = new int [ n ] ; for ( int i = 0 ; i < m ; i ++ ) { int i = 0 ; if ( s [ i ] . equals ( " AC " ) && cnt [ num [ i ] - 1 ] == 0 ) { cnt [ num [ i ] - 1 ] ++ ; continue ; } if ( s [ i ] . equals ( " WA " ) && cnt [ num [ i ] - 1 ] == 0 ) { wa [ num [ i ] - 1 ] ++ ; } } int a = 0 ; int w = 0 ; for ( int i = 0 ; i < n ; i ++ ) { a += cnt [ i ] ; if ( cnt [ i ] > 0 ) { w += wa [ i ] ; } } System . out . println ( a + " " + w ) ; } } +import java . io . IOException ; import java . io . BufferedReader ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws IOException { int j = 0 ; BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String line = br . readLine ( ) ; while ( ! ( line . equals ( " 0 0 " ) ) ) { String [ ] inputs = line . split ( " " ) ; int height = Integer . valueOf ( inputs [ 0 ] ) ; int width = Integer . valueOf ( inputs [ 1 ] ) ; StringBuilder result = new StringBuilder ( ) ; for ( int i = 0 ; i < height ; i ++ ) { if ( i == 0 || i == height - 1 ) { for ( int j = 0 ; j < width ; j ++ ) result . append ( " # " ) ; } else { for ( int j = 0 ; j < width ; j ++ ) { if ( j == 0 || j == width - 1 ) result . append ( " # " ) ; else result . append ( " . " ) ; } } result . append ( " \n " ) ; } System . out . println ( result ) ; line = br . readLine ( ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int j = i + 1 ; Scanner sc = new Scanner ( System . in ) ; int n = Integer . parseInt ( sc . next ( ) ) ; int [ ] ary = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { ary [ i ] = Integer . parseInt ( sc . next ( ) ) ; } int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { ans += ary [ i ] * ary [ j ] ; } } System . out . println ( ans ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Main m = new Main ( ) ; m . exec ( ) ; } private void exec ( ) { Scanner scan = new Scanner ( System . in ) ; int count5 = 0 ; int count7 = 0 ; for ( int i = 0 ; i < 3 ; i ++ ) { switch ( scan . nextInt ( ) ) { case 5 : count5 ++ ; break ; case 7 : count7 ++ ; break ; default : } } if ( count5 == 2 && count7 == 1 ) { int count7 = 0 ; System . out . println ( " YES " ) ; } else { System . out . println ( " NO " ) ; } scan . close ( ) ; } } +import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . io . IOException ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader in = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String s = in . readLine ( ) ; String t = in . readLine ( ) ; String s_rt = " " ; boolean matchingFlg = false ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { int i = 0 ; s_rt = s . substring ( s . length ( ) - i , s . length ( ) ) + s . substring ( 0 , s . length ( ) - i ) ; if ( s_rt . equals ( t ) ) matchingFlg = true ; } System . out . println ( matchingFlg == true ? " Yes " : " No " ) ; } } +import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner in = new Scanner ( new BufferedReader ( new InputStreamReader ( System . in ) ) ) ; int n = in . nextInt ( ) ; int [ ] value = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { value [ i ] = in . nextInt ( ) ; } int [ ] cost = new int [ n ] ; for ( int j = 0 ; j < n ; j ++ ) { cost [ j ] = in . nextInt ( ) ; } int result = solve ( n , value , cost ) ; System . out . println ( result ) ; in . close ( ) ; } public static int solve ( int n , int [ ] value , int [ ] cost ) { int result = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( ( value [ i ] - cost [ i ] ) > 0 ) { int i = 0 ; result += value [ i ] - cost [ i ] ; } } return result ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int b = sc . nextInt ( ) ; int [ ] hairetu = new int [ b ] ; for ( int i = 0 ; i < hairetu . length ; i ++ ) { int c = sc . nextInt ( ) ; hairetu [ i ] = c ; } int count = 0 ; int champ = hairetu [ 0 ] ; for ( int k = 0 ; k < hairetu . length ; k ++ ) { if ( champ >= hairetu [ k ] ) { int k = 0 ; champ = hairetu [ k ] ; count ++ ; } } System . out . println ( count ) ; } } +import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = Integer . parseInt ( sc . next ( ) ) ; int [ ] A = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { int i = 0 ; A [ i ] = Integer . parseInt ( sc . next ( ) ) ; } sc . close ( ) ; Arrays . sort ( A ) ; System . out . println ( Math . abs ( A [ 0 ] - A [ N - 1 ] ) ) ; } } +import java . io . * ; import java . util . * ; import java . lang . * ; class Main { public static void main ( String [ ] args ) throws IOException { Scanner scan = new Scanner ( System . in ) ; int n = Integer . parseInt ( scan . next ( ) ) ; int q = Integer . parseInt ( scan . next ( ) ) ; int sumTime = 0 ; Queue < Process > queue = new ArrayDeque < Process > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { String namae = scan . next ( ) ; int Time = Integer . parseInt ( scan . next ( ) ) ; queue . add ( new Process ( namae , Time ) ) ; } Queue < Process > ans = new ArrayDeque < > ( ) ; while ( ! queue . isEmpty ( ) ) { Process buf = queue . remove ( ) ; if ( buf . pTime - q <= 0 ) { int buf2 = buf . pTime ; buf . pTime += sumTime ; sumTime += buf2 ; ans . add ( buf ) ; } else { buf . pTime -= q ; queue . add ( buf ) ; sumTime += q ; } } for ( Process p : ans ) { System . out . println ( p . name + " " + p . pTime ) ; } } } class Process { String name ; int pTime ; public Process ( String name , int pTime ) { this . name = name ; this . pTime = pTime ; } } +import java . io . * ; import java . math . * ; import java . security . * ; import java . text . * ; import java . util . * ; import java . util . concurrent . * ; import java . util . function . * ; import java . util . regex . * ; import java . util . stream . * ; import static java . util . stream . Collectors . joining ; import static java . util . stream . Collectors . toList ; public class Main { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int n = in . nextInt ( ) ; long [ ] a = new long [ n ] ; for ( int i = 0 ; i < n ; i ++ ) a [ i ] = in . nextLong ( ) ; long curr = a [ 0 ] ; long total = 0 ; for ( int i = 1 ; i < n ; i ++ ) { int i = 1 ; if ( a [ i ] >= curr ) curr = a [ i ] ; else { total += ( curr - a [ i ] ) ; } } System . out . println ( total ) ; } } +import java . util . Scanner ; import java . lang . Math ; class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int n = scan . nextInt ( ) ; int m = scan . nextInt ( ) ; int sum = 0 ; for ( int i = 0 ; i < m ; i ++ ) { int sum = 0 ; sum += scan . nextInt ( ) ; } if ( n - sum < 0 ) { System . out . println ( - 1 ) ; } else { System . out . println ( n - sum ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; long a = Integer . parseInt ( scan . next ( ) ) ; long b = Integer . parseInt ( scan . next ( ) ) ; long mult = a * b ; if ( a < b ) { long tmp = a ; a = b ; b = tmp ; } long r = a % b ; while ( r > 0 ) { long r = a % b ; a = b ; b = r ; r = a % b ; } System . out . println ( mult / b ) ; scan . close ( ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int m = 0 ; int t = 1 ; while ( n > 0 ) { int t = 1 ; if ( n % 10 == 1 ) { m += 9 * t ; } else if ( n % 10 == 9 ) { m += t ; } else { m += n % 10 * t ; } n /= 10 ; t *= 10 ; } System . out . println ( m ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int count5 = 0 ; int count7 = 0 ; for ( int i = 0 ; i < 3 ; i ++ ) { switch ( sc . nextInt ( ) ) { case 5 : count5 ++ ; break ; case 7 : count7 ++ ; break ; } } if ( count5 == 2 && count7 == 1 ) { System . out . println ( " YES " ) ; } else { int count7 = 0 ; System . out . println ( " NO " ) ; } } } +import java . util . * ; import java . util . Arrays ; public class Main { public static void main ( String [ ] args ) { int j = 0 ; Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int K = sc . nextInt ( ) ; long [ ] arr = new long [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { arr [ i ] = sc . nextLong ( ) ; } Arrays . sort ( arr ) ; long total = 0 ; for ( int j = 0 ; j < N - K ; j ++ ) { total += arr [ j ] ; } System . out . println ( total ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int sweet = N ; if ( N % 7 == 0 ) { System . out . println ( " Yes " ) ; } else { while ( sweet > 0 ) { sweet = sweet - 4 ; if ( sweet % 7 == 0 ) { System . out . println ( " Yes " ) ; break ; } else { int sweet = N ; } } if ( sweet < 0 ) { System . out . println ( " No " ) ; } } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) , m = sc . nextInt ( ) ; int k , a ; int [ ] [ ] food = new int [ n ] [ m + 1 ] ; for ( int i = 0 ; i < n ; ++ i ) { k = sc . nextInt ( ) ; for ( int j = 0 ; j < k ; ++ j ) { a = sc . nextInt ( ) ; food [ i ] [ a ] ++ ; } } sc . close ( ) ; int ans = 0 ; int j = 0 ; for ( int i = 1 ; i <= m ; ++ i ) { int i = 1 ; for ( j = 0 ; j < n ; ++ j ) { if ( food [ j ] [ i ] == 0 ) break ; } if ( j == n ) ++ ans ; } System . out . println ( ans ) ; } } +import java . util . * ; import java . util . regex . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int w = sc . nextInt ( ) , n = sc . nextInt ( ) , a , b , z ; int [ ] amida = new int [ w ] ; for ( int i = 0 ; i < w ; i ++ ) amida [ i ] = i + 1 ; for ( int i = 0 ; i < n ; i ++ ) { int [ ] amida = new int [ w ] ; String s = sc . next ( ) ; Pattern pattern = Pattern . compile ( " \\ D " ) ; String [ ] splitStr = pattern . split ( s ) ; a = Integer . parseInt ( splitStr [ 0 ] ) ; b = Integer . parseInt ( splitStr [ 1 ] ) ; z = amida [ a - 1 ] ; amida [ a - 1 ] = amida [ b - 1 ] ; amida [ b - 1 ] = z ; } for ( int i = 0 ; i < w ; i ++ ) System . out . println ( amida [ i ] ) ; sc . close ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner input = new Scanner ( System . in ) ; int n = input . nextInt ( ) ; int X = input . nextInt ( ) ; int [ ] L = new int [ n ] ; for ( int i = 0 ; i < L . length ; i ++ ) { L [ i ] = input . nextInt ( ) ; } int count = 0 ; for ( int j = 0 ; j < L . length ; j ++ ) { X -= L [ j ] ; if ( X >= 0 ) { int j = 0 ; count += 1 ; } } System . out . println ( count + 1 ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int x = sc . nextInt ( ) ; int x = sc . nextInt ( ) ; while ( x > 0 && x % 2 == 0 ) { count ++ ; x /= 2 ; } } System . out . println ( count ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int A = sc . nextInt ( ) ; int B = sc . nextInt ( ) ; int count = 0 ; for ( int i = 1 ; i <= N ; i ++ ) { int [ ] sum = new int [ 5 ] ; sum [ 0 ] = i / 10000 ; sum [ 1 ] = ( i - sum [ 0 ] * 10000 ) / 1000 ; sum [ 2 ] = ( i - ( sum [ 0 ] * 10000 ) - ( sum [ 1 ] * 1000 ) ) / 100 ; sum [ 3 ] = ( i - ( sum [ 0 ] * 10000 ) - ( sum [ 1 ] * 1000 ) - sum [ 2 ] * 100 ) / 10 ; sum [ 4 ] = ( i - ( sum [ 0 ] * 10000 ) - ( sum [ 1 ] * 1000 ) - sum [ 2 ] * 100 - sum [ 3 ] * 10 ) ; int s = sum [ 0 ] + sum [ 1 ] + sum [ 2 ] + sum [ 3 ] + sum [ 4 ] ; if ( s >= A && s <= B ) { count += i ; } } System . out . println ( count ) ; } public static void print ( Object o ) { int i = 1 ; System . out . print ( o ) ; } public static void println ( Object o ) { System . out . println ( o ) ; } } +import java . util . * ; public class Main { public static void main ( final String [ ] args ) { String result = " No " ; final Scanner sc = new Scanner ( System . in ) ; final String s = sc . next ( ) ; final String t = sc . next ( ) ; sc . close ( ) ; String result = " No " ; if ( t . length ( ) == s . length ( ) + 1 && t . substring ( 0 , s . length ( ) ) . equals ( s ) ) { result = " Yes " ; } System . out . println ( result ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int N = scanner . nextInt ( ) ; int Q = scanner . nextInt ( ) ; String S = scanner . next ( ) ; int [ ] a = new int [ Q ] ; int [ ] b = new int [ Q ] ; for ( int i = 0 ; i < Q ; i ++ ) { a [ i ] = scanner . nextInt ( ) ; b [ i ] = scanner . nextInt ( ) ; } int [ ] t = new int [ N + 1 ] ; String find = " AC " ; for ( int i = 0 ; i < N ; i ++ ) { if ( i == 0 ) { t [ i ] = 0 ; } if ( i >= 1 && S . substring ( i - 1 , i + 1 ) . equals ( find ) ) { t [ i ] = 1 ; } else { t [ i ] = 0 ; } } int [ ] s = new int [ N + 1 ] ; for ( int i = 0 ; i < N ; i ++ ) { if ( i == 0 ) { s [ i ] = t [ i ] ; } else { s [ i ] = t [ i ] + s [ i - 1 ] ; } } for ( int i = 0 ; i < Q ; i ++ ) { int i = 0 ; System . out . println ( s [ b [ i ] - 1 ] - s [ a [ i ] - 1 ] ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int x = 100000 ; for ( int i = 0 ; i < n ; i ++ ) { x = ( int ) ( 1.05 * x ) ; if ( x % 1000 != 0 ) { int x = 100000 ; x = ( ( x / 1000 ) + 1 ) * 1000 ; } } System . out . println ( x ) ; } } +import java . util . * ; import java . io . * ; class Main { public static void main ( String [ ] args ) throws IOException { PrintWriter out = new PrintWriter ( System . out ) ; BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int n = Integer . parseInt ( br . readLine ( ) ) ; int answer = ( int ) ( Math . ceil ( n / 1000.0 ) ) ; out . println ( answer * 1000 - n ) ; out . flush ( ) ; out . close ( ) ; } static class pair { long x1 ; long x2 ; public pair ( long x1 , long x2 ) { this . x1 = x1 ; this . x2 = x2 ; } } } +import java . util . Scanner ; public class Main { static void putArray ( int [ ] array ) { int j = i - 1 ; System . out . print ( array [ 0 ] ) ; for ( int i = 1 ; i < array . length ; i ++ ) { System . out . print ( " " + array [ i ] ) ; } System . out . println ( ) ; } public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int num = sc . nextInt ( ) ; int [ ] array = new int [ num ] ; for ( int i = 0 ; i < array . length ; i ++ ) { array [ i ] = sc . nextInt ( ) ; } putArray ( array ) ; for ( int i = 1 ; i < array . length ; i ++ ) { int v = array [ i ] ; int j = i - 1 ; while ( j >= 0 && array [ j ] > v ) { array [ j + 1 ] = array [ j ] ; j -- ; } array [ j + 1 ] = v ; putArray ( array ) ; } } } +import java . util . * ; import java . lang . * ; import java . awt . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int [ ] t = new int [ 26 ] ; while ( sc . hasNext ( ) ) { int a = 0 ; String s = sc . nextLine ( ) ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { int countval = s . toLowerCase ( ) . codePointAt ( i ) - 97 ; if ( countval >= 0 ) t [ countval ] ++ ; } } for ( int a = 0 ; a < t . length ; a ++ ) { System . out . println ( String . format ( " %s : %d " , ( char ) ( a + 97 ) , t [ a ] ) ) ; } } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . Arrays ; public class Main { public static void main ( String [ ] args ) throws NumberFormatException , IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; while ( true ) { String [ ] tmpArray = br . readLine ( ) . split ( " " ) ; int a = Integer . parseInt ( tmpArray [ 0 ] ) ; int b = Integer . parseInt ( tmpArray [ 1 ] ) ; if ( a == 0 && b == 0 ) { break ; } for ( int i = 0 ; i < a ; i ++ ) { for ( int j = 0 ; j < b ; j ++ ) { if ( i != 0 && i != a - 1 && j != 0 && j != b - 1 ) { System . out . print ( " . " ) ; } else { int j = 0 ; System . out . print ( " # " ) ; } } System . out . println ( ) ; } System . out . println ( ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int cnt = 0 ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; Set < Integer > visited = new HashSet < > ( ) ; int cnt = 0 ; while ( n > 0 ) { n -- ; int num = sc . nextInt ( ) ; if ( visited . contains ( num ) ) continue ; visited . add ( num ) ; cnt ++ ; } System . out . println ( cnt ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int [ ] antennaArr = new int [ 5 ] ; for ( int i = 0 ; i < antennaArr . length ; i ++ ) { antennaArr [ i ] = sc . nextInt ( ) ; } int border = sc . nextInt ( ) ; boolean canConnect = true ; for ( int i = 0 ; i < antennaArr . length ; i ++ ) { int j = 0 ; for ( int j = 0 ; j < antennaArr . length ; j ++ ) { if ( i >= j ) { continue ; } if ( antennaArr [ j ] - antennaArr [ i ] > border ) { canConnect = false ; } } } if ( canConnect ) { System . out . println ( " Yay! " ) ; } else { System . out . println ( " :( " ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { try ( Scanner scanner = new Scanner ( System . in ) ) { Scanner scanner = new Scanner ( System . in ) ; String line = scanner . nextLine ( ) ; System . out . println ( " 2018/01/ " + line . split ( " / " ) [ 2 ] ) ; } } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . StringTokenizer ; class Main { static Scanner sc = new Scanner ( ) ; public static void main ( final String [ ] args ) throws IOException { int n = sc . nextInt ( ) ; String s = sc . next ( ) ; char [ ] c = s . toCharArray ( ) ; char temp = c [ 0 ] ; int ans = 1 ; for ( int i = 1 ; i < n ; i ++ ) { if ( c [ i ] != temp ) { temp = c [ i ] ; ans ++ ; } } System . out . println ( ans ) ; } static class Scanner { BufferedReader reader = new BufferedReader ( new InputStreamReader ( System . in ) , 1 << 15 ) ; StringTokenizer tokenizer ; String next ( ) throws IOException { while ( tokenizer == null || ! tokenizer . hasMoreTokens ( ) ) { tokenizer = new StringTokenizer ( reader . readLine ( ) ) ; } return tokenizer . nextToken ( ) ; } int nextInt ( ) throws IOException { return Integer . parseInt ( next ( ) ) ; } long nextLong ( ) throws IOException { return Long . parseLong ( next ( ) ) ; } } } +import java . util . Scanner ; import java . util . Arrays ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int age = scan . nextInt ( ) ; int price = scan . nextInt ( ) ; if ( age >= 13 ) { int price = scan . nextInt ( ) ; System . out . println ( price ) ; } else if ( age >= 6 ) { System . out . println ( price / 2 ) ; } else { System . out . println ( 0 ) ; } } } +import java . util . ArrayList ; import java . util . Collections ; import java . util . HashMap ; import java . util . List ; import java . util . Map ; import java . util . Map . Entry ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int max = 1 ; String w = " " ; Map < String , Integer > map = new HashMap < > ( ) ; List < String > strArr = new ArrayList < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { w = sc . next ( ) ; if ( map . get ( w ) == null ) { String str ; map . put ( w , 1 ) ; } else { map . put ( w , map . get ( w ) + 1 ) ; if ( map . get ( w ) > max ) { max = map . get ( w ) ; } } } for ( Entry < String , Integer > entry : map . entrySet ( ) ) { if ( entry . getValue ( ) == max ) { strArr . add ( entry . getKey ( ) ) ; } } Collections . sort ( strArr ) ; for ( String str : strArr ) { System . out . println ( str ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; int H = sc . nextInt ( ) ; int N = sc . nextInt ( ) ; int [ ] list = new int [ N ] ; int all = 0 ; for ( int i = 0 ; i < N ; i ++ ) { list [ i ] = sc . nextInt ( ) ; all += list [ i ] ; } if ( H <= all ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int a = scan . nextInt ( ) ; int b = scan . nextInt ( ) ; boolean flag = true ; long aa = a , bb = b ; while ( flag ) { if ( aa < bb ) { aa += a ; } else if ( bb < aa ) { long aa = a , bb = b ; bb += b ; } else if ( aa == bb ) { flag = false ; } } System . out . println ( aa ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = a ; Scanner scan = new Scanner ( System . in ) ; int a = scan . nextInt ( ) ; int b = scan . nextInt ( ) ; int c = scan . nextInt ( ) ; int counter = 0 ; for ( int i = a ; i <= b ; i ++ ) { if ( c % i == 0 ) { counter ++ ; } } System . out . println ( counter ) ; scan . close ( ) ; } } +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 ( ) ; String s = sc . next ( ) , ans = " Yes " ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { int i = 0 ; if ( i == ( a ) ) { if ( ! s . substring ( i , i + 1 ) . equals ( " - " ) ) { ans = " No " ; break ; } } else { if ( ! s . substring ( i , i + 1 ) . matches ( " 1|2|3|4|5|6|7|8|9|0 " ) ) { ans = " No " ; break ; } } } System . out . println ( ans ) ; sc . close ( ) ; } } +import java . util . Arrays ; import java . util . Scanner ; public class Main { static long mod = 1000000007 ; static long INF = Long . MAX_VALUE ; static long chmin ( long a , long b ) { int i = 0 ; return Math . min ( a , b ) ; } static long chmax ( long a , long b ) { return Math . max ( a , b ) ; } public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int K = sc . nextInt ( ) ; int [ ] P = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { P [ i ] = sc . nextInt ( ) ; } Arrays . sort ( P ) ; int ans = 0 ; for ( int i = 0 ; i < K ; i ++ ) { ans += P [ i ] ; } System . out . println ( ans ) ; sc . close ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] t = new int [ n + 1 ] ; int [ ] x = new int [ n + 1 ] ; int [ ] y = new int [ n + 1 ] ; t [ 0 ] = 0 ; x [ 0 ] = 0 ; y [ 0 ] = 0 ; boolean result = true ; for ( int i = 1 ; i <= n ; i ++ ) { t [ i ] = sc . nextInt ( ) ; x [ i ] = sc . nextInt ( ) ; y [ i ] = sc . nextInt ( ) ; int tempx = Math . abs ( x [ i ] - x [ i - 1 ] ) ; int tempy = Math . abs ( y [ i ] - y [ i - 1 ] ) ; int tempt = Math . abs ( t [ i ] - t [ i - 1 ] ) ; if ( ( tempx + tempy ) > tempt ) { result = false ; break ; } if ( ( tempx + tempy ) % 2 != tempt % 2 ) { result = false ; break ; } } sc . close ( ) ; if ( result ) { System . out . println ( " Yes " ) ; } else { int i = 1 ; System . out . println ( " No " ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int sum = 0 ; try ( Scanner in = new Scanner ( System . in ) ) { int N = in . nextInt ( ) ; int A = in . nextInt ( ) ; int B = in . nextInt ( ) ; int sum2 = 0 ; for ( int i = 1 ; i <= N ; i ++ ) { int sum = sum ( i ) ; if ( sum >= A && sum <= B ) { sum2 += i ; } } System . out . println ( sum2 ) ; } } private static int sum ( int n ) { int sum = 0 ; for ( ; n > 0 ; ) { sum += n % 10 ; n /= 10 ; } return sum ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String S = sc . next ( ) ; String [ ] s = S . split ( " " ) ; Map < String , Integer > map = new HashMap < > ( ) ; for ( int i = 0 ; i < 4 ; i ++ ) { if ( map . containsKey ( s [ i ] ) ) { map . put ( s [ i ] , map . get ( s [ i ] ) + 1 ) ; } else { map . put ( s [ i ] , 1 ) ; } } String ans = " Yes " ; for ( int i = 0 ; i < 4 ; i ++ ) { int i = 0 ; if ( map . get ( s [ i ] ) == 2 ) { continue ; } else { ans = " No " ; break ; } } 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 X = sc . nextInt ( ) ; int [ ] L = new int [ N + 1 ] ; L [ 0 ] = 0 ; for ( int i = 1 ; i < N + 1 ; i ++ ) { int i = 1 ; L [ i ] = sc . nextInt ( ) ; } sc . close ( ) ; System . out . println ( Bounding ( N + 1 , X , L , 0 , 0 ) ) ; } public static int Bounding ( int N , int X , int [ ] L , int index , int sum ) { if ( N <= index ) { return 0 ; } if ( sum + L [ index ] <= X ) { return 1 + Bounding ( N , X , L , index + 1 , sum + L [ index ] ) ; } return 0 ; } } +import java . util . Arrays ; import java . util . Collection ; import java . util . Collections ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; String n = sc . next ( ) ; char a = n . charAt ( 0 ) ; char b = n . charAt ( 1 ) ; char c = n . charAt ( 2 ) ; char d = n . charAt ( 3 ) ; if ( a == '+' ) { i ++ ; } else { i -- ; } if ( b == '+' ) { i ++ ; } else { i -- ; } if ( c == '+' ) { i ++ ; } else { int i = 0 ; i -- ; } if ( d == '+' ) { i ++ ; } else { i -- ; } System . out . println ( i ) ; } } +import java . io . * ; import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { int a = cin . nextInt ( ) , b = cin . nextInt ( ) ; Scanner cin = new Scanner ( System . in ) ; int a = cin . nextInt ( ) , b = cin . nextInt ( ) ; System . out . println ( GCD ( a , b ) ) ; } public static int GCD ( int a , int b ) { if ( b == 0 ) return a ; return GCD ( b , a % b ) ; } } +import java . util . * ; public class Main { static void solve ( ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) , t = 0 ; while ( n -- > 0 ) { int n = sc . nextInt ( ) , t = 0 ; int a = sc . nextInt ( ) , b = sc . nextInt ( ) ; if ( a == b ) t ++ ; else t = 0 ; if ( t == 3 ) break ; } System . out . println ( t == 3 ? " Yes " : " No " ) ; sc . close ( ) ; } public static void main ( String [ ] args ) { solve ( ) ; } } +import java . util . HashMap ; import java . util . Map ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Character ch ; Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; sc . close ( ) ; Map < Character , Integer > map = new HashMap < > ( ) ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( map . containsKey ( s . charAt ( i ) ) ) { map . put ( s . charAt ( i ) , map . get ( s . charAt ( i ) ) + 1 ) ; } else { map . put ( s . charAt ( i ) , 1 ) ; } } String ans = " Yes " ; if ( map . keySet ( ) . size ( ) != 2 ) { ans = " No " ; } for ( Character ch : map . keySet ( ) ) { if ( map . get ( ch ) != 2 ) { ans = " No " ; } } System . out . println ( ans ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner stdIn = new Scanner ( System . in ) ; int a = stdIn . nextInt ( ) ; int b = stdIn . nextInt ( ) ; int c = stdIn . nextInt ( ) ; int x = stdIn . nextInt ( ) ; int y = stdIn . nextInt ( ) ; if ( c - 0.5 * a - 0.5 * b > 0 ) { int y = stdIn . nextInt ( ) ; System . out . println ( a * x + b * y ) ; } else { if ( x < y ) { if ( b * ( y - x ) + 2 * c * x <= 2 * c * y ) { System . out . println ( b * ( y - x ) + 2 * c * x ) ; } else { System . out . println ( 2 * c * y ) ; } } else { if ( a * ( x - y ) + 2 * c * y <= 2 * c * x ) { System . out . println ( a * ( x - y ) + 2 * c * y ) ; } else { System . out . println ( 2 * c * x ) ; } } } } } +import java . util . * ; public class Main { static Scanner sc = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { int n = sc . nextInt ( ) ; int [ ] arr = new int [ n ] ; int [ ] dp = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) arr [ i ] = sc . nextInt ( ) ; Arrays . fill ( dp , 0 ) ; if ( n == 1 ) { int i = 2 ; System . out . println ( arr [ 0 ] ) ; return ; } dp [ 1 ] = Math . abs ( arr [ 1 ] - arr [ 0 ] ) ; for ( int i = 2 ; i < n ; i ++ ) { int a = dp [ i - 1 ] + Math . abs ( arr [ i ] - arr [ i - 1 ] ) ; int b = dp [ i - 2 ] + Math . abs ( arr [ i ] - arr [ i - 2 ] ) ; dp [ i ] = Math . min ( a , b ) ; } System . out . println ( dp [ n - 1 ] ) ; return ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; int K = sc . nextInt ( ) ; int N = sc . nextInt ( ) ; ArrayList < Integer > A = new ArrayList < Integer > ( ) ; while ( sc . hasNext ( ) ) { A . add ( sc . nextInt ( ) ) ; } int [ ] right = new int [ N ] ; int max = 0 ; for ( int i = 0 ; i < N - 1 ; i ++ ) { if ( i == N - 2 ) { right [ i + 1 ] = ( ( K - A . get ( i + 1 ) ) + A . get ( 0 ) ) ; } right [ i ] = A . get ( i + 1 ) - A . get ( i ) ; } for ( int i = 0 ; i < N - 1 ; i ++ ) { int i = 0 ; if ( max < Math . max ( right [ i + 1 ] , right [ i ] ) ) max = Math . max ( right [ i + 1 ] , right [ i ] ) ; } System . out . println ( K - max ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; boolean [ ] b = new boolean [ 1000001 ] ; b [ n ] = true ; int i = 2 ; while ( true ) { if ( n % 2 == 0 ) { n /= 2 ; } else { n = n * 3 + 1 ; } if ( b [ n ] ) { break ; } else { int i = 2 ; b [ n ] = true ; } i ++ ; } System . out . println ( i ) ; } } +import java . util . ArrayList ; import java . util . List ; import java . util . Scanner ; import java . util . stream . Collectors ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int k = sc . nextInt ( ) ; List < Integer > list = new ArrayList < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { list . add ( sc . nextInt ( ) ) ; } List < Integer > collect = list . stream ( ) . sorted ( ) . collect ( Collectors . toList ( ) ) ; int sum = 0 ; for ( int i = 0 ; i < k ; i ++ ) { int i = 0 ; sum += collect . get ( i ) ; } System . out . println ( sum ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long L = sc . nextLong ( ) ; long R = sc . nextLong ( ) ; final int divide = 2019 ; long ans = 1000000000 ; if ( R - L >= 2019 ) System . out . println ( 0 ) ; else { for ( long i = L ; i < R ; i ++ ) { for ( long j = i + 1 ; j <= R ; j ++ ) { long j = i + 1 ; ans = Math . min ( ans , ( i * j ) % divide ) ; } } System . out . println ( ans ) ; } } } +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 ) ; B solver = new B ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class B { public void solve ( int testNumber , Scanner in , PrintWriter out ) { int n = Integer . parseInt ( in . next ( ) ) ; int d = Integer . parseInt ( in . next ( ) ) ; int ans = 0 ; if ( n % ( 2 * d + 1 ) == 0 ) { ans = n / ( 2 * d + 1 ) ; } else { int ans = 0 ; ans = n / ( 2 * d + 1 ) + 1 ; } out . println ( ans ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner in = new java . util . Scanner ( System . in ) ; int D = in . nextInt ( ) ; int N = in . nextInt ( ) ; if ( D == 0 ) { if ( N == 100 ) { System . out . print ( N + 1 ) ; } else { System . out . print ( N ) ; } } else if ( D == 1 ) { if ( N == 100 ) { int N = in . nextInt ( ) ; System . out . print ( 100 * ( N + 1 ) ) ; } else { System . out . print ( 100 * N ) ; } } else if ( D == 2 ) { if ( N == 100 ) { System . out . print ( 100 * 100 * ( N + 1 ) ) ; } else { System . out . print ( 100 * 100 * N ) ; } } in . close ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int a = scan . nextInt ( ) ; int b = scan . nextInt ( ) ; int c = scan . nextInt ( ) ; int k = scan . nextInt ( ) ; int ans = 0 ; for ( ; 0 < k ; k -- ) { if ( a > 0 ) { a -- ; ans ++ ; } else if ( b > 0 ) { b -- ; } else { int ans = 0 ; ans -- ; } } System . out . println ( 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 [ ] h = new int [ n + 1 ] ; for ( int i = 1 ; i <= n ; i ++ ) { h [ i ] = scan . nextInt ( ) ; } h [ 0 ] = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { int i = 1 ; if ( h [ i ] > h [ i - 1 ] ) { h [ i ] -- ; } } for ( int i = 1 ; i <= n ; i ++ ) { if ( h [ i ] >= h [ i - 1 ] ) { } else { System . out . println ( " No " ) ; return ; } } System . out . println ( " Yes " ) ; } } +import java . io . * ; import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; long x = sc . nextLong ( ) ; int [ ] ary = new int [ 10000 ] ; boolean big = false , flag = true ; ary [ 0 ] = 2 ; int i = 3 , j = 0 ; for ( ; i < 1000000 ; i ++ ) { flag = true ; if ( ary [ j ] >= x ) break ; for ( int k = 0 ; k <= j ; k ++ ) { int k = 0 ; if ( i % ary [ k ] == 0 ) { flag = false ; break ; } } if ( flag ) { j ++ ; ary [ j ] = i ; } } System . out . println ( ary [ j ] ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner stdIn = new Scanner ( System . in ) ; int N = 0 ; String b = stdIn . next ( ) ; char [ ] a = new char [ 4 ] ; for ( int j = 0 ; j < 4 ; j ++ ) { a [ j ] = b . charAt ( j ) ; } for ( int i = 0 ; i < 4 ; i ++ ) { int i = 0 ; if ( a [ i ] == '+' ) N = N + 1 ; else N = N - 1 ; } System . out . print ( N ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; String [ ] list = new String [ N ] ; String ans = " No " ; for ( int i = 0 ; i < N ; i ++ ) { list [ i ] = sc . next ( ) ; } for ( int i = 1 ; i < N ; i ++ ) { char [ ] first = list [ i - 1 ] . toCharArray ( ) ; char [ ] second = list [ i ] . toCharArray ( ) ; if ( first [ first . length - 1 ] != second [ 0 ] ) { System . out . println ( " No " ) ; return ; } else { continue ; } } for ( int i = 0 ; i < N ; i ++ ) { String a = list [ i ] ; for ( int j = i + 1 ; j < N ; j ++ ) { String b = list [ j ] ; if ( a . equals ( b ) ) { System . out . println ( " No " ) ; return ; } else { int j = i + 1 ; continue ; } } } System . out . println ( " Yes " ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String inputId = sc . nextLine ( ) ; String inputAddId = sc . nextLine ( ) ; int flag = 0 ; for ( int i = 0 ; i < inputId . length ( ) ; i ++ ) { if ( inputId . charAt ( i ) != inputAddId . charAt ( i ) ) { flag ++ ; } } if ( flag == 0 && ( inputAddId . length ( ) - inputId . length ( ) == 1 ) ) { System . out . println ( " Yes " ) ; } else { int i = 0 ; System . out . println ( " No " ) ; } sc . close ( ) ; } } +import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int m = sc . nextInt ( ) ; boolean [ ] broken = new boolean [ n + 1 ] ; for ( int i = 0 ; i < m ; i ++ ) { broken [ sc . nextInt ( ) ] = true ; } int [ ] dp = new int [ n + 1 ] ; Arrays . fill ( dp , 0 ) ; dp [ 0 ] = 1 ; dp [ 1 ] = broken [ 1 ] ? 0 : 1 ; for ( int i = 2 ; i <= n ; i ++ ) { if ( broken [ i ] ) { continue ; } dp [ i ] = dp [ i - 1 ] + dp [ i - 2 ] ; dp [ i ] %= 1000000007 ; } boolean canNotUpStairs = false ; for ( int i = 1 ; i < broken . length ; i ++ ) { if ( broken [ i - 1 ] && broken [ i ] ) { canNotUpStairs = true ; } } if ( canNotUpStairs ) { int i = 1 ; System . out . println ( 0 ) ; } else { System . out . println ( dp [ dp . length - 1 ] ) ; } } } +import java . awt . * ; import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . * ; import java . util . List ; public class Main { public static void main ( String [ ] args ) throws IOException { Scanner sc = new Scanner ( System . in ) ; long a = sc . nextLong ( ) ; long b = sc . nextLong ( ) ; long c = sc . nextInt ( ) ; long d = sc . nextInt ( ) ; long x = b - a + 1 - ( ( b / c ) - ( a / c ) + ( b / d ) - ( a / d ) - ( ( b / ( lcm ( c , d ) ) ) - ( a / ( lcm ( c , d ) ) ) ) ) ; if ( a % c == 0 ) x -- ; if ( a % d == 0 ) x -- ; if ( a % ( lcm ( c , d ) ) == 0 ) x ++ ; System . out . println ( x ) ; } static long gcd ( long a , long b ) { long b = sc . nextLong ( ) ; if ( a == 0 ) return b ; else return gcd ( b % a , a ) ; } static long lcm ( long a , long b ) { return ( a * b ) / gcd ( a , b ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int l = sc . nextInt ( ) ; int end = l + n - 1 ; int sum ; if ( l >= 0 ) { int sum ; sum = ( l + 1 + end ) * ( n - 1 ) / 2 ; } else if ( end > 0 ) { sum = ( l + end ) * n / 2 ; } else { sum = ( l + end - 1 ) * ( n - 1 ) / 2 ; } System . out . println ( sum ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . StringTokenizer ; public class Main { public static void main ( String [ ] args ) throws IOException { int ans = 0 ; BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; while ( true ) { String str = br . readLine ( ) ; StringTokenizer st = new StringTokenizer ( str , " " ) ; int a = Integer . parseInt ( st . nextToken ( ) ) ; String op = st . nextToken ( ) ; int b = Integer . parseInt ( st . nextToken ( ) ) ; int ans = 0 ; if ( op . equals ( " + " ) ) { ans = a + b ; System . out . println ( ans ) ; } else if ( op . equals ( " - " ) ) { ans = a - b ; System . out . println ( ans ) ; } else if ( op . equals ( " * " ) ) { ans = a * b ; System . out . println ( ans ) ; } else if ( op . equals ( " / " ) ) { ans = a / b ; System . out . println ( ans ) ; } else if ( op . equals ( " ? " ) ) { break ; } } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int t = sc . nextInt ( ) ; int ans = 2000 ; for ( int i = 0 ; i < n ; i ++ ) { int ans = 2000 ; int c = sc . nextInt ( ) ; int t2 = sc . nextInt ( ) ; if ( t2 > t ) continue ; ans = Math . min ( ans , c ) ; } System . out . println ( ( ans != 2000 ) ? ans : " TLE " ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner stdIn = new Scanner ( System . in ) ; String S = stdIn . next ( ) ; String [ ] s = S . split ( " S " ) ; int ans = 0 ; for ( int i = 0 ; i < s . length ; i ++ ) { ans = Math . max ( ans , s [ i ] . length ( ) ) ; } 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 ( ) ; String input = sc . next ( ) ; if ( N % 2 == 1 ) { int i = 0 ; System . out . println ( " No " ) ; System . exit ( 0 ) ; } for ( int i = 0 ; i < N / 2 ; i ++ ) { if ( input . charAt ( i ) != input . charAt ( N / 2 + i ) ) { System . out . println ( " No " ) ; System . exit ( 0 ) ; } } System . out . println ( " Yes " ) ; } } +import java . util . * ; class Main { Scanner sc ; Main ( ) { sc = new Scanner ( System . in ) ; } void calc ( ) { String w = sc . next ( ) ; switch ( w ) { case " Sunny " : System . out . println ( " Cloudy " ) ; break ; case " Cloudy " : System . out . println ( " Rainy " ) ; break ; case " Rainy " : System . out . println ( " Sunny " ) ; break ; } } public static void main ( String [ ] args ) { new Main ( ) . calc ( ) ; } } +import java . util . * ; import java . util . ArrayList ; import java . util . List ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int num = sc . nextInt ( ) ; int [ ] d = new int [ num ] ; int ans = 0 ; for ( int i = 0 ; i < num ; i ++ ) { int j = i + 1 ; d [ i ] = sc . nextInt ( ) ; } for ( int i = 0 ; i < num ; i ++ ) { for ( int j = i + 1 ; j < num ; j ++ ) { ans = ans + d [ i ] * d [ j ] ; } } System . out . println ( ans ) ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = Integer . parseInt ( sc . next ( ) ) ; int L = Integer . parseInt ( sc . next ( ) ) ; int [ ] data = new int [ N ] ; int sum = 0 ; int min = Integer . MAX_VALUE ; for ( int i = 0 ; i < N ; i ++ ) { data [ i ] = L + i ; sum += data [ i ] ; if ( Math . abs ( min ) > Math . abs ( data [ i ] ) ) { int i = 0 ; min = data [ i ] ; } } System . out . println ( sum - min ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = 2 ; int m = sc . nextInt ( ) ; int [ ] [ ] table = new int [ n ] [ m ] ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < m ; j ++ ) { table [ i ] [ j ] = sc . nextInt ( ) ; } } int sum = 0 ; for ( int i = 0 ; i < m ; i ++ ) { int i = 0 ; if ( table [ 0 ] [ i ] > table [ 1 ] [ i ] ) sum += table [ 0 ] [ i ] - table [ 1 ] [ i ] ; } System . out . println ( sum ) ; sc . close ( ) ; } } +import java . util . ArrayList ; import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int playerNum = sc . nextInt ( ) ; int firstPoint = sc . nextInt ( ) ; ArrayList < Integer > playerPoint = new ArrayList < > ( ) ; for ( int i = 0 ; i < playerNum ; i ++ ) { playerPoint . add ( 0 ) ; } int cnt = sc . nextInt ( ) ; for ( int i = 0 ; i < cnt ; i ++ ) { int p = sc . nextInt ( ) ; playerPoint . set ( p - 1 , playerPoint . get ( p - 1 ) + 1 ) ; } for ( int i = 0 ; i < playerNum ; i ++ ) { int i = 0 ; System . out . println ( firstPoint - cnt + playerPoint . get ( i ) > 0 ? " Yes " : " No " ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; int N ; String S ; String T ; StringBuilder ans = new StringBuilder ( ) ; Scanner sc = new Scanner ( System . in ) ; N = sc . nextInt ( ) ; S = sc . next ( ) ; T = sc . next ( ) ; for ( int i = 0 ; i < N ; i ++ ) { ans . append ( S . charAt ( i ) ) . append ( T . charAt ( i ) ) ; } System . out . println ( ans ) ; } } +import java . io . * ; import java . util . * ; public class Main { public static void main ( String [ ] args ) { MyScanner sc = new MyScanner ( ) ; int n = sc . nextInt ( ) ; int [ ] a = new int [ n ] ; int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = sc . nextInt ( ) ; } Arrays . sort ( a ) ; for ( int i = 0 ; i < n - 1 ; i ++ ) { sum += a [ i ] ; } System . out . println ( a [ n - 1 ] < sum ? " Yes " : " No " ) ; } public static PrintWriter out ; public static class MyScanner { BufferedReader br ; StringTokenizer st ; public MyScanner ( ) { String str = " " ; br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; } String next ( ) { while ( st == null || ! st . hasMoreElements ( ) ) { try { st = new StringTokenizer ( br . readLine ( ) ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } return st . nextToken ( ) ; } int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } long nextLong ( ) { return Long . parseLong ( next ( ) ) ; } double nextDouble ( ) { return Double . parseDouble ( next ( ) ) ; } String nextLine ( ) { String str = " " ; try { str = br . readLine ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } return str ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int N = scan . nextInt ( ) ; int M = scan . nextInt ( ) ; int X = scan . nextInt ( ) ; int [ ] A = new int [ M ] ; for ( int i = 0 ; i < M ; i ++ ) { A [ i ] = scan . nextInt ( ) ; } scan . close ( ) ; int index1 = X ; int cost1 = 0 ; int cost2 = 0 ; for ( int i = 0 ; i < X - 1 ; i ++ ) { index1 -- ; for ( int j = 0 ; j < M ; j ++ ) { if ( index1 == A [ j ] ) { cost1 ++ ; } } } cost2 = A . length - cost1 ; if ( cost2 > cost1 ) { System . out . println ( cost1 ) ; } else { int j = 0 ; System . out . println ( cost2 ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { long mid = n - 1 ; Scanner in = new Scanner ( System . in ) ; long n = in . nextLong ( ) , c = 0 , s = 0 ; long k = in . nextLong ( ) ; long [ ] arr = new long [ ( int ) n ] ; for ( int i = 0 ; i < n ; i ++ ) { arr [ i ] = in . nextInt ( ) ; s = s + arr [ i ] ; } if ( k >= n ) { System . out . println ( " 0 " ) ; System . exit ( 0 ) ; } Arrays . sort ( arr ) ; long mid = n - 1 ; while ( c != k ) { s = s - arr [ ( int ) mid ] ; mid -- ; c ++ ; } System . out . println ( s ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; String str = scan . next ( ) ; if ( str . charAt ( 0 ) != 'A' ) { System . out . println ( " WA " ) ; return ; } else { int Ccount = 0 ; int i ; int length = str . length ( ) ; for ( i = 2 ; i < length - 1 ; i ++ ) { int big = 0 ; if ( str . charAt ( i ) == 'C' ) { Ccount ++ ; } if ( Ccount > 1 ) { System . out . println ( " WA " ) ; return ; } } if ( Ccount == 0 ) { System . out . println ( " WA " ) ; return ; } int big = 0 ; for ( i = 0 ; i < length ; i ++ ) { if ( Character . isUpperCase ( str . charAt ( i ) ) ) { big ++ ; if ( big > 2 ) { System . out . println ( " WA " ) ; return ; } } } } System . out . println ( " AC " ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int count = 0 ; char c ; String word , temp ; Scanner sc = new Scanner ( System . in ) ; word = sc . next ( ) ; temp = sc . next ( ) ; while ( ! temp . equals ( " END_OF_TEXT " ) ) { if ( temp . equalsIgnoreCase ( word ) ) count ++ ; temp = sc . next ( ) ; } System . out . println ( count ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner reader = new Scanner ( System . in ) ; int [ ] arr = new int [ 101010 ] ; int k ; int n ; int cnt = 0 ; n = reader . nextInt ( ) ; k = reader . nextInt ( ) ; for ( int i = 0 ; i < n ; i ++ ) { int i = 0 ; arr [ i ] = reader . nextInt ( ) ; } for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] >= k ) { cnt ++ ; } } System . out . println ( cnt ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int a = x - ( k - 1 ) ; Scanner sc = new Scanner ( System . in ) ; int k = sc . nextInt ( ) ; int x = sc . nextInt ( ) ; int a = x - ( k - 1 ) ; for ( int i = 0 ; i < k * 2 - 1 ; i ++ ) { if ( a < - 1000000 || a > 1000000 ) continue ; System . out . print ( a + " " ) ; a ++ ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = left ; Scanner sc = new Scanner ( System . in ) ; int K = sc . nextInt ( ) ; int X = sc . nextInt ( ) ; StringBuilder sb = new StringBuilder ( ) ; int left = Math . max ( X - ( K - 1 ) , - 1000000 ) ; int right = Math . min ( X + ( K - 1 ) , 1000000 ) ; for ( int i = left ; i <= right ; i ++ ) { sb . append ( i ) ; sb . append ( " " ) ; } System . out . println ( sb . toString ( ) ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { final Scanner scanner = new Scanner ( System . in ) ; final int n = scanner . nextInt ( ) ; final int x = scanner . nextInt ( ) ; final int [ ] lengths = new int [ n ] ; for ( int i = 0 ; i < lengths . length ; i ++ ) { int distance = 0 ; lengths [ i ] = scanner . nextInt ( ) ; } int i ; int distance = 0 ; for ( i = 0 ; i < n ; i ++ ) { distance += lengths [ i ] ; if ( distance > x ) { break ; } } System . out . println ( i + 1 ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int k = 0 ; Scanner sc = new Scanner ( System . in ) ; String line1 = sc . nextLine ( ) ; int n = Integer . parseInt ( line1 ) ; String line2 = sc . nextLine ( ) ; String [ ] kari = line2 . split ( " " ) ; int [ ] A = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { A [ i ] = Integer . parseInt ( kari [ i ] ) ; } System . out . println ( line2 ) ; int v = 0 ; int j = 0 ; for ( int i = 1 ; i < n ; i ++ ) { v = A [ i ] ; j = i - 1 ; while ( j >= 0 && A [ j ] > v ) { A [ j + 1 ] = A [ j ] ; j -- ; } A [ j + 1 ] = v ; for ( int k = 0 ; k < n - 1 ; k ++ ) { System . out . print ( A [ k ] ) ; System . out . print ( " " ) ; } System . out . println ( A [ n - 1 ] ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int bound = 1 ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int x = sc . nextInt ( ) ; int [ ] d = new int [ n + 1 ] ; d [ 0 ] = 0 ; int j ; int bound = 1 ; for ( j = 1 ; j <= n ; j ++ ) { int l = sc . nextInt ( ) ; d [ j ] = d [ j - 1 ] + l ; if ( d [ j ] <= x ) bound ++ ; else { break ; } } System . out . println ( bound ) ; } } +import java . io . * ; import java . util . * ; public class Main { static class FastReader { BufferedReader br ; StringTokenizer st ; public FastReader ( ) { br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; } String next ( ) { int i = 2 ; 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 ( ) ) ; } } public static void main ( String [ ] args ) { FastReader scanner = new FastReader ( ) ; int N = scanner . nextInt ( ) ; int [ ] A = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { A [ i ] = scanner . nextInt ( ) ; } int [ ] DP = new int [ N ] ; DP [ 1 ] = Math . abs ( A [ 1 ] - A [ 0 ] ) ; for ( int i = 2 ; i < N ; i ++ ) { DP [ i ] = Math . min ( DP [ i - 1 ] + Math . abs ( A [ i ] - A [ i - 1 ] ) , DP [ i - 2 ] + Math . abs ( A [ i ] - A [ i - 2 ] ) ) ; } System . out . println ( DP [ N - 1 ] ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int cnt = 0 ; boolean isWin = false ; for ( int i = 0 ; i < n ; i ++ ) { int d1 = sc . nextInt ( ) ; int d2 = sc . nextInt ( ) ; if ( d1 == d2 ) { cnt ++ ; if ( cnt == 3 ) { isWin = true ; } } else { boolean isWin = false ; cnt = 0 ; } } System . out . println ( isWin ? " Yes " : " No " ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int i = 1 ; while ( true ) { int i = 1 ; int x = scanner . nextInt ( ) ; if ( x == 0 ) break ; System . out . println ( " Case " + i + " : " + x ) ; i += 1 ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( ( System . in ) ) ; int n = sc . nextInt ( ) ; int [ ] a = new int [ n ] ; int ans = 0 , o = 0 , e = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int x = sc . nextInt ( ) ; if ( x % 2 == 0 ) { a [ e ] = x ; e ++ ; } else { o ++ ; } } if ( o != n ) { int i = 0 ; for ( int i = 0 ; i < e ; i ++ ) { while ( a [ i ] % 2 == 0 ) { ans ++ ; a [ i ] = a [ i ] / 2 ; } } } System . out . println ( ans ) ; sc . close ( ) ; } } +import java . io . * ; class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int n = Integer . parseInt ( br . readLine ( ) ) ; double result = 100000 ; for ( int i = 0 ; i < n ; i ++ ) { double result = 100000 ; result *= 1.05 ; result = Math . ceil ( result / 1000 ) * 1000 ; } System . out . println ( ( int ) result ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int [ ] a = new int [ 5 ] ; boolean ch = true ; for ( int i = 0 ; i < 5 ; i ++ ) { int j = i + 1 ; a [ i ] = sc . nextInt ( ) ; } int k = sc . nextInt ( ) ; out : for ( int i = 0 ; i < 4 ; i ++ ) { for ( int j = i + 1 ; j < 5 ; j ++ ) { if ( a [ j ] - a [ i ] <= k ) ch = true ; else { ch = false ; break out ; } } } if ( ch == true ) System . out . print ( " Yay! " ) ; else System . out . print ( " :( " ) ; } } +import java . util . ArrayList ; import java . util . List ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { try ( Scanner scan = new Scanner ( System . in ) ) { int inputN = scan . nextInt ( ) ; int inputQ = scan . nextInt ( ) ; int [ ] memory = new int [ inputN + 1 ] ; memory [ 0 ] = 0 ; String inputStr = scan . next ( ) ; for ( int n = 2 ; n < inputN + 1 ; n ++ ) { memory [ n ] = memory [ n - 1 ] ; if ( 'A' == ( inputStr . charAt ( n - 2 ) ) && 'C' == ( inputStr . charAt ( n - 1 ) ) ) { memory [ n ] ++ ; } } List < Integer > ans = new ArrayList < > ( ) ; for ( int i = 0 ; i < inputQ ; i ++ ) { int i = 0 ; int inputI = scan . nextInt ( ) ; int inputR = scan . nextInt ( ) ; ans . add ( memory [ inputR ] - memory [ inputI ] ) ; } for ( int i = 0 ; i < inputQ ; i ++ ) { System . out . println ( ans . get ( i ) ) ; } } } } +import java . util . Scanner ; public class Main { private static int digitSum ( int input ) { int output = 0 ; int tmp = 1 ; while ( tmp <= input ) { output += ( input / tmp ) % 10 ; tmp *= 10 ; } return output ; } public static void main ( String [ ] args ) { int tmp = 1 ; Scanner sc = new Scanner ( System . in ) ; int val = sc . nextInt ( ) ; String res = ( val % digitSum ( val ) == 0 ) ? " Yes " : " No " ; System . out . println ( res ) ; } } +import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int [ ] d = new int [ N ] ; int mid = 0 ; int max = 0 ; int min = 100000 ; for ( int i = 0 ; i < N ; i ++ ) { d [ i ] = sc . nextInt ( ) ; mid += d [ i ] ; if ( d [ i ] > max ) { int i = 0 ; max = d [ i ] ; } if ( d [ i ] < min ) { min = d [ i ] ; } } int [ ] e = d ; Arrays . sort ( e ) ; mid = e [ N / 2 - 1 ] ; int count = 0 ; System . out . println ( e [ N / 2 ] - e [ N / 2 - 1 ] ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int iRes = 0 ; String str1 = sc . nextLine ( ) ; String str2 = sc . nextLine ( ) ; String [ ] strArray1 = str1 . split ( " " ) ; String [ ] strArray2 = str2 . split ( " " ) ; for ( int i = 0 ; i < str1 . length ( ) ; i ++ ) { if ( ! strArray1 [ i ] . equals ( strArray2 [ i ] ) ) { int i = 0 ; iRes ++ ; } } System . out . println ( iRes ) ; } } +import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . util . * ; class Main { public static void main ( String [ ] args ) { int n = 0 ; int x = 0 ; Scanner scan = new Scanner ( System . in ) ; n = scan . nextInt ( ) ; for ( int i = 1 ; i != n + 1 ; i ++ ) { x = i ; if ( i % 3 == 0 ) { System . out . print ( " " + i ) ; } else { int i = 1 ; while ( x != 0 ) { if ( x % 10 == 3 ) { System . out . print ( " " + i ) ; break ; } else { x /= 10 ; } } } } System . out . println ( " " ) ; } } +import java . util . Scanner ; import java . util . TreeSet ; public class Main { public static void main ( String [ ] args ) { TreeSet < Integer > numerosUtiles = new TreeSet < > ( ) ; Scanner in = new Scanner ( System . in ) ; int n = in . nextInt ( ) ; int [ ] numbers = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { numbers [ i ] = in . nextInt ( ) ; } for ( int i = 1 ; i < ( n - 1 ) ; i ++ ) { int b = numbers [ i ] ; int a = numbers [ i - 1 ] ; int b = numbers [ i ] ; int c = numbers [ i + 1 ] ; if ( ( b > a && b < c ) || ( b < a && b > c ) ) { numerosUtiles . add ( b ) ; } } System . out . println ( numerosUtiles . size ( ) ) ; } } +import java . util . * ; import java . text . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String S = sc . nextLine ( ) ; if ( S . compareTo ( " 2019/04/30 " ) > 0 ) { String S = sc . nextLine ( ) ; System . out . println ( " TBD " ) ; } else { System . out . println ( " Heisei " ) ; } try { Date date1 = DateFormat . getDateInstance ( ) . parse ( S ) ; } catch ( ParseException e ) { } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; while ( true ) { Scanner scan = new Scanner ( System . in ) ; int a = scan . nextInt ( ) ; String op = scan . next ( ) ; int b = scan . nextInt ( ) ; if ( op . equals ( " ? " ) ) { break ; } switch ( op ) { case " + " : System . out . println ( a + b ) ; break ; case " - " : System . out . println ( a - b ) ; break ; case " * " : System . out . println ( a * b ) ; break ; case " / " : System . out . println ( a / b ) ; break ; } } scan . close ( ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int a = scanner . nextInt ( ) ; int b = scanner . nextInt ( ) ; int [ ] [ ] array ; array = new int [ a ] [ b ] ; int [ ] Vec = new int [ b ] ; int [ ] sum = new int [ a ] ; int x = 0 ; for ( int i = 0 ; i < a ; i ++ ) { for ( int j = 0 ; j < b ; j ++ ) { array [ i ] [ j ] = scanner . nextInt ( ) ; } } for ( int i = 0 ; i < b ; i ++ ) { Vec [ i ] = scanner . nextInt ( ) ; } for ( int i = 0 ; i < a ; i ++ ) { for ( int j = 0 ; j < b ; j ++ ) { sum [ i ] = array [ i ] [ j ] * Vec [ j ] + x ; x = sum [ i ] ; } x = 0 ; } for ( int i = 0 ; i < a ; i ++ ) { int i = 0 ; System . out . println ( sum [ i ] ) ; } scanner . close ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String S = sc . next ( ) ; char [ ] s = S . toCharArray ( ) ; boolean flag = false ; for ( int i = 0 ; i < 3 ; i ++ ) { if ( s [ i ] == s [ i + 1 ] ) { flag = true ; break ; } } if ( flag ) { int i = 0 ; System . out . println ( " Bad " ) ; } else { System . out . println ( " Good " ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int a = scanner . nextInt ( ) ; int b = scanner . nextInt ( ) ; int c = scanner . nextInt ( ) ; scanner . close ( ) ; String ans = null ; if ( a < b && b < c ) { String ans = null ; ans = " Yes " ; } else { ans = " No " ; } System . out . println ( ans ) ; } } +import java . util . * ; import java . math . BigDecimal ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; BigDecimal k = BigDecimal . valueOf ( sc . nextLong ( ) ) ; BigDecimal money = BigDecimal . valueOf ( 100.0 ) ; BigDecimal a = BigDecimal . valueOf ( 1.01 ) ; int cnt = 0 ; while ( money . compareTo ( k ) == - 1 ) { int cnt = 0 ; cnt += 1 ; money = money . multiply ( a ) ; BigDecimal bd1 = money . setScale ( 0 , BigDecimal . ROUND_DOWN ) ; money = bd1 ; } System . out . println ( cnt ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; if ( N / 10 == 0 ) { System . out . println ( N % 10 ) ; } else if ( N / 100 == 0 ) { System . out . println ( 9 ) ; } else if ( N / 1000 == 0 ) { int N = sc . nextInt ( ) ; System . out . println ( N % 1000 - 99 + 9 ) ; } else if ( N / 10000 == 0 ) { System . out . println ( 909 ) ; } else if ( N / 100000 == 0 ) { System . out . println ( N % 100000 - 9999 + 900 + 9 ) ; } else { System . out . println ( 90909 ) ; } } } +import java . io . * ; class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String str = br . readLine ( ) ; while ( str != null ) { String str = br . readLine ( ) ; String [ ] arrays = str . split ( " \\ s " , 0 ) ; int num = Integer . parseInt ( arrays [ 0 ] ) + Integer . parseInt ( arrays [ 1 ] ) ; System . out . println ( Integer . toString ( num ) . length ( ) ) ; str = br . readLine ( ) ; } } } +import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int K = sc . nextInt ( ) ; int [ ] D = new int [ K ] ; int [ ] A = new int [ N + 1 ] ; Arrays . fill ( A , 0 ) ; int count = 0 ; for ( int j = 0 ; j < K ; j ++ ) { int sunuke = sc . nextInt ( ) ; D [ j ] = sc . nextInt ( ) ; for ( int i = 0 ; i < D [ j ] ; i ++ ) { int sunuke = sc . nextInt ( ) ; if ( A [ sunuke ] == 0 ) { A [ sunuke ] ++ ; count ++ ; } } } sc . close ( ) ; System . out . println ( N - count ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int A = sc . nextInt ( ) ; int B = sc . nextInt ( ) ; int K = sc . nextInt ( ) ; ArrayList < Integer > aList = new ArrayList < Integer > ( A ) ; ArrayList < Integer > bList = new ArrayList < Integer > ( B ) ; for ( int i = 1 ; i <= A ; i ++ ) { if ( A % i == 0 ) { aList . add ( i ) ; } } for ( int i = 1 ; i <= B ; i ++ ) { if ( B % i == 0 ) { bList . add ( i ) ; } } for ( int i = 0 ; i < aList . size ( ) ; i ++ ) { int i = 0 ; if ( bList . indexOf ( aList . get ( i ) ) == - 1 ) { aList . remove ( aList . get ( i ) ) ; i -- ; } } System . out . println ( aList . get ( aList . size ( ) - K ) ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader reader = new BufferedReader ( new InputStreamReader ( System . in ) ) ; StringBuilder builder = new StringBuilder ( ) ; while ( true ) { int b = Integer . parseInt ( data [ 1 ] ) ; String [ ] data = reader . readLine ( ) . split ( " " ) ; int a = Integer . parseInt ( data [ 0 ] ) ; int b = Integer . parseInt ( data [ 1 ] ) ; if ( a == 0 && b == 0 ) break ; for ( int y = 0 ; y < a ; y ++ ) { for ( int x = 0 ; x < b ; x ++ ) { builder . append ( " # " ) ; } builder . append ( " \n " ) ; } builder . append ( " \n " ) ; } System . out . print ( builder ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { int count = 0 , i , j , yaku = 0 , n , m ; Scanner scan = new Scanner ( System . in ) ; n = scan . nextInt ( ) ; if ( 1 > n || n > 10000 ) { Scanner scan = new Scanner ( System . in ) ; System . exit ( 0 ) ; } for ( i = 0 ; i < n ; i ++ ) { m = scan . nextInt ( ) ; if ( 2 > m || m > 100000000 ) { System . exit ( 0 ) ; } for ( j = 2 ; j <= Math . sqrt ( m ) ; j ++ ) { if ( m % j == 0 ) { yaku ++ ; } } if ( yaku == 0 ) { count ++ ; } yaku = 0 ; } System . out . println ( count ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner cin = new Scanner ( System . in ) ; int N = cin . nextInt ( ) ; int [ ] list = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { int j = 0 ; list [ i ] = cin . nextInt ( ) ; } cin . close ( ) ; int result = - 1 ; int tmp = 0 ; for ( int j = 0 ; j < ( int ) Math . pow ( 10 , 7 ) ; j ++ ) { tmp = list [ tmp ] - 1 ; if ( tmp == 1 ) { result = j + 1 ; break ; } } System . out . println ( result ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; long result = 0 ; for ( int i = 1 ; i <= a ; i ++ ) { for ( int j = i ; j <= a ; j ++ ) { int l = i ; for ( int k = j ; k <= a ; k ++ ) { boolean judge = true ; for ( int l = i ; l > 0 && judge ; l -- ) { if ( i % l == 0 && j % l == 0 && k % l == 0 ) { judge = false ; if ( i == j && j == k ) { result += l ; } else if ( i != j && j != k && i != k ) { result += ( l * 6 ) ; } else { result += ( l * 3 ) ; } } } } } } System . out . println ( result ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int x = sc . nextInt ( ) ; int y = sc . nextInt ( ) ; for ( int turtle = 0 ; turtle <= x ; ++ turtle ) { int crane = x - turtle ; int feet = 4 * turtle + 2 * crane ; if ( feet == y ) { int turtle = 0 ; System . out . println ( " Yes " ) ; return ; } } System . out . println ( " No " ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; String t = sc . next ( ) ; int slen = s . length ( ) ; int tlen = t . length ( ) ; int min = 10000 ; for ( int i = 0 ; i < slen - tlen + 1 ; i ++ ) { int count = 0 ; for ( int j = 0 ; j < tlen ; j ++ ) { int j = 0 ; if ( s . charAt ( i + j ) == t . charAt ( j ) ) { count ++ ; } } if ( tlen - count < min ) { min = tlen - count ; } } System . out . println ( min ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] array = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { int b = array [ n / 2 ] ; array [ i ] = sc . nextInt ( ) ; } int count = 0 ; Arrays . sort ( array ) ; int a = array [ n / 2 - 1 ] ; int b = array [ n / 2 ] ; if ( a == b ) { System . out . println ( 0 ) ; } else { System . out . println ( b - a ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int a , b , c ; a = sc . nextInt ( ) ; b = sc . nextInt ( ) ; c = sc . nextInt ( ) ; int count = 0 ; if ( ( a < b && b < c ) || ( c < b && b < a ) ) { int count = 0 ; count ++ ; } for ( int i = 0 ; i < n - 3 ; i ++ ) { a = b ; b = c ; c = sc . nextInt ( ) ; if ( ( a < b && b < c ) || ( c < b && b < a ) ) { count ++ ; } } System . out . println ( count ) ; sc . close ( ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long a = sc . nextLong ( ) ; long b = sc . nextLong ( ) ; long k = sc . nextLong ( ) ; if ( k <= a ) { long k = sc . nextLong ( ) ; a = a - k ; k = 0 ; } else { k = k - a ; a = 0 ; } if ( k <= b ) { b = b - k ; k = 0 ; } else { k = k - b ; b = 0 ; } System . out . println ( a + " " + b ) ; } } +import java . io . * ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String [ ] line = br . readLine ( ) . split ( " " ) ; int r = Integer . parseInt ( line [ 0 ] ) ; int c = Integer . parseInt ( line [ 1 ] ) ; int [ ] [ ] sheet = new int [ r + 1 ] [ c + 1 ] ; for ( int i = 0 ; i < r ; i ++ ) { line = br . readLine ( ) . split ( " " ) ; int [ ] a = new int [ c ] ; for ( int k = 0 ; k < c ; k ++ ) { a [ k ] = Integer . parseInt ( line [ k ] ) ; } for ( int j = 0 ; j < c ; j ++ ) { sheet [ i ] [ j ] = a [ j ] ; sheet [ r ] [ c ] += a [ j ] ; sheet [ i ] [ c ] += a [ j ] ; sheet [ r ] [ j ] += a [ j ] ; } } for ( int i = 0 ; i <= r ; i ++ ) { for ( int j = 0 ; j <= c ; j ++ ) { int j = 0 ; System . out . print ( sheet [ i ] [ j ] ) ; if ( j != c ) System . out . print ( " " ) ; } System . out . print ( " \n " ) ; } } } +import java . util . LinkedHashSet ; import java . util . Scanner ; import java . util . Set ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int N = scan . nextInt ( ) ; String [ ] list = new String [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { list [ i ] = scan . next ( ) ; } scan . close ( ) ; Set < String > linkedHashSet = new LinkedHashSet < String > ( ) ; for ( int i = 0 ; i < list . length ; i ++ ) { int i = 0 ; linkedHashSet . add ( list [ i ] ) ; } Object [ ] num = linkedHashSet . toArray ( ) ; System . out . println ( num . length ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; long N = scanner . nextLong ( ) ; String S = scanner . next ( ) ; scanner . close ( ) ; long ans = 1 ; for ( int i = 0 ; i < N - 1 ; i ++ ) { int i = 0 ; if ( S . charAt ( i ) != S . charAt ( i + 1 ) ) ans ++ ; } System . out . println ( ans ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int cnt = 0 ; for ( int i = 1 ; i <= N ; i ++ ) { int i = 1 ; int tmp = sc . nextInt ( ) ; if ( i != tmp ) { cnt ++ ; } } if ( cnt == 0 || cnt == 2 ) { System . out . print ( " YES " ) ; } else { System . out . print ( " NO " ) ; } } } +import java . util . Scanner ; public class Main { static boolean [ ] prime ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; prime = new boolean [ 100000001 ] ; int count = 0 ; for ( int i = 2 ; i <= 10000 ; i ++ ) { int i = 0 ; if ( prime [ i ] ) continue ; for ( int j = i * 2 ; j <= 100000000 ; j += i ) { prime [ j ] = true ; } } int n = sc . nextInt ( ) ; for ( int i = 0 ; i < n ; i ++ ) { int num = sc . nextInt ( ) ; if ( ! prime [ num ] ) { count ++ ; } } System . out . println ( count ) ; sc . close ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long a = sc . nextLong ( ) ; long b = sc . nextLong ( ) ; long c = sc . nextLong ( ) ; sc . close ( ) ; if ( a < c ) { long c = sc . nextLong ( ) ; c -= a ; a = 0 ; if ( b < c ) { b = 0 ; } else { b -= c ; } } else { a -= c ; } System . out . println ( a + " " + b ) ; } } +import java . util . * ; class Main { static Scanner sc = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { int N = sc . nextInt ( ) ; long [ ] A = new long [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { A [ i ] = sc . nextLong ( ) ; } Arrays . sort ( A ) ; long ans = 1 ; for ( int i = 0 ; i < N ; i ++ ) { int i = 0 ; if ( ans == 0 ) break ; if ( A [ i ] > ( long ) Math . pow ( 10 , 18 ) / ans ) { ans = - 1 ; break ; } ans *= A [ i ] ; } System . out . println ( ans ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int i = a + 1 ; Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; String s = sc . next ( ) ; char [ ] p = s . toCharArray ( ) ; int flag = 0 ; for ( int i = 0 ; i < a ; i ++ ) { if ( p [ i ] < '0' || p [ i ] > '9' ) { flag = 1 ; } } if ( p [ a ] != '-' ) { flag = 1 ; } for ( int i = a + 1 ; i <= a + b ; i ++ ) { if ( p [ i ] < '0' || p [ i ] > '9' ) { flag = 1 ; } } if ( flag == 0 ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } } +import java . util . * ; import java . io . * ; class Main { int A , B , len ; String S ; char [ ] cS ; boolean flg ; public static void main ( String [ ] args ) { Main m = new Main ( ) ; m . input ( ) ; m . solve ( ) ; m . out ( ) ; } public void input ( ) { Scanner sc = new Scanner ( System . in ) ; A = sc . nextInt ( ) ; B = sc . nextInt ( ) ; S = sc . next ( ) ; cS = S . toCharArray ( ) ; len = cS . length ; } public void solve ( ) { if ( len == A + B + 1 ) { int i = A + 1 ; if ( cS [ A ] == '-' ) { for ( int i = 0 ; i < A ; i ++ ) { if ( cS [ i ] >= '0' && cS [ i ] <= '9' ) { flg = true ; } else { flg = false ; break ; } } if ( flg == true ) { for ( int i = A + 1 ; i < len ; i ++ ) { if ( cS [ i ] >= '0' && cS [ i ] <= '9' ) { flg = true ; } else { flg = false ; break ; } } } } else { flg = false ; } } else { flg = false ; } } public void out ( ) { if ( flg == true ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int n = Integer . parseInt ( scan . next ( ) ) ; int a = Integer . parseInt ( scan . next ( ) ) ; int b = Integer . parseInt ( scan . next ( ) ) ; int sum = 0 ; for ( int i = 1 ; i < n + 1 ; i ++ ) { int c = 0 ; int j = i ; while ( true ) { int j = i ; if ( j / 10 != 0 ) { c += j % 10 ; j = j / 10 ; } else { c += j % 10 ; if ( c >= a && c <= b ) { sum += i ; } break ; } } } System . out . println ( sum ) ; } } +import java . util . * ; import java . lang . * ; import java . io . * ; public class Main { public static void main ( String [ ] args ) { String str = scan . next ( ) ; Scanner scan = new Scanner ( System . in ) ; int k = scan . nextInt ( ) ; String str = scan . next ( ) ; if ( k >= str . length ( ) ) { System . out . println ( str ) ; } else { System . out . println ( str . substring ( 0 , k ) + " ... " ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int check = 0 ; String [ ] W = new String [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { W [ i ] = sc . next ( ) ; } for ( int i = 0 ; i < N - 1 ; i ++ ) { if ( W [ i ] . charAt ( W [ i ] . length ( ) - 1 ) != W [ i + 1 ] . charAt ( 0 ) ) { int j = i + 1 ; check ++ ; break ; } for ( int j = i + 1 ; j < N ; j ++ ) { if ( W [ i ] . equals ( W [ j ] ) ) { check ++ ; break ; } } } if ( check != 0 ) { System . out . print ( " No " ) ; } else { System . out . print ( " Yes " ) ; } } } +import java . util . ArrayList ; import java . util . HashMap ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 1 ; HashMap < Integer , Integer > h = new HashMap < > ( ) ; int count = 0 ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int k = sc . nextInt ( ) ; for ( int i = 1 ; i <= n ; i ++ ) { h . put ( i , 0 ) ; } for ( int i = 0 ; i < k ; i ++ ) { int d = sc . nextInt ( ) ; for ( int j = 0 ; j < d ; j ++ ) { int c = sc . nextInt ( ) ; h . put ( c , 1 ) ; } } for ( int i = 1 ; i <= n ; i ++ ) { if ( h . get ( i ) == 0 ) { count ++ ; } } System . out . println ( count ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; while ( sc . hasNext ( ) ) { int w = sc . nextInt ( ) ; int n = sc . nextInt ( ) ; int [ ] lots = new int [ w ] ; for ( int i = 1 ; i <= w ; ++ i ) { int i = 0 ; lots [ i - 1 ] = i ; } while ( 0 < n -- ) { String [ ] horizontal_line = sc . next ( ) . split ( " , " ) ; swapVerticalLines ( lots , Integer . parseInt ( horizontal_line [ 0 ] ) - 1 , Integer . parseInt ( horizontal_line [ 1 ] ) - 1 ) ; } for ( int i = 0 ; i < w ; ++ i ) { System . out . println ( String . valueOf ( lots [ i ] ) ) ; } } } private static void swapVerticalLines ( int [ ] lots , int line1 , int line2 ) { int tmp = lots [ line1 ] ; lots [ line1 ] = lots [ line2 ] ; lots [ line2 ] = tmp ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; @ SuppressWarnings ( " resource " ) Scanner sc = new Scanner ( System . in ) ; char [ ] s = sc . next ( ) . toCharArray ( ) ; char [ ] t = sc . next ( ) . toCharArray ( ) ; for ( int i = 0 ; i < s . length ; i ++ ) { if ( s [ i ] != t [ i ] ) { System . out . println ( " No " ) ; return ; } } System . out . println ( " Yes " ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; while ( in . hasNext ( ) ) { Scanner in = new Scanner ( System . in ) ; int a = in . nextInt ( ) ; int b = in . nextInt ( ) ; int c = ( int ) Math . log10 ( a + b ) + 1 ; System . out . println ( c ) ; } } } +import java . util . * ; import java . io . * ; import java . math . BigInteger ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; PrintWriter out = new PrintWriter ( System . out ) ; StringTokenizer st1 = new StringTokenizer ( br . readLine ( ) ) ; int n = Integer . parseInt ( st1 . nextToken ( ) ) ; int k = Integer . parseInt ( st1 . nextToken ( ) ) ; int q = Integer . parseInt ( st1 . nextToken ( ) ) ; int [ ] arr = new int [ n ] ; for ( int i = 0 ; i < q ; i ++ ) { arr [ Integer . parseInt ( br . readLine ( ) ) - 1 ] ++ ; } for ( int i = 0 ; i < n ; i ++ ) { int i = 0 ; if ( k - ( q - arr [ i ] ) > 0 ) { out . println ( " Yes " ) ; } else { out . println ( " No " ) ; } } out . flush ( ) ; out . close ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int n , x , ans ; while ( true ) { int k = j + 1 ; n = scan . nextInt ( ) ; x = scan . nextInt ( ) ; ans = 0 ; if ( n == 0 && x == 0 ) break ; for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = i + 1 ; j <= n ; j ++ ) { for ( int k = j + 1 ; k <= n ; k ++ ) { if ( i + j + k == x ) { ans ++ ; break ; } if ( x < i + j + k ) { break ; } } if ( x <= i + j ) { break ; } } if ( x <= i ) { break ; } } System . out . println ( ans ) ; } scan . close ( ) ; } } +import java . io . * ; public class Main { public static void main ( String [ ] args ) throws Exception { BufferedReader input = new BufferedReader ( new InputStreamReader ( System . in ) ) ; StringBuilder sb = new StringBuilder ( ) ; while ( true ) { String str = input . readLine ( ) ; String [ ] arr = str . split ( " " ) ; int h = Integer . parseInt ( arr [ 0 ] ) ; int w = Integer . parseInt ( arr [ 1 ] ) ; if ( h == 0 && w == 0 ) { break ; } for ( int i = 0 ; i < h ; i ++ ) { for ( int j = 0 ; j < w ; j ++ ) { int j = 0 ; if ( i == 0 || i == h - 1 || j == 0 || j == w - 1 ) { sb . append ( " # " ) ; } else { sb . append ( " . " ) ; } } sb . append ( " \n " ) ; } sb . append ( " \n " ) ; } System . out . print ( sb ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int N = scan . nextInt ( ) ; scan . close ( ) ; long sum = 0 ; for ( int a = 1 ; a <= N ; a ++ ) { for ( int b = 1 ; b <= N ; b ++ ) { for ( int c = 1 ; c <= N ; c ++ ) { sum += gcd ( a , gcd ( b , c ) ) ; } } } System . out . println ( sum ) ; } public static int gcd ( int a , int b ) { int r = a % b ; int r = a % b ; while ( r != 0 ) { a = b ; b = r ; r = a % b ; } return b ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; String str = scan . nextLine ( ) ; String [ ] alp = { " 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 " } ; int i ; for ( i = 0 ; i < 25 ; i ++ ) { if ( alp [ i ] . equals ( str ) ) { int i ; break ; } } System . out . println ( alp [ i + 1 ] ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner scan = new Scanner ( System . in ) ; String text ; text = scan . next ( ) ; char [ ] s = text . toCharArray ( ) ; text = scan . next ( ) ; char [ ] p = text . toCharArray ( ) ; func ( s , p , 0 ) ; } static void func ( char [ ] s , char [ ] p , int n ) { for ( int i = 0 ; i < s . length ; i ++ ) { if ( n == s . length ) { System . out . println ( " No " ) ; break ; } else if ( s [ i + n >= s . length ? i + n - s . length : i + n ] != p [ i ] ) { n ++ ; func ( s , p , n ) ; break ; } else if ( i == p . length - 1 ) { System . out . println ( " Yes " ) ; break ; } } } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner stdIn = new Scanner ( System . in ) ; int a = stdIn . nextInt ( ) ; int b = stdIn . nextInt ( ) ; String s = String . valueOf ( a ) + String . valueOf ( b ) ; int c = Integer . parseInt ( s ) ; boolean isSqare = false ; for ( int i = 1 ; i <= 1000 ; i ++ ) { int i = 1 ; if ( i * i == c ) { System . out . println ( " Yes " ) ; isSqare = true ; break ; } } if ( ! isSqare ) System . out . println ( " No " ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; long [ ] H = new long [ N ] ; int counter = 0 ; int countMax = 0 ; for ( int i = 0 ; i < N ; i ++ ) { int i = 0 ; H [ i ] = sc . nextLong ( ) ; if ( i > 0 ) { if ( H [ i - 1 ] >= H [ i ] ) { counter ++ ; } if ( H [ i - 1 ] < H [ i ] ) { if ( counter > countMax ) { countMax = counter ; } counter = 0 ; } } } if ( counter > countMax ) { countMax = counter ; } System . out . println ( countMax ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { long remainder = 0 ; Scanner sc = new Scanner ( System . in ) ; long A = sc . nextLong ( ) ; long B = sc . nextLong ( ) ; long answer = A * B / calcGcd ( A , B ) ; System . out . println ( answer ) ; sc . close ( ) ; } static long calcGcd ( long m , long n ) { if ( m < n ) { long tmp = m ; m = n ; n = tmp ; } long remainder = 0 ; while ( ( remainder = m % n ) != 0 ) { m = n ; n = remainder ; } return n ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = Integer . parseInt ( sc . nextLine ( ) ) ; String [ ] S = sc . nextLine ( ) . split ( " " ) ; int ans = 0 ; for ( int i = 0 ; i < N ; i ++ ) { int n = Integer . parseInt ( S [ i ] ) ; int n = Integer . parseInt ( S [ i ] ) ; while ( n % 2 == 0 ) { n /= 2 ; ans ++ ; } } System . out . println ( ans ) ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int [ ] x = new int [ b ] ; for ( int i = 0 ; i < a ; i ++ ) { int k = 0 ; int c = sc . nextInt ( ) ; for ( int j = 0 ; j < c ; j ++ ) { int d = sc . nextInt ( ) ; x [ d - 1 ] = x [ d - 1 ] + 1 ; } } int ret = 0 ; for ( int k = 0 ; k < b ; k ++ ) { if ( a == x [ k ] ) ret = ret + 1 ; } System . out . println ( ret ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int s = sc . nextInt ( ) ; Set < Integer > set = new HashSet < > ( ) ; int past = s ; set . add ( past ) ; for ( int i = 2 ; i <= 1000000 ; i ++ ) { int cur ; if ( past % 2 == 0 ) { int cur ; cur = past / 2 ; } else { cur = 3 * past + 1 ; } if ( set . contains ( cur ) ) { System . out . println ( i ) ; return ; } set . add ( cur ) ; past = cur ; } } } +import java . util . Scanner ; public class Main { String s ; public Main ( String str ) { s = str ; } public int searchA ( ) { String str = scan . nextLine ( ) ; return s . indexOf ( " A " ) ; } public int searchZ ( ) { return s . lastIndexOf ( " Z " ) + 1 ; } public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; String str = scan . nextLine ( ) ; Main m = new Main ( str ) ; int start = m . searchA ( ) ; int end = m . searchZ ( ) ; System . out . println ( end - start ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String info = br . readLine ( ) ; String [ ] split = info . split ( " " ) ; int H = Integer . parseInt ( split [ 0 ] ) ; int N = Integer . parseInt ( split [ 1 ] ) ; info = br . readLine ( ) ; String [ ] A = info . split ( " " ) ; for ( int i = 0 ; i < N ; i ++ ) { int i = 0 ; H = H - Integer . parseInt ( A [ i ] ) ; } if ( H <= 0 ) { System . out . println ( " Yes " ) ; } else System . out . println ( " No " ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { String strings = sc . nextLine ( ) ; Scanner sc = new Scanner ( System . in ) ; int num = Integer . parseInt ( sc . nextLine ( ) ) ; String strings = sc . nextLine ( ) ; if ( strings . length ( ) <= num ) { System . out . println ( strings ) ; } else { System . out . println ( strings . substring ( 0 , num ) + " ... " ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; for ( int b = 1 ; b > 0 ; b ++ ) { String r = scan . next ( ) ; int tot = 0 ; if ( r . equals ( " 0 " ) ) { int a = 1 ; break ; } for ( int a = 1 ; a <= r . length ( ) ; a ++ ) { String k = r . substring ( a - 1 , a ) ; int K = Integer . parseInt ( k ) ; tot = tot + K ; } System . out . println ( tot ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int numK = sc . nextInt ( ) ; int numX = sc . nextInt ( ) ; int initNum = numX - numK + 1 ; String retStr = " " + initNum ; for ( int i = initNum + 1 ; i < numX + numK ; i ++ ) { int i = initNum + 1 ; retStr = retStr + " " + i ; } System . out . println ( retStr ) ; } } +import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int t = scan . nextInt ( ) ; int [ ] array = new int [ t ] ; int [ ] copy = new int [ t ] ; for ( int count = 0 ; count < t ; count ++ ) { int count = 0 ; int n = scan . nextInt ( ) ; array [ count ] = n ; copy [ count ] = n ; } scan . close ( ) ; Arrays . sort ( copy ) ; int counter = 0 ; for ( int count = 0 ; count < t ; count ++ ) { if ( array [ count ] != copy [ count ] ) { counter ++ ; } } if ( counter < 3 ) { System . out . println ( " YES " ) ; } else System . out . println ( " NO " ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int c = scan . nextInt ( ) ; Scanner scan = new java . util . Scanner ( System . in ) ; int a = scan . nextInt ( ) ; int b = scan . nextInt ( ) ; int c = scan . nextInt ( ) ; if ( b + c <= a ) { System . out . println ( " 0 " ) ; } else { System . out . println ( b + c - a ) ; } } } +import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] p = new int [ n ] ; int [ ] q = new int [ n ] ; int replaceCnt = 0 ; String result = " YES " ; for ( int i = 0 ; i < n ; i ++ ) { p [ i ] = sc . nextInt ( ) ; q [ i ] = p [ i ] ; } Arrays . sort ( q ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( p [ i ] != q [ i ] ) { replaceCnt ++ ; if ( replaceCnt > 2 ) { int i = 0 ; result = " NO " ; break ; } } } System . out . println ( result ) ; sc . close ( ) ; } } +import java . util . Scanner ; import java . util . Arrays ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int M = sc . nextInt ( ) ; int [ ] key = new int [ N ] ; int [ ] L = new int [ M ] ; int [ ] R = new int [ M ] ; for ( int i = 0 ; i < M ; i ++ ) { int i = 0 ; L [ i ] = sc . nextInt ( ) ; R [ i ] = sc . nextInt ( ) ; } Arrays . sort ( R ) ; Arrays . sort ( L ) ; if ( R [ 0 ] - L [ M - 1 ] + 1 > 0 ) { System . out . println ( R [ 0 ] - L [ M - 1 ] + 1 ) ; } else { System . out . println ( " 0 " ) ; } sc . close ( ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { static int A ; static int B ; public static void main ( String [ ] args ) throws NumberFormatException , IOException { read ( ) ; } private static void read ( ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String [ ] word = br . readLine ( ) . split ( " \\ s+ " ) ; A = Integer . parseInt ( word [ 0 ] ) ; B = Integer . parseInt ( word [ 1 ] ) ; System . out . println ( A * B ) ; br . close ( ) ; } } +import java . io . BufferedReader ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws Exception { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String line ; while ( ( line = br . readLine ( ) ) != null ) { String [ ] arr = line . split ( " " ) ; int n = Integer . parseInt ( arr [ 0 ] ) ; int x = Integer . parseInt ( arr [ 1 ] ) ; if ( n == 0 && x == 0 ) break ; int cnt = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = i + 1 ; j <= n ; j ++ ) { int k = j + 1 ; for ( int k = j + 1 ; k <= n ; k ++ ) { if ( i + j + k == x ) cnt ++ ; } } } System . out . println ( cnt ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; int n = 0 ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { int i = 0 ; if ( s . charAt ( i ) == '+' ) n ++ ; if ( s . charAt ( i ) == '-' ) n -- ; } System . out . println ( n ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int change ; Scanner sc = new Scanner ( System . in ) ; for ( ; ; ) { int x = sc . nextInt ( ) ; int y = sc . nextInt ( ) ; if ( x == 0 && y == 0 ) break ; if ( x > y ) { int y = sc . nextInt ( ) ; change = x ; x = y ; y = change ; } System . out . println ( x + " " + y ) ; } } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; int r = sc . nextInt ( ) ; int c = sc . nextInt ( ) ; int [ ] [ ] h = new int [ r + 1 ] [ c + 1 ] ; StringBuilder sb1 = new StringBuilder ( ) ; StringBuilder sb2 = new StringBuilder ( ) ; String b = " " , n = " \n " ; for ( int i = 0 ; i < r ; i ++ ) { int j = 0 ; for ( int j = 0 ; j < c ; j ++ ) { h [ i ] [ j ] = sc . nextInt ( ) ; h [ i ] [ c ] += h [ i ] [ j ] ; h [ r ] [ j ] += h [ i ] [ j ] ; h [ r ] [ c ] += h [ i ] [ j ] ; sb1 . append ( h [ i ] [ j ] + b ) ; if ( i == r - 1 ) sb2 . append ( h [ r ] [ j ] + b ) ; } sb1 . append ( h [ i ] [ c ] + n ) ; } sb2 . append ( h [ r ] [ c ] ) ; System . out . print ( sb1 ) ; System . out . println ( sb2 ) ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { int i ; int stacksize = 100 ; String temp ; int calc ; int a , b ; Deque < Integer > stack = new ArrayDeque < Integer > ( ) ; String separator = System . getProperty ( " line.separator " ) ; Scanner sc1 = new Scanner ( System . in ) ; String str = sc1 . nextLine ( ) ; Scanner sc2 = new Scanner ( str ) ; sc2 . useDelimiter ( " " ) ; while ( sc2 . hasNext ( ) ) { temp = sc2 . next ( ) ; if ( temp . equals ( " + " ) ) { calc = stack . removeFirst ( ) + stack . removeFirst ( ) ; stack . addFirst ( calc ) ; } else if ( temp . equals ( " - " ) ) { a = stack . removeFirst ( ) ; b = stack . removeFirst ( ) ; calc = b - a ; stack . addFirst ( calc ) ; } else if ( temp . equals ( " * " ) ) { calc = stack . removeFirst ( ) * stack . removeFirst ( ) ; stack . addFirst ( calc ) ; } else { Scanner sc2 = new Scanner ( str ) ; stack . addFirst ( Integer . parseInt ( temp ) ) ; } } System . out . println ( stack . removeFirst ( ) ) ; } } +import java . util . * ; import java . lang . * ; import java . math . * ; public class Main { Scanner sc = new Scanner ( System . in ) ; void run ( ) { int b = 100 ; int n = sc . nextInt ( ) ; int b = 100 ; for ( int i = 0 ; i < n ; i ++ ) { if ( ( double ) ( b * 0.05 ) - ( int ) ( b * 0.05 ) > 0 ) b = ( int ) ( b * 1.05 ) + 1 ; else b = ( int ) ( b * 1.05 ) ; } System . out . println ( b * 1000 ) ; } public static void main ( String [ ] args ) { new Main ( ) . run ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; if ( N == 1 ) { System . out . println ( 0 ) ; } else { int Ans = 0 ; int Temp = 0 ; int [ ] H = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { H [ i ] = sc . nextInt ( ) ; } for ( int i = 0 ; i < N - 1 ; i ++ ) { if ( H [ i ] >= H [ i + 1 ] ) { Temp += 1 ; } if ( ( H [ i ] < H [ i + 1 ] ) | ( i == N - 2 ) ) { if ( Ans < Temp ) { int i = 0 ; Ans = Temp ; } Temp = 0 ; } } System . out . println ( Ans ) ; } sc . close ( ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int [ ] [ ] A = new int [ 2 ] [ N ] ; int [ ] sum = new int [ N ] ; int x = 0 , y = 0 , collect = 0 , max = 0 ; for ( int i = 0 ; i < 2 ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) { A [ i ] [ j ] = sc . nextInt ( ) ; } } for ( int j = 0 ; j < N ; j ++ ) { for ( int i = 0 ; i < N ; i ++ ) { if ( i <= j ) collect += A [ 0 ] [ i ] ; if ( i >= j ) collect += A [ 1 ] [ i ] ; } if ( collect > max ) max = collect ; collect = 0 ; } System . out . println ( max ) ; sc . close ( ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int K = sc . nextInt ( ) ; int S = sc . nextInt ( ) ; int ans = 0 ; int sum = 0 ; for ( int i = 0 ; i <= K ; i ++ ) { int j = 0 ; for ( int j = 0 ; j <= K ; j ++ ) { sum = S - ( i + j ) ; if ( 0 <= sum && sum <= K ) { ans ++ ; } } } System . out . println ( ans ) ; } } +import java . util . * ; import java . io . * ; public class Main { public static void main ( String [ ] args ) throws Exception { int i = 0 ; BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int N = Integer . parseInt ( br . readLine ( ) ) ; String [ ] Bstr = br . readLine ( ) . split ( " " ) ; int [ ] B = new int [ N - 1 ] ; for ( int i = 0 ; i < N - 1 ; i ++ ) { B [ i ] = Integer . parseInt ( Bstr [ i ] ) ; } int [ ] A = new int [ N ] ; int sum = 0 ; for ( int i = 0 ; i < N - 1 ; i ++ ) { if ( i == 0 ) { A [ i ] = B [ i ] ; } else { A [ i ] = Math . min ( A [ i ] , B [ i ] ) ; } sum += A [ i ] ; A [ i + 1 ] = B [ i ] ; if ( i == N - 2 ) sum += A [ N - 1 ] ; } System . out . println ( sum ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . StringTokenizer ; class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String name ; int num ; int compare ; String waku = " " ; int [ ] a = new int [ 2 ] ; int i = 0 ; while ( true ) { try { name = br . readLine ( ) ; StringTokenizer st = new StringTokenizer ( name , " " ) ; while ( st . hasMoreTokens ( ) ) { a [ i ] = Integer . parseInt ( st . nextToken ( ) ) ; i ++ ; } i = 0 ; if ( a [ 0 ] == 0 && a [ 1 ] == 0 ) { System . exit ( 0 ) ; } else { for ( int k = 0 ; k < a [ 1 ] ; k ++ ) { StringTokenizer st = new StringTokenizer ( name , " " ) ; waku = waku + " # " ; } for ( int j = 0 ; j < a [ 0 ] ; j ++ ) { System . out . println ( waku ) ; } System . out . println ( " " ) ; waku = " " ; } } catch ( Exception e ) { System . exit ( 0 ) ; } } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner std = new Scanner ( System . in ) ; String text = std . next ( ) ; String first = text . substring ( 0 , 2 ) ; String last = text . substring ( 2 ) ; Integer firstValue = Integer . parseInt ( first ) ; Integer lastValue = Integer . parseInt ( last ) ; String format ; if ( availableMonth ( firstValue ) && availableMonth ( lastValue ) ) { format = " AMBIGUOUS " ; } else if ( availableMonth ( firstValue ) ) { format = " MMYY " ; } else if ( availableMonth ( lastValue ) ) { String format ; format = " YYMM " ; } else { format = " NA " ; } System . out . println ( format ) ; } static boolean availableMonth ( int val ) { return val >= 1 && val <= 12 ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new java . util . Scanner ( System . in ) ; int k = scan . nextInt ( ) ; int x = scan . nextInt ( ) ; for ( int i = 1 ; i < 2 * Math . abs ( k ) ; i ++ ) { int i = 1 ; System . out . print ( x - k + i + " " ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int N = scan . nextInt ( ) ; int [ ] P = new int [ N ] ; int countI = 1 ; for ( int i = 0 ; i < N ; i ++ ) { int Min = P [ 0 ] ; int b = scan . nextInt ( ) ; P [ i ] = b ; } int j = 1 ; int Min = P [ 0 ] ; while ( j < N ) { if ( P [ j ] < Min ) { Min = P [ j ] ; countI ++ ; } j ++ ; } System . out . println ( countI ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int y = B ; Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int A = sc . nextInt ( ) ; int B = sc . nextInt ( ) ; int x = N * A ; int y = B ; if ( x < y ) { System . out . println ( x ) ; } else if ( x > y ) { System . out . println ( y ) ; } else if ( x == y ) { System . out . println ( y ) ; } } } +import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int monster = scan . nextInt ( ) ; int waza = scan . nextInt ( ) ; long [ ] hp = new long [ monster ] ; for ( int i = 0 ; i < monster ; i ++ ) { hp [ i ] = scan . nextInt ( ) ; } long sum = 0 ; Arrays . sort ( hp ) ; for ( int i = 0 ; i < monster - waza ; i ++ ) { int i = 0 ; sum += hp [ i ] ; } System . out . println ( sum ) ; scan . close ( ) ; } } +import java . util . * ; import java . io . * ; public class Main { public static void main ( final String [ ] args ) { final Scanner sc = new Scanner ( System . in ) ; long n = sc . nextLong ( ) ; long m = sc . nextLong ( ) ; if ( n > m ) System . out . println ( n * m / gcd ( n , m ) ) ; else System . out . println ( n * m / gcd ( m , n ) ) ; } static long gcd ( long a , long b ) { long temp ; long temp ; while ( ( temp = a % b ) != 0 ) { a = b ; b = temp ; } return b ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws IOException { String ring = inStr + inStr ; try ( BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ) { String result = " No " ; String inStr = br . readLine ( ) ; String target = br . readLine ( ) ; String ring = inStr + inStr ; if ( inStr . length ( ) >= target . length ( ) ) { if ( ring . indexOf ( target ) != - 1 ) result = " Yes " ; } System . out . println ( result ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int back , i , j = 1 ; Scanner input = new Scanner ( System . in ) ; int n = input . nextInt ( ) ; int back , i , j = 1 ; while ( true ) { i = j * 1000 ; if ( i >= n ) { back = i - n ; break ; } j ++ ; } System . out . println ( back ) ; } } +import java . util . HashMap ; import java . util . Map ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; char [ ] w = scanner . next ( ) . toCharArray ( ) ; scanner . close ( ) ; if ( w . length % 2 == 1 ) { Integer v ; System . out . println ( " No " ) ; return ; } Map < Character , Integer > map = new HashMap < > ( ) ; for ( char c : w ) { if ( map . containsKey ( c ) ) { map . put ( c , map . get ( c ) + 1 ) ; } else { map . put ( c , 1 ) ; } } for ( Integer v : map . values ( ) ) { if ( v % 2 != 0 ) { System . out . println ( " No " ) ; return ; } } System . out . println ( " Yes " ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int A = Integer . parseInt ( sc . next ( ) ) ; int B = Integer . parseInt ( sc . next ( ) ) ; int x = 1 ; int result = 0 ; while ( x < B ) { int result = 0 ; x += ( A - 1 ) ; result ++ ; } System . out . println ( result ) ; } } +import java . util . HashMap ; import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int m = sc . nextInt ( ) ; int [ ] k = new int [ n ] ; HashMap < Integer , Integer > map = new HashMap < Integer , Integer > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { k [ i ] = sc . nextInt ( ) ; for ( int j = 0 ; j < k [ i ] ; j ++ ) { int num ; int num = sc . nextInt ( ) ; int sum = map . getOrDefault ( num , 0 ) ; map . put ( num , sum + 1 ) ; } } int ans = 0 ; for ( int num : map . values ( ) ) { if ( num == n ) { ans ++ ; } } System . out . println ( ans ) ; } } +import java . util . * ; import java . math . * ; class Main { public static void main ( String [ ] args ) { try ( Scanner sc = new Scanner ( System . in ) ) { Scanner sc = new Scanner ( System . in ) ; String str = sc . next ( ) ; String ans = " " ; if ( str . equals ( " ABC " ) ) ans = " ARC " ; else ans = " ABC " ; System . out . println ( ans ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int N = in . nextInt ( ) ; int [ ] a = new int [ 100 ] ; for ( int i = 0 ; i < N ; i ++ ) { int val = in . nextInt ( ) ; a [ i ] = val ; } for ( int i = 1 ; i < N ; i ++ ) { output ( a , N ) ; int val = a [ i ] ; int j = i - 1 ; while ( j >= 0 && val < a [ j ] ) { a [ j + 1 ] = a [ j ] ; j -- ; } a [ j + 1 ] = val ; } output ( a , N ) ; } static void output ( int [ ] a , int N ) { for ( int i = 0 ; i < N - 1 ; i ++ ) { int i = 0 ; System . out . print ( a [ i ] + " " ) ; } System . out . println ( a [ N - 1 ] ) ; } } +import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int N = scan . nextInt ( ) ; int [ ] A = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { A [ i ] = scan . nextInt ( ) ; } insertionSort ( A , N ) ; } public static void insertionSort ( int [ ] A , int N ) { String output = Arrays . toString ( A ) . replaceAll ( " , " , " " ) ; System . out . println ( output . substring ( 1 , output . length ( ) - 1 ) ) ; for ( int i = 1 ; i < N ; i ++ ) { int v = A [ i ] ; int j = i - 1 ; while ( j >= 0 && A [ j ] > v ) { int j = i - 1 ; A [ j + 1 ] = A [ j ] ; j -- ; A [ j + 1 ] = v ; } output = Arrays . toString ( A ) . replaceAll ( " , " , " " ) ; System . out . println ( output . substring ( 1 , output . length ( ) - 1 ) ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; sc . close ( ) ; int n = 0 ; for ( int i = 0 ; i < 4 ; i ++ ) { n += ( Math . pow ( 10 , i ) * ( s . charAt ( 3 - i ) - 48 ) ) ; } n *= 10000 ; n += ( s . charAt ( 5 ) - 48 ) * 1000 ; n += ( s . charAt ( 6 ) - 48 ) * 100 ; n += ( s . charAt ( 8 ) - 48 ) * 10 ; n += s . charAt ( 9 ) - 48 ; if ( n < 20190431 ) { System . out . println ( " Heisei " ) ; } else { int i = 0 ; System . out . println ( " TBD " ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int [ ] an = new int [ 5 ] ; for ( int i = 0 ; i < 5 ; i ++ ) { an [ i ] = sc . nextInt ( ) ; } int k = sc . nextInt ( ) ; String ans = " :( " ; sc . close ( ) ; if ( an [ 4 ] - an [ 0 ] <= k ) { String ans = " :( " ; ans = " Yay! " ; } System . out . println ( ans ) ; } } +import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . util . ArrayList ; import java . util . Arrays ; import java . util . List ; import java . util . PriorityQueue ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner in = new Scanner ( new BufferedReader ( new InputStreamReader ( System . in ) ) ) ; int x = in . nextInt ( ) ; int r = solve ( x ) ; System . out . println ( r ) ; } private static int solve ( int x ) { if ( x == 2 ) return 2 ; int [ ] s = new int [ 10000 ] ; int sm = 1 ; s [ 0 ] = 2 ; for ( int i = 3 ; ; i ++ ) { int j = 0 ; while ( j < sm ) { int j = 0 ; if ( i % s [ j ] == 0 ) break ; j ++ ; } if ( j == sm ) { s [ sm ] = i ; sm ++ ; if ( i >= x ) return i ; } } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int num = sc . nextInt ( ) ; int [ ] ans = new int [ num + 1 ] ; for ( int i = 1 ; i < num ; i ++ ) { int a = sc . nextInt ( ) ; ans [ a ] ++ ; } for ( int i = 1 ; i <= num ; i ++ ) { int i = 1 ; System . out . println ( ans [ i ] ) ; } } } +import java . util . Scanner ; public class Main { static Scanner scanner ; public static void main ( String [ ] args ) { scanner = new Scanner ( System . in ) ; String [ ] you = { " SUN " , " MON " , " TUE " , " WED " , " THU " , " FRI " , " SAT " } ; String s = gs ( ) ; for ( int i = 0 ; i < you . length ; i ++ ) { if ( s . equals ( you [ i ] ) ) { System . out . print ( 7 - i ) ; return ; } } } public static String gs ( ) { return scanner . next ( ) ; } public static int gi ( ) { int i = 0 ; return Integer . parseInt ( scanner . next ( ) ) ; } public static long gl ( ) { return Long . parseLong ( scanner . next ( ) ) ; } public static double gd ( ) { return Double . parseDouble ( scanner . next ( ) ) ; } } +import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int k = 0 ; Scanner sc = new Scanner ( System . in ) ; int [ ] [ ] [ ] rooms = new int [ 4 ] [ 3 ] [ 10 ] ; for ( int i = 0 ; i < 4 ; i ++ ) { for ( int j = 0 ; j < 3 ; j ++ ) { for ( int k = 0 ; k < 10 ; k ++ ) { rooms [ i ] [ j ] [ k ] = 0 ; } } } int n = sc . nextInt ( ) ; for ( int i = 0 ; i < n ; i ++ ) { int b = sc . nextInt ( ) ; int f = sc . nextInt ( ) ; int r = sc . nextInt ( ) ; int v = sc . nextInt ( ) ; rooms [ b - 1 ] [ f - 1 ] [ r - 1 ] += v ; } for ( int i = 0 ; i < 4 ; i ++ ) { for ( int j = 0 ; j < 3 ; j ++ ) { for ( int k = 0 ; k < 10 ; k ++ ) { System . out . print ( " " + rooms [ i ] [ j ] [ k ] ) ; } System . out . println ( " " ) ; } if ( i < 3 ) { System . out . println ( " #################### " ) ; } } sc . close ( ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner s = new Scanner ( System . in ) ; String S = s . next ( ) ; String T = s . next ( ) ; char [ ] sc = S . toCharArray ( ) ; char [ ] tc = T . toCharArray ( ) ; if ( ( tc . length - sc . length ) > 1 ) { System . out . println ( " No " ) ; } for ( int i = 0 ; i < tc . length ; i ++ ) { int i = 0 ; if ( i < sc . length && sc [ i ] != tc [ i ] ) { System . out . println ( " No " ) ; break ; } if ( i == tc . length - 1 ) { System . out . println ( " Yes " ) ; } } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String S = sc . next ( ) ; if ( S . length ( ) < 6 ) { String S = sc . next ( ) ; System . out . print ( " No " ) ; } else { if ( S . charAt ( 2 ) == S . charAt ( 3 ) && S . charAt ( 4 ) == S . charAt ( 5 ) ) { System . out . print ( " Yes " ) ; } else { System . out . print ( " No " ) ; } } } } +import java . util . * ; public class Main { static int gcd ( int a , int b ) { return b > 0 ? gcd ( b , a % b ) : a ; } static long mod = 1000000007 ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; char [ ] S = sc . next ( ) . toCharArray ( ) ; char [ ] T = sc . next ( ) . toCharArray ( ) ; int ans = 1001 ; for ( int i = 0 ; i < S . length - T . length + 1 ; i ++ ) { int j = 0 ; int tempAns = 0 ; for ( int j = 0 ; j < T . length ; j ++ ) { if ( S [ i + j ] != T [ j ] ) { tempAns ++ ; } } ans = Math . min ( ans , tempAns ) ; } System . out . println ( ans ) ; } } +import java . util . LinkedHashSet ; import java . util . Scanner ; import java . util . Set ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] numbers = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { numbers [ i ] = sc . nextInt ( ) ; } int numbers_length = numbers . length ; Set < Integer > linkedHashSet = new LinkedHashSet < Integer > ( ) ; for ( int i = 0 ; i < numbers . length ; i ++ ) { int i = 0 ; linkedHashSet . add ( numbers [ i ] ) ; } int numbers_length2 = linkedHashSet . size ( ) ; if ( numbers_length == numbers_length2 ) { System . out . println ( " YES " ) ; } else { System . out . println ( " NO " ) ; } } } +import java . lang . Math ; import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { int year = 0 ; Scanner sc = new Scanner ( System . in ) ; long n = sc . nextLong ( ) ; double interest = 100 ; int year = 0 ; while ( interest < n ) { year += 1 ; interest *= 1.01 ; interest = Math . floor ( interest ) ; if ( interest >= n ) { break ; } } System . out . println ( year ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { int b = scan . nextInt ( ) ; Scanner scan = new Scanner ( System . in ) ; int a = scan . nextInt ( ) ; int b = scan . nextInt ( ) ; if ( a < 10 && b < 10 ) { System . out . println ( a * b ) ; } else { System . out . println ( - 1 ) ; } scan . close ( ) ; } } +import java . util . HashMap ; import java . util . HashSet ; import java . util . Map ; import java . util . Scanner ; import java . util . Set ; import java . util . TreeSet ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; Set < String > set = new HashSet < > ( ) ; Map < String , Integer > map = new HashMap < > ( ) ; String [ ] s = new String [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { s [ i ] = sc . next ( ) ; set . add ( s [ i ] ) ; map . put ( s [ i ] , 0 ) ; } for ( int i = 0 ; i < n ; i ++ ) { String string ; int v = map . get ( s [ i ] ) ; map . put ( s [ i ] , ++ v ) ; } int max = 1 ; for ( String key : map . keySet ( ) ) { if ( map . get ( key ) > max ) { max = map . get ( key ) ; } } Set < String > tSet = new TreeSet < > ( ) ; for ( String key : map . keySet ( ) ) { if ( map . get ( key ) == max ) { tSet . add ( key ) ; } } StringBuilder sb = new StringBuilder ( ) ; for ( String string : tSet ) { sb . append ( string ) ; sb . append ( '\n' ) ; } System . out . println ( sb . toString ( ) ) ; } } +import java . io . BufferedReader ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws Exception { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; char [ ] S = br . readLine ( ) . toCharArray ( ) ; char [ ] T = br . readLine ( ) . toCharArray ( ) ; int roop = S . length - T . length + 1 ; int [ ] cnt = new int [ roop ] ; int max = 0 ; for ( int i = 0 ; i < roop ; i ++ ) { for ( int j = 0 ; j < T . length ; j ++ ) { if ( T [ j ] == S [ i + j ] ) { int k = 0 ; cnt [ i ] ++ ; } } } for ( int k = 0 ; k < cnt . length ; k ++ ) { if ( max < cnt [ k ] ) { max = cnt [ k ] ; } } System . out . println ( T . length - max ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int n = scan . nextInt ( ) ; int [ ] h = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { h [ i ] = scan . nextInt ( ) ; } scan . close ( ) ; int check = 1 ; if ( n != 1 ) { for ( int i = n - 2 ; i >= 0 ; i -- ) { int i = n - 2 ; if ( h [ i ] > h [ i + 1 ] ) h [ i ] -- ; if ( h [ i ] > h [ i + 1 ] ) { check = 0 ; break ; } } } System . out . println ( ( check == 1 ) ? " Yes " : " No " ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int M = sc . nextInt ( ) ; double sum = 0 ; int cnt = 0 ; Integer [ ] items = new Integer [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { int itemVote = sc . nextInt ( ) ; sum += itemVote ; items [ i ] = itemVote ; } Arrays . sort ( items , Collections . reverseOrder ( ) ) ; double baseNum = sum / ( ( double ) 4 * ( double ) M ) ; for ( int l = 0 ; l < M ; l ++ ) { double val = ( double ) items [ l ] ; if ( val < baseNum ) { continue ; } cnt ++ ; } if ( cnt >= M ) { System . out . println ( " Yes " ) ; } else { int l = 0 ; System . out . println ( " No " ) ; } } } +import java . io . * ; import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; while ( true ) { int j = 0 ; String fst = br . readLine ( ) ; int n = Integer . parseInt ( fst ) ; if ( n == 0 ) { break ; } String line = br . readLine ( ) ; String [ ] str = line . split ( " " ) ; double [ ] s = new double [ str . length ] ; for ( int j = 0 ; j < n ; j ++ ) { s [ j ] = Double . parseDouble ( str [ j ] ) ; } double sum = 0.0 ; for ( int j = 0 ; j < n ; j ++ ) { sum += s [ j ] ; } double num = n ; double avr = sum / num ; double a = 0.0 ; for ( int j = 0 ; j < n ; j ++ ) { a += ( s [ j ] - avr ) * ( s [ j ] - avr ) ; } a /= num ; a = Math . sqrt ( a ) ; System . out . printf ( " %.6f \n " , a ) ; } } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int [ ] a = new int [ N ] ; int [ ] b = new int [ N - 1 ] ; for ( int i = 0 ; i < N ; i ++ ) { a [ i ] = sc . nextInt ( ) ; } for ( int j = 0 ; j < N - 1 ; j ++ ) { if ( a [ j + 1 ] <= a [ j ] ) { b [ j ] = 1 ; } else { b [ j ] = 0 ; } } int b_max = 0 ; int count = 0 ; for ( int c = 0 ; c < N - 1 ; c ++ ) { if ( b [ c ] == 1 ) { int c = 0 ; count ++ ; } else { if ( count > b_max ) { b_max = count ; } count = 0 ; } } if ( count > b_max ) { b_max = count ; } System . out . println ( b_max ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { try ( Scanner sc = new Scanner ( System . in ) ) { int c = sc . nextInt ( ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int c = sc . nextInt ( ) ; if ( a >= 0 && a <= 100 ) { if ( b >= 0 && b <= 100 ) { if ( c >= 0 && c <= 100 ) { if ( a < b && b < c ) { 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 N = sc . nextInt ( ) ; int count = 0 ; int [ ] flag = new int [ 101 ] ; for ( int i = 0 ; i < N ; i ++ ) { int i = 1 ; int d = sc . nextInt ( ) ; flag [ d ] = 1 ; } for ( int i = 1 ; i < 101 ; i ++ ) { count += flag [ i ] ; } System . out . println ( count ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String a = sc . next ( ) ; String b = sc . next ( ) ; String c = sc . next ( ) ; String next = a . substring ( 0 , 1 ) ; a = a . substring ( 1 , a . length ( ) ) ; for ( ; ; ) { if ( next . equals ( " a " ) ) { if ( a . isEmpty ( ) ) { System . out . println ( " A " ) ; return ; } next = a . substring ( 0 , 1 ) ; a = a . substring ( 1 , a . length ( ) ) ; } else if ( next . equals ( " b " ) ) { if ( b . isEmpty ( ) ) { String next = a . substring ( 0 , 1 ) ; System . out . println ( " B " ) ; return ; } next = b . substring ( 0 , 1 ) ; b = b . substring ( 1 , b . length ( ) ) ; } else { if ( c . isEmpty ( ) ) { System . out . println ( " C " ) ; return ; } next = c . substring ( 0 , 1 ) ; c = c . substring ( 1 , c . length ( ) ) ; } } } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . StringTokenizer ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; FastScanner fs = new FastScanner ( ) ; int n = fs . nextInt ( ) ; long ans = 0 ; for ( int i = 1 ; i <= n ; ++ i ) { if ( i % 3 != 0 && i % 5 != 0 ) ans += i ; } System . out . println ( ans ) ; } static class FastScanner { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; StringTokenizer st = new StringTokenizer ( " " ) ; String next ( ) { while ( ! st . hasMoreTokens ( ) ) try { st = new StringTokenizer ( br . readLine ( ) ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } return st . nextToken ( ) ; } int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } int [ ] readArray ( int n ) { int [ ] a = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) a [ i ] = nextInt ( ) ; return a ; } long nextLong ( ) { return Long . parseLong ( next ( ) ) ; } } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String w = sc . nextLine ( ) ; int count = 0 ; String t ; while ( ! ( ( t = sc . next ( ) ) . equals ( " END_OF_TEXT " ) ) ) { String t ; if ( t . toLowerCase ( ) . equals ( w ) ) count ++ ; } System . out . println ( count ) ; } } +import java . util . Arrays ; import java . util . HashMap ; import java . util . Map ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = Integer . parseInt ( sc . nextLine ( ) ) ; Map < String , Long > m = new HashMap < > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { Long v ; char [ ] c = sc . nextLine ( ) . toCharArray ( ) ; Arrays . sort ( c ) ; String k = new String ( c ) ; if ( m . get ( k ) == null ) { m . put ( k , 1L ) ; } else { m . put ( k , m . get ( k ) + 1 ) ; } } long ans = 0 ; for ( Long v : m . values ( ) ) { ans += v * ( v - 1 ) / 2 ; } System . out . println ( ans ) ; } } +import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] a = new int [ n ] ; int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int i = 0 ; a [ i ] = sc . nextInt ( ) ; sum += a [ i ] ; } Arrays . parallelSort ( a ) ; sum -= a [ n - 1 ] ; if ( sum > a [ n - 1 ] ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } } +import java . util . ArrayList ; import java . util . Arrays ; import java . util . Collections ; import java . util . Comparator ; import java . util . HashMap ; import java . util . HashSet ; import java . util . Iterator ; import java . util . Map . Entry ; import java . util . PriorityQueue ; import java . util . Scanner ; class Main { static final int MOD = 1000000007 ; static final int INF = 1 << 30 ; public static void main ( String [ ] args ) { int index = 0 ; Scanner sc = new Scanner ( System . in ) ; char [ ] s = sc . next ( ) . toCharArray ( ) ; String ans = " " ; for ( int index = 0 ; index < s . length ; index ++ ) { switch ( s [ index ] ) { case '0' : ans += " 0 " ; break ; case '1' : ans += " 1 " ; break ; case 'B' : ans = ans . substring ( 0 , Math . max ( 0 , ans . length ( ) - 1 ) ) ; break ; } } System . out . println ( ans ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int l = sc . nextInt ( ) ; int s = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { s = s + l + i - 1 ; } int a = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { if ( l - 1 + i == 0 ) { int i = 1 ; a = i ; } } if ( a == 0 ) { if ( l * l > ( l + n - 1 ) * ( l + n - 1 ) ) { a = n ; } else { a = 1 ; } } System . out . println ( s - l + 1 - a ) ; sc . close ( ) ; } } +import java . util . * ; import java . io . * ; public class Main { static StringTokenizer st ; static BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; public static void main ( String [ ] args ) throws IOException { int input = nextInt ( ) ; HashSet < String > kinds = new HashSet < > ( ) ; for ( int x = 0 ; x < input ; x ++ ) { String cur = next ( ) ; String cur = next ( ) ; if ( ! kinds . contains ( cur ) ) { kinds . add ( cur ) ; } } System . out . println ( kinds . size ( ) ) ; } public static int nextInt ( ) throws IOException { return Integer . parseInt ( next ( ) ) ; } public static long nextLong ( ) throws IOException { return Long . parseLong ( next ( ) ) ; } public static double nextDouble ( ) throws IOException { return Double . parseDouble ( next ( ) ) ; } static String next ( ) throws IOException { while ( st == null || ! st . hasMoreTokens ( ) ) st = new StringTokenizer ( br . readLine ( ) . trim ( ) ) ; return st . nextToken ( ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int j = 0 ; Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int [ ] A = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { A [ sc . nextInt ( ) - 1 ] = i + 1 ; } for ( int j = 0 ; j < N ; j ++ ) { System . out . print ( A [ j ] + " " ) ; } } } +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 Aval , Bval ; for ( int i = 1 ; i <= 1000 ; i ++ ) { int i = 1 ; Aval = ( int ) ( i * 0.08 ) ; Bval = ( int ) ( i * 0.1 ) ; if ( A == Aval && B == Bval ) { System . out . println ( i ) ; System . exit ( 0 ) ; } } System . out . println ( - 1 ) ; sc . close ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { final Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] rate = new int [ 8 ] ; int red = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int a = sc . nextInt ( ) ; if ( 3200 <= a ) { red ++ ; } else { rate [ ( a / 400 ) ] ++ ; } } int min = 0 ; int max = 0 ; int count = 0 ; for ( int i = 0 ; i < 8 ; i ++ ) { int i = 0 ; if ( rate [ i ] >= 1 ) { count ++ ; } } min = Math . max ( count , 1 ) ; max = count + red ; System . out . println ( min + " " + max ) ; } } +import java . util . Scanner ; import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int a = in . nextInt ( ) ; int b = in . nextInt ( ) ; int c = in . nextInt ( ) ; int [ ] sort = { a , b , c } ; for ( int i = 0 ; i < 2 ; i ++ ) { for ( int j = 0 ; j < 2 - i ; j ++ ) { int j = 0 ; if ( sort [ j ] < sort [ j + 1 ] ) { int temp = sort [ j ] ; sort [ j ] = sort [ j + 1 ] ; sort [ j + 1 ] = temp ; } } } System . out . println ( sort [ 2 ] + " " + sort [ 1 ] + " " + sort [ 0 ] ) ; } } +import java . util . * ; import java . io . * ; class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int x = Integer . parseInt ( br . readLine ( ) ) ; StringBuilder sb = new StringBuilder ( ) ; int count = 0 ; int a = 1 , b ; if ( x >= 3 && x <= 10000 ) { for ( ; count < x ; count ++ ) { b = a / 10 ; if ( a % 3 == 0 ) { sb . append ( " " ) ; sb . append ( a ) ; } else { b = a ; while ( b != 0 ) { int a = 1 , b ; if ( b % 10 == 3 ) { sb . append ( " " ) ; sb . append ( a ) ; break ; } b /= 10 ; } } a ++ ; } } System . out . println ( sb ) ; } } +import java . io . * ; import java . util . * ; class Main { public static void main ( String [ ] args ) { int time , t ; BufferedReader kb = new BufferedReader ( new InputStreamReader ( System . in ) ) ; try { String [ ] str = kb . readLine ( ) . split ( " " ) ; int n = Integer . parseInt ( str [ 0 ] ) ; int q = Integer . parseInt ( str [ 1 ] ) ; LinkedList < String > ps = new LinkedList < String > ( ) ; LinkedList < Integer > times = new LinkedList < Integer > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { str = kb . readLine ( ) . split ( " " ) ; ps . offer ( str [ 0 ] ) ; times . offer ( Integer . parseInt ( str [ 1 ] ) ) ; } StringBuilder output = new StringBuilder ( ) ; String job ; int time , t ; t = 0 ; while ( null != ( job = ps . peek ( ) ) ) { time = times . peek ( ) ; if ( times . peek ( ) <= q ) { output . append ( job ) ; output . append ( " " ) ; output . append ( t + time ) ; output . append ( " \n " ) ; t += time ; } else { ps . offer ( job ) ; times . offer ( time - q ) ; t += q ; } ps . poll ( ) ; times . poll ( ) ; } System . out . print ( output ) ; } catch ( IOException e ) { System . err . println ( e ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int [ ] d = new int [ N ] ; long sum = 0 ; d [ 0 ] = sc . nextInt ( ) ; for ( int i = 1 ; i < N ; i ++ ) { int j = 0 ; d [ i ] = sc . nextInt ( ) ; for ( int j = 0 ; j < i ; j ++ ) { sum = sum + d [ j ] * d [ i ] ; } } System . out . println ( sum ) ; } private static long lcm ( long m , long n ) { return m * n / gcd ( m , n ) ; } private static long gcd ( long m , long n ) { if ( m < n ) return gcd ( n , m ) ; if ( n == 0 ) return m ; return gcd ( n , m % n ) ; } } +import java . util . ArrayList ; import java . util . Comparator ; import java . util . List ; import java . util . Scanner ; import java . util . stream . Collectors ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; long n = scanner . nextLong ( ) ; long count = 0 ; while ( n > 1 ) { int i = 0 ; n = n / 2 ; count ++ ; } long answer = 0 ; for ( int i = 0 ; i <= count ; i ++ ) { answer += Math . pow ( 2 , i ) ; } System . out . println ( answer ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; int city = sc . nextInt ( ) ; long [ ] monster = new long [ city + 1 ] ; long [ ] brave = new long [ city ] ; long anser = 0 ; for ( int i = 0 ; i < city + 1 ; i ++ ) { monster [ i ] = sc . nextLong ( ) ; } for ( int i = 0 ; i < city ; i ++ ) { brave [ i ] = sc . nextLong ( ) ; } for ( int i = 0 ; i < brave . length ; i ++ ) { anser += Math . min ( monster [ i ] , brave [ i ] ) ; anser += Math . min ( monster [ i + 1 ] , Math . max ( brave [ i ] - monster [ i ] , 0 ) ) ; monster [ i + 1 ] -= Math . min ( monster [ i + 1 ] , Math . max ( brave [ i ] - monster [ i ] , 0 ) ) ; } System . out . println ( anser ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; sc . nextLine ( ) ; String s = sc . nextLine ( ) ; int i = 0 ; int cnt = 0 ; do { i = s . indexOf ( " ABC " , i ) ; if ( i != - 1 ) { int cnt = 0 ; cnt ++ ; i ++ ; } } while ( i >= 0 ) ; System . out . println ( cnt ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = ( Size - 1 ) ; Scanner sc = new Scanner ( System . in ) ; String input = sc . nextLine ( ) ; int Size = input . length ( ) ; String [ ] n = new String [ 30 ] ; for ( int i = 0 ; i < Size ; i ++ ) { n [ i ] = input . substring ( i , i + 1 ) ; } for ( int i = ( Size - 1 ) ; i > - 1 ; i -- ) { if ( i == 0 ) System . out . println ( n [ i ] ) ; else System . out . print ( n [ i ] ) ; } } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws IOException { InputStreamReader isr = new InputStreamReader ( System . in ) ; BufferedReader br = new BufferedReader ( isr ) ; String input = br . readLine ( ) ; String [ ] inputan = br . readLine ( ) . split ( " " ) ; for ( int j = Integer . parseInt ( input ) - 1 ; j >= 0 ; j -- ) { int j = Integer . parseInt ( input ) - 1 ; System . out . print ( inputan [ j ] ) ; if ( j > 0 ) System . out . print ( " " ) ; if ( j == 0 ) System . out . println ( ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner input = new Scanner ( System . in ) ; while ( true ) { String word = input . nextLine ( ) ; String word = input . nextLine ( ) ; if ( word . equals ( " - " ) ) break ; int wrapTime = input . nextInt ( ) ; for ( int i = 0 ; i < wrapTime ; i ++ ) { int index = input . nextInt ( ) ; String move = word . substring ( 0 , index ) ; String left = word . substring ( index ) ; word = left + move ; } input . nextLine ( ) ; System . out . println ( word ) ; } } } +import java . util . Scanner ; public class Main { public static int g ( long x ) { long i = 1 ; int res = 0 ; while ( x > 0 ) { ++ res ; x /= 10 ; } return res ; } public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long N = sc . nextLong ( ) ; int res = Integer . MAX_VALUE ; for ( long i = 1 ; i * i <= N ; ++ i ) { if ( N % i == 0 ) { long a = N / i ; res = Math . min ( res , Math . max ( g ( i ) , g ( a ) ) ) ; } } System . out . println ( res ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; String S = sc . next ( ) ; char [ ] s = S . toCharArray ( ) ; int ans = 0 ; for ( int i = 1 ; i <= s . length - 1 ; i ++ ) { if ( ( s [ i - 1 ] == '0' && s [ i ] == '1' ) || ( s [ i ] == '0' && s [ i - 1 ] == '1' ) ) { ans += 2 ; s [ i - 1 ] = '5' ; s [ i ] = '5' ; } } int count1 = 0 ; int count0 = 0 ; for ( int i = 0 ; i < s . length ; i ++ ) { if ( s [ i ] == '1' ) { count1 ++ ; } else if ( s [ i ] == '0' ) { count0 ++ ; } } if ( count1 > count0 ) { ans += count0 * 2 ; } else { ans += count1 * 2 ; } System . out . println ( ans ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . nextLine ( ) ; String c = sc . next ( ) ; char [ ] sChar = new char [ 3 ] ; char [ ] cChar = new char [ 3 ] ; int count = 0 ; for ( int i = 0 ; i < 3 ; i ++ ) { sChar [ i ] = s . charAt ( i ) ; cChar [ i ] = c . charAt ( i ) ; if ( sChar [ i ] == cChar [ i ] ) { int i = 0 ; count ++ ; } } System . out . println ( count ) ; } } +import java . util . * ; import java . lang . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String n = sc . next ( ) ; int [ ] a = new int [ n . length ( ) + 1 ] ; int ans = 0 ; for ( int i = 0 ; i < n . length ( ) ; i ++ ) { a [ i ] = n . charAt ( i ) - '0' ; } for ( int i = 0 ; i < n . length ( ) ; i ++ ) { int i = 0 ; ans = ans + a [ i ] ; } if ( ans % 9 == 0 ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } } +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 ] ; int count1 = 0 ; for ( int i = 0 ; i < N ; i ++ ) { a [ i ] = sc . nextInt ( ) ; if ( a [ i ] == 1 ) { int i = 0 ; count1 ++ ; } } if ( count1 == 0 ) { System . out . println ( - 1 ) ; return ; } int ans = 0 ; int num = 1 ; for ( int i = 0 ; i < N ; i ++ ) { if ( a [ i ] == num ) { num ++ ; } else { ans ++ ; } } System . out . println ( ans ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int cnt = 0 ; int ans = 0 ; Scanner sc = new Scanner ( System . in ) ; char [ ] s = sc . nextLine ( ) . toCharArray ( ) ; for ( int cnt = 0 ; cnt < s . length ; cnt ++ ) { if ( s [ cnt ] == '1' ) { ans ++ ; } } System . out . println ( ans ) ; sc . close ( ) ; } } +import java . io . OutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . PrintWriter ; import java . util . StringTokenizer ; import java . io . IOException ; import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . io . InputStream ; public class Main { public static void main ( String [ ] args ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; FastReader in = new FastReader ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; ASheepAndWolves solver = new ASheepAndWolves ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class ASheepAndWolves { public void solve ( int testNumber , FastReader in , PrintWriter out ) { out . println ( in . nextInt ( ) > in . nextInt ( ) ? " safe " : " unsafe " ) ; } } static class FastReader { BufferedReader br ; StringTokenizer st ; public FastReader ( InputStream inputStream ) { br = new BufferedReader ( new InputStreamReader ( inputStream ) ) ; } String next ( ) { while ( st == null || ! st . hasMoreElements ( ) ) { try { st = new StringTokenizer ( br . readLine ( ) ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } return st . nextToken ( ) ; } public int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } } } +import java . util . Arrays ; import java . util . Collections ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int size ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; Integer [ ] arrays = new Integer [ n ] ; int stepCnt = 0 ; int stepSize = 101 ; for ( int i = 0 ; i < arrays . length ; i ++ ) { arrays [ i ] = sc . nextInt ( ) ; } sc . close ( ) ; Arrays . sort ( arrays , Collections . reverseOrder ( ) ) ; for ( int size : arrays ) { if ( stepSize > size ) { stepCnt ++ ; stepSize = size ; } } System . out . println ( stepCnt ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int A = in . nextInt ( ) ; int B = in . nextInt ( ) ; String S = in . next ( ) ; char [ ] s_chars = S . toCharArray ( ) ; int flag = 0 ; if ( s_chars [ A ] == '-' ) { int i = 0 ; for ( int i = 0 ; i < A + B + 1 ; i ++ ) { if ( s_chars [ i ] == '-' ) { flag ++ ; } } } if ( flag == 1 ) { System . out . print ( " Yes " ) ; } else { System . out . print ( " No " ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String str , str2 ; while ( true ) { str = sc . next ( ) ; if ( str . equals ( " - " ) ) break ; str2 = " " ; int shuffulNum = sc . nextInt ( ) ; for ( int i = 0 ; i < shuffulNum ; i ++ ) { int n = sc . nextInt ( ) ; for ( int j = n ; j < str . length ( ) ; j ++ ) { str2 += str . charAt ( j ) ; } for ( int j = 0 ; j < n ; j ++ ) { int j = 0 ; str2 += str . charAt ( j ) ; } str = str2 ; str2 = " " ; } System . out . println ( str ) ; } } } +import java . io . * ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader buf = new BufferedReader ( new InputStreamReader ( System . in ) ) ; StringBuilder stb = new StringBuilder ( ) ; int a = Integer . parseInt ( buf . readLine ( ) ) ; int [ ] h = new int [ a ] ; String [ ] str = buf . readLine ( ) . split ( " " ) ; for ( int i = 0 ; i < h . length ; i ++ ) { h [ i ] = Integer . parseInt ( str [ i ] ) ; } Sert ( h , a ) ; } public static void Sert ( int [ ] h , int a ) { int i = 0 ; int v , j ; for ( int i = 0 ; i < h . length ; i ++ ) { v = h [ i ] ; j = i - 1 ; while ( j >= 0 && h [ j ] > v ) { h [ j + 1 ] = h [ j ] ; j -- ; } h [ j + 1 ] = v ; toArray ( h ) ; } } public static void toArray ( int [ ] h ) { StringBuilder sbu = new StringBuilder ( ) ; for ( int i = 0 ; i < h . length ; i ++ ) { sbu . append ( h [ i ] ) ; if ( i < h . length - 1 ) sbu . append ( " " ) ; } System . out . println ( sbu ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStream ; import java . io . InputStreamReader ; public class Main { private static final String WATHER_SUNNY = " Sunny " ; private static final String WATHER_CLOUDY = " Cloudy " ; private static final String WATHER_RAINY = " Rainy " ; public static void main ( String [ ] args ) { String today = scanTodayWeather ( System . in ) ; String tomorrow = predictTomorrowWeather ( today ) ; System . out . println ( tomorrow ) ; } private static String scanTodayWeather ( InputStream in ) { String tomorrow = null ; String today = null ; try { InputStreamReader isr = new InputStreamReader ( in ) ; BufferedReader br = new BufferedReader ( isr ) ; today = br . readLine ( ) ; br . close ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } return today ; } private static String predictTomorrowWeather ( String today ) { String tomorrow = null ; if ( today . equals ( WATHER_SUNNY ) ) { tomorrow = WATHER_CLOUDY ; } else if ( today . equals ( WATHER_CLOUDY ) ) { tomorrow = WATHER_RAINY ; } else if ( today . equals ( WATHER_RAINY ) ) { tomorrow = WATHER_SUNNY ; } return tomorrow ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int [ ] a = new int [ 3 ] ; a [ 0 ] = sc . nextInt ( ) ; a [ 1 ] = sc . nextInt ( ) ; a [ 2 ] = sc . nextInt ( ) ; int hoge ; for ( int i = 0 ; i < a . length ; i ++ ) { for ( int j = 0 ; j < i ; j ++ ) { int j = 0 ; if ( a [ i ] < a [ j ] ) { hoge = a [ i ] ; a [ i ] = a [ j ] ; a [ j ] = hoge ; } } } hoge = a [ 1 ] - a [ 0 ] ; hoge += a [ 2 ] - a [ 1 ] ; System . out . println ( hoge ) ; } } +import java . io . * ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String line ; while ( ( line = br . readLine ( ) ) != null ) { int i = numbers . length - 1 ; String [ ] numbers = line . split ( " " ) ; for ( int i = numbers . length - 1 ; i >= 0 ; i -- ) { System . out . print ( numbers [ i ] ) ; } System . out . println ( ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int years = scan . nextInt ( ) ; int money = scan . nextInt ( ) ; if ( years >= 13 ) { int money = scan . nextInt ( ) ; System . out . print ( money ) ; } else if ( years >= 6 ) { System . out . print ( money / 2 ) ; } else if ( years >= 0 ) { System . out . print ( 0 ) ; } } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner stdIn = new Scanner ( System . in ) ; int n = stdIn . nextInt ( ) ; int x = stdIn . nextInt ( ) ; int count = 1 ; int sum = 0 ; while ( n -- > 0 ) { int sum = 0 ; sum += stdIn . nextInt ( ) ; if ( x < sum ) break ; count ++ ; } System . out . println ( count ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int k = sc . nextInt ( ) ; String s = sc . next ( ) ; StringBuffer buf = new StringBuffer ( ) ; for ( int i = 0 ; i < n ; i ++ ) { char si = s . charAt ( i ) ; if ( i == k - 1 ) { char si = s . charAt ( i ) ; if ( si == 'A' ) { buf . append ( " a " ) ; } if ( si == 'B' ) { buf . append ( " b " ) ; } if ( si == 'C' ) { buf . append ( " c " ) ; } } else { buf . append ( s . charAt ( i ) ) ; } } String new_s = buf . toString ( ) ; System . out . println ( new_s ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { long resultB = b * c ; Scanner sc = new Scanner ( System . in ) ; long a = sc . nextLong ( ) ; long b = sc . nextLong ( ) ; long c = sc . nextLong ( ) ; long d = sc . nextLong ( ) ; long resultA = a * c ; resultA = resultA < a * d ? a * d : resultA ; long resultB = b * c ; resultB = resultB < b * d ? b * d : resultB ; if ( resultA < resultB ) { System . out . println ( resultB ) ; } else { System . out . println ( resultA ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int cnt = n <= x ? 1 : 0 , cur = 0 , temp ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) , x = sc . nextInt ( ) ; int cnt = n <= x ? 1 : 0 , cur = 0 , temp ; for ( int i = 0 ; i < n ; ++ i ) { temp = sc . nextInt ( ) ; cur += temp ; if ( cur <= x ) ++ cnt ; } System . out . printf ( " %d \n " , cnt ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int [ ] array = new int [ 100 ] ; int n = sc . nextInt ( ) ; for ( int i = 0 ; i < n ; i ++ ) array [ i ] = sc . nextInt ( ) ; doInsertionSort ( array , n ) ; printArray ( array , n ) ; } public static void doInsertionSort ( int [ ] array , int n ) { for ( int i = 1 ; i < n ; i ++ ) { printArray ( array , n ) ; int val = array [ i ] ; int j = i - 1 ; while ( j >= 0 && array [ j ] > val ) { int i = 0 ; array [ j + 1 ] = array [ j ] ; j -- ; } array [ j + 1 ] = val ; } } public static void printArray ( int [ ] array , int n ) { for ( int i = 0 ; i < n ; i ++ ) { if ( i != 0 ) System . out . print ( " " ) ; System . out . print ( array [ i ] ) ; } System . out . print ( " \n " ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; long x = scan . nextInt ( ) ; long y = scan . nextInt ( ) ; scan . close ( ) ; if ( x < y ) { long y = scan . nextInt ( ) ; long tmp = y ; y = x ; x = tmp ; } long ans = ( x * y ) / gcd ( x , y ) ; System . out . println ( ans ) ; } static long gcd ( long x , long y ) { if ( x % y == 0 ) return y ; else return gcd ( y , x % y ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int k = sc . nextInt ( ) ; double ans = 0 ; int times = 0 ; for ( int i = n ; i > 0 ; -- i ) { int i = n ; while ( i * Math . pow ( 2 , times ) < k ) ++ times ; ans = ans + ( 1 / ( double ) n ) * Math . pow ( 0.5 , times ) ; } System . out . println ( ans ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int x , y , z , a , b , c ; Scanner sc = new Scanner ( System . in ) ; a = 0 ; x = sc . nextInt ( ) ; y = sc . nextInt ( ) ; y = y / 1000 ; if ( y < x ) { int x , y , z , a , b , c ; System . out . println ( " -1 -1 -1 " ) ; } else if ( y == x ) { System . out . println ( " 0 0 " + y ) ; } else { z = y - x ; while ( z % 9 != 0 ) { z = z - 4 ; a ++ ; } b = z / 9 ; c = x - a - b ; if ( a < 0 || b < 0 || c < 0 ) { System . out . println ( " -1 -1 -1 " ) ; } else { System . out . println ( b + " " + a + " " + c ) ; } } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int n = scanner . nextInt ( ) ; int [ ] p = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { p [ i ] = scanner . nextInt ( ) ; } int count = 0 ; for ( int i = 0 ; i < n - 2 ; i ++ ) { int i = 0 ; if ( ( p [ i ] < p [ i + 1 ] && p [ i + 1 ] < p [ i + 2 ] ) || ( p [ i + 2 ] < p [ i + 1 ] && p [ i + 1 ] < p [ i ] ) ) { count ++ ; } } System . out . println ( count ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] arg ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] a = new int [ n ] ; int [ ] b = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) a [ i ] = sc . nextInt ( ) ; for ( int i = 0 ; i < n ; i ++ ) b [ i ] = sc . nextInt ( ) ; int c = 0 , s = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( a [ i ] > b [ i ] ) { c = c + a [ i ] ; s = s + b [ i ] ; } } System . out . println ( c - s ) ; } } +import java . util . * ; import java . io . * ; public class Main { public static void main ( String [ ] args ) { Scanner s = new Scanner ( new BufferedReader ( new InputStreamReader ( System . in ) ) ) ; String turn = s . next ( ) ; Integer tarou = 0 ; Integer hanako = 0 ; for ( int i = 0 ; i < Integer . parseInt ( turn ) ; i ++ ) { String tarou_card = s . next ( ) ; String hanako_card = s . next ( ) ; Integer result = tarou_card . compareTo ( hanako_card ) ; if ( result == 0 ) { if ( tarou_card . equals ( hanako_card ) ) { tarou += 1 ; hanako += 1 ; } } else if ( result > 0 ) { String hanako_card = s . next ( ) ; tarou += 3 ; } else { hanako += 3 ; } } s . close ( ) ; System . out . println ( tarou + " " + hanako ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int i = min ; Scanner sc = new Scanner ( System . in ) ; int k = sc . nextInt ( ) ; int x = sc . nextInt ( ) ; int min = x - k + 1 ; int max = x + k - 1 ; for ( int i = min ; i <= max ; i ++ ) { System . out . print ( i + " " ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner cin = new Scanner ( System . in ) ; while ( true ) { int n = cin . nextInt ( ) , x = cin . nextInt ( ) ; int res = 0 ; if ( n == 0 && x == 0 ) break ; for ( int i = 1 ; i <= n - 2 ; i ++ ) { int k = j + 1 ; for ( int j = i + 1 ; j <= n - 1 ; j ++ ) { for ( int k = j + 1 ; k <= n ; k ++ ) { if ( i + j + k == x ) res ++ ; } } } System . out . println ( res ) ; } } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { int j = 0 ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] b = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { int m = sc . nextInt ( ) ; b [ i ] = m ; } int w ; for ( int h = 0 ; h < ( n / 2 ) ; h ++ ) { w = b [ h ] ; b [ h ] = b [ n - 1 - h ] ; b [ n - 1 - h ] = w ; } for ( int j = 0 ; j < n - 1 ; j ++ ) { System . out . print ( b [ j ] + " " ) ; } System . out . print ( b [ n - 1 ] ) ; System . out . println ( " " ) ; } } +import java . util . ArrayList ; import java . util . List ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int dif = 0 ; Scanner sc = new Scanner ( System . in ) ; int x = sc . nextInt ( ) ; int n = sc . nextInt ( ) ; List < Integer > list = new ArrayList < > ( ) ; int ans = x ; for ( int i = 0 ; i < n ; i ++ ) { list . add ( sc . nextInt ( ) ) ; } for ( int dif = 0 ; dif <= n ; dif ++ ) { if ( ! list . contains ( x - dif ) ) { ans = x - dif ; break ; } if ( ! list . contains ( x + dif ) ) { ans = x + dif ; break ; } } if ( n > 100 ) { System . out . println ( " error " ) ; } System . out . println ( ans ) ; sc . close ( ) ; } } +import java . util . ArrayList ; import java . util . Comparator ; import java . util . List ; import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = Integer . parseInt ( sc . next ( ) ) ; List < Integer > numList = new ArrayList < > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { numList . add ( Integer . parseInt ( sc . next ( ) ) ) ; } numList . sort ( Comparator . reverseOrder ( ) ) ; int preNum = 0 ; List < Integer > removeList = new ArrayList < > ( ) ; for ( int i = 0 ; i < numList . size ( ) ; i ++ ) { Integer i ; int n = numList . get ( i ) . intValue ( ) ; if ( n == preNum ) { removeList . add ( i ) ; } else { preNum = n ; } } removeList . sort ( Comparator . reverseOrder ( ) ) ; for ( Integer i : removeList ) { numList . remove ( i . intValue ( ) ) ; } System . out . println ( numList . size ( ) ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; long n = Long . parseLong ( scanner . nextLine ( ) ) ; char [ ] ans = scanner . nextLine ( ) . toCharArray ( ) ; int a = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( i < n - 2 && ans [ i ] == 'A' ) { if ( ans [ i + 1 ] == 'B' ) { if ( ans [ i + 2 ] == 'C' ) { int i = 0 ; a ++ ; i += 2 ; } } } } System . out . println ( a ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long a , b , g , l ; while ( sc . hasNext ( ) ) { a = sc . nextLong ( ) ; b = sc . nextLong ( ) ; g = gcd ( a , b ) ; l = ( a * b ) / g ; System . out . println ( g + " " + l ) ; } } private static long gcd ( long a , long b ) { long a , b , g , l ; if ( a == 0 ) return b ; else if ( b == 0 ) return a ; return gcd ( b , a % b ) ; } } +import java . util . * ; import java . io . * ; import java . math . * ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; if ( a == 2 ) { System . out . println ( a ) ; return ; } ArrayList < Integer > list = getPrime ( a ) ; while ( true ) { if ( check ( a , list ) ) { System . out . println ( a ) ; return ; } a ++ ; } } static ArrayList < Integer > getPrime ( int x ) { ArrayList < Integer > list = new ArrayList < Integer > ( ) ; list . add ( 2 ) ; int max = ( int ) Math . pow ( x * 2 , 0.5 ) ; for ( int i = 3 ; i < max ; i += 2 ) { boolean chk = true ; for ( int j : list ) { if ( i % j == 0 ) { chk = false ; break ; } } if ( chk ) { list . add ( i ) ; } } return list ; } static boolean check ( int x , List < Integer > list ) { int j ; for ( int j : list ) { if ( x % j == 0 ) { return false ; } } return true ; } } +import java . util . Arrays ; import java . util . Scanner ; public class Main { static int chocoAmount ; public static void main ( String [ ] args ) { Scanner s = new Scanner ( System . in ) ; int N = s . nextInt ( ) ; int X = s . nextInt ( ) ; int [ ] race = new int [ N ] ; int donuts = 0 ; int result = 0 ; for ( int i = 0 ; i < N ; i ++ ) { race [ i ] = s . nextInt ( ) ; donuts += race [ i ] ; } int rest = X - donuts ; Arrays . sort ( race ) ; if ( race [ 0 ] < rest ) { int rest = X - donuts ; result = rest / race [ 0 ] ; System . out . println ( result + N ) ; } else { System . out . println ( N ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { long ansA , ansB ; Scanner sc = new Scanner ( System . in ) ; long a = sc . nextLong ( ) ; long b = sc . nextLong ( ) ; long k = sc . nextLong ( ) ; long ansA , ansB ; if ( a - k >= 0 ) { ansA = a - k ; } else { ansA = 0 ; } k -= a ; if ( k > 0 ) { if ( b - k >= 0 ) { ansB = b - k ; } else { ansB = 0 ; } } else { ansB = b ; } System . out . println ( ansA + " " + ansB ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int A = sc . nextInt ( ) ; int B = sc . nextInt ( ) ; int plus = A + B ; int minus = A - B ; int kakeru = A * B ; if ( B > - B ) { int kakeru = A * B ; if ( plus < kakeru ) System . out . println ( kakeru ) ; else System . out . println ( plus ) ; } else { if ( minus < kakeru ) System . out . println ( kakeru ) ; else System . out . println ( minus ) ; } } } +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 ) ; TaskA_147 solver = new TaskA_147 ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class TaskA_147 { public void solve ( int testNumber , Scanner in , PrintWriter out ) { PrintWriter out = new PrintWriter ( outputStream ) ; int a = in . nextInt ( ) ; int b = in . nextInt ( ) ; int c = in . nextInt ( ) ; out . println ( a + b + c >= 22 ? " bust " : " win " ) ; } } } +import java . io . * ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String input = br . readLine ( ) ; for ( int i = 0 ; i < input . length ( ) ; i ++ ) { char a = input . charAt ( i ) ; if ( Character . isUpperCase ( a ) ) { char a = input . charAt ( i ) ; System . out . print ( Character . toLowerCase ( a ) ) ; } else { System . out . print ( Character . toUpperCase ( a ) ) ; } } System . out . print ( " \n " ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int j = 0 ; try ( Scanner scan = new Scanner ( System . in ) ) { int K = scan . nextInt ( ) ; int S = scan . nextInt ( ) ; int count = 0 ; for ( int i = 0 ; i <= K ; i ++ ) { for ( int j = 0 ; j <= K ; j ++ ) { if ( S - i - j >= 0 && S - i - j <= K ) count ++ ; } } System . out . println ( count ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int n = Integer . parseInt ( scan . next ( ) ) ; int x = 0 ; int y = 0 ; int t = 0 ; boolean possible = true ; for ( int i = 0 ; i < n ; ++ i ) { int ti = Integer . parseInt ( scan . next ( ) ) ; int xi = Integer . parseInt ( scan . next ( ) ) ; int yi = Integer . parseInt ( scan . next ( ) ) ; int kyori = Math . abs ( x - xi ) + Math . abs ( y - yi ) ; int jikokuNoSa = Math . abs ( ti - t ) ; if ( kyori <= jikokuNoSa && Math . abs ( jikokuNoSa - kyori ) % 2 == 0 ) { t = ti ; x = xi ; y = yi ; } else { possible = false ; break ; } } scan . close ( ) ; if ( possible ) { int yi = Integer . parseInt ( scan . next ( ) ) ; System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } } +import java . util . * ; class Main { public static void main ( String [ ] g ) { Scanner S = new Scanner ( System . in ) ; for ( int i = S . nextInt ( ) , j , x , y , z , a [ ] = new int [ 3 ] ; i -- > 0 ; System . out . println ( a [ 2 ] * a [ 2 ] == a [ 1 ] * a [ 1 ] + a [ 0 ] * a [ 0 ] ? " YES " : " NO " ) ) { int i = S . nextInt ( ) , j , x , y , z , a [ ] = new int [ 3 ] ; for ( j = 0 ; j < 3 ; ) a [ j ++ ] = S . nextInt ( ) ; Arrays . sort ( a ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { long y = 0 ; Scanner sc = new Scanner ( System . in ) ; long n = sc . nextLong ( ) ; long checkx = 0 ; long x = 0 ; long checky = 0 ; long y = 0 ; for ( checkx = 1 ; checkx <= Math . sqrt ( n ) ; checkx ++ ) { if ( n % checkx == 0 ) { checky = n / checkx ; if ( x == 0 && y == 0 ) { x = checkx ; y = checky ; } if ( checkx + checky < x + y ) { x = checkx ; y = checky ; } } } System . out . println ( x + y - 2 ) ; } } +import java . util . * ; import java . io . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int k = sc . nextInt ( ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; if ( a % k == 0 || b % k == 0 ) { int temp = a - rem ; System . out . println ( " OK " ) ; return ; } int rem = a % k ; int temp = a - rem ; temp += k ; for ( int i = temp ; i < b ; i += k ) { if ( temp > a ) { System . out . println ( " OK " ) ; return ; } } System . out . println ( " NG " ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner cin = new Scanner ( System . in ) ; double r = cin . nextDouble ( ) ; System . out . printf ( " %.6f %.6f \n " , cal_area ( r ) , cal_cirum ( r ) ) ; } private static double cal_cirum ( double r ) { return ( r * 2 * Math . PI ) ; } private static double cal_area ( double r ) { double r = cin . nextDouble ( ) ; return ( r * r * Math . PI ) ; } } +import java . util . Scanner ; public class Main { public static int Int ( int a ) { int i = 0 ; if ( a == 9 ) { i = 1 ; } else { i = 9 ; } return i ; } public static void main ( String [ ] args ) { int a = scan . nextInt ( ) ; Scanner scan = new Scanner ( System . in ) ; int a = scan . nextInt ( ) ; int b = Int ( a % 10 ) ; a /= 10 ; int c = Int ( a % 10 ) ; a /= 10 ; int d = Int ( a % 10 ) ; System . out . println ( d + " " + c + " " + b ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner nine = new Scanner ( System . in ) ; int number1 = nine . nextInt ( ) ; int number2 = nine . nextInt ( ) ; if ( 1 <= number1 && number1 <= 9 && 1 <= number2 && number2 <= 9 ) { int number2 = nine . nextInt ( ) ; int answer = number1 * number2 ; System . out . println ( answer ) ; } else { System . out . println ( " -1 " ) ; } } } +import java . io . BufferedReader ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws Exception { BufferedReader in = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String W = in . readLine ( ) ; int N = Integer . parseInt ( W ) ; W = in . readLine ( ) ; String [ ] Ws = W . split ( " " ) ; int [ ] P = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { P [ i ] = Integer . parseInt ( Ws [ i ] ) ; } int ans = 0 ; int Pj = Integer . MAX_VALUE ; for ( int i = 0 ; i < N ; i ++ ) { int i = 0 ; if ( P [ i ] <= Pj ) { ans ++ ; Pj = P [ i ] ; } } System . out . println ( ans ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int k = scan . nextInt ( ) ; long total = 0 ; for ( int a = 1 ; a < k + 1 ; a ++ ) { for ( int b = 1 ; b < k + 1 ; b ++ ) { int c = 1 ; for ( int c = 1 ; c < k + 1 ; c ++ ) { total += gcd ( gcd ( a , b ) , c ) ; } } } System . out . println ( total ) ; } static int gcd ( int p , int q ) { if ( p % q == 0 ) return q ; return gcd ( q , p % q ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner stdIn = new Scanner ( System . in ) ; int n = stdIn . nextInt ( ) ; int [ ] s = new int [ n ] ; s [ 2 ] = n % 10 ; n /= 10 ; s [ 1 ] = n % 10 ; n /= 10 ; s [ 0 ] = n % 10 ; for ( int i = 0 ; i < 3 ; i ++ ) { if ( s [ i ] == 1 ) { s [ i ] = 9 ; } else { s [ i ] = 1 ; } } int goal = 100 * s [ 0 ] + 10 * s [ 1 ] + s [ 2 ] ; System . out . println ( goal ) ; } } +import java . util . * ; public class Main { static final int MOD = 1000000007 ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; double w = sc . nextInt ( ) ; double h = sc . nextInt ( ) ; int x = sc . nextInt ( ) ; int y = sc . nextInt ( ) ; int result = 0 ; if ( x * 2 == w && y * 2 == h ) { int result = 0 ; result ++ ; } System . out . println ( ( w * h / 2.0 ) + " " + result ) ; } } +import java . util . * ; import java . lang . * ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int N = scanner . nextInt ( ) ; int M = scanner . nextInt ( ) ; List < Integer > a = new ArrayList < > ( ) ; for ( int i = 0 ; i < M ; i ++ ) { a . add ( scanner . nextInt ( ) ) ; } Set < Integer > bloken = new HashSet < > ( a ) ; List < Integer > w = new ArrayList < > ( ) ; w . add ( 1 ) ; if ( bloken . contains ( 1 ) ) { w . add ( 0 ) ; } else { int i = 2 ; w . add ( 1 ) ; } for ( int i = 2 ; i <= N ; i ++ ) { if ( bloken . contains ( i ) ) { w . add ( 0 ) ; } else { w . add ( ( w . get ( i - 1 ) + w . get ( i - 2 ) ) % 1000000007 ) ; } } System . out . println ( w . get ( N ) % 1000000007 ) ; } } +import java . io . * ; public class Main { public static void main ( String [ ] args ) { try { BufferedReader in = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int count = Integer . parseInt ( in . readLine ( ) ) ; int [ ] iArr = new int [ count ] ; String [ ] sArr = in . readLine ( ) . split ( " " ) ; for ( int i = 0 ; i < sArr . length ; i ++ ) { iArr [ i ] = Integer . parseInt ( sArr [ i ] ) ; } int swapCount = 0 ; for ( int i = 0 ; i < iArr . length ; i ++ ) { int i ; int minj = i ; for ( int j = i ; j < iArr . length ; j ++ ) { if ( iArr [ j ] < iArr [ minj ] ) { minj = j ; } } if ( minj != i ) { int tmp = iArr [ minj ] ; iArr [ minj ] = iArr [ i ] ; iArr [ i ] = tmp ; swapCount ++ ; } } StringBuilder sb = new StringBuilder ( ) ; for ( int i : iArr ) { sb . append ( i ) . append ( " " ) ; } System . out . println ( sb . toString ( ) . trim ( ) ) ; System . out . println ( swapCount ) ; } catch ( IOException e ) { } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int input_500 = sc . nextInt ( ) ; int input_100 = sc . nextInt ( ) ; int input_50 = sc . nextInt ( ) ; int input_pay = sc . nextInt ( ) ; int result = 0 ; sc . close ( ) ; for ( int i = 0 ; i <= input_500 ; i ++ ) { for ( int j = 0 ; j <= input_100 ; j ++ ) { for ( int k = 0 ; k <= input_50 ; k ++ ) { int k = 0 ; if ( i * 500 + j * 100 + k * 50 == input_pay ) { result ++ ; } } } } System . out . println ( result ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long n = sc . nextLong ( ) ; int k = 1 ; long z = 26L ; long d = 0L ; while ( z < n ) { int i = k - 1 ; d = z ; k ++ ; z += ( long ) Math . pow ( 26 , k ) ; } long y = n - d - 1L ; String alp = " abcdefghijklmnopqrstuvwxyz " ; String [ ] s = new String [ k ] ; for ( int i = k - 1 ; i >= 0 ; i -- ) { int c = ( int ) ( y % 26L ) ; s [ i ] = alp . substring ( c , c + 1 ) ; y = y / 26L ; } System . out . println ( String . join ( " " , s ) ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; String t = sc . next ( ) ; char [ ] s1 = s . toCharArray ( ) ; char [ ] t1 = t . toCharArray ( ) ; int cnt = 0 ; for ( int i = 0 ; i < s1 . length ; i ++ ) { if ( s1 [ i ] != t1 [ i ] ) { int i = 0 ; cnt ++ ; } } System . out . println ( cnt ) ; sc . close ( ) ; } } +import java . io . * ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String line = br . readLine ( ) ; String ans = " " ; for ( int i = 0 ; i < line . length ( ) ; i ++ ) { String str = line . substring ( i , i + 1 ) ; if ( str . equals ( str . toUpperCase ( ) ) ) { String str = line . substring ( i , i + 1 ) ; ans += str . toLowerCase ( ) ; } else { ans += str . toUpperCase ( ) ; } } System . out . println ( ans ) ; } } +import java . util . ArrayList ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; ArrayList < Integer > list = new ArrayList < > ( ) ; for ( int i = 0 ; i < 5 ; i ++ ) { int i = 0 ; list . add ( Integer . parseInt ( sc . next ( ) ) ) ; } sc . close ( ) ; for ( int i = 0 ; i < 5 ; i ++ ) { if ( list . get ( i ) == 0 ) { int ans = i + 1 ; System . out . println ( ans ) ; return ; } } } } +import java . util . * ; import static java . lang . System . * ; import static java . lang . Math . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( in ) ; int n = sc . nextInt ( ) ; int [ ] [ ] a = new int [ 2 ] [ n + 1 ] ; for ( int i = 0 ; i < 2 ; i ++ ) { for ( int j = 1 ; j <= n ; j ++ ) { int j = 1 ; a [ i ] [ j ] = a [ i ] [ j - 1 ] + sc . nextInt ( ) ; } } int ans = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = 1 ; j <= n ; j ++ ) { ans = max ( ans , a [ 0 ] [ i ] + ( a [ 1 ] [ n ] - a [ 1 ] [ i - 1 ] ) ) ; } } 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 ( ) ; long max = 0L ; int Bi = 0 ; int save = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( i == N - 1 ) { max += save ; break ; } Bi = sc . nextInt ( ) ; if ( i == 0 ) { int i = 0 ; max += Bi ; save = Bi ; } else if ( Bi < save ) { max += Bi ; save = Bi ; } else { max += save ; save = Bi ; } } System . out . println ( max ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int k = sc . nextInt ( ) ; sc . close ( ) ; double prob = 0.0 ; for ( int i = 1 ; i <= n ; i ++ ) { double diff = 1.0 / n ; int points = i ; double diff = 1.0 / n ; while ( points < k ) { diff *= 0.5 ; points *= 2 ; } prob += diff ; } System . out . println ( prob ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; char [ ] s = sc . next ( ) . toCharArray ( ) ; int slen = s . length ; char [ ] t = sc . next ( ) . toCharArray ( ) ; int tlen = t . length ; int ans = Integer . MAX_VALUE ; for ( int i = 0 ; i < slen - tlen + 1 ; i ++ ) { int cnt = 0 ; for ( int j = 0 ; j < tlen ; j ++ ) { int j = 0 ; if ( s [ i + j ] != t [ j ] ) cnt ++ ; } if ( cnt < ans ) ans = cnt ; } System . out . println ( ans ) ; sc . close ( ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String S = sc . next ( ) ; int n = 1 ; int count = 0 ; if ( S . length ( ) % 2 == 0 ) { n = S . length ( ) ; } else { int i = 0 ; n = S . length ( ) - 1 ; } for ( int i = 0 ; i < n / 2 ; i ++ ) { if ( S . charAt ( i ) != S . charAt ( S . length ( ) - 1 - i ) ) { count ++ ; } } System . out . println ( count ) ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] [ ] t = new int [ n ] [ 3 ] ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < 3 ; j ++ ) { t [ i ] [ j ] = sc . nextInt ( ) ; } if ( triangle ( i , t ) ) { System . out . println ( " YES " ) ; } else { int j = 0 ; System . out . println ( " NO " ) ; } } } public static boolean triangle ( int i , int [ ] [ ] t ) { double max = Math . max ( Math . max ( t [ i ] [ 0 ] , t [ i ] [ 1 ] ) , t [ i ] [ 2 ] ) ; double res = Math . min ( Math . min ( Math . hypot ( t [ i ] [ 0 ] , t [ i ] [ 1 ] ) , Math . hypot ( t [ i ] [ 0 ] , t [ i ] [ 2 ] ) ) , Math . hypot ( t [ i ] [ 2 ] , t [ i ] [ 1 ] ) ) ; if ( res == max ) { return true ; } else { return false ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int timeTook = 0 ; Scanner inputs = new Scanner ( System . in ) ; int n = inputs . nextInt ( ) ; int x = inputs . nextInt ( ) ; int t = inputs . nextInt ( ) ; int takoyakiMade = 0 ; int timeTook = 0 ; do { timeTook += t ; takoyakiMade += x ; } while ( takoyakiMade < n ) ; System . out . println ( timeTook ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; long [ ] A = new long [ N + 1 ] ; long [ ] B = new long [ N ] ; for ( int i = 0 ; i < N + 1 ; i ++ ) { A [ i ] = sc . nextLong ( ) ; } for ( int i = 0 ; i < N ; i ++ ) { B [ i ] = sc . nextLong ( ) ; } long sum = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( A [ i ] > B [ i ] ) { int i = 0 ; sum += B [ i ] ; } else { sum += A [ i ] ; long temp = A [ i + 1 ] ; A [ i + 1 ] -= B [ i ] - A [ i ] ; A [ i + 1 ] = Math . max ( A [ i + 1 ] , 0 ) ; sum += temp - A [ i + 1 ] ; } } System . out . println ( sum ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int A = sc . nextInt ( ) ; int B = sc . nextInt ( ) ; if ( 0 <= A && A <= 5 ) { B = 0 ; System . out . print ( B ) ; } else if ( 6 <= A && A <= 12 ) { B = B / 2 ; System . out . print ( B ) ; } else if ( 13 <= A && A <= 100 ) { int B = sc . nextInt ( ) ; System . out . print ( B ) ; } } } +import java . util . * ; import java . lang . * ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int N = scan . nextInt ( ) ; int K = scan . nextInt ( ) ; int [ ] ans = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { int i = 0 ; ans [ i ] = scan . nextInt ( ) ; } Arrays . sort ( ans ) ; int answer = 0 ; for ( int i = 0 ; i < K ; i ++ ) { answer = answer + ans [ i ] ; } System . out . println ( answer ) ; } } +import java . util . ArrayDeque ; import java . util . ArrayList ; import java . util . Arrays ; import java . util . Deque ; import java . util . List ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int wk = 0 ; int ans = 0 ; ans = N / 2 ; wk = N % 2 ; if ( wk == 1 ) { int ans = 0 ; ans = ans + 1 ; } System . out . println ( ans ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; char [ ] s = sc . next ( ) . toCharArray ( ) ; int a = 0 ; int b = 0 ; for ( int i = 0 ; i < s . length ; i ++ ) { char c = s [ i ] ; if ( i % 2 == 0 ) { if ( c == '0' ) a ++ ; else b ++ ; } else { char c = s [ i ] ; if ( c == '1' ) a ++ ; else b ++ ; } } System . out . println ( Math . min ( a , b ) ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { try ( Scanner cs = new Scanner ( System . in ) ) { char ch = line . charAt ( i ) ; String line = cs . nextLine ( ) ; String answer = " " ; int length = line . length ( ) ; for ( int i = 0 ; i < length ; i ++ ) { char ch = line . charAt ( i ) ; if ( Character . isLowerCase ( ch ) ) { System . out . print ( Character . toUpperCase ( ch ) ) ; } else { System . out . print ( Character . toLowerCase ( ch ) ) ; } } System . out . printf ( " \n " ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String S = sc . next ( ) ; char [ ] s = S . toCharArray ( ) ; int n = S . length ( ) ; boolean OK = true ; int i = 0 ; int j = ( n - 1 ) / 2 - 1 ; while ( j - i >= 1 ) { if ( s [ i ] == s [ j ] && s [ n - 1 - i ] == s [ n - 1 - j ] ) { i ++ ; j -- ; } else { int k = 0 ; OK = false ; break ; } } for ( int k = 0 ; k < n / 2 ; k ++ ) { if ( s [ k ] != s [ n - 1 - k ] ) { OK = false ; break ; } } System . out . println ( OK ? " Yes " : " No " ) ; } } +import java . io . BufferedReader ; import java . io . * ; import java . util . * ; import java . util . ArrayList ; import java . util . Iterator ; import java . util . List ; import java . util . Collections ; import java . util . Arrays ; public class Main { public static void main ( final String [ ] args ) { final Scanner sc = new Scanner ( System . in ) ; final List < Integer > list = new ArrayList < > ( ) ; int n = sc . nextInt ( ) ; int s1 = 0 ; int s2 = 0 ; int min = 10001 ; for ( int i = 0 ; i < n ; i ++ ) { list . add ( sc . nextInt ( ) ) ; } for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { if ( j <= i ) { s1 += list . get ( j ) ; } else { int j = 0 ; s2 += list . get ( j ) ; } } if ( min >= Math . abs ( s1 - s2 ) ) { min = Math . abs ( s1 - s2 ) ; } s1 = 0 ; s2 = 0 ; } System . out . println ( min ) ; } } +import java . util . Scanner ; import java . util . Arrays ; import java . util . stream . Stream ; import java . util . stream . IntStream ; import java . lang . StringBuilder ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; String N = sc . next ( ) ; int [ ] cubes = new int [ 2 ] ; cubes [ 0 ] = 0 ; cubes [ 1 ] = 0 ; for ( int i = 0 ; i < N . length ( ) ; i ++ ) { int tmp = ( int ) ( N . charAt ( i ) - '0' ) ; cubes [ tmp ] += 1 ; } System . out . println ( Math . min ( cubes [ 0 ] , cubes [ 1 ] ) * 2 ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int j = 1 ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int cnt = 0 ; Set < Integer > set = new TreeSet < > ( ) ; for ( int i = 1 ; i <= n ; i += 2 ) { int tmp = i ; for ( int j = 1 ; j <= Math . sqrt ( tmp ) ; j ++ ) { if ( tmp % j == 0 ) { set . add ( tmp ) ; set . add ( j ) ; set . add ( tmp / j ) ; } } if ( set . size ( ) == 8 ) { cnt ++ ; } set . clear ( ) ; } System . out . println ( cnt ) ; } } +import java . util . Arrays ; import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { int i = 1 ; Scanner s = new Scanner ( System . in ) ; int stones = s . nextInt ( ) ; int [ ] arr = new int [ stones ] ; for ( int i = 0 ; i < stones ; i ++ ) { arr [ i ] = s . nextInt ( ) ; } long [ ] dp = new long [ stones ] ; dp [ 0 ] = 0 ; for ( int i = 1 ; i < stones ; i ++ ) { long option1 = Math . abs ( arr [ i ] - arr [ i - 1 ] ) + dp [ i - 1 ] ; long option2 = i == 1 ? Integer . MAX_VALUE : Math . abs ( arr [ i ] - arr [ i - 2 ] ) + dp [ i - 2 ] ; dp [ i ] = Math . min ( option1 , option2 ) ; } System . out . println ( dp [ stones - 1 ] ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int temp = 0 ; Scanner sc = new Scanner ( System . in ) ; int x = sc . nextInt ( ) ; int y = sc . nextInt ( ) ; sc . close ( ) ; for ( int i = 0 ; i < x ; i ++ ) { temp += 2 ; if ( ( i + 1 ) == x ) { if ( temp == y ) { System . out . println ( " Yes " ) ; } else { for ( int j = i ; j >= 0 ; j -- ) { temp -= 2 ; temp += 4 ; if ( temp == y ) { System . out . println ( " Yes " ) ; break ; } if ( j == 0 ) { int j = i ; System . out . println ( " No " ) ; } } } } } } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int N = scan . nextInt ( ) ; int [ ] data = new int [ N ] ; int sum = 0 ; for ( int i = 0 ; i < N ; i ++ ) { int i = 0 ; data [ i ] = scan . nextInt ( ) ; } for ( int i = 0 ; i < N ; i ++ ) { while ( data [ i ] % 2 == 0 ) { sum ++ ; data [ i ] /= 2 ; } } System . out . println ( sum ) ; } } +import java . io . * ; import java . util . * ; import static java . lang . System . * ; import static java . lang . Math . * ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String [ ] s = br . readLine ( ) . split ( " " ) ; long A = Long . parseLong ( s [ 0 ] ) ; long B = Long . parseLong ( s [ 1 ] ) ; long C = Long . parseLong ( s [ 2 ] ) ; long K = Long . parseLong ( s [ 3 ] ) ; long sum = 0 ; boolean flag = true ; if ( K > A && flag == true ) { K -= A ; sum += A ; } else if ( K <= A && flag == true ) { sum += K ; K = 0 ; flag = false ; } if ( K > B && flag == true ) { K -= B ; } else if ( K <= B && flag == true ) { K = 0 ; flag = false ; } if ( K > C && flag == true ) { boolean flag = true ; K -= C ; sum -= C ; } else if ( K <= C && flag == true ) { sum -= K ; K = 0 ; flag = false ; } out . println ( sum ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int T = sc . nextInt ( ) ; int min = 10001 ; for ( int i = 0 ; i < N ; i ++ ) { int cost = sc . nextInt ( ) ; int cost = sc . nextInt ( ) ; if ( sc . nextInt ( ) <= T ) { min = Math . min ( min , cost ) ; } } if ( min == 10001 ) { System . out . println ( " TLE " ) ; } else { System . out . println ( min ) ; } } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; try { String str = br . readLine ( ) ; int N = Integer . parseInt ( str ) ; str = br . readLine ( ) ; String [ ] s = str . split ( " " , 0 ) ; int [ ] a = new int [ 8 ] ; for ( int i = 0 ; i < 8 ; i ++ ) { a [ i ] = 0 ; } int count = 0 ; int over = 0 ; for ( int i = 0 ; i < N ; i ++ ) { int x = Integer . parseInt ( s [ i ] ) ; if ( x >= 3200 ) { over ++ ; } else if ( a [ x / 400 ] == 0 ) { int x = Integer . parseInt ( s [ i ] ) ; count ++ ; a [ x / 400 ] ++ ; } } int min = count ; if ( min == 0 ) min = 1 ; int max = over + count ; System . out . println ( min + " " + max ) ; } catch ( Exception e ) { System . exit ( 0 ) ; } } } +import java . io . OutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . PrintWriter ; import java . util . StringTokenizer ; import java . io . IOException ; import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . io . InputStream ; public class Main { public static void main ( String [ ] args ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; InputReader in = new InputReader ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; AAirplane solver = new AAirplane ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class AAirplane { public void solve ( int testNumber , InputReader in , PrintWriter out ) { int p = in . nextInt ( ) ; int q = in . nextInt ( ) ; int r = in . nextInt ( ) ; out . println ( Math . min ( Math . min ( p + q , p + r ) , q + r ) ) ; } } static class InputReader { public BufferedReader reader ; public StringTokenizer tokenizer ; public InputReader ( InputStream stream ) { reader = new BufferedReader ( new InputStreamReader ( stream ) , 32768 ) ; tokenizer = null ; } public String next ( ) { while ( tokenizer == null || ! tokenizer . hasMoreTokens ( ) ) { try { tokenizer = new StringTokenizer ( reader . readLine ( ) ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } } return tokenizer . nextToken ( ) ; } public int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . StringTokenizer ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; try { String s = br . readLine ( ) ; StringTokenizer st ; while ( s != null ) { StringTokenizer st ; st = new StringTokenizer ( s ) ; int p = Integer . parseInt ( st . nextToken ( ) ) + Integer . parseInt ( st . nextToken ( ) ) ; System . out . println ( ( int ) Math . log10 ( p ) + 1 ) ; s = br . readLine ( ) ; } } catch ( Exception ex ) { System . exit ( 0 ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; int x = sc . nextInt ( ) , n = sc . nextInt ( ) , min = 301 ; int [ ] p = new int [ n ] , a = new int [ 300 - n ] ; for ( int i = 0 ; i < n ; i ++ ) { p [ i ] = sc . nextInt ( ) ; } int l = 0 ; for ( int i = - 150 ; i < 150 ; i ++ ) { int f = 0 ; for ( int j = 0 ; j < n ; j ++ ) { if ( i == p [ j ] ) { f ++ ; break ; } } if ( f == 0 ) { a [ l ] = i ; l ++ ; } } if ( n == 0 ) { System . out . println ( x ) ; } else { for ( int i = 0 ; i < a . length ; i ++ ) { if ( min <= ( int ) Math . abs ( x - a [ i ] ) ) { System . out . println ( a [ i - 1 ] ) ; break ; } else { min = ( int ) Math . abs ( x - a [ i ] ) ; } } } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int j = 0 ; Scanner s = new Scanner ( System . in ) ; int N = s . nextInt ( ) ; int [ ] H = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { H [ i ] = s . nextInt ( ) ; } int cnt = 0 ; List < Integer > l = new ArrayList < > ( ) ; for ( int j = 0 ; j < N ; j ++ ) { if ( j == 0 ) continue ; if ( H [ j - 1 ] >= H [ j ] ) cnt ++ ; else { l . add ( cnt ) ; cnt = 0 ; } } l . add ( cnt ) ; Collections . sort ( l , Collections . reverseOrder ( ) ) ; System . out . print ( l . get ( 0 ) ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int d = sc . nextInt ( ) ; int sta = d * 2 + 1 ; for ( int i = 0 ; i < 20 ; i ++ ) { if ( sta * i >= n ) { System . out . println ( i ) ; break ; } } } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws NumberFormatException , IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int n = Integer . parseInt ( br . readLine ( ) ) ; String [ ] tmpArray = br . readLine ( ) . split ( " " ) ; int [ ] input = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { input [ i ] = Integer . parseInt ( tmpArray [ i ] ) ; } int target = 1 ; int length = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( input [ i ] == target ) { int i = 0 ; target ++ ; length ++ ; } } System . out . println ( length > 0 ? n - length : - 1 ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int a = sc . nextInt ( ) ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int cnt = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int a = sc . nextInt ( ) ; while ( ( a % 2 ) == 0 ) { cnt ++ ; a /= 2 ; } } System . out . println ( cnt ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner stdIn = new Scanner ( System . in ) ; int N = stdIn . nextInt ( ) ; int [ ] A = new int [ N ] ; int count = 0 ; int ans = 0 ; for ( int i = 0 ; i < N ; i ++ ) { A [ i ] = stdIn . nextInt ( ) ; if ( A [ i ] % 2 == 0 ) { count ++ ; if ( A [ i ] % 3 == 0 || A [ i ] % 5 == 0 ) { ans ++ ; } } } if ( ans == count ) { System . out . println ( " APPROVED " ) ; } else { int i = 0 ; System . out . println ( " DENIED " ) ; } stdIn . close ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String S = sc . next ( ) ; char c = ' ' ; for ( int i = 0 ; i < S . length ( ) ; i = i + 2 ) { int k = 1 ; c = S . charAt ( i ) ; if ( c != 'R' && c != 'U' && c != 'D' ) { System . out . println ( " No " ) ; return ; } } for ( int k = 1 ; k < S . length ( ) ; k = k + 2 ) { c = S . charAt ( k ) ; if ( c != 'L' && c != 'U' && c != 'D' ) { System . out . println ( " No " ) ; return ; } } System . out . println ( " Yes " ) ; } } +import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . util . ArrayList ; import java . util . Collections ; public class Main { public static void main ( String [ ] args ) throws Exception { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String line = br . readLine ( ) ; int n = Integer . parseInt ( line ) ; int tarouScore = 0 ; int hanakoScore = 0 ; for ( int i = 0 ; i < n ; i ++ ) { String [ ] s = br . readLine ( ) . split ( " " ) ; String tarou = s [ 0 ] ; String hanako = s [ 1 ] ; ArrayList < String > dic = new ArrayList < String > ( ) ; dic . add ( tarou ) ; dic . add ( hanako ) ; Collections . sort ( dic ) ; if ( tarou . equals ( hanako ) ) { int hanakoScore = 0 ; tarouScore += 1 ; hanakoScore += 1 ; } else if ( tarou . equals ( dic . get ( 0 ) ) ) { hanakoScore += 3 ; } else { tarouScore += 3 ; } } System . out . println ( tarouScore + " " + hanakoScore ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = Integer . parseInt ( ( sc . next ( ) ) ) ; long [ ] aArr = new long [ N + 1 ] ; for ( int i = 0 ; i <= N ; i ++ ) { aArr [ i ] = Long . parseLong ( sc . next ( ) ) ; } long [ ] bArr = new long [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { bArr [ i ] = Long . parseLong ( sc . next ( ) ) ; } sc . close ( ) ; long ans = 0 ; for ( int i = N - 1 ; i >= 0 ; i -- ) { int i = N - 1 ; long beated = Math . min ( aArr [ i + 1 ] , bArr [ i ] ) ; ans += beated ; aArr [ i + 1 ] -= beated ; bArr [ i ] -= beated ; beated = Math . min ( aArr [ i ] , bArr [ i ] ) ; ans += beated ; aArr [ i ] -= beated ; } System . out . println ( ans ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n , i , t , min , s1 , s2 ; int [ ] w ; n = sc . nextInt ( ) ; w = new int [ n ] ; for ( i = 0 ; i < n ; i ++ ) { w [ i ] = sc . nextInt ( ) ; } min = 99999 ; for ( t = 1 ; t < n ; t ++ ) { s1 = 0 ; s2 = 0 ; for ( i = 0 ; i < t ; i ++ ) { s1 += w [ i ] ; } for ( ; i < n ; i ++ ) { s2 += w [ i ] ; } if ( s1 > s2 ) { if ( min > s1 - s2 ) { int [ ] w ; min = s1 - s2 ; } } else { if ( min > s2 - s1 ) { min = s2 - s1 ; } } } System . out . println ( min ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int [ ] nums = new int [ 3 ] , rep = new int [ 2 ] ; rep [ 0 ] = 0 ; rep [ 1 ] = 0 ; for ( int i = 0 ; i < 3 ; i ++ ) { int i = 0 ; nums [ i ] = sc . nextInt ( ) ; if ( nums [ i ] == 5 ) { rep [ 0 ] ++ ; } else if ( nums [ i ] == 7 ) { rep [ 1 ] ++ ; } } if ( rep [ 0 ] == 2 && rep [ 1 ] == 1 ) { System . out . println ( " YES " ) ; } else { System . out . println ( " NO " ) ; } } } +import java . util . Scanner ; import java . util . Deque ; import java . util . ArrayDeque ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; Deque < Integer > deq = new ArrayDeque < Integer > ( ) ; String str = " " ; int a = 0 , b = 0 ; while ( sc . hasNext ( ) ) { int a = 0 , b = 0 ; str = sc . next ( ) ; if ( str . equals ( " + " ) ) { a = deq . pollLast ( ) ; b = deq . pollLast ( ) ; deq . addLast ( a + b ) ; } else if ( str . equals ( " - " ) ) { a = deq . pollLast ( ) ; b = deq . pollLast ( ) ; deq . addLast ( b - a ) ; } else if ( str . equals ( " * " ) ) { a = deq . pollLast ( ) ; b = deq . pollLast ( ) ; deq . addLast ( a * b ) ; } else if ( str . equals ( " / " ) ) { a = deq . pollLast ( ) ; b = deq . pollLast ( ) ; deq . addLast ( b / a ) ; } else { deq . addLast ( Integer . parseInt ( str ) ) ; } } System . out . println ( deq . peekLast ( ) ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String [ ] a = sc . nextLine ( ) . split ( " " ) ; int b = a . length ; String answer = " " ; for ( int i = 0 ; i < b ; i ++ ) { if ( a [ i ] . equals ( " 0 " ) ) { answer += " 0 " ; } if ( a [ i ] . equals ( " 1 " ) ) { answer += " 1 " ; } if ( a [ i ] . equals ( " B " ) ) { int i = 0 ; if ( answer != null && answer . length ( ) > 0 ) { answer = answer . substring ( 0 , answer . length ( ) - 1 ) ; } } } System . out . println ( answer ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; long a1 , b1 , r1 , r2 , temp , a2 , b2 ; while ( scan . hasNext ( ) ) { a1 = scan . nextInt ( ) ; a2 = a1 ; b1 = scan . nextInt ( ) ; b2 = b1 ; while ( a2 % b2 != 0 ) { if ( a2 < b2 ) { long a1 , b1 , r1 , r2 , temp , a2 , b2 ; temp = a2 ; a2 = b2 ; b2 = temp ; } a2 = a2 % b2 ; } r1 = b2 ; r2 = ( a1 * b1 ) / r1 ; System . out . println ( r1 + " " + r2 ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] gg ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; String s = sc . next ( ) ; int counter = 0 ; int i = 0 ; while ( i < n - 2 ) { int i = 0 ; if ( s . charAt ( i ) == 'A' && s . charAt ( i + 1 ) == 'B' && s . charAt ( i + 2 ) == 'C' ) { counter ++ ; i ++ ; } else { i ++ ; } } System . out . println ( counter ) ; } } +import java . util . * ; import java . util . Map . Entry ; import java . util . stream . Collectors ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; String [ ] S = new String [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { S [ i ] = sc . next ( ) ; } sc . close ( ) ; int maxDup = 1 ; Map < String , Integer > m = new HashMap < String , Integer > ( ) ; for ( String s : S ) { int v ; if ( m . containsKey ( s ) ) { v = m . get ( s ) + 1 ; if ( v > maxDup ) { maxDup = v ; } } else { v = 1 ; } m . put ( s , v ) ; } ArrayList < String > list = new ArrayList < String > ( ) ; for ( Entry < String , Integer > entry : m . entrySet ( ) ) { String s ; if ( entry . getValue ( ) == maxDup ) { list . add ( entry . getKey ( ) ) ; } } Collections . sort ( list ) ; for ( String s : list ) { System . out . println ( s ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int [ ] a = new int [ N + 1 ] ; for ( int i = 1 ; i <= N ; i ++ ) { a [ i ] = sc . nextInt ( ) ; } int cnt = 1 ; int point_now = 1 ; while ( cnt <= N ) { int point_now = 1 ; point_now = a [ point_now ] ; if ( point_now == 2 ) { System . out . print ( cnt ) ; return ; } cnt ++ ; } System . out . println ( - 1 ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int [ ] [ ] D = new int [ N ] [ 2 ] ; for ( int i = 0 ; i < D . length ; i ++ ) { D [ i ] [ 0 ] = sc . nextInt ( ) ; D [ i ] [ 1 ] = sc . nextInt ( ) ; } for ( int i = 0 ; i < D . length - 2 ; i ++ ) { if ( D [ i ] [ 0 ] == D [ i ] [ 1 ] && D [ i + 1 ] [ 0 ] == D [ i + 1 ] [ 1 ] && D [ i + 2 ] [ 0 ] == D [ i + 2 ] [ 1 ] ) { int i = 0 ; System . out . print ( " Yes " ) ; return ; } } System . out . print ( " No " ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int tmp = i ; Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; sc . close ( ) ; int count = 0 ; for ( int i = 1 ; i <= N ; i ++ ) { int cnt = 0 ; int tmp = i ; while ( tmp != 0 ) { tmp /= 10 ; cnt ++ ; } if ( cnt % 2 == 1 ) count ++ ; } System . out . println ( count ) ; } } +import java . util . Scanner ; public class Main { Scanner scan = new Scanner ( System . in ) ; void compute ( ) { int y = N / ( 2 * D + 1 ) ; int N = scan . nextInt ( ) ; int D = scan . nextInt ( ) ; double x = ( double ) N / ( double ) ( 2 * D + 1 ) ; int y = N / ( 2 * D + 1 ) ; if ( 0 < x - y ) { y ++ ; } System . out . println ( y ) ; } public static void main ( String [ ] args ) { new Main ( ) . compute ( ) ; } } +import java . io . * ; import java . math . * ; import java . security . * ; import java . text . * ; import java . util . * ; import java . util . concurrent . * ; import java . util . regex . * ; public class Main { public static void main ( String [ ] args ) throws IOException { int time = 0 ; Scanner scan = new Scanner ( System . in ) ; int n = scan . nextInt ( ) ; int x = scan . nextInt ( ) ; int t = scan . nextInt ( ) ; int time = 0 ; while ( n > 0 ) { n -= x ; time += t ; } System . out . println ( time ) ; } } +import java . util . * ; class Main { public void yatary ( ) { Scanner sc = new Scanner ( System . in ) ; int i ; int x = sc . nextInt ( ) ; int [ ] num = new int [ x ] ; for ( i = 0 ; i < x ; i ++ ) { int [ ] num = new int [ x ] ; num [ i ] = sc . nextInt ( ) ; } for ( i = x - 1 ; i >= 0 ; i -- ) { if ( i != 0 ) { System . out . print ( num [ i ] + " " ) ; } else { System . out . println ( num [ i ] ) ; } } } public static void main ( String [ ] args ) { new Main ( ) . yatary ( ) ; } } +import java . util . Scanner ; class Main { int n ; int [ ] d ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; Main m = new Main ( sc ) ; m . solve ( ) ; sc . close ( ) ; } Main ( Scanner sc ) { n = sc . nextInt ( ) ; d = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { boolean f ; d [ i ] = sc . nextInt ( ) ; } } void solve ( ) { boolean [ ] cnt = new boolean [ 100 ] ; for ( int i = 0 ; i < n ; i ++ ) { cnt [ d [ i ] - 1 ] = true ; } int dan = 0 ; for ( boolean f : cnt ) { if ( f ) dan ++ ; } System . out . println ( dan ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int n = scanner . nextInt ( ) ; int m = scanner . nextInt ( ) ; int [ ] [ ] a = new int [ n ] [ m ] ; int [ ] b = new int [ m ] ; for ( int y = 0 ; y < n ; y ++ ) { for ( int x = 0 ; x < m ; x ++ ) { a [ y ] [ x ] = scanner . nextInt ( ) ; } } for ( int y = 0 ; y < m ; y ++ ) { b [ y ] = scanner . nextInt ( ) ; } for ( int y = 0 ; y < n ; y ++ ) { int ans = 0 ; for ( int x = 0 ; x < m ; x ++ ) { int x = 0 ; ans += a [ y ] [ x ] * b [ x ] ; } System . out . println ( ans ) ; } scanner . close ( ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; if ( judge ( s , 0 ) ) { boolean f = false ; System . out . println ( " YES " ) ; } else { System . out . println ( " NO " ) ; } } public static boolean judge ( String s , int i ) { if ( i == s . length ( ) ) { return true ; } boolean f = false ; if ( s . length ( ) >= i + 7 && s . substring ( i , i + 7 ) . equals ( " dreamer " ) ) { f |= judge ( s , i + 7 ) ; } if ( s . length ( ) >= i + 5 && s . substring ( i , i + 5 ) . equals ( " dream " ) ) { f |= judge ( s , i + 5 ) ; } if ( s . length ( ) >= i + 6 && s . substring ( i , i + 6 ) . equals ( " eraser " ) ) { f |= judge ( s , i + 6 ) ; } if ( s . length ( ) >= i + 5 && s . substring ( i , i + 5 ) . equals ( " erase " ) ) { f |= judge ( s , i + 5 ) ; } return f ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] A = new int [ n ] ; int i ; int count = 0 ; for ( i = 0 ; i < n ; i ++ ) { A [ i ] = sc . nextInt ( ) ; if ( isprime ( A [ i ] ) == true ) { count ++ ; } } System . out . println ( count ) ; } public static boolean isprime ( int x ) { int i = 0 ; if ( x == 2 ) { return true ; } else if ( ( x % 2 ) == 0 ) { return false ; } else { i = 3 ; while ( i <= Math . sqrt ( x ) ) { int i = 0 ; if ( ( x % i ) == 0 ) { return false ; } i = i + 2 ; } } return true ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] sequence = new int [ n ] ; double denominator = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int i = 0 ; sequence [ i ] = sc . nextInt ( ) ; denominator += 1.0 / sequence [ i ] ; } System . out . println ( 1 / denominator ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws NumberFormatException , IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; StringBuilder sb = new StringBuilder ( ) ; int i = 1 ; while ( true ) { int n = Integer . parseInt ( br . readLine ( ) ) ; if ( n == 0 ) { int i = 1 ; break ; } sb . append ( " Case " ) . append ( i ) . append ( " : " ) . append ( n ) . append ( " \n " ) ; i ++ ; } System . out . print ( sb ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int ans = ( int ) Math . ceil ( ch ) ; Scanner sc = new Scanner ( System . in ) ; long N = sc . nextLong ( ) , K = sc . nextLong ( ) ; double ch = Math . log ( N ) / Math . log ( K ) ; int ans = ( int ) Math . ceil ( ch ) ; if ( ans == ch ) { System . out . println ( ans + 1 ) ; } else { System . out . println ( ans ) ; } } } +import java . util . ArrayList ; import java . util . List ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; List < Integer > list = new ArrayList < Integer > ( ) ; int n = sc . nextInt ( ) ; int m = sc . nextInt ( ) ; int c = sc . nextInt ( ) ; Integer [ ] [ ] array = new Integer [ n ] [ m ] ; for ( int i = 0 ; m > i ; i ++ ) { int a = sc . nextInt ( ) ; list . add ( a ) ; } for ( int i = 0 ; n > i ; i ++ ) { for ( int j = 0 ; m > j ; j ++ ) { int a = sc . nextInt ( ) ; array [ i ] [ j ] = a ; } } int count = 0 ; for ( int i = 0 ; n > i ; i ++ ) { int keisan = 0 ; for ( int j = 0 ; m > j ; j ++ ) { int j = 0 ; keisan = keisan + list . get ( j ) * array [ i ] [ j ] ; } if ( keisan + c > 0 ) count ++ ; } System . out . println ( count ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int n = scan . nextInt ( ) ; int a = scan . nextInt ( ) ; int b = scan . nextInt ( ) ; int ans = n * a ; if ( ans < b ) { System . out . println ( ans ) ; } else { int ans = n * a ; System . out . println ( b ) ; } } } +import java . util . Scanner ; import java . util . Arrays ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int [ ] array = new int [ a ] ; for ( int i = 0 ; i < a ; i ++ ) { int i ; array [ i ] = sc . nextInt ( ) ; } int i ; for ( i = 0 ; i < a - 1 ; i ++ ) { if ( array [ i ] == array [ i + 1 ] ) { continue ; } else if ( array [ i ] > ( array [ i + 1 ] ) ) { array [ i + 1 ] += 1 ; if ( array [ i ] > array [ i + 1 ] ) { System . out . println ( " No " ) ; break ; } } } if ( i == ( a - 1 ) ) { System . out . println ( " Yes " ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long A = sc . nextLong ( ) ; long B = sc . nextLong ( ) ; long K = sc . nextLong ( ) ; if ( K <= A ) { long K = sc . nextLong ( ) ; A = A - K ; K = 0 ; } else { K = K - A ; A = 0 ; } if ( K <= B ) { B = B - K ; K = 0 ; } else { K = K - B ; B = 0 ; } System . out . println ( A + " " + B ) ; } } +import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int [ ] task = new int [ 3 ] ; int ans = 0 ; for ( int i = 0 ; i < 3 ; i ++ ) { task [ i ] = sc . nextInt ( ) ; } Arrays . sort ( task ) ; for ( int i = 0 ; i < 2 ; i ++ ) { int i = 0 ; ans += Math . abs ( task [ i ] - task [ i + 1 ] ) ; } System . out . println ( ans ) ; } } +import java . util . Map ; import java . util . Scanner ; import java . util . TreeMap ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; char [ ] A = sc . next ( ) . toCharArray ( ) ; Map < Character , Integer > maplst = new TreeMap < Character , Integer > ( ) ; for ( char c : A ) { if ( maplst . containsKey ( c ) ) { maplst . put ( c , maplst . get ( c ) + 1 ) ; } else { maplst . put ( c , 1 ) ; } } boolean judge = true ; if ( maplst . keySet ( ) . size ( ) == 2 ) { char c ; for ( char c : maplst . keySet ( ) ) { if ( maplst . get ( c ) != 2 ) { judge = ! judge ; break ; } } } else { judge = ! judge ; } if ( judge ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String line = br . readLine ( ) ; String re = " " ; for ( int i = line . length ( ) ; i > 0 ; i -- ) { int i = line . length ( ) ; re += line . charAt ( i - 1 ) ; } System . out . println ( re ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String S = sc . next ( ) ; int count = 0 ; int maxCount = 0 ; for ( int i = 0 ; i < S . length ( ) ; i ++ ) { String a = S . substring ( i , i + 1 ) ; if ( a . equals ( " A " ) || a . equals ( " C " ) || a . equals ( " G " ) || a . equals ( " T " ) ) { count ++ ; } else { count = 0 ; } if ( maxCount < count ) { int i = 0 ; maxCount = count ; } } System . out . println ( maxCount ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int cnt = 0 ; Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int cnt = 0 ; if ( N % 2 == 0 ) { cnt = N / 2 ; System . out . println ( cnt ) ; } else { cnt = ( int ) ( N / 2 ) + 1 ; System . out . println ( cnt ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; int D = sc . nextInt ( ) ; int N = sc . nextInt ( ) ; int powD = 1 ; for ( int i = 0 ; i < D ; i ++ ) { powD *= 100 ; } int ans = N * powD ; if ( ( ans == 100 && powD == 1 ) || ( ans == 10000 && powD == 100 ) || ( ans == 1000000 && powD == 10000 ) ) { int ans = N * powD ; System . out . println ( ans + 1 * powD ) ; } else { System . out . println ( ans ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long n = sc . nextLong ( ) ; long ans = Long . MAX_VALUE / 2 ; for ( int i = 1 ; ( long ) i * i <= n ; i ++ ) { int res = 0 ; if ( n % i == 0 ) { long a = i ; long b = n / i ; long tmp = Math . max ( a , b ) ; ans = Math . min ( ans , tmp ) ; } } int res = 0 ; while ( ans > 0 ) { ans /= 10 ; res ++ ; } System . out . println ( res ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] arg ) { StringBuffer sb = new StringBuffer ( input ) ; Scanner in = new Scanner ( System . in ) ; String input = in . nextLine ( ) ; while ( ! input . equals ( " - " ) ) { String tmp = in . nextLine ( ) ; int h_cnt = Integer . parseInt ( tmp ) ; StringBuffer sb = new StringBuffer ( input ) ; for ( int i = 0 ; i < h_cnt ; i ++ ) { tmp = in . nextLine ( ) ; int h_pos = Integer . parseInt ( tmp ) ; String del_str = sb . substring ( 0 , h_pos ) ; sb = sb . delete ( 0 , h_pos ) ; sb . append ( del_str ) ; } System . out . println ( sb . toString ( ) ) ; input = in . nextLine ( ) ; } } } +import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws Exception { final Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int M = sc . nextInt ( ) ; int [ ] problems = new int [ N ] ; int [ ] was = new int [ N ] ; for ( int i = 0 ; i < M ; i ++ ) { final int p = sc . nextInt ( ) - 1 ; boolean isAC = sc . next ( ) . equals ( " AC " ) ; if ( isAC ) { problems [ p ] = 1 ; } else { int i = 0 ; if ( problems [ p ] != 1 ) { was [ p ] ++ ; } } } int wa = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( problems [ i ] == 1 ) { wa += was [ i ] ; } } System . out . println ( Arrays . stream ( problems ) . sum ( ) + " " + wa ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { long ans = 0 ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; boolean f = false ; int [ ] array = new int [ n + 1 ] ; int [ ] array2 = new int [ n ] ; for ( int i = 0 ; i < n + 1 ; i ++ ) { int i = 0 ; array [ i ] = sc . nextInt ( ) ; } for ( int i = 0 ; i < n ; i ++ ) { array2 [ i ] = sc . nextInt ( ) ; } long tmp = 0 ; for ( int i = 0 ; i < n + 1 ; i ++ ) { if ( tmp > 0 ) { if ( array [ i ] >= tmp ) { ans = ans + tmp ; array [ i ] = array [ i ] - ( int ) tmp ; } else { ans = ans + array [ i ] ; array [ i ] = 0 ; } tmp = 0 ; } if ( i == n ) { continue ; } if ( array [ i ] >= array2 [ i ] ) { ans = ans + array2 [ i ] ; tmp = 0 ; } else { ans = ans + array [ i ] ; tmp = ( array2 [ i ] - array [ i ] ) ; } } System . out . println ( ans ) ; sc . close ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int N = in . nextInt ( ) ; int [ ] [ ] A = new int [ 2 ] [ N ] ; for ( int i = 0 ; i < 2 ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) { A [ i ] [ j ] = in . nextInt ( ) ; } } int ans = 0 ; for ( int i = 0 ; i < N ; i ++ ) { int sum = 0 ; for ( int j = 0 ; j <= i ; j ++ ) { int j = i ; sum += A [ 0 ] [ j ] ; } for ( int j = i ; j < N ; j ++ ) { sum += A [ 1 ] [ j ] ; } ans = Math . max ( ans , sum ) ; } System . out . println ( ans ) ; in . close ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { String anser = " No " ; Scanner scan = new Scanner ( System . in ) ; String S = scan . next ( ) ; String anser = " No " ; if ( S . contains ( " A " ) && S . contains ( " B " ) ) { anser = " Yes " ; } System . out . println ( anser ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; long number = scanner . nextLong ( ) ; String result = new String ( ) ; while ( number > 0 ) { String result = new String ( ) ; int nums = ( int ) ( 'a' + ( number - 1 ) % 26 ) ; char temporal = ( char ) nums ; result = temporal + result ; number = number / 26 ; if ( temporal == 'z' ) number -- ; } System . out . print ( result ) ; } } +import java . util . * ; import java . util . Arrays ; public class Main { private static Scanner sc ; public static void main ( String [ ] args ) { sc = new Scanner ( System . in ) ; int [ ] a = new int [ 10 ] ; for ( int i = 0 ; i < a . length ; i ++ ) { int i = 9 ; a [ i ] = sc . nextInt ( ) ; } Arrays . sort ( a ) ; for ( int i = 9 ; i > 6 ; i -- ) { System . out . println ( a [ i ] ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int curr = scan . nextInt ( ) ; Scanner scan = new Scanner ( System . in ) ; int n = scan . nextInt ( ) ; int [ ] ar = new int [ n ] ; int ans = 0 ; int pre = 0 ; int cur ; for ( int i = 0 ; i < n ; i ++ ) { int curr = scan . nextInt ( ) ; if ( pre > curr ) { ans += pre - curr ; } pre = curr ; } ans += pre ; System . out . println ( ans ) ; } } +import java . util . * ; import java . util . Arrays ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner scanner = new Scanner ( System . in ) ; int K = scanner . nextInt ( ) ; int S = scanner . nextInt ( ) ; int sub = 0 ; int count = 0 ; for ( int i = 0 ; i <= K ; i ++ ) { if ( i != S ) { for ( int j = 0 ; j <= K ; j ++ ) { int j = 0 ; if ( i + j != S ) { sub = S - ( i + j ) ; if ( sub >= 0 && sub <= K ) { count ++ ; } } else if ( i + j == S ) { count ++ ; break ; } } } else if ( i == S ) { count ++ ; } } System . out . println ( count ) ; } } +import java . util . * ; import java . text . * ; public class Main { public static void main ( String [ ] args ) { double debt = 100000 ; Scanner sc = new Scanner ( System . in ) ; int n = Integer . parseInt ( sc . nextLine ( ) ) ; double debt = 100000 ; while ( n > 0 ) { debt *= 1.05 ; debt = 1000.0 * Math . ceil ( debt / 1000.0 ) ; n -- ; } System . out . println ( String . format ( " %.0f " , debt ) ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int j = 1 ; final Scanner sc = new Scanner ( System . in ) ; final int N = sc . nextInt ( ) ; int ans = 0 ; for ( int i = 1 ; i <= N ; i ++ ) { int sum = 0 ; for ( int j = 1 ; j <= N ; j ++ ) { if ( i % j == 0 ) { sum ++ ; } } if ( sum == 8 && i % 2 != 0 ) { ans ++ ; } } System . out . println ( ans ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int L = sc . nextInt ( ) ; int R = sc . nextInt ( ) ; boolean zero = false ; if ( L - R >= 2019 ) zero = true ; for ( int i = L ; i < R ; i ++ ) { int k = i + 1 ; if ( i % 2019 == 0 ) { zero = true ; break ; } } L = L % 2019 ; R = R % 2019 ; int min = 2017 * 2018 ; if ( ! zero ) { for ( int i = L ; i < R ; i ++ ) { for ( int k = i + 1 ; k <= R ; k ++ ) { if ( min > ( i * k ) % 2019 ) min = ( i * k ) % 2019 ; } } } if ( zero ) System . out . println ( 0 ) ; else System . out . println ( min ) ; } } +import java . util . * ; import java . math . BigDecimal ; public class Main { public static void main ( String [ ] args ) { int N ; int [ ] A ; try ( Scanner sc = new Scanner ( System . in ) ) { N = sc . nextInt ( ) ; A = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { A [ i ] = sc . nextInt ( ) ; } } double answer = solve ( A ) ; System . out . println ( answer ) ; } private static double solve ( int [ ] a ) { int n = a . length ; if ( n == 0 ) { throw new IllegalStateException ( " n must be positive " ) ; } if ( n == 1 ) { return ( double ) a [ 0 ] ; } int n0 = ( int ) Math . ceil ( n / 2 ) ; int n1 = n - n0 ; double r = 0.0d ; if ( n0 > 0 ) { double r = 0.0d ; int [ ] a0 = new int [ n0 ] ; System . arraycopy ( a , 0 , a0 , 0 , n0 ) ; double s0 = solve ( a0 ) ; r += 1 / s0 ; } if ( n1 > 0 ) { int [ ] a1 = new int [ n1 ] ; System . arraycopy ( a , n0 , a1 , 0 , n1 ) ; double s1 = solve ( a1 ) ; r += 1 / s1 ; } return 1 / r ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int a1 = sc . nextInt ( ) ; int a2 = sc . nextInt ( ) ; int a3 = sc . nextInt ( ) ; int sa12 = Math . abs ( a1 - a2 ) ; int sa23 = Math . abs ( a2 - a3 ) ; int sa31 = Math . abs ( a3 - a1 ) ; int max = Math . max ( Math . max ( sa12 , sa23 ) , sa31 ) ; int cost ; if ( max == sa12 ) { cost = sa23 + sa31 ; } else if ( max == sa23 ) { cost = sa12 + sa31 ; } else { int cost ; cost = sa12 + sa23 ; } System . out . println ( cost ) ; } } +import java . io . InputStream ; import java . io . PrintStream ; 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 ) ; int N = sc . nextInt ( ) ; int [ ] d = nextIntArray ( sc , N ) ; sc . close ( ) ; int ans = 0 ; for ( int i = 0 ; i < N - 1 ; i ++ ) { for ( int j = i + 1 ; j < N ; j ++ ) { int i = 0 ; ans += d [ i ] * d [ j ] ; } } out . println ( ans ) ; } public static void main ( String [ ] args ) { new Main ( ) . _main ( args ) ; } @ SuppressWarnings ( " unused " ) private int [ ] nextIntArray ( Scanner sc , int n ) { int [ ] result = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { result [ i ] = sc . nextInt ( ) ; } return result ; } } +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 ) ; BPapersPlease solver = new BPapersPlease ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class BPapersPlease { public void solve ( int testNumber , Scanner in , PrintWriter out ) { boolean f = true ; int n = in . nextInt ( ) ; int [ ] a = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = in . nextInt ( ) ; if ( a [ i ] % 2 == 0 ) { int i = 0 ; f = f && ( a [ i ] % 3 == 0 || a [ i ] % 5 == 0 ) ; } } out . println ( f ? " APPROVED " : " DENIED " ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int [ ] data = new int [ 3 ] ; for ( int i = 0 ; i < 3 ; i ++ ) { data [ i ] = sc . nextInt ( ) ; } int K = sc . nextInt ( ) ; int maxIdx = 0 ; int max = data [ 0 ] ; for ( int i = 1 ; i < 3 ; i ++ ) { int i = 0 ; if ( max < data [ i ] ) { max = data [ i ] ; maxIdx = i ; } } for ( int i = 0 ; i < K ; i ++ ) { data [ maxIdx ] *= 2 ; } System . out . println ( data [ 0 ] + data [ 1 ] + data [ 2 ] ) ; sc . close ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int n = scan . nextInt ( ) ; while ( n > 0 ) { int sum = 0 ; int [ ] s = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { int i = 0 ; s [ i ] = scan . nextInt ( ) ; sum += s [ i ] ; } double ave = ( double ) sum / n ; double HF = 0 ; for ( int i = 0 ; i < n ; i ++ ) { HF += ( ave - s [ i ] ) * ( ave - s [ i ] ) ; } HF /= ( double ) n ; HF = Math . pow ( HF , 0.5 ) ; System . out . println ( HF ) ; n = scan . nextInt ( ) ; } } } +import java . util . Scanner ; public class Main { public long getTotalHeightOfStools ( int n , int [ ] arr ) { long total = 0 ; int prevHeight = arr [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { if ( prevHeight > arr [ i ] ) { total += prevHeight - arr [ i ] ; arr [ i ] = prevHeight ; } prevHeight = arr [ i ] ; } return total ; } public static void main ( String [ ] args ) throws Exception { Main solution = new Main ( ) ; Scanner scanner = new Scanner ( System . in ) ; int n = scanner . nextInt ( ) ; int [ ] arr = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { int i = 0 ; arr [ i ] = scanner . nextInt ( ) ; } long answer = solution . getTotalHeightOfStools ( n , arr ) ; System . out . println ( answer ) ; } } +import java . util . * ; class Main { int max ( int a , int b ) { if ( a < b ) return b ; else return a ; } int min ( int a , int b ) { if ( a > b ) return b ; else return a ; } Main ( ) { Scanner sc = new Scanner ( System . in ) ; int a , c , d ; a = sc . nextInt ( ) ; d = - 1000000000 ; c = sc . nextInt ( ) ; for ( int i = 0 ; i < a - 1 ; i ++ ) { int a , c , d ; int f = sc . nextInt ( ) ; d = max ( d , f - c ) ; c = min ( c , f ) ; } System . out . println ( d ) ; } public static void main ( String [ ] arg ) { new Main ( ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner s = new Scanner ( System . in ) ; int n = s . nextInt ( ) ; int m = s . nextInt ( ) ; int ans = 10000 ; for ( int i = 0 ; i < n ; i ++ ) { int k = s . nextInt ( ) ; int b = s . nextInt ( ) ; if ( b <= m && k < ans ) { int k = s . nextInt ( ) ; ans = k ; } } if ( ans == 10000 ) { System . out . println ( " TLE " ) ; } else System . out . println ( ans ) ; } } +import java . util . Scanner ; import java . util . ArrayList ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int x = sc . nextInt ( ) ; if ( x == 2 ) { System . out . println ( 2 ) ; } else { ArrayList < Integer > li = new ArrayList < Integer > ( ) ; li . add ( 2 ) ; int i = 3 ; int l = 0 ; while ( i < 1000000 ) { for ( int j = 0 ; j < li . size ( ) ; j ++ ) { if ( i % li . get ( j ) == 0 ) { l ++ ; break ; } } if ( l == 0 && i >= x ) { System . out . println ( i ) ; break ; } else if ( l == 0 ) { int j = 0 ; li . add ( i ) ; } i ++ ; l = 0 ; } } } } +import java . util . * ; import javax . lang . model . util . ElementScanner6 ; public class Main { public static void main ( String [ ] args ) { HashSet < String > s = new HashSet < > ( ) ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; HashSet < String > s = new HashSet < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { String a = sc . next ( ) ; s . add ( a ) ; } int out = s . size ( ) ; System . out . println ( out ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; int A = sc . nextInt ( ) ; int B = sc . nextInt ( ) ; int C = sc . nextInt ( ) ; if ( A * B > C ) { int C = sc . nextInt ( ) ; System . out . println ( C ) ; } else { System . out . println ( A * B ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int ans = 0 ; if ( N >= 195 ) { int ans = 0 ; ans = 5 ; } else if ( N >= 189 ) { ans = 4 ; } else if ( N >= 165 ) { ans = 3 ; } else if ( N >= 135 ) { ans = 2 ; } else if ( N >= 105 ) { ans = 1 ; } System . out . println ( ans ) ; } } +import java . io . IOException ; import java . io . BufferedReader ; import java . io . InputStreamReader ; class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String str = br . readLine ( ) ; while ( ! ( str . equals ( " - " ) ) ) { String str = br . readLine ( ) ; String repStr = br . readLine ( ) ; int rep = Integer . parseInt ( repStr ) ; for ( int i = 0 ; i < rep ; i ++ ) { String posStr = br . readLine ( ) ; int pos = Integer . parseInt ( posStr ) ; String left = str . substring ( 0 , pos ) ; String right = str . substring ( pos ) ; str = right + left ; } System . out . println ( str ) ; str = br . readLine ( ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { solve ( ) ; } private static void solve ( ) { int i = 0 ; Scanner input = new Scanner ( System . in ) ; int n = input . nextInt ( ) ; int [ ] nums = new int [ n ] ; int first = 0 ; int second = 0 ; for ( int i = 0 ; i < n ; i ++ ) { nums [ i ] = input . nextInt ( ) ; if ( nums [ i ] >= first ) { second = first ; first = nums [ i ] ; } else if ( nums [ i ] >= second ) { second = nums [ i ] ; } } for ( int i = 0 ; i < n ; i ++ ) { if ( nums [ i ] == first ) { System . out . println ( second ) ; } else { System . out . println ( first ) ; } } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int a = scanner . nextInt ( ) ; int b = scanner . nextInt ( ) ; int c ; int k = scanner . nextInt ( ) ; if ( a > b ) c = a ; else c = b ; for ( int i = c ; i >= 1 ; i -- ) { int i = c ; if ( a % i == 0 && b % i == 0 ) { -- k ; if ( k == 0 ) { System . out . println ( i ) ; } } } } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; sc . nextLine ( ) ; String S = sc . nextLine ( ) ; String [ ] Sarray = S . split ( " " ) ; String before = " " ; int ans = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( ! before . equals ( Sarray [ i ] ) ) { ans ++ ; } before = Sarray [ i ] ; } System . out . println ( ans ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int K = sc . nextInt ( ) ; int S = sc . nextInt ( ) ; int count = 0 ; for ( int x = 0 ; x <= K ; x ++ ) { int y = 0 ; for ( int y = 0 ; y <= K ; y ++ ) { int z = S - ( x + y ) ; if ( 0 <= z && z <= K ) { count ++ ; } } } System . out . print ( count ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; String S = sc . next ( ) ; String T = sc . next ( ) ; if ( T . equals ( S ) ) { int i = 0 ; System . out . println ( " Yes " ) ; return ; } for ( int i = 0 ; i < S . length ( ) ; i ++ ) { String U = S . substring ( i , S . length ( ) ) + S . substring ( 0 , i ) ; if ( T . equals ( U ) ) { System . out . println ( " Yes " ) ; return ; } } System . out . println ( " No " ) ; } } +import java . util . HashSet ; import java . util . Scanner ; import java . util . Set ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; Set < Integer > arrays = new HashSet < > ( ) ; int cnt = 1 ; int s = sc . nextInt ( ) ; arrays . add ( s ) ; while ( true ) { cnt ++ ; s = result ( s ) ; if ( arrays . contains ( s ) ) { System . out . println ( cnt ) ; break ; } arrays . add ( s ) ; } } public static int result ( int a ) { if ( a % 2 == 0 ) { int s = sc . nextInt ( ) ; return a / 2 ; } return 3 * a + 1 ; } } +import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . io . IOException ; public class Main { public static void main ( String [ ] args ) throws IOException { int i = 0 ; BufferedReader in = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int n = Integer . parseInt ( in . readLine ( ) ) ; long [ ] a = new long [ n ] ; long sum = 1 ; long lastSum = 1 ; boolean over = false ; String [ ] str = in . readLine ( ) . split ( " " ) ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = Long . parseLong ( str [ i ] ) ; if ( a [ i ] == 0 ) { System . out . println ( 0 ) ; return ; } sum *= a [ i ] ; if ( lastSum > sum || sum > 1000000000000000000L ) { over = true ; } lastSum = sum ; } System . out . println ( over ? - 1 : sum ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { long ans = 0 ; Scanner sc = new Scanner ( System . in ) ; long n = sc . nextLong ( ) ; long x = sc . nextLong ( ) ; long t = sc . nextLong ( ) ; if ( n <= x ) { System . out . println ( t ) ; return ; } long ans = 0 ; ans += ( n / x ) * t ; n %= x ; if ( n > 0 ) { ans += t ; } sc . close ( ) ; System . out . println ( ans ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] a ) { int debt = 100000 ; Scanner scan = new Scanner ( System . in ) ; int n = scan . nextInt ( ) ; int debt = 100000 ; for ( int i = 0 ; i < n ; i ++ ) { debt += debt / 20 ; debt = up ( debt ) ; } System . out . println ( debt ) ; } static int up ( int money ) { money += 999 ; money -= money % 1000 ; return money ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; String str = scan . next ( ) ; int max = 0 ; for ( int i = 0 ; i < str . length ( ) ; ) { int cnt = 0 ; for ( int j = i ; j < str . length ( ) ; j ++ ) { int j = i ; i = j + 1 ; if ( ( str . charAt ( j ) == 'A' ) || ( str . charAt ( j ) == 'C' ) || ( str . charAt ( j ) == 'G' ) || ( str . charAt ( j ) == 'T' ) ) { cnt ++ ; } else { break ; } } max = Math . max ( max , cnt ) ; } System . out . println ( max ) ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner stdIn = new Scanner ( System . in ) ; int n = stdIn . nextInt ( ) ; int ans = - 1000000000 ; int min = stdIn . nextInt ( ) ; for ( int i = 1 ; i < n ; i ++ ) { int min = stdIn . nextInt ( ) ; int r = stdIn . nextInt ( ) ; ans = Math . max ( ans , r - min ) ; min = Math . min ( min , r ) ; } System . out . println ( ans ) ; } } +import java . util . * ; public class Main { static void solve ( ) { Scanner sc = new Scanner ( System . in ) ; int n = 0 ; char p = '.' ; for ( char ch : sc . next ( ) . toCharArray ( ) ) { n = ( ( p == '.' || p == 'S' ) && ch == 'R' ) ? 1 : n ; if ( ch == 'R' && p == 'R' ) n ++ ; p = ch ; } System . out . println ( n ) ; sc . close ( ) ; } public static void main ( String [ ] args ) { char ch ; solve ( ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int num = sc . nextInt ( ) ; int [ ] card = new int [ num ] ; int alice = 0 ; int bob = 0 ; for ( int i = 0 ; i < num ; i ++ ) { card [ i ] = sc . nextInt ( ) ; } Arrays . sort ( card ) ; for ( int i = ( num - 1 ) ; i >= 0 ; i -= 2 ) { int j = ( num - 2 ) ; alice += card [ i ] ; } for ( int j = ( num - 2 ) ; j >= 0 ; j -= 2 ) { bob += card [ j ] ; } int division = alice - bob ; System . out . println ( division ) ; } } +import java . util . Scanner ; class Main { static final long MOD = 1000000007 ; static int H , W , K ; static long [ ] [ ] dp = new long [ 110 ] [ 10 ] ; static int ans = 0 ; static long n = 0 ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int x = sc . nextInt ( ) ; for ( int i = x ; i <= 999 ; i ++ ) { if ( i == 111 || i == 222 || i == 333 || i == 444 || i == 555 || i == 666 || i == 777 || i == 888 || i == 999 ) { System . out . println ( i ) ; return ; } } } } class Pair implements Comparable { int from ; int end ; int num ; int bango ; @ Override public int compareTo ( Object other ) { Pair otherpair = ( Pair ) other ; return end - otherpair . end ; } } +import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; String s = in . next ( ) ; String t = in . next ( ) ; int count = 0 ; int min = 9999 ; for ( int i = 0 ; i <= s . length ( ) - t . length ( ) ; i ++ ) { count = 0 ; for ( int j = 0 ; j < t . length ( ) ; j ++ ) { if ( s . charAt ( i + j ) == t . charAt ( j ) ) { } else { count ++ ; } } if ( min > count ) { min = count ; } } if ( s . contains ( t ) ) { int j = 0 ; System . out . println ( 0 ) ; } else System . out . println ( min ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scn = new Scanner ( System . in ) ; int N = scn . nextInt ( ) ; int sum = 0 ; for ( int i = 1 ; i <= N ; i ++ ) { for ( int j = 1 ; j <= N ; j ++ ) { int y = Math . min ( a , b ) ; for ( int k = 1 ; k <= N ; k ++ ) { int c = HCF ( i , j ) ; int d = HCF ( c , k ) ; sum = sum + d ; } } } System . out . println ( sum ) ; } public static int HCF ( int a , int b ) { int temp = - 1 ; int x = Math . max ( a , b ) ; int y = Math . min ( a , b ) ; while ( x > 0 ) { temp = x ; x = y % x ; y = temp ; } return y ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int m = sc . nextInt ( ) ; int [ ] a = new int [ n ] ; int [ ] b = new int [ n ] ; for ( int i = 0 ; i < m ; i ++ ) { a [ sc . nextInt ( ) - 1 ] ++ ; b [ sc . nextInt ( ) - 1 ] ++ ; } sc . close ( ) ; for ( int i = 0 ; i < n ; i ++ ) { System . out . println ( a [ i ] + b [ i ] ) ; } } } +import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int a = scanner . nextInt ( ) ; int b = scanner . nextInt ( ) ; int c = scanner . nextInt ( ) ; int d = scanner . nextInt ( ) ; int ans = 0 ; boolean [ ] exits = new boolean [ 100 ] ; Arrays . fill ( exits , false ) ; for ( int i = a ; i < b ; i ++ ) { exits [ i ] = true ; } for ( int i = c ; i < d ; i ++ ) { if ( exits [ i ] ) { int i = c ; ans ++ ; } } System . out . println ( ans ) ; scanner . close ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int n = scan . nextInt ( ) ; int i ; for ( i = 1 ; i <= n ; i ++ ) { int i ; if ( i > n ) break ; String x = String . valueOf ( i ) ; if ( ( ( i % 3 ) == 0 ) || ( ( i % 10 ) == 3 ) || ( ( i / 10 ) == 3 ) ) { System . out . print ( " " + i ) ; } else if ( x . contains ( " 3 " ) ) { System . out . print ( " " + i ) ; } } System . out . println ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String color1 = sc . next ( ) ; sc . next ( ) ; int color1Cnt = sc . nextInt ( ) ; int color2Cnt = sc . nextInt ( ) ; String disposed = sc . next ( ) ; if ( disposed . equals ( color1 ) ) { int color2Cnt = sc . nextInt ( ) ; System . out . printf ( " %d %d " , color1Cnt - 1 , color2Cnt ) ; return ; } System . out . printf ( " %d %d " , color1Cnt , color2Cnt - 1 ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; String S = scan . next ( ) ; String result = " No " ; if ( String . valueOf ( S . charAt ( 2 ) ) . equals ( String . valueOf ( S . charAt ( 3 ) ) ) && ( String . valueOf ( S . charAt ( 4 ) ) . equals ( String . valueOf ( S . charAt ( 5 ) ) ) ) ) { String result = " No " ; result = " Yes " ; } System . out . println ( result ) ; } } +import java . io . * ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String str = br . readLine ( ) ; String [ ] text = str . split ( " " ) ; int a = Integer . parseInt ( text [ 0 ] ) ; String b = text [ 1 ] ; int c = Integer . parseInt ( text [ 2 ] ) ; while ( b . equals ( " ? " ) == false ) { if ( b . equals ( " + " ) ) { System . out . println ( a + c ) ; } else if ( b . equals ( " - " ) ) { int c = Integer . parseInt ( text [ 2 ] ) ; System . out . println ( a - c ) ; } else if ( b . equals ( " * " ) ) { System . out . println ( a * c ) ; } else if ( b . equals ( " / " ) ) { System . out . println ( a / c ) ; } str = br . readLine ( ) ; text = str . split ( " " ) ; a = Integer . parseInt ( text [ 0 ] ) ; b = text [ 1 ] ; c = Integer . parseInt ( text [ 2 ] ) ; } } } +import java . util . Arrays ; import java . util . Comparator ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; Integer [ ] mochi = new Integer [ N ] ; int ans = 1 ; for ( int i = 0 ; i < N ; i ++ ) { int i = 0 ; mochi [ i ] = sc . nextInt ( ) ; } Arrays . sort ( mochi , Comparator . reverseOrder ( ) ) ; for ( int i = 0 ; i < N ; i ++ ) { if ( i != N - 1 ) { if ( mochi [ i ] > mochi [ i + 1 ] ) { ans ++ ; } } } System . out . println ( ans ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . Arrays ; class Main { public static void main ( String [ ] args ) throws NumberFormatException , IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String [ ] numbers = br . readLine ( ) . split ( " " ) ; int n = Integer . parseInt ( numbers [ 0 ] ) ; int x = Integer . parseInt ( numbers [ 1 ] ) ; String [ ] length = br . readLine ( ) . split ( " " ) ; int [ ] len = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { len [ i ] = Integer . parseInt ( length [ i ] ) ; } int [ ] bounces = new int [ n + 1 ] ; bounces [ 0 ] = 0 ; for ( int j = 1 ; j <= len . length ; j ++ ) { bounces [ j ] = bounces [ j - 1 ] + len [ j - 1 ] ; } int count = 0 ; for ( int k = 0 ; k < bounces . length ; k ++ ) { if ( bounces [ k ] <= x ) { int k = 0 ; count ++ ; } } System . out . println ( count ) ; } } +import java . io . * ; public class Main { public static void main ( String [ ] args ) { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int m = 0 , f = 0 , r = 0 ; try { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; while ( true ) { String [ ] strAry = br . readLine ( ) . split ( " " ) ; m = Integer . parseInt ( strAry [ 0 ] ) ; f = Integer . parseInt ( strAry [ 1 ] ) ; r = Integer . parseInt ( strAry [ 2 ] ) ; if ( m == - 1 && f == - 1 && r == - 1 ) break ; System . out . printf ( " %s \n " , judge ( m , f , r ) ) ; } } catch ( Exception e ) { System . err . println ( e ) ; } } private static String judge ( int m , int f , int r ) { if ( ( m == - 1 || f == - 1 ) || m + f < 30 ) return " F " ; else if ( m + f < 50 ) { if ( r >= 50 ) return " C " ; else return " D " ; } else if ( m + f < 65 ) return " C " ; else if ( m + f < 80 ) return " B " ; else return " A " ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long n = sc . nextLong ( ) ; long t = ( long ) Math . sqrt ( n ) ; long a = 1 ; for ( long i = t ; 1 <= i ; i -- ) { if ( n % i == 0 ) { long i = t ; a = n / i ; break ; } } System . out . print ( ( n / a ) + a - 2 ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int cg = 1000 * i - yen ; Scanner sc = new Scanner ( System . in ) ; int yen = sc . nextInt ( ) ; boolean flg = true ; int i = 1 ; while ( flg ) { int cg = 1000 * i - yen ; if ( cg >= 0 ) { flg = false ; System . out . println ( cg ) ; } i ++ ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long N = sc . nextLong ( ) ; long ans = 100 ; for ( long i = 1 ; i * i <= N ; i ++ ) { if ( N % i == 0 ) { ans = Math . min ( ans , getDigits ( N / i ) ) ; } } System . out . println ( ans ) ; sc . close ( ) ; } static int getDigits ( long x ) { int ans = 0 ; while ( x > 0 ) { int ans = 0 ; x /= 10 ; ans ++ ; } return ans ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner scn = new Scanner ( System . in ) ; int n = scn . nextInt ( ) ; int m = scn . nextInt ( ) ; int [ ] [ ] a = new int [ n ] [ m ] ; int [ ] b = new int [ m ] ; int [ ] c = new int [ n ] ; Arrays . fill ( c , 0 ) ; for ( int i = 0 ; i < n ; i ++ ) { int j = 0 ; for ( int j = 0 ; j < m ; j ++ ) { a [ i ] [ j ] = scn . nextInt ( ) ; } } for ( int i = 0 ; i < m ; i ++ ) { b [ i ] = scn . nextInt ( ) ; } for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < m ; j ++ ) { c [ i ] = c [ i ] + a [ i ] [ j ] * b [ j ] ; } System . out . println ( c [ i ] ) ; } scn . close ( ) ; } } +import java . util . * ; public class Main { private static final Scanner scn = new Scanner ( System . in ) ; private static final String WALL = " #################### " ; public static void main ( String [ ] args ) { int elm ; int [ ] [ ] [ ] tbl = new int [ 4 ] [ 3 ] [ 10 ] ; for ( int n = scn . nextInt ( ) ; n > 0 ; n -- ) { int b = load ( ) , f = load ( ) , r = load ( ) ; tbl [ b ] [ f ] [ r ] += scn . nextInt ( ) ; } for ( int i = 0 ; i < 4 ; i ++ ) { if ( i > 0 ) { System . out . println ( WALL ) ; } print ( tbl [ i ] ) ; } } private static int load ( ) { return scn . nextInt ( ) - 1 ; } private static void print ( int [ ] [ ] tbl ) { for ( int [ ] ary : tbl ) { for ( int elm : ary ) { System . out . format ( " %2d " , elm ) ; } System . out . println ( ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] h = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { int i = 0 ; h [ i ] = sc . nextInt ( ) ; } int number = 0 ; int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( number > h [ i ] ) ans += number - h [ i ] ; number = h [ i ] ; } ans += number ; System . out . println ( ans ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int d = 0 ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; String ans = " No " ; int c = 0 ; int d = 0 ; while ( 4 * c + 7 * d <= n ) { while ( 4 * c + 7 * d <= n ) { if ( 4 * c + 7 * d == n ) { ans = " Yes " ; break ; } else d ++ ; } c ++ ; d = 0 ; } System . out . println ( ans ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int n ; while ( ( n = scan . nextInt ( ) ) != 0 ) { int [ ] s = new int [ n ] ; double m = 0 ; for ( int i = 0 ; i < n ; i ++ ) { s [ i ] = scan . nextInt ( ) ; m += s [ i ] ; } m /= n ; double sum = 0 ; for ( int i = 0 ; i < s . length ; i ++ ) { int i = 0 ; sum += ( s [ i ] - m ) * ( s [ i ] - m ) ; } System . out . println ( Math . sqrt ( sum / n ) ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int [ ] T = new int [ 5 ] ; int [ ] D = new int [ 5 ] ; for ( int i = 0 ; i < 5 ; i ++ ) { T [ i ] = sc . nextInt ( ) ; } int sum = 0 ; for ( int i = 0 ; i < 5 ; i ++ ) { int i = 0 ; if ( T [ i ] % 10 == 0 ) { D [ i ] = T [ i ] ; } else { D [ i ] = ( T [ i ] / 10 ) * 10 + 10 ; } } int max = 0 ; for ( int i = 0 ; i < 5 ; i ++ ) { if ( ( D [ i ] - T [ i ] ) > max ) { max = D [ i ] - T [ i ] ; } sum = sum + D [ i ] ; } System . out . println ( sum - max ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int x = sc . nextInt ( ) ; int point = 0 ; int res = 1 ; for ( int i = 0 ; i < n ; i ++ ) { int res = 1 ; point += Integer . parseInt ( sc . next ( ) ) ; if ( x < point ) break ; res ++ ; } System . out . println ( res ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int x = sc . nextInt ( ) ; int n = sc . nextInt ( ) ; int [ ] ps = new int [ n ] ; int ans ; int istack ; for ( int i = 0 ; i < n ; i ++ ) { int i = 0 ; istack = sc . nextInt ( ) ; if ( istack < x ) ps [ i ] = Math . abs ( x - istack ) * 2 ; else ps [ i ] = Math . abs ( x - istack ) * 2 + 1 ; } Arrays . sort ( ps ) ; ans = 1 ; for ( int i = 0 ; i < n ; i ++ ) { if ( ps [ i ] == ans ) ans ++ ; else break ; } if ( ans % 2 == 0 ) x -= ans / 2 ; else x += ans / 2 ; System . out . println ( x ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int M = sc . nextInt ( ) ; int left = 0 ; int right = N ; for ( int i = 0 ; i < M ; i ++ ) { left = Math . max ( sc . nextInt ( ) , left ) ; right = Math . min ( sc . nextInt ( ) , right ) ; } if ( left <= right ) { int right = N ; System . out . println ( right - left + 1 ) ; } else { System . out . println ( 0 ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; Set < String > set = new HashSet < > ( ) ; int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { String s = sc . next ( ) ; String s = sc . next ( ) ; if ( ! set . contains ( s ) ) { set . add ( s ) ; ans ++ ; } } System . out . print ( ans ) ; } } +import java . util . * ; public class Main { static Scanner s = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { int n = s . nextInt ( ) , x = s . nextInt ( ) , t = s . nextInt ( ) ; int count = 0 ; count = n / x * t ; if ( n % x > 0 ) count += t ; System . out . println ( count ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int m = sc . nextInt ( ) ; int [ ] a = new int [ n ] ; int x = 0 ; int aa = 0 ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = sc . nextInt ( ) ; aa += a [ i ] ; } for ( int i = 0 ; i < n ; i ++ ) { int i = 0 ; if ( ( ( double ) aa / ( 4 * m ) ) <= a [ i ] ) { x ++ ; } } if ( m <= x ) { System . out . print ( " Yes " ) ; } else { System . out . print ( " No " ) ; } } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; char [ ] dance = sc . next ( ) . toCharArray ( ) ; boolean bl = true ; for ( int i = 0 ; i < dance . length ; i ++ ) { if ( i % 2 == 0 ) { if ( dance [ i ] == 'L' ) { int i = 0 ; bl = false ; break ; } } else { if ( dance [ i ] == 'R' ) { bl = false ; break ; } } } if ( bl ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } } +import java . io . BufferedReader ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws java . lang . Exception { BufferedReader input = new BufferedReader ( new InputStreamReader ( System . in ) ) ; for ( ; ; ) { String [ ] numberStr = input . readLine ( ) . split ( " " ) ; int max = Integer . parseInt ( numberStr [ 0 ] ) ; int sum = Integer . parseInt ( numberStr [ 1 ] ) ; if ( ( max == 0 ) && ( sum == 0 ) ) { break ; } int set = 0 ; for ( int oneNum = 1 ; oneNum <= max - 2 ; oneNum ++ ) { for ( int twoNum = oneNum + 1 ; twoNum <= max + 1 ; twoNum ++ ) { for ( int threeNum = twoNum + 1 ; threeNum <= max ; threeNum ++ ) { if ( oneNum + twoNum + threeNum == sum ) { int threeNum = twoNum + 1 ; set ++ ; } } } } System . out . println ( set ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; boolean f = false ; int n = sc . nextInt ( ) ; int [ ] a = new int [ n ] ; int [ ] ans = new int [ n ] ; for ( int i = 0 ; i < n - 1 ; i ++ ) { a [ i ] = sc . nextInt ( ) ; ans [ i ] = 0 ; } ans [ n - 1 ] = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int i = 0 ; if ( a [ i ] != 0 ) ans [ a [ i ] - 1 ] ++ ; } for ( int i = 0 ; i < n ; i ++ ) { System . out . println ( ans [ i ] ) ; } sc . close ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int n = scan . nextInt ( ) ; String s = scan . next ( ) ; String t = scan . next ( ) ; String ans = " " ; for ( int i = 0 ; i < n ; i ++ ) { int i = 0 ; ans = ans . concat ( s . substring ( i , i + 1 ) ) . concat ( t . substring ( i , i + 1 ) ) ; } System . out . println ( ans ) ; } } +import java . util . * ; import java . math . * ; import java . io . * ; public class Main { static Scanner sc = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { int [ ] a = new int [ 5 ] ; for ( int i = 0 ; i < 5 ; i ++ ) { a [ i ] = sc . nextInt ( ) ; } int ans = 3928237 ; for ( int i = 0 ; i < 5 ; i ++ ) { int sum = 0 ; for ( int j = 0 ; j < 5 ; j ++ ) { if ( i != j ) { sum += a [ j ] ; if ( a [ j ] % 10 != 0 ) { sum += 10 - a [ j ] % 10 ; } } else { int j = 0 ; sum += a [ j ] ; } } ans = Math . min ( ans , sum ) ; } System . out . println ( ans ) ; } } +import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int [ ] a = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { a [ i ] = sc . nextInt ( ) ; } Arrays . sort ( a ) ; int x = 0 ; int y = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( i % 2 == 0 ) { x += a [ i ] ; } else { int i = 0 ; y += a [ i ] ; } } System . out . println ( Math . abs ( x - y ) ) ; } } +import java . util . Scanner ; public class Main { @ SuppressWarnings ( " resource " ) public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int a = scanner . nextInt ( ) ; int b = scanner . nextInt ( ) ; int c = scanner . nextInt ( ) ; int d = scanner . nextInt ( ) ; int ans = 0 ; if ( c < a && d < a ) { int ans = 0 ; ans = 0 ; } if ( c <= a && d >= a && d <= b ) { ans = d - a ; } if ( c >= a && d <= b ) { ans = d - c ; } if ( c >= a && d >= b && c <= b ) { ans = b - c ; } if ( b < c ) { ans = 0 ; } if ( c <= a && b <= d ) { ans = b - a ; } System . out . println ( ans ) ; } } +import java . io . FileNotFoundException ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws FileNotFoundException { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; String S = sc . next ( ) ; char [ ] C = S . toCharArray ( ) ; char x = C [ 0 ] ; for ( int i = 1 ; i < N ; i ++ ) { if ( C [ i ] == x ) { C [ i ] = 0 ; } else { int i = 0 ; x = C [ i ] ; } } int ans = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( C [ i ] != 0 ) { ans ++ ; } } System . out . println ( ans ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int bnd = in . nextInt ( ) ; int lim = in . nextInt ( ) ; int pos = 0 ; int ans = 0 ; for ( int i = 0 ; i < bnd ; i ++ ) { pos += in . nextInt ( ) ; if ( lim < pos ) { int i = 0 ; ans = i + 1 ; break ; } else if ( lim == pos ) { ans = i + 2 ; break ; } else if ( i == bnd - 1 ) { ans = bnd + 1 ; } } System . out . println ( ans ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String S = sc . next ( ) ; char [ ] ss = S . toCharArray ( ) ; String T = sc . next ( ) ; char [ ] t = T . toCharArray ( ) ; int cou = 0 ; for ( int i = 0 ; i < S . length ( ) ; i ++ ) { for ( int j = 0 ; j < T . length ( ) ; j ++ ) { if ( ss [ i ] == t [ j ] ) { if ( S . equals ( T . substring ( j , T . length ( ) ) + T . substring ( 0 , j ) ) ) { cou ++ ; } } } } if ( cou > 0 ) { System . out . println ( " Yes " ) ; } else { int j = 0 ; System . out . println ( " No " ) ; } } } +import java . lang . Math ; import java . util . ArrayList ; import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { int i = a ; Scanner sn = new Scanner ( System . in ) ; int a = sn . nextInt ( ) ; int b = sn . nextInt ( ) ; int c = sn . nextInt ( ) ; int co = 0 ; for ( int i = a ; i <= b ; i ++ ) { if ( c % i != 0 ) { continue ; } co ++ ; } System . out . println ( co ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int sum = 0 ; Scanner sc = new Scanner ( System . in ) ; int max = 0 ; int sum = 0 ; for ( int i = 0 ; i < 3 ; i ++ ) { int x = sc . nextInt ( ) ; max = Math . max ( max , x ) ; sum += x ; } System . out . println ( sum - max ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int K = scanner . nextInt ( ) ; String N = scanner . next ( ) ; if ( N . length ( ) <= K ) { System . out . println ( N ) ; } else { String N = scanner . next ( ) ; System . out . println ( N . substring ( 0 , K ) + " ... " ) ; } } } +import java . io . BufferedInputStream ; import java . io . BufferedOutputStream ; import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . io . OutputStream ; import java . nio . charset . StandardCharsets ; import java . util . HashSet ; public class Main { public static void main ( String [ ] args ) { try { BufferedInputStream bf = new BufferedInputStream ( System . in ) ; BufferedReader in = new BufferedReader ( new InputStreamReader ( bf , StandardCharsets . UTF_8 ) ) ; OutputStream out = new BufferedOutputStream ( System . out ) ; int s = Integer . parseInt ( in . readLine ( ) ) ; int lim = 1000000 , i = 2 , a = s ; HashSet < Integer > set = new HashSet ( ) ; set . add ( s ) ; while ( i < lim ) { HashSet < Integer > set = new HashSet ( ) ; if ( a % 2 == 0 ) a = a / 2 ; else a = 3 * a + 1 ; if ( ! set . add ( a ) ) break ; i ++ ; } out . write ( ( i + " \n " ) . getBytes ( ) ) ; out . flush ( ) ; } catch ( Exception ex ) { ex . printStackTrace ( ) ; } } } +import java . io . IOException ; import java . util . ArrayList ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws IOException { Scanner sc = new Scanner ( System . in ) ; int K = sc . nextInt ( ) ; String S = sc . next ( ) ; if ( S . length ( ) <= K ) { System . out . println ( S ) ; } else { System . out . println ( S . substring ( 0 , K ) + " ... " ) ; } } static private int binarySearch ( long num , long [ ] orderedArray ) { int lowerBorder = - 1 ; int upperBorder = orderedArray . length ; int mid ; while ( upperBorder - lowerBorder > 1 ) { int mid ; mid = ( upperBorder + lowerBorder ) / 2 ; if ( orderedArray [ mid ] <= num ) { lowerBorder = mid ; } else { upperBorder = mid ; } } return lowerBorder ; } static private int binarySearch ( long num , ArrayList < Long > orderedList ) { int lowerBorder = - 1 ; int upperBorder = orderedList . size ( ) ; int mid ; while ( upperBorder - lowerBorder > 1 ) { mid = ( upperBorder + lowerBorder ) / 2 ; if ( orderedList . get ( mid ) <= num ) { lowerBorder = mid ; } else { upperBorder = mid ; } } return lowerBorder ; } public static int gcd ( int a , int b ) { return b == 0 ? a : gcd ( b , a % b ) ; } public static long gcd ( long a , long b ) { return b == 0 ? a : gcd ( b , a % b ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; StringBuilder answer = new StringBuilder ( ) ; int n = sc . nextInt ( ) ; int i = 1 ; if ( n >= 3 && n <= 10000 ) { while ( i <= n ) { if ( i % 3 == 0 ) { answer . append ( " " ) . append ( String . valueOf ( i ) ) ; } else { int x ; x = i ; while ( x != 0 ) { if ( x % 10 == 3 ) { int x ; answer . append ( " " ) . append ( String . valueOf ( i ) ) ; break ; } x = x / 10 ; } } i ++ ; } } System . out . println ( answer . toString ( ) ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int numN = in . nextInt ( ) ; int numM = in . nextInt ( ) ; int numC = in . nextInt ( ) ; int [ ] arrayB = new int [ numM ] ; for ( int i = 0 ; i < numM ; i ++ ) { arrayB [ i ] = in . nextInt ( ) ; } int result = 0 ; int numForcheck = 0 ; for ( int k = 0 ; k < numN ; k ++ ) { int j = 0 ; for ( int j = 0 ; j < numM ; j ++ ) { numForcheck += in . nextInt ( ) * arrayB [ j ] ; } if ( numForcheck + numC > 0 ) { result ++ ; } numForcheck = 0 ; } System . out . println ( result ) ; in . close ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . nextLine ( ) ; int ans = s . length ( ) ; for ( int i = 0 ; i < 2 ; i ++ ) { int j = 0 ; int cnt = 0 ; for ( int j = 0 ; j < s . length ( ) ; j ++ ) { if ( j % 2 == 0 && s . charAt ( j ) != ( char ) ( i + '0' ) ) cnt ++ ; if ( j % 2 == 1 && s . charAt ( j ) == ( char ) ( i + '0' ) ) cnt ++ ; } ans = Math . min ( ans , cnt ) ; } System . out . println ( ans ) ; } } +import java . util . Scanner ; public class Main { public static int x ; public static int y ; public static int z ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; x = sc . nextInt ( ) ; y = sc . nextInt ( ) ; if ( x > y ) { solve ( x , y ) ; } else { solve ( y , x ) ; } System . out . println ( z ) ; } public static void solve ( int big , int small ) { z = big % small ; if ( z == 0 ) { z = small ; } else { solve ( small , z ) ; } } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; String S = sc . next ( ) ; String T = sc . next ( ) ; sc . close ( ) ; int cnt = 0 ; for ( int i = 0 ; i < S . length ( ) ; i ++ ) { if ( S . substring ( i , i + 1 ) . equals ( T . substring ( i , i + 1 ) ) ) cnt ++ ; } System . out . println ( cnt ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int n = scanner . nextInt ( ) ; int m = scanner . nextInt ( ) ; boolean [ ] bool = new boolean [ n + 1 ] ; for ( int i = 0 ; i <= n ; i ++ ) { int i = 2 ; bool [ i ] = true ; } for ( int i = 0 ; i < m ; i ++ ) { bool [ scanner . nextInt ( ) ] = false ; } int [ ] b = new int [ n + 1 ] ; b [ 0 ] = 1 ; b [ 1 ] = 1 ; int mod = 1000000007 ; for ( int i = 2 ; i <= n ; i ++ ) { b [ i ] = 0 ; if ( bool [ i - 2 ] ) b [ i ] += b [ i - 2 ] ; if ( bool [ i - 1 ] ) b [ i ] += b [ i - 1 ] ; b [ i ] %= mod ; } System . out . println ( b [ n ] ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner in = new Scanner ( System . in ) ; String str = in . nextLine ( ) ; char c ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { c = str . charAt ( i ) ; if ( Character . isUpperCase ( c ) ) System . out . print ( Character . toLowerCase ( c ) ) ; else System . out . print ( Character . toUpperCase ( c ) ) ; } System . out . println ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String ... args ) { Scanner scan = new Scanner ( System . in ) ; String answer = " " ; String input = scan . next ( ) ; int len = input . length ( ) ; for ( int i = 0 ; i < len ; i ++ ) { switch ( input . charAt ( 0 ) ) { case '0' : if ( input . length ( ) > 0 ) { String input = scan . next ( ) ; input = input . substring ( 1 ) ; } answer = answer . concat ( " 0 " ) ; break ; case '1' : if ( input . length ( ) > 0 ) { input = input . substring ( 1 ) ; } answer = answer . concat ( " 1 " ) ; break ; case 'B' : input = input . substring ( 1 ) ; if ( answer . length ( ) > 0 ) { answer = answer . substring ( 0 , answer . length ( ) - 1 ) ; } break ; } } System . out . println ( answer ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { String l ; Scanner sc = new Scanner ( System . in ) ; String [ ] list = { sc . next ( ) , sc . next ( ) , sc . next ( ) } ; int five_count = 0 ; int seven_count = 0 ; for ( String l : list ) { if ( l . equals ( " 5 " ) ) five_count ++ ; else if ( l . equals ( " 7 " ) ) seven_count ++ ; } if ( five_count == 2 && seven_count == 1 ) System . out . println ( " YES " ) ; else System . out . println ( " NO " ) ; } } +import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . io . IOException ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader in = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String [ ] str = in . readLine ( ) . split ( " " ) ; int a = Integer . parseInt ( str [ 0 ] ) ; int b = Integer . parseInt ( str [ 1 ] ) ; int c = Integer . parseInt ( str [ 2 ] ) ; int d = Integer . parseInt ( str [ 3 ] ) ; boolean flg = true ; for ( ; flg == true ; ) { c = c - b ; if ( c <= 0 ) { System . out . println ( " Yes " ) ; flg = false ; break ; } a = a - d ; if ( a <= 0 ) { boolean flg = true ; System . out . println ( " No " ) ; flg = false ; } } } } +import java . io . * ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String [ ] s = br . readLine ( ) . split ( " " ) ; long n = Long . parseLong ( s [ 0 ] ) ; long a = Long . parseLong ( s [ 1 ] ) ; long b = Long . parseLong ( s [ 2 ] ) ; if ( a == 0 && b == 0 ) { System . out . println ( 0 ) ; } else { long b = Long . parseLong ( s [ 2 ] ) ; long sum = a + b ; sum = n % sum ; if ( sum > a ) sum = a ; long x = n / ( a + b ) ; System . out . println ( x * a + sum ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; StringBuilder sb = new StringBuilder ( ) ; String [ ] s = sc . next ( ) . split ( " " ) ; for ( int i = 0 ; i < s . length ; i ++ ) { int i = 0 ; sb . append ( s [ i ] . equals ( " 1 " ) ? " 9 " : " 1 " ) ; } System . out . println ( sb ) ; } } +import java . util . * ; public class Main { static Scanner sc = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { int n = sc . nextInt ( ) ; int m = sc . nextInt ( ) ; int [ ] [ ] ints = new int [ n ] [ m ] ; int [ ] line = new int [ n ] ; int [ ] row = new int [ m ] ; int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < m ; j ++ ) { int temp = Integer . parseInt ( sc . next ( ) ) ; ints [ i ] [ j ] = temp ; line [ i ] += temp ; row [ j ] += temp ; } sum += line [ i ] ; } for ( int i = 0 ; i < n + 1 ; i ++ ) { int j = 0 ; for ( int j = 0 ; j < m + 1 ; j ++ ) { if ( i == n && j == m ) { System . out . print ( sum ) ; } else if ( j == m ) { System . out . print ( line [ i ] ) ; } else if ( i == n ) { System . out . print ( row [ j ] ) ; } else { System . out . print ( ints [ i ] [ j ] ) ; } if ( j != m ) { System . out . print ( " " ) ; } } System . out . println ( ) ; } } } +import java . math . BigInteger ; import java . util . Scanner ; import java . util . Arrays ; public class Main { public static void main ( String [ ] args ) { int n , i , j , m , k , p , q , o , l , s , tt = 1 ; Double x , y , z ; int [ ] ar , br ; char ch ; BigInteger an , su , u , v ; String a , b = " " , c = " " , d ; Scanner sc = new Scanner ( System . in ) ; Scanner scc = new Scanner ( System . in ) ; ar = new int [ 200001 ] ; br = new int [ 200001 ] ; n = sc . nextInt ( ) ; m = sc . nextInt ( ) ; sc . nextLine ( ) ; p = 0 ; q = 0 ; for ( i = 0 ; i < m ; i ++ ) { Scanner sc = new Scanner ( System . in ) ; a = sc . nextLine ( ) ; o = 0 ; for ( j = 0 ; ; j ++ ) { ch = a . charAt ( j ) ; if ( ch == ' ' ) { break ; } o *= 10 ; o += ( int ) ( ch - '0' ) ; } j ++ ; ch = a . charAt ( j ) ; if ( ch == 'W' ) { if ( ar [ o ] == 0 ) { br [ o ] ++ ; } } else { if ( ar [ o ] == 0 ) { p ++ ; q += br [ o ] ; } ar [ o ] = 1 ; } } System . out . println ( p + " " + q ) ; } } +import java . io . * ; public class Main { public static void main ( String ... args ) throws IOException { final StringBuilder sb = new StringBuilder ( ) ; final BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; final StringBuilder sb = new StringBuilder ( ) ; while ( true ) { final String line = br . readLine ( ) ; final int index = line . indexOf ( " " ) ; final int x = Integer . parseInt ( line . substring ( 0 , index ) ) ; final int y = Integer . parseInt ( line . substring ( index + 1 , line . length ( ) ) ) ; if ( x == 0 && y == 0 ) break ; sb . append ( x < y ? x + " " + y : y + " " + x ) . append ( " \n " ) ; } System . out . print ( sb ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . Arrays ; import java . util . Collections ; public class Main { public static void main ( String [ ] args ) throws NumberFormatException , IOException { BufferedReader sb = new BufferedReader ( new InputStreamReader ( System . in ) ) ; Integer [ ] hList = new Integer [ 10 ] ; for ( int num = 0 ; num < 10 ; num ++ ) { int h = Integer . parseInt ( sb . readLine ( ) ) ; hList [ num ] = h ; } Arrays . sort ( hList , Collections . reverseOrder ( ) ) ; for ( int rank = 0 ; rank < 3 ; rank ++ ) { int rank = 0 ; System . out . println ( hList [ rank ] ) ; } } } +import java . util . ArrayList ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int k = sc . nextInt ( ) ; ArrayList < Integer > arrayList = new ArrayList < Integer > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { arrayList . add ( sc . nextInt ( ) ) ; } int sum = 0 ; for ( int i = 0 ; i < k ; i ++ ) { int idx = 0 ; int min = 999999 ; for ( int j = 0 ; j < arrayList . size ( ) ; j ++ ) { int j = 0 ; if ( arrayList . get ( j ) < min ) { idx = j ; min = arrayList . get ( j ) ; } } sum += arrayList . get ( idx ) ; arrayList . remove ( idx ) ; } System . out . println ( sum ) ; } } +import java . io . OutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . PrintWriter ; import java . util . Arrays ; import java . util . Scanner ; import java . util . Collections ; public class Main { public static void main ( String [ ] args ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; Scanner in = new Scanner ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; C solver = new C ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class C { public void solve ( int testNumber , Scanner in , PrintWriter out ) { int i = 0 ; int N = Integer . parseInt ( in . next ( ) ) ; int K = Integer . parseInt ( in . next ( ) ) ; Integer [ ] H = new Integer [ N ] ; long ans = 0 ; for ( int i = 0 ; i < N ; i ++ ) { H [ i ] = Integer . valueOf ( in . next ( ) ) ; ans += H [ i ] ; } Arrays . sort ( H , Collections . reverseOrder ( ) ) ; if ( K > N ) K = N ; for ( int i = 0 ; i < K ; i ++ ) { ans -= H [ i ] ; } out . println ( ans ) ; } } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . text . ParseException ; import java . text . SimpleDateFormat ; import java . util . Date ; public class Main { public static void main ( String [ ] args ) { InputStreamReader isr = new InputStreamReader ( System . in ) ; BufferedReader br = new BufferedReader ( isr ) ; String s = null ; try { s = br . readLine ( ) ; br . close ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } SimpleDateFormat sdf = new SimpleDateFormat ( " yyyy/MM/dd " ) ; Date formatDate = null ; try { Date compareDate = null ; formatDate = sdf . parse ( s ) ; } catch ( ParseException e ) { e . printStackTrace ( ) ; } Date compareDate = null ; try { compareDate = sdf . parse ( " 2019/04/30 " ) ; } catch ( ParseException e ) { } if ( formatDate . after ( compareDate ) ) { System . out . println ( " TBD " ) ; } else { System . out . println ( " Heisei " ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; String S = scanner . next ( ) ; scanner . close ( ) ; int plus = 0 , minus = 0 ; for ( int n = 0 ; n < S . length ( ) ; n ++ ) { String s = S . substring ( n , n + 1 ) ; if ( s . equals ( " + " ) ) { int n = 0 ; plus ++ ; } else if ( s . equals ( " - " ) ) { minus ++ ; } } int A = plus - minus ; System . out . println ( A ) ; } } +import java . util . ArrayList ; import java . util . List ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { long i = 1 ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) , count = 0 ; for ( int i = 1 ; i <= n ; i += 2 ) { if ( divisorEnum ( i ) . size ( ) == 8 ) count ++ ; } System . out . println ( count ) ; } public static List < Long > divisorEnum ( long n ) { List < Long > l = new ArrayList < > ( ) ; for ( long i = 1 ; i <= Math . sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) { l . add ( i ) ; if ( i != Math . sqrt ( n ) ) l . add ( n / i ) ; } } l . sort ( null ) ; return l ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . nextLine ( ) ; String t = sc . nextLine ( ) ; int min = Integer . MAX_VALUE ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { int j = 0 ; if ( i + t . length ( ) <= s . length ( ) ) { int tot = 0 ; for ( int j = 0 ; j < t . length ( ) ; j ++ ) { if ( s . charAt ( i + j ) != t . charAt ( j ) ) tot ++ ; } min = Math . min ( min , tot ) ; } } System . out . println ( min ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; String S = sc . next ( ) ; String T = sc . next ( ) ; String [ ] Slist = S . split ( " " ) ; String [ ] Tlist = T . split ( " " ) ; int countNum = 0 ; for ( int i = 0 ; i <= 2 ; i ++ ) { if ( Slist [ i ] . equals ( Tlist [ i ] ) ) { countNum ++ ; } } System . out . println ( countNum ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int [ ] A = new int [ N + 1 ] ; int [ ] B = new int [ N ] ; long jizenSum = 0 ; for ( int i = 0 ; i < N + 1 ; i ++ ) { A [ i ] = sc . nextInt ( ) ; jizenSum += A [ i ] ; } for ( int i = 0 ; i < N ; i ++ ) { int i = 0 ; B [ i ] = sc . nextInt ( ) ; } int tmp = 0 ; for ( int i = 0 ; i < N ; i ++ ) { tmp = A [ i ] - B [ i ] ; if ( tmp < 0 ) { if ( B [ i ] - A [ i ] > A [ i + 1 ] ) { A [ i + 1 ] = 0 ; } else { A [ i + 1 ] = A [ i + 1 ] - ( B [ i ] - A [ i ] ) ; } A [ i ] = 0 ; } else { A [ i ] = tmp ; } } long sum = 0 ; for ( int i = 0 ; i < N + 1 ; i ++ ) { sum += A [ i ] ; } System . out . println ( jizenSum - sum ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { long ai = sc . nextLong ( ) ; try ( Scanner sc = new Scanner ( System . in ) ) { long max = ( long ) Math . pow ( 10 , 18 ) ; int n = sc . nextInt ( ) ; long ans = 1 ; boolean isOver = false ; for ( int i = 0 ; i < n ; i ++ ) { long ai = sc . nextLong ( ) ; if ( ai == 0 ) { System . out . println ( " 0 " ) ; return ; } if ( ! isOver ) { try { ans = Math . multiplyExact ( ans , ai ) ; } catch ( Exception e ) { isOver = true ; } } if ( ans > max || ans < 0 ) { isOver = true ; } } if ( isOver ) { System . out . println ( " -1 " ) ; } else { System . out . println ( ans ) ; } } } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws IOException { Scanner scan = new java . util . Scanner ( System . in ) ; InputStreamReader input = new InputStreamReader ( System . in ) ; BufferedReader br = new BufferedReader ( input ) ; StringBuilder sb = new StringBuilder ( ) ; while ( true ) { int n = Integer . parseInt ( br . readLine ( ) ) ; if ( n == 0 ) break ; int [ ] s = new int [ n ] ; String [ ] dataset = br . readLine ( ) . split ( " " ) ; for ( int i = 0 ; i < n ; i ++ ) { s [ i ] = Integer . parseInt ( dataset [ i ] ) ; } int goukei = 0 ; for ( int i : s ) { goukei += i ; } double m = ( double ) goukei / ( double ) n ; double alfa2 = 0.0 ; for ( int i : s ) { int i ; alfa2 += ( i - m ) * ( i - m ) ; } alfa2 = alfa2 / n ; double alfa = Math . sqrt ( alfa2 ) ; System . out . println ( alfa ) ; } } } +import java . io . * ; class Program { } class Main { public static void main ( String [ ] args ) throws IOException { Program obj = new Program ( ) ; BufferedReader in = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String [ ] ip ; int N , M , C ; int [ ] A , B ; ip = in . readLine ( ) . split ( " " ) ; N = Integer . parseInt ( ip [ 0 ] ) ; M = Integer . parseInt ( ip [ 1 ] ) ; C = Integer . parseInt ( ip [ 2 ] ) ; int count = 0 , score = 0 ; A = new int [ M ] ; B = new int [ M ] ; ip = in . readLine ( ) . split ( " " ) ; for ( int i = 0 ; i < M ; i ++ ) B [ i ] = Integer . parseInt ( ip [ i ] ) ; while ( -- N >= 0 ) { int i = 0 ; ip = in . readLine ( ) . split ( " " ) ; score = 0 ; for ( int i = 0 ; i < M ; i ++ ) { A [ i ] = Integer . parseInt ( ip [ i ] ) ; score += B [ i ] * A [ i ] ; } if ( score + C > 0 ) count ++ ; } System . out . println ( count ) ; } } +import java . math . * ; import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int [ ] hills = new int [ 10 ] ; for ( int i = 0 ; i < 10 ; i ++ ) { hills [ i ] = in . nextInt ( ) * - 1 ; } Arrays . sort ( hills ) ; for ( int i = 0 ; i < 3 ; i ++ ) { int i = 0 ; System . out . println ( hills [ i ] * - 1 ) ; } } } +import java . util . Scanner ; public class Main { static String str ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; str = sc . next ( ) ; int n = str . length ( ) ; boolean [ ] dp = new boolean [ n + 1 ] ; dp [ 0 ] = true ; for ( int i = 5 ; i <= n ; i ++ ) { if ( str . substring ( i - 5 , i ) . equals ( " dream " ) ) { dp [ i ] |= dp [ i - 5 ] ; } if ( str . substring ( i - 5 , i ) . equals ( " erase " ) ) { int i = 5 ; dp [ i ] |= dp [ i - 5 ] ; } if ( i - 7 >= 0 && str . substring ( i - 7 , i ) . equals ( " dreamer " ) ) { dp [ i ] |= dp [ i - 7 ] ; } if ( i - 6 >= 0 && str . substring ( i - 6 , i ) . equals ( " eraser " ) ) { dp [ i ] |= dp [ i - 6 ] ; } } if ( dp [ n ] ) { 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 ) ; char [ ] C = sc . next ( ) . toCharArray ( ) ; sc . close ( ) ; int n = C . length ; int st = 0 ; for ( int i = 0 ; i < n ; ++ i ) { if ( C [ i ] == 'A' ) { st = i ; break ; } } int gl = 0 ; for ( int i = n - 1 ; i >= 0 ; -- i ) { int i = n - 1 ; if ( C [ i ] == 'Z' ) { gl = i ; break ; } } System . out . println ( gl - st + 1 ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int [ ] H = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) H [ i ] = sc . nextInt ( ) ; int maxMove = 0 ; int currentMove = 0 ; for ( int i = 0 ; i < N - 1 ; i ++ ) { int i = 0 ; if ( H [ i ] >= H [ i + 1 ] ) { currentMove ++ ; if ( currentMove > maxMove ) maxMove = currentMove ; } else { currentMove = 0 ; } } System . out . println ( maxMove ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; String S = scan . next ( ) ; int length = S . length ( ) ; int count = 0 ; for ( int i = 0 ; i < length / 2 ; i ++ ) { int i = 0 ; if ( S . charAt ( i ) != S . charAt ( length - 1 - i ) ) count ++ ; } System . out . println ( count ) ; } } +import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int M = sc . nextInt ( ) ; int [ ] answerArr = new int [ M ] ; int answer = 0 ; Arrays . fill ( answerArr , 0 ) ; for ( int i = 0 ; i < N ; i ++ ) { int K = sc . nextInt ( ) ; for ( int j = 0 ; j < K ; j ++ ) { int Ki = sc . nextInt ( ) ; answerArr [ Ki - 1 ] ++ ; } } for ( int i = 0 ; i < M ; i ++ ) { if ( answerArr [ i ] == N ) { answer ++ ; } } System . out . println ( answer ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; String str = scan . nextLine ( ) ; String result = " " ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { String s = str . substring ( i , i + 1 ) ; if ( s . equals ( s . toLowerCase ( ) ) ) { result += s . toUpperCase ( ) ; } else { String s = str . substring ( i , i + 1 ) ; result += s . toLowerCase ( ) ; } } System . out . println ( result ) ; } } +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 n = Integer . parseInt ( String . valueOf ( a ) + String . valueOf ( b ) ) ; for ( int i = 1 ; i < 330 ; i ++ ) { int i = 1 ; if ( i * i == n ) { System . out . println ( " Yes " ) ; return ; } } System . out . println ( " No " ) ; } } +import java . util . * ; import static java . util . Map . Entry . comparingByValue ; import static java . util . stream . Collectors . toMap ; public class Main { public static void main ( String [ ] args ) { Scanner Input = new Scanner ( System . in ) ; int N = Input . nextInt ( ) ; HashMap < String , Integer > HM = new HashMap ( ) ; for ( int I = 0 ; I < N ; I ++ ) { String S = Input . next ( ) ; if ( ! HM . containsKey ( S ) ) { String S = Input . next ( ) ; HM . put ( S , 0 ) ; } } System . out . println ( HM . size ( ) ) ; } } +import java . util . * ; import java . util . Collections ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; String S = sc . next ( ) ; int cnt = 0 ; for ( int i = 0 ; i < N - 2 ; i ++ ) { if ( S . charAt ( i ) == 'A' & S . charAt ( i + 1 ) == 'B' & S . charAt ( i + 2 ) == 'C' ) { cnt ++ ; } } System . out . println ( cnt ) ; } public static void primeFactorization ( int num ) { int i = 3 ; int Z = 0 ; for ( int i = 2 ; num > i ; i ++ ) { while ( num % i == 0 ) { System . out . println ( i ) ; num /= i ; Z = num ; } } System . out . println ( Z ) ; } public static boolean isPrime ( int num ) { if ( num < 2 ) return false ; else if ( num == 2 ) return true ; else if ( num % 2 == 0 ) return false ; for ( int i = 3 ; i < num ; i += 2 ) { if ( num % i == 0 ) { return false ; } } return true ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int i ; String str ; while ( true ) { str = sc . next ( ) ; if ( str . equals ( " - " ) ) { int h ; break ; } String str1 ; String str2 ; int m ; m = sc . nextInt ( ) ; int h ; for ( i = 0 ; i < m ; i ++ ) { h = sc . nextInt ( ) ; str1 = str . substring ( 0 , h ) ; str2 = str . substring ( h ) ; str = str2 + str1 ; } System . out . println ( str ) ; } sc . close ( ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) , m = sc . nextInt ( ) ; int [ ] work = new int [ m ] ; int ans = 0 ; for ( int i = 0 ; i < m ; ++ i ) { int i = 0 ; work [ i ] = sc . nextInt ( ) ; ans += work [ i ] ; } ans = n - ans ; if ( ans < 0 ) ans = - 1 ; sc . close ( ) ; System . out . println ( ans ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int a3 = a * b ; Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int a1 = a + b ; int a2 = a - b ; int a3 = a * b ; if ( a1 >= a2 && a1 >= a3 ) { System . out . println ( a1 ) ; } else if ( a2 >= a1 && a2 >= a3 ) { System . out . println ( a2 ) ; } else if ( a3 >= a1 && a3 >= a2 ) { System . out . println ( a3 ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; String [ ] s = sc . next ( ) . split ( " " ) ; for ( int i = 0 ; i < s . length ; i ++ ) { if ( s [ i ] . equals ( " 1 " ) ) s [ i ] = " 9 " ; else if ( s [ i ] . equals ( " 9 " ) ) s [ i ] = " 1 " ; System . out . print ( s [ i ] ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] arges ) { int i = v [ 0 ] ; Scanner sc = new Scanner ( System . in ) ; String line = sc . nextLine ( ) ; String [ ] k = line . split ( " " ) ; int [ ] v = new int [ k . length ] ; for ( int i = 0 ; i < v . length ; i ++ ) { v [ i ] = Integer . parseInt ( k [ i ] ) ; } int count = 0 ; for ( int i = v [ 0 ] ; i <= v [ 1 ] ; i ++ ) { if ( v [ 2 ] % i == 0 ) { count ++ ; } } System . out . println ( count ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i ; Scanner scanner = new Scanner ( System . in ) ; int n = scanner . nextInt ( ) ; int [ ] h = new int [ n ] ; int [ ] curH = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { h [ i ] = scanner . nextInt ( ) ; } int count = 0 ; outer : while ( true ) { int start = 0 , end = 0 ; for ( start = 0 ; start < n ; start ++ ) { if ( curH [ start ] < h [ start ] ) { break ; } } if ( start >= n ) { break ; } count ++ ; int i ; for ( i = start ; i < n ; i ++ ) { if ( curH [ i ] < h [ i ] ) { curH [ i ] ++ ; } else { break ; } } } System . out . println ( count ) ; } } +import java . io . * ; import java . util . * ; class Main { public static void main ( String [ ] args ) throws IOException { try ( BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ) { String input = br . readLine ( ) ; int result = 0 ; if ( input . contains ( " A " ) ) { result ++ ; } if ( input . contains ( " B " ) ) { result ++ ; } if ( result == 2 ) { int result = 0 ; System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } } } +import java . io . IOException ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws IOException { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int x = sc . nextInt ( ) ; int [ ] m = new int [ n ] ; int minCost = Integer . MAX_VALUE ; int total = 0 ; for ( int i = 0 ; i < n ; i ++ ) { m [ i ] = sc . nextInt ( ) ; minCost = Math . min ( minCost , m [ i ] ) ; total += m [ i ] ; } System . out . println ( ( x - total ) / minCost + n ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; String search = scanner . nextLine ( ) ; boolean Judge = true ; int count = 0 ; String end = " END_OF_TEXT " ; while ( Judge ) { String word = scanner . next ( ) ; int result = word . lastIndexOf ( end ) ; if ( result != - 1 ) { Judge = false ; } else { String word = scanner . next ( ) ; word = word . toLowerCase ( ) ; } if ( word . equals ( search ) ) { count ++ ; } } System . out . println ( count ) ; scanner . close ( ) ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String str = sc . nextLine ( ) ; int n = Integer . parseInt ( str ) ; int h_point = 0 , t_point = 0 ; for ( int i = 0 ; i < n ; i ++ ) { String taro = sc . next ( ) ; String hanako = sc . next ( ) ; if ( taro . compareTo ( hanako ) > 0 ) t_point += 3 ; else if ( taro . compareTo ( hanako ) < 0 ) h_point += 3 ; else { int h_point = 0 , t_point = 0 ; t_point ++ ; h_point ++ ; } } System . out . println ( t_point + " " + h_point ) ; } } +import java . io . * ; public class Main { final static long MOD = 1000000007 ; public static void main ( String [ ] args ) throws Exception { BufferedReader in = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String W = in . readLine ( ) ; int N = Integer . parseInt ( W ) ; W = in . readLine ( ) ; String [ ] Ws = W . split ( " " ) ; long [ ] A = new long [ Ws . length ] ; for ( int i = 0 ; i < Ws . length ; i ++ ) { A [ i ] = Long . parseLong ( Ws [ i ] ) ; } String ans = " APPROVED " ; for ( int i = 0 ; i < N ; i ++ ) { int i = 0 ; if ( A [ i ] % 2 == 0 && ! ( A [ i ] % 3 == 0 || A [ i ] % 5 == 0 ) ) { ans = " DENIED " ; break ; } } System . out . println ( ans ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; String s = sc . next ( ) ; int count = 1 ; for ( int i = 1 ; i < s . length ( ) ; i ++ ) { int i = 1 ; if ( s . charAt ( i ) != s . charAt ( i - 1 ) ) { count ++ ; } } System . out . println ( count ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int i = 1 ; int x = i ; int start = 0 ; while ( i <= n ) { if ( start == 0 ) { x = i ; if ( x % 3 == 0 ) { int start = 0 ; System . out . print ( " " + i ) ; start = 2 ; } } if ( start <= 1 ) { if ( x % 10 == 3 ) { System . out . print ( " " + i ) ; start = 2 ; } if ( start <= 1 ) { x /= 10 ; if ( 0 < x ) { start = 1 ; continue ; } } } i ++ ; start = 0 ; } System . out . println ( ) ; } } +import java . io . * ; import java . util . * ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner in = new Scanner ( new BufferedReader ( new InputStreamReader ( System . in ) ) ) ; int t = 1 ; int n = in . nextInt ( ) ; int m = in . nextInt ( ) ; int [ ] a = new int [ n ] ; int x = 0 , cnt = 0 , sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = in . nextInt ( ) ; sum += a [ i ] ; } x = ( int ) Math . ceil ( sum / ( 1.0 * 4 * m ) ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( a [ i ] >= x ) cnt ++ ; } System . out . println ( cnt >= m ? " Yes " : " No " ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; while ( true ) { int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int saisi = sc . nextInt ( ) ; int c = a + b ; if ( a == - 1 && b == - 1 && saisi == - 1 ) { break ; } if ( a == - 1 || b == - 1 ) { System . out . println ( " F " ) ; } else if ( c >= 80 ) { System . out . println ( " A " ) ; } else if ( c >= 65 ) { System . out . println ( " B " ) ; } else if ( c >= 50 ) { System . out . println ( " C " ) ; } else if ( c >= 30 ) { if ( saisi >= 50 ) { System . out . println ( " C " ) ; } else { System . out . println ( " D " ) ; } } else { int saisi = sc . nextInt ( ) ; System . out . println ( " F " ) ; } } } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; List < Integer > list = new ArrayList < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { List < Integer > list = new ArrayList < > ( ) ; list . add ( sc . nextInt ( ) ) ; } List < Integer > listB = new ArrayList < Integer > ( new HashSet < > ( list ) ) ; System . out . print ( listB . size ( ) ) ; } } +import java . util . ArrayList ; import java . util . Collections ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int n = scan . nextInt ( ) , l = scan . nextInt ( ) ; ArrayList < String > dict = new ArrayList < String > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { dict . add ( scan . next ( ) ) ; } Collections . sort ( dict ) ; String result = " " ; for ( int i = 0 ; i < n ; i ++ ) { int i = 0 ; result += dict . get ( i ) ; } System . out . println ( result ) ; } } +import java . util . ArrayList ; import java . util . HashSet ; import java . util . List ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { List < String > list = new ArrayList < > ( ) ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; List < String > list = new ArrayList < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { String s = sc . next ( ) ; list . add ( s ) ; } List < String > listb = new ArrayList < String > ( new HashSet < > ( list ) ) ; sc . close ( ) ; System . out . println ( listb . size ( ) ) ; } } +import java . io . IOException ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws IOException { Scanner scan = new Scanner ( System . in ) ; int num = scan . nextInt ( ) ; boolean [ ] [ ] cards = new boolean [ 4 ] [ 13 ] ; for ( int i = 0 ; i < num ; i ++ ) { String design = scan . next ( ) ; int cardNumber = scan . nextInt ( ) ; int designNumber = 0 ; if ( design . equals ( " S " ) ) { designNumber = 0 ; } else if ( design . equals ( " H " ) ) { designNumber = 1 ; } else if ( design . equals ( " C " ) ) { designNumber = 2 ; } else if ( design . equals ( " D " ) ) { int j = 0 ; designNumber = 3 ; } cards [ designNumber ] [ cardNumber - 1 ] = true ; } for ( int i = 0 ; i < 4 ; i ++ ) { for ( int j = 0 ; j < 13 ; j ++ ) { if ( cards [ i ] [ j ] == false ) { if ( i == 0 ) { System . out . print ( " S " ) ; } else if ( i == 1 ) { System . out . print ( " H " ) ; } else if ( i == 2 ) { System . out . print ( " C " ) ; } else if ( i == 3 ) { System . out . print ( " D " ) ; } System . out . println ( " " + ( j + 1 ) ) ; } } } } } +import java . util . * ; import java . io . * ; public class Main { static StringTokenizer st ; static BufferedReader br ; static PrintWriter out ; public static void main ( String [ ] args ) throws IOException { br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String N = " " + nextInt ( ) ; if ( N . contains ( " 7 " ) ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } public static int nextInt ( ) throws IOException { return Integer . parseInt ( next ( ) ) ; } public static long nextLong ( ) throws IOException { return Long . parseLong ( next ( ) ) ; } public static double nextDouble ( ) throws IOException { return Double . parseDouble ( next ( ) ) ; } static String next ( ) throws IOException { while ( st == null || ! st . hasMoreTokens ( ) ) st = new StringTokenizer ( br . readLine ( ) . trim ( ) ) ; return st . nextToken ( ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int T = sc . nextInt ( ) ; int [ ] allList = new int [ 2 * N ] ; for ( int i = 0 ; i < 2 * N ; i ++ ) { allList [ i ] = sc . nextInt ( ) ; } int cost = 10001 ; for ( int i = 1 ; i < 2 * N ; i += 2 ) { int i = 1 ; if ( allList [ i ] <= T && allList [ i - 1 ] < cost ) { cost = allList [ i - 1 ] ; } } if ( cost == 10001 ) { System . out . println ( " TLE " ) ; } else { System . out . println ( cost ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int l = sc . nextInt ( ) ; int cnt = 0 ; while ( n > 0 ) { int cnt = 0 ; cnt ++ ; n = ( n / l ) ; } System . out . println ( cnt ) ; } } +import java . util . Scanner ; public class Main { void run ( ) { Scanner s = new Scanner ( System . in ) ; while ( true ) { int n = s . nextInt ( ) ; int x = s . nextInt ( ) ; if ( n == 0 && x == 0 ) break ; int sum = 0 ; int count = 0 ; int a = 0 ; int [ ] num = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) num [ i ] = i + 1 ; for ( int i = a ; i < n ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { int k = j + 1 ; for ( int k = j + 1 ; k < n ; k ++ ) { sum = num [ i ] + num [ j ] + num [ k ] ; if ( sum == x ) { count ++ ; } a ++ ; } } } System . out . println ( count ) ; } } public static void main ( String [ ] args ) { new Main ( ) . run ( ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int m = sc . nextInt ( ) ; int [ ] [ ] A = new int [ n ] [ m ] ; int [ ] b = new int [ m ] ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < m ; j ++ ) { A [ i ] [ j ] = sc . nextInt ( ) ; } sc . nextLine ( ) ; } for ( int i = 0 ; i < m ; i ++ ) { b [ i ] = sc . nextInt ( ) ; } int [ ] c = productVector ( A , b ) ; for ( int i = 0 ; i < n ; i ++ ) { System . out . println ( c [ i ] ) ; } } static int [ ] productVector ( int [ ] [ ] a , int [ ] b ) { int j = 0 ; int [ ] c = new int [ a . length ] ; for ( int i = 0 ; i < a . length ; i ++ ) { for ( int j = 0 ; j < a [ 0 ] . length ; j ++ ) { c [ i ] += ( a [ i ] [ j ] * b [ j ] ) ; } } return c ; } } +import java . util . ArrayList ; import java . util . Collections ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int inputDeckNum = sc . nextInt ( ) ; ArrayList < Integer > deckList = new ArrayList < > ( ) ; for ( int i = 1 ; i <= inputDeckNum ; i ++ ) { deckList . add ( sc . nextInt ( ) ) ; } Collections . sort ( deckList , Collections . reverseOrder ( ) ) ; int first_player = 0 ; int second_player = 0 ; for ( int i = 0 ; i < deckList . size ( ) ; i ++ ) { int i = 0 ; if ( i % 2 == 0 ) { first_player += deckList . get ( i ) ; } else { second_player += deckList . get ( i ) ; } } sc . close ( ) ; System . out . println ( first_player - second_player ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws IOException { int i = 0 ; BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; while ( true ) { int num = Integer . parseInt ( br . readLine ( ) ) ; if ( num == 0 ) { break ; } int [ ] su = new int [ num ] ; String [ ] str = br . readLine ( ) . split ( " " ) ; for ( int i = 0 ; i < str . length ; i ++ ) { su [ i ] = Integer . parseInt ( str [ i ] ) ; } double sum = 0 ; for ( int i = 0 ; i < su . length ; i ++ ) { sum += su [ i ] ; } double avg = sum / num ; double result = 0 ; for ( int i = 0 ; i < num ; i ++ ) { result += ( Math . pow ( ( su [ i ] - avg ) , 2 ) / num ) ; } System . out . println ( Math . sqrt ( result ) ) ; } } } +import java . util . Arrays ; import java . util . Scanner ; public class Main { char temp ; void run ( ) { Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; String str = sc . next ( ) ; for ( int i = 0 ; i < a ; i ++ ) { int i = a + 1 ; temp = str . charAt ( i ) ; if ( '0' > temp || temp > '9' ) { System . out . println ( " No " ) ; return ; } } if ( str . charAt ( a ) != '-' ) { System . out . println ( " No " ) ; return ; } for ( int i = a + 1 ; i <= a + b ; i ++ ) { temp = str . charAt ( i ) ; if ( '0' > temp || temp > '9' ) { System . out . println ( " No " ) ; return ; } } System . out . println ( " Yes " ) ; sc . close ( ) ; } void debug ( Object ... o ) { System . out . println ( Arrays . deepToString ( o ) ) ; } public static void main ( String [ ] args ) { new Main ( ) . run ( ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int num = sc . nextInt ( ) ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; Map < Integer , Boolean > map = new HashMap < > ( ) ; String ans = " YES " ; for ( int i = 0 ; i < n ; i ++ ) { int num = sc . nextInt ( ) ; if ( map . get ( num ) == null ) { map . put ( num , true ) ; } else { ans = " NO " ; break ; } } System . out . println ( ans ) ; } } +import java . util . ArrayList ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 1 ; Scanner scn = new Scanner ( System . in ) ; int A = scn . nextInt ( ) ; int B = scn . nextInt ( ) ; int K = scn . nextInt ( ) ; ArrayList < Integer > hits = new ArrayList < Integer > ( ) ; int cnt = 0 ; for ( int i = 1 ; i <= 100 ; i ++ ) { if ( A % i == 0 && B % i == 0 ) hits . add ( i ) ; } System . out . println ( hits . get ( hits . size ( ) - K ) ) ; scn . close ( ) ; } } +import java . util . * ; import java . lang . * ; public class Main { static class pair { double f , s ; pair ( double f , double s ) { this . f = f ; this . s = s ; } } public static void main ( String [ ] args ) { int i = 1 ; Scanner in = new Scanner ( System . in ) ; int c = in . nextInt ( ) ; int [ ] A = new int [ c + 1 ] ; int [ ] B = new int [ c + 1 ] ; int [ ] C = new int [ c ] ; for ( int i = 1 ; i <= c ; i ++ ) A [ i ] = in . nextInt ( ) ; for ( int i = 1 ; i <= c ; i ++ ) B [ i ] = in . nextInt ( ) ; for ( int i = 1 ; i < c ; i ++ ) C [ i ] = in . nextInt ( ) ; long sum = 0 ; int h = - 1 ; for ( int i = 1 ; i <= c ; i ++ ) { sum += B [ A [ i ] ] ; if ( h + 1 == A [ i ] ) sum += C [ h ] ; h = A [ i ] ; } System . out . println ( sum ) ; in . close ( ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; String [ ] tokens = in . nextLine ( ) . split ( " " ) ; in . close ( ) ; int A = Integer . parseInt ( tokens [ 0 ] ) ; int B = Integer . parseInt ( tokens [ 1 ] ) ; int a = Integer . parseInt ( tokens [ 0 ] . substring ( 0 , 3 ) ) ; int b = Integer . parseInt ( tokens [ 1 ] . substring ( 0 , 3 ) ) ; int min = Integer . parseInt ( tokens [ 0 ] . substring ( 0 , 3 ) + tokens [ 0 ] . charAt ( 1 ) + tokens [ 0 ] . charAt ( 0 ) ) ; int max = Integer . parseInt ( tokens [ 1 ] . substring ( 0 , 3 ) + tokens [ 1 ] . charAt ( 1 ) + tokens [ 1 ] . charAt ( 0 ) ) ; int result = b - a + 1 ; if ( A > min ) { int result = b - a + 1 ; result -= 1 ; } if ( B < max ) { result -= 1 ; } System . out . println ( result ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; PriorityQueue < Double > q = new PriorityQueue < > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { q . add ( ( double ) sc . nextInt ( ) ) ; } while ( q . size ( ) > 1 ) { PriorityQueue < Double > q = new PriorityQueue < > ( ) ; double x = q . poll ( ) ; double y = q . poll ( ) ; q . add ( ( x + y ) / 2 ) ; } System . out . println ( q . poll ( ) ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { solve_149_B ( ) ; return ; } private static void solve_149_B ( ) { Scanner sc = new Scanner ( System . in ) ; long A = sc . nextLong ( ) ; long B = sc . nextLong ( ) ; long K = sc . nextLong ( ) ; if ( A >= K ) { long K = sc . nextLong ( ) ; A = A - K ; } else { if ( B >= ( K - A ) ) { B = B - ( K - A ) ; } else { B = 0 ; } A = 0 ; } System . out . println ( A + " " + B ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; String S = sc . next ( ) ; String T = sc . next ( ) ; String [ ] Sarray = S . split ( " " , 0 ) ; String [ ] Tarray = T . split ( " " , 0 ) ; String ans = " " ; for ( int i = 0 ; i < n ; i ++ ) { ans = ans + Sarray [ i ] ; ans = ans + Tarray [ i ] ; } System . out . println ( ans ) ; } } +import java . util . * ; import java . lang . * ; public class Main { public static void main ( String [ ] args ) { Scanner dataScanner = new Scanner ( System . in ) ; String [ ] data = dataScanner . nextLine ( ) . split ( " " ) ; int numCards = Integer . parseInt ( data [ 0 ] ) ; int goal = Integer . parseInt ( data [ 1 ] ) ; boolean foundPair = false ; Integer [ ] pair = new Integer [ 3 ] ; int otoshidama = 0 ; outerloop : for ( Integer i = 0 ; i < Math . max ( numCards , 0 ) + 1 ; i ++ ) { Integer number ; for ( Integer j = 0 ; j < Math . max ( numCards - i , 0 ) + 1 ; j ++ ) { int k = numCards - i - j ; otoshidama = 10000 * i + 5000 * j + 1000 * k ; if ( otoshidama == goal ) { foundPair = true ; pair [ 0 ] = i ; pair [ 1 ] = j ; pair [ 2 ] = k ; break outerloop ; } } } if ( foundPair ) { StringJoiner toPrint = new StringJoiner ( " " ) ; for ( Integer number : pair ) { toPrint . add ( number . toString ( ) ) ; } System . out . println ( toPrint . toString ( ) ) ; } else { System . out . println ( " -1 -1 -1 " ) ; } } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; int ans = 0 ; for ( int i = 0 ; i < 3 ; i ++ ) { if ( s . charAt ( i ) == '1' ) { int i = 0 ; ans += 1 ; } } System . out . println ( ans ) ; } } +import java . math . BigDecimal ; import java . math . MathContext ; import java . math . RoundingMode ; import java . util . Scanner ; public class Main { static Scanner sc = new Scanner ( System . in ) ; static int A = sc . nextInt ( ) ; static int B = sc . nextInt ( ) ; static int H = sc . nextInt ( ) ; static int M = sc . nextInt ( ) ; public static void main ( String [ ] args ) { double kakudo = kHour - kMin ; double kHour = H * 30 + M * 0.5 ; double kMin = M * 6 ; double kakudo = kHour - kMin ; if ( kakudo > 180 ) { kakudo = 360 - kakudo ; } else if ( kakudo < 0 ) { kakudo *= - 1 ; } double dC = A * A + B * B - 2 * A * B * Math . cos ( Math . toRadians ( kakudo ) ) ; double result = Math . sqrt ( dC ) ; System . out . print ( result ) ; } } +import java . io . * ; import java . util . * ; public class Main { public static void main ( final String [ ] args ) throws Exception { final Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; String S = sc . next ( ) ; final Solver solver = new Solver ( ) ; solver . solve ( N , S ) ; } } class Solver { public void solve ( int N , String S ) { int ans = 0 ; int cur = 'A' ; for ( int i = 0 ; i < N ; i ++ ) { char c = S . charAt ( i ) ; char c = S . charAt ( i ) ; if ( cur == c ) { cur ++ ; if ( cur > 'C' ) { ans ++ ; cur = 'A' ; } } else { cur = ( c == 'A' ) ? 'B' : 'A' ; } } System . out . println ( ans ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long N = sc . nextLong ( ) ; long A = sc . nextLong ( ) ; long B = sc . nextLong ( ) ; long C = N / ( A + B ) ; long D = N % ( A + B ) ; if ( A == 0 ) { System . out . println ( 0 ) ; } else if ( D <= A ) { long D = N % ( A + B ) ; System . out . println ( C * A + D ) ; } else if ( D > A ) { System . out . println ( C * A + A ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner stdin = new Scanner ( System . in ) ; while ( true ) { int x = stdin . nextInt ( ) ; int y = stdin . nextInt ( ) ; if ( x == 0 && y == 0 ) { break ; } else if ( x > y ) { int y = stdin . nextInt ( ) ; System . out . printf ( " %d %d%n " , y , x ) ; } else { System . out . printf ( " %d %d%n " , x , y ) ; } } } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int A = sc . nextInt ( ) ; int B = sc . nextInt ( ) ; int C = sc . nextInt ( ) ; int X = sc . nextInt ( ) ; int count = 0 ; for ( int ca = 0 ; ca < A + 1 ; ++ ca ) { for ( int cb = 0 ; cb < B + 1 ; ++ cb ) { int cc = 0 ; for ( int cc = 0 ; cc < C + 1 ; ++ cc ) { if ( ( ca * 500 + cb * 100 + cc * 50 ) == X ) { ++ count ; } } } } System . out . println ( count ) ; } } +import java . io . * ; public class Main { public static void main ( String [ ] args ) throws IOException { long X = 0 ; int i = 0 ; long n = 100 ; double k = 0 ; BufferedReader r = new BufferedReader ( new InputStreamReader ( System . in ) ) ; X = Long . parseLong ( r . readLine ( ) ) ; do { double k = 0 ; i ++ ; k = Math . ceil ( ( double ) ( n / 100 ) ) ; n += ( long ) k ; } while ( n < X ) ; System . out . println ( i ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int H = 0 ; int W = 0 ; boolean flg = true ; while ( true ) { H = sc . nextInt ( ) ; W = sc . nextInt ( ) ; if ( H == 0 && W == 0 ) { break ; } for ( int i = 1 ; i <= H ; i ++ ) { if ( i % 2 == 0 ) { flg = false ; } else { int i = 1 ; flg = true ; } for ( int j = 1 ; j <= W ; j ++ ) { if ( flg == true ) { System . out . print ( " # " ) ; flg = false ; } else { System . out . print ( " . " ) ; flg = true ; } } System . out . println ( ) ; } System . out . println ( ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner scn = new Scanner ( System . in ) ; int x = scn . nextInt ( ) ; int n = scn . nextInt ( ) ; String [ ] p = new String [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { p [ i ] = scn . next ( ) ; } for ( int j = 0 ; j <= 51 ; j ++ ) { int j = 0 ; int min = x - j ; int max = x + j ; String mi = String . valueOf ( min ) ; String ma = String . valueOf ( max ) ; if ( ! Arrays . asList ( p ) . contains ( mi ) ) { System . out . println ( x - j ) ; return ; } if ( ! Arrays . asList ( p ) . contains ( ma ) ) { System . out . println ( x + j ) ; return ; } } scn . close ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int X = sc . nextInt ( ) ; int N = sc . nextInt ( ) ; int [ ] p = new int [ N ] ; int a = X ; int ans1 = X ; int ans2 = X ; int s = 0 ; for ( int i = 0 ; i < N ; i ++ ) { p [ i ] = sc . nextInt ( ) ; } for ( int i = 0 ; i < N + 1 ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) { if ( p [ j ] != X ) { s ++ ; } } if ( s == N ) { ans1 = X ; break ; } s = 0 ; X = X - 1 ; } X = a ; s = 0 ; for ( int i = 0 ; i < N + 1 ; i ++ ) { int j = 0 ; for ( int j = 0 ; j < N ; j ++ ) { if ( p [ j ] != X ) { s ++ ; } } if ( s == N ) { ans2 = X ; break ; } s = 0 ; X = X + 1 ; } X = a - ans1 ; N = ans2 - a ; if ( X <= N ) { System . out . println ( ans1 ) ; } else { System . out . println ( ans2 ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; String S = sc . next ( ) ; String [ ] str = { " MON " , " TUE " , " WED " , " THU " , " FRI " , " SAT " , " SUN " } ; for ( int i = 0 ; i < str . length ; i ++ ) { if ( str [ i ] . equals ( S ) ) { if ( i == 6 ) { System . out . println ( 7 ) ; } else { System . out . println ( 7 - ( i + 1 ) ) ; } } } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] h = new int [ n ] ; int viewableCnt = 0 ; for ( int i = 0 ; i < n ; i ++ ) { h [ i ] = sc . nextInt ( ) ; for ( int j = ( i - 1 ) ; j >= 0 ; j -- ) { if ( h [ i ] < h [ j ] ) { break ; } else if ( j == 0 ) { int j = ( i - 1 ) ; viewableCnt ++ ; } } } System . out . println ( viewableCnt + 1 ) ; sc . close ( ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner stdIn = new Scanner ( System . in ) ; int n = Integer . parseInt ( stdIn . next ( ) ) ; String s = stdIn . next ( ) ; int count = 0 ; int i = 0 ; while ( i < n - 2 ) { if ( s . charAt ( i ) == 'A' ) { if ( s . charAt ( i + 1 ) == 'B' ) { if ( s . charAt ( i + 2 ) == 'C' ) { int i = 0 ; count ++ ; } } } i ++ ; } System . out . println ( count ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { int x1 = x ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int x = sc . nextInt ( ) ; int t = sc . nextInt ( ) ; int time = t ; int x1 = x ; while ( x < n ) { t = t + time ; x = x + x1 ; } System . out . println ( t ) ; sc . close ( ) ; } } +import java . util . Scanner ; public class Main { private static Scanner scan ; public static void main ( String [ ] args ) { scan = new Scanner ( System . in ) ; String str = scan . next ( ) ; int l = str . length ( ) ; String rts = " " ; for ( int i = l - 1 ; i >= 0 ; i -- ) { int i = l - 1 ; rts = rts + str . charAt ( i ) ; } System . out . println ( rts ) ; System . exit ( 0 ) ; } } +import java . util . * ; import java . io . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; sc . nextLine ( ) ; String s = sc . nextLine ( ) ; int diff = 1 ; char prev = s . charAt ( 0 ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( s . charAt ( i ) != prev ) { int i = 0 ; diff ++ ; } prev = s . charAt ( i ) ; } System . out . println ( diff ) ; } } +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 te = - 1 ; for ( int i = 0 ; i < 10000 ; i ++ ) { if ( ( int ) ( i * 0.08 ) == a && ( int ) ( i * 0.1 ) == b ) { int i = 0 ; te = i ; break ; } } System . out . print ( te ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int k = sc . nextInt ( ) ; int x = sc . nextInt ( ) ; for ( int i = x - k + 1 ; i <= x + k - 1 ; i ++ ) { int i = x - k + 1 ; System . out . print ( i ) ; if ( i < x + k - 1 ) { System . out . print ( " " ) ; } else { System . out . println ( " " ) ; } } } } +import java . util . HashMap ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; Result result = execute ( sc . nextLine ( ) ) ; System . out . println ( result ) ; } public static Result execute ( String str ) { if ( ! isPalindrone ( str ) ) { return Result . No ; } int length = str . length ( ) ; String firstHalf = str . substring ( 0 , ( length - 1 ) / 2 ) ; if ( ! isPalindrone ( firstHalf ) ) { int i = 0 ; return Result . No ; } String lastHalf = str . substring ( ( length + 1 ) / 2 ) ; if ( ! isPalindrone ( lastHalf ) ) { return Result . No ; } return Result . Yes ; } private static boolean isPalindrone ( String str ) { int length = str . length ( ) ; if ( length == 1 ) { return true ; } for ( int i = 0 ; i < ( length + 1 ) / 2 ; i ++ ) { if ( str . charAt ( i ) != str . charAt ( length - i - 1 ) ) { return false ; } } return true ; } public static enum Result { Yes , No } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int K = sc . nextInt ( ) ; int sum = 0 ; for ( int i = 1 ; i <= K ; i ++ ) { for ( int j = 1 ; j <= K ; j ++ ) { int a = i ; int b = j ; int kou = 0 ; for ( int x = 0 ; x < 10 ; x ++ ) { int max = Math . max ( a , b ) ; int min = Math . min ( a , b ) ; if ( max % min == 0 && x == 0 ) { kou = min ; break ; } a = min ; b = max % min ; if ( a % b == 0 ) { kou = b ; break ; } } for ( int k = 1 ; k <= K ; k ++ ) { int min = Math . min ( c , d ) ; int c = k ; int d = kou ; for ( int x = 0 ; x < 10 ; x ++ ) { int max = Math . max ( c , d ) ; int min = Math . min ( c , d ) ; if ( max % min == 0 && x == 0 ) { d = min ; sum += d ; break ; } c = min ; d = max % min ; if ( c % d == 0 ) { sum += d ; break ; } } } } } System . out . println ( sum ) ; } } +import java . util . * ; public class Main { private static final int INF = Integer . MAX_VALUE ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String str = sc . next ( ) ; String [ ] strArray = str . split ( " " ) ; List < String > list = new ArrayList < > ( ) ; for ( int tmp = 0 ; tmp < strArray . length ; tmp ++ ) { list . add ( strArray [ tmp ] ) ; } boolean flagfirst = false ; String a = list . get ( 0 ) ; for ( int tmp = 1 ; tmp < list . size ( ) ; tmp ++ ) { boolean secondflag = false ; if ( list . get ( tmp ) . equals ( list . get ( 0 ) ) ) { list . remove ( tmp ) ; list . remove ( 0 ) ; flagfirst = true ; } } boolean secondflag = false ; if ( list . size ( ) == 2 ) { if ( list . get ( 0 ) . equals ( list . get ( 1 ) ) ) { secondflag = true ; } } if ( a . equals ( list . get ( 0 ) ) ) secondflag = false ; if ( flagfirst && secondflag ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] array = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { array [ i ] = sc . nextInt ( ) ; } int buff = 0 ; int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( array [ i ] == buff + 1 ) { buff = array [ i ] ; } else { count ++ ; } } if ( buff == 0 ) { System . out . println ( - 1 ) ; } else { System . out . println ( count ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int num = sc . nextInt ( ) ; int [ ] array = new int [ num ] ; int [ ] array_min = new int [ num ] ; int min = num + 1 ; for ( int i = 0 ; i < num ; i ++ ) { array [ i ] = sc . nextInt ( ) ; if ( min > array [ i ] ) { int i = 0 ; min = array [ i ] ; } array_min [ i ] = min ; } int count = 0 ; for ( int i = 0 ; i < num ; i ++ ) { if ( array_min [ i ] >= array [ i ] ) { count ++ ; } } System . out . println ( count ) ; } } +import java . lang . reflect . Array ; import java . util . ArrayList ; import java . util . List ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int c ; Scanner sc = new java . util . Scanner ( System . in ) ; int alice = 0 ; int bob = 0 ; int N = Integer . parseInt ( sc . nextLine ( ) ) ; String [ ] sCards = sc . nextLine ( ) . split ( " " ) ; List < Integer > iCards = new ArrayList < > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { iCards . add ( Integer . parseInt ( sCards [ i ] ) ) ; } for ( int n = 0 ; n < N ; n ++ ) { int max = 0 ; for ( int c : iCards ) { max = Math . max ( max , c ) ; } if ( n == 0 || n % 2 == 0 ) { alice += max ; } else { bob += max ; } iCards . remove ( iCards . indexOf ( max ) ) ; } System . out . println ( alice - bob ) ; } } +import java . util . * ; import java . util . ArrayList ; import java . util . List ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; List < Double > list = new ArrayList < > ( ) ; Double n = sc . nextDouble ( ) ; for ( int i = 0 ; i < n ; i ++ ) { List < Double > list = new ArrayList < > ( ) ; list . add ( sc . nextDouble ( ) ) ; } Collections . sort ( list ) ; System . out . println ( ( int ) ( list . get ( list . size ( ) - 1 ) - list . get ( 0 ) ) ) ; return ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String S = sc . next ( ) ; int l = S . length ( ) ; String a = " AC " ; int b = 0 ; int sum = 0 ; int [ ] x = new int [ l + 1 ] ; if ( S . charAt ( 0 ) != a . charAt ( 0 ) ) { System . out . println ( " WA " ) ; } else { for ( int i = 2 ; i <= l - 2 ; i ++ ) { int i = 0 ; if ( S . charAt ( i ) == a . charAt ( 1 ) ) { break ; } if ( i == l - 2 ) { System . out . println ( " WA " ) ; b = l - 2 ; } } if ( b != l - 2 ) { String US = S . toUpperCase ( ) ; for ( int i = 0 ; i < l ; i ++ ) { if ( S . charAt ( i ) == US . charAt ( i ) ) { sum += 1 ; x [ sum ] = i ; } } if ( sum == 2 && S . charAt ( x [ 1 ] ) == a . charAt ( 0 ) && S . charAt ( x [ 2 ] ) == a . charAt ( 1 ) ) { System . out . println ( " AC " ) ; } else if ( sum > 2 ) { System . out . println ( " WA " ) ; } } } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int l = sc . nextInt ( ) ; ArrayList < String > list = new ArrayList < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { String s ; list . add ( sc . next ( ) ) ; } Collections . sort ( list ) ; String output = " " ; for ( String s : list ) { output = output + s ; } System . out . println ( output ) ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; char [ ] a = sc . next ( ) . toCharArray ( ) ; int ans = 0 ; for ( int i = 0 ; i < 3 ; i ++ ) { if ( a [ i ] == '1' ) { ans += 1 ; } } System . out . print ( ans ) ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int sho = 0 ; int amrS = 0 ; int ans = 0 ; for ( int i = 1 ; i < n + 1 ; i ++ ) { sho = i ; amrS = 0 ; while ( sho != 0 ) { int i = 1 ; amrS += sho % 10 ; sho /= 10 ; } if ( amrS >= a && amrS <= b ) { ans += i ; } } System . out . println ( ans ) ; } } +import java . util . Scanner ; import java . util . Arrays ; class Main { public static void main ( String [ ] args ) { int [ ] m = new int [ 10 ] ; input ( m , 10 ) ; Arrays . sort ( m ) ; reverse ( m ) ; output ( m , 3 ) ; } private static final void reverse ( int [ ] m ) { int n = m . length ; for ( int i = 0 ; i < n / 2 ; i ++ ) { int tmp = m [ i ] ; m [ i ] = m [ n - i - 1 ] ; m [ n - i - 1 ] = tmp ; } } private static final void output ( int [ ] m , int n ) { for ( int i = 0 ; i < n ; i ++ ) { System . out . println ( m [ i ] ) ; } } private static final void input ( int [ ] m , int n ) { Scanner cin = new Scanner ( System . in ) ; for ( int i = 0 ; i < n ; i ++ ) { int i = 0 ; m [ i ] = cin . nextInt ( ) ; } } } +import java . util . * ; public class Main { Scanner sc ; public static void main ( String [ ] args ) { new Main ( ) . execute ( ) ; } public void execute ( ) { this . sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int cnt = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int d0 = sc . nextInt ( ) ; int d1 = sc . nextInt ( ) ; if ( d0 == d1 ) { cnt ++ ; if ( cnt >= 3 ) { System . out . println ( " Yes " ) ; return ; } } else { int cnt = 0 ; cnt = 0 ; } } System . out . println ( " No " ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int a ; Scanner sc = new Scanner ( System . in ) ; a = sc . nextInt ( ) ; int c = 0 ; int [ ] b = new int [ a ] ; for ( int i = 0 ; i < a ; i ++ ) { b [ i ] = sc . nextInt ( ) ; } Arrays . sort ( b ) ; for ( int j = 0 ; j < a - 1 ; j ++ ) { if ( b [ j ] == b [ j + 1 ] ) { c = c + 1 ; } } if ( c > 0 ) { System . out . println ( " NO " ) ; } else { int j = 0 ; System . out . println ( " YES " ) ; } } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int [ ] t = new int [ N + 1 ] ; t [ 0 ] = 0 ; int [ ] x = new int [ N + 1 ] ; x [ 0 ] = 0 ; int [ ] y = new int [ N + 1 ] ; x [ 0 ] = 0 ; for ( int i = 1 ; i <= N ; i ++ ) { int i = 0 ; t [ i ] = sc . nextInt ( ) ; x [ i ] = sc . nextInt ( ) ; y [ i ] = sc . nextInt ( ) ; } for ( int i = 0 ; i < N ; i ++ ) { int abs_t = t [ i + 1 ] - t [ i ] ; int abs_x = Math . abs ( x [ i + 1 ] - x [ i ] ) ; int abs_y = Math . abs ( y [ i + 1 ] - y [ i ] ) ; if ( abs_t < abs_x + abs_y || abs_t % 2 != ( abs_x + abs_y ) % 2 ) { System . out . println ( " No " ) ; System . exit ( 0 ) ; } } System . out . println ( " Yes " ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; while ( true ) { int count = sc . nextInt ( ) ; if ( count == 0 ) { break ; } double [ ] s = new double [ count ] ; double sum = 0 ; for ( int i = 0 ; i < count ; i ++ ) { int i = 0 ; s [ i ] = sc . nextDouble ( ) ; sum += s [ i ] ; } double average = sum / count ; double res = 0 ; for ( int i = 0 ; i < count ; i ++ ) { res += Math . pow ( s [ i ] - average , 2 ) / count ; } System . out . println ( Math . sqrt ( res ) ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws Exception { int j2 = 2 ; Scanner sc = new Scanner ( System . in ) ; int x = sc . nextInt ( ) ; sc . close ( ) ; for ( int i = x ; i >= 1 ; i -- ) { for ( int j = 1 ; j < 32 ; j ++ ) { for ( int j2 = 2 ; j2 < 10 ; j2 ++ ) { int a = ( int ) Math . pow ( j , j2 ) ; if ( a == i ) { System . out . println ( i ) ; return ; } } } } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int m = sc . nextInt ( ) ; int c = sc . nextInt ( ) ; int [ ] b = new int [ m ] ; for ( int i = 0 ; i < b . length ; i ++ ) { b [ i ] = sc . nextInt ( ) ; } int [ ] [ ] a = new int [ n ] [ m ] ; for ( int i = 0 ; i < a . length ; i ++ ) { for ( int j = 0 ; j < a [ i ] . length ; j ++ ) { a [ i ] [ j ] = sc . nextInt ( ) ; } } int counter = 0 ; for ( int i = 0 ; i < a . length ; i ++ ) { int sum = c ; for ( int j = 0 ; j < a [ i ] . length ; j ++ ) { int j = 0 ; sum += a [ i ] [ j ] * b [ j ] ; } if ( sum > 0 ) { counter ++ ; } } System . out . println ( counter ) ; sc . close ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; while ( true ) { Scanner scan = new Scanner ( System . in ) ; String str = scan . nextLine ( ) ; if ( str . equals ( " 0 " ) ) break ; int sum = 0 ; char [ ] box = str . toCharArray ( ) ; for ( int i = 0 ; i < box . length ; i ++ ) sum += box [ i ] - '0' ; System . out . println ( sum ) ; } } } +import java . util . * ; import java . io . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int x = sc . nextInt ( ) ; int [ ] l = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) l [ i ] = sc . nextInt ( ) ; int point = 0 , cnt = 1 ; for ( int i = 0 ; i < n ; i ++ ) { int i = 0 ; point += l [ i ] ; if ( point <= x ) cnt ++ ; else break ; } System . out . println ( cnt ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] a = new int [ n ] ; int j = 1 ; for ( int i = 0 ; i < n ; i ++ ) { int i = 0 ; a [ i ] = sc . nextInt ( ) ; if ( j == a [ i ] ) { j ++ ; } } if ( j == 1 ) { System . out . println ( - 1 ) ; return ; } System . out . println ( n - j + 1 ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) { try { String now = " a " ; InputStreamReader isr = new InputStreamReader ( System . in ) ; BufferedReader br = new BufferedReader ( isr ) ; String a = br . readLine ( ) ; int aCount = 0 ; String b = br . readLine ( ) ; int bCount = 0 ; String c = br . readLine ( ) ; int cCount = 0 ; ; String now = " a " ; while ( true ) { if ( " a " . equals ( now ) ) { if ( aCount >= a . length ( ) ) { System . out . println ( " A " ) ; break ; } now = a . substring ( aCount , aCount + 1 ) ; aCount ++ ; } else if ( " b " . equals ( now ) ) { if ( bCount >= b . length ( ) ) { System . out . println ( " B " ) ; break ; } now = b . substring ( bCount , bCount + 1 ) ; bCount ++ ; } else if ( " c " . equals ( now ) ) { if ( cCount >= c . length ( ) ) { System . out . println ( " C " ) ; break ; } now = c . substring ( cCount , cCount + 1 ) ; cCount ++ ; } } } catch ( IOException e ) { e . printStackTrace ( ) ; } } } +import java . util . * ; import java . io . * ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int K = sc . nextInt ( ) ; int Q = sc . nextInt ( ) ; int [ ] A = new int [ N ] ; for ( int i = 0 ; i < Q ; i ++ ) { int i_ = sc . nextInt ( ) ; A [ i_ - 1 ] ++ ; } sc . close ( ) ; PrintWriter out = new PrintWriter ( System . out ) ; for ( int i = 0 ; i < N ; i ++ ) { if ( 0 < A [ i ] + K - Q ) { out . println ( " Yes " ) ; } else { out . println ( " No " ) ; } } out . flush ( ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; while ( in . hasNext ( ) ) { int n = in . nextInt ( ) ; if ( n == 0 ) break ; int [ ] numbers = new int [ n ] ; long double_sum = 0 ; long sum_double = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int i = 0 ; numbers [ i ] = in . nextInt ( ) ; double_sum += numbers [ i ] ; } double_sum = double_sum * double_sum ; for ( int i = 0 ; i < n ; i ++ ) sum_double += ( numbers [ i ] * numbers [ i ] ) ; double sd = Math . sqrt ( ( sum_double - double_sum / ( double ) n ) / ( double ) n ) ; System . out . printf ( " %5.8f " , sd ) ; System . out . println ( ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] v = new int [ n ] ; int sum = 0 ; for ( int i = 0 ; i < n ; ++ i ) { int i = 0 ; v [ i ] = sc . nextInt ( ) ; } for ( int i = 0 ; i < n ; ++ i ) { int c = sc . nextInt ( ) ; sum = ( v [ i ] > c ) ? sum + v [ i ] - c : sum ; } System . out . println ( sum ) ; } } +import java . io . * ; import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; Question question = new Question ( ) ; question . solve ( sc ) ; } static class Question { public void solve ( Scanner sc ) { int i = 0 ; int len = sc . nextInt ( ) ; int n = sc . nextInt ( ) ; int [ ] distances = new int [ n ] ; for ( int i = 0 ; i < n ; ++ i ) { distances [ i ] = sc . nextInt ( ) ; } int m = 0 ; for ( int i = 0 ; i < n ; ++ i ) { int t = ( i + 1 ) % n ; int dist = distances [ t ] - distances [ i ] ; m = Math . max ( m , Math . min ( Math . abs ( dist ) , len - Math . abs ( dist ) ) ) ; } System . out . println ( len - m ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; String [ ] tmp = scanner . nextLine ( ) . split ( " " ) ; int ans = 0 ; for ( int i = 0 ; i < 5 ; i ++ ) { if ( Integer . parseInt ( tmp [ i ] ) == 0 ) { int i = 0 ; ans = i + 1 ; break ; } } System . out . println ( ans ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int y = sc . nextInt ( ) ; int x = y / 1000 - n ; int coefficient1 = 9 ; int coefficient2 = 4 ; int [ ] result = { - 1 , - 1 , - 1 } ; for ( int i = 0 ; i <= n ; i ++ ) { int tmp = x - ( 9 * i ) ; int [ ] tmp2 = new int [ 3 ] ; if ( tmp % 4 == 0 && tmp >= 0 && tmp <= 4 * n ) { int [ ] tmp2 = new int [ 3 ] ; tmp2 [ 0 ] = i ; tmp2 [ 1 ] = tmp / 4 ; tmp2 [ 2 ] = n - tmp2 [ 0 ] - tmp2 [ 1 ] ; if ( tmp2 [ 2 ] >= 0 && tmp2 [ 2 ] <= n ) { result = tmp2 ; break ; } } } System . out . println ( result [ 0 ] + " " + result [ 1 ] + " " + result [ 2 ] ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int roundUpNum = 1000 ; @ SuppressWarnings ( " resource " ) Scanner sc = new Scanner ( System . in ) ; int weekNum = sc . nextInt ( ) ; int debt = 100000 ; int roundUpNum = 1000 ; for ( int i = 0 ; i < weekNum ; i ++ ) { debt *= 1.05 ; debt = ( int ) Math . ceil ( ( double ) debt / roundUpNum ) * roundUpNum ; } System . out . println ( debt ) ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { int i = 0 ; try ( Scanner sc = new Scanner ( System . in ) ) { String S = sc . nextLine ( ) ; for ( int i = 0 ; i < S . length ( ) ; i ++ ) { if ( Character . isUpperCase ( S . charAt ( i ) ) ) { System . out . print ( Character . toLowerCase ( S . charAt ( i ) ) ) ; } else { System . out . print ( Character . toUpperCase ( S . charAt ( i ) ) ) ; } } System . out . println ( " " ) ; } } } +import java . util . ArrayList ; import java . util . List ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; final int N = sc . nextInt ( ) ; sc . nextLine ( ) ; final List < Integer > ls = new ArrayList < > ( ) ; int max = - 1 ; int maxId = - 1 ; for ( int i = 0 ; i < N ; i ++ ) { final int l = sc . nextInt ( ) ; ls . add ( l ) ; if ( l > max ) { int i = 0 ; max = l ; maxId = i ; } } int sum = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( i == maxId ) { continue ; } sum += ls . get ( i ) ; } if ( max < sum ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } } +import java . util . * ; import java . io . * ; import java . awt . * ; import java . awt . geom . * ; import static java . lang . System . * ; import static java . lang . Math . * ; public class Main { static Scanner sc = new Scanner ( in ) ; public static void main ( String [ ] args ) { int n = sc . nextInt ( ) ; int [ ] d = new int [ n ] ; int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int i = 0 ; d [ i ] = sc . nextInt ( ) ; } Arrays . sort ( d ) ; ans = max ( 0 , d [ n / 2 ] - d [ n / 2 - 1 ] ) ; out . println ( ans ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; if ( scanner . hasNextLine ( ) ) { String [ ] array = scanner . nextLine ( ) . split ( " " ) ; long a = Integer . parseInt ( array [ 0 ] ) ; long b = Integer . parseInt ( array [ 1 ] ) ; long c = Integer . parseInt ( array [ 2 ] ) ; int k = Integer . parseInt ( scanner . nextLine ( ) ) ; if ( a > b && a > c ) { for ( int i = 0 ; i < k ; ++ i ) { a *= 2 ; } } else if ( b > c ) { for ( int i = 0 ; i < k ; ++ i ) { b *= 2 ; } } else { int i = 0 ; for ( int i = 0 ; i < k ; ++ i ) { c *= 2 ; } } System . out . println ( a + b + c ) ; } } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . StringTokenizer ; public class Main { static class FastReader { BufferedReader br ; StringTokenizer st ; public FastReader ( ) { br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; } String next ( ) { while ( st == null || ! st . hasMoreElements ( ) ) { try { st = new StringTokenizer ( br . readLine ( ) ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } return st . nextToken ( ) ; } int nextInt ( ) { String str = " " ; 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 ; } } public static void main ( String [ ] args ) { FastReader obj = new FastReader ( ) ; String s1 = obj . next ( ) , s2 = obj . next ( ) ; int sn1 = obj . nextInt ( ) , sn2 = obj . nextInt ( ) ; String t = obj . next ( ) ; if ( t . equals ( s1 ) ) sn1 -- ; else sn2 -- ; System . out . println ( sn1 + " " + sn2 ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) , f = 1 ; int [ ] a = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { int i = 0 ; a [ i ] = sc . nextInt ( ) ; if ( a [ i ] % 2 == 0 ) { if ( a [ i ] % 3 == 0 || a [ i ] % 5 == 0 ) { } else { f = 0 ; break ; } } } if ( f == 0 ) { System . out . print ( " DENIED " ) ; } else { System . out . print ( " APPROVED " ) ; } } } +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 c = sc . nextInt ( ) ; int divisor = 0 ; for ( int i = 0 ; i <= ( b - a ) ; i ++ ) { if ( c % ( a + i ) == 0 ) { int i = 0 ; divisor += 1 ; } } System . out . println ( divisor ) ; sc . close ( ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . PrintWriter ; import java . util . StringTokenizer ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new java . io . InputStreamReader ( System . in ) ) ; PrintWriter pw = new PrintWriter ( System . out ) ; StringTokenizer st = new StringTokenizer ( br . readLine ( ) ) ; int x = Integer . parseInt ( st . nextToken ( ) ) ; if ( x == 0 ) { pw . println ( 1 ) ; } else { PrintWriter pw = new PrintWriter ( System . out ) ; pw . println ( 0 ) ; } br . close ( ) ; pw . close ( ) ; } } +import java . util . ArrayList ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { boolean flag = true ; Scanner sc = new Scanner ( System . in ) ; ArrayList < String > slist = new ArrayList < String > ( ) ; String beforeWord = null ; String word = null ; boolean flag = true ; int size = sc . nextInt ( ) ; if ( size > 100 ) { flag = false ; System . out . println ( " No " ) ; return ; } word = sc . nextLine ( ) ; for ( int i = 0 ; i < size ; i ++ ) { word = sc . nextLine ( ) ; if ( beforeWord != null ) { char shiri = beforeWord . charAt ( beforeWord . length ( ) - 1 ) ; char atama = word . charAt ( 0 ) ; if ( shiri == atama ) { flag = true ; } else { flag = false ; break ; } } if ( ! slist . contains ( word ) ) { if ( flag ) { slist . add ( word ) ; beforeWord = word ; } } else { flag = false ; break ; } } if ( flag ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int preTime = 0 ; Scanner sc = new Scanner ( System . in ) ; int moveCount = Integer . parseInt ( sc . nextLine ( ) ) ; boolean okFlag = true ; int prePosX = 0 ; int prePosY = 0 ; int preTime = 0 ; for ( int i = 1 ; i <= moveCount ; i ++ ) { String [ ] line = sc . nextLine ( ) . split ( " " ) ; int time = Integer . parseInt ( line [ 0 ] ) ; int posX = Integer . parseInt ( line [ 1 ] ) ; int posY = Integer . parseInt ( line [ 2 ] ) ; int disX = Math . abs ( posX - prePosX ) ; int disY = Math . abs ( posY - prePosY ) ; int disTime = Math . abs ( time - preTime ) ; if ( disTime < ( disX + disY ) ) { okFlag = false ; break ; } if ( disTime % 2 != ( disX + disY ) % 2 ) { okFlag = false ; break ; } prePosX = posX ; prePosY = posY ; preTime = time ; } if ( okFlag ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; String input = scanner . nextLine ( ) ; String [ ] inputs = input . split ( " " ) ; int n = Integer . parseInt ( inputs [ 0 ] ) ; int x = Integer . parseInt ( inputs [ 1 ] ) ; String lineStr = scanner . nextLine ( ) ; String [ ] lines = lineStr . split ( " " ) ; int [ ] line = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { int i = 0 ; line [ i ] = Integer . parseInt ( lines [ i ] ) ; } int answer = 1 ; int distance = 0 ; for ( int i = 0 ; i < n ; i ++ ) { distance = distance + line [ i ] ; if ( distance > x ) { break ; } answer ++ ; } System . out . println ( answer ) ; scanner . close ( ) ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { new Solver ( ) . run ( ) ; } } class Solver { public void run ( ) { Scanner sc = new Scanner ( System . in ) ; int A = sc . nextInt ( ) ; int B = sc . nextInt ( ) ; int cnt = 0 ; for ( int i = A ; i <= B ; i ++ ) { int j = 0 ; char [ ] s = new StringBuilder ( ) . append ( i ) . toString ( ) . toCharArray ( ) ; boolean ok = true ; for ( int j = 0 ; j < 5 / 2 ; j ++ ) { if ( s [ j ] != s [ 4 - j ] ) { ok = false ; break ; } } if ( ok ) cnt ++ ; } System . out . println ( cnt ) ; return ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; String S = sc . next ( ) ; int Length = S . length ( ) ; char [ ] tmp ; tmp = new char [ Length ] ; for ( int i = 0 ; i < Length ; i ++ ) { tmp [ i ] = 'x' ; } System . out . println ( tmp ) ; } } +import java . io . BufferedReader ; import java . io . InputStreamReader ; class Main { static BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; static String S , T ; static int result = 0 ; public static void main ( String [ ] args ) throws Exception { int i = 0 ; S = br . readLine ( ) ; T = br . readLine ( ) ; for ( int i = 0 ; i < S . length ( ) ; i ++ ) { char s = S . charAt ( i ) ; char t = T . charAt ( i ) ; if ( s != t ) { result ++ ; } } System . out . println ( result ) ; } } +import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . io . PrintWriter ; import java . util . StringTokenizer ; public class Main { public static void main ( String [ ] args ) throws Exception { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; StringTokenizer st ; PrintWriter pw = new PrintWriter ( System . out ) ; int n = Integer . parseInt ( br . readLine ( ) ) ; st = new StringTokenizer ( br . readLine ( ) ) ; char [ ] c1 = st . nextToken ( ) . toCharArray ( ) ; char [ ] c2 = st . nextToken ( ) . toCharArray ( ) ; for ( int i = 0 ; i < n ; i ++ ) { int i = 0 ; pw . print ( c1 [ i ] ) ; pw . print ( c2 [ i ] ) ; } pw . flush ( ) ; pw . close ( ) ; } } +import java . io . IOException ; import java . io . BufferedReader ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws IOException { int j = 0 ; try ( BufferedReader reader = new BufferedReader ( new InputStreamReader ( System . in ) ) ) { final String s = reader . readLine ( ) ; int N = Integer . parseInt ( s ) ; boolean flg = false ; for ( int i = 0 ; i <= N ; i ++ ) { for ( int j = 0 ; j <= N ; j ++ ) { if ( N == 4 * i + 7 * j ) { flg = true ; break ; } } } System . out . println ( flg ? " Yes " : " No " ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int jdg = n % 28 ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; String ans = " No " ; int jdg = n % 28 ; if ( jdg == 0 ) { ans = " Yes " ; } else { while ( jdg >= 3 ) { if ( jdg % 4 == 0 || jdg % 7 == 0 ) { ans = " Yes " ; break ; } else { jdg -= 7 ; } } } System . out . println ( ans ) ; sc . close ( ) ; } } +import java . io . BufferedReader ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws Exception { InputStreamReader is = new InputStreamReader ( System . in ) ; BufferedReader br = new BufferedReader ( is ) ; while ( true ) { int j = 0 ; String str = br . readLine ( ) ; String [ ] num = getElement ( str ) ; int h = Integer . parseInt ( num [ 0 ] ) ; int w = Integer . parseInt ( num [ 1 ] ) ; if ( h == 0 && w == 0 ) { break ; } for ( int i = 0 ; i < h ; i ++ ) { if ( i == 0 || i == h - 1 ) { for ( int j = 0 ; j < w ; j ++ ) { System . out . print ( " # " ) ; } } else { for ( int j = 0 ; j < w ; j ++ ) { if ( j == 0 || j == w - 1 ) { System . out . print ( " # " ) ; } else { System . out . print ( " . " ) ; } } } System . out . print ( " \r \n " ) ; } System . out . print ( " \r \n " ) ; } } public static String [ ] getElement ( String element ) { return ( element . split ( " " ) ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int a = 0 ; int tas = 0 ; ; int q ; int i ; int z ; int j = 0 ; int b = 0 ; String Bun = scan . nextLine ( ) ; String Miz = scan . nextLine ( ) ; Bun = Bun + Bun ; char [ ] bun = Bun . toCharArray ( ) ; char [ ] miz = Miz . toCharArray ( ) ; for ( q = 0 ; q < miz . length ; q ++ ) { char [ ] miz = Miz . toCharArray ( ) ; } for ( z = 0 ; z < bun . length ; z ++ ) { } int x = z - q ; for ( i = 0 ; i < x ; i ++ ) { if ( bun [ i ] == miz [ j ] ) { for ( j = 0 ; j <= q ; j ++ ) { if ( bun [ i + j ] != miz [ j ] ) { tas = 0 ; j = 0 ; break ; } tas ++ ; if ( tas == q ) { a = 1 ; b = 1 ; break ; } } } if ( b == 1 ) { break ; } } if ( a == 1 ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; String str = sc . next ( ) ; char [ ] c = str . toCharArray ( ) ; int count = 0 ; if ( N % 2 == 0 ) { for ( int i = 0 ; i < N / 2 ; i ++ ) { if ( c [ i ] == c [ N / 2 + i ] ) { int i = 0 ; count ++ ; } } if ( count == N / 2 ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } else { System . out . println ( " No " ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; while ( true ) { int m = sc . nextInt ( ) ; int f = sc . nextInt ( ) ; int r = sc . nextInt ( ) ; if ( m == - 1 && f == - 1 && r == - 1 ) { break ; } if ( m == - 1 || f == - 1 ) { System . out . println ( " F " ) ; } else { int S = m + f ; if ( S >= 80 ) { System . out . println ( " A " ) ; } else if ( S < 80 && S >= 65 ) { System . out . println ( " B " ) ; } else if ( S < 65 && S >= 50 ) { System . out . println ( " C " ) ; } else if ( S < 50 && S >= 30 ) { if ( r >= 50 ) { int r = sc . nextInt ( ) ; System . out . println ( " C " ) ; } else if ( r < 50 ) { System . out . println ( " D " ) ; } } else if ( S < 30 ) { System . out . println ( " F " ) ; } } } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; String answer = " Good " ; for ( int i = 0 ; i < 3 ; i ++ ) { if ( s . charAt ( i ) == s . charAt ( i + 1 ) ) { int i = 0 ; answer = " Bad " ; break ; } } System . out . println ( answer ) ; sc . close ( ) ; } } +import java . util . ArrayList ; import java . util . List ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int N = scanner . nextInt ( ) ; int M = scanner . nextInt ( ) ; scanner . nextLine ( ) ; List < Integer > alList = new ArrayList < > ( ) ; for ( int i = 1 ; i <= M ; i ++ ) { alList . add ( i ) ; } while ( scanner . hasNextLine ( ) ) { scanner . nextInt ( ) ; String string = scanner . nextLine ( ) ; String [ ] s = string . split ( " " ) ; List < String > kIntegers = new ArrayList < > ( ) ; for ( String k : s ) { kIntegers . add ( k ) ; } List < Integer > nothing = new ArrayList < > ( ) ; for ( int i = 1 ; i <= M ; i ++ ) { int i = 1 ; if ( ! kIntegers . contains ( String . valueOf ( i ) ) ) { nothing . add ( i ) ; } } alList . removeAll ( nothing ) ; } System . out . println ( alList . size ( ) ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int b = sca . nextInt ( ) ; Scanner sca = new Scanner ( System . in ) ; String s = sca . next ( ) ; String t = sca . next ( ) ; int a = sca . nextInt ( ) ; int b = sca . nextInt ( ) ; String u = sca . next ( ) ; if ( u . equals ( s ) ) { a -- ; } else { b -- ; } System . out . print ( a ) ; System . out . print ( " " ) ; System . out . println ( b ) ; sca . close ( ) ; } } +import java . util . * ; import java . util . ArrayList ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int N = scanner . nextInt ( ) ; Integer [ ] a = new Integer [ N ] ; boolean s = true ; int Alice = 0 ; int Bob = 0 ; for ( int i = 0 ; i < N ; i ++ ) { a [ i ] = scanner . nextInt ( ) ; } Arrays . sort ( a , Comparator . reverseOrder ( ) ) ; for ( int i = 0 ; i < N ; i ++ ) { if ( s ) { Alice += a [ i ] ; } else { int i = 0 ; Bob += a [ i ] ; } s = ! s ; } System . out . println ( Alice - Bob ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int H = sc . nextInt ( ) ; int N = sc . nextInt ( ) ; int [ ] A = new int [ N + 1 ] ; int total = 0 ; for ( int i = 1 ; i <= N ; i ++ ) { int i = 1 ; A [ i ] = sc . nextInt ( ) ; total += A [ i ] ; } if ( total >= H ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner s = null ; try { Scanner s = null ; s = new Scanner ( System . in ) ; String line = s . nextLine ( ) ; System . out . println ( powBy3 ( Integer . parseInt ( line ) ) ) ; } finally { if ( s != null ) { s . close ( ) ; } } } private static int powBy3 ( int i ) { return i * i * i ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { int i = 0 , j = 0 ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; String a = sc . next ( ) ; String b = sc . next ( ) ; StringBuilder sb = new StringBuilder ( " " ) ; for ( int i = 0 , j = 0 ; i < a . length ( ) && j < b . length ( ) ; i ++ , j ++ ) { sb . append ( ( char ) a . charAt ( i ) + " " ) . append ( ( char ) b . charAt ( j ) + " " ) ; } System . out . println ( sb ) ; } } +import java . util . * ; import java . lang . * ; import java . io . * ; public class Main { static int [ ] h ; static int [ ] dp ; public static void main ( String [ ] args ) throws java . lang . Exception { Scanner scan = new Scanner ( System . in ) ; int sz = scan . nextInt ( ) ; int k = scan . nextInt ( ) ; h = new int [ sz ] ; dp = new int [ sz ] ; for ( int i = 0 ; i < sz ; i ++ ) h [ i ] = scan . nextInt ( ) ; dp [ 0 ] = 0 ; dp [ 1 ] = Math . abs ( h [ 1 ] - h [ 0 ] ) ; for ( int i = 2 ; i < sz ; i ++ ) { int i = 2 ; int min = Integer . MAX_VALUE ; for ( int j = 1 ; i - j >= 0 && j <= k ; j ++ ) min = Math . min ( dp [ i - j ] + Math . abs ( h [ i ] - h [ i - j ] ) , min ) ; dp [ i ] = min ; } System . out . println ( dp [ sz - 1 ] ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int H = 0 ; int W = 0 ; while ( true ) { H = sc . nextInt ( ) ; W = sc . nextInt ( ) ; if ( H != 0 && W != 0 ) { for ( int i = 0 ; i < H ; i ++ ) { for ( int j = 0 ; j < W ; j ++ ) { int W = 0 ; System . out . print ( " # " ) ; } System . out . print ( " \n " ) ; } System . out . println ( " " ) ; } else { return ; } } } } +import java . util . * ; import static java . lang . System . * ; import static java . lang . Math . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( in ) ; String Sa = sc . next ( ) ; String Sb = sc . next ( ) ; String Sc = sc . next ( ) ; int a = Sa . length ( ) , b = Sb . length ( ) , c = Sc . length ( ) ; char p = Sa . charAt ( Sa . length ( ) - a ) ; a -- ; while ( true ) { switch ( p ) { case 'a' : if ( a == 0 ) { out . println ( " A " ) ; exit ( 0 ) ; } p = Sa . charAt ( Sa . length ( ) - a ) ; a -- ; break ; case 'b' : if ( b == 0 ) { char p = Sa . charAt ( Sa . length ( ) - a ) ; out . println ( " B " ) ; exit ( 0 ) ; } p = Sb . charAt ( Sb . length ( ) - b ) ; b -- ; break ; case 'c' : if ( c == 0 ) { out . println ( " C " ) ; exit ( 0 ) ; } p = Sc . charAt ( Sc . length ( ) - c ) ; c -- ; break ; } } } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws IOException { try ( BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ) { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String in = br . readLine ( ) ; System . out . println ( in . equals ( " Sunny " ) ? " Cloudy " : in . equals ( " Cloudy " ) ? " Rainy " : " Sunny " ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { String alphabet = " ABCDEFGHIJKLMNOPQRSTUVWXYZ " ; Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; String S = sc . next ( ) ; sc . close ( ) ; String ans = " " ; for ( int i = 0 ; i < S . length ( ) ; i ++ ) { for ( int j = 0 ; j < alphabet . length ( ) ; j ++ ) { if ( S . substring ( i , i + 1 ) . equals ( alphabet . substring ( j , j + 1 ) ) ) { int j = 0 ; ans += alphabet . substring ( ( j + N ) % alphabet . length ( ) , ( ( j + N ) % alphabet . length ( ) ) + 1 ) ; } } } System . out . println ( ans ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; while ( true ) { int H = Integer . parseInt ( sc . next ( ) ) ; int W = Integer . parseInt ( sc . next ( ) ) ; if ( H == 0 && W == 0 ) { break ; } for ( int i = 0 ; i < H ; i ++ ) { if ( i == 0 || i == H - 1 ) { for ( int j = 0 ; j < W ; j ++ ) { System . out . print ( " # " ) ; } System . out . print ( " \n " ) ; } else { int j = 0 ; System . out . print ( " # " ) ; for ( int j = 0 ; j < W - 2 ; j ++ ) { System . out . print ( " . " ) ; } System . out . print ( " # " ) ; System . out . print ( " \n " ) ; } } System . out . print ( " \n " ) ; } } } +import java . util . Scanner ; import java . util . List ; import java . util . ArrayList ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String a = sc . next ( ) ; String b = sc . next ( ) ; int ans = 10000 ; int loop = a . length ( ) - b . length ( ) + 1 ; if ( a . contains ( b ) ) { System . out . println ( 0 ) ; } else { for ( int i = 0 ; i < loop ; i ++ ) { int tmp = 0 ; String sub = a . substring ( i , i + b . length ( ) ) ; for ( int j = 0 ; j < sub . length ( ) ; j ++ ) { if ( sub . charAt ( j ) != b . charAt ( j ) ) { tmp ++ ; } } if ( ans > tmp ) { int j = 0 ; ans = tmp ; } } System . out . println ( ans ) ; } } } +import java . util . * ; import java . io . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int max = 0 ; int total = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int total = 0 ; int x = sc . nextInt ( ) ; total += x ; max = Math . max ( x , max ) ; } System . out . println ( max < total - max ? " Yes " : " No " ) ; } } +import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner std = new Scanner ( System . in ) ; int n = std . nextInt ( ) ; int k = std . nextInt ( ) ; int q = std . nextInt ( ) ; int [ ] as = new int [ q ] ; for ( int i = 0 ; i < q ; i ++ ) { as [ i ] = std . nextInt ( ) - 1 ; } int [ ] cp = new int [ n ] ; for ( int i = 0 ; i < q ; i ++ ) { int c = as [ i ] ; cp [ c ] ++ ; } int [ ] dp = new int [ n ] ; Arrays . fill ( dp , k ) ; long [ ] sum = new long [ n ] ; long all = Arrays . stream ( cp ) . sum ( ) ; for ( int i = 0 ; i < n ; i ++ ) { int i = 0 ; sum [ i ] = all - cp [ i ] ; } for ( int i = 0 ; i < n ; i ++ ) { if ( k > sum [ i ] ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } } } +import java . io . BufferedReader ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws Exception { boolean first = true ; try ( BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ) { String line ; while ( ( line = br . readLine ( ) ) != null ) { String [ ] str = line . split ( " " ) ; int x = Integer . parseInt ( str [ 0 ] ) ; int y = Integer . parseInt ( str [ 1 ] ) ; if ( x == 0 && y == 0 ) { int y = Integer . parseInt ( str [ 1 ] ) ; break ; } for ( int i = 0 ; i < x ; i ++ ) { for ( int j = 0 ; j < y ; j ++ ) { System . out . print ( " # " ) ; } System . out . println ( ) ; } System . out . println ( ) ; } } } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . math . BigInteger ; import java . util . * ; import java . util . stream . Collectors ; import java . util . stream . Stream ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner fr = new Scanner ( System . in ) ; int n = fr . nextInt ( ) ; int x = fr . nextInt ( ) ; int xx = x ; int t = fr . nextInt ( ) ; int tt = t ; if ( n < x ) { int tt = t ; System . out . println ( t ) ; } else { while ( x < n ) { x += xx ; t += tt ; } System . out . println ( t ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 2 ; Scanner sc = new Scanner ( System . in ) ; int n = Integer . parseInt ( sc . next ( ) ) ; String s = sc . next ( ) ; int result = 0 ; for ( int i = 2 ; i < n ; i ++ ) { result = s . charAt ( i ) == 'C' && s . charAt ( i - 1 ) == 'B' && s . charAt ( i - 2 ) == 'A' ? result + 1 : result ; } System . out . println ( result ) ; sc . close ( ) ; } } +import java . util . * ; import java . io . * ; class Main { static boolean found = false ; public static void main ( String [ ] args ) throws IOException { PrintWriter out = new PrintWriter ( System . out ) ; BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String s = br . readLine ( ) ; long sum = 0 ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { int i = 0 ; sum += Character . getNumericValue ( s . charAt ( i ) ) ; sum = sum % 9 ; } if ( sum % 9 == 0 ) { out . println ( " Yes " ) ; } else { out . println ( " No " ) ; } out . close ( ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner s = new Scanner ( System . in ) ; int N = s . nextInt ( ) ; int [ ] An = new int [ N ] ; int ans = 0 ; for ( int i = 0 ; i < N ; i ++ ) { An [ i ] = s . nextInt ( ) ; } Arrays . sort ( An ) ; ans = An [ N - 1 ] - An [ 0 ] ; System . out . print ( ans ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int M = sc . nextInt ( ) ; int LMax = 0 ; int RMin = N ; for ( int i = 0 ; i < M ; i ++ ) { int L = sc . nextInt ( ) ; int R = sc . nextInt ( ) ; LMax = L >= LMax ? L : LMax ; RMin = R <= RMin ? R : RMin ; } sc . close ( ) ; if ( LMax > RMin ) { int RMin = N ; System . out . println ( 0 ) ; } else { System . out . println ( RMin - LMax + 1 ) ; } } } +import java . io . * ; import java . util . * ; class Main { public static void main ( String [ ] args ) throws IOException { int n ; BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int count = 0 ; int n ; while ( true ) { count ++ ; n = Integer . parseInt ( br . readLine ( ) ) ; if ( n == 0 ) break ; System . out . println ( " Case " + count + " : " + n ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int j = 0 ; Scanner sc = new Scanner ( System . in ) ; int x = sc . nextInt ( ) ; int y = sc . nextInt ( ) ; int z = sc . nextInt ( ) ; int j = 0 ; while ( x <= y ) { if ( z % x == 0 ) { j ++ ; } x ++ ; } System . out . println ( j ) ; sc . close ( ) ; } } +import java . io . OutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . PrintWriter ; import java . util . StringTokenizer ; import java . io . IOException ; import java . util . InputMismatchException ; 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 ) ; TaskA solver = new TaskA ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class TaskA { public void solve ( int testNumber , InputReader in , PrintWriter out ) { String s = in . nextString ( ) ; out . println ( s . replaceAll ( " 1 " , " 2 " ) . replaceAll ( " 9 " , " 1 " ) . replaceAll ( " 2 " , " 9 " ) ) ; } } static class InputReader { private BufferedReader br ; private StringTokenizer st ; public InputReader ( InputStream inputStream ) { br = new BufferedReader ( new InputStreamReader ( inputStream ) ) ; st = new StringTokenizer ( " " ) ; } public String nextString ( ) { while ( ! st . hasMoreTokens ( ) ) { try { st = new StringTokenizer ( br . readLine ( ) , " " ) ; } catch ( IOException e ) { throw new InputMismatchException ( ) ; } } return st . nextToken ( ) ; } } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { int k = 0 ; int i = 0 ; int key = 0 ; int n = 0 ; Scanner sc = new Scanner ( System . in ) ; n = sc . nextInt ( ) ; int [ ] A = new int [ n ] ; for ( int k = 0 ; k < n ; k ++ ) { A [ k ] = sc . nextInt ( ) ; } for ( int j = 1 ; j < A . length ; j ++ ) { key = A [ j ] ; i = j - 1 ; for ( int k = 0 ; k < A . length - 1 ; k ++ ) { System . out . printf ( " %d " , A [ k ] ) ; } System . out . printf ( " %d \n " , A [ A . length - 1 ] ) ; while ( i >= 0 && A [ i ] > key ) { A [ i + 1 ] = A [ i ] ; i -- ; } A [ i + 1 ] = key ; } for ( int k = 0 ; k < A . length - 1 ; k ++ ) { System . out . printf ( " %d " , A [ k ] ) ; } System . out . printf ( " %d \n " , A [ A . length - 1 ] ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int X = sc . nextInt ( ) ; int a = 1 ; for ( int i = 2 ; i <= 32 ; i ++ ) { for ( int j = 2 ; j <= 10 ; j ++ ) { double b = Math . pow ( i , j ) ; if ( b <= X ) { double b = Math . pow ( i , j ) ; if ( X - a >= X - b ) { a = ( int ) b ; } } else { break ; } } } if ( X < 4 ) { System . out . println ( X ) ; } else { System . out . println ( a ) ; } } } +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 c = sc . nextInt ( ) ; int d = sc . nextInt ( ) ; while ( 0 < c && 0 < a ) { int d = sc . nextInt ( ) ; c -= b ; if ( c <= 0 ) { break ; } a -= d ; } if ( 0 < a ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } sc . close ( ) ; } } +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 res ; if ( a <= 5 ) { res = 0 ; } else if ( a <= 12 ) { res = b / 2 ; } else { int res ; res = b ; } System . out . println ( res ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; char [ ] [ ] s = new char [ n ] [ 10 ] ; HashMap < String , Long > h = new HashMap < > ( ) ; long ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { String st = String . valueOf ( s [ i ] ) ; s [ i ] = sc . next ( ) . toCharArray ( ) ; Arrays . parallelSort ( s [ i ] ) ; String st = String . valueOf ( s [ i ] ) ; if ( h . containsKey ( st ) ) { long temp = h . get ( st ) ; ans += temp ; h . put ( st , temp + 1 ) ; } else h . put ( st , ( long ) 1 ) ; } System . out . println ( ans ) ; sc . close ( ) ; } } +import java . util . * ; public class Main { Scanner sc ; int a , b ; static String testInput = " 998244353 99824435 " ; public Main ( ) { sc = new Scanner ( System . in ) ; } public Main ( String input ) { sc = new Scanner ( input ) ; } void out ( Object o ) { System . out . println ( o ) ; System . out . flush ( ) ; } public void exec ( ) throws Exception { a = sc . nextInt ( ) ; b = sc . nextInt ( ) ; int k = ( a + b ) / 2 ; if ( k * 2 != a + b ) out ( " IMPOSSIBLE " ) ; else out ( k ) ; } public static void main ( String [ ] args ) throws Exception { Main m = new Main ( ) ; m . exec ( ) ; } } +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 ) ; BBounding solver = new BBounding ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class BBounding { public void solve ( int testNumber , Scanner in , PrintWriter out ) { int n = in . nextInt ( ) ; int x = in . nextInt ( ) ; int d = 0 ; int best = 1 ; for ( int i = 0 ; i < n ; i ++ ) { d += in . nextInt ( ) ; if ( d > x ) { int i = 0 ; best = i + 1 ; break ; } if ( i == n - 1 ) best = n + 1 ; } out . println ( best ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; char [ ] str = sc . next ( ) . toCharArray ( ) ; int count = 0 ; if ( str [ 0 ] != 'A' || Character . isUpperCase ( str [ 1 ] ) || Character . isUpperCase ( str [ str . length - 1 ] ) ) { System . out . println ( " WA " ) ; return ; } for ( int i = 2 ; i < str . length - 1 ; i ++ ) { int i = 2 ; if ( Character . isUpperCase ( str [ i ] ) && str [ i ] == 'C' ) { count ++ ; } } System . out . println ( count == 1 ? " AC " : " WA " ) ; } } +public class Main { public void run ( java . util . Scanner sc ) { int [ ] a ; int i , j ; a = new int [ sc . nextInt ( ) ] ; for ( i = 0 ; i < a . length ; ++ i ) a [ i ] = sc . nextInt ( ) ; for ( i = 0 ; i < a . length ; ++ i ) { final int t = a [ i ] ; for ( j = i - 1 ; j >= 0 ; -- j ) { if ( t < a [ j ] ) { a [ j + 1 ] = a [ j ] ; a [ j ] = t ; } } printArray ( a ) ; } } private void printArray ( int [ ] a ) { int i ; for ( i = 0 ; i < a . length ; ++ i ) { System . out . print ( a [ i ] ) ; if ( i + 1 < a . length ) System . out . print ( " " ) ; else System . out . println ( ) ; } } public static void main ( String [ ] args ) { int i ; ( new Main ( ) ) . run ( new java . util . Scanner ( System . in ) ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int m = sc . nextInt ( ) ; int [ ] a = new int [ m ] ; int s = 0 ; int v = - 1 ; for ( int i = 0 ; i < m ; i ++ ) { int i = 0 ; a [ i ] = sc . nextInt ( ) ; s += a [ i ] ; } if ( n > s ) v = n - s ; else if ( n == s ) v = 0 ; else v = - 1 ; System . out . println ( v ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int a , b , sum ; a = sc . nextInt ( ) ; b = sc . nextInt ( ) ; sum = 0 ; if ( ( a == 1 || a == 2 ) && ( b == 1 || b == 2 ) ) { int a , b , sum ; sum = 3 ; System . out . println ( sum ) ; } else if ( ( a == 1 || a == 3 ) && ( b == 1 || b == 3 ) ) { sum = 2 ; System . out . println ( sum ) ; } else { sum = 1 ; System . out . println ( sum ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int N = sc . nextInt ( ) ; Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; if ( N % 2 == 1 ) { System . out . println ( ( double ) ( ( N - 1 ) / 2 + 1 ) / N ) ; } else { System . out . println ( 0.5 ) ; } } } +import java . io . BufferedReader ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws Exception { int i = 1 ; BufferedReader stdReader = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int N = Integer . parseInt ( stdReader . readLine ( ) ) ; String [ ] A = stdReader . readLine ( ) . split ( " " , 0 ) ; int j = 0 ; System . out . println ( String . join ( " " , A ) ) ; for ( int i = 1 ; i < N ; i ++ ) { String v = A [ i ] ; j = i - 1 ; while ( j >= 0 && Integer . parseInt ( A [ j ] ) > Integer . parseInt ( v ) ) { A [ j + 1 ] = A [ j ] ; j -- ; } A [ j + 1 ] = v ; System . out . println ( String . join ( " " , A ) ) ; } } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long N = sc . nextLong ( ) ; long [ ] A = new long [ ( int ) N ] ; int k = 1 ; int ans = 0 ; for ( int i = 0 ; i < N ; i ++ ) { int i = 0 ; A [ i ] = sc . nextLong ( ) ; } for ( int i = 0 ; i < N ; i ++ ) { if ( A [ i ] == k ) { k ++ ; } else { ans ++ ; } } if ( ans == N ) { ans = - 1 ; } System . out . println ( ans ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int ans = 0 ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int hako = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; if ( a == b ) { ans ++ ; if ( ans == 3 ) { hako = 1 ; } } else { int hako = 0 ; ans = 0 ; } } if ( hako == 1 ) { System . out . print ( " Yes " ) ; } else { System . out . print ( " No " ) ; } } } +import java . util . Scanner ; import java . util . InputMismatchException ; class Main { public static void main ( String [ ] args ) { int x = 0 , y = 0 , z = 0 ; int sum = 0 ; try { Scanner scanner = new Scanner ( System . in ) ; x = scanner . nextInt ( ) ; y = scanner . nextInt ( ) ; z = scanner . nextInt ( ) ; scanner . close ( ) ; } catch ( InputMismatchException e ) { int sum = 0 ; System . out . println ( " error " ) ; } for ( int i = x ; i < z + 1 ; i = i + x ) { sum = sum + y ; } System . out . println ( sum ) ; } } +import java . util . * ; import java . io . * ; public class Main { public static void main ( String [ ] args ) throws Exception { InputStreamReader r = new InputStreamReader ( System . in ) ; String S = nextString ( r ) ; int len = S . length ( ) ; int ans = 0 ; for ( int i = 0 ; i < len / 2 ; i ++ ) { if ( S . charAt ( i ) != S . charAt ( len - i - 1 ) ) { ans ++ ; } } System . out . println ( ans ) ; } public static String nextString ( InputStreamReader r ) throws Exception { String str = " " ; while ( true ) { int c = r . read ( ) ; if ( c == 32 || c == 10 || c == - 1 ) { String str = " " ; break ; } str += ( char ) c ; } return str ; } } +import java . io . * ; import java . util . * ; public class Main { static Scanner sc = new Scanner ( System . in ) ; static PrintWriter out = new PrintWriter ( System . out ) ; public static void main ( String [ ] args ) throws IOException { String s = sc . next ( ) ; int count = 0 ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( s . charAt ( i ) == '+' ) count ++ ; else count -- ; } out . println ( count ) ; out . flush ( ) ; out . close ( ) ; } static class Scanner { StringTokenizer st ; BufferedReader br ; public Scanner ( InputStream s ) { br = new BufferedReader ( new InputStreamReader ( s ) ) ; } public Scanner ( FileReader fileReader ) { br = new BufferedReader ( fileReader ) ; } public String next ( ) throws IOException { while ( st == null || ! st . hasMoreTokens ( ) ) st = new StringTokenizer ( br . readLine ( ) ) ; return st . nextToken ( ) ; } public int nextInt ( ) throws IOException { return Integer . parseInt ( next ( ) ) ; } public long nextLong ( ) throws IOException { return Long . parseLong ( next ( ) ) ; } public String nextLine ( ) throws IOException { return br . readLine ( ) ; } public boolean ready ( ) throws IOException { return br . ready ( ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String [ ] str = new String [ 3 ] ; int [ ] count = new int [ 3 ] ; for ( int i = 0 ; i < 3 ; ++ i ) { str [ i ] = sc . next ( ) ; count [ i ] = str [ i ] . length ( ) ; } int i = 0 ; while ( true ) { if ( count [ i ] == 0 && i == 0 ) { int i = 0 ; System . out . println ( " A " ) ; return ; } else if ( count [ i ] == 0 && i == 1 ) { System . out . println ( " B " ) ; return ; } else if ( count [ i ] == 0 && i == 2 ) { System . out . println ( " C " ) ; return ; } if ( str [ i ] . charAt ( str [ i ] . length ( ) - count [ i ] ) == 'a' ) { count [ i ] -- ; i = 0 ; } else if ( str [ i ] . charAt ( str [ i ] . length ( ) - count [ i ] ) == 'b' ) { count [ i ] -- ; i = 1 ; } else if ( str [ i ] . charAt ( str [ i ] . length ( ) - count [ i ] ) == 'c' ) { count [ i ] -- ; i = 2 ; } } } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int A = Integer . parseInt ( sc . next ( ) ) ; int B = Integer . parseInt ( sc . next ( ) ) ; int C = Integer . parseInt ( sc . next ( ) ) ; int X = Integer . parseInt ( sc . next ( ) ) ; int ans = 0 ; for ( int a = 0 ; a <= A ; a ++ ) { for ( int b = 0 ; b <= B ; b ++ ) { int c = 0 ; for ( int c = 0 ; c <= C ; c ++ ) { if ( a * 500 + b * 100 + c * 50 == X ) { ans ++ ; } } } } System . out . println ( ans ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int N = in . nextInt ( ) ; Integer [ ] nam = new Integer [ N ] ; int max1 = 0 ; int max2 = 0 ; for ( int i = 0 ; i < N ; i ++ ) { nam [ i ] = in . nextInt ( ) ; } Integer [ ] nam2 = nam . clone ( ) ; Arrays . sort ( nam , Collections . reverseOrder ( ) ) ; max1 = nam [ 0 ] ; max2 = nam [ 1 ] ; for ( int i = 0 ; i < N ; i ++ ) { int i = 0 ; if ( nam2 [ i ] != max1 ) { System . out . println ( max1 ) ; } else { System . out . println ( max2 ) ; } } } } +import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . util . ArrayList ; import java . util . Collections ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { ArrayList < Integer > list = new ArrayList < Integer > ( ) ; Scanner scan = new Scanner ( new BufferedReader ( new InputStreamReader ( System . in ) ) ) ; ArrayList < Integer > list = new ArrayList < Integer > ( ) ; for ( int i = 0 ; i < 10 ; i ++ ) { list . add ( scan . nextInt ( ) ) ; } Collections . sort ( list , Collections . reverseOrder ( ) ) ; System . out . println ( list . get ( 0 ) ) ; System . out . println ( list . get ( 1 ) ) ; System . out . println ( list . get ( 2 ) ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int h = sc . nextInt ( ) ; int n = sc . nextInt ( ) ; int [ ] A = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { int i = 0 ; A [ i ] = sc . nextInt ( ) ; h -= A [ i ] ; } if ( h <= 0 ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } } +import java . util . Arrays ; import java . util . Scanner ; public class Main { private static int total = 0 ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int [ ] nums = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { nums [ i ] = sc . nextInt ( ) ; } me ( nums ) ; System . out . println ( Main . total ) ; } public static void me ( int [ ] nums ) { int min = Integer . MAX_VALUE ; for ( int num : nums ) { int i ; min = num < min ? num : min ; } Main . total += min ; int ti = 0 ; int i ; for ( i = 0 ; i < nums . length ; i ++ ) { nums [ i ] -= min ; if ( nums [ i ] == 0 ) { if ( ti < i ) { me ( Arrays . copyOfRange ( nums , ti , i ) ) ; } ti = i + 1 ; } } if ( ti < i ) { me ( Arrays . copyOfRange ( nums , ti , i ) ) ; } } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { int ANS = 0 ; Scanner sc = new Scanner ( System . in ) ; int D = sc . nextInt ( ) ; int N = sc . nextInt ( ) ; int ANS = 0 ; if ( D == 0 ) { if ( N != 100 ) { ANS = N ; } else { ANS = N + 1 ; } } else if ( D == 1 ) { if ( N != 100 ) { ANS = N * 100 ; } else { ANS = ( N + 1 ) * 100 ; } } else { if ( N != 100 ) { ANS = N * 10000 ; } else { ANS = ( N + 1 ) * 10000 ; } } System . out . println ( ANS ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; int x = sc . nextInt ( ) ; int n = sc . nextInt ( ) ; int [ ] p = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { p [ i ] = sc . nextInt ( ) ; } if ( n == 0 ) { System . out . println ( x ) ; return ; } for ( int i = 0 ; i < n ; i ++ ) { int j = 0 ; int countm = 0 ; int countp = 0 ; for ( int j = 0 ; j < n ; j ++ ) { if ( x - i != p [ j ] ) { countm ++ ; } if ( x + i != p [ j ] ) { countp ++ ; } } if ( countm == n ) { System . out . println ( x - i ) ; return ; } else if ( countp == n ) { System . out . println ( x + i ) ; return ; } } System . out . println ( x - 1 ) ; } } +import java . util . Scanner ; public class Main { void run ( ) { Scanner s = new Scanner ( System . in ) ; String W = s . next ( ) ; int count = 0 ; while ( true ) { int count = 0 ; String T = s . next ( ) ; if ( T . equals ( " END_OF_TEXT " ) ) break ; if ( W . compareToIgnoreCase ( T ) == 0 ) { count ++ ; } } System . out . println ( count ) ; } public static void main ( String [ ] args ) { new Main ( ) . run ( ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) throws Exception { Scanner scan = new Scanner ( System . in ) ; int num ; int i = 1 ; while ( true ) { num = scan . nextInt ( ) ; ; if ( num != 0 ) { int i = 1 ; System . out . println ( " Case " + " " + i + " : " + " " + num ) ; i ++ ; } else { break ; } } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { int i = 0 ; Scanner scn = new Scanner ( System . in ) ; int n = scn . nextInt ( ) ; int k = scn . nextInt ( ) ; int [ ] a = new int [ n ] ; for ( int i = 0 ; i < a . length ; ++ i ) { a [ i ] = scn . nextInt ( ) ; } int count = 0 ; for ( int i = 0 ; i < a . length ; ++ i ) { if ( k <= a [ i ] ) { count = count + 1 ; } } System . out . println ( count ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] a = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = sc . nextInt ( ) ; } int bigTall = a [ 0 ] ; long count = 0 ; for ( int i = 1 ; i < n ; i ++ ) { int i = 1 ; if ( bigTall > a [ i ] ) { int sub = bigTall - a [ i ] ; count += sub ; } else { bigTall = a [ i ] ; } } System . out . println ( count ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int xx = 0 ; int yy = 0 ; int time = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int time = 0 ; int t = sc . nextInt ( ) ; int x = sc . nextInt ( ) ; int y = sc . nextInt ( ) ; int d = Math . abs ( x - xx ) + Math . abs ( y - yy ) ; int spent = t - time ; if ( d > spent || ( spent - d ) % 2 != 0 ) { System . out . println ( " No " ) ; return ; } xx = x ; yy = y ; time = t ; } System . out . println ( " Yes " ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int count = 1 ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int k = sc . nextInt ( ) ; int count = 1 ; while ( true ) { if ( n / ( int ) ( Math . pow ( k , count ) ) == 0 ) break ; count ++ ; } System . out . println ( " " + count ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int w , n ; w = sc . nextInt ( ) ; n = sc . nextInt ( ) ; int [ ] ans ; ans = new int [ w + 1 ] ; for ( int i = 0 ; i <= w ; i ++ ) { ans [ i ] = i ; } for ( int i = 0 ; i < n ; i ++ ) { int a , b ; String [ ] s = sc . next ( ) . split ( " , " ) ; a = Integer . parseInt ( s [ 0 ] ) ; b = Integer . parseInt ( s [ 1 ] ) ; int noise ; noise = ans [ a ] ; ans [ a ] = ans [ b ] ; ans [ b ] = noise ; } for ( int i = 1 ; i <= w ; i ++ ) { int i = 1 ; System . out . println ( ans [ i ] ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; double [ ] data = new double [ 1000 ] ; int v ; double temp ; double lenkin ; for ( int i = 0 ; i < N ; i ++ ) { v = sc . nextInt ( ) ; data [ i ] = v ; } for ( int i = 0 ; i < N ; i ++ ) { for ( int j = i + 1 ; j < N ; j ++ ) { if ( data [ i ] > data [ j ] ) { temp = data [ i ] ; data [ i ] = data [ j ] ; data [ j ] = temp ; } } } lenkin = ( data [ 0 ] + data [ 1 ] ) / 2 ; for ( int i = 2 ; i < N ; i ++ ) { int i = 2 ; lenkin = ( lenkin + data [ i ] ) / 2 ; } System . out . println ( lenkin ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { final String LAST_DATA = " END_OF_TEXT " ; Scanner scn = new Scanner ( System . in ) ; String W = scn . nextLine ( ) ; int count = 0 ; final String LAST_DATA = " END_OF_TEXT " ; while ( scn . hasNextLine ( ) ) { String T = scn . next ( ) ; if ( T . equals ( LAST_DATA ) ) { break ; } W = W . toLowerCase ( ) ; T = T . toLowerCase ( ) ; if ( T . equals ( W ) ) { count ++ ; } } System . out . println ( count ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String ans = " No " ; String s = sc . next ( ) ; String t = sc . next ( ) ; int n = s . length ( ) ; int temp = 0 ; int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int j = 0 ; for ( int j = 0 ; j < n ; j ++ ) { if ( s . charAt ( j ) != t . charAt ( ( j + temp ) % n ) ) { temp ++ ; count = 0 ; break ; } else { count ++ ; } } if ( count == n ) { ans = " Yes " ; break ; } } System . out . println ( ans ) ; } } +import java . util . ArrayList ; import java . util . Collections ; import java . util . List ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = Integer . parseInt ( sc . nextLine ( ) ) ; List < Integer > nums = new ArrayList < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { List < Integer > nums = new ArrayList < > ( ) ; nums . add ( sc . nextInt ( ) ) ; } Collections . sort ( nums ) ; int n1 = nums . get ( n / 2 - 1 ) ; int n2 = nums . get ( n / 2 ) ; System . out . println ( n2 - n1 ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; String moji = sc . nextLine ( ) ; char [ ] chmoji = new char [ moji . length ( ) ] ; for ( int i = 0 ; i < moji . length ( ) ; i ++ ) { chmoji [ i ] = moji . charAt ( i ) ; boolean kekka = Character . isUpperCase ( chmoji [ i ] ) ; if ( kekka == true ) { chmoji [ i ] = Character . toLowerCase ( chmoji [ i ] ) ; } else { chmoji [ i ] = Character . toUpperCase ( chmoji [ i ] ) ; } System . out . print ( chmoji [ i ] ) ; } System . out . println ( ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int A = sc . nextInt ( ) ; int B = sc . nextInt ( ) ; int C = sc . nextInt ( ) ; int K = sc . nextInt ( ) ; int ans = 0 ; int b = K - A ; int c = K - A - B ; if ( A == 0 && C == 0 ) { int c = K - A - B ; System . out . println ( " 0 " ) ; } else if ( K >= A && c < 1 ) { System . out . println ( A ) ; } else if ( K >= A && c >= 1 ) { System . out . println ( A + ( c * - 1 ) ) ; } else if ( K < A ) { System . out . println ( K ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int f = d - s ; Scanner sc = new Scanner ( System . in ) ; int d = sc . nextInt ( ) ; int as = sc . nextInt ( ) ; int [ ] ar = new int [ 10000 ] ; int s = 0 ; for ( int i = 0 ; i < as ; i ++ ) { ar [ i ] = sc . nextInt ( ) ; } for ( int i = 0 ; i < ar . length ; i ++ ) { s = s + ar [ i ] ; } int f = d - s ; if ( f >= 0 ) { System . out . println ( f ) ; } else { System . out . println ( " -1 " ) ; } } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; StringBuilder str = new StringBuilder ( ) ; int pointer = 0 ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { switch ( s . charAt ( i ) ) { case '0' : str . append ( '0' ) ; pointer ++ ; break ; case '1' : str . append ( '1' ) ; pointer ++ ; break ; case 'B' : if ( pointer == 0 ) { break ; } str . deleteCharAt ( pointer - 1 ) ; pointer -- ; break ; default : break ; } } System . out . println ( str . toString ( ) ) ; sc . close ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int dataset = sc . nextInt ( ) ; int a , b , c ; for ( int i = 0 ; i < dataset ; i ++ ) { int a , b , c ; a = sc . nextInt ( ) ; b = sc . nextInt ( ) ; c = sc . nextInt ( ) ; if ( judgeTriangle ( a , b , c ) ) System . out . println ( " YES " ) ; else System . out . println ( " NO " ) ; } sc . close ( ) ; } static boolean judgeTriangle ( int a , int b , int c ) { int da = a * a ; int db = b * b ; int dc = c * c ; if ( da + db == dc ) return true ; else if ( db + dc == da ) return true ; else if ( dc + da == db ) return true ; else return false ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws NumberFormatException , IOException { int task1 , task2 , task3 ; int [ ] cost = new int [ 6 ] ; int ans = 1000 ; BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String [ ] str = br . readLine ( ) . split ( " " ) ; task1 = Integer . parseInt ( str [ 0 ] ) ; task2 = Integer . parseInt ( str [ 1 ] ) ; task3 = Integer . parseInt ( str [ 2 ] ) ; cost [ 0 ] = Math . abs ( task1 - task2 ) + Math . abs ( task2 - task3 ) ; cost [ 1 ] = Math . abs ( task1 - task3 ) + Math . abs ( task3 - task2 ) ; cost [ 2 ] = Math . abs ( task2 - task1 ) + Math . abs ( task1 - task3 ) ; cost [ 3 ] = Math . abs ( task2 - task3 ) + Math . abs ( task3 - task1 ) ; cost [ 4 ] = Math . abs ( task3 - task1 ) + Math . abs ( task1 - task2 ) ; cost [ 5 ] = Math . abs ( task3 - task2 ) + Math . abs ( task2 - task1 ) ; for ( int i = 0 ; i < 6 ; i ++ ) { if ( ans > cost [ i ] ) { int i = 0 ; ans = cost [ i ] ; } } System . out . println ( ans ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int res = a / b ; if ( res * b < a ) { int res = a / b ; ++ res ; } System . out . println ( res ) ; } } +import java . util . ArrayList ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner s = new Scanner ( System . in ) ; int n = s . nextInt ( ) ; ArrayList < Long > list = new ArrayList < > ( ) ; long num = 1 ; while ( num != n + 1 ) { if ( num % 3 != 0 && num % 5 != 0 ) { list . add ( num ) ; num ++ ; } else { num ++ ; } } long sum = 0 ; for ( int i = 0 ; i < list . size ( ) ; i ++ ) { int i = 0 ; sum = sum + list . get ( i ) ; } System . out . println ( sum ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; Scanner scanner = new Scanner ( System . in ) ; while ( true ) { int a = scanner . nextInt ( ) ; int b = scanner . nextInt ( ) ; int c = scanner . nextInt ( ) ; if ( a == - 1 && b == - 1 && c == - 1 ) break ; if ( a == - 1 || b == - 1 ) System . out . println ( " F " ) ; else if ( a + b >= 80 ) System . out . println ( " A " ) ; else if ( a + b >= 65 ) System . out . println ( " B " ) ; else if ( a + b >= 50 ) System . out . println ( " C " ) ; else if ( a + b >= 30 ) if ( c >= 50 ) System . out . println ( " C " ) ; else System . out . println ( " D " ) ; else System . out . println ( " F " ) ; } } } +import java . util . * ; import java . io . * ; public class Main { public static void main ( String [ ] args ) throws Exception { int num = 998244353 ; BufferedReader bf = new BufferedReader ( new InputStreamReader ( System . in ) ) ; PrintWriter out = new PrintWriter ( System . out ) ; int n = Integer . parseInt ( bf . readLine ( ) ) ; ArrayList < Integer > array = new ArrayList < Integer > ( ) ; int min = Integer . MAX_VALUE ; StringTokenizer st = new StringTokenizer ( bf . readLine ( ) ) ; for ( int i = 0 ; i < n ; i ++ ) { int j = 0 ; array . add ( Integer . parseInt ( st . nextToken ( ) ) ) ; } for ( int i = 1 ; i <= 100 ; i ++ ) { int sum = 0 ; for ( int j = 0 ; j < array . size ( ) ; j ++ ) { sum += ( array . get ( j ) - i ) * ( array . get ( j ) - i ) ; } min = Math . min ( sum , min ) ; } out . println ( min ) ; out . close ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { long ans = 0 ; long ans2 = 0 ; Scanner sc = new Scanner ( System . in ) ; long n = sc . nextLong ( ) ; long m = sc . nextLong ( ) ; long k = sc . nextLong ( ) ; boolean f = false ; long temp = k - n ; if ( k >= n + m ) { long k = sc . nextLong ( ) ; ans = 0 ; ans2 = 0 ; } else { if ( k <= n ) { ans = n - k ; ans2 = m ; } else { ans = 0 ; ans2 = m - ( k - n ) ; } } System . out . println ( ans ) ; System . out . println ( ans2 ) ; sc . close ( ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; String [ ] split = s . split ( " " ) ; int i ; int count = 0 , ans = 0 ; for ( i = 0 ; i < s . length ( ) ; i ++ ) { if ( split [ i ] . equals ( " A " ) || split [ i ] . equals ( " C " ) || split [ i ] . equals ( " G " ) || split [ i ] . equals ( " T " ) ) { count += 1 ; } else { int count = 0 , ans = 0 ; if ( ans < count ) { ans = count ; } count = 0 ; } } if ( ans < count ) { ans = count ; } System . out . println ( ans ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner scanner = new Scanner ( System . in ) ; char [ ] S = scanner . next ( ) . toCharArray ( ) ; for ( int i = 0 ; i < S . length ; i ++ ) { if ( ( i + 1 ) % 2 == 1 ) { if ( S [ i ] == 'L' ) { System . out . println ( " No " ) ; return ; } } else { if ( S [ i ] == 'R' ) { System . out . println ( " No " ) ; return ; } } } System . out . println ( " Yes " ) ; } } +import java . util . ArrayList ; import java . util . List ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int j = i + 1 ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; List < Integer > list = new ArrayList < Integer > ( ) ; int max = 0 ; for ( int i = 0 ; n > i ; i ++ ) { int a = sc . nextInt ( ) ; list . add ( a ) ; } for ( int i = 0 ; n - 1 > i ; i ++ ) { for ( int j = i + 1 ; n > j ; j ++ ) { int b = Math . abs ( list . get ( i ) - list . get ( j ) ) ; if ( b > max ) max = b ; } } System . out . println ( max ) ; } } +import java . io . * ; import java . util . * ; public class Main { public static void main ( String [ ] args ) { try { BufferedReader br = createBufferedReader ( ) ; String line = br . readLine ( ) ; System . out . println ( method ( line ) ) ; } catch ( IOException ioe ) { ioe . printStackTrace ( ) ; } } private static int method ( final String str ) { int i = 0 ; String [ ] strings = { " SUN " , " MON " , " TUE " , " WED " , " THU " , " FRI " , " SAT " } ; for ( int i = 0 ; i < strings . length ; i ++ ) { if ( str . equals ( strings [ i ] ) ) { return 7 - i ; } } return - 1 ; } private static BufferedReader createBufferedReader ( ) { InputStreamReader isr = new InputStreamReader ( System . in ) ; return new BufferedReader ( isr ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String ... nui ) { int cnt = 0 ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int min = ( int ) 1e9 ; for ( int i = 0 ; i < n ; i ++ ) { int a = sc . nextInt ( ) ; int cnt = 0 ; while ( a % 2 == 0 ) { a /= 2 ; cnt ++ ; } min = Math . min ( min , cnt ) ; } System . out . println ( min ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; int total = 0 ; int [ ] num = new int [ 9 ] ; for ( int i = 0 ; i < 9 ; i ++ ) { num [ i ] = sc . nextInt ( ) ; total += num [ i ] ; } int nextTotal1 = num [ 0 ] + num [ 1 ] + num [ 3 ] + num [ 4 ] ; int nextTotal2 = num [ 4 ] + num [ 5 ] + num [ 7 ] + num [ 8 ] ; int nextTotal3 = num [ 1 ] + num [ 2 ] + num [ 4 ] + num [ 5 ] ; int nextTotal4 = num [ 3 ] + num [ 4 ] + num [ 6 ] + num [ 7 ] ; int nextTotal5 = num [ 0 ] + num [ 2 ] + num [ 6 ] + num [ 8 ] ; if ( total % 3 == 0 && nextTotal1 % 2 == 0 && nextTotal1 % 2 == 0 && nextTotal3 % 2 == 0 && nextTotal4 % 2 == 0 && nextTotal5 % 2 == 0 ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; sc . close ( ) ; } } +import java . io . * ; import java . util . * ; public class Main { public static void main ( final String [ ] args ) throws Exception { final Scanner sc = new Scanner ( System . in ) ; String S ; S = sc . next ( ) ; final Solver solver = new Solver ( ) ; solver . solve ( S ) ; } } class Solver { public void solve ( String S ) { for ( int i = 0 ; i < 3 ; i ++ ) { int i = 0 ; if ( S . charAt ( i ) == S . charAt ( i + 1 ) ) { System . out . println ( " Bad " ) ; return ; } } System . out . println ( " Good " ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int tt = 0 ; int tx = 0 ; int ty = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int t = sc . nextInt ( ) ; int x = sc . nextInt ( ) ; int y = sc . nextInt ( ) ; int dt = Math . abs ( t - tt ) ; int dx = Math . abs ( x - tx ) ; int dy = Math . abs ( y - ty ) ; if ( dt < dx + dy || ( dt - dx - dy ) % 2 == 1 ) { int ty = 0 ; System . out . println ( " No " ) ; sc . close ( ) ; return ; } } sc . close ( ) ; System . out . println ( " Yes " ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int maxNum = scan . nextInt ( ) ; int sum = scan . nextInt ( ) ; int ans = 0 ; for ( int x = 0 ; x <= maxNum ; ++ x ) { for ( int y = 0 ; y <= maxNum ; ++ y ) { int z = sum - x - y ; if ( 0 <= z && z <= maxNum ) { int y = 0 ; ans = ans + 1 ; } } } System . out . println ( ans ) ; } } +import java . util . Scanner ; public class Main { static Scanner scanner ; public static void main ( String [ ] args ) { scanner = new Scanner ( System . in ) ; int N = gi ( ) ; int M = gi ( ) ; int a = ( int ) Math . ceil ( ( double ) ( M - 1 ) / ( double ) ( N - 1 ) ) ; System . out . print ( a ) ; } public static String gs ( ) { return scanner . next ( ) ; } public static int gi ( ) { return Integer . parseInt ( scanner . next ( ) ) ; } public static long gl ( ) { return Long . parseLong ( scanner . next ( ) ) ; } public static double gd ( ) { return Double . parseDouble ( scanner . next ( ) ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; int friends = sc . nextInt ( ) ; int height = sc . nextInt ( ) ; int [ ] fh = new int [ friends ] ; int count = 0 ; for ( int i = 0 ; i < friends ; i ++ ) { fh [ i ] = sc . nextInt ( ) ; if ( fh [ i ] >= height ) { count ++ ; } } System . out . println ( count ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int A = sc . nextInt ( ) ; int B = sc . nextInt ( ) ; int sum = 0 ; for ( int i = 1 ; i <= N ; i ++ ) { int sum2 = 0 ; int ii = i ; int iii = 0 ; int sum2 = 0 ; for ( int j = 0 ; j < 5 ; j ++ ) { iii = ii % 10 ; sum2 += iii ; ii = ii / 10 ; } if ( sum2 >= A && sum2 <= B ) { sum += i ; } } System . out . println ( sum ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long nam = sc . nextLong ( ) ; long ans = Long . MAX_VALUE ; long j = 0 ; for ( long i = 1 ; i * i <= nam ; i ++ ) { if ( nam % i != 0 ) { long i = 1 ; continue ; } j = nam / i ; ans = Math . min ( ans , i + j - 2 ) ; } System . out . println ( ans ) ; } } +import java . util . * ; import java . util . Collections ; import java . util . ArrayList ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String S = sc . next ( ) ; String T = sc . next ( ) ; int l = S . length ( ) ; loop : for ( int i = 0 ; i < l ; i ++ ) { for ( int j = 0 ; j < l ; j ++ ) { if ( S . charAt ( ( j + i ) % l ) != T . charAt ( j ) ) { break ; } else { if ( j == l - 1 ) { System . out . println ( " Yes " ) ; break loop ; } } } if ( i == l - 1 ) { int j = 0 ; System . out . println ( " No " ) ; } } } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; String temp = String . valueOf ( n / 100 ) ; int tem = Integer . parseInt ( temp + temp + temp ) ; if ( n <= tem ) { int tem = Integer . parseInt ( temp + temp + temp ) ; System . out . println ( tem ) ; } else { System . out . println ( tem + 111 ) ; } } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = Integer . parseInt ( sc . next ( ) ) ; boolean aa = false ; boolean bb = true ; for ( int i = 0 ; i < N ; i ++ ) { int a = Integer . parseInt ( sc . next ( ) ) ; if ( a % 2 == 0 ) { int a = Integer . parseInt ( sc . next ( ) ) ; bb = false ; if ( a % 3 == 0 || a % 5 == 0 ) { aa = true ; } else { aa = false ; break ; } } } System . out . println ( aa || bb ? " APPROVED " : " DENIED " ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String S = sc . next ( ) ; if ( isKaibun ( S ) && isKaibun ( S . substring ( 0 , S . length ( ) / 2 ) ) ) { System . out . println ( " Yes " ) ; } else { int i = 0 ; System . out . println ( " No " ) ; } } public static boolean isKaibun ( String s ) { boolean result = true ; int len = s . length ( ) ; for ( int i = 0 ; i <= len / 2 ; i ++ ) { if ( s . charAt ( i ) != s . charAt ( len - 1 - i ) ) { result = false ; break ; } } return result ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int K = scan . nextInt ( ) ; String S = scan . next ( ) ; int S_length = S . length ( ) ; if ( K < S_length ) { for ( int i = 0 ; i < K ; i ++ ) { int i = 0 ; System . out . print ( S . charAt ( i ) ) ; } System . out . print ( " ... " ) ; } else { System . out . print ( S ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; while ( true ) { int H = sc . nextInt ( ) ; int W = sc . nextInt ( ) ; if ( H == 0 && W == 0 ) { int W = sc . nextInt ( ) ; break ; } for ( int i = 0 ; i < W ; i ++ ) { System . out . printf ( " # " ) ; } System . out . printf ( " %n " ) ; for ( int i = 0 ; i < H - 2 ; i ++ ) { System . out . printf ( " # " ) ; for ( int j = 0 ; j < W - 2 ; j ++ ) { System . out . printf ( " . " ) ; } System . out . printf ( " #%n " ) ; } for ( int i = 0 ; i < W ; i ++ ) { System . out . printf ( " # " ) ; } System . out . printf ( " %n%n " ) ; } } } +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 ( ) ; System . out . println ( solve ( A , B ) ) ; sc . close ( ) ; } static int solve ( int A , int B ) { if ( A >= 13 ) { return B ; } else if ( A >= 6 ) { return B / 2 ; } else { int B = sc . nextInt ( ) ; return 0 ; } } } +import java . util . * ; public class Main { static StringBuilder a = new StringBuilder ( ) ; static StringBuilder b = new StringBuilder ( ) ; static StringBuilder c = new StringBuilder ( ) ; public static void main ( String [ ] args ) { char tmp = c . charAt ( 0 ) ; Scanner sc = new Scanner ( System . in ) ; a . append ( sc . next ( ) ) ; b . append ( sc . next ( ) ) ; c . append ( sc . next ( ) ) ; char tmp = a . charAt ( 0 ) ; a . deleteCharAt ( 0 ) ; Main . nextTurn ( tmp ) ; } public static void nextTurn ( char card ) { if ( card == 'a' ) { if ( a . length ( ) == 0 ) { System . out . println ( " A " ) ; return ; } char tmp = a . charAt ( 0 ) ; a . deleteCharAt ( 0 ) ; Main . nextTurn ( tmp ) ; } else if ( card == 'b' ) { if ( b . length ( ) == 0 ) { System . out . println ( " B " ) ; return ; } char tmp = b . charAt ( 0 ) ; b . deleteCharAt ( 0 ) ; Main . nextTurn ( tmp ) ; } else if ( card == 'c' ) { if ( c . length ( ) == 0 ) { System . out . println ( " C " ) ; return ; } char tmp = c . charAt ( 0 ) ; c . deleteCharAt ( 0 ) ; Main . nextTurn ( tmp ) ; } } } +import java . util . * ; import java . io . * ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int [ ] [ ] c = new int [ 3 ] [ 3 ] ; int [ ] rx = new int [ 3 ] ; int [ ] ry = new int [ 3 ] ; boolean flag = true ; for ( int i = 0 ; i < 3 ; i ++ ) { for ( int j = 0 ; j < 3 ; j ++ ) { c [ i ] [ j ] = scan . nextInt ( ) ; } } ry [ 0 ] = 0 ; for ( int j = 0 ; j < 3 ; j ++ ) { rx [ j ] = c [ 0 ] [ j ] - ry [ 0 ] ; } for ( int j = 1 ; j < 3 ; j ++ ) { ry [ j ] = c [ j ] [ 0 ] - rx [ 0 ] ; } outside : for ( int i = 0 ; i < 3 ; i ++ ) { for ( int j = 0 ; j < 3 ; j ++ ) { if ( rx [ j ] + ry [ i ] != c [ i ] [ j ] ) { flag = false ; System . out . println ( " No " ) ; break outside ; } } } if ( flag ) { int j = 0 ; System . out . println ( " Yes " ) ; } } } +import java . io . * ; import java . util . * ; public class Main { public static void main ( String [ ] args ) { MyScanner sc = new MyScanner ( ) ; int n = sc . nextInt ( ) ; int [ ] s = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { s [ i ] = sc . nextInt ( ) ; } int ans = 0 ; int q = sc . nextInt ( ) ; for ( int i = 0 ; i < q ; i ++ ) { int t = sc . nextInt ( ) ; if ( binarySearch ( s , n , t ) >= 0 ) ans ++ ; } System . out . println ( ans ) ; } static int binarySearch ( int [ ] a , int n , int key ) { int left = 0 ; int right = n ; while ( left < right ) { int mid = ( left + right ) / 2 ; if ( a [ mid ] == key ) return mid ; else if ( a [ mid ] < key ) left = mid + 1 ; else right = mid ; } return - 1 ; } static class MyScanner { BufferedReader reader = new BufferedReader ( new InputStreamReader ( System . in ) , 1 << 15 ) ; StringTokenizer tokenizer ; String next ( ) { try { while ( tokenizer == null || ! tokenizer . hasMoreTokens ( ) ) { tokenizer = new StringTokenizer ( reader . readLine ( ) ) ; } } catch ( IOException ignored ) { } return tokenizer . nextToken ( ) ; } int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } long nextLong ( ) { return Long . parseLong ( next ( ) ) ; } } } +import java . util . Arrays ; import java . util . List ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; int ans = 0 ; String s = sc . nextLine ( ) ; List < String > a = Arrays . asList ( s . split ( " " ) ) ; String [ ] array = a . toArray ( new String [ a . size ( ) ] ) ; String hikaku = " R " ; for ( int i = 0 ; i < 3 ; i ++ ) { if ( array [ i ] . equals ( " R " ) ) { ans ++ ; } else if ( i == 1 && ans == 1 ) { break ; } } System . out . println ( ans ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int m = sc . nextInt ( ) ; int [ ] d ; d = new int [ 100 ] ; for ( int i = 0 ; i < m ; i ++ ) { int [ ] d ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; d [ a ] ++ ; d [ b ] ++ ; } for ( int i = 1 ; i <= n ; i ++ ) System . out . println ( d [ i ] ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int H = scan . nextInt ( ) ; int N = scan . nextInt ( ) ; int [ ] A = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { A [ i ] = scan . nextInt ( ) ; } scan . close ( ) ; int sum = 0 ; for ( int i = 0 ; i < N ; i ++ ) { int i = 0 ; sum += A [ i ] ; } System . out . println ( H > sum ? " No " : " Yes " ) ; } } +import java . lang . reflect . Array ; import java . util . Arrays ; import java . util . Comparator ; import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { int j = 2 ; Scanner sc = new Scanner ( System . in ) ; int x = sc . nextInt ( ) ; int xx = x / 2 ; int ans = 0 ; for ( int i = 1 ; i <= x ; i ++ ) { for ( int j = 2 ; j <= x + 1 ; j ++ ) { if ( Math . pow ( i , j ) > ans && Math . pow ( i , j ) <= x ) { ans = ( int ) Math . pow ( i , j ) ; } } } System . out . println ( ans ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int sp = sc . nextInt ( ) ; int q = sc . nextInt ( ) ; int [ ] point = new int [ n ] ; for ( int i = 0 ; i < point . length ; i ++ ) { point [ i ] = sp - q ; } int [ ] answer = new int [ q ] ; for ( int i = 0 ; i < answer . length ; i ++ ) { answer [ i ] = sc . nextInt ( ) ; point [ answer [ i ] - 1 ] ++ ; } for ( int i : point ) { if ( i <= 0 ) { System . out . println ( " No " ) ; } else { int i ; System . out . println ( " Yes " ) ; } } } } +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 tiles = input . readLine ( ) ; System . out . println ( Math . min ( getCount ( tiles , '0' ) , getCount ( tiles , '1' ) ) ) ; } public static int getCount ( String tiles , char tile ) { int count = 0 ; for ( int i = 0 ; i < tiles . length ( ) ; i ++ ) { int i = 0 ; if ( tile != tiles . charAt ( i ) ) count ++ ; tile = tile == '0' ? '1' : '0' ; } return count ; } } +import java . util . Scanner ; public class Main { public static String check ( int x , int y ) { return " " ; } public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int n = in . nextInt ( ) ; int count = 0 ; int vit = 0 ; while ( n -- != 0 ) { int x = in . nextInt ( ) ; int y = in . nextInt ( ) ; if ( x == y ) { count ++ ; } else { count = 0 ; } if ( count == 3 ) { vit = 1 ; } } if ( vit == 1 ) { int vit = 0 ; 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 = new int [ 26 ] ; while ( sc . hasNext ( ) ) { String s = sc . nextLine ( ) ; s = s . toLowerCase ( ) ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { char i = 'a' ; if ( s . charAt ( i ) >= 'a' && s . charAt ( i ) <= 'z' ) { a [ s . charAt ( i ) - 'a' ] ++ ; } } } for ( char i = 'a' ; i <= 'z' ; i ++ ) { System . out . println ( i + " : " + a [ i - 'a' ] ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner scan = new Scanner ( System . in ) ; int n = scan . nextInt ( ) ; scan . close ( ) ; String str = String . valueOf ( n ) ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { int x = Character . getNumericValue ( str . charAt ( i ) ) ; System . out . print ( ( x == 1 ) ? " 9 " : ( ( x == 9 ) ? " 1 " : x ) ) ; } System . out . println ( ) ; } } +import java . util . * ; import java . io . * ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int n = scan . nextInt ( ) ; int m = scan . nextInt ( ) ; int [ ] r = new int [ 2 * m ] ; int [ ] rr = new int [ n + 1 ] ; for ( int i = 0 ; i < 2 * m ; i ++ ) { r [ i ] = scan . nextInt ( ) ; } for ( int i = 0 ; i < n + 1 ; i ++ ) { int i = 1 ; rr [ i ] = 0 ; } for ( int i = 0 ; i < 2 * m ; i ++ ) { rr [ r [ i ] ] ++ ; } for ( int i = 1 ; i <= n ; i ++ ) { System . out . println ( rr [ i ] ) ; } } } +import java . util . * ; import java . io . * ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; String s1 = scanner . next ( ) ; char [ ] c = s1 . toCharArray ( ) ; List < Integer > list = new ArrayList < > ( ) ; for ( int i = 0 ; i < s1 . length ( ) ; i ++ ) { if ( c [ i ] != 'B' ) list . add ( ( int ) c [ i ] - '0' ) ; else { int i = 0 ; if ( list . size ( ) > 0 ) list . remove ( list . size ( ) - 1 ) ; } } for ( int i = 0 ; i < list . size ( ) ; i ++ ) System . out . print ( list . get ( i ) ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int i = 1 ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] t = new int [ n + 1 ] ; int [ ] x = new int [ n + 1 ] ; int [ ] y = new int [ n + 1 ] ; for ( int i = 1 ; i <= n ; i ++ ) { t [ i ] = sc . nextInt ( ) ; x [ i ] = sc . nextInt ( ) ; y [ i ] = sc . nextInt ( ) ; } int dist = 0 ; int flag = 1 ; int time = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { time = t [ i ] - t [ i - 1 ] ; dist = Math . abs ( Math . abs ( ( x [ i ] - x [ i - 1 ] ) ) + Math . abs ( ( y [ i ] - y [ i - 1 ] ) ) ) ; if ( time < dist ) { flag = 0 ; break ; } else if ( ( time - dist ) % 2 != 0 ) { flag = 0 ; break ; } } if ( flag == 1 ) { System . out . print ( " Yes " ) ; } else { System . out . print ( " No " ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int T = sc . nextInt ( ) ; int [ ] num = new int [ 2 * N ] ; int min = 1001 ; for ( int i = 0 ; i < 2 * N ; i ++ ) { num [ i ] = sc . nextInt ( ) ; } for ( int i = 0 ; i < N ; i ++ ) { if ( num [ 2 * i + 1 ] > T ) { num [ 2 * i ] = 1001 ; } } for ( int i = 0 ; i < N ; i ++ ) { if ( min > num [ 2 * i ] ) { min = num [ 2 * i ] ; } } if ( min == 1001 ) { int i = 0 ; System . out . println ( " TLE " ) ; } else { System . out . println ( min ) ; } } } +import java . util . * ; class Main { Scanner sc ; Main ( ) { sc = new Scanner ( System . in ) ; } void calc ( ) { int j = i + 1 ; int N = sc . nextInt ( ) ; int [ ] d = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) d [ i ] = sc . nextInt ( ) ; int sum = 0 ; for ( int i = 0 ; i < N - 1 ; i ++ ) { for ( int j = i + 1 ; j < N ; j ++ ) { sum += d [ i ] * d [ j ] ; } } System . out . println ( sum ) ; } public static void main ( String [ ] args ) { new Main ( ) . calc ( ) ; } } +import java . util . * ; import java . math . * ; import java . io . * ; public class Main { public static void main ( String [ ] args ) throws Exception { int num = 998244353 ; BufferedReader bf = new BufferedReader ( new InputStreamReader ( System . in ) ) ; PrintWriter out = new PrintWriter ( System . out ) ; int n = Integer . parseInt ( bf . readLine ( ) ) ; StringTokenizer st = new StringTokenizer ( bf . readLine ( ) ) ; ArrayList < BigInteger > array = new ArrayList < BigInteger > ( ) ; boolean found = false ; for ( int i = 0 ; i < n ; i ++ ) { int i = 0 ; array . add ( new BigInteger ( st . nextToken ( ) ) ) ; if ( array . get ( i ) . equals ( new BigInteger ( " 0 " ) ) ) { out . println ( 0 ) ; out . close ( ) ; found = true ; } } if ( found == false ) { BigInteger prod = new BigInteger ( " 1 " ) ; boolean found1 = true ; for ( int i = 0 ; i < n ; i ++ ) { prod = prod . multiply ( array . get ( i ) ) ; if ( prod . compareTo ( new BigInteger ( " 1000000000000000000 " ) ) > 0 ) { out . println ( - 1 ) ; found1 = false ; break ; } } if ( found1 == true ) { out . println ( prod ) ; } } out . close ( ) ; } } +import java . io . * ; import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . StringTokenizer ; import java . util . * ; public class Main { static class FastReader { BufferedReader br ; StringTokenizer st ; public FastReader ( ) { br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; } String next ( ) { String str = " " ; while ( st == null || ! st . hasMoreTokens ( ) ) { 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 ; } public Character charAt ( int i ) { return null ; } } public static void main ( String [ ] args ) throws IOException { FastReader s = new FastReader ( ) ; String n = s . next ( ) ; if ( n . charAt ( 0 ) >= 65 && n . charAt ( 0 ) <= 90 ) System . out . println ( " A " ) ; else System . out . println ( " a " ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . StringTokenizer ; public class Main { public static void main ( String [ ] args ) { int j = 1 ; try { InputStreamReader isr = new InputStreamReader ( System . in ) ; BufferedReader br = new BufferedReader ( isr ) ; while ( true ) { String buf = br . readLine ( ) ; StringTokenizer st = new StringTokenizer ( buf , " " ) ; int H = Integer . parseInt ( st . nextToken ( ) ) ; int W = Integer . parseInt ( st . nextToken ( ) ) ; if ( W == 0 && H == 0 ) break ; if ( H >= 300 && W >= 300 ) break ; ; for ( int i = 1 ; i <= H ; i ++ ) { for ( int j = 1 ; j <= W ; j ++ ) { if ( i % 2 == 0 ) { if ( j % 2 == 0 ) System . out . print ( " # " ) ; else System . out . print ( " . " ) ; } else { if ( j % 2 == 0 ) System . out . print ( " . " ) ; else System . out . print ( " # " ) ; } } System . out . println ( ) ; } System . out . println ( ) ; } } catch ( IOException e ) { System . err . println ( e ) ; } } } +import java . util . * ; import java . util . stream . Collectors ; import java . io . * ; import java . nio . charset . StandardCharsets ; public class Main { public static void main ( String [ ] args ) throws IOException { InputStreamReader reader = new InputStreamReader ( System . in , StandardCharsets . UTF_8 ) ; BufferedReader in = new BufferedReader ( reader ) ; Main ins = new Main ( in ) ; ins . calc ( ) ; ins . showResult ( ) ; } Main ( BufferedReader in ) throws IOException { String [ ] tokens = in . readLine ( ) . split ( " " ) ; int N = Integer . parseInt ( tokens [ 0 ] ) ; int M = Integer . parseInt ( tokens [ 1 ] ) ; int [ ] A = new int [ M ] ; tokens = in . readLine ( ) . split ( " " ) ; for ( int i = 0 ; i < M ; ++ i ) { A [ i ] = Integer . parseInt ( tokens [ i ] ) ; } long sum = 0 ; for ( int i = 0 ; i < M ; ++ i ) { sum += A [ i ] ; } if ( sum > N ) { System . out . println ( " -1 " ) ; } else { System . out . println ( ( N - sum ) ) ; } } void calc ( ) { } void showResult ( ) { int i = 0 ; } } +import java . util . * ; public class Main { static int MOD = 1000000007 ; static int INF = Integer . MAX_VALUE ; public static void main ( String [ ] args ) { Long k = sc . nextLong ( ) ; Scanner sc = new Scanner ( System . in ) ; Long a = sc . nextLong ( ) ; Long b = sc . nextLong ( ) ; Long k = sc . nextLong ( ) ; if ( a >= 1 && a >= k ) { a = a - k ; } else if ( a >= 1 && a < k ) { k = k - a ; a = ( long ) 0 ; if ( b >= k ) { b = b - k ; } else { b = ( long ) 0 ; } } else if ( a < 1 ) { if ( b >= k ) { b = b - k ; } else { b = ( long ) 0 ; } } System . out . println ( a + " " + b ) ; } } +import java . util . * ; import javax . lang . model . util . ElementScanner6 ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; long out = a ; long a1 = a ; long b1 = b ; while ( ! ( out % a == 0 && out % b == 0 ) ) { long b1 = b ; out = a1 > b1 ? a1 : b1 ; if ( a1 < out ) { a1 += a ; } if ( b1 < out ) { b1 += b ; } } System . out . println ( out ) ; } } +import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { int i = 0 ; BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String line = br . readLine ( ) ; String line2 = br . readLine ( ) ; String [ ] ary = line2 . split ( " " ) ; List < Integer > list = new ArrayList < Integer > ( ) ; for ( int i = 0 ; i < ary . length ; i ++ ) { list . add ( new Integer ( ary [ i ] ) ) ; } Collections . reverse ( list ) ; for ( int i = 0 ; i < list . size ( ) ; i ++ ) { System . out . print ( list . get ( i ) ) ; if ( i == list . size ( ) - 1 ) { System . out . println ( ) ; } else { System . out . print ( " " ) ; } } } } +import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . util . ArrayList ; import java . util . Arrays ; import java . util . List ; public class Main { public static void main ( String [ ] args ) throws Exception { InputStreamReader is = new InputStreamReader ( System . in ) ; BufferedReader reader = new BufferedReader ( is ) ; List < String > mylist = new ArrayList < > ( ) ; String strinput = reader . readLine ( ) ; while ( strinput != null ) { int i = n - 1 ; mylist . add ( strinput ) ; strinput = reader . readLine ( ) ; } String [ ] arr01 = mylist . get ( 0 ) . split ( " " ) ; String [ ] arr02 = mylist . get ( 1 ) . split ( " " ) ; int n = Integer . valueOf ( arr01 [ 0 ] ) ; String [ ] arr_result = new String [ n ] ; Arrays . fill ( arr_result , " 0 " ) ; for ( int i = n - 1 ; i >= 1 ; i -- ) { int a = Integer . valueOf ( arr02 [ i - 1 ] ) ; int val = Integer . valueOf ( arr_result [ a - 1 ] ) ; arr_result [ a - 1 ] = String . valueOf ( val + 1 ) ; } String result = String . join ( System . getProperty ( " line.separator " ) , arr_result ) ; System . out . println ( result ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int [ ] [ ] A = new int [ N + 1 ] [ 3 ] ; for ( int i = 1 ; i <= N ; i ++ ) { for ( int j = 0 ; j < 3 ; j ++ ) { A [ i ] [ j ] = sc . nextInt ( ) ; } } A [ 0 ] [ 0 ] = 0 ; A [ 0 ] [ 1 ] = 0 ; A [ 0 ] [ 2 ] = 0 ; sc . close ( ) ; int count = 0 ; for ( int i = 1 ; i <= N ; i ++ ) { int tmp = Math . abs ( A [ i ] [ 1 ] - A [ i - 1 ] [ 1 ] ) + Math . abs ( A [ i ] [ 2 ] - A [ i - 1 ] [ 2 ] ) ; int tmp2 = Math . abs ( A [ i ] [ 0 ] - A [ i - 1 ] [ 0 ] ) ; if ( ( tmp2 % 2 == tmp % 2 ) && tmp2 >= tmp ) { count ++ ; } } if ( count == N ) { System . out . println ( " Yes " ) ; } else { int i = 1 ; System . out . println ( " No " ) ; } } } +import java . util . Scanner ; import java . util . * ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int k = sc . nextInt ( ) ; int [ ] arr = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { arr [ i ] = sc . nextInt ( ) ; } Arrays . sort ( arr ) ; int sum = 0 ; for ( int i = 0 ; i < k && i < n ; i ++ ) { sum += arr [ i ] ; } System . out . println ( sum ) ; sc . close ( ) ; } } +import java . io . IOException ; public class Main { public static void main ( String [ ] args ) throws IOException { int bit = 0 ; int over = 0 ; int num ; int buf ; StringBuilder builder = new StringBuilder ( ) ; while ( ( buf = System . in . read ( ) ) != '\n' ) { } while ( true ) { builder . setLength ( 0 ) ; while ( ( buf = System . in . read ( ) ) != ' ' && buf != '\n' ) { builder . appendCodePoint ( buf ) ; } num = Integer . parseInt ( builder . toString ( ) ) / 400 ; if ( num < 1 ) { bit |= 1 ; } else if ( num < 2 ) { bit |= 2 ; } else if ( num < 3 ) { bit |= 4 ; } else if ( num < 4 ) { bit |= 8 ; } else if ( num < 5 ) { bit |= 16 ; } else if ( num < 6 ) { bit |= 32 ; } else if ( num < 7 ) { bit |= 64 ; } else if ( num < 8 ) { StringBuilder builder = new StringBuilder ( ) ; bit |= 128 ; } else { over ++ ; } if ( buf == '\n' ) break ; } int count = Integer . bitCount ( bit ) ; int max = count + over ; if ( count == 0 ) count = 1 ; System . out . print ( count + " " + max ) ; } } +import java . io . PrintStream ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = null ; PrintStream out = null ; try { sc = new Scanner ( System . in ) ; out = System . out ; exec ( sc , out ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; System . exit ( 1 ) ; } finally { if ( out != null ) { out . close ( ) ; } if ( sc != null ) { sc . close ( ) ; } } System . exit ( 0 ) ; } public static void exec ( final Scanner sc , final PrintStream out ) throws Exception { int i = 0 ; final String S = sc . next ( ) ; final String T = sc . next ( ) ; int cnt = 0 ; for ( int i = 0 ; i < 3 ; i ++ ) { if ( S . charAt ( i ) == T . charAt ( i ) ) { cnt ++ ; } } out . println ( cnt ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] t = new int [ n ] ; int [ ] x = new int [ n ] ; int [ ] y = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { t [ i ] = sc . nextInt ( ) ; x [ i ] = sc . nextInt ( ) ; y [ i ] = sc . nextInt ( ) ; } int tt = 0 ; int xx = 0 ; int yy = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int tmpT = t [ i ] - tt ; int tmpX = Math . abs ( x [ i ] - xx ) ; int tmpY = Math . abs ( y [ i ] - yy ) ; if ( tmpX + tmpY > tmpT ) { System . out . println ( " No " ) ; return ; } if ( tmpT % 2 != ( tmpX + tmpY ) % 2 ) { int i = 0 ; System . out . println ( " No " ) ; return ; } tt = t [ i ] ; xx = x [ i ] ; yy = y [ i ] ; } System . out . println ( " Yes " ) ; } } +import java . io . * ; import java . util . * ; class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; while ( true ) { StringTokenizer st = new StringTokenizer ( br . readLine ( ) ) ; int m = Integer . parseInt ( st . nextToken ( ) ) ; int f = Integer . parseInt ( st . nextToken ( ) ) ; int r = Integer . parseInt ( st . nextToken ( ) ) ; if ( m == - 1 && f == - 1 && r == - 1 ) { break ; } if ( m == - 1 || f == - 1 ) { System . out . println ( " F " ) ; } else if ( ( m + f ) >= 80 ) { System . out . println ( " A " ) ; } else if ( ( m + f ) >= 65 ) { System . out . println ( " B " ) ; } else if ( ( ( m + f ) >= 50 ) || ( ( m + f ) >= 30 && r >= 50 ) ) { System . out . println ( " C " ) ; } else if ( ( m + f ) >= 30 ) { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; System . out . println ( " D " ) ; } else { System . out . println ( " F " ) ; } } } } +import java . io . * ; import java . util . * ; public class Main { private static final BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; private static StringTokenizer st ; private static int readInt ( ) throws IOException { while ( st == null || ! st . hasMoreTokens ( ) ) st = new StringTokenizer ( br . readLine ( ) ) ; return Integer . parseInt ( st . nextToken ( ) ) ; } public static void main ( String [ ] args ) throws IOException { int N = readInt ( ) ; long D = readInt ( ) ; long D_squared = D * D ; int count = 0 ; for ( int i = 0 ; i < N ; i ++ ) { int count = 0 ; long dx = readInt ( ) ; long dy = readInt ( ) ; if ( dx * dx + dy * dy <= D_squared ) count ++ ; } System . out . println ( count ) ; } } +import java . io . ByteArrayInputStream ; import java . util . Scanner ; public class Main { private static boolean strcmp ( String s , int pos , String other ) { if ( pos >= other . length ( ) ) { int len = other . length ( ) ; for ( int i = 0 ; i < len ; i ++ ) { if ( s . charAt ( pos - i - 1 ) != other . charAt ( len - i - 1 ) ) { return false ; } } return true ; } else { return false ; } } public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . nextLine ( ) ; int pos = s . length ( ) ; while ( pos > 0 ) { int pos = s . length ( ) ; if ( strcmp ( s , pos , " dream " ) ) { pos -= 5 ; } else if ( strcmp ( s , pos , " dreamer " ) ) { pos -= 7 ; } else if ( strcmp ( s , pos , " erase " ) ) { pos -= 5 ; } else if ( strcmp ( s , pos , " eraser " ) ) { pos -= 6 ; } else { System . out . println ( " NO " ) ; return ; } } System . out . println ( " YES " ) ; } } +import java . io . OutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . PrintWriter ; import java . util . StringTokenizer ; import java . io . IOException ; import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . io . InputStream ; public class Main { public static void main ( String [ ] args ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; MyScanner in = new MyScanner ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; A solver = new A ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class A { public void solve ( int testNumber , MyScanner in , PrintWriter out ) { int A = in . Int ( ) ; int B = in . Int ( ) ; out . println ( A * B ) ; } } static class MyScanner { private BufferedReader in ; private StringTokenizer st ; public MyScanner ( InputStream stream ) { in = new BufferedReader ( new InputStreamReader ( stream ) ) ; } public String next ( ) { while ( st == null || ! st . hasMoreTokens ( ) ) { try { String rl = in . readLine ( ) ; if ( rl == null ) { return null ; } st = new StringTokenizer ( rl ) ; } catch ( IOException e ) { return null ; } } return st . nextToken ( ) ; } public int Int ( ) { return Integer . parseInt ( next ( ) ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { try ( Scanner in = new Scanner ( System . in ) ) { int j = i + 1 ; int N = in . nextInt ( ) ; int [ ] d = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { d [ i ] = in . nextInt ( ) ; } int sum = 0 ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = i + 1 ; j < N ; j ++ ) { sum += d [ i ] * d [ j ] ; } } System . out . println ( sum ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; int A = sc . nextInt ( ) ; int B = sc . nextInt ( ) ; int C = sc . nextInt ( ) ; int X = sc . nextInt ( ) ; int Y = sc . nextInt ( ) ; long min = Long . MAX_VALUE ; for ( int i = 0 ; i <= 100000 ; i ++ ) { long amount = 0 ; amount = i * 2 * C + Math . max ( 0 , X - i ) * A + Math . max ( 0 , Y - i ) * B ; min = Math . min ( min , amount ) ; } System . out . println ( min ) ; } } +import java . util . Collections ; import java . util . PriorityQueue ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; try ( Scanner sc = new Scanner ( System . in ) ) { int k = sc . nextInt ( ) ; int n = sc . nextInt ( ) ; int [ ] aArray = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { aArray [ i ] = sc . nextInt ( ) ; } PriorityQueue < Integer > pq = new PriorityQueue < > ( Collections . reverseOrder ( ) ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( i == 0 ) { int dist = k - aArray [ n - 1 ] + aArray [ 0 ] ; pq . add ( dist ) ; } else { pq . add ( aArray [ i ] - aArray [ i - 1 ] ) ; } } int max = pq . poll ( ) ; System . out . println ( k - max ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] [ ] array = new int [ 2 ] [ n ] ; for ( int i = 0 ; i < 2 ; i ++ ) { int i = 1 ; for ( int j = 0 ; j < n ; j ++ ) { array [ i ] [ j ] = sc . nextInt ( ) ; } } int [ ] [ ] ans = new int [ 2 ] [ n ] ; ans [ 0 ] [ 0 ] = array [ 0 ] [ 0 ] ; for ( int i = 0 ; i < n - 1 ; i ++ ) { ans [ 0 ] [ i + 1 ] = ans [ 0 ] [ i ] + array [ 0 ] [ i + 1 ] ; } ans [ 1 ] [ 0 ] = array [ 0 ] [ 0 ] + array [ 1 ] [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { ans [ 1 ] [ i ] = Math . max ( ans [ 0 ] [ i ] , ans [ 1 ] [ i - 1 ] ) + array [ 1 ] [ i ] ; } System . out . println ( ans [ 1 ] [ n - 1 ] ) ; } } +import java . util . Arrays ; import java . util . Comparator ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = input . length - 1 ; int [ ] input = new int [ 10 ] ; Scanner s = new Scanner ( System . in ) ; for ( int i = 0 ; i < 10 ; i ++ ) { input [ i ] = s . nextInt ( ) ; } Arrays . sort ( input ) ; int i = input . length - 1 ; while ( i > input . length - 4 ) { System . out . println ( input [ i ] ) ; i -- ; } } } +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 ) ; String s = sc . next ( ) ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( i == 3 ) { int i = 0 ; System . out . print ( 8 ) ; } else { System . out . print ( s . charAt ( i ) ) ; } } System . out . println ( ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; StringBuilder sb = new StringBuilder ( ) ; String [ ] str = sc . nextLine ( ) . split ( " " ) ; String p = sc . nextLine ( ) ; for ( int i = 0 ; i < str . length ; i ++ ) { sb . setLength ( 0 ) ; for ( int j = i ; j < i + str . length ; j ++ ) { int a = j ; if ( a >= str . length ) { a -= str . length ; } sb . append ( str [ a ] ) ; } String s = sb . toString ( ) ; if ( s . contains ( p ) ) { int a = j ; System . out . println ( " Yes " ) ; break ; } else if ( i == str . length - 1 ) { System . out . println ( " No " ) ; } } } } +import java . util . ArrayList ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int count = 0 ; Scanner sc = new Scanner ( System . in ) ; int i = sc . nextInt ( ) ; ArrayList < Integer > al = new ArrayList < Integer > ( i ) ; for ( int j = 0 ; j < i ; j ++ ) { al . add ( sc . nextInt ( ) ) ; } me : while ( true ) { for ( int t = 0 ; t < i ; t ++ ) { if ( al . get ( t ) % 2 == 0 ) { int t = 0 ; al . set ( t , al . get ( t ) / 2 ) ; } else { System . out . println ( count ) ; break me ; } } count ++ ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int z = 0 ; if ( n % 2 == 0 ) { z = n / 2 ; } else { int z = 0 ; z = n / 2 + 1 ; } System . out . print ( z ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int ans = Integer . parseInt ( String . valueOf ( c ) ) ; Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; String n = String . valueOf ( N ) ; char [ ] a = n . toCharArray ( ) ; char b = a [ 0 ] ; char [ ] c = { b , b , b } ; int ans = Integer . parseInt ( String . valueOf ( c ) ) ; if ( ans >= N ) { System . out . println ( ans ) ; } else { ans += 111 ; System . out . println ( ans ) ; } sc . close ( ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String w = sc . next ( ) ; char [ ] alpha = new char [ 26 ] ; String str = " abcdefghijklmnopqrstuvwxyz " ; for ( int i = 0 ; i < 26 ; i ++ ) { alpha [ i ] = str . charAt ( i ) ; } int [ ] count = new int [ 26 ] ; for ( int i = 0 ; i < w . length ( ) ; i ++ ) { for ( int j = 0 ; j < 26 ; j ++ ) { int i = 0 ; if ( w . charAt ( i ) == alpha [ j ] ) count [ j ] ++ ; } } for ( int i = 0 ; i < 26 ; i ++ ) { if ( count [ i ] % 2 != 0 ) { System . out . println ( " No " ) ; System . exit ( 0 ) ; } } System . out . println ( " Yes " ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; long k = sc . nextLong ( ) ; for ( int i = 0 ; i < Math . min ( k , s . length ( ) ) ; i ++ ) { if ( s . charAt ( i ) != '1' ) { int i = 0 ; System . out . println ( s . charAt ( i ) ) ; return ; } } System . out . println ( 1 ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int ac = 0 ; int wa = 0 ; int tle = 0 ; int re = 0 ; for ( int i = 0 ; i < N + 1 ; i ++ ) { String S = sc . nextLine ( ) ; if ( S . equals ( " AC " ) ) { ac ++ ; } else if ( S . equals ( " WA " ) ) { wa ++ ; } else if ( S . equals ( " TLE " ) ) { tle ++ ; } else if ( S . equals ( " RE " ) ) { int re = 0 ; re ++ ; } } System . out . println ( " AC x " + ac ) ; System . out . println ( " WA x " + wa ) ; System . out . println ( " TLE x " + tle ) ; System . out . println ( " RE x " + re ) ; } } +import java . util . HashSet ; import java . util . Scanner ; import java . util . Set ; public class Main { public static void main ( String [ ] args ) { int startPos = x ; Scanner sc = new Scanner ( System . in ) ; int x = sc . nextInt ( ) ; int n = sc . nextInt ( ) ; if ( n == 0 ) { System . out . println ( x ) ; return ; } Set < Integer > p = new HashSet < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { p . add ( sc . nextInt ( ) ) ; } sc . close ( ) ; Integer underPos = null ; Integer upwardPos = null ; int startPos = x ; while ( underPos == null ) { if ( p . contains ( startPos ) != true ) { underPos = startPos ; } startPos -- ; } startPos = x ; while ( upwardPos == null ) { if ( p . contains ( startPos ) != true ) { upwardPos = startPos ; } startPos ++ ; } int underDist = Math . abs ( x - underPos ) ; int upwardDist = Math . abs ( x - upwardPos ) ; if ( underDist == upwardDist ) { System . out . println ( underPos ) ; return ; } if ( underDist < upwardDist ) { System . out . println ( underPos ) ; } else { System . out . println ( upwardPos ) ; } } } +import java . io . * ; import java . util . Arrays ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; while ( true ) { int count = 0 ; String line = br . readLine ( ) ; String [ ] spl = line . split ( " " ) ; int n = Integer . parseInt ( spl [ 0 ] ) ; int x = Integer . parseInt ( spl [ 1 ] ) ; if ( n == 0 && x == 0 ) { break ; } for ( int i = 1 ; i <= ( n - 2 ) ; i ++ ) { for ( int j = i + 1 ; j <= ( n - 1 ) ; j ++ ) { int k = j + 1 ; for ( int k = j + 1 ; k <= n ; k ++ ) { if ( i + j + k == x ) { count ++ ; } } } } System . out . println ( count ) ; } } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; long N = Long . parseLong ( br . readLine ( ) ) ; int i = 10000000 ; long O = 0 ; long T = 0 ; int o = 0 ; int t = 0 ; for ( long l = 1 ; l < ( long ) Math . sqrt ( N ) + 10 ; l ++ ) { if ( N % l == 0 ) { long l = 1 ; O = l ; T = N / l ; o = ( int ) Math . log10 ( O ) + 1 ; t = ( int ) Math . log10 ( T ) + 1 ; if ( i > ( o > t ? o : t ) ) i = ( o > t ? o : t ) ; } } System . out . println ( i ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int x = 0 ; Scanner sc = new Scanner ( System . in ) ; int i = sc . nextInt ( ) ; int [ ] arr = new int [ i ] ; for ( int x = 0 ; x < arr . length ; x ++ ) { arr [ x ] = sc . nextInt ( ) ; } boolean f = true ; Arrays . sort ( arr ) ; for ( int x = 0 ; x < arr . length - 1 ; x ++ ) { if ( arr [ x ] == arr [ x + 1 ] ) f = false ; } if ( f == true ) System . out . println ( " YES " ) ; else System . out . println ( " NO " ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int n = scanner . nextInt ( ) ; Scanner scanner = new Scanner ( System . in ) ; int n = scanner . nextInt ( ) ; if ( n < 105 ) { n = 0 ; } else if ( n < 135 ) { n = 1 ; } else if ( n < 165 ) { n = 2 ; } else if ( n < 189 ) { n = 3 ; } else if ( n < 195 ) { n = 4 ; } else { n = 5 ; } System . out . println ( n ) ; } } +import java . util . ArrayList ; import java . util . List ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; List < String > list = new ArrayList < String > ( ) ; while ( true ) { String line = sc . nextLine ( ) ; if ( line . equals ( " 0 0 " ) ) { break ; } list . add ( line ) ; } for ( String line : list ) { String [ ] string = line . split ( " " ) ; int [ ] is = new int [ 2 ] ; is [ 0 ] = Integer . parseInt ( string [ 0 ] ) ; is [ 1 ] = Integer . parseInt ( string [ 1 ] ) ; if ( is [ 0 ] <= is [ 1 ] ) { System . out . println ( is [ 0 ] + " " + is [ 1 ] ) ; } else { System . out . println ( is [ 1 ] + " " + is [ 0 ] ) ; } if ( is [ 0 ] == 0 && is [ 1 ] == 0 ) { int [ ] is = new int [ 2 ] ; break ; } } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int [ ] A = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { A [ i ] = sc . nextInt ( ) ; } int sortCount = 0 ; for ( int i = 0 ; i < N ; i ++ ) { int a ; int flag = 0 ; int minj = i ; for ( int j = i ; j < N ; j ++ ) { if ( A [ j ] < A [ minj ] ) { minj = j ; flag = 1 ; } } if ( flag == 1 ) { int tmp = A [ i ] ; A [ i ] = A [ minj ] ; A [ minj ] = tmp ; sortCount ++ ; } } String delimiter = " " ; for ( int a : A ) { System . out . print ( delimiter + a ) ; delimiter = " " ; } System . out . println ( ) ; System . out . println ( sortCount ) ; sc . close ( ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int can = 0 ; Scanner sc = new Scanner ( System . in ) ; long W = sc . nextLong ( ) ; long H = sc . nextLong ( ) ; long x = sc . nextLong ( ) ; long y = sc . nextLong ( ) ; double ans = ( W * H ) / 2.0 ; int can = 0 ; if ( x * 2 == W && y * 2 == H ) { can = 1 ; } System . out . println ( ans + " " + can ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int [ ] A = new int [ N + 1 ] ; int [ ] B = new int [ N ] ; for ( int i = 0 ; i < N + 1 ; i ++ ) A [ i ] = sc . nextInt ( ) ; for ( int i = 0 ; i < N ; i ++ ) B [ i ] = sc . nextInt ( ) ; long res = 0 ; for ( int i = 0 ; i < N ; i ++ ) { int d = Math . min ( A [ i ] , B [ i ] ) ; res += d ; A [ i ] -= d ; B [ i ] -= d ; d = Math . min ( B [ i ] , A [ i + 1 ] ) ; res += d ; A [ i + 1 ] -= d ; } System . out . println ( res ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; ArrayList < Integer > List = new ArrayList < > ( ) ; for ( int i = 0 ; i < 5 ; i ++ ) { int j = sc . nextInt ( ) ; List . add ( j ) ; } int k = sc . nextInt ( ) ; int num = 0 ; for ( int i = 0 ; i < 4 ; i ++ ) { int j = i + 1 ; for ( int j = i + 1 ; j < 5 ; j ++ ) { if ( List . get ( j ) - List . get ( i ) > k ) num ++ ; } } if ( num == 0 ) System . out . println ( " Yay! " ) ; else System . out . println ( " :( " ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader in = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int range = Integer . parseInt ( in . readLine ( ) ) ; if ( range < 0 || Math . pow ( 10 , 4 ) < range ) throw new RuntimeException ( " error:range " ) ; String [ ] nums = new String [ range ] ; nums = in . readLine ( ) . split ( " " ) ; int min = Integer . parseInt ( nums [ 0 ] ) , max = Integer . parseInt ( nums [ 0 ] ) ; long sum = 0 ; for ( int i = 0 ; i < range ; i += 1 ) { int i = 0 ; max = Math . max ( max , Integer . parseInt ( nums [ i ] ) ) ; min = Math . min ( min , Integer . parseInt ( nums [ i ] ) ) ; if ( Integer . parseInt ( nums [ i ] ) < - Math . pow ( 10 , 6 ) || Math . pow ( 10 , 6 ) < Integer . parseInt ( nums [ i ] ) ) throw new RuntimeException ( " error:nums " ) ; sum = sum + Integer . parseInt ( nums [ i ] ) ; } System . out . println ( min + " " + max + " " + sum ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int number_n , i , answer ; int sum = 0 ; int temp_a = 0 ; int temp_b = 0 ; number_n = Integer . parseInt ( sc . next ( ) ) ; int [ ] weight = new int [ number_n ] ; for ( i = 0 ; i < number_n ; i ++ ) { weight [ i ] = Integer . parseInt ( sc . next ( ) ) ; sum += weight [ i ] ; } for ( i = 0 ; i < number_n ; i ++ ) { temp_a += weight [ i ] ; if ( sum <= 2 * temp_a ) { break ; } else { temp_b = temp_a ; } } temp_a = sum - 2 * temp_a ; temp_b = sum - 2 * temp_b ; temp_a = Math . abs ( temp_a ) ; temp_b = Math . abs ( temp_b ) ; if ( temp_b < temp_a ) { int [ ] weight = new int [ number_n ] ; answer = temp_b ; } else { answer = temp_a ; } System . out . println ( answer ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 1 ; Scanner scan = new Scanner ( System . in ) ; int a = scan . nextInt ( ) , b = scan . nextInt ( ) , c = scan . nextInt ( ) ; int count = 0 ; for ( int i = 1 ; i <= c ; i ++ ) { if ( a <= i && i <= b ) { if ( c % i == 0 ) { count ++ ; } } } System . out . println ( count ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws IOException { String readStr ; BufferedReader reader = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String readStr ; int c = 0 ; while ( ( readStr = reader . readLine ( ) ) != null ) { int [ ] list = new int [ 3 ] ; list [ 0 ] = Integer . parseInt ( readStr . split ( " " ) [ 0 ] ) ; list [ 1 ] = Integer . parseInt ( readStr . split ( " " ) [ 1 ] ) ; String sssss = String . format ( " %.6f " , ( 1.0 * list [ 0 ] / list [ 1 ] ) ) ; System . out . println ( ( int ) ( list [ 0 ] / list [ 1 ] ) + " " + ( list [ 0 ] % list [ 1 ] ) + " " + sssss ) ; break ; } } } +import java . util . HashSet ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int N = scanner . nextInt ( ) ; String s ; HashSet < String > list = new HashSet < String > ( N ) ; for ( int i = 0 ; i < N ; i ++ ) { HashSet < String > list = new HashSet < String > ( N ) ; s = scanner . next ( ) ; list . add ( s ) ; } System . out . println ( list . size ( ) ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] st = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { st [ i ] = sc . nextInt ( ) ; } Arrays . sort ( st ) ; int a = st [ 0 ] ; int b = st [ n - 1 ] ; System . out . println ( Math . abs ( a - b ) ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public Main ( ) { } static int input ; public static void main ( String [ ] args ) throws NumberFormatException , IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String str = br . readLine ( ) ; input = Integer . parseInt ( str ) ; System . out . println ( ( int ) Math . pow ( input , 3 ) ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int a = scanner . nextInt ( ) ; int b = scanner . nextInt ( ) ; int tax8pricemin = ( int ) ( ( ( double ) a ) / 0.08 ) ; int tax8pricemax = ( int ) ( ( ( double ) a + 1 ) / 0.08 ) ; for ( int i = tax8pricemin ; i < tax8pricemax ; i ++ ) { int i = tax8pricemin ; int tax8 = ( int ) ( i * 0.08 ) ; int tax10 = ( int ) ( i * 0.1 ) ; if ( tax8 == a && tax10 == b ) { System . out . println ( i ) ; System . exit ( 0 ) ; } } System . out . println ( - 1 ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner s = new Scanner ( System . in ) ; int n = s . nextInt ( ) ; int k = s . nextInt ( ) ; long [ ] h = new long [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { h [ i ] = s . nextLong ( ) ; } long [ ] dp = new long [ n ] ; dp [ 0 ] = 0 ; dp [ 1 ] = Math . abs ( h [ 1 ] - h [ 0 ] ) ; for ( int i = 2 ; i < n ; i ++ ) { dp [ i ] = Long . MAX_VALUE ; for ( int j = 1 ; j <= k ; j ++ ) { int j = 1 ; if ( i - j >= 0 ) { long op1 = dp [ i - j ] + Math . abs ( h [ i ] - h [ i - j ] ) ; dp [ i ] = Math . min ( dp [ i ] , op1 ) ; } else { break ; } } } System . out . println ( dp [ n - 1 ] ) ; } } +import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . io . IOException ; import java . util . StringTokenizer ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader in = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int n = Integer . parseInt ( in . readLine ( ) ) ; StringTokenizer stk = new StringTokenizer ( in . readLine ( ) ) ; String s = stk . nextToken ( ) ; String abc = " ABC " ; int cnt = 0 ; for ( int i = 0 ; i + 3 <= n ; i ++ ) { int i = 0 ; if ( s . substring ( i , i + 3 ) . equals ( abc ) ) cnt ++ ; } System . out . println ( cnt ) ; } } +import java . util . Scanner ; public class Main { private static Scanner scan = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { String SA = scan . next ( ) ; String SB = scan . next ( ) ; String SC = scan . next ( ) ; int sa = 0 ; int sb = 0 ; int sc = 0 ; char next = 'a' ; boolean flag = true ; char winner = 0 ; while ( flag ) { switch ( next ) { case 'a' : if ( sa == SA . length ( ) ) { char winner = 0 ; flag = false ; winner = 'A' ; } else { next = SA . charAt ( sa ) ; sa ++ ; } break ; case 'b' : if ( sb == SB . length ( ) ) { flag = false ; winner = 'B' ; } else { next = SB . charAt ( sb ) ; sb ++ ; } break ; case 'c' : if ( sc == SC . length ( ) ) { flag = false ; winner = 'C' ; } else { next = SC . charAt ( sc ) ; sc ++ ; } break ; } } System . out . println ( winner ) ; scan . close ( ) ; } } +import java . util . ArrayDeque ; import java . util . Deque ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int n , q , t ; int t_sum = 0 ; String pros ; Deque < String > name = new ArrayDeque < > ( ) ; Deque < Integer > time = new ArrayDeque < > ( ) ; Scanner sc = new Scanner ( System . in ) ; n = sc . nextInt ( ) ; q = sc . nextInt ( ) ; for ( int i = 0 ; i < n ; i ++ ) { name . offerLast ( sc . next ( ) ) ; time . offerLast ( sc . nextInt ( ) ) ; } while ( time . size ( ) != 0 ) { Scanner sc = new Scanner ( System . in ) ; t = time . poll ( ) ; if ( t <= q ) { t_sum += t ; pros = name . poll ( ) ; System . out . println ( pros + " " + t_sum ) ; } else { t_sum += q ; time . offerLast ( t - q ) ; name . offerLast ( name . poll ( ) ) ; } } } } +import java . io . StringReader ; import java . util . ArrayList ; import java . util . List ; import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int num = scanner . nextInt ( ) ; int pointSum = 0 ; scanner . useDelimiter ( " [ \r \n ]+ " ) ; scanner = new Scanner ( new StringReader ( scanner . next ( ) ) ) ; List < Integer > users = new ArrayList < > ( ) ; while ( scanner . hasNextInt ( ) ) { Integer u ; int user = scanner . nextInt ( ) ; users . add ( user ) ; pointSum += user ; } int middle = pointSum / num ; if ( ( pointSum % num ) > ( ( double ) num / 2 ) ) { middle ++ ; } long sum = 0 ; for ( Integer u : users ) { sum += Math . pow ( u - middle , 2 ) ; } System . out . println ( sum ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . nio . charset . StandardCharsets ; public class Main { public static void main ( String [ ] args ) throws IOException { InputStreamReader reader = new InputStreamReader ( System . in , StandardCharsets . UTF_8 ) ; BufferedReader in = new BufferedReader ( reader ) ; String s = in . readLine ( ) ; int n = Integer . parseInt ( s ) ; s = in . readLine ( ) ; String [ ] as = s . split ( " " ) ; int [ ] a = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { int i = 0 ; a [ i ] = Integer . parseInt ( as [ i ] ) ; } output ( a ) ; insertionSort ( a , n ) ; } private static void insertionSort ( int [ ] a , int n ) { for ( int i = 1 ; i < n ; i ++ ) { int v = a [ i ] ; int j = i - 1 ; while ( j >= 0 && a [ j ] > v ) { a [ j + 1 ] = a [ j ] ; j -- ; } a [ j + 1 ] = v ; output ( a ) ; } } private static void output ( int [ ] a ) { for ( int i = 0 ; i < a . length - 1 ; i ++ ) { System . out . print ( a [ i ] + " " ) ; } System . out . println ( a [ a . length - 1 ] ) ; } } +import java . io . PrintWriter ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { try ( InputReader in = new InputReader ( ) ; PrintWriter out = new PrintWriter ( System . out ) ) { new Main ( ) . solve ( in , out ) ; out . flush ( ) ; } } void solve ( InputReader in , PrintWriter out ) { int N = in . nextInt ( ) ; int M = in . nextInt ( ) ; int cL = 0 ; int cR = N + 1 ; for ( int i = 0 ; i < M ; i ++ ) { int L = in . nextInt ( ) ; int R = in . nextInt ( ) ; cL = Math . max ( cL , L ) ; cR = Math . min ( cR , R ) ; } if ( cR - cL < 0 ) { int cR = N + 1 ; out . println ( 0 ) ; } else if ( cR == cL ) { out . println ( 1 ) ; } else { out . println ( cR - cL + 1 ) ; } } } class InputReader implements AutoCloseable { private final Scanner sc = new Scanner ( System . in ) ; String next ( ) { return this . sc . next ( ) ; } int nextInt ( ) { return Integer . parseInt ( this . sc . next ( ) ) ; } long nextLong ( ) { return Long . parseLong ( this . sc . next ( ) ) ; } double nextDouble ( ) { return Double . parseDouble ( this . sc . next ( ) ) ; } @ Override public void close ( ) { this . sc . close ( ) ; } } +import java . util . * ; public class Main { Scanner sc = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { new Main ( ) . run ( ) ; } void run ( ) { int n = sc . nextInt ( ) ; int [ ] arr = new int [ n ] ; int [ ] check = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { arr [ i ] = sc . nextInt ( ) ; } int res = 0 ; while ( ! Arrays . equals ( arr , check ) ) { int i = cp ; int l = 0 ; int min = Integer . MAX_VALUE ; while ( l < n && arr [ l ] == 0 ) { l ++ ; } int cp = l ; while ( l < n && arr [ l ] != 0 ) { min = Math . min ( min , arr [ l ] ) ; l ++ ; } for ( int i = cp ; i < l ; i ++ ) { arr [ i ] -= min ; } res += min ; } System . out . println ( res ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; System . out . println ( solve ( n ) ) ; } public static int solve ( int n ) { int max = ( int ) Math . pow ( n , 0.5 ) + 1 ; int ret = 1 ; for ( int i = 2 ; i < max ; i ++ ) { int pow = 2 ; while ( Math . pow ( i , pow ) <= n ) { int pow = 2 ; ret = Math . max ( ret , ( int ) Math . pow ( i , pow ) ) ; pow ++ ; } } return ret ; } } +import java . lang . reflect . Array ; import java . util . ArrayList ; import java . util . List ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; List < String [ ] > list = new ArrayList < > ( ) ; int count = 0 ; int N = 0 ; int M = 0 ; while ( scan . hasNext ( ) ) { if ( count == 0 ) { N = scan . nextInt ( ) ; M = scan . nextInt ( ) ; count ++ ; continue ; } String str = scan . nextLine ( ) ; String [ ] sp = str . split ( " " ) ; list . add ( sp ) ; count ++ ; if ( count > N + 1 ) { break ; } } int [ ] result = new int [ 30 ] ; for ( int i = 1 ; i <= N ; i ++ ) { int r ; for ( int j = 1 ; j <= Integer . parseInt ( list . get ( i ) [ 0 ] ) ; j ++ ) { result [ Integer . parseInt ( list . get ( i ) [ j ] ) - 1 ] ++ ; } } int resultCount = 0 ; for ( int r : result ) { if ( r == N ) { resultCount ++ ; } } System . out . print ( resultCount ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner scan = new Scanner ( System . in ) ; int n = scan . nextInt ( ) ; int m = scan . nextInt ( ) ; int [ ] [ ] vectorA = new int [ n ] [ m ] ; int [ ] vectorB = new int [ m ] ; int [ ] vectorC = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < m ; j ++ ) { int elm = scan . nextInt ( ) ; vectorA [ i ] [ j ] = elm ; } } for ( int i = 0 ; i < m ; i ++ ) { int elm = scan . nextInt ( ) ; vectorB [ i ] = elm ; } for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < m ; j ++ ) { vectorC [ i ] += vectorA [ i ] [ j ] * vectorB [ j ] ; } } for ( int i = 0 ; i < n ; i ++ ) { System . out . println ( vectorC [ i ] ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int j = 1 ; Diagram diagram = new Diagram ( ) ; try ( Scanner stdin = new Scanner ( System . in ) ) { int h , w ; while ( stdin . hasNext ( ) ) { h = Integer . parseInt ( stdin . next ( ) ) ; w = Integer . parseInt ( stdin . next ( ) ) ; if ( h < 0 || h > 300 || w < 0 || w > 300 ) { throw new RuntimeException ( " Input Error:Range 0 to 300 " ) ; } if ( h == 0 && w == 0 ) { break ; } diagram . draw ( h , w ) ; System . out . println ( " " ) ; } } catch ( RuntimeException e ) { e . printStackTrace ( ) ; } } } abstract class AbstractDiagram { abstract void draw ( int height , int width ) ; } class Diagram extends AbstractDiagram { @ Override void draw ( int h , int w ) { StringBuilder sb = new StringBuilder ( ) ; for ( int i = 1 ; i <= h ; i ++ ) { for ( int j = 1 ; j <= w ; j ++ ) { if ( ( i == 1 || i == h ) || ( j == 1 || j == w ) ) { sb . append ( '#' ) ; } else { sb . append ( '.' ) ; } } System . out . println ( sb ) ; sb . setLength ( 0 ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; int n = s . length ( ) ; int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int k = 0 ; for ( int j = i + 1 ; j <= n ; j ++ ) { String str = s . substring ( i , j ) ; int cnt = 0 ; for ( int k = 0 ; k < str . length ( ) ; k ++ ) { char ch = str . charAt ( k ) ; if ( ! ( ch == 'A' || ch == 'C' || ch == 'G' || ch == 'T' ) ) { cnt = 0 ; break ; } cnt ++ ; } ans = Math . max ( ans , cnt ) ; } } System . out . println ( ans ) ; } } +import java . util . * ; class Main { static Scanner s = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { int i = 0 ; StringBuilder str = new StringBuilder ( s . next ( ) . replaceAll ( " eraser " , " " ) . replaceAll ( " dream " , " D " ) . replaceAll ( " er " , " R " ) . replaceAll ( " as " , " A " ) ) ; String [ ] m = { " RAe " , " DR " , " D " } ; String b , st ; boolean f ; do { f = false ; for ( int i = 0 ; i < m . length ; i ++ ) { b = m [ i ] ; st = str . toString ( ) ; if ( st . endsWith ( b ) ) { str . delete ( str . length ( ) - b . length ( ) , str . length ( ) ) ; f = true ; break ; } } } while ( f ) ; System . out . println ( ( str . toString ( ) . equals ( " " ) ) ? " YES " : " NO " ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner scan = new Scanner ( System . in ) ; int K = scan . nextInt ( ) ; int A = scan . nextInt ( ) ; int B = scan . nextInt ( ) ; int count = 0 ; for ( int i = 0 ; i < B - A + 1 ; i ++ ) { if ( ( A + i ) % K == 0 ) { count += 1 ; } else { } } if ( count > 0 ) { System . out . println ( " OK " ) ; } if ( count == 0 ) { System . out . println ( " NG " ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int [ ] P = new int [ N ] ; P [ 0 ] = sc . nextInt ( ) ; int error = 0 ; boolean asc = true ; boolean once = true ; for ( int i = 1 ; i < N ; i ++ ) { P [ i ] = sc . nextInt ( ) ; if ( once && ! asc && error - 1 == P [ i - 1 ] ) { int i = 1 ; asc = true ; once = false ; } else if ( P [ i ] < P [ i - 1 ] ) { error = P [ i - 1 ] ; asc = false ; } } System . out . println ( asc ? " YES " : " NO " ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] result = new int [ n ] ; for ( int i = 1 ; sc . hasNextInt ( ) ; i ++ ) { result [ sc . nextInt ( ) - 1 ] = i ; } StringBuilder sb = new StringBuilder ( ) ; for ( int i = 0 ; i < n ; i ++ ) { sb . append ( result [ i ] ) ; if ( i != n ) { int i = 0 ; sb . append ( " " ) ; } else { sb . append ( " \n " ) ; } } System . out . println ( sb . toString ( ) ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int N = scan . nextInt ( ) ; int Y = scan . nextInt ( ) ; for ( int x = 0 ; x <= N ; x ++ ) { int y = 0 ; for ( int y = 0 ; y <= N - x ; y ++ ) { int total = x * 10000 + y * 5000 + 1000 * ( N - x - y ) ; if ( total == Y ) { System . out . println ( x + " " + y + " " + ( N - x - y ) ) ; return ; } } } System . out . println ( " -1 -1 -1 " ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int a = scanner . nextInt ( ) ; int b = scanner . nextInt ( ) ; int c = scanner . nextInt ( ) ; int x = scanner . nextInt ( ) ; int y = scanner . nextInt ( ) ; int sum = 0 ; if ( a + b < c * 2 ) { int sum2 = sum ; sum = a * x + b * y ; System . out . println ( sum ) ; } else { while ( x >= 1 && y >= 1 ) { sum += c * 2 ; x -- ; y -- ; } int sum2 = sum ; sum += a * x + b * y ; if ( a > c * 2 || b > c * 2 ) { while ( x >= 1 || y >= 1 ) { sum2 += c * 2 ; x -- ; y -- ; } x = 0 ; y = 0 ; } sum2 += a * x + b * y ; if ( sum < sum2 ) { System . out . println ( sum ) ; } else { System . out . println ( sum2 ) ; } } } } +import java . util . Arrays ; import java . util . Collections ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int N = scanner . nextInt ( ) ; Integer [ ] nums = new Integer [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { int i = 0 ; nums [ i ] = scanner . nextInt ( ) ; } int diff = 0 ; boolean isEven = ( N % 2 ) == 0 ; Arrays . sort ( nums , Collections . reverseOrder ( ) ) ; int pairLastIndex = isEven ? N - 1 : N - 2 ; for ( int i = 0 ; i < pairLastIndex ; i = i + 2 ) { diff += nums [ i ] - nums [ i + 1 ] ; } if ( ! isEven ) diff += nums [ N - 1 ] ; System . out . println ( diff ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; long a = scan . nextLong ( ) ; long b = scan . nextLong ( ) ; long c = scan . nextLong ( ) ; long d = scan . nextLong ( ) ; scan . close ( ) ; long numC = b / c - ( a - 1 ) / c ; long numD = b / d - ( a - 1 ) / d ; long lcmCD = lcm ( c , d ) ; long numCD = b / lcmCD - ( a - 1 ) / lcmCD ; System . out . println ( b - a + 1 - numC - numD + numCD ) ; } public static long lcm ( long a , long b ) { return a * b / gcd ( a , b ) ; } public static long gcd ( long a , long b ) { if ( a < b ) { long b = scan . nextLong ( ) ; return gcd ( b , a ) ; } if ( b == 0 ) { return a ; } return gcd ( b , a % b ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner s = new Scanner ( System . in ) ; int a = s . nextInt ( ) ; long sum = 0 ; for ( int i = 0 ; i < a ; i ++ ) { int i = 0 ; if ( ( i + 1 ) % 3 != 0 ) { if ( ( i + 1 ) % 5 != 0 ) { sum = sum + ( i + 1 ) ; } } } System . out . println ( sum ) ; } } +import java . util . * ; import java . util . ArrayList ; import java . util . Collections ; import java . util . HashMap ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long L = sc . nextLong ( ) ; long R = sc . nextLong ( ) ; long ans = Long . MAX_VALUE ; loop : for ( long i = L ; i <= R ; i ++ ) { for ( long j = i + 1 ; j <= R ; j ++ ) { ans = Math . min ( ans , ( i * j ) % 2019 ) ; if ( ans == 0 ) { long j = i + 1 ; break loop ; } } } System . out . println ( ans ) ; } } +import java . util . HashMap ; import java . util . Map ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; Map < Integer , Integer > map = new HashMap < > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { map . put ( i , sc . nextInt ( ) ) ; } int cnt = 0 ; cnt += map . get ( 0 ) ; for ( int i = 1 ; i < N ; i ++ ) { int i = 1 ; if ( map . get ( i - 1 ) < map . get ( i ) ) { cnt += map . get ( i ) - map . get ( i - 1 ) ; } } System . out . println ( cnt ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i ; Scanner scan = new Scanner ( System . in ) ; int N = scan . nextInt ( ) ; int M = scan . nextInt ( ) ; int [ ] num_road = new int [ N ] ; int [ ] a = new int [ M ] ; int [ ] b = new int [ M ] ; int i ; for ( i = 0 ; i < N ; i ++ ) { num_road [ i ] = 0 ; } for ( i = 0 ; i < M ; i ++ ) { a [ i ] = scan . nextInt ( ) ; b [ i ] = scan . nextInt ( ) ; num_road [ a [ i ] - 1 ] ++ ; num_road [ b [ i ] - 1 ] ++ ; } for ( i = 0 ; i < N ; i ++ ) { System . out . println ( num_road [ i ] ) ; } } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner scn = new Scanner ( System . in ) ; String [ ] s = { " SUN " , " MON " , " TUE " , " WED " , " THU " , " FRI " , " SAT " } ; String input = scn . next ( ) ; int j = 0 ; for ( int i = 0 ; i <= 6 ; i ++ ) { int i = 0 ; if ( input . equals ( s [ i ] ) ) j = 7 - i ; } System . out . println ( j ) ; } } +import java . util . * ; import java . lang . * ; import java . io . * ; import java . math . * ; public class Main { public static void main ( String [ ] args ) throws java . lang . Exception { PrintWriter out = new PrintWriter ( System . out ) ; FastScanner fs = new FastScanner ( ) ; long a = fs . nextLong ( ) ; double b = fs . nextDouble ( ) ; BigDecimal bg1 = BigDecimal . valueOf ( a ) ; BigDecimal bg2 = BigDecimal . valueOf ( b ) ; out . println ( bg1 . multiply ( bg2 ) . setScale ( 0 , RoundingMode . DOWN ) ) ; out . close ( ) ; } static class FastScanner { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; StringTokenizer st = new StringTokenizer ( " " ) ; String next ( ) { while ( ! st . hasMoreTokens ( ) ) try { st = new StringTokenizer ( br . readLine ( ) ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } return st . nextToken ( ) ; } int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } int [ ] readArray ( int n ) { int [ ] a = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) a [ i ] = nextInt ( ) ; return a ; } long nextLong ( ) { return Long . parseLong ( next ( ) ) ; } double nextDouble ( ) { int [ ] a = new int [ n ] ; return Double . parseDouble ( next ( ) ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long a = sc . nextLong ( ) ; long b = sc . nextLong ( ) ; long c = 0 ; int i = 1 ; while ( i <= b ) { if ( ( long ) a * i % b == 0 ) { int i = 1 ; c = ( long ) a * i ; break ; } else { i ++ ; } } System . out . println ( c ) ; sc . close ( ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; long a = sc . nextLong ( ) ; long b = sc . nextLong ( ) ; long c = sc . nextLong ( ) ; long d = sc . nextLong ( ) ; long divc = b / c - ( a - 1 ) / c ; long divd = b / d - ( a - 1 ) / d ; long lcmcd = lcm ( c , d ) ; long divcd = b / lcmcd - ( a - 1 ) / lcmcd ; System . out . println ( ( b - a + 1 ) - divc - divd + divcd ) ; } private static long gcd ( long a , long b ) { long b = sc . nextLong ( ) ; while ( b > 0 ) { long temp = b ; b = a % b ; a = temp ; } return a ; } private static long lcm ( long a , long b ) { return a * ( b / gcd ( a , b ) ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int n = in . nextInt ( ) ; int [ ] order = new int [ n + 1 ] ; for ( int i = 1 ; i <= n ; i ++ ) { int i = 1 ; order [ in . nextInt ( ) ] = i ; } for ( int i = 1 ; i <= n ; i ++ ) { System . out . print ( order [ i ] + " " ) ; } in . close ( ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; String num = scan . nextLine ( ) ; String str = scan . nextLine ( ) ; String str_cha = " ABCDEFGHIJKLMNOPQRSTUVWXYZ " ; int number = Integer . parseInt ( num ) ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { for ( int j = 0 ; j < str_cha . length ( ) ; j ++ ) { int j = 0 ; if ( str . charAt ( i ) == str_cha . charAt ( j ) ) { System . out . print ( str_cha . charAt ( ( j + number ) % 26 ) ) ; } } } System . out . print ( " \n " ) ; } } +import java . io . * ; import java . util . * ; class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int i ; int j ; while ( true ) { String [ ] str = br . readLine ( ) . split ( " " ) ; int h = Integer . parseInt ( str [ 0 ] ) ; int w = Integer . parseInt ( str [ 1 ] ) ; if ( h == 0 || w == 0 ) break ; for ( i = 0 ; i < h ; i ++ ) { System . out . print ( " " ) ; for ( j = 0 ; j < w - 1 ; j ++ ) { if ( ( i % 2 != 0 && j % 2 == 0 ) ^ ( i % 2 == 0 && j % 2 != 0 ) ) { System . out . print ( " . " ) ; } else { int w = Integer . parseInt ( str [ 1 ] ) ; System . out . print ( " # " ) ; } } if ( ( i % 2 != 0 && j % 2 == 0 ) ^ ( i % 2 == 0 && j % 2 != 0 ) ) { System . out . println ( " . " ) ; } else { System . out . println ( " # " ) ; } } System . out . print ( " \n " ) ; } } } +import java . util . Scanner ; public class Main { static int r = 0 ; public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int D = sc . nextInt ( ) ; int [ ] [ ] X = new int [ N ] [ D ] ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < D ; j ++ ) { X [ i ] [ j ] = sc . nextInt ( ) ; } } sc . close ( ) ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = i + 1 ; j < N ; j ++ ) { solve ( D , X , i , j ) ; } } System . out . println ( r ) ; } static void solve ( int D , int [ ] [ ] X , int idx1 , int idx2 ) { int sum = 0 ; for ( int i = 0 ; i < D ; i ++ ) { int yx = Math . abs ( X [ idx1 ] [ i ] - X [ idx2 ] [ i ] ) ; sum += yx * yx ; } double sqrt1 = Math . sqrt ( sum ) ; int sqrt2 = ( int ) sqrt1 ; if ( sqrt1 == ( double ) sqrt2 ) r ++ ; } } +import java . util . * ; import java . math . BigDecimal ; import java . math . RoundingMode ; public class Main { public static void main ( String [ ] args ) { int i = 1 ; Scanner sc = new Scanner ( System . in ) ; int A = sc . nextInt ( ) ; int B = sc . nextInt ( ) ; double a1 = 0.08 ; double b1 = 0.1 ; double s = 0 ; int ans = - 1 ; int s1 = 0 ; double t = 0 ; double t1 = 0 ; for ( int i = 1 ; i < 10000 ; i ++ ) { s = i * 0.08 ; s1 = ( int ) s ; t = i * 0.1 ; t1 = ( int ) t ; if ( s1 == A && t1 == B ) { ans = i ; break ; } } System . out . print ( ans ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = Integer . parseInt ( sc . next ( ) ) ; int [ ] v = new int [ N ] ; int [ ] c = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { v [ i ] = Integer . parseInt ( sc . next ( ) ) ; } for ( int i = 0 ; i < N ; i ++ ) { c [ i ] = Integer . parseInt ( sc . next ( ) ) ; } int count = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( c [ i ] < v [ i ] ) { int i = 0 ; count += v [ i ] - c [ i ] ; } } System . out . println ( count ) ; } } +import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long [ ] inputs = new long [ 3 ] ; for ( int i = 0 ; i < 3 ; i ++ ) { inputs [ i ] = sc . nextLong ( ) ; } Arrays . sort ( inputs ) ; for ( int i = 0 ; i < 3 ; i ++ ) { int i = 0 ; System . out . print ( inputs [ i ] + ( ( i != 2 ) ? " " : " " ) ) ; } System . out . println ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Main main = new Main ( ) ; main . run ( ) ; } public void run ( ) { Scanner sc = new Scanner ( System . in ) ; long a = sc . nextLong ( ) ; long b = sc . nextLong ( ) ; long ans = lcm ( a , b ) ; System . out . println ( ans ) ; sc . close ( ) ; } public long gcd ( long a , long b ) { if ( b == 0 ) { long ans = gcd ( b , a % b ) ; return a ; } long ans = gcd ( b , a % b ) ; return ans ; } public long lcm ( long a , long b ) { long g = gcd ( a , b ) ; return a * b / g ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner scan = new Scanner ( System . in ) ; ; while ( true ) { Scanner scan = new Scanner ( System . in ) ; i ++ ; int a = scan . nextInt ( ) ; if ( a == 0 ) { break ; } System . out . println ( " Case " + i + " : " + a ) ; } scan . close ( ) ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; String [ ] S = scan . nextLine ( ) . split ( " " ) ; int count = 0 ; for ( int i = 0 ; i < S . length / 2 ; i ++ ) { if ( ! ( S [ i ] . equals ( S [ S . length - 1 - i ] ) ) ) { int i = 0 ; count ++ ; } } System . out . println ( count ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner scan = new Scanner ( System . in ) ; int w = scan . nextInt ( ) ; int [ ] x = new int [ w ] ; for ( int i = 0 ; i < w ; i ++ ) { x [ i ] = i + 1 ; } int n = scan . nextInt ( ) ; for ( int i = 0 ; i < n ; i ++ ) { String str = scan . next ( ) ; String [ ] strAry = str . split ( " , " ) ; int a = Integer . parseInt ( strAry [ 0 ] ) - 1 ; int b = Integer . parseInt ( strAry [ 1 ] ) - 1 ; int t = x [ a ] ; x [ a ] = x [ b ] ; x [ b ] = t ; } for ( int i = 0 ; i < w ; i ++ ) { System . out . println ( x [ i ] ) ; } } } +import java . util . Scanner ; public class Main { public static void select_Sort ( int n , int [ ] A ) { int i = 0 ; int min = 0 ; int mini = 0 ; int x = 0 ; int sortNum = 0 ; for ( int i = 0 ; i < n - 1 ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { if ( j == i + 1 ) { min = A [ j ] ; mini = j ; } if ( min > A [ j ] ) { min = A [ j ] ; mini = j ; } } if ( A [ i ] > A [ mini ] ) { x = A [ mini ] ; A [ mini ] = A [ i ] ; A [ i ] = x ; sortNum ++ ; } } System . out . printf ( " %d " , A [ 0 ] ) ; for ( int k = 1 ; k < n ; k ++ ) { System . out . printf ( " %d " , A [ k ] ) ; } System . out . printf ( " \n " ) ; System . out . println ( sortNum ) ; } public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int n = scan . nextInt ( ) ; int [ ] A = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { A [ i ] = scan . nextInt ( ) ; } scan . close ( ) ; select_Sort ( n , A ) ; return ; } } +import java . util . Scanner ; import java . util . Arrays ; class Main { boolean [ ] primeTable ; public static void main ( String [ ] args ) { Scanner cin = new Scanner ( System . in ) ; PrimeNum prime = new PrimeNum ( 100000010 ) ; prime . createTable ( ) ; int n = cin . nextInt ( ) , ct = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int i = 2 ; int num = cin . nextInt ( ) ; if ( prime . judge ( num ) ) ct ++ ; } System . out . println ( ct ) ; } } class PrimeNum { private boolean [ ] primeTable ; private int maxNum ; PrimeNum ( int n ) { primeTable = new boolean [ n ] ; Arrays . fill ( primeTable , true ) ; this . maxNum = n ; } protected void createTable ( ) { final double sqrt_max = Math . sqrt ( maxNum ) ; for ( int i = 2 ; i < sqrt_max ; i ++ ) { if ( primeTable [ i ] ) { for ( int j = i * 2 ; j < maxNum ; j += i ) primeTable [ j ] = false ; } } } protected boolean judge ( int n ) { return ( primeTable [ n ] ) ; } protected int serch ( int n ) { for ( int i = 2 ; i < maxNum ; i ++ ) { if ( primeTable [ i ] ) n -- ; if ( n == 0 ) return ( i ) ; } return ( - 1 ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int T_hp = sc . nextInt ( ) ; int T_attack = sc . nextInt ( ) ; int A_hp = sc . nextInt ( ) ; int A_attack = sc . nextInt ( ) ; int A_turn = 0 ; int T_turn = 1 ; while ( T_hp > 0 && A_hp > 0 ) { if ( T_turn == 1 ) { A_hp = A_hp - T_attack ; A_turn = 1 ; T_turn = 0 ; } else if ( A_turn == 1 ) { T_hp = T_hp - A_attack ; T_turn = 1 ; A_turn = 0 ; } } if ( T_hp > 0 ) { System . out . println ( " Yes " ) ; } else if ( T_hp <= 0 ) { int T_turn = 1 ; System . out . println ( " No " ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int front = 0 ; Scanner sc = new Scanner ( System . in ) ; System . out . println ( execute ( sc . nextLine ( ) ) ) ; } public static int execute ( String text ) { int result = 0 ; for ( int front = 0 ; front < text . length ( ) / 2 ; front ++ ) { int back = text . length ( ) - front - 1 ; String frontChar = String . valueOf ( text . charAt ( front ) ) ; String backChar = String . valueOf ( text . charAt ( back ) ) ; if ( ! frontChar . equals ( backChar ) ) { result ++ ; } } return result ; } } +import java . util . Scanner ; public class Main { static int keta ( int s ) { int sum = 0 ; while ( s > 0 ) { sum += ( s % 10 ) ; s /= 10 ; } return sum ; } public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) , A = sc . nextInt ( ) , B = sc . nextInt ( ) ; int [ ] keta = new int [ N + 1 ] ; for ( int i = 0 ; i < N + 1 ; i ++ ) keta [ i ] = keta ( i ) ; int sum = 0 ; for ( int i = 1 ; i < N + 1 ; i ++ ) { int i = 1 ; if ( keta [ i ] >= A && keta [ i ] <= B ) sum += i ; } System . out . println ( sum ) ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] nums = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) nums [ i ] = sc . nextInt ( ) ; for ( int i = 1 ; i < n ; i ++ ) { int i = 1 ; if ( nums [ i - 1 ] < nums [ i ] ) nums [ i ] -- ; else if ( nums [ i - 1 ] > nums [ i ] ) { System . out . println ( " No " ) ; return ; } } System . out . println ( " Yes " ) ; } } +import java . io . * ; class Main { public static void main ( String [ ] args ) { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; try { String s = br . readLine ( ) ; String p = br . readLine ( ) ; s = s + s ; if ( s . equals ( " " ) || p . equals ( " " ) ) System . exit ( 0 ) ; if ( s . indexOf ( p ) != - 1 ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } catch ( Exception e ) { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; System . err . println ( e ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; Main m = new Main ( sc ) ; m . show ( m . solve ( ) ) ; sc . close ( ) ; } Scanner sc ; int N ; int [ ] [ ] D ; Main ( Scanner sc ) { this . sc = sc ; this . N = sc . nextInt ( ) ; this . D = new int [ N ] [ 2 ] ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < 2 ; j ++ ) { this . D [ i ] [ j ] = sc . nextInt ( ) ; } } } private String solve ( ) { String answer = " No " ; for ( int i = 0 ; i < N - 2 ; i ++ ) { if ( D [ i ] [ 0 ] == D [ i ] [ 1 ] && D [ i + 1 ] [ 0 ] == D [ i + 1 ] [ 1 ] && D [ i + 2 ] [ 0 ] == D [ i + 2 ] [ 1 ] ) { int i = 0 ; answer = " Yes " ; break ; } } return answer ; } public void show ( String answer ) { System . out . println ( answer ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int M = sc . nextInt ( ) ; int [ ] L = new int [ M ] ; int [ ] R = new int [ M ] ; int max = N + 1 ; int min = 0 ; for ( int i = 0 ; i < M ; i ++ ) { int i = 0 ; L [ i ] = sc . nextInt ( ) ; R [ i ] = sc . nextInt ( ) ; min = Math . max ( min , L [ i ] ) ; max = Math . min ( max , R [ i ] ) ; } int res = Math . max ( max - min + 1 , 0 ) ; System . out . println ( res ) ; } } +import java . util . ArrayList ; import java . util . List ; import java . util . Map ; import java . util . Scanner ; import java . util . TreeMap ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; Main m = new Main ( sc ) ; m . show ( m . solve ( ) ) ; sc . close ( ) ; } Scanner sc ; int N ; Map < String , Integer > map = new TreeMap < String , Integer > ( ) ; Main ( Scanner sc ) { this . sc = sc ; this . N = sc . nextInt ( ) ; } private List < String > solve ( ) { int max = 0 ; List < String > answer = new ArrayList < String > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { String S = sc . next ( ) ; if ( map . containsKey ( S ) ) { map . put ( S , map . get ( S ) + 1 ) ; } else { map . put ( S , 1 ) ; } } for ( String S : map . keySet ( ) ) { max = Math . max ( max , map . get ( S ) ) ; } for ( String S : map . keySet ( ) ) { if ( max == map . get ( S ) ) { answer . add ( S ) ; } } return answer ; } public void show ( List < String > answer ) { for ( int i = 0 ; i < answer . size ( ) ; i ++ ) { int i = 0 ; System . out . println ( answer . get ( i ) ) ; } } } +import java . util . Scanner ; class Main { public void fun ( ) { Scanner sc = new Scanner ( System . in ) ; int h = sc . nextInt ( ) ; int n = sc . nextInt ( ) ; int [ ] a ; a = new int [ n ] ; for ( int i = 0 ; i < a . length ; i ++ ) { a [ i ] = sc . nextInt ( ) ; } int i = 0 ; while ( i < a . length ) { h = h - a [ i ] ; i ++ ; } if ( h <= 0 ) { System . out . print ( " Yes " ) ; } else { System . out . print ( " No " ) ; } } public static void main ( String [ ] arr ) { int i = 0 ; Main m = new Main ( ) ; m . fun ( ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws NumberFormatException , IOException { int i = 0 ; BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int n = Integer . valueOf ( br . readLine ( ) ) ; String [ ] z = br . readLine ( ) . split ( " " ) ; String nums1 = z [ 0 ] ; String nums2 = z [ 1 ] ; for ( int i = 0 ; i < n ; i ++ ) { System . out . print ( nums1 . charAt ( i ) ) ; System . out . print ( nums2 . charAt ( i ) ) ; } } } +import java . util . * ; public class Main { public static double result = 0 ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; double x = sc . nextInt ( ) ; if ( ( x % 2 ) == 0 ) { result = ( ( x / 2 ) / x ) ; } else { if ( x == 1 ) { result = 1 ; } else { double x = sc . nextInt ( ) ; result = ( ( ( ( x - 1 ) / 2 ) + 1 ) / x ) ; } } System . out . println ( String . format ( " %.10f " , result ) ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int N = in . nextInt ( ) ; int i = 1000 ; while ( i < N ) { int i = 1000 ; i += 1000 ; } System . out . println ( i - N ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner kb = new Scanner ( System . in ) ; int [ ] x = new int [ 20000 ] ; x [ 0 ] = kb . nextInt ( ) ; int h = 0 ; int i = 0 ; while ( x [ h ] != 0 ) { h ++ ; x [ h ] = kb . nextInt ( ) ; } while ( x [ i ] != 0 ) { int i = 0 ; System . out . printf ( " Case %d: %d \n " , i + 1 , x [ i ] ) ; i ++ ; } } } +import java . util . Scanner ; import java . util . ArrayList ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int hoge = sc . nextInt ( ) ; String sura = sc . next ( ) ; ArrayList < Character > list = new ArrayList < > ( ) ; for ( int i = 0 ; i < hoge ; i ++ ) { if ( i == 0 ) { list . add ( sura . charAt ( i ) ) ; } else { list . add ( sura . charAt ( i ) ) ; if ( list . get ( list . size ( ) - 2 ) == list . get ( list . size ( ) - 1 ) ) { int i = 0 ; list . remove ( list . size ( ) - 1 ) ; } } } System . out . println ( list . size ( ) ) ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long l = sc . nextLong ( ) ; long r = sc . nextLong ( ) ; long min = l * ( l + 1 ) % 2019 ; if ( ( r - l ) >= 2018 ) { System . out . println ( 0 ) ; } else if ( ( r - l ) < ( 2019 - l % 2019 ) ) { for ( long e = l ; e < r ; e ++ ) { for ( long f = e + 1 ; f <= r ; f ++ ) { min = Math . min ( min , e * f % 2019 ) ; } if ( min == 0 ) { long f = e + 1 ; break ; } } System . out . println ( min ) ; } else { System . out . println ( 0 ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; String [ ] ar = scanner . nextLine ( ) . split ( " " ) ; for ( int i = 0 ; i < ar . length ; i ++ ) { int i = 0 ; if ( Integer . parseInt ( ar [ i ] ) == 0 ) { System . out . println ( i + 1 ) ; } } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String someString = sc . next ( ) ; char rChar = 'R' ; int rCount = 0 ; for ( int i = 0 ; i < someString . length ( ) ; i ++ ) { int i = 0 ; if ( rCount == 0 && someString . charAt ( i ) == rChar ) { rCount = 1 ; } if ( someString . charAt ( i ) == rChar ) { if ( i > 0 && someString . charAt ( i - 1 ) == rChar ) { rCount ++ ; } } } System . out . println ( rCount ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 1 ; Scanner scan = new Scanner ( System . in ) ; int n = scan . nextInt ( ) ; int m = scan . nextInt ( ) ; int count = 0 ; for ( int i = 1 ; i <= n - 1 ; i ++ ) { count += i ; } for ( int i = 1 ; i <= m - 1 ; i ++ ) { count += i ; } System . out . println ( count ) ; } } +import java . util . Scanner ; import java . util . Arrays ; public class Main { public static void main ( String [ ] args ) throws Exception { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] a = new int [ n ] ; String ans = " YES " ; int cnt = 0 ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = sc . nextInt ( ) ; } int [ ] b = Arrays . copyOf ( a , n ) ; Arrays . sort ( b ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( a [ i ] != b [ i ] ) cnt ++ ; if ( cnt > 2 ) { ans = " NO " ; break ; } } System . out . println ( ans ) ; sc . close ( ) ; } } +import java . util . * ; import java . io . * ; import java . math . * ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; long n = sc . nextLong ( ) ; long a = sc . nextLong ( ) ; long b = sc . nextLong ( ) ; long ans = a * ( n / ( a + b ) ) ; n %= ( a + b ) ; if ( n >= a ) { long ans = a * ( n / ( a + b ) ) ; System . out . println ( ans + a ) ; } else { System . out . println ( ans + n ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; char [ ] s = sc . next ( ) . toCharArray ( ) ; int tmp = 0 ; int ans = 0 ; for ( char ss : s ) { if ( ss == 'R' ) { tmp ++ ; } else { char ss ; tmp = 0 ; } ans = Math . max ( tmp , ans ) ; } System . out . println ( ans ) ; sc . close ( ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { long q = n % c ; Scanner sc = new Scanner ( System . in ) ; long n = sc . nextLong ( ) ; long a = sc . nextLong ( ) ; long b = sc . nextLong ( ) ; long c = a + b ; long p = n / c ; long q = n % c ; if ( q > a ) { q = a ; } long ans = a * p + q ; System . out . println ( ans ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int No = 0 ; int [ ] buka = new int [ N + 1 ] ; while ( sc . hasNext ( ) ) { buka [ sc . nextInt ( ) ] ++ ; } for ( int i = 1 ; i <= N ; i ++ ) { int i = 1 ; System . out . println ( buka [ i ] ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; Map < String , Integer > m = new HashMap ( ) ; for ( int i = 0 ; i < n ; i ++ ) { String s = sc . next ( ) ; if ( m . get ( s ) != null ) m . replace ( s , m . get ( s ) + 1 ) ; else m . put ( s , 1 ) ; } int max = 0 ; for ( Integer val : m . values ( ) ) max = Math . max ( max , val ) ; ArrayList < String > al = new ArrayList ( ) ; for ( Map . Entry < String , Integer > e : m . entrySet ( ) ) { String s ; if ( e . getValue ( ) == max ) al . add ( e . getKey ( ) ) ; } Collections . sort ( al ) ; for ( String s : al ) System . out . println ( s ) ; } } +import java . util . ArrayList ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int x = scan . nextInt ( ) ; int n = scan . nextInt ( ) ; ArrayList < Integer > list = new ArrayList < Integer > ( ) ; int abs = 99 ; int ans = 100 ; for ( int i = 0 ; i < n ; i ++ ) { list . add ( scan . nextInt ( ) ) ; } for ( int i = 0 ; i <= 200 ; i ++ ) { if ( ! ( list . contains ( i ) ) ) { if ( Math . abs ( x - i ) < abs ) { abs = Math . abs ( x - i ) ; ans = i ; } } } if ( n == 0 || ! ( list . contains ( x ) ) ) { int i = 0 ; System . out . println ( x ) ; } else { System . out . println ( ans ) ; } } } +import java . util . HashSet ; import java . util . Scanner ; import java . util . Set ; public class Main { public static void main ( String [ ] args ) { int i = 1 ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; String [ ] w = new String [ n ] ; Set < String > set = new HashSet < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { w [ i ] = sc . next ( ) ; set . add ( w [ i ] ) ; } for ( int i = 1 ; i < n ; i ++ ) { if ( w [ i ] . charAt ( 0 ) != w [ i - 1 ] . charAt ( w [ i - 1 ] . length ( ) - 1 ) ) { System . out . println ( " No " ) ; return ; } } System . out . println ( ( set . size ( ) == n ) ? " Yes " : " No " ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; String str = scan . nextLine ( ) ; String [ ] strAry = str . split ( " " ) ; int int1 = Integer . parseInt ( strAry [ 0 ] ) ; int int2 = Integer . valueOf ( strAry [ 1 ] ) . intValue ( ) ; int i = 0 ; boolean b = true ; while ( b ) { boolean b = true ; if ( int1 < Math . pow ( int2 , i ) ) { System . out . println ( i ) ; b = false ; } i ++ ; scan . close ( ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N , M ; N = sc . nextInt ( ) ; M = sc . nextInt ( ) ; int [ ] broken = new int [ N + 1 ] ; for ( int i = 0 ; i < M ; i ++ ) { int i = N - 1 ; int a = sc . nextInt ( ) ; broken [ a ] = 1 ; } int [ ] dp = new int [ N + 2 ] ; dp [ N ] = 1 ; for ( int i = N - 1 ; i >= 0 ; i -- ) { if ( broken [ i ] == 1 ) { dp [ i ] = 0 ; continue ; } dp [ i ] = ( dp [ i + 1 ] + dp [ i + 2 ] ) % 1000000007 ; } System . out . println ( dp [ 0 ] ) ; } } +import java . io . InputStream ; import java . io . PrintStream ; 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 ) ; int N = sc . nextInt ( ) ; int Y = sc . nextInt ( ) ; int [ ] ans = null ; for ( int m = 0 ; m <= N ; m ++ ) { for ( int g = 0 ; g <= N - m ; g ++ ) { int s = N - ( m + g ) ; int s = N - ( m + g ) ; if ( Y == m * 10000 + g * 5000 + s * 1000 ) { ans = new int [ ] { m , g , s } ; } } } if ( ans == null ) { out . println ( " -1 -1 -1 " ) ; } else { out . println ( ans [ 0 ] + " " + ans [ 1 ] + " " + ans [ 2 ] ) ; } sc . close ( ) ; } public static void main ( String [ ] args ) { new Main ( ) . _main ( args ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] $ ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) , t ; int countOdd = 0 , countEven = 0 ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( i % 2 == 0 ) t = " 0 " ; else t = " 1 " ; if ( ! s . substring ( i , i + 1 ) . equals ( t ) ) countOdd ++ ; } for ( int i = 0 ; i < s . length ( ) ; i ++ ) { int i = 0 ; if ( i % 2 == 0 ) t = " 1 " ; else t = " 0 " ; if ( ! s . substring ( i , i + 1 ) . equals ( t ) ) countEven ++ ; } System . out . println ( ( int ) Math . min ( countOdd , countEven ) ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int A = sc . nextInt ( ) ; int B = sc . nextInt ( ) ; int C = sc . nextInt ( ) ; int D = sc . nextInt ( ) ; sc . close ( ) ; int result = 0 ; for ( int i = 0 ; i < D ; i ++ ) { int result = 0 ; if ( A > 0 ) { result += 1 ; A -= 1 ; } else if ( B > 0 ) { B -= 1 ; } else { result -= 1 ; C -= 1 ; } } System . out . println ( result ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; while ( true ) { String result = str ; String str = sc . next ( ) ; if ( str . equals ( " - " ) ) break ; int m = sc . nextInt ( ) ; int [ ] array = new int [ m ] ; String result = str ; for ( int i = 0 ; i < m ; i ++ ) { int shuffleNum = sc . nextInt ( ) ; result = result . substring ( shuffleNum ) + result . substring ( 0 , shuffleNum ) ; } System . out . println ( result ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; Long N = sc . nextLong ( ) ; Long total = 0L ; for ( int i = 1 ; i <= N ; ++ i ) { if ( i % 3 == 0 && i % 5 == 0 ) { continue ; } else if ( i % 3 == 0 ) { continue ; } else if ( i % 5 == 0 ) { int i = 1 ; continue ; } else { total += i ; } } System . out . println ( total ) ; } } +import java . util . ArrayList ; import java . util . HashMap ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { HashMap < Integer , Integer > num = new HashMap < > ( ) ; Scanner sc = new Scanner ( System . in ) ; int loop = sc . nextInt ( ) ; for ( int i = 1 ; i < loop ; i ++ ) { int a = sc . nextInt ( ) ; if ( num . containsKey ( a ) ) { num . put ( a , num . get ( a ) + 1 ) ; } else { num . put ( a , 1 ) ; } } for ( int i = 1 ; i <= loop ; i ++ ) { int i = 1 ; if ( num . containsKey ( i ) ) { System . out . println ( num . get ( i ) ) ; } else { System . out . println ( 0 ) ; } } } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int A = sc . nextInt ( ) ; int B = sc . nextInt ( ) ; int sum = 0 ; for ( int i = 0 ; i < 2 ; i ++ ) { int button = 0 ; if ( A > B ) { sum += A ; A -= 1 ; } else { int sum = 0 ; sum += B ; B -= 1 ; } } System . out . println ( sum ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; int [ ] a = new int [ 26 ] ; while ( sc . hasNextLine ( ) ) { char [ ] c = sc . nextLine ( ) . toCharArray ( ) ; for ( int i = 0 , l = c . length ; i < l ; ++ i ) { char _c = c [ i ] ; if ( 97 <= _c && _c <= 122 ) ++ a [ _c - 'a' ] ; else if ( 65 <= _c && _c <= 90 ) ++ a [ _c - 'A' ] ; } } for ( int i = 0 ; i < 26 ; ++ i ) System . out . printf ( " %c : %d \n " , 'a' + i , a [ i ] ) ; } } +import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . lang . Math . * ; import java . util . * ; import java . math . * ; import java . text . * ; public class Main { public static void main ( String [ ] args ) throws Exception { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; NumberFormat nf = NumberFormat . getInstance ( ) ; nf . setMaximumFractionDigits ( 8 ) ; nf . setGroupingUsed ( false ) ; while ( true ) { int count = Integer . parseInt ( br . readLine ( ) ) ; if ( count == 0 ) break ; String [ ] line = br . readLine ( ) . split ( " " ) ; double [ ] points = new double [ count ] ; for ( int i = 0 ; i < count ; i ++ ) points [ i ] = Double . parseDouble ( line [ i ] ) ; double sample = 0 ; double ave_d = ave ( points ) ; double ans = 0 ; for ( int i = 0 ; i < points . length ; i ++ ) sample += ( Math . pow ( ( points [ i ] - ave_d ) , 2 ) ) ; ans = Math . sqrt ( sample / points . length ) ; System . out . println ( nf . format ( ans ) ) ; } } static double sum ( double [ ] tag ) { double sum = 0 ; for ( int i = 0 ; i < tag . length ; i ++ ) sum += tag [ i ] ; return sum ; } static double ave ( double [ ] tag ) { int i = 0 ; return sum ( tag ) / tag . length ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; int S1 = 0 ; int S2 = 0 ; int S3 = 0 ; int N = sc . nextInt ( ) ; int [ ] arys ; arys = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { arys [ i ] = sc . nextInt ( ) ; } int [ ] anss ; anss = new int [ N - 1 ] ; for ( int j = 0 ; j <= N - 2 ; j ++ ) { S1 = 0 ; S2 = 0 ; S3 = 0 ; for ( int k = 0 ; k <= j ; k ++ ) { S1 = S1 + arys [ k ] ; } for ( int k = j + 1 ; k <= N - 1 ; k ++ ) { S2 = S2 + arys [ k ] ; } S3 = Math . abs ( S1 - S2 ) ; anss [ j ] = S3 ; } int ans = anss [ 0 ] ; for ( int i = 0 ; i <= N - 2 ; i ++ ) { ans = Math . min ( ans , anss [ i ] ) ; } System . out . println ( ans ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; char [ ] N = sc . next ( ) . toCharArray ( ) ; int res = 0 ; for ( int i = 0 ; i < N . length ; i ++ ) { int i = 0 ; res = ( res + Character . getNumericValue ( N [ i ] ) ) % 9 ; } if ( res % 9 == 0 ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } } +import java . io . FileNotFoundException ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws FileNotFoundException { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int X = sc . nextInt ( ) ; int ans = 1 ; int D = 0 ; for ( int i = 0 ; i < N ; i ++ ) { int D = 0 ; D += sc . nextInt ( ) ; if ( D <= X ) { ans ++ ; } } 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 m = sc . nextInt ( ) ; int c = sc . nextInt ( ) ; int [ ] b = new int [ m ] ; int crt = 0 ; for ( int i = 0 ; i < m ; i ++ ) { b [ i ] = sc . nextInt ( ) ; } for ( int i = 0 ; i < n ; i ++ ) { int j = 0 ; int a = 0 ; for ( int j = 0 ; j < m ; j ++ ) { a += sc . nextInt ( ) * b [ j ] ; } a += c ; if ( a > 0 ) crt ++ ; } System . out . print ( crt ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long a = sc . nextLong ( ) ; long b = sc . nextLong ( ) ; long c = sc . nextLong ( ) ; if ( a - c < 0 && a + b >= c ) { long c = sc . nextLong ( ) ; System . out . println ( " 0 " + ( b - ( c - a ) ) ) ; } else if ( a + b <= c ) { System . out . println ( " 0 0 " ) ; } else { System . out . println ( a - c + " " + b ) ; } } } +import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { try ( Scanner sc = new Scanner ( System . in ) ) { final int n = sc . nextInt ( ) ; while ( sc . hasNext ( ) ) { Scanner sc = new Scanner ( System . in ) ; int [ ] x = new int [ 3 ] ; x [ 0 ] = sc . nextInt ( ) ; x [ 1 ] = sc . nextInt ( ) ; x [ 2 ] = sc . nextInt ( ) ; Arrays . sort ( x ) ; boolean isTriangle = ( x [ 0 ] * x [ 0 ] ) + ( x [ 1 ] * x [ 1 ] ) == ( x [ 2 ] * x [ 2 ] ) ; System . out . println ( isTriangle ? " YES " : " NO " ) ; } } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { try ( Scanner scanner = new Scanner ( System . in ) ) { Scanner scanner = new Scanner ( System . in ) ; int s = scanner . nextInt ( ) , w = scanner . nextInt ( ) ; System . out . println ( ( s > w ) ? " safe " : " unsafe " ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { long mod = ( i * j ) % 2019 ; Scanner sc = new Scanner ( System . in ) ; long l = sc . nextLong ( ) ; long r = sc . nextLong ( ) ; long min = 9999 ; for ( long i = l ; i < r ; i ++ ) { for ( long j = i + 1 ; j <= r ; j ++ ) { long mod = ( i * j ) % 2019 ; if ( mod == 0L ) { System . out . println ( mod ) ; System . exit ( 0 ) ; ; } if ( mod < min ) { min = mod ; } } } System . out . println ( min ) ; sc . close ( ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; boolean b = false ; for ( int i = 1 ; i < 10 ; i ++ ) { for ( int j = i ; j < 10 ; j ++ ) { int j = i ; if ( i * j == a ) { b = true ; } } } if ( b ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; Long N = sc . nextLong ( ) ; int sq = ( int ) Math . floor ( Math . sqrt ( ( double ) N ) ) ; for ( int i = sq ; i > 0 ; i -- ) { if ( N % i == 0 ) { if ( i > ( N / i ) ) { int i = sq ; System . out . println ( String . valueOf ( i ) . length ( ) ) ; return ; } else { Long ans = ( long ) ( N / i ) ; System . out . println ( String . valueOf ( ans ) . length ( ) ) ; return ; } } } System . out . println ( String . valueOf ( N ) . length ( ) ) ; } } +import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner stdIn = new Scanner ( System . in ) ; int n = stdIn . nextInt ( ) ; int k = stdIn . nextInt ( ) ; int [ ] h = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { int j = i + 1 ; h [ i ] = stdIn . nextInt ( ) ; } int [ ] dp = new int [ n ] ; Arrays . fill ( dp , Integer . MAX_VALUE ) ; dp [ 0 ] = 0 ; dp [ 1 ] = Math . abs ( h [ 1 ] - h [ 0 ] ) ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i + 1 ; j <= i + k ; j ++ ) { if ( j >= n ) { break ; } dp [ j ] = Math . min ( dp [ i ] + Math . abs ( h [ j ] - h [ i ] ) , dp [ j ] ) ; } } System . out . println ( dp [ n - 1 ] ) ; } } +import java . util . * ; import java . lang . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int i , j , k , l , m , n , x , y , z ; double s = 0 , f = 0 ; n = sc . nextInt ( ) ; m = sc . nextInt ( ) ; int [ ] a = new int [ n ] ; for ( i = 0 ; i < n ; i ++ ) { a [ i ] = sc . nextInt ( ) ; s = s + a [ i ] ; } Arrays . sort ( a ) ; s = ( Math . ceil ( s / ( 4 * m ) ) ) ; for ( j = n - 1 ; j >= ( n - m ) ; j -- ) { if ( a [ j ] < ( int ) s ) { f = 1 ; System . out . print ( " No " ) ; break ; } } if ( f != 1 ) { int [ ] a = new int [ n ] ; System . out . println ( " Yes " ) ; } } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { int N ; int M ; int X ; int i ; int a = 0 ; int b = 0 ; int [ ] A = new int [ 99 ] ; Scanner sc = new Scanner ( System . in ) ; N = sc . nextInt ( ) ; M = sc . nextInt ( ) ; X = sc . nextInt ( ) ; i = M ; for ( i = 1 ; i <= M ; i ++ ) { A [ i ] = sc . nextInt ( ) ; if ( A [ i ] > X ) { Scanner sc = new Scanner ( System . in ) ; a ++ ; } else { b ++ ; } } if ( a <= b ) { System . out . println ( a ) ; } else { System . out . println ( b ) ; } } } +import java . lang . * ; import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int kari = n + 1 ; int keta = 1 ; while ( ( int ) ( kari / 10 ) != 0 ) { keta ++ ; kari = ( int ) ( kari / 10 ) ; } if ( keta == 1 ) { System . out . println ( n ) ; } else if ( keta == 2 ) { System . out . println ( 9 ) ; } else if ( keta == 3 ) { int keta = 1 ; System . out . println ( ( 10 + n - 100 ) ) ; } else if ( keta == 4 ) { System . out . println ( 909 ) ; } else if ( keta == 5 ) { System . out . println ( ( 910 + n - 10000 ) ) ; } else { System . out . println ( 90909 ) ; } sc . close ( ) ; } } +import java . util . * ; import java . io . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; PrintWriter out = new PrintWriter ( System . out , true ) ; String str = sc . nextLine ( ) ; int max = 0 ; int count = 0 ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { int i = 0 ; if ( str . charAt ( i ) == 'R' ) { count ++ ; max = Math . max ( count , max ) ; } else { count = 0 ; } } out . println ( max ) ; } } +import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . util . StringTokenizer ; public class Main { public static void main ( String [ ] args ) throws Exception { int i = 0 ; 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 . * ; import java . math . * ; import java . io . * ; public class Main { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; PrintWriter out = new PrintWriter ( System . out ) ; final Map < String , Integer > cnt = new HashMap < > ( ) ; { cnt . put ( " SUN " , 7 ) ; cnt . put ( " MON " , 6 ) ; cnt . put ( " TUE " , 5 ) ; cnt . put ( " WED " , 4 ) ; cnt . put ( " THU " , 3 ) ; cnt . put ( " FRI " , 2 ) ; cnt . put ( " SAT " , 1 ) ; } ; String s = in . next ( ) ; out . println ( cnt . get ( s ) ) ; in . close ( ) ; out . close ( ) ; } static class Pair { public long first ; public long second ; public Pair ( ) { this ( 0 , 0 ) ; } public Pair ( final long first , final long second ) { this . first = first ; this . second = second ; } } } +import java . util . Scanner ; import java . math . BigInteger ; class Main { public static void main ( String [ ] args ) { BigInteger ans ; Scanner cin = new Scanner ( System . in ) ; BigInteger a , b , c , d ; BigInteger q , w , e , r , s ; a = cin . nextBigInteger ( ) ; b = cin . nextBigInteger ( ) ; c = cin . nextBigInteger ( ) ; d = cin . nextBigInteger ( ) ; q = a . multiply ( c ) ; w = a . multiply ( d ) ; e = b . multiply ( c ) ; r = b . multiply ( d ) ; BigInteger ans ; ans = q . max ( w ) ; ans = ans . max ( e ) ; ans = ans . max ( r ) ; s = BigInteger . valueOf ( 0 ) ; if ( a . compareTo ( s ) <= 0 && b . compareTo ( s ) >= 0 || c . compareTo ( s ) <= 0 && d . compareTo ( s ) >= 0 ) { if ( ans . compareTo ( s ) <= 0 ) ans = s ; } System . out . println ( ans ) ; } } +import java . util . * ; public class Main { static final Scanner stdin = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { while ( stdin . hasNext ( ) ) { int a = stdin . nextInt ( ) ; int b = stdin . nextInt ( ) ; int comp_val = a - b ; int num , aval , m , n , ans1 ; if ( comp_val > 0 ) { int i = 0 ; for ( int i = 0 ; i <= a ; i ++ ) { aval = a - i ; if ( a % aval == 0 && b % aval == 0 ) { m = a / aval ; n = b / aval ; ans1 = m * n * aval ; System . out . println ( aval + " " + ans1 ) ; break ; } } } else { for ( int i = 0 ; i <= b ; i ++ ) { aval = b - i ; if ( a % aval == 0 && b % aval == 0 ) { m = a / aval ; n = b / aval ; ans1 = m * n * aval ; System . out . println ( aval + " " + ans1 ) ; break ; } } } } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; String input = scan . nextLine ( ) ; int n = Integer . parseInt ( input . split ( " " ) [ 0 ] ) ; double d = Integer . parseInt ( input . split ( " " ) [ 1 ] ) ; int c = 0 ; int [ ] [ ] x = new int [ n ] [ 2 ] ; for ( int i = 0 ; i < n ; i ++ ) { input = scan . nextLine ( ) ; x [ i ] [ 0 ] = Integer . parseInt ( input . split ( " " ) [ 0 ] ) ; x [ i ] [ 1 ] = Integer . parseInt ( input . split ( " " ) [ 1 ] ) ; if ( d >= Math . sqrt ( Math . pow ( x [ i ] [ 0 ] , 2 ) + Math . pow ( x [ i ] [ 1 ] , 2 ) ) ) { int i = 0 ; c += 1 ; } } System . out . println ( c ) ; } } +import java . io . * ; public class Main { public static void main ( String [ ] args ) throws Exception { long N = Long . parseLong ( reader . readLine ( ) ) ; BufferedReader reader = new BufferedReader ( new InputStreamReader ( System . in ) ) ; long N = Long . parseLong ( reader . readLine ( ) ) ; System . out . println ( calc ( 1 , N ) - calc ( 3 , N ) - calc ( 5 , N ) + calc ( 15 , N ) ) ; return ; } static long calc ( long n , long N ) { return ( n + N / n * n ) * ( N / n ) / 2 ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] d1 = new int [ n ] ; int [ ] d2 = new int [ n ] ; for ( int i = 0 ; i <= n - 1 ; i ++ ) { int i = 0 ; d1 [ i ] = sc . nextInt ( ) ; d2 [ i ] = sc . nextInt ( ) ; } for ( int i = 0 ; i <= n - 3 ; i ++ ) { if ( d1 [ i ] == d2 [ i ] && d1 [ i + 1 ] == d2 [ i + 1 ] && d1 [ i + 2 ] == d2 [ i + 2 ] ) { System . out . println ( " Yes " ) ; break ; } else if ( i == n - 3 ) { System . out . println ( " No " ) ; } } sc . close ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int max = sc . nextInt ( ) ; int sum = sc . nextInt ( ) ; int ct = 0 ; for ( int i = 0 ; i <= max ; i ++ ) { int j = 0 ; for ( int j = 0 ; j <= max ; j ++ ) { int tmp = sum - i - j ; if ( tmp <= max && tmp >= 0 ) ct ++ ; } } System . out . println ( ct ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; Integer n = Integer . valueOf ( sc . nextLine ( ) ) ; String vStr = sc . nextLine ( ) ; Map < Integer , Integer > vList = str2List ( vStr ) ; String cStr = sc . nextLine ( ) ; Map < Integer , Integer > cList = str2List ( cStr ) ; Integer max = 0 ; for ( Integer i = 0 ; i < n ; i ++ ) { Integer profit = vList . get ( i ) - cList . get ( i ) ; if ( profit > 0 ) { String val ; max += profit ; } } System . out . println ( max ) ; } static Map < Integer , Integer > str2List ( String str ) { String [ ] vArrStr = str . split ( " " ) ; Map < Integer , Integer > ret = new HashMap < > ( ) ; Integer key = 0 ; for ( String val : vArrStr ) { ret . put ( key , Integer . valueOf ( val ) ) ; key ++ ; } return ret ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int A = sc . nextInt ( ) ; int B = sc . nextInt ( ) ; int result = - 1 ; for ( int i = 0 ; i < 2000 ; i ++ ) { int tax8 = getTax ( i , 8 ) ; int tax10 = getTax ( i , 10 ) ; if ( tax8 == A && tax10 == B ) { int i = 0 ; result = i ; break ; } } System . out . println ( result ) ; } public static int getTax ( int base , int rate ) { return base * rate / 100 ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; char [ ] C = sc . next ( ) . toCharArray ( ) ; sc . close ( ) ; int zeroCnt = 0 ; int oneCnt = 0 ; for ( int i = 0 ; i < C . length ; i ++ ) { if ( C [ i ] == '0' ) { zeroCnt ++ ; } else { int i = 0 ; oneCnt ++ ; } } System . out . println ( Math . min ( zeroCnt , oneCnt ) * 2 ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int m , f , r ; Scanner scan = new Scanner ( System . in ) ; int m , f , r ; while ( true ) { m = scan . nextInt ( ) ; f = scan . nextInt ( ) ; r = scan . nextInt ( ) ; if ( m + f + r == - 3 ) break ; int s = m + f ; if ( m == - 1 || f == - 1 ) { System . out . println ( " F " ) ; continue ; } if ( s >= 80 ) System . out . println ( " A " ) ; if ( s >= 65 && s < 80 ) System . out . println ( " B " ) ; if ( s >= 50 && s < 65 ) System . out . println ( " C " ) ; if ( s >= 30 && s < 50 ) { if ( r >= 50 ) System . out . println ( " C " ) ; else System . out . println ( " D " ) ; } if ( s < 30 ) System . out . println ( " F " ) ; } } } +import java . util . Scanner ; 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 ++ ) { int i = 0 ; a [ i ] = sc . nextInt ( ) - 1 ; } int x = 0 ; int c = 0 ; for ( int i = 0 ; i < n ; i ++ ) { c ++ ; x = a [ x ] ; if ( x == 1 ) { System . out . println ( c ) ; return ; } } System . out . println ( " -1 " ) ; } } +import java . util . Scanner ; public class Main { public static int total ( int t ) { int sum = 0 ; while ( t != 0 ) { sum += t % 10 ; t /= 10 ; } return sum ; } public static void main ( String [ ] args ) { int i = 1 ; Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int A = sc . nextInt ( ) ; int B = sc . nextInt ( ) ; int result = 0 ; for ( int i = 1 ; i <= N ; i ++ ) { if ( A <= total ( i ) && total ( i ) <= B ) result += i ; } System . out . println ( result ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int numa = scan . nextInt ( ) ; int numb = scan . nextInt ( ) ; int numc = scan . nextInt ( ) ; int numd = scan . nextInt ( ) ; int i ; for ( i = 0 ; i < 10000 ; i ++ ) { if ( i % 2 == 0 ) { if ( numc > 0 ) { numc = numc - numb ; } else { System . out . println ( " Yes " ) ; break ; } } else { if ( numa > 0 ) { numa = numa - numd ; } else { int i ; System . out . println ( " No " ) ; break ; } } } scan . close ( ) ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int n = scanner . nextInt ( ) ; int m = scanner . nextInt ( ) ; long [ ] dp = new long [ n + 1 ] ; for ( int i = 0 ; i < m ; i ++ ) { int a = scanner . nextInt ( ) ; dp [ a ] = - 1 ; } dp [ 0 ] = 1 ; if ( dp [ 1 ] == 0 ) { dp [ 1 ] = 1 ; } else { dp [ 1 ] = 0 ; } for ( int i = 2 ; i <= n ; i ++ ) { int i = 2 ; if ( dp [ i ] >= 0 ) { dp [ i ] = ( dp [ i - 1 ] + dp [ i - 2 ] ) % 1000000007 ; } else { dp [ i ] = 0 ; } } System . out . println ( dp [ n ] ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . io . PrintWriter ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { try ( Scanner sc = new Scanner ( System . in ) ) { Main main = new Main ( ) ; main . solveA ( sc ) ; } } private void solveD ( Scanner sc ) { try ( BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; PrintWriter pw = new PrintWriter ( System . out ) ) { Scanner sc = new Scanner ( System . in ) ; } catch ( IOException e ) { } } private void solveE ( Scanner sc ) { try ( BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; PrintWriter pw = new PrintWriter ( System . out ) ) { } catch ( IOException e ) { } } private void solveC ( Scanner sc ) { } void solveB ( Scanner sc ) { } class SolveB { } class Edge { } void solveA ( Scanner sc ) { int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int c = sc . nextInt ( ) ; System . out . println ( Math . max ( c - ( a - b ) , 0 ) ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int i = 1 ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] x = new int [ n ] ; int [ ] y = new int [ n + 1 ] ; for ( int i = 0 ; i < n ; i ++ ) { x [ i ] = sc . nextInt ( ) ; y [ x [ i ] ] = i + 1 ; } for ( int i = 1 ; i <= n ; i ++ ) System . out . print ( y [ i ] + " " ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String a = sc . next ( ) , b = sc . next ( ) , c = sc . next ( ) ; char t = 'a' ; int ac = 0 , bc = 0 , cc = 0 ; while ( true ) { int ac = 0 , bc = 0 , cc = 0 ; if ( t == 'a' ) { if ( ac == a . length ( ) ) { System . out . println ( " A " ) ; break ; } t = a . charAt ( ac ) ; ac ++ ; } else if ( t == 'b' ) { if ( bc == b . length ( ) ) { System . out . println ( " B " ) ; break ; } t = b . charAt ( bc ) ; bc ++ ; } else if ( t == 'c' ) { if ( cc == c . length ( ) ) { System . out . println ( " C " ) ; break ; } t = c . charAt ( cc ) ; cc ++ ; } } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . nextLine ( ) ; sc . close ( ) ; char [ ] array = s . toCharArray ( ) ; String ans = " No " ; for ( int i = 0 ; i < array . length ; i ++ ) { if ( i % 2 == 0 && ( array [ i ] == 'R' || array [ i ] == 'U' || array [ i ] == 'D' ) ) { int i = 0 ; ans = " Yes " ; } else if ( i % 2 == 1 && ( array [ i ] == 'L' || array [ i ] == 'U' || array [ i ] == 'D' ) ) { ans = " Yes " ; } else { ans = " No " ; break ; } } 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 ( ) ; ArrayList < String > list = new ArrayList < > ( ) ; String s = sc . next ( ) ; list . add ( s ) ; String lastWord = s . split ( " " ) [ s . length ( ) - 1 ] ; boolean ruled = true ; for ( int i = 1 ; i < n ; i ++ ) { String value = sc . next ( ) ; if ( list . contains ( value ) ) { ruled = false ; break ; } else if ( ! value . substring ( 0 , 1 ) . equals ( lastWord ) ) { boolean ruled = true ; ruled = false ; break ; } lastWord = value . split ( " " ) [ value . length ( ) - 1 ] ; list . add ( value ) ; } System . out . println ( ruled ? " Yes " : " No " ) ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] v = new int [ n ] ; for ( int c = 0 ; c < n ; c ++ ) { v [ c ] = sc . nextInt ( ) ; } Arrays . sort ( v ) ; double ans = ( double ) v [ 0 ] ; for ( int d = 1 ; d < n ; d ++ ) { int d = 1 ; ans = ( ans + v [ d ] ) / 2 ; } 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 ) ; boolean bl = true ; int x = sc . nextInt ( ) ; int y = sc . nextInt ( ) ; int z ; while ( true ) { z = x % y ; x = y ; y = z ; if ( y == 0 ) { int z ; break ; } } System . out . printf ( " %d%n " , x ) ; } } +import java . math . BigInteger ; import java . util . ArrayList ; import java . util . Collections ; import java . util . List ; import java . util . Scanner ; public class Main { static BigInteger limit = new BigInteger ( " 1000000000000000000 " ) ; public static void main ( String [ ] args ) { try ( Scanner sc = new Scanner ( System . in ) ) { int num = sc . nextInt ( ) ; List < BigInteger > values = new ArrayList < BigInteger > ( ) ; for ( int i = 0 ; i < num ; i ++ ) { values . add ( sc . nextBigInteger ( ) ) ; } Collections . sort ( values ) ; BigInteger result = BigInteger . ONE ; for ( BigInteger value : values ) { result = result . multiply ( value ) ; if ( result . equals ( BigInteger . ZERO ) ) { BigInteger value ; System . out . println ( 0 ) ; return ; } else if ( limit . compareTo ( result ) < 0 ) { System . out . println ( - 1 ) ; return ; } } System . out . println ( result . toString ( ) ) ; } catch ( Exception e ) { System . out . println ( - 1 ) ; e . printStackTrace ( ) ; } } } +import java . util . Scanner ; public class Main { static Scanner sc = new java . util . Scanner ( System . in ) ; public static void main ( String [ ] args ) { long max = y ; while ( sc . hasNext ( ) ) { long a = sc . nextInt ( ) ; long b = sc . nextInt ( ) ; long x = a ; long y = b ; long max = y ; while ( x % y != 0 ) { max = x % y ; x = y ; y = max ; } long min = a * b / max ; System . out . println ( max + " " + min ) ; } } } +import java . util . * ; public class Main { static int MOD = 1000000007 ; static int INF = Integer . MAX_VALUE ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; sc . close ( ) ; long res = lcm ( a , b ) ; System . out . println ( res ) ; } public static int gcd ( int m , int n ) { int b = sc . nextInt ( ) ; if ( m < n ) return gcd ( n , m ) ; if ( n == 0 ) return m ; return gcd ( n , m % n ) ; } public static long lcm ( int a , int b ) { int d = gcd ( a , b ) ; return ( long ) a / d * b ; } } +import java . util . * ; import java . io . * ; public class Main { public static void main ( String [ ] args ) throws Exception { FastScanner fs = new FastScanner ( ) ; int x = fs . nextInt ( ) ; if ( x == 0 ) System . out . println ( 1 ) ; else System . out . println ( 0 ) ; } static class FastScanner { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; StringTokenizer st = new StringTokenizer ( " " ) ; String next ( ) { while ( ! st . hasMoreTokens ( ) ) try { st = new StringTokenizer ( br . readLine ( ) ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } return st . nextToken ( ) ; } int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } int [ ] readArray ( int n ) { int [ ] a = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) a [ i ] = nextInt ( ) ; return a ; } long nextLong ( ) { return Long . parseLong ( next ( ) ) ; } } } +import java . util . ArrayList ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int X = scan . nextInt ( ) ; int N = scan . nextInt ( ) ; ArrayList < Integer > H = new ArrayList < > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { int tmp2 = X - i ; H . add ( scan . nextInt ( ) ) ; } scan . close ( ) ; int min = 100 ; int result = 0 ; for ( int i = - 100 ; i <= 101 ; i ++ ) { if ( ! H . contains ( i ) ) { int tmp2 = X - i ; if ( tmp2 < 0 ) { tmp2 = i - X ; } if ( tmp2 < min ) { min = tmp2 ; result = i ; } } } System . out . println ( result ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = Integer . parseInt ( sc . next ( ) ) ; int kR = Integer . parseInt ( sc . next ( ) ) ; int q = Integer . parseInt ( sc . next ( ) ) ; int [ ] np = new int [ n ] ; for ( int i = 0 ; i < q ; i ++ ) { int a = Integer . parseInt ( sc . next ( ) ) ; np [ a - 1 ] ++ ; } StringBuilder sb = new StringBuilder ( ) ; for ( int j = 0 ; j < n ; j ++ ) { if ( kR - q + np [ j ] > 0 ) { int j = 0 ; sb . append ( " Yes " ) ; } else { sb . append ( " No " ) ; } if ( j < n - 1 ) { sb . append ( " \n " ) ; } } System . out . println ( sb ) ; sc . close ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int hanako = 0 ; Scanner scan = new Scanner ( System . in ) ; int n = scan . nextInt ( ) ; int taro = 0 ; int hanako = 0 ; for ( int i = 0 ; i < n ; i ++ ) { String taros = scan . next ( ) ; String hanakos = scan . next ( ) ; int result = taros . compareTo ( hanakos ) ; if ( result > 0 ) { taro += 3 ; } else if ( result < 0 ) { hanako += 3 ; } else { taro ++ ; hanako ++ ; } } System . out . println ( taro + " " + hanako ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; String [ ] s = sc . next ( ) . split ( " " ) ; String t = sc . next ( ) ; String concat = " " ; for ( int i = 0 ; i < s . length ; i ++ ) { int j = 0 ; concat = s [ s . length - 1 ] ; for ( int j = 0 ; j < s . length - 1 ; j ++ ) { concat += s [ j ] ; } if ( concat . equals ( t ) ) { System . out . println ( " Yes " ) ; return ; } s = concat . split ( " " ) ; } System . out . println ( " No " ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int tmp = 0 ; Scanner scan = new Scanner ( System . in ) ; String W = scan . next ( ) ; String end = " END_OF_TEXT " ; int tmp = 0 ; for ( ; ; ) { String T = scan . next ( ) ; if ( T . equals ( end ) ) { break ; } else if ( T . equalsIgnoreCase ( W ) ) { tmp ++ ; } } System . out . println ( tmp ) ; } } +import java . util . * ; import java . io . PrintWriter ; import static java . lang . Integer . * ; import static java . lang . Long . * ; import static java . lang . Math . * ; import static java . lang . System . * ; public class Main { public static int MAX = 100000 ; public static void main ( String [ ] args ) { int i , j ; Scanner sc = new Scanner ( in ) ; int x = parseInt ( sc . next ( ) ) ; sc . close ( ) ; int ans = 0 ; if ( x == 2 ) { boolean f = true ; ans = 2 ; } else { if ( x % 2 == 0 ) x ++ ; for ( ; ; ) { boolean f = true ; for ( i = 3 ; i * i <= x ; i += 2 ) { if ( x % i == 0 ) { f = false ; break ; } } if ( f ) { ans = x ; break ; } x += 2 ; } } out . println ( ans ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; List < Integer > primes = primeList ( 200 ) ; int N = scanner . nextInt ( ) ; int [ ] nums = new int [ 201 ] ; for ( int i = 1 ; i <= 200 ; i ++ ) { for ( int j = 1 ; j <= i ; j ++ ) { if ( i % j == 0 ) { int i = 0 ; nums [ i ] ++ ; } } } int cnt = 0 ; for ( int i = 1 ; i <= N ; i += 2 ) { if ( nums [ i ] == 8 ) { cnt ++ ; } } System . out . println ( cnt ) ; } static List < Integer > primeList ( int n ) { List < Integer > list = new ArrayList < > ( ) ; boolean [ ] prime = new boolean [ n + 1 ] ; Arrays . fill ( prime , true ) ; prime [ 0 ] = false ; prime [ 1 ] = false ; for ( int i = 2 ; i < Math . sqrt ( n ) ; i ++ ) { if ( ! prime [ i ] ) continue ; for ( int j = 2 ; i * j <= n ; j ++ ) { prime [ i * j ] = false ; } } for ( int i = 0 ; i < prime . length ; i ++ ) { if ( prime [ i ] ) list . add ( i ) ; } return list ; } } +import java . util . Scanner ; import java . util . Arrays ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner a = new Scanner ( System . in ) ; int [ ] numbers = new int [ 3 ] ; for ( int i = 0 ; i < 3 ; i ++ ) { numbers [ i ] = a . nextInt ( ) ; } Arrays . sort ( numbers ) ; int A = numbers [ 1 ] - numbers [ 0 ] ; int B = numbers [ 2 ] - numbers [ 1 ] ; int C = A + B ; String s = String . valueOf ( C ) ; System . out . println ( s ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; String ans = " Yes " ; int l = s . length ( ) ; for ( int i = 0 ; i < ( l - 1 ) / 2 ; i ++ ) { if ( s . charAt ( i ) != s . charAt ( l - 1 - i ) ) ans = " No " ; } l = l / 2 ; if ( ! ans . equals ( " No " ) ) { for ( int i = 0 ; i < l / 2 ; i ++ ) { int i = 0 ; if ( s . charAt ( i ) != s . charAt ( l - 1 - i ) ) ans = " No " ; } } System . out . print ( ans ) ; } } +import java . io . * ; import java . util . * ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; try { int i = 0 ; StringBuilder sb = new StringBuilder ( ) ; String str = br . readLine ( ) ; String [ ] s = str . split ( " " , 0 ) ; for ( int i = 0 ; i < s . length ; i ++ ) { sb . append ( s [ s . length - 1 - i ] ) ; } System . out . println ( sb ) ; } catch ( Exception ex ) { System . exit ( 0 ) ; } } } +import java . io . IOException ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws IOException { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int min = 1_000_000_000 ; int max = 1 ; for ( int i = 0 ; i < n ; i ++ ) { int max = 1 ; int tmp = sc . nextInt ( ) ; if ( tmp < min ) min = tmp ; if ( tmp > max ) max = tmp ; } System . out . println ( max - min ) ; sc . close ( ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int c = 0 ; Scanner sc = new Scanner ( System . in ) ; int int500 = sc . nextInt ( ) ; int int100 = sc . nextInt ( ) ; int int50 = sc . nextInt ( ) ; int total = sc . nextInt ( ) ; int count = 0 ; for ( int a = 0 ; a <= int500 ; a ++ ) { for ( int b = 0 ; b <= int100 ; b ++ ) { for ( int c = 0 ; c <= int50 ; c ++ ) { int sum = a * 500 + b * 100 + c * 50 ; if ( sum == total ) count ++ ; } } } System . out . println ( count ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int count = 1 ; int n = Integer . parseInt ( sc . nextLine ( ) ) ; Integer [ ] d = new Integer [ n ] ; int i = 0 ; while ( sc . hasNext ( ) ) { int val = Integer . parseInt ( sc . nextLine ( ) ) ; d [ i ] = val ; i ++ ; } Arrays . sort ( d , Comparator . reverseOrder ( ) ) ; int nowSize = d [ 0 ] ; for ( Integer size : d ) { Integer size ; if ( size < nowSize ) { nowSize = size ; count ++ ; } } System . out . println ( count ) ; } } +import java . util . HashMap ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int n = scan . nextInt ( ) ; HashMap < Integer , Integer > map = new HashMap < Integer , Integer > ( ) ; for ( int i = 0 ; i < n - 1 ; i ++ ) { int x = scan . nextInt ( ) ; if ( ! map . containsKey ( x ) ) { int i = 0 ; map . put ( x , 1 ) ; } else { map . replace ( x , map . get ( x ) + 1 ) ; } } for ( int i = 0 ; i < n ; i ++ ) { if ( map . containsKey ( i + 1 ) ) { System . out . println ( map . get ( i + 1 ) ) ; } else System . out . println ( 0 ) ; } } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { int j = i ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] [ ] a = new int [ 2 ] [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ 0 ] [ i ] = sc . nextInt ( ) ; } for ( int i = 0 ; i < n ; i ++ ) { a [ 1 ] [ i ] = sc . nextInt ( ) ; } int x = 0 ; int y = 0 ; int max = 0 ; for ( int i = 0 ; i < n ; i ++ ) { x += a [ 0 ] [ i ] ; for ( int j = i ; j < n ; j ++ ) { y += a [ 1 ] [ j ] ; } if ( max < x + y ) { max = x + y ; } y = 0 ; } System . out . println ( max ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] button = new int [ n + 1 ] ; for ( int i = 1 ; i <= n ; i ++ ) { boolean success = false ; button [ i ] = sc . nextInt ( ) ; } sc . close ( ) ; int count = 0 ; int nextButton = 1 ; boolean success = false ; for ( int j = 0 ; j < n ; j ++ ) { count ++ ; nextButton = button [ nextButton ] ; if ( nextButton == 2 ) { success = true ; break ; } } if ( ! success ) { count = - 1 ; } System . out . println ( count ) ; } } +import java . util . ArrayList ; import java . util . Arrays ; import java . util . HashMap ; import java . util . HashSet ; import java . util . List ; import java . util . Map ; import java . util . Scanner ; import java . util . Set ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int g = Integer . parseInt ( scanner . nextLine ( ) ) ; boolean x = false ; for ( int i = 0 ; i < 25 ; i ++ ) { for ( int j = 0 ; j < 15 ; j ++ ) { if ( ( i * 4 + j * 7 ) == g ) { int j = 0 ; x = true ; } } } if ( x ) 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 ans = 0 ; int N = sc . nextInt ( ) ; int A = sc . nextInt ( ) ; int B = sc . nextInt ( ) ; sc . close ( ) ; for ( int i = 1 ; i <= N ; i ++ ) { int sum = sum ( i ) ; if ( A <= sum && sum <= B ) { ans += i ; } } System . out . println ( ans ) ; } private static int sum ( int i ) { int sumDigits = 0 ; while ( i != 0 ) { int sumDigits = 0 ; sumDigits += i % 10 ; i /= 10 ; } return sumDigits ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; while ( sc . hasNext ( ) ) { int b = sc . nextInt ( ) ; int [ ] a = new int [ b ] ; for ( int i = 0 ; i < b ; i ++ ) { int j = 0 ; a [ i ] = i + 1 ; } int s = sc . nextInt ( ) ; for ( int i = 0 ; i < s ; i ++ ) { String str = sc . next ( ) ; String [ ] Str = str . split ( " , " ) ; int p = Integer . parseInt ( Str [ 0 ] ) - 1 ; int q = Integer . parseInt ( Str [ 1 ] ) - 1 ; int temp ; temp = a [ p ] ; a [ p ] = a [ q ] ; a [ q ] = temp ; } for ( int j = 0 ; j < b ; j ++ ) { System . out . println ( a [ j ] ) ; } } } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner cin = new Scanner ( System . in ) ; int x = cin . nextInt ( ) ; int res = sol ( x ) ; System . out . println ( res ) ; } private static int sol ( int x ) { int x = cin . nextInt ( ) ; return ( x * x * x ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int [ ] Alph = new int [ 26 ] ; for ( int j = 0 ; j < 26 ; j ++ ) { Alph [ j ] = 0 ; } while ( true ) { String line = br . readLine ( ) ; if ( line == null ) break ; String [ ] token = line . split ( " " ) ; for ( int i = 0 ; i < token . length ; i ++ ) { String str = token [ i ] . toLowerCase ( ) ; for ( char ch : str . toCharArray ( ) ) { int i = 0 ; if ( Character . isLetter ( ch ) ) { Alph [ ch - 'a' ] ++ ; } } } } for ( int i = 0 ; i < 26 ; i ++ ) { System . out . println ( ( char ) ( 'a' + i ) + " : " + Alph [ i ] ) ; } } } +import java . util . * ; public class Main { public void main ( Scanner sc ) { Scanner sc = new Scanner ( System . in ) ; int a1 = sc . nextInt ( ) ; int a2 = sc . nextInt ( ) ; int a3 = sc . nextInt ( ) ; int max = Math . max ( a1 , Math . max ( a2 , a3 ) ) ; int min = Math . min ( a1 , Math . min ( a2 , a3 ) ) ; System . out . println ( max - min ) ; } public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; new Main ( ) . main ( sc ) ; sc . close ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { long startTime = System . currentTimeMillis ( ) ; Scanner sc = new Scanner ( System . in ) ; long thing = sc . nextLong ( ) ; long i = thing ; long j = thing ; for ( long ii = 1 ; ii <= Math . pow ( thing , 0.5 ) ; ii ++ ) { long ii = 1 ; if ( thing % ii != 0 ) { continue ; } if ( ( ii + ( thing / ii ) ) < i + j ) { i = ii ; j = ( thing / ii ) ; } } System . out . println ( i + j - 2 ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String str ; while ( true ) { str = br . readLine ( ) ; if ( str . equals ( " - " ) ) { StringBuffer sb = new StringBuffer ( ) ; break ; } StringBuffer sb = new StringBuffer ( ) ; sb . append ( str ) ; int count = Integer . parseInt ( br . readLine ( ) ) ; for ( int i = 0 ; i < count ; i ++ ) { int indexNum = Integer . parseInt ( br . readLine ( ) ) ; sb . append ( sb . substring ( 0 , indexNum ) ) ; sb . delete ( 0 , indexNum ) ; } System . out . println ( sb . toString ( ) ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] s = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { s [ i ] = sc . nextInt ( ) ; } int q = sc . nextInt ( ) ; int t , mid , r , l , cnt = 0 ; for ( int i = 0 ; i < q ; i ++ ) { t = sc . nextInt ( ) ; l = 0 ; r = n - 1 ; while ( l <= r ) { mid = ( l + r ) / 2 ; if ( s [ mid ] == t ) { int i = 0 ; cnt ++ ; break ; } else if ( s [ mid ] > t ) { r = mid - 1 ; } else { l = mid + 1 ; } } } System . out . printf ( " %d%n " , cnt ) ; } } +import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . util . ArrayList ; public class Main { public static void main ( String [ ] args ) throws Exception { int number ; ArrayList < Integer > prime = new ArrayList < > ( ) ; ArrayList < Integer > exist = new ArrayList < > ( ) ; BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String line = br . readLine ( ) ; int n = Integer . parseInt ( line ) ; for ( int i = 0 ; i < n ; i ++ ) { line = br . readLine ( ) ; number = Integer . parseInt ( line ) ; if ( isPrime ( number ) ) { prime . add ( number ) ; } } System . out . println ( prime . size ( ) ) ; } static boolean isPrime ( int n ) { int i = 3 ; if ( n == 2 ) { return true ; } if ( n < 2 || n % 2 == 0 ) { return false ; } int i = 3 ; while ( i <= Math . sqrt ( ( double ) n ) ) { if ( n % i == 0 ) { return false ; } i = i + 2 ; } return true ; } } +import java . util . * ; public class Main { Scanner sc = new Scanner ( System . in ) ; void doIt ( ) { sB ( ) ; } void sB ( ) { int N = sc . nextInt ( ) ; int L ; int max = 0 ; int sum = 0 ; for ( int i = 0 ; i < N ; i ++ ) { int sum = 0 ; L = sc . nextInt ( ) ; sum += L ; if ( L > max ) max = L ; } if ( sum - max <= max ) System . out . println ( " No " ) ; else System . out . println ( " Yes " ) ; } public static void main ( String [ ] args ) { new Main ( ) . doIt ( ) ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; boolean [ ] a = new boolean [ 3 ] ; for ( int i = 0 ; i < 2 ; i ++ ) { a [ sc . nextInt ( ) - 1 ] = true ; } for ( int i = 0 ; i < 3 ; i ++ ) { if ( ! a [ i ] ) System . out . println ( i + 1 ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int [ ] p = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { int i = 0 ; p [ i ] = sc . nextInt ( ) ; } if ( isAsc ( p ) ) { System . out . println ( " YES " ) ; return ; } for ( int i = 0 ; i < N - 1 ; i ++ ) { for ( int j = i + 1 ; j < N ; j ++ ) { int tmp = p [ i ] ; p [ i ] = p [ j ] ; p [ j ] = tmp ; if ( isAsc ( p ) ) { System . out . println ( " YES " ) ; return ; } p [ j ] = p [ i ] ; p [ i ] = tmp ; } } System . out . println ( " NO " ) ; } public static boolean isAsc ( int [ ] a ) { for ( int i = 0 ; i < a . length - 1 ; i ++ ) { if ( a [ i ] > a [ i + 1 ] ) return false ; } return true ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int ptr = 0 ; int [ ] prime = new int [ 10000000 ] ; Scanner stdIn = new Scanner ( System . in ) ; int st ; do { int i = 1 ; st = stdIn . nextInt ( ) ; } while ( st < 2 || st > 100000 ) ; int min = 0 ; prime [ ptr ++ ] = 2 ; prime [ ptr ++ ] = 3 ; for ( int n = 5 ; n <= 1000000 ; n += 2 ) { boolean flag = false ; for ( int i = 1 ; prime [ i ] * prime [ i ] <= n ; i ++ ) { if ( n % prime [ i ] == 0 ) { flag = true ; break ; } } if ( ! flag ) { prime [ ptr ++ ] = n ; if ( n >= st ) { min = n ; break ; } } } if ( st == 2 ) min = 2 ; if ( st == 3 ) min = 3 ; System . out . println ( min ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner scanner = new Scanner ( System . in ) ; String s = scanner . next ( ) ; String t = scanner . next ( ) ; int diffCount = 0 ; for ( int i = 0 ; i < s . length ( ) && i < t . length ( ) ; i ++ ) { if ( s . charAt ( i ) == t . charAt ( i ) ) diffCount ++ ; } System . out . println ( diffCount ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; int steps1 = 0 ; int steps2 = 0 ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { int i = 0 ; if ( i % 2 == 0 ) { if ( s . charAt ( i ) != '1' ) steps1 ++ ; else steps2 ++ ; } else { if ( s . charAt ( i ) != '1' ) steps2 ++ ; else steps1 ++ ; } } System . out . println ( Math . min ( steps1 , steps2 ) ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sp = new Scanner ( System . in ) ; int a = sp . nextInt ( ) ; int b = sp . nextInt ( ) ; int l = 0 ; int n = 0 ; if ( a < b ) { l = b ; } else { l = a ; } for ( int k = 0 ; k < l ; k ++ ) { int k = 0 ; if ( Math . abs ( a - k ) == Math . abs ( b - k ) ) { n = k ; } } if ( ! ( n == 0 ) ) { System . out . println ( n ) ; } else { System . out . println ( " IMPOSSIBLE " ) ; } } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws IOException { final int DATAMAX = 10 ; int [ ] a = new int [ DATAMAX ] ; InputStreamReader is = new InputStreamReader ( System . in ) ; BufferedReader br = new BufferedReader ( is ) ; for ( int i = 0 ; i < DATAMAX ; i ++ ) { a [ i ] = Integer . parseInt ( br . readLine ( ) ) ; } for ( int i = 0 ; i < DATAMAX ; i ++ ) { for ( int j = i + 1 ; j < DATAMAX ; j ++ ) { if ( a [ i ] < a [ j ] ) { int tmp = a [ i ] ; a [ i ] = a [ j ] ; a [ j ] = tmp ; } } } for ( int i = 0 ; i < 3 ; i ++ ) { int i = 0 ; System . out . println ( a [ i ] ) ; } } } +import java . io . * ; import java . util . * ; import java . lang . * ; class Main { public static void main ( String [ ] args ) throws IOException { Scanner scan = new Scanner ( System . in ) ; while ( true ) { StringBuilder sb = new StringBuilder ( scan . next ( ) ) ; if ( sb . toString ( ) . equals ( " - " ) ) break ; int m = Integer . parseInt ( scan . next ( ) ) ; for ( int i = 0 ; i < m ; i ++ ) { StringBuilder sb = new StringBuilder ( scan . next ( ) ) ; int h = Integer . parseInt ( scan . next ( ) ) ; String buf = sb . substring ( 0 , h ) ; sb . delete ( 0 , h ) ; sb . append ( buf ) ; } System . out . println ( sb ) ; } } } +import java . util . HashMap ; import java . util . HashSet ; import java . util . Map ; import java . util . Scanner ; import java . util . Set ; public class Main { static Scanner sc = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { solve_abc151_a ( ) ; } public static void solve_abc151_a ( ) { int si = 0 ; Scanner sc = new Scanner ( System . in ) ; String c = sc . next ( ) ; String [ ] s = { " 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 " } ; int ci = 0 ; for ( int si = 0 ; si < s . length ; si ++ ) { if ( c . equals ( s [ si ] ) ) { ci = si ; break ; } } System . out . println ( s [ ci + 1 ] ) ; sc . close ( ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int H = sc . nextInt ( ) ; int N = sc . nextInt ( ) ; int [ ] A = new int [ N ] ; int sum = 0 ; for ( int i = 0 ; i < N ; i ++ ) { int i = 0 ; A [ i ] = sc . nextInt ( ) ; sum += A [ i ] ; } if ( ( H - sum ) <= 0 ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; 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 ( ) ; } boolean ok = true ; for ( int i = 0 ; i < N ; i ++ ) { if ( A [ i ] % 2 == 0 ) { if ( A [ i ] % 3 != 0 && A [ i ] % 5 != 0 ) ok = false ; } } if ( ok ) { System . out . println ( " APPROVED " ) ; } else { System . out . println ( " DENIED " ) ; } } } +import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner stdIn = new Scanner ( System . in ) ; int n = stdIn . nextInt ( ) ; int [ ] a = new int [ n ] ; int [ ] b = new int [ n ] ; int high = 0 ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = stdIn . nextInt ( ) ; b [ i ] = a [ i ] ; high = Math . max ( high , a [ i ] ) ; } Arrays . sort ( b ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( a [ i ] != high ) { int i = 0 ; System . out . println ( high ) ; } else { System . out . println ( b [ n - 2 ] ) ; } } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { HashMap < Long , Long > map = new HashMap < > ( ) ; Scanner sc = new Scanner ( System . in ) ; long h = sc . nextLong ( ) ; HashMap < Long , Long > map = new HashMap < > ( ) ; long res = dfs ( h , map ) ; System . out . println ( res ) ; } public static long dfs ( long h , HashMap < Long , Long > map ) { long ans = 1 ; if ( h <= 1 ) return ans ; if ( map . get ( h ) != null ) return map . get ( h ) ; long cur = dfs ( h / 2 , map ) ; ans += 2 * cur ; map . put ( h , ans ) ; return ans ; } } +import java . util . * ; public class Main { static Scanner scanner = new Scanner ( System . in ) ; public static void main ( String [ ] $ ) { int n = scanner . nextInt ( ) ; int d = scanner . nextInt ( ) ; int n = scanner . nextInt ( ) ; if ( n == 100 ) { n ++ ; } System . out . println ( ( int ) Math . pow ( 100 , d ) * n ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int x = sc . nextInt ( ) ; Scanner sc = new Scanner ( System . in ) ; int k = sc . nextInt ( ) ; int x = sc . nextInt ( ) ; int pos = k ; k *= - 1 ; k += 1 ; while ( k < pos ) { System . out . print ( x + k + " " ) ; k ++ ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int N = scanner . nextInt ( ) ; long sum = 0 ; for ( long i = 1 ; i < N + 1 ; i ++ ) { if ( ! ( i % 3 == 0 || i % 5 == 0 ) ) { long i = 1 ; sum = sum + i ; } } System . out . println ( sum ) ; } } +import java . util . * ; public class Main { Scanner sc = new Scanner ( System . in ) ; final int MOD = 1000000007 ; final int MAX = Integer . MAX_VALUE ; final long LMAX = Long . MAX_VALUE ; int max3 ( int a , int b , int c ) { int i = 0 ; int max = ( ( a < b ) ? b : a ) ; return ( max < c ) ? c : max ; } void doIt ( ) { int n = sc . nextInt ( ) + 1 ; int m = sc . nextInt ( ) ; boolean [ ] b = new boolean [ n ] ; Arrays . fill ( b , true ) ; for ( int i = 0 ; i < m ; i ++ ) b [ sc . nextInt ( ) ] = false ; int [ ] dp = new int [ n ] ; Arrays . fill ( dp , 0 ) ; dp [ 0 ] = 1 ; for ( int i = 0 ; i < n ; i ++ ) { if ( b [ i ] ) { if ( i + 1 < n ) { dp [ i + 1 ] = ( dp [ i + 1 ] + dp [ i ] ) % MOD ; } if ( i + 2 < n ) { dp [ i + 2 ] = ( dp [ i + 2 ] + dp [ i ] ) % MOD ; } } } System . out . println ( dp [ n - 1 ] ) ; } public static void main ( String [ ] args ) { new Main ( ) . doIt ( ) ; } } +import java . util . Arrays ; import java . util . HashMap ; import java . util . Map ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long ans = 0 ; int n = sc . nextInt ( ) ; Map < String , Long > map = new HashMap < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { String key ; char [ ] ca = sc . next ( ) . toCharArray ( ) ; Arrays . sort ( ca ) ; String s = String . valueOf ( ca ) ; if ( map . containsKey ( s ) ) map . put ( s , map . get ( s ) + 1 ) ; else map . put ( s , 1L ) ; } for ( String key : map . keySet ( ) ) { ans += map . get ( key ) * ( map . get ( key ) - 1 ) / 2 ; } System . out . println ( ans ) ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int d = sc . nextInt ( ) ; int n = sc . nextInt ( ) ; int sum = 1 ; for ( int i = 1 ; i <= d ; i ++ ) { int sum = 1 ; sum = sum * 100 ; } System . out . println ( sum * ( n + n / 100 ) ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; try ( Scanner scan = new Scanner ( System . in ) ) { int N = scan . nextInt ( ) ; int M = scan . nextInt ( ) ; int [ ] p = new int [ M ] ; String [ ] S = new String [ M ] ; for ( int i = 0 ; i < M ; i ++ ) { p [ i ] = scan . nextInt ( ) ; S [ i ] = scan . next ( ) ; } long seitou = 0 ; long pena = 0 ; String [ ] res = new String [ N ] ; int [ ] pe = new int [ N ] ; for ( int i = 0 ; i < M ; i ++ ) { if ( res [ p [ i ] - 1 ] == null ) { if ( S [ i ] . equals ( " WA " ) ) { res [ p [ i ] - 1 ] = " WA " ; pe [ p [ i ] - 1 ] ++ ; } else { res [ p [ i ] - 1 ] = " AC " ; seitou ++ ; } } else { if ( res [ p [ i ] - 1 ] . equals ( " WA " ) ) { if ( S [ i ] . equals ( " WA " ) ) { pe [ p [ i ] - 1 ] ++ ; } else { res [ p [ i ] - 1 ] = " AC " ; pena += pe [ p [ i ] - 1 ] ; seitou ++ ; } } } } System . out . println ( seitou ) ; System . out . println ( pena ) ; } } } +import java . util . HashSet ; import java . util . Scanner ; import java . util . Set ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int s = scanner . nextInt ( ) ; final Set < Integer > appeared = new HashSet < > ( ) ; int m = 1 ; do { appeared . add ( s ) ; if ( s % 2 == 0 ) { int m = 1 ; s = s / 2 ; } else { s = 3 * s + 1 ; } m ++ ; } while ( ! appeared . contains ( s ) ) ; System . out . println ( m ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int j = 0 ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int m = sc . nextInt ( ) ; int l = sc . nextInt ( ) ; int [ ] [ ] a = new int [ n ] [ m ] ; int [ ] [ ] b = new int [ m ] [ l ] ; for ( int i = 0 ; i < n ; i ++ ) for ( int j = 0 ; j < m ; j ++ ) a [ i ] [ j ] = sc . nextInt ( ) ; for ( int i = 0 ; i < m ; i ++ ) for ( int j = 0 ; j < l ; j ++ ) b [ i ] [ j ] = sc . nextInt ( ) ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < l ; j ++ ) { long cij = 0 ; for ( int k = 0 ; k < m ; k ++ ) cij += a [ i ] [ k ] * b [ k ] [ j ] ; System . out . print ( ( j == 0 ) ? cij : " " + cij ) ; } System . out . println ( ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; long n = scan . nextLong ( ) , m = scan . nextLong ( ) ; for ( int i = 0 ; i < m ; i ++ ) { long n = scan . nextLong ( ) , m = scan . nextLong ( ) ; n -= scan . nextLong ( ) ; if ( n < 0 ) { System . out . println ( - 1 ) ; scan . close ( ) ; return ; } } System . out . println ( n ) ; scan . close ( ) ; return ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int place ; double tSurf , tA ; Scanner sc = new Scanner ( System . in ) ; place = sc . nextInt ( ) ; tSurf = sc . nextDouble ( ) ; tA = sc . nextDouble ( ) ; double [ ] ts = new double [ place ] ; int result = 1 ; double min = 0 ; for ( int i = 0 ; i < place ; i ++ ) { ts [ i ] = tSurf - sc . nextInt ( ) * 0.006 ; if ( i == 0 ) { min = Math . abs ( tA - ts [ 0 ] ) ; continue ; } if ( Math . abs ( tA - ts [ i ] ) < min ) { int i = 0 ; min = Math . abs ( tA - ts [ i ] ) ; result = i + 1 ; } } System . out . println ( result ) ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { int j = 0 ; Scanner sc = new Scanner ( System . in ) ; char [ ] T = sc . next ( ) . toCharArray ( ) ; int ans = 0 ; int now = 0 ; char [ ] atcg = { 'A' , 'T' , 'C' , 'G' } ; for ( int i = 0 ; i < T . length ; i ++ ) { boolean isATCG = false ; for ( int j = 0 ; j < atcg . length ; j ++ ) { if ( T [ i ] == atcg [ j ] ) { isATCG = true ; } } if ( ! isATCG ) { now = 0 ; } else { now ++ ; ans = Math . max ( ans , now ) ; } } System . out . println ( ans ) ; } } +import java . lang . reflect . Array ; import java . util . * ; public class Main { class G { int x , y , t ; } public static void main ( String [ ] args ) { int i = 1 ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] [ ] a = new int [ n + 1 ] [ 3 ] ; for ( int i = 1 ; i <= n ; ++ i ) { a [ i ] [ 0 ] = sc . nextInt ( ) ; a [ i ] [ 1 ] = sc . nextInt ( ) ; a [ i ] [ 2 ] = sc . nextInt ( ) ; } a [ 0 ] [ 0 ] = 0 ; a [ 0 ] [ 1 ] = 0 ; a [ 0 ] [ 2 ] = 0 ; boolean ok = true ; for ( int i = 1 ; i <= n ; ++ i ) { int dt = a [ i ] [ 0 ] - a [ i - 1 ] [ 0 ] ; int dx = Math . abs ( a [ i ] [ 1 ] - a [ i - 1 ] [ 1 ] ) ; int dy = Math . abs ( a [ i ] [ 2 ] - a [ i - 1 ] [ 2 ] ) ; if ( dx + dy > dt || ( dt - dx - dy ) % 2 != 0 ) { ok = false ; System . out . println ( " No " ) ; break ; } } if ( ok ) System . out . println ( " Yes " ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner scn = new Scanner ( System . in ) ; ArrayList < Character > caca = new ArrayList < Character > ( ) ; String n = scn . next ( ) ; for ( int i = 0 ; i < n . length ( ) ; i ++ ) { int i = 0 ; if ( n . charAt ( i ) == '1' ) caca . add ( '1' ) ; else if ( n . charAt ( i ) == '0' ) caca . add ( '0' ) ; else if ( n . charAt ( i ) == 'B' ) { if ( ! caca . isEmpty ( ) ) caca . remove ( caca . size ( ) - 1 ) ; } } for ( int i = 0 ; i < caca . size ( ) ; i ++ ) System . out . print ( caca . get ( i ) ) ; System . out . println ( ) ; scn . close ( ) ; } } +import java . util . Scanner ; public class Main { void run ( ) { Scanner scan = new Scanner ( System . in ) ; int n = scan . nextInt ( ) ; int prime = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int p = scan . nextInt ( ) ; if ( is_prime ( p ) ) prime += 1 ; } System . out . println ( prime ) ; } boolean is_prime ( int p ) { int i = 3 ; if ( p == 2 ) return true ; if ( p < 2 || ( p & 1 ) == 0 ) return false ; int i = 3 ; while ( i <= Math . sqrt ( p ) ) { if ( p % i == 0 ) return false ; i = i + 2 ; } return true ; } public static void main ( String [ ] args ) { new Main ( ) . run ( ) ; } } +import java . util . * ; import java . lang . * ; import java . io . * ; public class Main { public static void main ( String [ ] args ) throws java . lang . Exception { char [ ] a = s . toCharArray ( ) ; Scanner scan = new Scanner ( System . in ) ; int n = scan . nextInt ( ) ; int k = scan . nextInt ( ) ; String s = scan . next ( ) ; char [ ] a = s . toCharArray ( ) ; if ( a [ k - 1 ] >= 'A' && a [ k - 1 ] <= 'Z' ) { a [ k - 1 ] = ( char ) ( a [ k - 1 ] - 'A' + 'a' ) ; } System . out . println ( a ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; ArrayList < Integer > vList = new ArrayList < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { vList . add ( sc . nextInt ( ) ) ; } Collections . sort ( vList ) ; double ans = ( double ) vList . get ( 0 ) ; for ( int i = 1 ; i < n ; i ++ ) { int i = 1 ; double sum = ans + ( double ) vList . get ( i ) ; ans = sum / 2 ; } System . out . println ( ans ) ; } } +import java . util . Scanner ; public class Main { public static double temp ( int t , int x ) { double hoge = Math . abs ( a - temp ( t , h [ i ] ) ) ; return t - x * 0.006 ; } public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int t = sc . nextInt ( ) ; int a = sc . nextInt ( ) ; int [ ] h = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { h [ i ] = sc . nextInt ( ) ; } double minDiff = Math . abs ( a - temp ( t , h [ 0 ] ) ) ; int num = 0 ; for ( int i = 1 ; i < n ; i ++ ) { double hoge = Math . abs ( a - temp ( t , h [ i ] ) ) ; if ( minDiff > hoge ) { minDiff = hoge ; num = i ; } } System . out . println ( num + 1 ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; String s = sc . next ( ) ; sc . close ( ) ; boolean sa = false ; boolean sine = false ; if ( n % 2 != 0 ) { System . out . println ( " No " ) ; sine = true ; } else { int [ ] a = new int [ n / 2 ] ; int [ ] b = new int [ n / 2 ] ; for ( int i = 0 ; i < n / 2 ; i ++ ) { int i = 0 ; a [ i ] = s . charAt ( i ) ; b [ i ] = s . charAt ( i + n / 2 ) ; if ( a [ i ] != b [ i ] ) { sa = true ; } } } if ( sa == true ) { System . out . println ( " No " ) ; } else if ( sine == false ) { System . out . println ( " Yes " ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; final int N = Integer . parseInt ( sc . next ( ) ) ; int [ ] a = new int [ N ] ; int first = 0 ; int second = 0 ; int loc = 0 ; for ( int i = 0 ; i < N ; i ++ ) { int k = Integer . parseInt ( sc . next ( ) ) ; if ( second <= k ) { if ( first <= k ) { second = first ; first = k ; loc = i ; } else { int j = 0 ; second = k ; } } } for ( int j = 0 ; j < N ; j ++ ) { if ( j == loc ) { System . out . println ( second ) ; } else { System . out . println ( first ) ; } } } } +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 ) { char c ; InputStream inputStream = System . in ; OutputStream outputStream = System . out ; Scanner in = new Scanner ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; TaskA solver = new TaskA ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class TaskA { public void solve ( int testNumber , Scanner in , PrintWriter out ) { String str = in . next ( ) ; int ans = 0 ; for ( char c : str . toCharArray ( ) ) { if ( c == '1' ) { ans ++ ; } } out . print ( ans ) ; } } } +import java . util . Scanner ; import java . util . Arrays ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; String [ ] sArray = s . split ( " " ) ; String t = sc . next ( ) ; String [ ] tArray = t . split ( " " ) ; String a = " " ; boolean judge = false ; for ( int k = 0 ; k < sArray . length ; k ++ ) { a = sArray [ sArray . length - 1 ] ; for ( int i = sArray . length - 1 ; i > 0 ; i -- ) { int i = sArray . length - 1 ; sArray [ i ] = sArray [ i - 1 ] ; } sArray [ 0 ] = a ; if ( Arrays . equals ( sArray , tArray ) ) { judge = true ; break ; } } if ( judge ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } sc . close ( ) ; } } +import java . io . Closeable ; import java . io . File ; import java . io . FileInputStream ; import java . io . FileNotFoundException ; import java . io . IOException ; import java . io . InputStream ; import java . io . PrintWriter ; import java . util . NoSuchElementException ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int cnt = 0 ; long A = Long . parseLong ( sc . next ( ) ) ; long B = Long . parseLong ( sc . next ( ) ) ; long C = Long . parseLong ( sc . next ( ) ) ; long D = Long . parseLong ( sc . next ( ) ) ; int [ ] g = new int [ 100 ] ; for ( int i = ( int ) A ; i < ( int ) B ; i ++ ) { int i = 0 ; g [ i ] ++ ; } for ( int i = ( int ) C ; i < ( int ) D ; i ++ ) { g [ i ] ++ ; } for ( int i = 0 ; i < 100 ; i ++ ) { if ( g [ i ] == 2 ) cnt ++ ; } System . out . print ( cnt ) ; System . out . println ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = Integer . parseInt ( sc . next ( ) ) ; int taro = 0 ; int hanako = 0 ; for ( int i = 0 ; i < n ; i ++ ) { String TS = sc . next ( ) ; String HS = sc . next ( ) ; if ( TS . compareTo ( HS ) > 0 ) { taro += 3 ; } else if ( TS . compareTo ( HS ) < 0 ) { hanako += 3 ; } else if ( TS . compareTo ( HS ) == 0 ) { int hanako = 0 ; taro ++ ; hanako ++ ; } } System . out . printf ( " %d %d \n " , taro , hanako ) ; } } +import java . math . BigDecimal ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int n = scan . nextInt ( ) ; BigDecimal [ ] an = new BigDecimal [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { BigDecimal a = scan . nextBigDecimal ( ) ; if ( BigDecimal . ZERO . compareTo ( a ) == 0 ) { System . out . println ( 0 ) ; System . exit ( 0 ) ; } an [ i ] = a ; } BigDecimal ans = BigDecimal . ONE ; for ( int i = 0 ; i < an . length ; i ++ ) { ans = ans . multiply ( an [ i ] ) ; if ( ans . compareTo ( BigDecimal . ONE . scaleByPowerOfTen ( 18 ) ) > 0 ) { System . out . println ( - 1 ) ; System . exit ( 0 ) ; } } if ( ans . compareTo ( BigDecimal . ONE . scaleByPowerOfTen ( 18 ) ) <= 0 ) { int i = 0 ; System . out . println ( ans ) ; } else { System . out . println ( - 1 ) ; } scan . close ( ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { ALDS1_1_A ( ) ; } public static void ALDS1_1_A ( ) { int j = 0 ; 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 ( ) ; } for ( int i = 1 ; i < n ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { if ( j == n - 1 ) { System . out . print ( a [ j ] ) ; } else { System . out . print ( a [ j ] + " " ) ; } } System . out . println ( ) ; int temp = a [ i ] ; int j = i - 1 ; while ( j >= 0 && temp < a [ j ] ) { a [ j + 1 ] = a [ j ] ; j -- ; } a [ j + 1 ] = temp ; } for ( int j = 0 ; j < n ; j ++ ) { if ( j == n - 1 ) { System . out . print ( a [ j ] ) ; } else { System . out . print ( a [ j ] + " " ) ; } } System . out . println ( ) ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int teki = sc . nextInt ( ) ; int waza = sc . nextInt ( ) ; long ret = 0 ; int [ ] hoge = new int [ teki ] ; if ( teki <= waza ) { System . out . println ( 0 ) ; return ; } for ( int i = 0 ; i < teki ; i ++ ) { hoge [ i ] = sc . nextInt ( ) ; } Arrays . sort ( hoge ) ; for ( int i = 0 ; i < teki - waza ; i ++ ) { int i = 0 ; ret += hoge [ i ] ; } System . out . print ( ret ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int n = scan . nextInt ( ) ; int [ ] a = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = scan . nextInt ( ) ; } int max = 0 ; int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( a [ i ] >= max ) { int i = 0 ; max = a [ i ] ; count = count + 1 ; } } System . out . println ( count ) ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { ArrayList < Integer > list = new ArrayList < Integer > ( ) ; Scanner sc = new Scanner ( System . in ) ; while ( sc . hasNext ( ) ) { list . add ( String . format ( " %d " , Math . abs ( sc . nextInt ( ) + sc . nextInt ( ) ) ) . length ( ) ) ; } for ( int i = 0 , size = list . size ( ) ; i < size ; i ++ ) { int i = 0 , size = list . size ( ) ; System . out . println ( list . get ( i ) ) ; } } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String str = sc . next ( ) ; boolean bl = false ; for ( int i = 0 ; i < 3 ; i ++ ) { bl |= ( str . charAt ( i ) == str . charAt ( i + 1 ) ) ; } if ( bl ) { int i = 0 ; System . out . println ( " Bad " ) ; } else { System . out . println ( " Good " ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int number = sc . nextInt ( ) ; int [ ] n = new int [ number ] ; int [ ] m = new int [ number ] ; for ( int i = 0 ; i < number ; i ++ ) { n [ i ] = sc . nextInt ( ) ; m [ i ] = sc . nextInt ( ) ; } int cnt = 0 ; for ( int i = 0 ; i < number ; i ++ ) { if ( n [ i ] == m [ i ] ) { cnt ++ ; } else if ( n [ i ] != m [ i ] ) { cnt = 0 ; } if ( cnt == 3 ) { int i = 0 ; System . out . println ( " Yes " ) ; return ; } } System . out . println ( " No " ) ; } } +import java . io . BufferedInputStream ; import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( new BufferedInputStream ( System . in ) ) ; Scanner sc = new Scanner ( new BufferedInputStream ( System . in ) ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int c = sc . nextInt ( ) ; if ( a + b + c >= 22 ) System . out . println ( " bust " ) ; else System . out . println ( " win " ) ; } private static int solve ( String s , int n ) { return n ; } private static int nextInt ( Scanner sc ) { return Integer . valueOf ( sc . nextLine ( ) ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int H = sc . nextInt ( ) ; int N = sc . nextInt ( ) ; int [ ] A = new int [ N ] ; for ( int i = 0 ; i < A . length ; i ++ ) { int i = 0 ; A [ i ] = sc . nextInt ( ) ; } for ( int i = 0 ; i < A . length ; i ++ ) { H -= A [ i ] ; } if ( H <= 0 ) { System . out . print ( " Yes " ) ; } else { System . out . print ( " No " ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { int ans = n * a ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int ans = n * a ; if ( ans >= b ) { ans = b ; } System . out . println ( ans ) ; sc . close ( ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) , T = sc . nextInt ( ) ; int [ ] c = new int [ n ] ; int [ ] t = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { c [ i ] = sc . nextInt ( ) ; t [ i ] = sc . nextInt ( ) ; } int ans = INF ; boolean exist = false ; for ( int i = 0 ; i < n ; i ++ ) { if ( t [ i ] <= T ) { exist = true ; ans = Math . min ( ans , c [ i ] ) ; } } if ( exist ) System . out . println ( ans ) ; else System . out . println ( " TLE " ) ; } public static final int INF = 10000 ; } +import java . io . PrintWriter ; import java . util . Arrays ; import java . util . HashSet ; import java . util . Scanner ; import java . util . Set ; public class Main { void solve ( Scanner in , PrintWriter out ) { int t = in . nextInt ( ) ; int cpt = 0 ; for ( int i = 0 ; i < t ; ++ i ) { int a1 = in . nextInt ( ) ; int b1 = in . nextInt ( ) ; if ( a1 == b1 ) { cpt ++ ; } else { cpt = 0 ; } if ( cpt == 3 ) { PrintWriter out = new PrintWriter ( System . out ) ; out . println ( " Yes " ) ; break ; } } if ( cpt != 3 ) out . println ( " No " ) ; } public static void main ( String [ ] args ) { try ( Scanner in = new Scanner ( System . in ) ; PrintWriter out = new PrintWriter ( System . out ) ) { new Main ( ) . solve ( in , out ) ; } } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int n = Integer . parseInt ( br . readLine ( ) ) ; String [ ] string = br . readLine ( ) . split ( " " ) ; int [ ] Progression = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { Progression [ i ] = Integer . parseInt ( string [ i ] ) ; } for ( int k = 0 ; k < n ; k ++ ) { System . out . print ( Progression [ k ] ) ; if ( k < n - 1 ) { System . out . print ( " " ) ; } } System . out . println ( ) ; int v ; for ( int i = 1 ; i < n ; i ++ ) { v = Progression [ i ] ; int j = i - 1 ; while ( j >= 0 && Progression [ j ] > v ) { int k = 0 ; Progression [ j + 1 ] = Progression [ j ] ; j -- ; } Progression [ j + 1 ] = v ; for ( int k = 0 ; k < n ; k ++ ) { System . out . print ( Progression [ k ] ) ; if ( k < n - 1 ) { System . out . print ( " " ) ; } } System . out . println ( ) ; } } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . StringTokenizer ; class Main { static Scanner sc = new Scanner ( ) ; public static void main ( final String [ ] args ) throws IOException { int n = sc . nextInt ( ) ; int [ ] a = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ sc . nextInt ( ) - 1 ] = i + 1 ; } for ( int i = 0 ; i < n ; i ++ ) { System . out . print ( a [ i ] + " " ) ; } } static class Scanner { BufferedReader reader = new BufferedReader ( new InputStreamReader ( System . in ) , 1 << 15 ) ; StringTokenizer tokenizer ; String next ( ) throws IOException { while ( tokenizer == null || ! tokenizer . hasMoreTokens ( ) ) { tokenizer = new StringTokenizer ( reader . readLine ( ) ) ; } return tokenizer . nextToken ( ) ; } int nextInt ( ) throws IOException { return Integer . parseInt ( next ( ) ) ; } long nextLong ( ) throws IOException { return Long . parseLong ( next ( ) ) ; } } } +import java . util . Arrays ; import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int A = sc . nextInt ( ) ; int B = sc . nextInt ( ) ; int C = sc . nextInt ( ) ; int X = sc . nextInt ( ) ; int Y = sc . nextInt ( ) ; int abprice = A * X + B * Y ; int target1 = 0 ; int target1_2 = 0 ; int target2 = 0 ; int dif = 0 ; if ( X < Y ) { int cprice = cprice1 > cprice2 ? cprice2 : cprice1 ; target1 = X ; target1_2 = Y ; target2 = B ; dif = Y - X ; } else { target1 = Y ; target1_2 = X ; target2 = A ; dif = X - Y ; } int cprice1 = C * target1 * 2 + dif * target2 ; int cprice2 = C * target1_2 * 2 ; int cprice = cprice1 > cprice2 ? cprice2 : cprice1 ; if ( abprice > cprice ) { System . out . println ( cprice ) ; } else { System . out . println ( abprice ) ; } } } +import java . util . ArrayList ; import java . util . Collections ; import java . util . List ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; List < Integer > list = new ArrayList < Integer > ( ) ; List < Integer > list_two = new ArrayList < Integer > ( ) ; int n = sc . nextInt ( ) ; for ( int i = 0 ; n > i ; i ++ ) { int a = sc . nextInt ( ) ; list . add ( a ) ; list_two . add ( a ) ; } Collections . sort ( list , Collections . reverseOrder ( ) ) ; int list_in_max = Collections . max ( list_two ) ; int maxIndex = list_two . indexOf ( Collections . max ( list_two ) ) ; if ( list . get ( 0 ) . equals ( list . get ( 1 ) ) ) { for ( int i = 0 ; n > i ; i ++ ) { System . out . println ( list_in_max ) ; } System . exit ( 0 ) ; } else { for ( int i = 0 ; n > i ; i ++ ) { int i = 0 ; if ( i == maxIndex ) { list_two . remove ( i ) ; System . out . println ( Collections . max ( list_two ) ) ; } else { System . out . println ( list_in_max ) ; } } } } } +public class Main { public static void main ( String [ ] args ) { java . util . Scanner sc = new java . util . Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] x = new int [ n ] ; double sum = 0 ; int total = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int i = 0 ; x [ i ] = sc . nextInt ( ) ; sum += x [ i ] ; } double val = sum / n ; val = Math . round ( val ) ; int avg = ( int ) val ; for ( int i = 0 ; i < n ; i ++ ) { int num = avg - x [ i ] ; num = num * num ; total += num ; } System . out . println ( total ) ; } } +import java . io . * ; import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int n = in . nextInt ( ) ; int x = in . nextInt ( ) ; int t = in . nextInt ( ) ; System . out . println ( ( int ) Math . ceil ( 1.0 * n / x ) * t ) ; } } class scan { public static BufferedReader reader ; public static StringTokenizer token ; scan ( InputStream str ) { reader = new BufferedReader ( new InputStreamReader ( str ) ) ; token = null ; } static int nextInt ( ) { while ( token == null || ! token . hasMoreTokens ( ) ) { try { token = new StringTokenizer ( reader . readLine ( ) ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } } return Integer . parseInt ( token . nextToken ( ) ) ; } static long nextLong ( ) { while ( token == null || ! token . hasMoreTokens ( ) ) { try { token = new StringTokenizer ( reader . readLine ( ) ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } } return Long . parseLong ( token . nextToken ( ) ) ; } static String next ( ) { while ( token == null || ! token . hasMoreTokens ( ) ) { try { token = new StringTokenizer ( reader . readLine ( ) ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } } return token . nextToken ( ) ; } } +import java . util . Scanner ; import java . util . Arrays ; class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int n = Integer . parseInt ( scan . nextLine ( ) ) ; String [ ] inputStr = scan . nextLine ( ) . split ( " " ) ; int inputLen = inputStr . length ; int [ ] inputInt = new int [ inputLen ] ; for ( int i = 0 ; i < inputLen ; i ++ ) { int i = 0 ; inputInt [ i ] = Integer . parseInt ( inputStr [ i ] ) ; } int tmp ; int numExchange = 0 ; int minj ; for ( int i = 0 ; i < inputLen - 1 ; i ++ ) { minj = i ; for ( int j = i + 1 ; j < inputLen ; j ++ ) { if ( inputInt [ minj ] > inputInt [ j ] ) { minj = j ; } } tmp = inputInt [ i ] ; inputInt [ i ] = inputInt [ minj ] ; inputInt [ minj ] = tmp ; if ( i != minj ) numExchange += 1 ; } for ( int i = 0 ; i < inputLen ; i ++ ) { inputStr [ i ] = String . valueOf ( inputInt [ i ] ) ; } System . out . println ( String . join ( " " , inputStr ) ) ; System . out . println ( numExchange ) ; } } +import java . util . * ; public class Main { public static Scanner in = new Scanner ( System . in ) ; public static int n = 0 , k = 2 ; public static int [ ] h = new int [ 100001 ] ; public static long [ ] dp = new long [ 100001 ] ; public final static long oo = 10000000000l ; public static long solve ( int idx ) { if ( idx == n - 1 ) { return 0 ; } else { if ( dp [ idx ] == - 1 ) { long c1 = solve ( idx + 1 ) + Math . abs ( h [ idx ] - h [ idx + 1 ] ) ; long c2 = oo ; if ( n - idx > 2 ) { c2 = solve ( idx + 2 ) + Math . abs ( h [ idx ] - h [ idx + 2 ] ) ; } return dp [ idx ] = Math . min ( c1 , c2 ) ; } else { return dp [ idx ] ; } } } public static void main ( String [ ] args ) { int i = 0 ; for ( int i = 0 ; i < 100001 ; i ++ ) { dp [ i ] = - 1 ; } n = in . nextInt ( ) ; for ( int i = 0 ; i < n ; i ++ ) { h [ i ] = in . nextInt ( ) ; } System . out . println ( solve ( 0 ) ) ; } } +import java . io . PrintWriter ; import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner stdin = new Scanner ( System . in ) ; PrintWriter out = new PrintWriter ( System . out ) ; int N = Integer . parseInt ( stdin . next ( ) ) ; int [ ] H = new int [ N ] ; int flag ; if ( N == 1 ) { flag = 1 ; } else { flag = 0 ; } for ( int i = 0 ; i < N ; i ++ ) { H [ i ] = Integer . parseInt ( stdin . next ( ) ) ; } for ( int i = N - 1 ; i > 0 ; i -- ) { if ( H [ i - 1 ] - H [ i ] > 1 ) { flag = 0 ; break ; } else if ( H [ i ] < H [ i - 1 ] ) { H [ i - 1 ] -= 1 ; } } for ( int i = 0 ; i < N - 1 ; i ++ ) { if ( H [ i ] <= H [ i + 1 ] ) { flag = 1 ; } else { flag = 0 ; break ; } } if ( flag == 1 ) { int i = 0 ; out . println ( " Yes " ) ; } else { out . println ( " No " ) ; } out . flush ( ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long a = sc . nextLong ( ) ; long b = sc . nextLong ( ) ; long c = sc . nextLong ( ) ; long d = sc . nextLong ( ) ; if ( a >= 0 ) { if ( d >= 0 ) { long d = sc . nextLong ( ) ; System . out . println ( b * d ) ; } else { System . out . println ( d * a ) ; } } else if ( b < 0 ) { if ( c >= 0 ) { System . out . println ( b * c ) ; } else { System . out . println ( c * a ) ; } } else { if ( d < 0 ) { System . out . println ( c * a ) ; } else if ( c >= 0 ) { System . out . println ( b * d ) ; } else { if ( a * c > b * d ) { System . out . println ( a * c ) ; } else { System . out . println ( b * d ) ; } } } } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader input = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String word = input . readLine ( ) ; String WORD = word . toUpperCase ( ) ; int count = 0 ; while ( true ) { String [ ] str = input . readLine ( ) . split ( " " ) ; if ( str [ 0 ] . equals ( " END_OF_TEXT " ) ) break ; String [ ] STR = new String [ str . length ] ; for ( int num = 0 ; num < str . length ; num ++ ) STR [ num ] = str [ num ] . toUpperCase ( ) ; for ( int num = 0 ; num < STR . length ; num ++ ) { int num = 0 ; if ( STR [ num ] . equals ( WORD ) ) { count ++ ; } } } System . out . println ( count ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int M = sc . nextInt ( ) ; int N = sc . nextInt ( ) ; int [ ] A = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { int M = sc . nextInt ( ) ; M -= sc . nextInt ( ) ; } System . out . println ( M >= 0 ? M : - 1 ) ; } } +import java . util . Scanner ; import java . util . ArrayDeque ; import java . util . Queue ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; Queue < Integer > queue = new ArrayDeque < > ( ) ; int n = sc . nextInt ( ) ; int q = sc . nextInt ( ) ; String [ ] name = new String [ n ] ; int [ ] time = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { name [ i ] = sc . next ( ) ; time [ i ] = sc . nextInt ( ) ; queue . add ( i ) ; } int x = 0 ; while ( ! queue . isEmpty ( ) ) { int y = queue . poll ( ) ; if ( time [ y ] <= q ) { int y = queue . poll ( ) ; x += time [ y ] ; System . out . println ( name [ y ] + " " + x ) ; } else { x += q ; time [ y ] -= q ; queue . add ( y ) ; } } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long h = sc . nextLong ( ) ; if ( h == 1 ) { long ans = 2 ; System . out . println ( 1 ) ; return ; } long x = h ; int cnt = 0 ; while ( true ) { x /= 2 ; cnt ++ ; if ( x == 1 ) break ; } long ans = 2 ; for ( int i = 0 ; i < cnt ; i ++ ) { ans *= 2 ; } if ( cnt > 0 ) ans -- ; System . out . println ( ans ) ; } } +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 ) ; BPalindromicNumbers solver = new BPalindromicNumbers ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class BPalindromicNumbers { public void solve ( int testNumber , Scanner in , PrintWriter out ) { PrintWriter out = new PrintWriter ( outputStream ) ; int a = in . nextInt ( ) ; int b = in . nextInt ( ) ; int res = 0 ; for ( int i = a ; i <= b ; i ++ ) if ( i / 10000 == i % 10 && i / 10 % 10 == i / 1000 % 10 ) res ++ ; out . println ( res ) ; } } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { int i = n ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int ans = 0 ; for ( int i = n ; i < 1000 ; i ++ ) { int k = i / 10 ; int l = i - ( int ) ( ( i / 100 ) * 100 ) ; if ( k == l ) { ans = i ; break ; } } System . out . println ( ans ) ; } } +import java . io . OutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . PrintWriter ; import java . util . StringTokenizer ; import java . io . IOException ; import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . io . InputStream ; public class Main { public static void main ( String [ ] args ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; InputReader in = new InputReader ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; AChangingACharacter solver = new AChangingACharacter ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class AChangingACharacter { public void solve ( int testNumber , InputReader in , PrintWriter out ) { int n = in . nextInt ( ) ; int k = in . nextInt ( ) ; StringBuilder ans = new StringBuilder ( in . next ( ) ) ; ans . setCharAt ( k - 1 , ( char ) ( ans . charAt ( k - 1 ) + 32 ) ) ; out . println ( ans . toString ( ) ) ; } } static class InputReader { public BufferedReader reader ; public StringTokenizer tokenizer ; public InputReader ( InputStream stream ) { reader = new BufferedReader ( new InputStreamReader ( stream ) , 32768 ) ; tokenizer = null ; } public String next ( ) { while ( tokenizer == null || ! tokenizer . hasMoreTokens ( ) ) { try { tokenizer = new StringTokenizer ( reader . readLine ( ) ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } } return tokenizer . nextToken ( ) ; } public int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner scan = new Scanner ( System . in ) ; int n = scan . nextInt ( ) ; int x = scan . nextInt ( ) ; int [ ] l = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { l [ i ] = scan . nextInt ( ) ; } scan . close ( ) ; int d = 0 ; int cnt = 1 ; for ( int i = 0 ; i < n ; i ++ ) { d = d + l [ i ] ; if ( d <= x ) cnt ++ ; } System . out . println ( cnt ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long X = sc . nextLong ( ) ; long bank = 100 ; long count = 0 ; for ( long i = bank ; i < X ; bank += bank / 100 , count ++ ) { if ( bank >= X ) { long count = 0 ; System . out . println ( count ) ; break ; } } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int [ ] a = new int [ 3 ] ; a [ 0 ] = sc . nextInt ( ) ; a [ 1 ] = sc . nextInt ( ) ; a [ 2 ] = sc . nextInt ( ) ; int K = sc . nextInt ( ) ; sc . close ( ) ; long sum = 0 ; if ( K >= a [ 0 ] ) { sum += a [ 0 ] ; K -= a [ 0 ] ; } else { long sum = 0 ; sum += K ; K = 0 ; } if ( K >= a [ 1 ] ) { K -= a [ 1 ] ; } else { K = 0 ; } if ( K >= a [ 2 ] ) { sum -= a [ 2 ] ; K -= a [ 2 ] ; } else { sum -= K ; K = 0 ; } System . out . println ( sum ) ; } } +import java . util . HashMap ; import java . util . Iterator ; import java . util . Map ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; try { String w = sc . nextLine ( ) ; int len = w . length ( ) ; Map < String , Integer > map = new HashMap < String , Integer > ( ) ; for ( int i = 0 ; i < len ; i ++ ) { String s = w . substring ( i , i + 1 ) ; if ( map . containsKey ( s ) ) { Iterator < String > iter = map . keySet ( ) . iterator ( ) ; map . put ( s , map . get ( s ) + 1 ) ; } else { map . put ( s , 1 ) ; } } for ( Iterator < String > iter = map . keySet ( ) . iterator ( ) ; iter . hasNext ( ) ; ) { if ( map . get ( iter . next ( ) ) . intValue ( ) % 2 != 0 ) { System . out . println ( " No " ) ; return ; } } System . out . println ( " Yes " ) ; } finally { sc . close ( ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner s = new Scanner ( System . in ) ; int a = s . nextInt ( ) ; String yvgubhij = s . nextLine ( ) ; HashSet < String > set = new HashSet < String > ( ) ; for ( int i = 0 ; i < a ; i ++ ) { HashSet < String > set = new HashSet < String > ( ) ; String b = s . nextLine ( ) ; set . add ( b ) ; } System . out . println ( set . size ( ) ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int a = 1 , b = 1 ; while ( a != 0 && b != 0 ) { a = scanner . nextInt ( ) ; b = scanner . nextInt ( ) ; if ( a == 0 && b == 0 ) { break ; } for ( int i = 1 ; i <= a ; i ++ ) { for ( int j = 1 ; j <= b ; j ++ ) { if ( i == 1 && j != b ) { System . out . print ( " # " ) ; } else if ( i == a && j != b ) { int j = 1 ; System . out . print ( " # " ) ; } else if ( j == b ) { System . out . println ( " # " ) ; } else if ( j == 1 ) { System . out . print ( " # " ) ; } else { System . out . print ( " . " ) ; } } } System . out . println ( " " ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int n = 1 ; Scanner stdIn = new Scanner ( System . in ) ; int i = stdIn . nextInt ( ) ; for ( int n = 1 ; i != 0 ; n ++ ) { System . out . println ( " Case " + n + " : " + i ) ; i = stdIn . nextInt ( ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { boolean flag = false ; Scanner scan = new Scanner ( System . in ) ; int A = scan . nextInt ( ) ; int B = scan . nextInt ( ) ; int C = scan . nextInt ( ) ; boolean flag = false ; if ( A == B && B != C ) { flag = true ; } if ( B == C && C != A ) { flag = true ; } if ( A == C && B != A ) { flag = true ; } if ( flag ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws IOException { int n , b , f , r , v ; String [ ] list ; int [ ] [ ] [ ] building ; StringBuilder builder = new StringBuilder ( ) ; BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; n = Integer . parseInt ( br . readLine ( ) ) ; building = new int [ 4 ] [ 3 ] [ 10 ] ; for ( int i = 0 ; i < n ; i ++ ) { list = br . readLine ( ) . split ( " " ) ; b = Integer . parseInt ( list [ 0 ] ) ; f = Integer . parseInt ( list [ 1 ] ) ; r = Integer . parseInt ( list [ 2 ] ) ; v = Integer . parseInt ( list [ 3 ] ) ; building [ b - 1 ] [ f - 1 ] [ r - 1 ] += v ; } for ( int i = 0 ; i < 4 ; i ++ ) { if ( i != 0 ) builder . append ( " #################### \n " ) ; for ( int j = 0 ; j < 3 ; j ++ ) { for ( int k = 0 ; k < 10 ; k ++ ) { int k = 0 ; builder . append ( " " + building [ i ] [ j ] [ k ] ) ; } builder . append ( " \n " ) ; } } builder . delete ( builder . length ( ) - 1 , builder . length ( ) ) ; System . out . println ( builder ) ; br . close ( ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { String R = " " ; Scanner ob = new Scanner ( System . in ) ; int N = ob . nextInt ( ) ; boolean C = true ; String R = " " ; while ( C ) { N %= 10 ; C = false ; } if ( ( N == 2 ) || ( N == 4 ) || ( N == 5 ) || ( N == 7 ) || ( N == 9 ) ) { R += " hon " ; } else if ( ( N == 0 ) || ( N == 1 ) || ( N == 6 ) || ( N == 8 ) ) { R += " pon " ; } else if ( N == 3 ) { R += " bon " ; } System . out . println ( R ) ; } } +import java . util . * ; import java . util . stream . * ; public class Main { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int N = in . nextInt ( ) ; int L = in . nextInt ( ) ; int min = Integer . MAX_VALUE ; int sum = 0 ; for ( int i = 0 ; i < N ; i ++ ) { int i = 0 ; sum += L + i ; if ( Math . abs ( L + i ) < Math . abs ( min ) ) { min = L + i ; } } System . out . println ( sum - min ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { long l = Long . parseLong ( sc . next ( ) ) ; Scanner sc = new Scanner ( System . in ) ; int n = Integer . parseInt ( sc . next ( ) ) ; int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { long l = Long . parseLong ( sc . next ( ) ) ; while ( l % 2 == 0 ) { l /= 2 ; count ++ ; } } System . out . println ( count ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { long hp = sc . nextLong ( ) ; Scanner sc = new Scanner ( System . in ) ; long hp = sc . nextLong ( ) ; System . out . println ( hit ( hp ) ) ; } private static long hit ( long hp ) { return hp == 1 ? 1 : hit ( hp / 2 ) * 2 + 1 ; } } +import java . util . * ; import java . lang . * ; import java . io . * ; public class Main { public static void main ( String [ ] args ) { int sum = 0 ; Scanner scan = new Scanner ( System . in ) ; int a = scan . nextInt ( ) ; int b = scan . nextInt ( ) ; int c = scan . nextInt ( ) ; int k = scan . nextInt ( ) ; int i = 0 ; int sum = 0 ; if ( k >= a ) { sum += a ; k = k - a ; } else { sum = k ; k = 0 ; } if ( k >= b ) k = k - b ; else k = 0 ; if ( k >= c ) sum = sum - c ; else sum = sum - k ; System . out . println ( sum ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int X = sc . nextInt ( ) ; int l = 1 ; int r = 1_000_000_007 ; for ( int i = X ; i <= r ; i ++ ) { if ( isPrime ( i ) ) { System . out . println ( i ) ; return ; } } } private static boolean isPrime ( int a ) { boolean isPrime = true ; for ( int i = 2 ; i * i < a ; i ++ ) { if ( a % i == 0 ) { int i = 2 ; isPrime = false ; break ; } } return isPrime ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] l = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { l [ i ] = sc . nextInt ( ) ; } sc . close ( ) ; int max = 0 ; int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( max < l [ i ] ) { int i = 0 ; max = l [ i ] ; } sum += l [ i ] ; } if ( sum - 2 * max > 0 ) { 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 t = 0 , h = 0 ; int x = sc . nextInt ( ) ; for ( int i = 0 ; i < x ; i ++ ) { String str1 = sc . next ( ) ; String str2 = sc . next ( ) ; if ( str1 . compareTo ( str2 ) < 0 ) { h += 3 ; } else if ( str1 . compareTo ( str2 ) == 0 ) { t ++ ; h ++ ; } else { int t = 0 , h = 0 ; t += 3 ; } } System . out . println ( t + " " + h ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String line = sc . nextLine ( ) ; String [ ] str = line . split ( " " ) ; String [ ] num = sc . nextLine ( ) . split ( " " ) ; String strU = sc . nextLine ( ) ; String strS = str [ 0 ] ; String strT = str [ 1 ] ; int numA = Integer . parseInt ( num [ 0 ] ) ; int numB = Integer . parseInt ( num [ 1 ] ) ; if ( strU . equals ( strS ) ) { numA -= 1 ; } else { int numB = Integer . parseInt ( num [ 1 ] ) ; numB -= 1 ; } System . out . println ( numA + " " + numB ) ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int ans = 1 ; int count = 0 ; int x = 0 ; int n = sc . nextInt ( ) ; for ( int i = 1 ; i <= n ; i ++ ) { if ( i % 2 == 0 ) { x = countHalf ( i ) ; if ( count < x ) { count = x ; ans = i ; } } } System . out . println ( ans ) ; sc . close ( ) ; } public static int countHalf ( int i ) { boolean a = true ; int count = 0 ; boolean a = true ; while ( a ) { if ( i % 2 == 0 ) { i /= 2 ; count ++ ; } else { a = false ; } } return count ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { long j = N / i ; Scanner scan = new Scanner ( System . in ) ; long N = scan . nextLong ( ) ; long moveCnt = ( long ) Math . pow ( 10 , 18 ) ; for ( long i = 1 ; i * i <= N ; i ++ ) { if ( N % i != 0 ) continue ; long j = N / i ; if ( moveCnt > i + j - 2 ) { moveCnt = i + j - 2 ; } } System . out . println ( moveCnt ) ; } } +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 c = sc . nextInt ( ) ; int count = 0 ; if ( a == b ) { count ++ ; } if ( b == c ) { count ++ ; } if ( c == a ) { int count = 0 ; count ++ ; } System . out . println ( count == 1 ? " Yes " : " No " ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner read = new Scanner ( System . in ) ; int n = read . nextInt ( ) ; int [ ] d = new int [ n ] ; d [ 0 ] = read . nextInt ( ) - 1 ; boolean ban = true ; for ( int i = 1 ; i < n ; i ++ ) { int i = 1 ; d [ i ] = read . nextInt ( ) ; if ( d [ i - 1 ] > d [ i ] ) { ban = false ; break ; } if ( d [ i - 1 ] < d [ i ] ) -- d [ i ] ; } if ( ban ) 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 , B , C , X , Y ; A = sc . nextInt ( ) ; B = sc . nextInt ( ) ; C = sc . nextInt ( ) ; X = sc . nextInt ( ) ; Y = sc . nextInt ( ) ; int min = A * X + B * Y ; if ( X > Y ) { int min = A * X + B * Y ; if ( C * 2 * X < min ) { min = C * 2 * X ; } if ( C * 2 * Y + ( X - Y ) * A < min ) { min = C * 2 * Y + ( X - Y ) * A ; } } else { if ( C * 2 * Y < min ) { min = C * 2 * Y ; } if ( C * 2 * X + ( Y - X ) * B < min ) { min = C * 2 * X + ( Y - X ) * B ; } } System . out . println ( min ) ; } } +import java . util . ArrayList ; import java . util . Collections ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N ; int M ; int temp ; int sum = 0 ; int P ; ArrayList < Integer > A = new ArrayList < Integer > ( ) ; Scanner sc = new Scanner ( System . in ) ; N = sc . nextInt ( ) ; M = sc . nextInt ( ) ; int i ; for ( i = 0 ; i < N ; i ++ ) { temp = sc . nextInt ( ) ; A . add ( temp ) ; sum += temp ; } Collections . sort ( A , Collections . reverseOrder ( ) ) ; P = A . get ( M - 1 ) ; if ( ( double ) sum / 4 / M > P ) { System . out . println ( " No " ) ; } else { System . out . println ( " Yes " ) ; } sc . close ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int K = sc . nextInt ( ) ; Scanner sc = new Scanner ( System . in ) ; int A = sc . nextInt ( ) ; int B = sc . nextInt ( ) ; int C = sc . nextInt ( ) ; int K = sc . nextInt ( ) ; for ( int i = 1 ; i <= K ; i ++ ) { if ( K - A == 0 ) { System . out . println ( A * 1 ) ; return ; } if ( K - A < 0 ) { System . out . println ( K * 1 ) ; return ; } if ( ( K - A ) - B <= 0 ) { System . out . println ( A * 1 + B * 0 ) ; return ; } if ( ( K - A ) - B > 0 ) { System . out . println ( A * 1 + B * 0 + ( ( ( K - A ) - B ) * ( - 1 ) ) ) ; return ; } } } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { int t = 0 ; Scanner scan = new Scanner ( System . in ) ; int n = scan . nextInt ( ) ; int [ ] [ ] [ ] OffHouse = new int [ 4 ] [ 3 ] [ 10 ] ; for ( int i = 0 ; i < n ; i ++ ) { int b = scan . nextInt ( ) ; int f = scan . nextInt ( ) ; int r = scan . nextInt ( ) ; OffHouse [ b - 1 ] [ f - 1 ] [ r - 1 ] += scan . nextInt ( ) ; } scan . close ( ) ; for ( int i = 0 ; i < 4 ; i ++ ) { for ( int s = 0 ; s < 3 ; s ++ ) { for ( int t = 0 ; t < 10 ; t ++ ) { System . out . print ( " " + OffHouse [ i ] [ s ] [ t ] ) ; } System . out . print ( " \n " ) ; if ( i != 3 && s == 2 ) System . out . println ( " #################### " ) ; } } } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { int fraction = 0 ; Scanner sc = new Scanner ( System . in ) ; long n = sc . nextInt ( ) ; long quo = n / 15 ; long rem = n % 15 ; long laps = calcLaps ( quo ) ; long rems = calcRems ( quo , rem ) ; System . out . println ( laps + rems ) ; } private static long calcLaps ( long quo ) { if ( quo == 0 ) { return 0 ; } else { long l = quo * quo ; int aLap = 60 ; return aLap * l ; } } private static long calcRems ( long quo , long rem ) { if ( rem == 0 ) { return 0 ; } else { long lapBottom = 15 * quo ; int i = 1 ; int valid = 0 ; int fraction = 0 ; while ( i <= rem ) { if ( i % 3 == 0 || i % 5 == 0 ) { i ++ ; } else { fraction += i ; valid ++ ; i ++ ; } } return lapBottom * valid + fraction ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int k = 0 ; Scanner sc = new Scanner ( System . in ) ; String s = sc . nextLine ( ) ; String t = sc . nextLine ( ) ; String [ ] sArray = s . split ( " " ) ; String [ ] tArray = t . split ( " " ) ; int num_times = sArray . length - tArray . length + 1 ; String part = new String ( ) ; int count = 9999 ; for ( int i = 0 ; i < num_times ; i ++ ) { StringBuilder sb = new StringBuilder ( ) ; for ( int j = i ; j < i + tArray . length ; j ++ ) { sb . append ( sArray [ j ] ) ; } part = sb . toString ( ) ; String [ ] partArray = part . split ( " " ) ; int currentCount = 0 ; for ( int k = 0 ; k < tArray . length ; k ++ ) { if ( ! partArray [ k ] . equals ( tArray [ k ] ) ) { currentCount ++ ; } } count = currentCount < count ? currentCount : count ; } System . out . println ( count ) ; sc . close ( ) ; } } +import java . io . * ; class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader buf = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int n = Integer . parseInt ( buf . readLine ( ) ) ; StringBuilder sb = new StringBuilder ( ) ; int num = 0 ; for ( int j = 3 ; j <= n ; j ++ ) { int j = 3 ; if ( j % 3 == 0 ) { sb . append ( " " + j ) ; } else { num = j ; while ( num != 0 ) { if ( num % 10 == 3 ) { sb . append ( " " + j ) ; break ; } else { num = num / 10 ; } } } } System . out . println ( sb ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; ArrayList < Integer > dan = new ArrayList < > ( ) ; int N = sc . nextInt ( ) ; int [ ] d = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { int i = 0 ; d [ i ] = sc . nextInt ( ) ; if ( ! dan . contains ( d [ i ] ) ) { dan . add ( d [ i ] ) ; } } System . out . println ( dan . size ( ) ) ; } } +import java . util . ArrayList ; 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 K = sc . nextInt ( ) ; ArrayList < Integer > d = new ArrayList < Integer > ( ) ; for ( int i = Math . max ( A , B ) ; i >= 1 ; i -- ) { int i = Math . max ( A , B ) ; if ( A % i == 0 && B % i == 0 ) d . add ( i ) ; } System . out . println ( d . get ( K - 1 ) ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i , o ; int q , minj , j , taihi ; int count = 0 ; Scanner sc = new Scanner ( System . in ) ; int n = Integer . parseInt ( sc . nextLine ( ) ) ; int [ ] array = new int [ n ] ; for ( i = 0 ; i < n ; i ++ ) array [ i ] = Integer . parseInt ( sc . next ( ) ) ; for ( q = 0 ; q < n ; q ++ ) { minj = q ; for ( j = q ; j < n ; j ++ ) { int [ ] array = new int [ n ] ; if ( array [ j ] < array [ minj ] ) minj = j ; } if ( q != minj ) { taihi = array [ q ] ; array [ q ] = array [ minj ] ; array [ minj ] = taihi ; count ++ ; } } for ( o = 0 ; o < n - 1 ; o ++ ) System . out . print ( array [ o ] + " " ) ; System . out . println ( array [ o ] ) ; System . out . println ( count ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . ArrayList ; import java . util . Collections ; import java . util . List ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; List < Integer > heightsOfMountain = new ArrayList < Integer > ( ) ; String line = null ; while ( ( line = br . readLine ( ) ) != null ) { String line = null ; heightsOfMountain . add ( Integer . valueOf ( line ) ) ; } Collections . sort ( heightsOfMountain ) ; Collections . reverse ( heightsOfMountain ) ; System . out . println ( heightsOfMountain . get ( 0 ) ) ; System . out . println ( heightsOfMountain . get ( 1 ) ) ; System . out . println ( heightsOfMountain . get ( 2 ) ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { int a = Integer . parseInt ( sc . next ( ) ) ; Scanner sc = new Scanner ( System . in ) ; int n = Integer . parseInt ( sc . next ( ) ) ; int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int a = Integer . parseInt ( sc . next ( ) ) ; while ( 0 < a && a % 2 == 0 ) { a /= 2 ; count ++ ; } } System . out . println ( count ) ; } } +import java . util . Scanner ; public class Main { public static Scanner scan = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { int n , sum ; n = nextInt ( ) ; sum = 0 ; int [ ] arr = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { arr [ i ] = nextInt ( ) ; } for ( int i = 0 ; i < n - 1 ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { sum += arr [ i ] * arr [ j ] ; } } print ( sum ) ; } public static int nextInt ( ) { return Integer . parseInt ( scan . next ( ) ) ; } public static long nextLong ( ) { return Long . parseLong ( scan . next ( ) ) ; } public static String next ( ) { return scan . next ( ) ; } public static double nextDouble ( ) { return Double . parseDouble ( scan . next ( ) ) ; } public static float nextFloat ( ) { return Float . parseFloat ( scan . next ( ) ) ; } public static void yesNo ( boolean flag ) { if ( flag ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } public static void print ( Object a ) { int j = i + 1 ; System . out . println ( a ) ; } } +import java . util . Scanner ; class Main { public static void main ( final String [ ] args ) { int flag = 0 ; Scanner scan = new Scanner ( System . in ) ; int W = scan . nextInt ( ) ; int H = scan . nextInt ( ) ; int x = scan . nextInt ( ) ; int y = scan . nextInt ( ) ; double area = ( double ) W * H / 2 ; int flag = 0 ; if ( x * 2 == W && y * 2 == H ) { flag = 1 ; } System . out . println ( area + " " + flag ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int A , B ; A = sc . nextInt ( ) ; B = sc . nextInt ( ) ; sc . close ( ) ; System . out . println ( solve ( A , B ) ) ; } static long solve ( int a , int b ) { long result = 1 ; int i ; for ( i = 2 ; i <= a && i <= b ; i ++ ) { if ( a % i == 0 && b % i == 0 ) { int i ; result = result * i ; a = a / i ; b = b / i ; i = 1 ; } } return result * ( long ) a * ( long ) b ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int count = 0 ; while ( sc . hasNext ( ) ) { int i = 0 ; String s = sc . next ( ) ; if ( s . equals ( " 0 " ) ) { break ; } count = 0 ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { char c = s . charAt ( i ) ; int digit = c - '0' ; count += digit ; } System . out . printf ( " %d \n " , count ) ; } } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int input = scan . nextInt ( ) ; int [ ] num = new int [ input ] ; boolean t ; int count = 0 ; for ( int i = 0 ; i < input ; i ++ ) { num [ i ] = scan . nextInt ( ) ; if ( isPrime ( num [ i ] ) ) { count ++ ; } } System . out . println ( count ) ; } static boolean isPrime ( int x ) { if ( x == 2 ) return true ; if ( x < 2 || ( x % 2 ) == 0 ) return false ; for ( int i = 3 ; i <= Math . sqrt ( x ) ; i += 2 ) { if ( x % i == 0 ) { int i = 3 ; return false ; } } return true ; } } +import java . util . Arrays ; import java . util . HashMap ; import java . util . Map ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; final int N = sc . nextInt ( ) ; int count = 0 ; for ( int i = 0 ; i < N ; i ++ ) { int j = 2 ; final int number = sc . nextInt ( ) ; final int limit = ( int ) ( Math . sqrt ( number ) ) ; boolean not_prime = false ; for ( int j = 2 ; j <= limit ; j ++ ) { if ( number % j == 0 ) { not_prime = true ; break ; } } count += not_prime ? 0 : 1 ; } System . out . println ( count ) ; } } +import java . util . Arrays ; import java . util . HashMap ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = Integer . parseInt ( sc . next ( ) ) ; int k = Integer . parseInt ( sc . next ( ) ) ; int q = Integer . parseInt ( sc . next ( ) ) ; int [ ] a = new int [ q ] ; for ( int i = 0 ; i < q ; i ++ ) { int i = 0 ; a [ i ] = Integer . parseInt ( sc . next ( ) ) ; } int [ ] point = new int [ n ] ; for ( int i = 0 ; i < q ; i ++ ) { int ans = a [ i ] - 1 ; point [ ans ] ++ ; } for ( int i = 0 ; i < n ; i ++ ) { if ( k - q + point [ i ] > 0 ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } } } +import java . io . * ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; for ( int i = 1 ; i <= n ; i ++ ) { int x = i ; if ( x % 3 == 0 ) { System . out . print ( " " + i ) ; continue ; } else if ( x % 10 == 3 ) { System . out . print ( " " + i ) ; continue ; } while ( ( x /= 10 ) != 0 ) { if ( x % 10 == 3 ) { int x = i ; System . out . print ( " " + i ) ; break ; } } } System . out . print ( " \n " ) ; } } +import javax . swing . * ; import java . io . * ; import java . util . * ; import java . math . * ; import static java . util . Comparator . * ; public class Main { public static void main ( String [ ] args ) throws IOException { FastReader s = new FastReader ( ) ; int a = s . nextInt ( ) ; int b = s . nextInt ( ) ; int numOfSock = 1 ; int count = 0 ; while ( numOfSock < b ) { numOfSock -= 1 ; numOfSock += a ; count ++ ; } System . out . println ( count ) ; } } class FastReader { BufferedReader br ; StringTokenizer st ; public FastReader ( ) { br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; } String next ( ) { while ( st == null || ! st . hasMoreElements ( ) ) { try { st = new StringTokenizer ( br . readLine ( ) ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } return st . nextToken ( ) ; } int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } long nextLong ( ) { return Long . parseLong ( next ( ) ) ; } double nextDouble ( ) { String str = " " ; return Double . parseDouble ( next ( ) ) ; } String nextLine ( ) { String str = " " ; try { str = br . readLine ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } return str ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int n ; n = in . nextInt ( ) ; SortedMap < String , Integer > poll = new TreeMap < String , Integer > ( ) ; int maxvote = 0 ; for ( long i = 0 ; i < n ; i ++ ) { String candidate = in . next ( ) ; if ( poll . containsKey ( candidate ) ) { String candidate ; poll . put ( candidate , poll . get ( candidate ) + 1 ) ; } else { poll . put ( candidate , 1 ) ; } maxvote = Math . max ( maxvote , poll . get ( candidate ) ) ; } for ( String candidate : poll . keySet ( ) ) { if ( poll . get ( candidate ) == maxvote ) System . out . println ( candidate ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; Integer [ ] p = new Integer [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { p [ i ] = sc . nextInt ( ) ; } sc . close ( ) ; Integer [ ] p_ = p . clone ( ) ; Arrays . sort ( p ) ; int count = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( p [ i ] != p_ [ i ] ) { int i = 0 ; count ++ ; } } if ( count == 0 || count == 2 ) { System . out . println ( " YES " ) ; } else { System . out . println ( " NO " ) ; } } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; StringBuilder sb = new StringBuilder ( ) ; int n = scan . nextInt ( ) ; int x = 1 ; int y = 0 ; if ( n >= 3 && n <= 10000 ) { int y = 0 ; for ( int count = 0 ; count < n ; count ++ ) { y = x / 10 ; if ( x % 3 == 0 ) { sb . append ( " " ) . append ( x ) ; } else { y = x ; while ( y != 0 ) { if ( y % 10 == 3 ) { sb . append ( " " ) . append ( x ) ; break ; } y /= 10 ; } } x ++ ; } System . out . println ( sb ) ; } } } +import java . io . * ; import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . StringTokenizer ; import java . util . * ; public class Main { static class FastReader { BufferedReader br ; StringTokenizer st ; public FastReader ( ) { br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; } String next ( ) { while ( st == null || ! st . hasMoreTokens ( ) ) { 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 { String str = " " ; str = br . readLine ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } return str ; } public Character charAt ( int i ) { return null ; } } public static void main ( String [ ] args ) throws IOException { FastReader s = new FastReader ( ) ; String n = s . next ( ) ; int p = ( int ) n . charAt ( 0 ) ; p ++ ; System . out . println ( ( char ) p ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int [ ] iro = new int [ 8 ] ; int tourist = 0 ; int N = sc . nextInt ( ) ; for ( int i = 0 ; i < 8 ; i ++ ) { iro [ i ] = 0 ; } int tmp = 0 ; for ( int i = 0 ; i < N ; i ++ ) { tmp = sc . nextInt ( ) ; if ( tmp < 3200 ) { iro [ tmp / 400 ] ++ ; } else { tourist ++ ; } } int clr = 0 ; for ( int i = 0 ; i < 8 ; i ++ ) { int i = 0 ; if ( iro [ i ] > 0 ) { clr ++ ; } } System . out . println ( Math . max ( 1 , clr ) + " " + ( clr + tourist ) ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { long v = a , u = b , y ; Scanner sc = new Scanner ( System . in ) ; long a = sc . nextLong ( ) ; long b = sc . nextLong ( ) ; System . out . println ( helper ( a , b ) ) ; sc . close ( ) ; } static long helper ( long a , long b ) { long v = a , u = b , y ; while ( b > 0 ) { y = a % b ; a = b ; b = y ; } return v * u / a ; } } +import java . util . ArrayList ; import java . util . List ; import java . util . Scanner ; public class Main { public static void main ( String [ ] arges ) { List < String > klist = new ArrayList < String > ( ) ; int i = 0 ; Scanner sc = new Scanner ( System . in ) ; while ( i < 1 ) { String line = sc . nextLine ( ) ; klist . add ( line ) ; if ( line . equals ( " 0 0 " ) ) { break ; } } for ( String string : klist ) { if ( string . equals ( " 0 0 " ) ) { break ; } String [ ] k = string . split ( " " ) ; int v = Integer . parseInt ( k [ 0 ] ) ; int v2 = Integer . parseInt ( k [ 1 ] ) ; for ( int j = 0 ; j < v ; j ++ ) { int count = 0 ; if ( ( j + 1 ) % 2 == 1 ) { while ( count < v2 ) { if ( ( count + 1 ) % 2 == 1 ) { System . out . print ( " # " ) ; count ++ ; } else { int count = 0 ; System . out . print ( " . " ) ; count ++ ; } } } else { while ( count < v2 ) { if ( ( count + 1 ) % 2 == 1 ) { System . out . print ( " . " ) ; count ++ ; } else { System . out . print ( " # " ) ; count ++ ; } } } System . out . println ( " " ) ; } System . out . println ( " " ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; String s = sc . next ( ) ; int count = 0 ; for ( int i = 0 ; i < n - 2 ; i ++ ) { if ( s . charAt ( i ) == 'A' && s . charAt ( i + 1 ) == 'B' && s . charAt ( i + 2 ) == 'C' ) { count ++ ; } } System . out . println ( count ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; String [ ] s = { " AC " , " WA " , " TLE " , " RE " } ; int [ ] ans = new int [ 4 ] ; for ( int N = sc . nextInt ( ) ; N > 0 ; N -- ) { String t = sc . next ( ) ; for ( int i = 0 ; i < 4 ; i ++ ) { if ( t . charAt ( 0 ) == s [ i ] . charAt ( 0 ) ) ans [ i ] ++ ; } } for ( int i = 0 ; i < 4 ; i ++ ) { System . out . println ( s [ i ] + " x " + ans [ i ] ) ; } } } +import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int n = scan . nextInt ( ) ; int [ ] A = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { A [ i ] = scan . nextInt ( ) ; } double c = 0 ; Arrays . sort ( A ) ; c = ( A [ 0 ] + A [ 1 ] ) / 2.0 ; for ( int i = 2 ; i < n ; i ++ ) { int i = 2 ; c = ( c + A [ i ] ) / 2.0 ; } System . out . println ( c ) ; } } +import java . io . BufferedInputStream ; import java . io . BufferedOutputStream ; import java . io . PrintWriter ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws Exception { try ( BufferedInputStream in = new BufferedInputStream ( System . in ) ; PrintWriter out = new PrintWriter ( new BufferedOutputStream ( System . out ) ) ) { Scanner sc = new Scanner ( in ) ; String s = sc . next ( ) ; int [ ] [ ] dp = new int [ 2 ] [ s . length ( ) ] ; char c = s . charAt ( 0 ) ; dp [ 0 ] [ 0 ] = ( c == '1' ? 1 : 0 ) ; dp [ 1 ] [ 0 ] = ( c == '0' ? 1 : 0 ) ; for ( int i = 1 ; i < s . length ( ) ; i ++ ) { int i = 1 ; char x = s . charAt ( i ) ; dp [ 0 ] [ i ] = ( x == '1' ? 1 : 0 ) + dp [ 1 ] [ i - 1 ] ; dp [ 1 ] [ i ] = ( x == '0' ? 1 : 0 ) + dp [ 0 ] [ i - 1 ] ; } out . println ( Math . min ( dp [ 0 ] [ s . length ( ) - 1 ] , dp [ 1 ] [ s . length ( ) - 1 ] ) ) ; } } } +import java . math . BigInteger ; import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String [ ] arg = sc . nextLine ( ) . split ( " " ) ; int n = Integer . parseInt ( arg [ 0 ] ) ; String d = arg [ 1 ] ; int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { String [ ] value = sc . nextLine ( ) . split ( " " ) ; BigInteger x = new BigInteger ( value [ 0 ] ) ; BigInteger y = new BigInteger ( value [ 1 ] ) ; BigInteger xs = x . multiply ( x ) ; BigInteger ys = y . multiply ( y ) ; BigInteger comp = xs . add ( ys ) ; BigInteger dd = new BigInteger ( d ) ; BigInteger ds = dd . multiply ( dd ) ; if ( comp . compareTo ( ds ) <= 0 ) { int count = 0 ; count ++ ; } } System . out . println ( count ) ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long l = sc . nextLong ( ) ; long r = sc . nextLong ( ) ; long min = Long . MAX_VALUE ; int cnt = 0 ; if ( r - l >= 2018 ) { System . out . println ( 0 ) ; return ; } for ( long i = l ; i < r ; i ++ ) { for ( long j = i + 1 ; j <= r ; j ++ ) { long j = i + 1 ; cnt ++ ; min = Math . min ( ( i * j ) % 2019 , min ) ; } if ( min == 0 ) break ; } System . out . println ( min ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int maxCount = 0 ; int maxNum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int count = 0 ; int num = i + 1 ; while ( true ) { if ( num % 2 != 0 ) { int num = i + 1 ; break ; } num /= 2 ; count ++ ; } if ( i == 0 || count > maxCount ) { maxCount = count ; maxNum = i + 1 ; } } System . out . println ( maxNum ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String S = sc . nextLine ( ) ; String T = sc . nextLine ( ) ; sc . close ( ) ; boolean isOK = true ; for ( int i = 0 ; i < S . length ( ) ; i ++ ) { char sVal = S . charAt ( i ) ; char tVal = T . charAt ( i ) ; if ( sVal != tVal ) { int i = 0 ; isOK = false ; break ; } } if ( isOK ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String input = sc . next ( ) ; char [ ] charArray = input . toCharArray ( ) ; Arrays . sort ( charArray ) ; String sortedString = new String ( charArray ) ; int N = sortedString . length ( ) ; int cnt = 0 ; char tmpVal = sortedString . charAt ( 0 ) ; if ( N <= 1 ) { char val = sortedString . charAt ( i ) ; System . out . println ( " No " ) ; return ; } for ( int i = 0 ; i < N ; i ++ ) { char val = sortedString . charAt ( i ) ; if ( val == tmpVal ) { cnt ++ ; } else { if ( cnt % 2 != 0 ) { System . out . println ( " No " ) ; return ; } cnt = 1 ; tmpVal = val ; } } System . out . println ( " Yes " ) ; } } +import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws Exception { int [ ] a = new int [ 3 ] ; Scanner sc = new Scanner ( System . in ) ; int [ ] a = new int [ 3 ] ; a [ 0 ] = sc . nextInt ( ) ; a [ 1 ] = sc . nextInt ( ) ; a [ 2 ] = sc . nextInt ( ) ; int k = sc . nextInt ( ) ; sc . close ( ) ; Arrays . parallelSort ( a ) ; for ( int i = 0 ; i < k ; i ++ ) { a [ 2 ] *= 2 ; } System . out . println ( a [ 0 ] + a [ 1 ] + a [ 2 ] ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; boolean b = true ; int n = sc . nextInt ( ) ; long l = 1000000000 ; l *= l ; long po = 1 ; for ( int i = 0 ; i < n ; i ++ ) { if ( po == 0 ) { break ; } else { long a = sc . nextLong ( ) ; long a = sc . nextLong ( ) ; if ( ( l / po >= a ) ) { po *= a ; } else { b = false ; } } } System . out . println ( b ? po : ( po == 0 ) ? 0 : - 1 ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int count5 = 0 ; int count7 = 0 ; Scanner sc = new Scanner ( System . in ) ; String [ ] line = sc . nextLine ( ) . split ( " " ) ; for ( String n : line ) { if ( n . equals ( " 5 " ) ) { String n ; count5 ++ ; } if ( n . equals ( " 7 " ) ) { count7 ++ ; } } if ( count5 == 2 && count7 == 1 ) { System . out . println ( " YES " ) ; } else { System . out . println ( " NO " ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int x = sc . nextInt ( ) ; int y = sc . nextInt ( ) ; int m = 0 ; int flag = 0 ; if ( y <= x * 2 || y <= x * 4 ) { int i = 1 ; for ( int i = 1 ; i <= x ; i ++ ) { int j = i * 2 ; m = i * 4 ; int h = y - j ; int h1 = y - m ; if ( ( h1 % 2 == 0 && h1 / 2 == x - i ) || ( h % 4 == 0 && h / 4 == x - i ) ) { flag = 1 ; break ; } } } if ( flag == 1 ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } } +import java . util . ArrayList ; import java . util . Collections ; import java . util . List ; import java . util . Scanner ; public class Main { private static Scanner sc = new Scanner ( System . in ) ; static void p ( String ans ) { System . out . println ( ans ) ; } static void p ( int ans ) { System . out . println ( ans ) ; } static void p ( long ans ) { System . out . println ( ans ) ; } static void p ( double ans ) { System . out . println ( ans ) ; } public static void main ( String [ ] args ) { String aa = sc . next ( ) ; char a = ( char ) ( aa . charAt ( 0 ) + 1 ) ; String vv = a + " " ; p ( vv ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int A = scanner . nextInt ( ) ; int B = scanner . nextInt ( ) ; if ( B == 1 ) { int count = 0 ; System . out . println ( 0 ) ; return ; } int count = 0 ; while ( ( A * count - ( count - 1 ) ) < B ) { count ++ ; } System . out . println ( count ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 1 ; Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; String C = sc . next ( ) ; int count = 1 ; for ( int i = 1 ; i < C . length ( ) ; i ++ ) { if ( ! C . substring ( i - 1 , i ) . equals ( C . substring ( i , i + 1 ) ) ) count ++ ; } System . out . println ( count ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner input = new Scanner ( System . in ) ; int N = Integer . parseInt ( input . nextLine ( ) ) ; int W = Integer . parseInt ( input . nextLine ( ) ) ; int [ ] v = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) v [ i ] = i ; for ( int i = 0 ; i < W ; i ++ ) { int i = 0 ; String [ ] s = input . nextLine ( ) . split ( " [,] " ) ; int a = Integer . parseInt ( s [ 0 ] ) - 1 ; int b = Integer . parseInt ( s [ 1 ] ) - 1 ; int tmp = v [ a ] ; v [ a ] = v [ b ] ; v [ b ] = tmp ; } for ( int i = 0 ; i < N ; i ++ ) { System . out . println ( v [ i ] + 1 ) ; } System . exit ( 0 ) ; } } +import java . util . * ; import java . lang . * ; import java . io . * ; import java . util . List ; import java . util . ArrayList ; import java . util . Comparator ; import java . util . Arrays ; class Main { public static void main ( String [ ] args ) { int ans = 0 ; Scanner scanner = new Scanner ( System . in ) ; int d = scanner . nextInt ( ) ; int n = scanner . nextInt ( ) ; switch ( d ) { case 0 : if ( n == 100 ) { int n = scanner . nextInt ( ) ; System . out . println ( n + 1 ) ; } else { System . out . println ( n ) ; } break ; case 1 : if ( n == 100 ) { System . out . println ( n * 100 + 100 ) ; } else { System . out . println ( n * 100 ) ; } break ; case 2 : if ( n == 100 ) { System . out . println ( n * 10000 + 10000 ) ; } else { System . out . println ( n * 10000 ) ; } break ; } scanner . close ( ) ; } } +import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . io . IOException ; import java . lang . Exception ; import java . lang . Integer ; import java . lang . String ; import java . lang . System ; import java . util . StringTokenizer ; class Main { public static void main ( String [ ] a ) throws IOException { int i = 0 ; java . io . BufferedReader r = new java . io . BufferedReader ( new java . io . InputStreamReader ( System . in ) ) ; try { int count = Integer . parseInt ( r . readLine ( ) ) ; String [ ] ans = new String [ count ] ; for ( int i = 0 ; i < count ; i ++ ) { String s = r . readLine ( ) ; StringTokenizer st = new StringTokenizer ( s ) ; int [ ] num = new int [ 4 ] ; for ( int j = 0 ; j < 3 ; j ++ ) { num [ j ] = Integer . parseInt ( st . nextToken ( ) ) ; if ( num [ 0 ] < num [ j ] ) { int tmp = num [ 0 ] ; num [ 0 ] = num [ j ] ; num [ j ] = tmp ; } } if ( num [ 0 ] * num [ 0 ] == num [ 1 ] * num [ 1 ] + num [ 2 ] * num [ 2 ] ) { ans [ i ] = " YES " ; } else { ans [ i ] = " NO " ; } } for ( int i = 0 ; i < count ; i ++ ) { System . out . println ( ans [ i ] ) ; } } catch ( Exception ex ) { System . exit ( 0 ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; String t = sc . next ( ) ; sc . close ( ) ; String [ ] s_arr = s . split ( " " ) ; String [ ] t_arr = t . split ( " " ) ; int count = 0 ; for ( int i = 0 ; i < s_arr . length ; i ++ ) { if ( s_arr [ i ] . equals ( t_arr [ i ] ) ) { count ++ ; } } System . out . println ( count ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int [ ] best = { 0 , 0 , 0 } ; for ( int i = 0 ; i < 10 ; i ++ ) { String line = br . readLine ( ) ; int height = Integer . parseInt ( line ) ; if ( height > best [ 0 ] ) { int h ; best [ 2 ] = best [ 1 ] ; best [ 1 ] = best [ 0 ] ; best [ 0 ] = height ; } else if ( height > best [ 1 ] ) { best [ 2 ] = best [ 1 ] ; best [ 1 ] = height ; } else if ( height > best [ 2 ] ) { best [ 2 ] = height ; } } for ( int h : best ) { System . out . println ( h ) ; } } } +import java . util . Scanner ; public class Main { void solve ( ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int [ ] p = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { p [ i ] = sc . nextInt ( ) ; } if ( isOK ( p ) ) { int i = 0 ; System . out . println ( " YES " ) ; return ; } for ( int i = 0 ; i <= N - 2 ; i ++ ) { for ( int j = i + 1 ; j <= N - 1 ; j ++ ) { int [ ] pClone = p . clone ( ) ; int tmp = pClone [ i ] ; pClone [ i ] = pClone [ j ] ; pClone [ j ] = tmp ; if ( isOK ( ( pClone ) ) ) { System . out . println ( " YES " ) ; return ; } } } System . out . println ( " NO " ) ; } boolean isOK ( int [ ] array ) { for ( int i = 0 ; i <= array . length - 2 ; i ++ ) { if ( array [ i ] > array [ i + 1 ] ) { return false ; } } return true ; } public static void main ( String [ ] args ) { new Main ( ) . solve ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int ans = 0 ; Scanner sc = new Scanner ( System . in ) ; int ans = 0 ; int A = sc . nextInt ( ) ; int B = sc . nextInt ( ) ; while ( ( A - 1 ) * ( ans - 1 ) + A < B ) { ans ++ ; } System . out . println ( ans ) ; sc . close ( ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int i = 1 ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] w = new int [ n + 1 ] ; int sum = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { w [ i ] = sc . nextInt ( ) ; sum += w [ i ] ; } int s1 = 0 ; int s2 = 0 ; int ans = sum ; for ( int i = 1 ; i <= n ; i ++ ) { s1 += w [ i ] ; s2 = sum - s1 ; ans = Math . min ( ans , Math . abs ( s2 - s1 ) ) ; } System . out . println ( ans ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { char [ ] Tchar = T . toCharArray ( ) ; Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; String S = sc . next ( ) ; String T = sc . next ( ) ; int i = 0 ; char [ ] Schar = S . toCharArray ( ) ; char [ ] Tchar = T . toCharArray ( ) ; for ( i = 0 ; i < N ; i ++ ) { System . out . print ( Schar [ i ] ) ; System . out . print ( Tchar [ i ] ) ; } return ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int [ ] country = new int [ sc . nextInt ( ) ] ; int M = sc . nextInt ( ) ; for ( int i = 0 ; i < M ; i ++ ) { int i ; int point = sc . nextInt ( ) - 1 ; country [ point ] = country [ point ] + 1 ; point = sc . nextInt ( ) - 1 ; country [ point ] = country [ point ] + 1 ; } for ( int i : country ) { System . out . println ( i ) ; } } } +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 ) ; C solver = new C ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class C { public void solve ( int testNumber , Scanner in , PrintWriter out ) { int N = Integer . parseInt ( in . next ( ) ) ; int preT = 0 ; int preX = 0 ; int preY = 0 ; for ( int i = 0 ; i < N ; i ++ ) { int preY = 0 ; int postT = Integer . parseInt ( in . next ( ) ) ; int postX = Integer . parseInt ( in . next ( ) ) ; int postY = Integer . parseInt ( in . next ( ) ) ; int dt = postT - preT ; int dist = Math . abs ( postX - preX ) + Math . abs ( postY - preY ) ; if ( ( dt < dist ) || ( ( ( dist - dt ) & 1 ) != 0 ) ) { out . println ( " No " ) ; return ; } preT = postT ; preX = postX ; preY = postY ; } out . println ( " Yes " ) ; } } } +import java . util . * ; import java . lang . * ; import java . io . * ; import java . util . Scanner ; class Main { public static void main ( String [ ] args ) throws java . lang . Exception { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; char [ ] chars = s . toCharArray ( ) ; for ( char c : chars ) { char c ; if ( c == '1' ) { System . out . print ( 9 ) ; } else { System . out . print ( 1 ) ; } } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner ob = new Scanner ( System . in ) ; int D = ob . nextInt ( ) ; int T = ob . nextInt ( ) ; int S = ob . nextInt ( ) ; int sum = 0 ; for ( int i = 1 ; i <= T ; i ++ ) { int sum = 0 ; sum += S ; } System . out . println ( ( sum < D ) ? " No " : " Yes " ) ; ob . close ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int i = 1 ; while ( true ) { int x = sc . nextInt ( ) ; int y = sc . nextInt ( ) ; if ( x == 0 && y == 0 ) break ; if ( x < y ) { System . out . println ( x + " " + y ) ; } else { int y = sc . nextInt ( ) ; System . out . println ( y + " " + x ) ; } i ++ ; } } } +import java . io . * ; import java . util . * ; import java . util . stream . * ; public class Main { private static BufferedReader br = null ; public static void main ( String [ ] args ) { String n = read ( 1 ) [ 0 ] ; for ( int i = 0 ; i < n . length ( ) ; i ++ ) { System . out . print ( n . charAt ( i ) == '1' ? '9' : '1' ) ; } System . out . println ( ) ; } private static String [ ] read ( int len ) { List < String > strList = new ArrayList < > ( ) ; try { if ( br == null ) { br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; } for ( int i = 0 ; i < len ; i ++ ) { int i = 0 ; strList . add ( br . readLine ( ) ) ; } } catch ( IOException e ) { } return strList . toArray ( new String [ 0 ] ) ; } private static void close ( ) { try { if ( br != null ) { br . close ( ) ; } } catch ( IOException e ) { } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; try ( Scanner scanner = new Scanner ( System . in ) ) { int x = scanner . nextInt ( ) , y = scanner . nextInt ( ) ; System . out . println ( ( ( x * 2 <= y ) && ( x * 4 >= y ) && ( 0 == ( y & 1 ) ) ) ? " Yes " : " No " ) ; } } } +import java . util . * ; public class Main { private final static int MOD = 1_000_000_007 ; public static int gcd ( int a , int b ) { if ( a == 0 ) return b ; if ( b == 0 ) return a ; if ( a == b ) return a ; if ( a > b ) return gcd ( a - b , b ) ; return gcd ( a , b - a ) ; } public static long mod ( long a , long b ) { return ( ( a % b ) + b ) % b ; } public static int mod ( int a , int b ) { return ( ( a % b ) + b ) % b ; } public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; String s = in . nextLine ( ) ; String t = in . nextLine ( ) ; int res = 0 ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { int i = 0 ; if ( s . charAt ( i ) != t . charAt ( i ) ) res ++ ; } System . out . println ( res ) ; in . close ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int d = sc . nextInt ( ) ; int result = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int result = 0 ; double calc = Math . sqrt ( Math . pow ( sc . nextInt ( ) , 2 ) + Math . pow ( sc . nextInt ( ) , 2 ) ) ; if ( calc <= d ) result ++ ; } System . out . println ( result ) ; sc . close ( ) ; } } +import java . util . Scanner ; import java . util . Date ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int a , b , c , m , n ; while ( sc . hasNext ( ) ) { int a , b , c , m , n ; a = sc . nextInt ( ) ; b = sc . nextInt ( ) ; m = a ; n = b ; if ( m < n ) { c = n ; n = m ; m = c ; } while ( true ) { if ( n == 0 ) break ; c = n ; n = m % n ; m = c ; } System . out . printf ( " %d %d \n " , m , a / m * b ) ; } } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner input = new Scanner ( System . in ) ; int count = 1 ; while ( true ) { String str = input . nextLine ( ) ; if ( ! str . equals ( " 0 " ) ) { System . out . println ( " Case " + count + " : " + str ) ; count = count + 1 ; } else { String str = input . nextLine ( ) ; break ; } } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int j = 0 ; Scanner scanner = new Scanner ( System . in ) ; int A = scanner . nextInt ( ) ; int B = scanner . nextInt ( ) ; int count = 0 ; for ( int i = A ; i < B + 1 ; i ++ ) { String s = String . valueOf ( i ) ; String [ ] array = new String [ 5 ] ; for ( int j = 0 ; j < 5 ; j ++ ) { array [ j ] = s . substring ( j , j + 1 ) ; } if ( array [ 0 ] . equals ( array [ 4 ] ) && array [ 1 ] . equals ( array [ 3 ] ) ) { count ++ ; } } System . out . println ( count ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int A = scan . nextInt ( ) ; int B = scan . nextInt ( ) ; int K = scan . nextInt ( ) ; int min = 0 ; int count = 0 ; if ( A < B ) { min = A ; } else { int i = min ; min = B ; } for ( int i = min ; i >= 1 ; i -- ) { if ( A % i == 0 && B % i == 0 ) { count ++ ; if ( count == K ) { System . out . println ( i ) ; break ; } } } scan . close ( ) ; } } +import java . util . Scanner ; public class Main { static Scanner sc = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { while ( sc . hasNext ( ) ) { String alf = sc . next ( ) ; String alf = sc . next ( ) ; if ( alf . equals ( " - " ) ) break ; int m = sc . nextInt ( ) ; for ( int i = 0 ; i < m ; i ++ ) { int subNum = sc . nextInt ( ) ; String tmpSub = alf . substring ( 0 , subNum ) ; String tmp = alf . substring ( subNum ) ; alf = tmp + tmpSub ; } System . out . println ( alf ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = Integer . parseInt ( sc . next ( ) ) ; int [ ] a = new int [ n + 1 ] ; for ( int i = 1 ; i <= n ; i ++ ) { a [ i ] = Integer . parseInt ( sc . next ( ) ) ; } int [ ] b = new int [ n + 1 ] ; b [ 0 ] = 1 ; int i = 1 ; int ans = - 1 ; while ( i <= n ) { int ans = - 1 ; b [ i ] = a [ b [ i - 1 ] ] ; if ( b [ i ] == 2 ) { ans = i ; break ; } i ++ ; } System . out . println ( ans ) ; } } +import java . io . * ; class Main { public static void main ( String [ ] args ) { try { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int i = Integer . parseInt ( br . readLine ( ) ) ; for ( int f = 0 ; f < i ; f ++ ) { String [ ] str = br . readLine ( ) . split ( " \\ s " ) ; int a = Integer . parseInt ( str [ 0 ] ) ; a *= a ; int b = Integer . parseInt ( str [ 1 ] ) ; b *= b ; int c = Integer . parseInt ( str [ 2 ] ) ; c *= c ; if ( a + b == c || b + c == a || c + a == b ) System . out . println ( " YES " ) ; else System . out . println ( " NO " ) ; } } catch ( IOException e ) { } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long x = sc . nextLong ( ) ; if ( x == 1 || x == 2 || x == 3 ) { System . out . println ( x ) ; return ; } while ( true ) { boolean prime = true ; for ( int i = 2 ; i <= x / 2 ; i ++ ) { int i = 2 ; if ( x % i == 0 ) { prime = false ; break ; } } if ( prime ) { System . out . println ( x ) ; return ; } x ++ ; } } } +import java . util . Arrays ; import java . util . HashMap ; import java . util . Map ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; Map < Integer , Integer > map = new HashMap < Integer , Integer > ( ) ; Integer [ ] a = new Integer [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = sc . nextInt ( ) ; map . put ( a [ i ] , i + 1 ) ; } Arrays . sort ( a ) ; StringBuilder ans = new StringBuilder ( ) ; for ( Integer i : a ) { Integer i ; ans . append ( map . get ( i ) ) ; ans . append ( " " ) ; } System . out . println ( ans ) ; } } +import java . util . Scanner ; import java . util . Arrays ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int n = scan . nextInt ( ) ; long [ ] a = new long [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = scan . nextLong ( ) ; if ( a [ i ] == 0 ) { System . out . println ( 0 ) ; return ; } } Arrays . sort ( a ) ; long ans = 1 ; for ( int i = n - 1 ; i >= 0 ; i -- ) { if ( a [ i ] > 1000000000000000000L / ans ) { System . out . println ( - 1 ) ; return ; } else { int i = n - 1 ; ans *= a [ i ] ; } } System . out . println ( ans ) ; } } +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 ) ; abc165_b solver = new abc165_b ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class abc165_b { public void solve ( int testNumber , Scanner in , PrintWriter out ) { long year = 1 ; long X = in . nextLong ( ) ; long base = 100 ; long year = 1 ; while ( true ) { base += Math . floor ( base / 100 ) ; if ( X <= base ) { out . println ( year ) ; return ; } else { year ++ ; } } } } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int ans = 0 ; for ( int i = a ; i <= b ; i ++ ) { int i = a ; String as = Integer . toString ( i ) ; List < String > list = Arrays . asList ( Integer . toString ( i ) . split ( " " ) ) ; Collections . reverse ( list ) ; String [ ] bs = ( String [ ] ) list . toArray ( new String [ list . size ( ) ] ) ; String strb = String . join ( " " , bs ) ; if ( as . equals ( strb ) ) ans ++ ; } System . out . println ( ans ) ; } } +import java . util . Scanner ; class Main { static Scanner sc = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { int N = sc . nextInt ( ) ; long sum = 0 , left = 0 ; int [ ] A = new int [ N + 1 ] ; for ( int i = 0 ; i <= N ; i ++ ) { int i = 0 ; A [ i ] = sc . nextInt ( ) ; sum += A [ i ] ; } for ( int i = 0 ; i < N ; i ++ ) { int temp = sc . nextInt ( ) ; if ( temp >= A [ i ] ) { temp -= A [ i ] ; if ( A [ i + 1 ] > temp ) A [ i + 1 ] -= temp ; else A [ i + 1 ] = 0 ; A [ i ] = 0 ; } else A [ i ] -= temp ; } for ( int i = 0 ; i <= N ; i ++ ) left += A [ i ] ; System . out . println ( sum - left ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int x = sc . nextInt ( ) ; int y = sc . nextInt ( ) ; for ( int i = 1 ; i <= x ; i ++ ) { if ( y == ( i * 2 ) + ( ( x - i ) * 4 ) ) { System . out . println ( " Yes " ) ; return ; } } for ( int i = 1 ; i <= x ; i ++ ) { if ( y == ( i * 4 ) + ( ( x - i ) * 2 ) ) { int i = 1 ; System . out . println ( " Yes " ) ; return ; } } for ( int i = 1 ; i <= x / 2 ; i ++ ) { if ( y == i * 2 ) { System . out . println ( " Yes " ) ; return ; } } for ( int i = 1 ; i <= x / 4 ; i ++ ) { if ( y == i * 4 ) { System . out . println ( " Yes " ) ; return ; } } System . out . println ( " No " ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner scan = new Scanner ( System . in ) ; int N = Integer . parseInt ( scan . next ( ) ) ; int T = Integer . parseInt ( scan . next ( ) ) ; int A = Integer . parseInt ( scan . next ( ) ) ; int H ; int temp ; int res = 0 ; int cc = 1000000000 ; int i = 0 ; for ( i = 1 ; i <= N ; i ++ ) { H = Integer . parseInt ( scan . next ( ) ) ; temp = T * 1000 - H * 6 - A * 1000 ; if ( temp < 0 ) temp = - temp ; if ( temp < cc ) { cc = temp ; res = i ; } } System . out . println ( res ) ; } } +import java . math . BigInteger ; import java . util . * ; import java . io . * ; public class Main { public static void main ( String [ ] args ) throws IOException { Scanner sc = new Scanner ( System . in ) ; PrintWriter pw = new PrintWriter ( System . out ) ; int n = sc . nextInt ( ) ; pw . println ( 1 - n ) ; pw . flush ( ) ; } static class Scanner { BufferedReader br ; StringTokenizer st ; public Scanner ( InputStream s ) { br = new BufferedReader ( new InputStreamReader ( s ) ) ; } public Scanner ( FileReader f ) { br = new BufferedReader ( f ) ; } public String next ( ) throws IOException { while ( st == null || ! st . hasMoreTokens ( ) ) st = new StringTokenizer ( br . readLine ( ) ) ; return st . nextToken ( ) ; } public int nextInt ( ) throws IOException { return Integer . parseInt ( next ( ) ) ; } public long nextLong ( ) throws IOException { return Long . parseLong ( next ( ) ) ; } public double nextDouble ( ) throws IOException { return Double . parseDouble ( next ( ) ) ; } public int [ ] nextIntArr ( int n ) throws IOException { int i = 0 ; int [ ] arr = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { arr [ i ] = Integer . parseInt ( next ( ) ) ; } return arr ; } } } +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 ] ; int sumA = 0 ; int sumB = 0 ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = sc . nextInt ( ) ; } Arrays . sort ( a ) ; for ( int i = n - 1 ; i >= 0 ; i -= 2 ) { sumA += a [ i ] ; } for ( int i = n - 2 ; i >= 0 ; i -= 2 ) { int i = n - 2 ; sumB += a [ i ] ; } System . out . println ( sumA - sumB ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int n = scan . nextInt ( ) ; int x = scan . nextInt ( ) ; int count = 0 ; while ( n != 0 || x != 0 ) { for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = i + 1 ; j <= n ; j ++ ) { int k = j + 1 ; for ( int k = j + 1 ; k <= n ; k ++ ) { if ( i + j + k == x ) { count ++ ; } } } } System . out . println ( count ) ; n = scan . nextInt ( ) ; x = scan . nextInt ( ) ; count = 0 ; } } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int c0 = 0 ; int c1 = 0 ; int c2 = 0 ; int c3 = 0 ; for ( int i = 0 ; i < n + 1 ; i ++ ) { String s = sc . nextLine ( ) ; if ( s . equals ( " AC " ) ) { int c3 = 0 ; ++ c0 ; } else if ( s . equals ( " WA " ) ) { ++ c1 ; } else if ( s . equals ( " TLE " ) ) { ++ c2 ; } else if ( s . equals ( " RE " ) ) { ++ c3 ; } } System . out . println ( " AC x " + c0 ) ; System . out . println ( " WA x " + c1 ) ; System . out . println ( " TLE x " + c2 ) ; System . out . println ( " RE x " + c3 ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . ArrayList ; import java . util . Arrays ; import java . util . HashMap ; import java . util . List ; import java . util . Map ; class Main { public static void main ( String [ ] args ) throws Exception { try { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; List < String > firstRow = Arrays . asList ( br . readLine ( ) . split ( " " ) ) ; List < String > secondRow = Arrays . asList ( br . readLine ( ) . split ( " " ) ) ; String thirdRow = br . readLine ( ) ; List < Integer > ballsCount = new ArrayList < > ( ) ; for ( String s : secondRow ) { ballsCount . add ( Integer . parseInt ( s ) ) ; } Map < String , Integer > ballsCountAndColor = new HashMap < > ( ) ; for ( int i = 0 ; i < firstRow . size ( ) ; i ++ ) { ballsCountAndColor . put ( firstRow . get ( i ) , ballsCount . get ( i ) ) ; } ballsCountAndColor . put ( thirdRow , ballsCountAndColor . get ( thirdRow ) . intValue ( ) - 1 ) ; System . out . print ( ballsCountAndColor . get ( firstRow . get ( 0 ) ) . intValue ( ) + " " + ballsCountAndColor . get ( firstRow . get ( 1 ) ) . intValue ( ) ) ; } catch ( IOException | NumberFormatException e ) { int i = 0 ; e . printStackTrace ( ) ; System . exit ( 0 ) ; } catch ( final Exception e ) { e . printStackTrace ( ) ; System . exit ( 0 ) ; } } } +import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int m = sc . nextInt ( ) ; boolean [ ] clash = new boolean [ n + 1 ] ; Arrays . fill ( clash , true ) ; for ( int i = 0 ; i < m ; i ++ ) clash [ sc . nextInt ( ) ] = false ; int [ ] dp = new int [ n + 1 ] ; dp [ 0 ] = 1 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i + 1 ; j <= Math . min ( i + 2 , n ) ; j ++ ) { if ( clash [ j ] ) { int j = i + 1 ; dp [ j ] += dp [ i ] ; dp [ j ] %= 1000000007 ; } } } System . out . println ( dp [ n ] ) ; sc . close ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; char [ ] chars = sc . next ( ) . toCharArray ( ) ; for ( char c : chars ) { if ( c == '1' ) { System . out . print ( 9 ) ; } else if ( c == '9' ) { char c ; System . out . print ( 1 ) ; } else { System . out . println ( c ) ; } } System . out . println ( ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws IOException { String [ ] su = br . readLine ( ) . split ( " " ) ; BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int n = Integer . parseInt ( br . readLine ( ) ) ; int i ; String [ ] su = br . readLine ( ) . split ( " " ) ; StringBuilder outArray = new StringBuilder ( ) ; for ( i = n - 1 ; i > 0 ; i -- ) { System . out . print ( su [ i ] + " " ) ; } System . out . print ( su [ i ] + " \n " ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int T = sc . nextInt ( ) ; int A = sc . nextInt ( ) ; double nearest = Double . MAX_VALUE ; int ans = 0 ; for ( int i = 1 ; i <= N ; i ++ ) { double avg = T - H * 0.006 ; int H = sc . nextInt ( ) ; double avg = T - H * 0.006 ; if ( nearest > Math . abs ( A - avg ) ) { nearest = Math . abs ( A - avg ) ; ans = i ; } } System . out . println ( ans ) ; } } +import java . util . * ; import java . util . stream . Collectors ; import java . util . stream . IntStream ; public class Main { public static void main ( String [ ] a ) { int j = 1 ; Scanner scan = new Scanner ( System . in ) ; int stuNum = scan . nextInt ( ) ; Map < Integer , Integer > numMap = new HashMap < > ( ) ; for ( int i = 1 ; i < stuNum + 1 ; i ++ ) { int s = scan . nextInt ( ) ; int dis = stuNum - s ; numMap . put ( stuNum - dis , i ) ; } for ( int j = 1 ; j < numMap . size ( ) + 1 ; j ++ ) { System . out . printf ( " %d " , numMap . get ( j ) ) ; } } } +import java . util . Scanner ; 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 ( ) ; } printArray ( a ) ; for ( int i = 1 ; i < n ; i ++ ) { int i = 0 ; int key = a [ i ] ; int j = i - 1 ; while ( j >= 0 && a [ j ] > key ) { a [ j + 1 ] = a [ j ] ; j -- ; } a [ j + 1 ] = key ; printArray ( a ) ; } } public static void printArray ( int [ ] a ) { for ( int i = 0 ; i < a . length - 1 ; i ++ ) { System . out . print ( a [ i ] + " " ) ; } System . out . println ( a [ a . length - 1 ] ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { double kingaku = 100 ; Scanner sc = new Scanner ( System . in ) ; long x = sc . nextLong ( ) ; long year = 0 ; double kingaku = 100 ; do { kingaku = kingaku * 1.01 ; kingaku = Math . floor ( kingaku ) ; year ++ ; } while ( kingaku < x ) ; System . out . println ( year ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; int [ ] x = new int [ 5 ] ; int ans = 0 ; for ( int i = 0 ; i < 5 ; i ++ ) { x [ i ] = sc . nextInt ( ) ; if ( x [ i ] != i + 1 ) ans = i + 1 ; } System . out . println ( ans ) ; } } +import java . lang . reflect . Array ; import java . util . ArrayList ; import java . util . List ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int n = scan . nextInt ( ) ; int a = scan . nextInt ( ) ; int b = scan . nextInt ( ) ; List < Integer > totalList = new ArrayList < Integer > ( ) ; for ( int i = 0 ; i <= n ; i ++ ) { int sum = 0 ; int sum = gettotal ( i ) ; if ( a <= sum && b >= sum ) { totalList . add ( i ) ; } } int res = 0 ; for ( int i = 0 ; i < totalList . size ( ) ; i ++ ) { res = res + totalList . get ( i ) ; } System . out . print ( res ) ; } private static int gettotal ( int i ) { int sum = 0 ; while ( i != 0 ) { sum += i % 10 ; i /= 10 ; } return sum ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int k = sc . nextInt ( ) ; int x = sc . nextInt ( ) ; int min = x - k + 1 ; int max = x + k - 1 ; for ( int i = min ; i <= max ; i ++ ) { int i = min ; System . out . print ( i + ( i == max ? " " : " " ) ) ; } System . out . println ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int ans = 0 ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int m = sc . nextInt ( ) ; int ans = 0 ; for ( int i = 0 ; true ; i ++ ) { n -= m ; ans ++ ; if ( n <= 0 ) { break ; } } System . out . println ( ans ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; String result = " " ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { int i = 0 ; switch ( s . charAt ( i ) ) { case '0' : result += 0 ; break ; case '1' : result += 1 ; break ; case 'B' : if ( ! result . isEmpty ( ) ) { result = result . substring ( 0 , result . length ( ) - 1 ) ; } break ; } } System . out . println ( result ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int t = sc . nextInt ( ) ; int a = sc . nextInt ( ) ; double [ ] h = new double [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { int b = sc . nextInt ( ) ; h [ i ] = t - b * 0.006 ; } double min = 1000000000 ; int ans = - 1 ; for ( int i = 0 ; i < n ; i ++ ) { double x ; if ( h [ i ] >= a ) { double x ; x = h [ i ] - a ; } else { x = a - h [ i ] ; } if ( x <= min ) { ans = i ; min = x ; } } System . out . println ( ans + 1 ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int tmp ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; Map < String , Integer > s = new HashMap < String , Integer > ( ) ; char [ ] c ; String ds ; long ans = 0 ; int tmp ; for ( int i = 0 ; i < n ; i ++ ) { c = sc . next ( ) . toCharArray ( ) ; Arrays . sort ( c ) ; ds = String . valueOf ( c ) ; tmp = s . getOrDefault ( ds , 0 ) ; ans += tmp ; s . put ( ds , tmp + 1 ) ; } sc . close ( ) ; System . out . println ( ans ) ; } } +import java . util . Scanner ; import java . util . Collections ; import java . util . List ; import java . util . ArrayList ; public class Main { public static void main ( String ... args ) { int num ; Scanner scan = new Scanner ( System . in ) ; int count = scan . nextInt ( ) ; List < Integer > list = new ArrayList < > ( ) ; while ( scan . hasNextInt ( ) ) { list . add ( scan . nextInt ( ) ) ; } Collections . sort ( list ) ; double x = 0 ; for ( int num : list ) { x = x == 0 ? num : ( num + x ) / 2 ; } System . out . println ( x ) ; } } +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 ( ) ; sc . close ( ) ; int count = 0 ; String str ; for ( int i = A ; i <= B ; i ++ ) { str = " " + A ; if ( str . charAt ( 0 ) == str . charAt ( 4 ) && str . charAt ( 1 ) == str . charAt ( 3 ) ) { String str ; count ++ ; } A ++ ; } System . out . println ( count ) ; } } +import java . io . * ; class Main { public static void main ( String [ ] args ) { try { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int n = Integer . parseInt ( br . readLine ( ) ) ; int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { long x = Long . parseLong ( br . readLine ( ) ) ; if ( isprime ( x ) ) count ++ ; } System . out . println ( count ) ; } catch ( Exception e ) { int i = 3 ; System . out . println ( e ) ; } } public static boolean isprime ( long x ) { if ( x == 2 ) return true ; if ( x < 2 || x % 2 == 0 ) return false ; int i = 3 ; while ( i <= Math . sqrt ( x ) ) { if ( x % i == 0 ) return false ; i = i + 2 ; } return true ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String F = sc . nextLine ( ) ; String C = sc . nextLine ( ) ; int count = 0 ; for ( int i = 0 ; i < F . length ( ) ; i ++ ) { int i = 0 ; Character c1 = F . charAt ( i ) ; Character c2 = C . charAt ( i ) ; if ( c1 == c2 ) count ++ ; } System . out . println ( count ) ; } } +import java . util . ArrayDeque ; import java . util . Deque ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { try ( Scanner scan = new Scanner ( System . in ) ) { String S = scan . next ( ) ; char [ ] s = new char [ S . length ( ) ] ; s = S . toCharArray ( ) ; Deque < Character > que = new ArrayDeque < Character > ( ) ; for ( int i = 0 ; i < s . length ; i ++ ) que . addLast ( s [ i ] ) ; while ( true ) { StringBuilder sb = new StringBuilder ( ) ; for ( int i = 0 ; i < 5 ; i ++ ) sb . append ( que . removeLast ( ) ) ; if ( sb . toString ( ) . equals ( " maerd " ) || sb . toString ( ) . equals ( " esare " ) ) { } else { sb . append ( que . removeLast ( ) ) ; if ( sb . toString ( ) . equals ( " resare " ) ) { } else { sb . append ( que . removeLast ( ) ) ; if ( sb . toString ( ) . equals ( " remaerd " ) ) { } else { int i = 0 ; System . out . println ( " NO " ) ; System . exit ( 0 ) ; } } } if ( que . isEmpty ( ) ) break ; } System . out . println ( " YES " ) ; } } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String [ ] strArray = br . readLine ( ) . split ( " " ) ; int a = Integer . parseInt ( strArray [ 0 ] ) ; int b = Integer . parseInt ( strArray [ 1 ] ) ; System . out . println ( getGCD ( a , b ) ) ; } public static int getGCD ( int a , int b ) { if ( a == b ) return a ; else if ( a < b ) { int b = Integer . parseInt ( strArray [ 1 ] ) ; return getGCD ( a , b - a ) ; } else return getGCD ( a - b , a ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader input = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String [ ] Aandb = ( input . readLine ( ) ) . split ( " \\ s " ) ; int n = Integer . parseInt ( Aandb [ 0 ] ) ; int m = Integer . parseInt ( Aandb [ 1 ] ) ; int [ ] [ ] A = new int [ n ] [ m ] ; String [ ] z = null ; for ( int i = 0 ; i < n ; i ++ ) { z = ( input . readLine ( ) ) . split ( " \\ s " ) ; for ( int j = 0 ; j < m ; j ++ ) { A [ i ] [ j ] = Integer . parseInt ( z [ j ] ) ; } } int [ ] b = new int [ m ] ; for ( int k = 0 ; k < m ; k ++ ) { b [ k ] = Integer . parseInt ( input . readLine ( ) ) ; } for ( int l = 0 ; l < n ; l ++ ) { int s = 0 ; int C = 0 ; for ( int s = 0 ; s < m ; s ++ ) { C += ( A [ l ] [ s ] * b [ s ] ) ; } System . out . println ( C ) ; } } } +import java . io . IOException ; import java . util . Scanner ; public class Main { static class Solution { public void find ( int perimeter , int [ ] arr ) { arr [ arr . length - 1 ] = perimeter ; int res = Integer . MAX_VALUE ; int antiClock = ( arr [ 0 ] + perimeter ) % perimeter ; res = Math . min ( res , perimeter - ( perimeter - arr [ arr . length - 2 ] ) - antiClock ) ; res = Math . min ( res , perimeter - ( arr [ 1 ] - arr [ 0 ] ) ) ; for ( int i = 1 ; i < arr . length - 1 ; i ++ ) { res = Math . min ( res , perimeter - ( arr [ i + 1 ] - arr [ i ] ) ) ; res = Math . min ( res , perimeter - ( arr [ i ] - arr [ i - 1 ] ) ) ; } System . out . println ( res ) ; } } public static void main ( String [ ] args ) throws IOException { int i = 0 ; Solution sol = new Solution ( ) ; Scanner sc = new Scanner ( System . in ) ; int perimeter = sc . nextInt ( ) ; int n = sc . nextInt ( ) ; int [ ] arr = new int [ n + 1 ] ; for ( int i = 0 ; i < n ; i ++ ) { arr [ i ] = sc . nextInt ( ) ; } sol . find ( perimeter , arr ) ; } } +import java . util . * ; class Main { Scanner sc ; int L ; private void calc ( ) { sc = new Scanner ( System . in ) ; L = sc . nextInt ( ) ; double l = L / 3d ; System . out . println ( l * l * l ) ; } public static void main ( String [ ] args ) { new Main ( ) . calc ( ) ; } } +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 ) ; abc139_a solver = new abc139_a ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class abc139_a { public void solve ( int testNumber , Scanner in , PrintWriter out ) { String [ ] S = in . next ( ) . split ( " " ) ; String [ ] T = in . next ( ) . split ( " " ) ; int hit = 0 ; for ( int i = 0 ; i < S . length ; i ++ ) { if ( S [ i ] . compareTo ( T [ i ] ) == 0 ) { int i = 0 ; hit ++ ; } } out . println ( hit ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int x = sc . nextInt ( ) ; int y = sc . nextInt ( ) ; int a , b , c ; a = x + y ; b = x - y ; c = x * y ; if ( a >= b && a >= c ) { System . out . print ( a ) ; } else if ( b >= a && b >= c ) { System . out . print ( b ) ; } else if ( c >= a && c >= b ) { int a , b , c ; System . out . print ( c ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int c = 0 ; while ( N > c ) { int c = 0 ; c = c + 1000 ; } c = c - N ; System . out . println ( c ) ; } } +import java . util . * ; import java . io . * ; public class Main { void solve ( InputReader in , PrintWriter out ) { out . println ( ( 1 + in . nextInt ( ) ) / 2 ) ; } public static void main ( String [ ] args ) throws Exception { InputReader in = new InputReader ( System . in ) ; PrintWriter out = new PrintWriter ( System . out ) ; Main solver = new Main ( ) ; solver . solve ( in , out ) ; out . close ( ) ; } static class InputReader { BufferedReader in ; StringTokenizer st ; public InputReader ( InputStream is ) { in = new BufferedReader ( new InputStreamReader ( is ) ) ; } public String next ( ) { try { while ( st == null || ! st . hasMoreTokens ( ) ) { st = new StringTokenizer ( in . readLine ( ) ) ; } return st . nextToken ( ) ; } catch ( Exception e ) { throw new RuntimeException ( e ) ; } } public int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } public long nextLong ( ) { return Long . parseLong ( next ( ) ) ; } } } +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 c = sc . nextInt ( ) ; int d = sc . nextInt ( ) ; while ( a > 0 || c > 0 ) { int d = sc . nextInt ( ) ; c -= b ; if ( c <= 0 ) break ; a -= d ; } if ( a > 0 ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int t = sc . nextInt ( ) ; double a = sc . nextInt ( ) ; double min = 1000000 ; int ans = 0 ; int [ ] h = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { h [ i ] = sc . nextInt ( ) ; } for ( int i = 0 ; i < n ; i ++ ) { int i = 0 ; double data = t - h [ i ] * 0.006 ; min = Math . min ( min , Math . abs ( a - data ) ) ; if ( min == Math . abs ( a - data ) ) { ans = i + 1 ; } } System . out . println ( ans ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int number_n , i , j , count = 0 ; number_n = Integer . parseInt ( sc . next ( ) ) ; int [ ] height = new int [ number_n ] ; for ( i = 0 ; i < number_n ; i ++ ) { int [ ] height = new int [ number_n ] ; height [ i ] = Integer . parseInt ( sc . next ( ) ) ; for ( j = 0 ; j < i ; j ++ ) { if ( height [ j ] > height [ i ] ) { break ; } } if ( j == i ) count ++ ; } System . out . println ( count ) ; } } +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 ) { int i = 0 ; InputStream inputStream = System . in ; OutputStream outputStream = System . out ; Scanner in = new Scanner ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; TaskBB solver = new TaskBB ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class TaskBB { public void solve ( int testNumber , Scanner in , PrintWriter out ) { int n = in . nextInt ( ) ; String a = in . next ( ) ; String b = in . next ( ) ; StringBuffer sb = new StringBuffer ( ) ; for ( int i = 0 ; i < n ; i ++ ) { sb . append ( a . charAt ( i ) ) ; sb . append ( b . charAt ( i ) ) ; } out . println ( sb . toString ( ) ) ; } } } +import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int n = scan . nextInt ( ) ; int [ ] ar = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { ar [ i ] = scan . nextInt ( ) ; } Arrays . parallelSort ( ar ) ; float ans = 0 ; float [ ] lol = new float [ n ] ; lol [ 0 ] = ar [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { int i = 1 ; lol [ i ] = ( float ) ( ( ar [ i ] + lol [ i - 1 ] ) / 2 ) ; } System . out . printf ( " %.04f " , lol [ n - 1 ] ) ; } } +import java . util . ArrayList ; import java . util . List ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int c = sc . nextInt ( ) ; int d = sc . nextInt ( ) ; int count = 0 ; for ( int i = a ; i <= b ; i ++ ) { for ( int j = c ; j <= d ; j ++ ) { if ( i == j ) { count ++ ; break ; } } } if ( count > 0 ) { int j = c ; count -- ; } System . out . println ( count ) ; } } +import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . util . ArrayList ; public class Main { public static void main ( String [ ] args ) throws java . lang . Exception { int i = 0 ; ArrayList < Integer > array = new ArrayList < Integer > ( ) ; ArrayList < Integer > array2 = new ArrayList < Integer > ( ) ; BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String data = " " ; br . readLine ( ) ; data = br . readLine ( ) ; String [ ] hairetsu = data . split ( " " , 0 ) ; for ( int i = 0 ; i < hairetsu . length ; i ++ ) { array . add ( Integer . parseInt ( hairetsu [ i ] ) ) ; } for ( int i = 0 ; i < array . size ( ) ; i ++ ) { array2 . add ( array . get ( array . size ( ) - 1 - i ) ) ; } for ( int i = 0 ; i < array2 . size ( ) ; i ++ ) { System . out . print ( array2 . get ( i ) ) ; if ( i < array2 . size ( ) - 1 ) { System . out . print ( " " ) ; } } System . out . println ( ) ; } } +import java . util . Scanner ; import java . lang . Math ; public class Main { public void run ( ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] [ ] grid = new int [ 2 ] [ n ] ; for ( int i = 0 ; i < 2 ; i ++ ) { int j = 1 ; for ( int j = 0 ; j < n ; j ++ ) { grid [ i ] [ j ] = sc . nextInt ( ) ; } } int [ ] [ ] ans = new int [ 2 ] [ n ] ; ans [ 0 ] [ 0 ] = grid [ 0 ] [ 0 ] ; ans [ 1 ] [ 0 ] = grid [ 1 ] [ 0 ] + ans [ 0 ] [ 0 ] ; for ( int j = 1 ; j < n ; j ++ ) { ans [ 0 ] [ j ] = grid [ 0 ] [ j ] + ans [ 0 ] [ j - 1 ] ; } for ( int j = 1 ; j < n ; j ++ ) { ans [ 1 ] [ j ] = grid [ 1 ] [ j ] + Math . max ( ans [ 1 ] [ j - 1 ] , ans [ 0 ] [ j ] ) ; } System . out . println ( ans [ 1 ] [ n - 1 ] ) ; } public static void main ( String [ ] args ) { new Main ( ) . run ( ) ; } } +import java . util . * ; import java . io . * ; public class Main { public static void main ( String ... args ) { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String password = null ; try { password = br . readLine ( ) ; br . close ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } System . out . println ( isDifficultToInput ( password ) ? " Bad " : " Good " ) ; } private static boolean isDifficultToInput ( String word ) { String [ ] splitWord = word . split ( " " ) ; for ( int i = 0 ; i < splitWord . length - 1 ; i ++ ) { String rear = splitWord [ i ] ; String front = splitWord [ i + 1 ] ; if ( front . equals ( rear ) ) { int i = 0 ; return true ; } } return false ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int [ ] h = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { h [ i ] = sc . nextInt ( ) ; } int tmp = 0 ; int count = 0 ; do { tmp = count ; int min = 100 ; int index = 0 ; int lastValue = 0 ; for ( int i = 0 ; i < N ; i ++ ) { int j = index ; if ( h [ i ] == 0 ) { if ( lastValue == 0 ) { index = i + 1 ; continue ; } for ( int j = index ; j < i ; j ++ ) { h [ j ] -= min ; } count += min ; min = 100 ; index = i + 1 ; lastValue = 0 ; } else if ( i == N - 1 ) { min = ( min < h [ i ] ) ? min : h [ i ] ; for ( int j = index ; j <= i ; j ++ ) { h [ j ] -= min ; } count += min ; min = 100 ; index = i + 1 ; } min = ( min < h [ i ] ) ? min : h [ i ] ; lastValue = h [ i ] ; } } while ( tmp != count ) ; System . out . println ( count ) ; } } +import java . util . Scanner ; public class Main { private static long WARU = 1000000007 ; public static void main ( final String [ ] args ) { final Scanner scanner = new Scanner ( System . in ) ; final int count = scanner . nextInt ( ) ; final int fallCount = scanner . nextInt ( ) ; final long [ ] steps = new long [ count + 1 ] ; for ( int i = 1 ; i < steps . length ; i ++ ) { int i = 0 ; steps [ i ] = 0 ; } steps [ 0 ] = 1 ; for ( int i = 0 ; i < fallCount ; i ++ ) { steps [ scanner . nextInt ( ) ] = - 1 ; } for ( int i = 0 ; i < count ; i ++ ) { if ( steps [ i ] == - 1 ) { continue ; } if ( i == count - 1 ) { steps [ i + 1 ] += steps [ i ] ; break ; } if ( steps [ i + 1 ] == - 1 && steps [ i + 2 ] == - 1 ) { System . out . println ( 0 ) ; return ; } if ( steps [ i + 2 ] != - 1 ) { steps [ i + 2 ] += steps [ i ] % WARU ; } if ( steps [ i + 1 ] != - 1 ) { steps [ i + 1 ] += steps [ i ] % WARU ; } } System . out . println ( steps [ count ] % WARU ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) , b = sc . nextInt ( ) , c = sc . nextInt ( ) , x = sc . nextInt ( ) , y = sc . nextInt ( ) ; long min = Long . MAX_VALUE ; for ( int i = 0 ; i <= Math . max ( x , y ) ; i ++ ) { min = Math . min ( min , 2 * c * i + Math . max ( 0 , x - i ) * a + Math . max ( 0 , y - i ) * b ) ; } System . out . println ( min ) ; } } +import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int n = scan . nextInt ( ) ; int [ ] length = new int [ n ] ; for ( int i = 0 ; i < length . length ; i ++ ) { length [ i ] = scan . nextInt ( ) ; } Arrays . sort ( length ) ; int sum = 0 ; for ( int i = 0 ; i < length . length - 1 ; i ++ ) { sum += length [ i ] ; } if ( sum > length [ length . length - 1 ] ) { int i = 0 ; System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } scan . close ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner s = new Scanner ( System . in ) ; String ns = s . nextLine ( ) ; String str = s . nextLine ( ) ; int n = Integer . parseInt ( ns ) ; int [ ] arr = new int [ n + 1 ] ; arr [ 0 ] = 0 ; String [ ] sss = str . split ( " \\ s " ) ; for ( int i = 1 ; i <= n ; i ++ ) { arr [ i ] = Integer . parseInt ( sss [ i - 1 ] ) ; } int [ ] a = new int [ n + 1 ] ; a [ 0 ] = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { a [ ( arr [ i ] ) ] = i ; } for ( int i = 1 ; i <= n ; i ++ ) { int i = 1 ; System . out . print ( a [ i ] + " " ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner yomi = new Scanner ( System . in ) ; int a = yomi . nextInt ( ) ; boolean tf = true ; int [ ] n = new int [ a ] ; for ( int i = 0 ; i < a ; i ++ ) { int i = 0 ; n [ i ] = yomi . nextInt ( ) ; } for ( int i = 0 ; i < a ; i ++ ) { if ( n [ i ] % 2 == 0 ) { if ( n [ i ] % 3 == 0 || n [ i ] % 5 == 0 ) { } else tf = false ; } } if ( tf ) { System . out . println ( " APPROVED " ) ; } else System . out . println ( " DENIED " ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int M = sc . nextInt ( ) ; int C = sc . nextInt ( ) ; int [ ] B = new int [ M ] ; for ( int i = 0 ; i < M ; i ++ ) { B [ i ] = sc . nextInt ( ) ; } List < int [ ] > Ai = new ArrayList < > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { int [ ] A = new int [ M ] ; for ( int j = 0 ; j < M ; j ++ ) { A [ j ] = sc . nextInt ( ) ; } Ai . add ( A ) ; } int count = 0 ; for ( int i = 0 ; i < Ai . size ( ) ; i ++ ) { int j = 0 ; int [ ] A = Ai . get ( i ) ; int clear = C ; for ( int j = 0 ; j < M ; j ++ ) { clear += A [ j ] * B [ j ] ; } if ( 0 < clear ) { count ++ ; } } System . out . println ( count ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int [ ] ary = new int [ n ] ; Scanner s = new Scanner ( System . in ) ; int n = s . nextInt ( ) ; int m = s . nextInt ( ) ; int i = 0 ; int j = 0 ; int count = 0 ; int [ ] ary1 = new int [ 2 * m ] ; for ( i = 0 ; i < 2 * m ; i ++ ) { ary1 [ i ] = s . nextInt ( ) ; } int [ ] ary = new int [ n ] ; for ( i = 0 ; i < n ; i ++ ) { count = 0 ; for ( j = 0 ; j < 2 * m ; j ++ ) { if ( ary1 [ j ] == i + 1 ) { count ++ ; } } ary [ i ] = count ; System . out . println ( ary [ i ] ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int n = scan . nextInt ( ) ; int n1 = n + 1 ; long [ ] m = new long [ n1 ] ; long [ ] h = new long [ n ] ; for ( int i = 0 ; i < n1 ; i ++ ) { m [ i ] = scan . nextInt ( ) ; } for ( int i = 0 ; i < n ; i ++ ) { h [ i ] = scan . nextInt ( ) ; } long result = 0 ; for ( int i = 0 ; i < n ; i ++ ) { long xh = h [ i ] ; if ( xh >= m [ i ] ) { long xh = h [ i ] ; result += m [ i ] ; xh -= m [ i ] ; if ( xh >= m [ i + 1 ] ) { result += m [ i + 1 ] ; m [ i + 1 ] = 0 ; } else { result += xh ; m [ i + 1 ] -= xh ; } } else { m [ i ] -= xh ; result += xh ; } } System . out . println ( result ) ; } } +import java . util . Scanner ; import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; String h = scan . nextLine ( ) ; String weather = " Sunny " ; if ( " Sunny " . equals ( h ) ) { weather = " Cloudy " ; } else if ( " Cloudy " . equals ( h ) ) { String weather = " Sunny " ; weather = " Rainy " ; } System . out . println ( weather ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { try ( Scanner sc = new Scanner ( System . in ) ) { int N = sc . nextInt ( ) ; String S = sc . next ( ) ; char [ ] cs = S . toCharArray ( ) ; int count = 0 ; for ( int i = 0 ; i < N - 2 ; i ++ ) { int i = 0 ; if ( cs [ i ] == 'A' && cs [ i + 1 ] == 'B' && cs [ i + 2 ] == 'C' ) { count ++ ; } } System . out . println ( count ) ; } } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; class Main { public static void main ( String [ ] args ) { InputStreamReader isr = new InputStreamReader ( System . in ) ; BufferedReader br = new BufferedReader ( isr ) ; try { String [ ] list = br . readLine ( ) . split ( " " ) ; int a = Integer . parseInt ( list [ 0 ] ) ; int b = Integer . parseInt ( list [ 1 ] ) ; int d = a / b ; int r = a % b ; double f = ( double ) a / b ; System . out . println ( d + " " + r + " " + String . format ( " %.5f " , f ) ) ; } catch ( IOException e ) { BufferedReader br = new BufferedReader ( isr ) ; e . printStackTrace ( ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Main main = new Main ( ) ; main . run ( ) ; } public void run ( ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int m = sc . nextInt ( ) ; boolean [ ] ac = new boolean [ n + 1 ] ; long [ ] wa = new long [ n + 1 ] ; for ( int i = 0 ; i < m ; i ++ ) { int p = sc . nextInt ( ) ; String s = sc . next ( ) ; if ( ac [ p ] ) continue ; if ( s . equals ( " AC " ) ) { int i = 1 ; ac [ p ] = true ; } else { wa [ p ] ++ ; } } long sum1 = 0 ; long sum2 = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { if ( ac [ i ] ) { sum1 ++ ; sum2 += wa [ i ] ; } } System . out . println ( sum1 + " " + sum2 ) ; sc . close ( ) ; } } +public class Main { public void run ( java . io . InputStream in , java . io . PrintStream out ) { java . util . Scanner sc = new java . util . Scanner ( in ) ; int n , x ; int i , j , k , count ; for ( ; ; ) { int i , j , k , count ; n = sc . nextInt ( ) ; x = sc . nextInt ( ) ; if ( n == 0 && x == 0 ) break ; count = 0 ; for ( i = 1 ; i <= n ; i ++ ) { for ( j = i + 1 ; j <= n ; j ++ ) { if ( x - i - j > j && x - i - j <= n ) count ++ ; } } System . out . println ( count ) ; } sc . close ( ) ; } public static void main ( String [ ] args ) { ( new Main ( ) ) . run ( System . in , System . out ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] p = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { p [ i ] = sc . nextInt ( ) ; } int c = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int i = 0 ; if ( p [ i ] != i + 1 ) c ++ ; } if ( c > 2 ) { System . out . println ( " NO " ) ; } else { System . out . println ( " YES " ) ; } } } +import java . util . ArrayList ; import java . util . Collections ; import java . util . Scanner ; public class Main { static int n = 0 ; public static void main ( String [ ] args ) { int anser = 100000000 ; Scanner scan = new Scanner ( System . in ) ; n = scan . nextInt ( ) ; ArrayList < Integer > address = new ArrayList < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { address . add ( scan . nextInt ( ) ) ; } Collections . sort ( address ) ; for ( int i = address . get ( 0 ) ; i <= address . get ( n - 1 ) ; i ++ ) { int sum = sumList ( address , i ) ; if ( anser > sum ) { anser = sum ; } } System . out . println ( anser ) ; } private static int sumList ( ArrayList < Integer > array , int j ) { int i = 0 ; int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { sum = sum + ( j - array . get ( i ) ) * ( j - array . get ( i ) ) ; } return sum ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int D = Integer . parseInt ( sc . next ( ) ) ; int N = Integer . parseInt ( sc . next ( ) ) ; sc . close ( ) ; if ( N != 100 ) { int answer = ( int ) ( 101 * Math . pow ( 100 , D ) ) ; int answer = ( int ) ( N * Math . pow ( 100 , D ) ) ; System . out . println ( answer ) ; return ; } else { int answer = ( int ) ( 101 * Math . pow ( 100 , D ) ) ; System . out . println ( answer ) ; return ; } } } +import java . util . * ; class Main { static Scanner sc = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { int t = 1 ; int n = sc . nextInt ( ) ; int [ ] a = new int [ n + 1 ] ; a [ 0 ] = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { a [ i ] = a [ i - 1 ] + sc . nextInt ( ) ; } int min = 10000000 ; for ( int t = 1 ; t < n ; t ++ ) { min = Math . min ( Math . abs ( ( a [ t ] - a [ 0 ] ) - ( a [ n ] - a [ t ] ) ) , min ) ; } System . out . println ( min ) ; } } +import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { final StringBuilder sb = new StringBuilder ( ) ; final Scanner in = new Scanner ( new BufferedReader ( new InputStreamReader ( System . in ) ) ) ; final int count = in . next ( ) . trim ( ) . length ( ) ; final StringBuilder sb = new StringBuilder ( ) ; for ( int i = 0 ; i < count ; i ++ ) { sb . append ( " x " ) ; } System . out . println ( sb ) ; } } +import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int N = Integer . parseInt ( scanner . next ( ) ) ; double [ ] S = new double [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { int i = 2 ; S [ i ] = Double . parseDouble ( scanner . next ( ) ) ; } Arrays . parallelSort ( S ) ; double m = ( S [ 0 ] + S [ 1 ] ) / 2 ; for ( int i = 2 ; i < N ; i ++ ) { m = ( m + S [ i ] ) / 2 ; } System . out . print ( m ) ; } } +import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . io . IOException ; public class Main { public static void main ( String [ ] args ) { try { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String str ; while ( ! ( ( str = br . readLine ( ) ) . equals ( " - " ) ) ) { int i = 0 ; int M = Integer . parseInt ( br . readLine ( ) ) ; int [ ] arrH = new int [ M ] ; for ( int i = 0 ; i < M ; i ++ ) { arrH [ i ] = Integer . parseInt ( br . readLine ( ) ) ; } shuff ( str , arrH , M ) ; } } catch ( IOException e ) { e . printStackTrace ( ) ; } } public static void shuff ( String s , int [ ] h , int l ) { StringBuilder sb = new StringBuilder ( ) ; sb . append ( s ) ; for ( int i = 0 ; i < l ; i ++ ) { sb . append ( sb . substring ( 0 , h [ i ] ) ) ; sb . delete ( 0 , h [ i ] ) ; } System . out . println ( sb . toString ( ) ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int count = 0 ; Scanner sc = new Scanner ( System . in ) ; String W = sc . next ( ) . toLowerCase ( ) ; String T ; int count = 0 ; while ( ! ( T = sc . next ( ) ) . equals ( " END_OF_TEXT " ) ) { if ( T . toLowerCase ( ) . equals ( W ) ) { count ++ ; } } sc . close ( ) ; System . out . println ( count ) ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner scn = new Scanner ( System . in ) ; int cnt = scn . nextInt ( ) ; String a = scn . next ( ) ; String b = scn . next ( ) ; String result = " " ; String [ ] c = new String [ cnt ] ; String [ ] d = new String [ cnt ] ; for ( int i = 0 ; i < cnt ; i ++ ) { int i = 0 ; c [ i ] = a . charAt ( i ) + " " ; d [ i ] = b . charAt ( i ) + " " ; result += c [ i ] + d [ i ] ; } System . out . println ( result ) ; } } +import java . io . * ; import java . util . * ; public class Main { private void solve ( ) { int K = sc . nextInt ( ) ; int A = sc . nextInt ( ) ; int B = sc . nextInt ( ) ; for ( int i = A ; i <= B ; ++ i ) { if ( i % K == 0 ) { out . println ( " OK " ) ; return ; } } out . println ( " NG " ) ; } private static PrintWriter out ; private static MyScanner sc ; private static class MyScanner { BufferedReader br ; StringTokenizer st ; private 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 ( ) ) ; } } public static void main ( String [ ] args ) { out = new PrintWriter ( new BufferedOutputStream ( System . out ) ) ; sc = new MyScanner ( ) ; new Main ( ) . solve ( ) ; out . close ( ) ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; Map < String , Integer > map = new HashMap < String , Integer > ( ) ; String tmp = sc . nextLine ( ) ; for ( int i = 0 ; i < n ; ++ i ) { String s = sc . nextLine ( ) ; map . putIfAbsent ( s , 0 ) ; map . put ( s , map . get ( s ) + 1 ) ; } SortedSet < String > st = new TreeSet < > ( ) ; int maxi = 0 ; for ( Map . Entry < String , Integer > entry : map . entrySet ( ) ) { maxi = Math . max ( maxi , entry . getValue ( ) ) ; } for ( Map . Entry < String , Integer > entry : map . entrySet ( ) ) { if ( entry . getValue ( ) == maxi ) { st . add ( entry . getKey ( ) ) ; } } for ( String ele : st ) { String ele ; System . out . println ( ele ) ; } } } +import java . util . * ; class Main { private static Scanner sc ; public static void main ( final String [ ] args ) { sc = new Scanner ( System . in ) ; String ans = sc . next ( ) ; if ( ans . equals ( " ABC " ) ) System . out . println ( " ARC " ) ; else { System . out . println ( " ABC " ) ; } } } +import java . util . Scanner ; import java . util . InputMismatchException ; class Main { public static void main ( String [ ] args ) { int x = 0 , y = 0 ; int [ ] [ ] z ; Scanner scanner = new Scanner ( System . in ) ; x = scanner . nextInt ( ) ; y = scanner . nextInt ( ) ; z = new int [ y ] [ 2 ] ; for ( int i = 0 ; i < y ; i ++ ) { int minz = 100001 ; for ( int j = 0 ; j < 2 ; j ++ ) { z [ i ] [ j ] = scanner . nextInt ( ) ; } } scanner . close ( ) ; int sum = 0 ; int i , j ; int maxz = 0 ; int minz = 100001 ; for ( j = 0 ; j < y ; j ++ ) { if ( maxz < z [ j ] [ 0 ] ) { maxz = z [ j ] [ 0 ] ; } if ( minz > z [ j ] [ 1 ] ) { minz = z [ j ] [ 1 ] ; } } if ( minz - maxz > - 1 ) { System . out . println ( minz - maxz + 1 ) ; } else { System . out . println ( 0 ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] a = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { int i = 0 ; a [ i ] = sc . nextInt ( ) ; } int count = 0 ; boolean flg = true ; while ( flg ) { for ( int i = 0 ; i < n ; i ++ ) { if ( a [ i ] % 2 == 0 ) { a [ i ] /= 2 ; if ( i == n - 1 ) count ++ ; } else { flg = false ; break ; } } } System . out . println ( count ) ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { printAns ( ) ; } static void isRightTriangle ( int a , int b , int c ) { if ( a * a + b * b == c * c ) System . out . println ( " YES " ) ; else System . out . println ( " NO " ) ; } static void printAns ( ) { Scanner sc = new Scanner ( System . in ) ; int set = sc . nextInt ( ) ; int [ ] triangle = new int [ 3 ] ; for ( int cnt = 0 ; cnt < set ; cnt ++ ) { for ( int i = 0 ; i < triangle . length ; i ++ ) { triangle [ i ] = sc . nextInt ( ) ; } sort ( triangle ) ; isRightTriangle ( triangle [ 0 ] , triangle [ 1 ] , triangle [ 2 ] ) ; } } static void sort ( int [ ] data ) { int min , tmp ; for ( int i = 0 ; i < data . length ; i ++ ) { int i = 0 ; min = i ; for ( int j = i + 1 ; j < data . length ; j ++ ) if ( data [ min ] > data [ j ] ) min = j ; tmp = data [ i ] ; data [ i ] = data [ min ] ; data [ min ] = tmp ; } } } +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 = new int [ a ] ; int sum = 0 ; int ans = 0 ; for ( int i = 0 ; i < b . length ; i ++ ) { int x = 0 ; b [ i ] = sc . nextInt ( ) ; sum += b [ i ] ; } for ( int j = 1 ; j < b . length ; j ++ ) { int half = 0 ; int tmp = 0 ; for ( int x = 0 ; x < j ; x ++ ) { half += b [ x ] ; tmp = sum - ( half * 2 ) ; tmp = Math . abs ( tmp ) ; if ( x == 0 || tmp < ans ) { ans = tmp ; } } } System . out . println ( ans ) ; } } +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 c = a * b ; int d = a + b ; int e = a - b ; if ( c >= d && c >= e ) { int e = a - b ; System . out . println ( c ) ; } else if ( d >= c && d >= e ) { System . out . println ( d ) ; } else { System . out . println ( e ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int X = sc . nextInt ( ) ; int [ ] variation = new int [ N ] ; int count = 0 ; int i , j , k = 0 ; int [ ] max = new int [ N ] ; for ( i = 0 ; i < N ; i ++ ) { variation [ i ] = sc . nextInt ( ) ; } for ( j = 0 ; j < N ; j ++ ) { int [ ] max = new int [ N ] ; X = X - variation [ j ] ; count ++ ; } for ( k = 0 ; k < N ; k ++ ) { max [ k ] = X / variation [ k ] ; } for ( j = 0 ; j < N ; j ++ ) { for ( k = j + 1 ; k < N ; k ++ ) { if ( max [ k ] > max [ j ] ) { int t = max [ k ] ; max [ k ] = max [ j ] ; max [ j ] = t ; } } } count = count + max [ 0 ] ; System . out . println ( count ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int m = sc . nextInt ( ) ; int min = sc . nextInt ( ) ; int max = sc . nextInt ( ) ; m -- ; while ( m -- > 0 ) { int max = sc . nextInt ( ) ; min = Math . max ( min , sc . nextInt ( ) ) ; max = Math . min ( max , sc . nextInt ( ) ) ; } if ( min > max ) { System . out . println ( 0 ) ; return ; } System . out . println ( max - min + 1 ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; while ( true ) { int j = i - 1 ; int counter = 0 ; int n = sc . nextInt ( ) ; int x = sc . nextInt ( ) ; if ( n == 0 && x == 0 ) { break ; } for ( int i = n ; i >= 3 ; i -- ) { for ( int j = i - 1 ; j >= 2 ; j -- ) { int remainder = x - i - j ; if ( remainder <= 0 ) { continue ; } else if ( remainder >= j ) { break ; } else { counter ++ ; } } } System . out . println ( counter ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int data ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int m = sc . nextInt ( ) ; int [ ] [ ] queue = new int [ n ] [ m ] ; int [ ] vector = new int [ m ] ; int [ ] vectorAns = new int [ n ] ; for ( int i = 0 ; i < queue . length ; i ++ ) { for ( int j = 0 ; j < queue [ i ] . length ; j ++ ) { queue [ i ] [ j ] = sc . nextInt ( ) ; } } for ( int i = 0 ; i < vector . length ; i ++ ) { vector [ i ] = sc . nextInt ( ) ; } for ( int i = 0 ; i < vectorAns . length ; i ++ ) { for ( int j = 0 ; j < queue [ i ] . length ; j ++ ) { vectorAns [ i ] += queue [ i ] [ j ] * vector [ j ] ; } } for ( int data : vectorAns ) { System . out . println ( data ) ; } } } +import java . util . * ; import java . io . * ; import java . lang . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; ArrayList < Integer > arr = new ArrayList < > ( ) ; int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int i = 1 ; int a = sc . nextInt ( ) ; arr . add ( a ) ; } for ( int i = 1 ; i < ( n - 1 ) ; i ++ ) { if ( arr . get ( i ) > arr . get ( i - 1 ) && ( arr . get ( i ) < arr . get ( i + 1 ) ) ) { ans ++ ; } else if ( arr . get ( i ) < arr . get ( i - 1 ) && ( arr . get ( i ) > arr . get ( i + 1 ) ) ) { ans ++ ; } } System . out . println ( ans ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long a = sc . nextLong ( ) ; long b = sc . nextLong ( ) ; long k = sc . nextLong ( ) ; if ( k == 0 ) { System . out . println ( a + " " + b ) ; return ; } if ( a >= k ) { long k = sc . nextLong ( ) ; System . out . println ( a - k + " " + b ) ; return ; } k -= a ; if ( b >= k ) { System . out . println ( " 0 " + ( b - k ) ) ; return ; } System . out . println ( " 0 0 " ) ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; String t = sc . next ( ) ; int sol = t . length ( ) ; for ( int i = 0 ; i <= s . length ( ) - t . length ( ) ; i ++ ) { int count = 0 ; int k = i ; for ( int j = 0 ; j < t . length ( ) ; j ++ ) { int j = 0 ; if ( s . charAt ( k ) != t . charAt ( j ) ) { count ++ ; } k ++ ; } sol = Math . min ( count , sol ) ; } System . out . println ( sol ) ; } } +import java . time . LocalDate ; import java . time . format . DateTimeFormatter ; import java . time . format . DateTimeParseException ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String sdate = sc . next ( ) ; try { DateTimeFormatter formatter = DateTimeFormatter . ofPattern ( " uuuu/MM/dd " ) ; LocalDate date = LocalDate . parse ( sdate , formatter ) ; LocalDate today = LocalDate . of ( 2019 , 4 , 30 ) ; int diff = date . compareTo ( today ) ; if ( diff <= 0 ) { String sdate = sc . next ( ) ; System . out . println ( " Heisei " ) ; } else { System . out . println ( " TBD " ) ; } } catch ( DateTimeParseException e ) { System . out . println ( " 入力値がyyyy/mm/dd形式ではありません"); } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { solve ( ) ; } private static void solve ( ) { Scanner sc = new Scanner ( System . in ) ; char [ ] sCode = sc . next ( ) . toCharArray ( ) ; boolean isExistSameCode = false ; for ( int i = 0 ; i < 3 ; i ++ ) { if ( sCode [ i ] == sCode [ i + 1 ] ) { int i = 0 ; isExistSameCode = true ; break ; } } if ( isExistSameCode ) { System . out . print ( " Bad " ) ; } else System . out . print ( " Good " ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { try ( Scanner sc = new Scanner ( System . in ) ) { int j = 0 ; int N = sc . nextInt ( ) ; int M = sc . nextInt ( ) ; int C = sc . nextInt ( ) ; sc . nextLine ( ) ; int [ ] BArray = new int [ M ] ; int answer = 0 ; for ( int i = 0 ; i < BArray . length ; i ++ ) { BArray [ i ] = sc . nextInt ( ) ; } sc . nextLine ( ) ; for ( int i = 0 ; i < N ; i ++ ) { int result = 0 ; for ( int j = 0 ; j < M ; j ++ ) { result += sc . nextInt ( ) * BArray [ j ] ; } if ( 0 < ( result + C ) ) { answer ++ ; } sc . nextLine ( ) ; } System . out . println ( answer ) ; } } } +import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; int output = 0 ; Scanner scanner = new Scanner ( System . in ) ; String s = scanner . nextLine ( ) ; scanner . close ( ) ; String [ ] str = s . split ( " " , 0 ) ; int [ ] input = new int [ str . length ] ; for ( int i = 0 ; i < str . length ; i ++ ) { input [ i ] = Integer . parseInt ( str [ i ] ) ; } Arrays . sort ( input ) ; for ( int i = 0 ; i < input . length - 1 ; i ++ ) { output += input [ i + 1 ] - input [ i ] ; } System . out . println ( output ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int result = 100000 ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int result = 100000 ; for ( int i = 0 ; i < n ; i ++ ) { result += result * 0.05 ; result = ( int ) Math . ceil ( ( double ) result / 1000 ) * 1000 ; } System . out . println ( result ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int num = scanner . nextInt ( ) ; int [ ] array = new int [ num ] ; for ( int i = 0 ; i < num ; i ++ ) { int cou = 0 ; array [ i ] = scanner . nextInt ( ) ; } insertionSort ( array , num ) ; scanner . close ( ) ; } public static int [ ] insertionSort ( int [ ] array , int num ) { int sub ; int comp = 0 ; int i ; for ( int cou = 0 ; cou < num ; cou ++ ) { System . out . print ( array [ cou ] ) ; if ( cou == num - 1 ) { System . out . print ( " \n " ) ; } else { System . out . print ( " " ) ; } } for ( i = 1 ; i <= num - 1 ; i ++ ) { sub = array [ i ] ; comp = i - 1 ; while ( comp >= 0 && array [ comp ] > sub ) { array [ comp + 1 ] = array [ comp ] ; comp -- ; } array [ comp + 1 ] = sub ; for ( int cou = 0 ; cou < num ; cou ++ ) { System . out . print ( array [ cou ] ) ; if ( cou == num - 1 ) { System . out . print ( " \n " ) ; } else { System . out . print ( " " ) ; } } } return array ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = Math . max ( a , b ) ; Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int k = sc . nextInt ( ) ; int count = 0 ; int n = 0 ; for ( int i = Math . max ( a , b ) ; i >= 1 ; i -- ) { if ( a % i == 0 && b % i == 0 ) { count ++ ; n = i ; if ( count >= k ) break ; } } System . out . println ( n ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int j = 0 ; Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; String t = sc . next ( ) ; int n = s . length ( ) ; int m = t . length ( ) ; int count = 0 ; int ans = Integer . MAX_VALUE ; for ( int i = 0 ; i < n - m + 1 ; i ++ ) { String ss = s . substring ( i , i + m ) ; for ( int j = 0 ; j < ss . length ( ) ; j ++ ) { if ( ss . charAt ( j ) != t . charAt ( j ) ) { count ++ ; } } ans = Math . min ( ans , count ) ; count = 0 ; } System . out . println ( ans ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int a = Integer . parseInt ( sc . next ( ) ) ; int b = Integer . parseInt ( sc . next ( ) ) ; int c = Integer . parseInt ( sc . next ( ) ) ; if ( c - ( a - b ) >= 0 ) { int c = Integer . parseInt ( sc . next ( ) ) ; System . out . println ( c - ( a - b ) ) ; } else { System . out . println ( 0 ) ; } } } +import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int [ ] arr = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { arr [ i ] = sc . nextInt ( ) ; } Arrays . sort ( arr ) ; boolean isDistinct = true ; for ( int i = 1 ; i < N ; i ++ ) { int i = 1 ; if ( arr [ i ] == arr [ i - 1 ] ) { isDistinct = false ; break ; } } if ( isDistinct ) System . out . println ( " YES " ) ; else System . out . println ( " NO " ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; String s = scanner . nextLine ( ) ; for ( int i = 0 ; i < s . length ( ) - 1 ; i ++ ) { if ( s . charAt ( i ) != s . charAt ( i + 1 ) ) { int i = 0 ; System . out . println ( " Yes " ) ; return ; } } System . out . println ( " No " ) ; } } +import java . io . * ; import java . util . * ; import java . lang . * ; public class Main { static class FastReader { BufferedReader br ; StringTokenizer st ; public FastReader ( ) { String str = " " ; 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 ; } } public static void main ( String [ ] args ) { FastReader ob = new FastReader ( ) ; int k = ob . nextInt ( ) , a = ob . nextInt ( ) , b = ob . nextInt ( ) ; int ans = ( a - ( a % k ) ) + k ; if ( ans >= a && ans <= b || a % k == 0 ) { System . out . println ( " OK " ) ; return ; } System . out . println ( " NG " ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int k = sc . nextInt ( ) ; ArrayList < Integer > divisor = new ArrayList < Integer > ( ) ; for ( int i = a ; i > 0 ; i -- ) { int i = a ; if ( a % i == 0 && b % i == 0 ) { divisor . add ( i ) ; } } System . out . println ( divisor . get ( k - 1 ) ) ; } } +import java . util . Scanner ; public class Main { static Scanner sc = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { int n = sc . nextInt ( ) ; int t , x , y , dis ; String ans = " Yes " ; for ( int i = 0 ; i < n ; i ++ ) { t = sc . nextInt ( ) ; x = sc . nextInt ( ) ; y = sc . nextInt ( ) ; dis = x + y ; if ( dis > t ) { String ans = " Yes " ; ans = " No " ; break ; } else { if ( ( t - dis ) % 2 == 1 ) { ans = " No " ; break ; } } } System . out . println ( ans ) ; } } +import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . util . ArrayList ; import java . util . Arrays ; import java . util . List ; public class Main { public static void main ( String [ ] args ) throws Exception { String strinput = reader . readLine ( ) ; InputStreamReader is = new InputStreamReader ( System . in ) ; BufferedReader reader = new BufferedReader ( is ) ; List < String > mylist = new ArrayList < > ( ) ; String strinput = reader . readLine ( ) ; while ( strinput != null ) { mylist . add ( strinput ) ; strinput = reader . readLine ( ) ; } List < String > list01 = new ArrayList < String > ( Arrays . asList ( " SUN " , " MON " , " TUE " , " WED " , " THU " , " FRI " , " SAT " ) ) ; String [ ] arr01 = mylist . get ( 0 ) . split ( " " ) ; String s = arr01 [ 0 ] ; System . out . println ( list01 . indexOf ( s ) == 0 ? 7 : 7 - list01 . indexOf ( s ) ) ; } } +import java . util . ArrayList ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; ArrayList < Integer > a = new ArrayList < > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { a . add ( sc . nextInt ( ) ) ; } sc . close ( ) ; long cnt = 0 ; int flg = 1 ; if ( a . indexOf ( 1 ) == - 1 ) { int i = a . indexOf ( 1 ) ; System . out . println ( - 1 ) ; return ; } else { cnt += a . indexOf ( 1 ) ; for ( int i = a . indexOf ( 1 ) ; i < N - 1 ; i ++ ) { if ( a . get ( i + 1 ) == flg + 1 ) { flg ++ ; } else { cnt ++ ; } } } System . out . println ( cnt ) ; } } +import java . io . FileNotFoundException ; import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws FileNotFoundException { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int [ ] A = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { int i = 0 ; A [ i ] = Integer . parseInt ( sc . next ( ) ) ; } sc . close ( ) ; int [ ] B = A . clone ( ) ; Arrays . sort ( B ) ; int max = B [ N - 1 ] ; int nextmax = B [ N - 2 ] ; for ( int i = 0 ; i < N ; i ++ ) { if ( A [ i ] == max ) { System . out . println ( nextmax ) ; } else { System . out . println ( max ) ; } } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String a = sc . next ( ) ; String b = sc . next ( ) ; String A = " " ; String B = " " ; for ( int i = 0 ; i < Integer . parseInt ( b ) ; i ++ ) { String B = " " ; A += a ; } for ( int i = 0 ; i < Integer . parseInt ( a ) ; i ++ ) { B += b ; } System . out . print ( ( A . compareTo ( B ) ) < 0 ? A : B ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . Arrays ; public class Main { public static void main ( String [ ] args ) throws NumberFormatException , IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; while ( true ) { int b = Integer . parseInt ( tmpArray [ 1 ] ) ; String [ ] tmpArray = br . readLine ( ) . split ( " " ) ; int a = Integer . parseInt ( tmpArray [ 0 ] ) ; int b = Integer . parseInt ( tmpArray [ 1 ] ) ; if ( a == 0 && b == 0 ) { break ; } for ( int i = 0 ; i < a ; i ++ ) { for ( int j = 0 ; j < b ; j ++ ) { System . out . print ( " # " ) ; } System . out . println ( ) ; } System . out . println ( ) ; } } } +class Main { public static void main ( String [ ] args ) { java . util . Scanner sc = new java . util . Scanner ( System . in ) ; final int N = sc . nextInt ( ) ; final int L = sc . nextInt ( ) ; int output = 0 ; if ( - 1 <= L - 1 ) { output -= L ; } else if ( L - 1 <= - N ) { int output = 0 ; output -= L + N - 1 ; } output += N * ( L - 1 ) + N * ( N + 1 ) / 2 ; System . out . println ( output ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String word = sc . next ( ) ; String mae = " " ; String usiro = " " ; while ( ! word . equals ( " - " ) ) { String usiro = " " ; int n = sc . nextInt ( ) ; for ( int i = 0 ; i < n ; i ++ ) { int a = sc . nextInt ( ) ; usiro = word . substring ( a ) ; mae = word . substring ( 0 , a ) ; word = usiro + mae ; } System . out . println ( word ) ; word = sc . next ( ) ; } sc . close ( ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int c = sc . nextInt ( ) ; int n = sc . nextInt ( ) ; int max = Math . max ( a , b ) ; max = Math . max ( max , c ) ; int sum = 0 ; if ( max == a ) { for ( int i = 0 ; i < n ; i ++ ) { a *= 2 ; } } else if ( max == b ) { for ( int i = 0 ; i < n ; i ++ ) { b *= 2 ; } } else { int i = 0 ; for ( int i = 0 ; i < n ; i ++ ) { c *= 2 ; } } sum = a + b + c ; System . out . println ( sum ) ; } public static void printArray ( int [ ] array ) { for ( int i = 0 ; i < array . length ; i ++ ) { if ( i == array . length ) { System . out . println ( array [ i ] ) ; } else { System . out . print ( String . format ( " %d " , array [ i ] ) ) ; } } } public static int gcd ( int a , int b ) { if ( b == 0 ) return a ; return gcd ( b , a % b ) ; } public static int lcm ( int a , int b ) { return a * b / gcd ( a , b ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int [ ] [ ] c = new int [ 3 ] [ 3 ] ; for ( int i = 0 ; i < 3 ; i ++ ) { c [ i ] [ 0 ] = Integer . parseInt ( scanner . next ( ) ) ; c [ i ] [ 1 ] = Integer . parseInt ( scanner . next ( ) ) ; c [ i ] [ 2 ] = Integer . parseInt ( scanner . next ( ) ) ; } scanner . close ( ) ; for ( int i = 0 ; i < c . length ; i ++ ) { int min = Integer . MAX_VALUE ; for ( int j = 0 ; j < c [ i ] . length ; j ++ ) { int num = c [ i ] [ j ] ; if ( min > num ) { min = num ; } } for ( int j = 0 ; j < c [ i ] . length ; j ++ ) { c [ i ] [ j ] -= min ; } } for ( int i = 0 ; i < c . length ; i ++ ) { int i = 0 ; if ( c [ 0 ] [ i ] != c [ 1 ] [ i ] || c [ 1 ] [ i ] != c [ 2 ] [ i ] ) { System . out . println ( " No " ) ; return ; } } System . out . println ( " Yes " ) ; } } +import java . util . Scanner ; class Main { int n , m , x , y ; public void solve ( ) { Scanner sc = new Scanner ( System . in ) ; sc . useDelimiter ( " \\ s " ) ; n = sc . nextInt ( ) ; m = sc . nextInt ( ) ; int [ ] [ ] A = new int [ n ] [ m ] ; int [ ] b = new int [ m ] ; int [ ] c = new int [ n ] ; for ( x = 0 ; x < n ; x ++ ) { c [ x ] = 0 ; for ( y = 0 ; y < m ; y ++ ) { A [ x ] [ y ] = sc . nextInt ( ) ; } } for ( y = 0 ; y < m ; y ++ ) { b [ y ] = sc . nextInt ( ) ; } for ( x = 0 ; x < n ; x ++ ) { int [ ] c = new int [ n ] ; for ( y = 0 ; y < m ; y ++ ) { c [ x ] = c [ x ] + A [ x ] [ y ] * b [ y ] ; } } for ( x = 0 ; x < n ; x ++ ) { System . out . println ( c [ x ] ) ; } } public static void main ( String [ ] args ) { new Main ( ) . solve ( ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; int x = Integer . parseInt ( sc . next ( ) ) ; int y = Integer . parseInt ( sc . next ( ) ) ; String postal = sc . next ( ) ; String [ ] decomp = new String [ 3 ] ; decomp [ 0 ] = postal . substring ( 0 , x ) ; decomp [ 1 ] = postal . substring ( x , x + 1 ) ; decomp [ 2 ] = postal . substring ( x + 1 , postal . length ( ) - 1 ) ; for ( int i = 0 ; i < 3 ; i ++ ) { char [ ] array = decomp [ i ] . toCharArray ( ) ; if ( i == 0 || i == 2 ) { for ( char c : array ) { if ( ! Character . isDigit ( c ) ) { System . out . println ( " No " ) ; return ; } } } else { char c ; if ( array [ 0 ] != '-' ) { System . out . println ( " No " ) ; return ; } } } System . out . println ( " Yes " ) ; } } +import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] array = new int [ n ] ; boolean b = true ; int i ; for ( i = 0 ; i < n ; i ++ ) { array [ i ] = sc . nextInt ( ) ; } Arrays . sort ( array ) ; for ( i = 0 ; i < n ; i ++ ) { if ( i != 0 ) { int i ; if ( array [ i - 1 ] == array [ i ] ) { b = false ; break ; } } } System . out . println ( b ? " YES " : " NO " ) ; } } +import java . io . * ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int numData = Integer . parseInt ( br . readLine ( ) ) ; int currentT = 0 ; int currentX = 0 ; int currentY = 0 ; int nextT = 0 ; int nextX = 0 ; int nextY = 0 ; int amountMove = 0 ; for ( int i = 0 ; i < numData ; i ++ ) { String [ ] data = br . readLine ( ) . split ( " " ) ; nextT = Integer . parseInt ( data [ 0 ] ) ; nextX = Integer . parseInt ( data [ 1 ] ) ; nextY = Integer . parseInt ( data [ 2 ] ) ; amountMove = Math . abs ( nextX - currentX ) + Math . abs ( nextY - currentY ) ; if ( amountMove > nextT - currentT || ( nextT - currentT - amountMove ) % 2 != 0 ) { int amountMove = 0 ; System . out . println ( " No " ) ; return ; } } System . out . println ( " Yes " ) ; } } +import java . util . HashSet ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scn = new Scanner ( System . in ) ; int N = scn . nextInt ( ) ; HashSet < Integer > arr = new HashSet < Integer > ( ) ; boolean yes = true ; for ( int i = 0 ; i < N ; i ++ ) { int a = scn . nextInt ( ) ; if ( arr . contains ( a ) ) { yes = false ; break ; } else { int a = scn . nextInt ( ) ; arr . add ( a ) ; } } System . out . println ( yes ? " YES " : " NO " ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; char [ ] s = scanner . next ( ) . toCharArray ( ) ; for ( int i = 1 ; i < 3 ; i ++ ) { if ( s [ i ] != s [ i - 1 ] ) { int i = 1 ; System . out . println ( " Yes " ) ; return ; } } System . out . println ( " No " ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int a = scanner . nextInt ( ) ; int b = scanner . nextInt ( ) ; int c = scanner . nextInt ( ) ; int count = 0 ; int compare = 0 ; for ( int i = a ; i > 0 ; i -- ) { compare = 0 ; List < String > split = Arrays . asList ( String . valueOf ( i ) . split ( " " ) ) ; for ( int j = 0 ; j < split . size ( ) ; j ++ ) { compare += Integer . parseInt ( split . get ( j ) ) ; } if ( b <= compare && compare <= c ) { int j = 0 ; count += i ; } } System . out . println ( count ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; final int k = sc . nextInt ( ) , a = sc . nextInt ( ) , b = sc . nextInt ( ) ; if ( a % k == 0 || b % k == 0 ) { System . out . println ( " OK " ) ; } else { if ( b / k - a / k == 0 ) { final int k = sc . nextInt ( ) , a = sc . nextInt ( ) , b = sc . nextInt ( ) ; System . out . println ( " NG " ) ; } else { System . out . println ( " OK " ) ; } } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int standard = 1 ; while ( true ) { int target = standard * 2 ; int target = standard * 2 ; if ( target <= n ) { standard = target ; } else { break ; } } System . out . println ( standard ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = Integer . parseInt ( sc . nextLine ( ) ) ; List < String > list = new ArrayList < > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { String s = sc . nextLine ( ) ; char [ ] c = s . toCharArray ( ) ; Arrays . sort ( c ) ; s = new String ( c ) ; list . add ( s ) ; } Collections . sort ( list ) ; long ans = 0 ; long count = 0 ; String t = " " ; String u = " " ; boolean check = false ; for ( int i = 0 ; i < N ; i ++ ) { int i = 0 ; check = false ; if ( i == 0 ) { t = list . get ( i ) ; count ++ ; continue ; } u = list . get ( i ) ; if ( t . equals ( u ) && i < N - 1 ) { count ++ ; } else if ( t . equals ( u ) && i == N - 1 ) { count ++ ; check = true ; } else { t = u ; check = true ; } if ( check ) { ans += ( count * ( count - 1 ) ) / 2 ; t = u ; count = 1 ; } } System . out . println ( ans ) ; } } +import java . util . * ; class Reader { Scanner sc = new Scanner ( System . in ) ; public int ini ( ) { return sc . nextInt ( ) ; } public int [ ] vi ( int n ) { int [ ] a = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) a [ i ] = sc . nextInt ( ) ; return a ; } } public class Main extends Reader { public static void main ( String [ ] args ) { Main main = new Main ( ) ; main . show ( main . solve ( ) ) ; } int n ; int [ ] a ; public Main ( ) { n = ini ( ) ; a = vi ( n ) ; } int solve ( ) { int ans = 0 ; for ( int i = 0 ; i < n - 1 ; i ++ ) { int j = i + 1 ; for ( int j = i + 1 ; j < n ; j ++ ) { ans += a [ i ] * a [ j ] ; } } return ans ; } void show ( int ans ) { System . out . println ( ans ) ; } } +import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . io . * ; import java . util . * ; public class Main { private static BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; public static void main ( String [ ] args ) throws IOException { getLine ( ) ; List < String > strings = getStrOnLine ( ) ; int n = bubbleSort ( strings ) ; String out = String . join ( " " , strings ) ; System . out . println ( out ) ; System . out . println ( n ) ; } private static int bubbleSort ( List < String > list ) { boolean flag = true ; int n = 0 ; while ( flag ) { List < String > list = new ArrayList < > ( ) ; flag = false ; for ( int j = list . size ( ) - 1 ; j >= 1 ; j -- ) { int a = Integer . parseInt ( list . get ( j ) ) ; int b = Integer . parseInt ( list . get ( j - 1 ) ) ; if ( a < b ) { String tmp = list . get ( j ) ; list . set ( j , list . get ( j - 1 ) ) ; list . set ( j - 1 , tmp ) ; n ++ ; flag = true ; } } } return n ; } public static String getLine ( ) throws IOException { String str = br . readLine ( ) ; return str ; } public static List < String > getStrOnLine ( ) throws IOException { List < String > list = new ArrayList < > ( ) ; String line = getLine ( ) ; list . addAll ( Arrays . asList ( line . split ( " " ) ) ) ; return list ; } } +import java . util . Scanner ; class Main { public static void main ( final String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int n = scan . nextInt ( ) ; int [ ] a = new int [ n + 1 ] ; int [ ] b = new int [ n ] ; for ( int i = 0 ; i < n + 1 ; i ++ ) { a [ i ] = scan . nextInt ( ) ; } for ( int i = 0 ; i < n ; i ++ ) { int j = 0 ; b [ i ] = scan . nextInt ( ) ; } long ans = 0 ; for ( int j = 0 ; j < n ; j ++ ) { int x = Math . min ( a [ j ] , b [ j ] ) ; ans += x ; b [ j ] -= x ; int y = Math . min ( a [ j + 1 ] , b [ j ] ) ; ans += y ; a [ j + 1 ] -= y ; } System . out . println ( ans ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { try ( Scanner sc = new Scanner ( System . in ) ) { solve ( sc ) ; } } static void solve ( Scanner sc ) { int d = sc . nextInt ( ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int c = sc . nextInt ( ) ; int d = sc . nextInt ( ) ; if ( d <= a || b <= c ) { System . out . println ( 0 ) ; return ; } if ( c <= a ) { if ( d <= b ) { System . out . println ( d - a ) ; } else { System . out . println ( b - a ) ; } } else if ( c < b ) { if ( d <= b ) { System . out . println ( d - c ) ; } else { System . out . println ( b - c ) ; } } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { char tmp = a . charAt ( 0 ) ; Scanner sc = new Scanner ( System . in ) ; String a = sc . next ( ) ; String b = sc . next ( ) ; String c = sc . next ( ) ; int aIndex = 1 ; int bIndex = 0 ; int cIndex = 0 ; char tmp = a . charAt ( 0 ) ; while ( true ) { switch ( tmp ) { case 'a' : if ( a . length ( ) == aIndex ) { System . out . println ( " A " ) ; System . exit ( 0 ) ; } tmp = a . charAt ( aIndex ++ ) ; break ; case 'b' : if ( b . length ( ) == bIndex ) { System . out . println ( " B " ) ; System . exit ( 0 ) ; } tmp = b . charAt ( bIndex ++ ) ; break ; case 'c' : if ( c . length ( ) == cIndex ) { System . out . println ( " C " ) ; System . exit ( 0 ) ; } tmp = c . charAt ( cIndex ++ ) ; break ; } } } } +import java . util . * ; public class Main { static long GOSENCHOU = 5000000000000000l ; public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; String str = sc . next ( ) ; int n = str . length ( ) ; int [ ] s = new int [ n ] ; long k = sc . nextLong ( ) ; int answer = - 1 ; for ( int i = 0 ; i < n ; i ++ ) { s [ i ] = Integer . parseInt ( String . valueOf ( str . charAt ( i ) ) ) ; if ( s [ i ] == 1 ) { if ( i + 1 == k ) { answer = 1 ; break ; } } else { int i = 0 ; answer = s [ i ] ; break ; } } System . out . println ( answer ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; Integer [ ] p = new Integer [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { p [ i ] = sc . nextInt ( ) ; } int result = 0 ; for ( int i = 1 ; i < n - 1 ; i ++ ) { if ( Math . max ( p [ i - 1 ] , p [ i + 1 ] ) >= p [ i ] && Math . min ( p [ i - 1 ] , p [ i + 1 ] ) <= p [ i ] ) { int i = 1 ; result ++ ; } } System . out . println ( result ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int i = 1 ; Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int Q = sc . nextInt ( ) ; char [ ] arr = sc . next ( ) . toCharArray ( ) ; int [ ] dp = new int [ arr . length ] ; for ( int i = 1 ; i < dp . length ; i ++ ) { if ( arr [ i ] == 'C' && arr [ i - 1 ] == 'A' ) { dp [ i ] = 1 ; } } for ( int i = 1 ; i < dp . length ; i ++ ) { dp [ i ] += dp [ i - 1 ] ; } while ( Q -- > 0 ) { int l = sc . nextInt ( ) ; int r = sc . nextInt ( ) ; l -- ; r -- ; int val = dp [ r ] - dp [ l ] ; System . out . println ( val ) ; } } } +import java . util . * ; import java . lang . * ; import java . io . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int p = sc . nextInt ( ) ; int q = sc . nextInt ( ) ; int r = sc . nextInt ( ) ; int [ ] times = new int [ 3 ] ; times [ 0 ] = p + q ; times [ 1 ] = q + r ; times [ 2 ] = r + p ; int min = 0 ; for ( int i = 0 ; i < 3 ; i ++ ) { int i = 0 ; if ( i == 0 ) { min = times [ 0 ] ; } else { min = Math . min ( min , times [ i ] ) ; } } System . out . println ( min ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 1 ; Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; String S = sc . next ( ) ; int count = 1 ; char [ ] slime = S . toCharArray ( ) ; for ( int i = 1 ; i < N ; i ++ ) { if ( slime [ i ] != slime [ i - 1 ] ) { count += 1 ; } } System . out . println ( count ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner stdIn = new Scanner ( System . in ) ; Scanner stdIn = new Scanner ( System . in ) ; while ( stdIn . hasNext ( ) ) { System . out . println ( ( int ) Math . log10 ( stdIn . nextInt ( ) + stdIn . nextInt ( ) ) + 1 ) ; } } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int k = sc . nextInt ( ) ; int [ ] a = new int [ k ] ; long sum = 0 ; for ( int i = 0 ; i < k ; i ++ ) { a [ i ] = sc . nextInt ( ) ; sum = sum + a [ i ] ; } if ( sum >= n ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } } +import java . io . IOException ; import java . io . InputStream ; import java . io . PrintWriter ; import java . util . StringTokenizer ; import java . io . BufferedReader ; import java . io . InputStreamReader ; class Main { public static void main ( String [ ] args ) { InputReader in = new InputReader ( System . in ) ; PrintWriter out = new PrintWriter ( System . out ) ; int x = in . nextInt ( ) ; int y = in . nextInt ( ) ; int z = in . nextInt ( ) ; int p = x ; System . out . println ( z + " " + x + " " + y ) ; } static class InputReader { public BufferedReader reader ; public StringTokenizer tokenizer ; public InputReader ( InputStream stream ) { reader = new BufferedReader ( new InputStreamReader ( stream ) , 32768 ) ; tokenizer = null ; } public String next ( ) { while ( tokenizer == null || ! tokenizer . hasMoreTokens ( ) ) { try { tokenizer = new StringTokenizer ( reader . readLine ( ) ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } } return tokenizer . nextToken ( ) ; } public int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } } } +import java . util . Scanner ; import java . util . regex . Pattern ; public class Main { static Scanner sc = new Scanner ( System . in ) ; public static void main ( String [ ] args ) throws Exception { new Main ( ) . run ( ) ; } void run ( ) { int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; Pattern ptn = Pattern . compile ( " \\ d { " + a + " } - \\ d { " + b + " } " ) ; String s = sc . next ( ) ; System . out . println ( ptn . matcher ( s ) . matches ( ) ? " Yes " : " No " ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { final int MOD = 1000000007 ; final Scanner scanner = new Scanner ( System . in ) ; int N = scanner . nextInt ( ) ; int M = scanner . nextInt ( ) ; final int [ ] a = new int [ N + 1 ] ; for ( int i = 0 ; i < M ; i ++ ) { a [ scanner . nextInt ( ) ] = - 1 ; } a [ 0 ] = 1 ; for ( int i = 0 ; i < a . length ; i ++ ) { int i = 0 ; if ( a [ i ] == - 1 ) continue ; if ( i + 1 < a . length && a [ i + 1 ] != - 1 ) a [ i + 1 ] = ( a [ i ] + a [ i + 1 ] ) % MOD ; if ( i + 2 < a . length && a [ i + 2 ] != - 1 ) { a [ i + 2 ] = ( a [ i ] + a [ i + 2 ] ) % MOD ; } } System . out . println ( a [ N ] % MOD ) ; } } +import java . util . HashSet ; import java . util . Scanner ; import java . util . Set ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int n = scan . nextInt ( ) ; int cnt = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int x = scan . nextInt ( ) ; int x = scan . nextInt ( ) ; if ( x % 2 == 0 ) { cnt ++ ; if ( x % 3 == 0 || x % 5 == 0 ) { cnt -- ; } } } if ( cnt == 0 ) { System . out . println ( " APPROVED " ) ; } else { System . out . println ( " DENIED " ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int k = sc . nextInt ( ) ; int [ ] b = new int [ n ] ; for ( int i = 0 ; i < k ; i ++ ) { int d = sc . nextInt ( ) ; int [ ] a = new int [ d ] ; for ( int j = 0 ; j < d ; j ++ ) { a [ j ] = sc . nextInt ( ) ; int c = a [ j ] ; b [ c - 1 ] = 1 ; } } int count = 0 ; for ( int x = 0 ; x < b . length ; x ++ ) { int x = 0 ; if ( b [ x ] == 0 ) { count = count + 1 ; } } System . out . println ( count ) ; } } +import java . util . HashSet ; import java . util . LinkedList ; import java . util . Queue ; import java . util . Scanner ; import java . util . Set ; public class Main { public static void main ( String [ ] args ) { int N ; int [ ] A1i ; int [ ] A2i ; Set < Integer > searched = new HashSet < > ( ) ; Queue < Integer > queue = new LinkedList < > ( ) ; try ( Scanner sc = new Scanner ( System . in ) ) { N = sc . nextInt ( ) ; A1i = new int [ N ] ; A2i = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { A1i [ i ] = sc . nextInt ( ) ; } for ( int i = 0 ; i < N ; i ++ ) { int i = 0 ; A2i [ i ] = sc . nextInt ( ) ; } } int [ ] Sum1 = new int [ N ] ; int sum1 = 0 ; for ( int i = 0 ; i < N ; i ++ ) { sum1 += A1i [ i ] ; Sum1 [ i ] = sum1 ; } int [ ] Sum2 = new int [ N ] ; int sum2 = 0 ; for ( int i = N - 1 ; i >= 0 ; i -- ) { sum2 += A2i [ i ] ; Sum2 [ i ] = sum2 ; } int result = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( result < Sum1 [ i ] + Sum2 [ i ] ) { result = Sum1 [ i ] + Sum2 [ i ] ; } } System . out . println ( result ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int B = sc . nextInt ( ) ; Scanner sc = new Scanner ( System . in ) ; int A = sc . nextInt ( ) ; int B = sc . nextInt ( ) ; if ( A == B ) { System . out . println ( " IMPOSSIBLE " ) ; } else if ( ( A + B ) % 2 == 0 ) { System . out . println ( ( A + B ) / 2 ) ; } else { System . out . println ( " IMPOSSIBLE " ) ; } sc . close ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; String s = scan . next ( ) ; String t = scan . next ( ) ; int ans = t . length ( ) ; for ( int i = 0 ; i <= s . length ( ) - t . length ( ) ; i ++ ) { int diff = 0 ; for ( int j = 0 ; j < t . length ( ) ; j ++ ) { if ( s . charAt ( i + j ) != t . charAt ( j ) ) { int j = 0 ; diff ++ ; } } ans = Math . min ( ans , diff ) ; } System . out . println ( ans ) ; } } +import java . io . IOException ; import java . util . Scanner ; class Main { public static void main ( String [ ] args ) throws IOException { Scanner scane = new Scanner ( System . in ) ; int m = 0 , f = 0 , r = 0 ; int sum = 0 ; m = scane . nextInt ( ) ; f = scane . nextInt ( ) ; r = scane . nextInt ( ) ; while ( ( m + f + r ) != - 3 ) { sum = m + f ; if ( m == - 1 || f == - 1 ) { System . out . println ( " F " ) ; } if ( ( m != - 1 && f != - 1 ) && sum >= 80 ) { System . out . println ( " A " ) ; } else if ( ( m != - 1 && f != - 1 ) && sum < 80 && sum >= 65 ) { System . out . println ( " B " ) ; } else if ( ( m != - 1 && f != - 1 ) && sum < 65 && sum >= 50 ) { System . out . println ( " C " ) ; } else if ( ( m != - 1 && f != - 1 ) && sum < 50 && sum >= 30 ) { if ( r >= 50 ) { System . out . println ( " C " ) ; } else { System . out . println ( " D " ) ; } } else if ( sum < 30 ) { int sum = 0 ; System . out . println ( " F " ) ; } m = scane . nextInt ( ) ; f = scane . nextInt ( ) ; r = scane . nextInt ( ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; int A = sc . nextInt ( ) ; String a1 ; String a2 ; a1 = sc . next ( ) ; a2 = sc . next ( ) ; String ans = " " ; for ( int i = 0 ; i < A ; i ++ ) { char aa = a1 . charAt ( i ) ; char bb = a2 . charAt ( i ) ; ans += String . valueOf ( aa ) + String . valueOf ( bb ) ; } System . out . println ( ans ) ; } } +import java . io . * ; public class Main { public static void main ( String [ ] args ) { String line = reader . readLine ( ) ; BufferedReader reader = new BufferedReader ( new InputStreamReader ( System . in ) ) ; while ( true ) { int i , sum = 0 ; try { String line = reader . readLine ( ) ; if ( line . equals ( " 0 " ) ) break ; for ( i = 0 ; i < line . length ( ) ; i ++ ) { char c = line . charAt ( i ) ; sum += Character . getNumericValue ( c ) ; } } catch ( IOException e ) { System . out . println ( e ) ; } System . out . println ( sum ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { long b = in . nextLong ( ) ; Scanner in = new Scanner ( System . in ) ; while ( in . hasNext ( ) ) { long a = in . nextLong ( ) ; long b = in . nextLong ( ) ; long c = LCM ( a , b ) ; long d = a * b / c ; System . out . println ( c + " " + d ) ; } } static long LCM ( long a , long b ) { if ( b == 0 ) { return a ; } else { return LCM ( b , a % b ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; String S = scanner . next ( ) ; int z = 0 ; int o = 0 ; for ( int i = 0 ; i < S . length ( ) ; i ++ ) { if ( S . charAt ( i ) == '0' ) { int i = 0 ; z ++ ; } else { o ++ ; } } int r = Math . min ( z , o ) * 2 ; System . out . print ( r ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int n = in . nextInt ( ) ; int [ ] hills = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { hills [ i ] = in . nextInt ( ) ; } int counter = 1 ; int cur = hills [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { if ( hills [ i ] >= cur ) { int i = 1 ; counter ++ ; cur = hills [ i ] ; } } System . out . println ( counter ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . Arrays ; public class Main { public static void main ( String [ ] args ) throws NumberFormatException , IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int n = Integer . parseInt ( br . readLine ( ) ) ; String [ ] tmpArray = br . readLine ( ) . split ( " " ) ; int [ ] input = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { input [ n - i - 1 ] = Integer . parseInt ( tmpArray [ i ] ) ; } System . out . print ( input [ 0 ] ) ; for ( int i = 1 ; i < n ; i ++ ) { int i = 1 ; System . out . print ( " " + input [ i ] ) ; } System . out . println ( ) ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int max = 0 ; int num = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int l = sc . nextInt ( ) ; int l = sc . nextInt ( ) ; if ( l > max ) { num = num + max ; max = l ; } else { num = num + l ; } } if ( max < num ) { System . out . print ( " Yes " ) ; } else { System . out . print ( " No " ) ; } } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int num = in . nextInt ( ) ; int Taro = 0 ; int Hanako = 0 ; while ( num != 0 ) { String taro = in . next ( ) ; String hanako = in . next ( ) ; if ( taro . compareTo ( hanako ) < 0 ) { int Hanako = 0 ; Hanako += 3 ; } else if ( taro . compareTo ( hanako ) > 0 ) { Taro += 3 ; } else { Taro += 1 ; Hanako += 1 ; } num -- ; } System . out . println ( Taro + " " + Hanako ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) , b = sc . nextInt ( ) , c = sc . nextInt ( ) , d = sc . nextInt ( ) , e = sc . nextInt ( ) , k = sc . nextInt ( ) ; String res = " Yay! " ; if ( e - a > k ) { String res = " Yay! " ; res = " :( " ; } System . out . println ( res ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner std = new Scanner ( System . in ) ; while ( true ) { int n = Integer . parseInt ( std . next ( ) ) ; if ( n == 0 ) { break ; } double [ ] score = new double [ n ] ; double ave = 0 ; for ( int i = 0 ; i < n ; i ++ ) { score [ i ] = Double . parseDouble ( std . next ( ) ) ; ave += score [ i ] ; } ave /= n ; double sd = 0 ; for ( int i = 0 ; i < n ; i ++ ) { sd += Math . pow ( ( score [ i ] - ave ) , 2 ) ; } sd /= n ; sd = Math . pow ( sd , 0.5 ) ; System . out . println ( String . format ( " %.5f " , sd ) ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int T = sc . nextInt ( ) ; int [ ] c = new int [ N ] ; int [ ] t = new int [ N ] ; int cmin = 1001 ; int twithin = 1001 ; for ( int i = 0 ; i < N ; i ++ ) { c [ i ] = sc . nextInt ( ) ; t [ i ] = sc . nextInt ( ) ; if ( t [ i ] <= T && cmin > c [ i ] ) { twithin = t [ i ] ; cmin = c [ i ] ; } } if ( twithin == 1001 ) { System . out . println ( " TLE " ) ; } else { int i = 0 ; System . out . println ( cmin ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; int [ ] num = new int [ 5 ] ; for ( int i = 0 ; i < 5 ; i ++ ) { num [ i ] = sc . nextInt ( ) ; } int k = sc . nextInt ( ) ; String result = " Yay! " ; out : for ( int i = 0 ; i < 5 ; i ++ ) { for ( int j = i + 1 ; j < 5 ; j ++ ) { if ( Math . abs ( num [ i ] - num [ j ] ) > k ) { int j = i + 1 ; result = " :( " ; break out ; } } } System . out . println ( result ) ; } } +import java . util . LinkedList ; import java . util . Queue ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; Queue < Character > [ ] queues = new Queue [ 3 ] ; for ( int i = 0 ; i < 3 ; i ++ ) { queues [ i ] = new LinkedList < > ( ) ; for ( char ch : scanner . next ( ) . toCharArray ( ) ) queues [ i ] . add ( ch ) ; } int c = 0 ; while ( true ) { if ( queues [ c ] . isEmpty ( ) ) { char ch = queues [ c ] . remove ( ) ; System . out . println ( ( char ) ( 'A' + c ) ) ; return ; } char ch = queues [ c ] . remove ( ) ; c = ch - 'a' ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { ( new Main ( ) ) . execute ( ) ; } public void execute ( ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int [ ] p = new int [ N + 1 ] ; int ngPos = 0 ; int ngNum = 0 ; int changeCount = 0 ; boolean ok = true ; for ( int i = 1 ; i <= N ; i ++ ) { int i = 1 ; p [ i ] = sc . nextInt ( ) ; if ( p [ i ] != i ) { if ( 0 < changeCount ) { ok = false ; break ; } if ( 0 == ngPos ) { ngPos = i ; ngNum = p [ i ] ; } else { if ( ngPos == p [ i ] && ngNum == i ) { changeCount ++ ; ngPos = 0 ; ngNum = 0 ; } else { ok = false ; break ; } } } } if ( ok ) { 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 n = 0 ; String str = sc . next ( ) ; for ( int i = 0 ; i < 4 ; i ++ ) { int i = 0 ; if ( str . charAt ( i ) == '+' ) n ++ ; else n -- ; } System . out . println ( n ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int j = 0 ; Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int sum = 0 ; for ( int i = a ; i <= b ; i ++ ) { char [ ] array = String . valueOf ( i ) . toCharArray ( ) ; int count = 0 ; for ( int j = 0 ; j < array . length - 2 ; j ++ ) { int tail = array . length - 1 - j ; if ( array [ j ] == array [ tail ] ) { count ++ ; } } if ( count == 3 ) { sum ++ ; } } System . out . println ( sum ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int k = sc . nextInt ( ) ; int [ ] h = new int [ n ] ; int counter = 0 ; for ( int i = 0 ; i < h . length ; i ++ ) { h [ i ] = sc . nextInt ( ) ; if ( h [ i ] >= k ) { counter ++ ; } } System . out . println ( counter ) ; sc . close ( ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner stdIn = new Scanner ( System . in ) ; int N = stdIn . nextInt ( ) ; int [ ] d = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { d [ i ] = stdIn . nextInt ( ) ; } Arrays . sort ( d ) ; int count = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( i >= 1 && d [ i ] != d [ i - 1 ] ) { count ++ ; } else if ( i == 0 ) { int i = 0 ; count ++ ; } } System . out . println ( count ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . StringTokenizer ; public class Main { static class FastReader { BufferedReader br ; StringTokenizer st ; public FastReader ( ) { br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; } String next ( ) { while ( st == null || ! st . hasMoreElements ( ) ) { try { st = new StringTokenizer ( br . readLine ( ) ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } return st . nextToken ( ) ; } int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } long nextLong ( ) { return Long . parseLong ( next ( ) ) ; } double nextDouble ( ) { return Double . parseDouble ( next ( ) ) ; } String nextLine ( ) { String str = " " ; try { str = br . readLine ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } return str ; } } public static void main ( String [ ] args ) { String str = obj . next ( ) ; FastReader obj = new FastReader ( ) ; String str = obj . next ( ) ; System . out . println ( ( str . compareTo ( " ABC " ) == 0 ) ? " ARC " : " ABC " ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Main main = new Main ( ) ; main . solve ( ) ; } void solve ( ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; int n = Integer . parseInt ( sc . next ( ) ) ; int q = Integer . parseInt ( sc . next ( ) ) ; String S = sc . next ( ) ; int [ ] dp = new int [ n ] ; for ( int i = 1 ; i < n ; i ++ ) { dp [ i ] = dp [ i - 1 ] ; if ( S . substring ( i - 1 , i + 1 ) . equals ( " AC " ) ) { dp [ i ] ++ ; } } for ( int i = 0 ; i < q ; i ++ ) { int L = Integer . parseInt ( sc . next ( ) ) ; int R = Integer . parseInt ( sc . next ( ) ) ; System . out . println ( ( dp [ R - 1 ] - dp [ L - 1 ] ) ) ; } sc . close ( ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner obj = new Scanner ( System . in ) ; ArrayList < Integer > a = new ArrayList < > ( ) ; for ( int i = 0 ; i < 3 ; i ++ ) { ArrayList < Integer > a = new ArrayList < > ( ) ; a . add ( obj . nextInt ( ) ) ; } Collections . sort ( a ) ; int sum = a . get ( 0 ) + a . get ( 1 ) ; System . out . println ( sum ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; String [ ] line = sc . nextLine ( ) . split ( " " ) ; int buttonA = Integer . parseInt ( line [ 0 ] ) ; int buttonB = Integer . parseInt ( line [ 1 ] ) ; int ans = 0 ; if ( buttonA > buttonB ) { int ans = 0 ; ans += buttonA ; buttonA -- ; } else { ans += buttonB ; buttonB -- ; } if ( buttonA > buttonB ) { ans += buttonA ; } else { ans += buttonB ; } System . out . println ( ans ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; int maxLen = 0 ; int leftIdx = 0 ; Set < Character > set = new HashSet < > ( ) ; set . add ( 'A' ) ; set . add ( 'C' ) ; set . add ( 'G' ) ; set . add ( 'T' ) ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( ! set . contains ( s . charAt ( i ) ) ) { maxLen = Math . max ( maxLen , i - leftIdx ) ; leftIdx = i + 1 ; } } maxLen = Math . max ( maxLen , s . length ( ) - leftIdx ) ; System . out . println ( maxLen ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String S = sc . next ( ) ; int n = 0 ; for ( int i = 0 ; i < S . length ( ) ; i ++ ) { if ( S . charAt ( i ) == '+' ) { int i = 0 ; n = n + 1 ; } else { n = n - 1 ; } } System . out . println ( n ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; for ( int i = 1 ; i <= n ; i ++ ) { if ( i % 3 == 0 || Integer . toString ( i ) . contains ( " 3 " ) ) { int i = 1 ; if ( 0 < i ) { System . out . print ( " " + i ) ; } else { System . out . print ( i ) ; } } } System . out . println ( ) ; } } +import java . math . BigInteger ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int toshi = 0 ; Long K ; Scanner sc = new Scanner ( System . in ) ; K = sc . nextLong ( ) ; Long bank = 100L ; int toshi = 0 ; while ( bank < K ) { bank = ( long ) ( bank * 1.01 ) ; toshi ++ ; } System . out . println ( toshi ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int c = sc . nextInt ( ) ; int s = 0 ; if ( a < b ) { int s = 0 ; for ( ; a < b ; a ++ ) { if ( c % a == 0 ) s ++ ; } } else if ( a > b ) ; { for ( ; b < a ; b ++ ) { if ( c % b == 0 ) s ++ ; } } if ( a == b ) if ( c % a == 0 ) s ++ ; System . out . println ( s ) ; } } +import java . util . Scanner ; public class Main { public void solve ( ) { Scanner sc = new Scanner ( System . in ) ; int a , b , c , hozon ; a = sc . nextInt ( ) ; b = sc . nextInt ( ) ; c = sc . nextInt ( ) ; if ( a > b ) { int a , b , c , hozon ; hozon = a ; a = b ; b = hozon ; } if ( b > c ) { hozon = b ; b = c ; c = hozon ; } if ( a > b ) { hozon = a ; a = b ; b = hozon ; } System . out . println ( a + " " + b + " " + c ) ; } public static void main ( String [ ] args ) { Main obj = new Main ( ) ; obj . solve ( ) ; } } +import java . io . IOException ; import java . io . BufferedReader ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws IOException { int i = 1 ; try ( BufferedReader reader = new BufferedReader ( new InputStreamReader ( System . in ) ) ) { final String s = reader . readLine ( ) ; boolean flg = false ; if ( s . charAt ( 0 ) == 'A' ) { int cnt = 0 ; int at = 0 ; for ( int i = 2 ; i <= s . length ( ) - 2 ; i ++ ) { if ( s . charAt ( i ) == 'C' ) { cnt ++ ; at = i ; } } if ( cnt == 1 ) { flg = true ; for ( int i = 1 ; i < s . length ( ) ; i ++ ) { if ( i == at ) continue ; if ( s . charAt ( i ) < 'a' || 'z' < s . charAt ( i ) ) { flg = false ; break ; } } } } System . out . println ( flg ? " AC " : " WA " ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner s = new Scanner ( System . in ) ; int a = s . nextInt ( ) ; int b = s . nextInt ( ) ; int c = s . nextInt ( ) ; int d = s . nextInt ( ) ; int start ; int end ; if ( a < c ) { int end ; start = c ; } else { start = a ; } if ( b < d ) { end = b ; } else { end = d ; } if ( start < end ) { System . out . println ( end - start ) ; } else { System . out . println ( " 0 " ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int a ; int b ; try ( Scanner scanner = new Scanner ( System . in ) ) { a = scanner . nextInt ( ) ; b = scanner . nextInt ( ) ; } if ( ( a & b & 1 ) == 0 ) { System . out . println ( " Even " ) ; } else { Scanner scanner = new Scanner ( System . in ) ; System . out . println ( " Odd " ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] w = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { int minTemp = Math . abs ( s1 - s2 ) ; w [ i ] = sc . nextInt ( ) ; } int min = 1000000000 ; for ( int i = 0 ; i < n ; i ++ ) { int s1 = 0 ; int s2 = 0 ; for ( int j = 0 ; j <= i ; j ++ ) { s1 += w [ j ] ; } for ( int k = i + 1 ; k <= n - 1 ; k ++ ) { s2 += w [ k ] ; } int minTemp = Math . abs ( s1 - s2 ) ; if ( minTemp < min ) { min = minTemp ; } } System . out . println ( min ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; String [ ] str ; str = new String [ 3 ] ; int num1 , num2 , Ans ; Ans = 0 ; for ( int i = 1 ; ; i ++ ) { str [ 0 ] = in . next ( ) ; str [ 1 ] = in . next ( ) ; str [ 2 ] = in . next ( ) ; num1 = Integer . parseInt ( str [ 0 ] ) ; num2 = Integer . parseInt ( str [ 2 ] ) ; if ( str [ 1 ] . equals ( " ? " ) ) { break ; } else { if ( str [ 1 ] . equals ( " + " ) ) { Ans = num1 + num2 ; } if ( str [ 1 ] . equals ( " - " ) ) { Ans = num1 - num2 ; } if ( str [ 1 ] . equals ( " * " ) ) { Ans = num1 * num2 ; } if ( str [ 1 ] . equals ( " / " ) ) { int num1 , num2 , Ans ; Ans = num1 / num2 ; } System . out . println ( Ans ) ; } } } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int h = sc . nextInt ( ) ; int a = sc . nextInt ( ) ; int count = 0 ; do { count ++ ; h -= a ; if ( h <= 0 ) { int count = 0 ; System . out . println ( count ) ; } } while ( h > 0 ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . StringTokenizer ; public class Main { public static void main ( String [ ] args ) throws IOException { int c = Integer . parseInt ( st . nextToken ( ) ) ; BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int d = 0 ; int sum = 0 ; String str = br . readLine ( ) ; StringTokenizer st = new StringTokenizer ( str , " " ) ; int a = Integer . parseInt ( st . nextToken ( ) ) ; int b = Integer . parseInt ( st . nextToken ( ) ) ; int c = Integer . parseInt ( st . nextToken ( ) ) ; for ( d = a ; d <= b ; d ++ ) { if ( c % d == 0 ) { sum ++ ; } } System . out . println ( sum ) ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int A = sc . nextInt ( ) ; final int B = sc . nextInt ( ) ; int C = sc . nextInt ( ) ; final int D = sc . nextInt ( ) ; sc . close ( ) ; while ( true ) { final int D = sc . nextInt ( ) ; C -= B ; if ( C <= 0 ) break ; A -= D ; if ( A <= 0 ) break ; } if ( C <= 0 ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { try ( Scanner sc = new Scanner ( System . in ) ) { while ( true ) { int n = sc . nextInt ( ) ; int sum = 0 ; if ( n == 0 ) { break ; } int [ ] scores = new int [ n ] ; for ( int i = 0 ; i < scores . length ; i ++ ) { scores [ i ] = sc . nextInt ( ) ; } double average = 0 , variance = 0 , y = 0 ; for ( int i = 0 ; i < scores . length ; i ++ ) { sum = sum + scores [ i ] ; } average = ( double ) sum / n ; for ( int i = 0 ; i < scores . length ; i ++ ) { int i = 0 ; double x = Math . pow ( ( scores [ i ] - average ) , 2 ) ; y = x + y ; } variance = y / n ; System . out . println ( Math . sqrt ( variance ) ) ; } } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int ans = 0 ; String s = sc . nextLine ( ) ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( s . charAt ( i ) == '+' ) { ans ++ ; } else if ( s . charAt ( i ) == '-' ) { int i = 0 ; ans -- ; } } System . out . println ( ans ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; String S = in . next ( ) ; String res ; if ( S . equals ( " Sunny " ) ) { res = " Cloudy " ; } else if ( S . equals ( " Cloudy " ) ) { String res ; res = " Rainy " ; } else { res = " Sunny " ; } System . out . println ( res ) ; in . close ( ) ; } } +import java . util . ArrayList ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner s = new Scanner ( System . in ) ; int x = s . nextInt ( ) ; int y = s . nextInt ( ) ; int flag = 0 ; for ( int i = 0 ; i <= x ; i ++ ) { if ( i * 2 + ( x - i ) * 4 == y ) { int i = 0 ; System . out . println ( " Yes " ) ; flag = 1 ; break ; } } if ( flag == 0 ) { System . out . println ( " No " ) ; } } } +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 + 1 ] ; for ( int i = 0 ; i < N ; i ++ ) { a [ i ] = sc . nextInt ( ) ; } int max ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = i ; j < N ; j ++ ) { if ( a [ i ] < a [ j ] ) { int i = 0 ; max = a [ i ] ; a [ i ] = a [ j ] ; a [ j ] = max ; } } } int A = 0 ; int B = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( i % 2 == 0 ) { A = A + a [ i ] ; } if ( i % 2 != 0 ) { B = B + a [ i ] ; } } int point = Math . abs ( A - B ) ; System . out . println ( point ) ; sc . close ( ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String y = sc . next ( ) ; String j = sc . next ( ) ; int result = 0 ; for ( int i = 0 ; i < y . length ( ) ; i ++ ) { if ( y . charAt ( i ) == j . charAt ( i ) ) { int i = 0 ; result += 1 ; } } System . out . println ( result ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws Exception { try ( Scanner sc = new Scanner ( System . in ) ) { String S = sc . next ( ) ; for ( int i = 1 ; i <= S . length ( ) ; i ++ ) { char c = S . charAt ( i - 1 ) ; if ( i % 2 == 1 ) { if ( c == 'R' || c == 'U' || c == 'D' ) { } else { System . out . println ( " No " ) ; System . exit ( 0 ) ; } } else { char c = S . charAt ( i - 1 ) ; if ( c == 'L' || c == 'U' || c == 'D' ) { } else { System . out . println ( " No " ) ; System . exit ( 0 ) ; } } } System . out . println ( " Yes " ) ; } } } +import java . util . * ; import java . io . * ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; int x = sc . nextInt ( ) ; int n = sc . nextInt ( ) ; if ( n == 0 ) { System . out . println ( x ) ; System . exit ( 0 ) ; } int [ ] number = new int [ 201 ] ; Arrays . fill ( number , 1 ) ; for ( int i = 0 ; i < n ; i ++ ) { int i = 0 ; int p = sc . nextInt ( ) ; number [ p ] = 0 ; } for ( int i = 0 ; i <= 200 ; i ++ ) { if ( x - i <= 0 ) continue ; if ( x + i > 200 ) continue ; if ( number [ x - i ] == 1 ) { System . out . println ( x - i ) ; System . exit ( 0 ) ; } if ( number [ x + i ] == 1 ) { System . out . println ( x + i ) ; System . exit ( 0 ) ; } } System . out . println ( 0 ) ; } } class Monmo { } +import java . io . * ; import java . util . * ; public class Main extends PrintWriter { Main ( ) { int i = 0 ; super ( System . out , true ) ; } Scanner sc = new Scanner ( System . in ) ; public static void main ( String [ ] $ ) { Main o = new Main ( ) ; o . main ( ) ; o . flush ( ) ; } void main ( ) { int N = sc . nextInt ( ) ; if ( N > 50 ) { N = 50 ; } String S = sc . next ( ) ; int Y = 0 ; int U = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( Y == 0 ) { if ( S . charAt ( i ) == 'A' ) { Y = 1 ; } } else if ( Y == 1 ) { if ( S . charAt ( i ) == 'B' ) { Y = 2 ; } else if ( S . charAt ( i ) == 'A' ) { Y = 1 ; } else { Y = 0 ; } } else if ( Y == 2 ) { if ( S . charAt ( i ) == 'C' ) { Y = 0 ; U ++ ; } else if ( S . charAt ( i ) == 'C' ) { Y = 1 ; } else { Y = 0 ; } } } print ( U ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] argc ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int [ ] A = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { A [ i ] = sc . nextInt ( ) ; } int count = 0 ; for ( int j = 0 ; j < N ; j ++ ) { int m = 0 ; int min = j ; for ( int k = j ; k < N ; k ++ ) { if ( A [ k ] < A [ min ] ) { min = k ; } } if ( j == min ) { int x = A [ min ] ; A [ min ] = A [ j ] ; A [ j ] = x ; } else { int x = A [ min ] ; A [ min ] = A [ j ] ; A [ j ] = x ; count ++ ; } } for ( int m = 0 ; m < N ; m ++ ) { if ( m == N - 1 ) { System . out . printf ( " %d " , A [ m ] ) ; } else { System . out . printf ( " %d " , A [ m ] ) ; } } System . out . printf ( " \n " ) ; System . out . println ( count ) ; } } +import java . util . * ; import java . io . PrintWriter ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int k = sc . nextInt ( ) ; long ans = 0 ; for ( int i = 1 ; i <= k ; i ++ ) { for ( int j = 1 ; j <= k ; j ++ ) { int t = 1 ; for ( int t = 1 ; t <= k ; t ++ ) { ans += gcd ( gcd ( i , j ) , t ) ; } } } System . out . println ( ans ) ; } private static long gcd ( long m , long n ) { if ( m < n ) return gcd ( n , m ) ; while ( n != 0 ) { long tmp = m ; m = n ; n = tmp % n ; } return m ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; Integer N = sc . nextInt ( ) ; Integer Q = sc . nextInt ( ) ; String S = sc . next ( ) ; Integer [ ] l = new Integer [ Q ] , r = new Integer [ Q ] ; for ( int i = 0 ; i < Q ; i ++ ) { l [ i ] = sc . nextInt ( ) ; r [ i ] = sc . nextInt ( ) ; } int [ ] a = new int [ N ] ; int count = 0 ; for ( int i = 1 ; i < N ; i ++ ) { if ( S . charAt ( i - 1 ) == 'A' && S . charAt ( i ) == 'C' ) { count ++ ; a [ i ] = count ; } else { int i = 0 ; a [ i ] = count ; } } for ( int i = 0 ; i < Q ; i ++ ) { System . out . println ( a [ r [ i ] - 1 ] - a [ l [ i ] - 1 ] ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] arr = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { arr [ sc . nextInt ( ) - 1 ] = i + 1 ; } StringBuilder sb = new StringBuilder ( ) ; for ( int i = 0 ; i < n ; i ++ ) { int i = 0 ; if ( i != 0 ) { sb . append ( " " ) ; } sb . append ( arr [ i ] ) ; } System . out . println ( sb ) ; } } +import java . io . * ; import java . util . * ; class Main { public static void main ( String [ ] args ) throws Exception { final Scanner sc = new Scanner ( System . in ) ; String S ; S = sc . next ( ) ; solve ( S ) ; } static void solve ( String S ) { System . out . println ( calc ( S ) ) ; } static int calc ( String S ) { String S ; switch ( S ) { case " SUN " : return 7 ; case " MON " : return 6 ; case " TUE " : return 5 ; case " WED " : return 4 ; case " THU " : return 3 ; case " FRI " : return 2 ; case " SAT " : return 1 ; } return 0 ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; String S = scanner . nextLine ( ) ; long K = scanner . nextLong ( ) ; StringBuilder sb = new StringBuilder ( ) ; for ( int i = 0 ; i < K ; i ++ ) { if ( S . charAt ( i ) == '1' ) { int i = 0 ; continue ; } System . out . println ( S . charAt ( i ) ) ; return ; } System . out . println ( 1 ) ; scanner . close ( ) ; } } +import java . io . * ; import java . util . * ; public class Main { static PrintWriter out = new PrintWriter ( ( System . out ) ) ; public static void main ( String [ ] args ) throws IOException { Kioken sc = new Kioken ( ) ; char ch = sc . next ( ) . charAt ( 0 ) ; if ( Character . isUpperCase ( ch ) ) { out . println ( " A " ) ; } else { out . println ( " a " ) ; } out . close ( ) ; } public static void kamehameha ( ) { } static class Kioken { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; StringTokenizer st = new StringTokenizer ( " " ) ; public String next ( ) { while ( ! st . hasMoreTokens ( ) ) { try { st = new StringTokenizer ( br . readLine ( ) ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; } } return st . nextToken ( ) ; } public int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } public long nextLong ( ) { return Long . parseLong ( next ( ) ) ; } public double nextDouble ( ) { return Double . parseDouble ( next ( ) ) ; } public String nextLine ( ) { try { return br . readLine ( ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; } return null ; } public boolean hasNext ( ) { String next = null ; String next = null ; try { next = br . readLine ( ) ; } catch ( Exception e ) { } if ( next == null ) { return false ; } st = new StringTokenizer ( next ) ; return true ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int maxAns = minAns ; Scanner scanner = new Scanner ( System . in ) ; int [ ] list = new int [ 9 ] ; int n = scanner . nextInt ( ) ; for ( int i = 0 ; i < n ; i ++ ) { int value = scanner . nextInt ( ) / 400 ; if ( value >= 8 ) { list [ 8 ] ++ ; } else { list [ value ] ++ ; } } int minAns = 0 ; for ( int i = 0 ; i < 8 ; i ++ ) { if ( list [ i ] > 0 ) { minAns ++ ; } } int maxAns = minAns ; if ( list [ 8 ] > 0 ) { minAns = Math . max ( minAns , 1 ) ; maxAns += list [ 8 ] ; } System . out . println ( minAns + " " + maxAns ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int ans = 0 ; @ SuppressWarnings ( " resource " ) Scanner scan = new Scanner ( System . in ) ; String W = scan . nextLine ( ) . toLowerCase ( ) ; int ans = 0 ; while ( scan . hasNext ( ) ) { String t = scan . next ( ) ; if ( t . equals ( " END_OF_TEXT " ) ) break ; t = t . toLowerCase ( ) ; if ( t . equals ( W ) ) ans ++ ; } System . out . println ( ans ) ; System . exit ( 0 ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] arg ) { Scanner sc = new Scanner ( System . in ) ; while ( true ) { int m = sc . nextInt ( ) ; int f = sc . nextInt ( ) ; int r = sc . nextInt ( ) ; int sum = m + f ; if ( m == - 1 && f == - 1 && r == - 1 ) break ; else if ( m == - 1 || f == - 1 || sum < 30 ) { System . out . println ( " F " ) ; } else if ( sum >= 80 ) { int r = sc . nextInt ( ) ; System . out . println ( " A " ) ; } else if ( 65 <= sum && sum < 80 ) { System . out . println ( " B " ) ; } else if ( 50 <= sum && sum < 65 ) { System . out . println ( " C " ) ; } else if ( 30 <= sum && sum < 50 ) { if ( r >= 50 ) System . out . println ( " C " ) ; else System . out . println ( " D " ) ; } } } } +import java . math . BigDecimal ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { final Scanner scanner = new Scanner ( System . in ) ; final int n = scanner . nextInt ( ) ; final int k = scanner . nextInt ( ) ; double result = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { final double a = Math . log ( k ) / Math . log ( 2 ) ; final double b = Math . log ( i ) / Math . log ( 2 ) ; double ceil = Math . ceil ( a - b ) ; if ( ceil < 0 ) { double ceil = Math . ceil ( a - b ) ; ceil = 0 ; } final double pow = Math . pow ( 0.5 , ceil ) ; result += pow ; } System . out . println ( result / n ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; char [ ] in = sc . next ( ) . toCharArray ( ) ; List < String > out = new ArrayList < > ( ) ; String kotae = " " ; for ( int i = 0 ; i < in . length ; i ++ ) { char b01 = in [ i ] ; if ( b01 == '0' ) { out . add ( out . size ( ) , " 0 " ) ; } else if ( b01 == '1' ) { out . add ( out . size ( ) , " 1 " ) ; } else if ( b01 == 'B' ) { if ( out . size ( ) == 0 ) { int i = 0 ; } else { out . remove ( out . size ( ) - 1 ) ; } } } for ( int i = 0 ; i < out . size ( ) ; i ++ ) { String s = out . get ( i ) ; kotae = kotae + s ; } System . out . println ( kotae ) ; } } +import java . io . BufferedReader ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws Exception { long K = A + B ; BufferedReader in = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String W = in . readLine ( ) ; String [ ] Ws = W . split ( " " ) ; long A = Long . parseLong ( Ws [ 0 ] ) ; long B = Long . parseLong ( Ws [ 1 ] ) ; long K = A + B ; if ( K % 2 == 1 ) { System . out . println ( " IMPOSSIBLE " ) ; } else { System . out . println ( K / 2 ) ; } } } +import java . util . * ; import static java . lang . Integer . * ; import static java . lang . System . * ; public class Main { public static void main ( String [ ] args ) { int i , j ; Scanner sc = new Scanner ( in ) ; int n = parseInt ( sc . next ( ) ) ; String [ ] s = new String [ n ] ; for ( i = 0 ; i < n ; i ++ ) { Integer ii ; s [ i ] = sc . next ( ) ; } sc . close ( ) ; String [ ] s2 ; for ( i = 0 ; i < n ; i ++ ) { s2 = s [ i ] . split ( " " ) ; Arrays . sort ( s2 ) ; s [ i ] = String . join ( " " , s2 ) ; } HashMap < String , Integer > c = new HashMap < > ( ) ; for ( i = 0 ; i < n ; i ++ ) { if ( c . containsKey ( s [ i ] ) ) { c . put ( s [ i ] , c . get ( s [ i ] ) + 1 ) ; } else { c . put ( s [ i ] , 1 ) ; } } long ans = 0 ; for ( Integer ii : c . values ( ) ) { ans += ( long ) ii * ( ii - 1 ) / 2 ; } 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 k = sc . nextInt ( ) ; int [ ] h = new int [ n + 1 ] ; for ( int i = 1 ; i <= n ; i ++ ) h [ i ] = sc . nextInt ( ) ; int [ ] dp = new int [ n + 1 ] ; dp [ 1 ] = 0 ; for ( int i = 2 ; i <= n ; i ++ ) { int j = i - 1 ; dp [ i ] = 1000000000 ; for ( int j = i - 1 ; j >= 1 && ( i - j ) <= k ; j -- ) { dp [ i ] = Math . min ( dp [ i ] , dp [ j ] + Math . abs ( h [ i ] - h [ j ] ) ) ; } } System . out . println ( dp [ n ] ) ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; long [ ] A = new long [ N + 2 ] ; long [ ] B = new long [ N + 1 ] ; long cnt = 0 ; long wk = 0 ; long wk2 = 0 ; for ( int i = 0 ; i < N + 1 ; i ++ ) { A [ i ] = sc . nextInt ( ) ; } for ( int i = 0 ; i < N ; i ++ ) { B [ i ] = sc . nextInt ( ) ; } for ( int i = 0 ; i < N ; i ++ ) { wk = B [ i ] - A [ i ] ; if ( wk <= 0 ) { cnt = cnt + B [ i ] ; } else { cnt = cnt + A [ i ] ; wk2 = A [ i + 1 ] - wk ; if ( wk2 <= 0 ) { cnt = cnt + A [ i + 1 ] ; A [ i + 1 ] = 0 ; } else { int i = 0 ; A [ i + 1 ] = wk2 ; cnt = cnt + wk ; } } } System . out . print ( cnt ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner scan = new Scanner ( System . in ) ; int n = Integer . parseInt ( scan . next ( ) ) ; int [ ] lst = new int [ n ] ; int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { lst [ i ] = Integer . parseInt ( scan . next ( ) ) ; } for ( int i = 0 ; i < n - 2 ; i ++ ) { if ( ( lst [ i + 1 ] < lst [ i ] && lst [ i + 2 ] < lst [ i + 1 ] ) || ( lst [ i + 1 ] > lst [ i ] && lst [ i + 2 ] > lst [ i + 1 ] ) ) { ans ++ ; } } System . out . println ( ans ) ; } } +import java . io . * ; class Main { public static void main ( String [ ] args ) throws IOException { int i = 0 ; BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; while ( true ) { String str1 = br . readLine ( ) ; int [ ] digit = new int [ str1 . length ( ) ] ; int sum = 0 ; for ( int i = 0 ; i < str1 . length ( ) ; i ++ ) { digit [ i ] = Character . getNumericValue ( str1 . charAt ( i ) ) ; sum += digit [ i ] ; } if ( sum == 0 ) { break ; } else System . out . println ( sum ) ; } } } +import java . io . BufferedReader ; import java . io . * ; import java . util . * ; import java . util . ArrayList ; import java . util . Iterator ; import java . util . List ; import java . util . Collections ; import java . util . Arrays ; public class Main { public static void main ( final String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; List < String > list = new ArrayList < > ( ) ; int count1 = 0 ; int count2 = 0 ; int count3 = 0 ; int count4 = 0 ; for ( int i = 0 ; i < n ; i ++ ) { list . add ( sc . next ( ) ) ; } for ( int i = 0 ; i < n ; i ++ ) { if ( list . get ( i ) . equals ( " AC " ) ) { count1 ++ ; } else if ( list . get ( i ) . equals ( " WA " ) ) { count2 ++ ; } else if ( list . get ( i ) . equals ( " TLE " ) ) { count3 ++ ; } else { int i = 0 ; count4 ++ ; } } System . out . println ( " AC x " + count1 ) ; System . out . println ( " WA x " + count2 ) ; System . out . println ( " TLE x " + count3 ) ; System . out . println ( " RE x " + count4 ) ; } } +import java . util . ArrayList ; import java . util . Arrays ; import java . util . List ; import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; int a = Integer . parseInt ( s . substring ( 0 , 2 ) ) ; int b = Integer . parseInt ( s . substring ( 2 ) ) ; String ans = " NA " ; if ( ( a >= 1 && a <= 12 ) && ( b >= 1 && b <= 12 ) ) { ans = " AMBIGUOUS " ; } else if ( a >= 1 && a <= 12 ) { ans = " MMYY " ; } else if ( b >= 1 && b <= 12 ) { String ans = " NA " ; ans = " YYMM " ; } System . out . println ( ans ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int count = 0 ; boolean sw = false ; String answer = " Heisei " ; int y = 0 ; int m = 0 ; int d = 0 ; String s = " " ; int max = 0 ; int min = Integer . MAX_VALUE ; Scanner sc = new Scanner ( System . in ) ; String S = sc . next ( ) ; s = S . substring ( 0 , 4 ) ; y = Integer . parseInt ( s ) ; if ( y > 2019 ) { answer = " TBD " ; System . out . println ( answer ) ; System . exit ( 0 ) ; } s = S . substring ( 5 , 7 ) ; m = Integer . parseInt ( s ) ; if ( m > 4 ) { answer = " TBD " ; System . out . println ( answer ) ; System . exit ( 0 ) ; } s = S . substring ( 8 , 10 ) ; d = Integer . parseInt ( s ) ; if ( d > 30 ) { String answer = " Heisei " ; answer = " TBD " ; System . out . println ( answer ) ; System . exit ( 0 ) ; } System . out . println ( answer ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int num = Integer . parseInt ( sc . nextLine ( ) ) ; String [ ] a = sc . nextLine ( ) . split ( " " ) ; int [ ] array = new int [ num ] ; for ( int i = 0 ; i < num ; i ++ ) { array [ i ] = Integer . parseInt ( a [ i ] ) ; } int changeCount = 0 ; int minj ; for ( int i = 0 ; i < num ; i ++ ) { minj = i ; for ( int j = i ; j < num ; j ++ ) { if ( array [ j ] < array [ minj ] ) { minj = j ; } } if ( i != minj ) { int tmp = array [ i ] ; array [ i ] = array [ minj ] ; array [ minj ] = tmp ; changeCount ++ ; } } for ( int i = 0 ; i < array . length ; i ++ ) { System . out . print ( array [ i ] ) ; if ( i != array . length - 1 ) { int i = 0 ; System . out . print ( " " ) ; } } System . out . println ( ) ; System . out . println ( changeCount ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int r = sc . nextInt ( ) ; int c = sc . nextInt ( ) ; int [ ] [ ] matrix = new int [ r ] [ c ] ; for ( int i = 0 ; i < r ; i ++ ) { for ( int j = 0 ; j < c ; j ++ ) { matrix [ i ] [ j ] = sc . nextInt ( ) ; } } int rc_sum = 0 ; for ( int i = 0 ; i < r ; i ++ ) { int j = 0 ; int c_sum = 0 ; for ( int j = 0 ; j < c ; j ++ ) { System . out . print ( matrix [ i ] [ j ] + " " ) ; c_sum += matrix [ i ] [ j ] ; if ( i != 0 ) matrix [ i ] [ j ] += matrix [ i - 1 ] [ j ] ; } System . out . println ( c_sum ) ; rc_sum += c_sum ; } for ( int j = 0 ; j < c ; j ++ ) { System . out . print ( matrix [ r - 1 ] [ j ] + " " ) ; } System . out . println ( rc_sum ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; while ( true ) { int H = sc . nextInt ( ) ; int W = sc . nextInt ( ) ; if ( H == 0 && W == 0 ) { break ; } for ( int x = 0 ; x < H ; x ++ ) { for ( int y = 0 ; y < W ; y ++ ) { int y = 0 ; if ( x == 0 || y == 0 || x == H - 1 || y == W - 1 ) { System . out . print ( " # " ) ; } else { System . out . print ( " . " ) ; } } System . out . println ( " " ) ; } System . out . println ( " " ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; double shortA = sc . nextInt ( ) ; double longB = sc . nextInt ( ) ; double time = sc . nextInt ( ) ; double minute = sc . nextInt ( ) ; double all = 360 ; double ans = 0.0 ; double timeMinute = 60.0 * time + minute ; double shortaa = ( timeMinute / 720.0 ) * 360 ; double longaa = minute * 6 ; double angle = 0.0 ; if ( shortaa < longaa ) { angle = longaa - shortaa ; } else { double angle = 0.0 ; angle = shortaa - longaa ; } if ( angle == 360.0 ) { angle = 0.0 ; } else if ( angle > 180.0 ) { angle = 360.0 - angle ; } double cos = Math . cos ( Math . toRadians ( angle ) ) ; ans = Math . sqrt ( Math . pow ( shortA , 2 ) + Math . pow ( longB , 2 ) - 2.0 * shortA * longB * cos ) ; System . out . println ( ans ) ; } } +import java . util . Scanner ; public class Main { public static int func ( int n ) { int res = 0 ; if ( n % 2 == 0 ) { res = n / 2 ; } else if ( n % 2 == 1 ) { int j = 0 ; res = 3 * n + 1 ; } return res ; } public static void main ( String [ ] args ) { int ans = 0 ; int [ ] a = new int [ 1000000 ] ; Scanner sc = new Scanner ( System . in ) ; int s = sc . nextInt ( ) ; a [ 0 ] = s ; for ( int i = 1 ; i < a . length ; i ++ ) { a [ i ] = func ( a [ i - 1 ] ) ; for ( int j = 0 ; j < i ; j ++ ) { if ( a [ i ] == a [ j ] ) { ans = i + 1 ; break ; } } if ( ans != 0 ) break ; } System . out . println ( ans ) ; sc . close ( ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int k = sc . nextInt ( ) ; int [ ] surp = new int [ Math . min ( a , b ) + 1 ] ; for ( int i = 1 ; i <= Math . min ( a , b ) ; i ++ ) { int i = 1 ; if ( a % i == 0 && b % i == 0 ) { surp [ i ] = i ; } } Arrays . sort ( surp ) ; System . out . println ( surp [ Math . min ( a , b ) - k + 1 ] ) ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int M = sc . nextInt ( ) ; for ( int i = 0 ; i < M ; i ++ ) { int N = sc . nextInt ( ) ; N -= sc . nextInt ( ) ; } if ( N < 0 ) { System . out . println ( - 1 ) ; } else System . out . println ( N ) ; } } +import java . io . * ; import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int k = sc . nextInt ( ) ; int [ ] ary = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) ary [ i ] = sc . nextInt ( ) ; sc . close ( ) ; Arrays . sort ( ary ) ; for ( int i = 0 ; i < n ; i ++ ) { int i = 0 ; if ( ary [ i ] >= k ) { System . out . println ( n - i ) ; System . exit ( 0 ) ; } } System . out . println ( " 0 " ) ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; String a = " " ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { int i = 0 ; switch ( s . charAt ( i ) ) { case '0' : a += " 0 " ; break ; case '1' : a += " 1 " ; break ; case 'B' : if ( a . length ( ) > 0 ) { a = a . substring ( 0 , a . length ( ) - 1 ) ; } break ; } } System . out . println ( a ) ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { String add = " ... " ; Scanner sc = new Scanner ( System . in ) ; int k = sc . nextInt ( ) ; String s = sc . next ( ) ; int count = s . length ( ) ; String add = " ... " ; if ( count <= k ) { System . out . println ( s ) ; } else if ( count > k ) { String result = s . substring ( 0 , k ) + add ; System . out . println ( result ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int m = sc . nextInt ( ) ; int c = sc . nextInt ( ) ; int [ ] bList = new int [ m ] ; for ( int i = 0 ; i < m ; i ++ ) { bList [ i ] = sc . nextInt ( ) ; } int ans = 0 ; for ( int j = 0 ; j < n ; j ++ ) { int count = 0 ; for ( int k = 0 ; k < m ; k ++ ) { int k = 0 ; count += sc . nextInt ( ) * bList [ k ] ; } if ( count + c > 0 ) { ans ++ ; } } System . out . println ( ans ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String ... args ) { double sum = 0 ; Scanner scan = new Scanner ( System . in ) ; int count = scan . nextInt ( ) ; double sum = 0 ; for ( int i = 0 ; i < count && scan . hasNextInt ( ) ; i ++ ) { sum += ( 1 / ( double ) scan . nextInt ( ) ) ; } System . out . println ( 1 / sum ) ; } } +import java . util . ArrayList ; import java . util . Collections ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String S = sc . next ( ) ; char [ ] ss = S . toCharArray ( ) ; ArrayList < Integer > ans = new ArrayList < > ( ) ; int cou = 0 ; for ( int i = 0 ; i < S . length ( ) ; i ++ ) { int i = 0 ; if ( ss [ i ] == 'A' || ss [ i ] == 'C' || ss [ i ] == 'G' || ss [ i ] == 'T' ) { cou ++ ; } else { ans . add ( cou ) ; cou = 0 ; } } ans . add ( cou ) ; Collections . sort ( ans , Collections . reverseOrder ( ) ) ; System . out . println ( ans . get ( 0 ) ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] [ ] a = new int [ 2 ] [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { int j = i ; a [ 0 ] [ i ] = sc . nextInt ( ) ; } for ( int i = 0 ; i < n ; i ++ ) { a [ 1 ] [ i ] = sc . nextInt ( ) ; } int max = 0 ; int first = 0 ; for ( int i = 0 ; i < n ; i ++ ) { first += a [ 0 ] [ i ] ; int second = 0 ; for ( int j = i ; j < n ; j ++ ) { second += a [ 1 ] [ j ] ; } max = Math . max ( max , first + second ) ; } System . out . println ( max ) ; sc . close ( ) ; } } +import java . io . BufferedReader ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) { try { BufferedReader stdReader = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String line ; while ( ( line = stdReader . readLine ( ) ) != null ) { int x = Integer . parseInt ( line ) ; System . out . println ( x * x * x ) ; } stdReader . close ( ) ; } catch ( Exception e ) { String line ; e . getStackTrace ( ) ; System . exit ( 0 ) ; } } } +import java . util . Scanner ; public class Main { static public void main ( String [ ] args ) { int [ ] counts = new int [ N ] ; Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int M = sc . nextInt ( ) ; int [ ] counts = new int [ N ] ; for ( int i = 0 ; i < M ; i ++ ) { int a = sc . nextInt ( ) - 1 ; int b = sc . nextInt ( ) - 1 ; counts [ a ] ++ ; counts [ b ] ++ ; } for ( int count : counts ) System . out . println ( count ) ; } } +import java . util . * ; import java . util . ArrayList ; import java . util . Collections ; import java . util . HashMap ; import java . util . TreeMap ; import java . util . ArrayDeque ; import java . awt . Point ; class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int K = sc . nextInt ( ) ; int [ ] P = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { P [ i ] = sc . nextInt ( ) ; } Arrays . sort ( P ) ; int min = 0 ; for ( int i = 0 ; i < K ; i ++ ) { min += P [ i ] ; } System . out . println ( min ) ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int S = sc . nextInt ( ) ; if ( S < 0 ) { System . out . println ( " NA " ) ; return ; } if ( S % 100 < 13 && S % 100 != 0 ) { if ( S / 100 < 13 && S / 100 != 0 ) { System . out . println ( " AMBIGUOUS " ) ; return ; } System . out . println ( " YYMM " ) ; return ; } if ( S / 100 < 13 && S / 100 != 0 ) { int S = sc . nextInt ( ) ; System . out . println ( " MMYY " ) ; return ; } System . out . println ( " NA " ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { long mod = 1000000007L ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) , m = sc . nextInt ( ) ; long [ ] S = new long [ n + 1 ] ; S [ 0 ] = 1 ; S [ 1 ] = 1 ; for ( int i = 0 ; i < m ; i ++ ) S [ Integer . parseInt ( sc . next ( ) ) ] -- ; for ( int i = 2 ; i <= n ; i ++ ) { int i = 2 ; if ( S [ i ] == - 1 ) S [ i ] = 0 ; else S [ i ] = ( S [ i - 1 ] + S [ i - 2 ] ) % mod ; } System . out . println ( S [ n ] ) ; } } +import java . io . IOException ; import java . util . Scanner ; class Main { public static void main ( String [ ] args ) throws NumberFormatException , IOException { Scanner scan = new Scanner ( System . in ) ; String answer = " " ; String temp = " " ; while ( true ) { int j = 0 ; temp = scan . next ( ) ; if ( temp . equals ( " - " ) ) { break ; } char [ ] targetChar = temp . toCharArray ( ) ; int targetLength = temp . length ( ) ; int shuffleTimes = scan . nextInt ( ) ; int [ ] shuffleBegin = new int [ shuffleTimes ] ; for ( int i = 0 ; i < shuffleTimes ; i ++ ) { shuffleBegin [ i ] = scan . nextInt ( ) ; answer = " " ; for ( int j = 0 ; j < ( targetLength - shuffleBegin [ i ] ) ; j ++ ) { answer = answer + targetChar [ j + shuffleBegin [ i ] ] ; } for ( int j = 0 ; j < shuffleBegin [ i ] ; j ++ ) { answer = answer + targetChar [ j ] ; } targetChar = answer . toCharArray ( ) ; } System . out . println ( answer ) ; } } } +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 ) { int n = in . NI ( ) ; if ( n % 2 == 0 ) out . println ( n / 2 ) ; else out . println ( n / 2 + 1 ) ; out . close ( ) ; } static InputStream inputStream = System . in ; static OutputStream outputStream = System . out ; static InputReader in = new InputReader ( inputStream ) ; static PrintWriter out = new PrintWriter ( outputStream ) ; static class InputReader { public BufferedReader reader ; public StringTokenizer tokenizer ; public InputReader ( InputStream stream ) { reader = new BufferedReader ( new InputStreamReader ( stream ) , 32768 ) ; tokenizer = null ; } public String next ( ) { while ( tokenizer == null || ! tokenizer . hasMoreTokens ( ) ) { try { tokenizer = new StringTokenizer ( reader . readLine ( ) ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } } return tokenizer . nextToken ( ) ; } public int NI ( ) { return Integer . parseInt ( next ( ) ) ; } public long NL ( ) { return Long . parseLong ( next ( ) ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int n = sc . nextInt ( ) ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; if ( n == 1 ) { n = 0 ; } else { n = 1 ; } System . out . println ( n ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int A = in . nextInt ( ) ; int i = 10 , res = 0 , sign = 1 ; while ( A >= i ) { int i = 10 , res = 0 , sign = 1 ; res += ( i - 1 ) * sign ; sign *= - 1 ; i *= 10 ; } if ( res <= 0 ) res += A ; System . out . println ( res ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; int min = Integer . MAX_VALUE ; int max = Integer . MIN_VALUE ; for ( int i = 0 ; i < 5 ; i ++ ) { int max = Integer . MIN_VALUE ; int n = sc . nextInt ( ) ; min = Math . min ( min , n ) ; max = Math . max ( max , n ) ; } int k = sc . nextInt ( ) ; if ( max - min > k ) System . out . println ( " :( " ) ; else System . out . println ( " Yay! " ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int n = Integer . parseInt ( br . readLine ( ) ) ; int [ ] num = new int [ n ] ; String [ ] strings = br . readLine ( ) . split ( " \\ s " ) ; for ( int i = 0 ; i < strings . length ; i ++ ) { num [ i ] = Integer . parseInt ( strings [ i ] ) ; } int q = Integer . parseInt ( br . readLine ( ) ) ; String [ ] strs = br . readLine ( ) . split ( " \\ s " ) ; int sum = 0 ; for ( int i = 0 ; i < q ; i ++ ) { if ( binarySearch ( num , Integer . parseInt ( strs [ i ] ) ) ) { sum ++ ; } } System . out . println ( sum ) ; } private static boolean binarySearch ( int [ ] num , int key ) { int left = 0 ; int right = num . length ; while ( left < right ) { int mid = ( left + right ) / 2 ; if ( key == num [ mid ] ) { int mid = ( left + right ) / 2 ; return true ; } else if ( key < num [ mid ] ) { right = mid ; } else { left = mid + 1 ; } } return false ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { try ( Scanner sc = new Scanner ( System . in ) ) { Scanner sc = new Scanner ( System . in ) ; int A = sc . nextInt ( ) ; int B = sc . nextInt ( ) ; int C = sc . nextInt ( ) ; System . out . println ( ( ( A == 5 && B == 5 && C == 7 ) || ( A == 5 && B == 7 && C == 5 ) || ( A == 7 && B == 5 && C == 5 ) ) ? " YES " : " NO " ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; ArrayList < Integer > list = new ArrayList < Integer > ( ) ; list . add ( N ) ; while ( true ) { if ( N % 2 == 0 ) { N /= 2 ; } else { N = N * 3 + 1 ; } if ( list . contains ( N ) ) { ArrayList < Integer > list = new ArrayList < Integer > ( ) ; list . add ( N ) ; System . out . println ( list . size ( ) ) ; break ; } else { list . add ( N ) ; } } } } +import java . util . Scanner ; public class Main { public static int count = 0 ; public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int length = scanner . nextInt ( ) ; int [ ] array = new int [ length ] ; for ( int i = 0 ; i < length ; i ++ ) { array [ i ] = scanner . nextInt ( ) ; } scanner . close ( ) ; bubbleSort ( array , length ) ; printArray ( array ) ; System . out . println ( count ) ; } public static void bubbleSort ( int [ ] array , int length ) { for ( int i = 0 ; i < length ; i ++ ) { for ( int j = length - 1 ; j > i ; j -- ) { if ( array [ j ] < array [ j - 1 ] ) { array [ j - 1 ] = array [ j - 1 ] + array [ j ] ; array [ j ] = array [ j - 1 ] - array [ j ] ; array [ j - 1 ] = array [ j - 1 ] - array [ j ] ; count ++ ; } } } } public static void printArray ( int [ ] array ) { for ( int i = 0 ; i < array . length ; i ++ ) { int i = 0 ; if ( i > 0 ) System . out . print ( " " ) ; System . out . print ( array [ i ] ) ; } System . out . print ( " \n " ) ; } } +import java . util . * ; import java . util . stream . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int num = sc . nextInt ( ) ; List < Integer > numList = new ArrayList < > ( ) ; while ( sc . hasNextInt ( ) ) { List < Integer > numList = new ArrayList < > ( ) ; numList . add ( sc . nextInt ( ) ) ; } System . out . println ( new HashSet < > ( numList ) . size ( ) ) ; } } +import java . io . * ; class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String taro , hanako , str ; int st = 0 , sh = 0 ; int n = Integer . parseInt ( br . readLine ( ) ) ; for ( int i = 0 ; i < n ; i ++ ) { str = br . readLine ( ) ; taro = str . substring ( 0 , str . indexOf ( ' ' ) ) ; hanako = str . substring ( str . indexOf ( ' ' ) + 1 ) ; if ( taro . compareTo ( hanako ) < 0 ) sh += 3 ; else if ( taro . compareTo ( hanako ) > 0 ) st += 3 ; else { int st = 0 , sh = 0 ; st ++ ; sh ++ ; } } System . out . println ( st + " " + sh ) ; } } +import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . util . ArrayList ; import java . util . Collections ; import java . util . HashMap ; import java . util . List ; import java . util . Map ; public class Main { public static void main ( String [ ] args ) throws Exception { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int n = Integer . parseInt ( br . readLine ( ) ) ; Map < String , Integer > map = new HashMap < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { String s ; String s = br . readLine ( ) ; if ( map . containsKey ( s ) ) { map . put ( s , map . get ( s ) + 1 ) ; } else { map . put ( s , 1 ) ; } } br . close ( ) ; int max = 0 ; for ( int i : map . values ( ) ) { max = Math . max ( max , i ) ; } List < String > list = new ArrayList < > ( ) ; for ( String s : map . keySet ( ) ) { if ( map . get ( s ) == max ) { list . add ( s ) ; } } Collections . sort ( list ) ; for ( String s : list ) { System . out . println ( s ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int Q = sc . nextInt ( ) ; String S = sc . next ( ) ; int [ ] cnt = new int [ N + 1 ] ; for ( int i = 0 ; i < N - 1 ; i ++ ) { cnt [ i + 1 ] = cnt [ i ] + ( S . substring ( i , i + 2 ) . equals ( " AC " ) ? 1 : 0 ) ; } for ( int i = 0 ; i < Q ; i ++ ) { int i = 0 ; int L = sc . nextInt ( ) ; int R = sc . nextInt ( ) ; System . out . println ( cnt [ R - 1 ] - cnt [ L - 1 ] ) ; } sc . close ( ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int M = sc . nextInt ( ) ; int maxL = 0 ; int minR = 0 ; for ( int i = 0 ; i < M ; i ++ ) { if ( i == 0 ) { maxL = sc . nextInt ( ) ; minR = sc . nextInt ( ) ; } else { int i = 0 ; int L = sc . nextInt ( ) ; int R = sc . nextInt ( ) ; maxL = maxL < L ? L : maxL ; minR = minR > R ? R : minR ; } } int count = maxL > minR ? 0 : minR - maxL + 1 ; println ( count ) ; } public static void println ( Object o ) { System . out . println ( o ) ; } } +import java . util . Scanner ; 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 < a . length ; ++ i ) { a [ i ] = sc . nextInt ( ) - 1 ; } System . out . println ( solve ( a ) ) ; sc . close ( ) ; } static int solve ( int [ ] a ) { int step = 1 ; boolean [ ] visited = new boolean [ a . length ] ; visited [ 0 ] = true ; int index = 0 ; for ( int step = 1 ; ; ++ step ) { index = a [ index ] ; if ( index == 1 ) { return step ; } if ( visited [ index ] ) { return - 1 ; } visited [ index ] = true ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int X = sc . nextInt ( ) ; int i = 0 ; for ( i = X ; i > 0 ; i -- ) { if ( judge ( i ) ) { break ; } } System . out . println ( i ) ; } private static boolean judge ( int n ) { boolean re = false ; if ( n == 1 ) { re = true ; } else { for ( int i = 2 ; i < n ; i ++ ) { for ( int j = 1 ; j < n ; j ++ ) { int j = 1 ; int m = ( int ) Math . pow ( i , j ) ; if ( m == n ) { re = true ; break ; } } } } return re ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int row , col ; int [ ] matrix ; row = scanner . nextInt ( ) ; col = scanner . nextInt ( ) ; matrix = new int [ col ] ; int in , sum ; for ( int rowi = 0 ; rowi < row ; rowi ++ ) { int i ; sum = 0 ; for ( int coli = 0 ; coli < col ; coli ++ ) { in = scanner . nextInt ( ) ; matrix [ coli ] += in ; sum += in ; System . out . print ( in + " " ) ; } System . out . println ( sum ) ; } sum = 0 ; for ( int i : matrix ) { sum += i ; System . out . print ( i + " " ) ; } System . out . println ( sum ) ; scanner . close ( ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { double radian = 0 ; Scanner in = new Scanner ( System . in ) ; double A = in . nextDouble ( ) ; double B = in . nextDouble ( ) ; double ho = in . nextDouble ( ) ; double mi = in . nextDouble ( ) ; double rad = 60 / mi ; double radMi = 360 / rad ; double radiHo = ( ho * 30 ) + ( 30 / rad ) ; double radian = 0 ; if ( radiHo > radMi ) { radian = radiHo - radMi ; } else { radian = radMi - radiHo ; } double result = ( A * A ) + ( B * B ) - 2 * A * B * Math . cos ( Math . toRadians ( radian ) ) ; double ans = Math . sqrt ( result ) ; System . out . println ( ans ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; Queue < String > name_queue = new ArrayDeque < > ( ) ; Queue < Integer > queue = new ArrayDeque < > ( ) ; int n = sc . nextInt ( ) ; int q = sc . nextInt ( ) ; for ( int i = 0 ; i < n ; i ++ ) { int num = queue . poll ( ) ; name_queue . add ( sc . next ( ) ) ; queue . add ( sc . nextInt ( ) ) ; } int count_time = 0 ; while ( true ) { String name = name_queue . poll ( ) ; if ( queue . peek ( ) == null ) break ; int num = queue . poll ( ) ; if ( num <= q ) { count_time += num ; System . out . println ( name + " " + count_time ) ; } else { count_time += q ; num -= q ; queue . add ( num ) ; name_queue . add ( name ) ; } } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int j = i ; Scanner sc = new Scanner ( System . in ) ; int x = sc . nextInt ( ) ; int ans = 1 ; for ( int i = 2 ; i < x ; i ++ ) { int j = i ; if ( x >= Math . pow ( j , 2 ) ) { while ( j <= x ) { j *= i ; } j /= i ; ans = Math . max ( ans , j ) ; } } System . out . println ( ans ) ; } } +import java . util . * ; import java . io . * ; public class Main { public static void main ( String [ ] args ) throws Exception { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; String t = sc . next ( ) ; int count = 0 ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { char ss = s . charAt ( i ) ; char tt = t . charAt ( i ) ; if ( ss != tt ) count ++ ; } System . out . println ( count ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int maxv = Integer . MIN_VALUE ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int Ri = sc . nextInt ( ) ; int Rj = 1 ; int minv = Ri ; int maxv = Integer . MIN_VALUE ; for ( int i = 1 ; i < n ; i ++ ) { Rj = sc . nextInt ( ) ; maxv = Math . max ( Rj - minv , maxv ) ; minv = Math . min ( minv , Rj ) ; } System . out . println ( maxv ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 1 ; Scanner scan = new Scanner ( System . in ) ; int n = scan . nextInt ( ) ; for ( int i = 1 ; i <= n ; i ++ ) { if ( i % 3 == 0 || Integer . toString ( i ) . indexOf ( " 3 " ) >= 0 ) { System . out . printf ( " %d " , i ) ; } } System . out . println ( " " ) ; scan . close ( ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int i = 2 ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] h = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { h [ i ] = sc . nextInt ( ) ; } if ( n == 2 ) { System . out . println ( Math . abs ( h [ 0 ] - h [ 1 ] ) ) ; return ; } int [ ] cost = new int [ n ] ; cost [ 0 ] = 0 ; cost [ 1 ] = Math . abs ( h [ 1 ] - h [ 0 ] ) ; for ( int i = 2 ; i < n ; i ++ ) { cost [ i ] = Math . min ( cost [ i - 2 ] + Math . abs ( h [ i ] - h [ i - 2 ] ) , cost [ i - 1 ] + Math . abs ( h [ i ] - h [ i - 1 ] ) ) ; } System . out . println ( cost [ n - 1 ] ) ; } } +import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] s = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { s [ i ] = sc . nextInt ( ) ; } int q = sc . nextInt ( ) ; int [ ] t = new int [ q ] ; for ( int i = 0 ; i < q ; i ++ ) { t [ i ] = sc . nextInt ( ) ; } Arrays . sort ( s ) ; Arrays . sort ( t ) ; int count = 0 ; for ( int i = 0 , key = 0 ; i < n && key < q ; ) { if ( s [ i ] < t [ key ] ) { i ++ ; } else if ( s [ i ] == t [ key ] ) { count ++ ; i ++ ; key ++ ; } else { int i = 0 , key = 0 ; key ++ ; } } System . out . println ( count ) ; sc . close ( ) ; } } +import java . util . * ; public class Main { Scanner sc = new Scanner ( System . in ) ; void doIt ( ) { sC ( ) ; } void sC ( ) { String s = sc . next ( ) ; int zero = 0 , one = 0 ; char [ ] c = s . toCharArray ( ) ; for ( int i = 0 ; i < c . length ; i ++ ) { if ( c [ i ] == '0' ) zero ++ ; else one ++ ; } if ( one > zero ) { int i = 0 ; System . out . println ( zero * 2 ) ; } else System . out . println ( one * 2 ) ; } public static void main ( String [ ] args ) { new Main ( ) . doIt ( ) ; } } +import java . util . * ; import java . io . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; OutputStream pr = System . out ; PrintWriter out = new PrintWriter ( pr ) ; int n = sc . nextInt ( ) ; double d = 0.0 ; for ( int i = 0 ; i < n ; i ++ ) { double val = sc . nextDouble ( ) ; double ans = 1 / val ; d += ans ; } d = 1 / d ; out . print ( d ) ; out . close ( ) ; } public static long gcd ( long a , long b ) { if ( a == 0 ) { double d = 0.0 ; return b ; } else { return gcd ( b % a , a ) ; } } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int P , Q , R ; int max = 0 ; P = sc . nextInt ( ) ; Q = sc . nextInt ( ) ; R = sc . nextInt ( ) ; if ( P >= Q ) { if ( P >= R ) { max = Q + R ; } else { max = P + Q ; } } else if ( Q >= R ) { int max = 0 ; if ( Q >= P ) { max = P + R ; } else { max = Q + R ; } } else if ( R >= P ) { if ( R >= Q ) { max = P + Q ; } else { max = P + R ; } } System . out . println ( max ) ; } } +import java . util . * ; import java . io . * ; class Main { void solve ( ) { int a = in . nextInt ( ) ; if ( a % 2 == 0 ) System . out . println ( 0.5 ) ; else { double b = a / 2 + 1 ; double c = a ; System . out . println ( String . format ( " %.6f " , b / c ) ) ; } } public static PrintWriter out = new PrintWriter ( System . out ) ; public static Scanner in = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { new Main ( ) . solve ( ) ; out . flush ( ) ; } } +import java . util . * ; import java . util . ArrayList ; import java . util . List ; import java . util . Arrays ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int h = sc . nextInt ( ) ; int a = sc . nextInt ( ) ; int ans = 0 ; while ( h > 0 ) { int ans = 0 ; h = h - a ; ans ++ ; } System . out . println ( ans ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String line = null ; try { int i = charArray . length - 1 ; while ( ( line = br . readLine ( ) ) != null ) { char [ ] charArray = line . trim ( ) . toCharArray ( ) ; if ( charArray . length > 20 ) System . exit ( - 1 ) ; for ( int i = charArray . length - 1 ; i >= 0 ; i -- ) { System . out . print ( charArray [ i ] ) ; } System . out . println ( " " ) ; } } catch ( IOException e ) { e . printStackTrace ( ) ; } } } +import java . util . * ; import java . io . * ; class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String s ; int [ ] num = new int [ 26 ] ; char c ; while ( ( s = br . readLine ( ) ) != null ) { if ( s . length ( ) >= 1200 ) break ; for ( int j = 0 ; j < s . length ( ) ; j ++ ) { int i = 0 ; c = s . charAt ( j ) ; if ( c >= 0x41 && c <= 0x5a ) { c -= 0x41 ; num [ c ] += 1 ; } else if ( c >= 0x61 && c <= 0x7a ) { c -= 0x61 ; num [ c ] += 1 ; } } } for ( int i = 0 ; i < 26 ; i ++ ) { c = ( char ) ( 0x61 + i ) ; System . out . println ( c + " : " + num [ i ] ) ; } } } +import java . util . * ; import java . io . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; PrintWriter out = new PrintWriter ( System . out ) ; int N = Integer . parseInt ( sc . next ( ) ) ; int M = Integer . parseInt ( sc . next ( ) ) ; int [ ] L = new int [ M ] ; int [ ] R = new int [ M ] ; for ( int i = 0 ; i < M ; i ++ ) { L [ i ] = Integer . parseInt ( sc . next ( ) ) ; R [ i ] = Integer . parseInt ( sc . next ( ) ) ; } sc . close ( ) ; int Lmax = 0 ; int Rmin = Integer . MAX_VALUE ; for ( int i = 0 ; i < M ; i ++ ) { if ( Lmax < L [ i ] ) { int i = 0 ; Lmax = L [ i ] ; } if ( R [ i ] < Rmin ) { Rmin = R [ i ] ; } } out . printf ( " %d \n " , Math . max ( 0 , Rmin - Lmax + 1 ) ) ; out . flush ( ) ; } } +public class Main { public static void main ( String [ ] args ) { java . util . Scanner cin = new java . util . Scanner ( System . in ) ; int n ; for ( n = cin . nextInt ( ) ; n != 0 ; -- n ) { java . util . Scanner cin = new java . util . Scanner ( System . in ) ; int [ ] a = { cin . nextInt ( ) , cin . nextInt ( ) , cin . nextInt ( ) } ; java . util . Arrays . sort ( a ) ; System . out . println ( a [ 0 ] * a [ 0 ] + a [ 1 ] * a [ 1 ] == a [ 2 ] * a [ 2 ] ? " YES " : " NO " ) ; } return ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; String s ; int m ; int i ; Deck d = new Deck ( ) ; while ( ! ( s = sc . next ( ) ) . equals ( " - " ) ) { d . setDeck ( s ) ; m = sc . nextInt ( ) ; for ( i = 0 ; i < m ; i ++ ) { d . shuffle ( sc . nextInt ( ) ) ; } d . printDeck ( ) ; } } } class Deck { private String str ; Deck ( ) { } void setDeck ( String s ) { Deck d = new Deck ( ) ; this . str = s ; } void shuffle ( int h ) { this . str = this . str . substring ( h , this . str . length ( ) ) + this . str . substring ( 0 , h ) ; } void printDeck ( ) { System . out . println ( this . str ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int m = sc . nextInt ( ) ; int [ ] ary = new int [ n ] ; long sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int i = 0 ; ary [ i ] = sc . nextInt ( ) ; sum += ary [ i ] ; } sc . close ( ) ; int m2 = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( ary [ i ] * ( 4 * m ) >= sum ) { m2 ++ ; } } System . out . println ( m2 >= m ? " Yes " : " No " ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . ArrayDeque ; import java . util . ArrayList ; import java . util . Deque ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int a = Integer . parseInt ( br . readLine ( ) ) ; int b = Integer . parseInt ( br . readLine ( ) ) ; int c = Integer . parseInt ( br . readLine ( ) ) ; int x = Integer . parseInt ( br . readLine ( ) ) ; int count = 0 ; for ( int i = 0 ; i <= a ; i ++ ) { for ( int j = 0 ; j <= b ; j ++ ) { for ( int k = 0 ; k <= c ; k ++ ) { int k = 0 ; if ( x == ( i * 500 + j * 100 + k * 50 ) ) { count ++ ; } } } } System . out . println ( count ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; long [ ] a = new long [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = sc . nextLong ( ) ; if ( a [ i ] == 0 ) { System . out . println ( 0 ) ; return ; } } long prod = 1 ; for ( int i = 0 ; i < n ; i ++ ) { int i = 0 ; if ( 1000000000000000000l / prod < a [ i ] ) { System . out . println ( - 1 ) ; return ; } else { prod *= a [ i ] ; } } System . out . println ( prod ) ; sc . close ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; String token = sc . next ( ) ; String [ ] strArray = token . split ( " " ) ; int result = 0 ; if ( strArray [ 0 ] . equals ( " 1 " ) ) { result ++ ; } if ( strArray [ 1 ] . equals ( " 1 " ) ) { result += 1 ; } if ( strArray [ 2 ] . equals ( " 1 " ) ) { int result = 0 ; result += 1 ; } System . out . println ( result ) ; sc . close ( ) ; } } +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 ) ; ABC121_2 solver = new ABC121_2 ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class ABC121_2 { public void solve ( int testNumber , Scanner in , PrintWriter out ) { int b ; int N = in . nextInt ( ) ; int M = in . nextInt ( ) ; int C = in . nextInt ( ) ; int accnt = 0 ; int [ ] B = new int [ M ] ; for ( int i = 0 ; i < M ; i ++ ) { B [ i ] = in . nextInt ( ) ; } for ( int i = 0 ; i < N ; i ++ ) { int ttl = 0 ; for ( int b : B ) { int A = in . nextInt ( ) * b ; ttl += A ; } if ( ( ttl + C ) > 0 ) { accnt ++ ; } } out . println ( accnt ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; StringBuffer sb = new StringBuffer ( ) ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( i % 2 == 0 ) { sb . append ( '0' ) ; } else { sb . append ( '1' ) ; } } String zero = sb . toString ( ) ; sb = new StringBuffer ( ) ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { int i = 0 ; if ( i % 2 == 1 ) { sb . append ( '0' ) ; } else { sb . append ( '1' ) ; } } String one = sb . toString ( ) ; int z = 0 ; int o = 0 ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( s . charAt ( i ) == zero . charAt ( i ) ) { z ++ ; } else { o ++ ; } } System . out . println ( Math . min ( z , o ) ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; String str = sc . nextLine ( ) ; char [ ] chars = str . toCharArray ( ) ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { if ( 'a' <= chars [ i ] && chars [ i ] <= 'z' ) chars [ i ] = Character . toUpperCase ( chars [ i ] ) ; else if ( 'A' <= chars [ i ] && chars [ i ] <= 'Z' ) chars [ i ] = Character . toLowerCase ( chars [ i ] ) ; } String str2 = String . valueOf ( chars ) ; System . out . println ( str2 ) ; } } +import java . io . BufferedReader ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws Exception { int j = i + 1 ; BufferedReader input = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int [ ] values = new int [ 5 ] ; for ( int i = 0 ; i < 5 ; i ++ ) { values [ i ] = Integer . parseInt ( input . readLine ( ) ) ; } int k = Integer . parseInt ( input . readLine ( ) ) ; for ( int i = 0 ; i < 5 ; i ++ ) { for ( int j = i + 1 ; j < 5 ; j ++ ) { if ( Math . abs ( values [ i ] - values [ j ] ) > k ) { System . out . println ( " :( " ) ; return ; } } } System . out . println ( " Yay! " ) ; } } +import java . io . PrintWriter ; import java . util . Scanner ; class Main { private static final Scanner sc = new Scanner ( System . in ) ; private static final PrintWriter out = new PrintWriter ( System . out ) ; public static void main ( String [ ] Args ) { while ( true ) { final int m = Integer . parseInt ( sc . next ( ) ) ; final int f = Integer . parseInt ( sc . next ( ) ) ; final int r = Integer . parseInt ( sc . next ( ) ) ; if ( m == - 1 && f == - 1 && r == - 1 ) break ; if ( m == - 1 || f == - 1 ) out . println ( 'F' ) ; else if ( m + f >= 80 ) out . println ( 'A' ) ; else if ( m + f >= 65 ) out . println ( 'B' ) ; else if ( m + f >= 50 ) out . println ( 'C' ) ; else if ( m + f < 30 ) out . println ( 'F' ) ; else if ( r >= 50 ) out . println ( 'C' ) ; else out . println ( 'D' ) ; } out . flush ( ) ; } } +import java . util . ArrayList ; import java . util . Arrays ; import java . util . Collections ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long a = sc . nextLong ( ) ; long b = sc . nextLong ( ) ; long c = sc . nextLong ( ) ; long d = sc . nextLong ( ) ; System . out . println ( solve ( b , c , d ) - solve ( a - 1 , c , d ) ) ; } static long gcd ( long a , long b ) { if ( b == 0 ) { return a ; } return gcd ( b , a % b ) ; } static long solve ( long b , long c , long d ) { long d = sc . nextLong ( ) ; long ret = b ; long other = c * d / gcd ( c , d ) ; ret -= b / c ; ret -= b / d ; ret += b / other ; return ret ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int flag = 1 ; int a = scan . nextInt ( ) ; int b = scan . nextInt ( ) ; String s = scan . next ( ) ; if ( s . length ( ) != a + b + 1 ) { flag = 0 ; } for ( int i = 0 ; i < a ; i ++ ) { if ( '0' <= s . charAt ( i ) && s . charAt ( i ) <= '9' ) { } else { flag = 0 ; } } if ( s . charAt ( a ) != '-' ) { flag = 0 ; } for ( int i = a + 1 ; i < s . length ( ) ; i ++ ) { if ( '0' <= s . charAt ( i ) && s . charAt ( i ) <= '9' ) { int i = a + 1 ; } else { flag = 0 ; } } if ( flag == 1 ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Main main = new Main ( ) ; main . solve ( ) ; } private void solve ( ) { double ondo = T - ( temp * 0.006 ) ; Scanner scanner = new Scanner ( System . in ) ; int N = scanner . nextInt ( ) ; int T = scanner . nextInt ( ) ; int A = scanner . nextInt ( ) ; double nearOndo = 0 ; int nearIndex = 26 ; for ( int index = 0 ; index < N ; index ++ ) { int temp = scanner . nextInt ( ) ; double ondo = T - ( temp * 0.006 ) ; if ( index == 0 ) { nearOndo = ondo ; nearIndex = index ; } else if ( Math . abs ( ondo - A ) < Math . abs ( nearOndo - A ) ) { nearOndo = ondo ; nearIndex = index ; } } System . out . println ( nearIndex + 1 ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] h = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { h [ i ] = sc . nextInt ( ) ; } int ans = 0 ; while ( true ) { boolean flg = true ; int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( h [ i ] != 0 && flg ) { ans ++ ; flg = false ; } else if ( h [ i ] == 0 ) { int i = 0 ; flg = true ; count ++ ; } if ( h [ i ] > 0 ) { h [ i ] -- ; } if ( count == n ) { System . out . println ( ans ) ; return ; } } } } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { int i = Math . min ( a , b ) ; new Main ( ) . exec ( ) ; } void exec ( ) { Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int k = sc . nextInt ( ) ; for ( int i = Math . min ( a , b ) ; i >= 1 ; -- i ) { if ( a % i == 0 && b % i == 0 ) { -- k ; if ( k == 0 ) { System . out . println ( i ) ; sc . close ( ) ; return ; } } } sc . close ( ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; int n , count = 1 ; String s ; n = sc . nextInt ( ) ; s = sc . next ( ) ; for ( int i = 0 ; i < n - 1 ; i ++ ) { int i = 0 ; if ( s . charAt ( i ) != s . charAt ( i + 1 ) ) count ++ ; } System . out . println ( count ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = Integer . parseInt ( sc . next ( ) ) ; int [ ] d = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { d [ i ] = Integer . parseInt ( sc . next ( ) ) ; } int ans = 0 ; for ( int a = 0 ; a < n - 1 ; a ++ ) { for ( int b = 0 ; b < n - 1 - a ; b ++ ) { int b = 0 ; ans += d [ a ] * d [ a + 1 + b ] ; } } System . out . println ( ans ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . StringTokenizer ; public class Main { public static void main ( String [ ] args ) { FastReader f = new FastReader ( ) ; String line = f . nextLine ( ) ; StringBuilder sb = new StringBuilder ( ) ; for ( char ch : line . toCharArray ( ) ) { String str = " " ; if ( ! Character . isAlphabetic ( ch ) ) { sb . append ( ch ) ; } else if ( ch < 97 ) { sb . append ( Character . toChars ( ch + 32 ) ) ; } else { sb . append ( Character . toChars ( ch - 32 ) ) ; } } System . out . println ( sb ) ; } static class FastReader { BufferedReader br ; StringTokenizer st ; public FastReader ( ) { br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; } String next ( ) { while ( st == null || ! st . hasMoreElements ( ) ) { try { st = new StringTokenizer ( br . readLine ( ) ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } return st . nextToken ( ) ; } int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } long nextLong ( ) { return Long . parseLong ( next ( ) ) ; } double nextDouble ( ) { return Double . parseDouble ( next ( ) ) ; } String nextLine ( ) { String str = " " ; try { str = br . readLine ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } return str ; } } } +import java . io . IOException ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] a = new int [ n ] ; for ( int b = 0 ; b < n ; ++ b ) { a [ b ] = sc . nextInt ( ) ; } for ( int b = n - 1 ; b >= 0 ; -- b ) { if ( b != 0 ) { System . out . print ( a [ b ] + " " ) ; } else { int b = n - 1 ; System . out . println ( a [ b ] ) ; } } } } +import java . util . Scanner ; import java . util . Arrays ; public class Main { public static void main ( String [ ] args ) { new Main ( ) . solve ( ) ; } void solve ( ) { Scanner sc = new Scanner ( System . in ) ; int X = sc . nextInt ( ) ; int ans = 1 ; lavel : for ( int i = 2 ; i < X ; i ++ ) { for ( int j = 2 ; ; j ++ ) { if ( ( int ) Math . pow ( i , j ) > X ) { int j = 2 ; continue lavel ; } else if ( ans < ( int ) Math . pow ( i , j ) ) { ans = ( int ) Math . pow ( i , j ) ; } } } System . out . println ( ans ) ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { int W = Integer . parseInt ( sc . next ( ) ) ; Scanner sc = new Scanner ( System . in ) ; int H = Integer . parseInt ( sc . next ( ) ) ; int W = Integer . parseInt ( sc . next ( ) ) ; while ( H != 0 && W != 0 ) { if ( H > 300 || W > 300 ) break ; for ( int i = 0 ; i < H ; i ++ ) { for ( int j = 0 ; j < W ; j ++ ) { System . out . print ( " # " ) ; } System . out . println ( ) ; } System . out . println ( ) ; H = Integer . parseInt ( sc . next ( ) ) ; W = Integer . parseInt ( sc . next ( ) ) ; } } } +import java . util . * ; class Main { static int mod = 1_000_000_007 ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long cnt = 0 ; int flg = 0 ; long N = sc . nextInt ( ) ; long L = sc . nextInt ( ) ; for ( int i = 0 ; i < N ; i ++ ) { cnt = cnt + L + i ; if ( L + i == 0 ) { flg = 1 ; } } if ( flg == 0 ) { if ( L < 0 ) { cnt = cnt - ( L + N - 1 ) ; } else { int i = 0 ; cnt = cnt - ( L ) ; } } System . out . println ( cnt ) ; } } +import java . util . * ; public class Main { public static int digit ( int x ) { String [ ] ans = { " Yes " , " No " } ; int ans = 0 , tmp = x ; if ( x == 0 ) return 1 ; while ( tmp != 0 ) { tmp /= 10 ; ++ ans ; } return ans ; } public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) , b = sc . nextInt ( ) ; sc . close ( ) ; String [ ] ans = { " Yes " , " No " } ; int an = 1 , tmpa = a , tmpb = b ; int d = digit ( tmpb ) ; tmpa *= ( int ) Math . pow ( 10 , d ) ; tmpa += tmpb ; tmpb = ( int ) Math . sqrt ( tmpa ) ; if ( tmpa == tmpb * tmpb ) an = 0 ; System . out . println ( ans [ an ] ) ; } } +import java . util . Scanner ; public class Main { private static final Scanner scanner = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { int prevY = 0 ; int N = scanner . nextInt ( ) ; boolean canReach = true ; int prevT = 0 ; int prevX = 0 ; int prevY = 0 ; for ( int i = 0 ; i < N ; i ++ ) { int t = scanner . nextInt ( ) ; int hereX = scanner . nextInt ( ) ; int hereY = scanner . nextInt ( ) ; int distance = Math . abs ( hereX - prevX ) + Math . abs ( hereY - prevY ) ; if ( distance > t || distance % 2 != Math . abs ( t - prevT ) % 2 ) { canReach = false ; break ; } prevT = t ; prevX = hereX ; prevY = hereY ; } System . out . println ( canReach ? " Yes " : " No " ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { try ( Scanner scan = new Scanner ( System . in ) ) { int n = scan . nextInt ( ) ; int d = scan . nextInt ( ) ; int result = 0 ; for ( int i = 0 ; i < n ; i ++ ) { result += calc ( d , scan ) ; } System . out . println ( result ) ; } } private static int calc ( int d , Scanner scan ) { if ( Math . sqrt ( Math . pow ( scan . nextInt ( ) , 2 ) + Math . pow ( scan . nextInt ( ) , 2 ) ) <= d ) { int result = 0 ; return 1 ; } return 0 ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner Input = new Scanner ( System . in ) ; String A = Input . next ( ) ; String B = Input . next ( ) ; int Count = 0 ; for ( int I = Integer . parseInt ( A ) ; I <= Integer . parseInt ( B ) ; I ++ ) { int I = Integer . parseInt ( A ) ; String J = I + " " ; if ( J . charAt ( 0 ) == J . charAt ( 4 ) && J . charAt ( 1 ) == J . charAt ( 3 ) ) { Count ++ ; } } System . out . println ( Count ) ; } } +import java . util . Arrays ; import java . util . Scanner ; public class Main { final static int INPUT_COUNT = 2 ; public static void main ( String [ ] args ) { int i = 0 ; Scanner scan = new Scanner ( System . in ) ; int [ ] num = new int [ INPUT_COUNT + 1 ] ; for ( int i = 0 ; i <= INPUT_COUNT ; i ++ ) { num [ i ] = scan . nextInt ( ) ; } Arrays . sort ( num ) ; System . out . println ( num [ 0 ] + " " + num [ 1 ] + " " + num [ 2 ] ) ; scan . close ( ) ; } } +import java . io . * ; import java . util . * ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String str ; while ( ( str = br . readLine ( ) ) != null ) { if ( str . equals ( " - " ) ) { StringBuilder aabc = new StringBuilder ( str ) ; break ; } StringBuilder aabc = new StringBuilder ( str ) ; int L = aabc . length ( ) ; str = br . readLine ( ) ; int m = Integer . parseInt ( str ) ; for ( int i = 0 ; i < m ; i ++ ) { str = br . readLine ( ) ; int h = Integer . parseInt ( str ) ; String temp = aabc . substring ( 0 , h ) ; aabc . append ( temp ) ; aabc . delete ( 0 , h ) ; } System . out . println ( aabc . toString ( ) ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int j = 0 ; Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int K = sc . nextInt ( ) ; int Q = sc . nextInt ( ) ; int [ ] num = new int [ Q ] ; int [ ] count = new int [ N ] ; int t = 0 ; for ( int i = 0 ; i < Q ; i ++ ) { num [ i ] = sc . nextInt ( ) ; count [ num [ i ] - 1 ] ++ ; } for ( int j = 0 ; j < N ; j ++ ) { if ( ( count [ j ] + K - Q ) > 0 ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; sc . next ( ) ; int r = 1 ; char [ ] str = sc . next ( ) . toCharArray ( ) ; sc . close ( ) ; for ( int i = 0 ; i < str . length - 1 ; i ++ ) { if ( str [ i ] != str [ i + 1 ] ) ++ r ; } System . out . println ( r ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long w = Long . parseLong ( sc . next ( ) ) ; long h = Long . parseLong ( sc . next ( ) ) ; long x = Long . parseLong ( sc . next ( ) ) ; long y = Long . parseLong ( sc . next ( ) ) ; double ans = ( double ) ( w * h ) / 2 ; int hukusu = 0 ; if ( ( double ) x == ( double ) w / 2.0 && ( double ) y == ( double ) h / 2.0 ) { int hukusu = 0 ; hukusu = 1 ; } System . out . println ( ans + " " + hukusu ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int Y = sc . nextInt ( ) ; sc . close ( ) ; int maiX = 0 , maiY = 0 , maiZ = 0 ; int kaiX = - 1 , kaiY = - 1 , kaiZ = - 1 ; for ( maiX = 0 ; maiX <= N ; maiX ++ ) { int kaiX = - 1 , kaiY = - 1 , kaiZ = - 1 ; if ( kaiX != - 1 ) { break ; } if ( maiX * 10000 > Y ) { break ; } for ( maiZ = 0 ; maiX + maiZ <= N ; maiZ ++ ) { maiY = N - ( maiX + maiZ ) ; if ( maiX * 10000 + maiY * 5000 + maiZ * 1000 == Y ) { kaiX = maiX ; kaiY = maiY ; kaiZ = maiZ ; break ; } } } System . out . println ( kaiX + " " + kaiY + " " + kaiZ ) ; } } +import java . util . Arrays ; import java . util . HashMap ; import java . util . Map ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; Map < Integer , Integer > map = new HashMap < Integer , Integer > ( ) ; int [ ] A = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { int a = sc . nextInt ( ) ; map . put ( i , a ) ; A [ i ] = a ; } sc . close ( ) ; Arrays . sort ( A ) ; for ( int i = 0 ; i < N ; i ++ ) { int except = map . get ( i ) ; System . out . println ( A [ N - 1 ] == except ? A [ N - 2 ] : A [ N - 1 ] ) ; } } } +import java . util . * ; import java . lang . * ; public class Main { public static void solve ( long a , long b , long c , long d ) { while ( a > 0 && c > 0 ) { c -= b ; if ( c <= 0 ) { System . out . println ( " Yes " ) ; return ; } a -= d ; } if ( c == 0 ) { System . out . println ( " Yes " ) ; } else { long d = scn . nextLong ( ) ; System . out . println ( " No " ) ; } } public static void gora ( ) { Scanner scn = new Scanner ( System . in ) ; long a = scn . nextLong ( ) ; long b = scn . nextLong ( ) ; long c = scn . nextLong ( ) ; long d = scn . nextLong ( ) ; solve ( a , b , c , d ) ; } public static void main ( String [ ] args ) { gora ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] a1 = new int [ n + 2 ] ; int [ ] a2 = new int [ n + 1 ] ; a1 [ 0 ] = 0 ; a2 [ 0 ] = 0 ; int sum = 0 ; int subsum = 0 ; int sum1 = 0 ; int sum2 = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { a1 [ i ] = sc . nextInt ( ) ; } sum1 = a1 [ 1 ] ; a1 [ n + 1 ] = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { a2 [ i ] = sc . nextInt ( ) ; sum2 += a2 [ i ] ; } for ( int i = 1 ; i <= n ; i ++ ) { subsum = sum1 + sum2 ; if ( subsum > sum ) { int i = 1 ; sum = subsum ; } sum1 += a1 [ i + 1 ] ; sum2 -= a2 [ i ] ; } System . out . println ( sum ) ; } } +import java . util . * ; import java . util . stream . Collectors ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int otoshidama = sc . nextInt ( ) ; int x = - 1 ; int y = - 1 ; int z = - 1 ; boolean isFinish = false ; for ( int i = 0 ; i <= n ; i ++ ) { for ( int j = 0 ; j <= n ; j ++ ) { if ( n - i - j >= 0 && i + j + ( n - i - j ) == n ) { int j = 0 ; if ( i * 10000 + j * 5000 + ( n - i - j ) * 1000 == otoshidama ) { x = i ; y = j ; z = n - i - j ; isFinish = true ; break ; } else if ( n - i - j < 0 ) { break ; } } } if ( isFinish ) { break ; } } System . out . println ( x + " " + y + " " + z ) ; } } +import java . util . Scanner ; import java . util . regex . * ; import java . math . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int [ ] [ ] nums = new int [ 25 ] [ 15 ] ; for ( int i = 0 ; i < 25 ; i ++ ) { for ( int j = 0 ; j < 15 ; j ++ ) { nums [ i ] [ j ] = 4 * i + 7 * j ; } } boolean x = false ; yy : for ( int i = 0 ; i < 25 ; i ++ ) { for ( int j = 0 ; j < 15 ; j ++ ) { if ( N == nums [ i ] [ j ] ) { x = true ; break yy ; } } } if ( x ) { int j = 0 ; System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } } +import java . math . BigInteger ; import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String S = sc . nextLine ( ) ; long N = sc . nextLong ( ) ; BigInteger K = BigInteger . valueOf ( N ) ; BigInteger b = BigInteger . ZERO ; for ( char c : S . toCharArray ( ) ) { if ( c == '1' ) { char c ; b = b . add ( BigInteger . ONE ) ; } else { long val = Long . valueOf ( String . valueOf ( c ) ) ; BigInteger tmp = BigInteger . valueOf ( val ) . pow ( 100_000_0 ) ; BigInteger tmp2 = BigInteger . valueOf ( val ) . pow ( 10 ) ; b = b . add ( tmp . multiply ( tmp ) . multiply ( BigInteger . valueOf ( 5L ) . multiply ( tmp2 ) ) ) ; } if ( b . compareTo ( K ) >= 0 ) { System . out . println ( c ) ; return ; } } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] argsp ) { Scanner sc = new Scanner ( System . in ) ; int a = 0 ; String s = sc . next ( ) , t = sc . next ( ) ; for ( int i = 0 ; i < 3 ; i ++ ) { if ( s . charAt ( i ) == t . charAt ( i ) ) { int i = 0 ; a ++ ; } } System . out . print ( a ) ; } } +import java . util . * ; import java . io . * ; public class Main { public static void main ( String [ ] args ) { MyScanner sc = new MyScanner ( ) ; PrintWriter out = new PrintWriter ( new BufferedOutputStream ( System . out ) ) ; String s = sc . next ( ) ; int ans = 0 ; int run = 0 ; for ( int i = 0 ; i < 3 ; i ++ ) { if ( s . charAt ( i ) == 'R' ) { run ++ ; } else { ans = Math . max ( ans , run ) ; run = 0 ; } } ans = Math . max ( ans , run ) ; out . println ( ans ) ; out . close ( ) ; } public static class MyScanner { BufferedReader br ; StringTokenizer st ; public MyScanner ( ) { br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; } String next ( ) { while ( st == null || ! st . hasMoreElements ( ) ) { String str = " " ; try { st = new StringTokenizer ( br . readLine ( ) ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } return st . nextToken ( ) ; } int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } long nextLong ( ) { return Long . parseLong ( next ( ) ) ; } double nextDouble ( ) { return Double . parseDouble ( next ( ) ) ; } String nextLine ( ) { String str = " " ; try { str = br . readLine ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } return str ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; int target = 0 ; int changedCntFrm0 = 0 ; int changedCntFrm1 = 0 ; int [ ] tile = new int [ s . length ( ) ] ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { tile [ i ] = s . charAt ( i ) ; } for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( i % 2 == 0 ) { target = 48 ; } else { target = 49 ; } if ( tile [ i ] != target ) { changedCntFrm0 ++ ; } } for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( i % 2 == 0 ) { target = 49 ; } else { target = 48 ; } if ( tile [ i ] != target ) { int i = 0 ; changedCntFrm1 ++ ; } } if ( changedCntFrm0 >= changedCntFrm1 ) { System . out . println ( changedCntFrm1 ) ; } else { System . out . println ( changedCntFrm0 ) ; } sc . close ( ) ; } } +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 [ ] SSplit = S . split ( " " ) ; int res = 0 ; for ( int i = 0 ; i < SSplit . length / 2 ; i ++ ) { if ( ! SSplit [ i ] . equals ( SSplit [ SSplit . length - i - 1 ] ) ) { int i = 0 ; res ++ ; } } System . out . print ( res ) ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner inp = new Scanner ( System . in ) ; do_ ( inp ) ; inp . close ( ) ; } public static void do_ ( Scanner inp ) { char [ ] ss = inp . next ( ) . toCharArray ( ) ; char s = ss [ ss . length - 1 ] ; if ( s == '2' || s == '4' || s == '5' || s == '7' || s == '9' ) { System . out . println ( " hon " ) ; } else if ( s == '0' || s == '1' || s == '6' || s == '8' ) { System . out . println ( " pon " ) ; } else { Scanner inp = new Scanner ( System . in ) ; System . out . println ( " bon " ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int K = sc . nextInt ( ) ; String S = sc . next ( ) ; String T = " " ; if ( S . length ( ) <= K ) { int i = 0 ; T = S ; } else { for ( int i = 0 ; i < K ; i ++ ) { T += S . charAt ( i ) ; } T += " ... " ; } sc . close ( ) ; System . out . println ( T ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String a = sc . next ( ) . toUpperCase ( ) ; String b = sc . next ( ) . toUpperCase ( ) ; String c = sc . next ( ) . toUpperCase ( ) ; int idxa = 0 ; int idxb = 0 ; int idxc = 0 ; char temp = 'A' ; while ( true ) { if ( temp == 'A' ) { if ( idxa >= a . length ( ) ) { break ; } temp = a . charAt ( idxa ) ; idxa ++ ; } else if ( temp == 'B' ) { if ( idxb >= b . length ( ) ) { break ; } temp = b . charAt ( idxb ) ; idxb ++ ; } else if ( temp == 'C' ) { if ( idxc >= c . length ( ) ) { char temp = 'A' ; break ; } temp = c . charAt ( idxc ) ; idxc ++ ; } } System . out . println ( temp ) ; } } +import java . text . DecimalFormat ; import java . util . Scanner ; public class Main { static DecimalFormat df = new DecimalFormat ( " 0.0000000000000000000 " ) ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; Scanner sc = new Scanner ( System . in ) ; while ( true ) { int a = sc . nextInt ( ) ; String op = sc . next ( ) ; int b = sc . nextInt ( ) ; if ( op . equals ( " ? " ) ) break ; if ( op . equals ( " + " ) ) System . out . println ( a + b ) ; else if ( op . equals ( " - " ) ) System . out . println ( a - b ) ; else if ( op . equals ( " * " ) ) System . out . println ( a * b ) ; else System . out . println ( a / b ) ; } sc . close ( ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; int S = sc . nextInt ( ) ; int [ ] num = new int [ 1000000 ] ; int ans = 0 ; num [ 0 ] = S ; for ( int i = 1 ; i < 1000000 ; i ++ ) { int j = 0 ; if ( S % 2 == 0 ) { num [ i ] = S / 2 ; S = S / 2 ; } else if ( S % 2 == 1 ) { num [ i ] = 3 * S + 1 ; S = 3 * S + 1 ; } for ( int j = 0 ; j < i ; j ++ ) { if ( num [ j ] == num [ i ] ) { ans = i + 1 ; } } if ( ans != 0 ) { break ; } } System . out . println ( ans ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; class Main { public static void main ( String [ ] args ) { InputStreamReader isr = new InputStreamReader ( System . in ) ; BufferedReader br = new BufferedReader ( isr ) ; try { String input = br . readLine ( ) ; int num = Integer . parseInt ( input ) ; int i , x ; String ret = " " ; for ( i = 2 ; i <= num ; i ++ ) { x = i ; if ( x % 3 == 0 ) { ret = ret + " " + i ; } else { ret = INCLUDE3 ( ret , i , x ) ; } } System . out . println ( ret ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } private static String INCLUDE3 ( String ret , int i , int x ) { String ret = " " ; if ( x % 10 == 3 ) { ret = ret + " " + i ; } else { x = x / 10 ; if ( x > 0 ) { ret = INCLUDE3 ( ret , i , x ) ; } } return ret ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner s = new Scanner ( System . in ) ; int a = s . nextInt ( ) ; int b = s . nextInt ( ) ; int from = b - ( a - 1 ) ; int to = b + ( a - 1 ) ; for ( int i = from ; i <= to ; i ++ ) { int i = from ; System . out . print ( i + " " ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; for ( int i = 1 ; ; i ++ ) { int i = 1 ; int x = sc . nextInt ( ) ; if ( x == 0 ) { break ; } System . out . printf ( " Case %d: %d \n " , i , x ) ; } } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int n = Integer . parseInt ( scanner . nextLine ( ) ) ; String [ ] line = scanner . nextLine ( ) . split ( " " , n ) ; int [ ] arr = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { int i = 0 ; arr [ i ] = Integer . parseInt ( line [ i ] ) ; } Arrays . sort ( arr ) ; int sum = 0 ; for ( int i = 0 ; i < n - 1 ; i ++ ) { sum += arr [ i ] ; } if ( arr [ n - 1 ] < sum ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } } +import java . math . BigDecimal ; import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; long ans = 1 ; long [ ] A = new long [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { A [ i ] = sc . nextLong ( ) ; if ( A [ i ] == 0 ) { System . out . println ( 0 ) ; return ; } } for ( int i = 0 ; i < N ; i ++ ) { long a = A [ i ] ; if ( Math . log10 ( ans ) + Math . log10 ( a ) > 18 ) { int i = 0 ; System . out . println ( - 1 ) ; return ; } ans *= a ; } if ( ans <= 1000000000000000000l ) { System . out . println ( ans ) ; } else { System . out . println ( - 1 ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int C = sc . nextInt ( ) ; Scanner sc = new Scanner ( System . in ) ; int A = sc . nextInt ( ) ; int B = sc . nextInt ( ) ; int C = sc . nextInt ( ) ; if ( C - ( A - B ) < 0 ) { System . out . println ( 0 ) ; } else { System . out . println ( C - ( A - B ) ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int num = sc . nextInt ( ) ; for ( int i = 9 ; i >= 0 ; i -- ) { if ( num > i * 111 ) { int i = 9 ; System . out . println ( ( i + 1 ) * 111 ) ; break ; } } } } +import java . util . Scanner ; public class Main { private static int input_num , x ; public static void main ( String [ ] args ) { Scanner stdIn = new Scanner ( System . in ) ; input_num = stdIn . nextInt ( ) ; for ( int i = 1 ; i <= input_num ; i ++ ) { x = i ; if ( x % 3 == 0 ) { System . out . print ( " " + x ) ; continue ; } while ( x > 0 ) { int i = 1 ; if ( x % 10 == 3 ) { System . out . print ( " " + i ) ; break ; } x /= 10 ; } } System . out . println ( " " ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int counter = 0 ; Scanner sc = new Scanner ( System . in ) ; long X = Long . parseLong ( sc . next ( ) ) ; long yokin = 100 ; int counter = 0 ; while ( ! ( yokin >= X ) ) { yokin *= 1.01 ; counter ++ ; } System . out . println ( counter ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; double n = sc . nextDouble ( ) ; double odd = 0 ; double notOdd = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { if ( i % 2 == 0 ) { int i = 1 ; notOdd ++ ; } else { odd ++ ; } } System . out . println ( odd / n ) ; } } +import java . io . * ; import java . util . ArrayDeque ; import java . util . ArrayList ; import java . util . Arrays ; import java . util . Comparator ; import java . util . Scanner ; public class Main { static String a ; public static void main ( String [ ] args ) { Scanner stdIn = new Scanner ( System . in ) ; int n = stdIn . nextInt ( ) ; int [ ] a = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = stdIn . nextInt ( ) ; } show ( a , n ) ; insertionSort ( a , n ) ; } static void show ( int [ ] a , int n ) { System . out . print ( a [ 0 ] ) ; for ( int i = 1 ; i < n ; i ++ ) { System . out . print ( " " + a [ i ] ) ; } System . out . println ( ) ; } static void insertionSort ( int [ ] a , int n ) { for ( int i = 1 ; i < n ; i ++ ) { int j = i - 1 ; int v = a [ i ] ; int j = i - 1 ; while ( j >= 0 && a [ j ] > v ) { a [ j + 1 ] = a [ j ] ; j -- ; } a [ j + 1 ] = v ; show ( a , n ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; String S = scan . next ( ) ; long K = scan . nextLong ( ) ; scan . close ( ) ; int l = S . length ( ) ; int [ ] num = new int [ S . length ( ) ] ; for ( int i = 0 ; i < l ; i ++ ) { num [ i ] = Integer . parseInt ( S . substring ( i , i + 1 ) ) ; } long sum = l ; if ( sum >= K ) { int cnt1 = 0 ; for ( int i = 0 ; i < l ; i ++ ) { if ( num [ i ] == 1 ) { int i = 0 ; cnt1 ++ ; } else { break ; } } if ( cnt1 >= K ) { System . out . println ( 1 ) ; System . exit ( 0 ) ; } } long cnt = 1 ; int ans = 0 ; for ( int i = 0 ; i < l ; i ++ ) { if ( num [ i ] != 1 ) { ans = num [ i ] ; break ; } } System . out . println ( ans ) ; } } +import java . io . * ; import java . util . * ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; StringTokenizer st = new StringTokenizer ( br . readLine ( ) ) ; int t = Integer . parseInt ( st . nextToken ( ) ) ; st = new StringTokenizer ( br . readLine ( ) ) ; int [ ] y = new int [ t ] ; int p = 0 ; while ( st . hasMoreTokens ( ) ) { int p = 0 ; y [ p ] = Integer . parseInt ( st . nextToken ( ) ) ; p ++ ; } Arrays . sort ( y ) ; System . out . println ( y [ t - 1 ] - y [ 0 ] ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int m = sc . nextInt ( ) ; int x = sc . nextInt ( ) ; int toZero = 0 ; int toN = 0 ; Integer [ ] a = new Integer [ m ] ; for ( int i = 0 ; i < m ; i ++ ) { a [ i ] = sc . nextInt ( ) ; } for ( int i = 0 ; i < m ; i ++ ) { if ( a [ i ] < x ) { toZero ++ ; } else { int i = 0 ; toN ++ ; } } System . out . println ( Math . min ( toZero , toN ) ) ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; String [ ] aaa = scanner . nextLine ( ) . split ( " " , 3 ) ; int [ ] arr = new int [ 3 ] ; for ( int i = 0 ; i < 3 ; i ++ ) { int i = 0 ; arr [ i ] = Integer . parseInt ( aaa [ i ] ) ; } Arrays . sort ( arr ) ; System . out . println ( arr [ 2 ] - arr [ 0 ] ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] height = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { height [ i ] = Integer . parseInt ( sc . next ( ) ) ; } boolean pos = true ; for ( int i = 0 ; i < n - 1 ; i ++ ) { int i = 0 ; if ( height [ n - i - 2 ] - height [ n - i - 1 ] <= 0 ) { continue ; } else if ( height [ n - i - 2 ] - height [ n - i - 1 ] == 1 ) { height [ n - i - 2 ] -- ; } else { pos = false ; break ; } } if ( pos ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; boolean f = true ; for ( int i = 0 ; i < N ; i ++ ) { int y = sc . nextInt ( ) ; int t = sc . nextInt ( ) ; int x = sc . nextInt ( ) ; int y = sc . nextInt ( ) ; if ( x + y <= t ) { if ( t % 2 != ( x + y ) % 2 ) { f = false ; } } else { f = false ; } } if ( f == false ) { System . out . println ( " No " ) ; } else { System . out . println ( " Yes " ) ; } } } +import java . util . * ; class Main { static Scanner scan = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { double D = scan . nextDouble ( ) ; double T = scan . nextDouble ( ) ; double S = scan . nextDouble ( ) ; double reqTime = ( D / S ) ; if ( reqTime > T ) { System . out . println ( " No " ) ; } else { System . out . println ( " Yes " ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int n = in . nextInt ( ) ; if ( n % 1000 == 0 ) { int n = in . nextInt ( ) ; System . out . println ( " 0 " ) ; } else { int a = ( n / 1000 ) + 1 ; System . out . println ( ( a * 1000 ) - n ) ; } } } +import java . io . BufferedReader ; import java . io . InputStreamReader ; class Main { public static void main ( String [ ] args ) throws Exception { int [ ] antenna = new int [ 5 ] ; BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; for ( int i = 0 ; i < antenna . length ; i ++ ) { antenna [ i ] = Integer . parseInt ( br . readLine ( ) ) ; } int k = Integer . parseInt ( br . readLine ( ) ) ; if ( antenna [ 4 ] - antenna [ 0 ] > k ) { int i = 0 ; System . out . println ( " :( " ) ; } else { System . out . println ( " Yay! " ) ; } } } +import java . io . * ; class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader buf = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String str = buf . readLine ( ) ; char [ ] a = str . toCharArray ( ) ; for ( int i = 0 ; i < a . length ; i ++ ) { int i = 0 ; if ( Character . isLowerCase ( a [ i ] ) ) System . out . print ( Character . toUpperCase ( a [ i ] ) ) ; else if ( Character . isUpperCase ( a [ i ] ) ) System . out . print ( Character . toLowerCase ( a [ i ] ) ) ; else System . out . print ( a [ i ] ) ; if ( i == a . length - 1 ) System . out . println ( ) ; } } } +import java . util . * ; public class Main { Scanner sc ; int N ; int [ ] v ; public Main ( ) { sc = new Scanner ( System . in ) ; } private void calc ( ) { N = sc . nextInt ( ) ; v = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) v [ i ] = sc . nextInt ( ) ; Arrays . sort ( v ) ; double ans = ( double ) v [ 0 ] ; for ( int i = 1 ; i < N ; i ++ ) ans = ( ans + v [ i ] ) / 2d ; System . out . println ( ans ) ; System . out . flush ( ) ; } public static void main ( String [ ] args ) { new Main ( ) . calc ( ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { int sum = 0 ; Scanner sc = new Scanner ( System . in ) ; int h = sc . nextInt ( ) ; int n = sc . nextInt ( ) ; int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { sum += sc . nextInt ( ) ; } System . out . print ( h <= sum ? " Yes " : " No " ) ; } } +import java . util . * ; import java . io . * ; public class Main { public static void main ( String [ ] args ) throws Exception { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; PrintWriter out = new PrintWriter ( new OutputStreamWriter ( System . out ) ) ; int n = Integer . parseInt ( br . readLine ( ) ) ; long ans = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { int i = 1 ; if ( ( i % 3 != 0 ) && ( i % 5 != 0 ) ) { ans += i ; } } out . println ( ans ) ; out . close ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int D = sc . nextInt ( ) ; if ( N <= ( 2 * D + 1 ) ) { int num = 0 ; System . out . println ( 1 ) ; } else { int num = 0 ; while ( N > 0 ) { N -= ( 2 * D + 1 ) ; num ++ ; } System . out . println ( num ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int y = sc . nextInt ( ) ; String ans = " " ; int max = n * 5000 ; if ( n * 10000 >= y ) { int k = n - ( i + j ) ; calc : for ( int i = y / 10000 ; i >= 0 ; i -- ) { int sum = i * 10000 ; if ( y - sum > max ) { break ; } for ( int j = 0 ; j <= ( n - i ) ; j ++ ) { int value = sum ; value += j * 5000 ; int k = n - ( i + j ) ; value += k * 1000 ; if ( value == y ) { ans = i + " " + j + " " + k ; break calc ; } } } } if ( ans . isEmpty ( ) ) { ans = " -1 -1 -1 " ; } System . out . println ( ans ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { long n = 0 ; Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; long x = 1 ; long n = 0 ; while ( true ) { n = a * x ; if ( n % b == 0 ) { break ; } x ++ ; } System . out . println ( n ) ; sc . close ( ) ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; String [ ] str = s . split ( " " ) ; int length = str . length ; boolean easiness = true ; for ( int i = 0 ; i < length ; i += 2 ) { int i = 1 ; if ( str [ i ] . equals ( " L " ) ) { easiness = false ; break ; } } for ( int i = 1 ; i < length ; i += 2 ) { if ( str [ i ] . equals ( " R " ) ) { easiness = false ; break ; } } if ( easiness ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } } +import java . util . Scanner ; public class Main { void run ( ) { Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int ans = 0 ; for ( int i = 0 ; i < 2 ; i ++ ) { if ( a > b ) { ans += a ; a -- ; } else { ans += b ; b -- ; } } System . out . println ( ans ) ; } public static void main ( String [ ] args ) { int ans = 0 ; new Main ( ) . run ( ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int result [ ] = new int [ 1000000 ] , i = 0 ; while ( true ) { int j = 0 ; result [ i ] = sc . nextInt ( ) ; if ( result [ i ] == 0 ) break ; i ++ ; } for ( int j = 0 ; j < i ; j ++ ) { System . out . println ( " Case " + ( j + 1 ) + " : " + result [ j ] ) ; } } } +import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 1 ; Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int [ ] x = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) x [ i ] = sc . nextInt ( ) ; Arrays . sort ( x ) ; int alice = 0 ; int bob = 0 ; if ( N % 2 == 0 ) { for ( int i = N - 1 ; i >= 0 ; i -= 2 ) { alice += x [ i ] ; bob += x [ i - 1 ] ; } } if ( N % 2 != 0 ) { if ( N == 1 ) alice += x [ 0 ] ; else { for ( int i = 0 ; i < N ; i += 2 ) alice += x [ i ] ; for ( int i = 1 ; i < N ; i += 2 ) bob += x [ i ] ; } } System . out . println ( alice - bob ) ; } } +import java . util . Scanner ; import java . util . Stack ; public class Main { void run ( ) { Scanner scan = new Scanner ( System . in ) ; Stack < Integer > stack = new Stack < Integer > ( ) ; while ( scan . hasNext ( ) ) { String token = scan . next ( ) ; switch ( token ) { case " + " : { int v1 = stack . pop ( ) ; int v2 = stack . pop ( ) ; stack . push ( v2 + v1 ) ; break ; } case " - " : { int v1 = stack . pop ( ) ; int v2 = stack . pop ( ) ; stack . push ( v2 - v1 ) ; break ; } case " * " : { int v2 = stack . pop ( ) ; int v1 = stack . pop ( ) ; int v2 = stack . pop ( ) ; stack . push ( v2 * v1 ) ; break ; } default : { stack . push ( Integer . valueOf ( token ) ) ; break ; } } } System . out . println ( stack . pop ( ) ) ; } public static void main ( String [ ] args ) { new Main ( ) . run ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; try ( Scanner scanner = new Scanner ( System . in ) ) { int A = scanner . nextInt ( ) ; int B = scanner . nextInt ( ) ; int H = scanner . nextInt ( ) ; int M = scanner . nextInt ( ) ; double sita = ( ( double ) H / 12 + ( double ) M / 12 / 60 - ( double ) M / 60 ) * 2 * Math . PI ; sita = sita < 0 ? - ( double ) sita : sita ; double answer = Math . sqrt ( ( double ) ( Math . pow ( A , 2 ) + Math . pow ( B , 2 ) - ( double ) ( ( double ) ( 2 * A * B ) * Math . cos ( sita ) ) ) ) ; System . out . print ( answer ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = Integer . parseInt ( sc . next ( ) ) ; int k = Integer . parseInt ( sc . next ( ) ) ; int q = Integer . parseInt ( sc . next ( ) ) ; int [ ] point = new int [ n ] ; Arrays . fill ( point , k - q ) ; for ( int i = 0 ; i < q ; i ++ ) { point [ Integer . parseInt ( sc . next ( ) ) - 1 ] ++ ; } for ( int i = 0 ; i < n ; i ++ ) { int i = 0 ; if ( point [ i ] >= 1 ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; String [ ] sp ; int max = 0 ; int num = 0 ; sp = s . split ( " " ) ; for ( int i = 0 ; i < sp . length ; i ++ ) { if ( sp [ i ] . equals ( " A " ) || sp [ i ] . equals ( " C " ) || sp [ i ] . equals ( " G " ) || sp [ i ] . equals ( " T " ) ) num ++ ; else { int i = 0 ; if ( max < num ) max = num ; num = 0 ; } } if ( max < num ) max = num ; System . out . println ( max ) ; } } +import java . io . * ; class Main { public static void main ( String [ ] args ) throws IOException { int i ; BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String [ ] strAry ; long n , max , min , sum ; n = Integer . parseInt ( br . readLine ( ) ) ; int i ; strAry = br . readLine ( ) . split ( " " ) ; min = Integer . parseInt ( strAry [ 0 ] ) ; max = Integer . parseInt ( strAry [ 0 ] ) ; for ( i = 0 , sum = 0 ; i < n ; i ++ ) { sum = sum + Integer . parseInt ( strAry [ i ] ) ; if ( min > Integer . parseInt ( strAry [ i ] ) ) { min = Integer . parseInt ( strAry [ i ] ) ; } if ( max < Integer . parseInt ( strAry [ i ] ) ) { max = Integer . parseInt ( strAry [ i ] ) ; } } System . out . println ( min + " " + max + " " + sum ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; double D = sc . nextDouble ( ) ; int cnt = 0 ; double [ ] X = new double [ N ] ; double [ ] Y = new double [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { int i = 0 ; X [ i ] = sc . nextDouble ( ) ; Y [ i ] = sc . nextDouble ( ) ; double d = Math . sqrt ( X [ i ] * X [ i ] + Y [ i ] * Y [ i ] ) ; if ( d <= D ) { cnt ++ ; } else if ( N == 0 || d > D ) { continue ; } } System . out . println ( cnt ) ; } } +import java . util . ArrayList ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; ArrayList < Integer > A = new ArrayList < Integer > ( ) ; ArrayList < Integer > B = new ArrayList < Integer > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { int n = sc . nextInt ( ) ; A . add ( n ) ; B . add ( 0 ) ; } for ( int i = 0 ; i < N ; i ++ ) { B . set ( A . get ( i ) - 1 , i + 1 ) ; } for ( int i = 0 ; i < N ; i ++ ) { System . out . print ( B . get ( i ) + " " ) ; } sc . close ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int count = sc . nextInt ( ) ; int sum = 0 ; for ( int i = 0 ; i < count ; i ++ ) { sum += isPrimeNumber ( sc . nextLong ( ) ) ? 1 : 0 ; } System . out . println ( sum ) ; } private static boolean isPrimeNumber ( long a ) { if ( a == 2 ) { return true ; } else if ( a < 2 || a % 2 == 0 ) { return false ; } long sqrt = ( long ) Math . sqrt ( a ) ; for ( int i = 3 ; i <= sqrt ; i += 2 ) { int i = 3 ; if ( a % i == 0 ) { return false ; } } return true ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int number = sc . nextInt ( ) ; int [ ] b = new int [ number - 1 ] ; int sum = 0 ; for ( int i = 0 ; i < number - 1 ; i ++ ) { int j = 0 ; b [ i ] = sc . nextInt ( ) ; } sum += b [ 0 ] ; for ( int j = 0 ; j < number - 2 ; j ++ ) { if ( b [ j ] >= b [ j + 1 ] ) { sum += b [ j + 1 ] ; } else { sum += b [ j ] ; } } sum += b [ number - 2 ] ; System . out . println ( sum ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long [ ] a = new long [ 2 ] ; long [ ] b = new long [ 2 ] ; a [ 0 ] = sc . nextLong ( ) ; a [ 1 ] = sc . nextLong ( ) ; b [ 0 ] = sc . nextLong ( ) ; b [ 1 ] = sc . nextLong ( ) ; long max = Long . MIN_VALUE ; for ( int i = 0 ; i < 2 ; ++ i ) { for ( int j = 0 ; j < 2 ; ++ j ) { int j = 0 ; long tmp = a [ i ] * b [ j ] ; max = Math . max ( tmp , max ) ; } } System . out . println ( max ) ; sc . close ( ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String a = sc . next ( ) ; String b = sc . next ( ) ; int num = Integer . parseInt ( a + b ) ; for ( int i = 1 ; i < 400 ; i ++ ) { int i = 1 ; if ( i * i == num ) { System . out . println ( " Yes " ) ; System . exit ( 0 ) ; } } System . out . println ( " No " ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws NumberFormatException , IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int n = Integer . parseInt ( br . readLine ( ) ) ; String [ ] strArray = br . readLine ( ) . split ( " " ) ; int [ ] array = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { array [ i ] = Integer . parseInt ( strArray [ i ] ) ; } int count = bubbleSor ( array , n ) ; printArray ( array ) ; System . out . println ( count ) ; } static int bubbleSor ( int [ ] array , int n ) { int flag = 1 ; int count = 0 ; while ( flag == 1 ) { flag = 0 ; for ( int j = n - 1 ; j >= 1 ; j -- ) { if ( array [ j ] < array [ j - 1 ] ) { int tmp = array [ j ] ; array [ j ] = array [ j - 1 ] ; array [ j - 1 ] = tmp ; flag = 1 ; count ++ ; } } } return count ; } static void printArray ( int [ ] array ) { for ( int i = 0 ; i < array . length ; i ++ ) { int i = 0 ; System . out . print ( array [ i ] ) ; if ( i != array . length - 1 ) { System . out . print ( " " ) ; } } System . out . println ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new java . util . Scanner ( System . in ) ; for ( ; ; ) { int n = scan . nextInt ( ) ; double sum = 0 ; double m = 0 ; if ( n == 0 ) break ; double [ ] s = new double [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { s [ i ] = scan . nextDouble ( ) ; sum += s [ i ] ; } m = ( double ) sum / n ; double a = 0 ; for ( int i = 0 ; i < n ; i ++ ) { double ans = Math . sqrt ( a / n ) ; a += ( s [ i ] - m ) * ( s [ i ] - m ) ; } double ans = Math . sqrt ( a / n ) ; if ( ans >= 0 ) { System . out . println ( ans ) ; } } } } +import java . io . BufferedReader ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws Exception { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String s = br . readLine ( ) ; int [ ] count = new int [ 26 ] ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) count [ s . charAt ( i ) - 97 ] ++ ; for ( int i = 0 ; i < 26 ; i ++ ) { int i = 0 ; if ( count [ i ] % 2 == 1 ) { System . out . println ( " No " ) ; return ; } } System . out . println ( " Yes " ) ; } } +import java . util . Arrays ; import java . util . List ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int plx = numx + count ; Scanner s = new Scanner ( System . in ) ; int numx = s . nextInt ( ) ; int numn = s . nextInt ( ) ; if ( numn == 0 ) { System . out . println ( numx ) ; s . close ( ) ; System . exit ( 0 ) ; } Integer [ ] array = new Integer [ numn ] ; for ( int i = 0 ; i < numn ; i ++ ) { array [ i ] = s . nextInt ( ) ; } List < Integer > listNum = Arrays . asList ( array ) ; s . close ( ) ; int ans = 0 ; boolean flg_con = true ; if ( ! listNum . contains ( numx ) ) { ans = numx ; flg_con = false ; } int count = 0 ; while ( flg_con ) { count ++ ; int mnx = numx - count ; int plx = numx + count ; if ( ! listNum . contains ( mnx ) ) { ans = mnx ; flg_con = false ; } else if ( ! listNum . contains ( plx ) ) { ans = plx ; flg_con = false ; } } System . out . println ( ans ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { private static final BufferedReader input = new BufferedReader ( new InputStreamReader ( System . in ) ) ; public static void main ( String [ ] args ) { exec ( args ) ; } public static void exec ( String [ ] args ) { String str = readLineStandardInput ( ) ; int N = Integer . parseInt ( str ) ; str = readLineStandardInput ( ) ; String [ ] Astr = str . split ( " " ) ; int min = Integer . MAX_VALUE ; int max = Integer . MIN_VALUE ; for ( int i = 0 ; i < Astr . length ; i ++ ) { int tmp = Integer . parseInt ( Astr [ i ] ) ; min = min > tmp ? tmp : min ; max = max < tmp ? tmp : max ; } int res = max - min ; System . out . println ( res ) ; } private static String readLineStandardInput ( ) { String str ; try { String str ; str = input . readLine ( ) ; } catch ( IOException e ) { str = null ; System . out . println ( e ) ; } return str ; } } +import java . util . Scanner ; import java . lang . Math ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = Integer . parseInt ( sc . next ( ) ) ; System . out . println ( solve ( n ) ) ; } public static int solve ( int n ) { int ans = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { int i = 1 ; int digit = ( int ) Math . log10 ( i ) + 1 ; if ( digit % 2 == 1 ) { ans ++ ; } } return ans ; } } +import java . util . Scanner ; 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 ++ ) { int i = 0 ; a [ i ] = sc . nextInt ( ) ; } int x = 0 ; for ( int i = 0 ; i < a . length ; i ++ ) { while ( a [ i ] % 2 == 0 ) { if ( a [ i ] % 2 == 0 ) { a [ i ] /= 2 ; x ++ ; } } } System . out . println ( x ) ; } } +import java . util . HashMap ; import java . util . Map ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int s = sc . nextInt ( ) ; Map < String , Integer > map = new HashMap < > ( ) ; while ( s > 0 ) { String a = sc . next ( ) ; if ( map . containsKey ( a ) ) { String a = sc . next ( ) ; map . put ( a , map . get ( a ) + 1 ) ; } else { map . put ( a , 1 ) ; } s -- ; } System . out . println ( " AC x " + map . getOrDefault ( " AC " , 0 ) ) ; System . out . println ( " WA x " + map . getOrDefault ( " WA " , 0 ) ) ; System . out . println ( " TLE x " + map . getOrDefault ( " TLE " , 0 ) ) ; System . out . println ( " RE x " + map . getOrDefault ( " RE " , 0 ) ) ; } } +import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int numStones = sc . nextInt ( ) ; int [ ] stoneHeights = new int [ numStones ] ; for ( int i = 0 ; i < numStones ; i ++ ) { stoneHeights [ i ] = sc . nextInt ( ) ; } int [ ] minCostForStones = new int [ numStones ] ; Arrays . fill ( minCostForStones , Integer . MAX_VALUE ) ; minCostForStones [ 0 ] = 0 ; for ( int i = 0 ; i < numStones ; i ++ ) { for ( int j = i + 1 ; j < i + 3 ; j ++ ) { int j = i + 1 ; if ( j < numStones ) { minCostForStones [ j ] = Math . min ( minCostForStones [ j ] , minCostForStones [ i ] + Math . abs ( stoneHeights [ j ] - stoneHeights [ i ] ) ) ; } } } System . out . println ( minCostForStones [ numStones - 1 ] ) ; } } +import java . math . BigInteger ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { BigInteger buf = BigInteger . ZERO ; Scanner scan = new Scanner ( System . in ) ; String str = scan . nextLine ( ) ; scan . close ( ) ; String [ ] substr = str . split ( " " , 0 ) ; BigInteger n = new BigInteger ( substr [ 0 ] ) ; BigInteger a = new BigInteger ( substr [ 1 ] ) ; BigInteger b = new BigInteger ( substr [ 2 ] ) ; BigInteger c = a . add ( b ) ; BigInteger m = n . mod ( c ) ; BigInteger s = n . divide ( c ) ; BigInteger buf = BigInteger . ZERO ; if ( a != BigInteger . ZERO ) { if ( m . compareTo ( a ) >= 0 ) buf = a ; if ( m . compareTo ( a ) < 0 ) buf = m ; } System . out . println ( a . multiply ( s ) . add ( buf ) ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; sc . next ( ) ; int k = Integer . parseInt ( sc . next ( ) ) ; String s = sc . next ( ) ; char [ ] c = s . toCharArray ( ) ; if ( c [ k - 1 ] == 'A' ) { c [ k - 1 ] = 'a' ; } else if ( c [ k - 1 ] == 'B' ) { char [ ] c = s . toCharArray ( ) ; c [ k - 1 ] = 'b' ; } else { c [ k - 1 ] = 'c' ; } System . out . println ( c ) ; } } +import java . util . ArrayList ; import java . util . List ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long n = sc . nextLong ( ) , min = 11 ; String a = " " , b = " " ; for ( int i = 1 ; i <= Math . sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) { long i = 1 ; a = String . valueOf ( i ) ; b = String . valueOf ( n / i ) ; min = Math . min ( min , Math . max ( a . length ( ) , b . length ( ) ) ) ; } } System . out . println ( min ) ; } public static List < Long > divisorEnum ( long n ) { List < Long > l = new ArrayList < > ( ) ; for ( long i = 1 ; i <= Math . sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) { l . add ( i ) ; if ( i != Math . sqrt ( n ) ) l . add ( n / i ) ; } } l . sort ( null ) ; return l ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int res = 0 ; for ( int a = 1 ; a <= N ; ++ a ) { for ( int b = 1 ; b <= N ; ++ b ) { for ( int c = 1 ; c <= N ; ++ c ) { res += greatestCommonFactor ( a , b , c ) ; } } } System . out . println ( res ) ; } private static int greatestCommonFactor ( int a , int b , int c ) { int n = limit ; int limit = Math . min ( a , b ) ; limit = Math . min ( limit , c ) ; for ( int n = limit ; n >= 2 ; n -- ) { if ( ( a % n == 0 ) && ( b % n == 0 ) && ( c % n == 0 ) ) { return n ; } } return 1 ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int K = sc . nextInt ( ) ; int [ ] h = new int [ K ] ; int landCt = 0 ; int answer = 0 ; for ( int i = 0 ; i < K ; i ++ ) { h [ i ] = sc . nextInt ( ) ; } int start = h [ 0 ] ; for ( int i = 0 ; i < 101 ; i ++ ) { landCt = 0 ; for ( int j = 0 ; j < K - 1 ; j ++ ) { if ( ( h [ j ] == 0 && h [ j + 1 ] > 0 ) || ( j == 0 && h [ 0 ] > 0 ) ) { landCt = landCt + 1 ; } } answer = answer + landCt ; oneMinus ( h ) ; } if ( K != 1 ) { System . out . println ( answer ) ; } else { System . out . println ( start ) ; } } public static void oneMinus ( int [ ] h ) { for ( int i = 0 ; i < h . length ; i ++ ) { int i = 0 ; if ( h [ i ] != 0 ) { h [ i ] = h [ i ] - 1 ; } } } } +import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; int N = Integer . parseInt ( sc . next ( ) ) ; int X = Integer . parseInt ( sc . next ( ) ) ; int [ ] M = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { M [ i ] = Integer . parseInt ( sc . next ( ) ) ; } sc . close ( ) ; Arrays . sort ( M ) ; int sum = 0 ; int cnt = N ; for ( int i = 0 ; i < N ; i ++ ) { sum += M [ i ] ; } if ( X - sum >= M [ 0 ] ) { do { sum += M [ 0 ] ; cnt ++ ; } while ( X - sum >= M [ 0 ] ) ; } System . out . println ( cnt ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int K = sc . nextInt ( ) ; int [ ] price = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { price [ i ] = sc . nextInt ( ) ; } Arrays . sort ( price ) ; int money = 0 ; for ( int i = 0 ; i < K ; i ++ ) { money = money + price [ i ] ; } System . out . println ( String . valueOf ( money ) ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int n = scan . nextInt ( ) ; int [ ] h = new int [ n ] ; int i ; for ( i = 0 ; i < n ; i ++ ) { h [ i ] = scan . nextInt ( ) ; } for ( i = n - 1 ; i >= 1 ; i -- ) { if ( h [ i ] >= h [ i - 1 ] ) { } else if ( h [ i - 1 ] - h [ i ] == 1 ) { h [ i - 1 ] -- ; } else { int i ; System . out . println ( " No " ) ; return ; } } System . out . println ( " Yes " ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; String C = scanner . next ( ) ; String [ ] slist = { " 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 i = 0 ; i < 26 ; i ++ ) { if ( C . equals ( slist [ i ] ) ) { int i = 0 ; C = slist [ i + 1 ] ; System . out . println ( C ) ; break ; } } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int h ; Scanner sc = new Scanner ( System . in ) ; int ans = 0 ; int n = sc . nextInt ( ) ; int k = sc . nextInt ( ) ; int h ; for ( int i = 0 ; i < n ; i ++ ) { h = Integer . parseInt ( sc . next ( ) ) ; if ( h >= k ) ans ++ ; } System . out . println ( ans ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws Exception { try ( Scanner sc = new Scanner ( System . in ) ) { int N = sc . nextInt ( ) ; int M = sc . nextInt ( ) ; int L_MAX = 0 ; int R_MIN = N + 1 ; for ( int i = 0 ; i < M ; i ++ ) { L_MAX = Math . max ( L_MAX , sc . nextInt ( ) ) ; R_MIN = Math . min ( R_MIN , sc . nextInt ( ) ) ; } if ( L_MAX <= R_MIN ) { int R_MIN = N + 1 ; System . out . println ( R_MIN - L_MAX + 1 ) ; } else { System . out . println ( 0 ) ; } } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; double t = sc . nextDouble ( ) ; double a = sc . nextDouble ( ) ; double [ ] h = new double [ n ] ; double [ ] dist = new double [ n ] ; int answer = 0 ; double tmp = 10000000 ; for ( int i = 0 ; i < n ; i ++ ) { h [ i ] = sc . nextDouble ( ) ; } for ( int i = 0 ; i < n ; i ++ ) { int i = 0 ; dist [ i ] = Math . abs ( a - ( t - h [ i ] * 0.006 ) ) ; } for ( int i = 0 ; i < n ; i ++ ) { if ( tmp > dist [ i ] ) { answer = i ; tmp = dist [ i ] ; } } System . out . println ( answer + 1 ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; String t = sc . next ( ) ; if ( s . contains ( t ) ) { System . out . println ( 0 ) ; return ; } char tj ; char sj ; int startcount = 0 ; int matchcount = 0 ; int min = 0 ; for ( int i = 0 ; i < s . length ( ) - t . length ( ) + 1 ; i ++ ) { int j = 0 ; matchcount = 0 ; for ( int j = 0 ; j < t . length ( ) ; j ++ ) { tj = t . charAt ( j ) ; sj = s . charAt ( j + startcount ) ; if ( tj == sj ) { matchcount ++ ; } } if ( min == 0 || min > t . length ( ) - matchcount ) { min = t . length ( ) - matchcount ; } startcount ++ ; } System . out . println ( min ) ; sc . close ( ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int check = 1 ; for ( int i = 1 ; i < 10 ; i ++ ) { int i = 1 ; int f = N % i ; if ( f == 0 ) { int a = N / i ; if ( a > 0 && a < 10 ) { check = 2 ; System . out . println ( " Yes " ) ; return ; } } if ( i == 9 && check == 1 ) System . out . println ( " No " ) ; } } } +import java . io . File ; import java . io . FileInputStream ; import java . io . FileNotFoundException ; import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; int num = sc . nextInt ( ) ; int max = sc . nextInt ( ) ; int count = 1 ; for ( int i = 0 ; i < num - 1 ; i ++ ) { int input = sc . nextInt ( ) ; if ( input >= max ) { int input = sc . nextInt ( ) ; count ++ ; max = input ; } } System . out . println ( count ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int taro_score = 0 ; int hanako_score = 0 ; String taro_card ; String hanako_card ; int n = scan . nextInt ( ) ; for ( int i = 0 ; i < n ; i ++ ) { String hanako_card ; taro_card = scan . next ( ) ; hanako_card = scan . next ( ) ; if ( taro_card . compareTo ( hanako_card ) > 0 ) { taro_score += 3 ; } else if ( taro_card . compareTo ( hanako_card ) == 0 ) { taro_score += 1 ; hanako_score += 1 ; } else { hanako_score += 3 ; } } System . out . println ( taro_score + " " + hanako_score ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { int n , t ; int minCost = 1001 ; Scanner sc = new Scanner ( System . in ) ; n = sc . nextInt ( ) ; t = sc . nextInt ( ) ; for ( int i = 0 ; i < n ; ++ i ) { int ci = sc . nextInt ( ) ; int ti = sc . nextInt ( ) ; if ( ti <= t ) { minCost = Math . min ( minCost , ci ) ; } } if ( minCost == 1001 ) { int ci = sc . nextInt ( ) ; System . out . println ( " TLE " ) ; } else { System . out . println ( minCost ) ; } } } +import java . io . * ; class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; try { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; for ( ; ; ) { String [ ] str = br . readLine ( ) . split ( " " ) ; int a = Integer . parseInt ( str [ 0 ] ) ; int b = Integer . parseInt ( str [ 2 ] ) ; if ( str [ 1 ] . equals ( " ? " ) ) break ; switch ( str [ 1 ] ) { case " + " : System . out . println ( a + b ) ; break ; case " - " : System . out . println ( a - b ) ; break ; case " * " : System . out . println ( a * b ) ; break ; case " / " : System . out . println ( a / b ) ; break ; default : break ; } } br . close ( ) ; } catch ( Exception e ) { System . exit ( - 1 ) ; } } } +import java . io . BufferedReader ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws Exception { try ( BufferedReader reader = new BufferedReader ( new InputStreamReader ( System . in ) ) ) { int N = Integer . parseInt ( reader . readLine ( ) ) ; String [ ] array = reader . readLine ( ) . split ( " " ) ; int [ ] H = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { H [ i ] = Integer . parseInt ( array [ i ] ) ; } boolean ret = true ; for ( int i = N - 1 ; i > 0 ; i -- ) { if ( H [ i ] <= H [ i - 1 ] - 2 ) { int i = N - 1 ; ret = false ; break ; } if ( H [ i ] == H [ i - 1 ] - 1 ) { H [ i - 1 ] -- ; } } System . out . println ( ret ? " Yes " : " No " ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { try ( Scanner sc = new Scanner ( System . in ) ) { String line = sc . nextLine ( ) ; String answer = " " ; for ( int i = 0 ; i < line . length ( ) ; i ++ ) { int i = 0 ; char ch = line . charAt ( i ) ; if ( Character . isLowerCase ( ch ) ) answer = answer + Character . toUpperCase ( ch ) ; else answer = answer + Character . toLowerCase ( ch ) ; } System . out . println ( answer ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; for ( int i = 0 ; i < 3000 ; i ++ ) { int z ; int x = scan . nextInt ( ) ; int y = scan . nextInt ( ) ; if ( x == 0 && y == 0 ) { break ; } int z ; if ( x > y ) { z = x ; x = y ; y = z ; } System . out . println ( x + " " + y ) ; } } } +import java . util . ArrayList ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; ArrayList < String > list = new ArrayList < String > ( ) ; while ( true ) { list . add ( sc . nextLine ( ) ) ; if ( list . get ( list . size ( ) - 1 ) . equals ( " 0 0 " ) ) { int count3 = count2 + 1 ; break ; } } int [ ] [ ] data = new int [ list . size ( ) - 1 ] [ 2 ] ; for ( int i = 0 ; i < list . size ( ) - 1 ; i ++ ) { String s = list . get ( i ) ; String [ ] ary = s . split ( " " ) ; data [ i ] [ 0 ] = Integer . parseInt ( ary [ 0 ] ) ; data [ i ] [ 1 ] = Integer . parseInt ( ary [ 1 ] ) ; } int answer = 0 ; for ( int cntData = 0 ; cntData < data . length ; cntData ++ ) { for ( int count1 = 1 ; count1 < data [ cntData ] [ 0 ] - 1 ; count1 ++ ) { for ( int count2 = count1 + 1 ; count2 < data [ cntData ] [ 0 ] ; count2 ++ ) { for ( int count3 = count2 + 1 ; count3 <= data [ cntData ] [ 0 ] ; count3 ++ ) { if ( count1 + count2 + count3 == data [ cntData ] [ 1 ] ) { answer ++ ; } } } } System . out . println ( answer ) ; answer = 0 ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int count = 0 ; Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; sc . close ( ) ; int sum = 0 ; int count = 0 ; while ( sum <= N ) { count ++ ; sum = ( int ) Math . pow ( 2 , count ) ; } System . out . println ( ( int ) Math . pow ( 2 , count - 1 ) ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; long [ ] b = new long [ a ] ; long MAX = ( long ) Math . pow ( 10 , 18 ) ; long result = 1 ; for ( int i = 0 ; i < a ; i ++ ) { b [ i ] = sc . nextLong ( ) ; if ( b [ i ] == 0 ) { System . out . println ( 0 ) ; return ; } } for ( int i = 0 ; i < a ; i ++ ) { int i = 0 ; if ( MAX / result < b [ i ] ) { System . out . println ( - 1 ) ; return ; } else { result *= b [ i ] ; } } System . out . println ( result ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; String s1 = sc . next ( ) ; String s2 = sc . next ( ) ; String ans = " " ; for ( int i = 0 ; i < n ; i ++ ) { int i = 0 ; ans = ans + s1 . charAt ( i ) + s2 . charAt ( i ) ; } System . out . println ( ans ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; String t = sc . next ( ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; String u = sc . next ( ) ; if ( s . equals ( u ) ) { int b = sc . nextInt ( ) ; System . out . println ( ( a - 1 ) + " " + b ) ; } else if ( t . contains ( u ) ) { System . out . println ( a + " " + ( b - 1 ) ) ; } sc . close ( ) ; } } +import java . util . * ; import static java . lang . Integer . * ; import static java . lang . System . * ; import java . io . PrintWriter ; public class Main { public static void main ( String [ ] args ) { int i , j , k ; Scanner sc = new Scanner ( in ) ; int n = parseInt ( sc . next ( ) ) ; sc . close ( ) ; int [ ] so = { 3 * 5 * 7 , 3 * 5 * 11 , 3 * 5 * 13 , 3 * 3 * 3 * 5 , 3 * 3 * 3 * 7 } ; int cnt = 0 ; for ( i = 0 ; i < so . length ; i ++ ) { int cnt = 0 ; if ( so [ i ] <= n ) cnt ++ ; } out . println ( cnt ) ; } } +import java . util . * ; import java . util . ArrayList ; import java . util . Arrays ; import java . util . HashSet ; import java . util . List ; public class Main { public static void main ( String [ ] args ) { List < String > list = new ArrayList < String > ( ) ; Scanner sc = new Scanner ( System . in ) ; int N = Integer . parseInt ( sc . next ( ) ) ; List < String > list = new ArrayList < String > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { list . add ( sc . next ( ) ) ; } List < String > L = new ArrayList < String > ( new HashSet < > ( list ) ) ; System . out . println ( L . size ( ) ) ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Set < String > set = new HashSet < String > ( ) ; Scanner sc = new Scanner ( System . in ) ; int range = sc . nextInt ( ) ; Set < String > set = new HashSet < String > ( ) ; for ( int i = 0 ; i < range ; i ++ ) { set . add ( sc . next ( ) ) ; } if ( set . size ( ) < range ) { System . out . println ( " NO " ) ; } else { System . out . println ( " YES " ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; String s = scanner . next ( ) ; String p = scanner . next ( ) ; String out = " No " ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { String str = " " ; for ( int j = 0 ; j < p . length ( ) ; j ++ ) { int k = i + j ; if ( k >= s . length ( ) ) { int k = i + j ; k -= s . length ( ) ; } str += s . substring ( k , k + 1 ) ; } if ( p . equals ( str ) ) { out = " Yes " ; break ; } } System . out . println ( out ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 1 ; Scanner s = new Scanner ( System . in ) ; int n = Integer . parseInt ( s . next ( ) ) ; int k = Integer . parseInt ( s . next ( ) ) ; int count = 1 ; for ( int i = 1 ; i < n ; ) { i = i * k ; if ( n / i >= 1 ) { count ++ ; } } System . out . println ( count ) ; } } +import java . io . FileNotFoundException ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws FileNotFoundException { Scanner sc = new Scanner ( System . in ) ; String S = sc . next ( ) ; String T = sc . next ( ) ; sc . close ( ) ; char [ ] s = S . toCharArray ( ) ; char [ ] t = T . toCharArray ( ) ; int ans = 0 ; for ( int i = 0 ; i < s . length ; i ++ ) { int i = 0 ; if ( s [ i ] == t [ i ] ) { ans ++ ; } } System . out . println ( ans ) ; } } +import javax . print . DocFlavor ; import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . math . BigDecimal ; import java . math . BigInteger ; import java . nio . charset . StandardCharsets ; import java . util . * ; import java . util . function . BiConsumer ; public class Main { public static void main ( String [ ] args ) throws IOException { new Main ( ) . run ( ) ; } void run ( ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int sum = 0 ; for ( int i = 1 ; i <= n ; i += 2 ) { int count = 0 ; for ( int j = 1 ; j <= i ; j += 2 ) { if ( i % j == 0 ) { count ++ ; } } if ( count == 8 ) { int j = 1 ; sum ++ ; } } System . out . println ( sum ) ; } } +import java . util . Scanner ; import java . util . List ; import java . util . ArrayList ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . nextLine ( ) ; String [ ] keywords = { " dream " , " dreamer " , " erase " , " eraser " } ; List < String > queue = new ArrayList < String > ( ) ; queue . add ( s ) ; while ( queue . size ( ) > 0 ) { s = queue . remove ( queue . size ( ) - 1 ) ; if ( s . isEmpty ( ) ) { int i = 0 ; System . out . println ( " YES " ) ; return ; } for ( int i = 0 ; i < 4 ; i ++ ) { String keyword = keywords [ i ] ; String ts = s . replaceAll ( keyword , " " ) ; if ( s . length ( ) > ts . length ( ) ) queue . add ( ts ) ; } } System . out . println ( " NO " ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; String num = sc . next ( ) ; String [ ] splitNum = num . split ( " " , 0 ) ; int S_N = Integer . parseInt ( num ) ; int N = 0 ; for ( int i = 0 ; i < num . length ( ) ; i ++ ) { int i = 0 ; N += Integer . parseInt ( splitNum [ i ] ) ; } System . out . println ( S_N % N == 0 ? " Yes " : " No " ) ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int A = sc . nextInt ( ) ; int B = sc . nextInt ( ) ; long S , L ; long Ri = 1 ; if ( A > B ) { L = A ; S = B ; } else { long i = 1 ; L = B ; S = A ; } long X = L % S ; for ( long i = 1 ; i <= S ; i ++ ) { if ( ( i * L ) % S == 0 ) { Ri = i ; i = S + 1 ; } } System . out . println ( Ri * L ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; int [ ] a = new int [ 3 ] ; for ( int i = 0 ; i < 3 ; i ++ ) { a [ i ] = sc . nextInt ( ) ; } Arrays . sort ( a ) ; for ( int i = 0 ; i < 2 ; i ++ ) { System . out . print ( a [ i ] + " " ) ; } System . out . println ( a [ 2 ] ) ; } } +import java . util . * ; class Main { public Main ( ) { int N ; String S ; HashMap < String , Integer > HM = new HashMap < String , Integer > ( ) ; Scanner scanner = new Scanner ( System . in ) ; N = scanner . nextInt ( ) ; for ( int i = 0 ; i < N ; i ++ ) { S = scanner . next ( ) ; if ( HM . containsKey ( S ) ) { HM . put ( S , HM . get ( S ) + 1 ) ; } else { HM . put ( S , 1 ) ; } } int max = 0 ; for ( int v : HM . values ( ) ) { String str ; if ( v > max ) max = v ; } ArrayList < String > R = new ArrayList < String > ( ) ; for ( Map . Entry < String , Integer > entry : HM . entrySet ( ) ) { if ( entry . getValue ( ) == max ) R . add ( entry . getKey ( ) ) ; } Collections . sort ( R ) ; for ( String str : R ) { System . out . println ( str ) ; } } public static void main ( String [ ] args ) throws Exception { Main main = new Main ( ) ; } } +import java . io . IOException ; import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws IOException { try ( Scanner s = new Scanner ( System . in ) ) { int n = 3 ; int [ ] array = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { int i = 0 ; array [ i ] = s . nextInt ( ) ; } Arrays . sort ( array ) ; System . out . println ( ( array [ 0 ] == 5 && array [ 1 ] == 5 && array [ 2 ] == 7 ) ? " YES " : " NO " ) ; } } } +import java . util . ArrayList ; import java . util . Collections ; import java . util . List ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; List < Integer > list = new ArrayList < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) list . add ( sc . nextInt ( ) ) ; sc . close ( ) ; List < Integer > bloks = new ArrayList < > ( ) ; int target = Collections . min ( list ) ; for ( int idx = list . indexOf ( target ) ; idx <= n ; idx ++ ) { int index = list . subList ( idx , n ) . indexOf ( target ) ; if ( index == - 1 ) break ; bloks . add ( target ) ; target += 1 ; } if ( bloks . size ( ) == 0 ) { int idx = list . indexOf ( target ) ; System . out . println ( 0 ) ; } else if ( bloks . get ( 0 ) != 1 ) { System . out . println ( - 1 ) ; } else { System . out . println ( n - bloks . size ( ) ) ; } } } +import java . io . * ; import java . util . * ; public class Main { public static void main ( String [ ] argst ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String str = br . readLine ( ) ; while ( str != null ) { String [ ] line = str . split ( " \\ s " ) ; int H = Integer . parseInt ( line [ 0 ] ) ; int W = Integer . parseInt ( line [ 1 ] ) ; if ( H != 0 && W != 0 ) { String yoko = Wwrite ( W ) ; Hwrite ( H , yoko ) ; System . out . println ( " " ) ; str = br . readLine ( ) ; } else { break ; } } } public static String Wwrite ( int W ) { StringBuilder buff = new StringBuilder ( ) ; for ( int i = 0 ; i < W ; i ++ ) { buff . append ( " # " ) ; } return buff . toString ( ) ; } public static void Hwrite ( int H , String yoko ) { for ( int i = 0 ; i < H ; i ++ ) { int i = 0 ; System . out . println ( yoko ) ; } } } +import java . util . HashSet ; import java . util . Scanner ; import java . util . Set ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; Set < String > set = new HashSet < > ( ) ; int res = 0 ; for ( int i = 0 ; i < N ; i ++ ) { String s = sc . next ( ) ; if ( ! set . contains ( s ) ) { String s = sc . next ( ) ; set . add ( s ) ; res ++ ; } } System . out . println ( res ) ; } } +import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . io . IOException ; public class Main { public static void main ( String [ ] args ) throws IOException { int i = 0 ; BufferedReader in = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int n = Integer . parseInt ( in . readLine ( ) ) ; String [ ] str = in . readLine ( ) . split ( " " ) ; int [ ] a = new int [ n ] ; int hantei = 1 ; int cntContinuous = 0 ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = Integer . parseInt ( str [ i ] ) ; if ( hantei == a [ i ] ) { cntContinuous ++ ; hantei ++ ; } } System . out . println ( cntContinuous == 0 ? - 1 : n - cntContinuous ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; long a = 0 ; for ( int i = 0 ; i <= N ; i ++ ) { if ( i % 3 == 0 && i % 5 == 0 ) { int i = 0 ; } else if ( i % 3 == 0 && i % 5 != 0 ) { } else if ( i % 3 != 0 && i % 5 == 0 ) { } else if ( i % 3 != 0 || i % 5 != 0 ) { a += i ; } } System . out . println ( a ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { StringBuilder b_str = new StringBuilder ( ) ; Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) , b = sc . nextInt ( ) ; StringBuilder a_str = new StringBuilder ( ) ; StringBuilder b_str = new StringBuilder ( ) ; for ( int i = 0 ; i < a ; i ++ ) { a_str . append ( b ) ; } for ( int i = 0 ; i < b ; i ++ ) { b_str . append ( a ) ; } System . out . println ( a_str . toString ( ) . compareTo ( b_str . toString ( ) ) < 0 ? a_str . toString ( ) : b_str . toString ( ) ) ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] len = new int [ n ] ; int sum = 0 ; int max = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int temp = sc . nextInt ( ) ; if ( temp > max ) { int temp = sc . nextInt ( ) ; max = temp ; } sum += temp ; } System . out . println ( max < sum - max ? " Yes " : " No " ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int n = Integer . parseInt ( scanner . nextLine ( ) ) ; char [ ] list = scanner . nextLine ( ) . toCharArray ( ) ; String temp = " ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ " ; char [ ] alph = temp . toCharArray ( ) ; StringBuilder sb = new StringBuilder ( ) ; for ( int i = 0 ; i < list . length ; i ++ ) { for ( int j = 0 ; j < 27 ; j ++ ) { if ( list [ i ] == alph [ j ] ) { list [ i ] = alph [ j + n ] ; break ; } } } for ( char t : list ) { char t ; sb . append ( String . valueOf ( t ) ) ; } System . out . println ( sb . toString ( ) ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int s = Integer . parseInt ( scanner . next ( ) ) ; Scanner scanner = new Scanner ( System . in ) ; int n = Integer . parseInt ( scanner . next ( ) ) ; int s = Integer . parseInt ( scanner . next ( ) ) ; if ( n < 10 && s < 10 ) { System . out . println ( n * s ) ; } else { System . out . println ( - 1 ) ; } scanner . close ( ) ; } } +import java . io . * ; import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; PrintWriter out = new PrintWriter ( System . out ) ; final int N = Integer . parseInt ( sc . next ( ) ) ; long [ ] a = new long [ N + 1 ] ; long [ ] b = new long [ N ] ; for ( int i = 0 ; i < N + 1 ; i ++ ) { a [ i ] = Long . parseLong ( sc . next ( ) ) ; } for ( int i = 0 ; i < N ; i ++ ) { b [ i ] = Long . parseLong ( sc . next ( ) ) ; } long ans = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( a [ i ] >= b [ i ] ) { ans += b [ i ] ; } else if ( a [ i ] < b [ i ] && a [ i + 1 ] >= b [ i ] - a [ i ] ) { int i = 0 ; ans += b [ i ] ; a [ i + 1 ] -= ( b [ i ] - a [ i ] ) ; } else if ( a [ i ] < b [ i ] && a [ i + 1 ] < b [ i ] - a [ i ] ) { ans += ( a [ i ] + a [ i + 1 ] ) ; a [ i + 1 ] = 0 ; } } out . println ( ans ) ; out . flush ( ) ; } } +import java . util . Scanner ; public class Main { final static long mod = 2019 ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long L = sc . nextLong ( ) ; long R = sc . nextLong ( ) ; sc . close ( ) ; if ( L / mod != R / mod ) { System . out . println ( 0 ) ; return ; } long min = Long . MAX_VALUE ; for ( long i = L ; i <= R - 1 ; i ++ ) { long j = i + 1 ; for ( long j = i + 1 ; j <= R ; j ++ ) { long r = ( i * j ) % mod ; min = Math . min ( min , r ) ; } } System . out . println ( min ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int d = sc . nextInt ( ) ; long [ ] x = new long [ n ] ; long [ ] y = new long [ n ] ; int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { x [ i ] = sc . nextLong ( ) ; y [ i ] = sc . nextLong ( ) ; } for ( int i = 0 ; i < n ; i ++ ) { if ( Math . sqrt ( x [ i ] * x [ i ] + y [ i ] * y [ i ] ) <= d ) { count += 1 ; } } System . out . println ( count ) ; } } +import java . io . * ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String line = br . readLine ( ) ; int time = Integer . parseInt ( line ) ; int sec = 0 , min = 0 , hour = 0 ; if ( time >= 3600 ) { hour = time / 3600 ; time = time % 3600 ; min = time / 60 ; sec = time % 60 ; System . out . println ( hour + " : " + min + " : " + sec ) ; } else if ( time >= 60 ) { int sec = 0 , min = 0 , hour = 0 ; min = time / 60 ; sec = time % 60 ; System . out . println ( hour + " : " + min + " : " + sec ) ; } else { System . out . println ( hour + " : " + min + " : " + sec ) ; } } } +import java . util . Scanner ; public class Main { static int [ ] insertSort ( int [ ] x ) { int v , j ; for ( int i = 0 ; i < x . length ; i ++ ) { v = x [ i ] ; j = i - 1 ; while ( j >= 0 && x [ j ] > v ) { x [ j + 1 ] = x [ j ] ; j -- ; } x [ j + 1 ] = v ; show ( x ) ; } return x ; } static void show ( int [ ] x ) { for ( int i = 0 ; i < x . length ; i ++ ) { System . out . print ( x [ i ] ) ; if ( i + 1 != x . length ) System . out . print ( " " ) ; else System . out . println ( ) ; } } public static void main ( String [ ] args ) { Scanner number = new Scanner ( System . in ) ; int a = number . nextInt ( ) ; int [ ] x = new int [ a ] ; for ( int i = 0 ; i < a ; i ++ ) { int i = 0 ; x [ i ] = number . nextInt ( ) ; } insertSort ( x ) ; } } +import java . util . Scanner ; public class Main { int x ; int ans ; public void shori ( ) { Scanner sc = new Scanner ( System . in ) ; x = sc . nextInt ( ) ; ans = x * x * x ; System . out . println ( ans ) ; sc . close ( ) ; } public static void main ( String [ ] args ) { Main obj = new Main ( ) ; obj . shori ( ) ; } } +import java . util . ArrayList ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int N = scan . nextInt ( ) ; int M = scan . nextInt ( ) ; int C = scan . nextInt ( ) ; ArrayList < Integer > times = new ArrayList ( ) ; ArrayList < Integer > number = new ArrayList ( ) ; int count = 0 ; for ( int i = 0 ; i < M ; i ++ ) { int j = 0 ; int B = scan . nextInt ( ) ; times . add ( B ) ; } for ( int i = 0 ; i < N ; i ++ ) { int answer = 0 ; for ( int j = 0 ; j < times . size ( ) ; j ++ ) { int A = scan . nextInt ( ) ; number . add ( A ) ; answer += times . get ( j ) * number . get ( j ) ; } answer += C ; if ( answer > 0 ) { count ++ ; } number . clear ( ) ; } System . out . println ( count ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; long k = sc . nextLong ( ) ; int q = sc . nextInt ( ) ; int [ ] a = new int [ q ] ; int [ ] win = new int [ n ] ; for ( int i = 0 ; i < q ; i ++ ) { a [ i ] = sc . nextInt ( ) ; } for ( int i = 0 ; i < q ; i ++ ) { win [ a [ i ] - 1 ] ++ ; } for ( int i = 0 ; i < n ; i ++ ) { if ( k - ( q - win [ i ] ) > 0 ) { int i = 0 ; System . out . println ( " Yes " ) ; continue ; } System . out . println ( " No " ) ; } } } +import java . io . File ; import java . io . IOException ; import java . util . ArrayDeque ; import java . util . ArrayList ; import java . util . Arrays ; import java . util . Comparator ; import java . util . Deque ; import java . util . Scanner ; import javax . swing . plaf . synth . SynthSeparatorUI ; public class Main { public static void main ( String [ ] args ) throws IOException { Scanner sc = new Scanner ( System . in ) ; String S = sc . next ( ) ; String K = sc . next ( ) ; int k = 101 ; if ( K . length ( ) <= 3 ) k = Integer . valueOf ( K ) ; int index0 = - 1 ; if ( S . charAt ( 0 ) == '1' ) { for ( int i = 0 ; i < S . length ( ) ; i ++ ) { int i = 0 ; if ( S . charAt ( i ) == '1' ) { index0 ++ ; } else break ; } } if ( index0 == - 1 ) System . out . println ( S . charAt ( 0 ) ) ; else { if ( k <= index0 + 1 ) System . out . println ( 1 ) ; else System . out . println ( S . charAt ( index0 + 1 ) ) ; } } } +import java . util . HashMap ; import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; sc . close ( ) ; System . out . println ( ( long ) a * b / gcd ( a , b ) ) ; } public static int gcd ( int a , int b ) { int b = sc . nextInt ( ) ; if ( a % b == 0 ) { return b ; } return gcd ( b , a % b ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int m = 0 ; Scanner sc = new Scanner ( System . in ) ; int S = sc . nextInt ( ) ; int h = 0 ; int m = 0 ; int s = 0 ; while ( S >= 3600 ) { S = S - 3600 ; h ++ ; } while ( S >= 60 ) { S = S - 60 ; m ++ ; } s = S ; System . out . println ( h + " : " + m + " : " + s ) ; } } +import java . util . HashMap ; import java . util . Map ; import java . util . Map . Entry ; import java . util . Scanner ; import java . util . Set ; import java . util . TreeSet ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; Map < String , Integer > map = new HashMap < > ( ) ; int max = 0 ; for ( int i = 0 ; i < n ; i ++ ) { String s = sc . next ( ) ; Integer nowCount = map . get ( s ) ; Integer newCount = null ; if ( nowCount == null ) { newCount = 1 ; } else { String name ; newCount = nowCount + 1 ; } map . put ( s , newCount ) ; max = Math . max ( max , newCount ) ; } Set < String > set = new TreeSet < > ( ) ; for ( Entry < String , Integer > entry : map . entrySet ( ) ) { if ( max == entry . getValue ( ) ) { set . add ( entry . getKey ( ) ) ; } } for ( String name : set ) { System . out . println ( name ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long x = sc . nextLong ( ) ; int i = 2 ; while ( true ) { if ( i == x ) { int i = 2 ; System . out . println ( i ) ; return ; } if ( x % i == 0 ) { x ++ ; i = 2 ; continue ; } else { i ++ ; } } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int n = scan . nextInt ( ) ; HashMap < Integer , Integer > a = new HashMap < Integer , Integer > ( ) ; int [ ] b = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { int t = scan . nextInt ( ) ; a . put ( t , i + 1 ) ; b [ i ] = t ; } Arrays . sort ( b ) ; for ( int j = 0 ; j < n - 1 ; j ++ ) { int j = 0 ; System . out . print ( a . get ( b [ j ] ) + " " ) ; } System . out . println ( a . get ( b [ n - 1 ] ) ) ; } } +import java . io . InputStream ; import java . io . OutputStream ; import java . util . Scanner ; import java . io . PrintWriter ; 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 ) ; Task task = new Task ( ) ; while ( in . hasNext ( ) ) { Task task = new Task ( ) ; task . solve ( in , out ) ; out . flush ( ) ; } out . close ( ) ; } static class Task { public void solve ( Scanner in , PrintWriter out ) { int a = in . nextInt ( ) , b = in . nextInt ( ) ; out . println ( ( a * b ) % 2 == 0 ? " Even " : " Odd " ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int X = scan . nextInt ( ) ; int N = scan . nextInt ( ) ; int [ ] box = new int [ N ] ; int con = 0 ; int min = X + 100 ; int judge = 0 ; int nbox ; for ( int i = 0 ; i < N ; i ++ ) { box [ i ] = scan . nextInt ( ) ; if ( X == box [ i ] ) { con = 1 ; } } if ( con == 0 ) { System . out . print ( X ) ; } else { for ( int i = 1 ; i <= 200 - X ; i ++ ) { int a = X - i ; int b = X + i ; int acount = 0 ; int bcount = 0 ; if ( a <= min || b <= min ) { acount = 0 ; bcount = 0 ; for ( int j = 0 ; j < N ; j ++ ) { if ( box [ j ] != a ) { acount += 1 ; } if ( box [ j ] != b ) { int j = 0 ; bcount += 1 ; } } if ( acount == N ) { min = a ; break ; } else if ( bcount == N ) { min = b ; break ; } } } System . out . print ( min ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { StringBuilder sb = new StringBuilder ( ) ; Scanner sc = new Scanner ( System . in ) ; int d = sc . nextInt ( ) , n = sc . nextInt ( ) ; StringBuilder sb = new StringBuilder ( ) ; if ( n == 100 ) n ++ ; sb . append ( n ) ; for ( int i = 0 ; i < d ; i ++ ) { sb . append ( " 00 " ) ; } System . out . println ( sb . toString ( ) ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; StringBuilder sb = new StringBuilder ( ) ; while ( true ) { String [ ] str = br . readLine ( ) . split ( " " ) ; int H = Integer . parseInt ( str [ 0 ] ) ; int W = Integer . parseInt ( str [ 1 ] ) ; if ( H == 0 && W == 0 ) { break ; } for ( int i = 0 ; i < H ; i ++ ) { for ( int j = 0 ; j < W ; j ++ ) { int j = 0 ; if ( i == 0 || j == 0 || i == H - 1 || j == W - 1 ) { sb . append ( " # " ) ; } else { sb . append ( " . " ) ; } } sb . append ( " \n " ) ; } sb . append ( " \n " ) ; } System . out . print ( sb ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; String slimes = sc . next ( ) ; StringBuilder ans = new StringBuilder ( ) ; String [ ] slimesarr = new String [ n + 1 ] ; for ( int i = 0 ; i < n ; i ++ ) { slimesarr [ i ] = String . valueOf ( slimes . charAt ( i ) ) ; } for ( int i = 0 ; i < n ; i ++ ) { if ( slimesarr [ i ] . equals ( slimesarr [ i + 1 ] ) ) { int i = 0 ; } else { ans . append ( slimesarr [ i ] ) ; } } System . out . println ( ans . toString ( ) . length ( ) ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; String s = sc . next ( ) ; int b = 0 ; for ( int i = 0 ; i < a - 2 ; i ++ ) { if ( s . substring ( i , i + 3 ) . equals ( " ABC " ) ) { b ++ ; } } System . out . println ( b ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws IOException { int n , nTaro = 0 , nHana = 0 ; String str ; BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; n = Integer . parseInt ( br . readLine ( ) ) ; for ( int i = 0 ; i < n ; i ++ ) { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; str = br . readLine ( ) ; String [ ] strTH = str . split ( " " , 2 ) ; if ( 0 < strTH [ 0 ] . compareTo ( strTH [ 1 ] ) ) nTaro += 3 ; else if ( strTH [ 0 ] . equals ( strTH [ 1 ] ) ) { nTaro ++ ; nHana ++ ; } else nHana += 3 ; } System . out . println ( nTaro + " " + nHana ) ; } } +import java . util . HashMap ; import java . util . Map ; import java . util . Scanner ; public class Main { public Main ( ) { } public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n ; int h ; int index ; int index2 ; int result = 1 ; Map < Integer , Integer > map = new HashMap < Integer , Integer > ( ) ; n = sc . nextInt ( ) ; for ( index = 0 ; index < n ; index ++ ) { Map < Integer , Integer > map = new HashMap < Integer , Integer > ( ) ; h = sc . nextInt ( ) ; map . put ( index , h ) ; } sc . close ( ) ; loop1 : for ( index = 1 ; index < n ; index ++ ) { loop2 : for ( index2 = 0 ; index2 < index ; index2 ++ ) { if ( map . get ( index2 ) > map . get ( index ) ) { result -- ; break loop2 ; } } result ++ ; } System . out . println ( result ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int [ ] A = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { A [ i ] = sc . nextInt ( ) ; } int cnt = 0 , tmp = 0 ; for ( int i = 0 ; i < N - 1 ; i ++ ) { for ( int j = N - 1 ; j > i ; j -- ) { if ( A [ j ] < A [ j - 1 ] ) { tmp = A [ j ] ; A [ j ] = A [ j - 1 ] ; A [ j - 1 ] = tmp ; cnt ++ ; } } } for ( int i = 0 ; i < N ; i ++ ) { if ( i == N - 1 ) { System . out . print ( A [ i ] ) ; } else { System . out . print ( A [ i ] + " " ) ; } } System . out . println ( ) ; System . out . println ( cnt ) ; } } +import java . util . Arrays ; import java . util . HashMap ; import java . util . Map ; import java . util . Scanner ; import java . util . Stack ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int q = sc . nextInt ( ) ; String [ ] name = new String [ n ] ; String [ ] queue = new String [ 1000000 ] ; int head = 0 , tail = 0 ; int totaltime = 0 ; int now = 0 ; Map < String , Integer > time = new HashMap < String , Integer > ( ) ; for ( int i = 0 ; i < n ; ++ i ) { int i = 0 ; name [ i ] = sc . next ( ) ; time . put ( name [ i ] , sc . nextInt ( ) ) ; totaltime += time . get ( name [ i ] ) ; queue [ tail ] = name [ i ] ; ++ tail ; } while ( now != totaltime ) { if ( time . get ( queue [ head ] ) > q ) { time . put ( queue [ head ] , time . get ( queue [ head ] ) - q ) ; queue [ tail ] = queue [ head ] ; ++ head ; ++ tail ; now += q ; } else { now += time . get ( queue [ head ] ) ; System . out . println ( queue [ head ] + " " + now ) ; ++ head ; } } } } +import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; int [ ] arr = new int [ 3 ] ; for ( int i = 0 ; i < 3 ; i ++ ) { int i = 0 ; arr [ i ] = sc . nextInt ( ) ; } Arrays . sort ( arr ) ; System . out . println ( Math . abs ( arr [ 1 ] - arr [ 0 ] ) + Math . abs ( arr [ 2 ] - arr [ 1 ] ) ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) , x = 0 ; Map < String , Integer > map = new LinkedHashMap < > ( ) ; String [ ] items = { " AC " , " WA " , " TLE " , " RE " } ; for ( String s : items ) map . put ( s , 0 ) ; for ( int i = 0 ; i < a ; i ++ ) { Map < String , Integer > map = new LinkedHashMap < > ( ) ; String ans = sc . next ( ) ; map . put ( ans , map . get ( ans ) + 1 ) ; } for ( int n : map . values ( ) ) System . out . println ( items [ x ++ ] + " x " + n ) ; } } +import java . io . * ; import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int H = sc . nextInt ( ) ; int W = sc . nextInt ( ) ; while ( H != 0 || W != 0 ) { for ( int i = 0 ; i < H ; i ++ ) { int W = sc . nextInt ( ) ; for ( int j = 0 ; j < W ; j ++ ) { System . out . printf ( " # " ) ; } System . out . printf ( " \n " ) ; } System . out . printf ( " \n " ) ; H = sc . nextInt ( ) ; W = sc . nextInt ( ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String S = sc . next ( ) ; Boolean bool = true ; for ( int i = 0 ; i < S . length ( ) ; i ++ ) { if ( i % 2 == 0 ) { int i = 0 ; if ( ! ( ( S . charAt ( i ) == 'R' ) || ( S . charAt ( i ) == 'U' ) || ( S . charAt ( i ) == 'D' ) ) ) { bool = false ; } } if ( i % 2 == 1 ) { if ( ! ( ( S . charAt ( i ) == 'L' ) || ( S . charAt ( i ) == 'U' ) || ( S . charAt ( i ) == 'D' ) ) ) { bool = false ; } } } if ( bool == true ) { System . out . print ( " Yes " ) ; } else { System . out . print ( " No " ) ; } sc . close ( ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . ArrayList ; import java . util . Collections ; import java . util . List ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String [ ] str = br . readLine ( ) . split ( " " ) ; long k = Long . parseLong ( br . readLine ( ) ) ; long one = 0 ; for ( int i = 0 ; i < str . length ; i ++ ) { if ( str [ i ] . equals ( " 1 " ) ) { one ++ ; } else { break ; } } if ( one >= k ) { System . out . println ( " 1 " ) ; } else { int i = 0 ; System . out . println ( str [ ( int ) one ] ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int N = in . nextInt ( ) ; int T = in . nextInt ( ) ; int A = in . nextInt ( ) ; int [ ] h = new int [ N ] ; double [ ] t = new double [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { int i = 0 ; h [ i ] = in . nextInt ( ) ; t [ i ] = Math . abs ( ( T - h [ i ] * 0.006 ) - A ) ; } int minn = 10000 ; double min = 10000000 ; for ( int i = 0 ; i < N ; i ++ ) { if ( min > t [ i ] ) { min = t [ i ] ; minn = i ; } } System . out . println ( minn + 1 ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int divValue , modValue , totalHp ; Scanner scanner = new Scanner ( System . in ) ; int yen = scanner . nextInt ( ) ; int divValue , modValue , totalHp ; divValue = yen / 500 ; totalHp = divValue * 1000 ; modValue = yen % 500 ; if ( modValue != 0 ) { divValue = modValue / 5 ; totalHp = totalHp + divValue * 5 ; } System . out . println ( totalHp ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) , m = sc . nextInt ( ) ; int [ ] arr = new int [ n ] ; int totalVotes = 0 ; for ( int i = 0 ; i < n ; i ++ ) { arr [ i ] = sc . nextInt ( ) ; totalVotes += arr [ i ] ; } double popular = totalVotes / ( 4 * m ) ; int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int i = 0 ; if ( totalVotes <= arr [ i ] * 4 * m ) ans ++ ; } if ( ans >= m ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int i = 1 ; Scanner sc = new Scanner ( System . in ) ; int A = sc . nextInt ( ) ; int B = sc . nextInt ( ) ; for ( int i = 1 ; i < 10000 ; i ++ ) { if ( ( int ) Math . floor ( i * 0.08 ) == A && ( int ) Math . floor ( i * 0.1 ) == B ) { System . out . println ( i ) ; return ; } } System . out . println ( - 1 ) ; return ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int use = 0 ; Scanner sc = new Scanner ( System . in ) ; int A = sc . nextInt ( ) ; int B = sc . nextInt ( ) ; int C = sc . nextInt ( ) ; int cap1 = A - B ; int use = 0 ; if ( cap1 < C ) { use = cap1 ; } else { use = C ; } System . out . println ( C - use ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) , b = sc . nextInt ( ) ; while ( a != 0 && b != 0 ) { int a = sc . nextInt ( ) , b = sc . nextInt ( ) ; int c = b ; b = a % b ; a = c ; } System . out . println ( a + b ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner scanner = new Scanner ( System . in ) ; int N = scanner . nextInt ( ) ; int M = scanner . nextInt ( ) ; int [ ] cnts = new int [ M ] ; for ( int i = 0 ; i < N ; i ++ ) { int k = scanner . nextInt ( ) ; for ( int j = 0 ; j < k ; j ++ ) { int idx = scanner . nextInt ( ) ; idx -- ; cnts [ idx ] ++ ; } } int cnt = 0 ; for ( int i = 0 ; i < M ; i ++ ) { if ( cnts [ i ] == N ) { cnt ++ ; } } System . out . println ( cnt ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] li = new int [ n ] ; for ( int i = 1 ; i <= n ; i ++ ) { li [ sc . nextInt ( ) - 1 ] = i ; } int i = 0 ; for ( int k : li ) { int i = 0 ; if ( i != n - 1 ) { System . out . print ( li [ i ] + " " ) ; } else { System . out . println ( li [ i ] ) ; } i ++ ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long k = sc . nextLong ( ) ; long sum = 0 ; for ( int a = 1 ; a <= k ; ++ a ) { for ( int b = 1 ; b <= k ; ++ b ) { long g1 = findGcd ( a , b ) ; for ( int c = 1 ; c <= k ; ++ c ) { long g2 = findGcd ( g1 , c ) ; sum += g2 ; } } } System . out . println ( sum ) ; } public static long findGcd ( long a , long b ) { int c = 1 ; if ( b == 0L ) { return a ; } return findGcd ( b , a % b ) ; } } +import java . util . ArrayList ; import java . util . Collections ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = Integer . parseInt ( sc . next ( ) ) ; ArrayList < Integer > nums = new ArrayList < Integer > ( N ) ; for ( int i = 0 ; i < N ; i ++ ) { nums . add ( Integer . parseInt ( sc . next ( ) ) ) ; } int ans = 0 ; while ( true ) { int max = Collections . max ( nums ) ; if ( max == 0 ) { break ; } int index = nums . indexOf ( max ) ; while ( true ) { int index = nums . indexOf ( max ) ; nums . set ( index , max - 1 ) ; if ( index == N - 1 ) { break ; } else if ( nums . get ( index ) == nums . get ( index + 1 ) - 1 ) { index += 1 ; } else { break ; } } ans ++ ; } System . out . println ( ans ) ; sc . close ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = Integer . parseInt ( sc . next ( ) ) ; int [ ] p = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { int i = 1 ; p [ i ] = Integer . parseInt ( sc . next ( ) ) ; } int cnt = 0 ; for ( int i = 1 ; i < n - 1 ; i ++ ) { if ( Math . min ( p [ i - 1 ] , p [ i ] ) == p [ i ] ) { if ( Math . min ( p [ i ] , p [ i + 1 ] ) == p [ i + 1 ] ) { cnt += 1 ; } } else { if ( Math . min ( p [ i ] , p [ i + 1 ] ) == p [ i ] ) { cnt += 1 ; } } } System . out . println ( cnt ) ; } } +import java . util . * ; import java . lang . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int x = sc . nextInt ( ) ; int sum = 0 ; for ( int i = 1 ; i <= 3 ; i ++ ) { int i = 1 ; int b = ( int ) Math . pow ( x , i ) ; sum = sum + b ; } System . out . println ( sum ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int T = sc . nextInt ( ) ; int A = sc . nextInt ( ) ; int [ ] H = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { H [ i ] = sc . nextInt ( ) ; } double min = Double . MAX_VALUE ; int minPotision = 0 ; for ( int i = 0 ; i < N ; i ++ ) { int i = 0 ; if ( Math . abs ( T - H [ i ] * 0.006 - A ) < min ) { min = Math . abs ( T - H [ i ] * 0.006 - A ) ; minPotision = i ; } } System . out . print ( minPotision + 1 ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int kosuu = sc . nextInt ( ) ; int [ ] arrayOishi = new int [ kosuu ] ; for ( int i = 0 ; i < arrayOishi . length ; i ++ ) { arrayOishi [ i ] = sc . nextInt ( ) ; } int result = 0 ; for ( int j = 0 ; j < kosuu ; j ++ ) { int k = j + 1 ; for ( int k = j + 1 ; k < kosuu ; k ++ ) { result += arrayOishi [ j ] * arrayOishi [ k ] ; } } System . out . println ( result ) ; sc . close ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; while ( true ) { int h = sc . nextInt ( ) ; int w = sc . nextInt ( ) ; if ( h == 0 && w == 0 ) break ; for ( int i = 0 ; i < h ; i ++ ) { for ( int j = 0 ; j < w ; j ++ ) { int j = 0 ; boolean oddRow = ( i % 2 ) == 1 ; boolean oddColumn = ( j % 2 ) == 1 ; if ( ( oddRow && oddColumn ) || ( ! oddRow && ! oddColumn ) ) { System . out . print ( " # " ) ; } else { System . out . print ( " . " ) ; } } System . out . println ( " " ) ; } System . out . println ( " " ) ; } sc . close ( ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int limit = sc . nextInt ( ) ; int max = 0 ; int result = 1 ; for ( int i = 1 ; i <= limit ; i ++ ) { int tmp = i ; int cnt = 0 ; while ( true ) { if ( tmp % 2 != 0 ) { break ; } tmp = tmp / 2 ; cnt ++ ; } if ( cnt > max ) { int cnt = 0 ; max = cnt ; result = i ; } } System . out . println ( result ) ; } } +import java . util . * ; import java . lang . * ; import java . io . * ; public class Main { PrintWriter out = new PrintWriter ( System . out ) ; BufferedReader in = new BufferedReader ( new InputStreamReader ( System . in ) ) ; StringTokenizer tok = new StringTokenizer ( " " ) ; String next ( ) throws IOException { if ( ! tok . hasMoreTokens ( ) ) { tok = new StringTokenizer ( in . readLine ( ) ) ; } return tok . nextToken ( ) ; } int ni ( ) throws IOException { return Integer . parseInt ( next ( ) ) ; } long nl ( ) throws IOException { return Long . parseLong ( next ( ) ) ; } void solve ( ) throws IOException { String s = next ( ) ; String t = next ( ) ; int ans = Integer . MAX_VALUE ; for ( int i = 0 ; i <= s . length ( ) - t . length ( ) ; i ++ ) { int na = 0 ; for ( int j = 0 ; j < t . length ( ) ; j ++ ) { int j = 0 ; if ( s . charAt ( i + j ) != t . charAt ( j ) ) na ++ ; } ans = Math . min ( ans , na ) ; } System . out . println ( ans ) ; } public static void main ( String [ ] args ) throws IOException { new Main ( ) . solve ( ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; String number ; char [ ] ca ; int num ; for ( ; ; ) { number = scan . next ( ) ; ca = number . toCharArray ( ) ; num = 0 ; if ( ca [ 0 ] == '0' ) { break ; } for ( int i = 0 ; i < ca . length ; i ++ ) { int i = 0 ; num += ca [ i ] - '0' ; } System . out . println ( num ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] l = new int [ n ] ; int max = 0 ; int pnt = - 1 ; for ( int i = 0 ; i < n ; i ++ ) { l [ i ] = sc . nextInt ( ) ; if ( max < l [ i ] ) { max = l [ i ] ; pnt = i ; } } int total = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( i == pnt ) continue ; total += l [ i ] ; } if ( max < total ) { int i = 0 ; System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } } +import java . math . BigInteger ; import java . util . Scanner ; public class Main { private static long n ; private static String [ ] numeralSystem ; public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; BigInteger bigInteger = new BigInteger ( scanner . next ( ) ) ; n = bigInteger . longValue ( ) ; fillNumeralSystem ( ) ; System . out . println ( translateNumber ( ) ) ; } private static void fillNumeralSystem ( ) { String res = " " ; numeralSystem = new String [ 27 ] ; numeralSystem [ 0 ] = " z " ; int delta = ( int ) 'a' ; for ( int i = 1 ; i < numeralSystem . length ; i ++ ) { numeralSystem [ i ] = Character . toString ( i - 1 + delta ) ; } } public static String translateNumber ( ) { String res = " " ; while ( n > 26 ) { res = numeralSystem [ ( int ) ( n % 26 ) ] . concat ( res ) ; n -- ; n /= 26 ; } res = numeralSystem [ ( int ) n ] . concat ( res ) ; return res ; } } +import java . util . ArrayList ; import java . util . Collections ; import java . util . List ; 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 K = sc . nextInt ( ) ; sc . close ( ) ; List < Integer > ary = new ArrayList < > ( ) ; int flg = 1 ; while ( flg <= A || flg <= B ) { if ( A % flg == 0 && B % flg == 0 ) { int flg = 1 ; ary . add ( flg ) ; } flg ++ ; } Collections . sort ( ary , Collections . reverseOrder ( ) ) ; System . out . println ( ary . get ( K - 1 ) ) ; } } +import java . io . * ; import java . util . * ; public class Main { public static void main ( String [ ] args ) throws IOException { int c = 0 ; int sum = 0 ; int n = 0 ; int i = 1 ; String s ; int a = 0 ; int b = 0 ; int c = 0 ; while ( i > 0 ) { BufferedReader x = new BufferedReader ( new InputStreamReader ( System . in ) ) ; s = x . readLine ( ) ; StringTokenizer st = new StringTokenizer ( s , " " ) ; a = Integer . parseInt ( st . nextToken ( ) ) ; b = Integer . parseInt ( st . nextToken ( ) ) ; c = Integer . parseInt ( st . nextToken ( ) ) ; if ( a >= 1 && a <= 10000 ) i = - 1 ; else if ( b >= 1 && b <= 10000 ) i = - 1 ; else if ( c >= 1 && c <= 10000 ) i = - 1 ; else if ( a <= b ) i = - 1 ; else i = 1 ; } for ( n = a ; n <= b ; n ++ ) { if ( c % n == 0 ) sum ++ ; } System . out . println ( " " + sum + " " ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; int A = sc . nextInt ( ) ; int B = sc . nextInt ( ) ; int res = 0 ; if ( ( A >= 10 ) || ( B >= 10 ) ) { int res = 0 ; res = - 1 ; } else { res = A * B ; } System . out . println ( res ) ; } } +import java . util . Scanner ; public class Main { private static Scanner sc ; public static void main ( String [ ] args ) { int b = sc . nextInt ( ) ; sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; String op = sc . next ( ) ; int b = sc . nextInt ( ) ; for ( ; ! op . equals ( " ? " ) ; ) { int ans = 0 ; switch ( op ) { case " + " : ans = a + b ; break ; case " - " : ans = a - b ; break ; case " * " : ans = a * b ; break ; case " / " : if ( a == 0 ) { break ; } ans = a / b ; } System . out . println ( ans ) ; a = sc . nextInt ( ) ; op = sc . next ( ) ; b = sc . nextInt ( ) ; } } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader bis = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String s = bis . readLine ( ) ; int l = s . length ( ) ; int ans = 0 ; for ( int i = 0 ; i < l ; i ++ ) { char c = s . charAt ( i ) ; if ( c == '+' ) { ans += 1 ; } if ( c == '-' ) { int i = 0 ; ans -= 1 ; } } System . out . println ( ans ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner In = new Scanner ( System . in ) ; int n ; do { int j = 1 ; n = In . nextInt ( ) ; } while ( n <= 2 && n >= 200000 ) ; int [ ] a = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { do { a [ i ] = In . nextInt ( ) ; } while ( 1 >= a [ i ] && a [ i ] >= Math . pow ( 10 , 9 ) ) ; } int minv = a [ 0 ] ; int maxv = a [ 1 ] - a [ 0 ] ; for ( int j = 1 ; j <= n - 1 ; j ++ ) { maxv = maxv > ( a [ j ] - minv ) ? maxv : ( a [ j ] - minv ) ; minv = minv < a [ j ] ? minv : a [ j ] ; } System . out . println ( maxv ) ; } } +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 firstIndex = S . length ( ) ; int lastIndex = S . length ( ) ; char [ ] sArray = S . toCharArray ( ) ; for ( int i = 0 ; i < sArray . length ; i ++ ) { int i = 0 ; if ( sArray [ i ] == 'A' ) { firstIndex = i ; break ; } } for ( int i = 0 ; i < sArray . length ; i ++ ) { if ( sArray [ i ] == 'Z' ) lastIndex = i ; } System . out . println ( S . substring ( firstIndex , lastIndex + 1 ) . length ( ) ) ; sc . close ( ) ; } } +import java . io . * ; import java . math . * ; import java . util . * ; public class Main { static final long MOD = 1000000007L ; static final int INF = 50000000 ; public static void main ( String [ ] args ) { FastScanner sc = new FastScanner ( ) ; PrintWriter pw = new PrintWriter ( System . out ) ; String s = sc . next ( ) ; int d = 0 ; for ( char c : s . toCharArray ( ) ) { d += ( c - '0' ) ; } if ( d % 9 == 0 ) { pw . println ( " Yes " ) ; } else { pw . println ( " No " ) ; } pw . close ( ) ; } static class FastScanner { BufferedReader br ; StringTokenizer st ; public FastScanner ( ) { String str = " " ; 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 ni ( ) { return Integer . parseInt ( next ( ) ) ; } long nl ( ) { return Long . parseLong ( next ( ) ) ; } double nd ( ) { return Double . parseDouble ( next ( ) ) ; } String nextLine ( ) { String str = " " ; try { str = br . readLine ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } return str ; } } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; try { String str = br . readLine ( ) ; String [ ] strArr = str . split ( " " ) ; int n = Integer . parseInt ( strArr [ 0 ] ) ; int m = Integer . parseInt ( strArr [ 1 ] ) ; String [ ] [ ] a = new String [ n ] [ m ] ; String [ ] b = new String [ m ] ; for ( int i = 0 ; i < n ; i ++ ) { str = br . readLine ( ) ; a [ i ] = str . split ( " " ) ; } for ( int i = 0 ; i < m ; i ++ ) { b [ i ] = br . readLine ( ) ; } int sum ; for ( int i = 0 ; i < n ; i ++ ) { sum = 0 ; for ( int j = 0 ; j < m ; j ++ ) { sum += Integer . parseInt ( a [ i ] [ j ] ) * Integer . parseInt ( b [ j ] ) ; } System . out . println ( sum ) ; } } catch ( IOException e ) { e . printStackTrace ( ) ; } finally { try { if ( br != null ) { int j = 0 ; br . close ( ) ; } } catch ( IOException ioe ) { } } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner scan = new Scanner ( System . in ) ; int [ ] pizza = new int [ 5 ] ; int ans = 1000000000 ; for ( int i = 0 ; i < 5 ; i ++ ) { pizza [ i ] = scan . nextInt ( ) ; } for ( int i = 0 ; i < 2 * ( pizza [ 3 ] + pizza [ 4 ] ) + 1 ; i ++ ) { int a = Math . max ( 0 , ( pizza [ 3 ] - i / 2 ) ) ; int b = Math . max ( 0 , ( pizza [ 4 ] - i / 2 ) ) ; int c = i ; ans = Math . min ( ans , pizza [ 0 ] * a + pizza [ 1 ] * b + pizza [ 2 ] * c ) ; } System . out . println ( ans ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int i , j , t ; int cnt = 0 ; int check = 0 ; int mini , minikey ; int n = sc . nextInt ( ) ; int [ ] num ; num = new int [ n ] ; for ( i = 0 ; i < n ; i ++ ) { num [ i ] = sc . nextInt ( ) ; } for ( i = 0 ; i < n - 1 ; i ++ ) { mini = i ; minikey = num [ i ] ; for ( j = i + 1 ; j < n ; j ++ ) { if ( num [ j ] < minikey ) { int [ ] num ; mini = j ; minikey = num [ j ] ; check ++ ; } } t = num [ i ] ; num [ i ] = num [ mini ] ; num [ mini ] = t ; if ( check > 0 ) cnt ++ ; check = 0 ; } for ( i = 0 ; i < n - 1 ; i ++ ) { System . out . print ( num [ i ] + " " ) ; } System . out . println ( num [ n - 1 ] ) ; System . out . println ( cnt ) ; sc . close ( ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String S = sc . next ( ) ; int n = S . length ( ) ; int tmp = 0 ; String [ ] part = new String [ n * ( n + 1 ) / 2 ] ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i ; j < n ; j ++ ) { part [ tmp ] = S . substring ( i , j + 1 ) ; tmp = tmp + 1 ; } } int answer = 0 ; for ( int i = 0 ; i < part . length ; i ++ ) { if ( isATGC ( part [ i ] ) ) { if ( answer < part [ i ] . length ( ) ) { answer = part [ i ] . length ( ) ; } } } System . out . println ( answer ) ; } public static boolean isATGC ( String s ) { int i = 0 ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( s . substring ( i , i + 1 ) . equals ( " A " ) || s . substring ( i , i + 1 ) . equals ( " T " ) || s . substring ( i , i + 1 ) . equals ( " G " ) || s . substring ( i , i + 1 ) . equals ( " C " ) ) { continue ; } else { return false ; } } return true ; } } +import java . util . * ; class Problem { long n ; long a = 0 ; long b = 0 ; final long START_DISTANCE_FROM_ORIGIN = 2 ; public Problem ( long n ) { this . n = n ; } public void solve ( ) { for ( long i = 1 ; i * i <= n ; i ++ ) if ( n % i == 0 ) update ( i ) ; } private void update ( long i ) { a = i ; b = n / i ; } public void show ( ) { System . out . println ( a + b - START_DISTANCE_FROM_ORIGIN ) ; } } public class Main { public static void main ( String [ ] args ) { long n = sc . nextLong ( ) ; Scanner sc = new Scanner ( System . in ) ; long n = sc . nextLong ( ) ; Problem p = new Problem ( n ) ; p . solve ( ) ; p . show ( ) ; } } +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 ] ; int ans = 0 ; for ( int i = 0 ; i < N ; i ++ ) { int count = 0 ; A [ i ] = sc . nextInt ( ) ; int count = 0 ; if ( A [ i ] % 2 != 0 ) { ans = 0 ; break ; } while ( A [ i ] % 2 == 0 ) { A [ i ] /= 2 ; count ++ ; } if ( count > 0 ) { if ( ans == 0 ) ans = count ; else ans = Math . min ( ans , count ) ; } } System . out . println ( ans ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; String t = sc . next ( ) ; int min = 1000000000 ; int sum = 0 ; for ( int i = 0 ; i < s . length ( ) - ( t . length ( ) - 1 ) ; i ++ ) { sum = 0 ; for ( int j = 0 ; j < t . length ( ) ; j ++ ) { int j = 0 ; if ( s . charAt ( i + j ) != t . charAt ( j ) ) sum ++ ; } min = Math . min ( min , sum ) ; } System . out . println ( min ) ; } } +import java . io . * ; public class Main { public static void main ( String [ ] args ) throws Exception { int i = 0 ; BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; StringBuilder sb = new StringBuilder ( ) ; String [ ] str = br . readLine ( ) . split ( " " ) ; int n = Integer . parseInt ( str [ 0 ] ) ; int m = Integer . parseInt ( str [ 1 ] ) ; int [ ] [ ] matrix = new int [ n ] [ m ] ; int [ ] vector = new int [ m ] ; int [ ] result = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { String [ ] str2 = br . readLine ( ) . split ( " " ) ; for ( int k = 0 ; k < m ; k ++ ) { matrix [ i ] [ k ] = Integer . parseInt ( str2 [ k ] ) ; } } for ( int i = 0 ; i < m ; i ++ ) { vector [ i ] = Integer . parseInt ( br . readLine ( ) ) ; } for ( int i = 0 ; i < n ; i ++ ) { for ( int k = 0 ; k < m ; k ++ ) { result [ i ] += matrix [ i ] [ k ] * vector [ k ] ; } } for ( int i = 0 ; i < n ; i ++ ) { System . out . println ( result [ i ] ) ; } } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int t = sc . nextInt ( ) ; int a = sc . nextInt ( ) ; double A = ( t - a ) * 1000 / 6.0 ; double [ ] h = new double [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { h [ i ] = Math . abs ( sc . nextInt ( ) - A ) ; } int idx = 0 ; for ( int i = 1 ; i < n ; i ++ ) { int i = 1 ; if ( h [ i ] < h [ idx ] ) { idx = i ; } } System . out . println ( idx + 1 ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { try ( Scanner sc = new Scanner ( System . in ) ) { int N = Integer . parseInt ( sc . next ( ) ) ; long [ ] a = new long [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { a [ i ] = Long . parseLong ( sc . next ( ) ) ; if ( a [ i ] == 0 ) { System . out . println ( 0 ) ; return ; } } long total = 1L ; long LIMIT = 1000000000000000000L ; for ( int i = 0 ; i < N ; i ++ ) { if ( a [ i ] <= LIMIT / total ) { int i = 0 ; total *= a [ i ] ; } else { System . out . println ( - 1 ) ; return ; } } System . out . println ( total ) ; } } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int numRow1 = sc . nextInt ( ) ; int numCol1Row2 = sc . nextInt ( ) ; int numCol2 = sc . nextInt ( ) ; int [ ] [ ] mat1 = new int [ numRow1 ] [ numCol1Row2 ] ; int [ ] [ ] mat2 = new int [ numCol1Row2 ] [ numCol2 ] ; long [ ] [ ] matOut = new long [ numRow1 ] [ numCol2 ] ; int i , j , k ; for ( i = 0 ; i < numRow1 ; i ++ ) { for ( j = 0 ; j < numCol1Row2 ; j ++ ) { int i , j , k ; mat1 [ i ] [ j ] = sc . nextInt ( ) ; } } for ( i = 0 ; i < numCol1Row2 ; i ++ ) { for ( j = 0 ; j < numCol2 ; j ++ ) { mat2 [ i ] [ j ] = sc . nextInt ( ) ; } } for ( i = 0 ; i < numRow1 ; i ++ ) { for ( j = 0 ; j < numCol2 ; j ++ ) { for ( k = 0 ; k < numCol1Row2 ; k ++ ) { matOut [ i ] [ j ] += mat1 [ i ] [ k ] * mat2 [ k ] [ j ] ; } if ( j != 0 ) System . out . print ( " " ) ; System . out . print ( matOut [ i ] [ j ] ) ; } System . out . println ( ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; String ans = " No " ; for ( int i = 1 ; i < 10 ; i ++ ) { for ( int j = 1 ; j < 10 ; j ++ ) { int j = 1 ; if ( i * j == N ) { ans = " Yes " ; break ; } } } System . out . println ( ans ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; String w = scan . nextLine ( ) ; char [ ] c = w . toCharArray ( ) ; int [ ] count = new int [ c . length ] ; String show = null ; for ( int i = 0 ; i < c . length ; i ++ ) { for ( int m = 0 ; m < c . length ; m ++ ) { int i = 0 ; if ( c [ i ] == c [ m ] ) { count [ i ] ++ ; } } } for ( int i = 0 ; i < c . length ; i ++ ) { if ( count [ i ] % 2 != 0 ) { show = " No " ; break ; } else { show = " Yes " ; } } System . out . println ( show ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . io . PrintWriter ; public class Main { public static void main ( String [ ] args ) { InputStreamReader isr = new InputStreamReader ( System . in ) ; BufferedReader br = new BufferedReader ( isr ) ; PrintWriter out = new PrintWriter ( System . out ) ; try { String strData = br . readLine ( ) ; String [ ] strDat = strData . split ( " " , - 1 ) ; int intCard = Integer . parseInt ( strDat [ 0 ] ) ; int intGate = Integer . parseInt ( strDat [ 1 ] ) ; int [ ] intL = new int [ intGate ] ; int [ ] intR = new int [ intGate ] ; int intSt ; int intEd ; intSt = 0 ; intEd = intCard ; for ( int i = 0 ; i < intGate ; i ++ ) { int i = 0 ; strData = br . readLine ( ) ; strDat = strData . split ( " " , - 1 ) ; intL [ i ] = Integer . parseInt ( strDat [ 0 ] ) ; intR [ i ] = Integer . parseInt ( strDat [ 1 ] ) ; if ( intL [ i ] > intSt ) intSt = intL [ i ] ; if ( intR [ i ] < intEd ) intEd = intR [ i ] ; } int ans = 0 ; ans = intEd - intSt + 1 ; if ( ans < 0 ) ans = 0 ; System . out . println ( ans ) ; out . flush ( ) ; } catch ( IOException e ) { } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int k = sc . nextInt ( ) ; String s = sc . next ( ) ; System . out . println ( sln ( k , s ) ) ; } public static String sln ( int k , String s ) { String s = sc . next ( ) ; String res = s . substring ( 0 , k - 1 ) + ( s . charAt ( k - 1 ) + " " ) . toLowerCase ( ) + s . substring ( k ) ; return res ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; String s = scan . next ( ) ; String [ ] t = s . split ( " " ) ; for ( int i = 0 ; i < t . length ; i ++ ) { int i = 0 ; t [ i ] = " x " ; } String u = String . join ( " " , t ) ; System . out . println ( u ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; boolean [ ] [ ] cardHasFlag = new boolean [ 4 ] [ 13 ] ; int n = sc . nextInt ( ) ; for ( int i = 0 ; i < n ; i ++ ) { String make = sc . next ( ) ; int card = sc . nextInt ( ) ; switch ( make ) { case " S " : cardHasFlag [ 0 ] [ card - 1 ] = true ; break ; case " H " : cardHasFlag [ 1 ] [ card - 1 ] = true ; break ; case " C " : cardHasFlag [ 2 ] [ card - 1 ] = true ; break ; case " D " : cardHasFlag [ 3 ] [ card - 1 ] = true ; break ; } } for ( int i = 0 ; i < 4 ; i ++ ) { for ( int j = 0 ; j < 13 ; j ++ ) { if ( cardHasFlag [ i ] [ j ] == false ) { int j = 0 ; switch ( i ) { case 0 : System . out . printf ( " S %d \n " , j + 1 ) ; break ; case 1 : System . out . printf ( " H %d \n " , j + 1 ) ; break ; case 2 : System . out . printf ( " C %d \n " , j + 1 ) ; break ; case 3 : System . out . printf ( " D %d \n " , j + 1 ) ; break ; } } } } } } +import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . util . ArrayList ; import java . util . Arrays ; import java . util . List ; import java . util . stream . Collectors ; public class Main { public static void main ( String [ ] args ) throws Exception { InputStreamReader is = new InputStreamReader ( System . in ) ; BufferedReader reader = new BufferedReader ( is ) ; List < String > mylist = new ArrayList < > ( ) ; String strinput = reader . readLine ( ) ; while ( strinput != null ) { String strinput = reader . readLine ( ) ; mylist . add ( strinput ) ; strinput = reader . readLine ( ) ; } String [ ] arr01 = mylist . get ( 0 ) . split ( " " ) ; String [ ] arr02 = mylist . get ( 1 ) . split ( " " ) ; int n = Integer . valueOf ( arr01 [ 0 ] ) ; List < String > list01 = Arrays . asList ( arr02 ) ; List < String > list02 = list01 . stream ( ) . distinct ( ) . collect ( Collectors . toList ( ) ) ; System . out . println ( list01 . size ( ) == list02 . size ( ) ? " YES " : " NO " ) ; } } +import java . io . * ; import java . util . * ; public class Main { public static void main ( final String [ ] args ) throws Exception { long B ; final Scanner sc = new Scanner ( System . in ) ; long A ; A = sc . nextLong ( ) ; long B ; B = sc . nextLong ( ) ; final Solver solver = new Solver ( ) ; solver . solve ( A , B ) ; } } class Solver { public void solve ( long A , long B ) { System . out . println ( A * B / lcd ( A , B ) ) ; } private long lcd ( long A , long B ) { if ( B == 0 ) { return A ; } return lcd ( B , A % B ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int count = 0 ; Scanner sc = new Scanner ( System . in ) ; int A = sc . nextInt ( ) ; int B = sc . nextInt ( ) ; int count = 0 ; while ( true ) { if ( ( A - 1 ) * count + 1 >= B ) { break ; } count += 1 ; } System . out . println ( count ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int m = sc . nextInt ( ) ; int [ ] [ ] a = new int [ n ] [ m ] ; int [ ] b = new int [ m ] ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < m ; j ++ ) { a [ i ] [ j ] = sc . nextInt ( ) ; } } for ( int i = 0 ; i < m ; i ++ ) { b [ i ] = sc . nextInt ( ) ; } for ( int i = 0 ; i < n ; i ++ ) { int j = 0 ; int total = 0 ; for ( int j = 0 ; j < m ; j ++ ) { total += a [ i ] [ j ] * b [ j ] ; } System . out . println ( total ) ; } } } +import java . util . Scanner ; class Main { private static String toString ( int [ ] numbers ) { StringBuilder ans = new StringBuilder ( ) . append ( numbers [ 0 ] ) ; for ( int x = 1 ; x < numbers . length ; x ++ ) ans . append ( " " ) . append ( numbers [ x ] ) ; return ans . toString ( ) ; } 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 ++ ) { int mini = i ; A [ i ] = sc . nextInt ( ) ; } int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int mini = i ; for ( int j = i ; j < n ; j ++ ) if ( A [ j ] < A [ mini ] ) mini = j ; if ( mini != i ) { int temp = A [ i ] ; A [ i ] = A [ mini ] ; A [ mini ] = temp ; count ++ ; } } System . out . println ( toString ( A ) ) ; System . out . println ( count ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner x = new Scanner ( System . in ) ; int m = x . nextInt ( ) ; int f = x . nextInt ( ) ; int r = x . nextInt ( ) ; int go = m + f ; while ( m != - 1 || f != - 1 || r != - 1 ) { if ( m == - 1 || f == - 1 || go < 30 ) { int go = m + f ; System . out . println ( " F " ) ; } else if ( go >= 80 ) { System . out . println ( " A " ) ; } else if ( go >= 65 ) { System . out . println ( " B " ) ; } else if ( go >= 50 || r >= 50 ) { System . out . println ( " C " ) ; } else if ( go >= 30 ) { System . out . println ( " D " ) ; } m = x . nextInt ( ) ; f = x . nextInt ( ) ; r = x . nextInt ( ) ; go = m + f ; } } } +import java . io . IOException ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws IOException { int d ; Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int c = sc . nextInt ( ) ; int d ; d = 0 ; while ( a <= b ) { if ( c % a == 0 ) { d = d + 1 ; } a = a + 1 ; } System . out . println ( d ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; String line1 = sc . nextLine ( ) ; String line2 = sc . nextLine ( ) ; String [ ] array1 = line1 . split ( " " ) ; String [ ] array2 = line2 . split ( " " ) ; int hp = Integer . parseInt ( array1 [ 0 ] ) ; int n = Integer . parseInt ( array1 [ 1 ] ) ; long sum = 0 ; String result = " No " ; for ( int i = 0 ; i < n ; i ++ ) { int buf = Integer . parseInt ( array2 [ i ] ) ; sum += buf ; if ( sum >= hp ) { result = " Yes " ; break ; } } System . out . println ( result ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int tairyoku = scanner . nextInt ( ) ; int hissatsuwazashurui = scanner . nextInt ( ) ; int sum = 0 ; for ( int i = 0 ; i < hissatsuwazashurui ; i ++ ) { int sum = 0 ; sum += scanner . nextInt ( ) ; } if ( tairyoku > sum ) { System . out . println ( " No " ) ; } else { System . out . println ( " Yes " ) ; } } } +import java . util . * ; import java . io . * ; public class Main { public static void main ( String [ ] args ) throws Exception { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; PrintWriter out = new PrintWriter ( new OutputStreamWriter ( System . out ) ) ; int n = Integer . parseInt ( br . readLine ( ) ) ; int a = 0 ; int b = 0 ; String [ ] input = br . readLine ( ) . split ( " " ) ; Integer [ ] numbers = new Integer [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { int i = 0 ; numbers [ i ] = Integer . valueOf ( input [ i ] ) ; } Arrays . sort ( numbers , Collections . reverseOrder ( ) ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( i % 2 == 0 ) { a += numbers [ i ] ; } else { b += numbers [ i ] ; } } out . println ( a - b ) ; out . close ( ) ; } } +import java . util . * ; import java . util . Collections ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int L = sc . nextInt ( ) ; String [ ] A = new String [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { A [ i ] = sc . next ( ) ; } Arrays . sort ( A ) ; StringBuilder B = new StringBuilder ( ) ; for ( int i = 0 ; i < A . length ; i ++ ) { int i = 0 ; B . append ( A [ i ] ) ; } System . out . println ( B ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; long A = scan . nextInt ( ) ; long B = scan . nextInt ( ) ; long gcd = GCD ( A , B ) ; long lcm = LCM ( A , B , gcd ) ; System . out . println ( lcm ) ; } public static long GCD ( long a , long b ) { for ( long i = a ; i > 0 ; i -- ) { if ( a % i == 0 && b % i == 0 ) { return i ; } } return 1 ; } public static long LCM ( long a , long b , long gcd ) { long i = a ; return a * b / gcd ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { char c ; Scanner input = new Scanner ( System . in ) ; String s ; for ( s = input . next ( ) ; ! s . equals ( " 0 " ) ; s = input . next ( ) ) { int sum = 0 ; for ( char c : s . toCharArray ( ) ) { sum += c - '0' ; } System . out . println ( sum ) ; } } } +import java . util . * ; import java . io . * ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner s = new Scanner ( System . in ) ; String S = s . next ( ) ; String T = s . next ( ) ; int count = 0 ; for ( int i = 0 ; i < S . length ( ) ; i ++ ) { if ( S . charAt ( i ) != T . charAt ( i ) ) count ++ ; } System . out . println ( count ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int N = scanner . nextInt ( ) ; int K = scanner . nextInt ( ) ; int a = 0 ; for ( int i = 1 ; i <= N ; i ++ ) { int a = 0 ; int h = scanner . nextInt ( ) ; if ( h >= K ) { a ++ ; } else { continue ; } } System . out . println ( a ) ; } } +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 c = sc . nextInt ( ) ; int k = sc . nextInt ( ) ; for ( int i = 0 ; i < k ; i ++ ) { int [ ] result = getMax ( a , b , c ) ; a = result [ 0 ] ; b = result [ 1 ] ; c = result [ 2 ] ; } System . out . println ( a + b + c ) ; } private static int [ ] getMax ( int a , int b , int c ) { int [ ] newInput = new int [ ] { a , b , c } ; int [ ] newInput = new int [ ] { a , b , c } ; if ( a <= b && c <= b ) { newInput [ 1 ] = 2 * b ; } else if ( b <= a && c <= a ) { newInput [ 0 ] = 2 * a ; } else if ( a <= c && b <= c ) { newInput [ 2 ] = 2 * c ; } return newInput ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int k = sc . nextInt ( ) ; long sum = 0 ; for ( int a = 1 ; a <= k ; a ++ ) { int small = Math . min ( x , y ) ; for ( int b = 1 ; b <= k ; b ++ ) { int sur_1 = gcd ( a , b ) ; for ( int c = 1 ; c <= k ; c ++ ) { sum += gcd ( sur_1 , c ) ; } } } System . out . println ( sum ) ; } public static int gcd ( int x , int y ) { int big = Math . max ( x , y ) ; int small = Math . min ( x , y ) ; int surplus = big % small ; if ( surplus == 0 ) { return small ; } surplus = gcd ( small , surplus ) ; return surplus ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws IOException , Exception { BufferedReader st = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int [ ] data1 = getIntArry ( st ) ; int n = data1 [ 0 ] ; int k = data1 [ 1 ] ; int [ ] data2 = getIntArry ( st ) ; int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( data2 [ i ] >= k ) { int i = 0 ; ans ++ ; } } anser ( ans ) ; } private static int [ ] getIntArry ( BufferedReader st ) throws Exception , IOException { String line = st . readLine ( ) ; String [ ] strData = line . split ( " " ) ; int [ ] intData = new int [ strData . length ] ; for ( int i = 0 ; i < strData . length ; i ++ ) { intData [ i ] = Integer . parseInt ( strData [ i ] ) ; } return intData ; } private static void anser ( int num ) { System . out . println ( num ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { try ( final Scanner sc = new Scanner ( System . in ) ) { Resolver resolver = new Resolver ( sc ) ; resolver . resolve ( ) ; } } private static class Resolver { private final int a , b , t ; private Resolver ( final Scanner sc ) { this . a = sc . nextInt ( ) ; this . b = sc . nextInt ( ) ; this . t = sc . nextInt ( ) ; } private void resolve ( ) { int k = t / a ; System . out . println ( b * k ) ; } } } +import java . util . HashMap ; import java . util . Map ; import java . util . Map . Entry ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { try ( Scanner scanner = new Scanner ( System . in ) ) { int cityCnt = scanner . nextInt ( ) ; int routeCnt = scanner . nextInt ( ) ; Map < Integer , Integer > map = initMap ( cityCnt ) ; for ( int i = 0 ; i < routeCnt ; i ++ ) { int i = 1 ; for ( int j = 0 ; j < 2 ; j ++ ) { int routeA = scanner . nextInt ( ) ; if ( map . containsKey ( routeA ) ) { map . put ( routeA , map . get ( routeA ) + 1 ) ; } else { map . put ( routeA , 1 ) ; } } } for ( Entry < Integer , Integer > entry : map . entrySet ( ) ) { System . out . println ( entry . getValue ( ) ) ; } } } private static Map < Integer , Integer > initMap ( int cityCnt ) { Map < Integer , Integer > map = new HashMap < Integer , Integer > ( ) ; for ( int i = 1 ; i <= cityCnt ; i ++ ) { map . put ( i , 0 ) ; } return map ; } } +import java . util . ArrayList ; import java . util . List ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int j = 0 ; Scanner sc = new Scanner ( System . in ) ; int num = sc . nextInt ( ) ; int hp = 0 ; List < Integer > takoyaki = new ArrayList < Integer > ( ) ; takoyaki . add ( sc . nextInt ( ) ) ; for ( int i = 1 ; i < num ; i ++ ) { takoyaki . add ( sc . nextInt ( ) ) ; for ( int j = 0 ; j < i ; j ++ ) { hp = hp + takoyaki . get ( i ) * takoyaki . get ( j ) ; } } System . out . println ( hp ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws Exception { int numberOfB ; String inputNameA ; String inputNameB ; int numberOfA ; int numberOfB ; String choiceName ; Scanner scanner = new Scanner ( System . in ) ; String inputName = scanner . nextLine ( ) ; String inputNum = scanner . nextLine ( ) ; choiceName = scanner . nextLine ( ) ; scanner . close ( ) ; String [ ] editInputName = inputName . split ( " " ) ; inputNameA = editInputName [ 0 ] ; inputNameB = editInputName [ 1 ] ; String [ ] editInputNum = inputNum . split ( " " ) ; numberOfA = Integer . parseInt ( editInputNum [ 0 ] ) ; numberOfB = Integer . parseInt ( editInputNum [ 1 ] ) ; if ( inputNameA . equals ( choiceName ) ) { numberOfA -- ; } else if ( inputNameB . equals ( choiceName ) ) { numberOfB -- ; } System . out . println ( numberOfA + " " + numberOfB ) ; } } +import java . util . Scanner ; public class Main { private static final Scanner SC = new Scanner ( System . in ) ; private static final int ELEMENTS = SC . nextInt ( ) ; private static final int [ ] VALUE = load ( SC ) ; private static int [ ] load ( Scanner sc ) { int [ ] value = new int [ ELEMENTS ] ; for ( int i = 0 ; i < ELEMENTS ; i ++ ) { value [ i ] = sc . nextInt ( ) ; } return value ; } public static void main ( String [ ] args ) { int sumOfAll = 0 ; for ( int i : VALUE ) { sumOfAll += i ; } int turningPoint = 0 ; int partialSum = 0 ; for ( int i = 0 ; i < VALUE . length ; i ++ ) { int i = 0 ; partialSum += VALUE [ i ] ; sumOfAll -= VALUE [ i ] ; if ( sumOfAll - partialSum < 0 ) { turningPoint = i ; break ; } } int resultA = partialSum - sumOfAll ; int resultB = sumOfAll - partialSum + 2 * VALUE [ turningPoint ] ; System . out . println ( Math . min ( resultA , resultB ) ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int ex = 0 ; int [ ] h = new int [ 8 ] ; for ( int i = 0 ; i < 8 ; i ++ ) { h [ i ] = 0 ; } for ( int i = 0 ; i < n ; i ++ ) { int buf = sc . nextInt ( ) ; for ( int j = 0 ; j < 8 ; j ++ ) { if ( buf <= 399 + j * 400 ) { h [ j ] ++ ; break ; } if ( j == 7 ) { ex ++ ; } } } int min = 0 ; for ( int i = 0 ; i < 8 ; i ++ ) { if ( h [ i ] >= 1 ) { int i = 0 ; min ++ ; } } int max = min + ex ; if ( min == 0 ) { min = 1 ; } System . out . println ( min + " " + max ) ; } } +import java . util . * ; import java . io . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long size = sc . nextLong ( ) ; long blue = sc . nextLong ( ) ; long red = sc . nextLong ( ) ; long total = blue + red ; long ans = 0 ; long div = 0 ; long mod = 0 ; if ( blue == 0 ) { ans = 0 ; } else if ( size < total ) { if ( size >= blue ) { ans = blue ; } else if ( size < blue ) { long mod = 0 ; ans = size ; } } else if ( size >= total ) { div = size / total ; mod = size % total ; if ( mod > blue ) { mod = blue ; } ans = ( div * blue ) + mod ; } System . out . println ( ans ) ; } } +import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int M = sc . nextInt ( ) ; int [ ] m = new int [ M + 1 ] ; Arrays . fill ( m , 0 ) ; int K = 0 ; int A = 0 ; int ans = 0 ; for ( int i = 0 ; i < N ; i ++ ) { K = sc . nextInt ( ) ; for ( int j = 0 ; j < K ; j ++ ) { A = sc . nextInt ( ) ; m [ A ] ++ ; } } for ( int i = 0 ; i <= M ; i ++ ) { int i = 0 ; if ( m [ i ] == N ) ans ++ ; } System . out . println ( ans ) ; } } +import java . util . ArrayList ; import java . util . Collections ; import java . util . List ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int K = sc . nextInt ( ) ; List < Integer > list = new ArrayList < > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { int i = 0 ; list . add ( sc . nextInt ( ) ) ; } Collections . sort ( list ) ; int ans = 0 ; for ( int i = 0 ; i < K ; ++ i ) { ans += list . get ( i ) ; } System . out . println ( ans ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int num1 = scan . nextInt ( ) ; int num2 = scan . nextInt ( ) ; int num3 = scan . nextInt ( ) ; int count = 0 ; if ( num1 != num2 ) { count ++ ; } if ( num2 != num3 ) { count ++ ; } if ( num1 != num3 ) { count ++ ; } if ( count == 1 || count == 2 ) { int count = 0 ; System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { boolean stop = false ; Scanner sc = new Scanner ( System . in ) ; long m = sc . nextInt ( ) ; long n = sc . nextInt ( ) ; long k = 0 ; boolean stop = false ; if ( m < n ) { k = m ; } else { k = n ; } for ( ; k >= 1 && stop == false ; k -- ) { if ( n % k == 0 && m % k == 0 ) { stop = true ; } } long l = n * m / ( k + 1 ) ; System . out . println ( l ) ; } } +import java . io . BufferedReader ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws Exception { String line = readLine ( ) ; String WA = " WA " ; String AC = " AC " ; if ( line . startsWith ( " A " ) ) { if ( line . substring ( 0 , 2 ) . indexOf ( " C " ) != - 1 || line . endsWith ( " C " ) ) { System . out . println ( WA ) ; return ; } if ( line . replace ( " C " , " " ) . length ( ) != line . length ( ) - 1 ) { System . out . println ( WA ) ; return ; } String str1 = line . replace ( " A " , " " ) ; String str2 = str1 . replace ( " C " , " " ) ; if ( str2 . equals ( str2 . toLowerCase ( ) ) ) { System . out . println ( AC ) ; } else { String AC = " AC " ; System . out . println ( WA ) ; } } else { System . out . println ( WA ) ; } } private static String readLine ( ) throws Exception { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; return br . readLine ( ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner scan = new Scanner ( System . in ) ; String numM = scan . next ( ) ; int origin = Integer . parseInt ( numM ) ; int startNum = 0 ; for ( int i = 0 ; i < numM . length ( ) ; i ++ ) { startNum = startNum + Integer . parseInt ( String . valueOf ( numM . charAt ( i ) ) ) ; } if ( origin % startNum == 0 ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int N , M , ans = 0 ; int [ ] [ ] Food ; Scanner scan = new Scanner ( System . in ) ; N = scan . nextInt ( ) ; M = scan . nextInt ( ) ; Food = new int [ N + 1 ] [ M ] ; for ( int i = 0 ; i < M ; i ++ ) { Food [ N ] [ i ] = 1 ; } int A , K ; for ( int i = 0 ; i < N ; i ++ ) { K = scan . nextInt ( ) ; for ( int j = 0 ; j < K ; j ++ ) { int i = 0 ; A = scan . nextInt ( ) ; Food [ i ] [ A - 1 ] = 1 ; } } for ( int i = 0 ; i < M ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) { Food [ N ] [ i ] *= Food [ j ] [ i ] ; } } for ( int i = 0 ; i < M ; i ++ ) { ans += Food [ N ] [ i ] ; } System . out . print ( ans ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int [ ] in = new int [ a ] ; for ( int i = 0 ; i < a ; i ++ ) { in [ i ] = sc . nextInt ( ) ; } int count = 0 ; int ans = 0 ; for ( int i = 0 ; i < a - 1 ; i ++ ) { int i = 0 ; if ( in [ i ] >= in [ i + 1 ] ) { count ++ ; } else { ans = Math . max ( ans , count ) ; count = 0 ; } if ( i == a - 2 ) { ans = Math . max ( ans , count ) ; } } System . out . println ( ans ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int startNum ; int endNum ; int answer = 0 ; Scanner sc = new Scanner ( System . in ) ; startNum = sc . nextInt ( ) ; endNum = sc . nextInt ( ) ; for ( int i = startNum ; i <= endNum ; i ++ ) { String numStr = String . valueOf ( i ) ; char num1 = numStr . charAt ( 0 ) ; char num2 = numStr . charAt ( 1 ) ; char num4 = numStr . charAt ( 3 ) ; char num5 = numStr . charAt ( 4 ) ; if ( ( num1 == num5 ) && ( num2 == num4 ) ) { int i = startNum ; answer ++ ; } } System . out . println ( answer ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; if ( s . charAt ( 0 ) == 'A' ) { int i = 1 ; int cnt = 0 ; int index = 0 ; for ( int j = 2 ; j < s . length ( ) - 1 ; j ++ ) { if ( s . charAt ( j ) == 'C' ) { cnt ++ ; index = j ; } } if ( cnt == 1 ) { boolean ok = true ; for ( int i = 1 ; i < s . length ( ) ; i ++ ) { if ( i == index ) continue ; if ( Character . isUpperCase ( s . charAt ( i ) ) ) ok = false ; } if ( ok ) { System . out . println ( " AC " ) ; return ; } } } System . out . println ( " WA " ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner a = new Scanner ( System . in ) ; int n = a . nextInt ( ) ; int [ ] A = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { int i = 0 ; A [ i ] = a . nextInt ( ) ; } int flag = 1 ; int count = 0 ; while ( flag == 1 ) { flag = 0 ; for ( int i = n - 1 ; i >= 1 ; i -- ) { if ( A [ i ] < A [ i - 1 ] ) { A [ i ] = A [ i ] + A [ i - 1 ] ; A [ i - 1 ] = A [ i ] - A [ i - 1 ] ; A [ i ] = A [ i ] - A [ i - 1 ] ; flag = 1 ; count ++ ; } } } for ( int i = 0 ; i < n ; i ++ ) { System . out . print ( A [ i ] ) ; if ( i < n - 1 ) { System . out . print ( " " ) ; } } System . out . println ( ) ; System . out . println ( count ) ; } } +import java . util . HashSet ; import java . util . Scanner ; import java . util . Set ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; sc . nextLine ( ) ; String word = null ; String prevWord = null ; Set < String > wordSet = new HashSet < > ( ) ; boolean failed = false ; while ( sc . hasNextLine ( ) ) { word = sc . nextLine ( ) ; if ( ! wordSet . add ( word ) ) { failed = true ; break ; } if ( prevWord != null ) { boolean chained = ( prevWord . charAt ( prevWord . length ( ) - 1 ) == word . charAt ( 0 ) ) ; if ( ! chained ) { boolean failed = false ; failed = true ; break ; } } prevWord = word ; } System . out . println ( failed ? " No " : " Yes " ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; String s = scan . nextLine ( ) ; long sum = 0 ; int l = s . length ( ) ; for ( int i = 0 ; i < l ; i ++ ) { int num = Character . getNumericValue ( s . charAt ( i ) ) ; sum += num ; } if ( sum % 9 == 0 ) { System . out . println ( " Yes " ) ; } else { int i = 0 ; System . out . println ( " No " ) ; } scan . close ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String a = sc . next ( ) ; String [ ] ar = a . split ( " " ) ; for ( String s : ar ) { if ( s . equals ( " 1 " ) ) { System . out . print ( 9 ) ; } else { String s ; System . out . print ( 1 ) ; } } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int count = 0 ; int numberCount = sc . nextInt ( ) ; long [ ] numbers = new long [ numberCount ] ; for ( int i = 0 ; i < numbers . length ; i ++ ) { numbers [ i ] = sc . nextLong ( ) ; } while ( true ) { boolean end = false ; for ( int i = 0 ; i < numbers . length ; i ++ ) { if ( numbers [ i ] % 2 == 1 ) { int i = 0 ; end = true ; break ; } numbers [ i ] = numbers [ i ] / 2 ; } if ( end ) break ; count ++ ; } System . out . println ( count ) ; } } +import java . util . HashMap ; import java . util . Map ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { try ( Scanner scanner = new Scanner ( System . in ) ) { char [ ] array = scanner . next ( ) . toCharArray ( ) ; Map < Character , Integer > map = new HashMap < > ( ) ; map . put ( '0' , 0 ) ; map . put ( '1' , 0 ) ; for ( char c : array ) { char c ; if ( map . containsKey ( c ) ) { map . put ( c , map . get ( c ) + 1 ) ; } } System . out . println ( map . get ( '1' ) ) ; } } } +import java . util . Arrays ; import java . util . Comparator ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = Integer . parseInt ( sc . next ( ) ) ; int M = Integer . parseInt ( sc . next ( ) ) ; double divM = ( double ) 1 / ( 4 * M ) ; boolean judge = true ; int voteSum = 0 ; Integer [ ] arrayA = new Integer [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { arrayA [ i ] = Integer . parseInt ( sc . next ( ) ) ; voteSum += arrayA [ i ] ; } sc . close ( ) ; Arrays . sort ( arrayA , Comparator . reverseOrder ( ) ) ; for ( int i = 0 ; i < M ; i ++ ) { int i = 0 ; if ( ( double ) arrayA [ i ] / voteSum < divM ) { judge = false ; break ; } } System . out . println ( judge ? " Yes " : " No " ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner input = new Scanner ( System . in ) ; char [ ] S ; int count = 0 ; S = input . next ( ) . toCharArray ( ) ; for ( int i = 0 ; i < 3 ; i ++ ) { if ( S [ i ] == S [ i + 1 ] ) { int i = 0 ; System . out . println ( " Bad " ) ; count ++ ; break ; } } if ( count == 0 ) { System . out . println ( " Good " ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { char c ; Scanner sc = new Scanner ( System . in ) ; String n = sc . next ( ) ; String r = " " ; for ( char c : n . toCharArray ( ) ) { r += solve ( c ) ; } System . out . print ( r ) ; } static char solve ( char c ) { switch ( c ) { case '1' : return '9' ; case '9' : return '1' ; default : return c ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; while ( true ) { String line = sc . next ( ) ; if ( line . equals ( " - " ) ) { break ; } ; int n = line . length ( ) ; char [ ] str = new char [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { str [ i ] = line . charAt ( i ) ; } int m = sc . nextInt ( ) ; for ( int i = 0 ; i < m ; i ++ ) { int h = sc . nextInt ( ) ; char [ ] hoge = new char [ n ] ; System . arraycopy ( str , 0 , hoge , 0 , n ) ; for ( int j = 0 ; j < n ; j ++ ) { str [ j ] = hoge [ ( j + h ) % n ] ; } } for ( int k = 0 ; k < n ; k ++ ) { int k = 0 ; System . out . print ( str [ k ] ) ; } System . out . println ( " " ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int a = Integer . parseInt ( sc . next ( ) ) ; int b = Integer . parseInt ( sc . next ( ) ) ; int c = Integer . parseInt ( sc . next ( ) ) ; int x = Integer . parseInt ( sc . next ( ) ) ; int count = 0 ; for ( int i = 0 ; i <= a ; i ++ ) { if ( i * 500 + b * 100 + c * 50 < x ) continue ; for ( int j = 0 ; j <= b ; j ++ ) { if ( i * 500 + j * 100 + c * 50 < x ) continue ; for ( int k = 0 ; k <= c ; k ++ ) { int k = 0 ; if ( i * 500 + j * 100 + k * 50 == x ) { count ++ ; break ; } } } } System . out . println ( count ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner s = new Scanner ( System . in ) ; int n = s . nextInt ( ) ; int [ ] check = { 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 } ; String ans = " No " ; if ( n >= 10 ) { for ( int i = 0 ; i < check . length ; i ++ ) { int i = 0 ; if ( n % check [ i ] == 0 && n / check [ i ] < 10 ) { ans = " Yes " ; break ; } } } else { ans = " Yes " ; } System . out . println ( ans ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { String s ; Scanner sc = new Scanner ( System . in ) ; int a = getInputInteger ( sc ) ; int b = getInputInteger ( sc ) ; if ( a % 2 == 0 || b % 2 == 0 ) { output ( " Even " ) ; } else { output ( " Odd " ) ; } } public static String getInputString ( Scanner sc ) { return sc . next ( ) ; } public static int getInputInteger ( Scanner sc ) { return Integer . parseInt ( sc . next ( ) ) ; } public static void output ( String ... params ) { boolean isInit = true ; String str = " " ; for ( String s : params ) { if ( ! isInit ) { str += " " ; } str += s ; isInit = false ; } System . out . println ( str ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { StringBuilder sb = new StringBuilder ( ) ; Scanner as = new Scanner ( System . in ) ; int N = 0 ; int tre = 0 ; int count = 0 ; int [ ] A ; Boolean flag = true ; N = Integer . parseInt ( as . next ( ) ) ; A = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { A [ i ] = Integer . parseInt ( as . next ( ) ) ; } while ( flag ) { flag = false ; for ( int j = N - 1 ; j >= 1 ; j -- ) { if ( A [ j ] < A [ j - 1 ] ) { tre = A [ j ] ; A [ j ] = A [ j - 1 ] ; A [ j - 1 ] = tre ; flag = true ; count ++ ; } } } for ( int i = 0 ; i < N ; i ++ ) { if ( i != N - 1 ) { sb . append ( A [ i ] ) . append ( ' ' ) ; } else { int i = 0 ; sb . append ( A [ i ] ) ; } } System . out . println ( sb . toString ( ) ) ; sb . setLength ( 0 ) ; sb . append ( count ) ; System . out . println ( sb . toString ( ) ) ; } } +import java . io . * ; import java . util . StringTokenizer ; public class Main { public static void main ( String [ ] args ) throws IOException { int tmp ; BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String s = br . readLine ( ) ; StringTokenizer st = new StringTokenizer ( s , " " ) ; int a = Integer . parseInt ( st . nextToken ( ) ) ; int b = Integer . parseInt ( st . nextToken ( ) ) ; int c = Integer . parseInt ( st . nextToken ( ) ) ; if ( a > b ) { tmp = a ; a = b ; b = tmp ; } if ( b > c ) { tmp = b ; b = c ; c = tmp ; } if ( a > b ) { int c = Integer . parseInt ( st . nextToken ( ) ) ; tmp = a ; a = b ; b = tmp ; } System . out . println ( a + " " + b + " " + c ) ; } } +import java . util . HashMap ; import java . util . Map ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String a = sc . next ( ) ; Map < String , String > map = new HashMap < String , String > ( ) ; map . put ( " ABC " , " ARC " ) ; map . put ( " ARC " , " ABC " ) ; if ( map . containsKey ( a ) ) { System . out . println ( map . get ( a ) ) ; } else { Map < String , String > map = new HashMap < String , String > ( ) ; System . out . println ( " もう一度やり直して下さい"); } } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws IOException { int a = 0 ; int b = 0 ; int c = 0 ; int answer = 0 ; BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String str = br . readLine ( ) ; String [ ] result = str . split ( " " ) ; a = Integer . parseInt ( result [ 0 ] ) ; b = Integer . parseInt ( result [ 1 ] ) ; c = Integer . parseInt ( result [ 2 ] ) ; for ( int i = a ; i <= b ; i += 1 ) { int i = a ; if ( c % i == 0 ) { answer ++ ; } } System . out . println ( answer ) ; } } +import java . io . IOException ; import java . util . ArrayList ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws IOException { Scanner scanner = new Scanner ( System . in ) ; long k = scanner . nextLong ( ) ; long n = scanner . nextLong ( ) ; long max = 0 ; long sum = 0 ; long first = 0 ; long previous = 0 ; for ( long i = 0 ; i < n ; i ++ ) { long a = scanner . nextLong ( ) ; if ( i == 0 ) { long saigo = k - sum + first ; max = a ; sum = a ; first = a ; previous = a ; } else { long aida = a - previous ; previous = a ; sum = sum + aida ; if ( aida > max ) { max = aida ; } } } long saigo = k - sum + first ; if ( saigo > max ) { max = saigo ; } System . out . println ( k - max ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 1 ; Scanner scanner = new Scanner ( System . in ) ; int n = scanner . nextInt ( ) ; int a = scanner . nextInt ( ) ; int b = scanner . nextInt ( ) ; int total = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { int one = i % 10 ; int ten = Math . floorDiv ( i % 100 , 10 ) ; int hundred = Math . floorDiv ( i % 1000 , 100 ) ; int thousand = Math . floorDiv ( i % 10000 , 1000 ) ; int man = ( i == 10000 ) ? 1 : 0 ; int sum = one + ten + hundred + thousand + man ; if ( a <= sum && sum <= b ) { total += i ; } } System . out . println ( total ) ; } } +import java . util . * ; import java . lang . * ; import java . io . * ; class Main { public static long gcd ( long a , long b ) { if ( b == 0 ) return a ; return gcd ( b , a % b ) ; } public static void main ( String [ ] args ) throws java . lang . Exception { long b = s . nextLong ( ) ; Scanner s = new Scanner ( System . in ) ; long a = s . nextLong ( ) ; long b = s . nextLong ( ) ; long k = gcd ( a , b ) ; System . out . println ( ( a * b ) / k ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String answer = " " ; final String S = sc . next ( ) ; char [ ] s = S . toCharArray ( ) ; char [ ] sA = { s [ 0 ] , s [ 1 ] } ; char [ ] sB = { s [ 2 ] , s [ 3 ] } ; int a = Integer . parseInt ( String . valueOf ( sA ) ) ; int b = Integer . parseInt ( String . valueOf ( sB ) ) ; if ( a == 0 && b == 0 ) { answer = " NA " ; } else if ( a == 0 ) { if ( b <= 12 ) { answer = " YYMM " ; } else { answer = " NA " ; } } else if ( b == 0 ) { if ( a <= 12 ) { answer = " MMYY " ; } else { answer = " NA " ; } } else if ( a <= 12 ) { if ( b <= 12 ) { answer = " AMBIGUOUS " ; } else { int b = Integer . parseInt ( String . valueOf ( sB ) ) ; answer = " MMYY " ; } } else { if ( b <= 12 ) { answer = " YYMM " ; } else { answer = " NA " ; } } System . out . println ( answer ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int k = scan . nextInt ( ) ; int n = scan . nextInt ( ) ; int [ ] array = new int [ 200000 ] ; for ( int i = 0 ; i < n ; i ++ ) { array [ i ] = scan . nextInt ( ) ; } int distance = 0 ; int max = array [ 0 ] + ( k - array [ n - 1 ] ) ; for ( int i = 0 ; i < n - 1 ; i ++ ) { int i = 0 ; distance = array [ i + 1 ] - array [ i ] ; if ( distance >= max ) { max = distance ; } } System . out . println ( k - max ) ; scan . close ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int cnt = 0 ; for ( int i = a ; i <= n ; i ++ ) { int total = x % 10 ; int x = i ; int total = x % 10 ; while ( x >= 10 ) { x /= 10 ; total += x % 10 ; } if ( total >= a && total <= b ) cnt += i ; } System . out . println ( cnt ) ; } } +import java . util . Scanner ; class Main { public static void main ( final String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String x = sc . next ( ) ; double xDouble = Double . valueOf ( x ) ; int ans = 0 ; double tot = 100 ; while ( tot < xDouble ) { double tot = 100 ; tot = Math . floor ( tot * 1.01 ) ; ans ++ ; } System . out . println ( ans ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; for ( int i = 1 ; i <= 10000 ; i ++ ) { int x = sc . nextInt ( ) ; int y = sc . nextInt ( ) ; if ( x == 0 && y == 0 ) { break ; } else { int y = sc . nextInt ( ) ; System . out . println ( Math . min ( x , y ) + " " + Math . max ( x , y ) ) ; } } sc . close ( ) ; } } +import java . util . ArrayList ; import java . util . Arrays ; import java . util . HashSet ; import java . util . List ; 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 ( ) ; String [ ] str = new String [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { str [ i ] = sc . next ( ) ; } List < String > listA = new ArrayList < String > ( Arrays . asList ( str ) ) ; List < String > listB = new ArrayList < String > ( new HashSet < > ( listA ) ) ; if ( listA . size ( ) == listB . size ( ) ) { System . out . println ( " YES " ) ; } else { int i = 0 ; System . out . println ( " NO " ) ; } } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws IOException { String s ; BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String [ ] line = br . readLine ( ) . split ( " " ) ; int h = Integer . parseInt ( line [ 0 ] ) ; int n = Integer . parseInt ( line [ 1 ] ) ; line = br . readLine ( ) . split ( " " ) ; br . close ( ) ; boolean flg = false ; for ( String s : line ) { if ( ( h -= Integer . parseInt ( s ) ) <= 0 ) { flg = true ; break ; } } if ( flg ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int n , m , i , j ; int [ ] [ ] a = new int [ 100 ] [ 100 ] ; int [ ] b = new int [ 100 ] ; int [ ] c = new int [ 100 ] ; n = scan . nextInt ( ) ; m = scan . nextInt ( ) ; for ( i = 0 ; i < n ; i ++ ) { for ( j = 0 ; j < m ; j ++ ) { a [ i ] [ j ] = scan . nextInt ( ) ; } } for ( j = 0 ; j < m ; j ++ ) { b [ j ] = scan . nextInt ( ) ; } for ( i = 0 ; i < n ; i ++ ) { int [ ] c = new int [ 100 ] ; for ( j = 0 ; j < m ; j ++ ) { c [ i ] += a [ i ] [ j ] * b [ j ] ; } System . out . println ( c [ i ] ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner stdIn = new Scanner ( System . in ) ; int n = stdIn . nextInt ( ) ; char [ ] s = stdIn . next ( ) . toCharArray ( ) ; int [ ] ans = new int [ s . length ] ; char [ ] words = { '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' } ; int count = 0 ; for ( int i = 0 ; i < s . length ; i ++ ) { int i = 0 ; for ( int j = 0 ; j < words . length ; j ++ ) { if ( s [ i ] == words [ j ] ) { ans [ count ++ ] = j ; } } } for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < ans . length ; j ++ ) { if ( ans [ j ] == 25 ) { ans [ j ] = 0 ; } else { ans [ j ] ++ ; } } } for ( int i = 0 ; i < ans . length ; i ++ ) { System . out . print ( words [ ans [ i ] ] ) ; } } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws IOException { int i = 0 ; BufferedReader input = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String str = input . readLine ( ) ; String answer = " " ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { if ( String . valueOf ( str . charAt ( i ) ) . equals ( " B " ) && answer . length ( ) != 0 ) { answer = answer . substring ( 0 , answer . length ( ) - 1 ) ; } else if ( String . valueOf ( str . charAt ( i ) ) . equals ( " 0 " ) || String . valueOf ( str . charAt ( i ) ) . equals ( " 1 " ) ) { answer = answer + str . charAt ( i ) ; } } System . out . println ( answer ) ; } } +import java . util . ArrayList ; import java . util . List ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; String [ ] str = ( sc . next ( ) ) . split ( " " ) ; sc . close ( ) ; List < String > list = new ArrayList < String > ( ) ; int cnt = 0 ; for ( int i = 0 ; i < 4 ; i ++ ) { if ( list . contains ( str [ i ] ) ) { cnt ++ ; } else { list . add ( str [ i ] ) ; } } if ( list . size ( ) > 2 ) { System . out . println ( " No " ) ; } else { if ( cnt == 2 ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String str ; long [ ] ans = new long [ 2 ] ; while ( ( str = br . readLine ( ) ) != null ) { String [ ] aa = str . split ( " " ) ; long [ ] a = new long [ aa . length ] ; for ( int i = 0 ; i < aa . length ; i ++ ) { int i = 0 ; a [ i ] = Long . parseLong ( aa [ i ] ) ; } ans [ 0 ] = gcd ( a [ 0 ] , a [ 1 ] ) ; ans [ 1 ] = ( a [ 0 ] / ans [ 0 ] ) * a [ 1 ] ; System . out . printf ( " %d %d \n " , ans [ 0 ] , ans [ 1 ] ) ; } } static long gcd ( long a , long b ) { if ( b > 0 ) { return gcd ( b , a % b ) ; } else { return a ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; String ans = " " ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { String temp = s . substring ( i , i + 1 ) ; if ( temp . equals ( " 0 " ) ) { ans += " 0 " ; } else if ( temp . equals ( " 1 " ) ) { int i = 0 ; ans += " 1 " ; } else { if ( ans . length ( ) > 0 ) { ans = ans . substring ( 0 , ans . length ( ) - 1 ) ; } } } System . out . println ( ans ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner cin = new Scanner ( System . in ) ; int a , b , c ; a = cin . nextInt ( ) ; b = cin . nextInt ( ) ; c = cin . nextInt ( ) ; int res = serch_divisor_number ( a , b , c ) ; System . out . println ( res ) ; } private static int serch_divisor_number ( int a , int b , int c ) { int i = a ; int m = 0 ; for ( int i = a ; i <= b ; i ++ ) { if ( c % i == 0 ) m ++ ; } return ( m ) ; } } +import java . io . * ; public class Main { public static void main ( String [ ] args ) throws IOException { int m = 0 , f = 0 , r = 0 ; BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; while ( true ) { String str = br . readLine ( ) ; String [ ] i = str . split ( " " ) ; m = Integer . parseInt ( i [ 0 ] ) ; f = Integer . parseInt ( i [ 1 ] ) ; r = Integer . parseInt ( i [ 2 ] ) ; if ( m == ( - 1 ) && f == ( - 1 ) && r == ( - 1 ) ) { break ; } if ( m == ( - 1 ) || f == ( - 1 ) ) { System . out . println ( " F " ) ; } else if ( m + f >= 80 ) { System . out . println ( " A " ) ; } else if ( m + f >= 65 ) { System . out . println ( " B " ) ; } else if ( m + f >= 50 ) { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; System . out . println ( " C " ) ; } else if ( m + f >= 30 ) { if ( r >= 50 ) { System . out . println ( " C " ) ; } else { System . out . println ( " D " ) ; } } else { System . out . println ( " F " ) ; } } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = a ; run ( ) ; } static void run ( ) { Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int c = sc . nextInt ( ) ; int ans = isDivisor ( a , b , c ) ; System . out . println ( ans ) ; } static int isDivisor ( int a , int b , int c ) { int ans = 0 ; for ( int i = a ; i <= b ; i ++ ) { if ( c % i == 0 ) { ans ++ ; } } return ans ; } } +import java . util . ArrayList ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int a ; ArrayList < String > list = new ArrayList < String > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { a = sc . nextInt ( ) ; list . add ( String . valueOf ( a ) ) ; list . add ( " " ) ; } list . remove ( list . size ( ) - 1 ) ; for ( int i = 0 ; i < list . size ( ) ; i ++ ) { int i = 0 ; System . out . print ( list . get ( list . size ( ) - 1 - i ) ) ; } System . out . println ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int w = Integer . parseInt ( scanner . nextLine ( ) ) ; int n = Integer . parseInt ( scanner . nextLine ( ) ) ; int [ ] a = new int [ n ] ; int [ ] b = new int [ n ] ; int [ ] z = new int [ w ] ; for ( int i = 0 ; i < n ; i ++ ) { String s = scanner . nextLine ( ) ; String [ ] t = s . split ( " , " ) ; a [ i ] = Integer . parseInt ( t [ 0 ] ) ; b [ i ] = Integer . parseInt ( t [ 1 ] ) ; } for ( int i = 0 ; i < w ; i ++ ) { int i = 0 ; int p = i + 1 ; for ( int j = 0 ; j < n ; j ++ ) { if ( p == a [ j ] ) { p = b [ j ] ; } else if ( p == b [ j ] ) { p = a [ j ] ; } } z [ p - 1 ] = i + 1 ; } for ( int i = 0 ; i < w ; i ++ ) { System . out . println ( z [ i ] ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; String a = sc . next ( ) ; String b = " " ; String [ ] data = a . split ( " " ) ; for ( int i = 0 ; data . length > i ; i ++ ) { if ( i == 3 ) { data [ i ] = " 8 " ; b = b + data [ i ] ; } else { b = b + data [ i ] ; } } System . out . println ( b ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { try ( Scanner sc = new Scanner ( System . in ) ) { Scanner sc = new Scanner ( System . in ) ; solve ( sc ) ; } } public static void solve ( Scanner sc ) { char [ ] x = sc . next ( ) . toCharArray ( ) ; x [ 3 ] = '8' ; System . out . println ( x ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int k = 0 ; Scanner sc = new Scanner ( System . in ) ; int A = sc . nextInt ( ) ; int B = sc . nextInt ( ) ; int C = sc . nextInt ( ) ; int X = sc . nextInt ( ) ; int ans = 0 ; for ( int i = 0 ; i <= A ; i ++ ) { int ans1 = + 500 * i ; for ( int j = 0 ; j <= B ; j ++ ) { int ans2 = + 100 * j ; for ( int k = 0 ; k <= C ; k ++ ) { int ans3 = + 50 * k ; if ( ans1 + ans2 + ans3 == X ) { ans ++ ; } } } } System . out . print ( ans ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int yen = 1000 ; Scanner sc = new Scanner ( System . in ) ; int payment = sc . nextInt ( ) ; int yen = 1000 ; while ( yen < payment ) { yen = yen + 1000 ; } System . out . println ( yen - payment ) ; } } +import java . util . Arrays ; import java . util . Scanner ; public class Main { static Scanner scanner ; public static void main ( String [ ] args ) { scanner = new Scanner ( System . in ) ; int n = gi ( ) ; int c = 0 ; for ( int i = 1 ; i <= n ; i += 2 ) { if ( yakusuC ( i ) == 8 ) { c ++ ; } } System . out . print ( c ) ; } public static int yakusuC ( int n ) { int i = 1 ; StringBuilder sb = new StringBuilder ( ) ; int c = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { if ( n % i == 0 ) { c ++ ; } } return c ; } public static long d ( long n ) { String a = String . valueOf ( n ) ; return ( long ) a . length ( ) ; } public static String gs ( ) { return scanner . next ( ) ; } public static int gi ( ) { return Integer . parseInt ( scanner . next ( ) ) ; } public static long gl ( ) { return Long . parseLong ( scanner . next ( ) ) ; } public static double gd ( ) { return Double . parseDouble ( scanner . next ( ) ) ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; String str = sc . nextLine ( ) ; String [ ] str_split = str . split ( " " , 0 ) ; int [ ] nums = new int [ str_split . length ] ; int top = 0 ; for ( int i = 0 ; i < str_split . length ; i ++ ) { switch ( str_split [ i ] . charAt ( 0 ) ) { case '+' : top -- ; nums [ top - 1 ] = nums [ top - 1 ] + nums [ top ] ; break ; case '-' : top -- ; nums [ top - 1 ] = nums [ top - 1 ] - nums [ top ] ; break ; case '*' : top -- ; nums [ top - 1 ] = nums [ top - 1 ] * nums [ top ] ; break ; default : nums [ top ] = Integer . parseInt ( str_split [ i ] ) ; top ++ ; break ; } } System . out . println ( nums [ 0 ] ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int q = sc . nextInt ( ) ; String s = sc . next ( ) ; int [ ] l = new int [ q ] ; int [ ] r = new int [ q ] ; for ( int i = 0 ; i < q ; i ++ ) { l [ i ] = sc . nextInt ( ) ; r [ i ] = sc . nextInt ( ) ; } int [ ] at = new int [ n ] ; int t = 0 ; for ( int i = 1 ; i < n ; ++ i ) { int i = 0 ; if ( s . charAt ( i - 1 ) == 'A' & s . charAt ( i ) == 'C' ) ++ t ; at [ i ] = t ; } for ( int i = 0 ; i < q ; ++ i ) { System . out . println ( at [ r [ i ] - 1 ] - at [ l [ i ] - 1 ] ) ; } } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader in = new BufferedReader ( new InputStreamReader ( System . in ) ) ; Solver solver = new Solver ( ) ; solver . init ( ) ; solver . readHead ( in . readLine ( ) ) ; } } class Solver { int N ; int cnt ; public void init ( ) { N = 0 ; cnt = 0 ; } public void readHead ( String str ) { String [ ] strArr = str . split ( " \\ s+ " ) ; int x = Integer . parseInt ( str ) ; int [ ] prime = new int [ 200000 ] ; for ( int n = 2 ; ; n ++ ) { int n = 2 ; if ( prime [ n ] != 0 ) continue ; if ( n >= x ) { System . out . println ( n ) ; break ; } for ( int np = n + n ; np < 200000 ; np += n ) prime [ np ] = 1 ; } } public boolean hasNext ( ) { return cnt < N ; } public void readBody ( String str ) { cnt ++ ; } public void solve ( ) { } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; while ( true ) { char b ; String a = scanner . nextLine ( ) ; if ( a . equals ( " 0 " ) ) break ; int sum = 0 ; for ( char b : a . toCharArray ( ) ) { sum += Integer . parseInt ( String . valueOf ( b ) ) ; } System . out . println ( sum ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] nlist = new int [ n ] ; for ( int i = 1 ; i <= n ; i ++ ) { int i = 0 ; int a = sc . nextInt ( ) ; nlist [ a - 1 ] = i ; } for ( int i = 0 ; i < n ; i ++ ) { System . out . print ( nlist [ i ] + " " ) ; } sc . close ( ) ; } } +import java . util . * ; import java . io . * ; import java . lang . * ; public class Main { public static void main ( String [ ] args ) { int [ ] arr = new int [ 5 ] ; Scanner sc = new Scanner ( System . in ) ; for ( int i = 0 ; i < 5 ; i ++ ) { int i = 0 ; arr [ i ] = sc . nextInt ( ) ; if ( arr [ i ] == 0 ) System . out . println ( i + 1 ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int wk = 0 ; int ans = 0 ; HashMap < Integer , Integer > map = new HashMap < Integer , Integer > ( ) ; for ( int i = 2 ; i <= N ; i ++ ) { wk = sc . nextInt ( ) ; if ( map . containsKey ( wk ) ) { map . put ( wk , map . get ( wk ) + 1 ) ; } else { map . put ( wk , 1 ) ; } } Object [ ] mapkey = map . keySet ( ) . toArray ( ) ; Arrays . sort ( mapkey ) ; for ( int i = 1 ; i <= N ; i ++ ) { if ( map . containsKey ( i ) ) { int i = 1 ; System . out . println ( map . get ( i ) ) ; } else { System . out . println ( ans ) ; } } } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . io . OutputStreamWriter ; import java . io . PrintWriter ; import java . util . StringTokenizer ; public class Main { static PrintWriter out ; public static void main ( String [ ] args ) throws IOException { out = new PrintWriter ( new OutputStreamWriter ( System . out ) ) ; CF_Reader in = new CF_Reader ( ) ; long yen = in . nextLong ( ) ; long rem = yen % 500 ; long total = ( yen - rem ) * 2 ; total += ( rem - ( rem % 5 ) ) ; out . println ( total ) ; out . close ( ) ; } static class CF_Reader { BufferedReader br ; StringTokenizer st ; public CF_Reader ( ) throws IOException { br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; } String next ( ) throws IOException { while ( st == null || ! st . hasMoreTokens ( ) ) st = new StringTokenizer ( br . readLine ( ) . trim ( ) ) ; return st . nextToken ( ) ; } long nextLong ( ) throws IOException { return Long . parseLong ( next ( ) ) ; } int nextInt ( ) throws IOException { return Integer . parseInt ( next ( ) ) ; } double nextDouble ( ) throws IOException { return Double . parseDouble ( next ( ) ) ; } char nextCharacter ( ) throws IOException { return next ( ) . charAt ( 0 ) ; } String nextLine ( ) throws IOException { return br . readLine ( ) . trim ( ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int j = n - 1 ; int [ ] arr = new int [ 100 ] ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; for ( int i = 0 ; i < n ; i ++ ) { arr [ i ] = sc . nextInt ( ) ; } for ( int j = n - 1 ; j > 0 ; j -- ) { System . out . print ( arr [ j ] + " " ) ; } System . out . println ( arr [ 0 ] ) ; sc . close ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int [ ] h = new int [ N ] ; int count = 0 ; for ( int i = 0 ; i < N ; i ++ ) { h [ i ] = sc . nextInt ( ) ; } int a = 0 ; int b = 0 ; L : while ( a <= N - 1 && b <= N - 1 ) { if ( h [ a ] == 0 ) { a ++ ; continue ; } b = a ; while ( b <= N - 1 ) { int i = a ; if ( h [ b ] != 0 && b != N - 1 ) { b ++ ; continue ; } else { for ( int i = a ; i <= b ; i ++ ) { h [ i ] -- ; if ( h [ i ] < 0 ) { h [ i ] = 0 ; } } } count ++ ; continue L ; } } System . out . println ( count ) ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; int [ ] rec = new int [ 26 ] ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { int i = 0 ; rec [ s . charAt ( i ) - 'a' ] ++ ; } String ans = " Yes " ; for ( int i = 0 ; i < 26 ; i ++ ) { if ( rec [ i ] % 2 == 1 ) ans = " No " ; } System . out . println ( ans ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int p = sc . nextInt ( ) ; int q = sc . nextInt ( ) ; int result = 0 ; for ( int i = 0 ; i < p ; i ++ ) { int result = 0 ; double x1 = sc . nextDouble ( ) ; double x2 = sc . nextDouble ( ) ; double dis = Math . sqrt ( Math . pow ( x1 , 2 ) + Math . pow ( x2 , 2 ) ) ; if ( dis <= q ) result ++ ; } System . out . println ( result ) ; } } +import java . util . * ; import java . util . PriorityQueue ; class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int num = scan . nextInt ( ) ; boolean flag = true ; PriorityQueue in = new PriorityQueue ( ) ; for ( int x = 0 ; x < num ; x ++ ) { int input = scan . nextInt ( ) ; in . offer ( input ) ; } int before = ( int ) in . poll ( ) ; int after ; for ( int x = 1 ; x < num ; x ++ ) { after = ( int ) in . poll ( ) ; if ( before == after ) { flag = false ; break ; } else { int after ; before = after ; } } if ( flag ) { System . out . println ( " YES " ) ; } else { System . out . println ( " NO " ) ; } } } +import java . util . ArrayList ; import java . util . List ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; Integer s = Integer . parseInt ( sc . next ( ) ) ; List < Integer > list = new ArrayList < > ( ) ; list . add ( s ) ; int result = 0 ; boolean doContinue = true ; for ( int i = 0 ; doContinue ; i ++ ) { if ( s % 2 == 0 ) { if ( list . contains ( s / 2 ) ) { int i = 0 ; result = i + 2 ; doContinue = false ; } else { s = s / 2 ; list . add ( s ) ; } } else { if ( list . contains ( 3 * s + 1 ) ) { result = i + 2 ; doContinue = false ; } else { s = 3 * s + 1 ; list . add ( s ) ; } } } System . out . println ( result ) ; sc . close ( ) ; } } +import static java . lang . System . out ; import java . io . File ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { new Main ( ) . reverse ( ) ; } public void reverse ( ) { try ( Scanner scan = new Scanner ( System . in ) ) { reverseStr ( scan ) ; } catch ( Exception e ) { System . exit ( 0 ) ; } } public void reverse ( String inputDataPath ) { try ( Scanner scan = new Scanner ( new File ( inputDataPath ) ) ) { reverseStr ( scan ) ; } catch ( Exception e ) { Scanner scan = new Scanner ( new File ( inputDataPath ) ) ; e . printStackTrace ( ) ; } } private void reverseStr ( Scanner scan ) { StringBuffer str = new StringBuffer ( scan . nextLine ( ) ) ; out . println ( str . reverse ( ) ) ; } } +import java . util . Scanner ; public class Main { public static int gcd ( int a , int b ) { if ( b == 0 ) return a ; return gcd ( b , a % b ) ; } public static int gcd_roop ( int a , int b ) { while ( true ) { int a , b ; if ( b == 0 ) return a ; int t ; t = a ; a = b ; b = t % b ; } } public static void main ( String [ ] args ) { int a , b ; Scanner scan = new Scanner ( System . in ) ; a = scan . nextInt ( ) ; b = scan . nextInt ( ) ; System . out . println ( gcd_roop ( a , b ) ) ; scan . close ( ) ; } } +import java . util . ArrayList ; import java . util . Arrays ; import java . util . Collections ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; ArrayList < Integer > A = new ArrayList < Integer > ( ) ; for ( int i = 0 ; i < N ; i ++ ) A . add ( sc . nextInt ( ) ) ; ArrayList < Integer > output = new ArrayList < Integer > ( ) ; for ( int i = 0 ; i < N ; i ++ ) output . add ( 0 ) ; for ( int i = 0 ; i < N ; i ++ ) { int AIndex = A . get ( i ) - 1 ; output . set ( AIndex , i + 1 ) ; } for ( int i = 0 ; i < N ; i ++ ) { int i = 0 ; System . out . print ( output . get ( i ) + " " ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; try ( Scanner sc = new Scanner ( System . in ) ) { int A = Integer . parseInt ( sc . next ( ) ) ; int B = Integer . parseInt ( sc . next ( ) ) ; int T = Integer . parseInt ( sc . next ( ) ) ; System . out . println ( ( T / A ) * B ) ; } } } +import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int su ; int num = 0 ; String mark ; Boolean [ ] s = new Boolean [ 52 ] ; Arrays . fill ( s , false ) ; for ( int i = 0 ; i < n ; i ++ ) { mark = sc . next ( ) ; su = sc . nextInt ( ) ; if ( mark . equals ( " S " ) ) num = 0 ; else if ( mark . equals ( " H " ) ) num = 13 ; else if ( mark . equals ( " C " ) ) num = 26 ; else if ( mark . equals ( " D " ) ) num = 39 ; s [ num + su - 1 ] = true ; } for ( int i = 0 ; i < 52 ; i ++ ) { if ( i < 13 && s [ i ] == false ) { System . out . println ( " S " + ( i + 1 ) ) ; } else if ( i < 26 && s [ i ] == false ) { int i = 0 ; System . out . println ( " H " + ( i - 12 ) ) ; } else if ( i < 39 && s [ i ] == false ) { System . out . println ( " C " + ( i - 25 ) ) ; } else if ( i < 52 && s [ i ] == false ) { System . out . println ( " D " + ( i - 38 ) ) ; } else continue ; } } } +import java . util . ArrayList ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = Integer . parseInt ( sc . next ( ) ) ; ArrayList < String > shiritoriList = new ArrayList < > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { shiritoriList . add ( sc . next ( ) ) ; } sc . close ( ) ; ArrayList < String > checkList = new ArrayList < > ( ) ; for ( int i = 0 ; i < shiritoriList . size ( ) ; i ++ ) { String word = shiritoriList . get ( i ) ; if ( i != 0 ) { String formerWords = shiritoriList . get ( i - 1 ) ; char lastWord = formerWords . charAt ( formerWords . length ( ) - 1 ) ; if ( lastWord != word . charAt ( 0 ) ) { String word = shiritoriList . get ( i ) ; System . out . println ( " No " ) ; return ; } if ( checkList . contains ( word ) ) { System . out . println ( " No " ) ; return ; } } checkList . add ( word ) ; } System . out . println ( " Yes " ) ; return ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i , n , q , tail , head , hz , notime = 0 ; String hzn ; Scanner sc = new Scanner ( System . in ) ; n = sc . nextInt ( ) ; q = sc . nextInt ( ) ; tail = n ; head = 0 ; String [ ] name = new String [ n + 1 ] ; int [ ] time = new int [ n + 1 ] ; for ( i = 0 ; i < n ; i ++ ) { name [ i ] = sc . next ( ) ; time [ i ] = sc . nextInt ( ) ; } while ( true ) { if ( tail == head ) break ; if ( q <= time [ head ] ) { hz = time [ head ] - q ; notime += q ; } else { hz = 0 ; notime += time [ head ] ; } hzn = name [ head ] ; if ( head + 1 == n + 1 ) { head = 0 ; } else { head ++ ; } if ( hz == 0 ) { System . out . println ( hzn + " " + notime ) ; continue ; } time [ tail ] = hz ; name [ tail ] = hzn ; if ( tail + 1 == n + 1 ) { int [ ] time = new int [ n + 1 ] ; tail = 0 ; } else { tail ++ ; } } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; while ( true ) { int sum = 0 , i ; String x = sc . next ( ) ; if ( x . equals ( " 0 " ) ) break ; int sum = 0 , i ; for ( i = 0 ; i < x . length ( ) ; i ++ ) { sum = sum + x . charAt ( i ) - 48 ; } System . out . printf ( " %d \n " , sum ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int temp = sc . nextInt ( ) ; Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int max = 0 ; int count = 0 ; for ( int i = 0 ; i < N ; i ++ ) { int temp = sc . nextInt ( ) ; if ( max <= temp ) { count ++ ; max = temp ; } } System . out . println ( count ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int c = sc . nextInt ( ) ; int k = sc . nextInt ( ) ; int powk = ( ( int ) Math . pow ( 2 , k ) ) ; int answer = 0 ; if ( a > b && a > c ) { int answer = 0 ; answer = a * powk + b + c ; } else if ( b > a && b > c ) { answer = b * powk + a + c ; } else { answer = c * powk + a + b ; } System . out . println ( answer ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; final int NUM = scan . nextInt ( ) ; final int M = scan . nextInt ( ) ; int [ ] [ ] codes = new int [ NUM ] [ M ] ; int [ ] rate = new int [ M ] ; int bonus = scan . nextInt ( ) ; for ( int i = 0 ; i < M ; i ++ ) { int j = 0 ; rate [ i ] = scan . nextInt ( ) ; } for ( int i = 0 ; i < NUM ; i ++ ) { for ( int j = 0 ; j < M ; j ++ ) { codes [ i ] [ j ] = scan . nextInt ( ) ; } } int count = 0 ; for ( int i = 0 ; i < NUM ; i ++ ) { int sum = 0 ; for ( int j = 0 ; j < M ; j ++ ) { sum += codes [ i ] [ j ] * rate [ j ] ; } sum += bonus ; if ( sum > 0 ) { count ++ ; } } System . out . println ( count ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; Map < String , Integer > map = new HashMap < String , Integer > ( ) ; int max = 1 ; for ( int i = 0 ; i < N ; i ++ ) { String temp = sc . next ( ) ; if ( map . containsKey ( temp ) ) { int value = map . get ( temp ) + 1 ; map . put ( temp , value ) ; if ( value > max ) { max = value ; } } else { int i = 0 ; map . put ( temp , 1 ) ; } } List maxstr = new ArrayList < String > ( ) ; for ( String key : map . keySet ( ) ) { if ( map . get ( key ) == max ) { maxstr . add ( key ) ; } } Collections . sort ( maxstr ) ; for ( int i = 0 ; i < maxstr . size ( ) ; i ++ ) { System . out . println ( maxstr . get ( i ) ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner ob = new Scanner ( System . in ) ; String patt = ob . next ( ) ; int result = 0 ; for ( int i = 0 ; i < patt . length ( ) ; i ++ ) { int temp = 0 ; for ( int j = i ; j < patt . length ( ) ; j ++ ) { int j = i ; if ( patt . charAt ( j ) == 'R' ) { temp ++ ; } else { break ; } } result = Math . max ( result , temp ) ; } System . out . println ( result ) ; ob . close ( ) ; } } +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 c = sc . nextInt ( ) ; int x = sc . nextInt ( ) ; int y = sc . nextInt ( ) ; int result = Integer . MAX_VALUE ; for ( int i = 0 ; i <= x ; i ++ ) { int rx = x - i ; int sum = 0 ; sum += i * a ; int rx = x - i ; if ( rx > y ) { sum += c * 2 * rx ; } else { int diff = y - rx ; sum += Math . min ( c * 2 * rx + diff * b , c * 2 * y ) ; } result = Math . min ( sum , result ) ; } System . out . println ( result ) ; sc . close ( ) ; } } +import java . io . * ; import java . util . * ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner in = new Scanner ( System . in ) ; int N = in . nextInt ( ) ; boolean [ ] rate = new boolean [ 8 ] ; int free = 0 ; int a ; for ( int i = 0 ; i < N ; i ++ ) { a = in . nextInt ( ) ; if ( a <= 399 ) { rate [ 0 ] = true ; } else if ( a <= 799 ) { rate [ 1 ] = true ; } else if ( a <= 1199 ) { rate [ 2 ] = true ; } else if ( a <= 1599 ) { rate [ 3 ] = true ; } else if ( a <= 1999 ) { rate [ 4 ] = true ; } else if ( a <= 2399 ) { rate [ 5 ] = true ; } else if ( a <= 2799 ) { rate [ 6 ] = true ; } else if ( a <= 3199 ) { rate [ 7 ] = true ; } else { free ++ ; } } int ans = 0 ; for ( int i = 0 ; i < rate . length ; i ++ ) { if ( rate [ i ] == true ) { ans ++ ; } } int max = ans + free ; if ( ans == 0 ) { ans = 1 ; } System . out . println ( ans + " " + max ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; long n = scanner . nextLong ( ) ; long k = scanner . nextLong ( ) ; int len = 0 ; if ( n == 0 ) { System . out . println ( 1 ) ; return ; } while ( n > 0 ) { int len = 0 ; ++ len ; n /= k ; } System . out . println ( len ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; String key = in . next ( ) . toLowerCase ( ) ; int count = 0 ; while ( true ) { int count = 0 ; String input = in . next ( ) ; if ( input . equals ( " END_OF_TEXT " ) ) break ; if ( input . equalsIgnoreCase ( key ) ) count ++ ; } System . out . println ( count ) ; } } +import java . io . * ; import java . util . * ; class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; String t = sc . next ( ) ; int c = 0 ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { for ( int j = i ; j < t . length ( ) ; j ++ ) { int j = i ; if ( s . charAt ( i ) == t . charAt ( j ) ) c ++ ; break ; } } System . out . print ( c ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int l = Integer . parseInt ( s . substring ( 2 , 4 ) ) ; Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; String ans = " " ; int f = Integer . parseInt ( s . substring ( 0 , 2 ) ) ; int l = Integer . parseInt ( s . substring ( 2 , 4 ) ) ; if ( f < 1 || 12 < f ) { if ( l < 1 || 12 < l ) { ans = " NA " ; } else { ans = " YYMM " ; } } else { if ( l < 1 || 12 < l ) { ans = " MMYY " ; } else { ans = " AMBIGUOUS " ; } } System . out . println ( ans ) ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; long [ ] h = new long [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { h [ i ] = sc . nextLong ( ) ; } long max = 0 , count = 0 ; for ( int i = 0 ; i < n - 1 ; i ++ ) { if ( h [ i ] >= h [ i + 1 ] ) { count += 1 ; } else { count = 0 ; } if ( max < count ) { max = count ; } } System . out . println ( max ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String str = sc . next ( ) ; int num = Integer . parseInt ( str ) ; if ( ( num % S ( str ) ) == 0 ) { int ct = 0 ; System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } static int S ( String str ) { int result = 0 ; for ( int ct = 0 ; ct < str . length ( ) ; ct ++ ) { result += Integer . parseInt ( str . charAt ( ct ) + " " ) ; } return result ; } } +import java . io . IOException ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws IOException { long ans = 1 ; Scanner scan = new Scanner ( System . in ) ; String input = scan . next ( ) ; char [ ] inputArray = input . toCharArray ( ) ; int ans = 0 ; for ( int i = 0 ; i < inputArray . length ; i ++ ) { if ( inputArray [ i ] == '1' ) { ans ++ ; } } System . out . println ( ans ) ; } public static String myReverse ( String pStr ) { if ( pStr . length ( ) < 1 ) { return " " ; } StringBuffer sb = new StringBuffer ( pStr ) ; return sb . reverse ( ) . toString ( ) ; } public static long myMod ( long a , long b ) { long ret = 0 ; ret = a % b ; if ( ret < 0 ) { ret += b ; } return ret ; } public static long myPowWithMod ( long kisu , long josu , long primeNumMod_0 ) { long ans = 1 ; if ( josu == 0 ) return 1 ; if ( primeNumMod_0 == 0 ) { while ( josu > 0 ) { if ( josu % 2 == 0 ) { kisu *= kisu ; josu = josu / 2 ; } else { ans *= kisu ; josu -- ; } } return ans ; } else { kisu = myMod ( kisu , primeNumMod_0 ) ; while ( josu > 0 ) { if ( josu % 2 == 0 ) { kisu *= myMod ( kisu , primeNumMod_0 ) ; josu = josu / 2 ; } else { ans *= myMod ( kisu , primeNumMod_0 ) ; josu -- ; } } return myMod ( ans , primeNumMod_0 ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { String [ ] lines = getStdin ( ) ; String str = lines [ 0 ] ; long num = Long . parseLong ( str ) ; long sum = 100 ; int count = 0 ; while ( sum < num ) { sum = sum + ( sum * 1 / 100 ) ; count ++ ; } System . out . println ( count ) ; } private static String [ ] getStdin ( ) { Scanner scanner = new Scanner ( System . in ) ; ArrayList < String > lines = new ArrayList < > ( ) ; while ( scanner . hasNext ( ) ) { ArrayList < String > lines = new ArrayList < > ( ) ; lines . add ( scanner . nextLine ( ) ) ; } return lines . toArray ( new String [ lines . size ( ) ] ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int [ ] list = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { int i = 1 ; list [ i ] = sc . nextInt ( ) ; } int count = 0 ; int Max = 0 ; for ( int i = 1 ; i < N ; i ++ ) { if ( list [ i - 1 ] >= list [ i ] ) { count ++ ; if ( Max < count ) { Max = count ; } } else { if ( Max < count ) { Max = count ; } count = 0 ; } } System . out . println ( Max ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; String [ ] W = new String [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { W [ i ] = sc . next ( ) ; } sc . close ( ) ; String result = " Yes " ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = i + 1 ; j < N ; j ++ ) { String [ ] s_ = W [ i ] . split ( " " ) ; if ( W [ i ] . equals ( W [ j ] ) ) { result = " No " ; break ; } } if ( result == " No " ) { break ; } } String start = " " ; if ( result == " Yes " ) { for ( int i = 0 ; i < N ; i ++ ) { if ( i != 0 ) { String [ ] s_ = W [ i ] . split ( " " ) ; if ( s_ [ 0 ] . equals ( start ) ) { start = s_ [ s_ . length - 1 ] ; } else { result = " No " ; break ; } } else { String [ ] s_ = W [ i ] . split ( " " ) ; start = s_ [ s_ . length - 1 ] ; } } } System . out . println ( result ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; String [ ] sArray = s . split ( " " ) ; List < String > acgt = Arrays . asList ( " A " , " C " , " G " , " T " ) ; int count = 0 ; int maxCount = 0 ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( acgt . contains ( sArray [ i ] ) ) { int i = 0 ; count ++ ; if ( count > maxCount ) { maxCount = count ; } } else { count = 0 ; } } System . out . println ( maxCount ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = Integer . parseInt ( sc . nextLine ( ) ) ; String [ ] S = sc . nextLine ( ) . split ( " " ) ; int count = 0 ; int now = 0 ; for ( int i = 0 ; i < N ; i ++ ) { int n = Integer . parseInt ( S [ i ] ) ; if ( n > now ) { int n = Integer . parseInt ( S [ i ] ) ; count += n - now ; now = n ; } else { now = n ; } } System . out . println ( count ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String str = sc . next ( ) ; int length = str . length ( ) ; for ( int i = 0 ; i < length ; i ++ ) { int i = 0 ; if ( str . charAt ( i ) == '1' ) System . out . print ( 9 ) ; else System . out . print ( 1 ) ; } } } +import java . util . HashSet ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; HashSet < Integer > set = new HashSet < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { HashSet < Integer > set = new HashSet < > ( ) ; set . add ( sc . nextInt ( ) ) ; } System . out . println ( set . size ( ) ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int n = scan . nextInt ( ) ; int [ ] a = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = scan . nextInt ( ) ; } long sum = 0 ; while ( true ) { boolean flag = true ; for ( int i = 0 ; i < n ; i ++ ) { if ( a [ i ] == 0 ) { int i = 0 ; if ( flag == false ) { break ; } } else { a [ i ] -= 1 ; flag = false ; } } if ( flag == true ) { System . out . println ( sum ) ; return ; } sum += 1 ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner scan = new Scanner ( System . in ) ; String str1 = scan . nextLine ( ) ; String [ ] str2 = new String [ str1 . length ( ) ] ; boolean flag = true ; for ( int i = 0 ; i < str1 . length ( ) ; i ++ ) { str2 [ i ] = str1 . substring ( i , i + 1 ) ; if ( i % 2 == 0 && ! str1 . substring ( i , i + 1 ) . equals ( " R " ) && ! str1 . substring ( i , i + 1 ) . equals ( " U " ) && ! str1 . substring ( i , i + 1 ) . equals ( " D " ) ) { flag = false ; } else if ( i % 2 == 1 && ! str1 . substring ( i , i + 1 ) . equals ( " L " ) && ! str1 . substring ( i , i + 1 ) . equals ( " U " ) && ! str1 . substring ( i , i + 1 ) . equals ( " D " ) ) { flag = false ; } } if ( flag ) { System . out . println ( " Yes " ) ; } else { int i = 0 ; System . out . println ( " No " ) ; } } } +import java . util . ArrayList ; import java . util . Collections ; import java . util . List ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int n = scan . nextInt ( ) ; if ( n <= 100 ) { List < Integer > list = new ArrayList < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { int ai = scan . nextInt ( ) ; if ( ai >= 0 && ai < 1000 ) { list . add ( ai ) ; } } Collections . reverse ( list ) ; for ( int i = 0 ; i < list . size ( ) ; i ++ ) { if ( i == ( list . size ( ) - 1 ) ) { System . out . println ( list . get ( i ) ) ; } else { int i = 0 ; System . out . print ( list . get ( i ) + " " ) ; } } } } } +import java . util . * ; public class Main { public static int [ ] ans ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] list = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { list [ i ] = sc . nextInt ( ) ; } int count = 0 ; boolean flag = true ; while ( flag ) { for ( int i = 0 ; i < n ; i ++ ) { int i = 0 ; if ( list [ i ] % 2 == 1 ) { flag = false ; } list [ i ] = list [ i ] / 2 ; if ( i == n - 1 && flag ) { count ++ ; } } } System . out . println ( count ) ; } } +import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int answer = 0 ; Scanner scan = new Scanner ( new BufferedReader ( new InputStreamReader ( System . in ) ) ) ; int n = scan . nextInt ( ) ; if ( n == 1 ) { System . out . println ( 1 ) ; return ; } int answer = 0 ; while ( n != 1 ) { answer += 1 ; n /= 2 ; } System . out . println ( ( int ) Math . pow ( 2 , answer ) ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int K = sc . nextInt ( ) ; int [ ] A = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { int i = 0 ; A [ i ] = sc . nextInt ( ) ; } int count = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( A [ i ] >= K ) { count ++ ; } } System . out . println ( count ) ; sc . close ( ) ; } } +import java . util . * ; import java . io . * ; class Main { public static void main ( String [ ] args ) throws IOException { int result = 0 ; try ( BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ) { String [ ] input = br . readLine ( ) . split ( " " ) ; int N = Integer . parseInt ( input [ 0 ] ) ; int M = Integer . parseInt ( input [ 1 ] ) ; int result = 0 ; if ( N > 1 ) { result += ( N * ( N - 1 ) ) / 2 ; } if ( M > 1 ) { result += ( M * ( M - 1 ) ) / 2 ; } System . out . println ( result ) ; } } } +import java . util . * ; import java . io . * ; public class Main { public static int solve ( int n , int k , int [ ] arr ) { int [ ] dp = new int [ n ] ; for ( int i = 1 ; i < n ; i ++ ) { int ans = Integer . MAX_VALUE ; for ( int j = i - 1 ; j >= 0 && ( i - j ) <= k ; j -- ) { int diff = Math . abs ( arr [ i ] - arr [ j ] ) ; ans = Math . min ( ans , diff + dp [ j ] ) ; } dp [ i ] = ans ; } return dp [ n - 1 ] ; } public static void main ( String [ ] args ) { int i = 0 ; Scanner s = new Scanner ( System . in ) ; int n = s . nextInt ( ) ; int k = s . nextInt ( ) ; int [ ] arr = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { arr [ i ] = s . nextInt ( ) ; } System . out . println ( solve ( n , k , arr ) ) ; } } +import java . util . * ; import java . io . * ; import java . math . BigInteger ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; PrintWriter out = new PrintWriter ( System . out ) ; int n = Integer . parseInt ( br . readLine ( ) ) ; int [ ] arr = new int [ n ] ; StringTokenizer st1 = new StringTokenizer ( br . readLine ( ) ) ; for ( int i = 0 ; i < n ; i ++ ) { int i = 0 ; arr [ i ] = Integer . parseInt ( st1 . nextToken ( ) ) ; } int [ ] cnt = new int [ n ] ; int max = 0 ; for ( int i = n - 2 ; i >= 0 ; i -- ) { if ( arr [ i ] >= arr [ i + 1 ] ) { cnt [ i ] = cnt [ i + 1 ] + 1 ; } } for ( int i = 0 ; i < n ; i ++ ) max = Math . max ( max , cnt [ i ] ) ; out . println ( max ) ; out . flush ( ) ; out . close ( ) ; } } +import java . io . * ; class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int cnt = Integer . parseInt ( br . readLine ( ) ) ; String [ ] str = br . readLine ( ) . split ( " " ) ; for ( int i = 0 ; i < cnt ; i ++ ) { if ( i == cnt - 1 ) { System . out . println ( str [ cnt - i - 1 ] ) ; } else { int i = 0 ; System . out . print ( str [ cnt - i - 1 ] + " " ) ; } } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int [ ] num = new int [ N + 1 ] ; for ( int i = 1 ; i <= N ; i ++ ) { num [ i ] = sc . nextInt ( ) ; } int number = 1 ; int count = 0 ; boolean key = false ; for ( int i = 1 ; i <= N ; i ++ ) { int tmp = num [ number ] ; if ( tmp == - 1 ) { int i = 1 ; System . out . println ( - 1 ) ; System . exit ( 0 ) ; } num [ number ] = - 1 ; number = tmp ; count ++ ; if ( number == 2 ) { key = true ; break ; } } System . out . println ( true ? count : - 1 ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int k = 0 ; Scanner scan = new Scanner ( System . in ) ; int n = scan . nextInt ( ) ; int [ ] b = new int [ n ] ; int [ ] f = new int [ n ] ; int [ ] r = new int [ n ] ; int [ ] v = new int [ n ] ; int [ ] [ ] [ ] num = new int [ 4 ] [ 3 ] [ 10 ] ; for ( int i = 0 ; i < n ; i ++ ) { b [ i ] = scan . nextInt ( ) ; f [ i ] = scan . nextInt ( ) ; r [ i ] = scan . nextInt ( ) ; v [ i ] = scan . nextInt ( ) ; num [ b [ i ] - 1 ] [ f [ i ] - 1 ] [ r [ i ] - 1 ] += v [ i ] ; } for ( int i = 0 ; i < 4 ; i ++ ) { for ( int j = 0 ; j < 3 ; j ++ ) { String str = " " ; for ( int k = 0 ; k < 10 ; k ++ ) { str += " " + num [ i ] [ j ] [ k ] ; } System . out . println ( str ) ; } if ( i != 3 ) { System . out . println ( " #################### " ) ; } } scan . close ( ) ; } } +import java . io . OutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . PrintWriter ; import java . util . StringTokenizer ; import java . io . IOException ; import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . io . InputStream ; public class Main { public static void main ( String [ ] args ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; MyScanner in = new MyScanner ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; B solver = new B ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class B { public void solve ( int testNumber , MyScanner in , PrintWriter out ) { String S = in . next ( ) ; int count = 0 ; for ( int i = 0 ; i < S . length ( ) / 2 ; i ++ ) { if ( S . charAt ( i ) != S . charAt ( S . length ( ) - 1 - i ) ) { count ++ ; } } out . println ( count ) ; } } static class MyScanner { private BufferedReader in ; private StringTokenizer st ; public MyScanner ( InputStream stream ) { in = new BufferedReader ( new InputStreamReader ( stream ) ) ; } public String next ( ) { while ( st == null || ! st . hasMoreTokens ( ) ) { try { String rl = in . readLine ( ) ; if ( rl == null ) { return null ; } st = new StringTokenizer ( rl ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } } return st . nextToken ( ) ; } } } +import java . io . * ; class Main { public static void main ( String [ ] args ) throws IOException { int hanako = 0 ; BufferedReader buf = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int n = Integer . parseInt ( buf . readLine ( ) ) ; String [ ] str ; int tarou = 0 ; int hanako = 0 ; for ( int i = 0 ; i < n ; i ++ ) { str = buf . readLine ( ) . split ( " " ) ; if ( str [ 0 ] . compareTo ( str [ 1 ] ) > 0 ) tarou += 3 ; else if ( str [ 0 ] . compareTo ( str [ 1 ] ) < 0 ) hanako += 3 ; else { tarou ++ ; hanako ++ ; } } System . out . println ( tarou + " " + hanako ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long num = sc . nextLong ( ) ; num -- ; String result = " " ; String alp = " abcdefghijklmnopqrstuvwxyz " ; while ( true ) { long syou = num / alp . length ( ) ; long mod = num % alp . length ( ) ; String tmp = alp . substring ( ( int ) mod , ( int ) mod + 1 ) ; result = tmp + result ; num = syou - 1 ; if ( syou == 0 ) { String alp = " abcdefghijklmnopqrstuvwxyz " ; break ; } } System . out . println ( result ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int strNum = sc . nextInt ( ) ; int strLen = sc . nextInt ( ) ; sc . nextLine ( ) ; String [ ] strs = new String [ strNum ] ; for ( int i = 0 ; i < strNum ; i ++ ) { int i = 0 ; strs [ i ] = sc . nextLine ( ) ; } for ( int i = 0 ; i < strNum ; i ++ ) { for ( int j = i + 1 ; j < strNum ; j ++ ) { if ( ! minStr ( strLen , strs [ i ] , strs [ j ] ) ) { String tmp = strs [ i ] ; strs [ i ] = strs [ j ] ; strs [ j ] = tmp ; } } } output ( strs ) ; } private static boolean minStr ( int strLen , String strs , String strt ) { for ( int j = 0 ; j < strLen ; j ++ ) { char sChar = strs . charAt ( j ) ; char tChar = strt . charAt ( j ) ; if ( sChar != tChar ) { return sChar < tChar ; } } return true ; } private static void output ( String [ ] strs ) { for ( int i = 0 ; i < strs . length ; i ++ ) { System . out . print ( strs [ i ] ) ; } System . out . println ( ) ; } } +import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int n = scan . nextInt ( ) ; int [ ] a = new int [ n ] ; int i = 0 ; int Alice = 0 ; int Bob = 0 ; for ( i = 0 ; i < n ; i ++ ) { a [ i ] = scan . nextInt ( ) ; } Arrays . sort ( a ) ; for ( i = 1 ; i <= n ; i ++ ) { if ( i % 2 == 1 ) { int Bob = 0 ; Alice = Alice + a [ n - i ] ; } else { Bob = Bob + a [ n - i ] ; } } System . out . println ( Alice - Bob ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String s1 = sc . next ( ) ; String s2 = sc . next ( ) ; char [ ] S1 = s1 . toCharArray ( ) ; char [ ] S2 = s2 . toCharArray ( ) ; int count = 0 ; for ( int i = 0 ; i < S1 . length ; i ++ ) { if ( S1 [ i ] == S2 [ i ] ) { count ++ ; } } if ( count == S1 . length ) { int i = 0 ; System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } } +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 + 1 ] ; for ( int i = 1 ; i <= N ; i ++ ) { a [ i ] = sc . nextInt ( ) ; } int answer = 0 ; int lightNum = 1 ; while ( 1 == 1 ) { lightNum = a [ lightNum ] ; answer ++ ; if ( lightNum == 2 ) { int lightNum = 1 ; System . out . println ( answer ) ; return ; } if ( answer > 110000 ) { System . out . println ( - 1 ) ; return ; } } } } +import java . util . ArrayList ; import java . util . Collections ; import java . util . Comparator ; import java . util . HashSet ; import java . util . List ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { HashSet < Integer > set = new HashSet < Integer > ( ) ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; HashSet < Integer > set = new HashSet < Integer > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { int number = sc . nextInt ( ) ; set . add ( number ) ; } System . out . println ( set . size ( ) ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; String t = sc . next ( ) ; int ans = 0 ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( s . charAt ( i ) != t . charAt ( i ) ) { int i = 0 ; ans ++ ; } } System . out . println ( ans ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String S = sc . next ( ) ; int count = 0 ; int tmp = 0 ; char [ ] weather = new char [ 3 ] ; for ( int i = 0 ; i < 3 ; i ++ ) { weather [ i ] = S . charAt ( i ) ; } for ( int j = 0 ; j < 3 ; j ++ ) { int j = 0 ; if ( weather [ j ] == 'R' ) { tmp ++ ; if ( count < tmp ) count = tmp ; } else { if ( count < tmp ) count = tmp ; tmp = 0 ; } } System . out . println ( count ) ; } } +import java . util . Scanner ; import java . util . List ; import java . util . ArrayList ; import java . util . Objects ; import java . lang . StringBuilder ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; List < Integer > list = new ArrayList < Integer > ( ) ; for ( int i = 0 ; i < 5 ; i ++ ) { int j = i + 1 ; int a = sc . nextInt ( ) ; list . add ( a ) ; } int k = sc . nextInt ( ) ; boolean cantConnect = false ; for ( int i = 0 ; i < list . size ( ) ; i ++ ) { for ( int j = i + 1 ; j < list . size ( ) ; j ++ ) { if ( list . get ( j ) - list . get ( i ) > k ) cantConnect = true ; } } System . out . println ( cantConnect ? " :( " : " Yay! " ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; sc . close ( ) ; boolean can = false ; for ( int i = 0 ; i < 25 ; ++ i ) { for ( int j = 0 ; j < 25 ; ++ j ) { if ( N == 4 * i + 7 * j ) { int j = 0 ; can = true ; } } } if ( can == true ) { System . out . print ( " Yes " ) ; } else { System . out . print ( " No " ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; String a = scan . next ( ) ; String b = scan . next ( ) ; String c = scan . next ( ) ; String next = " a " ; while ( true ) { if ( next . equals ( " a " ) && a . length ( ) > 0 ) { String next = " a " ; next = a . substring ( 0 , 1 ) ; a = a . substring ( 1 ) ; } else if ( next . equals ( " b " ) && b . length ( ) > 0 ) { next = b . substring ( 0 , 1 ) ; b = b . substring ( 1 ) ; } else if ( c . length ( ) > 0 ) { next = c . substring ( 0 , 1 ) ; c = c . substring ( 1 ) ; } else { break ; } } System . out . println ( next . toUpperCase ( ) ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; while ( true ) { String num = sc . next ( ) ; int [ ] x ; x = new int [ 1000 ] ; int length = num . length ( ) ; int sum = 0 ; for ( int i = 0 ; i < length ; i ++ ) x [ i ] = num . charAt ( i ) - '0' ; for ( int i = 0 ; i < length ; i ++ ) sum += x [ i ] ; if ( sum == 0 ) { int sum = 0 ; break ; } else { System . out . println ( sum ) ; } } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int c = sc . nextInt ( ) ; int five = 0 ; int seven = 0 ; if ( a == 5 ) { five ++ ; } else if ( a == 7 ) { seven ++ ; } if ( b == 5 ) { five ++ ; } else if ( b == 7 ) { seven ++ ; } if ( c == 5 ) { int seven = 0 ; five ++ ; } else if ( c == 7 ) { seven ++ ; } if ( five == 2 && seven == 1 ) { System . out . println ( " YES " ) ; } else { System . out . println ( " NO " ) ; } } } +import java . util . Arrays ; import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; long [ ] A = new long [ N ] ; for ( long i = 0L ; i < N ; i ++ ) { long t = sc . nextLong ( ) * 100000000L + ( i + 1L ) ; A [ ( int ) i ] = t ; } Arrays . sort ( A ) ; for ( int i = 0 ; i < N - 1 ; i ++ ) { int i = 0 ; System . out . print ( A [ i ] % 100000000 + " " ) ; } System . out . println ( A [ N - 1 ] % 100000000 ) ; } public static void p ( Object o ) { System . out . println ( o ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int hp = sc . nextInt ( ) ; int n = sc . nextInt ( ) ; for ( int i = 0 ; i < n ; i ++ ) { hp -= sc . nextInt ( ) ; } if ( hp <= 0 ) { int hp = sc . nextInt ( ) ; System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; Integer [ ] dArr = new Integer [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { dArr [ i ] = sc . nextInt ( ) ; } Arrays . sort ( dArr , Collections . reverseOrder ( ) ) ; int count = 1 ; for ( int i = 1 ; i < n ; i ++ ) { int i = 1 ; if ( dArr [ i - 1 ] == dArr [ i ] ) continue ; if ( dArr [ i - 1 ] > dArr [ i ] ) { count ++ ; } else { break ; } } System . out . println ( count ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int n = scanner . nextInt ( ) ; int a = 0 ; int b = 0 ; for ( int i = 1 ; i <= n ; i += 2 ) { for ( int j = 1 ; j <= n ; j += 2 ) { if ( i % j == 0 && i >= j ) { int j = 1 ; a ++ ; if ( a == 8 ) { b ++ ; } } } a = 0 ; } System . out . print ( b ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner stdIn = new Scanner ( System . in ) ; int a = Integer . parseInt ( stdIn . next ( ) ) ; int b = Integer . parseInt ( stdIn . next ( ) ) ; int pl = 0 ; int pr = 1250 ; do { int pc = ( pl + pr ) / 2 ; if ( ( int ) ( pc * 0.08 ) == a && ( int ) ( pc * 0.1 ) == b ) { int pc = ( pl + pr ) / 2 ; while ( ( int ) ( pc * 0.08 ) == a && ( int ) ( pc * 0.1 ) == b ) { pc -- ; } pc ++ ; System . out . println ( pc ) ; return ; } else if ( ( int ) ( pc * 0.08 ) < a || ( int ) ( pc * 0.1 ) < b ) { pl = pc + 1 ; } else if ( ( int ) ( pc * 0.08 ) > a || ( int ) ( pc * 0.1 ) > b ) { pr = pc - 1 ; } } while ( pl <= pr ) ; System . out . println ( - 1 ) ; } } +import java . util . Scanner ; import java . util . ArrayList ; import java . util . List ; public class Main { public static void main ( String [ ] args ) { Integer [ ] input = readInput ( ) ; int a = input [ 0 ] ; int b = input [ 1 ] ; if ( a < b ) { System . out . println ( " a < b " ) ; } else if ( a > b ) { System . out . println ( " a > b " ) ; } else { System . out . println ( " a == b " ) ; } } public static Integer [ ] readInput ( ) { Scanner sc = new Scanner ( System . in ) ; List < Integer > l = new ArrayList < Integer > ( ) ; Scanner sc = new Scanner ( System . in ) ; while ( sc . hasNextInt ( ) ) { l . add ( sc . nextInt ( ) ) ; } return l . toArray ( new Integer [ l . size ( ) ] ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int ans = a % 1000 ; if ( ans != 0 ) { int ans = a % 1000 ; ans = 1000 - ans ; } System . out . println ( ans ) ; } } +import java . util . * ; import java . util . Map . Entry ; class Main { static int mod = ( int ) ( Math . pow ( 10 , 9 ) + 7 ) ; static int [ ] ans ; public static void main ( String [ ] args ) { long ans2 = 0 ; Scanner sc = new Scanner ( System . in ) ; long N = sc . nextLong ( ) ; long A = sc . nextLong ( ) ; long B = sc . nextLong ( ) ; long ans1 = 0 ; long ans2 = 0 ; ans1 = A * ( N / ( A + B ) ) ; ans2 = B * ( N / ( A + B ) ) ; if ( N % ( A + B ) < A ) { ans1 = ans1 + N % ( A + B ) ; } else { ans1 = ans1 + A ; ans2 = ans2 + N % ( A + B ) - A ; } System . out . println ( ans1 ) ; return ; } } +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 ( ) ; sc . close ( ) ; String [ ] ans = { " YES " , " NO " } ; int an = 0 ; Arrays . sort ( a ) ; int t = a [ 0 ] ; for ( int i = 1 ; i < n ; ++ i ) { int i = 1 ; if ( t == a [ i ] ) { an = 1 ; break ; } t = a [ i ] ; } System . out . println ( ans [ an ] ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; double n = in . nextDouble ( ) ; double d = in . nextDouble ( ) ; int ans = 0 ; while ( n -- > 0 ) { int ans = 0 ; double x = in . nextDouble ( ) ; double y = in . nextDouble ( ) ; if ( Math . sqrt ( x * x + y * y ) <= d ) ans ++ ; } System . out . println ( ans ) ; in . close ( ) ; } } +import java . util . * ; import java . math . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int tap = 1 ; int atap = 0 ; while ( tap < b ) { int atap = 0 ; tap -- ; tap += a ; atap ++ ; } System . out . println ( atap ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int [ ] array = new int [ 3 ] ; int sum = 0 ; for ( int i = 0 ; i < 3 ; i ++ ) { int i = 0 ; array [ i ] = sc . nextInt ( ) ; } Arrays . sort ( array ) ; sum = array [ 0 ] + array [ 1 ] ; System . out . println ( sum ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int vacation = scanner . nextInt ( ) ; int homeworkNumber = scanner . nextInt ( ) ; int [ ] daysSpentInHomework = new int [ homeworkNumber ] ; int studyDay = 0 ; for ( int i = 0 ; i < homeworkNumber ; i ++ ) { daysSpentInHomework [ i ] = scanner . nextInt ( ) ; } for ( int j = 0 ; j < homeworkNumber ; j ++ ) { studyDay = studyDay + daysSpentInHomework [ j ] ; } int playable ; if ( vacation - studyDay >= 0 ) { int playable ; playable = vacation - studyDay ; System . out . println ( playable ) ; } else { System . out . println ( " -1 " ) ; } scanner . close ( ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; int n = Integer . parseInt ( sc . next ( ) ) ; int l = Integer . parseInt ( sc . next ( ) ) ; int [ ] x = new int [ n + 1 ] ; x [ 0 ] = 0 ; for ( int i = 1 ; i < n + 1 ; i ++ ) { x [ i ] = x [ i - 1 ] + Integer . parseInt ( sc . next ( ) ) ; } int ans = 0 ; for ( int i = 0 ; i < n + 1 ; i ++ ) { if ( x [ i ] > l ) { ans = i ; break ; } if ( i == n ) { ans = i + 1 ; } } System . out . println ( ans ) ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; Main app = new Main ( ) ; while ( sc . hasNext ( ) ) { System . out . println ( app . length ( sc . nextInt ( ) , sc . nextInt ( ) ) ) ; } } int length ( int a , int b ) { int ans = 1 ; int ans = 1 ; a += b ; while ( a >= 10 ) { ans ++ ; a /= 10 ; } return ans ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int M = sc . nextInt ( ) ; int sum = 0 ; int [ ] arr = new int [ M ] ; for ( int i = 0 ; i < M ; i ++ ) { arr [ i ] = sc . nextInt ( ) ; sum = sum + arr [ i ] ; } if ( N - sum >= 0 ) { System . out . print ( ( N - sum ) ) ; } else { System . out . print ( - 1 ) ; } } } +import java . io . PrintWriter ; import java . util . * ; class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; int N = Integer . parseInt ( sc . next ( ) ) ; int [ ] A = new int [ N ] ; int [ ] B = new int [ N - 1 ] ; for ( int i = 0 ; i < N ; i ++ ) A [ i ] = 100_000 ; for ( int i = 0 ; i < N - 1 ; i ++ ) { B [ i ] = Integer . parseInt ( sc . next ( ) ) ; if ( B [ i ] < A [ i ] ) A [ i ] = B [ i ] ; if ( B [ i ] < A [ i + 1 ] ) A [ i + 1 ] = B [ i ] ; } sc . close ( ) ; int sum = Arrays . stream ( A ) . sum ( ) ; PrintWriter out = new PrintWriter ( System . out ) ; out . println ( sum ) ; out . flush ( ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; String h = sc . nextLine ( ) ; String s = sc . nextLine ( ) ; int k = Integer . parseInt ( h ) ; int len = String . valueOf ( s ) . length ( ) ; if ( len <= k ) { System . out . println ( s ) ; } else { for ( int i = 0 ; i < k ; i ++ ) { int i = 0 ; System . out . print ( s . charAt ( i ) ) ; } System . out . print ( " ... " ) ; } } } +import java . io . * ; import java . util . * ; import java . lang . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int k = sc . nextInt ( ) ; int [ ] arr = new int [ n + 1 ] ; int temp = k ; int d = 0 , val = 0 , count = 0 ; while ( k != 0 ) { int i = 0 ; d = sc . nextInt ( ) ; for ( int i = 0 ; i < d ; i ++ ) { val = sc . nextInt ( ) ; arr [ val ] ++ ; } k -- ; } for ( int i = 0 ; i <= n ; i ++ ) { if ( arr [ i ] == 0 ) count ++ ; } count -- ; System . out . println ( count ) ; } } +import java . util . ArrayList ; import java . util . Collections ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int k = sc . nextInt ( ) ; ArrayList < Integer > list = new ArrayList < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { int i = 0 ; int p = sc . nextInt ( ) ; list . add ( p ) ; } Collections . sort ( list ) ; int sum = 0 ; for ( int i = 0 ; i < k ; i ++ ) { sum += list . get ( i ) ; } System . out . println ( sum ) ; sc . close ( ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws IOException { long b = Long . valueOf ( strArr [ 1 ] ) ; BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String [ ] strArr = br . readLine ( ) . split ( " " ) ; long a = Long . valueOf ( strArr [ 0 ] ) ; long b = Long . valueOf ( strArr [ 1 ] ) ; System . out . println ( gcd ( a , b ) ) ; } private static long gcd ( long a , long b ) { long r = a % b ; if ( r == 0 ) return b ; else return gcd ( b , a % b ) ; } } +import java . util . Arrays ; import java . util . Collections ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int n = Integer . parseInt ( scan . next ( ) ) ; int m = Integer . parseInt ( scan . next ( ) ) ; Integer [ ] a = new Integer [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = Integer . parseInt ( scan . next ( ) ) ; } scan . close ( ) ; int sum = 0 ; for ( int i : a ) { sum += i ; } int border = ( sum + ( 4 * m ) - 1 ) / ( 4 * m ) ; Arrays . sort ( a , Collections . reverseOrder ( ) ) ; if ( a [ m - 1 ] >= border ) { int i ; System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int c = sc . nextInt ( ) ; int t = a - b ; if ( c - t <= 0 ) { int t = a - b ; System . out . println ( " 0 " ) ; } if ( t < c ) { System . out . println ( c - t ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner stdIn = new Scanner ( System . in ) ; for ( ; ; ) { int h = stdIn . nextInt ( ) ; int w = stdIn . nextInt ( ) ; if ( h == 0 && w == 0 ) break ; for ( int i = 0 ; i < h ; i ++ ) { for ( int j = 0 ; j < w ; j ++ ) { if ( ( i + j ) % 2 == 0 ) { System . out . print ( " # " ) ; } else { int j = 0 ; System . out . print ( " . " ) ; } } System . out . println ( ) ; } System . out . println ( ) ; } } } +import java . util . * ; import java . io . * ; public class Main { public static void main ( String [ ] Args ) { Scanner in = new Scanner ( System . in ) ; String s = in . next ( ) ; int n = s . length ( ) ; int flag = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { int i = 1 ; if ( i % 2 == 0 && s . charAt ( i - 1 ) == 'R' ) flag = 1 ; if ( i % 2 == 1 && s . charAt ( i - 1 ) == 'L' ) flag = 1 ; } if ( flag == 0 ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } } +import java . util . Scanner ; import java . util . TreeSet ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner scan = new Scanner ( System . in ) ; String s = scan . next ( ) ; TreeSet < Integer > A = new TreeSet < > ( ) ; TreeSet < Integer > Z = new TreeSet < > ( ) ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( s . charAt ( i ) == 'A' ) { A . add ( i ) ; } else if ( s . charAt ( i ) == 'Z' ) { Z . add ( i ) ; } } System . out . println ( Z . last ( ) - A . first ( ) + 1 ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { final Scanner sc = new Scanner ( System . in ) ; final int x = sc . nextInt ( ) ; for ( int i = x ; i <= 110000 ; i ++ ) { if ( isPrime ( i ) ) { System . out . println ( i ) ; return ; } } } public static boolean isPrime ( int n ) { int i = 2 ; for ( int i = 2 ; i <= Math . sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) { return false ; } } return true ; } } +import java . io . * ; import java . util . * ; public class Main { private static final BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; private static StringTokenizer st ; public static void main ( String [ ] args ) throws IOException { char [ ] cs = br . readLine ( ) . toCharArray ( ) ; int ds = 0 ; for ( char c : cs ) { char c ; ds += c ; } ds -= cs . length * '0' ; System . out . println ( ds % 9 == 0 ? " Yes " : " No " ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; char [ ] s = in . next ( ) . toCharArray ( ) ; boolean A = false ; boolean B = false ; for ( int i = 0 ; i < s . length ; i ++ ) { int i = 0 ; if ( s [ i ] == 'A' ) A = true ; if ( s [ i ] == 'B' ) B = true ; } if ( A && 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 n = sc . nextInt ( ) ; int q = sc . nextInt ( ) ; String s = sc . next ( ) ; int [ ] pos = new int [ n ] ; for ( int i = 0 ; i < n - 1 ; i ++ ) { if ( s . charAt ( i ) == 'A' && s . charAt ( i + 1 ) == 'C' ) { pos [ i ] = 1 ; } } int [ ] num = new int [ n ] ; num [ 0 ] = pos [ 0 ] ; for ( int i = 1 ; i < n - 1 ; i ++ ) { int min ; num [ i ] = num [ i - 1 ] + pos [ i ] ; } for ( int i = 0 ; i < q ; i ++ ) { int l = sc . nextInt ( ) ; int r = sc . nextInt ( ) ; int max ; if ( r - 1 - 1 < 0 ) { max = 0 ; } else { max = num [ r - 1 - 1 ] ; } int min ; if ( l - 1 - 1 < 0 ) { min = 0 ; } else { min = num [ l - 1 - 1 ] ; } int ans = max - min ; System . out . println ( ans ) ; } sc . close ( ) ; } } +import java . util . Scanner ; public class Main { static String str ; static int N , zeroC , oneC ; static int [ ] A ; public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; str = sc . next ( ) ; N = str . length ( ) ; A = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { A [ i ] = Character . getNumericValue ( str . charAt ( i ) ) ; if ( A [ i ] == 0 ) { zeroC ++ ; } else { oneC ++ ; } } System . out . println ( N - ( Math . abs ( zeroC - oneC ) ) ) ; } } +import java . io . * ; import java . util . * ; public class Main { private static final BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; private static final PrintWriter pw = new PrintWriter ( new BufferedWriter ( new OutputStreamWriter ( System . out ) ) ) ; private static StringTokenizer st ; private static int readInt ( ) throws IOException { while ( st == null || ! st . hasMoreTokens ( ) ) st = new StringTokenizer ( br . readLine ( ) ) ; return Integer . parseInt ( st . nextToken ( ) ) ; } public static void main ( String [ ] args ) throws IOException { int N = readInt ( ) ; if ( N % 1000 == 0 ) pw . println ( 0 ) ; else pw . println ( 1000 - N % 1000 ) ; pw . close ( ) ; } } +import java . util . * ; public class Main { static Scanner scanner = new Scanner ( System . in ) ; public static void main ( String [ ] $ ) { int n = scanner . nextInt ( ) ; int max = Integer . MAX_VALUE ; for ( int i = 0 ; i < n ; i ++ ) { int max = Integer . MAX_VALUE ; max = Math . min ( max , Integer . numberOfTrailingZeros ( scanner . nextInt ( ) ) ) ; } System . out . println ( max ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws IOException { InputStreamReader is = new InputStreamReader ( System . in ) ; BufferedReader br = new BufferedReader ( is ) ; String str = br . readLine ( ) ; calc ( str ) ; } public static void calc ( String str ) { int num3 = Integer . parseInt ( result [ 2 ] ) ; String [ ] result = str . split ( " " ) ; int num1 = Integer . parseInt ( result [ 0 ] ) ; int num2 = Integer . parseInt ( result [ 1 ] ) ; int num3 = Integer . parseInt ( result [ 2 ] ) ; if ( num1 < num2 ) { if ( num2 < num3 ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } else { System . out . println ( " No " ) ; } } } +import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int n = scan . nextInt ( ) ; int [ ] a = new int [ n ] ; long sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int i = 0 ; a [ i ] = scan . nextInt ( ) ; sum += a [ i ] ; } Arrays . sort ( a ) ; System . out . println ( a [ 0 ] + " " + a [ a . length - 1 ] + " " + sum ) ; scan . close ( ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws IOException { int i = 0 ; BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String line = br . readLine ( ) ; String [ ] oneline = line . split ( " " ) ; int [ ] data = { 0 , 0 } ; for ( int i = 0 ; i < oneline . length ; i ++ ) { data [ i ] = Integer . parseInt ( oneline [ i ] ) ; } int area = data [ 0 ] * data [ 1 ] ; int length = 2 * ( data [ 0 ] + data [ 1 ] ) ; System . out . println ( area + " " + length ) ; } } +import java . util . Scanner ; public class Main { static long bignum = 1000000000 + 7 ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; n = n % 10 ; if ( n == 2 || n == 4 || n == 5 || n == 7 || n == 9 ) { System . out . println ( " hon " ) ; } if ( n == 0 || n == 1 || n == 6 || n == 8 ) { System . out . println ( " pon " ) ; } if ( n == 3 ) { System . out . println ( " bon " ) ; } } static long divn ( int target , int times ) { long holder = ans ; int sqtimes = ( int ) Math . sqrt ( times ) ; long ans = 1 ; for ( int i = 0 ; i < sqtimes ; i ++ ) { ans = ( ans * target ) % ( 1000000000 + 7 ) ; } long holder = ans ; ans = 1 ; for ( int i = 0 ; i < sqtimes ; i ++ ) { ans = ( ans * holder ) % ( 1000000000 + 7 ) ; } for ( int i = 0 ; i < times - sqtimes * sqtimes ; i ++ ) { ans = ( ans * target ) % ( 1000000000 + 7 ) ; } return ans ; } static long div ( long a ) { if ( a < 0 ) a += 1000000000 + 7 ; return a % ( 1000000000 + 7 ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long X = sc . nextLong ( ) ; int count = 1 ; long money = 100 ; while ( true ) { long money = 100 ; money *= 1.01 ; if ( money >= X ) { System . out . println ( count ) ; return ; } count ++ ; } } } +import java . util . Scanner ; public class Main { static class Solution { Integer [ ] [ ] dp ; public void find ( int k ) { int k = sc . nextInt ( ) ; dp = new Integer [ k + 1 ] [ k + 1 ] ; long res = 0 ; for ( int a = 1 ; a <= k ; a ++ ) { for ( int b = 1 ; b <= k ; b ++ ) { for ( int c = 1 ; c <= k ; c ++ ) { int val = gcd ( b , c ) ; if ( dp [ b ] [ c ] == null ) { dp [ b ] [ c ] = val ; } int val2 = gcd ( a , val ) ; if ( dp [ a ] [ val ] == null ) { dp [ a ] [ val ] = val2 ; } res += val2 ; } } } System . out . println ( res ) ; } int gcd ( int a , int b ) { if ( dp [ a ] [ b ] != null ) { return dp [ a ] [ b ] ; } if ( a == 0 ) return b ; if ( b == 0 ) return a ; if ( a == b ) return a ; if ( a > b ) return gcd ( a - b , b ) ; return gcd ( a , b - a ) ; } } public static void main ( String [ ] args ) { Solution sol = new Solution ( ) ; Scanner sc = new Scanner ( System . in ) ; int k = sc . nextInt ( ) ; sol . find ( k ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; long min = sc . nextInt ( ) ; long ret = - 1000000001 ; for ( int i = 1 ; i < n ; i ++ ) { long ret = - 1000000001 ; long r = sc . nextInt ( ) ; if ( r - min > ret ) ret = r - min ; if ( r < min ) min = r ; } System . out . println ( ret ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; String [ ] list = scanner . next ( ) . split ( " " ) ; int count = 0 ; for ( String s : list ) { String s ; if ( Integer . parseInt ( s ) == 1 ) { count ++ ; } } System . out . println ( count ) ; scanner . close ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int k = sc . nextInt ( ) ; int [ ] h = new int [ n ] ; long [ ] dp = new long [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { int m = 1 ; h [ i ] = sc . nextInt ( ) ; dp [ i ] = 9223372036854775807l ; } dp [ 0 ] = 0 ; for ( int i = 1 ; i < n ; i ++ ) { for ( int m = 1 ; m < k + 1 ; m ++ ) { if ( i >= m ) dp [ i ] = Math . min ( dp [ i ] , dp [ i - m ] + Math . abs ( h [ i ] - h [ i - m ] ) ) ; } } System . out . println ( dp [ n - 1 ] ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int b = a ; int ans = 0 ; while ( a > 0 ) { int ans = 0 ; ans += a % 10 ; a /= 10 ; } System . out . println ( b % ans == 0 ? " Yes " : " No " ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 1 ; Scanner scan = new Scanner ( System . in ) ; long seisu = scan . nextLong ( ) ; long syou = 0 ; long a = 0 , b = 0 ; long re = Long . MAX_VALUE ; for ( int i = 1 ; i <= Math . sqrt ( seisu ) ; i ++ ) { if ( seisu % i == 0 ) { a = i ; b = seisu / i ; } re = Math . min ( re , a + b - 2 ) ; } System . out . println ( re ) ; scan . close ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; long input = scanner . nextLong ( ) ; long answer = input - 1 ; answer = getAnswer ( input , answer ) ; System . out . println ( answer ) ; } private static long getAnswer ( long input , long answer ) { int newStart = ( int ) Math . sqrt ( input ) ; for ( long i = newStart ; i > 1 ; i -- ) { if ( input % i == 0 ) { long i = newStart ; long divisible = input / i ; long possibleAnswer = ( i - 1 ) + ( divisible - 1 ) ; return possibleAnswer ; } } return answer ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { int j = 2 ; Scanner scanner = new Scanner ( System . in ) ; int x = scanner . nextInt ( ) ; int i = 0 ; int X ; int hantei = 0 ; int ans = 0 ; while ( hantei == 0 ) { X = x + i ; for ( int j = 2 ; j <= X ; j ++ ) { if ( X % j == 0 ) { if ( j == X ) { hantei = 1 ; ans = X ; } else { break ; } } } i ++ ; } System . out . println ( ans ) ; } } +import java . util . ArrayList ; import java . util . List ; import java . util . Scanner ; public class Main { public static void main ( String [ ] arges ) { Scanner sc = new Scanner ( System . in ) ; List < String > klist = new ArrayList < String > ( ) ; while ( true ) { int j2 = j + 1 ; String line = sc . nextLine ( ) ; klist . add ( line ) ; if ( line . equals ( " 0 0 " ) ) { break ; } } for ( String string : klist ) { if ( string . equals ( " 0 0 " ) ) { break ; } String [ ] k = string . split ( " " ) ; int [ ] v = new int [ 2 ] ; v [ 0 ] = Integer . parseInt ( k [ 0 ] ) ; v [ 1 ] = Integer . parseInt ( k [ 1 ] ) ; int count = 0 ; for ( int i = 1 ; i <= v [ 0 ] - 2 ; i ++ ) { for ( int j = i + 1 ; j <= v [ 0 ] - 1 ; j ++ ) { for ( int j2 = j + 1 ; j2 <= v [ 0 ] ; j2 ++ ) { int sum = i + j + j2 ; if ( sum == v [ 1 ] ) { count ++ ; } } } } System . out . println ( count ) ; } } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . * ; public class Main { static class FastReader { BufferedReader br ; StringTokenizer st ; public FastReader ( ) { br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; } String next ( ) { while ( st == null || ! st . hasMoreElements ( ) ) { try { st = new StringTokenizer ( br . readLine ( ) ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } return st . nextToken ( ) ; } int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } long nextLong ( ) { return Long . parseLong ( next ( ) ) ; } double nextDouble ( ) { return Double . parseDouble ( next ( ) ) ; } String nextLine ( ) { String str = " " ; try { String str = " " ; str = br . readLine ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } return str ; } } public static void main ( String [ ] args ) { FastReader fr = new FastReader ( ) ; char ch = fr . next ( ) . charAt ( 0 ) ; if ( ch >= 65 && ch <= 90 ) { System . out . println ( " A " ) ; } else { System . out . println ( " a " ) ; } } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) { BufferedReader reader = new BufferedReader ( new InputStreamReader ( System . in ) ) ; try { int w = Integer . parseInt ( reader . readLine ( ) ) ; int n = Integer . parseInt ( reader . readLine ( ) ) ; int [ ] x = new int [ w ] ; for ( int i = 0 ; i < w ; i ++ ) { int i = 0 ; x [ i ] = i + 1 ; } int a ; int b ; for ( int i = 0 ; i < n ; i ++ ) { String line = reader . readLine ( ) ; String [ ] s = line . split ( " , " ) ; a = Integer . parseInt ( s [ 0 ] ) ; b = Integer . parseInt ( s [ 1 ] ) ; int temp = x [ a - 1 ] ; x [ a - 1 ] = x [ b - 1 ] ; x [ b - 1 ] = temp ; } for ( int i = 0 ; i < w ; i ++ ) { System . out . println ( x [ i ] ) ; } } catch ( IOException e ) { } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long A = Integer . parseInt ( sc . next ( ) ) ; long B = Integer . parseInt ( sc . next ( ) ) ; System . out . print ( A * B / gcd ( A , B ) ) ; return ; } static long gcd ( long a , long b ) { long min = Math . min ( a , b ) ; long max = Math . max ( a , b ) ; long min = Math . min ( a , b ) ; if ( max % min == 0 ) { return min ; } else { return gcd ( max % min , min ) ; } } } +import java . util . * ; class Main { final Scanner sc = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { new Main ( ) . run ( ) ; } private void run ( ) { int n = sc . nextInt ( ) ; Set < Long > set = new HashSet < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { long a = sc . nextInt ( ) ; if ( set . contains ( a ) ) { Set < Long > set = new HashSet < > ( ) ; System . out . println ( " NO " ) ; return ; } set . add ( a ) ; } System . out . println ( " YES " ) ; } } +import java . util . * ; import java . io . * ; import java . math . * ; class Main { static class FastReader { BufferedReader br ; StringTokenizer st ; public FastReader ( ) { br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; } String next ( ) { while ( st == null || ! st . hasMoreElements ( ) ) { try { st = new StringTokenizer ( br . readLine ( ) ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } return st . nextToken ( ) ; } int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } long nextLong ( ) { int i = a ; 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 ; } } public static void main ( String [ ] args ) { FastReader sc = new FastReader ( ) ; int k = sc . nextInt ( ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int sum = 0 ; for ( int i = a ; i <= b ; i ++ ) { if ( i % k == 0 ) { sum = 1 ; } } if ( sum == 1 ) { System . out . println ( " OK " ) ; } else { System . out . println ( " NG " ) ; } } } +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 + 1 ] ; int [ ] B = new int [ N ] ; for ( int i = 0 ; i < N + 1 ; i ++ ) A [ i ] = sc . nextInt ( ) ; for ( int i = 0 ; i < N ; i ++ ) B [ i ] = sc . nextInt ( ) ; int [ ] AC = A . clone ( ) ; long cnt = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( A [ i ] >= B [ i ] ) { int i = 0 ; A [ i ] -= B [ i ] ; B [ i ] = 0 ; } else { B [ i ] -= A [ i ] ; A [ i ] = 0 ; } if ( A [ i + 1 ] >= B [ i ] ) { A [ i + 1 ] -= B [ i ] ; B [ i ] = 0 ; } else { B [ i ] -= A [ i + 1 ] ; A [ i + 1 ] = 0 ; } } for ( int i = 0 ; i < N + 1 ; i ++ ) { cnt += AC [ i ] - A [ i ] ; } System . out . println ( cnt ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . nextLine ( ) ; String p = sc . nextLine ( ) ; int sLen = s . length ( ) ; int pLen = p . length ( ) ; boolean ok = false ; for ( int i = 0 ; i < sLen ; i ++ ) { int j = 0 ; for ( int j = 0 ; j < pLen ; j ++ ) { if ( s . charAt ( ( i + j ) % sLen ) != p . charAt ( j ) ) { break ; } if ( j == pLen - 1 ) ok = true ; } if ( ok ) break ; } System . out . println ( ok ? " Yes " : " No " ) ; } } +import java . util . * ; import java . lang . * ; import java . io . * ; public class Main { public static boolean isPalindrome ( int n ) { int i = a ; String s = " " + n ; String a = " " ; for ( int i = s . length ( ) - 1 ; i >= 0 ; i -- ) { a += s . charAt ( i ) ; } return s . equals ( a ) ; } public static void main ( String [ ] args ) throws IOException { Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int count = 0 ; for ( int i = a ; i <= b ; i ++ ) { if ( isPalindrome ( i ) ) count ++ ; } System . out . println ( count ) ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; long co = 0 ; HashMap < String , Long > l = new HashMap < String , Long > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { char [ ] c = sc . next ( ) . toCharArray ( ) ; Arrays . sort ( c ) ; String S = new String ( c ) ; if ( l . containsKey ( S ) ) { String S = new String ( c ) ; l . put ( S , l . get ( S ) + 1 ) ; co += l . get ( S ) ; } else { l . put ( S , ( long ) 0 ) ; } } sc . close ( ) ; System . out . println ( co ) ; } } +import javax . print . DocFlavor ; import java . awt . * ; import java . io . PrintWriter ; import java . lang . reflect . Array ; import java . math . BigInteger ; import java . util . * ; import java . util . List ; public class Main { static String br = System . getProperty ( " line.separator " ) ; static Scanner sc = new Scanner ( System . in ) ; static PrintWriter out = new PrintWriter ( System . out ) ; public static void main ( String [ ] args ) { int A = nextInt ( ) ; int B = nextInt ( ) ; if ( A == 1 ) { if ( B == 3 ) { println ( 2 ) ; return ; } else { println ( 3 ) ; return ; } } else if ( A == 2 ) { if ( B == 1 ) { println ( 3 ) ; return ; } else { println ( 1 ) ; return ; } } else { if ( B == 1 ) { println ( 2 ) ; return ; } else { println ( 1 ) ; return ; } } } static int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } static Long nextLong ( ) { PrintWriter out = new PrintWriter ( System . out ) ; return Long . parseLong ( next ( ) ) ; } static String next ( ) { return sc . next ( ) ; } static String nextLine ( ) { return sc . nextLine ( ) ; } static void println ( Object o ) { out . println ( o ) ; out . flush ( ) ; } static void print ( Object o ) { PrintWriter out = new PrintWriter ( System . out ) ; out . print ( o ) ; out . flush ( ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; String s = sc . next ( ) ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { int start = ( int ) s . charAt ( i ) ; int ans = start + n ; if ( ans < 91 ) { System . out . print ( ( char ) ans ) ; } else { int ans = start + n ; System . out . print ( ( char ) ( ans - 26 ) ) ; } } System . out . println ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int [ ] result = new int [ 26 ] ; for ( int i = 0 ; i < result . length ; i ++ ) { result [ i ] = 0 ; } while ( sc . hasNext ( ) ) { String input = sc . nextLine ( ) ; for ( int i = 0 ; i < input . length ( ) ; i ++ ) { char ch = input . charAt ( i ) ; String str = String . valueOf ( ch ) ; str = str . toLowerCase ( ) ; ch = str . charAt ( 0 ) ; for ( char c = 'a' ; c <= 'z' ; c ++ ) { int index = c - 'a' ; if ( ch == c ) { result [ index ] ++ ; } } } } for ( int i = 0 ; i < result . length ; i ++ ) { int i = 0 ; char alphabet = ( char ) ( i + 'a' ) ; System . out . println ( alphabet + " : " + result [ i ] ) ; } sc . close ( ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws NumberFormatException , IOException { int i = 0 ; BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int n = Integer . parseInt ( br . readLine ( ) ) ; String [ ] kachi = br . readLine ( ) . split ( " " ) ; String [ ] cost = br . readLine ( ) . split ( " " ) ; int k = 0 ; int c = 0 ; int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { k = Integer . parseInt ( kachi [ i ] ) ; c = Integer . parseInt ( cost [ i ] ) ; if ( k - c > 0 ) { sum += k - c ; } } System . out . println ( sum ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sn = new Scanner ( System . in ) ; long n = sn . nextLong ( ) ; long sum = 0 ; for ( long i = 1 ; i <= n ; i ++ ) { long i = 1 ; if ( ( i % 3 ) == 0 || ( i % 5 ) == 0 || ( i % 15 ) == 0 ) { } else { sum += i ; } } System . out . print ( sum ) ; } } +import java . io . BufferedReader ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws Exception { try ( BufferedReader reader = new BufferedReader ( new InputStreamReader ( System . in ) ) ) { BufferedReader reader = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String [ ] array = reader . readLine ( ) . split ( " " ) ; int A = Integer . parseInt ( array [ 0 ] ) ; int B = Integer . parseInt ( array [ 1 ] ) ; int C = Integer . parseInt ( array [ 2 ] ) ; System . out . println ( Math . max ( B + C - A , 0 ) ) ; } } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { int j = 0 ; Scanner sc = new Scanner ( System . in ) ; int [ ] x = new int [ 100000 ] , y = new int [ 100000 ] ; int i = 0 , a ; while ( true ) { x [ i ] = sc . nextInt ( ) ; y [ i ] = sc . nextInt ( ) ; if ( x [ i ] == 0 && y [ i ] == 0 ) break ; if ( x [ i ] > y [ i ] ) { a = x [ i ] ; x [ i ] = y [ i ] ; y [ i ] = a ; } i ++ ; } for ( int j = 0 ; j < i ; j ++ ) { System . out . println ( x [ j ] + " " + y [ j ] ) ; } } } +import java . util . ArrayList ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; ArrayList < Integer > array = new ArrayList < Integer > ( ) ; long ans = 0 ; for ( int i = 1 ; i <= N ; i ++ ) { int i = 0 ; if ( ! ( i % 3 == 0 || i % 5 == 0 ) ) { array . add ( i ) ; } } for ( int i = 0 ; i < array . size ( ) ; i ++ ) { ans += array . get ( i ) ; } System . out . println ( ans ) ; sc . close ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int d = sc . nextInt ( ) , n = sc . nextInt ( ) ; int sum = 0 , count = 0 , flag = 0 , max = - 999999 , min = 99999 ; if ( d == 0 ) { if ( n != 100 ) System . out . println ( n ) ; else System . out . println ( n + 1 ) ; } else if ( d == 1 ) { if ( n != 100 ) System . out . println ( n * 100 ) ; else System . out . println ( ( n + 1 ) * 100 ) ; } else { int d = sc . nextInt ( ) , n = sc . nextInt ( ) ; if ( n != 100 ) System . out . println ( n * 10000 ) ; else System . out . println ( ( n + 1 ) * 10000 ) ; } } public static int sample ( int n ) { return n ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] arrs = new int [ n + 1 ] ; for ( int i = 1 ; i <= n ; i ++ ) { int i = 1 ; arrs [ i ] = sc . nextInt ( ) ; } int result = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { result += Math . max ( arrs [ i ] - arrs [ i - 1 ] , 0 ) ; } System . out . println ( result ) ; } } +import java . util . * ; import java . io . * ; class Main { static PrintStream out = System . out ; static Scanner in = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { int n = in . nextInt ( ) ; int a = in . nextInt ( ) ; long min = a , max = a , sum = a ; for ( int i = 1 ; i < n ; i ++ ) { long min = a , max = a , sum = a ; a = in . nextInt ( ) ; min = Math . min ( a , min ) ; max = Math . max ( a , max ) ; sum += a ; } out . println ( String . format ( " %d %d %d " , min , max , sum ) ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner s = new Scanner ( System . in ) ; String n = s . nextLine ( ) ; String s1 = String . valueOf ( n . charAt ( 0 ) ) ; int i1 = 0 ; int i2 = 0 ; String s2 = " " ; for ( int i = 0 ; i < n . length ( ) ; i ++ ) { if ( String . valueOf ( n . charAt ( i ) ) . equals ( s1 ) ) { i1 ++ ; } else { if ( s2 . equals ( " " ) || String . valueOf ( n . charAt ( i ) ) . equals ( s2 ) ) { s2 = String . valueOf ( n . charAt ( i ) ) ; i2 ++ ; } } } System . out . println ( i1 == 2 && i2 == 2 ? " Yes " : " No " ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner s = null ; try { long b = num [ 1 ] ; s = new Scanner ( System . in ) ; while ( s . hasNextLong ( ) ) { long [ ] num = { s . nextLong ( ) , s . nextLong ( ) } ; System . out . println ( gcd ( num ) + " " + lcm ( num ) ) ; } } finally { s . close ( ) ; } } private static long gcd ( long [ ] num ) { long x = 0 ; long a = num [ 0 ] ; long b = num [ 1 ] ; do { x = a % b ; a = b ; b = x ; } while ( x != 0 ) ; return a ; } private static long lcm ( long [ ] num ) { return ( num [ 0 ] * num [ 1 ] ) / gcd ( num ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int x = sc . nextInt ( ) ; int [ ] m = new int [ n ] ; int sumG = 0 ; int minDonut = 1001 ; for ( int i = 0 ; i < n ; i ++ ) { m [ i ] = sc . nextInt ( ) ; sumG += m [ i ] ; minDonut = Math . min ( minDonut , m [ i ] ) ; } int sumDonut = n + ( x - sumG ) / minDonut ; System . out . println ( sumDonut ) ; } } +import java . util . ArrayList ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; ArrayList < String > list = new ArrayList < > ( ) ; String newWord ; for ( int i = 0 ; i < N ; i ++ ) { newWord = sc . next ( ) ; if ( list . contains ( newWord ) || ( ! list . isEmpty ( ) && ! ( list . get ( list . size ( ) - 1 ) ) . endsWith ( String . valueOf ( newWord . charAt ( 0 ) ) ) ) ) { System . out . println ( " No " ) ; return ; } else { String newWord ; list . add ( newWord ) ; } } System . out . println ( " Yes " ) ; } } +import java . util . Arrays ; import java . util . Collections ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; Integer [ ] a = new Integer [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { a [ i ] = sc . nextInt ( ) ; } sc . close ( ) ; Arrays . sort ( a , Collections . reverseOrder ( ) ) ; int A = a [ 0 ] , B = 0 ; for ( int i = 1 ; i < N ; i ++ ) { if ( i % 2 == 0 ) { A += a [ i ] ; } else { int i = 1 ; B += a [ i ] ; } } System . out . println ( A - B ) ; } } +import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int [ ] d = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { String line = sc . next ( ) ; d [ i ] = Integer . parseInt ( line ) ; } int K = 0 ; int count = 0 ; int countLeft = 0 ; int countRight = N ; Arrays . sort ( d ) ; for ( int i = 0 ; i < N ; i ++ ) { countLeft ++ ; countRight -- ; if ( countLeft == countRight ) { int i = 0 ; K = d [ i ] ; while ( d [ i ] <= K && K < d [ i + 1 ] ) { K ++ ; count ++ ; } break ; } } System . out . println ( count ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int [ ] point = new int [ 2 ] ; Scanner sc = new Scanner ( System . in ) ; int n = Integer . parseInt ( sc . nextLine ( ) ) ; int [ ] point = new int [ 2 ] ; for ( int i = 0 ; i < n ; i ++ ) { String game = sc . nextLine ( ) ; String [ ] games = game . split ( " " ) ; if ( games [ 0 ] . compareTo ( games [ 1 ] ) == 0 ) { point [ 0 ] ++ ; point [ 1 ] ++ ; } else if ( games [ 0 ] . compareTo ( games [ 1 ] ) > 0 ) { point [ 0 ] += 3 ; } else { point [ 1 ] += 3 ; } } System . out . println ( String . format ( " %d %d " , point [ 0 ] , point [ 1 ] ) ) ; } } +import java . util . Scanner ; class Main { int x , y ; public void suzuki ( ) { Scanner sc = new Scanner ( System . in ) ; x = sc . nextInt ( ) ; y = sc . nextInt ( ) ; while ( x != 0 || y != 0 ) { Scanner sc = new Scanner ( System . in ) ; if ( x > y ) { System . out . println ( y + " " + x ) ; } else { System . out . println ( x + " " + y ) ; } x = sc . nextInt ( ) ; y = sc . nextInt ( ) ; } } public static void main ( String [ ] args ) { new Main ( ) . suzuki ( ) ; } } +import java . io . OutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . PrintWriter ; import java . util . StringTokenizer ; import java . io . IOException ; import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . io . InputStream ; public class Main { public static void main ( String [ ] args ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; InputReader in = new InputReader ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; AWeatherPrediction solver = new AWeatherPrediction ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class AWeatherPrediction { public void solve ( int testNumber , InputReader in , PrintWriter out ) { String x = in . next ( ) ; if ( x . compareTo ( " Sunny " ) == 0 ) { out . println ( " Cloudy " ) ; } else if ( x . compareTo ( " Cloudy " ) == 0 ) { out . println ( " Rainy " ) ; } else { out . println ( " Sunny " ) ; } } } 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 ( ) ; } } } +import java . util . ArrayList ; import java . util . Collections ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int all = 0 ; Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int [ ] c = new int [ N - 1 ] ; ArrayList < Integer > CN = new ArrayList < > ( ) ; int check , checkB = 0 ; checkB = sc . nextInt ( ) ; for ( int i = 0 ; i < N - 1 ; i ++ ) { check = sc . nextInt ( ) ; if ( checkB == ( check - 1 ) ) { CN . add ( checkB ) ; } checkB = check ; } for ( int j = 0 ; j < N ; j ++ ) { all = all + sc . nextInt ( ) ; } Collections . sort ( CN ) ; for ( int k = 0 ; k < N - 1 ; k ++ ) { int l = 0 ; c [ k ] = sc . nextInt ( ) ; } for ( int l = 0 ; l < CN . size ( ) ; l ++ ) { all = all + c [ CN . get ( l ) - 1 ] ; } System . out . println ( all ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int M = sc . nextInt ( ) ; int [ ] [ ] mat = new int [ N ] [ M ] ; for ( int i = 0 ; i < N ; i ++ ) { int tmp = sc . nextInt ( ) ; for ( int j = 0 ; j < tmp ; j ++ ) { mat [ i ] [ j ] = sc . nextInt ( ) ; } } int answer = 0 ; for ( int i = 1 ; i <= M ; i ++ ) { int j = 0 ; if ( isAllLike ( mat , i , N , M ) ) { answer = answer + 1 ; } } System . out . println ( answer ) ; } public static boolean isAllLike ( int [ ] [ ] mat , int x , int N , int M ) { boolean isLike = false ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < M ; j ++ ) { if ( mat [ i ] [ j ] == x ) { isLike = true ; } } if ( ! isLike ) { return false ; } isLike = false ; } return true ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int k = sc . nextInt ( ) ; int N = sc . nextInt ( ) ; int [ ] A = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { A [ i ] = sc . nextInt ( ) ; } int X = 0 ; int Y = A [ 0 ] + ( k - A [ N - 1 ] ) ; for ( int i = 0 ; i < N - 1 ; i ++ ) { int i = 0 ; X = A [ i + 1 ] - A [ i ] ; if ( X >= Y ) { Y = X ; } } System . out . print ( k - Y ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] argv ) { Scanner scan = new Scanner ( System . in ) ; int num = scan . nextInt ( ) ; int h = 0 , m = 0 , s = 0 ; while ( true ) { if ( num - 3600 >= 0 ) { int h = 0 , m = 0 , s = 0 ; num = num - 3600 ; h ++ ; } else if ( num - 60 >= 0 ) { num = num - 60 ; m ++ ; } else { if ( num == 0 ) break ; s ++ ; num -- ; } } System . out . println ( h + " : " + m + " : " + s ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; long [ ] a = new long [ n + 1 ] ; long [ ] b = new long [ n ] ; for ( int i = 0 ; i < n + 1 ; i ++ ) { a [ i ] = sc . nextInt ( ) ; } for ( int i = 0 ; i < n ; i ++ ) { int i = 0 ; b [ i ] = sc . nextInt ( ) ; } long fii1 = 0 ; long sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { long fii = Math . min ( a [ i ] - fii1 , b [ i ] ) ; fii1 = Math . min ( a [ i + 1 ] , b [ i ] - fii ) ; sum += fii + fii1 ; } System . out . println ( sum ) ; } } +import java . io . * ; import java . util . * ; import java . lang . * ; public class Main { static class FastReader { BufferedReader br ; StringTokenizer st ; public FastReader ( ) { br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; } String next ( ) { while ( st == null || ! st . hasMoreElements ( ) ) { try { st = new StringTokenizer ( br . readLine ( ) ) ; } catch ( IOException e ) { String s1 = ob . next ( ) ; 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 ; } } public static void main ( String [ ] args ) { FastReader ob = new FastReader ( ) ; int n = ob . nextInt ( ) ; HashMap < String , Integer > map = new HashMap < > ( ) ; int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { String s1 = ob . next ( ) ; if ( ! map . containsKey ( s1 ) ) { map . put ( s1 , 0 ) ; count ++ ; } } System . out . println ( count ) ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int A = sc . nextInt ( ) ; int B = sc . nextInt ( ) ; int C = sc . nextInt ( ) ; int K = sc . nextInt ( ) ; int Ans = 0 ; int Max = Math . max ( A , B ) ; Max = Math . max ( Max , C ) ; double pow = Math . pow ( 2 , K ) ; if ( Max == A ) { Ans = ( A * ( int ) pow ) + B + C ; } else if ( Max == B ) { double pow = Math . pow ( 2 , K ) ; Ans = ( B * ( ( int ) pow ) ) + A + C ; } else { Ans = ( C * ( ( int ) pow ) ) + A + B ; } System . out . println ( Ans ) ; } } +import java . util . Scanner ; public class Main { static float roundUp ( float value ) { float mod = value % 1000 ; if ( mod > 0 ) { value = value + ( 1000 - mod ) ; } return value ; } public static void main ( String [ ] args ) { float debt = gankin ; float gankin = 100_000f ; Scanner sc = new Scanner ( System . in ) ; int nweek = sc . nextInt ( ) ; float debt = gankin ; for ( int i = 0 ; i < nweek ; i ++ ) { debt = roundUp ( debt * 1.05f ) ; } System . out . printf ( " %d \n " , Math . round ( debt ) ) ; } } +import java . io . BufferedReader ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; try { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int count = 0 ; String s = br . readLine ( ) ; String t = br . readLine ( ) ; for ( int i = 0 ; i < 3 ; i ++ ) { if ( s . charAt ( i ) == t . charAt ( i ) ) { count ++ ; } } System . out . println ( count ) ; } catch ( Exception e ) { System . out . println ( e ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner s = new Scanner ( System . in ) ; int n = s . nextInt ( ) ; int [ ] a = new int [ n ] ; for ( int i = 0 ; i < a . length ; i ++ ) { a [ i ] = 0 ; } for ( int i = 0 ; i < n - 1 ; i ++ ) { int i ; a [ s . nextInt ( ) - 1 ] ++ ; } for ( int i : a ) { System . out . println ( i ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner in = new Scanner ( System . in ) ; int k = in . nextInt ( ) ; int n = in . nextInt ( ) ; int [ ] a = new int [ 200009 ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = in . nextInt ( ) ; } a [ n ] = k + a [ 0 ] ; int ans = 1000000009 ; for ( int i = 0 ; i < n ; i ++ ) { ans = Math . min ( ans , k - ( a [ i + 1 ] - a [ i ] ) ) ; } System . out . println ( ans ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String s1 = sc . next ( ) ; int a = Integer . parseInt ( s1 ) ; String s2 = sc . next ( ) ; int b = Integer . parseInt ( s2 ) ; double p = Math . pow ( 10 , 9 ) ; if ( 1 <= a && a <= p ) { double p = Math . pow ( 10 , 9 ) ; if ( 1 <= b && b <= p ) { int d = a / b ; int r = a % b ; double f = ( double ) a / ( double ) b ; System . out . println ( d + " " + r + " " + String . format ( " %1$3f " , f ) ) ; } } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; String str = in . nextLine ( ) ; in . close ( ) ; int max = 0 ; int count = 0 ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { int i = 0 ; char a = str . charAt ( i ) ; if ( a == 'A' || a == 'C' || a == 'G' || a == 'T' ) { count ++ ; } else { if ( max < count ) max = count ; count = 0 ; } } if ( max < count ) max = count ; System . out . println ( max ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws IOException { int i = 0 ; try ( BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ) { String result = " No " ; String inStr = br . readLine ( ) ; String target = br . readLine ( ) ; String ring = inStr + inStr ; if ( inStr . length ( ) >= target . length ( ) ) for ( int i = 0 ; i < inStr . length ( ) ; i ++ ) { if ( target . charAt ( 0 ) == ring . charAt ( i ) ) { if ( target . equals ( ring . substring ( i , i + target . length ( ) ) ) ) { result = " Yes " ; break ; } } } System . out . println ( result ) ; } } } +import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . io . PrintWriter ; import java . util . Map ; import java . util . TreeMap ; public class Main { public static void main ( String [ ] args ) throws Exception { String key ; try ( BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ) { int n = Integer . parseInt ( br . readLine ( ) ) ; Map < String , Integer > map = new TreeMap < > ( ) ; int max = 0 ; for ( int i = 0 ; i < n ; i ++ ) { String s = br . readLine ( ) ; int val = map . containsKey ( s ) ? map . get ( s ) + 1 : 1 ; map . put ( s , val ) ; max = Math . max ( max , val ) ; } PrintWriter out = new PrintWriter ( System . out ) ; for ( String key : map . keySet ( ) ) { if ( map . get ( key ) == max ) { out . println ( key ) ; } } out . flush ( ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner scn = new Scanner ( System . in ) ; String s = scn . next ( ) ; int ans = 0 ; int nans = 0 ; int i = 0 ; while ( i < s . length ( ) ) { int i = 0 ; if ( s . charAt ( i ) == 'A' || s . charAt ( i ) == 'G' || s . charAt ( i ) == 'C' || s . charAt ( i ) == 'T' ) { nans ++ ; i ++ ; } else { ans = Math . max ( nans , ans ) ; nans = 0 ; i ++ ; } } ans = Math . max ( nans , ans ) ; System . out . println ( ans ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; sc . close ( ) ; char [ ] chars = s . toCharArray ( ) ; int count = 0 ; for ( int i = 0 ; i < chars . length / 2 ; i ++ ) { if ( chars [ i ] != chars [ chars . length - 1 - i ] ) { count ++ ; } } System . out . println ( count ) ; } } +import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; String [ ] vote = new String [ N ] ; int i = 0 ; while ( i < N ) { int j = 0 ; vote [ i ] = sc . next ( ) ; i ++ ; } Arrays . sort ( vote ) ; int maxCounter = 0 ; int [ ] a = new int [ N ] ; String [ ] b = new String [ N ] ; int j = 0 ; a [ 0 ] = 1 ; b [ 0 ] = vote [ 0 ] ; for ( i = 1 ; i < N ; i ++ ) { if ( vote [ i ] . equals ( b [ j ] ) ) { a [ j ] ++ ; } else { if ( maxCounter < a [ j ] ) { maxCounter = a [ j ] ; } j ++ ; a [ j ] = 1 ; b [ j ] = vote [ i ] ; } } if ( maxCounter < a [ j ] ) { maxCounter = a [ j ] ; } for ( i = 0 ; i < N ; i ++ ) { if ( a [ i ] == maxCounter ) { System . out . println ( b [ i ] ) ; } } } } +import java . util . * ; import java . lang . * ; import java . io . * ; class Main { public static void main ( String [ ] args ) throws java . lang . Exception { try { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] ar = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { ar [ i ] = 0 ; } int k = sc . nextInt ( ) ; for ( int i = 1 ; i <= k ; i ++ ) { int d = sc . nextInt ( ) ; for ( int j = 1 ; j <= d ; j ++ ) { int i = 0 ; int in = sc . nextInt ( ) ; ar [ in - 1 ] ++ ; } } int s = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( ar [ i ] == 0 ) s ++ ; } System . out . println ( s ) ; } catch ( Exception e ) { } } } +import java . io . BufferedReader ; import java . io . * ; import java . util . * ; import java . util . ArrayList ; import java . util . Iterator ; import java . util . List ; import java . util . Collections ; import java . util . Arrays ; public class Main { public static void main ( final String [ ] args ) { int c = sc . nextInt ( ) ; Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int c = sc . nextInt ( ) ; List < String > list = new ArrayList < > ( ) ; int count = 0 ; if ( b + c - a <= 0 ) { System . out . println ( 0 ) ; } else { System . out . println ( b + c - a ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int k = sc . nextInt ( ) ; int q = sc . nextInt ( ) ; int [ ] p = new int [ n ] ; for ( int i = 0 ; i < q ; i ++ ) p [ sc . nextInt ( ) - 1 ] ++ ; for ( int i = 0 ; i < n ; i ++ ) { if ( k - q + p [ i ] > 0 ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int N = in . nextInt ( ) ; long [ ] mo = new long [ N + 1 ] ; for ( int i = 0 ; i < N + 1 ; i ++ ) { mo [ i ] = in . nextInt ( ) ; } long sum = 0 ; long yu = 0 ; for ( int i = 0 ; i < N ; i ++ ) { yu = in . nextInt ( ) ; if ( yu > mo [ i ] ) { int i = 0 ; sum += mo [ i ] ; yu -= mo [ i ] ; sum += Math . min ( mo [ i + 1 ] , yu ) ; mo [ i + 1 ] = Math . max ( 0 , mo [ i + 1 ] - yu ) ; } else { sum += yu ; } } System . out . print ( sum ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String S = sc . next ( ) ; long K = sc . nextLong ( ) ; int x = 0 ; for ( int i = 0 ; i < S . length ( ) ; i ++ ) { x ++ ; if ( S . charAt ( i ) == '1' && x < K ) { int i = 0 ; continue ; } else { System . out . println ( S . charAt ( i ) ) ; break ; } } } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { try ( Scanner sc = new Scanner ( System . in ) ) { int n = sc . nextInt ( ) , m = sc . nextInt ( ) ; int [ ] [ ] a = new int [ n ] [ m ] ; for ( int i = 0 ; i < n ; i ++ ) { int j = 0 ; for ( int j = 0 ; j < m ; j ++ ) { a [ i ] [ j ] = sc . nextInt ( ) ; } } int [ ] x = new int [ m ] ; for ( int i = 0 ; i < m ; i ++ ) { x [ i ] = sc . nextInt ( ) ; } for ( int i = 0 ; i < n ; i ++ ) { int ans = 0 ; for ( int j = 0 ; j < m ; j ++ ) { ans += x [ j ] * a [ i ] [ j ] ; } System . out . println ( ans ) ; } } } } +import java . util . * ; class Main { public static void main ( String [ ] a ) { int i = 0 ; Scanner c = new Scanner ( System . in ) ; String s = c . next ( ) ; String t = c . next ( ) ; int b = 0 ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( s . charAt ( i ) != t . charAt ( i ) ) b ++ ; } System . out . println ( b ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner scanner = new Scanner ( System . in ) ; String [ ] scan = scanner . nextLine ( ) . split ( " " ) ; int k = scanner . nextInt ( ) ; scanner . close ( ) ; int max = 0 ; int sum = 0 ; for ( int i = 0 ; i < 3 ; i ++ ) { int n = Integer . parseInt ( scan [ i ] ) ; sum += n ; if ( max < n ) max = n ; } sum -= max ; sum += max * Math . pow ( 2 , k ) ; System . out . println ( sum ) ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { int i = 0 ; int count = 0 ; String [ ] ans = { " No " , " Yes " } ; Scanner sc = new Scanner ( System . in ) ; String str = sc . next ( ) ; char [ ] a = new char [ str . length ( ) ] ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { a [ i ] = str . charAt ( i ) ; } if ( a [ 0 ] == a [ 1 ] && a [ 1 ] == a [ 2 ] && a [ 2 ] == a [ 3 ] ) { } else if ( a [ 0 ] == a [ 1 ] && a [ 2 ] == a [ 3 ] ) { count ++ ; } else if ( a [ 0 ] == a [ 2 ] && a [ 1 ] == a [ 3 ] ) { count ++ ; } else if ( a [ 0 ] == a [ 3 ] && a [ 1 ] == a [ 2 ] ) { count ++ ; } System . out . print ( ans [ count ] ) ; } } +import java . util . * ; class Main { static Scanner scan = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { char c = scan . next ( ) . charAt ( 0 ) ; if ( c >= 'A' && c <= 'Z' ) { System . out . println ( " A " ) ; } else if ( c >= 'a' && c <= 'z' ) { System . out . println ( " a " ) ; } } } +import java . io . * ; class Main { public static void main ( String [ ] args ) throws IOException { int i = 0 ; BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int quantity = Integer . parseInt ( br . readLine ( ) ) ; String [ ] str = br . readLine ( ) . split ( " " ) ; long min = 1000000 ; long max = - 1000000 ; long sum = 0 ; for ( int i = 0 ; i < quantity ; i ++ ) { long value = Integer . parseInt ( str [ i ] ) ; if ( min > value ) min = value ; if ( max < value ) max = value ; sum += value ; } System . out . println ( min + " " + max + " " + sum ) ; } } +import java . util . * ; import java . io . * ; public class Main { public static void main ( String [ ] args ) { int num = 0 ; Scanner sc = new Scanner ( System . in ) ; int n = Integer . parseInt ( sc . next ( ) ) ; int x = n ; int num = 0 ; while ( x > 0 ) { num += x % 10 ; x /= 10 ; } if ( n % num == 0 ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } sc . close ( ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = Integer . parseInt ( sc . nextLine ( ) ) ; int max = 1 ; for ( int i = 2 ; i <= Math . sqrt ( N ) ; i ++ ) { int n = i ; int n = i ; for ( int j = 2 ; n * i <= N ; j ++ ) { n *= i ; } max = max < n ? n : max ; } System . out . println ( max ) ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int [ ] array = { 1 , 2 , 3 } ; for ( int i = 0 ; i < 3 ; i ++ ) { if ( ( array [ i ] == a ) || ( array [ i ] == b ) ) { array [ i ] = 0 ; } } for ( int i = 0 ; i < 3 ; i ++ ) { int i = 0 ; if ( array [ i ] != 0 ) { System . out . println ( array [ i ] ) ; return ; } } } } +import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int [ ] a = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { int i = N - 1 ; a [ i ] = sc . nextInt ( ) ; } Arrays . sort ( a ) ; int alice = 0 ; int bob = 0 ; int check = 0 ; for ( int i = N - 1 ; i > - 1 ; i -- ) { if ( check == 0 ) { alice += a [ i ] ; check = 1 ; } else { bob += a [ i ] ; check = 0 ; } } System . out . println ( alice - bob ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int k = sc . nextInt ( ) ; int ans = 0 ; for ( int a = 1 ; a <= k ; a ++ ) { int ret = 0 ; for ( int b = 1 ; b <= k ; b ++ ) { for ( int c = 1 ; c <= k ; c ++ ) { ans += gcd ( a , b , c ) ; } } } System . out . println ( ans ) ; } public static int gcd ( int a , int b , int c ) { return gcd ( a , gcd ( b , c ) ) ; } public static int gcd ( int x , int y ) { int ret = 0 ; if ( x % y == 0 ) return y ; else { int z = x % y ; ret = gcd ( y , z ) ; } return ret ; } } +import java . text . MessageFormat ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Solve s = new Solve ( ) ; s . solve ( ) ; } } class Solve { public void solve ( ) { Scanner sc = new Scanner ( System . in ) ; double N = sc . nextInt ( ) ; double K = sc . nextInt ( ) ; double n = 0d ; double res = 0d ; String message ; for ( double i = 1 ; i <= N ; i ++ ) { int j = 0 ; for ( int j = 0 ; j < 100000 ; j ++ ) { if ( i * Math . pow ( 2 , j ) >= K ) { n = j ; j = 100000 ; } } res += 1 / ( N * Math . pow ( 2 , n ) ) ; } message = MessageFormat . format ( " { 0,number,0.000000000000 } " , res ) ; System . out . println ( message ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int break_count = 0 ; int next = 1 ; for ( int i = 0 ; i < n ; i ++ ) { if ( sc . nextInt ( ) == next ) { int next = 1 ; next ++ ; } else { break_count ++ ; } } if ( next == 1 ) { System . out . println ( - 1 ) ; } else { System . out . println ( break_count ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; sc . nextLine ( ) ; String s = sc . nextLine ( ) ; char [ ] p = { 'A' , 'B' , 'C' } ; int idx = 0 ; int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int i = 0 ; if ( s . charAt ( i ) != p [ idx ] ) { idx = s . charAt ( i ) == p [ 0 ] ? 1 : 0 ; } else idx ++ ; if ( idx == 3 ) { idx = 0 ; count ++ ; } } System . out . println ( count ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] arg ) { int check = 0 ; Scanner scan = new Scanner ( System . in ) ; int A = scan . nextInt ( ) ; int B = scan . nextInt ( ) ; int K = 0 ; int check = 0 ; if ( ( A + B ) % 2 == 0 ) { K = ( Math . abs ( A ) + Math . abs ( B ) ) / 2 ; check ++ ; } if ( check == 0 ) { System . out . println ( " IMPOSSIBLE " ) ; } else { System . out . println ( K ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int [ ] a = new int [ 100 ] ; int count = 0 ; for ( int i = 0 ; i < 100 ; i ++ ) { a [ i ] = 0 ; } int A = sc . nextInt ( ) ; int B = sc . nextInt ( ) ; int C = sc . nextInt ( ) ; int D = sc . nextInt ( ) ; for ( int i = A ; i < B ; i ++ ) { int i = 0 ; a [ i ] ++ ; } for ( int i = C ; i < D ; i ++ ) { a [ i ] ++ ; } for ( int i = 0 ; i < 100 ; i ++ ) { if ( a [ i ] == 2 ) { count ++ ; } } System . out . println ( count ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int i , n , j , S = 0 ; double avr , O = 0 , s ; for ( i = 0 ; ; i ++ ) { int [ ] array = new int [ n ] ; n = sc . nextInt ( ) ; int [ ] array = new int [ n ] ; if ( n == 0 ) { break ; } else { for ( j = 1 ; j <= n ; j ++ ) { array [ j - 1 ] = sc . nextInt ( ) ; S += array [ j - 1 ] ; } avr = S / ( double ) n ; for ( j = 1 ; j <= n ; j ++ ) { O += ( avr - array [ j - 1 ] ) * ( avr - array [ j - 1 ] ) ; } s = Math . sqrt ( O / n ) ; System . out . println ( s ) ; } S = 0 ; O = 0 ; } } } +import java . io . * ; import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . Scanner ; import java . util . StringTokenizer ; import java . util . * ; class Main { static class FastReader { BufferedReader br ; StringTokenizer st ; public FastReader ( ) { int i = 0 ; br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; } String next ( ) { while ( st == null || ! st . hasMoreTokens ( ) ) { try { st = new StringTokenizer ( br . readLine ( ) ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } return st . nextToken ( ) ; } int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } } public static void main ( String [ ] args ) { FastReader ob = new FastReader ( ) ; String w = ob . next ( ) ; int [ ] arr = new int [ 26 ] ; for ( int i = 0 ; i < w . length ( ) ; i ++ ) { int k = w . charAt ( i ) - 'a' ; arr [ k ] = arr [ k ] + 1 ; } for ( int i = 0 ; i < 26 ; i ++ ) { if ( arr [ i ] % 2 != 0 ) { System . out . println ( " No " ) ; return ; } } System . out . println ( " Yes " ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . lang . Character ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws IOException { int i = 0 ; Scanner scan = new Scanner ( System . in ) ; int [ ] cnt = new int [ 26 ] ; int num = 0 ; String line = " " ; while ( scan . hasNext ( ) ) { line = scan . nextLine ( ) ; String st = line . toLowerCase ( ) ; for ( int i = 0 ; i < st . length ( ) ; i ++ ) { char c = st . charAt ( i ) ; if ( 'a' <= c && c <= 'z' ) cnt [ c - 'a' ] ++ ; else continue ; } } for ( int i = 0 ; i < cnt . length ; i ++ ) { System . out . println ( ( char ) ( 'a' + i ) + " : " + cnt [ i ] ) ; } } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; String t = sc . next ( ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; String ans = sc . next ( ) ; int sum = 0 ; if ( ans . equals ( s ) ) { int sum = 0 ; sum = a - 1 ; System . out . println ( sum + " " + b ) ; } if ( ans . equals ( t ) ) { sum = b - 1 ; System . out . println ( a + " " + sum ) ; } sc . close ( ) ; } } +import java . math . BigInteger ; 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 ( ) ; BigInteger c = BigInteger . valueOf ( a ) . multiply ( BigInteger . valueOf ( b ) ) ; int d = a % b ; while ( d != 0 ) { int d = a % b ; a = b ; b = d ; d = a % b ; } System . out . println ( c . divide ( BigInteger . valueOf ( b ) ) ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int s = sc . nextInt ( ) ; int [ ] a = new int [ 1000000 ] ; int Answer = 0 ; a [ 0 ] = s ; loop : for ( int i = 1 ; i < a . length ; i ++ ) { if ( a [ i - 1 ] % 2 == 0 ) { a [ i ] = a [ i - 1 ] / 2 ; } else if ( a [ i - 1 ] % 2 != 0 ) { int j = 0 ; a [ i ] = a [ i - 1 ] * 3 + 1 ; } for ( int j = 0 ; j < i ; j ++ ) { if ( a [ i ] == a [ j ] ) { Answer = i ; break loop ; } } } System . out . println ( Answer + 1 ) ; sc . close ( ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String [ ] parts = br . readLine ( ) . split ( " " ) ; int H = Integer . parseInt ( parts [ 0 ] ) ; int A = Integer . parseInt ( parts [ 1 ] ) ; int a = H % A ; if ( a == 0 ) { int A = Integer . parseInt ( parts [ 1 ] ) ; System . out . println ( H / A ) ; } else { System . out . println ( H / A + 1 ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int N = scan . nextInt ( ) ; int M = scan . nextInt ( ) ; int [ ] [ ] root = new int [ N ] [ N ] ; for ( int i = 0 ; i < M ; i ++ ) { int j = 0 ; int a = scan . nextInt ( ) - 1 ; int b = scan . nextInt ( ) - 1 ; root [ a ] [ b ] ++ ; root [ b ] [ a ] ++ ; } for ( int i = 0 ; i < N ; i ++ ) { int sum = 0 ; for ( int j = 0 ; j < N ; j ++ ) { sum += root [ i ] [ j ] ; } System . out . println ( sum ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { double h = A - ( T - ( 0.006 * sc . nextDouble ( ) ) ) ; Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; double T = sc . nextDouble ( ) , A = sc . nextInt ( ) , temp = 60001 ; int ans = 0 ; for ( int i = 1 ; i <= N ; i ++ ) { double h = A - ( T - ( 0.006 * sc . nextDouble ( ) ) ) ; if ( Math . abs ( h ) < Math . abs ( temp ) ) { temp = Math . abs ( h ) ; ans = i ; } } System . out . println ( ans ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; String S = sc . next ( ) ; int count = 0 ; for ( int i = 0 ; i < N - 2 ; i ++ ) { int i = 0 ; if ( S . substring ( i , i + 3 ) . equals ( " ABC " ) ) { count ++ ; } } System . out . println ( count ) ; } } +import java . util . * ; import java . lang . * ; import java . math . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int variety = sc . nextInt ( ) ; int [ ] k = new int [ n ] ; int [ ] preference = new int [ variety ] ; int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { k [ i ] = sc . nextInt ( ) ; for ( int j = 0 ; j < k [ i ] ; j ++ ) { int i = 0 ; int tmp = sc . nextInt ( ) ; preference [ tmp - 1 ] ++ ; } } for ( int i = 0 ; i < variety ; i ++ ) { if ( preference [ i ] == n ) { ans ++ ; } } System . out . println ( ans ) ; sc . close ( ) ; } private static int gcd ( int m , int n ) { if ( m < n ) { return gcd ( n , m ) ; } if ( n == 0 ) { return m ; } return gcd ( n , m % n ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int m = 0 ; Scanner scan = new Scanner ( System . in ) ; int n = scan . nextInt ( ) ; for ( int h = 0 ; h < 241 ; h ++ ) { if ( n >= 3600 ) { n = n - 3600 ; } else { System . out . print ( h + " : " ) ; break ; } } for ( int m = 0 ; m < 60 ; m ++ ) { if ( n >= 60 ) { n = n - 60 ; } else { System . out . println ( m + " : " + n ) ; break ; } } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner stdIn = new Scanner ( System . in ) ; int N = stdIn . nextInt ( ) ; int A = stdIn . nextInt ( ) ; int B = stdIn . nextInt ( ) ; int z = 1 , y = 0 , x = 0 , ans = 0 ; while ( z <= N ) { y = z ; while ( true ) { int z = 1 , y = 0 , x = 0 , ans = 0 ; x += y % 10 ; y /= 10 ; if ( y == 0 ) break ; } if ( A <= x && B >= x ) ans += z ; x = 0 ; z ++ ; } System . out . println ( ans ) ; } } +import java . util . * ; import java . io . * ; import java . lang . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; char [ ] s = sc . next ( ) . toCharArray ( ) ; char [ ] t = sc . next ( ) . toCharArray ( ) ; int count = 0 ; int len = s . length ; for ( int i = 0 ; i < len ; i ++ ) { int i = 0 ; if ( s [ i ] != t [ i ] ) count ++ ; } System . out . println ( count ) ; } } +import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . util . Arrays ; import java . util . StringTokenizer ; public class Main { public static void main ( String [ ] args ) throws Exception { int i = 0 ; BufferedReader input = new BufferedReader ( new InputStreamReader ( System . in ) ) ; StringTokenizer tokenizer = new StringTokenizer ( input . readLine ( ) ) ; int n = Integer . parseInt ( tokenizer . nextToken ( ) ) ; String [ ] a = new String [ n ] ; for ( int i = 0 ; i < a . length ; i ++ ) { a [ i ] = input . readLine ( ) ; } Arrays . sort ( a ) ; StringBuilder out = new StringBuilder ( ) ; for ( int i = 0 ; i < n ; i ++ ) { out . append ( a [ i ] ) ; } System . out . println ( out ) ; } } +import java . util . * ; import java . lang . * ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; String s = sc . next ( ) ; String t = sc . next ( ) ; String result = new String ( ) ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { result = result . concat ( String . valueOf ( s . charAt ( i ) ) ) ; result = result . concat ( String . valueOf ( t . charAt ( i ) ) ) ; } System . out . println ( result ) ; sc . close ( ) ; } } +import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = N - 1 ; Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int [ ] A = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { A [ i ] = sc . nextInt ( ) ; } Arrays . parallelSort ( A ) ; int count = 1 ; for ( int i = N - 1 ; i > 0 ; i -- ) { if ( A [ i ] != A [ i - 1 ] ) { count ++ ; } } System . out . println ( count ) ; } } +import java . util . * ; public class Main { static Scanner sc = new Scanner ( System . in ) ; static Scanner sc2 = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { int i = 0 ; int N = sc . nextInt ( ) ; int T = sc . nextInt ( ) ; int [ ] c = new int [ N ] ; int [ ] t = new int [ N ] ; int min = 10000 ; for ( int i = 0 ; i < N ; i ++ ) { c [ i ] = sc . nextInt ( ) ; t [ i ] = sc . nextInt ( ) ; } for ( int i = 0 ; i < N ; i ++ ) { if ( T >= t [ i ] ) { min = min > c [ i ] ? c [ i ] : min ; } } if ( min == 10000 ) { System . out . println ( " TLE " ) ; } else { System . out . println ( min ) ; } } } +import java . util . Scanner ; import java . util . List ; import java . util . ArrayList ; public class Main { public static void main ( String [ ] args ) { int b = sc . nextInt ( ) ; Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; if ( a > b ) { System . out . println ( 2 * a - 1 ) ; } else if ( a == b ) { System . out . println ( 2 * a ) ; } else { System . out . println ( 2 * b - 1 ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; String S = sc . next ( ) ; String T = sc . next ( ) ; char [ ] s = new char [ n ] ; char [ ] t = new char [ n ] ; int i ; int m ; char [ ] b = new char [ 2 * n ] ; for ( i = 0 ; i < n ; i ++ ) { s [ i ] = S . charAt ( i ) ; } for ( i = 0 ; i < n ; i ++ ) { t [ i ] = T . charAt ( i ) ; } for ( i = 0 , m = 0 ; i < n ; i ++ , m = m + 2 ) { b [ m ] = s [ i ] ; } for ( i = 0 , m = 1 ; i < n ; i ++ , m = m + 2 ) { char [ ] b = new char [ 2 * n ] ; b [ m ] = t [ i ] ; } String str = String . valueOf ( b ) ; System . out . println ( str ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int elements = sc . nextInt ( ) ; int [ ] value = new int [ elements ] ; for ( int i = 0 ; i < elements ; i ++ ) { value [ i ] = sc . nextInt ( ) ; } solve ( value ) ; } public static void solve ( int [ ] value ) { int an ; double result = 0 ; for ( int an : value ) { result += ( double ) 1 / an ; } result = 1 / result ; System . out . println ( result ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; while ( true ) { int j = i + 1 ; int n = scan . nextInt ( ) ; int x = scan . nextInt ( ) ; if ( n == 0 ) break ; int count = 0 ; for ( int i = 1 ; i <= n - 2 ; i ++ ) { for ( int j = i + 1 ; j <= n - 1 ; j ++ ) { int check_number = x - i - j ; if ( check_number <= n && check_number > j ) { count ++ ; } } } System . out . println ( count ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; String s = sc . next ( ) ; boolean val = true ; if ( s . length ( ) % 2 != 0 ) val = false ; else { int i = 0 ; for ( int i = 0 ; i < n / 2 ; i ++ ) { if ( s . charAt ( i ) != s . charAt ( i + n / 2 ) ) { val = false ; break ; } } } System . out . println ( val ? " Yes " : " No " ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) { StringBuilder result = new StringBuilder ( ) ; new Main ( ) . run ( ) ; } public void run ( ) { try ( BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ) { String line ; String [ ] num ; int a , b , t , gdc ; long lcm ; StringBuilder result = new StringBuilder ( ) ; while ( true ) { if ( ( ( line = br . readLine ( ) ) == null ) || line . isEmpty ( ) ) break ; num = line . split ( " " ) ; a = Integer . parseInt ( num [ 0 ] ) ; b = Integer . parseInt ( num [ 1 ] ) ; if ( a < b ) { t = a ; a = b ; b = t ; } gdc = gdc ( a , b ) ; lcm = lcm ( a , b , gdc ) ; result . append ( gdc ) . append ( " " ) . append ( lcm ) . append ( " \n " ) ; } System . out . print ( result ) ; } catch ( IOException e ) { System . out . println ( " IOException! " ) ; } } private int gdc ( int x , int y ) { int d = x % y ; if ( d == 0 ) return y ; else return gdc ( y , d ) ; } private long lcm ( long x , long y , int gdc ) { return x * y / gdc ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int num = 1 ; for ( int i = 0 ; i < 9 ; i ++ ) { int i = 0 ; if ( N - 111 > 0 ) { N -= 111 ; } else { num += i ; break ; } } System . out . println ( num * 111 ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; long [ ] townmonster = new long [ n + 1 ] ; for ( int i = 0 ; i < n + 1 ; i ++ ) { townmonster [ i ] = sc . nextLong ( ) ; } long [ ] yusha = new long [ n + 1 ] ; for ( int i = 0 ; i < n ; i ++ ) { yusha [ i ] = sc . nextLong ( ) ; } yusha [ n ] = 0 ; long count = 0 ; long yojou = 0 ; for ( int i = 0 ; i < n + 1 ; i ++ ) { long nokori = target - yojou ; long target = townmonster [ i ] ; long yusha_yoryoku = yusha [ i ] ; if ( target >= yusha_yoryoku + yojou ) { count += yusha_yoryoku + yojou ; yojou = 0 ; } else { count += target ; long nokori = target - yojou ; if ( nokori > 0 ) { yojou = yusha_yoryoku - nokori ; } else { yojou = yusha_yoryoku ; } } } System . out . println ( count ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int k = scanner . nextInt ( ) ; int n = scanner . nextInt ( ) ; long first = 0 ; long previous = 0 ; long max = 0 ; long sum = 0 ; for ( long i = 0 ; i < n ; i ++ ) { long saigo = k - sum + first ; int a = scanner . nextInt ( ) ; if ( i == 0 ) { first = a ; previous = a ; max = a ; sum = a ; } else { long aida = a - previous ; previous = a ; sum = sum + aida ; if ( aida > max ) { max = aida ; } } } long saigo = k - sum + first ; if ( saigo > max ) { max = saigo ; } System . out . println ( k - max ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int d = Integer . parseInt ( sc . next ( ) ) ; int n = Integer . parseInt ( sc . next ( ) ) ; int result = n ; if ( d == 0 && n == 100 ) { result ++ ; } else if ( 0 < d ) { for ( int i = 0 ; i < d ; i ++ ) { int i = 0 ; result *= 100 ; } if ( n == 100 ) { int add = 1 ; for ( int i = 0 ; i < d ; i ++ ) { add *= 100 ; } result += add ; } } System . out . println ( result ) ; sc . close ( ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . StringTokenizer ; public class Main { public static void main ( String [ ] args ) { FastReader sc = new FastReader ( ) ; int n = sc . nextInt ( ) ; int t = sc . nextInt ( ) ; String res = " TLE " ; int minCost = Integer . MAX_VALUE ; for ( int i = 0 ; i < n ; i ++ ) { int c = sc . nextInt ( ) ; int T = sc . nextInt ( ) ; if ( T <= t ) { if ( c < minCost ) { minCost = c ; res = " " + c ; } } } System . out . println ( res ) ; } static class FastReader { BufferedReader br ; StringTokenizer st ; public FastReader ( ) { br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; } String next ( ) { while ( st == null || ! st . hasMoreElements ( ) ) { try { st = new StringTokenizer ( br . readLine ( ) ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } return st . nextToken ( ) ; } int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } long nextLong ( ) { return Long . parseLong ( next ( ) ) ; } double nextDouble ( ) { return Double . parseDouble ( next ( ) ) ; } String nextLine ( ) { String str = " " ; try { str = br . readLine ( ) ; } catch ( IOException e ) { String str = " " ; e . printStackTrace ( ) ; } return str ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int cnt = 1 ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int cnt = 1 ; while ( true ) { if ( n == 1 || n == 2 || n == 4 ) { System . out . println ( cnt + 3 ) ; return ; } if ( n % 2 == 0 ) n /= 2 ; else n = n * 3 + 1 ; cnt ++ ; } } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner stdIn = new Scanner ( System . in ) ; int r , c , a [ ] [ ] = new int [ 101 ] [ 101 ] , i , j ; r = stdIn . nextInt ( ) ; c = stdIn . nextInt ( ) ; for ( i = 0 ; i < r ; i ++ ) { for ( j = 0 ; j < c ; j ++ ) { a [ i ] [ j ] = stdIn . nextInt ( ) ; a [ i ] [ c ] += a [ i ] [ j ] ; } } for ( i = 0 ; i < c ; i ++ ) { int r , c , a [ ] [ ] = new int [ 101 ] [ 101 ] , i , j ; for ( j = 0 ; j < r ; j ++ ) a [ r ] [ i ] += a [ j ] [ i ] ; a [ r ] [ c ] += a [ r ] [ i ] ; } for ( i = 0 ; i <= r ; i ++ ) { for ( j = 0 ; j <= c ; j ++ ) { if ( j != 0 ) System . out . print ( " " ) ; System . out . print ( a [ i ] [ j ] ) ; } System . out . println ( ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int j = 0 ; Scanner scan = new Scanner ( System . in ) ; int [ ] [ ] [ ] houses = new int [ 4 ] [ 3 ] [ 10 ] ; int n = scan . nextInt ( ) ; int m = scan . nextInt ( ) ; int [ ] [ ] a = new int [ n ] [ m ] ; int [ ] b = new int [ m ] ; int [ ] c = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < m ; j ++ ) { int element = scan . nextInt ( ) ; a [ i ] [ j ] = element ; } } for ( int i = 0 ; i < m ; i ++ ) { int element = scan . nextInt ( ) ; b [ i ] = element ; } for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < m ; j ++ ) { c [ i ] += a [ i ] [ j ] * b [ j ] ; } System . out . println ( c [ i ] ) ; } } } +import java . io . IOException ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws IOException { Scanner sc = new Scanner ( System . in ) ; int n = Integer . parseInt ( sc . nextLine ( ) ) ; int counter = 0 ; int [ ] [ ] result = new int [ n ] [ 2 ] ; for ( int i = 0 ; i < n ; i ++ ) { result [ i ] [ 0 ] = sc . nextInt ( ) ; result [ i ] [ 1 ] = sc . nextInt ( ) ; } for ( int i = 0 ; i < n ; i ++ ) { if ( result [ i ] [ 0 ] == result [ i ] [ 1 ] ) { counter ++ ; if ( counter == 3 ) { break ; } } else { int i = 0 ; counter = 0 ; } } if ( counter == 3 ) { System . out . println ( " Yes " ) ; } else { System . out . println ( ( " No " ) ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int N = scanner . nextInt ( ) ; int N6 = N / 100000 % 10 ; int N5 = N / 10000 % 10 ; int N4 = N / 1000 % 10 ; int N3 = N / 100 % 10 ; int N2 = N / 10 % 10 ; int result = 0 ; if ( N6 == 1 ) { result = 90909 ; } else if ( N5 != 0 ) { result = ( N - 9999 ) + 909 ; } else if ( N4 != 0 ) { result = 909 ; } else if ( N3 != 0 ) { result = ( N - 99 ) + 9 ; } else if ( N2 != 0 ) { result = 9 ; } else { int result = 0 ; result = N ; } System . out . println ( result ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int [ ] B = new int [ N ] ; for ( int i = 1 ; i < N ; i ++ ) { B [ i ] = sc . nextInt ( ) ; } sc . close ( ) ; int [ ] A = new int [ N + 1 ] ; A [ 1 ] = B [ 1 ] ; for ( int i = 1 ; i < N ; i ++ ) { if ( B [ i ] < A [ i ] ) { A [ i ] = B [ i ] ; } A [ i + 1 ] = B [ i ] ; } int max = 0 ; for ( int i = 1 ; i <= N ; i ++ ) { int i = 1 ; max += A [ i ] ; } System . out . println ( max ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long L ; try ( Scanner sc = new Scanner ( System . in ) ) { L = sc . nextLong ( ) ; } double c = ( double ) L / 3 ; double M = c * c * c ; System . out . println ( String . format ( " %.8f " , M ) ) ; } } +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 + 1 ] ; int [ ] b = new int [ n + 1 ] ; int [ ] c = new int [ n ] ; String dm = " " ; for ( int i = 1 ; i <= n ; i ++ ) { int i = 1 ; a [ i ] = sc . nextInt ( ) ; } for ( int i = 1 ; i <= n ; i ++ ) { b [ i ] = sc . nextInt ( ) ; } for ( int i = 1 ; i < n ; i ++ ) { c [ i ] = sc . nextInt ( ) ; } int ans = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { ans += b [ a [ i ] ] ; if ( i < n && a [ i + 1 ] == a [ i ] + 1 ) ans += c [ a [ i ] ] ; } System . out . println ( ans ) ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int A = sc . nextInt ( ) ; int B = sc . nextInt ( ) ; int C = sc . nextInt ( ) ; int X = sc . nextInt ( ) ; int cnt = 0 ; for ( int i = 0 ; i <= A ; i ++ ) { int j = 0 ; for ( int j = 0 ; j <= B ; j ++ ) { int k = ( X - i * 500 - j * 100 ) / 50 ; if ( k >= 0 && k <= C ) { cnt ++ ; } } } System . out . println ( cnt ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { int l = 0 ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] [ ] [ ] bill = new int [ 4 ] [ 3 ] [ 10 ] ; int b ; int f ; int r ; int v = 0 ; for ( int i = 0 ; i < n ; i ++ ) { b = sc . nextInt ( ) ; f = sc . nextInt ( ) ; r = sc . nextInt ( ) ; v = sc . nextInt ( ) ; bill [ b - 1 ] [ f - 1 ] [ r - 1 ] = bill [ b - 1 ] [ f - 1 ] [ r - 1 ] + ( v ) ; } for ( int j = 0 ; j < 4 ; j ++ ) { for ( int k = 0 ; k < 3 ; k ++ ) { for ( int l = 0 ; l < 10 ; l ++ ) { System . out . print ( " " + bill [ j ] [ k ] [ l ] ) ; } System . out . println ( ) ; } if ( j != 3 ) { System . out . println ( " #################### " ) ; } } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String N_str = sc . next ( ) ; String [ ] N_list = N_str . split ( " " ) ; int check = 0 ; for ( int i = 0 ; i < N_list . length ; i ++ ) { int i = 0 ; check += Integer . parseInt ( N_list [ i ] ) ; } if ( check % 9 == 0 ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } } +import java . util . * ; import java . lang . * ; import java . io . * ; class Main { public static void main ( String [ ] args ) throws java . lang . Exception { Scanner scan = new Scanner ( System . in ) ; int count = 0 ; BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String w = " " ; String line = " " ; while ( ( line = br . readLine ( ) ) != null ) { int i = 0 ; if ( w . isEmpty ( ) ) { w = line . toLowerCase ( ) ; continue ; } if ( " END_OF_TEXT " . equals ( line ) ) { break ; } String [ ] words = line . split ( " " ) ; for ( int i = 0 ; i < words . length ; i ++ ) { if ( w . equals ( words [ i ] . toLowerCase ( ) ) ) { count ++ ; } } } System . out . println ( count ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String buff = " " ; int m = sc . nextInt ( ) ; int k = sc . nextInt ( ) ; double count = 1 , flag = 0 ; double count1 = 0 , count2 = 0 ; int count3 = 9999999 ; int [ ] [ ] array1 = new int [ m ] [ k ] ; for ( int i = 0 ; i < m ; i ++ ) { for ( int j = 0 ; j < k ; j ++ ) { array1 [ i ] [ j ] = sc . nextInt ( ) ; } } for ( int i = 0 ; i < m - 1 ; i ++ ) { for ( int j = i + 1 ; j < m ; j ++ ) { int g = 0 ; for ( int g = 0 ; g < k ; g ++ ) { count2 += Math . pow ( ( array1 [ i ] [ g ] - array1 [ j ] [ g ] ) , 2 ) ; } count = Math . sqrt ( count2 ) ; count3 = ( int ) count ; if ( count - count3 == 0 ) { count1 ++ ; } count2 = 0 ; } } System . out . println ( ( int ) count1 ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; Random rand = new Random ( ) ; int hp = sc . nextInt ( ) ; int n = sc . nextInt ( ) ; int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { sum += sc . nextInt ( ) ; } if ( hp <= sum ) { int sum = 0 ; System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } } +import java . util . Arrays ; import java . util . List ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner keyboard = new Scanner ( System . in ) ; String SA = keyboard . nextLine ( ) ; String SB = keyboard . nextLine ( ) ; String SC = keyboard . nextLine ( ) ; String input = SA . substring ( 0 , 1 ) ; keyboard . close ( ) ; System . out . print ( solve ( SA , SB , SC , input ) ) ; } public static String solve ( String A , String B , String C , String input2 ) { String output ; if ( input2 . equals ( " a " ) ) { if ( A . length ( ) != 0 ) { output = A . substring ( 0 , 1 ) ; return solve ( A . substring ( 1 ) , B , C , output ) ; } else { return " A " ; } } else if ( input2 . equals ( " b " ) ) { if ( B . length ( ) != 0 ) { output = B . substring ( 0 , 1 ) ; return solve ( A , B . substring ( 1 ) , C , output ) ; } else { return " B " ; } } else { if ( C . length ( ) != 0 ) { output = C . substring ( 0 , 1 ) ; return solve ( A , B , C . substring ( 1 ) , output ) ; } else { String output ; return " C " ; } } } } +import java . util . ArrayList ; import java . util . List ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { try ( Scanner scanner = new Scanner ( System . in ) ) { Integer i ; int N = scanner . nextInt ( ) ; int count = 0 ; boolean flg = true ; List < Integer > numList = new ArrayList < > ( ) ; scanner . nextLine ( ) ; for ( int i = 0 ; i < N ; i ++ ) { int j = scanner . nextInt ( ) ; if ( j % 2 == 1 ) { flg = false ; break ; } numList . add ( j ) ; } while ( flg ) { List < Integer > nextNumList = new ArrayList < > ( ) ; for ( Integer i : numList ) { if ( i % 2 == 1 ) { flg = false ; break ; } nextNumList . add ( i / 2 ) ; } if ( ! flg ) { break ; } numList = nextNumList ; count ++ ; } System . out . println ( count ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = Integer . parseInt ( sc . next ( ) ) ; int d = Integer . parseInt ( sc . next ( ) ) ; int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int count = 0 ; long x = Integer . parseInt ( sc . next ( ) ) ; long y = Integer . parseInt ( sc . next ( ) ) ; if ( Math . sqrt ( x * x + y * y ) <= d ) { count ++ ; } } System . out . println ( count ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int size = scanner . nextInt ( ) ; int [ ] arr = new int [ size ] ; for ( int i = 0 ; i < size ; i ++ ) { int cost1 = Integer . MAX_VALUE , cost2 = Integer . MAX_VALUE ; arr [ i ] = scanner . nextInt ( ) ; } System . out . println ( frog1 ( arr ) ) ; scanner . close ( ) ; } public static int frog1 ( int [ ] arr ) { int [ ] sol = new int [ arr . length ] ; sol [ arr . length - 1 ] = 0 ; for ( int j = arr . length - 2 ; j >= 0 ; j -- ) { int cost1 = Integer . MAX_VALUE , cost2 = Integer . MAX_VALUE ; if ( j + 1 < arr . length ) { cost1 = Math . abs ( arr [ j + 1 ] - arr [ j ] ) + sol [ j + 1 ] ; } if ( j + 2 < arr . length ) { cost2 = Math . abs ( arr [ j + 2 ] - arr [ j ] ) + sol [ j + 2 ] ; } sol [ j ] = Math . min ( cost1 , cost2 ) ; } return sol [ 0 ] ; } } +import java . util . * ; public class Main { static int c = 0 ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int num = sc . nextInt ( ) ; int k = sc . nextInt ( ) ; double sum_power = 0 , count = 0 ; if ( ( num >= 1 && num <= 100000 ) && ( k >= 1 && k <= 100000 ) ) { for ( int i = 1 ; i <= num ; i ++ ) { int i = 1 ; count = doublet ( i , k ) ; double p = Math . pow ( 2 , count ) * num ; sum_power = sum_power + 1 / p ; c = 0 ; } System . out . println ( sum_power ) ; } } static int doublet ( int n , int f ) { if ( n < f ) { c = c + 1 ; return doublet ( 2 * n , f ) ; } else return c ; } } +import java . io . BufferedReader ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws Exception { int i = 0 ; BufferedReader breader = getReader ( ) ; int [ ] ary = getAry ( breader ) ; while ( ary [ 0 ] != 0 || ary [ 1 ] != 0 ) { for ( int i = 0 ; i < ary [ 0 ] ; i ++ ) { for ( int j = 0 ; j < ary [ 1 ] ; j ++ ) { System . out . print ( " # " ) ; } System . out . println ( " " ) ; } System . out . println ( " " ) ; ary = getAry ( breader ) ; } } public static BufferedReader getReader ( ) { return ( new BufferedReader ( new InputStreamReader ( System . in ) ) ) ; } public static int [ ] getAry ( BufferedReader br ) throws Exception { String line = br . readLine ( ) ; String [ ] nstr = line . split ( " " ) ; int [ ] n = new int [ nstr . length ] ; for ( int i = 0 ; i < nstr . length ; i ++ ) { n [ i ] = Integer . valueOf ( nstr [ i ] ) ; } return n ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; int sum = 0 ; int [ ] line = new int [ 3 ] ; for ( int i = 0 ; i < 3 ; i ++ ) { line [ i ] = sc . nextInt ( ) ; sum += line [ i ] ; } int min = Integer . MAX_VALUE ; for ( int i = 0 ; i < 3 ; i ++ ) { min = Math . min ( min , sum - line [ i ] ) ; } System . out . println ( min ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int M = sc . nextInt ( ) ; int [ ] A = new int [ N ] ; int wa = 0 ; for ( int i = 0 ; i < N ; i ++ ) { int i = N - 1 ; A [ i ] = sc . nextInt ( ) ; wa += A [ i ] ; } sc . close ( ) ; int ok = 0 ; for ( int i = N - 1 ; i >= 0 ; i -- ) { ok += A [ i ] * ( 4 * M ) >= wa ? 1 : 0 ; } System . out . println ( ok >= M ? " Yes " : " No " ) ; } } +import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int m = sc . nextInt ( ) ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int m = sc . nextInt ( ) ; long count = 0 ; long count1 = 0 ; int [ ] array = new int [ 3 ] ; Arrays . sort ( array ) ; if ( n <= 9 && m <= 9 ) { System . out . println ( n * m ) ; } else { System . out . println ( - 1 ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int n = scan . nextInt ( ) ; int [ ] a = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = scan . nextInt ( ) ; } int count = 0 ; while ( true ) { boolean bool = false ; for ( int an : a ) { if ( an % 2 != 0 ) { int i = 0 ; bool = true ; } } if ( bool ) { break ; } for ( int i = 0 ; i < n ; i ++ ) { a [ i ] /= 2 ; } count ++ ; } System . out . println ( count ) ; } } +import java . math . * ; import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int x = sc . nextInt ( ) ; while ( true ) { int x = sc . nextInt ( ) ; if ( BigInteger . valueOf ( x ) . isProbablePrime ( 100 ) ) { System . out . println ( x ) ; return ; } x ++ ; } } } +import java . util . ArrayList ; import java . util . List ; import java . util . Scanner ; public class Main { public static void main ( String [ ] arges ) { Scanner sc = new Scanner ( System . in ) ; List < String > k = new ArrayList < String > ( ) ; while ( true ) { String line = sc . nextLine ( ) ; k . add ( line ) ; if ( line . equals ( " 0 " ) ) { break ; } } for ( String string : k ) { if ( string . equals ( " 0 " ) ) { break ; } String [ ] lig = new String [ string . length ( ) ] ; for ( int i = 0 ; i < string . length ( ) ; i ++ ) { lig [ i ] = string . substring ( i , i + 1 ) ; } int sum = 0 ; int [ ] v = new int [ lig . length ] ; for ( int i = 0 ; i < lig . length ; i ++ ) { int i = 0 ; v [ i ] = Integer . parseInt ( lig [ i ] ) ; sum += v [ i ] ; } System . out . println ( sum ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int res = 0 ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int ans = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { int digCount = digCount ( i ) ; if ( digCount % 2 != 0 ) { ans ++ ; } } System . out . println ( ans ) ; } static int digCount ( int n ) { int res = 0 ; while ( n > 0 ) { res ++ ; n /= 10 ; } return res ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] A ; A = new int [ n ] ; int count = 0 ; for ( int i = 0 ; i < n ; ++ i ) { A [ i ] = sc . nextInt ( ) ; } for ( int i = 0 ; i < n - 1 ; ++ i ) { int i = 0 ; for ( int j = 0 ; j < n - 1 ; ++ j ) { if ( A [ j ] > A [ j + 1 ] ) { int c ; c = A [ j ] ; A [ j ] = A [ j + 1 ] ; A [ j + 1 ] = c ; count ++ ; } } } print ( A , n ) ; System . out . println ( count ) ; } public static void print ( int [ ] A , int n ) { for ( int i = 0 ; i < n ; ++ i ) { System . out . print ( A [ i ] ) ; if ( i < n - 1 ) { System . out . print ( " " ) ; } } System . out . println ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int [ ] arr = new int [ N ] ; boolean flg = true ; int count = 0 ; for ( int i = 0 ; i < N ; i ++ ) { arr [ i ] = sc . nextInt ( ) ; } while ( flg ) { int j = 0 ; boolean existOdd = false ; for ( int i = 0 ; i < N ; i ++ ) { if ( arr [ i ] % 2 != 0 ) { flg = false ; } } if ( ! flg ) break ; for ( int j = 0 ; j < N ; j ++ ) { arr [ j ] = arr [ j ] / 2 ; } count ++ ; } System . out . println ( count ) ; } } +import java . util . ArrayList ; import java . util . List ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner stdIn = new Scanner ( System . in ) ; List < Integer > H = new ArrayList < Integer > ( ) ; List < Integer > W = new ArrayList < Integer > ( ) ; int lastH = 0 ; int lastW = 0 ; do { lastH = stdIn . nextInt ( ) ; lastW = stdIn . nextInt ( ) ; H . add ( lastH ) ; W . add ( lastW ) ; } while ( lastH != 0 || lastW != 0 ) ; for ( int i = 0 ; i < H . size ( ) - 1 ; i ++ ) { int i = 0 ; for ( int j = 0 ; j < H . get ( i ) ; j ++ ) { for ( int k = 0 ; k < W . get ( i ) ; k ++ ) { System . out . print ( " # " ) ; } System . out . println ( ) ; } System . out . println ( ) ; } } } +import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . io . IOException ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader in = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String [ ] str = in . readLine ( ) . split ( " " ) ; int n = Integer . parseInt ( str [ 0 ] ) ; int m = Integer . parseInt ( str [ 1 ] ) ; int [ ] l = new int [ m ] ; int [ ] r = new int [ m ] ; int l_max = 0 ; int r_min = 100000 ; for ( int i = 0 ; i < m ; i ++ ) { int i = 0 ; str = in . readLine ( ) . split ( " " ) ; l [ i ] = Integer . parseInt ( str [ 0 ] ) ; l_max = Math . max ( l [ i ] , l_max ) ; r [ i ] = Integer . parseInt ( str [ 1 ] ) ; r_min = Math . min ( r [ i ] , r_min ) ; } System . out . println ( r_min - l_max + 1 > 0 ? r_min - l_max + 1 : 0 ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int cnt = 0 ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int x = sc . nextInt ( ) ; int [ ] l = new int [ n ] ; int d = 0 ; int i = 0 ; for ( int cnt = 0 ; cnt < n ; cnt ++ ) { l [ cnt ] = sc . nextInt ( ) ; d += l [ cnt ] ; if ( d > x ) { i = cnt + 1 ; break ; } else { i = n + 1 ; } } System . out . println ( i ) ; sc . close ( ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { double temp = sc . nextDouble ( ) ; Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int T = sc . nextInt ( ) ; int A = sc . nextInt ( ) ; double [ ] Temp = new double [ N ] ; double min = ( double ) Integer . MAX_VALUE ; int minNum = - 1 ; for ( int i = 0 ; i < N ; i ++ ) { double temp = sc . nextDouble ( ) ; if ( Math . abs ( A - ( T - temp * 0.006 ) ) < min ) { min = Math . abs ( A - ( T - temp * 0.006 ) ) ; minNum = i + 1 ; } } System . out . println ( minNum ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Main main = new Main ( ) ; main . run ( ) ; } long a ; long b ; long c ; long k ; long ans ; public void run ( ) { Scanner sc = new Scanner ( System . in ) ; a = sc . nextLong ( ) ; b = sc . nextLong ( ) ; c = sc . nextLong ( ) ; k = sc . nextLong ( ) ; sc . close ( ) ; solve ( ) ; } private void solve ( ) { if ( a < k ) { ans = a ; k -= a ; } else { ans = k ; k = 0 ; } if ( b < k && k > 0 ) { k -= b ; } else { k = 0 ; } if ( k > 0 ) { ans -= k ; } System . out . println ( ans ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int n = in . nextInt ( ) ; int [ ] a = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = in . nextInt ( ) ; } int [ ] dp = new int [ n ] ; int max = - 1 ; for ( int i = n - 2 ; i >= 0 ; i -- ) { if ( a [ i ] >= a [ i + 1 ] ) { dp [ i ] = dp [ i + 1 ] + 1 ; max = Math . max ( max , dp [ i ] ) ; } else { int i = n - 2 ; dp [ i ] = 0 ; } } if ( max == - 1 ) { System . out . println ( 0 ) ; } else { System . out . println ( max ) ; } } } +import java . util . Scanner ; public class Main { public void run ( ) { Scanner sc = new Scanner ( System . in ) ; while ( sc . hasNext ( ) ) { long b = sc . nextInt ( ) ; long a = sc . nextInt ( ) ; long b = sc . nextInt ( ) ; long c = gcd ( a , b ) ; long d = a * b / c ; System . out . println ( c + " " + d ) ; } sc . close ( ) ; } public long gcd ( long a , long b ) { if ( b == 0 ) { return a ; } else { return gcd ( b , a % b ) ; } } public static void main ( String [ ] args ) { new Main ( ) . run ( ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . text . DecimalFormat ; public class Main { public static void main ( String [ ] args ) { String [ ] arrStr ; BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String str ; String [ ] arrStr ; try { str = br . readLine ( ) ; arrStr = str . split ( " " ) ; long a = Integer . parseInt ( arrStr [ 0 ] ) ; long b = Integer . parseInt ( arrStr [ 1 ] ) ; long d = a / b ; long r = a % b ; double f = ( double ) a / b ; DecimalFormat df = new DecimalFormat ( " 0.00000000 " ) ; System . out . println ( d + " " + r + " " + df . format ( f ) ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } } +import java . util . * ; import java . io . * ; public class Main { public static void main ( String [ ] args ) throws IOException { new ABC133 ( ) . c ( ) ; } } class ABC133 { void c ( ) { long L , R ; long M = 2019L ; Scanner in = new Scanner ( System . in ) ; L = in . nextLong ( ) ; R = in . nextLong ( ) ; int ans = 2018 ; long maxI = ( long ) Math . min ( R , L + M ) ; for ( long i = L ; i <= maxI ; ++ i ) { long j = i + 1 ; long maxJ = ( long ) Math . min ( R , i + 1L + M ) ; for ( long j = i + 1 ; j <= maxJ ; ++ j ) { ans = ( int ) Math . min ( ans , i * j % M ) ; } } System . out . println ( ans ) ; in . close ( ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner kb = new Scanner ( System . in ) ; int n = kb . nextInt ( ) , k = kb . nextInt ( ) ; int [ ] h = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { h [ i ] = kb . nextInt ( ) ; } int [ ] dp = new int [ n ] ; boolean [ ] visited = new boolean [ n ] ; dp [ 0 ] = 0 ; visited [ 0 ] = true ; for ( int i = 1 ; i < n ; i ++ ) { for ( int j = 1 ; j <= k && j <= i ; j ++ ) { int ksteps = dp [ i - j ] + Math . abs ( h [ i - j ] - h [ i ] ) ; if ( ! visited [ i ] ) { int ksteps = dp [ i - j ] + Math . abs ( h [ i - j ] - h [ i ] ) ; dp [ i ] = ksteps ; visited [ i ] = true ; } else dp [ i ] = Math . min ( dp [ i ] , ksteps ) ; } } System . out . println ( dp [ n - 1 ] ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { int A = 0 ; Scanner sc = new Scanner ( System . in ) ; int H = sc . nextInt ( ) ; int N = sc . nextInt ( ) ; int A = 0 ; for ( int i = 0 ; i < N ; i ++ ) { A += sc . nextInt ( ) ; } System . out . println ( H > A ? " No " : " Yes " ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] h = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { int i = 0 ; h [ i ] = sc . nextInt ( ) ; } int max = 1 ; for ( int i = 0 ; i < n ; i ++ ) { if ( h [ i ] > max ) { max = h [ i ] ; } else if ( max - h [ i ] > 1 ) { System . out . println ( " No " ) ; return ; } } System . out . println ( " Yes " ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int [ ] [ ] A = new int [ 2 ] [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { A [ 0 ] [ i ] = sc . nextInt ( ) ; } for ( int i = 0 ; i < N ; i ++ ) { A [ 1 ] [ i ] = sc . nextInt ( ) ; } int ans ; int tempofans = 0 ; int num = 0 ; for ( int k = 0 ; k < N ; k ++ ) { int j = 0 ; num = 0 ; for ( int j = 0 ; j < N ; j ++ ) { if ( j <= k ) { num += A [ 0 ] [ j ] ; } if ( j >= k ) { num += A [ 1 ] [ j ] ; } } if ( num > tempofans ) { tempofans = num ; } } ans = tempofans ; System . out . println ( ans ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String line = null ; while ( ( line = br . readLine ( ) ) != null ) { char [ ] input = line . toCharArray ( ) ; for ( int i = input . length ; i > 0 ; i -- ) { int i = input . length ; System . out . print ( input [ i - 1 ] ) ; } System . out . println ( ) ; } } } +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 ) ; B121 solver = new B121 ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class B121 { public void solve ( int testNumber , Scanner in , PrintWriter out ) { int m = Integer . parseInt ( in . next ( ) + in . next ( ) ) ; for ( int i = 1 ; i < 10000 ; i ++ ) { int i = 1 ; if ( m == i * i ) { out . println ( " Yes " ) ; return ; } } out . println ( " No " ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = Integer . parseInt ( sc . next ( ) ) ; int [ ] H = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { H [ i ] = Integer . parseInt ( sc . next ( ) ) ; } int prev = ( H [ 0 ] > 1 ) ? H [ 0 ] - 1 : H [ 0 ] ; for ( int i = 1 ; i < N - 1 ; i ++ ) { int target = H [ i ] ; int next = H [ i + 1 ] ; if ( ( target - next ) > 1 ) { System . out . println ( " No " ) ; return ; } else if ( ( target - next ) == 1 ) { target -= 1 ; if ( prev > target ) { System . out . println ( " No " ) ; return ; } } else { int target = H [ i ] ; if ( prev < target ) { target -= 1 ; } } prev = target ; } System . out . println ( " Yes " ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws IOException { int counter = 0 ; BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String [ ] inputNum = br . readLine ( ) . split ( " " ) ; int a = Integer . parseInt ( inputNum [ 0 ] ) ; int b = Integer . parseInt ( inputNum [ 1 ] ) ; int c = Integer . parseInt ( inputNum [ 2 ] ) ; for ( int i = a ; i <= b ; i ++ ) { if ( c % i == 0 ) { int i = a ; counter ++ ; } } System . out . println ( counter ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int [ ] X = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { int i = N - 2 ; X [ i ] = sc . nextInt ( ) ; } boolean flag = true ; for ( int i = N - 2 ; i >= 0 ; i -- ) { if ( X [ i ] > X [ i + 1 ] ) { if ( X [ i ] - X [ i + 1 ] == 1 ) X [ i ] -- ; else { flag = false ; break ; } } } System . out . println ( ( flag ) ? " Yes " : " 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 [ ] array = { 1 , 1 , 1 } ; array [ a - 1 ] = 0 ; array [ b - 1 ] = 0 ; for ( int i = 0 ; i < array . length ; i ++ ) { if ( array [ i ] == 1 ) { int i = 0 ; System . out . println ( i + 1 ) ; } } } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { System . out . println ( Tile ( ) ) ; } public static int Tile ( ) { int i = 1 ; Scanner scanner = new Scanner ( System . in ) ; String str = scanner . nextLine ( ) ; if ( str . length ( ) == 1 ) return 0 ; String tmp = str . substring ( 0 , 1 ) ; int result = 0 ; for ( int i = 1 ; i < str . length ( ) ; i ++ ) { if ( tmp . equals ( str . substring ( i , i + 1 ) ) ) { result ++ ; tmp = tmp . equals ( " 0 " ) ? " 1 " : " 0 " ; } else { tmp = str . substring ( i , i + 1 ) ; } } return result ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws Exception { String answer = " No " ; Scanner sc = new Scanner ( System . in ) ; Main m = new Main ( sc ) ; m . show ( m . solve ( ) ) ; sc . close ( ) ; } Scanner sc ; int A ; int B ; int C ; Main ( Scanner sc ) { this . sc = sc ; this . A = sc . nextInt ( ) ; this . B = sc . nextInt ( ) ; this . C = sc . nextInt ( ) ; } private String solve ( ) { String answer = " No " ; if ( A == B && B != C || A == C && B != C || B == C && C != A ) { answer = " Yes " ; } return answer ; } public void show ( String answer ) { System . out . println ( answer ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int sum = 0 ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int m = sc . nextInt ( ) ; int sum = 0 ; for ( int i = 0 ; i < m ; i ++ ) { int x = sc . nextInt ( ) ; sum += x ; } System . out . println ( n - sum < 0 ? - 1 : n - sum ) ; sc . close ( ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { double hour , minute , c , co , ans ; Scanner scan = new Scanner ( System . in ) ; double A = scan . nextDouble ( ) ; double B = scan . nextDouble ( ) ; double H = scan . nextDouble ( ) ; double M = scan . nextDouble ( ) ; double hour , minute , c , co , ans ; hour = H * 30 + M * 0.5 ; minute = M * 6 ; c = hour - minute ; if ( c > 180 ) { c = 360 - c ; } else if ( c < 0 ) { c = 360 + c ; } co = Math . cos ( Math . toRadians ( c ) ) ; ans = A * A + B * B - 2 * A * B * co ; System . out . println ( Math . sqrt ( ans ) ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { int Cc ; Scanner scan ; int A ; int B ; int C ; int K ; int Aa ; int Bb ; int Cc ; scan = new Scanner ( System . in ) ; A = scan . nextInt ( ) ; B = scan . nextInt ( ) ; C = scan . nextInt ( ) ; K = scan . nextInt ( ) ; if ( K >= A ) { Aa = A ; K = K - Aa ; if ( K == 0 ) { System . out . println ( 1 * Aa ) ; } else { if ( K >= B ) { Bb = B ; K = K - Bb ; if ( K == 0 ) { System . out . println ( 1 * Aa + 0 * Bb ) ; } else { if ( K >= C ) { Cc = C ; K = K - Cc ; if ( K == 0 ) { System . out . println ( 1 * Aa + 0 * Bb + ( - 1 * Cc ) ) ; } else { System . out . println ( 1 * Aa + 0 * K ) ; } } else { System . out . println ( 1 * Aa + 0 * Bb + ( - 1 * K ) ) ; } } } } } else { System . out . println ( 1 * K ) ; } } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String op ; String [ ] ArrayX = new String [ 3 ] ; int [ ] ArrayA = new int [ 2 ] ; int resultNum = 0 ; String resultLine = " " ; boolean check = true ; while ( check ) { String line = br . readLine ( ) ; ArrayX = line . split ( " " ) ; op = ArrayX [ 1 ] ; ArrayA [ 0 ] = Integer . parseInt ( ArrayX [ 0 ] ) ; ArrayA [ 1 ] = Integer . parseInt ( ArrayX [ 2 ] ) ; if ( op . equals ( " + " ) ) { resultNum = ArrayA [ 0 ] + ArrayA [ 1 ] ; resultLine = resultLine + resultNum + ( " \n " ) ; } else if ( op . equals ( " - " ) ) { resultNum = ArrayA [ 0 ] - ArrayA [ 1 ] ; resultLine = resultLine + resultNum + ( " \n " ) ; } else if ( op . equals ( " * " ) ) { resultNum = ArrayA [ 0 ] * ArrayA [ 1 ] ; resultLine = resultLine + resultNum + ( " \n " ) ; } else if ( op . equals ( " / " ) ) { boolean check = true ; resultNum = ( ArrayA [ 0 ] / ArrayA [ 1 ] ) ; resultLine = resultLine + resultNum + ( " \n " ) ; } else if ( op . equals ( " ? " ) ) { check = false ; } } System . out . print ( resultLine ) ; } } +import java . io . * ; import java . util . * ; class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; while ( true ) { StringTokenizer st = new StringTokenizer ( br . readLine ( ) ) ; int h = Integer . parseInt ( st . nextToken ( ) ) ; int w = Integer . parseInt ( st . nextToken ( ) ) ; if ( w == 0 && h == 0 ) break ; for ( int i = 0 ; i < h ; i ++ ) { int w = Integer . parseInt ( st . nextToken ( ) ) ; for ( int j = 0 ; j < w ; j ++ ) { System . out . print ( " # " ) ; } System . out . println ( ) ; } System . out . println ( ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; double M = sc . nextInt ( ) ; int [ ] A = new int [ N ] ; double sum = 0 ; for ( int i = 0 ; i < N ; i ++ ) { int i = 0 ; A [ i ] = sc . nextInt ( ) ; sum += A [ i ] ; } sc . close ( ) ; int temp ; int n = A . length ; for ( int i = 0 ; i < n - 1 ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { if ( A [ i ] < A [ j ] ) { temp = A [ i ] ; A [ i ] = A [ j ] ; A [ j ] = temp ; } } } double line = 1 / ( 4 * M ) ; for ( int i = 0 ; i < M ; i ++ ) { if ( A [ i ] / sum < line ) { System . out . println ( " No " ) ; return ; } } System . out . println ( " Yes " ) ; } } +import java . io . * ; import java . util . * ; import java . lang . * ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int A = scan . nextInt ( ) ; int B = scan . nextInt ( ) ; int T = scan . nextInt ( ) ; int i = 0 , count = 0 ; ; while ( i + A <= ( T + 0.5 ) ) { int i = 0 , count = 0 ; count ++ ; i += A ; } System . out . println ( B * count ) ; } } +import java . io . * ; public class Main { public static void main ( String [ ] args ) { String [ ] line ; BufferedReader reader = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int i = 0 ; String [ ] line ; line = new String [ 10000 ] ; try { while ( i < 10000 ) { line [ i ] = reader . readLine ( ) ; if ( line [ i ] . equals ( " 0 " ) ) break ; i ++ ; } i = 0 ; while ( i < 10000 ) { if ( line [ i ] . equals ( " 0 " ) ) break ; System . out . println ( " Case " + ( i + 1 ) + " : " + line [ i ] ) ; i ++ ; } } catch ( IOException e ) { System . out . println ( e ) ; } catch ( NumberFormatException e ) { System . out . println ( e ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int temp ; Scanner sc = new Scanner ( System . in ) ; int A = sc . nextInt ( ) ; int B = sc . nextInt ( ) ; System . out . println ( lcm ( A , B ) ) ; } public static long lcm ( int A , int B ) { int temp ; long C = A ; C *= B ; while ( ( temp = A % B ) != 0 ) { A = B ; B = temp ; } return ( C / B ) ; } } +import java . util . Arrays ; import java . util . Collections ; import java . util . Scanner ; import java . util . Vector ; public class Main { public static void main ( String [ ] arg ) { int i = 0 ; Scanner ob = new Scanner ( System . in ) ; int n = ob . nextInt ( ) ; String s = ob . next ( ) ; int k = 0 ; for ( int i = 0 ; i <= s . length ( ) - 3 ; i ++ ) { if ( s . charAt ( i ) == 'A' && s . charAt ( i + 1 ) == 'B' && s . charAt ( i + 2 ) == 'C' ) { k ++ ; } } System . out . println ( k ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { String ans ; Scanner s = new Scanner ( System . in ) ; int N = s . nextInt ( ) ; int ones = N % 10 ; String ans ; if ( ones == 3 ) { ans = " bon " ; } else if ( ones == 0 || ones == 1 || ones == 6 || ones == 8 ) { ans = " pon " ; } else { ans = " hon " ; } System . out . println ( ans ) ; } } +import java . util . ArrayList ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; ArrayList < Integer > list = new ArrayList < Integer > ( ) ; while ( sc . hasNext ( ) ) { list . add ( Integer . parseInt ( sc . next ( ) ) ) ; } int num = list . get ( 0 ) ; int sum = list . get ( 1 ) ; int i = 0 ; if ( sum == 1 ) { int i = 0 ; System . out . print ( 0 ) ; } else if ( num >= sum ) { System . out . print ( 1 ) ; } else { sum = sum - num ; i ++ ; num -- ; while ( true ) { sum = sum - num ; i ++ ; if ( sum < 1 ) { System . out . print ( i ) ; break ; } } } } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStream ; import java . io . InputStreamReader ; import java . util . StringTokenizer ; public class Main { public static void main ( String [ ] args ) { FastScanner sc = new FastScanner ( System . in ) ; long N = sc . nextLong ( ) ; long D = sc . nextLong ( ) ; long ans = 0 ; for ( long i = 0 ; i < N ; i ++ ) { long x = sc . nextLong ( ) ; long y = sc . nextLong ( ) ; if ( Math . sqrt ( ( x * x ) + ( y * y ) ) <= D ) { ans ++ ; } } System . out . println ( ans ) ; } private static class FastScanner { private BufferedReader reader = null ; private StringTokenizer tokenizer = null ; public FastScanner ( InputStream in ) { reader = new BufferedReader ( new InputStreamReader ( in ) ) ; tokenizer = null ; } public String next ( ) { if ( tokenizer == null || ! tokenizer . hasMoreTokens ( ) ) { try { tokenizer = new StringTokenizer ( reader . readLine ( ) ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } } return tokenizer . nextToken ( ) ; } public int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } public long nextLong ( ) { return Long . parseLong ( next ( ) ) ; } } } +import java . util . ArrayList ; import java . util . Arrays ; import java . util . List ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; boolean [ ] isZorome = new boolean [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { int d_1 = sc . nextInt ( ) ; int d_2 = sc . nextInt ( ) ; isZorome [ i ] = ( d_1 == d_2 ) ; } String ans = " No " ; for ( int i = 0 ; i < n - 2 ; i ++ ) { int i = 0 ; boolean sanren = isZorome [ i ] && isZorome [ i + 1 ] && isZorome [ i + 2 ] ; if ( sanren ) { ans = " Yes " ; } } System . out . println ( ans ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) { int timeTaken = 0 ; InputStreamReader in = new InputStreamReader ( System . in ) ; BufferedReader bufferedReader = new BufferedReader ( in ) ; try { String input = bufferedReader . readLine ( ) ; String [ ] inputsArrays = input . split ( " " ) ; int N = Integer . parseInt ( inputsArrays [ 0 ] ) ; int X = Integer . parseInt ( inputsArrays [ 1 ] ) ; int T = Integer . parseInt ( inputsArrays [ 2 ] ) ; int timeTaken = 0 ; while ( N > 0 ) { timeTaken += T ; N -= X ; } System . out . println ( timeTaken ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int end = w . length ( ) ; Scanner sc = new Scanner ( System . in ) ; String sline = sc . next ( ) ; int n = sline . length ( ) ; sc . close ( ) ; StringBuffer sb = new StringBuffer ( sline ) ; String reversed = sb . reverse ( ) . toString ( ) ; boolean ans = true ; String [ ] words = { " maerd " , " remaerd " , " esare " , " resare " } ; for ( int i = 0 ; i < n ; ) { boolean can = false ; for ( String w : words ) { int end = w . length ( ) ; if ( i + end > n ) continue ; if ( reversed . substring ( i , i + end ) . equals ( w ) ) { i += end ; can = true ; } } if ( can == false ) { ans = false ; break ; } } if ( ans ) { System . out . println ( " YES " ) ; } else { System . out . println ( " NO " ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int [ ] result = new int [ 4 ] ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] result = new int [ 4 ] ; for ( int i = 0 ; i < n ; i ++ ) { String s = sc . next ( ) ; switch ( s ) { case " AC " : result [ 0 ] ++ ; break ; case " WA " : result [ 1 ] ++ ; break ; case " TLE " : result [ 2 ] ++ ; break ; case " RE " : result [ 3 ] ++ ; break ; } } System . out . println ( " AC x " + result [ 0 ] ) ; System . out . println ( " WA x " + result [ 1 ] ) ; System . out . println ( " TLE x " + result [ 2 ] ) ; System . out . println ( " RE x " + result [ 3 ] ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner s = new Scanner ( System . in ) ; String S = s . nextLine ( ) ; int count = 0 , ans = 0 ; for ( int i = 0 ; i < S . length ( ) ; i ++ ) { if ( S . charAt ( i ) == 'A' || S . charAt ( i ) == 'C' || S . charAt ( i ) == 'G' || S . charAt ( i ) == 'T' ) { count ++ ; if ( ans < count ) { ans = count ; } } else { count = 0 ; } } System . out . println ( ans ) ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = Integer . parseInt ( sc . next ( ) ) ; String str = sc . next ( ) ; if ( n % 2 == 1 ) { System . out . println ( " No " ) ; return ; } else { String str = sc . next ( ) ; String s_1 = str . substring ( 0 , n / 2 ) ; String s_2 = str . substring ( n / 2 , n ) ; if ( s_1 . equals ( s_2 ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws NumberFormatException , IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String str ; while ( ( str = br . readLine ( ) ) != null ) { String [ ] inputs = str . split ( " " ) ; int a = Integer . parseInt ( inputs [ 0 ] ) ; int b = Integer . parseInt ( inputs [ 1 ] ) ; int c = Integer . parseInt ( inputs [ 2 ] ) ; int k = Integer . parseInt ( br . readLine ( ) ) ; for ( int i = 0 ; i < k ; i ++ ) { if ( a > b && a > c ) { a *= 2 ; } else if ( b > c ) { int c = Integer . parseInt ( inputs [ 2 ] ) ; b *= 2 ; } else { c *= 2 ; } } System . out . println ( a + b + c ) ; } } } +import java . math . * ; import java . util . * ; import java . io . * ; import java . lang . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int x = sc . nextInt ( ) ; if ( isPrime ( x ) ) { System . out . println ( x ) ; } else { while ( ! isPrime ( x ) ) { x ++ ; } System . out . println ( x ) ; } } public static boolean isPrime ( int a ) { int x = sc . nextInt ( ) ; BigInteger bi = BigInteger . valueOf ( a ) ; return bi . isProbablePrime ( 1 ) ; } } +import java . util . ArrayList ; import java . util . Collections ; import java . util . List ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; List < Long > list = new ArrayList < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { List < Long > list = new ArrayList < > ( ) ; list . add ( sc . nextLong ( ) ) ; } long max = Collections . max ( list ) ; long min = Collections . min ( list ) ; System . out . println ( max - min ) ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] cnt = new int [ 4 ] ; for ( int i = 0 ; i < 4 ; i ++ ) { cnt [ i ] = 0 ; } String [ ] s = new String [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { int i = 0 ; s [ i ] = sc . next ( ) ; switch ( s [ i ] ) { case " AC " : cnt [ 0 ] ++ ; break ; case " WA " : cnt [ 1 ] ++ ; break ; case " TLE " : cnt [ 2 ] ++ ; break ; case " RE " : cnt [ 3 ] ++ ; break ; } } sc . close ( ) ; System . out . println ( " AC x " + cnt [ 0 ] ) ; System . out . println ( " WA x " + cnt [ 1 ] ) ; System . out . println ( " TLE x " + cnt [ 2 ] ) ; System . out . println ( " RE x " + cnt [ 3 ] ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; String [ ] S = new String [ N ] ; for ( int i = 0 ; i < N ; ++ i ) { S [ i ] = sc . next ( ) ; } int [ ] C = new int [ 4 ] ; for ( int i = 0 ; i < N ; ++ i ) { if ( S [ i ] . equals ( " AC " ) ) { C [ 0 ] ++ ; } else if ( S [ i ] . equals ( " WA " ) ) { C [ 1 ] ++ ; } else if ( S [ i ] . equals ( " TLE " ) ) { int i = 0 ; C [ 2 ] ++ ; } else if ( S [ i ] . equals ( " RE " ) ) { C [ 3 ] ++ ; } } System . out . println ( " AC x " + C [ 0 ] ) ; System . out . println ( " WA x " + C [ 1 ] ) ; System . out . println ( " TLE x " + C [ 2 ] ) ; System . out . println ( " RE x " + C [ 3 ] ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int [ ] H = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { H [ i ] = sc . nextInt ( ) ; } sc . close ( ) ; boolean out = false ; H [ 0 ] -- ; for ( int i = 0 ; i < N - 1 ; i ++ ) { if ( H [ i + 1 ] < H [ i ] ) { int i = 0 ; out = true ; } if ( H [ i + 1 ] - 1 >= H [ i ] ) { H [ i + 1 ] -- ; } } if ( out ) System . out . println ( " No " ) ; else System . out . println ( " Yes " ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int hei , wid , cnt_wid ; while ( true ) { int hei , wid , cnt_wid ; hei = scan . nextInt ( ) ; wid = scan . nextInt ( ) ; if ( hei == 0 && wid == 0 ) { break ; } for ( cnt_wid = 0 ; cnt_wid < wid ; cnt_wid ++ ) { System . out . print ( " # " ) ; } System . out . println ( ) ; for ( int cnt_hei = 0 ; cnt_hei < hei - 2 ; cnt_hei ++ ) { System . out . print ( " # " ) ; for ( cnt_wid = 0 ; cnt_wid < wid - 2 ; cnt_wid ++ ) { System . out . print ( " . " ) ; } System . out . print ( " # " ) ; System . out . println ( ) ; } for ( cnt_wid = 0 ; cnt_wid < wid ; cnt_wid ++ ) { System . out . print ( " # " ) ; } System . out . println ( " \n " ) ; } scan . close ( ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . Arrays ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String [ ] numberArray = br . readLine ( ) . split ( " " ) ; int N = Integer . parseInt ( numberArray [ 0 ] ) ; int K = Integer . parseInt ( numberArray [ 1 ] ) ; String [ ] inputArray = br . readLine ( ) . split ( " " ) ; int [ ] priceArray = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { priceArray [ i ] = Integer . parseInt ( inputArray [ i ] ) ; } Arrays . sort ( priceArray ) ; int result = 0 ; for ( int j = 0 ; j < K ; j ++ ) { int j = 0 ; result += priceArray [ j ] ; } System . out . println ( result ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] arr = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { arr [ i ] = sc . nextInt ( ) ; } int left = 0 ; int count = 0 ; while ( left < arr . length ) { int right = left ; if ( arr [ left ] == 0 ) left ++ ; else { int right = left ; while ( right < arr . length && arr [ right ] != 0 ) { arr [ right ++ ] -- ; } count ++ ; } } System . out . println ( count ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int [ ] b = new int [ N - 1 ] ; int sum = 0 ; for ( int i = 0 ; i < N - 1 ; i ++ ) { int i = 1 ; b [ i ] = sc . nextInt ( ) ; } sum += b [ 0 ] ; for ( int i = 1 ; i < N - 1 ; i ++ ) { sum += min ( b [ i - 1 ] , b [ i ] ) ; } sum += b [ N - 2 ] ; System . out . println ( sum ) ; } public static int min ( int x , int y ) { if ( x < y ) { return x ; } else { return y ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; int a = 0 ; int z = 0 ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( s . charAt ( i ) == 'A' ) { a = i ; break ; } } for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( s . charAt ( i ) == 'Z' ) { z = i + 1 ; } } System . out . println ( z - a ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String ... args ) { Scanner sc = new Scanner ( System . in ) ; try ( Scanner sc = new Scanner ( System . in ) ) { String a = sc . next ( ) ; String b = sc . next ( ) ; int ab = Integer . parseInt ( a + b ) ; int tmp = ( int ) Math . sqrt ( ab ) ; if ( Math . pow ( tmp , 2 ) == ab ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws IOException { long candidate = a ; BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; while ( true ) { String tmp = br . readLine ( ) ; if ( tmp == null ) { break ; } String [ ] tmpArray = tmp . split ( " " ) ; int a = Integer . parseInt ( tmpArray [ 0 ] ) ; int b = Integer . parseInt ( tmpArray [ 1 ] ) ; System . out . println ( GCD ( a , b ) + " " + LCM ( a , b ) ) ; } } static long GCD ( long a , long b ) { long candidate = a ; while ( b % a != 0 ) { candidate = b % a ; b = a ; a = candidate ; } return candidate ; } static long LCM ( long a , long b ) { long GCD = GCD ( a , b ) ; return GCD * ( a / GCD ) * ( b / GCD ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; long [ ] line = new long [ 4 ] ; for ( int i = 0 ; i < 4 ; i ++ ) { line [ i ] = sc . nextLong ( ) ; } long max = Long . MIN_VALUE ; for ( int i = 0 ; i < 2 ; i ++ ) { int j = 2 ; for ( int j = 2 ; j < 4 ; j ++ ) { max = Math . max ( max , line [ i ] * line [ j ] ) ; } } System . out . println ( max ) ; sc . close ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int j = 0 ; Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; String t = sc . next ( ) ; int out = Integer . MAX_VALUE ; for ( int i = 0 ; i < s . length ( ) - t . length ( ) + 1 ; i ++ ) { int diff = 0 ; for ( int j = 0 ; j < t . length ( ) ; j ++ ) { if ( s . charAt ( j + i ) != t . charAt ( j ) ) diff ++ ; } out = Math . min ( out , diff ) ; } System . out . println ( out ) ; } } +import java . awt . print . Printable ; import java . util . Scanner ; import javax . sound . midi . SysexMessage ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String [ ] strs = new String [ 100 ] ; int count2 = 0 ; while ( true ) { String str = sc . next ( ) ; if ( str . equals ( " - " ) ) { int j = 0 ; for ( int j = 0 ; j < count2 ; j ++ ) { System . out . println ( strs [ j ] ) ; } sc . close ( ) ; break ; } int num = sc . nextInt ( ) ; for ( int i = 0 ; i < num ; i ++ ) { int count = sc . nextInt ( ) ; String str1 = str . substring ( 0 , count ) ; String str2 = str . substring ( count , str . length ( ) ) ; str = str2 + str1 ; } strs [ count2 ] = str ; count2 ++ ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] v = new int [ n ] ; int [ ] c = new int [ n ] ; int [ ] a = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { v [ i ] = sc . nextInt ( ) ; } for ( int j = 0 ; j < n ; j ++ ) { c [ j ] = sc . nextInt ( ) ; a [ j ] = v [ j ] - c [ j ] ; } int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( a [ i ] >= 0 ) { ans += a [ i ] ; } } System . out . println ( 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 m = scan . nextInt ( ) ; int [ ] [ ] arrayA = new int [ n ] [ m ] ; int [ ] arrayB = new int [ m ] ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < m ; j ++ ) { arrayA [ i ] [ j ] = scan . nextInt ( ) ; } } for ( int i = 0 ; i < m ; i ++ ) { arrayB [ i ] = scan . nextInt ( ) ; } int intCount = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int j = 0 ; intCount = 0 ; for ( int j = 0 ; j < m ; j ++ ) { intCount += arrayA [ i ] [ j ] * arrayB [ j ] ; } System . out . println ( intCount ) ; } scan . close ( ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; boolean ans = false ; for ( int i = 0 ; i <= n / 7 ; i ++ ) { int i = 0 ; if ( ( n - i * 7 ) % 4 == 0 ) { ans = true ; break ; } } if ( ans == true ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int n = scan . nextInt ( ) ; int k = scan . nextInt ( ) ; int q = scan . nextInt ( ) ; int [ ] g = new int [ n ] ; for ( int i = 0 ; i < q ; i ++ ) { int j = 0 ; int t = scan . nextInt ( ) ; g [ t - 1 ] += 1 ; } for ( int j = 0 ; j < n ; j ++ ) { if ( k - q + g [ j ] > 0 ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { try ( Scanner sc = new Scanner ( System . in ) ) { int k = sc . nextInt ( ) ; String s = sc . next ( ) ; if ( s . length ( ) <= k ) { String s = sc . next ( ) ; System . out . println ( s ) ; } else { System . out . println ( s . subSequence ( 0 , k ) + " ... " ) ; } } } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner stdIn = new Scanner ( System . in ) ; boolean bl = true ; int a = 0 , b = 0 ; while ( bl ) { a = stdIn . nextInt ( ) ; b = stdIn . nextInt ( ) ; if ( ( 1 <= a ) && ( a <= Math . pow ( 10 , 9 ) ) && ( 1 <= b ) && ( b <= Math . pow ( 10 , 9 ) ) ) { int a = 0 , b = 0 ; break ; } } int d = a / b ; int r = a % b ; double f = ( double ) a / ( double ) b ; System . out . printf ( " %d %d %.6f " , d , r , f ) ; } } +import java . util . Scanner ; public class Main { public static void main ( final String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; String S = scan . next ( ) ; String T = scan . next ( ) ; for ( int i = 0 ; i < S . length ( ) ; i ++ ) { if ( S . charAt ( i ) != T . charAt ( i ) ) { int i = 0 ; System . out . println ( " No " ) ; break ; } else if ( ( i == S . length ( ) - 1 ) && ( S . length ( ) == T . length ( ) - 1 ) ) { System . out . println ( " Yes " ) ; } else if ( S . length ( ) == T . length ( ) ) { System . out . println ( " No " ) ; } } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int L = sc . nextInt ( ) ; String [ ] s = new String [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { s [ i ] = sc . next ( ) ; } for ( int i = 0 ; i < N ; i ++ ) { for ( int j = N - 1 ; j > i ; j -- ) { if ( s [ j ] . compareTo ( s [ j - 1 ] ) < 0 ) { int j = N - 1 ; String exc = s [ j ] ; s [ j ] = s [ j - 1 ] ; s [ j - 1 ] = exc ; } } System . out . print ( s [ i ] ) ; } System . out . println ( " " ) ; } } +import java . io . OutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . PrintWriter ; import java . util . HashSet ; import java . util . Scanner ; import java . util . Set ; public class Main { public static void main ( String [ ] args ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; Scanner in = new Scanner ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; A solver = new A ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class A { public void solve ( int testNumber , Scanner in , PrintWriter out ) { PrintWriter out = new PrintWriter ( outputStream ) ; int a = Integer . parseInt ( in . next ( ) ) ; int b = Integer . parseInt ( in . next ( ) ) ; int c = Integer . parseInt ( in . next ( ) ) ; Set < Integer > s = new HashSet < > ( ) ; s . add ( a ) ; s . add ( b ) ; s . add ( c ) ; if ( s . size ( ) == 2 ) out . println ( " Yes " ) ; else out . println ( " No " ) ; } } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . Stack ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String [ ] inputArray = br . readLine ( ) . split ( " " ) ; Stack < Integer > stack = new Stack < Integer > ( ) ; int a = 0 ; int b = 0 ; for ( int i = 0 ; i < inputArray . length ; i ++ ) { if ( inputArray [ i ] . equals ( " + " ) ) { a = stack . pop ( ) ; b = stack . pop ( ) ; stack . add ( b + a ) ; continue ; } if ( inputArray [ i ] . equals ( " - " ) ) { a = stack . pop ( ) ; b = stack . pop ( ) ; stack . add ( b - a ) ; continue ; } if ( inputArray [ i ] . equals ( " * " ) ) { int i = 0 ; a = stack . pop ( ) ; b = stack . pop ( ) ; stack . add ( b * a ) ; continue ; } stack . push ( Integer . parseInt ( inputArray [ i ] ) ) ; } System . out . println ( stack . pop ( ) ) ; } } +import java . util . Scanner ; public class Main { private static final int MOD = 1_000_000_007 ; private static int [ ] [ ] X ; private static int D ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; D = sc . nextInt ( ) ; X = new int [ N ] [ D ] ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < D ; j ++ ) { X [ i ] [ j ] = sc . nextInt ( ) ; } } int cnt = 0 ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) { int k = 0 ; if ( i == j ) break ; if ( distance ( i , j ) ) cnt ++ ; } } System . out . println ( cnt ) ; } private static boolean distance ( int i , int j ) { double sum = 0 ; for ( int k = 0 ; k < D ; k ++ ) { long x = X [ i ] [ k ] - X [ j ] [ k ] ; sum += x * x ; } double s = Math . sqrt ( sum ) ; return s == Math . floor ( s ) ; } } +import java . text . DecimalFormat ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int jisin_nagasa = sc . nextInt ( ) ; int hunsin_nagasa = sc . nextInt ( ) ; int jikan = sc . nextInt ( ) ; int hun = sc . nextInt ( ) ; double jisin_kakudo = ( jikan * 60 + hun ) * 0.5 ; double hunsin_kakudo = hun * 6 ; double kakudo_sa = 0 ; if ( jisin_kakudo > hunsin_kakudo ) { kakudo_sa = jisin_kakudo - hunsin_kakudo ; } else { double kakudo_sa = 0 ; kakudo_sa = hunsin_kakudo - jisin_kakudo ; } double b = jisin_nagasa ; double c = hunsin_nagasa ; double e = kakudo_sa ; double r = Math . sqrt ( Math . pow ( b , 2 ) + Math . pow ( c , 2 ) - 2 * b * c * Math . cos ( Math . toRadians ( e ) ) ) ; System . out . println ( r ) ; } } +import java . util . Scanner ; import java . lang . Math ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; while ( scan . hasNext ( ) ) { String input = scan . nextLine ( ) ; String [ ] inputs = input . split ( " " ) ; int height = Integer . parseInt ( inputs [ 0 ] ) ; int width = Integer . parseInt ( inputs [ 1 ] ) ; if ( height == 0 && width == 0 ) { break ; } for ( int i = 0 ; i < height ; i ++ ) { int width = Integer . parseInt ( inputs [ 1 ] ) ; for ( int j = 0 ; j < width ; j ++ ) { System . out . print ( " # " ) ; } System . out . println ( ) ; } System . out . println ( ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner kb = new Scanner ( System . in ) ; int size = kb . nextInt ( ) ; int [ ] [ ] a = new int [ size ] [ 3 ] ; int x , y , z ; for ( int i = 0 ; i < size ; i ++ ) { a [ i ] [ 0 ] = kb . nextInt ( ) ; a [ i ] [ 1 ] = kb . nextInt ( ) ; a [ i ] [ 2 ] = kb . nextInt ( ) ; } for ( int i = 0 ; i < size ; i ++ ) { x = a [ i ] [ 0 ] ; y = a [ i ] [ 1 ] ; z = a [ i ] [ 2 ] ; if ( x * x + y * y == z * z || y * y + z * z == x * x || z * z + x * x == y * y ) { 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 ) ; String s = sc . next ( ) ; String t = sc . next ( ) ; char [ ] c = s . toCharArray ( ) ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { int j = 0 ; for ( int j = 0 ; j < c . length ; j ++ ) { c [ j ] = s . charAt ( ( j + i ) % c . length ) ; } if ( String . valueOf ( c ) . equals ( t ) ) { System . out . println ( " Yes " ) ; sc . close ( ) ; return ; } } System . out . println ( " No " ) ; sc . close ( ) ; } } +import java . io . OutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . PrintWriter ; import java . util . StringTokenizer ; import java . io . IOException ; import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . io . InputStream ; public class Main { public static void main ( String [ ] args ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; MyScanner in = new MyScanner ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; A solver = new A ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class A { public void solve ( int testNumber , MyScanner in , PrintWriter out ) { int H = in . nextInt ( ) ; int A = in . nextInt ( ) ; out . println ( ( int ) Math . ceil ( H / ( double ) A ) ) ; } } static class MyScanner { private BufferedReader in ; private StringTokenizer st ; public MyScanner ( InputStream stream ) { in = new BufferedReader ( new InputStreamReader ( stream ) ) ; } public String next ( ) { while ( st == null || ! st . hasMoreTokens ( ) ) { try { String rl = in . readLine ( ) ; if ( rl == null ) { return null ; } st = new StringTokenizer ( rl ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } } return st . nextToken ( ) ; } public int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { @ SuppressWarnings ( " resource " ) Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] p = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { int i = 0 ; p [ i ] = sc . nextInt ( ) ; } int min = 10000000 ; int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( p [ i ] < min ) { count ++ ; min = p [ i ] ; } } System . out . println ( count ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner scn = new Scanner ( System . in ) ; int N = scn . nextInt ( ) ; int [ ] Nmonster = new int [ N + 1 ] ; for ( int i = 0 ; i < N + 1 ; i ++ ) { Nmonster [ i ] = scn . nextInt ( ) ; } long Nbeaten = 0 ; for ( int i = 0 ; i < N ; i ++ ) { int Nbeatble = scn . nextInt ( ) ; if ( Nbeatble < Nmonster [ i ] ) { Nbeaten += Nbeatble ; } else { Nbeaten += Nmonster [ i ] ; Nbeatble -= Nmonster [ i ] ; int diff = Nbeatble - Nmonster [ i + 1 ] ; if ( diff >= 0 ) { int Nbeatble = scn . nextInt ( ) ; Nbeaten += Nmonster [ i + 1 ] ; Nmonster [ i + 1 ] = 0 ; } else { Nbeaten += Nbeatble ; Nmonster [ i + 1 ] -= Nbeatble ; } } } System . out . println ( Nbeaten ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; int k = sc . nextInt ( ) ; if ( k == 10 ) { long n = 0 ; System . out . println ( s . length ( ) ) ; } else { long n = 0 ; while ( Math . pow ( k , n ) < Long . valueOf ( s ) + 1 ) { n ++ ; } System . out . println ( n ) ; } } } +import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . io . PrintStream ; import java . util . HashMap ; import java . util . Map ; import java . util . Scanner ; public class Main { public static final Scanner in = new Scanner ( new BufferedReader ( new InputStreamReader ( System . in ) ) ) ; public static final PrintStream out = System . out ; public static void main ( String [ ] args ) { int i ; int N = in . nextInt ( ) ; int [ ] H = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { H [ i ] = in . nextInt ( ) ; } int step = 0 ; for ( int i : H ) { if ( i < step ) { out . println ( " No " ) ; return ; } else if ( i <= step + 1 ) { continue ; } else { step = i - 1 ; } } out . println ( " Yes " ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int [ ] numbers = new int [ 3 ] ; for ( int i = 0 ; i < numbers . length ; i ++ ) { int j = point ; String input = scan . next ( ) ; numbers [ i ] = Integer . parseInt ( input ) ; } for ( int i = 0 ; i < 3 ; i ++ ) { int point = i ; for ( int j = point ; j < 3 ; j ++ ) { if ( numbers [ point ] > numbers [ j ] ) { point = j ; } } int tmp = numbers [ point ] ; numbers [ point ] = numbers [ i ] ; numbers [ i ] = tmp ; } System . out . println ( numbers [ 0 ] + " " + numbers [ 1 ] + " " + numbers [ 2 ] ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; StringBuilder sb = new StringBuilder ( ) ; int inputValue = Integer . parseInt ( br . readLine ( ) ) ; String [ ] inputData = br . readLine ( ) . split ( " " ) ; Integer [ ] number = new Integer [ inputValue ] ; for ( int i = 0 ; i < inputData . length ; i ++ ) { number [ i ] = Integer . parseInt ( inputData [ i ] ) ; } for ( int i = number . length - 1 ; i >= 1 ; i -- ) { int i = number . length - 1 ; sb . append ( number [ i ] + " " ) ; } sb . append ( number [ 0 ] ) ; System . out . println ( sb ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String S = sc . next ( ) ; String H = sc . next ( ) ; int A = sc . nextInt ( ) ; int B = sc . nextInt ( ) ; String U = sc . next ( ) ; if ( U . equals ( S ) ) { A -- ; } else if ( U . equals ( H ) ) { int B = sc . nextInt ( ) ; B -- ; } System . out . println ( A ) ; System . out . println ( B ) ; } } +import java . util . * ; import java . io . * ; class Main { static PrintStream out = System . out ; static Scanner in = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { int n = in . nextInt ( ) ; int i = 1 ; do { int x = i ; if ( x % 3 == 0 ) { int x = i ; out . print ( " " + i ) ; } else { do { if ( x % 10 == 3 ) { out . print ( " " + i ) ; break ; } x /= 10 ; } while ( x != 0 ) ; } } while ( ++ i <= n ) ; out . println ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = Integer . parseInt ( sc . nextLine ( ) ) ; String [ ] an = sc . nextLine ( ) . split ( " " ) ; long molec = 0L ; for ( String elm : an ) { int i = Integer . parseInt ( elm ) ; if ( molec == 0L ) { long tmp ; molec = gcd ( i , i ) ; } else { molec = gcd ( i , molec ) ; } } long denom = 0L ; for ( String elm : an ) { int i = Integer . parseInt ( elm ) ; long times = molec / i ; denom += times ; } System . err . println ( molec + " / " + denom ) ; double ans = ( double ) molec / ( double ) denom ; System . out . println ( ans ) ; } private static long gcd ( long a , long b ) { long tmp ; long c = a ; c *= b ; while ( ( tmp = a % b ) != 0 ) { a = b ; b = tmp ; } return c / b ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String [ ] weather = new String [ ] { " Sunny " , " Cloudy " , " Rainy " } ; String tw = sc . next ( ) ; for ( int i = 0 ; i < weather . length ; ++ i ) { if ( tw . equals ( weather [ i ] ) ) { int i = 0 ; System . out . println ( weather [ ( i + 1 ) % 3 ] ) ; break ; } } } } +import java . util . Scanner ; public class Main { static final long MOD = 1_000_000_007 ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int m = sc . nextInt ( ) ; boolean [ ] broken = new boolean [ n + 1 ] ; for ( int i = 0 ; i < m ; i ++ ) { int a = sc . nextInt ( ) ; broken [ a ] = true ; } long [ ] dp = new long [ n + 1 ] ; dp [ 0 ] = 1 ; dp [ 1 ] = broken [ 1 ] ? 0 : 1 ; for ( int i = 2 ; i < dp . length ; i ++ ) { int i = 2 ; dp [ i ] = broken [ i ] ? 0 : ( dp [ i - 2 ] + dp [ i - 1 ] ) % MOD ; } System . out . println ( dp [ n ] ) ; sc . close ( ) ; } } +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 ) { PrintWriter out = new PrintWriter ( outputStream ) ; InputStream inputStream = System . in ; OutputStream outputStream = System . out ; Scanner sc = new Scanner ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; String a = sc . next ( ) ; String b = sc . next ( ) ; int ab = Integer . parseInt ( a + b ) ; double number = Math . sqrt ( ab ) ; if ( number == Math . floor ( number ) ) { out . println ( " Yes " ) ; } else { out . println ( " No " ) ; } out . close ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int N , k = 0 ; int [ ] A = new int [ 100 ] ; Scanner stdIn = new Scanner ( System . in ) ; N = stdIn . nextInt ( ) ; for ( int i = 0 ; i < N ; i ++ ) { A [ i ] = stdIn . nextInt ( ) ; } k = bubbleSort ( N , A ) ; trace ( N , A , k ) ; } public static void trace ( int N , int [ ] A , int k ) { for ( int i = 0 ; i < N ; i ++ ) { int j = N - 1 ; if ( i > 0 ) System . out . print ( " " ) ; System . out . print ( A [ i ] ) ; } System . out . println ( ) ; System . out . println ( k ) ; } public static int bubbleSort ( int N , int [ ] A ) { int k = 0 ; for ( int i = 0 ; i < N - 1 ; i ++ ) { for ( int j = N - 1 ; j > i ; j -- ) { if ( A [ j ] < A [ j - 1 ] ) { int tmp = A [ j - 1 ] ; A [ j - 1 ] = A [ j ] ; A [ j ] = tmp ; k ++ ; } } } return k ; } } +import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int k = sc . nextInt ( ) ; int [ ] monsters = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { monsters [ i ] = sc . nextInt ( ) ; } Arrays . sort ( monsters ) ; long hp = 0 ; if ( k >= n ) { int j = 0 ; System . out . println ( hp ) ; } else { for ( int j = 0 ; j < n - k ; j ++ ) { hp += monsters [ j ] ; } System . out . println ( hp ) ; } } } +import java . util . * ; public class Main { static final String ascii = " ABCDEFGHIJKLMNOPQRSTUVWXYZ " ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int index = sc . nextInt ( ) ; String str = sc . next ( ) ; if ( index == 0 ) { System . out . println ( str ) ; } else { String replaced = " " ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { char c = str . charAt ( i ) ; int si = ascii . indexOf ( String . valueOf ( c ) ) ; int ri = si + index ; if ( ri >= ascii . length ( ) ) { int ri = si + index ; ri = ri - ascii . length ( ) ; } replaced = replaced + String . valueOf ( ascii . charAt ( ri ) ) ; } System . out . println ( replaced ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int num1 = sc . nextInt ( ) ; int num2 = sc . nextInt ( ) ; int sum = 0 ; for ( int i = 0 ; i < 2 ; i ++ ) { if ( num1 < num2 ) { int sum = 0 ; sum += num2 ; num2 -- ; } else { sum += num1 ; num1 -- ; } } System . out . println ( sum ) ; } } +import java . util . Scanner ; public class Main { public static int getGcd ( int a , int b ) { int b = s . nextInt ( ) ; if ( a == b ) return b ; int bigger = Math . max ( a , b ) ; int smaller = Math . min ( a , b ) ; int modded = bigger % smaller ; if ( modded == 0 ) return smaller ; return getGcd ( smaller , bigger % smaller ) ; } public static void main ( String [ ] args ) { Scanner s = new Scanner ( System . in ) ; int a = s . nextInt ( ) ; int b = s . nextInt ( ) ; int result = getGcd ( a , b ) ; System . out . println ( result ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Main main = new Main ( ) ; main . solveB ( ) ; } private void solveA ( ) { Scanner sc = new Scanner ( System . in ) ; int A = sc . nextInt ( ) ; int B = sc . nextInt ( ) ; String s ; if ( A >= 9 || B >= 9 ) { s = " :( " ; } else { int p = 1 ; s = " Yay! " ; } System . out . println ( s ) ; } private void solveB ( ) { Scanner sc = new Scanner ( System . in ) ; int D = sc . nextInt ( ) ; int N = sc . nextInt ( ) ; int p = 1 ; for ( int i = 0 ; i < D ; i ++ ) { p *= 100 ; } if ( N == 100 ) N = 101 ; System . out . println ( p * N ) ; } } +import java . io . BufferedReader ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws Exception { int i = 0 ; BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int numberCount = Integer . parseInt ( br . readLine ( ) ) ; String [ ] sNumbers = br . readLine ( ) . split ( " " ) ; int [ ] numbers = new int [ numberCount ] ; for ( int i = 0 ; i < numberCount ; i ++ ) { numbers [ i ] = Integer . parseInt ( sNumbers [ i ] ) ; } insertionSort ( numbers ) ; } private static void insertionSort ( int [ ] numbers ) { displayNumbers ( numbers ) ; for ( int i = 1 ; i < numbers . length ; i ++ ) { int currentNumber = numbers [ i ] ; int insertIndex = i ; for ( int y = i - 1 ; y >= 0 ; y -- ) { if ( currentNumber < numbers [ y ] ) { numbers [ y + 1 ] = numbers [ y ] ; insertIndex = y ; } else { break ; } } numbers [ insertIndex ] = currentNumber ; displayNumbers ( numbers ) ; } } private static void displayNumbers ( int [ ] numbers ) { StringBuffer sb = new StringBuffer ( ) ; for ( int i = 0 ; i < numbers . length ; i ++ ) { sb . append ( numbers [ i ] ) ; sb . append ( " " ) ; } System . out . println ( sb . toString ( ) . trim ( ) ) ; } } +import java . util . * ; public class Main { static Scanner sc = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { int N = sc . nextInt ( ) ; int [ ] a = new int [ 100 ] ; for ( int i = 0 ; i < N ; i ++ ) a [ i ] = sc . nextInt ( ) ; Arrays . sort ( a ) ; int Alice = 0 ; int Bob = 0 ; for ( int i = 99 ; i > 99 - N ; i -- ) if ( i % 2 == 1 ) Alice += a [ i ] ; else Bob += a [ i ] ; System . out . println ( Alice - Bob ) ; } } +import java . util . ArrayList ; import java . util . List ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int t = sc . nextInt ( ) ; List < Integer > cList = new ArrayList < > ( ) ; List < Integer > tList = new ArrayList < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { int cost = cList . get ( i ) ; cList . add ( sc . nextInt ( ) ) ; tList . add ( sc . nextInt ( ) ) ; } Integer minCost = null ; for ( int i = 0 ; i < n ; i ++ ) { if ( tList . get ( i ) > t ) { continue ; } int cost = cList . get ( i ) ; if ( minCost == null || cost < minCost ) { minCost = cost ; } } if ( minCost == null ) { System . out . println ( " TLE " ) ; return ; } System . out . println ( minCost ) ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { String d2 = str . substring ( i , i ) ; Scanner sc = new Scanner ( System . in ) ; String [ ] devider = { " maerd " , " remaerd " , " esare " , " resare " } ; String str = new StringBuffer ( sc . nextLine ( ) ) . reverse ( ) . toString ( ) ; boolean flag1 = true ; for ( int i = 0 ; i < str . length ( ) ; ) { boolean flag2 = false ; for ( int j = 0 ; j < 4 ; j ++ ) { String d = devider [ j ] ; String d2 = str . substring ( i , i ) ; if ( ( i + d . length ( ) ) <= str . length ( ) ) { d2 = str . substring ( i , i + d . length ( ) ) ; } if ( d2 . equals ( d ) ) { flag2 = true ; i += d . length ( ) ; } } if ( ! flag2 ) { flag1 = false ; break ; } } System . out . println ( flag1 ? " YES " : " NO " ) ; } } +import java . io . File ; import java . io . FileNotFoundException ; import java . util . HashSet ; import java . util . Scanner ; import java . util . Set ; public class Main { public static void main ( String [ ] args ) throws FileNotFoundException { Scanner s = new Scanner ( System . in ) ; int N = s . nextInt ( ) ; int K = s . nextInt ( ) ; Set set = new HashSet ( ) ; for ( int i = 1 ; i <= N ; i ++ ) { set . add ( i ) ; } for ( int i = 0 ; i < K ; i ++ ) { int num = s . nextInt ( ) ; if ( set . size ( ) <= 0 ) { break ; } int di = s . nextInt ( ) ; for ( int j = 0 ; j < di ; j ++ ) { int num = s . nextInt ( ) ; if ( set . contains ( num ) ) { set . remove ( num ) ; } } } System . out . println ( set . size ( ) ) ; } } +import java . awt . * ; import java . awt . geom . * ; import java . io . * ; import java . util . * ; class Main { static char [ ] xx = new char [ ] { 'S' , 'H' , 'C' , 'D' } ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; boolean [ ] [ ] l = new boolean [ 4 ] [ 13 ] ; for ( int i = 0 ; i < n ; i ++ ) { char k = sc . next ( ) . charAt ( 0 ) ; int r = sc . nextInt ( ) ; if ( k == 'S' ) { l [ 0 ] [ r - 1 ] = true ; } if ( k == 'H' ) { l [ 1 ] [ r - 1 ] = true ; } if ( k == 'C' ) { l [ 2 ] [ r - 1 ] = true ; } if ( k == 'D' ) { l [ 3 ] [ r - 1 ] = true ; } } for ( int i = 0 ; i < 4 ; i ++ ) { for ( int j = 0 ; j < 13 ; j ++ ) { if ( ! l [ i ] [ j ] ) { int j = 0 ; System . out . println ( xx [ i ] + " " + ( j + 1 ) ) ; } } } } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws IOException { int j = 0 ; BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String [ ] str = br . readLine ( ) . split ( " " ) ; int n = Integer . parseInt ( str [ 0 ] ) ; int m = Integer . parseInt ( str [ 1 ] ) ; int [ ] [ ] matrix = new int [ n ] [ m ] ; int [ ] vector = new int [ m ] ; for ( int i = 0 ; i < n ; i ++ ) { str = br . readLine ( ) . split ( " " ) ; for ( int j = 0 ; j < m ; j ++ ) { matrix [ i ] [ j ] = Integer . parseInt ( str [ j ] ) ; } } for ( int k = 0 ; k < m ; k ++ ) { String str1 = br . readLine ( ) ; vector [ k ] = Integer . parseInt ( str1 ) ; } for ( int i = 0 ; i < n ; i ++ ) { int kakezan = 0 ; for ( int j = 0 ; j < m ; j ++ ) { kakezan += matrix [ i ] [ j ] * vector [ j ] ; } System . out . println ( kakezan ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; LinkedList < Integer > ll = new LinkedList < > ( ) ; int n = 999 ; int x = 999 ; int cnt = 0 ; while ( n != 0 || x != 0 ) { int i = 0 ; n = sc . nextInt ( ) ; x = sc . nextInt ( ) ; int ans = 0 ; if ( n == 0 && x == 0 ) { break ; } else { cnt ++ ; for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = 1 ; j < i ; j ++ ) { for ( int k = 1 ; k < j ; k ++ ) { if ( i + k + j == x ) { ans ++ ; } } } } ll . add ( ans ) ; } } for ( int i = 0 ; i < cnt ; i ++ ) { System . out . println ( ll . get ( i ) ) ; } } } +import java . util . * ; public class Main { Scanner sc ; int N , D ; public Main ( ) { sc = new Scanner ( System . in ) ; } void out ( Object o ) { System . out . println ( o ) ; System . out . flush ( ) ; } public void exec ( ) throws Exception { N = sc . nextInt ( ) ; D = sc . nextInt ( ) ; int n = ( N + 2 * D ) / ( 2 * D + 1 ) ; out ( n ) ; } public static void main ( String [ ] args ) throws Exception { Main m = new Main ( ) ; m . exec ( ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int X = sc . nextInt ( ) ; int N = sc . nextInt ( ) ; Integer [ ] p = new Integer [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { p [ i ] = sc . nextInt ( ) ; } int min = Integer . MAX_VALUE ; for ( int j = - 1000 ; j < 1000 ; j ++ ) { int a = X - min ; if ( Arrays . asList ( p ) . contains ( j ) ) { continue ; } min = Math . min ( min , Math . abs ( X - j ) ) ; } int a = X - min ; if ( Arrays . asList ( p ) . contains ( a ) ) { System . out . println ( X + min ) ; } else { System . out . println ( a ) ; } } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { long tmp ; Scanner scn = new Scanner ( System . in ) ; long num1 = scn . nextInt ( ) ; long num2 = scn . nextInt ( ) ; System . out . println ( CommonMultipleNum . cmn ( num1 , num2 ) ) ; } } class CommonMultipleNum { static long cmn ( long num1 , long num2 ) { long tmp ; long num3 = num1 ; num3 *= num2 ; while ( ( tmp = num1 % num2 ) != 0 ) { num1 = num2 ; num2 = tmp ; } return ( long ) ( num3 / num2 ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int n = scanner . nextInt ( ) ; String s = scanner . next ( ) ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { int i = 0 ; System . out . print ( ( char ) ( ( s . charAt ( i ) - 'A' + n ) % 26 + 'A' ) ) ; } } } +import java . util . Scanner ; import java . util . Arrays ; import java . util . Deque ; import java . util . ArrayDeque ; class Main { public static void main ( String [ ] args ) throws Exception { int i = 0 ; Scanner scanner = new Scanner ( System . in ) ; Deque < Integer > stack = new ArrayDeque < > ( ) ; String [ ] line = scanner . nextLine ( ) . split ( " " ) ; int a , b ; for ( int i = 0 ; i < line . length ; i ++ ) { switch ( line [ i ] ) { case " + " : a = stack . pollLast ( ) ; b = stack . pollLast ( ) ; stack . offer ( b + a ) ; break ; case " - " : a = stack . pollLast ( ) ; b = stack . pollLast ( ) ; stack . offer ( b - a ) ; break ; case " * " : a = stack . pollLast ( ) ; b = stack . pollLast ( ) ; stack . offer ( b * a ) ; break ; default : stack . offer ( Integer . parseInt ( line [ i ] ) ) ; break ; } } System . out . println ( stack . poll ( ) ) ; } } +import java . util . * ; import java . io . * ; public class Main { public static void main ( String [ ] args ) throws Exception { FastReader s = new FastReader ( ) ; int n = s . nextInt ( ) ; long sum = 0 ; int max = Integer . MIN_VALUE ; int [ ] arr = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { arr [ i ] = s . nextInt ( ) ; if ( arr [ i ] < max ) { sum += max - arr [ i ] ; } max = Math . max ( max , arr [ i ] ) ; } System . out . println ( sum ) ; } static class FastReader { BufferedReader br ; StringTokenizer st ; public FastReader ( ) { br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; } String next ( ) { while ( st == null || ! st . hasMoreElements ( ) ) { String str = " " ; 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 . OutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . PrintWriter ; import java . util . Arrays ; 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 ) ; C solver = new C ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class C { int N ; int M ; boolean [ ] a ; int mod = ( int ) ( 1e9 + 7 ) ; public void solve ( int testNumber , Scanner in , PrintWriter out ) { N = in . nextInt ( ) ; M = in . nextInt ( ) ; a = new boolean [ N + 1 ] ; Arrays . fill ( a , true ) ; for ( int i = 0 ; i < M ; i ++ ) { a [ in . nextInt ( ) ] = false ; } int [ ] dp = new int [ N + 1 ] ; dp [ 0 ] = 1 ; for ( int i = 1 ; i <= N ; i ++ ) { int i = 1 ; if ( a [ i ] ) { dp [ i ] = dp [ i - 1 ] ; if ( i - 2 >= 0 ) { dp [ i ] += dp [ i - 2 ] ; } dp [ i ] %= mod ; } } out . println ( dp [ N ] ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String n = sc . next ( ) ; int N = Integer . parseInt ( n ) ; int [ ] sn = new int [ n . length ( ) ] ; int S = 0 ; sc . close ( ) ; for ( int i = 0 ; i < n . length ( ) ; i ++ ) { sn [ i ] = Integer . parseInt ( n . substring ( i , i + 1 ) ) ; S += sn [ i ] ; } if ( N % S == 0 ) { System . out . print ( " Yes " ) ; } else { int i = 0 ; System . out . print ( " No " ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; int [ ] menu = new int [ 5 ] ; int ans = 0 ; int max = 0 ; int idx = 0 ; for ( int i = 0 ; i < 5 ; i ++ ) { menu [ i ] = sc . nextInt ( ) ; if ( max < ( 10 - ( menu [ i ] % 10 ) ) && ( 10 - ( menu [ i ] % 10 ) ) != 10 ) { int i = 0 ; max = 10 - ( menu [ i ] % 10 ) ; idx = i ; } } sc . close ( ) ; for ( int i = 0 ; i < 5 ; i ++ ) { if ( idx != i ) { if ( ( 10 - ( menu [ i ] % 10 ) ) == 10 ) { ans += menu [ i ] ; } else { ans += menu [ i ] + ( 10 - ( menu [ i ] % 10 ) ) ; } } } ans += menu [ idx ] ; System . out . println ( ans ) ; } } +import java . util . * ; import static java . lang . Math . * ; import java . math . BigInteger ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; String result = " No " ; int n = 0 ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { n += s . charAt ( i ) - '0' ; } if ( Integer . valueOf ( s ) % n == 0 ) result = " Yes " ; System . out . println ( result ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; while ( true ) { String s1 = sc . next ( ) ; int a = Integer . parseInt ( s1 ) ; String sop = sc . next ( ) ; char op = sop . charAt ( 0 ) ; String s2 = sc . next ( ) ; int b = Integer . parseInt ( s2 ) ; if ( op == '?' ) { break ; } if ( 0 <= a && a <= 20000 ) { if ( 0 <= b && b <= 20000 ) { int b = Integer . parseInt ( s2 ) ; if ( op == '+' ) { System . out . println ( a + b ) ; } else if ( op == '-' ) { System . out . println ( a - b ) ; } else if ( op == '*' ) { System . out . println ( a * b ) ; } else if ( op == '/' ) { System . out . println ( a / b ) ; } } } } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int m = sc . nextInt ( ) ; sc . close ( ) ; int cnt = 0 ; if ( n >= 2 ) { int cnt = 0 ; cnt += n * ( n - 1 ) / 2 ; } if ( m >= 2 ) { cnt += m * ( m - 1 ) / 2 ; } System . out . println ( cnt ) ; } } +import java . io . * ; public class Main { public static void main ( String [ ] args ) throws IOException { String s ; BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String s ; try { while ( ( s = br . readLine ( ) ) != null ) { String [ ] str = s . split ( " " ) ; int n = Integer . parseInt ( str [ 0 ] ) + Integer . parseInt ( str [ 1 ] ) ; System . out . println ( Integer . toString ( n ) . length ( ) ) ; } br . close ( ) ; } catch ( Exception e ) { } } } +import java . io . * ; import java . util . * ; public class Main { private static int [ ] heights ; private static int n , ans = Integer . MAX_VALUE , k ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; n = sc . nextInt ( ) ; k = sc . nextInt ( ) ; heights = new int [ n + 3 ] ; dp = new int [ n + 3 ] ; for ( int i = 1 ; i <= n ; i ++ ) { int i = ind + 1 ; heights [ i ] = sc . nextInt ( ) ; } Arrays . fill ( dp , - 1 ) ; System . out . println ( findJumpCost ( 1 ) ) ; sc . close ( ) ; } private static int [ ] dp ; private static int findJumpCost ( int ind ) { if ( ind == n ) return 0 ; if ( dp [ ind ] != - 1 ) { return dp [ ind ] ; } int min = Integer . MAX_VALUE ; for ( int i = ind + 1 ; i <= Math . min ( n , ind + k ) ; i ++ ) { min = Math . min ( min , Math . abs ( heights [ i ] - heights [ ind ] ) + findJumpCost ( i ) ) ; } return dp [ ind ] = min ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int b = 1 ; int p = 2 ; double max = 0 ; double result ; Scanner scanner = new Scanner ( System . in ) ; int x = scanner . nextInt ( ) ; while ( b < 1000 ) { while ( p < 1000 ) { int x = scanner . nextInt ( ) ; result = Math . pow ( b , p ) ; if ( result > x ) break ; if ( result >= max ) max = result ; p ++ ; } p = 2 ; b ++ ; } System . out . println ( ( int ) max ) ; } } +import java . io . InputStream ; import java . io . PrintStream ; 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 ) ; final String S = sc . next ( ) ; sc . close ( ) ; String ans = null ; switch ( S ) { case " Sunny " : ans = " Cloudy " ; break ; case " Cloudy " : ans = " Rainy " ; break ; case " Rainy " : ans = " Sunny " ; break ; } out . println ( ans ) ; } public static void main ( String [ ] args ) { new Main ( ) . _main ( args ) ; } } +import java . io . * ; import java . util . ArrayList ; import java . util . List ; import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int K = sc . nextInt ( ) ; sc . nextLine ( ) ; List < Integer > list = new ArrayList < Integer > ( ) ; for ( int i = 0 ; i < n ; i ++ ) list . add ( sc . nextInt ( ) ) ; List < Integer > dyn = new ArrayList < Integer > ( ) ; dyn . add ( 0 ) ; dyn . add ( ( int ) ( Math . abs ( list . get ( 1 ) - list . get ( 0 ) ) ) ) ; for ( int i = 2 ; i < n ; i ++ ) { int min = Integer . MAX_VALUE ; for ( int j = 1 ; j <= K ; j ++ ) { if ( i - j >= 0 ) { int j = 1 ; min = ( int ) Math . min ( min , Math . abs ( list . get ( i ) - list . get ( i - j ) ) + dyn . get ( i - j ) ) ; } if ( i - j < 0 ) break ; } dyn . add ( min ) ; } System . out . println ( dyn . get ( n - 1 ) ) ; sc . close ( ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner stdIn = new Scanner ( System . in ) ; int N = stdIn . nextInt ( ) ; String S = stdIn . next ( ) ; String answer = " Yes " ; if ( N % 2 != 0 ) { System . out . println ( " No " ) ; System . exit ( 0 ) ; } for ( int i = 0 ; i < N / 2 ; i ++ ) { int i = 0 ; if ( S . charAt ( i ) != S . charAt ( N / 2 + i ) ) { System . out . println ( " No " ) ; System . exit ( 0 ) ; } } System . out . println ( answer ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int sum = 0 ; for ( int i = 0 ; i < 3 ; i ++ ) { sum += sc . nextInt ( ) ; } if ( sum >= 22 ) { int sum = 0 ; System . out . println ( " bust " ) ; return ; } System . out . println ( " win " ) ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; String [ ] nl = scanner . nextLine ( ) . split ( " " , 2 ) ; int n = Integer . parseInt ( nl [ 0 ] ) ; int l = Integer . parseInt ( nl [ 1 ] ) ; String [ ] arr = new String [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { arr [ i ] = scanner . nextLine ( ) ; } Arrays . sort ( arr ) ; for ( int i = 0 ; i < n ; i ++ ) { int i = 0 ; System . out . print ( arr [ i ] ) ; } System . out . print ( " \n " ) ; } } +import java . math . BigDecimal ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner f = new Scanner ( System . in ) ; while ( true ) { int num = f . nextInt ( ) ; if ( num == 0 ) break ; BigDecimal [ ] entries = new BigDecimal [ num ] ; BigDecimal sum = new BigDecimal ( 0 ) ; BigDecimal std = new BigDecimal ( 0 ) ; for ( int i = 0 ; i < num ; i ++ ) { int i = 0 ; BigDecimal temp = new BigDecimal ( f . nextInt ( ) ) ; entries [ i ] = temp ; sum = sum . add ( temp ) ; } BigDecimal average = sum . divide ( new BigDecimal ( num ) , 6 , BigDecimal . ROUND_HALF_UP ) ; for ( int i = 0 ; i < num ; i ++ ) { std = std . add ( entries [ i ] . subtract ( average ) . pow ( 2 ) ) ; } System . out . println ( Math . sqrt ( std . divide ( new BigDecimal ( num ) , 6 , BigDecimal . ROUND_HALF_UP ) . doubleValue ( ) ) ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] s ) { boolean res = false ; Scanner sc = new Scanner ( System . in ) ; int n = 0 ; if ( sc . hasNextInt ( ) ) n = sc . nextInt ( ) ; int cnt = 0 ; boolean res = false ; while ( n -- != 0 ) { byte x = sc . nextByte ( ) ; byte y = sc . nextByte ( ) ; if ( x == y ) cnt ++ ; else cnt = 0 ; if ( cnt == 3 ) res = true ; } if ( res ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } } +import java . util . Scanner ; public class Main { private static int sum ( int aNum , int bNum , int cNum , int k ) { int sum = 0 ; if ( k <= aNum ) { return k ; } else { sum += aNum ; k -= aNum ; } if ( k <= bNum ) { return sum ; } else { k -= bNum ; } return sum + Math . min ( k , cNum ) * - 1 ; } public static void main ( String [ ] args ) { int aNum = sc . nextInt ( ) , bNum = sc . nextInt ( ) , cNum = sc . nextInt ( ) , k = sc . nextInt ( ) ; Scanner sc = new Scanner ( System . in ) ; int aNum = sc . nextInt ( ) , bNum = sc . nextInt ( ) , cNum = sc . nextInt ( ) , k = sc . nextInt ( ) ; System . out . println ( sum ( aNum , bNum , cNum , k ) ) ; sc . close ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; sc . nextLine ( ) ; int [ ] p = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { p [ i ] = sc . nextInt ( ) ; } int count = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( p [ i ] != i + 1 ) { int i = 0 ; count ++ ; } } if ( count == 0 || count == 2 ) { 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 ) ; String a = sc . next ( ) ; String b = sc . next ( ) ; int number = Integer . parseInt ( a + b ) ; for ( int i = 2 ; i * i <= number ; i ++ ) { int i = 2 ; if ( i * i == number ) { System . out . println ( " Yes " ) ; return ; } } System . out . println ( " No " ) ; } } +import java . util . ArrayList ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; ArrayList < Integer > Array = new ArrayList < Integer > ( ) ; for ( int i = 1 ; i < 10 ; i ++ ) { for ( int j = 1 ; j < 10 ; j ++ ) { int j = 1 ; Array . add ( i * j ) ; } } if ( Array . contains ( n ) ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } sc . close ( ) ; } } +import java . util . ArrayList ; import java . util . List ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; final int n = sc . nextInt ( ) ; List < Integer > list = new ArrayList < Integer > ( ) ; int resultCount = 0 ; for ( int i = 0 ; i < n ; i ++ ) { final int num = sc . nextInt ( ) ; if ( num % 2 == 0 ) { list . add ( num ) ; } else { break ; } } if ( list . size ( ) != n ) { System . out . print ( resultCount ) ; return ; } boolean continueFlag = true ; while ( continueFlag ) { int count = 0 ; for ( int j = 0 ; j < n ; j ++ ) { int num = list . get ( j ) ; if ( num % 2 == 0 ) { list . set ( j , num / 2 ) ; count ++ ; } else { continueFlag = false ; break ; } } if ( count == n ) { int num = list . get ( j ) ; resultCount ++ ; } } System . out . print ( resultCount ) ; sc . close ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; String s = in . next ( ) ; String lower = " abcdefghijklmnopqrstuvwxyz " ; if ( s . charAt ( 0 ) != 'A' ) { System . out . println ( " WA " ) ; } else { if ( ! lower . contains ( s . charAt ( 1 ) + " " ) ) { System . out . println ( " WA " ) ; return ; } int Ccount = 0 ; for ( int i = 2 ; i < s . length ( ) - 1 ; i ++ ) { if ( s . charAt ( i ) == 'C' ) { Ccount ++ ; } else { if ( ! lower . contains ( s . charAt ( i ) + " " ) ) { System . out . println ( " WA " ) ; return ; } } } if ( ! lower . contains ( s . charAt ( s . length ( ) - 1 ) + " " ) ) { System . out . println ( " WA " ) ; return ; } if ( Ccount == 1 ) { System . out . println ( " AC " ) ; } else { int i = 2 ; System . out . println ( " WA " ) ; } } } } +import java . io . * ; import java . util . * ; class Main { public static void main ( String [ ] args ) throws IOException { int w , h , x , y , r ; BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String [ ] input = br . readLine ( ) . split ( " " ) ; List < Integer > list = new ArrayList < Integer > ( ) ; for ( String f : input ) { list . add ( Integer . parseInt ( f ) ) ; } w = list . get ( 0 ) ; h = list . get ( 1 ) ; x = list . get ( 2 ) ; y = list . get ( 3 ) ; r = list . get ( 4 ) ; if ( x <= 0 || y <= 0 ) { System . out . println ( " No " ) ; } else if ( 0 <= ( x + r ) && ( x + r ) <= w && 0 <= ( y + r ) && ( y + r ) <= h ) { System . out . println ( " Yes " ) ; } else { String f ; System . out . println ( " No " ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] value = new int [ n ] ; int [ ] cost = new int [ n ] ; int [ ] trueValue = new int [ n ] ; int max = 0 ; for ( int i = 0 ; i < n ; i ++ ) { value [ i ] = sc . nextInt ( ) ; } for ( int i = 0 ; i < n ; i ++ ) { cost [ i ] = sc . nextInt ( ) ; } for ( int i = 0 ; i < n ; i ++ ) { int i = 0 ; trueValue [ i ] = value [ i ] - cost [ i ] ; if ( trueValue [ i ] > 0 ) { max += trueValue [ i ] ; } } System . out . println ( max ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; Long [ ] in = new Long [ a ] ; for ( int i = 0 ; i < a ; i ++ ) { in [ i ] = sc . nextLong ( ) ; } Arrays . sort ( in ) ; Long c = in [ 0 ] - in [ 0 ] ; for ( int i = 0 ; i < a - b ; i ++ ) { c += in [ i ] ; } System . out . println ( c ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; while ( sc . hasNext ( ) ) { int m = sc . nextInt ( ) ; int f = sc . nextInt ( ) ; int r = sc . nextInt ( ) ; if ( m == - 1 && f == - 1 && r == - 1 ) { break ; } else { int x ; x = m + f ; if ( m == - 1 || f == - 1 ) { int r = sc . nextInt ( ) ; System . out . println ( " F " ) ; } if ( x >= 80 && m != - 1 && f != - 1 ) { System . out . println ( " A " ) ; } if ( x < 80 && x >= 65 && m != - 1 && f != - 1 ) { System . out . println ( " B " ) ; } if ( x < 65 && x >= 50 && m != - 1 && f != - 1 ) { System . out . println ( " C " ) ; } if ( x < 50 && x >= 30 && m != - 1 && f != - 1 && r >= 50 ) { System . out . println ( " C " ) ; } if ( x >= 30 && x < 50 && m != - 1 && f != - 1 && r < 50 ) { System . out . println ( " D " ) ; } if ( x < 30 && m != - 1 && f != - 1 ) { System . out . println ( " F " ) ; } } } } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner stdIn = new Scanner ( System . in ) ; int x = stdIn . nextInt ( ) ; int y = stdIn . nextInt ( ) ; int z = stdIn . nextInt ( ) ; int temp ; if ( x > y ) { int temp ; temp = x ; x = y ; y = temp ; } if ( x > z ) { temp = x ; x = z ; z = temp ; } if ( y > z ) { temp = z ; z = y ; y = temp ; } System . out . printf ( " %d %d %d \n " , x , y , z ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { try ( Scanner sc = new Scanner ( System . in ) ) { char [ ] S = sc . next ( ) . toCharArray ( ) ; int result = 0 ; for ( int i = 0 ; i < S . length ; i ++ ) { if ( S [ i ] == '+' ) { result ++ ; } else { int i = 0 ; result -- ; } } System . out . println ( result ) ; } } } +import java . util . * ; public class Main { private static Scanner sc ; public static void main ( String [ ] args ) { int j = 0 ; sc = new Scanner ( System . in ) ; String w = sc . next ( ) ; for ( int i = 0 ; i < w . length ( ) ; i ++ ) { int sum = 0 ; for ( int j = 0 ; j < w . length ( ) ; j ++ ) { if ( w . charAt ( i ) == w . charAt ( j ) ) sum = sum + 1 ; } if ( sum % 2 != 0 ) { System . out . println ( " No " ) ; System . exit ( 0 ) ; } } System . out . println ( " Yes " ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; long n = scanner . nextLong ( ) ; long r = scanner . nextLong ( ) ; scanner . close ( ) ; int count = 0 ; while ( n >= r ) { int count = 0 ; count += 1 ; n = n / r ; } System . out . println ( count + 1 ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . text . Collator ; public class Main { public static void main ( String [ ] args ) throws IOException { try ( BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ) { StringBuilder line = new StringBuilder ( ) ; StringBuilder wordA = new StringBuilder ( ) ; StringBuilder wordB = new StringBuilder ( ) ; Collator collator = Collator . getInstance ( ) ; int turn = Integer . parseInt ( br . readLine ( ) ) ; int pointA = 0 ; int pointB = 0 ; int result = 0 ; for ( int i = 0 ; i < turn ; i ++ ) { int result = 0 ; line . append ( br . readLine ( ) ) ; wordA . append ( line . substring ( 0 , line . indexOf ( " " ) ) ) ; wordB . append ( line . substring ( line . indexOf ( " " ) + 1 , line . length ( ) ) ) ; result = collator . compare ( wordA . toString ( ) , wordB . toString ( ) ) ; pointA += result == 0 ? 1 : result < 0 ? 0 : 3 ; pointB += result == 0 ? 1 : result < 0 ? 3 : 0 ; line . setLength ( 0 ) ; wordA . setLength ( 0 ) ; wordB . setLength ( 0 ) ; } System . out . println ( pointA + " " + pointB ) ; } } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { int l = sc . nextInt ( ) ; Scanner sc = new Scanner ( System . in ) ; do { int h = sc . nextInt ( ) ; int l = sc . nextInt ( ) ; if ( h == 0 && l == 0 ) { break ; } else { for ( int i = 0 ; i < h ; i ++ ) { for ( int j = 0 ; j < l ; j ++ ) { System . out . print ( '#' ) ; } System . out . println ( ) ; } System . out . println ( ) ; } } while ( true ) ; } } +import java . util . * ; public class Main { private static final Scanner scan = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { int a = scan . nextInt ( ) ; int b = scan . nextInt ( ) ; int d = a / b ; int r = a % b ; double f = ( double ) a / ( double ) b ; System . out . printf ( " %d %d %f \n " , d , r , f ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String S = sc . next ( ) ; long K = sc . nextLong ( ) ; int i = 0 ; while ( i < S . length ( ) && S . charAt ( i ) == '1' ) { i ++ ; } if ( i == S . length ( ) || K <= i ) { System . out . println ( 1 ) ; } else { int i = 0 ; System . out . println ( S . charAt ( i ) ) ; } } } +import java . util . Scanner ; public class Main { private static final String SUNNY = " Sunny " ; private static final String CLOUDY = " Cloudy " ; private static final String RAINY = " Rainy " ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; String r = null ; switch ( s ) { case SUNNY : r = CLOUDY ; break ; case CLOUDY : r = RAINY ; break ; case RAINY : r = SUNNY ; break ; default : break ; } System . out . println ( r ) ; sc . close ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int Y = sc . nextInt ( ) ; boolean flag = false ; A : for ( int x = 0 ; x <= Math . min ( Y / 10000 , N ) ; x ++ ) { int z = k / 1000 ; for ( int y = 0 ; y <= Math . min ( ( Y - 10000 * x ) / 5000 , N - x ) ; y ++ ) { int k = Y - 10000 * x - 5000 * y ; if ( k % 1000 == 0 ) { int z = k / 1000 ; if ( z == ( N - x - y ) ) { System . out . printf ( " %d %d %d " , x , y , z ) ; flag = true ; break A ; } } } } if ( ! flag ) System . out . printf ( " -1 -1 -1 " ) ; sc . close ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int N = scanner . nextInt ( ) ; for ( int i = 1 ; i <= 9 ; i ++ ) { if ( N <= 111 * i ) { int i = 1 ; System . out . println ( 111 * i ) ; break ; } } } } +import java . util . * ; import java . io . * ; public class Main { public static void main ( String [ ] Args ) { Scanner in = new Scanner ( System . in ) ; String s = in . next ( ) ; int ans = 0 ; for ( int i = 0 ; i < 26 ; i ++ ) { int check = 0 ; for ( int j = 0 ; j < 4 ; j ++ ) { int j = 0 ; if ( s . charAt ( j ) - 'A' == i ) { check ++ ; } } if ( check != 0 && check != 2 ) { ans = 1 ; } } if ( ans == 0 ) 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 = Integer . parseInt ( sc . next ( ) ) ; int B = Integer . parseInt ( sc . next ( ) ) ; if ( A >= 10 || B >= 10 ) { System . out . println ( - 1 ) ; } else { int B = Integer . parseInt ( sc . next ( ) ) ; System . out . println ( A * B ) ; } } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner obj = new Scanner ( System . in ) ; int n = obj . nextInt ( ) ; int m = obj . nextInt ( ) ; int [ ] a = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { int i = 0 ; a [ i ] = obj . nextInt ( ) ; } Arrays . sort ( a ) ; int sum = 0 ; for ( int i = 0 ; i < m ; i ++ ) sum = sum + a [ i ] ; System . out . println ( sum ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String N = sc . next ( ) ; sc . close ( ) ; String [ ] arr = N . split ( " " ) ; int n = Integer . valueOf ( N ) ; int sn = 0 ; for ( int i = 0 ; i < arr . length ; i ++ ) { sn += Integer . valueOf ( arr [ i ] ) ; } if ( n % sn == 0 ) { int i = 0 ; System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { String f = sc . next ( ) ; Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; String f = sc . next ( ) ; if ( a % 2 == 0 ) { if ( f . substring ( 0 , a / 2 ) . equals ( f . substring ( a / 2 , a ) ) ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } else { System . out . println ( " No " ) ; } } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String w = sc . nextLine ( ) . toLowerCase ( ) ; int count = 0 ; while ( true ) { String [ ] line = sc . nextLine ( ) . split ( " " ) ; if ( line [ 0 ] . equals ( " END_OF_TEXT " ) ) { break ; } for ( int i = 0 ; i < line . length ; i ++ ) { if ( w . equals ( line [ i ] . toLowerCase ( ) ) ) { int i = 0 ; count += 1 ; } } } System . out . println ( count ) ; } } +import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = a . length - 1 ; Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int [ ] a = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { a [ i ] = sc . nextInt ( ) ; } Arrays . sort ( a ) ; int alice = 0 ; int bob = 0 ; boolean isAlice = true ; for ( int i = a . length - 1 ; i != - 1 ; i -- ) { if ( isAlice ) { alice += a [ i ] ; } else { bob += a [ i ] ; } isAlice = ! isAlice ; } System . out . println ( alice - bob ) ; } } +import java . io . PrintStream ; import java . util . Scanner ; public class Main { private static final PrintStream so = System . out ; private static final Scanner sc = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { int K = sc . nextInt ( ) ; int S = sc . nextInt ( ) ; int count = 0 ; for ( int x = 0 ; x <= K ; x ++ ) { int y = 0 ; for ( int y = 0 ; y <= K ; y ++ ) { int z = S - ( x + y ) ; if ( 0 <= z && z <= K ) { count ++ ; } } } so . println ( count ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; String S = sc . next ( ) ; if ( N % 2 == 0 ) { String S = sc . next ( ) ; int h = N / 2 - 1 ; String bs = S . substring ( 0 , h + 1 ) ; String as = S . substring ( h + 1 , N ) ; if ( as . equals ( bs ) ) { System . out . println ( " Yes " ) ; return ; } } System . out . println ( " No " ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; String ans = " Yes " ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( i % 2 == 0 && s . charAt ( i ) == 'L' ) { ans = " No " ; break ; } else if ( i % 2 == 1 && s . charAt ( i ) == 'R' ) { int i = 0 ; ans = " No " ; break ; } } System . out . println ( ans ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner s1 = new Scanner ( System . in ) ; int n = s1 . nextInt ( ) ; int A = s1 . nextInt ( ) ; int B = s1 . nextInt ( ) ; for ( int i = A ; i <= B ; i ++ ) { int i = A ; if ( i % n == 0 ) { System . out . println ( " OK " ) ; return ; } } System . out . println ( " NG " ) ; } } +import java . util . * ; class Main { static Scanner scan = new Scanner ( System . in ) ; public static void main ( String [ ] argv ) { int n = scan . nextInt ( ) ; int n1 = n % 10 ; int n2 = ( n % 100 - n1 ) / 10 ; int n3 = ( n - n1 - n1 ) / 100 ; if ( n3 == 9 ) { n = 999 ; System . out . println ( n ) ; return ; } if ( n1 > n3 || n2 > n3 ) { int n3 = ( n - n1 - n1 ) / 100 ; n3 += 1 ; } n = n3 * 100 + n3 * 10 + n3 ; System . out . println ( n ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; while ( sc . hasNext ( ) ) { long m = sc . nextLong ( ) ; long n = sc . nextLong ( ) ; System . out . printf ( " %d %d \n " , gcd ( m , n ) , lcm ( m , n ) ) ; } } public static long gcd ( long a , long b ) { if ( b == 0 ) return a ; else return gcd ( b , a % b ) ; } public static long lcm ( long a , long b ) { Scanner sc = new Scanner ( System . in ) ; return a * b / gcd ( a , b ) ; } } +import java . util . * ; public class Main { public static void main ( final String [ ] args ) { final Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int M = sc . nextInt ( ) ; sc . close ( ) ; int sum = 0 ; for ( int i = 1 ; i < N ; i ++ ) { int i = 1 ; sum += i ; } for ( int i = 1 ; i < M ; i ++ ) { sum += i ; } System . out . println ( sum ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int elements = sc . nextInt ( ) ; int [ ] value = new int [ elements ] ; for ( int i = 0 ; i < elements ; i ++ ) { int i = 1 ; value [ i ] = sc . nextInt ( ) ; } solve ( value ) ; } public static void solve ( int [ ] height ) { int result = 0 ; int now = 0 ; for ( int i = 1 ; i < height . length ; i ++ ) { if ( height [ i - 1 ] >= height [ i ] ) { now ++ ; } else { if ( result < now ) result = now ; now = 0 ; } } if ( result < now ) result = now ; System . out . println ( result ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner keyboard = new Scanner ( System . in ) ; String S = keyboard . next ( ) ; String X1 = S . replace ( 'A' , '#' ) ; String X2 = X1 . replace ( 'T' , '#' ) ; String X3 = X2 . replace ( 'G' , '#' ) ; String X4 = X3 . replace ( 'C' , '#' ) ; String [ ] Y = X4 . split ( " " ) ; int count = 0 ; int ans = 0 ; for ( int i = 0 ; i < S . length ( ) ; i ++ ) { if ( Y [ i ] . equals ( " # " ) ) { count ++ ; ans = ( count > ans ) ? count : ans ; if ( count == S . length ( ) ) { ans = count ; } } else { int i = 0 ; ans = ( count > ans ) ? count : ans ; count = 0 ; } } System . out . println ( ans ) ; keyboard . close ( ) ; } } +import java . util . * ; class Main { static int n ; static int [ ] a ; static Scanner scanner = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { int i = 0 ; while ( read ( ) ) { insertionSort ( a ) ; } } static boolean read ( ) { if ( ! scanner . hasNext ( ) ) return false ; n = scanner . nextInt ( ) ; a = new int [ n ] ; for ( int i = 0 ; i < a . length ; i ++ ) { a [ i ] = scanner . nextInt ( ) ; } return true ; } static int [ ] insertionSort ( int [ ] array ) { for ( int i = 0 ; i < array . length ; i ++ ) { int v = array [ i ] ; int j = i - 1 ; while ( j >= 0 && array [ j ] > v ) { array [ j + 1 ] = array [ j ] ; j -- ; } array [ j + 1 ] = v ; traceArray ( array ) ; } return array ; } static void traceArray ( int [ ] array ) { for ( int i = 0 ; i < array . length ; i ++ ) { if ( i == array . length - 1 ) { System . out . print ( array [ i ] ) ; continue ; } System . out . print ( array [ i ] + " " ) ; } System . out . println ( ) ; } } +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 ( ) ; String s = sc . next ( ) ; boolean ok = true ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { int i = 0 ; if ( i == a && s . charAt ( a ) != '-' ) { ok = false ; } if ( i != a && s . charAt ( i ) == '-' ) { ok = false ; } } if ( ok ) { 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 n = Integer . parseInt ( sc . next ( ) ) ; int k = Integer . parseInt ( sc . next ( ) ) ; String s = sc . next ( ) ; StringBuilder sb = new StringBuilder ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( i == k - 1 ) { sb . appendCodePoint ( s . charAt ( i ) + 32 ) ; } else { int i = 0 ; sb . append ( s . charAt ( i ) ) ; } } System . out . println ( sb . toString ( ) ) ; } } +import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int count = scan . nextInt ( ) ; int strlenge = scan . nextInt ( ) ; String [ ] output = new String [ count ] ; for ( int i = 0 ; i < count ; i ++ ) { int i = 0 ; output [ i ] = scan . next ( ) ; } Arrays . sort ( output ) ; for ( int i = 0 ; i < count ; i ++ ) { System . out . print ( output [ i ] ) ; } scan . close ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int num = sc . nextInt ( ) ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int cnt = 0 ; while ( n -- > 0 ) { int num = sc . nextInt ( ) ; if ( isPrime ( num ) ) cnt ++ ; } System . out . println ( cnt ) ; } public static boolean isPrime ( int num ) { for ( int i = 2 ; i * i <= num ; i ++ ) if ( num % i == 0 ) return false ; return true ; } } +import java . util . Scanner ; public class Main { void reverse ( ) { int i = n - 1 ; Scanner s = new Scanner ( System . in ) ; int n = s . nextInt ( ) ; int [ ] a = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = s . nextInt ( ) ; } for ( int i = n - 1 ; i >= 0 ; i -- ) { System . out . print ( a [ i ] ) ; if ( i > 0 ) { System . out . print ( " " ) ; } else { System . out . print ( " \n " ) ; } } } public static void main ( String [ ] args ) { Main m = new Main ( ) ; m . reverse ( ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; char [ ] S = sc . next ( ) . toCharArray ( ) ; String output = " Good " ; for ( int i = 0 ; i < S . length - 1 ; i ++ ) { int i = 0 ; if ( S [ i ] == S [ i + 1 ] ) { output = " Bad " ; break ; } } System . out . println ( output ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; String [ ] s = sc . next ( ) . split ( " " ) ; String ans = " Yes " ; for ( int i = 0 ; i < s . length ; i ++ ) { int i = 0 ; if ( i == a ) { if ( ! s [ a ] . equals ( " - " ) ) { ans = " No " ; break ; } } else { if ( s [ i ] . equals ( " - " ) ) { ans = " No " ; break ; } } } System . out . println ( ans ) ; } } +import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . io . IOException ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader in = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String [ ] str = in . readLine ( ) . split ( " " ) ; int n = Integer . parseInt ( str [ 0 ] ) ; int k = Integer . parseInt ( str [ 1 ] ) ; int q = Integer . parseInt ( str [ 2 ] ) ; int [ ] a = new int [ q ] ; int [ ] count = new int [ n ] ; for ( int i = 0 ; i < q ; i ++ ) { int i = 0 ; a [ i ] = Integer . parseInt ( in . readLine ( ) ) ; count [ a [ i ] - 1 ] ++ ; } for ( int i = 0 ; i < n ; i ++ ) { if ( k - ( q - count [ i ] ) <= 0 ) System . out . println ( " No " ) ; else System . out . println ( " Yes " ) ; } } } +import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] ary = new int [ n ] ; for ( int i = 0 ; i < ary . length ; i ++ ) { int i = 0 ; ary [ i ] = sc . nextInt ( ) ; } Arrays . sort ( ary ) ; long sum = 0 ; for ( int i = 0 ; i < ary . length ; i ++ ) { sum += ary [ i ] ; } System . out . printf ( " %d %d %d%n " , ary [ 0 ] , ary [ n - 1 ] , sum ) ; } } +import java . io . * ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; Main m = new Main ( ) ; String sec_ = br . readLine ( ) ; int sec = Integer . parseInt ( sec_ ) ; m . SecToTime ( sec ) ; } public void SecToTime ( int sec ) { int h = 0 , m = 0 ; while ( sec >= 3600 ) { int h = 0 , m = 0 ; h ++ ; sec -= 3600 ; } while ( sec >= 60 ) { m ++ ; sec -= 60 ; } System . out . println ( h + " : " + m + " : " + sec ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int k = 0 ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int d = sc . nextInt ( ) ; String dummy = sc . nextLine ( ) ; int [ ] [ ] x = new int [ n ] [ d ] ; for ( int i = 0 ; i < n ; i ++ ) { String [ ] s = sc . nextLine ( ) . split ( " " ) ; for ( int j = 0 ; j < d ; j ++ ) { x [ i ] [ j ] = Integer . parseInt ( s [ j ] ) ; } } int ans = 0 ; for ( int i = 0 ; i < n - 1 ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { int sum = 0 ; for ( int k = 0 ; k < d ; k ++ ) { sum += ( x [ i ] [ k ] - x [ j ] [ k ] ) * ( x [ i ] [ k ] - x [ j ] [ k ] ) ; } if ( Math . sqrt ( sum ) == ( int ) Math . sqrt ( sum ) ) ans ++ ; } } System . out . println ( ans ) ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] h = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { h [ i ] = sc . nextInt ( ) ; } int sum = 0 ; boolean flag = true ; while ( flag ) { flag = false ; boolean ed = false ; for ( int i = 0 ; i < n ; i ++ ) { if ( h [ i ] != 0 ) { int i = 0 ; h [ i ] = h [ i ] - 1 ; if ( ! ed ) { ed = true ; flag = true ; sum ++ ; } } else { ed = false ; } } } System . out . println ( sum ) ; } } +import java . util . ArrayDeque ; import java . util . ArrayList ; import java . util . Collections ; import java . util . HashMap ; import java . util . HashSet ; import java . util . LinkedList ; import java . util . List ; import java . util . Map ; import java . util . Queue ; import java . util . Scanner ; import java . util . Set ; public class Main { static Scanner sc = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { solve_abc158_c ( ) ; } public static void solve_abc158_c ( ) { Scanner sc = new Scanner ( System . in ) ; int A = sc . nextInt ( ) ; int B = sc . nextInt ( ) ; int ans = - 1 ; for ( int i = 1 ; i <= 1250 ; i ++ ) { int i = 1 ; int c = ( int ) Math . floor ( i * 0.08 ) ; int d = ( int ) Math . floor ( i * 0.1 ) ; if ( c == A && d == B ) { ans = i ; break ; } } System . out . println ( ans ) ; sc . close ( ) ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; if ( n % 2 == 0 ) { int [ ] d = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { int i = 0 ; d [ i ] = sc . nextInt ( ) ; } Arrays . sort ( d ) ; int ans = d [ n / 2 ] - d [ n / 2 - 1 ] ; System . out . println ( ans ) ; } else { System . out . println ( 0 ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = Integer . parseInt ( sc . next ( ) ) ; int m = Integer . parseInt ( sc . next ( ) ) ; int [ ] love = new int [ m ] ; int k , a ; for ( int i = 0 ; i < n ; i ++ ) { k = Integer . parseInt ( sc . next ( ) ) ; for ( int j = 0 ; j < k ; j ++ ) { a = Integer . parseInt ( sc . next ( ) ) ; love [ a - 1 ] ++ ; } } int count = 0 ; for ( int i = 0 ; i < m ; i ++ ) { if ( love [ i ] == n ) { int i = 0 ; count ++ ; } } System . out . println ( count ) ; } } +import java . util . Scanner ; class Main { static Scanner sc = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { int i = 0 ; String S = sc . next ( ) ; boolean f = true ; for ( int i = 0 ; i < S . length ( ) / 2 ; i ++ ) { if ( S . charAt ( i ) != S . charAt ( S . length ( ) - i - 1 ) ) { f = false ; break ; } } for ( int i = 0 ; i < S . length ( ) / 4 ; i ++ ) { if ( S . charAt ( i ) != S . charAt ( S . length ( ) / 2 - i - 1 ) ) { f = false ; break ; } } System . out . println ( f ? " Yes " : " No " ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int n = scan . nextInt ( ) ; int [ ] r = new int [ n ] ; int ans ; for ( int i = 0 ; i < n ; i ++ ) { r [ i ] = scan . nextInt ( ) ; } int maxv = r [ 1 ] - r [ 0 ] ; int minv = r [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { int i = 1 ; maxv = Math . max ( maxv , r [ i ] - minv ) ; minv = Math . min ( minv , r [ i ] ) ; } System . out . println ( maxv ) ; } } +import java . math . BigDecimal ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { BigDecimal e = a . multiply ( c ) ; Scanner sc = new Scanner ( System . in ) ; BigDecimal a = sc . nextBigDecimal ( ) ; BigDecimal b = sc . nextBigDecimal ( ) ; BigDecimal c = sc . nextBigDecimal ( ) ; BigDecimal d = sc . nextBigDecimal ( ) ; BigDecimal e = a . multiply ( c ) ; if ( e . compareTo ( a . multiply ( d ) ) < 0 ) { e = a . multiply ( d ) ; } if ( e . compareTo ( b . multiply ( c ) ) < 0 ) { e = b . multiply ( c ) ; } if ( e . compareTo ( b . multiply ( d ) ) < 0 ) { e = b . multiply ( d ) ; } System . out . println ( e ) ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int A = sc . nextInt ( ) ; int B = sc . nextInt ( ) ; int ans = 0 ; int T = N * A ; if ( T < B ) { ans = T ; } else { int T = N * A ; ans = B ; } System . out . println ( ans ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int num = Integer . parseInt ( sc . nextLine ( ) ) ; sc . close ( ) ; int ans = 0 ; if ( num < 10 ) { ans = num ; } else if ( num < 100 ) { ans = 9 ; } else if ( num < 1000 ) { ans = num - 99 + 9 ; } else if ( num < 10000 ) { ans = 999 - 99 + 9 ; } else if ( num < 100000 ) { int ans = 0 ; ans = num - 9999 + 999 - 99 + 9 ; } else if ( num < 1000000 ) { ans = 99999 - 9999 + 999 - 99 + 9 ; } System . out . println ( ans ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] a ) { Scanner scan = new Scanner ( System . in ) ; String [ ] t = scan . nextLine ( ) . split ( " \\ s " ) ; int people = Integer . parseInt ( t [ 0 ] ) ; int ht = Integer . parseInt ( t [ 1 ] ) ; int count = 0 ; while ( scan . hasNextInt ( ) ) { int count = 0 ; int memHt = scan . nextInt ( ) ; if ( memHt >= ht ) { count ++ ; } } System . out . println ( count ) ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; String t = sc . next ( ) ; String s1 = s . substring ( 0 , 1 ) ; String s2 = s . substring ( 1 , 2 ) ; String s3 = s . substring ( 2 , 3 ) ; String t1 = t . substring ( 0 , 1 ) ; String t2 = t . substring ( 1 , 2 ) ; String t3 = t . substring ( 2 , 3 ) ; int result = 0 ; if ( s1 . equals ( t1 ) ) { result += 1 ; } else { result += 0 ; } if ( s2 . equals ( t2 ) ) { result += 1 ; } else { result += 0 ; } if ( s3 . equals ( t3 ) ) { int result = 0 ; result += 1 ; } else { result += 0 ; } System . out . println ( result ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int i = 1 ; Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; char pre = s . charAt ( 0 ) ; String ans = " Good " ; for ( int i = 1 ; i < 4 ; i ++ ) { if ( pre == s . charAt ( i ) ) ans = " Bad " ; pre = s . charAt ( i ) ; } System . out . println ( ans ) ; sc . close ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner stdIn = new Scanner ( System . in ) ; int n = stdIn . nextInt ( ) ; int x = stdIn . nextInt ( ) ; int [ ] l = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { l [ i ] = stdIn . nextInt ( ) ; } int counter = 1 ; long zahyou = 0 ; for ( int i = 0 ; i < n ; i ++ ) { zahyou += l [ i ] ; if ( x < zahyou ) { int i = 0 ; break ; } else { counter ++ ; } } System . out . println ( counter ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; long n = in . nextInt ( ) ; long sum = 0 ; for ( long i = 0 ; i <= n ; i ++ ) { long i = 0 ; if ( i % 3 != 0 && i % 5 != 0 ) sum += i ; } System . out . println ( sum ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String weather = sc . next ( ) ; String S = " Sunny " ; String C = " Cloudy " ; String R = " Rainy " ; if ( weather . equals ( S ) ) { String R = " Rainy " ; System . out . println ( C ) ; } else if ( weather . equals ( C ) ) { System . out . println ( R ) ; } else { System . out . println ( S ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { int j = 0 ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] [ ] nums = new int [ 4 ] [ 13 ] ; for ( int i = 0 ; i < n ; i ++ ) { String suit = sc . next ( ) ; int num = sc . nextInt ( ) ; if ( " S " . equals ( suit ) ) { nums [ 0 ] [ num - 1 ] = 1 ; } else if ( " H " . equals ( suit ) ) { nums [ 1 ] [ num - 1 ] = 1 ; } else if ( " C " . equals ( suit ) ) { nums [ 2 ] [ num - 1 ] = 1 ; } else { nums [ 3 ] [ num - 1 ] = 1 ; } } for ( int i = 0 ; i < 4 ; i ++ ) { String suit = " S " ; if ( i == 0 ) { suit = " S " ; } else if ( i == 1 ) { suit = " H " ; } else if ( i == 2 ) { suit = " C " ; } else { suit = " D " ; } for ( int j = 0 ; j < 13 ; j ++ ) { if ( nums [ i ] [ j ] == 0 ) { System . out . println ( suit + " " + ( j + 1 ) ) ; } } } } } +import java . util . Scanner ; import java . lang . Math ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int n ; double [ ] ans = new double [ 1000 ] ; int k = 0 ; while ( true ) { n = scan . nextInt ( ) ; if ( n == 0 ) break ; int [ ] a = new int [ n ] ; int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = scan . nextInt ( ) ; sum += a [ i ] ; } double ave = ( double ) sum / n ; double var = 0 ; for ( int i = 0 ; i < n ; i ++ ) { var = var + ( ( a [ i ] - ave ) * ( a [ i ] - ave ) / n ) ; } ans [ k ] = Math . sqrt ( var ) ; k ++ ; } for ( int i = 0 ; i < k ; i ++ ) { int i = 0 ; System . out . printf ( " %.5f \n " , ans [ i ] ) ; } } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; Integer [ ] num = new Integer [ N ] ; int alice = 0 ; int bob = 0 ; for ( int i = 0 ; i < N ; i ++ ) { num [ i ] = sc . nextInt ( ) ; } Arrays . sort ( num ) ; for ( int i = N - 1 ; i != - 1 ; i -- ) { if ( i % 2 == 0 ) { int i = N - 1 ; alice += num [ i ] ; } else { bob += num [ i ] ; } } System . out . println ( Math . abs ( alice - bob ) ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int y = sc . nextInt ( ) ; int res10000 = - 1 , res5000 = - 1 , res1000 = - 1 ; sc . close ( ) ; for ( int a = 0 ; a <= N ; a ++ ) { int c = N - a - b ; for ( int b = 0 ; b + a <= N ; b ++ ) { int c = N - a - b ; int total = 10000 * a + 5000 * b + 1000 * c ; if ( total == y ) { res10000 = a ; res5000 = b ; res1000 = c ; } } } System . out . println ( res10000 + " " + res5000 + " " + res1000 ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int k = i + 1 ; Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int [ ] tako = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { tako [ i ] = sc . nextInt ( ) ; } int sum = 0 ; for ( int i = 0 ; i < N ; i ++ ) { for ( int k = i + 1 ; k < N ; k ++ ) { sum += tako [ i ] * tako [ k ] ; } } System . out . println ( sum ) ; } } +import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] arg ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int [ ] d = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { int i = 0 ; d [ i ] = sc . nextInt ( ) ; } Arrays . sort ( d ) ; System . out . print ( d [ N / 2 ] - d [ N / 2 - 1 ] ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String S = sc . next ( ) ; sc . close ( ) ; int count0 = 0 ; int count1 = 0 ; for ( int i = 0 ; i < S . length ( ) ; i ++ ) { int i = 0 ; if ( S . charAt ( i ) == '1' ) count1 ++ ; if ( S . charAt ( i ) == '0' ) count0 ++ ; } System . out . println ( 2 * Math . min ( count1 , count0 ) ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int now = sc . nextInt ( ) ; int next = 0 ; int count = 0 ; int answer = 0 ; for ( int i = 0 ; i < N - 1 ; i ++ ) { next = sc . nextInt ( ) ; if ( now >= next ) { int answer = 0 ; count ++ ; } else { answer = Math . max ( answer , count ) ; count = 0 ; } now = next ; } answer = Math . max ( answer , count ) ; System . out . println ( answer ) ; sc . close ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = n - 1 ; 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 ( ) ; } boolean f = true ; for ( int i = n - 1 ; i > 0 ; i -- ) { if ( a [ i - 1 ] - a [ i ] >= 2 ) { f = false ; } else if ( a [ i - 1 ] - a [ i ] == 1 ) { a [ i - 1 ] -- ; } } if ( f ) System . out . print ( " Yes " ) ; else System . out . print ( " No " ) ; } } +import java . io . * ; import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . StringTokenizer ; import java . util . * ; public class Main { static class FastReader { BufferedReader br ; StringTokenizer st ; public FastReader ( ) { br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; } String next ( ) { while ( st == null || ! st . hasMoreTokens ( ) ) { try { String str = " " ; 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 ; } public Character charAt ( int i ) { return null ; } } public static void main ( String [ ] args ) throws IOException { FastReader s = new FastReader ( ) ; int n = s . nextInt ( ) ; int v = ( int ) ( n + Math . pow ( n , 2 ) + Math . pow ( n , 3 ) ) ; System . out . println ( v ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int [ ] B = new int [ N - 1 ] ; for ( int i = 0 ; i < N - 1 ; i ++ ) B [ i ] = sc . nextInt ( ) ; int count = B [ 0 ] ; for ( int i = 0 ; i < N - 2 ; i ++ ) { if ( B [ i ] < B [ i + 1 ] ) count += B [ i ] ; else count += B [ i + 1 ] ; } count += B [ N - 2 ] ; System . out . println ( count ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int x = sc . nextInt ( ) ; int y = sc . nextInt ( ) ; for ( int i = 0 ; i <= x ; i ++ ) { int i = 0 ; if ( i * 2 + ( x - i ) * 4 == y ) { System . out . println ( " Yes " ) ; return ; } } System . out . println ( " No " ) ; sc . close ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int last = sc . nextInt ( ) ; int res = last ; for ( int i = 0 ; i < n - 2 ; i ++ ) { int res = last ; int t = sc . nextInt ( ) ; res += Math . min ( t , last ) ; last = t ; } System . out . println ( res + last ) ; } } +import java . lang . reflect . Array ; import java . util . * ; public class Main { static int N ; static int K ; static long Q ; static int A ; static int B ; static long C ; static double min = 9999999 ; static long ans = 0 ; public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int A = scanner . nextInt ( ) ; int B = scanner . nextInt ( ) ; int T = scanner . nextInt ( ) ; System . out . println ( ( T / A ) * B ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; final int N = sc . nextInt ( ) ; int [ ] x = new int [ N ] ; int [ ] y = new int [ N ] ; int sum = 0 ; for ( int i = 0 ; i < N ; i ++ ) { x [ i ] = sc . nextInt ( ) ; } for ( int i = 0 ; i < N ; i ++ ) { y [ i ] = sc . nextInt ( ) ; } for ( int i = 0 ; i < N ; i ++ ) { int i = 0 ; if ( x [ i ] >= y [ i ] ) { sum += x [ i ] - y [ i ] ; } } System . out . println ( sum ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; String input = sc . next ( ) ; String [ ] inputSplit = input . split ( " " ) ; int num0 = 0 ; for ( int i = 0 ; i < inputSplit . length ; i ++ ) { if ( inputSplit [ i ] . equals ( " 0 " ) ) { int i = 0 ; num0 ++ ; } } System . out . print ( Math . min ( num0 , inputSplit . length - num0 ) * 2 ) ; } } +import java . util . * ; import java . lang . * ; import java . math . * ; public class Main { Scanner sc = new Scanner ( System . in ) ; void run ( ) { long x , y , z ; long first , second ; long tmp ; while ( sc . hasNext ( ) ) { first = sc . nextLong ( ) ; second = sc . nextLong ( ) ; x = first ; y = second ; if ( x < y ) { long tmp ; tmp = x ; x = y ; y = tmp ; } do { z = x % y ; x = y ; y = z ; } while ( z != 0 ) ; System . out . println ( x + " " + first * second / x ) ; } } public static void main ( String [ ] args ) { new Main ( ) . run ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Main main = new Main ( ) ; main . run ( ) ; } public void run ( ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; while ( true ) { if ( prime ( n ) ) { break ; } n ++ ; } System . out . println ( n ) ; sc . close ( ) ; } private boolean prime ( int n ) { int i = 3 ; if ( n == 0 || n == 1 ) { return false ; } if ( n == 2 ) return true ; if ( n % 2 == 0 ) return false ; for ( int i = 3 ; i * i <= n ; i += 2 ) { if ( n % i == 0 ) { return false ; } } return true ; } } +import java . io . * ; public class Main { public static void main ( String [ ] args ) throws IOException { int i = 0 ; BufferedReader bf = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int w , n , right , left , x ; String str ; w = Integer . parseInt ( bf . readLine ( ) ) ; n = Integer . parseInt ( bf . readLine ( ) ) ; int [ ] order = new int [ w ] ; for ( int i = 0 ; i < w ; i ++ ) { order [ i ] = i + 1 ; } for ( int i = 0 ; i < 2 * n ; i += 2 ) { str = bf . readLine ( ) ; String [ ] deta = str . split ( " , " , 0 ) ; left = Integer . parseInt ( deta [ 0 ] ) ; right = Integer . parseInt ( deta [ 1 ] ) ; x = order [ left - 1 ] ; order [ left - 1 ] = order [ right - 1 ] ; order [ right - 1 ] = x ; } for ( int i = 0 ; i < w ; i ++ ) { System . out . println ( order [ i ] ) ; } } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader in = new BufferedReader ( new InputStreamReader ( System . in ) ) ; Solver solver = new Solver ( ) ; solver . init ( ) ; solver . readHead ( in . readLine ( ) ) ; } } class Solver { int N ; int cnt ; public void init ( ) { N = 0 ; cnt = 0 ; } public void readHead ( String str ) { String [ ] strArr = str . split ( " " ) ; N = Integer . parseInt ( strArr [ 0 ] ) ; int a = Integer . parseInt ( strArr [ 0 ] ) ; int b = Integer . parseInt ( strArr [ 1 ] ) ; int k = Integer . parseInt ( strArr [ 2 ] ) ; for ( int ans = Integer . min ( a , b ) ; ; ans -- ) { if ( a % ans == 0 && b % ans == 0 ) k -- ; if ( k <= 0 ) { System . out . println ( ans ) ; return ; } } } public boolean hasNext ( ) { int ans = Integer . min ( a , b ) ; return cnt < N ; } public void readBody ( String str ) { cnt ++ ; } public void solve ( ) { } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner stdIn = new Scanner ( System . in ) ; int N = stdIn . nextInt ( ) ; int Q = stdIn . nextInt ( ) ; int [ ] ans = new int [ N ] ; int [ ] kota = new int [ Q ] ; String S = stdIn . next ( ) ; int z = 1 , y = 0 , l = 0 , r = 0 , num = 0 ; while ( z < N ) { int z = 1 , y = 0 , l = 0 , r = 0 , num = 0 ; if ( S . substring ( z , z + 1 ) . equals ( " C " ) && S . substring ( z - 1 , z ) . equals ( " A " ) ) { y ++ ; } ans [ z ] = y ; z ++ ; } z = 0 ; y = 0 ; while ( z < Q ) { l = stdIn . nextInt ( ) ; r = stdIn . nextInt ( ) ; kota [ z ] = ans [ r - 1 ] - ans [ l - 1 ] ; z ++ ; } z = 0 ; while ( z < Q ) { System . out . println ( kota [ z ] ) ; z ++ ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int cards = sc . nextInt ( ) ; int gates = sc . nextInt ( ) ; Integer [ ] start = new Integer [ gates ] ; Integer [ ] end = new Integer [ gates ] ; for ( Integer i = 0 ; i < gates ; i ++ ) { start [ i ] = sc . nextInt ( ) ; end [ i ] = sc . nextInt ( ) ; } Arrays . sort ( start , Collections . reverseOrder ( ) ) ; Arrays . sort ( end ) ; Integer result = end [ 0 ] - start [ 0 ] + 1 ; if ( result < 0 ) { Integer result = end [ 0 ] - start [ 0 ] + 1 ; result = 0 ; } System . out . println ( result ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . HashMap ; import java . util . Map ; public class Main { public static void main ( String [ ] args ) throws IOException { int count = 0 ; BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int n = Integer . parseInt ( br . readLine ( ) ) ; int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { String [ ] str = br . readLine ( ) . split ( " " ) ; int a = Integer . parseInt ( str [ 0 ] ) ; int b = Integer . parseInt ( str [ 1 ] ) ; if ( a == b ) { count ++ ; } else { count = 0 ; } if ( count >= 3 ) { System . out . println ( " Yes " ) ; return ; } } System . out . println ( " No " ) ; } } +import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner reader = new Scanner ( new BufferedReader ( new InputStreamReader ( System . in ) ) ) ; int A , B , C , mili = 0 ; A = reader . nextInt ( ) ; B = reader . nextInt ( ) ; C = reader . nextInt ( ) ; mili = ( B + C ) - A ; if ( mili > 0 ) { System . out . println ( mili ) ; } else { int A , B , C , mili = 0 ; System . out . println ( 0 ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int result = 0 ; Scanner scan = new Scanner ( System . in ) ; int A = scan . nextInt ( ) ; int B = scan . nextInt ( ) ; int result = 0 ; if ( A == B ) { result = A + B ; } else if ( A > B ) { result = A + A - 1 ; } else if ( B > A ) { result = B + B - 1 ; } System . out . println ( result ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] a = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = sc . nextInt ( ) ; } int cnt = 0 ; boolean is_odd = false ; while ( ! is_odd ) { for ( int i = 0 ; i < n ; i ++ ) { if ( ( a [ i ] & 1 ) == 0 ) { a [ i ] >>= 1 ; } else { is_odd = true ; break ; } } if ( ! is_odd ) cnt ++ ; } System . out . println ( cnt ) ; } } +import java . io . FileNotFoundException ; import java . math . BigDecimal ; import java . math . RoundingMode ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws FileNotFoundException { Scanner sc = new Scanner ( System . in ) ; int W = sc . nextInt ( ) ; int H = sc . nextInt ( ) ; int x = sc . nextInt ( ) ; int y = sc . nextInt ( ) ; boolean flg = false ; BigDecimal S = BigDecimal . valueOf ( W ) ; S = S . multiply ( BigDecimal . valueOf ( H ) ) ; S = S . divide ( BigDecimal . valueOf ( 2 ) , 10 , RoundingMode . HALF_UP ) ; if ( 2 * x == W && 2 * y == H ) { flg = true ; } System . out . print ( S + " " ) ; if ( flg ) { boolean flg = false ; System . out . println ( " 1 " ) ; } else { System . out . println ( " 0 " ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int h ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int k = sc . nextInt ( ) ; int [ ] people = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { people [ i ] = sc . nextInt ( ) ; } int ok = 0 ; for ( int h : people ) { ok += h >= k ? 1 : 0 ; } System . out . println ( ok ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String line = sc . nextLine ( ) ; int inputNumber = Integer . parseInt ( line ) ; String result = " No " ; for ( int i = 1 ; i <= 9 ; i ++ ) { for ( int j = 1 ; j <= 9 ; j ++ ) { int tmp = i * j ; if ( inputNumber == tmp ) { int j = 1 ; result = " Yes " ; } } } System . out . println ( result ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; while ( true ) { String [ ] str = scan . nextLine ( ) . split ( " " ) ; int a = Integer . parseInt ( str [ 0 ] ) ; int b = Integer . parseInt ( str [ 2 ] ) ; if ( " ? " . equals ( str [ 1 ] ) ) break ; if ( " + " . equals ( str [ 1 ] ) ) { int b = Integer . parseInt ( str [ 2 ] ) ; System . out . println ( a + b ) ; } else if ( " - " . equals ( str [ 1 ] ) ) { System . out . println ( a - b ) ; } else if ( " * " . equals ( str [ 1 ] ) ) { System . out . println ( a * b ) ; } else if ( " / " . equals ( str [ 1 ] ) ) { System . out . println ( a / b ) ; } } } } +import java . util . Scanner ; public class Main { static Scanner sc = new Scanner ( System . in ) ; static int n = Integer . parseInt ( sc . next ( ) ) ; static int [ ] a = new int [ 100000 ] ; public static void main ( String [ ] args ) { int mid ; int q , key , sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = Integer . parseInt ( sc . next ( ) ) ; } q = Integer . parseInt ( sc . next ( ) ) ; for ( int i = 0 ; i < q ; i ++ ) { key = Integer . parseInt ( sc . next ( ) ) ; if ( binarySearch ( key ) ) sum ++ ; } System . out . println ( sum ) ; } static boolean binarySearch ( int key ) { int left = 0 ; int right = n ; int mid ; while ( left < right ) { mid = ( left + right ) / 2 ; if ( key == a [ mid ] ) return true ; if ( key > a [ mid ] ) left = mid + 1 ; else if ( key < a [ mid ] ) right = mid ; } return false ; } } +import java . util . * ; public class Main { Scanner sc = new Scanner ( System . in ) ; final int MOD = 1000000007 ; final int MAX = Integer . MAX_VALUE ; final long LMAX = Long . MAX_VALUE ; void doIt ( ) { int n = sc . nextInt ( ) ; String s = sc . next ( ) ; char [ ] c = s . toCharArray ( ) ; int len = n ; for ( int i = 1 ; i < n ; i ++ ) { if ( c [ i - 1 ] == c [ i ] ) len -- ; } System . out . println ( len ) ; } public static void main ( String [ ] args ) { int i = 1 ; new Main ( ) . doIt ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int min = sc . nextInt ( ) ; int ans = Integer . MIN_VALUE ; for ( int i = 0 ; i < n - 1 ; i ++ ) { int ans = Integer . MIN_VALUE ; int input = sc . nextInt ( ) ; ans = Math . max ( input - min , ans ) ; min = Math . min ( input , min ) ; } 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 K = sc . nextInt ( ) ; int count = 0 ; for ( int i = 0 ; i < N ; ++ i ) { int count = 0 ; int high = sc . nextInt ( ) ; if ( high >= K ) { count ++ ; } } System . out . println ( count ) ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; int index = - 1 ; String [ ] ss = { " SUN " , " MON " , " TUE " , " WED " , " THU " , " FRI " , " SAT " } ; for ( int i = 0 ; i < ss . length ; i ++ ) { int i = 0 ; if ( ss [ i ] . equals ( s ) ) { index = i ; } } System . out . println ( 7 - index ) ; } } +import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int [ ] num = new int [ 3 ] ; Scanner sc1 = new Scanner ( System . in ) ; int [ ] num = new int [ 3 ] ; num [ 0 ] = sc1 . nextInt ( ) ; num [ 1 ] = sc1 . nextInt ( ) ; num [ 2 ] = sc1 . nextInt ( ) ; int k = sc1 . nextInt ( ) ; Arrays . sort ( num ) ; for ( int i = 0 ; i < k ; i ++ ) { num [ 2 ] *= 2 ; } System . out . println ( num [ 0 ] + num [ 1 ] + num [ 2 ] ) ; sc1 . close ( ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { final String RESULT_YES = " Yes " ; final String RESULT_NO = " No " ; Scanner sc = new Scanner ( System . in ) ; int postOfficeCode = sc . nextInt ( ) ; int locationCode = sc . nextInt ( ) ; String val = sc . next ( ) ; boolean result = false ; if ( val . matches ( " [0-9] { " + postOfficeCode + " } -[0-9] { " + locationCode + " } " ) ) { result = true ; } if ( result ) { boolean result = false ; System . out . println ( RESULT_YES ) ; } else { System . out . println ( RESULT_NO ) ; } } } +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 ) { PrintWriter out = new PrintWriter ( outputStream ) ; InputStream inputStream = System . in ; OutputStream outputStream = System . out ; Scanner in = new Scanner ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; AHarmonyABC135 solver = new AHarmonyABC135 ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class AHarmonyABC135 { public void solve ( int testNumber , Scanner in , PrintWriter out ) { int a = in . nextInt ( ) ; int b = in . nextInt ( ) ; if ( a == b ) out . println ( 0 ) ; else if ( ( a + b ) % 2 == 1 ) out . println ( " IMPOSSIBLE " ) ; else out . println ( ( a + b ) / 2 ) ; } } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { int i = 1 ; Scanner sc = new Scanner ( System . in ) ; ArrayList < Integer > list = new ArrayList < > ( ) ; list . add ( sc . nextInt ( ) ) ; for ( int i = 1 ; i < 10001 ; i ++ ) { if ( list . get ( i - 1 ) == 0 ) { break ; } System . out . println ( " Case " + i + " : " + list . get ( i - 1 ) ) ; list . add ( sc . nextInt ( ) ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] arg ) { int i = 3 ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int c = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( PNcheck ( sc . nextInt ( ) ) ) c ++ ; } System . out . println ( c ) ; } static boolean PNcheck ( int n ) { if ( n == 2 ) return true ; if ( ( n % 2 ) == 0 ) return false ; for ( int i = 3 ; i * i <= n ; i = i + 2 ) { if ( ( n % i ) == 0 ) return false ; } return true ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = null ; try { sc = new Scanner ( System . in ) ; int leng = Integer . parseInt ( sc . nextLine ( ) ) ; int [ ] numBox = new int [ leng ] ; String line = sc . nextLine ( ) ; String [ ] list = line . split ( " " ) ; for ( int i = 0 ; i < numBox . length ; i ++ ) { numBox [ i ] = Integer . parseInt ( list [ i ] ) ; } for ( int i2 = 0 ; i2 < numBox . length ; i2 ++ ) { int work = numBox [ i2 ] ; int j = i2 - 1 ; while ( j >= 0 && numBox [ j ] > work ) { numBox [ j + 1 ] = numBox [ j ] ; j -- ; } numBox [ j + 1 ] = work ; for ( int i = 0 ; i < numBox . length ; i ++ ) { System . out . print ( numBox [ i ] ) ; if ( i != numBox . length - 1 ) { System . out . print ( " " ) ; } } System . out . println ( " " ) ; } } catch ( NumberFormatException e ) { System . out . println ( e ) ; } finally { if ( sc != null ) { sc . close ( ) ; } } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; char [ ] c = sc . next ( ) . toCharArray ( ) ; sc . close ( ) ; for ( int i = 0 ; i < c . length ; i ++ ) { char a = c [ i ] ; if ( i % 2 == 0 ) { if ( ! ( a == 'R' || a == 'U' || a == 'D' ) ) { char a = c [ i ] ; System . out . println ( " No " ) ; return ; } } else { if ( ! ( a == 'L' || a == 'U' || a == 'D' ) ) { System . out . println ( " No " ) ; return ; } } } System . out . println ( " Yes " ) ; } } +import java . util . ArrayList ; import java . util . List ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = fe ; Scanner sc = new Scanner ( System . in ) ; final int n = sc . nextInt ( ) ; List < Long > a = new ArrayList < Long > ( ) ; int fe = - 1 ; int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { a . add ( sc . nextLong ( ) ) ; if ( a . get ( i ) % 2 == 0 ) { fe = i ; } } sc . close ( ) ; long j = 0 ; for ( int i = fe ; i >= 0 ; i -- ) { j = a . get ( i ) ; while ( j % 2 == 0 ) { count ++ ; j /= 2 ; } } System . out . println ( count ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; PriorityQueue < Integer > queue = new PriorityQueue < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { int sum = 0 ; queue . add ( sc . nextInt ( ) ) ; } int sum = 0 ; for ( int i = 0 ; i < n - 1 ; i ++ ) { sum += queue . poll ( ) ; } System . out . println ( queue . poll ( ) < sum ? " Yes " : " No " ) ; } } +import java . math . BigInteger ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { BigInteger MAX = new BigInteger ( " 1000000000000000000 " ) ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; BigInteger [ ] s = new BigInteger [ n ] ; BigInteger ans = BigInteger . ONE ; for ( int i = 0 ; i < n ; i ++ ) { int i = 0 ; s [ i ] = sc . nextBigInteger ( ) ; if ( s [ i ] . compareTo ( BigInteger . ZERO ) == 0 ) { System . out . println ( 0 ) ; System . exit ( 0 ) ; } } for ( int i = 0 ; i < n ; i ++ ) { ans = ans . multiply ( s [ i ] ) ; if ( ans . compareTo ( MAX ) == 1 ) { System . out . println ( - 1 ) ; System . exit ( 0 ) ; } } System . out . println ( ans ) ; } } +import java . util . * ; class Main { Scanner sc ; void calc ( ) { sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; if ( s . charAt ( 2 ) == s . charAt ( 3 ) && s . charAt ( 4 ) == s . charAt ( 5 ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } public static void main ( String [ ] args ) { new Main ( ) . calc ( ) ; } } +import java . io . InputStream ; import java . io . PrintStream ; import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { solve ( System . in , System . out ) ; } static void solve ( InputStream is , PrintStream os ) { Scanner scan = new Scanner ( is ) ; long X = scan . nextLong ( ) ; long depo = 100 ; int ans = 0 ; while ( X > depo ) { int ans = 0 ; depo *= 1.01 ; ans ++ ; } os . println ( ans ) ; } } +import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . io . IOException ; public class Main { public static void main ( String [ ] args ) throws IOException { int i = 0 ; BufferedReader in = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String [ ] str = in . readLine ( ) . split ( " " ) ; int n = Integer . parseInt ( str [ 0 ] ) ; int d = Integer . parseInt ( str [ 1 ] ) ; int [ ] [ ] p = new int [ n ] [ d ] ; for ( int i = 0 ; i < n ; i ++ ) { str = in . readLine ( ) . split ( " " ) ; for ( int j = 0 ; j < d ; j ++ ) { p [ i ] [ j ] = Integer . parseInt ( str [ j ] ) ; } } int count = 0 ; for ( int i = 0 ; i < n ; ++ i ) { for ( int j = i + 1 ; j < n ; ++ j ) { if ( f ( p [ i ] , p [ j ] , d ) ) ++ count ; } } System . out . println ( count ) ; } private static boolean f ( int [ ] p , int [ ] p2 , int n ) { int sum = 0 ; for ( int i = 0 ; i < n ; ++ i ) sum += ( p [ i ] - p2 [ i ] ) * ( p [ i ] - p2 [ i ] ) ; return Math . abs ( Math . pow ( ( int ) Math . sqrt ( sum ) , 2 ) - sum ) < 0.001 ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int count = 0 ; Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int yoke = 0 ; int count = 0 ; for ( int i = 0 ; i < 3 ; i ++ ) { count += a % 10 ; a -= a % 10 ; a /= 10 ; } System . out . println ( count ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { int e = 0 ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int m = sc . nextInt ( ) ; int [ ] [ ] a = new int [ n ] [ m ] ; int [ ] b = new int [ m ] ; for ( int i = 0 ; i < n ; i ++ ) { for ( int s = 0 ; s < m ; s ++ ) { int A = sc . nextInt ( ) ; a [ i ] [ s ] = A ; } } for ( int q = 0 ; q < m ; q ++ ) { int B = sc . nextInt ( ) ; b [ q ] = B ; } int y ; for ( int w = 0 ; w < n ; w ++ ) { y = 0 ; for ( int e = 0 ; e < m ; e ++ ) { y += a [ w ] [ e ] * b [ e ] ; } System . out . println ( y ) ; } sc . close ( ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws IOException { String [ ] s ; BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int a , b , w ; String str ; String [ ] s ; str = br . readLine ( ) ; while ( str != null ) { StringBuilder out = new StringBuilder ( ) ; s = str . split ( " " ) ; a = Integer . parseInt ( s [ 0 ] ) ; b = Integer . parseInt ( s [ 1 ] ) ; w = a + b ; out . append ( w ) ; System . out . println ( out . length ( ) ) ; str = br . readLine ( ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int c = 1 ; while ( true ) { int c = 1 ; int a = sc . nextInt ( ) ; if ( a != 0 ) System . out . println ( " Case " + c + " : " + a ) ; else break ; c = c + 1 ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int h = scanner . nextInt ( ) ; int w = scanner . nextInt ( ) ; while ( h + w > 0 ) { int j = 0 ; for ( int i = 0 ; i < h ; i ++ ) { for ( int j = 0 ; j < w ; j ++ ) { if ( j == 0 || j == w - 1 || i == 0 || i == h - 1 ) System . out . print ( " # " ) ; else System . out . print ( " . " ) ; } System . out . println ( ) ; } System . out . println ( ) ; h = scanner . nextInt ( ) ; w = scanner . nextInt ( ) ; } } } +public class Main { protected static String calc ( String input ) { final int data = Integer . parseInt ( input ) ; StringBuilder sb = new StringBuilder ( ) ; for ( int i = 1 ; i <= data ; i ++ ) { if ( check ( i ) ) { sb . append ( ' ' ) ; sb . append ( i ) ; } } return sb . toString ( ) ; } static boolean check ( int x ) { if ( x % 3 == 0 ) { return true ; } return check0 ( x ) ; } static boolean check0 ( int x ) { java . util . Scanner s = null ; if ( x % 10 == 3 ) { return true ; } x /= 10 ; if ( x > 0 ) { return check0 ( x ) ; } return false ; } public static void main ( String [ ] args ) { final String line = readLine ( ) ; System . out . println ( calc ( line ) ) ; } private static String readLine ( ) { java . util . Scanner s = null ; try { s = new java . util . Scanner ( System . in ) ; return s . nextLine ( ) ; } finally { if ( s != null ) { s . close ( ) ; } } } } +public class Main { public static void main ( String [ ] args ) { int r = scan . nextInt ( ) ; java . util . Scanner scan = new java . util . Scanner ( System . in ) ; int W = scan . nextInt ( ) ; int H = scan . nextInt ( ) ; int x = scan . nextInt ( ) ; int y = scan . nextInt ( ) ; int r = scan . nextInt ( ) ; if ( - 100 <= x && x <= 100 && - 100 <= y && y <= 100 && 0 < r && r <= 100 && 0 < W && W <= 100 && 0 < H && H <= 100 ) { if ( W >= ( x + r ) && H >= ( y + r ) && ( y + r ) > 0 && ( x + r ) > 0 ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int A1 = 0 , A2 = 0 , A3 = 0 , result = 0 ; Scanner input = new Scanner ( System . in ) ; int A1 = 0 , A2 = 0 , A3 = 0 , result = 0 ; A1 = input . nextInt ( ) ; A2 = input . nextInt ( ) ; A3 = input . nextInt ( ) ; if ( 1 <= A1 && A1 <= 13 && 1 <= A2 && A2 <= 13 && 1 <= A3 && A3 <= 13 ) { if ( A1 + A2 + A3 == 22 || A1 + A2 + A3 > 22 ) { System . out . println ( " bust " ) ; } else { System . out . println ( " win " ) ; } } else { } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int A = scan . nextInt ( ) ; int B = scan . nextInt ( ) ; int AB = scan . nextInt ( ) ; int x = scan . nextInt ( ) ; int y = scan . nextInt ( ) ; int ans = 1000000000 ; for ( int i = 0 ; i < 2 * ( x + y ) + 1 ; i ++ ) { int i = 0 ; int ABpizza = i ; int Apizza = Math . max ( 0 , x - ( i / 2 ) ) ; int Bpizza = Math . max ( 0 , y - ( i / 2 ) ) ; ans = Math . min ( ans , ( ABpizza * AB ) + ( Apizza * A ) + ( Bpizza * B ) ) ; } System . out . println ( ans ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { try ( Scanner in = new Scanner ( System . in ) ) { String s = in . next ( ) ; int count = 0 ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { int i = 0 ; if ( s . charAt ( i ) == '1' ) { count ++ ; } } System . out . println ( count ) ; } } } +import java . io . * ; import java . util . * ; public class Main { static long mod = ( long ) 1e9 + 7 ; public static void main ( String [ ] args ) throws IOException { Reader . init ( System . in ) ; PrintWriter out = new PrintWriter ( System . out ) ; int n = Reader . nextInt ( ) , x = Reader . nextInt ( ) , t = Reader . nextInt ( ) ; long ans = ( n + x - 1 ) / x ; ans *= t ; out . println ( ans ) ; out . flush ( ) ; } } class Reader { static BufferedReader reader ; static StringTokenizer tokenizer ; static void init ( ) throws IOException { reader = new BufferedReader ( new FileReader ( " C: \\ Users \\ samee \\ Desktop \\ GRE prep \\ confusion.txt " ) ) ; tokenizer = new StringTokenizer ( " " ) ; } static void init ( InputStream input ) { reader = new BufferedReader ( new InputStreamReader ( input ) ) ; tokenizer = new StringTokenizer ( " " ) ; } static String nextLine ( ) throws IOException { return reader . readLine ( ) ; } static String next ( ) throws IOException { while ( ! tokenizer . hasMoreTokens ( ) ) { tokenizer = new StringTokenizer ( reader . readLine ( ) ) ; } return tokenizer . nextToken ( ) ; } static int nextInt ( ) throws IOException { return Integer . parseInt ( next ( ) ) ; } static long nextLong ( ) throws IOException { return Long . parseLong ( next ( ) ) ; } static double nextDouble ( ) throws IOException { return Double . parseDouble ( next ( ) ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { char ch = 'a' ; Scanner scan = new Scanner ( System . in ) ; int [ ] chars = new int [ 256 ] ; for ( int i = 0 ; i < 256 ; i ++ ) chars [ i ] = 0 ; while ( scan . hasNextLine ( ) ) { String line = scan . nextLine ( ) ; for ( int i = 0 ; i < line . length ( ) ; i ++ ) { char ch = Character . toLowerCase ( line . charAt ( i ) ) ; if ( ch >= 'a' && ch <= 'z' ) chars [ ch ] ++ ; } } for ( char ch = 'a' ; ch <= 'z' ; ch ++ ) System . out . println ( ch + " : " + chars [ ch ] ) ; } } +import java . io . IOException ; import java . util . NoSuchElementException ; import java . io . BufferedReader ; import java . io . InputStream ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws IOException { try ( BufferedReader reader = new BufferedReader ( new InputStreamReader ( System . in ) ) ) { final String s = reader . readLine ( ) ; int atA = 200001 ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( s . charAt ( i ) == 'A' ) { atA = i ; break ; } } int atZ = - 1 ; for ( int i = s . length ( ) - 1 ; 0 <= i ; i -- ) { if ( s . charAt ( i ) == 'Z' ) { int i = s . length ( ) - 1 ; atZ = i ; break ; } } System . out . println ( atZ - atA + 1 ) ; } } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; br . readLine ( ) ; int count = 0 ; String str ; while ( ( str = br . readLine ( ) ) != null ) { if ( isPrime ( Long . valueOf ( str ) ) ) count ++ ; } System . out . println ( count ) ; } private static boolean isPrime ( long n ) { String str ; if ( n < 2 ) return false ; else if ( n == 2 ) return true ; if ( n % 2 == 0 ) return false ; for ( long i = 3 ; i <= n / i ; i += 2 ) if ( n % i == 0 ) return false ; return true ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] Args ) { Scanner sc = new Scanner ( System . in ) ; String [ ] s = new String [ 3 ] ; for ( int i = 0 ; i < 3 ; i ++ ) { s [ i ] = sc . next ( ) ; } int p = 0 ; while ( s [ p ] . length ( ) != 0 ) { int p = 0 ; int np = s [ p ] . charAt ( 0 ) - 'a' ; s [ p ] = s [ p ] . substring ( 1 , s [ p ] . length ( ) ) ; p = np ; } System . out . println ( ( char ) ( 'A' + p ) ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { int empty = a - b ; Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int c = sc . nextInt ( ) ; int empty = a - b ; if ( c - empty < 0 ) { System . out . println ( 0 ) ; } else { System . out . println ( c - empty ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { boolean flag = false ; Scanner sc = new Scanner ( System . in ) ; Integer x = sc . nextInt ( ) ; String y = sc . next ( ) ; if ( x % 2 == 0 ) { String firstHalf = y . substring ( 0 , y . length ( ) / 2 ) ; String secondHalf = y . substring ( y . length ( ) / 2 , y . length ( ) ) ; if ( firstHalf . equals ( secondHalf ) ) { String y = sc . next ( ) ; System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } else { System . out . println ( " No " ) ; } } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long N = sc . nextLong ( ) - 1 ; List < Integer > list = new ArrayList < > ( ) ; while ( N > 25 ) { list . add ( ( int ) ( N % 26 ) ) ; N = N / 26 - 1 ; } list . add ( ( int ) N ) ; char [ ] alphabet = " abcdefghijklmnopqrstuvwxyz " . toCharArray ( ) ; String ans = " " ; for ( int i = 0 ; i < list . size ( ) ; i ++ ) { int i = 0 ; int index = list . get ( list . size ( ) - i - 1 ) ; ans += alphabet [ index ] ; } System . out . println ( ans ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int N = scan . nextInt ( ) ; boolean flag = false ; for ( int i = 0 ; i <= 25 ; i ++ ) { for ( int j = 0 ; j <= 14 ; j ++ ) { int a = 7 * j + i * 4 ; if ( N == a ) { flag = true ; } } } if ( flag ) { System . out . println ( " Yes " ) ; } else { int j = 0 ; System . out . println ( " No " ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { final Scanner sc = new Scanner ( System . in ) ; final int A = sc . nextInt ( ) ; final int B = sc . nextInt ( ) ; final int C = sc . nextInt ( ) ; final int X = sc . nextInt ( ) ; final int Y = sc . nextInt ( ) ; final int price = Math . min ( C * 2 , A + B ) * Math . min ( X , Y ) ; final int nokori = Math . max ( X , Y ) - Math . min ( X , Y ) ; if ( X > Y ) { final int nokori = Math . max ( X , Y ) - Math . min ( X , Y ) ; System . out . println ( price + Math . min ( nokori * A , nokori * C * 2 ) ) ; } else { System . out . println ( price + Math . min ( nokori * B , nokori * C * 2 ) ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; String word ; String [ ] sen = new String [ 1000 ] ; int i = 0 ; word = scan . next ( ) ; while ( true ) { sen [ i ] = scan . next ( ) ; if ( sen [ i ] . equals ( " END_OF_TEXT " ) ) break ; i ++ ; } int ans = 0 ; int num = word . length ( ) ; ; for ( int j = 0 ; j < i + 1 ; j ++ ) { int j = 0 ; if ( sen [ j ] . equalsIgnoreCase ( word ) ) ans ++ ; } System . out . println ( ans ) ; return ; } } +import java . io . * ; import java . util . ArrayDeque ; import java . util . ArrayList ; import java . util . Arrays ; import java . util . Comparator ; import java . util . Scanner ; public class Main { static String a ; public static void main ( String [ ] args ) { int j = 2 ; Scanner stdIn = new Scanner ( System . in ) ; int n = stdIn . nextInt ( ) ; int count = 0 ; IN : for ( int i = 0 ; i < n ; i ++ ) { int x = stdIn . nextInt ( ) ; for ( int j = 2 ; j * j <= x ; j ++ ) { if ( x % j == 0 ) continue IN ; } count ++ ; } System . out . println ( count ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; int L = sc . nextInt ( ) ; int R = sc . nextInt ( ) ; int min = 2018 ; if ( R - L > 2019 ) { System . out . print ( 0 ) ; } else { int LMod = Math . floorMod ( L , 2019 ) ; int RMod = Math . floorMod ( R , 2019 ) ; if ( LMod < RMod ) { for ( int i = LMod ; i < RMod ; i ++ ) { for ( int j = i + 1 ; j <= RMod ; j ++ ) { int surPlus = ( i * j ) % 2019 ; if ( surPlus < min ) { int surPlus = ( i * j ) % 2019 ; min = surPlus ; } } } System . out . print ( min ) ; } else { System . out . print ( 0 ) ; } } } } +import java . io . * ; import java . util . * ; import java . math . * ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; PrintWriter pw = new PrintWriter ( System . out ) ; int s = sc . nextInt ( ) ; int w = sc . nextInt ( ) ; if ( s > w ) System . out . println ( " safe " ) ; else System . out . println ( " unsafe " ) ; } static class Scanner { StringTokenizer st ; BufferedReader br ; public Scanner ( InputStream s ) { br = new BufferedReader ( new InputStreamReader ( s ) ) ; } public Scanner ( String file ) throws FileNotFoundException { br = new BufferedReader ( new FileReader ( file ) ) ; } public String next ( ) throws IOException { while ( st == null || ! st . hasMoreTokens ( ) ) st = new StringTokenizer ( br . readLine ( ) ) ; return st . nextToken ( ) ; } public int nextInt ( ) throws IOException { return Integer . parseInt ( next ( ) ) ; } public long nextLong ( ) throws IOException { return Long . parseLong ( next ( ) ) ; } public String nextLine ( ) throws IOException { return br . readLine ( ) ; } public double nextDouble ( ) throws IOException { return Double . parseDouble ( next ( ) ) ; } public boolean ready ( ) throws IOException { return br . ready ( ) ; } public int [ ] nextArr ( int n ) throws IOException { int [ ] arr = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) arr [ i ] = nextInt ( ) ; return arr ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int M = sc . nextInt ( ) ; int X = sc . nextInt ( ) ; int [ ] A = new int [ M ] ; int left = 0 ; for ( int i = 0 ; i < M ; i ++ ) { int left = 0 ; if ( sc . nextInt ( ) < X ) { left ++ ; } } System . out . println ( Math . min ( left , M - left ) ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { int syusseki ; Scanner scanner = new Scanner ( System . in ) ; int n = scanner . nextInt ( ) ; int a ; int [ ] order = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { a = scanner . nextInt ( ) ; order [ a - 1 ] = i + 1 ; } for ( int syusseki : order ) { System . out . println ( syusseki ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { long n , c , b , a , mal = 0 , need , sum = 0 ; Scanner in = new Scanner ( System . in ) ; long n , c , b , a , mal = 0 , need , sum = 0 ; a = in . nextLong ( ) ; b = in . nextLong ( ) ; c = in . nextLong ( ) ; if ( a >= c ) { sum = a - c ; mal = b ; } else if ( a <= c ) { sum = c - a ; mal = b - sum ; if ( b <= sum ) { mal = 0 ; } if ( a <= c ) { sum = 0 ; } } System . out . println ( sum + " " + mal ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; String t = sc . next ( ) ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { String t = sc . next ( ) ; if ( s . equals ( t ) ) { System . out . println ( " Yes " ) ; return ; } s = s . charAt ( s . length ( ) - 1 ) + s . substring ( 0 , s . length ( ) - 1 ) ; } System . out . println ( " No " ) ; } } +import java . util . * ; public class Main { Scanner sc = new Scanner ( System . in ) ; int a , b , c , d , e , f , k , l , m , n , x , y , z ; int ans ; String [ ] S ; Main ( ) { n = sc . nextInt ( ) ; a = sc . nextInt ( ) ; b = sc . nextInt ( ) ; System . out . println ( Math . min ( a * n , b ) ) ; } public static void main ( String [ ] args ) { new Main ( ) ; } } +import java . io . * ; import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int A , B ; A = scan . nextInt ( ) ; B = scan . nextInt ( ) ; double tax8 = 0.08 ; double tax10 = 0.10 ; int price = - 1 ; for ( int i = 1 ; i <= 1000 ; i ++ ) { if ( ( int ) ( i * tax8 + i ) - i == A && ( int ) ( i * tax10 + i ) - i == B ) { int i = 1 ; price = i ; break ; } } System . out . println ( price ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String a = sc . next ( ) ; String b = sc . next ( ) ; int n = Integer . parseInt ( a + b ) ; boolean bl = false ; for ( int i = 1 ; i * i <= n ; i ++ ) { if ( i * i == n ) { int i = 1 ; bl = true ; break ; } } System . out . println ( bl == true ? " Yes " : " No " ) ; } } +import java . util . * ; public class Main { public static void main ( final String [ ] args ) { int result = 0 ; final Scanner sc = new Scanner ( System . in ) ; final int a = sc . nextInt ( ) ; final int b = sc . nextInt ( ) ; final int c = sc . nextInt ( ) ; final int k = sc . nextInt ( ) ; sc . close ( ) ; int result = 0 ; if ( a >= k ) { result = k ; } else if ( b >= k - a ) { result = a ; } else if ( c >= k - b - a ) { result = 2 * a + b - k ; } System . out . println ( result ) ; } } +import java . util . Scanner ; import java . util . ArrayList ; class Main { public static void main ( String [ ] args ) { Scanner scn = new Scanner ( System . in ) ; int s = scn . nextInt ( ) ; ArrayList < Integer > element = new ArrayList < Integer > ( ) ; for ( int i = 1 ; ; ) { if ( i == 1 ) { element . add ( s ) ; } else { if ( s % 2 == 1 ) { s = odd ( s ) ; } else { s = even ( s ) ; } if ( element . indexOf ( s ) == - 1 ) { element . add ( s ) ; } else { System . out . println ( i ) ; break ; } } i ++ ; } } public static int even ( int n ) { return n / 2 ; } public static int odd ( int n ) { int i = 1 ; return 3 * n + 1 ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int ans = 0 ; sc . close ( ) ; for ( int i = 1 ; i <= n ; i += 2 ) { if ( numYaku8 ( i ) ) ans += 1 ; } System . out . println ( ans ) ; } private static boolean numYaku8 ( int n ) { int yaku = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { int i = 1 ; if ( n % i == 0 ) yaku += 1 ; } if ( yaku == 8 ) return true ; return false ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int m , i , j , big , k ; int count = 0 ; Scanner in = new Scanner ( System . in ) ; int n = Integer . parseInt ( in . nextLine ( ) ) ; int [ ] array = new int [ n ] ; for ( m = 0 ; m < n ; m ++ ) array [ m ] = Integer . parseInt ( in . next ( ) ) ; for ( i = 0 ; i < n - 1 ; i ++ ) { for ( j = n - 1 ; j >= i + 1 ; j -- ) { int [ ] array = new int [ n ] ; if ( array [ j ] < array [ j - 1 ] ) { big = array [ j - 1 ] ; array [ j - 1 ] = array [ j ] ; array [ j ] = big ; count ++ ; } } } for ( k = 0 ; k < n - 1 ; k ++ ) { System . out . print ( array [ k ] + " " ) ; } if ( k == ( n - 1 ) ) System . out . println ( array [ k ] ) ; System . out . println ( count ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int [ ] time = new int [ 5 ] , wait = new int [ 5 ] ; int total = 0 ; for ( int i = 0 ; i < 5 ; i ++ ) { time [ i ] = sc . nextInt ( ) ; wait [ i ] = ( 10 - time [ i ] % 10 ) % 10 ; total += time [ i ] + wait [ i ] ; } int idx = maxIdx ( wait ) ; total -= wait [ idx ] ; System . out . println ( total ) ; } public static int maxIdx ( int [ ] wait ) { int i = 1 ; int idx = 0 , data = wait [ 0 ] ; for ( int i = 1 ; i < 5 ; i ++ ) { if ( data < wait [ i ] ) { data = wait [ i ] ; idx = i ; } } return idx ; } } +import java . io . OutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . PrintWriter ; import java . util . Arrays ; 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 ) ; AStationAndBus solver = new AStationAndBus ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class AStationAndBus { public void solve ( int testNumber , Scanner in , PrintWriter out ) { PrintWriter out = new PrintWriter ( outputStream ) ; char [ ] c = in . next ( ) . toCharArray ( ) ; Arrays . sort ( c ) ; out . println ( c [ 0 ] == c [ c . length - 1 ] ? " No " : " Yes " ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner s = new Scanner ( System . in ) ; int yusha = s . nextInt ( ) ; long [ ] monsters = new long [ yusha + 1 ] ; long [ ] strength = new long [ yusha ] ; long count = 0 ; for ( int i = 0 ; i < yusha + 1 ; i ++ ) { monsters [ i ] = s . nextInt ( ) ; } for ( int i = 0 ; i < yusha ; i ++ ) { strength [ i ] = s . nextInt ( ) ; } for ( int i = 0 ; i < yusha ; i ++ ) { for ( int j = 0 ; j < 2 ; j ++ ) { int j = 0 ; if ( monsters [ i + j ] >= strength [ i ] ) { count += strength [ i ] ; monsters [ i + j ] = monsters [ i + j ] - strength [ i ] ; strength [ i ] = 0 ; } else { count += monsters [ j + i ] ; strength [ i ] = strength [ i ] - monsters [ i + j ] ; monsters [ i + j ] = 0 ; } } } System . out . println ( count ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . nextLine ( ) ; long k = sc . nextLong ( ) ; int ans = 0 ; int n = 0 ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { int i = 0 ; n = s . charAt ( i ) - '0' ; k -- ; if ( k == 0 || n > 1 ) break ; } System . out . println ( n ) ; sc . close ( ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; String s = sc . next ( ) ; char before = '0' ; int count = 0 ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { char c = s . charAt ( i ) ; char c = s . charAt ( i ) ; if ( c != before ) { before = c ; count ++ ; } } System . out . println ( count ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n , m , l ; n = sc . nextInt ( ) ; m = sc . nextInt ( ) ; l = sc . nextInt ( ) ; long [ ] [ ] A = new long [ n ] [ m ] ; long [ ] [ ] B = new long [ m ] [ l ] ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < m ; j ++ ) { A [ i ] [ j ] = sc . nextLong ( ) ; } } for ( int i = 0 ; i < m ; i ++ ) { for ( int j = 0 ; j < l ; j ++ ) { int k = 0 ; B [ i ] [ j ] = sc . nextLong ( ) ; } } for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < l ; j ++ ) { long sum = 0 ; for ( int k = 0 ; k < m ; k ++ ) { sum = sum + A [ i ] [ k ] * B [ k ] [ j ] ; } if ( j != l - 1 ) { System . out . print ( sum + " " ) ; } else System . out . println ( sum ) ; } } } } +import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int n = scan . nextInt ( ) ; int [ ] a = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = scan . nextInt ( ) ; } scan . close ( ) ; Arrays . sort ( a ) ; int check = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { if ( i != j ) { if ( a [ i ] == a [ j ] ) { int j = i + 1 ; check = 1 ; break ; } else { break ; } } } if ( check == 1 ) break ; } System . out . println ( ( check == 1 ) ? " NO " : " YES " ) ; } } +import java . util . Scanner ; public class Main { static long max = Long . MIN_VALUE ; static long [ ] C ; static int [ ] P ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; String string = sc . next ( ) ; if ( N % 2 == 1 ) { System . out . println ( " No " ) ; } else { if ( string . substring ( 0 , N / 2 ) . equals ( string . substring ( N / 2 , N ) ) ) { String string = sc . next ( ) ; System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { String ans = " " ; try ( Scanner sc = new Scanner ( System . in ) ) { int x = Integer . parseInt ( sc . next ( ) ) ; int y = Integer . parseInt ( sc . next ( ) ) ; String ans = " " ; if ( y % 2 != 0 ) { ans = " No " ; } else { if ( ( y / 2 ) >= x && x >= ( ( y / 4 ) + ( y % 4 / 2 ) ) ) { ans = " Yes " ; } else { ans = " No " ; } } System . out . println ( ans ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int [ ] a = new int [ 2 ] ; while ( true ) { int [ ] a = new int [ 2 ] ; a [ 0 ] = sc . nextInt ( ) ; a [ 1 ] = sc . nextInt ( ) ; if ( a [ 0 ] == 0 && a [ 1 ] == 0 ) break ; Arrays . sort ( a ) ; System . out . println ( a [ 0 ] + " " + a [ 1 ] ) ; } } } +import java . io . * ; import java . util . StringTokenizer ; public class Main { public static void main ( String [ ] args ) throws Exception { PrintWriter prnt = new PrintWriter ( System . out ) ; StringTokenizer st ; BufferedReader read = new BufferedReader ( new InputStreamReader ( System . in ) ) ; PrintWriter prnt = new PrintWriter ( System . out ) ; String num = read . readLine ( ) ; if ( num . charAt ( 0 ) == '7' ) { prnt . println ( " Yes " ) ; } else if ( num . charAt ( 1 ) == '7' ) { prnt . println ( " Yes " ) ; } else if ( num . charAt ( 2 ) == '7' ) { prnt . println ( " Yes " ) ; } else { prnt . println ( " No " ) ; } prnt . close ( ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader reader = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String str = reader . readLine ( ) ; int n = Integer . parseInt ( str ) ; long sum = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { int i = 1 ; if ( i % 3 == 0 || i % 5 == 0 ) continue ; sum += i ; } System . out . print ( sum ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { boolean sw = false ; int answer = 0 ; List < Integer > a = new ArrayList < Integer > ( ) ; int s ; int n = 1 ; int ai = 0 ; int count = 0 ; Scanner sc = new Scanner ( System . in ) ; s = sc . nextInt ( ) ; while ( sw == false ) { if ( count == 0 ) { a . add ( s ) ; count ++ ; } else { n = a . get ( count - 1 ) ; if ( n % 2 == 0 ) { int i = 0 ; ai = n / 2 ; a . add ( ai ) ; } else { ai = 3 * n + 1 ; a . add ( ai ) ; } count ++ ; } for ( int i = 0 ; i < count - 1 ; i ++ ) { if ( a . get ( i ) == ai ) { answer = a . size ( ) ; sw = true ; } } } System . out . println ( answer ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; int h = sc . nextInt ( ) ; int n = sc . nextInt ( ) ; int [ ] a = new int [ n ] ; int attack = 0 ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = sc . nextInt ( ) ; attack += a [ i ] ; } if ( h <= attack ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int n = 0 ; for ( int i = 0 ; i < ( b - a + 1 ) ; i ++ ) { int i = 0 ; String [ ] s = String . valueOf ( a + i ) . split ( " " ) ; String t = s [ 4 ] + s [ 3 ] + s [ 2 ] + s [ 1 ] + s [ 0 ] ; if ( String . valueOf ( a + i ) . equals ( t ) ) n ++ ; } System . out . println ( n ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int j = 0 ; Scanner scan = new Scanner ( System . in ) ; int codeNum = scan . nextInt ( ) ; int num = scan . nextInt ( ) ; int C = scan . nextInt ( ) ; int [ ] B = new int [ num ] ; for ( int i = 0 ; i < B . length ; i ++ ) { B [ i ] = scan . nextInt ( ) ; } int [ ] [ ] A = new int [ codeNum ] [ num ] ; for ( int i = 0 ; i < codeNum ; i ++ ) { for ( int j = 0 ; j < num ; j ++ ) { A [ i ] [ j ] = scan . nextInt ( ) ; } } int sum = 0 ; int count = 0 ; for ( int i = 0 ; i < A . length ; i ++ ) { for ( int j = 0 ; j < num ; j ++ ) { sum += B [ j ] * A [ i ] [ j ] ; } if ( sum + C > 0 ) { count ++ ; } sum = 0 ; } System . out . println ( count ) ; scan . close ( ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int D = sc . nextInt ( ) ; int N = sc . nextInt ( ) ; int base = 1 ; for ( int i = 0 ; i < D ; i ++ ) { base *= 100 ; } if ( N % 100 == 0 ) { System . out . println ( base * ( N + 1 ) ) ; } else { int base = 1 ; System . out . println ( base * N ) ; } } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws Exception { int in2 = Integer . valueOf ( se [ 1 ] ) ; BufferedReader stdIn = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String s ; int inCnt = 0 ; while ( ( s = stdIn . readLine ( ) ) != null ) { String [ ] se = s . split ( " " ) ; int in1 = Integer . valueOf ( se [ 0 ] ) ; int in2 = Integer . valueOf ( se [ 1 ] ) ; if ( in1 == 0 && in2 == 0 ) break ; doMain ( ++ inCnt , in1 , in2 ) ; } System . exit ( 0 ) ; } private static void doMain ( int inCnt , int in1 , int in2 ) { if ( in1 < in2 ) System . out . println ( in1 + " " + in2 ) ; else System . out . println ( in2 + " " + in1 ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { char x = ( char ) ( 'a' + i ) ; Scanner sc = new Scanner ( System . in ) ; String str = null ; int [ ] count = new int [ 26 ] ; while ( sc . hasNext ( ) ) { str = sc . nextLine ( ) ; str = str . toLowerCase ( ) ; char [ ] ch = str . toCharArray ( ) ; for ( int i = 0 ; i < ch . length ; i ++ ) { if ( Character . isAlphabetic ( ch [ i ] ) ) { int x = ch [ i ] - 'a' ; count [ x ] ++ ; } } } for ( int i = 0 ; i < count . length ; i ++ ) { char x = ( char ) ( 'a' + i ) ; System . out . print ( x + " : " ) ; System . out . println ( count [ i ] ) ; } } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { int d = sc . nextInt ( ) ; Scanner sc = new Scanner ( System . in ) ; String a = sc . next ( ) ; String b = sc . next ( ) ; int c = sc . nextInt ( ) ; int d = sc . nextInt ( ) ; String j = sc . next ( ) ; if ( a . equals ( j ) ) { c = c - 1 ; } else if ( b . equals ( j ) ) { d = d - 1 ; } System . out . println ( c ) ; System . out . println ( d ) ; } } +import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner s = new Scanner ( System . in ) ; int n = s . nextInt ( ) ; int m = s . nextInt ( ) ; int x = s . nextInt ( ) ; char [ ] road = new char [ n ] ; int countFromStart = 0 ; int countToEnd = 0 ; int countC = 0 ; Arrays . fill ( road , 'a' ) ; road [ x ] = 'x' ; for ( int i = 0 ; i < m ; i ++ ) { int tmp = s . nextInt ( ) ; road [ tmp ] = 'c' ; } for ( int j = 0 ; j < x ; j ++ ) { if ( road [ j ] == 'c' ) { ++ countFromStart ; } } for ( int k = x + 1 ; k < n ; k ++ ) { if ( road [ k ] == 'c' ) { ++ countToEnd ; } } if ( countToEnd > countFromStart ) { for ( int p = 0 ; p < x ; p ++ ) { int q = x + 1 ; if ( road [ p ] == 'c' ) ++ countC ; } } else { for ( int q = x + 1 ; q < n ; q ++ ) { if ( road [ q ] == 'c' ) { ++ countC ; } } } System . out . println ( countC ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) { try ( BufferedReader in = new BufferedReader ( new InputStreamReader ( System . in ) ) ) { int taro = 0 ; int hanako = 0 ; int n = Integer . parseInt ( in . readLine ( ) ) ; for ( int i = 0 ; i < n ; i ++ ) { int hanako = 0 ; String [ ] arr = in . readLine ( ) . split ( " " ) ; int cmp = arr [ 0 ] . compareTo ( arr [ 1 ] ) ; if ( cmp > 0 ) { taro += 3 ; } else if ( cmp == 0 ) { taro ++ ; hanako ++ ; } else { hanako += 3 ; } } System . out . println ( taro + " " + hanako ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String str = br . readLine ( ) ; char [ ] strArray = str . toCharArray ( ) ; for ( int i = 0 ; i < strArray . length ; i ++ ) { if ( Character . isUpperCase ( strArray [ i ] ) ) { strArray [ i ] = Character . toLowerCase ( strArray [ i ] ) ; } else if ( Character . isLowerCase ( strArray [ i ] ) ) { strArray [ i ] = Character . toUpperCase ( strArray [ i ] ) ; } else { int i = 0 ; strArray [ i ] = strArray [ i ] ; } } for ( int i = 0 ; i < strArray . length - 1 ; i ++ ) { System . out . print ( strArray [ i ] ) ; } System . out . println ( strArray [ strArray . length - 1 ] ) ; } } +import java . io . IOException ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws IOException { int W = sc . nextInt ( ) ; Scanner sc = new Scanner ( System . in ) ; while ( true ) { int H = sc . nextInt ( ) ; int W = sc . nextInt ( ) ; if ( H == 0 && W == 0 ) { break ; } for ( int i = 0 ; i < H ; i ++ ) { for ( int j = 0 ; j < W ; j ++ ) { System . out . print ( " # " ) ; } System . out . println ( ) ; } System . out . println ( ) ; } sc . close ( ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader input = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String first_line = input . readLine ( ) ; String [ ] array_of_li_col = first_line . split ( " " ) ; int line = Integer . parseInt ( array_of_li_col [ 0 ] ) ; int column = Integer . parseInt ( array_of_li_col [ 1 ] ) ; int [ ] [ ] matrix_array_A = new int [ line ] [ column ] ; int [ ] vector_array_b = new int [ column ] ; for ( int line_A = 0 ; line_A < line ; line_A ++ ) { String elements_A = input . readLine ( ) ; String [ ] elements_A_array = elements_A . split ( " " ) ; for ( int column_A = 0 ; column_A < column ; column_A ++ ) { int elements_A_num = Integer . parseInt ( elements_A_array [ column_A ] ) ; matrix_array_A [ line_A ] [ column_A ] = elements_A_num ; } } for ( int column_b = 0 ; column_b < column ; column_b ++ ) { String elements_b = input . readLine ( ) ; int elements_b_num = Integer . parseInt ( elements_b ) ; vector_array_b [ column_b ] = elements_b_num ; } int elements_Ci = 0 ; for ( int line_A = 0 ; line_A < line ; line_A ++ ) { int column_A = 0 ; for ( int column_A = 0 ; column_A < column ; column_A ++ ) { elements_Ci += matrix_array_A [ line_A ] [ column_A ] * vector_array_b [ column_A ] ; } System . out . println ( elements_Ci ) ; elements_Ci = 0 ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long n = sc . nextLong ( ) ; if ( n < 10 ) { System . out . println ( n ) ; } else if ( n < 100 ) { System . out . println ( 9 ) ; } else if ( n < 1000 ) { System . out . println ( 9 + n - 99 ) ; } else if ( n < 10000 ) { long n = sc . nextLong ( ) ; System . out . println ( 909 ) ; } else if ( n < 100000 ) { System . out . println ( 909 + n - 9999 ) ; } else { System . out . println ( 90909 ) ; } sc . close ( ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long l = sc . nextInt ( ) ; long r = sc . nextInt ( ) ; long min = l * ( l + 1 ) % 2019 ; if ( ( l % 2019 == 0 ) || ( r % 2019 == 0 ) ) { System . out . println ( 0 ) ; } else if ( ( l / 2019 ) != ( r / 2019 ) ) { System . out . println ( 0 ) ; } else if ( ( l / 2019 ) == ( r / 2019 ) ) { for ( long i = l ; i < r ; i ++ ) { for ( long j = i + 1 ; j < r + 1 ; j ++ ) { long j = i + 1 ; min = Math . min ( min , i * j % 2019 ) ; } } System . out . println ( min ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] arr = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) arr [ i ] = sc . nextInt ( ) ; int [ ] leftSum = new int [ n ] ; leftSum [ 0 ] = arr [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) leftSum [ i ] = leftSum [ i - 1 ] + arr [ i ] ; int [ ] rightSum = new int [ n ] ; rightSum [ n - 1 ] = arr [ n - 1 ] ; for ( int i = n - 2 ; i >= 0 ; i -- ) { int i = 0 ; rightSum [ i ] += rightSum [ i + 1 ] + arr [ i ] ; } int min = Integer . MAX_VALUE ; for ( int i = 0 ; i < n - 1 ; i ++ ) min = Math . min ( min , Math . abs ( leftSum [ i ] - rightSum [ i + 1 ] ) ) ; System . out . println ( min ) ; } } +import java . io . * ; import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; PrintWriter out = new PrintWriter ( System . out ) ; String [ ] ss = sc . next ( ) . split ( " [^ACGT] " ) ; if ( ss . length == 0 ) { out . println ( " 0 " ) ; } else { Integer [ ] a = new Integer [ ss . length ] ; for ( int i = 0 ; i < ss . length ; i ++ ) { int i = 0 ; a [ i ] = ss [ i ] . length ( ) ; } Arrays . sort ( a , Collections . reverseOrder ( ) ) ; out . println ( a [ 0 ] ) ; } out . flush ( ) ; } } +import java . util . ArrayList ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner s = new Scanner ( System . in ) ; int a = s . nextInt ( ) ; int b = s . nextInt ( ) ; int c = s . nextInt ( ) ; int d = s . nextInt ( ) ; int ans1 = 0 , ans2 = 0 ; if ( a % d == 0 ) { ans1 = a / d ; } else { ans1 = a / d + 1 ; } if ( c % b == 0 ) { ans2 = c / b ; } else { ans2 = c / b + 1 ; } if ( ans1 >= ans2 ) { int ans1 = 0 , ans2 = 0 ; System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws NumberFormatException , IOException { int j = 0 ; BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int [ ] input = new int [ 10 ] ; boolean [ ] checked = new boolean [ 10 ] ; for ( int i = 0 ; i < 10 ; i ++ ) { input [ i ] = Integer . parseInt ( br . readLine ( ) ) ; checked [ i ] = false ; } for ( int i = 0 ; i < 3 ; i ++ ) { int maxIndex = - 1 ; int max = - 1 ; for ( int j = 0 ; j < 10 ; j ++ ) { if ( input [ j ] > max && checked [ j ] == false ) { max = input [ j ] ; maxIndex = j ; } } checked [ maxIndex ] = true ; System . out . println ( input [ maxIndex ] ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int j = 0 ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int yen = sc . nextInt ( ) ; int s = yen / 1000 - n ; for ( int i = 0 ; i <= Math . min ( s / 9 , n ) ; i ++ ) { for ( int j = 0 ; j <= Math . min ( n - i , s / 4 ) ; j ++ ) { if ( i * 9 + j * 4 == s ) { System . out . println ( i + " " + j + " " + ( n - i - j ) ) ; return ; } } } System . out . println ( ( - 1 ) + " " + ( - 1 ) + " " + ( - 1 ) ) ; } public static int lcm ( int x , int y ) { return x * y / gcd ( x , y ) ; } public static int gcd ( int x , int y ) { if ( x < y ) return gcd ( y , x ) ; if ( y == 0 ) return x ; return gcd ( y , x % y ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { new Main ( ) . run ( ) ; } private void run ( ) { int B = scanner . nextInt ( ) ; Scanner scanner = new Scanner ( System . in ) ; int A = scanner . nextInt ( ) ; int B = scanner . nextInt ( ) ; if ( ( A + B ) % 2 == 0 ) { System . out . println ( ( A + B ) / 2 ) ; } else { System . out . println ( " IMPOSSIBLE " ) ; } } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; char [ ] n = new char [ 4 ] ; n = sc . next ( ) . toCharArray ( ) ; sc . close ( ) ; for ( int i = 0 ; i < 3 ; ++ i ) { if ( n [ i ] == '1' ) n [ i ] = '9' ; else if ( n [ i ] == '9' ) n [ i ] = '1' ; } System . out . print ( n ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner s = new Scanner ( System . in ) ; String S1 = s . next ( ) ; String S2 = s . next ( ) ; char [ ] t = new char [ 3 ] ; char [ ] t2 = new char [ 3 ] ; int ans = 0 ; for ( int i = 0 ; i < 3 ; i ++ ) { t [ i ] = S1 . charAt ( i ) ; } for ( int i = 0 ; i < 3 ; i ++ ) { t2 [ i ] = S2 . charAt ( i ) ; } for ( int i = 0 ; i < 3 ; i ++ ) { int i = 0 ; if ( t [ i ] == t2 [ i ] ) { ans ++ ; } } System . out . println ( ans ) ; } } +import java . util . Scanner ; import java . util . ArrayList ; import java . util . Collections ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int L = sc . nextInt ( ) ; ArrayList < String > S = new ArrayList < > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { ArrayList < String > S = new ArrayList < > ( ) ; S . add ( sc . next ( ) ) ; } Collections . sort ( S ) ; for ( int i = 0 ; i < N ; i ++ ) System . out . print ( S . get ( i ) ) ; sc . close ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String S = getLine ( sc ) ; show ( calc ( S ) ) ; } private static String calc ( String S ) { int front = Integer . parseInt ( S . substring ( 0 , 2 ) ) ; int back = Integer . parseInt ( S . substring ( 2 , 4 ) ) ; if ( isMonth ( front ) ) { if ( isMonth ( back ) ) return " AMBIGUOUS " ; else return " MMYY " ; } else { int back = Integer . parseInt ( S . substring ( 2 , 4 ) ) ; if ( isMonth ( back ) ) return " YYMM " ; else return " NA " ; } } private static boolean isMonth ( int n ) { return 0 < n && n < 13 ; } private static String getLine ( Scanner sc ) { return sc . next ( ) ; } private static void show ( String answer ) { System . out . println ( answer ) ; } } +import java . util . Scanner ; public class Main { static Scanner scan ; public static boolean judgePN ( int a ) { if ( a == 1 ) return false ; int quotient = a ; for ( int i = 2 ; i < a ; i ++ ) { quotient = a / i ; if ( a % i == 0 ) return false ; if ( i > quotient ) break ; } return true ; } public static void main ( String [ ] args ) { scan = new Scanner ( System . in ) ; final int n = scan . nextInt ( ) ; int [ ] list = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { int i = 0 ; list [ i ] = scan . nextInt ( ) ; } int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( judgePN ( list [ i ] ) ) count ++ ; } System . out . println ( count ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; char [ ] c = s . toCharArray ( ) ; String t = " abcdefghijklmnopqrstuvwxyz " ; char [ ] al = t . toCharArray ( ) ; for ( int i = 0 ; i < t . length ( ) ; i ++ ) { int i = 0 ; if ( c [ 0 ] == al [ i ] ) { System . out . println ( al [ i + 1 ] ) ; } } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int m = sc . nextInt ( ) ; int [ ] mArray = new int [ m + 1 ] ; for ( int i = 0 ; i < n ; i ++ ) { int i = 1 ; int k = sc . nextInt ( ) ; int [ ] aArray = new int [ k ] ; for ( int j = 0 ; j < k ; j ++ ) { aArray [ j ] = sc . nextInt ( ) ; mArray [ aArray [ j ] ] ++ ; } } int result = 0 ; for ( int i = 1 ; i < m + 1 ; i ++ ) { if ( mArray [ i ] == n ) result ++ ; } System . out . println ( result ) ; sc . close ( ) ; } } +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 ) ; BBounding solver = new BBounding ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class BBounding { public void solve ( int testNumber , Scanner in , PrintWriter out ) { long count = 1 , sum = 0 ; long n = in . nextLong ( ) , x = in . nextLong ( ) ; long count = 1 , sum = 0 ; for ( long i = 1 ; i <= n ; i ++ ) { long y = in . nextLong ( ) ; sum += y ; if ( sum <= x ) count ++ ; } out . println ( count ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { long bm = m ; Scanner sc = new Scanner ( System . in ) ; long a = sc . nextLong ( ) ; a -- ; long b = sc . nextLong ( ) ; long c = sc . nextLong ( ) ; long d = sc . nextLong ( ) ; long total = b - a ; long divD = b / d - a / d ; long divC = b / c - a / c ; long lcm = getLcm ( c , d ) ; long divL = b / lcm - a / lcm ; System . out . println ( total - ( divD + divC - divL ) ) ; } private static long getLcm ( long n , long m ) { long bn = n ; long bm = m ; while ( n != m ) { if ( n < m ) { n += bn ; } else { m += bm ; } } return n ; } } +import java . io . IOException ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws IOException { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; long a , b , c , d , e ; a = 2 ; b = sc . nextLong ( ) ; c = b ; d = b ; e = b ; while ( a <= n ) { long a , b , c , d , e ; b = sc . nextLong ( ) ; c = c + b ; if ( b > d ) { d = b ; } else if ( b < e ) { e = b ; } a = a + 1 ; } System . out . println ( e + " " + d + " " + c ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int K = sc . nextInt ( ) ; double d = 0.0 ; int coin = 0 ; int calc = 0 ; for ( int i = 1 ; i <= N ; i ++ ) { int i = 1 ; calc = i ; coin = 0 ; for ( ; calc < K ; coin ++ ) calc *= 2 ; d += ( 1.0 / N ) * Math . pow ( ( 1.0 / 2 ) , coin ) ; } System . out . println ( d ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner t = new Scanner ( System . in ) ; String S = t . nextLine ( ) ; int c = 0 ; int [ ] v = new int [ 4 ] ; for ( int i = 0 ; i < 4 ; i ++ ) { v [ i ] = S . charAt ( i ) ; } if ( v [ 0 ] == v [ 1 ] || v [ 1 ] == v [ 2 ] || v [ 2 ] == v [ 3 ] ) { System . out . println ( " Bad " ) ; } else { int i = 0 ; System . out . println ( " Good " ) ; t . close ( ) ; } } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long n = sc . nextLong ( ) ; sc . close ( ) ; long p = 1 ; long sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( p % 5 == 0 || p % 3 == 0 ) { long sum = 0 ; p ++ ; continue ; } else { sum += p ; p ++ ; } } System . out . println ( sum ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { String S = sc . next ( ) ; Scanner sc = new Scanner ( System . in ) ; int K = sc . nextInt ( ) ; String S = sc . next ( ) ; if ( K >= S . length ( ) ) { System . out . println ( S ) ; } else { System . out . println ( S . substring ( 0 , K ) + " ... " ) ; } } } +import java . util . * ; public class Main { public static void main ( final String [ ] args ) { int i = 0 ; final Scanner sc = new Scanner ( System . in ) ; final int N = Integer . parseInt ( sc . next ( ) ) ; final int K = Integer . parseInt ( sc . next ( ) ) ; int result = 0 ; int [ ] pricelist = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { pricelist [ i ] = Integer . parseInt ( sc . next ( ) ) ; } sc . close ( ) ; Arrays . sort ( pricelist ) ; for ( int i = 0 ; i < K ; i ++ ) { result = result + pricelist [ i ] ; } System . out . println ( result ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] x = new int [ n ] ; int l = Integer . MAX_VALUE / 2 , r = - 1 ; for ( int i = 0 ; i < n ; i ++ ) { x [ i ] = sc . nextInt ( ) ; l = Math . min ( l , x [ i ] ) ; r = Math . max ( r , x [ i ] ) ; } long min = Integer . MAX_VALUE / 2 ; for ( int i = l ; i <= r ; i ++ ) { long d = 0 ; for ( int j = 0 ; j < n ; j ++ ) { int j = 0 ; d += Math . pow ( i - x [ j ] , 2 ) ; } min = Math . min ( min , d ) ; } System . out . println ( min ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int buildcnt = sc . nextInt ( ) ; int [ ] hights = new int [ buildcnt ] ; boolean reach = false ; String answer = " Yes " ; for ( int i = 0 ; i < buildcnt ; i ++ ) { hights [ i ] = sc . nextInt ( ) ; } for ( int i = buildcnt - 1 ; i > 0 ; i -- ) { if ( hights [ i - 1 ] - hights [ i ] > 1 ) { int i = buildcnt - 1 ; answer = " No " ; break ; } else if ( hights [ i - 1 ] - hights [ i ] == 1 && ! reach ) { reach = true ; } else if ( hights [ i - 1 ] - hights [ i ] == 1 && reach ) { answer = " No " ; break ; } else if ( hights [ i - 1 ] - hights [ i ] == 0 && reach ) { reach = true ; } else { reach = false ; } } System . out . println ( answer ) ; } } +import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = Integer . parseInt ( sc . next ( ) ) ; int ex = Integer . parseInt ( sc . next ( ) ) ; int [ ] teki = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { int i = 0 ; teki [ i ] = Integer . parseInt ( sc . next ( ) ) ; } Arrays . sort ( teki ) ; n -= ex ; long res = 0L ; for ( int i = 0 ; i < n ; i ++ ) { res += teki [ i ] ; } System . out . println ( res ) ; } } +import java . util . * ; import java . util . Collections ; import java . util . ArrayList ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int M = sc . nextInt ( ) ; int X = sc . nextInt ( ) ; int a = 0 ; int b = 0 ; for ( int i = 0 ; i < M ; i ++ ) { if ( sc . nextInt ( ) < X ) { a += 1 ; } else { int b = 0 ; b += 1 ; } } if ( a <= b ) { System . out . println ( a ) ; } else { System . out . println ( b ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int [ ] a ; int i = 0 , count = 1 ; a = new int [ 100000 ] ; a [ 0 ] = 1 ; Scanner n = new Scanner ( System . in ) ; while ( a [ i ] != 0 ) { Scanner n = new Scanner ( System . in ) ; i ++ ; a [ i ] = n . nextInt ( ) ; if ( a [ i ] != 0 ) { count += 1 ; } } i = 1 ; while ( count > i ) { System . out . println ( " Case " + i + " : " + a [ i ] ) ; i ++ ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int ans = 0 ; exec ( ) ; } static void exec ( ) { Scanner sc = new Scanner ( System . in ) ; long n = sc . nextLong ( ) ; long d = sc . nextLong ( ) ; int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { long x = sc . nextLong ( ) ; long y = sc . nextLong ( ) ; if ( x * x + y * y <= d * d ) { ans ++ ; } } System . out . println ( ans ) ; } } +import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . util . Map ; import java . util . HashMap ; import java . util . List ; import java . util . ArrayList ; import java . util . Collections ; public class Main { public static void main ( String [ ] args ) throws Exception { int digits , mindigits = 11 ; BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; long a , b = 0 ; long n = Long . parseLong ( br . readLine ( ) ) ; int digits , mindigits = 11 ; for ( a = 1 ; a <= Math . sqrt ( n ) ; a ++ ) { if ( n % a == 0 ) { b = n / a ; digits = String . valueOf ( Math . max ( a , b ) ) . length ( ) ; if ( digits < mindigits ) mindigits = digits ; } } System . out . println ( mindigits ) ; } } +import java . awt . * ; import java . awt . geom . * ; import java . io . * ; import java . util . * ; class Main { public static void main ( String [ ] args ) { int i = 1 ; Scanner sc = new Scanner ( System . in ) ; int [ ] list = new int [ 3 ] ; for ( int i = 0 ; i < 3 ; i ++ ) { list [ i ] = sc . nextInt ( ) ; } Arrays . sort ( list ) ; System . out . print ( list [ 0 ] ) ; for ( int i = 1 ; i < 3 ; i ++ ) { System . out . print ( " " + list [ i ] ) ; } System . out . println ( ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int x = sc . nextInt ( ) ; int ans = 0 ; while ( x >= 5 ) { int ans = 0 ; if ( x >= 500 ) { x -= 500 ; ans += 1000 ; } else { x -= 5 ; ans += 5 ; } } System . out . println ( ans ) ; } } +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 C = sc . nextInt ( ) ; int X = sc . nextInt ( ) ; int ans = 0 ; for ( int i = 0 ; i <= A ; i ++ ) { for ( int j = 0 ; j <= B ; j ++ ) { int j = 0 ; int tmp = X - i * 500 - j * 100 ; if ( 0 <= tmp && tmp <= C * 50 ) { ans ++ ; } } } System . out . println ( ans ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int t ; char [ ] ch = " abcdefghijklmnopqrstuvwxyz " . toCharArray ( ) ; Scanner scan = new Scanner ( System . in ) ; long n = scan . nextLong ( ) ; StringBuilder sb = new StringBuilder ( ) ; int t ; for ( ; n > 0 ; n = ( n - 1 ) / 26 ) { t = ( int ) ( ( n - 1 ) % 26 ) ; sb . append ( ch [ t ] ) ; } System . out . println ( sb . reverse ( ) . toString ( ) ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int n = scan . nextInt ( ) ; int i = 0 ; int taro_count = 0 ; int hana_count = 0 ; for ( i = 0 ; i < n ; i ++ ) { String a = scan . next ( ) ; String b = scan . next ( ) ; if ( a . compareTo ( b ) == 0 ) { taro_count += 1 ; hana_count += 1 ; } else if ( a . compareTo ( b ) < 0 ) { int hana_count = 0 ; hana_count += 3 ; } else { taro_count += 3 ; } } System . out . println ( taro_count + " " + hana_count ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { char [ ] arr = sc . next ( ) . toCharArray ( ) ; Scanner sc = new Scanner ( System . in ) ; char [ ] arr = sc . next ( ) . toCharArray ( ) ; if ( arr [ 1 ] == 'R' ) { arr [ 1 ] = 'B' ; } else { arr [ 1 ] = 'R' ; } System . out . println ( arr ) ; } } +import java . util . * ; import java . io . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int k = sc . nextInt ( ) ; int d ; int A ; int [ ] people = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { int i = 0 ; people [ i ] = 0 ; } for ( int i = 0 ; i < k ; i ++ ) { d = sc . nextInt ( ) ; for ( int j = 0 ; j < d ; j ++ ) { A = sc . nextInt ( ) ; A -- ; people [ A ] ++ ; } } int res = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( people [ i ] == 0 ) res ++ ; } System . out . println ( res ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int a = scan . nextInt ( ) ; int b = scan . nextInt ( ) ; int c = scan . nextInt ( ) ; double d = 0 ; int ans = 0 ; double ans1 = 1000 ; int j = 0 ; for ( int i = 0 ; i != a ; i ++ ) { int i = 0 ; d = scan . nextInt ( ) ; d = b - ( d * 0.006 ) ; d -= c ; if ( d < 0 ) { d *= - 1 ; } if ( d < ans1 ) { ans1 = d ; ans = i + 1 ; } } System . out . println ( ans ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . Arrays ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String [ ] parts = br . readLine ( ) . split ( " " ) ; long N = Integer . parseInt ( parts [ 0 ] ) ; long K = Integer . parseInt ( parts [ 1 ] ) ; parts = br . readLine ( ) . split ( " " ) ; long [ ] H = new long [ parts . length ] ; for ( int i = 0 ; i < H . length ; i ++ ) { H [ i ] = Integer . parseInt ( parts [ i ] ) ; } Arrays . sort ( H ) ; long sum = 0 ; for ( int i = 0 ; i < H . length - K ; i ++ ) { int i = 0 ; sum += H [ i ] ; } System . out . println ( sum ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] nums = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { nums [ i ] = sc . nextInt ( ) ; } boolean result = true ; for ( int i = 0 ; i < n ; i ++ ) { int before = 0 ; if ( i != 0 ) { before = nums [ i - 1 ] ; } if ( nums [ i ] < before ) { result = false ; break ; } if ( nums [ i ] != before ) { nums [ i ] -- ; } } if ( result ) { int before = 0 ; System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } } +import java . util . Arrays ; import java . util . Collections ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; Integer [ ] d = new Integer [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { int i = 0 ; d [ i ] = sc . nextInt ( ) ; } sc . close ( ) ; Arrays . sort ( d , Collections . reverseOrder ( ) ) ; int ans = 1 ; for ( int i = 0 ; i < N - 1 ; i ++ ) { if ( d [ i ] > d [ i + 1 ] ) { ans ++ ; } } System . out . println ( ans ) ; } } +import java . util . Scanner ; public class Main { static Scanner sc = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { int i = 0 ; int n = sc . nextInt ( ) ; int m = sc . nextInt ( ) ; int [ ] L = new int [ m ] ; int [ ] R = new int [ m ] ; int maxL = 0 ; int minR = Integer . MAX_VALUE ; for ( int i = 0 ; i < m ; i ++ ) { L [ i ] = sc . nextInt ( ) ; R [ i ] = sc . nextInt ( ) ; maxL = Math . max ( maxL , L [ i ] ) ; minR = Math . min ( minR , R [ i ] ) ; } System . out . println ( Math . max ( minR - maxL + 1 , 0 ) ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; String s = scan . next ( ) ; int len = s . length ( ) ; int [ ] A = new int [ len ] ; int [ ] B = new int [ len ] ; int i ; for ( i = 0 ; i < len ; i ++ ) { A [ i ] = i % 2 ; B [ i ] = ( i + 1 ) % 2 ; } int tempA = 0 ; int tempB = 0 ; int intS ; for ( i = 0 ; i < len ; i ++ ) { int intS ; intS = Integer . parseInt ( s . substring ( i , i + 1 ) ) ; if ( intS != A [ i ] ) tempA ++ ; if ( intS != B [ i ] ) tempB ++ ; } System . out . println ( Math . min ( tempA , tempB ) ) ; } } +import java . io . * ; class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int n = Integer . parseInt ( br . readLine ( ) ) ; int i = 1 ; int x ; while ( true ) { int x ; x = i ; if ( x % 3 == 0 ) { System . out . print ( " " + i ) ; } else { while ( x != 0 ) { if ( x % 10 == 3 ) { System . out . print ( " " + i ) ; break ; } x /= 10 ; } } if ( ++ i > n ) break ; } System . out . print ( " \n " ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { long ans = 0 ; Scanner sc = new Scanner ( System . in ) ; long N = sc . nextLong ( ) ; long K = sc . nextLong ( ) ; long A = N % K ; long ans = 0 ; if ( N % K == 0 ) { ans = 0 ; } else { ans = Math . min ( A , K - A ) ; } System . out . println ( ans ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int l = 0 ; Scanner sc = new Scanner ( System . in ) ; String s = sc . nextLine ( ) ; String s1 = s + s ; char [ ] s1str = s1 . toCharArray ( ) ; String p = sc . nextLine ( ) ; char [ ] pstr = p . toCharArray ( ) ; boolean flag = false ; String msg = " No " ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { for ( int l = 0 ; l < p . length ( ) ; l ++ ) { if ( s1str [ i + l ] != pstr [ l ] ) { flag = false ; break ; } flag = true ; } if ( flag == true ) { msg = " Yes " ; break ; } } System . out . println ( msg ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int c = sc . nextInt ( ) ; int x = sc . nextInt ( ) ; int y = sc . nextInt ( ) ; long i = a * x + b * y ; long ii = c * 2 * Math . max ( x , y ) ; long iii = 0 ; if ( x > y ) { iii = c * 2 * y + a * ( x - y ) ; } else { long iii = 0 ; iii = c * 2 * x + b * ( y - x ) ; } System . out . println ( Math . min ( Math . min ( i , ii ) , iii ) ) ; } } +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 + 1 ] ; int [ ] w = new int [ N + 1 ] ; int [ ] s = new int [ N + 1 ] ; int [ ] indice = new int [ N ] ; a [ 0 ] = 0 ; for ( int i = 1 ; i <= N ; i ++ ) { int i = 1 ; a [ i ] = sc . nextInt ( ) ; } int nr_breaks = 0 ; int cur = 1 ; for ( int i = 1 ; i <= N ; i ++ ) { if ( a [ i ] == cur ) { cur ++ ; } else { nr_breaks ++ ; } } if ( nr_breaks == N ) { System . out . println ( - 1 ) ; } else { System . out . println ( nr_breaks ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] a = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = sc . nextInt ( ) ; } int b = 1 ; int c = 0 ; int d = 0 ; while ( b != 2 ) { int d = 0 ; d += 1 ; c = b ; b = a [ b - 1 ] ; if ( b == 0 ) { System . out . println ( - 1 ) ; return ; } a [ c - 1 ] = 0 ; } System . out . println ( d ) ; } } +import java . io . * ; import java . util . * ; public class Main { PrintWriter out = new PrintWriter ( new BufferedWriter ( new OutputStreamWriter ( System . out ) ) ) ; BufferedReader in = new BufferedReader ( new InputStreamReader ( System . in ) ) ; StringTokenizer tok ; public void go ( ) throws IOException { ntok ( ) ; String s = spar ( ) ; out . println ( s . indexOf ( '7' ) != - 1 ? " Yes " : " No " ) ; out . flush ( ) ; in . close ( ) ; } public void ntok ( ) throws IOException { tok = new StringTokenizer ( in . readLine ( ) ) ; } public int ipar ( ) { return Integer . parseInt ( tok . nextToken ( ) ) ; } public int [ ] iapar ( int n ) { int [ ] arr = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { arr [ i ] = ipar ( ) ; } return arr ; } public long lpar ( ) { return Long . parseLong ( tok . nextToken ( ) ) ; } public long [ ] lapar ( int n ) { long [ ] arr = new long [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { arr [ i ] = lpar ( ) ; } return arr ; } public double dpar ( ) { int i = 0 ; return Double . parseDouble ( tok . nextToken ( ) ) ; } public String spar ( ) { return tok . nextToken ( ) ; } public static void main ( String [ ] args ) throws IOException { new Main ( ) . go ( ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) { int numN = 0 ; int i = 0 ; String outputNum = " " ; String [ ] NumList ; try { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String line = br . readLine ( ) ; numN = Integer . parseInt ( line ) ; line = br . readLine ( ) ; if ( line != null ) { NumList = line . split ( " " , 0 ) ; int Count = numN - 1 ; for ( i = 0 ; i < NumList . length ; i ++ ) { if ( Count != numN - 1 ) { int Count = numN - 1 ; outputNum += " " ; } outputNum += NumList [ Count ] ; Count -- ; } System . out . println ( outputNum ) ; } } catch ( NumberFormatException e ) { System . out . println ( e ) ; } catch ( IOException e ) { System . out . println ( e ) ; } } } +import java . util . ArrayList ; import java . util . Collections ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int number = scanner . nextInt ( ) ; ArrayList < Integer > list = new ArrayList < Integer > ( ) ; long total = 0 ; for ( int i = 0 ; i < number ; i ++ ) { int i = 0 ; list . add ( scanner . nextInt ( ) ) ; } Collections . sort ( list ) ; System . out . print ( list . get ( 0 ) + " " ) ; System . out . print ( list . get ( list . size ( ) - 1 ) + " " ) ; for ( int i = 0 ; i < list . size ( ) ; i ++ ) { total += list . get ( i ) ; } System . out . println ( total ) ; } } +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 c = sc . nextInt ( ) ; System . out . println ( method ( a , b , c ) ) ; } static int method ( int a , int b , int c ) { int divisor = 0 ; for ( int i = a ; i < b + 1 ; i ++ ) { int i = a ; if ( c % i == 0 ) { divisor ++ ; } } return divisor ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int Y = sc . nextInt ( ) ; int A = 10000 ; int B = 5000 ; int C = 1000 ; for ( int ai = 0 ; ai <= N ; ai ++ ) { for ( int bi = 0 ; bi <= N - ai ; bi ++ ) { int ci = N - ai - bi ; int sum = ai * A + bi * B + ci * 1000 ; if ( sum == Y ) { int ci = N - ai - bi ; System . out . println ( ai + " " + bi + " " + ci ) ; return ; } } } System . out . println ( " -1 -1 -1 " ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int a = Integer . parseInt ( sc . next ( ) ) ; int b = Integer . parseInt ( sc . next ( ) ) ; double d = a / 0.08 ; int x = ( int ) ( a / 0.08 ) ; if ( d != x ) x ++ ; System . err . println ( x ) ; int min = a ; int max = a ; int xmin = x ; int xmax = x ; int i = 0 ; while ( min == a ) { xmin -- ; min = ( int ) ( xmin * 0.08 ) ; } while ( max == a ) { xmax ++ ; max = ( int ) ( xmax * 0.08 ) ; } System . err . println ( " min: " + xmin + " max: " + xmax ) ; for ( int j = xmin + 1 ; j < xmax ; j ++ ) { if ( b == ( int ) ( j * 0.1 ) ) { int j = xmin + 1 ; System . out . println ( j ) ; return ; } } System . out . println ( - 1 ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int num = Integer . parseInt ( sc . nextLine ( ) ) ; int result = 0 ; for ( int i = 0 ; i < num ; i ++ ) { int target = Integer . parseInt ( sc . nextLine ( ) ) ; if ( target == 1 ) { continue ; } boolean flgPrime = true ; for ( int j = 2 ; j <= ( int ) Math . sqrt ( target ) ; j ++ ) { if ( target % j == 0 ) { int j = 2 ; flgPrime = false ; break ; } } if ( flgPrime ) { result ++ ; } } System . out . println ( result ) ; } } +import java . io . OutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . PrintWriter ; import java . util . StringTokenizer ; import java . io . IOException ; import java . util . InputMismatchException ; 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 ) ; BDigitSums solver = new BDigitSums ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class BDigitSums { public void solve ( int testNumber , InputReader in , PrintWriter out ) { int n = in . nextInt ( ) ; int sum = 0 ; int tmp = n ; while ( tmp > 0 ) { sum += tmp % 10 ; tmp /= 10 ; } out . println ( n % sum == 0 ? " Yes " : " No " ) ; } } static class InputReader { private BufferedReader br ; private StringTokenizer st ; public InputReader ( InputStream inputStream ) { br = new BufferedReader ( new InputStreamReader ( inputStream ) ) ; st = new StringTokenizer ( " " ) ; } public String nextString ( ) { while ( ! st . hasMoreTokens ( ) ) { try { st = new StringTokenizer ( br . readLine ( ) , " " ) ; } catch ( IOException e ) { throw new InputMismatchException ( ) ; } } return st . nextToken ( ) ; } public int nextInt ( ) { return Integer . parseInt ( nextString ( ) ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; long N = sc . nextLong ( ) ; long ans = 100 ; long sum = 0 ; while ( ans < N ) { long sum = 0 ; ans = ans + ( long ) ( ans / 100 ) ; sum ++ ; } System . out . println ( sum ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner scan = new Scanner ( System . in ) ; String s , t ; int con ; s = scan . next ( ) ; t = scan . next ( ) ; con = 0 ; for ( int i = 0 ; i < 3 ; i ++ ) { if ( s . charAt ( i ) == t . charAt ( i ) ) con += 1 ; } System . out . println ( con ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner std = new Scanner ( System . in ) ; int n = Integer . parseInt ( std . next ( ) ) ; int [ ] line = new int [ n ] ; int temp = 0 ; int exchange = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int i = 1 ; line [ i ] = Integer . parseInt ( std . next ( ) ) ; } boolean flag = true ; while ( flag ) { flag = false ; for ( int j = ( n - 1 ) ; j > 0 ; j -- ) { if ( line [ j ] < line [ j - 1 ] ) { temp = line [ j ] ; line [ j ] = line [ j - 1 ] ; line [ j - 1 ] = temp ; exchange ++ ; flag = true ; } } } String outsd = Integer . toString ( line [ 0 ] ) ; for ( int i = 1 ; i < n ; i ++ ) { outsd += " " + line [ i ] ; } System . out . println ( outsd ) ; System . out . println ( exchange ) ; } } +import java . util . * ; class Main { static Scanner sc = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { int A = sc . nextInt ( ) ; int B = sc . nextInt ( ) ; int ans = - 1 ; for ( int i = 12 ; i <= 1000 ; i ++ ) { int i = 12 ; if ( i * 8 / 100 == A && i / 10 == B ) { ans = i ; break ; } } System . out . println ( ans ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = Integer . parseInt ( sc . nextLine ( ) ) ; String sTaro ; String sHanako ; int iTaro = 0 ; int iHanako = 0 ; for ( int i = 0 ; i < n ; i ++ ) { sTaro = sc . next ( ) ; sHanako = sc . next ( ) ; if ( sTaro . compareTo ( sHanako ) < 0 ) { iHanako += 3 ; } else if ( sTaro . compareTo ( sHanako ) > 0 ) { int iHanako = 0 ; iTaro += 3 ; } else { iTaro ++ ; iHanako ++ ; } } System . out . println ( iTaro + " " + iHanako ) ; } } +import java . util . * ; public class Main { static boolean [ ] targetNumbers ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long A = sc . nextLong ( ) ; long B = sc . nextLong ( ) ; long gcd = calcGcd ( A , B ) ; System . out . println ( A * B / gcd ) ; } public static long calcGcd ( long m , long n ) { long remainder = 0 ; if ( m < n ) { long tmp = m ; m = n ; n = tmp ; } long remainder = 0 ; while ( ( remainder = m % n ) != 0 ) { m = n ; n = remainder ; } return n ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int n = scan . nextInt ( ) ; int l = scan . nextInt ( ) ; int [ ] arr = new int [ n ] ; int sum = 0 ; int min = 0 ; for ( int i = 0 ; i < n ; i ++ ) { arr [ i ] = l + i ; sum += arr [ i ] ; } if ( l >= 0 ) { System . out . print ( sum - l ) ; } else { if ( n + l > 0 ) { int i = 0 ; min = sum ; } else { min = sum - ( n + l - 1 ) ; } System . out . print ( min ) ; } } } +import java . util . Scanner ; public class Main { static boolean solve ( int d , int t , int s ) { if ( s * t >= d ) return true ; else return false ; } public static void main ( String [ ] args ) { int d , t , s ; Scanner stdIn = new Scanner ( System . in ) ; int d , t , s ; d = stdIn . nextInt ( ) ; t = stdIn . nextInt ( ) ; s = stdIn . nextInt ( ) ; boolean result = solve ( d , t , s ) ; if ( result ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; stdIn . close ( ) ; } } +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 ) { PrintWriter out = new PrintWriter ( outputStream ) ; InputStream inputStream = System . in ; OutputStream outputStream = System . out ; Scanner in = new Scanner ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; A solver = new A ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class A { public void solve ( int testNumber , Scanner in , PrintWriter out ) { String S = in . next ( ) ; if ( S . charAt ( 0 ) == 'A' && S . charAt ( 1 ) == 'A' && S . charAt ( 2 ) == 'A' ) { out . println ( " No " ) ; return ; } if ( S . charAt ( 0 ) == 'B' && S . charAt ( 1 ) == 'B' && S . charAt ( 2 ) == 'B' ) { out . println ( " No " ) ; return ; } out . println ( " Yes " ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { long k = sc . nextLong ( ) ; Scanner sc = new Scanner ( System . in ) ; long a = sc . nextLong ( ) ; long b = sc . nextLong ( ) ; long k = sc . nextLong ( ) ; if ( a >= k ) { System . out . println ( ( a - k ) + " " + b ) ; } else if ( b >= k - a ) { System . out . println ( " 0 " + " " + ( b - ( k - a ) ) ) ; } else { System . out . println ( " 0 0 " ) ; } } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . ArrayList ; import java . util . List ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String [ ] tmp = br . readLine ( ) . split ( " " ) ; int N = Integer . parseInt ( tmp [ 0 ] ) ; int M = Integer . parseInt ( tmp [ 1 ] ) ; List < Integer > L = new ArrayList < Integer > ( ) ; List < Integer > R = new ArrayList < Integer > ( ) ; for ( int i = 0 ; i < M ; i ++ ) { int min = L . get ( L . size ( ) - 1 ) ; tmp = br . readLine ( ) . split ( " " ) ; L . add ( Integer . parseInt ( tmp [ 0 ] ) ) ; R . add ( Integer . parseInt ( tmp [ 1 ] ) ) ; } L . sort ( null ) ; R . sort ( null ) ; int max = R . get ( 0 ) ; int min = L . get ( L . size ( ) - 1 ) ; if ( max - min + 1 < 0 ) { System . out . println ( 0 ) ; } else { System . out . println ( max - min + 1 ) ; } } } +import java . util . Scanner ; class Solver { private final int K ; Solver ( Scanner in ) { int N = in . nextInt ( ) ; K = in . nextInt ( ) ; int count = 0 ; for ( int i = 0 ; i < N ; i ++ ) { Scanner in = new Scanner ( System . in ) ; if ( in . nextInt ( ) >= K ) count ++ ; } System . out . println ( count ) ; } void solve ( ) { } } class Main { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; new Solver ( in ) . solve ( ) ; in . close ( ) ; } } +import java . util . Scanner ; import java . util . Arrays ; import static java . lang . System . out ; class SortingThreeNumbers { public static int [ ] sorted ( int [ ] inputs ) { int num ; int [ ] res = Arrays . copyOf ( inputs , inputs . length ) ; for ( int i = 0 ; i < res . length ; i ++ ) { for ( int j = 1 ; j < res . length - i ; j ++ ) { if ( res [ j - 1 ] > res [ j ] ) { int tmp = res [ j - 1 ] ; res [ j - 1 ] = res [ j ] ; res [ j ] = tmp ; } } } return res ; } } public class Main { public static void main ( String ... args ) { Scanner scan = new Scanner ( System . in ) ; int [ ] inputs = new int [ 3 ] ; int i = 0 ; while ( scan . hasNext ( ) ) { inputs [ i ] = scan . nextInt ( ) ; i ++ ; } StringBuilder output = new StringBuilder ( ) ; for ( int num : SortingThreeNumbers . sorted ( inputs ) ) { output . append ( String . valueOf ( num ) + " " ) ; } output . deleteCharAt ( output . length ( ) - 1 ) ; out . println ( output ) ; } } +import java . io . IOException ; import java . io . BufferedReader ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; StringBuilder sb = new StringBuilder ( ) ; while ( true ) { sb . delete ( 0 , sb . length ( ) ) ; String line = br . readLine ( ) ; sb . append ( line ) ; if ( line . equals ( " - " ) ) break ; int m = Integer . parseInt ( br . readLine ( ) ) ; for ( int i = 0 ; i < m ; i ++ ) { StringBuilder sb = new StringBuilder ( ) ; int hi = Integer . parseInt ( br . readLine ( ) ) ; sb . append ( sb . substring ( 0 , hi ) ) ; sb . delete ( 0 , hi ) ; } System . out . println ( sb . toString ( ) ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String S = sc . next ( ) ; int cnt = 0 ; int max = 0 ; for ( int i = 0 ; i < S . length ( ) ; i ++ ) { int i = 0 ; if ( S . charAt ( i ) == 'A' || S . charAt ( i ) == 'C' || S . charAt ( i ) == 'G' || S . charAt ( i ) == 'T' ) { cnt ++ ; } else { cnt = 0 ; } if ( max < cnt ) { max = cnt ; } } System . out . println ( max ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String line = sc . nextLine ( ) ; String [ ] nt = line . split ( " " ) ; int n = Integer . parseInt ( nt [ 0 ] ) ; int t = Integer . parseInt ( nt [ 1 ] ) ; String rel = " TLE " ; for ( int i = 0 ; i < n ; i ++ ) { String keiro = sc . nextLine ( ) ; String [ ] k = keiro . split ( " " ) ; if ( Integer . parseInt ( k [ 1 ] ) <= t ) { if ( rel . equals ( " TLE " ) ) { rel = String . valueOf ( k [ 0 ] ) ; } else if ( Integer . parseInt ( rel ) > Integer . parseInt ( k [ 0 ] ) ) { String [ ] k = keiro . split ( " " ) ; rel = String . valueOf ( k [ 0 ] ) ; } } } System . out . println ( rel ) ; sc . close ( ) ; } } +import java . util . Map ; import java . util . Map . Entry ; import java . util . Scanner ; import java . util . TreeMap ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; Map < String , Integer > m = new TreeMap < String , Integer > ( ) ; int max = 0 ; for ( int i = 0 ; i < N ; i ++ ) { String S = sc . next ( ) ; if ( m . containsKey ( S ) ) { m . put ( S , m . get ( S ) + 1 ) ; } else { Entry < String , Integer > s ; m . put ( S , 1 ) ; } if ( max < m . get ( S ) ) { max = m . get ( S ) ; } } for ( Entry < String , Integer > s : m . entrySet ( ) ) { if ( s . getValue ( ) == max ) { System . out . println ( s . getKey ( ) ) ; } } } } +import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . io . IOException ; public class Main { public static void main ( String [ ] args ) throws IOException { int j = 0 ; BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; StringBuilder sb = new StringBuilder ( ) ; while ( true ) { String [ ] line = br . readLine ( ) . split ( " " ) ; int h = Integer . parseInt ( line [ 0 ] ) ; int w = Integer . parseInt ( line [ 1 ] ) ; if ( h == 0 && w == 0 ) break ; for ( int i = 0 ; i < h ; i ++ ) { for ( int j = 0 ; j < w ; j ++ ) { if ( ( i % 2 == 0 && j % 2 != 0 ) || ( i % 2 != 0 && j % 2 == 0 ) ) sb . append ( " . " ) ; else sb . append ( " # " ) ; } sb . append ( " \n " ) ; } sb . append ( " \n " ) ; } System . out . print ( sb ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int roop = 0 ; Scanner sc = new Scanner ( System . in ) ; int n = Integer . parseInt ( sc . next ( ) ) ; int ans = 1 ; int count = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { int divi = i ; int roop = 0 ; while ( divi % 2 == 0 ) { divi = divi / 2 ; roop ++ ; } if ( count < roop ) { count = roop ; ans = i ; } } 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 [ ] L = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { L [ i ] = sc . nextInt ( ) ; } sc . close ( ) ; Arrays . sort ( L ) ; int sum = 0 ; for ( int i = N - 2 ; 0 <= i ; i -- ) { int i = N - 2 ; sum += L [ i ] ; } if ( L [ N - 1 ] < sum ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } } +import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int j = n - 1 ; Scanner scanner = new Scanner ( System . in ) ; int n = scanner . nextInt ( ) ; int [ ] nums = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) nums [ i ] = scanner . nextInt ( ) ; bubbleSort ( n , nums ) ; } private static void bubbleSort ( int n , int [ ] a ) { boolean flg = true ; int i = 0 ; int sw = 0 ; while ( flg ) { flg = false ; for ( int j = n - 1 ; j > i ; j -- ) { if ( a [ j ] < a [ j - 1 ] ) { int w = a [ j ] ; a [ j ] = a [ j - 1 ] ; a [ j - 1 ] = w ; sw ++ ; flg = true ; } } i ++ ; } trace ( a ) ; System . out . println ( sw ) ; } private static void trace ( int [ ] nums ) { System . out . println ( Arrays . toString ( nums ) . replaceAll ( " [ \\ [ \\ ],] " , " " ) ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { int k = 0 ; Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int c = sc . nextInt ( ) ; int x = sc . nextInt ( ) ; int cnt = 0 ; int z ; for ( int i = 0 ; i <= a ; i ++ ) { z = x - 500 * i ; for ( int j = 0 ; j <= b ; j ++ ) { z -= 100 * j ; for ( int k = 0 ; k <= c ; k ++ ) { z = z - 50 * k ; if ( z == 0 ) { cnt ++ ; } z = z + 50 * k ; } z += 100 * j ; } } System . out . println ( cnt ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int x , t = 1 ; Scanner sc = new Scanner ( System . in ) ; while ( true ) { Scanner sc = new Scanner ( System . in ) ; x = sc . nextInt ( ) ; if ( x == 0 ) break ; System . out . println ( " Case " + t ++ + " : " + x ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String ... args ) { try ( Scanner sc = new Scanner ( System . in ) ) { int ans = 0 ; String [ ] s = sc . next ( ) . split ( " " ) ; for ( String i : s ) { if ( i . equals ( " + " ) ) { ans ++ ; } else { String i ; ans -- ; } } 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 ] ; int max = 0 ; int m = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int i = 0 ; a [ i ] = sc . nextInt ( ) ; max = Math . max ( max , a [ i ] ) ; m += a [ i ] ; } System . out . println ( ( m > 2 * max ) ? " Yes " : " No " ) ; } } +import java . util . ArrayList ; import java . util . List ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int N = scan . nextInt ( ) ; ArrayList < Integer > result = new ArrayList < > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { Integer r ; result . add ( 0 ) ; } for ( int i = 0 ; i < N - 1 ; i ++ ) { int tmp = scan . nextInt ( ) ; result . set ( tmp - 1 , result . get ( tmp - 1 ) + 1 ) ; } for ( Integer r : result ) { System . out . println ( r ) ; } } } +import java . util . Arrays ; import java . util . HashMap ; import java . util . Map ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { String sch = new String ( ch ) ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; String [ ] s = new String [ n ] ; Map < String , Integer > map = new HashMap < String , Integer > ( ) ; long result = 0 ; for ( int i = 0 ; i < n ; i ++ ) { s [ i ] = sc . next ( ) ; char [ ] ch = s [ i ] . toCharArray ( ) ; Arrays . sort ( ch ) ; String sch = new String ( ch ) ; if ( map . containsKey ( sch ) ) { map . replace ( sch , map . get ( sch ) + 1 ) ; result += map . get ( sch ) ; } else { map . put ( sch , 0 ) ; } } System . out . println ( result ) ; sc . close ( ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String input = sc . nextLine ( ) ; StringBuilder output = new StringBuilder ( ) ; for ( int i = 0 ; i < input . length ( ) ; ++ i ) { if ( input . charAt ( i ) != 'B' ) { int len = output . length ( ) ; output . append ( input . charAt ( i ) ) ; } else { int len = output . length ( ) ; if ( len > 0 ) { output . deleteCharAt ( len - 1 ) ; } } } sc . close ( ) ; System . out . println ( output ) ; } } +import java . util . * ; public class Main { public static void main ( final String [ ] args ) { final Scanner sc = new Scanner ( System . in ) ; final String color1 = sc . next ( ) ; final String color2 = sc . next ( ) ; int color1_n = sc . nextInt ( ) ; int color2_n = sc . nextInt ( ) ; final String target = sc . next ( ) ; if ( target . equals ( color1 ) ) { int color2_n = sc . nextInt ( ) ; color1_n -- ; } else if ( target . equals ( color2 ) ) { color2_n -- ; } System . out . println ( color1_n + " " + color2_n ) ; sc . close ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int [ ] B = new int [ N ] ; for ( int i = 0 ; i < N - 1 ; i ++ ) { int i = 0 ; B [ i ] = sc . nextInt ( ) ; } int total = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( i == 0 ) total += B [ i ] ; else if ( i == N - 1 ) total += B [ i - 1 ] ; else { if ( B [ i ] > B [ i - 1 ] ) total += B [ i - 1 ] ; else total += B [ i ] ; } } System . out . println ( total ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int k = sc . nextInt ( ) ; List < Integer > divsA = new ArrayList < > ( ) ; List < Integer > divsB = new ArrayList < > ( ) ; for ( int i = 1 ; i <= a ; ++ i ) { if ( a % i == 0 ) divsA . add ( i ) ; } for ( int i = 1 ; i <= b ; ++ i ) { int j = 0 ; if ( b % i == 0 ) divsB . add ( i ) ; } List < Integer > divs = new ArrayList < > ( ) ; for ( int i = 0 ; i < divsA . size ( ) ; ++ i ) { for ( int j = 0 ; j < divsB . size ( ) ; ++ j ) { if ( divsA . get ( i ) == divsB . get ( j ) ) { divs . add ( divsA . get ( i ) ) ; } } } System . out . println ( divs . get ( divs . size ( ) - k ) ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] a ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String str = br . readLine ( ) ; char [ ] data = str . toCharArray ( ) ; char buf ; for ( int i = 0 ; i < data . length / 2 ; i ++ ) { int i = 0 ; buf = data [ i ] ; data [ i ] = data [ data . length - 1 - i ] ; data [ data . length - 1 - i ] = buf ; } System . out . println ( data ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int a = in . nextInt ( ) ; int b = in . nextInt ( ) ; int min = b ; int max = b ; long sum = b ; for ( int i = 0 ; i < a - 1 ; i ++ ) { int c = in . nextInt ( ) ; int c = in . nextInt ( ) ; if ( min > c ) { min = c ; } if ( max < c ) { max = c ; } sum += c ; } System . out . println ( min + " " + max + " " + sum ) ; } } +import java . io . * ; import java . util . * ; public class Main { public static void main ( String [ ] args ) { new Main ( ) ; } Scanner in = new Scanner ( System . in ) ; PrintWriter out = new PrintWriter ( System . out ) ; int a , b ; Main ( ) { a = in . nextInt ( ) ; b = in . nextInt ( ) ; if ( ( a % 2 ) != ( b % 2 ) ) out . println ( " IMPOSSIBLE " ) ; else out . println ( ( a + b ) / 2 ) ; out . close ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { try ( Scanner in = new Scanner ( System . in ) ) { int n = N ; int N = in . nextInt ( ) ; for ( int n = N ; n < 1000 ; n ++ ) { if ( n % 111 == 0 ) { System . out . println ( n ) ; return ; } } } } } +import java . io . IOException ; import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . util . Scanner ; import java . util . Arrays ; import java . util . Collections ; class Main { public static void main ( String [ ] args ) throws IOException { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; Integer [ ] mountains = new Integer [ 10 ] ; for ( int i = 0 ; i < 10 ; i ++ ) { mountains [ i ] = sc . nextInt ( ) ; } Arrays . sort ( mountains , Collections . reverseOrder ( ) ) ; StringBuilder sb = new StringBuilder ( " " ) ; for ( int i = 0 ; i < 3 ; i ++ ) { sb . append ( mountains [ i ] ) ; sb . append ( '\n' ) ; } System . out . print ( sb ) ; } } +import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . util . * ; public class Main { public static void main ( String [ ] args ) { int i = 1 ; Scanner in = new Scanner ( new BufferedReader ( new InputStreamReader ( System . in ) ) ) ; int n = in . nextInt ( ) ; String [ ] array = new String [ n ] ; for ( int i = 0 ; i < n ; i ++ ) array [ i ] = in . next ( ) ; List < String > list = new ArrayList < > ( ) ; list . add ( array [ 0 ] ) ; char c = array [ 0 ] . charAt ( array [ 0 ] . length ( ) - 1 ) ; for ( int i = 1 ; i < n ; i ++ ) { if ( list . contains ( array [ i ] ) || array [ i ] . charAt ( 0 ) != c ) { System . out . println ( " No " ) ; return ; } c = array [ i ] . charAt ( array [ i ] . length ( ) - 1 ) ; list . add ( array [ i ] ) ; } System . out . println ( " Yes " ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; Set < Character > ODD_STEP = new HashSet < Character > ( ) ; Set < Character > EVEN_STEP = new HashSet < Character > ( ) ; String ODD_STEP_STR = " RUD " ; String EVEN_STEP_STR = " LUD " ; for ( int i = 0 ; i < 3 ; i ++ ) { ODD_STEP . add ( ODD_STEP_STR . charAt ( i ) ) ; EVEN_STEP . add ( EVEN_STEP_STR . charAt ( i ) ) ; } int current_step = 0 ; String steps = sc . next ( ) ; for ( int i = 0 ; i < steps . length ( ) ; i ++ ) { char step = steps . charAt ( i ) ; if ( ( i + 1 ) % 2 == 0 && ! EVEN_STEP . contains ( step ) ) { int i = 0 ; break ; } else if ( ( i + 1 ) % 2 != 0 && ! ODD_STEP . contains ( step ) ) { break ; } current_step ++ ; } if ( current_step == steps . length ( ) ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; Scanner scan = new Scanner ( System . in ) ; while ( true ) { int a = scan . nextInt ( ) ; int b = scan . nextInt ( ) ; if ( a == 0 && b == 0 ) break ; if ( a < b ) System . out . println ( a + " " + b ) ; else System . out . println ( b + " " + a ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { String s = ( new Scanner ( System . in ) ) . next ( ) ; char [ ] acgt = { 'A' , 'C' , 'G' , 'T' } ; int ans = 0 ; int tmp1 = 0 ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { int tmp2 = tmp1 ; for ( int j = 0 ; j < acgt . length ; j ++ ) { if ( s . charAt ( i ) == acgt [ j ] ) { int j = 0 ; ++ tmp1 ; break ; } } if ( tmp1 == tmp2 ) { ans = Math . max ( ans , tmp1 ) ; tmp1 = 0 ; } } ans = Math . max ( ans , tmp1 ) ; System . out . println ( ans ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { long i = 2 ; Scanner sc = new Scanner ( System . in ) ; long x = sc . nextLong ( ) ; sc . close ( ) ; long ret = x ; while ( true ) { if ( isPrime ( ret ) ) { break ; } ret ++ ; } System . out . println ( ret ) ; } public static boolean isPrime ( long x ) { if ( x == 1 || x == 2 ) { return true ; } if ( x % 2 == 0 ) { return false ; } boolean ret = false ; for ( long i = 2 ; i <= Math . sqrt ( x ) ; i ++ ) { if ( x % i == 0 ) { ret = false ; break ; } ret = true ; } return ret ; } } +import java . util . HashMap ; import java . util . Map ; import java . util . Scanner ; public class Main { public static void main ( String ... args ) { Scanner in = new Scanner ( System . in ) ; int n = in . nextInt ( ) ; int k = in . nextInt ( ) ; int q = in . nextInt ( ) ; int [ ] poinst = new int [ n ] ; for ( int i = 0 ; i < poinst . length ; i ++ ) { poinst [ i ] = k - q ; } for ( int i = 0 ; i < q ; i ++ ) { int a = in . nextInt ( ) ; poinst [ a - 1 ] = poinst [ a - 1 ] + 1 ; } StringBuilder sb = new StringBuilder ( ) ; for ( int i = 0 ; i < poinst . length ; i ++ ) { if ( poinst [ i ] > 0 ) { int i = 0 ; sb . append ( " Yes " + System . lineSeparator ( ) ) ; } else { sb . append ( " No " + System . lineSeparator ( ) ) ; } } System . out . print ( sb . toString ( ) ) ; } } +import java . io . * ; import java . util . * ; class Main { public static void main ( String [ ] args ) throws IOException { try ( BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ) { int i = 0 ; int num = Integer . parseInt ( br . readLine ( ) ) ; String [ ] str = br . readLine ( ) . split ( " " ) ; String [ ] str_1 = str [ 0 ] . split ( " " ) ; String [ ] str_2 = str [ 1 ] . split ( " " ) ; StringBuilder sb = new StringBuilder ( ) ; for ( int i = 0 ; i < num ; i ++ ) { sb . append ( str_1 [ i ] ) ; sb . append ( str_2 [ i ] ) ; } System . out . println ( sb ) ; } } } +import java . util . ArrayList ; import java . util . Collections ; import java . util . List ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; String a = sc . next ( ) ; String [ ] b = a . split ( " " ) ; List < String > word = new ArrayList < String > ( ) ; List < String > rev_word = new ArrayList < String > ( ) ; for ( int s = 0 ; s < b . length ; s ++ ) { word . add ( b [ s ] ) ; rev_word . add ( b [ s ] ) ; } Collections . reverse ( rev_word ) ; int count = 0 ; for ( int i = 0 ; i < word . size ( ) ; i ++ ) { if ( ! word . get ( i ) . equals ( rev_word . get ( i ) ) ) count ++ ; } System . out . println ( count / 2 ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int times = 1 ; while ( true ) { String str = br . readLine ( ) ; String [ ] s = str . split ( " " ) ; int [ ] n = new int [ s . length ] ; for ( int i = 0 ; i < s . length ; i ++ ) { n [ i ] = Integer . parseInt ( s [ i ] ) ; } if ( n [ 0 ] == 0 && n [ 1 ] == 0 ) { int i = 0 ; break ; } System . out . println ( Math . min ( n [ 0 ] , n [ 1 ] ) + " " + Math . max ( n [ 0 ] , n [ 1 ] ) ) ; times ++ ; } } } +import java . util . MissingResourceException ; import java . util . Scanner ; public class Main { public static void main ( String [ ] arg ) { Scanner sc = new Scanner ( System . in ) ; try { while ( true ) { String line = sc . next ( ) ; if ( line . equals ( " - " ) ) { break ; } int m = sc . nextInt ( ) ; for ( int i = 0 ; i < m ; i ++ ) { String line = sc . next ( ) ; int h = sc . nextInt ( ) ; line = line . substring ( h ) + line . substring ( 0 , h ) ; } System . out . println ( line ) ; } } catch ( MissingResourceException e ) { System . out . println ( e ) ; } sc . close ( ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; int n = Integer . parseInt ( sc . next ( ) ) ; int [ ] l = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { l [ i ] = Integer . parseInt ( sc . next ( ) ) ; } Arrays . sort ( l ) ; int max = Arrays . stream ( l ) . max ( ) . getAsInt ( ) ; int other = Arrays . stream ( l ) . sum ( ) - max ; String result = max < other ? " Yes " : " No " ; System . out . println ( result ) ; sc . close ( ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { String [ ] S = sc . next ( ) . split ( " - " ) ; Scanner sc = new Scanner ( System . in ) ; int A = Integer . parseInt ( sc . next ( ) ) ; int B = Integer . parseInt ( sc . next ( ) ) ; String [ ] S = sc . next ( ) . split ( " - " ) ; if ( S . length == 2 ) { if ( S [ 0 ] . length ( ) == A && S [ 1 ] . length ( ) == B ) { System . out . println ( " Yes " ) ; sc . close ( ) ; System . exit ( 0 ) ; } } System . out . println ( " No " ) ; sc . close ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int k = scan . nextInt ( ) ; long sum = 0 ; for ( int i = 1 ; i <= k ; i ++ ) { for ( int j = 1 ; j <= k ; j ++ ) { for ( int l = 1 ; l <= k ; l ++ ) { int first = gcd ( Math . max ( i , j ) , Math . min ( i , j ) ) ; int res = gcd ( Math . max ( first , l ) , Math . min ( first , l ) ) ; sum += res ; } } } System . out . println ( sum ) ; } private static int gcd ( int a , int b ) { int r = a % b ; int r = a % b ; if ( r == 0 ) { return b ; } else { return gcd ( b , r ) ; } } } +import java . util . Scanner ; import java . util . Arrays ; import java . lang . Math ; public class Main { public static void main ( String [ ] args ) { Integer result ; Scanner scanner = new Scanner ( System . in ) ; Integer a = Integer . parseInt ( scanner . next ( ) ) ; Integer b = Integer . parseInt ( scanner . next ( ) ) ; Integer result ; Integer total = Integer . sum ( a , b ) ; if ( total > 3 ) { result = Math . abs ( a - b ) ; } else { result = a + b ; } System . out . println ( result ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int b = 0 ; int [ ] d = new int [ a ] ; int [ ] e = new int [ a ] ; for ( int i = 0 ; i < a ; i ++ ) { d [ i ] = sc . nextInt ( ) ; d [ i ] -- ; e [ d [ i ] ] = i + 1 ; } for ( int i = 0 ; i < a ; i ++ ) { int i = 0 ; System . out . print ( e [ i ] + " " ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int a = scan . nextInt ( ) ; int b = scan . nextInt ( ) ; int c = scan . nextInt ( ) ; int x = scan . nextInt ( ) ; System . out . println ( ans ( a , b , c , x ) ) ; } static int ans ( int a , int b , int c , int x ) { int ans = 0 ; for ( int i = 0 ; i <= a ; i ++ ) { for ( int j = 0 ; j <= b ; j ++ ) { int k = 0 ; for ( int k = 0 ; k <= c ; k ++ ) { int work = i * 500 + j * 100 + k * 50 ; if ( work == x ) ans ++ ; } } } return ans ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; Scanner scanner = new Scanner ( System . in ) ; loop : while ( true ) { long a = scanner . nextInt ( ) ; String op = scanner . next ( ) ; long b = scanner . nextInt ( ) ; switch ( op ) { case " + " : System . out . println ( a + b ) ; break ; case " - " : System . out . println ( a - b ) ; break ; case " * " : System . out . println ( a * b ) ; break ; case " / " : System . out . println ( a / b ) ; break ; case " ? " : break loop ; } } scanner . close ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int m = sc . nextInt ( ) ; if ( m == 0 ) { System . out . println ( " 0 0 " ) ; return ; } String [ ] [ ] p = new String [ m ] [ 2 ] ; for ( int i = 0 ; i < m ; i ++ ) { p [ i ] [ 0 ] = sc . next ( ) ; p [ i ] [ 1 ] = sc . next ( ) ; } boolean [ ] acA = new boolean [ n + 1 ] ; int [ ] waA = new int [ n + 1 ] ; int wa = 0 ; int ac = 0 ; for ( int i = 0 ; i < m ; i ++ ) { int a = Integer . parseInt ( p [ i ] [ 0 ] ) ; int a = Integer . parseInt ( p [ i ] [ 0 ] ) ; if ( acA [ a ] ) continue ; if ( " WA " . equals ( p [ i ] [ 1 ] ) ) { waA [ a ] ++ ; } else { ac ++ ; wa += waA [ a ] ; acA [ a ] = true ; } } System . out . println ( ac + " " + wa ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner in = new Scanner ( System . in ) ; while ( true ) { String s = in . nextLine ( ) ; if ( s . equals ( " 0 " ) ) return ; long ans = 0 ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { ans += Integer . parseInt ( " " + s . charAt ( i ) ) ; } System . out . println ( ans ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String input = sc . nextLine ( ) ; sc . close ( ) ; int sa = ( int ) 'A' - ( int ) 'a' ; for ( char moji : input . toCharArray ( ) ) { if ( 'a' <= moji && moji <= 'z' ) { System . out . print ( ( char ) ( ( int ) moji + sa ) ) ; } else if ( 'A' <= moji && moji <= 'Z' ) { System . out . print ( ( char ) ( ( int ) moji - sa ) ) ; } else { char moji ; System . out . print ( moji ) ; } } System . out . println ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int N = scanner . nextInt ( ) ; int [ ] a = new int [ N ] ; int count = 0 ; int v = 1 ; int flg = 0 ; for ( int i = 0 ; i < N ; i ++ ) { int i = 0 ; a [ i ] = scanner . nextInt ( ) ; } for ( int i = 0 ; i < N ; i ++ ) { v = a [ v - 1 ] ; count ++ ; if ( v == 2 ) { System . out . println ( count ) ; count = 0 ; break ; } } if ( count == N ) { System . out . println ( - 1 ) ; } } } +import java . io . * ; import java . util . * ; 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 ; } } public class Main { public static PrintWriter out ; public static void main ( String [ ] args ) { MyScanner sc = new MyScanner ( ) ; out = new PrintWriter ( new BufferedOutputStream ( System . out ) ) ; int s = sc . nextInt ( ) ; int w = sc . nextInt ( ) ; if ( w >= s ) { out . println ( " unsafe " ) ; } else { out . println ( " safe " ) ; } out . close ( ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . StringTokenizer ; import java . lang . Math ; public class Main { static class FastReader { BufferedReader br ; StringTokenizer st ; public FastReader ( ) { br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; } String next ( ) { while ( st == null || ! st . hasMoreElements ( ) ) { try { st = new StringTokenizer ( br . readLine ( ) ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } return st . nextToken ( ) ; } int nextInt ( ) { int i = 1 ; return Integer . parseInt ( next ( ) ) ; } long nextLong ( ) { return Long . parseLong ( next ( ) ) ; } } public static void main ( String [ ] args ) { FastReader ob = new FastReader ( ) ; int a = ob . nextInt ( ) , b = ob . nextInt ( ) ; for ( int i = 1 ; i <= 10000 ; i ++ ) { double k1 = Math . floor ( ( double ) i * 0.08 ) ; double k2 = Math . floor ( ( double ) i * 0.1 ) ; if ( k1 == a && k2 == b ) { System . out . println ( i ) ; return ; } } System . out . println ( " -1 " ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int A = Integer . parseInt ( sc . next ( ) ) ; int B = Integer . parseInt ( sc . next ( ) ) ; sc . close ( ) ; int count = 0 ; for ( int i = A ; i <= B ; i ++ ) { int i = A ; String tmp = String . valueOf ( i ) ; if ( tmp . charAt ( 0 ) == tmp . charAt ( 4 ) && tmp . charAt ( 1 ) == tmp . charAt ( 3 ) ) { count ++ ; } } System . out . println ( count ) ; } } +import java . util . Scanner ; class Main { public void cubic ( ) { Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int c = sc . nextInt ( ) ; String out = " No " ; if ( a < b ) { if ( b < c ) { out = " Yes " ; } } System . out . println ( out ) ; } public static void main ( String [ ] args ) { String out = " No " ; new Main ( ) . cubic ( ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int numA = scanner . nextInt ( ) ; int numB = scanner . nextInt ( ) ; int numC = scanner . nextInt ( ) ; int ans = 0 ; for ( int val = numA ; val <= numB ; val ++ ) { int val = numA ; if ( numC % val == 0 ) ans ++ ; } System . out . println ( ans ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; String [ ] line = sc . nextLine ( ) . split ( " " ) ; int K = Integer . parseInt ( line [ 0 ] ) ; int S = Integer . parseInt ( line [ 1 ] ) ; int ans = 0 ; for ( int x = 0 ; x <= K ; x ++ ) { int y = 0 ; for ( int y = 0 ; y <= K ; y ++ ) { int target = S - x - y ; if ( target >= 0 && target <= K ) { ans ++ ; } } } System . out . println ( ans ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; double ans1 = 0 ; for ( int i = 0 ; i < N ; i ++ ) { double ans1 = 0 ; ans1 += 1 / ( double ) sc . nextInt ( ) ; } sc . close ( ) ; double ans2 = ( 1 / ans1 ) ; System . out . println ( ans2 ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { double average = ( double ) sum / n ; Scanner scan = new Scanner ( System . in ) ; while ( true ) { int n = scan . nextInt ( ) ; if ( n == 0 ) { break ; } double [ ] s = new double [ n ] ; int i = 0 ; double sum = 0 ; double sumHensa = 0 ; double ans = 0 ; for ( i = 0 ; i < n ; i ++ ) { s [ i ] = scan . nextDouble ( ) ; sum += s [ i ] ; } double average = ( double ) sum / n ; for ( i = 0 ; i < n ; i ++ ) { sumHensa += ( s [ i ] - average ) * ( s [ i ] - average ) ; } ans = Math . sqrt ( ( double ) sumHensa / n ) ; System . out . println ( ans ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { try ( Scanner in = new Scanner ( System . in ) ) { int c = 1 ; int [ ] [ ] C = new int [ 3 ] [ 3 ] ; for ( int r = 0 ; r < 3 ; r ++ ) { for ( int c = 0 ; c < 3 ; c ++ ) { C [ r ] [ c ] = in . nextInt ( ) ; } } int [ ] a = new int [ 3 ] ; int [ ] b = new int [ 3 ] ; int [ ] [ ] a2 = new int [ 3 ] [ 3 ] ; a [ 0 ] = 0 ; for ( int c = 0 ; c < 3 ; c ++ ) { b [ c ] = C [ 0 ] [ c ] - a [ 0 ] ; } for ( int r = 0 ; r < 3 ; r ++ ) { for ( int c = 0 ; c < 3 ; c ++ ) { a2 [ r ] [ c ] = C [ r ] [ c ] - b [ c ] ; } } for ( int r = 0 ; r < 3 ; r ++ ) { for ( int c = 1 ; c < 3 ; c ++ ) { if ( a2 [ r ] [ c - 1 ] != a2 [ r ] [ c ] ) { System . out . println ( " No " ) ; return ; } } } System . out . println ( " Yes " ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] h = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { h [ i ] = sc . nextInt ( ) ; } int cnt = 1 ; int max = h [ 0 ] ; for ( int i = 0 ; i < n - 1 ; i ++ ) { if ( max <= h [ i + 1 ] ) { int i = 0 ; cnt ++ ; max = h [ i + 1 ] ; } } System . out . println ( cnt ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; char [ ] ary = sc . next ( ) . toCharArray ( ) ; int ans = 0 ; for ( int i = 0 ; i < 4 ; i ++ ) { if ( ary [ i ] == '+' ) { ans ++ ; } else { int i = 0 ; ans -- ; } } sc . close ( ) ; System . out . println ( ans ) ; } } +import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner inData = new Scanner ( System . in ) ; int N = inData . nextInt ( ) ; int K = inData . nextInt ( ) ; int [ ] P = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) P [ i ] = inData . nextInt ( ) ; Arrays . sort ( P ) ; int kin = 0 ; for ( int i = 0 ; i < K ; i ++ ) { int i = 0 ; kin += P [ i ] ; } System . out . println ( kin ) ; inData . close ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws Exception { String t_word ; Scanner sc = new Scanner ( System . in ) ; String word = sc . nextLine ( ) ; int count = 0 ; while ( true ) { String text = sc . nextLine ( ) ; if ( text . equals ( " END_OF_TEXT " ) ) { break ; } String [ ] t = text . split ( " " ) ; for ( String t_word : t ) { if ( t_word . equalsIgnoreCase ( word ) ) { count ++ ; } } } System . out . println ( count ) ; } } +import java . util . * ; import java . util . Collections ; public class Main { public static void main ( String [ ] args ) { HashSet < Integer > A = new HashSet < Integer > ( ) ; Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; HashSet < Integer > A = new HashSet < Integer > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { A . add ( sc . nextInt ( ) ) ; } System . out . println ( A . size ( ) ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws IOException { int ans = Rmin - Lmax + 1 ; BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String [ ] str = br . readLine ( ) . split ( " " ) ; int N = Integer . parseInt ( str [ 0 ] ) ; int M = Integer . parseInt ( str [ 1 ] ) ; int [ ] L = new int [ M ] ; int [ ] R = new int [ M ] ; int Lmax = 0 ; int Rmin = 0 ; for ( int i = 0 ; i < M ; i ++ ) { String [ ] str1 = br . readLine ( ) . split ( " " ) ; L [ i ] = Integer . parseInt ( str1 [ 0 ] ) ; R [ i ] = Integer . parseInt ( str1 [ 1 ] ) ; if ( L [ i ] > Lmax ) { Lmax = L [ i ] ; } if ( i == 0 ) { Rmin = R [ i ] ; } if ( R [ i ] < Rmin ) { Rmin = R [ i ] ; } } int ans = Rmin - Lmax + 1 ; if ( ans > 0 ) { System . out . print ( ans ) ; } else { System . out . print ( 0 ) ; } } } +import java . io . InputStream ; import java . io . IOException ; import java . util . HashSet ; class MyScanner { InputStream stream ; public MyScanner ( ) { stream = System . in ; } public int nextInt ( ) { int ret = 0 ; try { int j = 0 ; while ( true ) { char readed = ( char ) stream . read ( ) ; if ( readed < '0' || readed > '9' ) { break ; } ret = ret * 10 + ( readed - '0' ) ; } } catch ( IOException e ) { e . printStackTrace ( ) ; } finally { return ret ; } } } class Main { public static void main ( String [ ] args ) { MyScanner sc = new MyScanner ( ) ; HashSet < Integer > set = new HashSet < Integer > ( ) ; int n = sc . nextInt ( ) , m = sc . nextInt ( ) ; boolean [ ] selected = new boolean [ m ] ; for ( int i = 0 ; i < m ; i ++ ) { set . add ( i ) ; } for ( int i = 0 ; i < n ; ++ i ) { for ( int j = 0 ; j < m ; ++ j ) { selected [ j ] = true ; } int c = sc . nextInt ( ) ; for ( int j = 0 ; j < c ; ++ j ) { selected [ sc . nextInt ( ) - 1 ] = false ; } for ( int j = 0 ; j < m ; ++ j ) { if ( selected [ j ] ) { set . remove ( j ) ; } } } System . out . println ( set . size ( ) ) ; } } +import java . io . InputStream ; import java . io . PrintStream ; import java . math . BigDecimal ; 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 ) ; long W = sc . nextInt ( ) ; long H = sc . nextInt ( ) ; long x = sc . nextInt ( ) ; long y = sc . nextInt ( ) ; sc . close ( ) ; String a = BigDecimal . valueOf ( ( ( double ) W * H ) / 2.0 ) . toPlainString ( ) ; out . print ( a ) ; out . print ( " " ) ; if ( W == x * 2 && H == y * 2 ) { out . println ( " 1 " ) ; } else { out . println ( " 0 " ) ; } } public static void main ( String [ ] args ) { new Main ( ) . _main ( args ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int numFriends = sc . nextInt ( ) ; int cent = sc . nextInt ( ) ; int yes = 0 ; for ( int i = 0 ; i < numFriends ; i ++ ) { int yes = 0 ; int height = sc . nextInt ( ) ; if ( height >= cent ) { yes ++ ; } } System . out . print ( yes ) ; } } +import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner s = new Scanner ( System . in ) ; int X = s . nextInt ( ) ; int N = s . nextInt ( ) ; int [ ] p = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { p [ i ] = s . nextInt ( ) ; } int ans = 0 ; Arrays . sort ( p ) ; for ( int i = 0 ; i <= 101 ; i ++ ) { boolean include = false ; for ( int k = 0 ; k < p . length ; k ++ ) { int k = 0 ; if ( i == p [ k ] ) { include = true ; break ; } } if ( ! include && Math . abs ( X - ans ) > Math . abs ( X - i ) ) { ans = i ; } } System . out . println ( ans ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int j = i ; Main main = new Main ( ) ; main . run ( ) ; } public void run ( ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int k = sc . nextInt ( ) ; double ans = 0.0 ; for ( int i = 1 ; i <= n ; i ++ ) { int x = 1 ; int j = i ; while ( j < k ) { x *= 2 ; j *= 2 ; } x *= n ; ans += ( double ) 1 / ( double ) x ; } System . out . println ( ans ) ; sc . close ( ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int n = scan . nextInt ( ) ; int [ ] a = new int [ n + 1 ] ; for ( int i = 1 ; i < n ; i ++ ) { int i = 1 ; int j = scan . nextInt ( ) ; a [ j ] ++ ; } for ( int i = 1 ; i < n + 1 ; i ++ ) { System . out . println ( a [ i ] ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int k = sc . nextInt ( ) ; Set < Integer > set = new HashSet < > ( ) ; for ( int i = 0 ; i < k ; i ++ ) { int snack = sc . nextInt ( ) ; for ( int j = 0 ; j < snack ; j ++ ) { Set < Integer > set = new HashSet < > ( ) ; int people = sc . nextInt ( ) ; set . add ( people ) ; } } System . out . println ( n - set . size ( ) ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { try ( Scanner sc = new Scanner ( System . in ) ) { int n = sc . nextInt ( ) ; int [ ] d = new int [ 100001 ] ; for ( int i = 0 ; i < n ; i ++ ) { d [ sc . nextInt ( ) ] ++ ; } int tmp = 0 ; int cnt = 0 ; for ( int i = 0 ; i < 100001 ; i ++ ) { int i = 0 ; tmp += d [ i ] ; if ( n == tmp * 2 ) { cnt ++ ; } else if ( n < tmp * 2 ) { break ; } } System . out . println ( cnt ) ; } } } +import java . util . * ; public class Main { static boolean [ ] targetNumbers ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int X = sc . nextInt ( ) ; printPrimeNumbers2 ( 1000000 ) ; for ( int i = X ; i <= 1000000 ; i ++ ) { if ( targetNumbers [ i ] ) { System . out . println ( i ) ; System . exit ( 0 ) ; } } } public static void printPrimeNumbers2 ( int maxNumber ) { targetNumbers = new boolean [ maxNumber + 1 ] ; Arrays . fill ( targetNumbers , true ) ; targetNumbers [ 0 ] = false ; targetNumbers [ 1 ] = false ; List < Integer > primeNumbers = new ArrayList < Integer > ( ) ; int sqrt = ( int ) Math . sqrt ( maxNumber ) ; for ( int i = 2 ; i <= sqrt ; i ++ ) { if ( targetNumbers [ i ] ) { int i = 2 ; for ( int j = 2 ; i * j <= maxNumber ; j ++ ) { targetNumbers [ i * j ] = false ; } } } for ( int i = 2 ; i < targetNumbers . length ; i ++ ) { if ( targetNumbers [ i ] ) { primeNumbers . add ( i ) ; } } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; while ( true ) { int k = j + 1 ; int n = sc . nextInt ( ) ; int x = sc . nextInt ( ) ; int ans = 0 ; if ( n == 0 && x == 0 ) break ; for ( int i = 1 ; i < n + 1 ; i ++ ) { for ( int j = i + 1 ; j < n + 1 ; j ++ ) { for ( int k = j + 1 ; k < n + 1 ; k ++ ) { if ( i + j + k == x ) ans ++ ; } } } System . out . println ( ans ) ; } } } +import java . util . * ; public class Main { private static final Scanner scn = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { int a = scn . nextInt ( ) , b = scn . nextInt ( ) , c = scn . nextInt ( ) ; System . out . println ( a < b && b < c ? " Yes " : " No " ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int A , B , C , D ; Scanner scan = new Scanner ( System . in ) ; A = scan . nextInt ( ) ; B = scan . nextInt ( ) ; C = scan . nextInt ( ) ; D = scan . nextInt ( ) ; while ( true ) { if ( A <= 0 || C <= 0 ) break ; C -= B ; if ( A <= 0 || C <= 0 ) break ; A -= D ; } if ( C <= 0 ) { System . out . println ( " Yes " ) ; } else { int A , B , C , D ; System . out . println ( " No " ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; String t = sc . next ( ) ; if ( s . indexOf ( t ) != - 1 ) { System . out . println ( 0 ) ; } else { int i = 0 ; int min = Integer . MAX_VALUE ; for ( int i = 0 ; i <= s . length ( ) - t . length ( ) ; i ++ ) { if ( min > helper ( s . substring ( i , i + t . length ( ) ) , t ) ) { min = helper ( s . substring ( i , i + t . length ( ) ) , t ) ; } } System . out . println ( min ) ; } } public static int helper ( String s1 , String s2 ) { int count = 0 ; for ( int i = 0 ; i < s1 . length ( ) ; i ++ ) { if ( s1 . charAt ( i ) != s2 . charAt ( i ) ) { count ++ ; } } return count ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] array = new int [ n ] ; int [ ] DP = new int [ n + 1 ] ; Arrays . fill ( DP , Integer . MAX_VALUE ) ; DP [ 0 ] = 0 ; for ( int i = 0 ; i < n ; i ++ ) { array [ i ] = sc . nextInt ( ) ; } for ( int i = 0 ; i < n - 2 ; i ++ ) { int i = 0 ; DP [ i + 1 ] = Math . min ( DP [ i + 1 ] , DP [ i ] + Math . abs ( array [ i + 1 ] - array [ i ] ) ) ; DP [ i + 2 ] = Math . min ( DP [ i + 2 ] , DP [ i ] + Math . abs ( array [ i + 2 ] - array [ i ] ) ) ; } DP [ n - 1 ] = Math . min ( DP [ n - 1 ] , DP [ n - 2 ] + Math . abs ( array [ n - 1 ] - array [ n - 2 ] ) ) ; System . out . println ( DP [ n - 1 ] ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int min = Integer . MAX_VALUE ; for ( int i = 0 ; i < n ; i ++ ) { int a = sc . nextInt ( ) ; int c = 0 ; while ( a % 2 == 0 ) { int c = 0 ; a /= 2 ; c ++ ; } if ( c < min ) min = c ; } System . out . println ( min ) ; } } +import java . util . ArrayList ; import java . util . List ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner stdIn = new Scanner ( System . in ) ; int n = stdIn . nextInt ( ) ; int [ ] d = new int [ n ] ; List < Integer > list = new ArrayList < > ( ) ; int cnt = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int a = stdIn . nextInt ( ) ; if ( ! list . contains ( a ) ) { int a = stdIn . nextInt ( ) ; list . add ( a ) ; cnt ++ ; } } System . out . println ( cnt ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . StringTokenizer ; public class Main { public static void main ( String [ ] args ) { FastReader sc = new FastReader ( ) ; long n = sc . nextLong ( ) ; int m = sc . nextInt ( ) ; long sum = 0 ; for ( int i = 0 ; i < m ; i ++ ) sum += sc . nextLong ( ) ; System . out . println ( ( sum <= n ) ? n - sum : " -1 " ) ; } static class FastReader { BufferedReader br ; StringTokenizer st ; public FastReader ( ) { br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; } String next ( ) { String str = " " ; while ( st == null || ! st . hasMoreElements ( ) ) { try { st = new StringTokenizer ( br . readLine ( ) ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } return st . nextToken ( ) ; } int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } long nextLong ( ) { return Long . parseLong ( next ( ) ) ; } double nextDouble ( ) { return Double . parseDouble ( next ( ) ) ; } String nextLine ( ) { String str = " " ; try { str = br . readLine ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } return str ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; List < Integer > listN = new ArrayList < Integer > ( ) ; List < Integer > listX = new ArrayList < Integer > ( ) ; for ( ; ; ) { int n = scan . nextInt ( ) ; int x = scan . nextInt ( ) ; if ( ( n == 0 ) && ( x == 0 ) ) { break ; } listN . add ( n ) ; listX . add ( x ) ; } for ( int i = 0 ; i < listN . size ( ) ; i ++ ) { int n = listN . get ( i ) ; int x = listX . get ( i ) ; int cnt = 0 ; for ( int a = 1 ; a <= n ; a ++ ) { for ( int b = a + 1 ; b <= n ; b ++ ) { for ( int c = b + 1 ; c <= n ; c ++ ) { int sum = a + b + c ; if ( sum == x ) { int c = b + 1 ; cnt ++ ; } } } } System . out . println ( cnt ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { @ SuppressWarnings ( " resource " ) Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int m = sc . nextInt ( ) ; int [ ] p = new int [ m ] ; String [ ] s = new String [ m ] ; for ( int i = 0 ; i < m ; i ++ ) { p [ i ] = sc . nextInt ( ) - 1 ; s [ i ] = sc . next ( ) ; } int [ ] [ ] a = new int [ 2 ] [ n ] ; for ( int i = 0 ; i < m ; i ++ ) { if ( s [ i ] . equals ( " WA " ) && a [ 1 ] [ p [ i ] ] == 0 ) { a [ 0 ] [ p [ i ] ] ++ ; } if ( s [ i ] . equals ( " AC " ) && a [ 1 ] [ p [ i ] ] == 0 ) { int i = 0 ; a [ 1 ] [ p [ i ] ] ++ ; } } int ac = 0 ; int wa = 0 ; for ( int i = 0 ; i < n ; i ++ ) { ac += a [ 1 ] [ i ] ; if ( a [ 1 ] [ i ] == 1 ) { wa += a [ 0 ] [ i ] ; } } System . out . println ( ac + " " + wa ) ; } } +import java . util . ArrayList ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = numList . size ( ) - 1 ; Scanner sc = new Scanner ( System . in ) ; long num = sc . nextLong ( ) ; ArrayList < Integer > numList = new ArrayList < Integer > ( ) ; while ( true ) { int digit = ( int ) ( num % 26L ) ; if ( digit == 0 ) { digit = 26 ; } numList . add ( digit + 96 ) ; num = ( num - digit ) / 26L ; if ( num == 0 ) { break ; } } for ( int i = numList . size ( ) - 1 ; i >= 0 ; i -- ) { int let = ( int ) numList . get ( i ) ; char c = ( char ) let ; System . out . print ( c ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int j = 1 ; Scanner sc = new Scanner ( System . in ) ; while ( true ) { int H = sc . nextInt ( ) ; int W = sc . nextInt ( ) ; if ( H == 0 && W == 0 ) break ; for ( int i = 1 ; i <= H ; i ++ ) { for ( int j = 1 ; j <= W ; j ++ ) { if ( i % 2 == 1 ) { if ( j % 2 == 1 ) System . out . print ( " # " ) ; else System . out . print ( " . " ) ; } else { if ( j % 2 == 1 ) System . out . print ( " . " ) ; else System . out . print ( " # " ) ; } } System . out . println ( ) ; } System . out . println ( ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner scanner = new Scanner ( System . in ) ; String S = scanner . next ( ) ; int count = 0 ; int max = 0 ; for ( int i = 0 ; i < S . length ( ) ; i ++ ) { if ( S . charAt ( i ) == 'A' || S . charAt ( i ) == 'G' || S . charAt ( i ) == 'C' || S . charAt ( i ) == 'T' ) { count ++ ; if ( max <= count ) { max = count ; } } else { int i = 0 ; count = 0 ; } } System . out . println ( max ) ; } } +import java . util . ArrayList ; import java . util . Collections ; import java . util . List ; import java . util . Scanner ; public class Main { private void solve ( ) { Scanner sc = new Scanner ( System . in ) ; String S = sc . next ( ) ; char [ ] charArray = S . toCharArray ( ) ; List < Integer > counts = new ArrayList < Integer > ( ) ; int cnt = 0 ; for ( int i = 0 ; i < charArray . length ; i ++ ) { if ( charArray [ i ] == 'A' || charArray [ i ] == 'C' || charArray [ i ] == 'G' || charArray [ i ] == 'T' ) { cnt ++ ; if ( i == charArray . length - 1 ) { counts . add ( cnt ) ; } } else { if ( cnt != 0 ) { counts . add ( cnt ) ; cnt = 0 ; } } } Collections . sort ( counts , Collections . reverseOrder ( ) ) ; if ( counts . size ( ) == 0 ) { System . out . print ( 0 ) ; } else { System . out . print ( counts . get ( 0 ) ) ; } } public static void main ( String [ ] args ) { int i = 0 ; new Main ( ) . solve ( ) ; } } +public class Main { public static void main ( String [ ] args ) { try ( java . util . Scanner sc = new java . util . Scanner ( System . in ) ) { String s = sc . next ( ) ; String p = sc . next ( ) ; int cnt = 0 ; while ( cnt != s . length ( ) ) { if ( s . contains ( p ) ) { int cnt = 0 ; System . out . println ( " Yes " ) ; return ; } s = s . substring ( 1 ) + s . charAt ( 0 ) ; cnt ++ ; } System . out . println ( " No " ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner scan = new Scanner ( System . in ) ; int n = scan . nextInt ( ) ; String s = scan . next ( ) ; int out = s . length ( ) ; for ( int i = 0 ; i < s . length ( ) - 1 ; i ++ ) { if ( s . charAt ( i ) == s . charAt ( i + 1 ) ) out -- ; } System . out . println ( out ) ; scan . close ( ) ; } } +import java . util . * ; import java . math . BigInteger ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int k = sc . nextInt ( ) ; boolean [ ] sunukes = new boolean [ n ] ; for ( int i = 0 ; i < k ; i ++ ) { int d = sc . nextInt ( ) ; for ( int j = 0 ; j < d ; j ++ ) { boolean hasSweets ; sunukes [ sc . nextInt ( ) - 1 ] = true ; } } int ans = 0 ; for ( boolean hasSweets : sunukes ) { if ( hasSweets ) continue ; ans ++ ; } System . out . println ( ans ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . ArrayDeque ; import java . util . Queue ; public class Main { public static void main ( String [ ] args ) throws NumberFormatException , IOException { BufferedReader reader = new BufferedReader ( new InputStreamReader ( System . in ) ) ; StringBuilder builder = new StringBuilder ( ) ; String [ ] line = reader . readLine ( ) . split ( " " ) ; int n = Integer . parseInt ( line [ 0 ] ) ; int q = Integer . parseInt ( line [ 1 ] ) ; Queue < String [ ] > queue = new ArrayDeque < String [ ] > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { queue . add ( reader . readLine ( ) . split ( " " ) ) ; } String [ ] work = new String [ 2 ] ; int elapse = 0 ; while ( ( work = queue . poll ( ) ) != null ) { int time = Integer . parseInt ( work [ 1 ] ) ; if ( time <= q ) { int time = Integer . parseInt ( work [ 1 ] ) ; elapse += time ; builder . append ( work [ 0 ] ) . append ( " " ) . append ( elapse ) . append ( " \n " ) ; } else { time -= q ; elapse += q ; work [ 1 ] = String . valueOf ( time ) ; queue . add ( work ) ; } } System . out . print ( builder ) ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int ans = 0 ; int [ ] [ ] nums = new int [ 3 ] [ 3 ] ; for ( int i = 0 ; i < 9 ; i ++ ) { int i = 0 ; nums [ i / 3 ] [ i % 3 ] = sc . nextInt ( ) ; } System . out . println ( nums [ 1 ] [ 0 ] - nums [ 0 ] [ 0 ] == nums [ 1 ] [ 1 ] - nums [ 0 ] [ 1 ] && nums [ 1 ] [ 1 ] - nums [ 0 ] [ 1 ] == nums [ 1 ] [ 2 ] - nums [ 0 ] [ 2 ] && nums [ 2 ] [ 0 ] - nums [ 1 ] [ 0 ] == nums [ 2 ] [ 1 ] - nums [ 1 ] [ 1 ] && nums [ 2 ] [ 1 ] - nums [ 1 ] [ 1 ] == nums [ 2 ] [ 2 ] - nums [ 1 ] [ 2 ] ? " Yes " : " No " ) ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) , count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( sc . nextInt ( ) == count + 1 ) { int n = sc . nextInt ( ) , count = 0 ; count ++ ; } } System . out . println ( count == 0 ? - 1 : n - count ) ; } } +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 ) ; abc134_b solver = new abc134_b ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class abc134_b { public void solve ( int testNumber , Scanner in , PrintWriter out ) { int mans = ( int ) Math . ceil ( N / ( ( D * 2 ) + 1 ) ) ; int N = in . nextInt ( ) ; int D = in . nextInt ( ) ; int mans = ( int ) Math . ceil ( N / ( ( D * 2 ) + 1 ) ) ; if ( N % ( ( D * 2 ) + 1 ) != 0 ) { mans ++ ; } out . println ( mans ) ; } } } +import java . util . HashSet ; import java . util . Scanner ; import java . util . Set ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long n = sc . nextLong ( ) ; Set < Long > numSet = new HashSet < > ( ) ; boolean hasSame = false ; for ( int i = 0 ; i < n ; i ++ ) { Long num = sc . nextLong ( ) ; if ( numSet . contains ( num ) ) { Long num = sc . nextLong ( ) ; hasSame = true ; break ; } else { numSet . add ( num ) ; } } System . out . println ( hasSame ? " NO " : " YES " ) ; sc . close ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int [ ] [ ] [ ] BigHouse = new int [ 4 ] [ 3 ] [ 10 ] ; for ( int i = 0 ; i < 4 ; i ++ ) { for ( int j = 0 ; j < 3 ; j ++ ) { for ( int k = 0 ; k < 10 ; k ++ ) { BigHouse [ i ] [ j ] [ k ] = 0 ; } } } int order = sc . nextInt ( ) ; for ( int i = 0 ; i < order ; i ++ ) { int b = sc . nextInt ( ) - 1 ; int f = sc . nextInt ( ) - 1 ; int r = sc . nextInt ( ) - 1 ; int v = sc . nextInt ( ) ; BigHouse [ b ] [ f ] [ r ] += v ; if ( BigHouse [ b ] [ f ] [ r ] < 0 ) { BigHouse [ b ] [ f ] [ r ] = 0 ; } } for ( int i = 0 ; i < 4 ; i ++ ) { int k = 0 ; for ( int j = 0 ; j < 3 ; j ++ ) { for ( int k = 0 ; k < 10 ; k ++ ) { System . out . print ( " " + BigHouse [ i ] [ j ] [ k ] ) ; } System . out . println ( ) ; } if ( i != 3 ) { System . out . println ( " #################### " ) ; } } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner ob = new Scanner ( System . in ) ; int n = ob . nextInt ( ) ; int k = ob . nextInt ( ) ; int [ ] a = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = ob . nextInt ( ) ; } int min = 0 ; int [ ] arr = new int [ n ] ; arr [ 0 ] = 0 ; arr [ 1 ] = Math . abs ( a [ 1 ] - a [ 0 ] ) ; for ( int i = 2 ; i < a . length ; i ++ ) { int j = 1 ; min = Integer . MAX_VALUE ; for ( int j = 1 ; j <= k ; j ++ ) { if ( i - j >= 0 ) { min = Math . min ( arr [ i - j ] + Math . abs ( a [ i ] - a [ i - j ] ) , min ) ; } } arr [ i ] = min ; } System . out . println ( arr [ n - 1 ] ) ; ob . close ( ) ; } } +import java . util . Scanner ; public class Main { public static int eukleides ( int a , int b ) { if ( b % a == 0 ) { return a ; } int mod = b % a ; return eukleides ( mod , a ) ; } public static void main ( String [ ] args ) { int i = gcd ; Scanner scan = new Scanner ( System . in ) ; int a = scan . nextInt ( ) ; int b = scan . nextInt ( ) ; int border = scan . nextInt ( ) ; int gcd = eukleides ( Math . min ( a , b ) , Math . max ( a , b ) ) ; int count = 0 ; for ( int i = gcd ; i >= 1 ; i -- ) { if ( gcd % i == 0 ) { count ++ ; } if ( count == border ) { System . out . println ( i ) ; break ; } } } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) { try { BufferedReader reader = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String s = reader . readLine ( ) ; int n = Integer . parseInt ( s ) ; String t = reader . readLine ( ) ; String [ ] u = t . split ( " " ) ; int [ ] m = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { m [ i ] = Integer . parseInt ( u [ i ] ) ; } for ( int j = n - 1 ; j > - 1 ; j -- ) { int j = n - 1 ; System . out . print ( m [ j ] ) ; if ( j != 0 ) { System . out . print ( " " ) ; } } System . out . println ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } } +import java . io . PrintWriter ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 1 ; Scanner sc = new Scanner ( System . in ) ; int N = Integer . parseInt ( sc . next ( ) ) ; int count = 0 ; for ( int i = 1 ; i <= N ; i ++ ) { if ( String . valueOf ( i ) . length ( ) == 1 ) { count ++ ; } else if ( String . valueOf ( i ) . length ( ) % 2 != 0 ) { count ++ ; } } PrintWriter out = new PrintWriter ( System . out ) ; out . println ( count ) ; out . flush ( ) ; sc . close ( ) ; } } +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 ( ) ; if ( a <= b ) { String stringA = String . valueOf ( a ) ; for ( int i = 1 ; i < b ; i ++ ) { stringA += a ; } System . out . println ( stringA ) ; } else { int i = 1 ; String stringB = String . valueOf ( b ) ; for ( int i = 1 ; i < a ; i ++ ) { stringB += b ; } System . out . println ( stringB ) ; } sc . close ( ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String strs = sc . next ( ) ; String strp = sc . next ( ) ; int snum = strs . length ( ) ; int psum = strp . length ( ) ; for ( int p = 0 ; p < snum ; p ++ ) { int s = 0 ; String str1 = " " ; String str2 = " " ; String str3 = " " ; for ( int q = p ; q < snum ; q ++ ) { char c1 = strs . charAt ( q ) ; str1 += c1 ; } for ( int r = 0 ; r < p ; r ++ ) { char c2 = strs . charAt ( r ) ; str2 += c2 ; } for ( int s = 0 ; s < psum ; s ++ ) { char c3 = ( str1 + str2 ) . charAt ( s ) ; str3 += c3 ; } if ( str3 . equals ( strp ) ) { System . out . println ( " Yes " ) ; break ; } else if ( p == snum - 1 ) { System . out . println ( " No " ) ; } } } } +import java . io . BufferedReader ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws Exception { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String s = br . readLine ( ) ; int a = 0 ; int z = 0 ; while ( s . charAt ( a ) != 'A' ) { a ++ ; } for ( int i = a + 1 ; i < s . length ( ) ; i ++ ) { int i = a + 1 ; if ( s . charAt ( i ) == 'Z' ) { z = i ; } } System . out . println ( z - a + 1 ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int [ ] h = new int [ N ] ; int max = 0 ; int idx = 0 ; for ( int i = 0 ; i < N ; i ++ ) { h [ i ] = sc . nextInt ( ) ; if ( h [ i ] > max ) { max = h [ i ] ; idx = i ; } } int max2 = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( i != idx ) { if ( h [ i ] > max2 ) { max2 = h [ i ] ; } } } for ( int i = 0 ; i < N ; i ++ ) { int i = 0 ; if ( i != idx ) { System . out . println ( max ) ; } else { System . out . println ( max2 ) ; } } } } +import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . util . ArrayList ; import java . util . Arrays ; import java . util . HashMap ; import java . util . HashSet ; import java . util . List ; import java . util . Map ; import java . util . Map . Entry ; import java . util . Scanner ; import java . util . Set ; public class Main { static long MOD = 1_000_000_007 ; public static void main ( String [ ] args ) throws Exception { long temp ; int INF = Integer . MAX_VALUE ; Scanner sc = new Scanner ( System . in ) ; int N = Integer . parseInt ( sc . next ( ) ) ; int [ ] P = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { P [ i ] = Integer . parseInt ( sc . next ( ) ) ; } int ans = 0 ; for ( int i = 1 ; i < N - 1 ; i ++ ) { if ( ( P [ i - 1 ] > P [ i ] && P [ i ] > P [ i + 1 ] ) || ( P [ i - 1 ] < P [ i ] && P [ i ] < P [ i + 1 ] ) ) ans ++ ; } System . out . println ( ans ) ; } static long lcm ( long a , long b ) { long temp ; long c = a ; c *= b ; while ( ( temp = a % b ) != 0 ) { a = b ; b = temp ; } return ( c / b ) ; } } +import java . util . * ; import static java . lang . Math . ceil ; class Main { public static void main ( String [ ] args ) { Scanner input = new Scanner ( System . in ) ; int health = input . nextInt ( ) ; int n = input . nextInt ( ) ; Vector < Integer > a = new Vector < > ( n ) ; int sum = 0 ; for ( int i = 0 ; i < n ; ++ i ) { int x = input . nextInt ( ) ; a . add ( x ) ; } for ( int i = 0 ; i < n ; ++ i ) { int i = 0 ; sum += a . get ( i ) ; } if ( sum >= health ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 1 ; Scanner scan = new Scanner ( System . in ) ; int a = scan . nextInt ( ) ; int b = scan . nextInt ( ) ; int min = 0 ; for ( int i = 1 ; i <= 1009 ; i ++ ) { if ( ( int ) ( i * 0.08 ) == a && ( int ) ( i * 0.1 ) == b ) { min = i ; break ; } else { min = - 1 ; } } System . out . println ( min ) ; scan . close ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 1 ; Scanner sc = new Scanner ( System . in ) ; int A = sc . nextInt ( ) ; int B = sc . nextInt ( ) ; sc . close ( ) ; int s = - 1 ; for ( int i = 1 ; i <= 1009 ; i ++ ) { if ( ( int ) ( i * 0.08 ) == A && ( int ) ( i * 0.1 ) == B ) { s = i ; break ; } } System . out . println ( s ) ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { int n , ans ; Scanner sc = new Scanner ( System . in ) ; int n , ans ; while ( sc . hasNext ( ) ) { n = sc . nextInt ( ) ; ans = 100000 ; for ( int i = 0 ; i < n ; i ++ ) { ans += ans / 20 ; if ( ans != ( ans = ans / 1000 * 1000 ) ) { ans += 1000 ; } } System . out . println ( ans ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 1 ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] a = new int [ n ] ; int [ ] b = new int [ n - 1 ] ; for ( int i = 0 ; i < n - 1 ; i ++ ) { b [ i ] = sc . nextInt ( ) ; } a [ 0 ] = b [ 0 ] ; int score = a [ 0 ] ; for ( int i = 1 ; i < n - 1 ; i ++ ) { a [ i ] = Math . min ( b [ i - 1 ] , b [ i ] ) ; score += a [ i ] ; } if ( n != 1 ) { a [ n - 1 ] = b [ n - 2 ] ; score += a [ n - 1 ] ; } System . out . println ( score ) ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; long [ ] a = new long [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = sc . nextLong ( ) ; } long num = lcm ( a , n ) ; long deno = sum ( a , n , num ) ; double ans = num / ( double ) deno ; System . out . println ( ans ) ; } public static long gcd ( long a , long b ) { if ( a == 0 ) return b ; return gcd ( b % a , a ) ; } public static long lcm ( long [ ] a , long n ) { long lc = 1 ; for ( int i = 0 ; i < n ; i ++ ) { lc = ( lc * a [ i ] ) / gcd ( lc , a [ i ] ) ; } return lc ; } public static long sum ( long [ ] a , int n , long num ) { int i = 0 ; long count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { count += ( num / a [ i ] ) ; } return count ; } } +import java . io . * ; import java . util . StringTokenizer ; public class Main { public static void main ( String [ ] args ) throws Exception { String s = " 5 \n " + " 1 2 \n " + " 6 6 \n " + " 4 4 \n " + " 3 3 \n " + " 3 2 " ; br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; bw = new BufferedWriter ( new OutputStreamWriter ( System . out ) ) ; rl ( ) ; int n = nin ( ) ; boolean res = false ; int c = 0 ; for ( int i = 0 ; i < n ; ++ i ) { rl ( ) ; if ( nin ( ) == nin ( ) ) { ++ c ; } else { c = 0 ; } if ( c == 3 ) res = true ; } bw . write ( ( res ? " Yes " : " No " ) + " \n " ) ; bw . flush ( ) ; } static BufferedReader br ; static BufferedWriter bw ; static StringTokenizer st ; static void rl ( ) throws Exception { st = new StringTokenizer ( br . readLine ( ) ) ; } static long nlo ( ) { return Long . parseLong ( st . nextToken ( ) ) ; } static int nin ( ) { return Integer . parseInt ( st . nextToken ( ) ) ; } static double ndo ( ) { return Double . parseDouble ( st . nextToken ( ) ) ; } static char [ ] nca ( ) { return st . nextToken ( ) . toCharArray ( ) ; } static String nstr ( ) { return st . nextToken ( ) ; } } +import java . io . * ; import java . util . * ; public class Main { public static void main ( String [ ] args ) { int j = 0 ; Scanner in = new Scanner ( new BufferedReader ( new InputStreamReader ( System . in ) ) ) ; int a = in . nextInt ( ) , b = in . nextInt ( ) , c = in . nextInt ( ) , n = in . nextInt ( ) ; int count = 0 ; for ( int i = 0 ; i <= a ; i ++ ) { int x = 500 * i ; for ( int j = 0 ; j <= b ; j ++ ) { int y = 100 * j ; if ( n - x - y >= 0 && ( n - x - y ) % 50 == 0 && ( n - x - y ) / 50 <= c ) count ++ ; } } System . out . println ( count ) ; } } +import java . io . IOException ; import java . io . BufferedReader ; import java . io . InputStreamReader ; class Main { public static void main ( String [ ] args ) throws IOException { int count = 1 ; BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String str = br . readLine ( ) ; int count = 1 ; while ( ! str . equals ( " 0 " ) ) { System . out . println ( " Case " + count + " : " + str ) ; count ++ ; str = br . readLine ( ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; char st ; char [ ] ch = { 'A' , 'C' , 'G' , 'T' } ; int count = 0 ; int count_max = 0 ; boolean con ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { st = s . charAt ( i ) ; con = true ; count ++ ; for ( int j = 0 ; j < 4 && con ; j ++ ) { int j = 0 ; if ( st == ch [ j ] ) con = false ; } if ( con ) count = 0 ; if ( count > count_max ) count_max = count ; } System . out . println ( count_max ) ; } } +import java . util . Scanner ; public class Main { private static double r ; public static void main ( String [ ] args ) { Scanner stdIn = new Scanner ( System . in ) ; r = stdIn . nextDouble ( ) ; double Pi = Math . PI ; System . out . printf ( " %.6f %.6f \n " , ( r * r * Pi ) , ( 2 * Pi * r ) ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int s = sc . nextInt ( ) ; int [ ] arr = new int [ 1000000 ] ; arr [ 0 ] = s ; Set < Integer > set = new HashSet < > ( ) ; set . add ( s ) ; for ( int i = 1 ; i < 1000000000 ; i ++ ) { if ( arr [ i - 1 ] % 2 == 0 ) { arr [ i ] = arr [ i - 1 ] / 2 ; } else { arr [ i ] = arr [ i - 1 ] * 3 + 1 ; } if ( set . contains ( arr [ i ] ) ) { int i = 1 ; System . out . println ( i + 1 ) ; return ; } else { set . add ( arr [ i ] ) ; } } } } +import java . awt . * ; import java . io . PrintWriter ; import java . lang . reflect . Array ; import java . math . BigInteger ; import java . util . * ; import java . util . List ; public class Main { static String br = System . getProperty ( " line.separator " ) ; static Scanner sc = new Scanner ( System . in ) ; static PrintWriter out = new PrintWriter ( System . out ) ; public static void main ( String [ ] args ) { int N = nextInt ( ) ; int [ ] K = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { K [ nextInt ( ) - 1 ] = i ; } for ( int i = 0 ; i < N ; i ++ ) { PrintWriter out = new PrintWriter ( System . out ) ; print ( K [ i ] + 1 + " " ) ; } } static int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } static Long nextLong ( ) { return Long . parseLong ( next ( ) ) ; } static String next ( ) { return sc . next ( ) ; } static String nextLine ( ) { return sc . nextLine ( ) ; } static void println ( Object o ) { out . println ( o ) ; out . flush ( ) ; } static void print ( Object o ) { PrintWriter out = new PrintWriter ( System . out ) ; out . print ( o ) ; out . flush ( ) ; } } +import java . util . Scanner ; public class Main { public static final String OK = " Yay! " ; public static final String NO = " :( " ; public static void main ( final String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int c = sc . nextInt ( ) ; int d = sc . nextInt ( ) ; int e = sc . nextInt ( ) ; int k = sc . nextInt ( ) ; sc . close ( ) ; if ( e - a > k ) System . out . println ( NO ) ; else System . out . println ( OK ) ; } } +import java . util . Scanner ; public class Main { static int [ ] stack = new int [ 1000 ] ; static int counta = 0 ; public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; String [ ] input = ( scanner . nextLine ( ) ) . split ( " " ) ; for ( int i = 0 ; i < input . length ; i ++ ) { if ( input [ i ] . equals ( " * " ) ) { push ( pop ( ) * pop ( ) ) ; } else if ( input [ i ] . equals ( " + " ) ) { int i = 0 ; push ( pop ( ) + pop ( ) ) ; } else if ( input [ i ] . equals ( " - " ) ) { push ( - pop ( ) + pop ( ) ) ; } else { push ( Integer . parseInt ( input [ i ] ) ) ; } } System . out . println ( pop ( ) ) ; } public static int pop ( ) { counta -- ; return stack [ counta + 1 ] ; } public static void push ( int i ) { counta ++ ; stack [ counta ] = i ; } } +import java . util . * ; import java . util . stream . * ; class Main { static final List < String > RESULT_TYPE = Collections . unmodifiableList ( Arrays . asList ( " AC " , " WA " , " TLE " , " RE " ) ) ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; Map < String , Integer > result = new HashMap < > ( ) ; int N = sc . nextInt ( ) ; for ( int i = 0 ; i < N ; i ++ ) { String judge = sc . next ( ) ; result . put ( judge , result . get ( judge ) == null ? 1 : result . get ( judge ) + 1 ) ; } dispResult ( result ) ; } static void dispResult ( Map < String , Integer > result ) { String R ; for ( String R : RESULT_TYPE ) { System . out . println ( R + " x " + ( result . get ( R ) == null ? 0 : result . get ( R ) ) ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; String line = sc . nextLine ( ) ; String [ ] line1 = line . split ( " " ) ; int n = Integer . parseInt ( line1 [ 0 ] ) ; int k = Integer . parseInt ( line1 [ 1 ] ) ; int q = Integer . parseInt ( line1 [ 2 ] ) ; int [ ] ary = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) ary [ i ] = k - q ; for ( int i = 0 ; i < q ; i ++ ) { int a = sc . nextInt ( ) ; ary [ a - 1 ] ++ ; } for ( int i = 0 ; i < n ; i ++ ) { int i = 0 ; if ( ary [ i ] <= 0 ) System . out . println ( " No " ) ; else System . out . println ( " Yes " ) ; } } } +import java . io . * ; import java . util . * ; class Main { public static void main ( String [ ] args ) throws IOException { StringTokenizer stringTokenizer = new StringTokenizer ( str , delimiter ) ; int a = 0 ; int b = 0 ; int c = 0 ; int i = 0 ; int tmp = 0 ; BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String str = br . readLine ( ) ; String delimiter = " " ; StringTokenizer stringTokenizer = new StringTokenizer ( str , delimiter ) ; while ( stringTokenizer . hasMoreTokens ( ) ) { String current = stringTokenizer . nextToken ( ) ; if ( i == 0 ) a = Integer . parseInt ( current ) ; if ( i == 1 ) b = Integer . parseInt ( current ) ; if ( i == 2 ) c = Integer . parseInt ( current ) ; i ++ ; } if ( a > c ) { tmp = a ; a = c ; c = tmp ; } if ( a > b ) { tmp = a ; a = b ; b = tmp ; } if ( b > c ) { tmp = b ; b = c ; c = tmp ; } System . out . println ( a + " " + b + " " + c ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int a = 1 ; Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; for ( int i = 1 ; i <= 9 ; i ++ ) for ( int a = 1 ; a <= 9 ; a ++ ) { if ( i * a == N ) { System . out . println ( " Yes " ) ; return ; } } System . out . println ( " No " ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; String N = scan . next ( ) ; if ( N . length ( ) == 3 ) { String N = scan . next ( ) ; if ( N . contains ( " 7 " ) ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; String c = scan . next ( ) , str = " " ; for ( int i = 0 ; i < c . length ( ) ; i ++ ) { int i = 0 ; str = c . substring ( i , i + 1 ) + str ; } System . out . println ( str ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { String q = " Odd " ; Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; String q = " Odd " ; if ( a % 2 == 0 || b % 2 == 0 ) { q = " Even " ; } System . out . println ( q ) ; } } +import java . io . * ; class Main { public static int prime ( int x ) { int k = 0 ; if ( x == 1 ) { k = 1 ; } else if ( x % 2 == 0 ) { k = 1 ; } for ( int i = 3 ; i <= Math . sqrt ( x ) ; i += 2 ) { if ( x % i == 0 ) { k = 1 ; break ; } } if ( x == 2 ) { k = 0 ; } return k ; } public static void main ( String [ ] args ) { BufferedReader reader = new BufferedReader ( new InputStreamReader ( System . in ) ) ; try { int N = Integer . parseInt ( reader . readLine ( ) ) ; ; int [ ] a = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { a [ i ] = Integer . parseInt ( reader . readLine ( ) ) ; } int count = 0 ; for ( int i = 0 ; i < a . length ; i ++ ) { if ( prime ( a [ i ] ) == 0 ) { int i = 0 ; count += 1 ; } } System . out . println ( count ) ; } catch ( IOException e ) { System . out . println ( e ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] arg ) { Scanner scan = new Scanner ( System . in ) ; int N = scan . nextInt ( ) ; int [ ] p = new int [ N ] ; int check = 0 ; for ( int i = 0 ; i < N ; i ++ ) { int i = 0 ; p [ i ] = scan . nextInt ( ) ; if ( p [ i ] != i + 1 ) { check ++ ; } } if ( check == 0 || check == 2 ) { 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 ) ; String [ ] tmp = sc . nextLine ( ) . split ( " " ) ; int a = Integer . valueOf ( tmp [ 0 ] ) ; int b = Integer . valueOf ( tmp [ 1 ] ) ; int sum = judge ( a , b ) ; if ( a < b ) { b -- ; } else { a -- ; } sum += judge ( a , b ) ; System . out . println ( sum ) ; } public static int judge ( int a , int b ) { int res = 0 ; int res = 0 ; if ( a < b ) { res = b ; } else { res = a ; } return res ; } } +import java . util . * ; public class Main { long INF = Long . MAX_VALUE ; public static void main ( String [ ] args ) { new Main ( ) . solve ( ) ; } void solve ( ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int ans = N / 100 ; int A = ans * 100 + ans * 10 + ans ; if ( A >= N ) { ans = ans ; } else { int ans = N / 100 ; ans ++ ; } for ( int i = 0 ; i < 3 ; i ++ ) { System . out . print ( ans ) ; } System . out . println ( ) ; } } +import java . io . * ; public class Main { public static void main ( String ... args ) { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; try { String [ ] line = br . readLine ( ) . split ( " " ) ; int n = Integer . parseInt ( line [ 0 ] ) ; int k = Integer . parseInt ( line [ 1 ] ) ; int q = Integer . parseInt ( line [ 2 ] ) ; int [ ] point = new int [ n ] ; for ( int i = 0 ; i < q ; i ++ ) { int i = 0 ; point [ Integer . parseInt ( br . readLine ( ) ) - 1 ] += 1 ; } for ( int i = 0 ; i < n ; i ++ ) { point [ i ] += k - q ; } for ( int i = 0 ; i < point . length ; i ++ ) { if ( point [ i ] <= 0 ) { System . out . println ( " No " ) ; } else { System . out . println ( " Yes " ) ; } } br . close ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int x = sc . nextInt ( ) ; int n = sc . nextInt ( ) ; String [ ] nums = new String [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { int count = 0 ; nums [ i ] = sc . next ( ) ; } sc . close ( ) ; for ( int count = 0 ; ; count ++ ) { if ( ! ( Arrays . asList ( nums ) . contains ( String . valueOf ( x - count ) ) ) ) { System . out . println ( x - count ) ; break ; } if ( ! ( Arrays . asList ( nums ) . contains ( String . valueOf ( x + count ) ) ) ) { System . out . println ( x + count ) ; break ; } } } } +import java . util . Scanner ; public class Main { private final static Scanner sc = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { int N = sc . nextInt ( ) ; long K = sc . nextInt ( ) ; long Q = sc . nextInt ( ) ; long [ ] array = new long [ N ] ; for ( int i = 0 ; i < Q ; i ++ ) { array [ sc . nextInt ( ) - 1 ] ++ ; } for ( int i = 0 ; i < N ; i ++ ) { if ( ( K + array [ i ] - Q ) > 0 ) { System . out . println ( " Yes " ) ; } else { int i = 0 ; System . out . println ( " No " ) ; } } } } +import java . util . * ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] a = new int [ n ] ; int res = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int i = 0 ; a [ i ] = sc . nextInt ( ) ; } Arrays . sort ( a ) ; if ( a [ n / 2 - 1 ] != a [ n / 2 ] ) { res = a [ n / 2 ] - a [ n / 2 - 1 ] ; } System . out . println ( res ) ; } } +import java . util . ArrayList ; import java . util . Collections ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sn = new Scanner ( System . in ) ; ArrayList < Integer > a = new ArrayList < Integer > ( ) ; for ( int i = 0 ; i < 10 ; i ++ ) { a . add ( sn . nextInt ( ) ) ; } Collections . sort ( a ) ; for ( int i = 0 ; i < 3 ; i ++ ) { int i = 0 ; System . out . println ( a . get ( a . size ( ) - i - 1 ) ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = min ; Scanner sc = new Scanner ( System . in ) ; int numbers = sc . nextInt ( ) ; int point = sc . nextInt ( ) ; int min = point - numbers + 1 ; int max = point + numbers - 1 ; for ( int i = min ; i <= max ; i ++ ) { System . out . print ( i + " " ) ; } } } +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 ( ) ; boolean bool = true ; loop : for ( int i = 1 ; i <= 1010 ; i ++ ) { int k1 = ( int ) ( i * 0.08 ) ; int k2 = ( int ) ( i * 0.1 ) ; if ( k1 == a && k2 == b ) { int i = 1 ; bool = false ; System . out . println ( i ) ; break loop ; } } if ( bool ) { System . out . println ( " -1 " ) ; } sc . close ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { String S = scan . next ( ) ; Scanner scan = new Scanner ( System . in ) ; int K = scan . nextInt ( ) ; String S = scan . next ( ) ; int x = S . length ( ) ; if ( x > K ) { String ans = S . substring ( 0 , K ) ; System . out . println ( ans + " ... " ) ; } else { System . out . println ( S ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int a = scan . nextInt ( ) ; int b = scan . nextInt ( ) ; int c = scan . nextInt ( ) ; int d = scan . nextInt ( ) ; int ans = 0 ; if ( b <= c || d <= a ) { ans = 0 ; } else if ( c <= a && b <= d ) { int ans = 0 ; ans = b - a ; } else if ( a <= c && d <= b ) { ans = d - c ; } else if ( a <= c && c <= b && b <= d ) { ans = b - c ; } else if ( c <= a && a <= d && d <= b ) { ans = d - a ; } System . out . println ( ans ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; String s = scan . nextLine ( ) ; if ( s . equals ( " ABC " ) ) { s = s . replace ( " ABC " , " ARC " ) ; } else { String s = scan . nextLine ( ) ; s = s . replace ( " ARC " , " ABC " ) ; } System . out . println ( s ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] a ) { Scanner scanner = new Scanner ( System . in ) ; String input = scanner . nextLine ( ) ; scanner . close ( ) ; if ( input . length ( ) > 20 ) return ; String reverse = " " ; char [ ] c = input . toCharArray ( ) ; for ( int i = c . length ; i > 0 ; i -- ) { int i = c . length ; reverse += c [ i - 1 ] ; } System . out . println ( reverse ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int num = in . nextInt ( ) ; int [ ] value = new int [ num ] ; int a = 0 ; int b = 0 ; for ( int i = 0 ; i < num ; i ++ ) { value [ i ] = in . nextInt ( ) ; if ( a < value [ i ] ) { b = a ; a = value [ i ] ; } else if ( b < value [ i ] ) { b = value [ i ] ; } } in . close ( ) ; for ( int i = 0 ; i < num ; i ++ ) { if ( a == value [ i ] ) { System . out . println ( b ) ; } else { int i = 0 ; System . out . println ( a ) ; } } } } +import java . io . * ; public class Main { public static void main ( String [ ] args ) { String [ ] arange = null ; BufferedReader in = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int a , b , c ; String [ ] arange = null ; try { arange = in . readLine ( ) . split ( " " , 0 ) ; } catch ( Exception e ) { } a = Integer . parseInt ( arange [ 0 ] ) ; b = Integer . parseInt ( arange [ 1 ] ) ; c = Integer . parseInt ( arange [ 2 ] ) ; if ( a <= b && a <= c ) { if ( b < c ) System . out . println ( a + " " + b + " " + c ) ; else System . out . println ( a + " " + c + " " + b ) ; } else if ( b <= a && b <= c ) { if ( a < c ) System . out . println ( b + " " + a + " " + c ) ; else System . out . println ( b + " " + c + " " + a ) ; } else { if ( a < b ) System . out . println ( c + " " + a + " " + b ) ; else System . out . println ( c + " " + b + " " + a ) ; } } } +import java . util . ArrayList ; import java . util . Arrays ; import java . util . Collections ; import java . util . Scanner ; public class Main { private static Scanner sc = new Scanner ( System . in ) ; static void p ( String ans ) { System . out . println ( ans ) ; } static void p ( int ans ) { System . out . println ( ans ) ; } static void p ( long ans ) { System . out . println ( ans ) ; } static void p ( double ans ) { System . out . println ( ans ) ; } public static void main ( String [ ] args ) { int i = 0 ; String s = sc . next ( ) ; int ctn = 0 ; for ( int i = 0 ; i < s . length ( ) / 2 ; i ++ ) { if ( s . charAt ( i ) != s . charAt ( s . length ( ) - i - 1 ) ) { ctn ++ ; } } p ( ctn ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String alpha = " abcdefghijklmnopqrstuvwxyz " ; String target = sc . next ( ) ; for ( int i = 0 ; i <= 24 ; i ++ ) { int i = 0 ; if ( String . valueOf ( alpha . charAt ( i ) ) . equals ( target ) ) { System . out . println ( alpha . charAt ( i + 1 ) ) ; } } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; char [ ] s = sc . next ( ) . toCharArray ( ) ; int n = s . length ; int res = 0 ; for ( int i = 0 ; i < ( n - 1 - i ) ; i ++ ) { if ( s [ i ] != s [ n - 1 - i ] ) { int i = 0 ; res ++ ; } } System . out . println ( res ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; while ( in . hasNext ( ) ) { Scanner in = new Scanner ( System . in ) ; int n = in . nextInt ( ) ; if ( n == 0 ) break ; int [ ] numbers = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) numbers [ i ] = in . nextInt ( ) ; long double_sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) double_sum += numbers [ i ] ; double_sum = double_sum * double_sum ; long sum_double = 0 ; for ( int i = 0 ; i < n ; i ++ ) sum_double += ( numbers [ i ] * numbers [ i ] ) ; double sd = Math . sqrt ( ( sum_double - double_sum / ( double ) n ) / ( double ) n ) ; System . out . printf ( " %5.8f " , sd ) ; System . out . println ( ) ; } } } +import java . util . Scanner ; import java . util . Arrays ; import java . util . ArrayList ; public class Main { public static void main ( String [ ] args ) { int p ; Scanner sc = new Scanner ( System . in ) ; ArrayList < Integer > A = new ArrayList < > ( ) ; int N = sc . nextInt ( ) ; for ( int a = 0 ; a < N ; ++ a ) { A . add ( sc . nextInt ( ) ) ; } int [ ] p_num = new int [ 8 ] ; Arrays . fill ( p_num , 0 ) ; int sp = 0 ; int redExist = 0 ; for ( int a : A ) { if ( a < 3200 ) { p_num [ a / 400 ] += 1 ; } else { sp += 1 ; redExist = 1 ; } } int ans = 0 ; for ( int p : p_num ) { if ( p > 0 ) { ans += 1 ; } } int ans_min = Math . max ( ans , 1 ) ; int ans_max = ans + sp ; System . out . println ( ans_min + " " + ans_max ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int ans = 0 ; Scanner sc = new Scanner ( System . in ) ; int tap = sc . nextInt ( ) ; int over = sc . nextInt ( ) ; int outlet = 1 ; int ans = 0 ; while ( outlet < over ) { -- outlet ; outlet += tap ; ans ++ ; } System . out . println ( ans ) ; } } +import java . util . ArrayList ; import java . util . List ; import java . util . Scanner ; public class Main { final static Long MAX = 1000000000000000000L ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; sc . nextLine ( ) ; List < Long > l = new ArrayList < Long > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { Long l2 ; l . add ( sc . nextLong ( ) ) ; } sc . close ( ) ; if ( l . contains ( 0L ) ) { System . out . println ( 0 ) ; } else { Long sum = 1L ; for ( Long l2 : l ) { if ( sum > MAX / l2 ) { System . out . println ( - 1 ) ; return ; } sum *= l2 ; } System . out . println ( sum ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int m = sc . nextInt ( ) ; Map < Integer , List < String > > result = new HashMap < > ( ) ; for ( int i = 0 ; i < m ; i ++ ) { Map . Entry < Integer , List < String > > entry ; int p = sc . nextInt ( ) ; String s = sc . next ( ) ; if ( ! result . containsKey ( p ) ) { result . put ( p , new ArrayList < > ( ) ) ; } result . get ( p ) . add ( s ) ; } int ok = 0 ; int ng = 0 ; for ( Map . Entry < Integer , List < String > > entry : result . entrySet ( ) ) { int acIndex = entry . getValue ( ) . indexOf ( " AC " ) ; if ( acIndex == - 1 ) { continue ; } ok ++ ; ng += acIndex ; } System . out . println ( ok + " " + ng ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int tyuukan = scan . nextInt ( ) ; int kimatu = scan . nextInt ( ) ; int saisiken = scan . nextInt ( ) ; while ( tyuukan != - 1 || kimatu != - 1 || saisiken != - 1 ) { int y ; y = tyuukan + kimatu ; if ( tyuukan == - 1 || kimatu == - 1 ) { System . out . println ( " F " ) ; } else if ( y >= 80 ) { System . out . println ( " A " ) ; } else if ( y >= 65 && y < 80 ) { System . out . println ( " B " ) ; } else if ( y >= 50 && y < 65 ) { int saisiken = scan . nextInt ( ) ; System . out . println ( " C " ) ; } else if ( y >= 30 && y < 50 ) { if ( saisiken >= 50 ) { System . out . println ( " C " ) ; } else { System . out . println ( " D " ) ; } } else { System . out . println ( " F " ) ; } tyuukan = scan . nextInt ( ) ; kimatu = scan . nextInt ( ) ; saisiken = scan . nextInt ( ) ; } } } +import java . util . Scanner ; public class Main { public static int Num ; public static int [ ] List ; public static int Count = 0 ; public static int min_j ; public static int tmp ; public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; Num = scan . nextInt ( ) ; List = new int [ Num ] ; for ( int i = 0 ; i < Num ; i ++ ) { List [ i ] = scan . nextInt ( ) ; } SelectionSort ( ) ; if ( Num == 1 ) System . out . println ( List [ 0 ] ) ; else { int j = i ; for ( int i = 0 ; i < Num ; i ++ ) { if ( i == Num - 1 ) System . out . println ( List [ Num - 1 ] ) ; else System . out . print ( List [ i ] + " " ) ; } } System . out . println ( Count ) ; } public static void SelectionSort ( ) { for ( int i = 0 ; i < Num ; i ++ ) { min_j = i ; for ( int j = i ; j < Num ; j ++ ) { if ( List [ j ] < List [ min_j ] ) { min_j = j ; } } if ( min_j != i ) { tmp = List [ i ] ; List [ i ] = List [ min_j ] ; List [ min_j ] = tmp ; Count ++ ; } } } } +import java . io . * ; import java . util . * ; import java . math . * ; import java . lang . * ; class Main { public static void PrintIntArray ( int [ ] Arr ) { for ( int i = 0 ; i < Arr . length ; i ++ ) { System . out . print ( Arr [ i ] + " " ) ; } System . out . println ( ) ; } public static void main ( String [ ] args ) throws IOException { Reader . init ( System . in ) ; long A = Reader . nextLong ( ) ; long B = Reader . nextLong ( ) ; if ( ( A + B ) % 2 == 0 ) { System . out . println ( ( A + B ) / 2 ) ; } else { System . out . println ( " IMPOSSIBLE " ) ; } } } class Reader { static BufferedReader reader ; static StringTokenizer tokenizer ; static void init ( InputStream input ) { reader = new BufferedReader ( new InputStreamReader ( input ) ) ; tokenizer = new StringTokenizer ( " " ) ; } static String next ( ) throws IOException { while ( ! tokenizer . hasMoreTokens ( ) ) { tokenizer = new StringTokenizer ( reader . readLine ( ) ) ; } return tokenizer . nextToken ( ) ; } static int nextInt ( ) throws IOException { return Integer . parseInt ( next ( ) ) ; } static long nextLong ( ) throws IOException { return Long . parseLong ( next ( ) ) ; } static double nextDouble ( ) throws IOException { return Double . parseDouble ( next ( ) ) ; } } +import java . util . * ; public class Main { public static long gcd ( long a , long b ) { while ( a % b != 0 ) { long tmp = a % b ; a = b ; b = tmp ; } return b ; } public static long lcm ( long a , long b ) { return a * b / gcd ( a , b ) ; } public static long divnum ( long a , long b , long x ) { long d = sc . nextLong ( ) ; return b / x - ( a - 1 ) / x ; } public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long a = sc . nextLong ( ) ; long b = sc . nextLong ( ) ; long c = sc . nextLong ( ) ; long d = sc . nextLong ( ) ; if ( d % c == 0 ) { System . out . println ( b - a + 1 - divnum ( a , b , c ) ) ; } else { System . out . println ( b - a + 1 - divnum ( a , b , c ) - divnum ( a , b , d ) + divnum ( a , b , lcm ( c , d ) ) ) ; } } } +import java . util . Scanner ; import java . util . Arrays ; import java . util . ArrayList ; import java . util . List ; import java . util . stream . Collectors ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int Sum = 0 ; List < String > listA = new ArrayList < String > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { List < String > listA = new ArrayList < String > ( ) ; listA . add ( sc . next ( ) ) ; } List < String > listB = listA . stream ( ) . distinct ( ) . collect ( Collectors . toList ( ) ) ; System . out . println ( listB . size ( ) ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int Q = sc . nextInt ( ) ; String S = sc . next ( ) ; int [ ] count = new int [ N ] ; Arrays . fill ( count , 0 ) ; for ( int i = 1 ; i < N ; i ++ ) { if ( S . charAt ( i - 1 ) == 'A' && S . charAt ( i ) == 'C' ) { count [ i ] = count [ i - 1 ] + 1 ; } else { count [ i ] = count [ i - 1 ] ; } } for ( int i = 0 ; i < Q ; i ++ ) { int l = sc . nextInt ( ) - 1 ; int r = sc . nextInt ( ) - 1 ; System . out . println ( count [ r ] - count [ l ] ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] a = new int [ n ] ; int b = 0 ; int [ ] c = new int [ n - 1 ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = sc . nextInt ( ) ; } for ( int i = 0 ; i < n ; i ++ ) { b += sc . nextInt ( ) ; } for ( int i = 0 ; i < n - 1 ; i ++ ) { c [ i ] = sc . nextInt ( ) ; } for ( int i = 1 ; i < n ; i ++ ) { int f = a [ i - 1 ] ; int r = a [ i ] ; int f = a [ i - 1 ] ; if ( ( r - f ) == 1 ) { b += c [ f - 1 ] ; } } System . out . println ( b ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int a = scanner . nextInt ( ) ; int b = scanner . nextInt ( ) ; int plus = a + b ; int minus = a - b ; int multiplied = a * b ; int result = 0 ; if ( plus > minus ) { if ( plus > multiplied ) { int result = 0 ; result = plus ; } else { result = multiplied ; } } else if ( minus > multiplied ) { result = minus ; } else { result = multiplied ; } System . out . println ( result ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int b = Integer . parseInt ( Str . next ( ) ) ; Scanner Str = new Scanner ( System . in ) ; int a = Integer . parseInt ( Str . next ( ) ) ; int b = Integer . parseInt ( Str . next ( ) ) ; if ( Math . floor ( a / 10 ) + Math . floor ( b / 10 ) == 0 ) { System . out . println ( a * b ) ; } else { System . out . println ( " -1 " ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String str = sc . nextLine ( ) ; int result = 0 ; boolean flag = false ; for ( int i = 0 ; i < 3 ; i ++ ) { if ( str . charAt ( i ) == 'R' ) { int i = 0 ; result ++ ; flag = true ; } else { if ( flag == true ) break ; } } System . out . println ( result ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int p = sc . nextInt ( ) ; int a = 1000 ; int i = 2 ; while ( a < p ) { int i = 2 ; a = 1000 * i ; i ++ ; } System . out . println ( a - p ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int x = 0 ; if ( a <= b ) { x = x + b ; if ( a <= b - 1 ) { int x = 0 ; x = x + b - 1 ; } else { x = x + a ; } } else { x = x + a ; if ( b <= a - 1 ) { x = x + a - 1 ; } else { x = x + b ; } } System . out . println ( x ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long x = sc . nextLong ( ) ; long start = 100 ; int answer = 0 ; while ( x > start ) { int answer = 0 ; start += start / 100 ; answer ++ ; } System . out . println ( answer ) ; sc . close ( ) ; } } +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 [ ] n = new int [ 5 ] ; int count = 0 ; int temp = 0 ; for ( int i = A ; i <= B ; i ++ ) { int j = 0 ; temp = i ; for ( int j = 0 ; j < 5 ; j ++ ) { n [ j ] = temp % 10 ; temp = temp / 10 ; } if ( n [ 0 ] == n [ 4 ] && n [ 1 ] == n [ 3 ] ) { count ++ ; } } System . out . println ( count ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { new Main ( ) . run ( ) ; } private void run ( ) { int a , b , c ; Scanner sc = new Scanner ( System . in ) ; String [ ] input = sc . nextLine ( ) . split ( " " ) ; a = Integer . parseInt ( input [ 0 ] ) ; b = Integer . parseInt ( input [ 1 ] ) ; c = Integer . parseInt ( input [ 2 ] ) ; int cnt = 0 ; for ( int i = a ; i <= b ; i ++ ) { int i = a ; if ( c % i == 0 ) cnt ++ ; } System . out . println ( cnt ) ; } } +import java . util . ArrayList ; import java . util . Iterator ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long n = sc . nextLong ( ) ; long result = 0 ; long num = sc . nextLong ( ) ; for ( int i = 1 ; i < n ; i ++ ) { long a = sc . nextInt ( ) ; long a = sc . nextInt ( ) ; if ( a >= num ) { num = a ; } else { result = result + num - a ; } } System . out . println ( result ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int cnt = 0 ; Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; long d = sc . nextInt ( ) ; d = d * d ; int cnt = 0 ; for ( int i = 0 ; i < N ; i ++ ) { long x = sc . nextInt ( ) ; long y = sc . nextInt ( ) ; if ( d >= x * x + y * y ) cnt ++ ; } System . out . println ( cnt ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; for ( int i = 1 ; i <= 10 ; i ++ ) { int i = 1 ; if ( ( n - 1000 * i ) <= 0 ) { System . out . println ( ( n - 1000 * i ) * - 1 ) ; break ; } } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int S = sc . nextInt ( ) ; int count = 0 ; int tens = ( ( S / 10 ) - ( ( int ) ( S / 100 ) ) * 10 ) * 10 ; int ones = S % 10 ; if ( ( S / 100 ) <= 12 && ( S / 100 ) != 0 ) { count += 1 ; } if ( ( tens + ones ) <= 12 && ( tens + ones ) != 0 ) { int count = 0 ; count += 2 ; } switch ( count ) { case 0 : System . out . print ( " NA " ) ; break ; case 2 : System . out . print ( " YYMM " ) ; break ; case 1 : System . out . print ( " MMYY " ) ; break ; case 3 : System . out . print ( " AMBIGUOUS " ) ; break ; } sc . close ( ) ; } } +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 ++ ) { int i = 0 ; a [ i ] = sc . nextInt ( ) ; } Arrays . sort ( a ) ; System . out . println ( a [ ( n - 1 ) / 2 + 1 ] - a [ ( n - 1 ) / 2 ] ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String S = sc . next ( ) ; sc . close ( ) ; char [ ] c = S . toCharArray ( ) ; int ans = 0 ; for ( int i = 0 ; i < S . length ( ) ; i ++ ) { if ( c [ i ] == '+' ) { ans ++ ; } else { int i = 0 ; ans -- ; } } System . out . println ( ans ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws Exception { int n = Integer . parseInt ( sc . next ( ) ) ; Scanner sc = new Scanner ( System . in ) ; int n = Integer . parseInt ( sc . next ( ) ) ; if ( n % 2 == 0 ) { System . out . println ( n / 2 ) ; } else { System . out . println ( ( n + 1 ) / 2 ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { try ( Scanner sc = new Scanner ( System . in ) ) { int A , B , T ; A = sc . nextInt ( ) ; B = sc . nextInt ( ) ; T = sc . nextInt ( ) ; int sum = 0 ; for ( int time = 1 ; time <= T ; time ++ ) { if ( time % A == 0 ) { int time = 1 ; sum += B ; } } System . out . println ( sum ) ; } catch ( Exception e ) { } } } +import java . util . Scanner ; class Main { public static void main ( final String [ ] args ) { try ( Scanner scanner = new Scanner ( System . in ) ) { String s = scanner . nextLine ( ) ; int count = 0 ; boolean flag = true ; for ( int i = 0 ; i < 4 ; i ++ ) { String s1 = s . substring ( i , i + 1 ) ; for ( int k = 0 ; k < 4 ; k ++ ) { String s2 = s . substring ( k , k + 1 ) ; if ( s1 . equals ( s2 ) ) { count ++ ; } } if ( count == 2 ) { int k = 0 ; count = 0 ; } else { System . out . println ( " No " ) ; flag = false ; break ; } } if ( flag ) { System . out . println ( " Yes " ) ; } } } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int r , c , e = 0 ; r = scan . nextInt ( ) ; c = scan . nextInt ( ) ; int [ ] [ ] a = new int [ r ] [ c ] ; for ( int i = 0 ; i < r ; i ++ ) { int b = 0 ; for ( int j = 0 ; j < c ; j ++ ) { a [ i ] [ j ] = scan . nextInt ( ) ; b += a [ i ] [ j ] ; System . out . print ( a [ i ] [ j ] + " " ) ; } e += b ; System . out . println ( b ) ; } for ( int i = 0 ; i < c ; i ++ ) { int j = 0 ; int d = 0 ; for ( int j = 0 ; j < r ; j ++ ) { d += a [ j ] [ i ] ; } System . out . print ( d + " " ) ; } System . out . println ( e ) ; } } +import java . util . * ; class Main { Scanner sc ; String s ; Main ( ) { sc = new Scanner ( System . in ) ; } void calc ( ) { char c = s . charAt ( i ) ; s = sc . next ( ) ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { char c = s . charAt ( i ) ; if ( ( i % 2 ) == 0 ) { if ( c != 'R' && c != 'U' && c != 'D' ) { System . out . println ( " No " ) ; return ; } } else { if ( c != 'L' && c != 'U' && c != 'D' ) { System . out . println ( " No " ) ; return ; } } } System . out . println ( " Yes " ) ; } public static void main ( String [ ] args ) { new Main ( ) . calc ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; String S = scanner . next ( ) ; int x = S . length ( ) ; String ans = " " ; for ( int i = 0 ; i < x ; i ++ ) { String ans = " " ; ans = ans . concat ( " x " ) ; } System . out . println ( ans ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int num1 = sc . nextInt ( ) ; int num2 = sc . nextInt ( ) ; int tap = 0 ; int outlet = 1 ; while ( num2 > outlet ) { int outlet = 1 ; outlet += num1 - 1 ; tap ++ ; } System . out . println ( tap ) ; } } +import java . util . Scanner ; class Main { public static final String SEVEN = " 7 " ; public static void main ( final String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int inputN = scan . nextInt ( ) ; scan . close ( ) ; String numN = String . valueOf ( inputN ) ; String charN = null ; for ( int i = 0 ; i < numN . length ( ) ; i ++ ) { if ( i != ( numN . length ( ) - 1 ) ) { int i = 0 ; charN = numN . substring ( i , i + 1 ) ; } else { charN = numN . substring ( i ) ; } if ( SEVEN . equals ( charN ) ) { System . out . println ( " Yes " ) ; return ; } } System . out . println ( " No " ) ; } } +import java . util . Scanner ; import java . util . Stack ; class Main { public static void main ( String [ ] args ) { new Main ( ) . compute ( ) ; } void compute ( ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int M = sc . nextInt ( ) ; int [ ] nanbon = new int [ N ] ; for ( int i = 0 ; i < M ; i ++ ) { nanbon [ sc . nextInt ( ) - 1 ] ++ ; nanbon [ sc . nextInt ( ) - 1 ] ++ ; } for ( int i = 0 ; i < N ; i ++ ) { System . out . println ( nanbon [ i ] ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long A = Long . parseLong ( sc . next ( ) ) ; long B = Long . parseLong ( sc . next ( ) ) ; long n = Math . abs ( A - ( A - B ) / 2 ) ; if ( Math . abs ( A - n ) == Math . abs ( B - n ) ) { long n = Math . abs ( A - ( A - B ) / 2 ) ; System . out . println ( n ) ; } else { System . out . println ( " IMPOSSIBLE " ) ; } } } +import java . util . Arrays ; import java . util . Scanner ; import java . util . Set ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = Integer . parseInt ( sc . next ( ) ) ; int [ ] d = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { int i = 0 ; d [ i ] = Integer . parseInt ( sc . next ( ) ) ; } Arrays . sort ( d ) ; System . out . println ( d [ n / 2 ] - d [ n / 2 - 1 ] ) ; } } +import java . io . OutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . PrintWriter ; import java . util . StringTokenizer ; import java . io . IOException ; import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . io . InputStream ; public class Main { public static void main ( String [ ] args ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; InputReader in = new InputReader ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; AStationAndBus solver = new AStationAndBus ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class AStationAndBus { public void solve ( int testNumber , InputReader in , PrintWriter out ) { String x = in . next ( ) ; for ( int i = 0 ; i < 3 ; i ++ ) { if ( x . charAt ( i ) != x . charAt ( ( i + 1 ) % 3 ) ) { out . println ( " Yes " ) ; return ; } } out . println ( " No " ) ; } } 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 ( ) ; } } } +import java . io . * ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int [ ] w = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { w [ i ] = sc . nextInt ( ) ; } int ans = 100000000 ; for ( int i = 0 ; i < N ; i ++ ) { int sum1 = 0 ; int sum2 = 0 ; for ( int j = 0 ; j < i ; j ++ ) { sum1 += w [ j ] ; } for ( int k = i ; k < N ; k ++ ) { int k = i ; sum2 += w [ k ] ; } ans = Math . min ( ans , ( int ) Math . abs ( sum1 - sum2 ) ) ; } System . out . println ( ans ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; Scanner scan = new Scanner ( System . in ) ; int n = scan . nextInt ( ) ; for ( int i = 0 ; i < n ; i ++ ) { int a = scan . nextInt ( ) ; if ( a % 2 == 0 && ! ( a % 3 == 0 || a % 5 == 0 ) ) { System . out . println ( " DENIED " ) ; scan . close ( ) ; return ; } } System . out . println ( " APPROVED " ) ; scan . close ( ) ; return ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int q = n ; int num = 0 ; while ( q > 0 ) { num += q % 10 ; q = q / 10 ; } if ( n % num == 0 ) { System . out . println ( " Yes " ) ; } else { int num = 0 ; System . out . println ( " No " ) ; } } } +import java . util . Arrays ; import java . util . HashMap ; import java . util . Map ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { try ( Scanner sc = new Scanner ( System . in ) ) { int n = sc . nextInt ( ) ; Map < String , Integer > map = new HashMap < String , Integer > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { String tmp = change ( sc . next ( ) ) ; if ( map . containsKey ( tmp ) ) { map . put ( tmp , map . get ( tmp ) + 1 ) ; } else { map . put ( tmp , 1 ) ; } } long result = 0 ; for ( String str : map . keySet ( ) ) { String str ; result += calc ( map . get ( str ) ) ; } System . out . println ( result ) ; } } private static long calc ( long num ) { return ( num * ( num - 1 ) ) / 2 ; } private static String change ( String str ) { char [ ] arr = str . toCharArray ( ) ; Arrays . sort ( arr ) ; return new String ( arr ) ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { new Solver ( ) . run ( ) ; } } class Solver { public void run ( ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int [ ] A = new int [ N ] ; int top1 = 0 ; int idx1 = 0 ; for ( int i = 0 ; i < N ; i ++ ) { A [ i ] = sc . nextInt ( ) ; if ( top1 < A [ i ] ) { top1 = A [ i ] ; idx1 = i ; } } int top2 = 0 ; for ( int i = 0 ; i < N ; i ++ ) { int i = 0 ; if ( i != idx1 && top2 < A [ i ] ) { top2 = A [ i ] ; } } long max = Integer . MIN_VALUE ; for ( int i = 0 ; i < N ; i ++ ) { if ( A [ i ] == top1 ) { System . out . println ( top2 ) ; } else { System . out . println ( top1 ) ; } } return ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int n = Integer . parseInt ( br . readLine ( ) ) ; int answer = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int x = Integer . parseInt ( br . readLine ( ) ) ; int flag = 0 ; if ( x == 2 ) { int j = 3 ; flag = 0 ; } else if ( x % 2 == 0 || x < 2 ) { flag = 1 ; } else { double sqrt = Math . sqrt ( x ) ; for ( int j = 3 ; j <= sqrt ; j = j + 2 ) { if ( x % j == 0 ) { flag = 1 ; break ; } } } if ( flag == 0 ) { answer ++ ; } } System . out . println ( answer ) ; } } +import java . io . IOException ; import java . util . Scanner ; class Main { public static void main ( String [ ] args ) throws NumberFormatException , IOException { Scanner scan = new Scanner ( System . in ) ; int n = scan . nextInt ( ) ; int m = scan . nextInt ( ) ; int l = scan . nextInt ( ) ; int [ ] [ ] A = new int [ 100 ] [ 100 ] ; int [ ] [ ] B = new int [ 100 ] [ 100 ] ; long keisan = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int ii = 0 ; ii < m ; ii ++ ) { A [ i ] [ ii ] = scan . nextInt ( ) ; } } for ( int i = 0 ; i < m ; i ++ ) { for ( int ii = 0 ; ii < l ; ii ++ ) { B [ i ] [ ii ] = scan . nextInt ( ) ; } } for ( int i = 0 ; i < n ; i ++ ) { for ( int ii = 0 ; ii < l ; ii ++ ) { keisan = 0 ; for ( int iii = 0 ; iii < m ; iii ++ ) { keisan += A [ i ] [ iii ] * B [ iii ] [ ii ] ; } System . out . print ( keisan ) ; if ( ii < l - 1 ) { int iii = 0 ; System . out . print ( " " ) ; } } System . out . println ( " " ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; String w = scan . nextLine ( ) ; int count = 0 ; while ( scan . hasNext ( ) ) { String T = scan . nextLine ( ) ; if ( T . equals ( " END_OF_TEXT " ) ) { int i = 0 ; break ; } String [ ] Ts = T . split ( " " ) ; for ( int i = 0 ; i < Ts . length ; i ++ ) { if ( Ts [ i ] . equalsIgnoreCase ( w ) ) { count ++ ; } } } System . out . println ( count ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { @ SuppressWarnings ( " resource " ) Scanner scanner = new Scanner ( System . in ) ; int n = scanner . nextInt ( ) ; String s = scanner . next ( ) ; System . out . println ( rotN ( n , s ) ) ; } private static String rotN ( int n , String s ) { StringBuilder sb = new StringBuilder ( ) ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { int i = 0 ; sb . append ( rot ( n , s . charAt ( i ) ) ) ; } return sb . toString ( ) ; } private static char rot ( int n , char ch ) { int code = ( int ) ch - 'A' ; return ( char ) ( ( ( code + n ) % 26 ) + 'A' ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int [ ] H = new int [ N ] ; for ( int i = 0 ; i < H . length ; i ++ ) { H [ i ] = sc . nextInt ( ) ; } sc . close ( ) ; int ans = 1 ; int max = H [ 0 ] ; for ( int i = 1 ; i < H . length ; i ++ ) { if ( max <= H [ i ] ) { int i = 1 ; max = H [ i ] ; ans ++ ; } } System . out . println ( ans ) ; } } +import java . util . * ; import java . lang . * ; class Main { public static void main ( String [ ] args ) { int e ; Scanner sc = new Scanner ( System . in ) ; double w = sc . nextDouble ( ) ; double h = sc . nextDouble ( ) ; int x = sc . nextInt ( ) ; int y = sc . nextInt ( ) ; double s = w * h / 2.0 ; int e ; if ( x == w / 2 && y == h / 2 && w % 2 == 0 && h % 2 == 0 ) { e = 1 ; } else { e = 0 ; } System . out . println ( s ) ; System . out . println ( e ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String str ; String [ ] arrStr ; StringBuilder sb = new StringBuilder ( ) ; try { while ( true ) { str = br . readLine ( ) ; arrStr = str . split ( " " ) ; int h = Integer . parseInt ( arrStr [ 0 ] ) ; int w = Integer . parseInt ( arrStr [ 1 ] ) ; if ( h == 0 && w == 0 ) { int j = 0 ; break ; } boolean iKisu = false ; for ( int i = 0 ; i < h ; i ++ ) { iKisu = ( i % 2 == 0 ) ; for ( int j = 0 ; j < w ; j ++ ) { if ( iKisu ) { sb . append ( j % 2 == 0 ? " # " : " . " ) ; } else { sb . append ( j % 2 == 0 ? " . " : " # " ) ; } } sb . append ( " \n " ) ; } System . out . println ( sb . toString ( ) ) ; sb . setLength ( 0 ) ; } } catch ( IOException e ) { e . printStackTrace ( ) ; } } } +import java . util . Arrays ; import java . util . HashMap ; import java . util . Map ; import java . util . Scanner ; import static java . lang . Math . min ; public class Main { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; Map < String , Integer > count = new HashMap < > ( ) ; int n = in . nextInt ( ) ; for ( int i = 0 ; i < n ; i ++ ) { String s = sort ( in . next ( ) ) ; if ( count . containsKey ( s ) ) { Map . Entry < String , Integer > kv ; count . replace ( s , count . get ( s ) + 1 ) ; } else { count . put ( s , 1 ) ; } } long res = 0 ; for ( Map . Entry < String , Integer > kv : count . entrySet ( ) ) { res += ( long ) kv . getValue ( ) * ( long ) ( kv . getValue ( ) - 1 ) / 2 ; } System . out . println ( res ) ; } private static String sort ( String text ) { char [ ] chars = text . toCharArray ( ) ; Arrays . sort ( chars ) ; return new String ( chars ) ; } } +import java . util . * ; public class Main { static public void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int K = sc . nextInt ( ) ; int [ ] sunuke = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { sunuke [ i ] = 0 ; } int di , A ; for ( int j = 0 ; j < K ; j ++ ) { di = sc . nextInt ( ) ; for ( int k = 0 ; k < di ; k ++ ) { A = sc . nextInt ( ) ; if ( sunuke [ A - 1 ] == 0 ) { sunuke [ A - 1 ] ++ ; } } } int count = 0 ; for ( int h = 0 ; h < N ; h ++ ) { if ( sunuke [ h ] == 0 ) { int h = 0 ; count ++ ; } } System . out . println ( count ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; while ( sc . hasNext ( ) ) { int num = sc . nextInt ( ) ; int taro = 0 , hanako = 0 ; for ( int i = 0 ; i < num ; i ++ ) { String a = sc . next ( ) ; String b = sc . next ( ) ; if ( a . compareTo ( b ) > 0 ) { taro += 3 ; } else if ( a . compareTo ( b ) < 0 ) { hanako += 3 ; } else { int taro = 0 , hanako = 0 ; taro += 1 ; hanako += 1 ; } } System . out . println ( taro + " " + hanako ) ; } } } +import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = Integer . parseInt ( sc . next ( ) ) ; int [ ] l = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { l [ i ] = Integer . parseInt ( sc . next ( ) ) ; } Arrays . sort ( l ) ; int x = 0 ; for ( int i = 0 ; i < n - 1 ; i ++ ) { x += l [ i ] ; } if ( l [ n - 1 ] < x ) { System . out . println ( " Yes " ) ; } else { int i = 0 ; System . out . println ( " No " ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scn = new Scanner ( System . in ) ; int N = scn . nextInt ( ) ; int ans = 0 ; int num = 0 ; while ( N / ( int ) Math . pow ( 10 , num ) > 0 ) { num ++ ; } for ( int i = 0 ; i < num - 1 ; i += 2 ) { ans += 9 * Math . pow ( 10 , i ) ; } if ( num % 2 == 1 ) { int i = 0 ; ans += N - Math . pow ( 10 , num - 1 ) + 1 ; } System . out . println ( ans ) ; } } +import java . util . Scanner ; import java . util . ArrayList ; import java . util . Arrays ; import java . util . Collections ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; ArrayList < Integer > height = new ArrayList < Integer > ( ) ; ArrayList < Integer > width = new ArrayList < Integer > ( ) ; int H , W ; while ( true ) { H = sc . nextInt ( ) ; W = sc . nextInt ( ) ; if ( H == 0 && W == 0 ) break ; height . add ( H ) ; width . add ( W ) ; } int countH = 0 ; int countW = 0 ; for ( countH = 0 ; countH < height . size ( ) ; countH ++ ) { for ( int i = 0 ; i < height . get ( countH ) ; i ++ ) { for ( int t = 0 ; t < width . get ( countW ) ; t ++ ) { int t = 0 ; if ( t < width . get ( countW ) - 1 ) { if ( 0 < t && 0 < i && i < height . get ( countH ) - 1 ) { System . out . print ( " . " ) ; } else { System . out . print ( " # " ) ; } } else if ( t == width . get ( countW ) - 1 ) { System . out . println ( " # " ) ; } } } System . out . println ( " " ) ; countW ++ ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String n = String . valueOf ( sc . nextInt ( ) ) ; String rn = " " ; for ( int i = 0 ; i < 3 ; i ++ ) { int i = 0 ; if ( n . charAt ( i ) == '1' ) rn += " 9 " ; else rn += " 1 " ; } System . out . println ( Integer . valueOf ( rn ) ) ; } } +import java . util . Scanner ; import java . util . Stack ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner scan = new Scanner ( System . in ) ; String [ ] A = scan . nextLine ( ) . split ( " " ) ; Stack < Integer > num = new Stack < Integer > ( ) ; int a = 0 ; int b = 0 ; for ( int i = 0 ; i < A . length ; i ++ ) { if ( A [ i ] . equals ( " + " ) ) { a = num . pop ( ) ; b = num . pop ( ) ; num . add ( b + a ) ; continue ; } if ( A [ i ] . equals ( " - " ) ) { a = num . pop ( ) ; b = num . pop ( ) ; num . add ( b - a ) ; continue ; } if ( A [ i ] . equals ( " * " ) ) { a = num . pop ( ) ; b = num . pop ( ) ; num . add ( b * a ) ; continue ; } if ( A [ i ] . equals ( " / " ) ) { a = num . pop ( ) ; b = num . pop ( ) ; num . add ( b / a ) ; continue ; } num . push ( Integer . parseInt ( A [ i ] ) ) ; } System . out . println ( num . pop ( ) ) ; } } +import java . util . * ; import java . math . BigDecimal ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long ans = sc . nextLong ( ) ; BigDecimal x = BigDecimal . valueOf ( ans ) ; BigDecimal sum = BigDecimal . valueOf ( 100 ) ; BigDecimal foo = BigDecimal . valueOf ( 1.01 ) ; for ( int i = 1 ; sum . compareTo ( x ) == - 1 ; i ++ ) { int i = 1 ; sum = sum . multiply ( foo ) . setScale ( 0 , BigDecimal . ROUND_DOWN ) ; if ( sum . compareTo ( x ) >= 0 ) { System . out . println ( i ) ; } } } } +import java . util . * ; public class Main { public static void main ( String ... args ) { Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int count = 0 ; if ( b != 1 ) { int sum = a ; count = 1 ; } int sum = a ; while ( b > sum ) { sum += a - 1 ; count ++ ; } System . out . println ( count ) ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; int N = Integer . parseInt ( sc . next ( ) ) ; int K = Integer . parseInt ( sc . next ( ) ) ; Integer [ ] h = new Integer [ N ] ; int c = 0 ; for ( int i = 0 ; i < N ; i ++ ) { h [ i ] = Integer . parseInt ( sc . next ( ) ) ; if ( h [ i ] >= K ) c ++ ; } System . out . println ( c ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int num = scan . nextInt ( ) ; int first = num / 100 ; int last = num % 100 ; String answer = " NA " ; if ( last >= 1 && last <= 12 && first >= 1 && first <= 12 ) { String answer = " NA " ; answer = " AMBIGUOUS " ; } else if ( last >= 1 && last <= 12 ) { answer = " YYMM " ; } else if ( first >= 1 && first <= 12 ) { answer = " MMYY " ; } System . out . println ( answer ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int a = scan . nextInt ( ) ; int b = scan . nextInt ( ) ; int max = a + b ; if ( max < a - b ) { max = a - b ; } if ( max < a * b ) { int max = a + b ; max = a * b ; } System . out . println ( max ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; String s = scanner . nextLine ( ) ; long sum = 0 ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { sum += s . charAt ( i ) - '0' ; } if ( sum % 9 == 0 ) { int i = 0 ; System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String [ ] weathers = new String [ 3 ] ; weathers [ 0 ] = " Sunny " ; weathers [ 1 ] = " Cloudy " ; weathers [ 2 ] = " Rainy " ; String today = sc . next ( ) ; int cnt = 0 ; for ( String weather : weathers ) { String weather ; if ( weather . equals ( today ) ) { System . out . println ( weathers [ ( cnt + 1 ) % 3 ] ) ; return ; } cnt ++ ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int m = sc . nextInt ( ) ; int c = sc . nextInt ( ) ; int count = 0 ; int [ ] array_b = new int [ m ] ; for ( int i = 0 ; i < m ; i ++ ) { array_b [ i ] = sc . nextInt ( ) ; } for ( int i = 0 ; i < n ; i ++ ) { int [ ] array_a = new int [ m ] ; int ans = 0 ; for ( int j = 0 ; j < m ; j ++ ) { int j = 0 ; int temp = sc . nextInt ( ) ; ans += array_b [ j ] * temp ; } ans += c ; if ( ans > 0 ) { count ++ ; } } System . out . println ( count ) ; } } +import java . io . * ; class Main { public static void main ( String [ ] args ) throws Exception { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String W = br . readLine ( ) ; String [ ] T ; int c = 0 ; while ( true ) { String str ; T = br . readLine ( ) . split ( " " ) ; if ( T [ 0 ] . equals ( " END_OF_TEXT " ) ) break ; for ( String str : T ) { if ( str . equalsIgnoreCase ( W ) ) c ++ ; } } System . out . println ( c ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; final int NUM = scan . nextInt ( ) ; String [ ] words = new String [ NUM ] ; for ( int i = 0 ; i < NUM ; i ++ ) { String input = scan . next ( ) ; char [ ] inputChar = input . toCharArray ( ) ; Arrays . sort ( inputChar ) ; words [ i ] = new String ( inputChar ) ; } Arrays . sort ( words ) ; String memory = words [ 0 ] ; long count = 1 ; long answer = 0 ; for ( int i = 1 ; i < NUM ; i ++ ) { if ( memory . equals ( words [ i ] ) ) { count ++ ; } else { answer += count * ( count - 1 ) / 2 ; memory = words [ i ] ; count = 1 ; } } if ( count >= 2 ) { int i = 1 ; answer += count * ( count - 1 ) / 2 ; } System . out . println ( answer ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long N = sc . nextInt ( ) ; long total = 0 ; for ( long i = 0 ; i <= N ; i ++ ) { if ( i % 3 != 0 && i % 5 != 0 ) { long i = 0 ; total += i ; } } System . out . println ( total ) ; } } +import java . util . * ; import java . io . * ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int n = scan . nextInt ( ) ; int max = 0 ; int ans = 0 ; int cnt = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { int j = i ; int j = i ; while ( j % 2 == 0 ) { j /= 2 ; cnt ++ ; } if ( cnt >= max ) { max = cnt ; ans = i ; } cnt = 0 ; } System . out . println ( ans ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String S = sc . next ( ) ; long K = sc . nextLong ( ) ; if ( S . length ( ) == 1 ) { System . out . println ( S ) ; return ; } int i = 0 ; while ( i < S . length ( ) && S . charAt ( i ) == '1' ) { int i = 0 ; i ++ ; } if ( K <= i ) { System . out . println ( 1 ) ; return ; } System . out . print ( S . charAt ( i ) ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; long K = sc . nextLong ( ) ; int Q = sc . nextInt ( ) ; long lim = K - Q ; int [ ] winCon = new int [ N + 1 ] ; for ( int i = 0 ; i < Q ; i ++ ) { winCon [ sc . nextInt ( ) ] ++ ; } for ( int i = 1 ; i < winCon . length ; i ++ ) { if ( winCon [ i ] + lim > 0 ) { int i = 1 ; System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int j = 0 ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; String [ ] str = new String [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { str [ i ] = sc . next ( ) ; } int acCount = 0 ; int waCount = 0 ; int tleCount = 0 ; int reCount = 0 ; for ( int j = 0 ; j < n ; j ++ ) { if ( str [ j ] . equals ( " AC " ) ) { acCount ++ ; } else if ( str [ j ] . equals ( " WA " ) ) { waCount ++ ; } else if ( str [ j ] . equals ( " TLE " ) ) { tleCount ++ ; } else if ( str [ j ] . equals ( " RE " ) ) { reCount ++ ; } } System . out . printf ( " AC x %d \n " , acCount ) ; System . out . printf ( " WA x %d \n " , waCount ) ; System . out . printf ( " TLE x %d \n " , tleCount ) ; System . out . printf ( " RE x %d \n " , reCount ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { double exp = Math . pow ( b , p ) ; Scanner sc = new Scanner ( System . in ) ; int X = sc . nextInt ( ) ; int max = 1 ; for ( int b = 1 ; b < 32 ; b ++ ) { for ( int p = 2 ; p < 10 ; p ++ ) { double exp = Math . pow ( b , p ) ; if ( exp > X ) { break ; } if ( max < exp ) { max = ( int ) exp ; } } } System . out . println ( max ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long n = Long . parseLong ( sc . next ( ) ) ; int sqrt = ( int ) Math . sqrt ( n ) ; for ( int i = sqrt ; i >= 1 ; i -- ) { if ( n % i == 0 ) { int i = sqrt ; System . out . println ( i + n / i - 2 ) ; break ; } } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; String str = scan . next ( ) ; char [ ] c = str . toCharArray ( ) ; for ( int i = 0 ; i < c . length ; i ++ ) { int count = 0 ; for ( int j = 0 ; j < c . length ; j ++ ) { if ( c [ i ] == c [ j ] ) { int j = 0 ; count ++ ; } } if ( count % 2 != 0 ) { System . out . println ( " No " ) ; System . exit ( 0 ) ; } } System . out . println ( " Yes " ) ; } } +import java . io . InputStream ; import java . io . PrintStream ; import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { solve ( System . in , System . out ) ; } static void solve ( InputStream is , PrintStream os ) { int ans = 0 ; Scanner scan = new Scanner ( is ) ; int N = scan . nextInt ( ) ; int K = scan . nextInt ( ) ; int ans = 0 ; while ( N >= K ) { N /= K ; ans ++ ; } if ( N != 0 ) ans ++ ; os . println ( ans ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { String ans ; Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; String ans ; if ( s . equals ( " Sunny " ) ) { ans = " Cloudy " ; } else if ( s . equals ( " Cloudy " ) ) { ans = " Rainy " ; } else { ans = " Sunny " ; } System . out . println ( ans ) ; sc . close ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int m = sc . nextInt ( ) ; int [ ] [ ] matrix = new int [ n ] [ m ] ; int [ ] vector = new int [ m ] ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < m ; j ++ ) { int j = 0 ; matrix [ i ] [ j ] = sc . nextInt ( ) ; } } for ( int i = 0 ; i < m ; i ++ ) { vector [ i ] = sc . nextInt ( ) ; } for ( int i = 0 ; i < n ; i ++ ) { int sum = 0 ; for ( int j = 0 ; j < m ; j ++ ) { sum += matrix [ i ] [ j ] * vector [ j ] ; } System . out . println ( sum ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner scan = new Scanner ( System . in ) ; int n = scan . nextInt ( ) ; int [ ] a = new int [ n ] ; int [ ] b = new int [ n ] ; int [ ] c = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = scan . nextInt ( ) - 1 ; } for ( int i = 0 ; i < n ; i ++ ) { b [ i ] = scan . nextInt ( ) ; } for ( int i = 1 ; i < n ; i ++ ) { c [ i ] = scan . nextInt ( ) ; } int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { sum = sum + b [ a [ i ] ] ; if ( i != 0 && a [ i ] - a [ i - 1 ] == 1 ) { sum = sum + c [ a [ i ] ] ; } } System . out . println ( sum ) ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int [ ] [ ] values = new int [ 3 ] [ 3 ] ; for ( int i = 0 ; i < 3 ; i ++ ) { for ( int j = 0 ; j < 3 ; j ++ ) { values [ i ] [ j ] = sc . nextInt ( ) ; } } boolean ok = false ; for ( int i = 0 ; i < 101 ; i ++ ) { for ( int j = 0 ; j < 101 ; j ++ ) { int k = 0 ; for ( int k = 0 ; k < 101 ; k ++ ) { int b1 = values [ 0 ] [ 0 ] - i ; int b2 = values [ 0 ] [ 1 ] - i ; int b3 = values [ 0 ] [ 2 ] - i ; if ( b1 < 0 || b2 < 0 || b3 < 0 ) continue ; if ( ( values [ 1 ] [ 0 ] == j + b1 && values [ 1 ] [ 1 ] == j + b2 && values [ 1 ] [ 2 ] == j + b3 ) && ( values [ 2 ] [ 0 ] == k + b1 && values [ 2 ] [ 1 ] == k + b2 && values [ 2 ] [ 2 ] == k + b3 ) ) { ok = true ; } } } } System . out . println ( ok ? " Yes " : " No " ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; StringBuilder sb = new StringBuilder ( ) ; int n = sc . nextInt ( ) ; int [ ] a = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = sc . nextInt ( ) ; } int t = a [ n - 1 ] ; int max = 0 , cnt = 0 ; for ( int i = n - 2 ; i >= 0 ; i -- ) { int i = n - 2 ; if ( t <= a [ i ] ) { cnt ++ ; max = Math . max ( max , cnt ) ; } else { cnt = 0 ; } t = a [ i ] ; } System . out . println ( max ) ; } } +import java . io . * ; class Main { public static void main ( String [ ] args ) { try { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int n = Integer . parseInt ( br . readLine ( ) ) ; String buf = br . readLine ( ) ; String [ ] line = buf . split ( " " ) ; int a = Integer . parseInt ( line [ 0 ] ) ; long max = a ; long min = a ; long total = a ; for ( int i = 1 ; i < n ; i ++ ) { int b = Integer . parseInt ( line [ i ] ) ; if ( max < b ) max = b ; if ( min > b ) min = b ; total = total + b ; } System . out . print ( min + " " + max + " " + total ) ; System . out . print ( " \n " ) ; } catch ( Exception e ) { int i = 1 ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] h = new int [ n + 2 ] ; int maxh = 0 ; int zero1 = 0 ; int zero2 = n ; int ret = 0 ; for ( int i = 1 ; i < n + 1 ; i ++ ) { h [ i ] = sc . nextInt ( ) ; maxh = Math . max ( maxh , h [ i ] ) ; } h [ 0 ] = 0 ; h [ n + 1 ] = 0 ; for ( int i = 1 ; i <= maxh ; i ++ ) { zero1 = 0 ; zero2 = n ; for ( int j = 0 ; j < n + 2 ; j ++ ) { int k = 0 ; if ( h [ j ] == 0 ) { zero2 = j ; if ( zero2 - zero1 > 1 ) { ret ++ ; } zero1 = zero2 ; } } for ( int k = 0 ; k < n + 2 ; k ++ ) { if ( h [ k ] > 0 ) { h [ k ] -- ; } } } System . out . println ( ret ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String str = sc . next ( ) ; int [ ] A = new int [ str . length ( ) ] ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { int i = 0 ; A [ i ] = str . charAt ( i ) ; } if ( A [ 0 ] == A [ 1 ] || A [ 1 ] == A [ 2 ] || A [ 2 ] == A [ 3 ] ) { System . out . println ( " Bad " ) ; } else { System . out . println ( " Good " ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int x = scan . nextInt ( ) ; Scanner scan = new Scanner ( System . in ) ; int n = scan . nextInt ( ) ; int min = 0 ; int max = 0 ; long amount = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int x = scan . nextInt ( ) ; if ( i == 0 ) { min = x ; max = x ; amount = x ; } else { if ( x < min ) { min = x ; } else if ( x > max ) { max = x ; } amount = amount + x ; } } System . out . println ( min + " " + max + " " + amount ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int K = sc . nextInt ( ) ; int Q = sc . nextInt ( ) ; int [ ] m = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { int i = 0 ; m [ i ] = K ; } for ( int i = 0 ; i < Q ; i ++ ) { int c = sc . nextInt ( ) ; m [ c - 1 ] ++ ; } for ( int i = 0 ; i < m . length ; i ++ ) { System . out . println ( ( m [ i ] - Q ) > 0 ? " Yes " : " No " ) ; } sc . close ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int c = 0 ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int a = sc . nextInt ( ) ; int c = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int b = sc . nextInt ( ) ; if ( a <= b ) c ++ ; } System . out . println ( c ) ; } } +import java . util . * ; public class Main { static Scanner scanner = new Scanner ( System . in ) ; public static void main ( String [ ] $ ) { int x = scanner . nextInt ( ) ; int max = 1 ; for ( int i = 2 ; i <= x ; i ++ ) { int j = i ; while ( true ) { int j = i ; j *= i ; if ( j > x ) { break ; } max = Math . max ( max , j ) ; } } System . out . println ( max ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { String x = " " ; Scanner sc = new Scanner ( System . in ) ; int a = 0 ; int b = 0 ; int c = 0 ; int d = 0 ; int score = 0 ; String x = " " ; a = sc . nextInt ( ) ; x = sc . next ( ) ; if ( x . length ( ) > a ) { x = x . substring ( 0 , a ) + " ... " ; } System . out . print ( x ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; Integer N = Integer . parseInt ( sc . next ( ) ) ; Integer Y = Integer . parseInt ( sc . next ( ) ) ; for ( int i = 0 ; i <= N ; i ++ ) { int n = N - i - m ; for ( int m = 0 ; m <= N - i ; m ++ ) { int n = N - i - m ; if ( i * 10000 + m * 5000 + n * 1000 == Y ) { System . out . println ( i + " " + m + " " + n ) ; return ; } } } System . out . println ( " -1 -1 -1 " ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int i = 1 ; taskScheduling ( ) ; } public static void taskScheduling ( ) { Scanner sc = new Scanner ( System . in ) ; int [ ] a = new int [ 3 ] ; a [ 0 ] = sc . nextInt ( ) ; a [ 1 ] = sc . nextInt ( ) ; a [ 2 ] = sc . nextInt ( ) ; Arrays . sort ( a ) ; int res = 0 ; for ( int i = 1 ; i < a . length ; i ++ ) { res += a [ i ] - a [ i - 1 ] ; } System . out . println ( res ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; String a = scanner . next ( ) ; String b = scanner . next ( ) ; int length = Math . min ( a . length ( ) , b . length ( ) ) ; int pos = 0 ; while ( pos < length ) { if ( 0 != ( a . charAt ( pos ) ^ b . charAt ( pos ) ) ) { int pos = 0 ; break ; } pos ++ ; } if ( a . substring ( pos ) . length ( ) == 0 ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int t = 0 ; Scanner stdIn = new Scanner ( System . in ) ; int a = stdIn . nextInt ( ) ; int b = stdIn . nextInt ( ) ; int ab = stdIn . nextInt ( ) ; int x = stdIn . nextInt ( ) ; int y = stdIn . nextInt ( ) ; int a_b = ( ab * 2 ) ; long sum = 0 ; int t = 0 ; if ( a_b > a + b ) { t = 1 ; } else { t = 2 ; } if ( t == 2 ) { sum += Math . min ( x , y ) * a_b ; if ( x > y ) { sum += ( x - y ) * a ; } else { sum += ( y - x ) * b ; } sum = Math . min ( sum , a_b * ( Math . max ( x , y ) ) ) ; } else { sum += ( x * a ) + ( y * b ) ; } System . out . println ( sum ) ; } } +import java . util . Scanner ; public class Main { private static int gcd ( int a , int b ) { if ( ( a % b ) == 0 ) return b ; return gcd ( b , a % b ) ; } public static void main ( String [ ] args ) { int k = 1 ; Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int tmp ; int count = 0 ; for ( int i = 1 ; i < a + 1 ; i ++ ) { for ( int j = 1 ; j < a + 1 ; j ++ ) { tmp = gcd ( i , j ) ; for ( int k = 1 ; k < a + 1 ; k ++ ) { count += gcd ( k , tmp ) ; } } } System . out . println ( count ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int maxHigh = 0 ; int view = 0 ; for ( int i = 0 ; i < N ; i ++ ) { int High = sc . nextInt ( ) ; if ( maxHigh <= High ) { int High = sc . nextInt ( ) ; maxHigh = High ; view ++ ; } } System . out . println ( view ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int k = sc . nextInt ( ) ; int [ ] alpha = new int [ n ] ; int i , j ; for ( i = 0 ; i < n ; i ++ ) { alpha [ i ] = sc . nextInt ( ) ; } int flag ; for ( j = 1 ; j < alpha . length ; j ++ ) { int ans = 0 ; int key = alpha [ j ] ; i = j - 1 ; while ( i >= 0 && alpha [ i ] > key ) { alpha [ i + 1 ] = alpha [ i ] ; i -- ; } alpha [ i + 1 ] = key ; } int ans = 0 ; for ( j = 0 ; j < k ; j ++ ) { ans += alpha [ j ] ; } System . out . println ( ans ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; final String EOT = " END_OF_TEXT " ; String w , t ; int count = 0 ; w = sc . next ( ) ; while ( true ) { t = sc . next ( ) ; if ( t . equals ( EOT ) ) { int count = 0 ; break ; } if ( t . equalsIgnoreCase ( w ) ) { count ++ ; } } System . out . println ( count ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int kind = sc . nextInt ( ) ; int [ ] di = new int [ kind ] ; int [ ] count = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { count [ i ] = 0 ; } for ( int i = 0 ; i < kind ; i ++ ) { int i = 0 ; di [ i ] = sc . nextInt ( ) ; for ( int j = 0 ; j < di [ i ] ; j ++ ) { count [ sc . nextInt ( ) - 1 ] ++ ; } } int trickCount = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( count [ i ] == 0 ) { trickCount ++ ; } } System . out . println ( trickCount ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner stdin = new Scanner ( System . in ) ; int num = Integer . parseInt ( stdin . nextLine ( ) ) ; boolean boo = true ; int [ ] seq = new int [ num ] ; if ( num <= 100 ) { int j = num ; for ( int i = 0 ; i < num ; i ++ ) { seq [ i ] = stdin . nextInt ( ) ; if ( seq [ i ] >= 0 && seq [ i ] <= 1000 ) { continue ; } else { boo = false ; break ; } } } if ( boo == true ) { for ( int j = num ; j > 0 ; j -- ) { if ( j != 1 ) { System . out . print ( seq [ j - 1 ] + " " ) ; } else { System . out . println ( seq [ j - 1 ] ) ; } } } stdin . close ( ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int k ; k = in . nextInt ( ) ; int a , b , i , num ; a = in . nextInt ( ) ; b = in . nextInt ( ) ; num = a ; for ( i = num ; i <= b ; i ++ , num ++ ) { int a , b , i , num ; if ( i % k == 0 ) { System . out . println ( " OK " ) ; System . exit ( 0 ) ; } } System . out . println ( " NG " ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int m = sc . nextInt ( ) ; int l = sc . nextInt ( ) ; int [ ] [ ] mrxA = new int [ n ] [ m ] ; int [ ] [ ] mrxB = new int [ m ] [ l ] ; long [ ] [ ] mrxC = new long [ n ] [ l ] ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < m ; j ++ ) { int k = 0 ; mrxA [ i ] [ j ] = sc . nextInt ( ) ; } } for ( int i = 0 ; i < m ; i ++ ) { for ( int j = 0 ; j < l ; j ++ ) { mrxB [ i ] [ j ] = sc . nextInt ( ) ; } } for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < l ; j ++ ) { for ( int k = 0 ; k < m ; k ++ ) { mrxC [ i ] [ j ] += ( mrxA [ i ] [ k ] * mrxB [ k ] [ j ] ) ; } System . out . print ( mrxC [ i ] [ j ] ) ; if ( j != l - 1 ) { System . out . print ( " " ) ; } } System . out . println ( ) ; } } } +import java . util . HashSet ; import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { HashSet hs = new HashSet ( ) ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int k = sc . nextInt ( ) ; int d ; int count = 0 ; HashSet hs = new HashSet ( ) ; while ( k -- > 0 ) { d = sc . nextInt ( ) ; for ( int i = 0 ; i < d ; i ++ ) { hs . add ( sc . nextInt ( ) ) ; } } System . out . println ( n - hs . size ( ) ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int be = sc . nextInt ( ) ; int ans = 0 ; boolean check1 = false , check2 = false ; for ( int i = 1 ; i < N ; i ++ ) { boolean check1 = false , check2 = false ; int ch = sc . nextInt ( ) ; if ( be < ch ) { if ( check1 == true ) ans ++ ; check1 = true ; check2 = false ; } else if ( be > ch ) { if ( check2 == true ) ans ++ ; check1 = false ; check2 = true ; } else { check1 = false ; check2 = false ; } be = ch ; } System . out . println ( ans ) ; } } +import java . io . PrintWriter ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = Integer . parseInt ( sc . next ( ) ) ; int Y = Integer . parseInt ( sc . next ( ) ) ; int k = 0 ; PrintWriter out = new PrintWriter ( System . out ) ; for ( int i = 0 ; i <= N ; i ++ ) { for ( int j = 0 ; j <= N - i ; j ++ ) { int j = 0 ; k = N - i - j ; if ( 10000 * i + 5000 * j + 1000 * k == Y ) { out . println ( i + " " + j + " " + k ) ; sc . close ( ) ; out . flush ( ) ; return ; } } } out . println ( " -1 -1 -1 " ) ; sc . close ( ) ; out . flush ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int [ ] nums = new int [ 11 ] ; for ( int i = 0 ; i < 3 ; i ++ ) { int [ ] nums = new int [ 11 ] ; int num = sc . nextInt ( ) ; nums [ num ] ++ ; } if ( nums [ 5 ] == 2 && nums [ 7 ] == 1 ) System . out . println ( " YES " ) ; else System . out . println ( " NO " ) ; sc . close ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] a = new int [ n ] ; float sum = 0 ; for ( int y = 0 ; y < n ; y ++ ) { a [ y ] = sc . nextInt ( ) ; sum += a [ y ] ; } int p = Math . round ( sum / n ) ; int res = 0 ; for ( int i = 0 ; i < n ; i ++ ) { res += ( a [ i ] - p ) * ( a [ i ] - p ) ; } System . out . println ( res ) ; sc . close ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; int [ ] x = new int [ 4 ] ; char [ ] y = new char [ 3 ] ; x [ 0 ] = Integer . parseInt ( s . substring ( 0 , 1 ) ) ; x [ 1 ] = Integer . parseInt ( s . substring ( 1 , 2 ) ) ; x [ 2 ] = Integer . parseInt ( s . substring ( 2 , 3 ) ) ; x [ 3 ] = Integer . parseInt ( s . substring ( 3 , 4 ) ) ; for ( int i = 0 ; i < 8 ; i ++ ) { int j = 0 ; int sum = x [ 0 ] ; for ( int j = 0 ; j < 3 ; j ++ ) { if ( ( 1 & ( i >> j ) ) == 1 ) { sum += x [ 3 - j ] ; y [ 2 - j ] = '+' ; } else { sum -= x [ 3 - j ] ; y [ 2 - j ] = '-' ; } } if ( sum == 7 ) { System . out . print ( x [ 0 ] ) ; System . out . print ( y [ 0 ] ) ; System . out . print ( x [ 1 ] ) ; System . out . print ( y [ 1 ] ) ; System . out . print ( x [ 2 ] ) ; System . out . print ( y [ 2 ] ) ; System . out . print ( x [ 3 ] ) ; System . out . print ( " =7 " ) ; return ; } } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int c = 4 ; int d = 7 ; int flag = 0 ; int cut = 0 ; for ( int i = 0 ; i <= 25 ; i ++ ) { for ( int j = 0 ; j <= 14 ; j ++ ) { cut = c * i + d * j ; if ( cut == 0 ) cut = 4 ; if ( n % cut == 0 ) { flag = 1 ; break ; } if ( cut > 100 ) { int j = 0 ; break ; } } if ( flag == 1 ) break ; } if ( flag == 1 ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int a , b ; Scanner scanner = new Scanner ( System . in ) ; while ( scanner . hasNext ( ) ) { a = scanner . nextInt ( ) ; b = scanner . nextInt ( ) ; System . out . println ( ( String . valueOf ( a + b ) . length ( ) ) ) ; } scanner . close ( ) ; } } +import java . util . ArrayList ; import java . util . List ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int m = sc . nextInt ( ) ; List < Integer > k = new ArrayList < > ( ) ; List < List < Integer > > a = new ArrayList < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { int i = 1 ; k . add ( sc . nextInt ( ) ) ; List < Integer > list = new ArrayList < > ( ) ; for ( int j = 0 ; j < k . get ( i ) ; j ++ ) { list . add ( sc . nextInt ( ) ) ; } a . add ( list ) ; } List < Integer > correct = new ArrayList < > ( a . get ( 0 ) ) ; for ( int i = 1 ; i < n ; i ++ ) { correct . retainAll ( a . get ( i ) ) ; } System . out . println ( correct . size ( ) ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] [ ] array = new int [ n ] [ 2 ] ; for ( int i = 0 ; i < n ; i ++ ) { array [ i ] [ 0 ] = sc . nextInt ( ) ; } for ( int i = 0 ; i < n ; i ++ ) { array [ i ] [ 1 ] = sc . nextInt ( ) ; } int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int s = array [ i ] [ 0 ] - array [ i ] [ 1 ] ; if ( s > 0 ) { int s = array [ i ] [ 0 ] - array [ i ] [ 1 ] ; sum += s ; } } System . out . println ( sum ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { String answer = " No " ; Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; int n = s . length ( ) ; String str1 = s . substring ( 0 , ( n - 1 ) / 2 ) ; String str2 = s . substring ( ( ( n + 3 ) - 1 ) / 2 ) ; String answer = " No " ; if ( checkKaibun ( s ) && checkKaibun ( str1 ) && checkKaibun ( str2 ) ) { answer = " Yes " ; } System . out . println ( answer ) ; sc . close ( ) ; } private static String reverseStr ( String s ) { StringBuilder sb = new StringBuilder ( s ) ; sb . reverse ( ) ; return sb . toString ( ) ; } private static boolean checkKaibun ( String s ) { if ( s . equals ( reverseStr ( s ) ) ) { return true ; } return false ; } } +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 ) ; TaskB solver = new TaskB ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class TaskB { int LOWER_LIMIT = - 1000_000_000 ; int UPPER_LIMIT = 1000_000_000 ; public void solve ( int testNumber , Scanner in , PrintWriter out ) { int i = start ; int K = in . nextInt ( ) ; int X = in . nextInt ( ) ; int start = 0 ; int end = 0 ; if ( X - LOWER_LIMIT + 1 < K ) { start = LOWER_LIMIT ; end = X + K - 1 ; } else if ( UPPER_LIMIT - X + 1 < K ) { start = UPPER_LIMIT - X + 1 ; end = UPPER_LIMIT ; } else { start = X - ( K - 1 ) ; end = X + ( K - 1 ) ; } for ( int i = start ; i <= end ; i ++ ) { out . println ( i ) ; } } } } +import java . util . Scanner ; public class Main { static boolean binary_search ( int x , int [ ] data ) { int left = 0 , right = data . length ; while ( true ) { int mid = ( left + right ) / 2 ; if ( left > right ) return false ; if ( data [ mid ] == x ) { int i = 0 ; return true ; } else if ( data [ mid ] < x ) { left = mid + 1 ; } else { right = mid - 1 ; } } } public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int n = scanner . nextInt ( ) ; int [ ] s = new int [ n ] ; for ( int i = 0 ; i < n ; ++ i ) { s [ i ] = scanner . nextInt ( ) ; } int q = scanner . nextInt ( ) ; int cnt = 0 ; for ( int i = 0 ; i < q ; ++ i ) { int t = scanner . nextInt ( ) ; if ( binary_search ( t , s ) ) ++ cnt ; } System . out . println ( cnt ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int sum = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { int temp ; for ( int j = 1 ; j <= n ; j ++ ) { for ( int k = 1 ; k <= n ; k ++ ) { sum += gcd ( i , gcd ( j , k ) ) ; } } } System . out . println ( sum ) ; } static int gcd ( int a , int b ) { int temp ; while ( ( temp = a % b ) != 0 ) { a = b ; b = temp ; } return b ; } } +import java . util . LinkedHashSet ; import java . util . Scanner ; import java . util . Set ; 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 ++ ) { int i = 0 ; a [ i ] = sc . nextInt ( ) ; } Set < Integer > lhs = new LinkedHashSet < Integer > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { lhs . add ( a [ i ] ) ; } Object [ ] newa = lhs . toArray ( ) ; System . out . println ( newa . length ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int c = sc . nextInt ( ) ; int k = sc . nextInt ( ) ; int cnt = 0 ; while ( true ) { if ( a > k ) { int cnt = 0 ; cnt += k ; k = 0 ; break ; } else { cnt += a ; k -= a ; } if ( k <= 0 ) { break ; } if ( b > k ) { k = 0 ; break ; } else { k -= b ; } if ( k <= 0 ) { break ; } if ( c > k ) { cnt -= k ; k = 0 ; break ; } else { cnt -= c ; k -= c ; } if ( k <= 0 ) { break ; } } System . out . println ( cnt ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String S = sc . next ( ) ; sc . close ( ) ; int zero = 0 ; int one = 0 ; for ( int i = 0 ; i < S . length ( ) ; i ++ ) { int i = 0 ; if ( S . charAt ( i ) == '0' ) { zero ++ ; } else { one ++ ; } } System . out . println ( 2 * Math . min ( zero , one ) ) ; } } +import java . util . * ; import java . math . * ; import java . io . * ; import java . lang . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int l = sc . nextInt ( ) ; int [ ] ar = new int [ n ] ; int sum = 0 ; int res = 114514 ; for ( int i = 0 ; i < n ; i ++ ) { ar [ i ] = l + i ; sum += ar [ i ] ; if ( Math . abs ( res ) > Math . abs ( ar [ i ] ) ) { int i = 0 ; res = ar [ i ] ; } } res = sum - res ; System . out . println ( res ) ; } } class io { public static void br ( ) { System . out . println ( " " ) ; } public static void YesNo ( boolean f ) { System . out . println ( f ? " Yes " : " No " ) ; } public static void YESNO ( boolean f ) { System . out . println ( f ? " YES " : " NO " ) ; } } class Algo { public static boolean isOdd ( int n ) { return n % 2 == 1 ; } public static boolean isEven ( int n ) { return n % 2 == 0 ; } } +import java . util . * ; public class Main { static public void main ( String [ ] args ) { Scanner s = new Scanner ( System . in ) ; int n = s . nextInt ( ) ; String c = s . next ( ) ; if ( n % 2 == 1 ) { int i = 0 ; System . out . println ( " No " ) ; } else { boolean yes = true ; for ( int i = 0 ; i < n / 2 && yes ; i ++ ) { if ( c . charAt ( i ) != c . charAt ( i + n / 2 ) ) yes = false ; } if ( yes ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } } } +import java . util . Scanner ; public class Main { static void lnJudge ( char a , boolean ln ) { if ( ln == true ) { System . out . println ( a ) ; } else { System . out . print ( a ) ; } } public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; while ( true ) { int H = sc . nextInt ( ) ; int W = sc . nextInt ( ) ; if ( H == 0 && W == 0 ) { break ; } for ( int i = 0 ; i < H ; i ++ ) { int j = 0 ; char p ; if ( i == 0 || i == H - 1 ) { p = '#' ; } else { p = '.' ; } for ( int j = 0 ; j < W ; j ++ ) { if ( j == W - 1 ) { lnJudge ( '#' , true ) ; } else if ( j == 0 ) { lnJudge ( '#' , false ) ; } else { lnJudge ( p , false ) ; } } } System . out . println ( " " ) ; } sc . close ( ) ; } } +import java . util . HashSet ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; HashSet < Integer > A = new HashSet < > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { if ( ! A . add ( sc . nextInt ( ) ) ) { HashSet < Integer > A = new HashSet < > ( ) ; System . out . println ( " NO " ) ; return ; } } System . out . println ( " YES " ) ; sc . close ( ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . regex . Matcher ; import java . util . regex . Pattern ; public class Main { public static void main ( String [ ] args ) { BufferedReader reader = new BufferedReader ( new InputStreamReader ( System . in ) ) ; try { String s = reader . readLine ( ) ; String p = reader . readLine ( ) ; String ss = s + s ; Pattern pat = Pattern . compile ( p ) ; check ( pat , ss ) ; } catch ( IOException e ) { Pattern pat = Pattern . compile ( p ) ; System . out . print ( e ) ; } } private static void check ( Pattern pat , String ss ) { Matcher m = pat . matcher ( ss ) ; if ( m . find ( ) ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Main main = new Main ( ) ; main . run ( ) ; } long n ; long k ; long res ; public void run ( ) { Scanner sc = new Scanner ( System . in ) ; n = sc . nextLong ( ) ; k = sc . nextLong ( ) ; sc . close ( ) ; solve ( ) ; } private void solve ( ) { a ( n % k ) ; System . out . println ( res ) ; } private void a ( long a ) { if ( Math . abs ( a - k ) <= a ) { a = Math . abs ( a - k ) ; a ( a ) ; } else { res = a ; return ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N , T , A ; N = sc . nextInt ( ) ; T = sc . nextInt ( ) ; A = sc . nextInt ( ) ; int [ ] H = new int [ N ] ; double max = 99999 ; int ans = 0 ; for ( int i = 0 ; i < N ; i ++ ) { H [ i ] = sc . nextInt ( ) ; double t = T - H [ i ] * 0.006 ; if ( max > Math . abs ( A - t ) ) { double t = T - H [ i ] * 0.006 ; ; max = Math . abs ( A - t ) ; ans = i + 1 ; } } sc . close ( ) ; System . out . println ( ans ) ; } } +import java . io . * ; import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int w = sc . nextInt ( ) ; int n = sc . nextInt ( ) ; int [ ] a = new int [ w ] ; int [ ] b = new int [ n ] ; int [ ] c = new int [ n ] ; int temp = 0 ; int i = 0 ; String str ; for ( i = 0 ; i < n ; i ++ ) { str = sc . next ( ) ; String [ ] bc = str . split ( " , " ) ; b [ i ] = Integer . parseInt ( bc [ 0 ] ) - 1 ; c [ i ] = Integer . parseInt ( bc [ 1 ] ) - 1 ; } for ( i = 0 ; i < w ; i ++ ) { String str ; a [ i ] = i + 1 ; } for ( i = 0 ; i < n ; i ++ ) { temp = a [ b [ i ] ] ; a [ b [ i ] ] = a [ c [ i ] ] ; a [ c [ i ] ] = temp ; } for ( i = 0 ; i < w ; i ++ ) { System . out . println ( a [ i ] ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner input = new Scanner ( System . in ) ; int n ; double [ ] b = new double [ 1111 ] ; double av ; double sum ; while ( true ) { n = input . nextInt ( ) ; if ( n == 0 ) break ; else { sum = 0 ; av = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int i = 0 ; b [ i ] = input . nextDouble ( ) ; av += b [ i ] ; } av /= n ; for ( int i = 0 ; i < n ; i ++ ) { sum += ( b [ i ] - av ) * ( b [ i ] - av ) / n ; } System . out . println ( Math . sqrt ( sum ) ) ; } } input . close ( ) ; } } +import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . io . IOException ; class Main { public static void main ( String [ ] args ) throws IOException { double a , b , f ; int d , r ; double a , b , f ; BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String input = br . readLine ( ) ; String [ ] strArray = input . split ( " " ) ; a = Integer . parseInt ( strArray [ 0 ] ) ; b = Integer . parseInt ( strArray [ 1 ] ) ; d = getD ( a , b ) ; r = getR ( a , b ) ; f = getF ( a , b ) ; System . out . printf ( " %d %d %.5f " , d , r , f ) ; } static int getD ( double a , double b ) { return ( int ) ( a / b ) ; } static int getR ( double a , double b ) { return ( int ) ( a % b ) ; } static double getF ( double a , double b ) { return a / b ; } } +import java . util . Scanner ; public class Main { void solve ( ) { int j = i + 1 ; Scanner sc = new Scanner ( System . in ) ; int L = sc . nextInt ( ) ; int R = sc . nextInt ( ) ; long min = Long . MAX_VALUE ; for ( int i = L ; i <= R ; i ++ ) { for ( int j = i + 1 ; j <= R ; j ++ ) { long ij = ( ( long ) i * j ) % 2019 ; if ( ij == 0 ) { min = 0 ; break ; } min = Math . min ( min , ij ) ; } if ( min == 0 ) { break ; } } System . out . print ( min ) ; } public static void main ( String [ ] args ) { new Main ( ) . solve ( ) ; } } +import java . io . IOException ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws IOException { Scanner sc = new Scanner ( System . in ) ; int x = sc . nextInt ( ) ; int y = sc . nextInt ( ) ; int z = sc . nextInt ( ) ; int [ ] [ ] a = new int [ x ] [ y ] ; int [ ] [ ] b = new int [ y ] [ z ] ; for ( int i = 0 ; i < x ; i ++ ) { for ( int j = 0 ; j < y ; j ++ ) { a [ i ] [ j ] = sc . nextInt ( ) ; } } for ( int i = 0 ; i < y ; i ++ ) { int k = 0 ; for ( int j = 0 ; j < z ; j ++ ) { b [ i ] [ j ] = sc . nextInt ( ) ; } } long tmp = 0 ; for ( int i = 0 ; i < x ; i ++ ) { for ( int j = 0 ; j < z ; j ++ ) { for ( int k = 0 ; k < y ; k ++ ) { tmp += a [ i ] [ k ] * b [ k ] [ j ] ; } System . out . print ( tmp ) ; if ( j != z - 1 ) { System . out . print ( " " ) ; } tmp = 0 ; } System . out . println ( ) ; } sc . close ( ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . StringTokenizer ; public class Main { public static void main ( String [ ] args ) { FastScanner fs = new FastScanner ( ) ; int n = fs . nextInt ( ) ; if ( n == 0 ) { System . out . println ( 1 ) ; } else if ( n == 1 ) { System . out . println ( 0 ) ; } else { } } static class FastScanner { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; StringTokenizer st = new StringTokenizer ( " " ) ; String next ( ) { while ( ! st . hasMoreTokens ( ) ) try { st = new StringTokenizer ( br . readLine ( ) ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } return st . nextToken ( ) ; } int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } int [ ] readArray ( int n ) { int [ ] a = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) a [ i ] = nextInt ( ) ; return a ; } long nextLong ( ) { return Long . parseLong ( next ( ) ) ; } } } +import java . util . Scanner ; public class Main { private int a ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int a = 0 ; if ( N % 2 == 1 ) { a = ( N / 2 ) + 1 ; } else { int a = 0 ; a = ( N / 2 ) ; } System . out . print ( a ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { String name = " " ; Scanner sc = new Scanner ( System . in ) ; long n = sc . nextLong ( ) ; String alphabet = " abcdefghijklmnopqrstuvwxyz " ; String name = " " ; while ( n > 0 ) { n -- ; long remain = n % 26l ; name = alphabet . charAt ( ( int ) remain ) + name ; n = n / 26l ; } System . out . println ( name ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; char [ ] c = s . toCharArray ( ) ; StringBuilder ans = new StringBuilder ( ) ; for ( char ch : c ) { if ( ch == '0' ) ans . append ( " 0 " ) ; if ( ch == '1' ) ans . append ( " 1 " ) ; if ( ch == 'B' ) { char ch ; if ( ans . length ( ) == 1 ) ans = new StringBuilder ( ) ; if ( ! ans . toString ( ) . isEmpty ( ) ) ans . setLength ( ans . length ( ) - 1 ) ; } } System . out . println ( ans . toString ( ) ) ; } } +import java . util . * ; import java . io . * ; class Main { public static void main ( String [ ] args ) { try { int i = str . length - 1 ; BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String line = br . readLine ( ) ; if ( line . length ( ) <= 20 && line . length ( ) > 0 ) { char [ ] str = line . toCharArray ( ) ; for ( int i = str . length - 1 ; i >= 0 ; i -- ) { System . out . print ( str [ i ] ) ; } } else { System . exit ( 0 ) ; } System . out . println ( " " ) ; System . exit ( 0 ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int i = s ; Scanner scanner = new Scanner ( System . in ) ; int K = scanner . nextInt ( ) ; int X = scanner . nextInt ( ) ; int s = X - ( K - 1 ) ; int e = X + ( K - 1 ) ; for ( int i = s ; i <= e ; i ++ ) { System . out . println ( i ) ; } } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int k = sc . nextInt ( ) ; Integer [ ] h = new Integer [ n ] ; long ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { h [ i ] = sc . nextInt ( ) ; } if ( k >= n ) { int i = 0 ; System . out . println ( ans ) ; } else { Arrays . sort ( h , Collections . reverseOrder ( ) ) ; for ( int i = 0 ; i < k ; i ++ ) { h [ i ] = 0 ; } for ( int i = 0 ; i < n ; i ++ ) { ans += h [ i ] ; } System . out . println ( ans ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int [ ] A = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { A [ i ] = sc . nextInt ( ) ; } int count = 0 ; for ( int i = 0 ; i < N ; i ++ ) { int minj = i ; for ( int j = i ; j < N ; j ++ ) { if ( A [ j ] < A [ minj ] ) { minj = j ; } } if ( i != minj ) { count ++ ; } int x = A [ i ] ; A [ i ] = A [ minj ] ; A [ minj ] = x ; } for ( int i = 0 ; i < N - 1 ; i ++ ) { int i = 0 ; System . out . print ( A [ i ] + " " ) ; } System . out . println ( A [ N - 1 ] ) ; System . out . print ( count ) ; System . out . printf ( " \n " ) ; } } +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 c = sc . nextInt ( ) ; int tmp ; if ( a > b ) { tmp = a ; a = b ; b = tmp ; } if ( b > c ) { tmp = b ; b = c ; c = tmp ; } if ( a > b ) { int tmp ; tmp = a ; a = b ; b = tmp ; } System . out . println ( a + " " + b + " " + c ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int min = sc . nextInt ( ) ; int max = sc . nextInt ( ) ; int [ ] a = new int [ n ] ; int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = i + 1 ; int e = a [ i ] ; int dig = 0 ; while ( e != 0 ) { dig += e % 10 ; e /= 10 ; } if ( min <= dig && dig <= max ) { int dig = 0 ; sum += a [ i ] ; } } System . out . println ( sum ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int m = sc . nextInt ( ) ; int [ ] cities = new int [ n ] ; for ( int i = 0 ; i < m ; i ++ ) { int l = sc . nextInt ( ) ; int r = sc . nextInt ( ) ; cities [ l - 1 ] ++ ; cities [ r - 1 ] ++ ; } for ( int j = 0 ; j < n ; j ++ ) { int j = 0 ; System . out . println ( cities [ j ] ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int count = 0 ; for ( int i = 1 ; i <= N ; i ++ ) { int i = 1 ; if ( String . valueOf ( i ) . length ( ) % 2 == 1 ) count ++ ; } System . out . println ( count ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Main m = new Main ( ) ; m . answer ( ) ; } private Scanner scan = new Scanner ( System . in ) ; private int a ; private int b ; public Main ( ) { a = Integer . parseInt ( scan . next ( ) ) ; b = Integer . parseInt ( scan . next ( ) ) ; scan . close ( ) ; } public final void answer ( ) { String ans = a * b % 2 == 0 ? " Even " : " Odd " ; System . out . println ( ans ) ; } } +import java . util . * ; import static java . lang . System . * ; import java . math . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int cnt = 0 ; int plug = 1 ; for ( ; ; ) { int plug = 1 ; if ( plug >= b ) break ; plug = plug + a - 1 ; cnt ++ ; } out . println ( cnt ) ; } } +import java . io . * ; import java . util . * ; class Main { public static void main ( String [ ] args ) throws IOException { int i = 0 ; BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int [ ] array = new int [ 26 ] ; Arrays . fill ( array , 0 ) ; char [ ] c_array ; String str ; do { if ( ( str = br . readLine ( ) ) == null ) break ; c_array = str . toCharArray ( ) ; for ( char c : c_array ) { if ( 'a' <= c && c <= 'z' ) array [ c - 'a' ] ++ ; else if ( 'A' <= c && c <= 'Z' ) array [ c - 'A' ] ++ ; } } while ( true ) ; for ( int i = 0 ; i < 26 ; i ++ ) { System . out . println ( ( char ) ( 'a' + i ) + " : " + array [ i ] ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { String bx = " " ; Scanner sc = new Scanner ( System . in ) ; String a = sc . next ( ) ; String b = sc . next ( ) ; int A = Integer . parseInt ( a ) ; int B = Integer . parseInt ( b ) ; String ax = " " ; String bx = " " ; for ( int i = 0 ; i < B ; i ++ ) { ax += a ; } for ( int i = 0 ; i < A ; i ++ ) { bx += b ; } if ( ax . compareTo ( bx ) < 0 ) { System . out . println ( ax ) ; } else { System . out . println ( bx ) ; } } } +import java . util . Scanner ; public class Main { @ SuppressWarnings ( " resource " ) public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; String s = scanner . nextLine ( ) ; long n = scanner . nextLong ( ) ; if ( n <= s . length ( ) ) { for ( int i = 0 ; i < n ; i ++ ) { int i = 0 ; if ( s . charAt ( i ) == '1' ) { continue ; } else { System . out . println ( s . charAt ( i ) ) ; return ; } } System . out . println ( 1 ) ; return ; } for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( s . charAt ( i ) == '1' ) { continue ; } else { System . out . println ( s . charAt ( i ) ) ; return ; } } System . out . println ( 1 ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int a = 0 , b = 0 , c = 0 ; int [ ] n = new int [ 10 ] ; for ( int i = 0 ; i < 10 ; i ++ ) { int i = 0 ; n [ i ] = sc . nextInt ( ) ; if ( n [ i ] > a ) { c = b ; b = a ; a = n [ i ] ; } else if ( n [ i ] > b ) { c = b ; b = n [ i ] ; } else if ( n [ i ] > c ) { c = n [ i ] ; } } System . out . println ( a ) ; System . out . println ( b ) ; System . out . println ( c ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; StringBuilder sb = new StringBuilder ( ) ; char [ ] cs = sc . next ( ) . toCharArray ( ) ; for ( char c : cs ) { switch ( c ) { case '1' : sb . append ( c ) ; break ; case '0' : sb . append ( c ) ; break ; case 'B' : if ( sb . length ( ) > 0 ) { char c ; sb . deleteCharAt ( sb . length ( ) - 1 ) ; } break ; } } System . out . println ( sb ) ; } } +import java . io . PrintStream ; import java . util . Scanner ; public class Main { static final PrintStream out = System . out ; static Scanner sc = new Scanner ( System . in ) ; static final long Mod = 1000_000_007L ; public static void main ( String [ ] args ) { Main main = new Main ( ) ; main . solve ( ) ; System . exit ( 0 ) ; } void solve ( ) { long A = nextInt ( ) ; long B = nextInt ( ) ; long K = ( A + B ) / 2 ; if ( Math . abs ( A - K ) == Math . abs ( B - K ) ) { int i = 0 ; out . println ( K ) ; } else { out . println ( " IMPOSSIBLE " ) ; } } public int [ ] nextIntArray ( int n ) { int [ ] a = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) a [ i ] = nextInt ( ) ; return a ; } public long [ ] nextLongArray ( int n ) { long [ ] a = new long [ n ] ; for ( int i = 0 ; i < n ; i ++ ) a [ i ] = nextLong ( ) ; return a ; } public int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } public long nextLong ( ) { return Long . parseLong ( next ( ) ) ; } public String next ( ) { return sc . next ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] av ) { Scanner s = new Scanner ( System . in ) ; int n = s . nextInt ( ) ; int [ ] a = new int [ n + 1 ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = s . nextInt ( ) ; } for ( int i = 1 ; i < n ; i ++ ) { for ( int k = 0 ; k < n ; k ++ ) { System . out . print ( a [ k ] ) ; if ( k != n - 1 ) System . out . print ( " " ) ; } System . out . println ( " " ) ; int v = a [ i ] ; int j = i - 1 ; while ( j >= 0 && a [ j ] > v ) { a [ j + 1 ] = a [ j ] ; j -- ; } a [ j + 1 ] = v ; } for ( int k = 0 ; k < n ; k ++ ) { int k = 0 ; System . out . print ( a [ k ] ) ; if ( k != n - 1 ) System . out . print ( " " ) ; } System . out . println ( " " ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int digitNum = ( int ) Math . log10 ( N ) + 1 ; int ans = 0 ; if ( digitNum == 6 ) { ans = 9 + 900 + 90000 ; } else if ( digitNum == 5 ) { int ans = 0 ; ans = 9 + 900 + N - 10000 + 1 ; } else if ( digitNum == 4 ) { ans = 9 + 900 ; } else if ( digitNum == 3 ) { ans = 9 + N - 100 + 1 ; } else if ( digitNum == 2 ) { ans = 9 ; } else if ( digitNum == 1 ) { ans = N ; } System . out . println ( " " + ans ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int n = scanner . nextInt ( ) ; int taroPoint = 0 ; int hanakoPoint = 0 ; scanner . nextLine ( ) ; for ( int i = 1 ; i <= n ; i ++ ) { String input = scanner . nextLine ( ) ; String [ ] inputArr = input . split ( " " ) ; int check = inputArr [ 0 ] . compareTo ( inputArr [ 1 ] ) ; if ( check > 0 ) { taroPoint += 3 ; } else if ( check == 0 ) { int hanakoPoint = 0 ; taroPoint += 1 ; hanakoPoint += 1 ; } else { hanakoPoint += 3 ; } } System . out . println ( Integer . toString ( taroPoint ) + " " + Integer . toString ( hanakoPoint ) ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int m = sc . nextInt ( ) ; int [ ] [ ] A = new int [ n ] [ m ] ; int [ ] b = new int [ m ] ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < m ; j ++ ) { A [ i ] [ j ] = sc . nextInt ( ) ; } } for ( int k = 0 ; k < m ; k ++ ) { b [ k ] = sc . nextInt ( ) ; } int [ ] c = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < m ; j ++ ) { int j = 0 ; c [ i ] += A [ i ] [ j ] * b [ j ] ; } } for ( int ans : c ) System . out . println ( ans ) ; sc . close ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { String ans = " " ; Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int k = ( a + b ) / 2 ; String ans = " " ; if ( ( a + b ) % 2 == 0 && Math . abs ( a - k ) == Math . abs ( b - k ) ) { ans = String . valueOf ( k ) ; } else { ans = " IMPOSSIBLE " ; } System . out . println ( ans ) ; sc . close ( ) ; } } +import java . util . Scanner ; 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 ( ) ; } bubbleSort ( A , N ) ; } public static void bubbleSort ( int [ ] A , int N ) { int flag = 1 , count = 0 ; while ( flag == 1 ) { flag = 0 ; int i = 0 ; for ( int j = i ; j < N - 1 ; j ++ ) { if ( A [ j + 1 ] < A [ j ] ) { int i = 0 ; int c = A [ j + 1 ] ; A [ j + 1 ] = A [ j ] ; A [ j ] = c ; count ++ ; flag = 1 ; } } i ++ ; } for ( int i = 0 ; i < N ; i ++ ) { System . out . print ( A [ i ] ) ; if ( i != N - 1 ) System . out . print ( " " ) ; } System . out . printf ( " \n %d \n " , count ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) { int j ; BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; try { String str ; String [ ] arr ; int i ; int j ; while ( ( str = br . readLine ( ) ) != null ) { arr = str . split ( " " ) ; i = Integer . parseInt ( arr [ 0 ] ) ; j = Integer . parseInt ( arr [ 1 ] ) ; if ( i == 0 && j == 0 ) { break ; } if ( i <= j ) System . out . println ( str ) ; else { System . out . println ( arr [ 1 ] + " " + arr [ 0 ] ) ; } } br . close ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String [ ] str = br . readLine ( ) . split ( " " ) ; int x = Integer . parseInt ( str [ 0 ] ) , y = Integer . parseInt ( str [ 1 ] ) , rest ; if ( x < y ) { int x = Integer . parseInt ( str [ 0 ] ) , y = Integer . parseInt ( str [ 1 ] ) , rest ; int temp = x ; x = y ; y = temp ; } do { rest = x % y ; x = y ; y = rest ; } while ( y != 0 ) ; System . out . println ( x ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = Integer . parseInt ( sc . next ( ) ) ; int [ ] a = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = Integer . parseInt ( sc . next ( ) ) ; } Insertion_Sort ( a ) ; } private static void Insertion_Sort ( int [ ] a ) { for ( int i = 0 ; i < a . length ; i ++ ) { int p = a [ i ] ; int j = i - 1 ; while ( j >= 0 && a [ j ] > p ) { a [ j + 1 ] = a [ j ] ; j -- ; } a [ j + 1 ] = p ; for ( int j2 = 0 ; j2 < a . length ; j2 ++ ) { int j2 = 0 ; System . out . print ( a [ j2 ] ) ; if ( j2 != a . length - 1 ) { System . out . print ( " " ) ; } } System . out . println ( " " ) ; } } } +import java . io . BufferedReader ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws Exception { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String line = br . readLine ( ) ; int n = Integer . parseInt ( line ) ; int [ ] a = new int [ n ] ; int k = 0 ; int count = 1 ; boolean fin = false ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = Integer . parseInt ( br . readLine ( ) ) ; } for ( int i = 0 ; i < n ; i ++ ) { if ( a [ k ] != 2 && ! fin ) { int i = 0 ; count ++ ; k = a [ k ] - 1 ; } else { fin = true ; } } if ( fin ) { System . out . println ( count ) ; } else { System . out . println ( " -1 " ) ; } } } +import java . io . IOException ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws IOException { Scanner sc = new Scanner ( System . in ) ; int x = 1 ; int i = 0 ; while ( true ) { int i = 0 ; x = sc . nextInt ( ) ; i ++ ; if ( x == 0 ) { break ; } System . out . println ( " Case " + i + " : " + x ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; String [ ] strArray = scan . nextLine ( ) . split ( " " ) ; int H = Integer . parseInt ( strArray [ 0 ] ) ; int A = Integer . parseInt ( strArray [ 1 ] ) ; int lastCount = 0 ; for ( int i = 1 ; H > 0 ; i ++ ) { int i = 1 ; H = H - A ; lastCount = i ; } System . out . println ( lastCount ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; Integer [ ] list = new Integer [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { list [ i ] = sc . nextInt ( ) ; } Integer [ ] sorted = Arrays . copyOf ( list , n ) ; Arrays . sort ( sorted ) ; String ans = " YES " ; int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( ! sorted [ i ] . equals ( list [ i ] ) ) { count ++ ; if ( count > 2 ) { ans = " NO " ; break ; } } } System . out . println ( ans ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int A = scan . nextInt ( ) ; int B = scan . nextInt ( ) ; int i = 0 ; int a_tax = ( int ) ( i * 0.08 ) ; int b_tax = ( int ) ( i * 0.1 ) ; int ans = - 1 ; while ( i < 1000 ) { i ++ ; a_tax = ( int ) ( i * 0.08 ) ; b_tax = ( int ) ( i * 0.1 ) ; if ( a_tax == A && b_tax == B ) { int ans = - 1 ; ans = i ; break ; } } System . out . println ( ans ) ; } } +import java . util . ArrayList ; import java . util . List ; import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int n = scanner . nextInt ( ) ; List < Integer > numList = new ArrayList < Integer > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { int i = 0 ; numList . add ( scanner . nextInt ( ) ) ; } scanner . close ( ) ; int flag = 1 ; int c = 0 ; while ( flag == 1 ) { flag = 0 ; for ( int j = n - 1 ; j >= 1 ; j -- ) { if ( numList . get ( j ) < numList . get ( j - 1 ) ) { numList . add ( j - 1 , numList . get ( j ) ) ; numList . remove ( j + 1 ) ; c ++ ; flag = 1 ; } } } for ( int i = 0 ; i < n ; i ++ ) { System . out . print ( numList . get ( i ) ) ; if ( i < n - 1 ) { System . out . print ( " " ) ; } } System . out . println ( ) ; System . out . println ( c ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int n = scan . nextInt ( ) ; for ( int i = 1 ; i <= n ; i ++ ) { if ( n >= 10 ) { if ( ( i % 10 == 3 ) || ( i % 3 == 0 ) ) { System . out . print ( " " + i ) ; continue ; } int x = i ; while ( x > 9 ) { x = x / 10 ; if ( ( x % 10 == 3 ) ) { System . out . print ( " " + i ) ; break ; } } } else { if ( ( i % 10 == 3 ) || ( i % 3 == 0 ) ) { int x = i ; System . out . print ( " " + i ) ; } } } System . out . println ( ) ; } } +import java . util . Scanner ; class Main { static Scanner scan = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { int n ; double t , a ; n = scan . nextInt ( ) ; t = scan . nextDouble ( ) ; a = scan . nextDouble ( ) ; double [ ] h = new double [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { h [ i ] = scan . nextDouble ( ) ; } double min = 99999999.0 ; double x ; int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int i = 0 ; x = t - h [ i ] * 0.006 ; if ( Math . abs ( x - a ) < min ) { min = Math . abs ( x - a ) ; ans = i + 1 ; } } System . out . println ( ans ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int sanka = sc . nextInt ( ) ; int point = sc . nextInt ( ) ; int seikai = sc . nextInt ( ) ; int [ ] array = new int [ sanka ] ; for ( int i = 0 ; i < sanka ; i ++ ) { array [ i ] = point - seikai ; } for ( int i = 0 ; i < seikai ; i ++ ) { array [ sc . nextInt ( ) - 1 ] ++ ; } for ( int i = 0 ; i < sanka ; i ++ ) { if ( array [ i ] <= 0 ) { int i = 0 ; System . out . println ( " No " ) ; } else { System . out . println ( " Yes " ) ; } } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int c = 0 ; int [ ] d = new int [ a ] ; for ( int i = 0 ; i < a ; i ++ ) { d [ i ] = sc . nextInt ( ) ; } for ( int i = 0 ; i < a ; i ++ ) { int i = 0 ; if ( d [ i ] >= b ) { c ++ ; } } System . out . println ( c ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int M = sc . nextInt ( ) ; int [ ] [ ] input = new int [ M ] [ 2 ] ; for ( int i = 0 ; i < M ; i ++ ) { input [ i ] [ 0 ] = sc . nextInt ( ) ; String tmp = sc . next ( ) ; if ( tmp . equals ( " AC " ) ) { input [ i ] [ 1 ] = 1 ; } else { input [ i ] [ 1 ] = 0 ; } } int resCorr = 0 ; int pena = 0 ; int [ ] [ ] qa = new int [ N ] [ 2 ] ; for ( int i = 0 ; i < M ; i ++ ) { if ( qa [ input [ i ] [ 0 ] - 1 ] [ 1 ] == 1 ) { continue ; } if ( input [ i ] [ 1 ] == 0 ) { qa [ input [ i ] [ 0 ] - 1 ] [ 0 ] ++ ; } else { int i = 0 ; resCorr ++ ; pena += qa [ input [ i ] [ 0 ] - 1 ] [ 0 ] ; qa [ input [ i ] [ 0 ] - 1 ] [ 1 ] = 1 ; } } System . out . print ( resCorr + " " + pena ) ; } } +import java . util . * ; import java . lang . * ; import java . io . * ; class Main { public static void main ( String [ ] args ) throws java . lang . Exception { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; ArrayList < Integer > a = new ArrayList < Integer > ( n ) ; for ( int i = 0 ; i < n ; i ++ ) { int x = sc . nextInt ( ) ; a . add ( x ) ; } int ans = Integer . MAX_VALUE ; for ( int k = 1 ; k <= 100 ; k ++ ) { int i = 0 ; int mans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { mans += ( ( a . get ( i ) - k ) * ( a . get ( i ) - k ) ) ; } ans = Math . min ( ans , mans ) ; } 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 K = sc . nextInt ( ) ; int [ ] [ ] dp = new int [ 201 ] [ 201 ] ; long res = 0 ; for ( int i = 1 ; i <= K ; i ++ ) { for ( int j = 1 ; j <= K ; j ++ ) { int gcd ; if ( dp [ i ] [ j ] == 0 ) { gcd = gcd ( i , j ) ; dp [ i ] [ j ] = gcd ; } else { gcd = dp [ i ] [ j ] ; } for ( int k = 1 ; k <= K ; k ++ ) { int gcd3 ; if ( dp [ gcd ] [ k ] == 0 ) { gcd3 = gcd ( gcd , k ) ; dp [ gcd ] [ k ] = gcd3 ; } else { gcd3 = dp [ gcd ] [ k ] ; } res += gcd3 ; } } } System . out . println ( res ) ; } private static int gcd ( int i , int j ) { while ( i != 0 && j != 0 ) { if ( i < j ) { int gcd3 ; j %= i ; } else { i %= j ; } } return Math . max ( i , j ) ; } } +import java . util . * ; public class Main { private static final int INF = Integer . MAX_VALUE ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int m = sc . nextInt ( ) ; int l = 0 ; int r = INF ; for ( int tmp = 0 ; tmp < m ; tmp ++ ) { int r = INF ; int x = sc . nextInt ( ) ; l = Math . max ( x , l ) ; int y = sc . nextInt ( ) ; r = Math . min ( y , r ) ; } System . out . println ( l <= r ? r - l + 1 : 0 ) ; } } +import java . util . * ; import java . lang . * ; class Main { public static void main ( String [ ] args ) { int count = 0 ; Scanner sc = new Scanner ( System . in ) ; String s = " " ; while ( sc . hasNext ( ) ) { int count = 0 ; s = sc . nextLine ( ) ; if ( s . equalsIgnoreCase ( " ssr " ) || s . equalsIgnoreCase ( " srs " ) || s . equalsIgnoreCase ( " rss " ) || s . equalsIgnoreCase ( " rsr " ) ) { count = 1 ; } else if ( s . equalsIgnoreCase ( " rrs " ) || s . equalsIgnoreCase ( " srr " ) ) { count = 2 ; } else if ( s . equalsIgnoreCase ( " rrr " ) ) { count = 3 ; } else count = 0 ; System . out . println ( count ) ; } } } +import java . util . * ; import java . util . stream . Collectors ; class Main { public static void main ( String [ ] args ) { int upper ; Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int c = sc . nextInt ( ) ; int d = sc . nextInt ( ) ; int result = 0 ; int lower ; int upper ; lower = Math . max ( a , c ) ; upper = Math . min ( b , d ) ; if ( upper >= lower ) { result = upper - lower ; } System . out . println ( result ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int [ ] A = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { A [ i ] = sc . nextInt ( ) ; } int ans = 1 ; for ( int i = 0 ; i < N ; i ++ ) { int i = 0 ; if ( A [ i ] % 2 == 0 ) { if ( A [ i ] % 3 == 0 || A [ i ] % 5 == 0 ) { ans *= 1 ; } else { ans *= 0 ; } } } if ( ans == 0 ) { System . out . println ( " DENIED " ) ; } else { System . out . println ( " APPROVED " ) ; } sc . close ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String ... args ) { Scanner scanner = new Scanner ( System . in ) ; int A = scanner . nextInt ( ) ; int B = scanner . nextInt ( ) ; System . out . println ( lcm ( A , B ) ) ; } static long gcd ( long a , long b ) { long max = Math . max ( a , b ) ; long min = Math . min ( a , b ) ; long r = max % min ; if ( r == 0 ) { return min ; } else { return gcd ( min , r ) ; } } static long lcm ( long a , long b ) { long r = max % min ; return a * b / gcd ( a , b ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; String n = scan . nextLine ( ) ; String [ ] array = n . split ( " " ) ; int frag = 0 ; for ( String a : array ) { if ( a . equals ( " 7 " ) ) { String a ; frag = 1 ; } } if ( frag == 1 ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int pos = 1 ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] a = new int [ n + 1 ] ; for ( int i = 1 ; i <= n ; i ++ ) { a [ i ] = sc . nextInt ( ) ; } int count = 0 ; boolean [ ] flag = new boolean [ n + 1 ] ; int pos = 1 ; while ( pos != 2 && ! flag [ pos ] ) { flag [ pos ] = true ; pos = a [ pos ] ; count ++ ; } if ( pos == 2 ) { System . out . println ( count ) ; } else { System . out . println ( - 1 ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int count = sc . nextInt ( ) ; int [ ] v = new int [ count ] ; int [ ] c = new int [ count ] ; for ( int i = 0 ; i < count ; i ++ ) { v [ i ] = sc . nextInt ( ) ; } for ( int i = 0 ; i < count ; i ++ ) { c [ i ] = sc . nextInt ( ) ; } int result = 0 ; for ( int i = 0 ; i < count ; i ++ ) { int i = 0 ; if ( v [ i ] > c [ i ] ) { result += v [ i ] - c [ i ] ; } } System . out . println ( result ) ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner inp = new Scanner ( System . in ) ; do_ ( inp ) ; inp . close ( ) ; } public static void do_ ( Scanner inp ) { Scanner inp = new Scanner ( System . in ) ; int a = inp . nextInt ( ) ; int b = inp . nextInt ( ) ; int c = inp . nextInt ( ) ; System . out . println ( c + " " + a + " " + b ) ; } } +import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . lang . Exception ; import java . lang . Integer ; import java . lang . System ; public class Main { public static void main ( String [ ] a ) throws Exception { BufferedReader r = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String s ; int week ; double total ; while ( ( s = r . readLine ( ) ) != null ) { week = Integer . parseInt ( s ) ; total = 100000 ; for ( int i = 0 ; i < week ; i ++ ) { double total ; total *= 1.05 ; total /= 1000 ; total = Math . ceil ( total ) * 1000 ; } System . out . printf ( " %.0f \n " , total ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int m = sc . nextInt ( ) ; int [ ] ACs = new int [ n + 1 ] ; int [ ] WAs = new int [ n + 1 ] ; for ( int i = 0 ; i < n + 1 ; i ++ ) { ACs [ i ] = 0 ; WAs [ i ] = 0 ; } for ( int i = 1 ; i <= m ; i ++ ) { int i = 1 ; int p = sc . nextInt ( ) ; String s = sc . next ( ) ; if ( s . equals ( " AC " ) && ACs [ p ] == 0 ) { ACs [ p ] ++ ; } else if ( s . equals ( " WA " ) && ACs [ p ] == 0 ) { WAs [ p ] ++ ; } } int sumAC = 0 ; int sumWA = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { sumAC += ACs [ i ] ; if ( ACs [ i ] == 1 ) { sumWA += WAs [ i ] ; } } System . out . println ( sumAC ) ; System . out . println ( sumWA ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] list = new int [ n - 1 ] ; for ( int i = 0 ; i < n - 1 ; i ++ ) { list [ i ] = sc . nextInt ( ) ; } int ans = 0 ; int lastV = 0 ; for ( int i = 0 ; i < n - 1 ; i ++ ) { if ( i == 0 ) { ans += list [ i ] ; } else if ( list [ i ] > lastV ) { int i = 0 ; ans += lastV ; } else { ans += list [ i ] ; } if ( i == n - 2 ) { ans += list [ i ] ; } lastV = list [ i ] ; } System . out . println ( ans ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] color = new int [ 9 ] ; int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int a = sc . nextInt ( ) ; color [ Math . min ( a / 400 , 8 ) ] ++ ; } for ( int i = 0 ; i < 8 ; i ++ ) { int i = 0 ; if ( color [ i ] > 0 ) ans ++ ; } int ans2 = ans + color [ 8 ] ; if ( ans == 0 && color [ 8 ] > 0 ) ans = 1 ; System . out . printf ( " %d %d " , ans , ans2 ) ; sc . close ( ) ; } } +import java . util . * ; public class Main { static final long mod = ( long ) ( 1e9 + 7 ) ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int m = sc . nextInt ( ) ; boolean [ ] oks = new boolean [ n + 1 ] ; Arrays . fill ( oks , true ) ; for ( int i = 0 ; i < m ; i ++ ) { int a = sc . nextInt ( ) ; oks [ a ] = false ; } long [ ] dp = new long [ n + 1 ] ; dp [ 0 ] = 1 ; for ( int now = 0 ; now < n ; now ++ ) { for ( int next = now + 1 ; next <= Math . min ( n , now + 2 ) ; next ++ ) { int next = now + 1 ; if ( oks [ next ] ) { dp [ next ] += dp [ now ] ; dp [ next ] %= mod ; } } } System . out . println ( dp [ n ] ) ; sc . close ( ) ; } } +import java . util . Scanner ; import java . lang . Math ; class Main { public static void main ( String [ ] args ) { int i ; Scanner stdIn = new Scanner ( System . in ) ; int x = Integer . parseInt ( stdIn . next ( ) ) ; if ( x != 2 && x % 2 == 0 ) x ++ ; while ( true ) { int i ; double sqrtNum = Math . sqrt ( x ) ; for ( i = 3 ; i <= sqrtNum ; i += 2 ) { if ( x % i == 0 ) break ; } if ( i > sqrtNum ) break ; x += 2 ; } System . out . println ( x ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long x = sc . nextLong ( ) ; for ( long j = x ; j < 1000000 ; j ++ ) { int count = 0 ; for ( long i = 2 ; i < x ; i ++ ) { if ( x % i == 0 ) { count ++ ; } } if ( count == 0 ) { long i = 2 ; System . out . println ( x ) ; System . exit ( 0 ) ; } x ++ ; } } } +import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) , k = sc . nextInt ( ) ; int [ ] array = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) array [ i ] = sc . nextInt ( ) ; Arrays . sort ( array ) ; for ( int i = n - 1 ; i >= n - k ; i -- ) { int i = 0 ; if ( i >= 0 ) array [ i ] = 0 ; else break ; } long sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) sum += array [ i ] ; System . out . println ( sum ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int A = sc . nextInt ( ) ; int B = sc . nextInt ( ) ; int C = A + B ; int c = ( A + B ) / 2 ; int ans = 0 ; for ( int k = 0 ; k <= c ; k ++ ) { if ( C == 2 * k ) { ans = k ; } } if ( ans != 0 ) { int k = 0 ; System . out . println ( ans ) ; } else { System . out . println ( " IMPOSSIBLE " ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int ans = 0 ; if ( a == 0 ) { a = 1 ; } else if ( a == 1 ) { a = 100 ; } else { int i = 1 ; a = 10000 ; } for ( int i = 1 ; i <= b ; i ++ ) { ans = a * i ; if ( i >= 100 ) { ans = a * ( i + 1 ) ; } } System . out . println ( ans ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) , sum = 0 ; double ave , tmpsum = 0 ; while ( n != 0 ) { int [ ] s = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { int i = 0 ; s [ i ] = sc . nextInt ( ) ; sum += s [ i ] ; } ave = ( double ) sum / n ; for ( int i = 0 ; i < n ; i ++ ) tmpsum += ( s [ i ] - ave ) * ( s [ i ] - ave ) ; ave = tmpsum / n ; System . out . println ( Math . sqrt ( ave ) ) ; sum = 0 ; tmpsum = 0 ; n = sc . nextInt ( ) ; } } } +import java . util . StringTokenizer ; public class Main { public static void main ( String [ ] args ) { java . io . BufferedReader in = new java . io . BufferedReader ( new java . io . InputStreamReader ( System . in ) ) ; { StringTokenizer st ; try { String s = in . readLine ( ) ; StringTokenizer st ; while ( s != null ) { st = new StringTokenizer ( s ) ; int p = Integer . parseInt ( st . nextToken ( ) ) + Integer . parseInt ( st . nextToken ( ) ) ; System . out . println ( ( int ) Math . log10 ( p ) + 1 ) ; s = in . readLine ( ) ; } } catch ( Exception ex ) { System . exit ( 0 ) ; } } } } +import java . util . * ; import java . lang . * ; import java . io . * ; public class Main { public static void main ( String [ ] args ) throws java . lang . Exception { Scanner s = new Scanner ( System . in ) ; int n = s . nextInt ( ) ; int k = s . nextInt ( ) ; int [ ] a = new int [ n ] ; for ( int i = 0 ; i < k ; i ++ ) { int d = s . nextInt ( ) ; for ( int j = 0 ; j < d ; j ++ ) { int x = s . nextInt ( ) ; a [ x - 1 ] ++ ; } } int c = 0 ; for ( int i = 0 ; i < a . length ; i ++ ) { int i = 0 ; if ( a [ i ] == 0 ) c ++ ; } System . out . println ( c ) ; } } +import java . io . PrintWriter ; import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = Integer . parseInt ( sc . next ( ) ) ; int [ ] X = new int [ N ] ; int minSum = 2000000 ; int sum = 0 ; for ( int i = 0 ; i < N ; i ++ ) { X [ i ] = Integer . parseInt ( sc . next ( ) ) ; } Arrays . sort ( X ) ; for ( int i = X [ 0 ] ; i <= X [ N - 1 ] ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) { sum += ( X [ j ] - i ) * ( X [ j ] - i ) ; } if ( sum < minSum ) { int j = 0 ; minSum = sum ; } sum = 0 ; } PrintWriter out = new PrintWriter ( System . out ) ; out . println ( minSum ) ; sc . close ( ) ; out . flush ( ) ; } } +import java . util . Scanner ; class Main { public static void main ( String ... args ) { Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int lower ; int bigger ; if ( a > b ) { lower = b ; bigger = a ; } else { lower = a ; bigger = b ; } int tmp = bigger % lower ; while ( lower != 0 ) { int tmp = bigger % lower ; tmp = bigger % lower ; bigger = lower ; lower = tmp ; } System . out . println ( bigger ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner stdIn = new Scanner ( System . in ) ; int N = stdIn . nextInt ( ) ; int Y = stdIn . nextInt ( ) / 1000 ; int ans10 = - 1 ; int ans5 = - 1 ; int ans1 = - 1 ; for ( int i = 0 ; i <= N ; i ++ ) { for ( int j = 0 ; j <= N - i ; j ++ ) { int j = 0 ; if ( 10 * i + 5 * j + ( N - i - j ) == Y ) { ans10 = i ; ans5 = j ; ans1 = N - i - j ; break ; } } } System . out . println ( ans10 + " " + ans5 + " " + ans1 ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner keyboard = new Scanner ( System . in ) ; int N = keyboard . nextInt ( ) ; HashMap < String , Integer > count = new HashMap < String , Integer > ( ) ; for ( int s = 0 ; s < N ; s ++ ) { String S = keyboard . next ( ) ; if ( count . containsKey ( S ) ) { int now = count . get ( S ) ; count . replace ( S , now + 1 ) ; } else { count . put ( S , 1 ) ; } } int Max = 0 ; for ( int val : count . values ( ) ) { if ( Max <= val ) { int i = 0 ; Max = val ; } } List < String > print = new ArrayList < String > ( ) ; for ( String s : count . keySet ( ) ) { int now = count . get ( s ) ; if ( now == Max ) { print . add ( s ) ; } } Collections . sort ( print ) ; for ( int i = 0 ; i < print . size ( ) ; i ++ ) { String ans = print . get ( i ) ; System . out . println ( ans ) ; } keyboard . close ( ) ; } } +import java . util . Scanner ; public class Main { private static int countPower ( int n ) { int count = 0 ; while ( n % 2 == 0 ) { int ans = 100 ; ++ count ; n /= 2 ; } return count ; } public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int ans = 100 ; for ( int i = 0 ; i < n ; ++ i ) { int a = sc . nextInt ( ) ; ans = Math . min ( ans , countPower ( a ) ) ; } System . out . println ( ans ) ; sc . close ( ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] p = new int [ n ] ; int flg = 0 ; String ans = " NO " ; for ( int i = 0 ; i < n ; i ++ ) { int i = 0 ; p [ i ] = sc . nextInt ( ) ; if ( p [ i ] != i + 1 ) { flg += 1 ; } } if ( flg == 0 || flg == 2 ) { ans = " YES " ; } System . out . println ( ans ) ; } } +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 ( ) ; sc . close ( ) ; if ( a * b >= a + b && a * b >= a - b ) { int b = sc . nextInt ( ) ; System . out . println ( a * b ) ; } else if ( a + b >= a - b && a + b >= a * b ) { System . out . println ( a + b ) ; } else { System . out . println ( a - b ) ; } } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . Arrays ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; while ( true ) { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String [ ] strArr = br . readLine ( ) . split ( " " ) ; long [ ] arr = new long [ 2 ] ; arr [ 0 ] = Long . parseLong ( strArr [ 0 ] ) ; arr [ 1 ] = Long . parseLong ( strArr [ 1 ] ) ; if ( arr [ 0 ] == 0 && arr [ 1 ] == 0 ) break ; Arrays . sort ( arr ) ; System . out . printf ( " %d %d%n " , arr [ 0 ] , arr [ 1 ] ) ; } } } +import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int l = sc . nextInt ( ) ; String [ ] s = new String [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { int i = 0 ; s [ i ] = sc . next ( ) ; } Arrays . sort ( s ) ; String ans = " " ; for ( int i = 0 ; i < n ; i ++ ) { ans += s [ i ] ; } System . out . println ( ans ) ; } } +import java . io . InputStreamReader ; import java . io . LineNumberReader ; public class Main { public static final int WIN_POINTS = 3 ; public static final int EVEN_POINTS = 1 ; public static void main ( String [ ] args ) { try { LineNumberReader lineNumReader = new LineNumberReader ( new InputStreamReader ( System . in ) ) ; String inputStr = null ; long turnNum = 0 ; String taro = null ; String hanako = null ; long taroPoint = 0 ; long hanakoPoint = 0 ; while ( ( inputStr = lineNumReader . readLine ( ) ) != null ) { if ( lineNumReader . getLineNumber ( ) == 1 ) { turnNum = Integer . parseInt ( inputStr ) ; } if ( lineNumReader . getLineNumber ( ) > 1 ) { String [ ] line = inputStr . split ( " " ) ; taro = line [ 0 ] ; hanako = line [ 1 ] ; if ( taro . compareTo ( hanako ) < 0 ) { hanakoPoint += WIN_POINTS ; } else if ( taro . compareTo ( hanako ) == 0 ) { long hanakoPoint = 0 ; taroPoint += EVEN_POINTS ; hanakoPoint += EVEN_POINTS ; } else { taroPoint += WIN_POINTS ; } } if ( lineNumReader . getLineNumber ( ) == turnNum + 1 ) { System . out . print ( taroPoint ) ; System . out . print ( " " ) ; System . out . println ( hanakoPoint ) ; break ; } } lineNumReader . close ( ) ; } catch ( Exception e ) { System . exit ( - 1 ) ; } } public static String shuffle ( String original , int h ) { StringBuilder shuffledStr = new StringBuilder ( original ) ; String temp = shuffledStr . substring ( 0 , h ) ; shuffledStr . delete ( 0 , h ) ; shuffledStr . append ( temp ) ; return shuffledStr . toString ( ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int M = sc . nextInt ( ) ; int p ; String S ; int [ ] AC = new int [ N ] ; int [ ] WA = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { int i = 0 ; AC [ i ] = 0 ; WA [ i ] = 0 ; } int penalty = 0 ; for ( int i = 0 ; i < M ; i ++ ) { p = sc . nextInt ( ) - 1 ; S = sc . next ( ) ; if ( S . equals ( " WA " ) ) { WA [ p ] ++ ; } else if ( S . equals ( " AC " ) ) { if ( AC [ p ] == 0 ) { penalty = penalty + WA [ p ] ; } AC [ p ] = 1 ; } } int clear = 0 ; for ( int i = 0 ; i < N ; i ++ ) { clear = clear + AC [ i ] ; } System . out . print ( clear + " " + penalty ) ; } } +import java . util . * ; import java . lang . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int K = sc . nextInt ( ) ; int count = 0 ; for ( int i = 0 ; i < 40 ; i ++ ) { if ( N >= K ) { count ++ ; N = N / K ; } else { int count = 0 ; break ; } } System . out . println ( count + 1 ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = Integer . parseInt ( sc . next ( ) ) ; int A = Integer . parseInt ( sc . next ( ) ) ; int B = Integer . parseInt ( sc . next ( ) ) ; int sum = 0 ; for ( int i = 1 ; i < N + 1 ; i ++ ) { int tmp = addPerDegit ( i ) ; if ( A <= tmp && tmp <= B ) { sum += i ; } } System . out . println ( sum ) ; } private static int addPerDegit ( int i ) { int sum = 0 ; while ( i > 0 ) { int sum = 0 ; sum += i % 10 ; i /= 10 ; } return sum ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; String [ ] ss = new String [ 4 ] ; for ( int i = 0 ; i < 4 ; i ++ ) { int i = 0 ; ss [ i ] = s . substring ( i , i + 1 ) ; } for ( int i = 0 ; i < 3 ; i ++ ) { if ( ss [ i ] . equals ( ss [ i + 1 ] ) ) { System . out . println ( " Bad " ) ; return ; } } System . out . println ( " Good " ) ; } } +import java . io . * ; import java . util . * ; class Main { public static void main ( String [ ] args ) throws IOException { InputStreamReader in = new InputStreamReader ( System . in ) ; BufferedReader br = new BufferedReader ( in ) ; String [ ] buf = ( br . readLine ( ) ) . split ( " " ) ; int n = Integer . parseInt ( buf [ 0 ] ) ; int m = Integer . parseInt ( buf [ 1 ] ) ; ArrayList < Integer > matrix = new ArrayList < Integer > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { buf = ( br . readLine ( ) ) . split ( " " ) ; for ( int j = 0 ; j < m ; j ++ ) { matrix . add ( Integer . parseInt ( buf [ j ] ) ) ; } } ArrayList < Integer > vector = new ArrayList < Integer > ( ) ; for ( int i = 0 ; i < m ; i ++ ) { int num_element = Integer . parseInt ( br . readLine ( ) ) ; vector . add ( num_element ) ; } ArrayList < Integer > answer = new ArrayList < Integer > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { int i = 0 ; int temp = 0 ; for ( int j = 0 ; j < m ; j ++ ) { temp += matrix . get ( i * m + j ) * vector . get ( j ) ; } answer . add ( temp ) ; } for ( int i = 0 ; i < n ; i ++ ) { System . out . println ( answer . get ( i ) ) ; } } } +public class Main { public static void main ( String [ ] args ) { int pay = 0 ; int price = new java . util . Scanner ( System . in ) . nextInt ( ) ; int pay = 0 ; while ( pay < price ) { pay += 1000 ; } System . out . println ( pay - price ) ; } } +import java . util . * ; import java . util . InputMismatchException ; public class Main { public static void main ( String [ ] args ) { try { int k ; Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int k ; if ( a == b ) { System . out . println ( " IMPOSSIBLE " ) ; } else if ( a < 0 ) { System . out . println ( " IMPOSSIBLE " ) ; } else if ( b > 1000000000 ) { System . out . println ( " IMPOSSIBLE " ) ; } else { k = ( b + a ) / 2 ; if ( ( k * 2 ) != ( a + b ) ) { System . out . println ( " IMPOSSIBLE " ) ; } else { System . out . println ( k ) ; } } } catch ( InputMismatchException e ) { System . out . println ( " IMPOSSIBLE " ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = Integer . parseInt ( sc . next ( ) ) ; int [ ] ary = new int [ n ] ; for ( int i = 0 ; i < ary . length ; i ++ ) { ary [ i ] = Integer . parseInt ( sc . next ( ) ) ; } if ( isAscendingOrder ( ary ) ) { System . out . print ( " YES " ) ; } else { System . out . print ( " NO " ) ; } } public static boolean isAscendingOrder ( int [ ] ary ) { int x = 0 ; int y = 0 ; int k = 0 ; for ( int i = 0 ; i < ary . length - 1 ; i ++ ) { if ( ary [ i ] > ary [ i + 1 ] ) { if ( x == 0 ) { x = ary [ i ] ; } else if ( y == 0 ) { y = ary [ i + 1 ] ; } } } for ( int i = 0 ; i < ary . length - 1 ; i ++ ) { if ( ary [ i ] > ary [ i + 1 ] ) { if ( k == 0 ) { int i = 0 ; ary [ i ] = y ; k += 1 ; } else if ( k == 1 ) { ary [ i + 1 ] = x ; k += 1 ; } } } for ( int i = 0 ; i < ary . length - 1 ; i ++ ) { if ( ary [ i ] > ary [ i + 1 ] ) { return false ; } } return true ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int m = sc . nextInt ( ) ; int x = sc . nextInt ( ) ; int cost_n = 0 ; for ( int i = 0 ; i < m ; i ++ ) { int cost_n = 0 ; int am = sc . nextInt ( ) ; if ( am > x ) { cost_n ++ ; } } System . out . println ( Math . min ( cost_n , m - cost_n ) ) ; } } +import java . util . * ; import java . io . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; PrintWriter ou = new PrintWriter ( System . out ) ; int n = Integer . parseInt ( sc . next ( ) ) ; int k = Integer . parseInt ( sc . next ( ) ) ; int q = Integer . parseInt ( sc . next ( ) ) ; int [ ] s = new int [ n ] ; int i ; Arrays . fill ( s , k - q ) ; for ( i = 0 ; i < q ; i ++ ) { s [ Integer . parseInt ( sc . next ( ) ) - 1 ] ++ ; } for ( i = 0 ; i < n ; i ++ ) { int i ; if ( s [ i ] > 0 ) ou . print ( " Yes \n " ) ; else ou . print ( " No \n " ) ; } ou . flush ( ) ; } } +import java . util . * ; import java . lang . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] sum1 = new int [ n + 1 ] ; int [ ] sum2 = new int [ n + 1 ] ; for ( int i = 1 ; i <= n ; i ++ ) { sum1 [ i ] = sum1 [ i - 1 ] + sc . nextInt ( ) ; } for ( int i = 1 ; i <= n ; i ++ ) { int i = 1 ; sum2 [ i ] = sum2 [ i - 1 ] + sc . nextInt ( ) ; } int max = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { max = Math . max ( max , sum1 [ i ] + sum2 [ n ] - sum2 [ i - 1 ] ) ; } System . out . println ( max ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { new Main ( ) . run ( ) ; } private void run ( ) { int a , b ; Scanner sc = new Scanner ( System . in ) ; while ( true ) { String [ ] input = sc . nextLine ( ) . split ( " " ) ; a = Integer . parseInt ( input [ 0 ] ) ; b = Integer . parseInt ( input [ 1 ] ) ; if ( a == 0 && b == 0 ) { Scanner sc = new Scanner ( System . in ) ; break ; } System . out . println ( Math . min ( a , b ) + " " + Math . max ( a , b ) ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int m = c - n ; Scanner sc = new Scanner ( System . in ) ; int a , b , c ; a = sc . nextInt ( ) ; b = sc . nextInt ( ) ; c = sc . nextInt ( ) ; int n = a - b ; int m = c - n ; if ( m > 0 ) { System . out . println ( m ) ; } else { System . out . println ( 0 ) ; } } } +import java . util . Scanner ; public class Main { public static Scanner sc = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { int max_index = 0 ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int c = sc . nextInt ( ) ; int k = sc . nextInt ( ) ; for ( int i = 0 ; i < k ; i ++ ) { int max = a ; int max_index = 0 ; if ( max < b ) { max = b ; max_index = 1 ; } if ( max < c ) { max = c ; max_index = 2 ; } switch ( max_index ) { case 0 : a *= 2 ; break ; case 1 : b *= 2 ; break ; case 2 : c *= 2 ; break ; } } System . out . println ( a + b + c ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String [ ] line = sc . nextLine ( ) . split ( " " ) ; ArrayDeque < Integer > stack = new ArrayDeque < > ( ) ; for ( String x : line ) { char c = x . charAt ( 0 ) ; if ( c == '+' || c == '-' || c == '*' ) { int second = stack . pop ( ) ; int first = stack . pop ( ) ; if ( c == '+' ) { int first = stack . pop ( ) ; first += second ; } else if ( c == '-' ) { first -= second ; } else { first *= second ; } stack . push ( first ) ; } else { stack . push ( Integer . parseInt ( x ) ) ; } } System . out . println ( stack . pop ( ) ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws IOException { int i = str . length - 1 ; BufferedReader bufferedReader = new BufferedReader ( new InputStreamReader ( System . in ) ) ; Integer nInteger = Integer . parseInt ( bufferedReader . readLine ( ) ) ; String string = bufferedReader . readLine ( ) ; String [ ] str = string . split ( " " ) ; for ( int i = str . length - 1 ; i >= 0 ; i -- ) { if ( i != 0 ) { System . out . print ( str [ i ] + " " ) ; } else { System . out . print ( str [ i ] ) ; } } System . out . println ( ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; ArrayList < Integer > asiba = new ArrayList < Integer > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { asiba . add ( sc . nextInt ( ) ) ; } ArrayList < Integer > cost = new ArrayList < Integer > ( ) ; cost . add ( 0 ) ; cost . add ( Math . abs ( asiba . get ( 1 ) - asiba . get ( 0 ) ) ) ; for ( int i = 2 ; i < N ; i ++ ) { int i = 2 ; int MAX = Math . abs ( asiba . get ( i ) - asiba . get ( i - 1 ) ) + cost . get ( i - 1 ) ; int MAX2 = Math . abs ( asiba . get ( i ) - asiba . get ( i - 2 ) ) + cost . get ( i - 2 ) ; if ( MAX > MAX2 ) MAX = MAX2 ; cost . add ( MAX ) ; } System . out . println ( cost . get ( N - 1 ) ) ; } } +import java . util . * ; import java . lang . * ; import java . io . * ; public class Main { public static void main ( String [ ] args ) throws java . lang . Exception { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; InputReader in = new InputReader ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; long a = in . nextLong ( ) ; long b = in . nextLong ( ) ; long max = Math . max ( a , b ) ; for ( long i = 0 ; i < max ; i ++ ) { if ( Math . abs ( a - i ) == Math . abs ( b - i ) ) { out . println ( i ) ; out . close ( ) ; return ; } } out . println ( " IMPOSSIBLE " ) ; out . close ( ) ; } static class InputReader { public BufferedReader reader ; public StringTokenizer tokenizer ; public InputReader ( InputStream stream ) { reader = new BufferedReader ( new InputStreamReader ( stream ) , 32768 ) ; tokenizer = null ; } public String next ( ) { while ( tokenizer == null || ! tokenizer . hasMoreTokens ( ) ) { try { tokenizer = new StringTokenizer ( reader . readLine ( ) ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } } return tokenizer . nextToken ( ) ; } public int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } public long nextLong ( ) { return Long . parseLong ( next ( ) ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int kIndex = 1 ; Scanner scanner = new Scanner ( System . in ) ; int N = Integer . parseInt ( scanner . next ( ) ) ; int breakCount = 0 ; int kIndex = 1 ; for ( int i = 0 ; i < N ; i ++ ) { int num = Integer . parseInt ( scanner . next ( ) ) ; if ( kIndex != num ) { breakCount ++ ; } else { kIndex ++ ; } } scanner . close ( ) ; if ( breakCount == N ) { System . out . println ( " -1 " ) ; } else { System . out . println ( breakCount ) ; } } } +import java . util . Arrays ; import java . util . HashMap ; import java . util . Map ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; Map < String , Integer > count = new HashMap < > ( ) ; int n = in . nextInt ( ) ; long res = 0 ; for ( int i = 0 ; i < n ; i ++ ) { String s = sort ( in . next ( ) ) ; String s = sort ( in . next ( ) ) ; res += ( count . containsKey ( s ) ? count . get ( s ) : 0 ) ; if ( count . containsKey ( s ) ) { count . replace ( s , count . get ( s ) + 1 ) ; } else { count . put ( s , 1 ) ; } } System . out . println ( res ) ; } private static String sort ( String text ) { char [ ] chars = text . toCharArray ( ) ; Arrays . sort ( chars ) ; return new String ( chars ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; try { final int A = sc . nextInt ( ) ; final int B = sc . nextInt ( ) ; int kuchi = 1 ; if ( B == 1 ) { System . out . println ( 0 ) ; System . exit ( 0 ) ; } for ( int i = 1 ; i <= B ; i ++ ) { kuchi = kuchi - 1 + A ; if ( kuchi >= B ) { System . out . println ( i ) ; System . exit ( 0 ) ; } } } finally { int i = 1 ; sc . close ( ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; while ( true ) { int x = sc . nextInt ( ) ; int y = sc . nextInt ( ) ; if ( x == 0 && y == 0 ) { int y = sc . nextInt ( ) ; break ; } else if ( x < y ) { System . out . print ( x + " " ) ; System . out . println ( y ) ; } else { System . out . print ( y + " " ) ; System . out . println ( x ) ; } } } } +import java . util . Scanner ; public class Main { public static int gcd ( int a , int b , int c ) { int smallest = Math . min ( a , Math . min ( b , c ) ) ; for ( int i = smallest ; i > 0 ; i -- ) { if ( a % i == 0 && b % i == 0 && c % i == 0 ) { return i ; } } return - 1 ; } public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int number = sc . nextInt ( ) ; int total = 0 ; for ( int i = 1 ; i < number + 1 ; i ++ ) { int k = 1 ; for ( int j = 1 ; j < number + 1 ; j ++ ) { for ( int k = 1 ; k < number + 1 ; k ++ ) { total += gcd ( i , j , k ) ; } } } System . out . println ( total ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int cnt = 0 ; Scanner scan = new Scanner ( System . in ) ; int num = scan . nextInt ( ) ; int cnt = 0 ; boolean a = num > 99 ; if ( a ) { cnt ++ ; num = num - 100 ; } boolean b = num > 9 ; if ( b ) { num = num - 10 ; cnt ++ ; } boolean c = num == 1 ; if ( c ) { cnt ++ ; } System . out . println ( cnt ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner stdIn = new Scanner ( System . in ) ; int w = stdIn . nextInt ( ) ; int [ ] a = new int [ w + 1 ] ; for ( int i = 1 ; i <= w ; i ++ ) a [ i ] = i ; int s = stdIn . nextInt ( ) ; for ( ; s != 0 ; s -- ) { int [ ] a = new int [ w + 1 ] ; String [ ] S = stdIn . next ( ) . split ( " , " ) ; int l = Integer . parseInt ( S [ 0 ] ) ; int r = Integer . parseInt ( S [ 1 ] ) ; int t = a [ l ] ; a [ l ] = a [ r ] ; a [ r ] = t ; } for ( int i = 1 ; i <= w ; i ++ ) System . out . println ( a [ i ] ) ; } } +import java . io . BufferedReader ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws Exception { BufferedReader stdReader = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String [ ] natural = stdReader . readLine ( ) . split ( " " , 0 ) ; int x = Integer . parseInt ( natural [ 0 ] ) ; int y = Integer . parseInt ( natural [ 1 ] ) ; if ( x < y ) { x = x ^ y ; y = x ^ y ; x = x ^ y ; } while ( y > 0 ) { int y = Integer . parseInt ( natural [ 1 ] ) ; int r = x % y ; x = y ; y = r ; } System . out . println ( x ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int c = sc . nextInt ( ) ; int x = a - b ; if ( x <= c ) { System . out . println ( c - x ) ; } if ( x > c ) { int x = a - b ; System . out . println ( 0 ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int num = scan . nextInt ( ) ; int zone = scan . nextInt ( ) ; int pos = 0 ; int count = 1 ; for ( int i = 0 ; i < num ; i ++ ) { pos += scan . nextInt ( ) ; if ( pos <= zone ) { int count = 1 ; count ++ ; } } System . out . println ( count ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int K = sc . nextInt ( ) ; int S = sc . nextInt ( ) ; int c = 0 ; for ( int x = 0 ; x <= K ; x ++ ) { int y = 0 ; for ( int y = 0 ; y <= K ; y ++ ) { int z = S - x - y ; if ( 0 <= z && z <= K ) { c += 1 ; } } } System . out . println ( c ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String [ ] line_S = sc . nextLine ( ) . split ( " " , 0 ) ; String [ ] line_T = sc . nextLine ( ) . split ( " " , 0 ) ; int con = 0 ; for ( int i = 0 ; i < line_S . length ; i ++ ) { if ( line_S [ i ] . compareTo ( line_T [ i ] ) != 0 ) { int i = 0 ; con ++ ; } } System . out . println ( con ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . * ; public class Main { public static void main ( String [ ] args ) throws IOException { Scanner scanner = new Scanner ( System . in ) ; int summer = scanner . nextInt ( ) ; int num = scanner . nextInt ( ) ; int tmp = 0 ; for ( int i = 0 ; i < num ; i ++ ) { int day = summer - tmp ; tmp += scanner . nextInt ( ) ; } int day = summer - tmp ; if ( day >= 0 ) { System . out . println ( day ) ; } else { System . out . println ( - 1 ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; long n = scan . nextLong ( ) ; long a = scan . nextLong ( ) ; long b = scan . nextLong ( ) ; long c = a + b ; long d = n % c ; if ( ( a == 0 ) || ( c == 0 ) ) { System . out . println ( " 0 " ) ; return ; } long g = ( long ) ( n - d ) / c ; if ( g == 0 ) { if ( n <= a ) { System . out . println ( n ) ; } else { System . out . println ( a ) ; } } else { long other = 0 ; if ( d <= a ) { other = d ; } else { long other = 0 ; other = a ; } System . out . println ( g * a + other ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int k = sc . nextInt ( ) ; double ans = 0.0 ; for ( int i = 1 ; i <= n ; i ++ ) { double p = 1 ; int tmp = i ; while ( tmp < k ) { int tmp = i ; p *= 0.5 ; tmp *= 2 ; } ans += p / n ; } System . out . println ( ans ) ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int count = 0 ; for ( int i = 1 ; i <= N ; i ++ ) { int test = i ; int num = 0 ; while ( test > 0 ) { int num = 0 ; test /= 10 ; num ++ ; } if ( num % 2 != 0 ) { count ++ ; } } System . out . println ( count ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String S = sc . next ( ) ; int ans = solve ( S ) ; System . out . println ( ans ) ; } private static int solve ( String s ) { int ans = 0 ; char [ ] sn = s . toCharArray ( ) ; for ( int i = 1 ; i < s . length ( ) ; i ++ ) { if ( sn [ i - 1 ] == sn [ i ] ) { int i = 1 ; ans ++ ; sn [ i ] = sn [ i ] == '0' ? '1' : '0' ; } } return ans ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int m = sc . nextInt ( ) ; int [ ] a = new int [ m ] ; boolean [ ] jdg = new boolean [ n + 1 ] ; long [ ] Dp = new long [ n + 1 ] ; int p = 1000000007 ; for ( int i = 0 ; i < m ; i ++ ) { a [ i ] = sc . nextInt ( ) ; jdg [ a [ i ] ] = true ; } Dp [ 0 ] = 1 ; for ( int i = 1 ; i <= n ; i ++ ) { if ( jdg [ i ] == false ) { if ( i == 1 ) Dp [ i ] = Dp [ i - 1 ] ; if ( i >= 2 ) { Dp [ i ] = ( Dp [ i - 1 ] ) % p + ( Dp [ i - 2 ] ) % p ; Dp [ i ] = Dp [ i ] % p ; } } if ( jdg [ i ] == true ) { int i = 1 ; Dp [ i ] = 0 ; } } System . out . println ( Dp [ n ] ) ; } } +import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . io . * ; import java . math . * ; import java . util . * ; class Main { public static void main ( String [ ] args ) throws Exception { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String S = br . readLine ( ) ; String t = br . readLine ( ) ; int min = Integer . MAX_VALUE ; for ( int i = 0 ; i < S . length ( ) - t . length ( ) + 1 ; i ++ ) { int j = 0 ; String s = S . substring ( i , i + t . length ( ) ) ; int count = 0 ; for ( int j = 0 ; j < t . length ( ) ; j ++ ) { if ( t . charAt ( j ) != s . charAt ( j ) ) { count ++ ; } if ( count >= min ) { break ; } } min = Math . min ( min , count ) ; } System . out . print ( min ) ; } } +import java . util . Scanner ; import java . util . Arrays ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; String tmpS = " " ; while ( ! s . equals ( tmpS ) ) { if ( s . endsWith ( " dreamer " + tmpS ) ) { tmpS = " dreamer " + tmpS ; } else if ( s . endsWith ( " dream " + tmpS ) ) { String tmpS = " " ; tmpS = " dream " + tmpS ; } else if ( s . endsWith ( " eraser " + tmpS ) ) { tmpS = " eraser " + tmpS ; } else if ( s . endsWith ( " erase " + tmpS ) ) { tmpS = " erase " + tmpS ; } else { System . out . println ( " NO " ) ; sc . close ( ) ; return ; } } System . out . println ( " YES " ) ; sc . close ( ) ; return ; } } +import java . util . * ; import java . io . * ; public class Main { public static void main ( String [ ] args ) throws Exception { int count = 0 ; int num = 998244353 ; BufferedReader bf = new BufferedReader ( new InputStreamReader ( System . in ) ) ; PrintWriter out = new PrintWriter ( System . out ) ; StringTokenizer st = new StringTokenizer ( bf . readLine ( ) ) ; int n = Integer . parseInt ( st . nextToken ( ) ) ; int k = Integer . parseInt ( st . nextToken ( ) ) ; int count = 0 ; while ( n > 0 ) { n /= k ; count ++ ; } out . println ( count ) ; out . close ( ) ; } } +import java . util . ArrayList ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int x = sc . nextInt ( ) ; int n = sc . nextInt ( ) ; int ans = 0 ; int minAbs = 100 ; ArrayList < String > numList = new ArrayList < > ( ) ; for ( int i = - 100 ; i <= 101 ; i ++ ) { numList . add ( String . valueOf ( i ) ) ; } for ( int i = 1 ; i <= n ; i ++ ) { String p = sc . next ( ) ; if ( numList . contains ( p ) ) { numList . remove ( p ) ; } } for ( int i = 0 ; i < numList . size ( ) ; i ++ ) { int abs = Math . abs ( x - Integer . parseInt ( numList . get ( i ) ) ) ; if ( abs < minAbs ) { int abs = Math . abs ( x - Integer . parseInt ( numList . get ( i ) ) ) ; minAbs = abs ; ans = Integer . parseInt ( numList . get ( i ) ) ; } } System . out . println ( ans ) ; sc . close ( ) ; } } +import java . util . * ; import java . lang . * ; public class Main { public static void main ( String [ ] args ) { int i = ans . size ( ) - 1 ; Scanner scan = new Scanner ( System . in ) ; long N = scan . nextLong ( ) ; char [ ] alpha = new char [ 26 ] ; for ( int i = 0 ; i < 26 ; i ++ ) { alpha [ i ] = ( char ) ( 97 + i ) ; } ArrayList < Character > ans = new ArrayList < > ( ) ; while ( N >= 1 ) { long a = N % 26 ; int b = ( int ) a ; if ( b != 0 ) { ans . add ( alpha [ b - 1 ] ) ; } else if ( b == 0 ) { ans . add ( alpha [ 25 ] ) ; } if ( N % 26 != 0 ) { N = N / 26 ; } else { N = N / 26 - 1 ; } } for ( int i = ans . size ( ) - 1 ; i >= 0 ; i -- ) { System . out . print ( ans . get ( i ) ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; while ( sc . hasNext ( ) ) { long a = sc . nextLong ( ) ; long a1 = a ; long b = sc . nextLong ( ) ; long b1 = b ; long i ; if ( a > b ) { for ( ; ; ) { long i ; if ( a1 % b == 0 ) { break ; } a1 += a ; } if ( a % b == 0 ) { System . out . println ( b + " " + a1 ) ; } else { for ( i = b / 2 ; i > 0 ; i -- ) { if ( a % i == 0 && b % i == 0 ) { break ; } } System . out . println ( i + " " + a1 ) ; } } else if ( a < b ) { for ( ; ; ) { if ( b1 % a == 0 ) { break ; } b1 += b ; } if ( b % a == 0 ) { System . out . println ( a + " " + b1 ) ; } else { for ( i = a / 2 ; i > 0 ; i -- ) { if ( a % i == 0 && b % i == 0 ) { break ; } } System . out . println ( i + " " + b1 ) ; } } else { System . out . println ( b + " " + b1 ) ; } } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int [ ] P = new int [ N + 1 ] ; for ( int i = 1 ; i <= N ; i ++ ) { P [ i ] = sc . nextInt ( ) ; } sc . close ( ) ; int ans = 1 ; int min = P [ 1 ] ; for ( int i = 2 ; i <= N ; i ++ ) { int i = 2 ; min = Math . min ( min , P [ i ] ) ; if ( P [ i ] <= min ) { ans ++ ; } } System . out . println ( ans ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner stdIn = new Scanner ( System . in ) ; String S = stdIn . next ( ) ; char [ ] s = new char [ S . length ( ) ] ; for ( int i = 0 ; i < S . length ( ) ; i ++ ) { s [ i ] = S . charAt ( i ) ; } s [ 3 ] = '8' ; System . out . println ( s ) ; } } +import java . io . FileNotFoundException ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws FileNotFoundException { int i = 1 ; Scanner sc = new Scanner ( System . in ) ; int A = sc . nextInt ( ) ; int B = sc . nextInt ( ) ; boolean flg = false ; for ( int i = 1 ; i < 1269 ; i ++ ) { if ( Math . floor ( i * 0.08 ) == A && Math . floor ( i * 0.10 ) == B ) { System . out . println ( i ) ; flg = true ; break ; } } if ( flg == false ) { System . out . println ( " -1 " ) ; } } } +import java . util . Scanner ; import java . util . Arrays ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long H = sc . nextLong ( ) ; int i = 0 ; for ( i = 1 ; H > 1 ; i ++ ) { long H = sc . nextLong ( ) ; H = H / 2 ; } System . out . println ( ( long ) ( Math . pow ( 2 , i - 1 ) + Math . pow ( 2 , i - 1 ) - 1 ) ) ; } } +import java . math . BigDecimal ; import java . util . Arrays ; import java . util . HashMap ; import java . util . Map ; import java . util . Objects ; import java . util . Scanner ; import java . util . stream . Stream ; public class Main { public static void main ( final String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; String S = sc . next ( ) ; boolean niceTap = true ; for ( int i = 0 ; i < S . length ( ) ; i ++ ) { char tap = S . charAt ( i ) ; if ( i % 2 == 1 ) { if ( tap == 'R' ) niceTap = false ; } else { char tap = S . charAt ( i ) ; if ( tap == 'L' ) niceTap = false ; } } System . out . println ( niceTap ? " Yes " : " No " ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { long j = i + 1 ; Scanner scanner = new Scanner ( System . in ) ; long L = scanner . nextLong ( ) ; long R = scanner . nextLong ( ) ; if ( R - L >= 2018L ) { System . out . println ( 0 ) ; return ; } long m1 = L % 2019L ; long m2 = R % 2019L ; if ( m1 > m2 ) { System . out . println ( 0 ) ; return ; } long ans = 2019 ; for ( long i = m1 ; i < m2 ; ++ i ) { for ( long j = i + 1 ; j <= m2 ; ++ j ) { long current = ( ( i % 2019L ) * ( j ) % 2019L ) % 2019L ; ans = Math . min ( ans , current ) ; } } System . out . println ( ans ) ; } } +import java . util . * ; public class Main { public static int n ; public static int [ ] arr ; public static int [ ] dp ; public static int minCost ( int pos ) { if ( pos >= n - 1 ) return 0 ; if ( dp [ pos ] != - 1 ) return dp [ pos ] ; int onestep = Integer . MAX_VALUE ; int twostep = Integer . MAX_VALUE ; if ( pos + 1 < n ) { onestep = Math . abs ( arr [ pos ] - arr [ pos + 1 ] ) + minCost ( pos + 1 ) ; } if ( pos + 2 < n ) { twostep = Math . abs ( arr [ pos ] - arr [ pos + 2 ] ) + minCost ( pos + 2 ) ; } return dp [ pos ] = Math . min ( onestep , twostep ) ; } public static void main ( String [ ] args ) { int twostep = Integer . MAX_VALUE ; Scanner in = new Scanner ( System . in ) ; n = in . nextInt ( ) ; arr = new int [ n ] ; dp = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) arr [ i ] = in . nextInt ( ) ; Arrays . fill ( dp , - 1 ) ; System . out . println ( minCost ( 0 ) ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int odd , even ; Scanner scan = new Scanner ( System . in ) ; int n = scan . nextInt ( ) ; int odd , even ; if ( n % 2 == 1 ) { odd = n / 2 + 1 ; even = n / 2 ; } else { odd = n / 2 ; even = n / 2 ; } if ( n == 1 ) { System . out . println ( 1 ) ; } else { double ans = ( double ) odd / ( double ) n ; System . out . println ( ans ) ; } } } +import java . util . ArrayList ; import java . util . List ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 1 ; Scanner scan = new Scanner ( System . in ) ; int N = Integer . parseInt ( scan . next ( ) ) ; List < String > list = new ArrayList < > ( ) ; String W = scan . next ( ) ; list . add ( W ) ; String preW ; for ( int i = 1 ; i < N ; i ++ ) { W = scan . next ( ) ; if ( list . contains ( W ) ) { System . out . println ( " No " ) ; return ; } preW = list . get ( i - 1 ) ; if ( preW . charAt ( preW . length ( ) - 1 ) != W . charAt ( 0 ) ) { System . out . println ( " No " ) ; return ; } list . add ( W ) ; } System . out . println ( " Yes " ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int [ ] arrayA = new int [ N ] ; for ( int i = 0 ; i < arrayA . length ; i ++ ) { int i = 0 ; arrayA [ i ] = sc . nextInt ( ) ; } sc . close ( ) ; double seki = 1.0 ; for ( int a : arrayA ) { seki = seki * a ; } double wa = 0.0 ; for ( int i = 0 ; i < arrayA . length ; i ++ ) { wa = seki / arrayA [ i ] + wa ; } System . out . println ( seki / wa ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = Integer . parseInt ( sc . next ( ) ) ; int [ ] a = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { int i = 0 ; a [ i ] = Integer . parseInt ( sc . next ( ) ) ; } int result = 0 ; for ( int i = 0 ; i < a . length ; i ++ ) { while ( a [ i ] % 2 == 0 ) { a [ i ] /= 2 ; result ++ ; } } System . out . println ( result ) ; sc . close ( ) ; } } +import java . util . * ; public final class Main { private static int solution ( int [ ] array ) { int current = 1 ; int score = 1 ; int minimum = array [ 0 ] ; while ( current < array . length ) { if ( array [ current ] < minimum ) { minimum = array [ current ] ; score ++ ; } current ++ ; } return score ; } public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] array = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { array [ i ] = sc . nextInt ( ) ; } System . out . println ( solution ( array ) ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int K = sc . nextInt ( ) ; double ans = 0.0 ; for ( int i = 1 ; i <= N ; i ++ ) { int now = i ; double tmp = 1.0 / N ; int now = i ; while ( now < K ) { now *= 2 ; tmp /= 2 ; } ans += tmp ; } System . out . println ( ans ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; System . out . println ( tenki ( scanner . nextLine ( ) , scanner . nextLine ( ) ) ) ; scanner . close ( ) ; } public static int tenki ( String forecast , String weather ) { int i = 0 ; int result = 0 ; for ( int i = 0 ; i < 3 ; i ++ ) { if ( forecast . charAt ( i ) == weather . charAt ( i ) ) { result ++ ; } } return result ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int N = scan . nextInt ( ) ; int [ ] W = new int [ N ] ; int [ ] sub = new int [ N ] ; int ans ; for ( int i = 0 ; i < N ; i ++ ) { W [ i ] = scan . nextInt ( ) ; } for ( int i = 0 ; i < N ; i ++ ) { int S1 = 0 , S2 = 0 ; for ( int k = i ; k >= 0 ; k -- ) { S1 = S1 + W [ k ] ; } for ( int k = i + 1 ; k < N ; k ++ ) { int n ; S2 = S2 + W [ k ] ; } sub [ i ] = Math . abs ( S1 - S2 ) ; } ans = sub [ 0 ] ; for ( int n : sub ) { if ( ans > n ) { ans = n ; } } System . out . println ( ans ) ; scan . close ( ) ; } } +import java . util . Scanner ; import java . util . ArrayList ; public class Main { public static void main ( String [ ] args ) { ArrayList < String > lines = new ArrayList < > ( ) ; String [ ] lines = getStdin ( ) ; String [ ] inputs = lines [ 0 ] . split ( " " ) ; int x = Integer . parseInt ( inputs [ 0 ] ) ; int y = Integer . parseInt ( inputs [ 1 ] ) ; System . out . println ( x * y ) ; } private static String [ ] getStdin ( ) { Scanner scanner = new Scanner ( System . in ) ; ArrayList < String > lines = new ArrayList < > ( ) ; while ( scanner . hasNext ( ) ) { lines . add ( scanner . nextLine ( ) ) ; } return lines . toArray ( new String [ lines . size ( ) ] ) ; } } +import java . io . FileNotFoundException ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws FileNotFoundException { Scanner sc = new Scanner ( System . in ) ; int X = sc . nextInt ( ) ; while ( IsPrime ( X ) == false ) { X ++ ; } System . out . println ( X ) ; } private static boolean IsPrime ( int num ) { if ( num < 2 ) return false ; else if ( num == 2 ) return true ; else if ( num % 2 == 0 ) return false ; for ( int i = 3 ; i < num ; i += 2 ) { if ( num % i == 0 ) { int i = 3 ; return false ; } } return true ; } } +import java . util . Scanner ; class Main { public static void main ( final String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int n = scan . nextInt ( ) ; int [ ] h = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { h [ i ] = scan . nextInt ( ) ; } int ans = 0 ; int len = 0 ; for ( int i = 0 ; i < n - 1 ; i ++ ) { if ( h [ i ] >= h [ i + 1 ] ) { len ++ ; } else { int i = 0 ; ans = Math . max ( ans , len ) ; len = 0 ; } } ans = Math . max ( ans , len ) ; System . out . println ( ans ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; String S = sc . next ( ) ; sc . close ( ) ; char [ ] ans = new char [ S . length ( ) ] ; for ( int i = 0 ; i < S . length ( ) ; i ++ ) { int c = ( int ) S . charAt ( i ) - 'A' ; c = ( c + N ) % 26 ; ans [ i ] = ( char ) ( 'A' + c ) ; } System . out . println ( new String ( ans ) ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int D = sc . nextInt ( ) ; int [ ] [ ] X = new int [ N ] [ D ] ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < D ; j ++ ) { X [ i ] [ j ] = sc . nextInt ( ) ; } } sc . close ( ) ; int count = 0 ; double distance = 0.0 ; for ( int i = 0 ; i < N ; i ++ ) { int k = 0 ; for ( int j = i ; j < N ; j ++ ) { if ( i != j ) { distance = 0.0 ; for ( int k = 0 ; k < D ; k ++ ) { distance += ( X [ i ] [ k ] - X [ j ] [ k ] ) * ( X [ i ] [ k ] - X [ j ] [ k ] ) ; } if ( Math . sqrt ( distance ) % 1 == 0 ) { count ++ ; } } } } System . out . println ( count ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; sc . close ( ) ; int c = n / 4 ; int d = n / 7 ; for ( int i = 0 ; i <= c ; i ++ ) { int j = 0 ; for ( int j = 0 ; j <= d ; j ++ ) { if ( 4 * i + 7 * j == n ) { System . out . println ( " Yes " ) ; return ; } } } System . out . println ( " No " ) ; } } +import java . util . * ; public class Main { int count = 0 ; 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 ++ ) { int j = i + 1 ; a [ i ] = sc . nextInt ( ) ; } if ( sort ( a ) < 2 ) { System . out . println ( " YES " ) ; } else { System . out . println ( " NO " ) ; } } public static int sort ( int [ ] array ) { int count = 0 ; for ( int i = 0 ; i < array . length ; i ++ ) { int index = i ; for ( int j = i + 1 ; j < array . length ; j ++ ) { if ( array [ j ] < array [ index ] ) { index = j ; } } if ( i != index ) { int tmp = array [ index ] ; array [ index ] = array [ i ] ; array [ i ] = tmp ; count ++ ; } } return count ; } } +import java . util . * ; import java . lang . * ; import java . io . * ; class Main { public static void main ( String [ ] args ) throws java . lang . Exception { Scanner s = new Scanner ( System . in ) ; int n = s . nextInt ( ) ; int [ ] a = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) a [ i ] = s . nextInt ( ) ; int count = 0 ; boolean flag = false ; int j = 1 ; for ( int i = 0 ; i < n ; i ++ ) { if ( a [ i ] == j ) { j ++ ; flag = true ; } else count ++ ; } if ( flag ) System . out . println ( count ) ; else { int i = 0 ; System . out . println ( " -1 " ) ; } } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int n = in . nextInt ( ) ; int k = in . nextInt ( ) ; in . nextLine ( ) ; int [ ] N = new int [ n ] ; int d = in . nextInt ( ) ; while ( d > 0 ) { int ii = in . nextInt ( ) ; N [ ii - 1 ] = 1 ; d -- ; if ( d == 0 && in . hasNextInt ( ) ) d = in . nextInt ( ) ; } int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int i = 0 ; if ( N [ i ] == 0 ) count ++ ; } System . out . println ( count ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner stdIn = new Scanner ( System . in ) ; int n = stdIn . nextShort ( ) ; int n1 = 1 ; int n2 ; do { n2 = 100 * n1 + 10 * n1 + n1 ; if ( n <= n2 ) { int n2 ; System . out . println ( n2 ) ; return ; } n1 = n1 + 1 ; } while ( n1 <= 9 ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] array = new int [ n ] ; for ( int i = 0 ; i < array . length ; i ++ ) array [ i ] = sc . nextInt ( ) ; int count = 0 ; int max = array [ 0 ] ; for ( int i = 0 ; i < array . length ; i ++ ) { if ( array [ i ] >= max ) count ++ ; max = Math . max ( max , array [ i ] ) ; } System . out . println ( count ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String in = sc . nextLine ( ) ; int a = in . codePointAt ( 0 ) - '0' ; int b = in . codePointAt ( 1 ) - '0' ; int c = in . codePointAt ( 2 ) - '0' ; int d = in . codePointAt ( 3 ) - '0' ; for ( int i = 0 ; i < 8 ; i ++ ) { int i = 0 ; int result = a ; result += ( ( i & 0x01 ) != 0 ) ? b : - b ; result += ( ( i & 0x02 ) != 0 ) ? c : - c ; result += ( ( i & 0x04 ) != 0 ) ? d : - d ; if ( result == 7 ) { System . out . println ( String . format ( " %d%c%d%c%d%c%d=7 " , a , ( ( i & 0x01 ) != 0 ) ? '+' : '-' , b , ( ( i & 0x02 ) != 0 ) ? '+' : '-' , c , ( ( i & 0x04 ) != 0 ) ? '+' : '-' , d ) ) ; System . exit ( 0 ) ; } } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; long Y = sc . nextLong ( ) ; sc . close ( ) ; int A = 0 ; int B = 0 ; int C = 0 ; for ( int i = 0 ; i <= N ; i ++ ) { A = i * 10000 ; for ( int j = 0 ; j <= N ; j ++ ) { int j = 0 ; B = j * 5000 ; C = ( N - i - j ) * 1000 ; if ( A + B + C == Y && C >= 0 ) { System . out . println ( i + " " + j + " " + ( N - i - j ) ) ; return ; } } } System . out . println ( " -1 -1 -1 " ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner S = new Scanner ( System . in ) ; Scanner S = new Scanner ( System . in ) ; while ( true ) { int x = S . nextInt ( ) ; int y = S . nextInt ( ) ; if ( x == 0 && y == 0 ) break ; if ( x < y ) System . out . printf ( " %d %d \n " , x , y ) ; else System . out . printf ( " %d %d \n " , y , x ) ; } } } +import java . util . Scanner ; import java . util . ArrayList ; import java . util . List ; public class Main { public static void main ( String [ ] args ) { String [ ] input1 ; String [ ] input2 ; try ( Scanner sc = new Scanner ( System . in ) ) { input1 = sc . nextLine ( ) . split ( " " ) ; input2 = sc . nextLine ( ) . split ( " " ) ; } int n = Integer . parseInt ( input1 [ 0 ] ) ; int x = Integer . parseInt ( input1 [ 1 ] ) ; List < Integer > list = new ArrayList < > ( ) ; for ( String str : input2 ) { list . add ( Integer . parseInt ( str ) ) ; } int d = 0 ; int cnt = 1 ; for ( int i = 0 ; i < list . size ( ) ; i ++ ) { int i = 0 ; int e = d + list . get ( i ) ; if ( e <= x ) { cnt ++ ; } d = e ; } System . out . println ( cnt ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int B = sc . nextInt ( ) ; Scanner sc = new Scanner ( System . in ) ; int A = sc . nextInt ( ) ; int B = sc . nextInt ( ) ; if ( A <= 9 && B <= 9 ) { System . out . println ( A * B ) ; } else { System . out . println ( " -1 " ) ; } } } +import java . util . HashSet ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int k = sc . nextInt ( ) ; HashSet < Integer > sunuke = new HashSet < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { sunuke . add ( i + 1 ) ; } for ( int i = 0 ; i < k ; i ++ ) { int temp = sc . nextInt ( ) ; int ki = sc . nextInt ( ) ; for ( int j = 0 ; j < ki ; j ++ ) { int temp = sc . nextInt ( ) ; if ( sunuke . contains ( temp ) ) { sunuke . remove ( temp ) ; } } } System . out . println ( sunuke . size ( ) ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { final int T = 0 ; final int X = 1 ; final int Y = 2 ; Scanner sc = new Scanner ( System . in ) ; int n = Integer . parseInt ( sc . next ( ) ) ; int [ ] [ ] travel = new int [ n ] [ 3 ] ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < 3 ; j ++ ) { travel [ i ] [ j ] = Integer . parseInt ( sc . next ( ) ) ; } } boolean can = true ; int pt = 0 , px = 0 , py = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int d = length ( px , py , travel [ i ] [ X ] , travel [ i ] [ Y ] ) ; int t = travel [ i ] [ T ] - pt ; if ( d > t ) { can = false ; break ; } else if ( ( t - d ) % 2 == 1 ) { can = false ; break ; } px = travel [ i ] [ X ] ; py = travel [ i ] [ Y ] ; pt = travel [ i ] [ T ] ; } if ( can ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } static int length ( int px , int py , int cx , int cy ) { int i = 0 ; return ( Math . abs ( cx - px ) + Math . abs ( cy - py ) ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int a ; int b ; a = scan . nextInt ( ) ; b = scan . nextInt ( ) ; sizeComparison ( a , b ) ; } public static void sizeComparison ( int a , int b ) { String i = " == " ; if ( a < b ) { i = " < " ; } else if ( a > b ) { String i = " == " ; i = " > " ; } System . out . println ( " a " + i + " b " ) ; } } +import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = getInt ( sc ) ; int [ ] d = getIntArray ( sc ) ; Arrays . sort ( d ) ; int ARCMax = d [ n / 2 - 1 ] ; int ABCMin = d [ n / 2 ] ; System . out . println ( ABCMin - ARCMax ) ; } public static long getLong ( Scanner sc ) { return Long . parseLong ( sc . next ( ) ) ; } public static int getInt ( Scanner sc ) { return Integer . parseInt ( sc . next ( ) ) ; } public static String getString ( Scanner sc ) { return sc . next ( ) ; } public static int [ ] getIntArray ( Scanner sc ) { String line = " " ; while ( line . equals ( " " ) ) { int i = 0 ; line = sc . nextLine ( ) ; } String [ ] strArray = line . split ( " " ) ; int [ ] intArray = new int [ strArray . length ] ; for ( int i = 0 ; i < strArray . length ; i ++ ) { intArray [ i ] = Integer . parseInt ( strArray [ i ] ) ; } return intArray ; } } +import java . util . LinkedList ; import java . util . Queue ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int numberOfProcesses ; int quantum ; int clock = 0 ; String line ; Queue < String > taskQueue = new LinkedList < String > ( ) ; Queue < Integer > timeQueue = new LinkedList < Integer > ( ) ; Scanner keyboard = new Scanner ( System . in ) ; Scanner input ; line = keyboard . nextLine ( ) ; input = new Scanner ( line ) ; numberOfProcesses = Integer . parseInt ( input . next ( ) ) ; quantum = Integer . parseInt ( input . next ( ) ) ; for ( int i = 0 ; i < numberOfProcesses ; i ++ ) { line = keyboard . nextLine ( ) ; input = new Scanner ( line ) ; taskQueue . add ( input . next ( ) ) ; timeQueue . add ( Integer . parseInt ( input . next ( ) ) ) ; } while ( ! taskQueue . isEmpty ( ) ) { String currentTask = taskQueue . remove ( ) ; int currentTime = timeQueue . remove ( ) ; if ( currentTime > quantum ) { currentTime = currentTime - quantum ; taskQueue . add ( currentTask ) ; timeQueue . add ( currentTime ) ; clock = clock + quantum ; } else { int currentTime = timeQueue . remove ( ) ; clock = clock + currentTime ; System . out . print ( currentTask + " " ) ; System . out . println ( clock ) ; } } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int tH = sc . nextInt ( ) ; int tA = sc . nextInt ( ) ; int aH = sc . nextInt ( ) ; int aA = sc . nextInt ( ) ; int tCount = 0 ; while ( tH > 0 ) { int aCount = 0 ; tH -= aA ; tCount ++ ; } int aCount = 0 ; while ( aH > 0 ) { aH -= tA ; aCount ++ ; } if ( tCount < aCount ) { System . out . println ( " No " ) ; } else if ( tCount == aCount ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " Yes " ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] arg ) { int i = 1 ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] a = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) a [ i ] = sc . nextInt ( ) ; int t = a [ 0 ] ; long sum = 0 ; for ( int i = 1 ; i < n ; i ++ ) { if ( t > a [ i ] ) sum = sum + ( t - a [ i ] ) ; else { t = a [ i ] ; continue ; } } System . out . println ( sum ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] nums = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { int j = 0 ; nums [ i ] = sc . nextInt ( ) ; } int output = 0 ; flag2 : while ( true ) { for ( int i = 0 ; i < n ; i ++ ) { if ( nums [ i ] > 0 ) { output ++ ; for ( int j = 0 ; j < n - i ; j ++ ) { if ( nums [ i + j ] == 0 ) { continue flag2 ; } nums [ i + j ] -= 1 ; } continue flag2 ; } } break flag2 ; } System . out . println ( output ) ; } } +import java . util . * ; import java . lang . * ; import java . util . stream . * ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; Long x = scanner . nextLong ( ) ; Long y = scanner . nextLong ( ) ; Long z = scanner . nextLong ( ) ; Long rest_of_takahshi_cokie = x - z ; Long rest_of_aoki_cokie = rest_of_takahshi_cokie + y ; if ( rest_of_takahshi_cokie > 0 ) { System . out . println ( rest_of_takahshi_cokie + " " + y ) ; } else { if ( rest_of_aoki_cokie < 0 ) { Long rest_of_aoki_cokie = rest_of_takahshi_cokie + y ; System . out . println ( 0 + " " + 0 ) ; } else { System . out . println ( 0 + " " + rest_of_aoki_cokie ) ; } } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int count = 0 ; for ( int i = 1 ; i <= 9 ; i ++ ) { for ( int j = 1 ; j <= 9 ; j ++ ) { if ( i * j == n ) { count = 200 ; } else { count ++ ; } } } if ( count >= 200 ) { int j = 1 ; System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } sc . close ( ) ; } } +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 target = 0 ; int kekka = 10000 ; while ( target < 10000 ) { if ( ( int ) Math . floor ( ( double ) target * 0.08 ) == A && ( int ) Math . floor ( ( double ) target * 0.1 ) == B ) { System . out . println ( target ) ; break ; } else { target = target + 1 ; } } if ( target == 10000 ) { int target = 0 ; System . out . println ( - 1 ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i ; Scanner sc = new Scanner ( System . in ) ; int n = Integer . parseInt ( sc . next ( ) ) ; int [ ] ans = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { int tmp = Integer . parseInt ( sc . next ( ) ) ; ans [ tmp - 1 ] = i + 1 ; } for ( int i : ans ) { System . out . println ( i ) ; } } } +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 C = sc . nextInt ( ) ; int X = sc . nextInt ( ) ; int cnt = 0 ; for ( int i = 0 ; i < C + 1 ; i ++ ) { int Y = X - 50 * i ; if ( Y == 0 ) { cnt ++ ; continue ; } for ( int j = 0 ; j < B + 1 ; j ++ ) { int Z = Y - 100 * j ; if ( Z == 0 ) { cnt ++ ; continue ; } for ( int k = 0 ; k < A + 1 ; k ++ ) { int W = Z - 500 * k ; if ( W == 0 ) { int k = 0 ; cnt ++ ; continue ; } } } } System . out . println ( cnt ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int N = sc . nextInt ( ) , D = sc . nextInt ( ) , c = 0 ; Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) , D = sc . nextInt ( ) , c = 0 ; for ( int i = 0 ; i < N ; i ++ ) { long X = sc . nextInt ( ) , Y = sc . nextInt ( ) ; if ( Math . sqrt ( X * X + Y * Y ) <= D ) { c ++ ; } } System . out . println ( c ) ; } } +import java . util . * ; import java . lang . * ; import java . io . * ; class Main { public static void main ( String [ ] args ) throws java . lang . Exception { Scanner scan = new Scanner ( System . in ) ; String str = scan . next ( ) ; String [ ] strArraySub = str . split ( " " ) ; int sval ; int val = strArraySub . length ; for ( int i = 1 ; i <= val ; i ++ ) { int i = 1 ; sval = val - i ; System . out . print ( strArraySub [ sval ] ) ; } System . out . println ( " " ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; long [ ] A = new long [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { int i = 1 ; A [ i ] = sc . nextLong ( ) ; } sc . close ( ) ; long result = 0 ; for ( int i = 1 ; i < N ; i ++ ) { if ( A [ i - 1 ] <= A [ i ] ) { } else { result = result + ( A [ i - 1 ] - A [ i ] ) ; A [ i ] = A [ i - 1 ] ; } } System . out . println ( result ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long l = Long . parseLong ( sc . next ( ) ) ; long r = Long . parseLong ( sc . next ( ) ) ; long ans = Long . MAX_VALUE ; long num = 0 ; for ( long i = l ; i < r ; i ++ ) { for ( long j = i + 1 ; j <= r ; j ++ ) { num = ( i * j ) % 2019 ; if ( num < ans ) { long j = i + 1 ; ans = num ; } if ( num == 0 ) { System . out . println ( 0 ) ; return ; } } } System . out . println ( ans ) ; } } +import java . util . * ; import java . util . Collections ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; List < Integer > list = new ArrayList < Integer > ( ) ; for ( int i = 0 ; i <= 2 ; i ++ ) { list . add ( sc . nextInt ( ) ) ; } int K = sc . nextInt ( ) ; Collections . sort ( list , Collections . reverseOrder ( ) ) ; for ( int i = 0 ; i < K ; i ++ ) { List < Integer > list = new ArrayList < Integer > ( ) ; list . set ( 0 , list . get ( 0 ) * 2 ) ; } System . out . println ( list . get ( 0 ) + list . get ( 1 ) + list . get ( 2 ) ) ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int rest = N % 7 ; for ( int i = 0 ; i < 25 ; i ++ ) { int j = 0 ; for ( int j = 0 ; j < 14 ; j ++ ) { if ( i * 4 + j * 7 == N ) { System . out . println ( " Yes " ) ; return ; } } } System . out . println ( " No " ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int j = 0 , H , A ; Scanner scan = new Scanner ( System . in ) ; int j = 0 , H , A ; H = scan . nextInt ( ) ; A = scan . nextInt ( ) ; while ( H > 0 ) { H = H - A ; j ++ ; } System . out . println ( j ) ; } } +import java . util . Scanner ; import java . util . Arrays ; public class Main { public static void main ( String [ ] args ) { final Scanner cin = new Scanner ( System . in ) ; int n = cin . nextInt ( ) ; long [ ] arr = new long [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { arr [ i ] = cin . nextLong ( ) ; } Arrays . parallelSort ( arr ) ; if ( arr [ 0 ] == 0 ) { long a ; System . out . print ( 0 ) ; return ; } long mul = 1L ; for ( long a : arr ) { if ( mul * 1.0 * a > ( long ) 1e18 ) { System . out . print ( - 1 ) ; System . exit ( 0 ) ; } mul = mul * a ; } System . out . print ( mul > ( long ) 1e18 ? - 1 : mul ) ; } } +import java . util . Arrays ; import java . util . Map ; import java . util . Scanner ; import java . util . TreeMap ; public class Main { public static void main ( String [ ] args ) { Scanner scn = new Scanner ( System . in ) ; Map < String , Integer > tV = new TreeMap < > ( ) ; int nV = scn . nextInt ( ) ; int [ ] VList = new int [ nV ] ; for ( int i = 0 ; i < nV ; i ++ ) { String v = scn . next ( ) ; if ( ! tV . isEmpty ( ) ) { if ( tV . containsKey ( v ) ) { tV . put ( v , tV . get ( v ) + 1 ) ; } else { tV . put ( v , 1 ) ; } } else { Map . Entry < String , Integer > vote ; tV . put ( v , 1 ) ; } VList [ i ] = tV . get ( v ) ; } Arrays . sort ( VList ) ; if ( VList [ nV - 1 ] == VList [ 0 ] ) { for ( Map . Entry < String , Integer > vote : tV . entrySet ( ) ) { System . out . println ( vote . getKey ( ) . toString ( ) ) ; } } else { if ( VList [ 0 ] != VList [ nV - 1 ] ) { for ( Map . Entry < String , Integer > vote : tV . entrySet ( ) ) { if ( vote . getValue ( ) == VList [ nV - 1 ] ) { System . out . println ( vote . getKey ( ) . toString ( ) ) ; } } } } scn . close ( ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int b = Integer . parseInt ( dates2 . nextToken ( ) ) ; Scanner sc = new Scanner ( System . in ) ; int N = Integer . parseInt ( sc . nextLine ( ) ) ; StringTokenizer dates = new StringTokenizer ( sc . nextLine ( ) ) ; StringTokenizer dates2 = new StringTokenizer ( sc . nextLine ( ) ) ; int mayor = 0 ; for ( int i = 0 ; i < N ; i ++ ) { int a = Integer . parseInt ( dates . nextToken ( ) ) ; int b = Integer . parseInt ( dates2 . nextToken ( ) ) ; if ( a - b > 0 ) { mayor += a - b ; } } System . out . println ( mayor ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int m = sc . nextInt ( ) ; int [ ] [ ] b = new int [ n ] [ 3 ] ; for ( int i = 0 ; i < m ; i ++ ) { int p = sc . nextInt ( ) ; String s = sc . next ( ) ; if ( b [ p - 1 ] [ 0 ] == 0 ) { if ( " AC " . equals ( s ) ) { int i = 0 ; b [ p - 1 ] [ 0 ] = i + 1 ; } else { b [ p - 1 ] [ 1 ] ++ ; } } } int ok = 0 ; int ng = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( b [ i ] [ 0 ] > 0 ) { ok ++ ; ng += b [ i ] [ 1 ] ; } } System . out . println ( ok + " " + ng ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int i = 1 ; Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; String S = sc . next ( ) ; char Si = S . charAt ( 0 ) ; int count = 1 ; for ( int i = 1 ; i < N ; i ++ ) { if ( S . charAt ( i ) == Si ) ; else { count ++ ; Si = S . charAt ( i ) ; } } System . out . println ( count ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner input = new Scanner ( System . in ) ; int n = input . nextInt ( ) ; int [ ] level = new int [ n ] ; int count = 1 ; int min = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int i = 0 ; level [ i ] = input . nextInt ( ) ; if ( i == 0 ) { min = level [ 0 ] ; } else { if ( level [ i ] <= min ) { count ++ ; min = level [ i ] ; } } } System . out . println ( count ) ; } } +import java . io . BufferedReader ; import java . io . * ; import java . io . InputStreamReader ; import java . util . Scanner ; import java . util . StringTokenizer ; import java . util . * ; import java . math . * ; public class Main { static class FastReader { BufferedReader br ; StringTokenizer st ; public FastReader ( ) { br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; } String next ( ) { while ( st == null || ! st . hasMoreElements ( ) ) { try { PrintWriter pw = new PrintWriter ( System . out ) ; 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 ; } } public static void main ( String [ ] args ) { FastReader sc = new FastReader ( ) ; PrintWriter pw = new PrintWriter ( System . out ) ; int t = 1 ; long ans = 0 , mod = 1000000007 ; while ( t -- > 0 ) { int n = sc . nextInt ( ) , m = sc . nextInt ( ) ; pw . println ( ( n * ( n - 1 ) ) / 2 + ( m * ( m - 1 ) ) / 2 ) ; } pw . close ( ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; Integer [ ] ans = new Integer [ N ] ; for ( int n = 0 ; n < N ; n ++ ) { ans [ n ] = sc . nextInt ( ) ; } sc . close ( ) ; int sunuke = 0 ; for ( int an = 0 ; an < ans . length ; an ++ ) { if ( ans [ an ] == sunuke + 1 ) { sunuke ++ ; } } if ( sunuke == 0 ) { int an = 0 ; System . out . println ( " -1 " ) ; } else { System . out . println ( N - sunuke ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String [ ] nyu = sc . nextLine ( ) . split ( " " ) ; int num = Integer . parseInt ( nyu [ 0 ] ) ; int numnext = Integer . parseInt ( nyu [ 1 ] ) ; int numend = Integer . parseInt ( nyu [ 2 ] ) ; int count = 0 ; if ( numend - ( num - numnext ) < 0 ) { count = 0 ; } else { int count = 0 ; count = numend - ( num - numnext ) ; } System . out . println ( count ) ; } } +import java . util . * ; class Main { private static Scanner sc ; public static void main ( final String [ ] args ) { sc = new Scanner ( System . in ) ; long a = sc . nextLong ( ) , ans = 0 , num = 100 ; while ( true ) { long a = sc . nextLong ( ) , ans = 0 , num = 100 ; if ( num >= a ) { System . out . println ( ans ) ; break ; } num += num / 100 ; ans ++ ; } } } +import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int n = scan . nextInt ( ) ; String [ ] s = new String [ n ] ; int [ ] cnt = new int [ n ] ; String [ ] scheck = new String [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { s [ i ] = scan . next ( ) ; cnt [ i ] = 0 ; scheck [ i ] = " " ; } scan . close ( ) ; Arrays . sort ( s ) ; int suffix = 0 ; int max = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( i != 0 && s [ i ] . equals ( s [ i - 1 ] ) == false ) { scheck [ suffix ] = s [ i - 1 ] ; suffix += 1 ; } if ( i == n - 1 ) scheck [ suffix ] = s [ i ] ; if ( i == n - 1 && s [ i ] . equals ( s [ i - 1 ] ) == false ) scheck [ suffix ] = s [ i ] ; cnt [ suffix ] += 1 ; if ( max < cnt [ suffix ] ) max = cnt [ suffix ] ; } for ( int i = 0 ; i <= suffix ; i ++ ) { int i = 0 ; if ( cnt [ i ] == max ) System . out . println ( scheck [ i ] ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { String cards = sc . next ( ) ; Scanner sc = new Scanner ( System . in ) ; while ( true ) { String cards = sc . next ( ) ; if ( cards . equals ( " - " ) ) { break ; } int m = sc . nextInt ( ) ; for ( int i = 0 ; i < m ; i ++ ) { int count = sc . nextInt ( ) ; String move = cards . substring ( 0 , count ) ; String move2 = cards . substring ( count ) ; cards = move2 + move ; } System . out . println ( cards ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int D = sc . nextInt ( ) ; int N = sc . nextInt ( ) ; if ( N <= 99 ) { System . out . print ( N * ( int ) Math . pow ( 100 , D ) ) ; } else if ( N == 100 ) { int N = sc . nextInt ( ) ; System . out . print ( 101 * ( int ) Math . pow ( 100 , D ) ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int plus = a + b ; int minus = a - b ; int mult = a * b ; if ( plus > minus ) { if ( plus > mult ) { System . out . println ( plus ) ; } else { System . out . println ( mult ) ; } } else if ( minus > plus ) { if ( minus > mult ) { int mult = a * b ; System . out . println ( minus ) ; } else { System . out . println ( mult ) ; } } else { System . out . println ( plus ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Main mainObj = new Main ( ) ; mainObj . exec ( ) ; } public void exec ( ) { Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; sc . close ( ) ; if ( ! inRange ( a ) || ! inRange ( b ) ) { System . out . println ( - 1 ) ; return ; } System . out . println ( a * b ) ; } boolean inRange ( int a ) { if ( a >= 1 && a <= 9 ) { int a = sc . nextInt ( ) ; return true ; } else { return false ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int M = sc . nextInt ( ) ; int [ ] food = new int [ M + 1 ] ; for ( int i = 0 ; i < food . length ; i ++ ) { food [ i ] = 0 ; } for ( int i = 0 ; i < N ; i ++ ) { int i = 0 ; int K = sc . nextInt ( ) ; for ( int j = 0 ; j < K ; j ++ ) { food [ sc . nextInt ( ) ] += 1 ; } } int sum = 0 ; for ( int i = 0 ; i < food . length ; i ++ ) { if ( food [ i ] == N ) { sum ++ ; } } System . out . println ( sum ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 1 ; Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; if ( b == 1 ) { System . out . println ( 0 ) ; return ; } if ( b <= a ) { System . out . println ( 1 ) ; return ; } int sum = 0 ; for ( int i = 1 ; ; i ++ ) { sum += a ; if ( sum >= b ) { System . out . println ( i ) ; return ; } sum -= 1 ; } } } +import java . util . Scanner ; public class Main { public static int head1 = 0 ; public static int head2 = 0 ; public static int tail = 0 ; public static String [ ] queue1 = new String [ 1000000 ] ; public static int [ ] queue2 = new int [ 1000000 ] ; public static void main ( String [ ] args ) { Scanner stdIn = new Scanner ( System . in ) ; int n = stdIn . nextInt ( ) ; int q = stdIn . nextInt ( ) ; for ( int i = 0 ; i < n ; i ++ ) { String a = stdIn . next ( ) ; int b = stdIn . nextInt ( ) ; enqueue ( a , b ) ; } int time = 0 ; while ( head1 != tail ) { String a = strDequeue ( ) ; int b = intDequeue ( ) ; if ( b <= q ) { time += b ; System . out . println ( a + " " + time ) ; } else { int b = intDequeue ( ) ; time += q ; b -= q ; enqueue ( a , b ) ; } } } public static void enqueue ( String x , int y ) { queue1 [ tail ] = x ; queue2 [ tail ] = y ; tail ++ ; } public static String strDequeue ( ) { return queue1 [ head1 ++ ] ; } public static int intDequeue ( ) { return queue2 [ head2 ++ ] ; } } +import java . util . ArrayList ; import java . util . Collections ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int count = 0 ; int N = scanner . nextInt ( ) ; int X = scanner . nextInt ( ) ; ArrayList < Integer > list = new ArrayList < > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { int m = scanner . nextInt ( ) ; list . add ( m ) ; X -= m ; } Collections . sort ( list ) ; int min = list . get ( 0 ) ; for ( int x = 0 ; x <= X / min ; x ++ ) { int x = 0 ; count = x ; if ( min * x > X ) { break ; } } count += N ; System . out . println ( count ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; try ( Scanner sc = new Scanner ( System . in ) ) { int n = sc . nextInt ( ) ; int k = sc . nextInt ( ) ; String s = sc . next ( ) ; String tmp = null ; switch ( s . substring ( k - 1 , k ) ) { case " A " : tmp = " a " ; break ; case " B " : tmp = " b " ; break ; case " C " : tmp = " c " ; break ; } System . out . println ( s . substring ( 0 , k - 1 ) + tmp + s . substring ( k ) ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int K = scan . nextInt ( ) ; int A = scan . nextInt ( ) ; int B = scan . nextInt ( ) ; int cnt = 0 ; for ( int i = A ; i <= B ; i ++ ) { if ( i % K == 0 ) { cnt = cnt + 1 ; } } if ( cnt >= 1 ) { int i = A ; System . out . println ( " OK " ) ; } else { System . out . println ( " NG " ) ; } scan . close ( ) ; } } +import java . io . * ; class Main { public static void main ( String [ ] args ) throws Exception { int y = Integer . parseInt ( line [ 1 ] ) ; BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; StringBuilder sb = new StringBuilder ( ) ; while ( true ) { String [ ] line = br . readLine ( ) . split ( " " ) ; int x = Integer . parseInt ( line [ 0 ] ) ; int y = Integer . parseInt ( line [ 1 ] ) ; if ( x == 0 && y == 0 ) { break ; } else { sb . append ( Integer . toString ( x < y ? x : y ) ) . append ( " " ) . append ( Integer . toString ( x < y ? y : x ) ) . append ( " \n " ) ; } } System . out . print ( sb ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Main main = new Main ( ) ; main . run ( ) ; } public void run ( ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; int a1 = Integer . parseInt ( s . substring ( 0 , 2 ) ) ; int a2 = Integer . parseInt ( s . substring ( 2 , 4 ) ) ; boolean m1 = false ; if ( 1 <= a1 && a1 <= 12 ) { m1 = true ; } boolean m2 = false ; if ( 1 <= a2 && a2 <= 12 ) { m2 = true ; } String ans = " " ; if ( m1 && m2 ) { ans = " AMBIGUOUS " ; } else if ( m1 && ! m2 ) { ans = " MMYY " ; } else if ( ! m1 && m2 ) { ans = " YYMM " ; } else { String ans = " " ; ans = " NA " ; } System . out . println ( ans ) ; sc . close ( ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int t = sc . nextInt ( ) ; int ac = 0 , wa = 0 , tle = 0 , re = 0 ; while ( t -- > 0 ) { int ac = 0 , wa = 0 , tle = 0 , re = 0 ; String s = sc . next ( ) ; if ( s . equals ( " WA " ) ) { wa ++ ; } if ( s . equals ( " AC " ) ) { ac ++ ; } if ( s . equals ( " TLE " ) ) { tle ++ ; } if ( s . equals ( " RE " ) ) { re ++ ; } } System . out . println ( " AC x " + ac ) ; System . out . println ( " WA x " + wa ) ; System . out . println ( " TLE x " + tle ) ; System . out . println ( " RE x " + re ) ; } } +import java . util . * ; import static java . lang . Math . * ; import java . math . BigInteger ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] b = new int [ n - 1 ] ; int result = 0 ; int pre = 0 ; for ( int i = 0 ; i < n - 1 ; i ++ ) { b [ i ] = sc . nextInt ( ) ; if ( i == 0 ) result = result + b [ i ] ; if ( i > 0 ) { result = result + min ( pre , b [ i ] ) ; } if ( i == n - 2 ) result = result + b [ i ] ; pre = b [ i ] ; } System . out . println ( result ) ; } } +import java . util . * ; import javax . lang . model . util . ElementScanner6 ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; int out = 0 ; int h = 0 ; int t = s . length ( ) - 1 ; while ( h < t ) { int t = s . length ( ) - 1 ; if ( s . charAt ( h ) != s . charAt ( t ) ) { out += 1 ; } h += 1 ; t -= 1 ; } System . out . println ( out ) ; } } +import java . util . * ; import java . io . * ; class Main { public static void main ( String [ ] args ) { int r , l , m , n , q , i , j , count = 0 ; int [ ] s = new int [ 1000000 ] ; int [ ] t = new int [ 1000000 ] ; Scanner scan = new Scanner ( System . in ) ; n = scan . nextInt ( ) ; for ( i = 0 ; i < n ; i ++ ) { s [ i ] = scan . nextInt ( ) ; } q = scan . nextInt ( ) ; for ( j = 0 ; j < q ; j ++ ) { t [ j ] = scan . nextInt ( ) ; } for ( j = 0 ; j < q ; j ++ ) { r = n ; l = 0 ; m = n / 2 ; while ( true ) { if ( s [ m ] == t [ j ] ) { count ++ ; break ; } if ( m == l ) { break ; } if ( s [ m ] > t [ j ] ) { Scanner scan = new Scanner ( System . in ) ; r = m ; m = ( r + l ) / 2 ; } if ( s [ m ] < t [ j ] ) { l = m + 1 ; m = ( r + l ) / 2 ; } } } System . out . println ( count ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long k = sc . nextLong ( ) ; int n = sc . nextInt ( ) ; long [ ] a = new long [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = sc . nextLong ( ) ; } Arrays . sort ( a ) ; long d = k + a [ 0 ] - a [ n - 1 ] ; for ( int i = 1 ; i < n ; i ++ ) { int i = 1 ; if ( d < a [ i ] - a [ i - 1 ] ) { d = a [ i ] - a [ i - 1 ] ; } } System . out . println ( k - d ) ; } } +import java . io . IOException ; import java . util . ArrayList ; import java . util . Scanner ; class Main { public static void main ( String [ ] args ) throws NumberFormatException , IOException { Scanner scan = new Scanner ( System . in ) ; ArrayList < Integer > NN = new ArrayList < Integer > ( ) ; ArrayList < Integer > XX = new ArrayList < Integer > ( ) ; int n = 1 ; int x = 1 ; int kumi = 0 ; while ( n != 0 || x != 0 ) { n = scan . nextInt ( ) ; x = scan . nextInt ( ) ; NN . add ( n ) ; XX . add ( x ) ; } for ( int i = 0 ; i < NN . size ( ) - 1 ; i ++ ) { kumi = 0 ; for ( int i1 = 0 ; i1 < NN . get ( i ) ; i1 ++ ) { for ( int i2 = 0 ; i2 < NN . get ( i ) ; i2 ++ ) { for ( int i3 = 0 ; i3 < NN . get ( i ) ; i3 ++ ) { int N3 = i3 + 1 ; int N1 = i1 + 1 ; int N2 = i2 + 1 ; int N3 = i3 + 1 ; if ( N1 == N2 || N2 == N3 || N3 == N1 ) { } else { if ( N1 + N2 + N3 == XX . get ( i ) ) { kumi += 1 ; } } } } } System . out . println ( kumi / 6 ) ; } } } +import java . util . * ; import java . io . * ; public class Main { static Scanner inp = new Scanner ( System . in ) ; static PrintWriter out = new PrintWriter ( System . out ) ; public static void main ( String [ ] args ) { Main g = new Main ( ) ; g . main ( ) ; out . close ( ) ; } void main ( ) { String s = inp . next ( ) ; String t = inp . next ( ) ; int n = s . length ( ) ; int m = t . length ( ) ; int gg = m ; for ( int i = 0 ; i <= n - m ; i ++ ) { int j = 0 ; int c = m ; for ( int j = 0 ; j < m ; j ++ ) { if ( s . charAt ( i + j ) == t . charAt ( j ) ) c -- ; } gg = Math . min ( gg , c ) ; } System . out . println ( gg ) ; } } +import java . util . * ; class Main { Scanner sc ; Main ( ) { sc = new Scanner ( System . in ) ; } void calc ( ) { int A = sc . nextInt ( ) ; int B = sc . nextInt ( ) ; if ( A > 9 || B > 9 ) System . out . println ( - 1 ) ; else System . out . println ( A * B ) ; } public static void main ( String [ ] args ) { new Main ( ) . calc ( ) ; } } +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 sum = a ; int ans = 1 ; while ( sum < b ) { int ans = 1 ; ans ++ ; sum += a - 1 ; } if ( b == 1 ) ans = 0 ; System . out . print ( ans ) ; } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { int sum = 0 ; Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int t = sc . nextInt ( ) ; int i = 1 ; int sum = 0 ; while ( a * i <= t ) { sum += b ; i += 1 ; } System . out . println ( sum ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int sum = 1 ; Scanner sc = new Scanner ( System . in ) ; int D = sc . nextInt ( ) ; int N = sc . nextInt ( ) ; int sum = 1 ; for ( int i = 0 ; i < D ; i ++ ) { sum = sum * 100 ; } if ( N == 100 ) { System . out . println ( 101 * sum ) ; return ; } System . out . println ( N * sum ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = Integer . parseInt ( sc . next ( ) ) ; Integer [ ] d1 = new Integer [ n ] ; Integer [ ] d2 = new Integer [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { int i = 0 ; d1 [ i ] = Integer . parseInt ( sc . next ( ) ) ; d2 [ i ] = Integer . parseInt ( sc . next ( ) ) ; } sc . close ( ) ; boolean judge = false ; int renzoku = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( d1 [ i ] == d2 [ i ] ) { renzoku ++ ; } else { renzoku = 0 ; } if ( renzoku == 3 ) { judge = true ; break ; } } String result = judge ? " Yes " : " No " ; System . out . println ( result ) ; } } +import java . util . Scanner ; import java . util . regex . * ; class Main { public static void main ( String [ ] args ) { Scanner stdin = new Scanner ( System . in ) . useDelimiter ( " [ \t , \n ] " ) ; int n = stdin . nextInt ( ) ; int line = stdin . nextInt ( ) ; int [ ] nums = new int [ n + 1 ] ; for ( int i = 1 ; i <= n ; i ++ ) { nums [ i ] = i ; } stdin . nextLine ( ) ; for ( int i = 0 ; i < line ; i ++ ) { int sw1 = stdin . nextInt ( ) ; int sw2 = stdin . nextInt ( ) ; int temp = nums [ sw1 ] ; nums [ sw1 ] = nums [ sw2 ] ; nums [ sw2 ] = temp ; } for ( int i = 1 ; i <= n ; i ++ ) { int i = 1 ; System . out . println ( nums [ i ] ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int A = scan . nextInt ( ) ; int B = scan . nextInt ( ) ; int f = 0 ; for ( int price = B * 10 ; price < ( B + 1 ) * 10 ; price ++ ) { if ( ( int ) ( ( double ) price * 0.08 + 0.01 ) == A ) { int price = B * 10 ; System . out . println ( price ) ; f ++ ; break ; } } if ( f == 0 ) { System . out . println ( - 1 ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; long sum = 0 ; while ( s . length ( ) > 0 ) { long sum = 0 ; sum += Integer . parseInt ( s . substring ( 0 , 1 ) ) ; s = s . substring ( 1 ) ; } System . out . println ( sum % 9 == 0 ? " Yes " : " No " ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int sum = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { int sum = 0 ; int sumOfDigits = findSumOfDigits ( i ) ; if ( a <= sumOfDigits && sumOfDigits <= b ) { sum += i ; } } System . out . println ( sum ) ; } public static int findSumOfDigits ( int num ) { int sum = 0 ; while ( num > 0 ) { sum += num % 10 ; num /= 10 ; } return sum ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; int red = 0 ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { int i = 0 ; if ( '0' == s . charAt ( i ) ) red ++ ; } System . out . println ( 2 * Math . min ( s . length ( ) - red , red ) ) ; } } +import java . util . Scanner ; import java . util . stream . IntStream ; public class Main { public static void main ( String [ ] args ) { int max = Integer . MIN_VALUE ; final Scanner sc = new Scanner ( System . in ) ; final int N = sc . nextInt ( ) ; int sum = 0 ; int max = Integer . MIN_VALUE ; for ( int i = 0 ; i < N ; i ++ ) { final int L = sc . nextInt ( ) ; max = Math . max ( max , L ) ; sum += L ; } System . out . println ( max * 2 < sum ? " Yes " : " No " ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = Integer . parseInt ( sc . next ( ) ) ; int L = Integer . parseInt ( sc . next ( ) ) ; int [ ] appleValue = new int [ N ] ; int sum = 0 ; int a = 0 ; int min = 9999 ; for ( int i = 0 ; i < N ; i ++ ) { int value = L + i ; int value = L + i ; appleValue [ i ] = value ; sum += appleValue [ i ] ; if ( min > Math . abs ( value ) ) { min = Math . abs ( value ) ; a = value ; } } System . out . println ( sum - a ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int result = 0 ; int ahead ; int current = 100000 ; for ( int i = 0 ; i < N - 1 ; i ++ ) { int current = 100000 ; ahead = current ; current = sc . nextInt ( ) ; result += Math . min ( ahead , current ) ; } result += current ; System . out . println ( result ) ; } } +import java . util . ArrayList ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int n = scan . nextInt ( ) ; int ans = 0 ; int b = 1 ; ArrayList < Integer > list = new ArrayList ( ) ; while ( n > 0 ) { list . add ( n % 10 ) ; n /= 10 ; } for ( int i = 0 ; i < 3 ; i ++ ) { int i = 0 ; if ( list . get ( i ) == 9 ) { ans += 1 * b ; } else if ( list . get ( i ) == 1 ) { ans += 9 * b ; } b *= 10 ; } System . out . println ( ans ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) throws Exception { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] array = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { array [ i ] = sc . nextInt ( ) ; } int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { while ( true ) { int i = 0 ; if ( array [ i ] % 2 == 0 ) { array [ i ] /= 2 ; ans ++ ; } else { break ; } } } 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 [ ] arr = new int [ n + 1 ] ; arr [ 0 ] = - 1 ; for ( int i = 1 ; i < n + 1 ; i ++ ) { int i = 1 ; arr [ i ] = sc . nextInt ( ) ; } String ans = " Yes " ; for ( int i = 1 ; i < n ; i ++ ) { if ( arr [ i ] <= arr [ i + 1 ] - 1 ) { arr [ i + 1 ] -- ; } else if ( arr [ i ] <= arr [ i + 1 ] ) { continue ; } else { ans = " No " ; break ; } } System . out . println ( ans ) ; } } +import java . util . Scanner ; public class Main { public static void debug ( String str ) { boolean debug = false ; if ( debug == false ) { return ; } System . out . println ( str ) ; } public static void main ( String [ ] args ) { int N ; int A ; int B ; try ( Scanner sc = new Scanner ( System . in ) ) { Scanner sc = new Scanner ( System . in ) ; N = sc . nextInt ( ) ; A = sc . nextInt ( ) ; B = sc . nextInt ( ) ; } int res = N * A < B ? N * A : B ; System . out . println ( res ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws IOException { try ( BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ) { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int in = Integer . parseInt ( br . readLine ( ) ) ; System . out . println ( in * 2 * Math . PI ) ; } } } +import java . io . * ; import java . util . * ; class Main { public static void main ( String [ ] args ) throws IOException { int a = 0 ; int b = 0 ; int c = 0 ; int i = 0 ; BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String str = br . readLine ( ) ; String delimiter = " " ; StringTokenizer stringTokenizer = new StringTokenizer ( str , delimiter ) ; while ( stringTokenizer . hasMoreTokens ( ) ) { StringTokenizer stringTokenizer = new StringTokenizer ( str , delimiter ) ; String current = stringTokenizer . nextToken ( ) ; if ( i == 0 ) a = Integer . parseInt ( current ) ; if ( i == 1 ) b = Integer . parseInt ( current ) ; if ( i == 2 ) c = Integer . parseInt ( current ) ; i ++ ; } if ( a < b && b < c ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } } +import java . util . Arrays ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; try ( Scanner sc = new Scanner ( System . in ) ) { int n = sc . nextInt ( ) ; int [ ] S = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { S [ i ] = sc . nextInt ( ) ; } int q = sc . nextInt ( ) ; int [ ] T = new int [ q ] ; for ( int i = 0 ; i < q ; i ++ ) { T [ i ] = sc . nextInt ( ) ; } int C = 0 ; for ( int i = 0 ; i < q ; i ++ ) { if ( Arrays . binarySearch ( S , T [ i ] ) >= 0 ) { C ++ ; } } System . out . println ( C ) ; } } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String [ ] lines = br . readLine ( ) . split ( " " ) ; int n = Integer . parseInt ( lines [ 0 ] ) ; int m = Integer . parseInt ( lines [ 1 ] ) ; int [ ] rowSum = new int [ m ] ; for ( int i = 0 ; i < n ; i ++ ) { lines = br . readLine ( ) . split ( " " ) ; int columnSum = 0 ; for ( int j = 0 ; j < m ; j ++ ) { int i = 0 ; int e = Integer . parseInt ( lines [ j ] ) ; columnSum += e ; rowSum [ j ] += e ; System . out . print ( e + " " ) ; } System . out . println ( columnSum ) ; } int totalSum = 0 ; for ( int i = 0 ; i < m ; i ++ ) { totalSum += rowSum [ i ] ; System . out . print ( rowSum [ i ] + " " ) ; } System . out . println ( totalSum ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = Integer . parseInt ( sc . next ( ) ) ; int [ ] numList = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { int j = i + 1 ; numList [ i ] = Integer . parseInt ( sc . next ( ) ) ; } int r = 0 ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = i + 1 ; j < N ; j ++ ) { r += numList [ i ] * numList [ j ] ; } } System . out . println ( r ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int y = scan . nextInt ( ) ; Scanner scan = new Scanner ( System . in ) ; while ( scan . hasNext ( ) ) { int x = scan . nextInt ( ) ; int y = scan . nextInt ( ) ; while ( x != 0 && y != 0 ) { int t = y ; y = x ; x = t % x ; } System . out . println ( ( x == 0 ) ? y : x ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { char c = S . charAt ( i ) ; Scanner input = new Scanner ( System . in ) ; String S = input . next ( ) ; long K = input . nextLong ( ) ; String ans = " " ; double days = 5.0 * Math . pow ( 10 , 15 ) ; for ( int i = 0 ; i < S . length ( ) ; i ++ ) { char c = S . charAt ( i ) ; int n = Character . getNumericValue ( c ) ; K -= ( long ) Math . pow ( n , days ) ; if ( K <= 0 ) { System . out . println ( c ) ; return ; } } } } +import java . util . Scanner ; import java . lang . * ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; String input = scanner . nextLine ( ) ; String [ ] inputs = input . split ( " " ) ; int P = Integer . parseInt ( inputs [ 0 ] ) ; int Q = Integer . parseInt ( inputs [ 1 ] ) ; int R = Integer . parseInt ( inputs [ 2 ] ) ; int min1 = Math . min ( P , Q ) ; int max1 = Math . max ( P , Q ) ; if ( max1 <= R ) { int max1 = Math . max ( P , Q ) ; System . out . println ( min1 + max1 ) ; } else { System . out . println ( min1 + R ) ; } scanner . close ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int [ ] list ; int length ; int primes = 0 ; Scanner keyboard = new Scanner ( System . in ) ; length = keyboard . nextInt ( ) ; list = new int [ length ] ; for ( int i = 0 ; i < length ; i ++ ) { list [ i ] = keyboard . nextInt ( ) ; } for ( int i = 0 ; i < length ; i ++ ) { if ( isPrime ( list [ i ] ) ) primes ++ ; } System . out . println ( primes ) ; } public static boolean isPrime ( int a ) { if ( a == 2 || a == 3 || a == 5 || a == 7 ) { return true ; } if ( a % 2 == 0 ) { return false ; } for ( int j = 3 ; j <= Math . sqrt ( a ) ; j ++ ) { if ( a % j == 0 ) { int j = 3 ; return false ; } } return true ; } } +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 c = sc . nextInt ( ) ; int k = sc . nextInt ( ) ; if ( a <= b ) { if ( b <= c ) { System . out . println ( ( int ) ( Math . pow ( 2 , k ) * c + a + b ) ) ; } else { System . out . println ( ( int ) ( Math . pow ( 2 , k ) * b + a + c ) ) ; } } else { if ( a <= c ) { int k = sc . nextInt ( ) ; System . out . println ( ( int ) ( Math . pow ( 2 , k ) * c + a + b ) ) ; } else { System . out . println ( ( int ) ( Math . pow ( 2 , k ) * a + b + c ) ) ; } } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int X = sc . nextInt ( ) ; int Y = sc . nextInt ( ) ; if ( Y % 2 == 1 ) { System . out . println ( " No " ) ; } else { int y = Y / 2 ; if ( y - X < 0 ) { int Y = sc . nextInt ( ) ; System . out . println ( " No " ) ; } else if ( y - 2 * X > 0 ) { System . out . println ( " No " ) ; } else { System . out . println ( " Yes " ) ; } } } } +import java . util . * ; import java . lang . Math ; public class Main { public static void main ( String [ ] args ) { int count2 = 0 ; Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int count = 0 ; int count2 = 0 ; if ( a == 1 ) count -- ; if ( a == 2 ) count -= 2 ; while ( count2 < 2 ) { count ++ ; if ( a == 4 ) count2 ++ ; if ( a % 2 == 0 ) a /= 2 ; else a = a * 3 + 1 ; } System . out . println ( count ) ; } } +import java . util . Scanner ; import java . util . List ; import java . util . ArrayList ; import java . util . Map ; import java . util . HashMap ; class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int n = scanner . nextInt ( ) ; List < String > list = new ArrayList < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { String val ; list . add ( scanner . next ( ) ) ; } scanner . close ( ) ; Map < String , Integer > map = new HashMap < > ( ) ; for ( String val : list ) { map . put ( val , 0 ) ; } System . out . println ( map . size ( ) ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { @ SuppressWarnings ( " resource " ) Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int c = sc . nextInt ( ) ; int k = sc . nextInt ( ) ; if ( k <= a ) { int k = sc . nextInt ( ) ; System . out . println ( k ) ; return ; } if ( k <= a + b ) { System . out . println ( a ) ; return ; } System . out . println ( a - ( k - a - b ) ) ; } } +import java . util . ArrayDeque ; import java . util . Queue ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int q = sc . nextInt ( ) ; Queue < Process > Q = new ArrayDeque < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { Q . add ( new Process ( sc . next ( ) , sc . nextInt ( ) ) ) ; } int t = 0 ; while ( ! Q . isEmpty ( ) ) { Process p = Q . poll ( ) ; if ( p . time <= q ) { t += p . time ; System . out . println ( p . name + " " + t ) ; } else { t += q ; p . time -= q ; Q . add ( p ) ; } } sc . close ( ) ; } static class Process { String name ; int time ; public Process ( String name , int time ) { this . name = name ; this . time = time ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int tmp , remainder ; int [ ] next = { 0 , 0 } ; Scanner in = new Scanner ( System . in ) ; next [ 0 ] = Integer . parseInt ( in . next ( ) ) ; next [ 1 ] = Integer . parseInt ( in . next ( ) ) ; if ( next [ 0 ] < next [ 1 ] ) { tmp = next [ 1 ] ; next [ 1 ] = next [ 0 ] ; next [ 0 ] = tmp ; } int i = 1 ; while ( i == 1 ) { remainder = gcd ( next [ 0 ] , next [ 1 ] ) ; if ( remainder == 0 ) { System . out . println ( next [ 1 ] ) ; System . exit ( 0 ) ; } next [ 0 ] = remainder ; remainder = gcd ( next [ 1 ] , next [ 0 ] ) ; if ( remainder == 0 ) { int remainder = big % small ; System . out . println ( next [ 0 ] ) ; System . exit ( 0 ) ; } next [ 1 ] = remainder ; } } public static int gcd ( int big , int small ) { int remainder = big % small ; return remainder ; } } +import java . util . ArrayList ; import java . util . List ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; List < Integer > x = new ArrayList < > ( ) ; for ( int i = 0 ; i < 5 ; i ++ ) { x . add ( sc . nextInt ( ) ) ; } for ( Integer i : x ) { if ( i == 0 ) { Integer i ; System . out . println ( x . indexOf ( i ) + 1 ) ; } } sc . close ( ) ; } } +import java . util . Comparator ; import java . util . HashSet ; import java . util . List ; import java . util . Scanner ; import java . util . Set ; import java . util . stream . Collectors ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; long n = sc . nextLong ( ) ; List < Long > divisor = divisor ( n ) ; long min = 1000000000001L ; for ( Long elm : divisor ) { min = Math . min ( min , elm + ( n / elm ) ) ; } long ans = min - 2 ; System . out . println ( ans ) ; } static List < Long > divisor ( long n ) { Set < Long > ret = new HashSet < > ( ) ; for ( long i = 1 ; i * i <= n ; i ++ ) { if ( n % i == 0 ) { long i = 1 ; ret . add ( i ) ; if ( i != n / i ) ret . add ( n / i ) ; } } return ret . stream ( ) . sorted ( Comparator . naturalOrder ( ) ) . collect ( Collectors . toList ( ) ) ; } } +import java . util . Scanner ; import java . util . Arrays ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] p = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { p [ i ] = sc . nextInt ( ) ; } int min = n + 1 ; int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( p [ i ] < min ) { min = p [ i ] ; ans ++ ; } } System . out . println ( ans ) ; } } +public class Main { public static void main ( String [ ] args ) { java . util . Scanner scan = new java . util . Scanner ( System . in ) ; int a , b , c , d , e ; long f ; a = scan . nextInt ( ) ; d = - 1000000 ; e = 1000000 ; f = 0 ; if ( 0 <= a && a <= 10000 ) { long f ; for ( b = 1 ; b <= a ; b ++ ) { c = scan . nextInt ( ) ; if ( - 1000000 <= c && c <= 1000000 ) { if ( c >= d ) { d = c ; } if ( c <= e ) { e = c ; } f += c ; } } } System . out . print ( e + " " ) ; System . out . print ( d + " " ) ; System . out . println ( f ) ; } } +import java . util . Scanner ; import java . util . ArrayList ; import java . util . Collections ; import java . util . Iterator ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; ArrayList < String > list = new ArrayList < > ( ) ; ArrayList < String > anslist = new ArrayList < > ( ) ; int n = sc . nextInt ( ) ; String [ ] a = new String [ n ] ; int max = 1 ; int count = 1 ; for ( int i = 0 ; i < n ; i ++ ) { Iterator < String > it = anslist . iterator ( ) ; a [ i ] = sc . next ( ) ; list . add ( a [ i ] ) ; } Collections . sort ( list ) ; for ( int j = 1 ; j < n ; j ++ ) { if ( list . get ( j - 1 ) . equals ( list . get ( j ) ) ) { count ++ ; if ( j == n - 1 ) max = Math . max ( max , count ) ; } else { max = Math . max ( max , count ) ; count = 1 ; } } for ( int x = 0 ; x < n - max + 1 ; x ++ ) { if ( list . get ( x + max - 1 ) . equals ( list . get ( x ) ) ) { anslist . add ( list . get ( x ) ) ; } } Iterator < String > it = anslist . iterator ( ) ; while ( it . hasNext ( ) ) { System . out . println ( it . next ( ) ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int k = sc . nextInt ( ) ; int s = sc . nextInt ( ) ; int ans = 0 ; aLoop : for ( int a = 0 ; a <= k ; a ++ ) { bLoop : for ( int b = 0 ; b <= k ; b ++ ) { int abSum = a + b ; if ( abSum > s ) { int b = 0 ; continue aLoop ; } else if ( s - abSum <= k ) { ans ++ ; } } } System . out . println ( ans ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; String S = sc . next ( ) ; String T = sc . next ( ) ; String [ ] Sarr = new String [ S . length ( ) ] ; for ( int i = 0 ; i < S . length ( ) ; i ++ ) { Sarr [ i ] = S . substring ( i ) + S . substring ( 0 , i ) ; } boolean result = false ; for ( int i = 0 ; i < S . length ( ) ; i ++ ) { if ( Sarr [ i ] . equals ( T ) ) { result = true ; break ; } } System . out . println ( result ? " Yes " : " No " ) ; } } +import java . util . Scanner ; public class Main { public static void swap ( int [ ] A , int a , int b ) { int s = A [ a ] ; A [ a ] = A [ b ] ; A [ b ] = s ; } public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int cnt = 0 ; int [ ] a = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = sc . nextInt ( ) ; } for ( int i = 0 ; i < n - 1 ; i ++ ) { int min = i ; for ( int j = i + 1 ; j < n ; j ++ ) { int i = 0 ; if ( a [ j ] < a [ min ] ) min = j ; } if ( i != min ) { swap ( a , i , min ) ; cnt ++ ; } } for ( int i = 0 ; i < n - 1 ; i ++ ) System . out . printf ( " %d " , a [ i ] ) ; System . out . println ( a [ n - 1 ] ) ; System . out . println ( cnt ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { char c ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; String s = sc . next ( ) ; char [ ] tmp = s . toCharArray ( ) ; for ( int i = 0 ; i < tmp . length ; i ++ ) { int j = n ; while ( j > 0 ) { if ( tmp [ i ] == 'Z' ) { tmp [ i ] = 'A' ; } else { tmp [ i ] = ( char ) ( tmp [ i ] + 1 ) ; } j -- ; } } for ( char c : tmp ) { System . out . print ( c ) ; } } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . ArrayList ; import java . util . List ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; List < String > list = new ArrayList < > ( ) ; String data ; while ( ( data = br . readLine ( ) ) != null ) { list . add ( data ) ; } int n = Integer . parseInt ( list . get ( 0 ) ) ; String s = list . get ( 1 ) ; br . close ( ) ; int count = 0 ; int size = n ; for ( int i = 0 ; i < size ; i ++ ) { if ( size - i >= 3 ) { int i = 0 ; String tmp = s . substring ( i , i + 3 ) ; if ( " ABC " . equals ( tmp ) ) { count ++ ; } } else { break ; } } System . out . println ( count ) ; } } +import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . Arrays ; import java . util . Comparator ; import java . util . PriorityQueue ; import java . util . regex . Pattern ; public class Main { public static void main ( String [ ] args ) throws IOException { BufferedReader stdin = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String s = stdin . readLine ( ) ; String t = ok ( s ) ? " Yes " : " No " ; System . out . println ( t ) ; } public static boolean ok ( String s ) { for ( int i = 0 ; i < s . length ( ) ; i ++ ) { char ch = s . charAt ( i ) ; char ch = s . charAt ( i ) ; if ( i % 2 == 0 ) { if ( ch == 'L' ) return false ; } else { if ( ch == 'R' ) return false ; } } return true ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String S = sc . next ( ) ; String S1 = S . substring ( 0 , 1 ) ; String S2 = S . substring ( 1 , 2 ) ; String S3 = S . substring ( 2 , 3 ) ; String S4 = S . substring ( 3 , 4 ) ; String kekka = " Good " ; if ( S1 . equals ( S2 ) || S2 . equals ( S3 ) || S3 . equals ( S4 ) ) { String kekka = " Good " ; kekka = " Bad " ; } System . out . println ( kekka ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner s = new Scanner ( System . in ) ; int A = s . nextInt ( ) ; int B = s . nextInt ( ) ; if ( 0 < A && A < 10 && 0 < B && B < 10 ) { System . out . println ( A * B ) ; } else { int B = s . nextInt ( ) ; System . out . println ( - 1 ) ; } s . close ( ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; boolean ok = false ; LOOP : for ( int i = 0 ; i <= n ; i += 4 ) { for ( int j = 0 ; i + j <= n ; j += 7 ) { int j = 0 ; if ( i + j == n ) { ok = true ; break LOOP ; } } } if ( ok ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } sc . close ( ) ; } } +import java . util . ArrayList ; import java . util . List ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; String input = scanner . nextLine ( ) ; Iroha solver = new Iroha ( ) ; System . out . println ( solver . anotherSolve ( input ) ) ; } static class Iroha { public String anotherSolve ( String input ) { List < Integer > inputList = new ArrayList < Integer > ( ) ; int five = 0 ; int seven = 0 ; for ( String s : input . split ( " " ) ) { if ( Integer . parseInt ( s ) == 5 ) { five ++ ; } else if ( Integer . parseInt ( s ) == 7 ) { seven ++ ; } } if ( five == 2 && seven == 1 ) { String s ; return " YES " ; } else { return " NO " ; } } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int i = n ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int ans = 0 ; for ( int i = n ; i <= 999 ; i ++ ) { String s = String . valueOf ( i ) ; if ( ( s . charAt ( 0 ) == s . charAt ( 1 ) ) && ( s . charAt ( 1 ) == s . charAt ( 2 ) ) ) { ans = i ; break ; } } 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 n = N ; int m , s = 0 ; for ( int i = 10 ; i > 0 ; i -- ) { int i = 10 ; m = n / ( int ) ( Math . pow ( 10 , i ) ) ; s = s + m ; if ( m != 0 ) { n = n - ( int ) ( Math . pow ( 10 , i ) ) * m ; } } s = s + n % 10 ; if ( N % s == 0 ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int loop = sc . nextInt ( ) ; int [ ] array = new int [ loop ] ; long count = 0 ; for ( int i = 0 ; i < loop ; i ++ ) { int next = array [ i + 1 ] ; array [ i ] = sc . nextInt ( ) ; } for ( int i = 0 ; i < ( loop - 1 ) ; i ++ ) { int temp = array [ i ] ; int next = array [ i + 1 ] ; if ( next < temp ) { count += ( temp - next ) ; array [ i + 1 ] = temp ; } } System . out . println ( count ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int max = - 1 ; Scanner in = new Scanner ( System . in ) ; int min = 124 ; int max = - 1 ; for ( int i = 0 ; i < 5 ; i ++ ) { int n = in . nextInt ( ) ; if ( n < min ) min = n ; if ( n > max ) max = n ; } int k = in . nextInt ( ) ; System . out . println ( ( max - min <= k ) ? " Yay! " : " :( " ) ; in . close ( ) ; } } +import java . util . ArrayList ; import java . util . Scanner ; public class Main { static int getMorePrime ( int n ) { int n = sc . nextInt ( ) ; if ( n == 2 ) return n ; ArrayList < Integer > primes = new ArrayList < Integer > ( ) ; primes . add ( 2 ) ; int i = 2 ; while ( true ) { for ( int j = 0 ; j < primes . size ( ) ; j ++ ) if ( i % primes . get ( j ) == 0 ) { ++ i ; j = 0 ; } if ( i >= n ) return i ; primes . add ( i ) ; ++ i ; } } public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; System . out . println ( getMorePrime ( n ) ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { int n , point1 = 0 , point2 = 0 ; String card1 , card2 ; Scanner sc = new Scanner ( System . in ) ; n = sc . nextInt ( ) ; for ( int i = 0 ; i < n ; i ++ ) { card1 = sc . next ( ) ; card2 = sc . next ( ) ; if ( card2 . compareTo ( card1 ) < 0 ) { point1 += 3 ; } else if ( card1 . equals ( card2 ) ) { point1 ++ ; point2 ++ ; } else { Scanner sc = new Scanner ( System . in ) ; point2 += 3 ; } } System . out . println ( point1 + " " + point2 ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int [ ] ary = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { int i = 0 ; ary [ i ] = sc . nextInt ( ) ; } boolean flag = true ; int numSwap = 0 ; while ( flag ) { flag = false ; for ( int i = N - 1 ; i >= 1 ; i -- ) { if ( ary [ i ] < ary [ i - 1 ] ) { int temp = ary [ i ] ; ary [ i ] = ary [ i - 1 ] ; ary [ i - 1 ] = temp ; numSwap ++ ; flag = true ; } } } for ( int i = 0 ; i < N ; i ++ ) { System . out . print ( ary [ i ] ) ; if ( i < N - 1 ) { System . out . print ( " " ) ; } } System . out . println ( " " ) ; System . out . println ( numSwap ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int tmp = i ; int n , a , b , digitsSum = 0 , totalSum = 0 ; Scanner sc = new Scanner ( System . in ) ; n = sc . nextInt ( ) ; a = sc . nextInt ( ) ; b = sc . nextInt ( ) ; for ( int i = 1 ; i <= n ; i ++ ) { int tmp = i ; for ( int j = 0 ; j < 5 ; j ++ ) { digitsSum += tmp % 10 ; tmp /= 10 ; } if ( a <= digitsSum && digitsSum <= b ) totalSum += i ; digitsSum = 0 ; } System . out . println ( totalSum ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = Integer . parseInt ( sc . next ( ) ) ; int [ ] a = new int [ n ] ; int [ ] c = new int [ n ] ; int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = Integer . parseInt ( sc . next ( ) ) ; } for ( int i = 0 ; i < n ; i ++ ) { ans += Integer . parseInt ( sc . next ( ) ) ; } for ( int i = 1 ; i < n ; i ++ ) { int i = 0 ; c [ i ] = Integer . parseInt ( sc . next ( ) ) ; } for ( int i = 0 ; i < n - 1 ; i ++ ) { if ( a [ i ] + 1 == a [ i + 1 ] ) { ans += c [ a [ i ] ] ; } } System . out . println ( ans ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { int cnt = 0 ; Scanner sc = new Scanner ( System . in ) ; String w = sc . next ( ) ; int i , j , flag = 0 ; for ( i = 0 ; i < w . length ( ) ; i ++ ) { int cnt = 0 ; for ( j = 0 ; j < w . length ( ) ; j ++ ) { if ( w . charAt ( i ) == w . charAt ( j ) ) { cnt ++ ; } } if ( cnt % 2 != 0 ) { flag = 1 ; System . out . println ( " No " ) ; break ; } } if ( flag == 0 ) System . out . println ( " Yes " ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int [ ] sum = new int [ 101 ] ; int [ ] [ ] h = new int [ 101 ] [ 101 ] ; int [ ] m = new int [ 101 ] ; int a = scan . nextInt ( ) ; for ( int d = 0 ; d < a ; d ++ ) { sum [ d ] = 0 ; } int b = scan . nextInt ( ) ; for ( int c = 0 ; c < a ; c ++ ) { int c = 0 ; for ( int d = 0 ; d < b ; d ++ ) { h [ c ] [ d ] = scan . nextInt ( ) ; } } for ( int d = 0 ; d < b ; d ++ ) { m [ d ] = scan . nextInt ( ) ; } for ( int c = 0 ; c < a ; c ++ ) { for ( int d = 0 ; d < b ; d ++ ) { sum [ c ] += h [ c ] [ d ] * m [ d ] ; } } for ( int c = 0 ; c < a ; c ++ ) { System . out . println ( sum [ c ] ) ; } } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; if ( a > b ) { int b = sc . nextInt ( ) ; System . out . println ( 2 * a - 1 ) ; } else if ( a == b ) { System . out . println ( 2 * a ) ; } else { System . out . println ( 2 * b - 1 ) ; } } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int [ ] [ ] c = new int [ 3 ] [ 3 ] ; for ( int i = 0 ; i < 3 ; i ++ ) { for ( int j = 0 ; j < 3 ; j ++ ) { c [ i ] [ j ] = sc . nextInt ( ) ; } } int [ ] [ ] d = new int [ 3 ] [ 2 ] ; for ( int i = 0 ; i < 3 ; i ++ ) { for ( int j = 0 ; j < 2 ; j ++ ) { int j = 0 ; d [ i ] [ j ] = c [ i ] [ j + 1 ] - c [ i ] [ j ] ; } } if ( d [ 0 ] [ 0 ] == d [ 1 ] [ 0 ] && d [ 1 ] [ 0 ] == d [ 2 ] [ 0 ] && d [ 0 ] [ 1 ] == d [ 1 ] [ 1 ] && d [ 1 ] [ 1 ] == d [ 2 ] [ 1 ] ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int n = scan . nextInt ( ) ; String s = Integer . toString ( n ) ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { int i = 0 ; if ( s . charAt ( i ) == '7' ) { System . out . println ( " Yes " ) ; return ; } } System . out . println ( " No " ) ; } } +import java . util . HashMap ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; HashMap < String , String > map = new HashMap < String , String > ( ) ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; String str = sc . nextLine ( ) ; for ( int i = 0 ; i < n ; i ++ ) { map . put ( sc . nextLine ( ) , " " ) ; } sc . close ( ) ; System . out . println ( map . size ( ) ) ; } } +import java . io . * ; import java . util . Scanner ; import java . util . Arrays ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; if ( N % 2 == 0 ) { System . out . println ( " 0.5000000000 " ) ; } else { int N = sc . nextInt ( ) ; int s = N / 2 + 1 ; double ans = ( double ) s / N ; System . out . println ( String . format ( " %.10f " , ans ) ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int m = sc . nextInt ( ) ; int count1 = 0 ; int count2 = 0 ; if ( n >= 2 ) { count1 = ( n * ( n - 1 ) ) / 2 ; } if ( m >= 2 ) { int count2 = 0 ; count2 = ( m * ( m - 1 ) ) / 2 ; } System . out . println ( count1 + count2 ) ; } } +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 ) ; TaskA solver = new TaskA ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class TaskA { public void solve ( int testNumber , Scanner in , PrintWriter out ) { PrintWriter out = new PrintWriter ( outputStream ) ; String s = in . next ( ) ; String t = in . next ( ) ; out . println ( s . equals ( t . substring ( 0 , s . length ( ) ) ) ? " Yes " : " No " ) ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int m = sc . nextInt ( ) ; Integer [ ] array = new Integer [ m ] ; for ( int i = 0 ; m > i ; i ++ ) { array [ i ] = 0 ; } for ( int i = 0 ; n > i ; i ++ ) { int k = sc . nextInt ( ) ; for ( int j = 0 ; k > j ; j ++ ) { int a = sc . nextInt ( ) ; array [ a - 1 ] = array [ a - 1 ] + 1 ; } } int count = 0 ; for ( int i = 0 ; m > i ; i ++ ) { if ( array [ i ] > n - 1 ) count ++ ; } System . out . println ( count ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int A = Integer . parseInt ( sc . next ( ) ) ; int B = Integer . parseInt ( sc . next ( ) ) ; int C = Integer . parseInt ( sc . next ( ) ) ; int K = Integer . parseInt ( sc . next ( ) ) ; int a = A ; int b = B ; int c = C ; for ( int i = 0 ; i < K ; i ++ ) { int c = C ; a *= 2 ; b *= 2 ; c *= 2 ; } System . out . println ( Math . max ( a + B + C , Math . max ( A + b + C , A + B + c ) ) ) ; } } +import java . math . BigInteger ; import java . util . Scanner ; import java . util . Arrays ; public class Main { public static void main ( String [ ] args ) { int n , i , j , m , k , p , q , o , l , s , tt = 1 ; Double x , y , z ; int [ ] ar , br ; char ch ; BigInteger an , su , u , v ; String a , b = " " , c = " " , d ; Scanner sc = new Scanner ( System . in ) ; Scanner scc = new Scanner ( System . in ) ; ar = new int [ 200001 ] ; br = new int [ 200001 ] ; n = sc . nextInt ( ) ; k = 50000000 ; for ( i = 0 ; i < n ; i ++ ) { o = sc . nextInt ( ) ; if ( k > o ) { k = o ; } ar [ i ] = o ; br [ i ] = k ; } k = 0 ; for ( i = 1 ; i < n ; i ++ ) { if ( ar [ i ] <= br [ i ] ) { Scanner sc = new Scanner ( System . in ) ; k ++ ; } } System . out . println ( k + 1 ) ; } } +import java . io . FileNotFoundException ; import java . util . ArrayList ; import java . util . HashSet ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) throws FileNotFoundException { ArrayList < String > result = new ArrayList < > ( ) ; Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; ArrayList < String > result = new ArrayList < > ( ) ; result . add ( sc . next ( ) ) ; for ( int i = 1 ; i < N ; i ++ ) { result . add ( sc . next ( ) ) ; } ArrayList < String > ans = new ArrayList < String > ( new HashSet < > ( result ) ) ; System . out . println ( ans . size ( ) ) ; } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String x = sc . next ( ) ; int y = 0 ; for ( int i = 0 ; i < x . length ( ) ; i ++ ) { y += Character . getNumericValue ( x . charAt ( i ) ) ; } if ( y % 9 == 0 ) { int i = 0 ; System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; StringBuilder str = new StringBuilder ( ) ; while ( true ) { int w = scan . nextInt ( ) ; int h = scan . nextInt ( ) ; int w = scan . nextInt ( ) ; if ( h == 0 && w == 0 ) break ; for ( int i = 0 ; i < h ; i ++ ) { for ( int j = 0 ; j < w ; j ++ ) { str . append ( " # " ) ; } str . append ( " \n " ) ; } str . append ( " \n " ) ; } System . out . print ( str ) ; } } +import java . io . * ; import java . util . * ; import java . lang . * ; class Main { public static void main ( String [ ] args ) throws java . lang . NumberFormatException { Scanner scan = new Scanner ( System . in ) ; StringBuilder input = new StringBuilder ( ) ; do { input . append ( scan . nextLine ( ) ) ; } while ( scan . hasNext ( ) ) ; for ( char i = 'a' ; i <= 'z' ; i ++ ) { int count = 0 ; for ( int j = 0 ; j < input . length ( ) ; j ++ ) { if ( input . toString ( ) . charAt ( j ) == i || Character . toUpperCase ( input . toString ( ) . charAt ( j ) ) == Character . toUpperCase ( i ) ) { int j = 0 ; count ++ ; } } System . out . println ( i + " : " + count ) ; } } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { int i = 1 ; Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int [ ] t = new int [ n + 1 ] , x = new int [ n + 1 ] , y = new int [ n + 1 ] ; boolean flag = true ; t [ 0 ] = 0 ; x [ 0 ] = 0 ; y [ 0 ] = 0 ; for ( int i = 1 ; i < n + 1 ; i ++ ) { t [ i ] = sc . nextInt ( ) ; x [ i ] = sc . nextInt ( ) ; y [ i ] = sc . nextInt ( ) ; } for ( int i = 1 ; i < n + 1 ; i ++ ) { if ( t [ i ] - t [ i - 1 ] < Math . abs ( x [ i ] - x [ i - 1 ] ) + Math . abs ( y [ i ] - y [ i - 1 ] ) || ( t [ i ] - t [ i - 1 ] ) % 2 != Math . abs ( x [ i ] + y [ i ] - x [ i - 1 ] - y [ i - 1 ] ) % 2 ) flag = false ; } String ans = flag ? " Yes " : " No " ; System . out . println ( ans ) ; } } +import java . util . * ; class Main { Scanner sc = new Scanner ( System . in ) ; void main ( ) { int r = sc . nextInt ( ) ; int c = sc . nextInt ( ) ; int [ ] [ ] x = new int [ r + 1 ] [ c + 1 ] ; for ( int i = 0 ; i < r ; i ++ ) { for ( int j = 0 ; j < c ; j ++ ) { x [ i ] [ j ] = sc . nextInt ( ) ; x [ i ] [ c ] += x [ i ] [ j ] ; } } for ( int i = 0 ; i < r ; i ++ ) for ( int j = 0 ; j < c + 1 ; j ++ ) x [ r ] [ j ] += x [ i ] [ j ] ; for ( int i = 0 ; i < r + 1 ; i ++ ) { int j = 0 ; for ( int j = 0 ; j < c ; j ++ ) System . out . print ( x [ i ] [ j ] + " " ) ; System . out . println ( x [ i ] [ c ] ) ; } } public static void main ( String [ ] ag ) { new Main ( ) . main ( ) ; } } +import java . io . PrintWriter ; import java . util . ArrayList ; import java . util . Arrays ; import java . util . Collection ; import java . util . Collections ; import java . util . HashMap ; import java . util . List ; import java . util . Map ; import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { solve ( ) ; } public static void solve ( ) { Scanner sc = new Scanner ( System . in ) ; PrintWriter out = new PrintWriter ( System . out ) ; int n = sc . nextInt ( ) ; int m = sc . nextInt ( ) ; int [ ] ans = new int [ n ] ; Arrays . fill ( ans , 0 ) ; for ( int i = 0 ; i < m ; i ++ ) { int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; a -- ; b -- ; ans [ a ] ++ ; ans [ b ] ++ ; } sc . close ( ) ; for ( int i = 0 ; i < n ; i ++ ) { out . println ( ans [ i ] ) ; } out . flush ( ) ; } static class Pair { int a , b ; public Pair ( int a , int b ) { this . a = a ; this . b = b ; } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; long n = Long . parseLong ( scan . next ( ) ) ; scan . close ( ) ; StringBuilder sb = new StringBuilder ( ) ; while ( n > 0 ) { long l = n % 26 ; if ( l == 0 ) { long l = n % 26 ; sb . append ( 'z' ) ; n -= 1 ; } else { char c = 'a' ; c += l - 1 ; sb . append ( c ) ; } n /= 26 ; } System . out . println ( sb . reverse ( ) . toString ( ) ) ; } } +import java . util . ArrayList ; 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 k = sc . nextInt ( ) ; int ans = getKth ( getGcd ( a , b ) , k ) ; System . out . println ( ans ) ; } static int getGcd ( int a , int b ) { int i = 1 ; if ( a == 0 ) { return b ; } return getGcd ( b % a , a ) ; } static int getKth ( int n , int k ) { ArrayList < Integer > divisors = new ArrayList < > ( ) ; for ( int i = 1 ; i <= n / 2 ; i ++ ) { if ( n % i == 0 ) { divisors . add ( i ) ; } } divisors . add ( n ) ; return ( divisors . get ( divisors . size ( ) - k ) ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; String S = sc . next ( ) ; if ( N % 2 == 0 ) { for ( int i = 0 ; i < N / 2 ; i ++ ) { if ( S . charAt ( i ) != S . charAt ( N / 2 + i ) ) { System . out . println ( " No " ) ; break ; } else if ( i < N / 2 - 1 ) { continue ; } System . out . println ( " Yes " ) ; } } else if ( N % 2 != 0 ) { int i = 0 ; System . out . println ( " No " ) ; } } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { int i = 1 ; Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int [ ] T = new int [ N + 1 ] ; int [ ] X = new int [ N + 1 ] ; int [ ] Y = new int [ N + 1 ] ; T [ 0 ] = X [ 0 ] = Y [ 0 ] = 0 ; boolean yes = true ; for ( int i = 1 ; i <= N ; i ++ ) { T [ i ] = sc . nextInt ( ) ; X [ i ] = sc . nextInt ( ) ; Y [ i ] = sc . nextInt ( ) ; int d = Math . abs ( X [ i ] - X [ i - 1 ] ) + Math . abs ( Y [ i ] - Y [ i - 1 ] ) ; int dt = T [ i ] - T [ i - 1 ] ; if ( d > dt || d % 2 != dt % 2 ) { yes = false ; break ; } } System . out . println ( yes ? " Yes " : " No " ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { try ( Scanner sc = new Scanner ( System . in ) ) { while ( true ) { int m = sc . nextInt ( ) , f = sc . nextInt ( ) , r = sc . nextInt ( ) ; if ( m == - 1 && f == - 1 && r == - 1 ) { int m = sc . nextInt ( ) , f = sc . nextInt ( ) , r = sc . nextInt ( ) ; break ; } if ( m == - 1 || f == - 1 ) { System . out . println ( " F " ) ; } else if ( m + f >= 80 ) { System . out . println ( " A " ) ; } else if ( m + f >= 65 ) { System . out . println ( " B " ) ; } else if ( m + f >= 50 ) { System . out . println ( " C " ) ; } else if ( m + f >= 30 ) { if ( r >= 50 ) { System . out . println ( " C " ) ; } else { System . out . println ( " D " ) ; } } else { System . out . println ( " F " ) ; } } } } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { int cnt = 0 ; Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int min = 200000 ; int cnt = 0 ; for ( int i = 0 ; i < N ; i ++ ) { int P = sc . nextInt ( ) ; min = Math . min ( min , P ) ; if ( min == P ) cnt ++ ; } System . out . println ( cnt ) ; } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; String s = sc . next ( ) ; String ss = s ; ss = ss . substring ( a , a + 1 ) ; if ( ss . equals ( " - " ) ) { String s = sc . next ( ) ; s = s . replace ( " - " , " " ) ; int slen = s . length ( ) ; if ( slen == a + b ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } else { System . out . println ( " No " ) ; } } } +import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int hitPoint = sc . nextInt ( ) ; int attackCount = sc . nextInt ( ) ; int [ ] list = new int [ attackCount ] ; int damage = 0 ; for ( int i = 0 ; i < attackCount ; ++ i ) { int i = 0 ; list [ i ] = sc . nextInt ( ) ; damage += list [ i ] ; } if ( hitPoint <= damage ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } } +import java . util . * ; class Main { public static void main ( String [ ] args ) { int i = 0 ; Scanner sc = new Scanner ( System . in ) ; int r = sc . nextInt ( ) ; int c = sc . nextInt ( ) ; int value ; int rowTotal ; int [ ] colTotal = new int [ c ] ; for ( int i = 0 ; i < r ; i ++ ) { rowTotal = 0 ; for ( int j = 0 ; j < c ; j ++ ) { value = sc . nextInt ( ) ; System . out . print ( value + " " ) ; rowTotal += value ; colTotal [ j ] += value ; } System . out . println ( rowTotal ) ; } rowTotal = 0 ; for ( int i = 0 ; i < c ; i ++ ) { System . out . print ( colTotal [ i ] + " " ) ; rowTotal += colTotal [ i ] ; } System . out . println ( rowTotal ) ; } } +import java . util . Scanner ; class Main { public static void main ( String [ ] args ) { Scanner input = new Scanner ( System . in ) ; String a = input . next ( ) ; if ( a . length ( ) == 10 ) { if ( a . contains ( " 2017/01/ " ) ) { String a = input . next ( ) ; String temp = " " + a . charAt ( 8 ) + a . charAt ( 9 ) ; int tempa = Integer . parseInt ( temp ) ; if ( tempa >= 1 && tempa <= 31 ) { a = a . replace ( " 2017 " , " 2018 " ) ; System . out . println ( a ) ; } } } } } +import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { long resultB = b ; Scanner sc = new Scanner ( System . in ) ; long a = Long . parseLong ( sc . next ( ) ) ; long b = Long . parseLong ( sc . next ( ) ) ; long k = Long . parseLong ( sc . next ( ) ) ; long resultA = a - k ; long resultB = b ; if ( resultA < 0 ) { resultB = Math . max ( b + resultA , 0 ) ; resultA = 0 ; } System . out . println ( resultA + " " + resultB ) ; sc . close ( ) ; } } \ No newline at end of file