id
stringlengths 2
6
| java
stringlengths 48
5.92k
| python
stringlengths 33
11.1k
|
---|---|---|
T700 | import java . io . OutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . PrintWriter ; import java . util . InputMismatchException ; import java . io . IOException ; import java . io . InputStream ; public class Main { public static void main ( String [ ] args ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; FastScanner in = new FastScanner ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; TaskA solver = new TaskA ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class TaskA { public void solve ( int testNumber , FastScanner in , PrintWriter out ) { int n = in . nextInt ( ) ; out . println ( 100 * ( n / 10 ) + Math . min ( ( n % 10 ) * 15 , 100 ) ) ; } } static class FastScanner { private InputStream in ; private byte [ ] buffer = new byte [ 1024 ] ; private int bufPointer ; private int bufLength ; public FastScanner ( InputStream in ) { this . in = in ; this . bufPointer = 0 ; this . bufLength = 0 ; } private int readByte ( ) { if ( bufPointer >= bufLength ) { if ( bufLength == - 1 ) throw new InputMismatchException ( ) ; bufPointer = 0 ; try { bufLength = in . read ( buffer ) ; } catch ( IOException e ) { throw new InputMismatchException ( ) ; } if ( bufLength <= 0 ) return - 1 ; } return buffer [ bufPointer ++ ] ; } private static boolean isSpaceChar ( int c ) { return c == ' ▁ ' || c == ' \n ' || c == ' \r ' || c == ' \t ' || c == - 1 ; } public int nextInt ( ) { int n = 0 ; int b = readByte ( ) ; while ( isSpaceChar ( b ) ) b = readByte ( ) ; boolean minus = ( b == ' - ' ) ; if ( minus ) b = readByte ( ) ; while ( b >= '0' && b <= '9' ) { n *= 10 ; n += b - '0' ; b = readByte ( ) ; } if ( ! isSpaceChar ( b ) ) throw new NumberFormatException ( ) ; return minus ? - n : n ; } } }
| n = int ( input ( ) ) NEW_LINE print ( ( n // 10 ) * 100 + min ( 100 , ( n % 10 ) * 15 ) ) NEW_LINE
|
T701 | import java . io . OutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . PrintWriter ; import java . util . InputMismatchException ; import java . io . IOException ; import java . io . InputStream ; public class Main { public static void main ( String [ ] args ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; FastScanner in = new FastScanner ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; TaskA solver = new TaskA ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class TaskA { public void solve ( int testNumber , FastScanner in , PrintWriter out ) { int n = in . nextInt ( ) ; out . println ( 100 * ( n / 10 ) + Math . min ( ( n % 10 ) * 15 , 100 ) ) ; } } static class FastScanner { private InputStream in ; private byte [ ] buffer = new byte [ 1024 ] ; private int bufPointer ; private int bufLength ; public FastScanner ( InputStream in ) { this . in = in ; this . bufPointer = 0 ; this . bufLength = 0 ; } private int readByte ( ) { if ( bufPointer >= bufLength ) { if ( bufLength == - 1 ) throw new InputMismatchException ( ) ; bufPointer = 0 ; try { bufLength = in . read ( buffer ) ; } catch ( IOException e ) { throw new InputMismatchException ( ) ; } if ( bufLength <= 0 ) return - 1 ; } return buffer [ bufPointer ++ ] ; } private static boolean isSpaceChar ( int c ) { return c == ' ▁ ' || c == ' \n ' || c == ' \r ' || c == ' \t ' || c == - 1 ; } public int nextInt ( ) { int n = 0 ; int b = readByte ( ) ; while ( isSpaceChar ( b ) ) b = readByte ( ) ; boolean minus = ( b == ' - ' ) ; if ( minus ) b = readByte ( ) ; while ( b >= '0' && b <= '9' ) { n *= 10 ; n += b - '0' ; b = readByte ( ) ; } if ( ! isSpaceChar ( b ) ) throw new NumberFormatException ( ) ; return minus ? - n : n ; } } }
| import sys NEW_LINE import copy NEW_LINE input = sys . stdin . readline NEW_LINE N = int ( input ( ) ) NEW_LINE ans = 1000000000000000 NEW_LINE for i in range ( 100 ) : NEW_LINE INDENT for j in range ( 100 ) : NEW_LINE INDENT money = i * 15 + j * 100 NEW_LINE tako = i + j * 10 NEW_LINE if tako >= N : NEW_LINE INDENT ans = min ( ans , money ) NEW_LINE DEDENT DEDENT DEDENT print ( ans ) NEW_LINE
|
T702 | import java . io . OutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . PrintWriter ; import java . util . InputMismatchException ; import java . io . IOException ; import java . io . InputStream ; public class Main { public static void main ( String [ ] args ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; FastScanner in = new FastScanner ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; TaskA solver = new TaskA ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class TaskA { public void solve ( int testNumber , FastScanner in , PrintWriter out ) { int n = in . nextInt ( ) ; out . println ( 100 * ( n / 10 ) + Math . min ( ( n % 10 ) * 15 , 100 ) ) ; } } static class FastScanner { private InputStream in ; private byte [ ] buffer = new byte [ 1024 ] ; private int bufPointer ; private int bufLength ; public FastScanner ( InputStream in ) { this . in = in ; this . bufPointer = 0 ; this . bufLength = 0 ; } private int readByte ( ) { if ( bufPointer >= bufLength ) { if ( bufLength == - 1 ) throw new InputMismatchException ( ) ; bufPointer = 0 ; try { bufLength = in . read ( buffer ) ; } catch ( IOException e ) { throw new InputMismatchException ( ) ; } if ( bufLength <= 0 ) return - 1 ; } return buffer [ bufPointer ++ ] ; } private static boolean isSpaceChar ( int c ) { return c == ' ▁ ' || c == ' \n ' || c == ' \r ' || c == ' \t ' || c == - 1 ; } public int nextInt ( ) { int n = 0 ; int b = readByte ( ) ; while ( isSpaceChar ( b ) ) b = readByte ( ) ; boolean minus = ( b == ' - ' ) ; if ( minus ) b = readByte ( ) ; while ( b >= '0' && b <= '9' ) { n *= 10 ; n += b - '0' ; b = readByte ( ) ; } if ( ! isSpaceChar ( b ) ) throw new NumberFormatException ( ) ; return minus ? - n : n ; } } }
| n = int ( input ( ) ) NEW_LINE num = float ( ' inf ' ) NEW_LINE for i in range ( 100 ) : NEW_LINE INDENT num = min ( num , i * 100 + max ( 0 , ( n - i * 10 ) ) * 15 ) NEW_LINE DEDENT print ( num ) NEW_LINE
|
T703 | import java . io . OutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . PrintWriter ; import java . util . InputMismatchException ; import java . io . IOException ; import java . io . InputStream ; public class Main { public static void main ( String [ ] args ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; FastScanner in = new FastScanner ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; TaskA solver = new TaskA ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class TaskA { public void solve ( int testNumber , FastScanner in , PrintWriter out ) { int n = in . nextInt ( ) ; out . println ( 100 * ( n / 10 ) + Math . min ( ( n % 10 ) * 15 , 100 ) ) ; } } static class FastScanner { private InputStream in ; private byte [ ] buffer = new byte [ 1024 ] ; private int bufPointer ; private int bufLength ; public FastScanner ( InputStream in ) { this . in = in ; this . bufPointer = 0 ; this . bufLength = 0 ; } private int readByte ( ) { if ( bufPointer >= bufLength ) { if ( bufLength == - 1 ) throw new InputMismatchException ( ) ; bufPointer = 0 ; try { bufLength = in . read ( buffer ) ; } catch ( IOException e ) { throw new InputMismatchException ( ) ; } if ( bufLength <= 0 ) return - 1 ; } return buffer [ bufPointer ++ ] ; } private static boolean isSpaceChar ( int c ) { return c == ' ▁ ' || c == ' \n ' || c == ' \r ' || c == ' \t ' || c == - 1 ; } public int nextInt ( ) { int n = 0 ; int b = readByte ( ) ; while ( isSpaceChar ( b ) ) b = readByte ( ) ; boolean minus = ( b == ' - ' ) ; if ( minus ) b = readByte ( ) ; while ( b >= '0' && b <= '9' ) { n *= 10 ; n += b - '0' ; b = readByte ( ) ; } if ( ! isSpaceChar ( b ) ) throw new NumberFormatException ( ) ; return minus ? - n : n ; } } }
| def main ( ) : NEW_LINE INDENT n = int ( input ( ) ) NEW_LINE print ( min ( ( n // 10 ) * 100 + ( n % 10 ) * 15 , ( ( n - 1 ) // 10 + 1 ) * 100 ) ) NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT main ( ) NEW_LINE DEDENT
|
T704 | import java . io . OutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . PrintWriter ; import java . util . InputMismatchException ; import java . io . IOException ; import java . io . InputStream ; public class Main { public static void main ( String [ ] args ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; FastScanner in = new FastScanner ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; TaskA solver = new TaskA ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class TaskA { public void solve ( int testNumber , FastScanner in , PrintWriter out ) { int n = in . nextInt ( ) ; out . println ( 100 * ( n / 10 ) + Math . min ( ( n % 10 ) * 15 , 100 ) ) ; } } static class FastScanner { private InputStream in ; private byte [ ] buffer = new byte [ 1024 ] ; private int bufPointer ; private int bufLength ; public FastScanner ( InputStream in ) { this . in = in ; this . bufPointer = 0 ; this . bufLength = 0 ; } private int readByte ( ) { if ( bufPointer >= bufLength ) { if ( bufLength == - 1 ) throw new InputMismatchException ( ) ; bufPointer = 0 ; try { bufLength = in . read ( buffer ) ; } catch ( IOException e ) { throw new InputMismatchException ( ) ; } if ( bufLength <= 0 ) return - 1 ; } return buffer [ bufPointer ++ ] ; } private static boolean isSpaceChar ( int c ) { return c == ' ▁ ' || c == ' \n ' || c == ' \r ' || c == ' \t ' || c == - 1 ; } public int nextInt ( ) { int n = 0 ; int b = readByte ( ) ; while ( isSpaceChar ( b ) ) b = readByte ( ) ; boolean minus = ( b == ' - ' ) ; if ( minus ) b = readByte ( ) ; while ( b >= '0' && b <= '9' ) { n *= 10 ; n += b - '0' ; b = readByte ( ) ; } if ( ! isSpaceChar ( b ) ) throw new NumberFormatException ( ) ; return minus ? - n : n ; } } }
| n = int ( input ( ) ) NEW_LINE ten = n // 10 NEW_LINE one = n % 10 NEW_LINE print ( min ( ( ten + 1 ) * 100 , ten * 100 + one * 15 ) ) NEW_LINE
|
T705 | import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStream ; import java . io . InputStreamReader ; import java . io . UncheckedIOException ; import java . util . StringTokenizer ; class Main { public static void main ( String [ ] args ) { SC sc = new SC ( System . in ) ; int N = sc . nextInt ( ) ; pl ( Math . min ( ( ( N / 10 ) * 100 + ( N % 10 ) * 15 ) , ( ( N + 9 ) / 10 ) * 100 ) ) ; } static class SC { private BufferedReader reader = null ; private StringTokenizer tokenizer = null ; public SC ( InputStream in ) { reader = new BufferedReader ( new InputStreamReader ( in ) ) ; } public String next ( ) { if ( tokenizer == null || ! tokenizer . hasMoreTokens ( ) ) { try { tokenizer = new StringTokenizer ( reader . readLine ( ) ) ; } catch ( IOException e ) { throw new UncheckedIOException ( e ) ; } } return tokenizer . 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 reader . readLine ( ) ; } catch ( IOException e ) { throw new UncheckedIOException ( e ) ; } } } public static void pl ( Object o ) { System . out . println ( o ) ; } public static void p ( Object o ) { System . out . print ( o ) ; } public static boolean isPrime ( int a ) { if ( a < 4 ) { if ( a == 2 || a == 3 ) { return true ; } else { return false ; } } else { for ( int j = 2 ; j * j <= a ; j ++ ) { if ( a % j == 0 ) { return false ; } if ( a % j != 0 && ( j + 1 ) * ( j + 1 ) > a ) { return true ; } } return true ; } } }
| n = int ( input ( ) ) NEW_LINE print ( ( n // 10 ) * 100 + min ( 100 , ( n % 10 ) * 15 ) ) NEW_LINE
|
T706 | import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStream ; import java . io . InputStreamReader ; import java . io . UncheckedIOException ; import java . util . StringTokenizer ; class Main { public static void main ( String [ ] args ) { SC sc = new SC ( System . in ) ; int N = sc . nextInt ( ) ; pl ( Math . min ( ( ( N / 10 ) * 100 + ( N % 10 ) * 15 ) , ( ( N + 9 ) / 10 ) * 100 ) ) ; } static class SC { private BufferedReader reader = null ; private StringTokenizer tokenizer = null ; public SC ( InputStream in ) { reader = new BufferedReader ( new InputStreamReader ( in ) ) ; } public String next ( ) { if ( tokenizer == null || ! tokenizer . hasMoreTokens ( ) ) { try { tokenizer = new StringTokenizer ( reader . readLine ( ) ) ; } catch ( IOException e ) { throw new UncheckedIOException ( e ) ; } } return tokenizer . 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 reader . readLine ( ) ; } catch ( IOException e ) { throw new UncheckedIOException ( e ) ; } } } public static void pl ( Object o ) { System . out . println ( o ) ; } public static void p ( Object o ) { System . out . print ( o ) ; } public static boolean isPrime ( int a ) { if ( a < 4 ) { if ( a == 2 || a == 3 ) { return true ; } else { return false ; } } else { for ( int j = 2 ; j * j <= a ; j ++ ) { if ( a % j == 0 ) { return false ; } if ( a % j != 0 && ( j + 1 ) * ( j + 1 ) > a ) { return true ; } } return true ; } } }
| import sys NEW_LINE import copy NEW_LINE input = sys . stdin . readline NEW_LINE N = int ( input ( ) ) NEW_LINE ans = 1000000000000000 NEW_LINE for i in range ( 100 ) : NEW_LINE INDENT for j in range ( 100 ) : NEW_LINE INDENT money = i * 15 + j * 100 NEW_LINE tako = i + j * 10 NEW_LINE if tako >= N : NEW_LINE INDENT ans = min ( ans , money ) NEW_LINE DEDENT DEDENT DEDENT print ( ans ) NEW_LINE
|
T707 | import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStream ; import java . io . InputStreamReader ; import java . io . UncheckedIOException ; import java . util . StringTokenizer ; class Main { public static void main ( String [ ] args ) { SC sc = new SC ( System . in ) ; int N = sc . nextInt ( ) ; pl ( Math . min ( ( ( N / 10 ) * 100 + ( N % 10 ) * 15 ) , ( ( N + 9 ) / 10 ) * 100 ) ) ; } static class SC { private BufferedReader reader = null ; private StringTokenizer tokenizer = null ; public SC ( InputStream in ) { reader = new BufferedReader ( new InputStreamReader ( in ) ) ; } public String next ( ) { if ( tokenizer == null || ! tokenizer . hasMoreTokens ( ) ) { try { tokenizer = new StringTokenizer ( reader . readLine ( ) ) ; } catch ( IOException e ) { throw new UncheckedIOException ( e ) ; } } return tokenizer . 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 reader . readLine ( ) ; } catch ( IOException e ) { throw new UncheckedIOException ( e ) ; } } } public static void pl ( Object o ) { System . out . println ( o ) ; } public static void p ( Object o ) { System . out . print ( o ) ; } public static boolean isPrime ( int a ) { if ( a < 4 ) { if ( a == 2 || a == 3 ) { return true ; } else { return false ; } } else { for ( int j = 2 ; j * j <= a ; j ++ ) { if ( a % j == 0 ) { return false ; } if ( a % j != 0 && ( j + 1 ) * ( j + 1 ) > a ) { return true ; } } return true ; } } }
| n = int ( input ( ) ) NEW_LINE num = float ( ' inf ' ) NEW_LINE for i in range ( 100 ) : NEW_LINE INDENT num = min ( num , i * 100 + max ( 0 , ( n - i * 10 ) ) * 15 ) NEW_LINE DEDENT print ( num ) NEW_LINE
|
T708 | import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStream ; import java . io . InputStreamReader ; import java . io . UncheckedIOException ; import java . util . StringTokenizer ; class Main { public static void main ( String [ ] args ) { SC sc = new SC ( System . in ) ; int N = sc . nextInt ( ) ; pl ( Math . min ( ( ( N / 10 ) * 100 + ( N % 10 ) * 15 ) , ( ( N + 9 ) / 10 ) * 100 ) ) ; } static class SC { private BufferedReader reader = null ; private StringTokenizer tokenizer = null ; public SC ( InputStream in ) { reader = new BufferedReader ( new InputStreamReader ( in ) ) ; } public String next ( ) { if ( tokenizer == null || ! tokenizer . hasMoreTokens ( ) ) { try { tokenizer = new StringTokenizer ( reader . readLine ( ) ) ; } catch ( IOException e ) { throw new UncheckedIOException ( e ) ; } } return tokenizer . 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 reader . readLine ( ) ; } catch ( IOException e ) { throw new UncheckedIOException ( e ) ; } } } public static void pl ( Object o ) { System . out . println ( o ) ; } public static void p ( Object o ) { System . out . print ( o ) ; } public static boolean isPrime ( int a ) { if ( a < 4 ) { if ( a == 2 || a == 3 ) { return true ; } else { return false ; } } else { for ( int j = 2 ; j * j <= a ; j ++ ) { if ( a % j == 0 ) { return false ; } if ( a % j != 0 && ( j + 1 ) * ( j + 1 ) > a ) { return true ; } } return true ; } } }
| def main ( ) : NEW_LINE INDENT n = int ( input ( ) ) NEW_LINE print ( min ( ( n // 10 ) * 100 + ( n % 10 ) * 15 , ( ( n - 1 ) // 10 + 1 ) * 100 ) ) NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT main ( ) NEW_LINE DEDENT
|
T709 | import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStream ; import java . io . InputStreamReader ; import java . io . UncheckedIOException ; import java . util . StringTokenizer ; class Main { public static void main ( String [ ] args ) { SC sc = new SC ( System . in ) ; int N = sc . nextInt ( ) ; pl ( Math . min ( ( ( N / 10 ) * 100 + ( N % 10 ) * 15 ) , ( ( N + 9 ) / 10 ) * 100 ) ) ; } static class SC { private BufferedReader reader = null ; private StringTokenizer tokenizer = null ; public SC ( InputStream in ) { reader = new BufferedReader ( new InputStreamReader ( in ) ) ; } public String next ( ) { if ( tokenizer == null || ! tokenizer . hasMoreTokens ( ) ) { try { tokenizer = new StringTokenizer ( reader . readLine ( ) ) ; } catch ( IOException e ) { throw new UncheckedIOException ( e ) ; } } return tokenizer . 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 reader . readLine ( ) ; } catch ( IOException e ) { throw new UncheckedIOException ( e ) ; } } } public static void pl ( Object o ) { System . out . println ( o ) ; } public static void p ( Object o ) { System . out . print ( o ) ; } public static boolean isPrime ( int a ) { if ( a < 4 ) { if ( a == 2 || a == 3 ) { return true ; } else { return false ; } } else { for ( int j = 2 ; j * j <= a ; j ++ ) { if ( a % j == 0 ) { return false ; } if ( a % j != 0 && ( j + 1 ) * ( j + 1 ) > a ) { return true ; } } return true ; } } }
| n = int ( input ( ) ) NEW_LINE ten = n // 10 NEW_LINE one = n % 10 NEW_LINE print ( min ( ( ten + 1 ) * 100 , ten * 100 + one * 15 ) ) NEW_LINE
|
T710 | import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStream ; import java . io . InputStreamReader ; import java . io . OutputStream ; import java . io . PrintWriter ; import java . util . StringTokenizer ; public class Main { public static void main ( String [ ] args ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; InputReader in = new InputReader ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; Task solver = new Task ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class Task { public void solve ( int testNumber , InputReader in , PrintWriter out ) { int N = in . nextInt ( ) ; int ans = 0 ; while ( N > 10 ) { N -= 10 ; ans += 100 ; } if ( N >= 7 ) { out . println ( ans + 100 ) ; } else { out . println ( ans + N * 15 ) ; } } } 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 ( ) ) ; } } }
| n = int ( input ( ) ) NEW_LINE print ( ( n // 10 ) * 100 + min ( 100 , ( n % 10 ) * 15 ) ) NEW_LINE
|
T711 | import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStream ; import java . io . InputStreamReader ; import java . io . OutputStream ; import java . io . PrintWriter ; import java . util . StringTokenizer ; public class Main { public static void main ( String [ ] args ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; InputReader in = new InputReader ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; Task solver = new Task ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class Task { public void solve ( int testNumber , InputReader in , PrintWriter out ) { int N = in . nextInt ( ) ; int ans = 0 ; while ( N > 10 ) { N -= 10 ; ans += 100 ; } if ( N >= 7 ) { out . println ( ans + 100 ) ; } else { out . println ( ans + N * 15 ) ; } } } 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 sys NEW_LINE import copy NEW_LINE input = sys . stdin . readline NEW_LINE N = int ( input ( ) ) NEW_LINE ans = 1000000000000000 NEW_LINE for i in range ( 100 ) : NEW_LINE INDENT for j in range ( 100 ) : NEW_LINE INDENT money = i * 15 + j * 100 NEW_LINE tako = i + j * 10 NEW_LINE if tako >= N : NEW_LINE INDENT ans = min ( ans , money ) NEW_LINE DEDENT DEDENT DEDENT print ( ans ) NEW_LINE
|
T712 | import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStream ; import java . io . InputStreamReader ; import java . io . OutputStream ; import java . io . PrintWriter ; import java . util . StringTokenizer ; public class Main { public static void main ( String [ ] args ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; InputReader in = new InputReader ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; Task solver = new Task ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class Task { public void solve ( int testNumber , InputReader in , PrintWriter out ) { int N = in . nextInt ( ) ; int ans = 0 ; while ( N > 10 ) { N -= 10 ; ans += 100 ; } if ( N >= 7 ) { out . println ( ans + 100 ) ; } else { out . println ( ans + N * 15 ) ; } } } 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 ( ) ) ; } } }
| n = int ( input ( ) ) NEW_LINE num = float ( ' inf ' ) NEW_LINE for i in range ( 100 ) : NEW_LINE INDENT num = min ( num , i * 100 + max ( 0 , ( n - i * 10 ) ) * 15 ) NEW_LINE DEDENT print ( num ) NEW_LINE
|
T713 | import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStream ; import java . io . InputStreamReader ; import java . io . OutputStream ; import java . io . PrintWriter ; import java . util . StringTokenizer ; public class Main { public static void main ( String [ ] args ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; InputReader in = new InputReader ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; Task solver = new Task ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class Task { public void solve ( int testNumber , InputReader in , PrintWriter out ) { int N = in . nextInt ( ) ; int ans = 0 ; while ( N > 10 ) { N -= 10 ; ans += 100 ; } if ( N >= 7 ) { out . println ( ans + 100 ) ; } else { out . println ( ans + N * 15 ) ; } } } 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 ( ) ) ; } } }
| def main ( ) : NEW_LINE INDENT n = int ( input ( ) ) NEW_LINE print ( min ( ( n // 10 ) * 100 + ( n % 10 ) * 15 , ( ( n - 1 ) // 10 + 1 ) * 100 ) ) NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT main ( ) NEW_LINE DEDENT
|
T714 | import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStream ; import java . io . InputStreamReader ; import java . io . OutputStream ; import java . io . PrintWriter ; import java . util . StringTokenizer ; public class Main { public static void main ( String [ ] args ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; InputReader in = new InputReader ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; Task solver = new Task ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class Task { public void solve ( int testNumber , InputReader in , PrintWriter out ) { int N = in . nextInt ( ) ; int ans = 0 ; while ( N > 10 ) { N -= 10 ; ans += 100 ; } if ( N >= 7 ) { out . println ( ans + 100 ) ; } else { out . println ( ans + N * 15 ) ; } } } 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 ( ) ) ; } } }
| n = int ( input ( ) ) NEW_LINE ten = n // 10 NEW_LINE one = n % 10 NEW_LINE print ( min ( ( ten + 1 ) * 100 , ten * 100 + one * 15 ) ) NEW_LINE
|
T715 | import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; int L = 2 * N - 1 ; int [ ] a = new int [ L ] ; for ( int i = 0 ; i < L ; i ++ ) a [ i ] = sc . nextInt ( ) ; int min = 1 ; int max = L ; boolean b [ ] = new boolean [ L ] ; while ( min + 1 < max ) { int mid = ( min + max ) / 2 ; for ( int i = 0 ; i < L ; i ++ ) b [ i ] = a [ i ] >= mid ; if ( satisfy ( b ) ) min = mid ; else max = mid ; } System . out . println ( min ) ; sc . close ( ) ; } static boolean satisfy ( boolean [ ] b ) { int L = b . length ; int N = ( L + 1 ) / 2 ; int l = N - 1 ; while ( l > 0 && b [ l ] != b [ l - 1 ] ) l -- ; int r = N - 1 ; while ( r < L - 1 && b [ r ] != b [ r + 1 ] ) r ++ ; if ( l > 0 ) { if ( r < L - 1 ) { if ( b [ l ] == b [ r ] ) return b [ l ] ; else return ( l + r ) / 2 >= N - 1 ? b [ l ] : b [ r ] ; } else { return b [ l ] ; } } else if ( r < L - 1 ) { return b [ r ] ; } else { return b [ N - 1 ] ^ N % 2 == 0 ; } } }
| N = int ( input ( ) ) NEW_LINE a = [ 0 ] + list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE def check ( n ) : NEW_LINE INDENT b = [ False ] * ( len ( a ) ) NEW_LINE for i in range ( 1 , len ( a ) ) : NEW_LINE INDENT if a [ i ] >= n : NEW_LINE INDENT b [ i ] = True NEW_LINE DEDENT else : NEW_LINE INDENT b [ i ] = False NEW_LINE DEDENT DEDENT r = int ( 1e9 ) NEW_LINE l = int ( 1e9 ) NEW_LINE rb = b [ N ] NEW_LINE lb = b [ N ] NEW_LINE for i in range ( 1 , N ) : NEW_LINE INDENT if lb == b [ N - i ] : NEW_LINE INDENT l = i NEW_LINE break NEW_LINE DEDENT else : NEW_LINE INDENT lb = b [ N - i ] NEW_LINE DEDENT DEDENT for i in range ( 1 , N ) : NEW_LINE INDENT if rb == b [ N + i ] : NEW_LINE INDENT r = i NEW_LINE break NEW_LINE DEDENT else : NEW_LINE INDENT rb = b [ N + i ] NEW_LINE DEDENT DEDENT if r == int ( 1e9 ) and l == int ( 1e9 ) : NEW_LINE INDENT if N % 2 == 1 : NEW_LINE INDENT return b [ N ] NEW_LINE DEDENT else : NEW_LINE INDENT return not b [ N ] NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT if r < l : NEW_LINE INDENT return rb NEW_LINE DEDENT else : NEW_LINE INDENT return lb NEW_LINE DEDENT DEDENT DEDENT def binarySearch ( small , big ) : NEW_LINE INDENT mid = ( big + small ) // 2 NEW_LINE if big - small <= 1 : NEW_LINE INDENT if check ( small ) : return small NEW_LINE else : return big NEW_LINE DEDENT else : NEW_LINE INDENT if not check ( mid ) : NEW_LINE INDENT return binarySearch ( small , mid ) NEW_LINE DEDENT else : NEW_LINE INDENT return binarySearch ( mid , big ) NEW_LINE DEDENT DEDENT DEDENT print ( binarySearch ( 2 , 2 * N - 2 ) ) NEW_LINE
|
T716 | 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 ] [ N ] ; long sum = 0 ; for ( int i = 0 ; i < N ; i ++ ) for ( int j = 0 ; j < N ; j ++ ) { A [ i ] [ j ] = sc . nextInt ( ) ; sum += A [ i ] [ j ] ; } sum /= 2 ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = i + 1 ; j < N ; j ++ ) { for ( int k = 0 ; k < N ; k ++ ) { if ( i == k || j == k ) continue ; if ( A [ i ] [ j ] > A [ i ] [ k ] + A [ k ] [ j ] ) { System . out . println ( - 1 ) ; return ; } if ( A [ i ] [ j ] == A [ i ] [ k ] + A [ k ] [ j ] ) { sum -= A [ i ] [ j ] ; break ; } } } } System . out . println ( sum ) ; } }
| def inpl ( ) : return [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE import sys NEW_LINE import numpy NEW_LINE N = int ( input ( ) ) NEW_LINE A = numpy . asarray ( [ inpl ( ) for _ in range ( N ) ] ) NEW_LINE ans = 0 NEW_LINE for i in range ( N ) : NEW_LINE INDENT A [ i ] [ i ] = 10 ** 9 + 1 NEW_LINE DEDENT for i in range ( N ) : NEW_LINE INDENT for j in range ( i ) : NEW_LINE INDENT mindis = numpy . min ( [ A [ i ] + A [ j ] ] ) NEW_LINE if mindis > A [ i ] [ j ] : NEW_LINE INDENT ans += A [ i ] [ j ] NEW_LINE continue NEW_LINE DEDENT if mindis < A [ i ] [ j ] : NEW_LINE INDENT print ( - 1 ) NEW_LINE sys . exit ( ) NEW_LINE DEDENT DEDENT DEDENT print ( ans ) NEW_LINE
|
T717 | 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 ] [ N ] ; long sum = 0 ; for ( int i = 0 ; i < N ; i ++ ) for ( int j = 0 ; j < N ; j ++ ) { A [ i ] [ j ] = sc . nextInt ( ) ; sum += A [ i ] [ j ] ; } sum /= 2 ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = i + 1 ; j < N ; j ++ ) { for ( int k = 0 ; k < N ; k ++ ) { if ( i == k || j == k ) continue ; if ( A [ i ] [ j ] > A [ i ] [ k ] + A [ k ] [ j ] ) { System . out . println ( - 1 ) ; return ; } if ( A [ i ] [ j ] == A [ i ] [ k ] + A [ k ] [ j ] ) { sum -= A [ i ] [ j ] ; break ; } } } } System . out . println ( sum ) ; } }
| import numpy as np NEW_LINE import scipy . sparse . csgraph as csg NEW_LINE if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT N = int ( input ( ) ) NEW_LINE A = [ list ( map ( int , input ( ) . split ( ) ) ) for i in range ( N ) ] NEW_LINE G = np . asarray ( A , dtype = np . uint32 ) NEW_LINE G2 = csg . floyd_warshall ( G , directed = False ) NEW_LINE if np . any ( G != G2 ) : NEW_LINE INDENT print ( - 1 ) NEW_LINE exit ( ) NEW_LINE DEDENT ans = 0 NEW_LINE G [ G == 0 ] = 1 NEW_LINE for i in range ( N ) : NEW_LINE INDENT for j in range ( i + 1 , N ) : NEW_LINE INDENT n = np . min ( G [ i ] + G [ j ] ) NEW_LINE if n > G [ i , j ] : NEW_LINE INDENT ans += G [ i , j ] NEW_LINE DEDENT DEDENT DEDENT print ( ans ) NEW_LINE DEDENT
|
T718 | 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 ] [ N ] ; long sum = 0 ; for ( int i = 0 ; i < N ; i ++ ) for ( int j = 0 ; j < N ; j ++ ) { A [ i ] [ j ] = sc . nextInt ( ) ; sum += A [ i ] [ j ] ; } sum /= 2 ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = i + 1 ; j < N ; j ++ ) { for ( int k = 0 ; k < N ; k ++ ) { if ( i == k || j == k ) continue ; if ( A [ i ] [ j ] > A [ i ] [ k ] + A [ k ] [ j ] ) { System . out . println ( - 1 ) ; return ; } if ( A [ i ] [ j ] == A [ i ] [ k ] + A [ k ] [ j ] ) { sum -= A [ i ] [ j ] ; break ; } } } } System . out . println ( sum ) ; } }
| def solve ( n , tbl ) : NEW_LINE INDENT ans = 0 NEW_LINE for i , row_i in enumerate ( tbl ) : NEW_LINE INDENT for j in range ( i + 1 , n ) : NEW_LINE INDENT row_j = tbl [ j ] NEW_LINE ij = row_i [ j ] NEW_LINE mind = min ( ( ik + kj for ik , kj in zip ( row_i , row_j ) if ik and kj ) , default = float ( ' inf ' ) ) NEW_LINE if ij > mind : NEW_LINE INDENT return - 1 NEW_LINE DEDENT if ij < mind : NEW_LINE INDENT ans += ij NEW_LINE DEDENT DEDENT DEDENT return ans NEW_LINE DEDENT n = int ( input ( ) ) NEW_LINE tbl = [ list ( map ( int , input ( ) . split ( ) ) ) for _ in range ( n ) ] NEW_LINE print ( solve ( n , tbl ) ) NEW_LINE
|
T719 | 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 ] [ N ] ; long sum = 0 ; for ( int i = 0 ; i < N ; i ++ ) for ( int j = 0 ; j < N ; j ++ ) { A [ i ] [ j ] = sc . nextInt ( ) ; sum += A [ i ] [ j ] ; } sum /= 2 ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = i + 1 ; j < N ; j ++ ) { for ( int k = 0 ; k < N ; k ++ ) { if ( i == k || j == k ) continue ; if ( A [ i ] [ j ] > A [ i ] [ k ] + A [ k ] [ j ] ) { System . out . println ( - 1 ) ; return ; } if ( A [ i ] [ j ] == A [ i ] [ k ] + A [ k ] [ j ] ) { sum -= A [ i ] [ j ] ; break ; } } } } System . out . println ( sum ) ; } }
| N = int ( input ( ) ) NEW_LINE inf = float ( " inf " ) NEW_LINE A = [ list ( map ( int , input ( ) . split ( ) ) ) for _ in [ 0 ] * N ] NEW_LINE for i in range ( N ) : NEW_LINE INDENT A [ i ] [ i ] = inf NEW_LINE DEDENT result = 0 NEW_LINE for i in range ( N - 1 ) : NEW_LINE INDENT for j , dist in enumerate ( A [ i ] [ i + 1 : ] , start = i + 1 ) : NEW_LINE INDENT for _A in A : NEW_LINE INDENT if dist >= _A [ i ] + _A [ j ] : NEW_LINE INDENT if dist > _A [ i ] + _A [ j ] : NEW_LINE INDENT print ( - 1 ) NEW_LINE exit ( ) NEW_LINE DEDENT break NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT result += dist NEW_LINE DEDENT DEDENT DEDENT print ( result ) NEW_LINE
|
T720 | 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 ] [ N ] ; long sum = 0 ; for ( int i = 0 ; i < N ; i ++ ) for ( int j = 0 ; j < N ; j ++ ) { A [ i ] [ j ] = sc . nextInt ( ) ; sum += A [ i ] [ j ] ; } sum /= 2 ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = i + 1 ; j < N ; j ++ ) { for ( int k = 0 ; k < N ; k ++ ) { if ( i == k || j == k ) continue ; if ( A [ i ] [ j ] > A [ i ] [ k ] + A [ k ] [ j ] ) { System . out . println ( - 1 ) ; return ; } if ( A [ i ] [ j ] == A [ i ] [ k ] + A [ k ] [ j ] ) { sum -= A [ i ] [ j ] ; break ; } } } } System . out . println ( sum ) ; } }
| import numpy as np NEW_LINE N = int ( input ( ) ) NEW_LINE dist = [ [ 0.0 for _ in range ( N ) ] for _ in range ( N ) ] NEW_LINE for i in range ( N ) : NEW_LINE INDENT for j , x in enumerate ( map ( int , input ( ) . split ( ) ) ) : NEW_LINE INDENT dist [ i ] [ j ] = float ( x ) NEW_LINE DEDENT DEDENT dist = np . array ( dist ) NEW_LINE for i in range ( N ) : NEW_LINE INDENT dist [ i , i ] = float ( ' inf ' ) NEW_LINE DEDENT ans = 0 NEW_LINE for i in range ( N ) : NEW_LINE INDENT for j in range ( i + 1 , N ) : NEW_LINE INDENT min_ = min ( dist [ i ] + dist [ j ] ) NEW_LINE if min_ < dist [ i , j ] : NEW_LINE INDENT ans = - 1 NEW_LINE break NEW_LINE DEDENT elif min_ > dist [ i , j ] : NEW_LINE INDENT ans += dist [ i , j ] NEW_LINE DEDENT DEDENT if ans < 0 : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT print ( int ( ans ) ) NEW_LINE
|
T721 | import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int n = scanner . nextInt ( ) ; long [ ] [ ] dist = new long [ n + 1 ] [ n + 1 ] ; for ( int i = 1 ; i <= n ; ++ i ) { for ( int j = 1 ; j <= n ; ++ j ) { long a = scanner . nextInt ( ) ; dist [ i ] [ j ] = a ; } } long totalLength = 0 ; for ( int i = 1 ; i <= n ; ++ i ) { for ( int j = i + 1 ; j <= n ; ++ j ) { boolean isNecessary = true ; for ( int k = 1 ; k <= n ; ++ k ) { if ( i == k || j == k ) { continue ; } if ( dist [ i ] [ k ] + dist [ k ] [ j ] < dist [ i ] [ j ] ) { System . out . println ( - 1 ) ; return ; } else if ( dist [ i ] [ k ] + dist [ k ] [ j ] == dist [ i ] [ j ] ) { isNecessary = false ; break ; } } if ( isNecessary ) { totalLength += dist [ i ] [ j ] ; } } } System . out . println ( totalLength ) ; } }
| def inpl ( ) : return [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE import sys NEW_LINE import numpy NEW_LINE N = int ( input ( ) ) NEW_LINE A = numpy . asarray ( [ inpl ( ) for _ in range ( N ) ] ) NEW_LINE ans = 0 NEW_LINE for i in range ( N ) : NEW_LINE INDENT A [ i ] [ i ] = 10 ** 9 + 1 NEW_LINE DEDENT for i in range ( N ) : NEW_LINE INDENT for j in range ( i ) : NEW_LINE INDENT mindis = numpy . min ( [ A [ i ] + A [ j ] ] ) NEW_LINE if mindis > A [ i ] [ j ] : NEW_LINE INDENT ans += A [ i ] [ j ] NEW_LINE continue NEW_LINE DEDENT if mindis < A [ i ] [ j ] : NEW_LINE INDENT print ( - 1 ) NEW_LINE sys . exit ( ) NEW_LINE DEDENT DEDENT DEDENT print ( ans ) NEW_LINE
|
T722 | import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int n = scanner . nextInt ( ) ; long [ ] [ ] dist = new long [ n + 1 ] [ n + 1 ] ; for ( int i = 1 ; i <= n ; ++ i ) { for ( int j = 1 ; j <= n ; ++ j ) { long a = scanner . nextInt ( ) ; dist [ i ] [ j ] = a ; } } long totalLength = 0 ; for ( int i = 1 ; i <= n ; ++ i ) { for ( int j = i + 1 ; j <= n ; ++ j ) { boolean isNecessary = true ; for ( int k = 1 ; k <= n ; ++ k ) { if ( i == k || j == k ) { continue ; } if ( dist [ i ] [ k ] + dist [ k ] [ j ] < dist [ i ] [ j ] ) { System . out . println ( - 1 ) ; return ; } else if ( dist [ i ] [ k ] + dist [ k ] [ j ] == dist [ i ] [ j ] ) { isNecessary = false ; break ; } } if ( isNecessary ) { totalLength += dist [ i ] [ j ] ; } } } System . out . println ( totalLength ) ; } }
| import numpy as np NEW_LINE import scipy . sparse . csgraph as csg NEW_LINE if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT N = int ( input ( ) ) NEW_LINE A = [ list ( map ( int , input ( ) . split ( ) ) ) for i in range ( N ) ] NEW_LINE G = np . asarray ( A , dtype = np . uint32 ) NEW_LINE G2 = csg . floyd_warshall ( G , directed = False ) NEW_LINE if np . any ( G != G2 ) : NEW_LINE INDENT print ( - 1 ) NEW_LINE exit ( ) NEW_LINE DEDENT ans = 0 NEW_LINE G [ G == 0 ] = 1 NEW_LINE for i in range ( N ) : NEW_LINE INDENT for j in range ( i + 1 , N ) : NEW_LINE INDENT n = np . min ( G [ i ] + G [ j ] ) NEW_LINE if n > G [ i , j ] : NEW_LINE INDENT ans += G [ i , j ] NEW_LINE DEDENT DEDENT DEDENT print ( ans ) NEW_LINE DEDENT
|
T723 | import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int n = scanner . nextInt ( ) ; long [ ] [ ] dist = new long [ n + 1 ] [ n + 1 ] ; for ( int i = 1 ; i <= n ; ++ i ) { for ( int j = 1 ; j <= n ; ++ j ) { long a = scanner . nextInt ( ) ; dist [ i ] [ j ] = a ; } } long totalLength = 0 ; for ( int i = 1 ; i <= n ; ++ i ) { for ( int j = i + 1 ; j <= n ; ++ j ) { boolean isNecessary = true ; for ( int k = 1 ; k <= n ; ++ k ) { if ( i == k || j == k ) { continue ; } if ( dist [ i ] [ k ] + dist [ k ] [ j ] < dist [ i ] [ j ] ) { System . out . println ( - 1 ) ; return ; } else if ( dist [ i ] [ k ] + dist [ k ] [ j ] == dist [ i ] [ j ] ) { isNecessary = false ; break ; } } if ( isNecessary ) { totalLength += dist [ i ] [ j ] ; } } } System . out . println ( totalLength ) ; } }
| def solve ( n , tbl ) : NEW_LINE INDENT ans = 0 NEW_LINE for i , row_i in enumerate ( tbl ) : NEW_LINE INDENT for j in range ( i + 1 , n ) : NEW_LINE INDENT row_j = tbl [ j ] NEW_LINE ij = row_i [ j ] NEW_LINE mind = min ( ( ik + kj for ik , kj in zip ( row_i , row_j ) if ik and kj ) , default = float ( ' inf ' ) ) NEW_LINE if ij > mind : NEW_LINE INDENT return - 1 NEW_LINE DEDENT if ij < mind : NEW_LINE INDENT ans += ij NEW_LINE DEDENT DEDENT DEDENT return ans NEW_LINE DEDENT n = int ( input ( ) ) NEW_LINE tbl = [ list ( map ( int , input ( ) . split ( ) ) ) for _ in range ( n ) ] NEW_LINE print ( solve ( n , tbl ) ) NEW_LINE
|
T724 | import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int n = scanner . nextInt ( ) ; long [ ] [ ] dist = new long [ n + 1 ] [ n + 1 ] ; for ( int i = 1 ; i <= n ; ++ i ) { for ( int j = 1 ; j <= n ; ++ j ) { long a = scanner . nextInt ( ) ; dist [ i ] [ j ] = a ; } } long totalLength = 0 ; for ( int i = 1 ; i <= n ; ++ i ) { for ( int j = i + 1 ; j <= n ; ++ j ) { boolean isNecessary = true ; for ( int k = 1 ; k <= n ; ++ k ) { if ( i == k || j == k ) { continue ; } if ( dist [ i ] [ k ] + dist [ k ] [ j ] < dist [ i ] [ j ] ) { System . out . println ( - 1 ) ; return ; } else if ( dist [ i ] [ k ] + dist [ k ] [ j ] == dist [ i ] [ j ] ) { isNecessary = false ; break ; } } if ( isNecessary ) { totalLength += dist [ i ] [ j ] ; } } } System . out . println ( totalLength ) ; } }
| N = int ( input ( ) ) NEW_LINE inf = float ( " inf " ) NEW_LINE A = [ list ( map ( int , input ( ) . split ( ) ) ) for _ in [ 0 ] * N ] NEW_LINE for i in range ( N ) : NEW_LINE INDENT A [ i ] [ i ] = inf NEW_LINE DEDENT result = 0 NEW_LINE for i in range ( N - 1 ) : NEW_LINE INDENT for j , dist in enumerate ( A [ i ] [ i + 1 : ] , start = i + 1 ) : NEW_LINE INDENT for _A in A : NEW_LINE INDENT if dist >= _A [ i ] + _A [ j ] : NEW_LINE INDENT if dist > _A [ i ] + _A [ j ] : NEW_LINE INDENT print ( - 1 ) NEW_LINE exit ( ) NEW_LINE DEDENT break NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT result += dist NEW_LINE DEDENT DEDENT DEDENT print ( result ) NEW_LINE
|
T725 | import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int n = scanner . nextInt ( ) ; long [ ] [ ] dist = new long [ n + 1 ] [ n + 1 ] ; for ( int i = 1 ; i <= n ; ++ i ) { for ( int j = 1 ; j <= n ; ++ j ) { long a = scanner . nextInt ( ) ; dist [ i ] [ j ] = a ; } } long totalLength = 0 ; for ( int i = 1 ; i <= n ; ++ i ) { for ( int j = i + 1 ; j <= n ; ++ j ) { boolean isNecessary = true ; for ( int k = 1 ; k <= n ; ++ k ) { if ( i == k || j == k ) { continue ; } if ( dist [ i ] [ k ] + dist [ k ] [ j ] < dist [ i ] [ j ] ) { System . out . println ( - 1 ) ; return ; } else if ( dist [ i ] [ k ] + dist [ k ] [ j ] == dist [ i ] [ j ] ) { isNecessary = false ; break ; } } if ( isNecessary ) { totalLength += dist [ i ] [ j ] ; } } } System . out . println ( totalLength ) ; } }
| import numpy as np NEW_LINE N = int ( input ( ) ) NEW_LINE dist = [ [ 0.0 for _ in range ( N ) ] for _ in range ( N ) ] NEW_LINE for i in range ( N ) : NEW_LINE INDENT for j , x in enumerate ( map ( int , input ( ) . split ( ) ) ) : NEW_LINE INDENT dist [ i ] [ j ] = float ( x ) NEW_LINE DEDENT DEDENT dist = np . array ( dist ) NEW_LINE for i in range ( N ) : NEW_LINE INDENT dist [ i , i ] = float ( ' inf ' ) NEW_LINE DEDENT ans = 0 NEW_LINE for i in range ( N ) : NEW_LINE INDENT for j in range ( i + 1 , N ) : NEW_LINE INDENT min_ = min ( dist [ i ] + dist [ j ] ) NEW_LINE if min_ < dist [ i , j ] : NEW_LINE INDENT ans = - 1 NEW_LINE break NEW_LINE DEDENT elif min_ > dist [ i , j ] : NEW_LINE INDENT ans += dist [ i , j ] NEW_LINE DEDENT DEDENT if ans < 0 : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT print ( int ( ans ) ) NEW_LINE
|
T726 | import java . util . * ; import java . util . stream . Stream ; public class Main { private static int N ; private static int A [ ] [ ] ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; N = sc . nextInt ( ) ; A = new int [ N ] [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) { A [ i ] [ j ] = sc . nextInt ( ) ; } } System . out . println ( solve ( ) ) ; } static long solve ( ) { boolean [ ] [ ] indirect = new boolean [ N ] [ N ] ; for ( int i = 0 ; i < N - 1 ; i ++ ) { for ( int j = i + 1 ; j < N ; j ++ ) { for ( int k = 0 ; k < N ; k ++ ) { if ( k == i || k == j ) continue ; int ikj = A [ i ] [ k ] + A [ k ] [ j ] ; int ij = A [ i ] [ j ] ; if ( ikj < ij ) { return - 1 ; } else if ( ikj == ij ) { indirect [ i ] [ j ] = true ; } } } } long ans = 0 ; for ( int i = 0 ; i < N - 1 ; i ++ ) { for ( int j = i + 1 ; j < N ; j ++ ) { if ( ! indirect [ i ] [ j ] ) { ans += A [ i ] [ j ] ; } } } return ans ; } }
| def inpl ( ) : return [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE import sys NEW_LINE import numpy NEW_LINE N = int ( input ( ) ) NEW_LINE A = numpy . asarray ( [ inpl ( ) for _ in range ( N ) ] ) NEW_LINE ans = 0 NEW_LINE for i in range ( N ) : NEW_LINE INDENT A [ i ] [ i ] = 10 ** 9 + 1 NEW_LINE DEDENT for i in range ( N ) : NEW_LINE INDENT for j in range ( i ) : NEW_LINE INDENT mindis = numpy . min ( [ A [ i ] + A [ j ] ] ) NEW_LINE if mindis > A [ i ] [ j ] : NEW_LINE INDENT ans += A [ i ] [ j ] NEW_LINE continue NEW_LINE DEDENT if mindis < A [ i ] [ j ] : NEW_LINE INDENT print ( - 1 ) NEW_LINE sys . exit ( ) NEW_LINE DEDENT DEDENT DEDENT print ( ans ) NEW_LINE
|
T727 | import java . util . * ; import java . util . stream . Stream ; public class Main { private static int N ; private static int A [ ] [ ] ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; N = sc . nextInt ( ) ; A = new int [ N ] [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) { A [ i ] [ j ] = sc . nextInt ( ) ; } } System . out . println ( solve ( ) ) ; } static long solve ( ) { boolean [ ] [ ] indirect = new boolean [ N ] [ N ] ; for ( int i = 0 ; i < N - 1 ; i ++ ) { for ( int j = i + 1 ; j < N ; j ++ ) { for ( int k = 0 ; k < N ; k ++ ) { if ( k == i || k == j ) continue ; int ikj = A [ i ] [ k ] + A [ k ] [ j ] ; int ij = A [ i ] [ j ] ; if ( ikj < ij ) { return - 1 ; } else if ( ikj == ij ) { indirect [ i ] [ j ] = true ; } } } } long ans = 0 ; for ( int i = 0 ; i < N - 1 ; i ++ ) { for ( int j = i + 1 ; j < N ; j ++ ) { if ( ! indirect [ i ] [ j ] ) { ans += A [ i ] [ j ] ; } } } return ans ; } }
| import numpy as np NEW_LINE import scipy . sparse . csgraph as csg NEW_LINE if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT N = int ( input ( ) ) NEW_LINE A = [ list ( map ( int , input ( ) . split ( ) ) ) for i in range ( N ) ] NEW_LINE G = np . asarray ( A , dtype = np . uint32 ) NEW_LINE G2 = csg . floyd_warshall ( G , directed = False ) NEW_LINE if np . any ( G != G2 ) : NEW_LINE INDENT print ( - 1 ) NEW_LINE exit ( ) NEW_LINE DEDENT ans = 0 NEW_LINE G [ G == 0 ] = 1 NEW_LINE for i in range ( N ) : NEW_LINE INDENT for j in range ( i + 1 , N ) : NEW_LINE INDENT n = np . min ( G [ i ] + G [ j ] ) NEW_LINE if n > G [ i , j ] : NEW_LINE INDENT ans += G [ i , j ] NEW_LINE DEDENT DEDENT DEDENT print ( ans ) NEW_LINE DEDENT
|
T728 | import java . util . * ; import java . util . stream . Stream ; public class Main { private static int N ; private static int A [ ] [ ] ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; N = sc . nextInt ( ) ; A = new int [ N ] [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) { A [ i ] [ j ] = sc . nextInt ( ) ; } } System . out . println ( solve ( ) ) ; } static long solve ( ) { boolean [ ] [ ] indirect = new boolean [ N ] [ N ] ; for ( int i = 0 ; i < N - 1 ; i ++ ) { for ( int j = i + 1 ; j < N ; j ++ ) { for ( int k = 0 ; k < N ; k ++ ) { if ( k == i || k == j ) continue ; int ikj = A [ i ] [ k ] + A [ k ] [ j ] ; int ij = A [ i ] [ j ] ; if ( ikj < ij ) { return - 1 ; } else if ( ikj == ij ) { indirect [ i ] [ j ] = true ; } } } } long ans = 0 ; for ( int i = 0 ; i < N - 1 ; i ++ ) { for ( int j = i + 1 ; j < N ; j ++ ) { if ( ! indirect [ i ] [ j ] ) { ans += A [ i ] [ j ] ; } } } return ans ; } }
| def solve ( n , tbl ) : NEW_LINE INDENT ans = 0 NEW_LINE for i , row_i in enumerate ( tbl ) : NEW_LINE INDENT for j in range ( i + 1 , n ) : NEW_LINE INDENT row_j = tbl [ j ] NEW_LINE ij = row_i [ j ] NEW_LINE mind = min ( ( ik + kj for ik , kj in zip ( row_i , row_j ) if ik and kj ) , default = float ( ' inf ' ) ) NEW_LINE if ij > mind : NEW_LINE INDENT return - 1 NEW_LINE DEDENT if ij < mind : NEW_LINE INDENT ans += ij NEW_LINE DEDENT DEDENT DEDENT return ans NEW_LINE DEDENT n = int ( input ( ) ) NEW_LINE tbl = [ list ( map ( int , input ( ) . split ( ) ) ) for _ in range ( n ) ] NEW_LINE print ( solve ( n , tbl ) ) NEW_LINE
|
T729 | import java . util . * ; import java . util . stream . Stream ; public class Main { private static int N ; private static int A [ ] [ ] ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; N = sc . nextInt ( ) ; A = new int [ N ] [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) { A [ i ] [ j ] = sc . nextInt ( ) ; } } System . out . println ( solve ( ) ) ; } static long solve ( ) { boolean [ ] [ ] indirect = new boolean [ N ] [ N ] ; for ( int i = 0 ; i < N - 1 ; i ++ ) { for ( int j = i + 1 ; j < N ; j ++ ) { for ( int k = 0 ; k < N ; k ++ ) { if ( k == i || k == j ) continue ; int ikj = A [ i ] [ k ] + A [ k ] [ j ] ; int ij = A [ i ] [ j ] ; if ( ikj < ij ) { return - 1 ; } else if ( ikj == ij ) { indirect [ i ] [ j ] = true ; } } } } long ans = 0 ; for ( int i = 0 ; i < N - 1 ; i ++ ) { for ( int j = i + 1 ; j < N ; j ++ ) { if ( ! indirect [ i ] [ j ] ) { ans += A [ i ] [ j ] ; } } } return ans ; } }
| N = int ( input ( ) ) NEW_LINE inf = float ( " inf " ) NEW_LINE A = [ list ( map ( int , input ( ) . split ( ) ) ) for _ in [ 0 ] * N ] NEW_LINE for i in range ( N ) : NEW_LINE INDENT A [ i ] [ i ] = inf NEW_LINE DEDENT result = 0 NEW_LINE for i in range ( N - 1 ) : NEW_LINE INDENT for j , dist in enumerate ( A [ i ] [ i + 1 : ] , start = i + 1 ) : NEW_LINE INDENT for _A in A : NEW_LINE INDENT if dist >= _A [ i ] + _A [ j ] : NEW_LINE INDENT if dist > _A [ i ] + _A [ j ] : NEW_LINE INDENT print ( - 1 ) NEW_LINE exit ( ) NEW_LINE DEDENT break NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT result += dist NEW_LINE DEDENT DEDENT DEDENT print ( result ) NEW_LINE
|
T730 | import java . util . * ; import java . util . stream . Stream ; public class Main { private static int N ; private static int A [ ] [ ] ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; N = sc . nextInt ( ) ; A = new int [ N ] [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) { A [ i ] [ j ] = sc . nextInt ( ) ; } } System . out . println ( solve ( ) ) ; } static long solve ( ) { boolean [ ] [ ] indirect = new boolean [ N ] [ N ] ; for ( int i = 0 ; i < N - 1 ; i ++ ) { for ( int j = i + 1 ; j < N ; j ++ ) { for ( int k = 0 ; k < N ; k ++ ) { if ( k == i || k == j ) continue ; int ikj = A [ i ] [ k ] + A [ k ] [ j ] ; int ij = A [ i ] [ j ] ; if ( ikj < ij ) { return - 1 ; } else if ( ikj == ij ) { indirect [ i ] [ j ] = true ; } } } } long ans = 0 ; for ( int i = 0 ; i < N - 1 ; i ++ ) { for ( int j = i + 1 ; j < N ; j ++ ) { if ( ! indirect [ i ] [ j ] ) { ans += A [ i ] [ j ] ; } } } return ans ; } }
| import numpy as np NEW_LINE N = int ( input ( ) ) NEW_LINE dist = [ [ 0.0 for _ in range ( N ) ] for _ in range ( N ) ] NEW_LINE for i in range ( N ) : NEW_LINE INDENT for j , x in enumerate ( map ( int , input ( ) . split ( ) ) ) : NEW_LINE INDENT dist [ i ] [ j ] = float ( x ) NEW_LINE DEDENT DEDENT dist = np . array ( dist ) NEW_LINE for i in range ( N ) : NEW_LINE INDENT dist [ i , i ] = float ( ' inf ' ) NEW_LINE DEDENT ans = 0 NEW_LINE for i in range ( N ) : NEW_LINE INDENT for j in range ( i + 1 , N ) : NEW_LINE INDENT min_ = min ( dist [ i ] + dist [ j ] ) NEW_LINE if min_ < dist [ i , j ] : NEW_LINE INDENT ans = - 1 NEW_LINE break NEW_LINE DEDENT elif min_ > dist [ i , j ] : NEW_LINE INDENT ans += dist [ i , j ] NEW_LINE DEDENT DEDENT if ans < 0 : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT print ( int ( ans ) ) NEW_LINE
|
T731 | import java . util . Scanner ; public class Main { static int n ; static int [ ] [ ] dist ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; n = sc . nextInt ( ) ; dist = new int [ n ] [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { dist [ i ] [ j ] = sc . nextInt ( ) ; } } long sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { sum += ( long ) dist [ i ] [ j ] ; } } boolean [ ] [ ] subtracted = new boolean [ n ] [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { for ( int k = 0 ; k < n ; k ++ ) { if ( k == i || k == j ) { continue ; } if ( dist [ i ] [ j ] > dist [ i ] [ k ] + dist [ k ] [ j ] ) { System . out . println ( - 1 ) ; return ; } if ( ! subtracted [ i ] [ j ] && dist [ i ] [ j ] == dist [ i ] [ k ] + dist [ k ] [ j ] ) { sum -= ( long ) dist [ i ] [ j ] ; subtracted [ i ] [ j ] = true ; } } } } System . out . println ( sum ) ; } }
| def inpl ( ) : return [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE import sys NEW_LINE import numpy NEW_LINE N = int ( input ( ) ) NEW_LINE A = numpy . asarray ( [ inpl ( ) for _ in range ( N ) ] ) NEW_LINE ans = 0 NEW_LINE for i in range ( N ) : NEW_LINE INDENT A [ i ] [ i ] = 10 ** 9 + 1 NEW_LINE DEDENT for i in range ( N ) : NEW_LINE INDENT for j in range ( i ) : NEW_LINE INDENT mindis = numpy . min ( [ A [ i ] + A [ j ] ] ) NEW_LINE if mindis > A [ i ] [ j ] : NEW_LINE INDENT ans += A [ i ] [ j ] NEW_LINE continue NEW_LINE DEDENT if mindis < A [ i ] [ j ] : NEW_LINE INDENT print ( - 1 ) NEW_LINE sys . exit ( ) NEW_LINE DEDENT DEDENT DEDENT print ( ans ) NEW_LINE
|
T732 | import java . util . Scanner ; public class Main { static int n ; static int [ ] [ ] dist ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; n = sc . nextInt ( ) ; dist = new int [ n ] [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { dist [ i ] [ j ] = sc . nextInt ( ) ; } } long sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { sum += ( long ) dist [ i ] [ j ] ; } } boolean [ ] [ ] subtracted = new boolean [ n ] [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { for ( int k = 0 ; k < n ; k ++ ) { if ( k == i || k == j ) { continue ; } if ( dist [ i ] [ j ] > dist [ i ] [ k ] + dist [ k ] [ j ] ) { System . out . println ( - 1 ) ; return ; } if ( ! subtracted [ i ] [ j ] && dist [ i ] [ j ] == dist [ i ] [ k ] + dist [ k ] [ j ] ) { sum -= ( long ) dist [ i ] [ j ] ; subtracted [ i ] [ j ] = true ; } } } } System . out . println ( sum ) ; } }
| import numpy as np NEW_LINE import scipy . sparse . csgraph as csg NEW_LINE if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT N = int ( input ( ) ) NEW_LINE A = [ list ( map ( int , input ( ) . split ( ) ) ) for i in range ( N ) ] NEW_LINE G = np . asarray ( A , dtype = np . uint32 ) NEW_LINE G2 = csg . floyd_warshall ( G , directed = False ) NEW_LINE if np . any ( G != G2 ) : NEW_LINE INDENT print ( - 1 ) NEW_LINE exit ( ) NEW_LINE DEDENT ans = 0 NEW_LINE G [ G == 0 ] = 1 NEW_LINE for i in range ( N ) : NEW_LINE INDENT for j in range ( i + 1 , N ) : NEW_LINE INDENT n = np . min ( G [ i ] + G [ j ] ) NEW_LINE if n > G [ i , j ] : NEW_LINE INDENT ans += G [ i , j ] NEW_LINE DEDENT DEDENT DEDENT print ( ans ) NEW_LINE DEDENT
|
T733 | import java . util . Scanner ; public class Main { static int n ; static int [ ] [ ] dist ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; n = sc . nextInt ( ) ; dist = new int [ n ] [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { dist [ i ] [ j ] = sc . nextInt ( ) ; } } long sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { sum += ( long ) dist [ i ] [ j ] ; } } boolean [ ] [ ] subtracted = new boolean [ n ] [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { for ( int k = 0 ; k < n ; k ++ ) { if ( k == i || k == j ) { continue ; } if ( dist [ i ] [ j ] > dist [ i ] [ k ] + dist [ k ] [ j ] ) { System . out . println ( - 1 ) ; return ; } if ( ! subtracted [ i ] [ j ] && dist [ i ] [ j ] == dist [ i ] [ k ] + dist [ k ] [ j ] ) { sum -= ( long ) dist [ i ] [ j ] ; subtracted [ i ] [ j ] = true ; } } } } System . out . println ( sum ) ; } }
| def solve ( n , tbl ) : NEW_LINE INDENT ans = 0 NEW_LINE for i , row_i in enumerate ( tbl ) : NEW_LINE INDENT for j in range ( i + 1 , n ) : NEW_LINE INDENT row_j = tbl [ j ] NEW_LINE ij = row_i [ j ] NEW_LINE mind = min ( ( ik + kj for ik , kj in zip ( row_i , row_j ) if ik and kj ) , default = float ( ' inf ' ) ) NEW_LINE if ij > mind : NEW_LINE INDENT return - 1 NEW_LINE DEDENT if ij < mind : NEW_LINE INDENT ans += ij NEW_LINE DEDENT DEDENT DEDENT return ans NEW_LINE DEDENT n = int ( input ( ) ) NEW_LINE tbl = [ list ( map ( int , input ( ) . split ( ) ) ) for _ in range ( n ) ] NEW_LINE print ( solve ( n , tbl ) ) NEW_LINE
|
T734 | import java . util . Scanner ; public class Main { static int n ; static int [ ] [ ] dist ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; n = sc . nextInt ( ) ; dist = new int [ n ] [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { dist [ i ] [ j ] = sc . nextInt ( ) ; } } long sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { sum += ( long ) dist [ i ] [ j ] ; } } boolean [ ] [ ] subtracted = new boolean [ n ] [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { for ( int k = 0 ; k < n ; k ++ ) { if ( k == i || k == j ) { continue ; } if ( dist [ i ] [ j ] > dist [ i ] [ k ] + dist [ k ] [ j ] ) { System . out . println ( - 1 ) ; return ; } if ( ! subtracted [ i ] [ j ] && dist [ i ] [ j ] == dist [ i ] [ k ] + dist [ k ] [ j ] ) { sum -= ( long ) dist [ i ] [ j ] ; subtracted [ i ] [ j ] = true ; } } } } System . out . println ( sum ) ; } }
| N = int ( input ( ) ) NEW_LINE inf = float ( " inf " ) NEW_LINE A = [ list ( map ( int , input ( ) . split ( ) ) ) for _ in [ 0 ] * N ] NEW_LINE for i in range ( N ) : NEW_LINE INDENT A [ i ] [ i ] = inf NEW_LINE DEDENT result = 0 NEW_LINE for i in range ( N - 1 ) : NEW_LINE INDENT for j , dist in enumerate ( A [ i ] [ i + 1 : ] , start = i + 1 ) : NEW_LINE INDENT for _A in A : NEW_LINE INDENT if dist >= _A [ i ] + _A [ j ] : NEW_LINE INDENT if dist > _A [ i ] + _A [ j ] : NEW_LINE INDENT print ( - 1 ) NEW_LINE exit ( ) NEW_LINE DEDENT break NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT result += dist NEW_LINE DEDENT DEDENT DEDENT print ( result ) NEW_LINE
|
T735 | import java . util . Scanner ; public class Main { static int n ; static int [ ] [ ] dist ; public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; n = sc . nextInt ( ) ; dist = new int [ n ] [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { dist [ i ] [ j ] = sc . nextInt ( ) ; } } long sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { sum += ( long ) dist [ i ] [ j ] ; } } boolean [ ] [ ] subtracted = new boolean [ n ] [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { for ( int k = 0 ; k < n ; k ++ ) { if ( k == i || k == j ) { continue ; } if ( dist [ i ] [ j ] > dist [ i ] [ k ] + dist [ k ] [ j ] ) { System . out . println ( - 1 ) ; return ; } if ( ! subtracted [ i ] [ j ] && dist [ i ] [ j ] == dist [ i ] [ k ] + dist [ k ] [ j ] ) { sum -= ( long ) dist [ i ] [ j ] ; subtracted [ i ] [ j ] = true ; } } } } System . out . println ( sum ) ; } }
| import numpy as np NEW_LINE N = int ( input ( ) ) NEW_LINE dist = [ [ 0.0 for _ in range ( N ) ] for _ in range ( N ) ] NEW_LINE for i in range ( N ) : NEW_LINE INDENT for j , x in enumerate ( map ( int , input ( ) . split ( ) ) ) : NEW_LINE INDENT dist [ i ] [ j ] = float ( x ) NEW_LINE DEDENT DEDENT dist = np . array ( dist ) NEW_LINE for i in range ( N ) : NEW_LINE INDENT dist [ i , i ] = float ( ' inf ' ) NEW_LINE DEDENT ans = 0 NEW_LINE for i in range ( N ) : NEW_LINE INDENT for j in range ( i + 1 , N ) : NEW_LINE INDENT min_ = min ( dist [ i ] + dist [ j ] ) NEW_LINE if min_ < dist [ i , j ] : NEW_LINE INDENT ans = - 1 NEW_LINE break NEW_LINE DEDENT elif min_ > dist [ i , j ] : NEW_LINE INDENT ans += dist [ i , j ] NEW_LINE DEDENT DEDENT if ans < 0 : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT print ( int ( ans ) ) NEW_LINE
|
T736 | 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 ( ) ; long [ ] [ ] A = new long [ N ] [ N ] ; long [ ] [ ] D = new long [ N ] [ N ] ; Boolean nes [ ] [ ] = new Boolean [ N ] [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) { A [ i ] [ j ] = sc . nextLong ( ) ; if ( A [ i ] [ j ] == 0 && i != j ) { A [ i ] [ j ] = ( long ) 10e12 ; } D [ i ] [ j ] = A [ i ] [ j ] ; nes [ i ] [ j ] = true ; } } for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) { for ( int k = 0 ; k < N ; k ++ ) { if ( j != i && k != i && D [ j ] [ k ] == D [ j ] [ i ] + D [ i ] [ k ] ) { nes [ j ] [ k ] = false ; } D [ j ] [ k ] = Math . min ( D [ j ] [ k ] , D [ j ] [ i ] + D [ i ] [ k ] ) ; } } } long ans = 0 ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = i + 1 ; j < N ; j ++ ) { if ( A [ i ] [ j ] != D [ i ] [ j ] ) { System . out . println ( - 1 ) ; return ; } if ( nes [ i ] [ j ] ) { ans += D [ i ] [ j ] ; } } } System . out . println ( ans ) ; } }
| def inpl ( ) : return [ int ( i ) for i in input ( ) . split ( ) ] NEW_LINE import sys NEW_LINE import numpy NEW_LINE N = int ( input ( ) ) NEW_LINE A = numpy . asarray ( [ inpl ( ) for _ in range ( N ) ] ) NEW_LINE ans = 0 NEW_LINE for i in range ( N ) : NEW_LINE INDENT A [ i ] [ i ] = 10 ** 9 + 1 NEW_LINE DEDENT for i in range ( N ) : NEW_LINE INDENT for j in range ( i ) : NEW_LINE INDENT mindis = numpy . min ( [ A [ i ] + A [ j ] ] ) NEW_LINE if mindis > A [ i ] [ j ] : NEW_LINE INDENT ans += A [ i ] [ j ] NEW_LINE continue NEW_LINE DEDENT if mindis < A [ i ] [ j ] : NEW_LINE INDENT print ( - 1 ) NEW_LINE sys . exit ( ) NEW_LINE DEDENT DEDENT DEDENT print ( ans ) NEW_LINE
|
T737 | 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 ( ) ; long [ ] [ ] A = new long [ N ] [ N ] ; long [ ] [ ] D = new long [ N ] [ N ] ; Boolean nes [ ] [ ] = new Boolean [ N ] [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) { A [ i ] [ j ] = sc . nextLong ( ) ; if ( A [ i ] [ j ] == 0 && i != j ) { A [ i ] [ j ] = ( long ) 10e12 ; } D [ i ] [ j ] = A [ i ] [ j ] ; nes [ i ] [ j ] = true ; } } for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) { for ( int k = 0 ; k < N ; k ++ ) { if ( j != i && k != i && D [ j ] [ k ] == D [ j ] [ i ] + D [ i ] [ k ] ) { nes [ j ] [ k ] = false ; } D [ j ] [ k ] = Math . min ( D [ j ] [ k ] , D [ j ] [ i ] + D [ i ] [ k ] ) ; } } } long ans = 0 ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = i + 1 ; j < N ; j ++ ) { if ( A [ i ] [ j ] != D [ i ] [ j ] ) { System . out . println ( - 1 ) ; return ; } if ( nes [ i ] [ j ] ) { ans += D [ i ] [ j ] ; } } } System . out . println ( ans ) ; } }
| import numpy as np NEW_LINE import scipy . sparse . csgraph as csg NEW_LINE if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT N = int ( input ( ) ) NEW_LINE A = [ list ( map ( int , input ( ) . split ( ) ) ) for i in range ( N ) ] NEW_LINE G = np . asarray ( A , dtype = np . uint32 ) NEW_LINE G2 = csg . floyd_warshall ( G , directed = False ) NEW_LINE if np . any ( G != G2 ) : NEW_LINE INDENT print ( - 1 ) NEW_LINE exit ( ) NEW_LINE DEDENT ans = 0 NEW_LINE G [ G == 0 ] = 1 NEW_LINE for i in range ( N ) : NEW_LINE INDENT for j in range ( i + 1 , N ) : NEW_LINE INDENT n = np . min ( G [ i ] + G [ j ] ) NEW_LINE if n > G [ i , j ] : NEW_LINE INDENT ans += G [ i , j ] NEW_LINE DEDENT DEDENT DEDENT print ( ans ) NEW_LINE DEDENT
|
T738 | 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 ( ) ; long [ ] [ ] A = new long [ N ] [ N ] ; long [ ] [ ] D = new long [ N ] [ N ] ; Boolean nes [ ] [ ] = new Boolean [ N ] [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) { A [ i ] [ j ] = sc . nextLong ( ) ; if ( A [ i ] [ j ] == 0 && i != j ) { A [ i ] [ j ] = ( long ) 10e12 ; } D [ i ] [ j ] = A [ i ] [ j ] ; nes [ i ] [ j ] = true ; } } for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) { for ( int k = 0 ; k < N ; k ++ ) { if ( j != i && k != i && D [ j ] [ k ] == D [ j ] [ i ] + D [ i ] [ k ] ) { nes [ j ] [ k ] = false ; } D [ j ] [ k ] = Math . min ( D [ j ] [ k ] , D [ j ] [ i ] + D [ i ] [ k ] ) ; } } } long ans = 0 ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = i + 1 ; j < N ; j ++ ) { if ( A [ i ] [ j ] != D [ i ] [ j ] ) { System . out . println ( - 1 ) ; return ; } if ( nes [ i ] [ j ] ) { ans += D [ i ] [ j ] ; } } } System . out . println ( ans ) ; } }
| def solve ( n , tbl ) : NEW_LINE INDENT ans = 0 NEW_LINE for i , row_i in enumerate ( tbl ) : NEW_LINE INDENT for j in range ( i + 1 , n ) : NEW_LINE INDENT row_j = tbl [ j ] NEW_LINE ij = row_i [ j ] NEW_LINE mind = min ( ( ik + kj for ik , kj in zip ( row_i , row_j ) if ik and kj ) , default = float ( ' inf ' ) ) NEW_LINE if ij > mind : NEW_LINE INDENT return - 1 NEW_LINE DEDENT if ij < mind : NEW_LINE INDENT ans += ij NEW_LINE DEDENT DEDENT DEDENT return ans NEW_LINE DEDENT n = int ( input ( ) ) NEW_LINE tbl = [ list ( map ( int , input ( ) . split ( ) ) ) for _ in range ( n ) ] NEW_LINE print ( solve ( n , tbl ) ) NEW_LINE
|
T739 | 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 ( ) ; long [ ] [ ] A = new long [ N ] [ N ] ; long [ ] [ ] D = new long [ N ] [ N ] ; Boolean nes [ ] [ ] = new Boolean [ N ] [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) { A [ i ] [ j ] = sc . nextLong ( ) ; if ( A [ i ] [ j ] == 0 && i != j ) { A [ i ] [ j ] = ( long ) 10e12 ; } D [ i ] [ j ] = A [ i ] [ j ] ; nes [ i ] [ j ] = true ; } } for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) { for ( int k = 0 ; k < N ; k ++ ) { if ( j != i && k != i && D [ j ] [ k ] == D [ j ] [ i ] + D [ i ] [ k ] ) { nes [ j ] [ k ] = false ; } D [ j ] [ k ] = Math . min ( D [ j ] [ k ] , D [ j ] [ i ] + D [ i ] [ k ] ) ; } } } long ans = 0 ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = i + 1 ; j < N ; j ++ ) { if ( A [ i ] [ j ] != D [ i ] [ j ] ) { System . out . println ( - 1 ) ; return ; } if ( nes [ i ] [ j ] ) { ans += D [ i ] [ j ] ; } } } System . out . println ( ans ) ; } }
| N = int ( input ( ) ) NEW_LINE inf = float ( " inf " ) NEW_LINE A = [ list ( map ( int , input ( ) . split ( ) ) ) for _ in [ 0 ] * N ] NEW_LINE for i in range ( N ) : NEW_LINE INDENT A [ i ] [ i ] = inf NEW_LINE DEDENT result = 0 NEW_LINE for i in range ( N - 1 ) : NEW_LINE INDENT for j , dist in enumerate ( A [ i ] [ i + 1 : ] , start = i + 1 ) : NEW_LINE INDENT for _A in A : NEW_LINE INDENT if dist >= _A [ i ] + _A [ j ] : NEW_LINE INDENT if dist > _A [ i ] + _A [ j ] : NEW_LINE INDENT print ( - 1 ) NEW_LINE exit ( ) NEW_LINE DEDENT break NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT result += dist NEW_LINE DEDENT DEDENT DEDENT print ( result ) NEW_LINE
|
T740 | 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 ( ) ; long [ ] [ ] A = new long [ N ] [ N ] ; long [ ] [ ] D = new long [ N ] [ N ] ; Boolean nes [ ] [ ] = new Boolean [ N ] [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) { A [ i ] [ j ] = sc . nextLong ( ) ; if ( A [ i ] [ j ] == 0 && i != j ) { A [ i ] [ j ] = ( long ) 10e12 ; } D [ i ] [ j ] = A [ i ] [ j ] ; nes [ i ] [ j ] = true ; } } for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) { for ( int k = 0 ; k < N ; k ++ ) { if ( j != i && k != i && D [ j ] [ k ] == D [ j ] [ i ] + D [ i ] [ k ] ) { nes [ j ] [ k ] = false ; } D [ j ] [ k ] = Math . min ( D [ j ] [ k ] , D [ j ] [ i ] + D [ i ] [ k ] ) ; } } } long ans = 0 ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = i + 1 ; j < N ; j ++ ) { if ( A [ i ] [ j ] != D [ i ] [ j ] ) { System . out . println ( - 1 ) ; return ; } if ( nes [ i ] [ j ] ) { ans += D [ i ] [ j ] ; } } } System . out . println ( ans ) ; } }
| import numpy as np NEW_LINE N = int ( input ( ) ) NEW_LINE dist = [ [ 0.0 for _ in range ( N ) ] for _ in range ( N ) ] NEW_LINE for i in range ( N ) : NEW_LINE INDENT for j , x in enumerate ( map ( int , input ( ) . split ( ) ) ) : NEW_LINE INDENT dist [ i ] [ j ] = float ( x ) NEW_LINE DEDENT DEDENT dist = np . array ( dist ) NEW_LINE for i in range ( N ) : NEW_LINE INDENT dist [ i , i ] = float ( ' inf ' ) NEW_LINE DEDENT ans = 0 NEW_LINE for i in range ( N ) : NEW_LINE INDENT for j in range ( i + 1 , N ) : NEW_LINE INDENT min_ = min ( dist [ i ] + dist [ j ] ) NEW_LINE if min_ < dist [ i , j ] : NEW_LINE INDENT ans = - 1 NEW_LINE break NEW_LINE DEDENT elif min_ > dist [ i , j ] : NEW_LINE INDENT ans += dist [ i , j ] NEW_LINE DEDENT DEDENT if ans < 0 : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT print ( int ( ans ) ) NEW_LINE
|
T741 | import java . util . Collections ; import java . util . HashMap ; import java . util . HashSet ; import java . util . Map ; import java . util . Scanner ; import java . util . Set ; import java . util . TreeMap ; import java . util . Map . Entry ; public class Main { public static void main ( String [ ] args ) { try ( Scanner sc = new Scanner ( System . in ) ; ) { new Main ( ) . solve ( sc ) ; } } void solve ( Scanner sc ) { int n = sc . nextInt ( ) ; Map < Integer , Integer > aMap = new TreeMap < > ( ( x , y ) -> y - x ) ; for ( int i = 0 ; i < n ; i ++ ) { int a = sc . nextInt ( ) ; Integer count = aMap . getOrDefault ( a , 0 ) + 1 ; aMap . put ( a , count ) ; } long x = 0 ; for ( Entry < Integer , Integer > e : aMap . entrySet ( ) ) { if ( e . getValue ( ) >= 4 && x == 0 ) { System . out . println ( ( long ) e . getKey ( ) * e . getKey ( ) ) ; return ; } if ( e . getValue ( ) >= 2 && x == 0 ) { x = e . getKey ( ) ; continue ; } if ( e . getValue ( ) >= 2 ) { System . out . println ( x * e . getKey ( ) ) ; return ; } } System . out . println ( 0 ) ; } }
| import sys NEW_LINE import collections NEW_LINE ns = lambda : sys . stdin . readline ( ) . rstrip ( ) NEW_LINE ni = lambda : int ( ns ( ) ) NEW_LINE nm = lambda : map ( int , sys . stdin . readline ( ) . split ( ) ) NEW_LINE nl = lambda : list ( nm ( ) ) NEW_LINE nsl = lambda : map ( str , sys . stdin . readline ( ) . split ( ) ) NEW_LINE n = ni ( ) NEW_LINE a = nl ( ) NEW_LINE c = collections . Counter ( a ) NEW_LINE key = list ( c . keys ( ) ) NEW_LINE key . sort ( reverse = True ) NEW_LINE count = 0 NEW_LINE for i in range ( len ( key ) ) : NEW_LINE INDENT if c [ key [ i ] ] >= 4 and count != 1 : NEW_LINE INDENT print ( key [ i ] ** 2 ) NEW_LINE exit ( ) NEW_LINE DEDENT if c [ key [ i ] ] >= 2 : NEW_LINE INDENT if count == 0 : NEW_LINE INDENT a = key [ i ] NEW_LINE count += 1 NEW_LINE DEDENT elif count == 1 : NEW_LINE INDENT b = key [ i ] NEW_LINE count += 1 NEW_LINE DEDENT DEDENT if count >= 2 : NEW_LINE INDENT print ( a * b ) NEW_LINE exit ( ) NEW_LINE DEDENT DEDENT print ( 0 ) NEW_LINE
|
T742 | import java . util . Collections ; import java . util . HashMap ; import java . util . HashSet ; import java . util . Map ; import java . util . Scanner ; import java . util . Set ; import java . util . TreeMap ; import java . util . Map . Entry ; public class Main { public static void main ( String [ ] args ) { try ( Scanner sc = new Scanner ( System . in ) ; ) { new Main ( ) . solve ( sc ) ; } } void solve ( Scanner sc ) { int n = sc . nextInt ( ) ; Map < Integer , Integer > aMap = new TreeMap < > ( ( x , y ) -> y - x ) ; for ( int i = 0 ; i < n ; i ++ ) { int a = sc . nextInt ( ) ; Integer count = aMap . getOrDefault ( a , 0 ) + 1 ; aMap . put ( a , count ) ; } long x = 0 ; for ( Entry < Integer , Integer > e : aMap . entrySet ( ) ) { if ( e . getValue ( ) >= 4 && x == 0 ) { System . out . println ( ( long ) e . getKey ( ) * e . getKey ( ) ) ; return ; } if ( e . getValue ( ) >= 2 && x == 0 ) { x = e . getKey ( ) ; continue ; } if ( e . getValue ( ) >= 2 ) { System . out . println ( x * e . getKey ( ) ) ; return ; } } System . out . println ( 0 ) ; } }
| N = int ( input ( ) ) NEW_LINE A = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE dic = { } NEW_LINE max1 , max2 = 0 , 0 NEW_LINE count = 0 NEW_LINE for i in range ( N ) : NEW_LINE INDENT if ( A [ i ] in dic ) : NEW_LINE INDENT dic [ A [ i ] ] += 1 NEW_LINE if ( dic [ A [ i ] ] % 2 == 0 ) : NEW_LINE INDENT count += 1 NEW_LINE if ( max1 < A [ i ] ) : NEW_LINE INDENT max2 = max1 NEW_LINE max1 = A [ i ] NEW_LINE DEDENT if ( A [ i ] < max1 ) : NEW_LINE INDENT max2 = max ( max2 , A [ i ] ) NEW_LINE DEDENT DEDENT DEDENT else : NEW_LINE INDENT dic [ A [ i ] ] = 1 NEW_LINE DEDENT DEDENT ans = 0 NEW_LINE if ( count >= 2 ) : NEW_LINE INDENT if ( dic [ max1 ] >= 4 ) : NEW_LINE INDENT ans = max1 * max1 NEW_LINE DEDENT else : NEW_LINE INDENT ans = max1 * max2 NEW_LINE DEDENT DEDENT print ( ans ) NEW_LINE
|
T743 | import java . util . Collections ; import java . util . HashMap ; import java . util . HashSet ; import java . util . Map ; import java . util . Scanner ; import java . util . Set ; import java . util . TreeMap ; import java . util . Map . Entry ; public class Main { public static void main ( String [ ] args ) { try ( Scanner sc = new Scanner ( System . in ) ; ) { new Main ( ) . solve ( sc ) ; } } void solve ( Scanner sc ) { int n = sc . nextInt ( ) ; Map < Integer , Integer > aMap = new TreeMap < > ( ( x , y ) -> y - x ) ; for ( int i = 0 ; i < n ; i ++ ) { int a = sc . nextInt ( ) ; Integer count = aMap . getOrDefault ( a , 0 ) + 1 ; aMap . put ( a , count ) ; } long x = 0 ; for ( Entry < Integer , Integer > e : aMap . entrySet ( ) ) { if ( e . getValue ( ) >= 4 && x == 0 ) { System . out . println ( ( long ) e . getKey ( ) * e . getKey ( ) ) ; return ; } if ( e . getValue ( ) >= 2 && x == 0 ) { x = e . getKey ( ) ; continue ; } if ( e . getValue ( ) >= 2 ) { System . out . println ( x * e . getKey ( ) ) ; return ; } } System . out . println ( 0 ) ; } }
| N = int ( input ( ) ) NEW_LINE A = [ int ( a ) for a in input ( ) . split ( ) ] NEW_LINE d = { } NEW_LINE for a in A : NEW_LINE INDENT d [ a ] = d . get ( a , 0 ) + 1 NEW_LINE DEDENT B = [ 0 , 0 ] NEW_LINE for k in d : NEW_LINE INDENT if d [ k ] >= 4 : NEW_LINE INDENT B . append ( k ) NEW_LINE B . append ( k ) NEW_LINE DEDENT elif d [ k ] >= 2 : NEW_LINE INDENT B . append ( k ) NEW_LINE DEDENT DEDENT B . sort ( ) NEW_LINE print ( B [ - 1 ] * B [ - 2 ] ) NEW_LINE
|
T744 | import java . util . Collections ; import java . util . HashMap ; import java . util . HashSet ; import java . util . Map ; import java . util . Scanner ; import java . util . Set ; import java . util . TreeMap ; import java . util . Map . Entry ; public class Main { public static void main ( String [ ] args ) { try ( Scanner sc = new Scanner ( System . in ) ; ) { new Main ( ) . solve ( sc ) ; } } void solve ( Scanner sc ) { int n = sc . nextInt ( ) ; Map < Integer , Integer > aMap = new TreeMap < > ( ( x , y ) -> y - x ) ; for ( int i = 0 ; i < n ; i ++ ) { int a = sc . nextInt ( ) ; Integer count = aMap . getOrDefault ( a , 0 ) + 1 ; aMap . put ( a , count ) ; } long x = 0 ; for ( Entry < Integer , Integer > e : aMap . entrySet ( ) ) { if ( e . getValue ( ) >= 4 && x == 0 ) { System . out . println ( ( long ) e . getKey ( ) * e . getKey ( ) ) ; return ; } if ( e . getValue ( ) >= 2 && x == 0 ) { x = e . getKey ( ) ; continue ; } if ( e . getValue ( ) >= 2 ) { System . out . println ( x * e . getKey ( ) ) ; return ; } } System . out . println ( 0 ) ; } }
| import array NEW_LINE from bisect import * NEW_LINE from collections import * NEW_LINE import fractions NEW_LINE import heapq NEW_LINE from itertools import * NEW_LINE import math NEW_LINE import random NEW_LINE import re NEW_LINE import string NEW_LINE import sys NEW_LINE N = int ( input ( ) ) NEW_LINE As = map ( int , input ( ) . split ( ) ) NEW_LINE c = Counter ( As ) NEW_LINE ans = [ ] NEW_LINE for k in reversed ( sorted ( c . keys ( ) ) ) : NEW_LINE INDENT v = c [ k ] NEW_LINE while v >= 2 : NEW_LINE INDENT ans . append ( k ) NEW_LINE v -= 2 NEW_LINE if len ( ans ) == 2 : NEW_LINE INDENT print ( ans [ 0 ] * ans [ 1 ] ) NEW_LINE sys . exit ( 0 ) NEW_LINE DEDENT DEDENT DEDENT print ( 0 ) NEW_LINE
|
T745 | import java . util . Collections ; import java . util . HashMap ; import java . util . HashSet ; import java . util . Map ; import java . util . Scanner ; import java . util . Set ; import java . util . TreeMap ; import java . util . Map . Entry ; public class Main { public static void main ( String [ ] args ) { try ( Scanner sc = new Scanner ( System . in ) ; ) { new Main ( ) . solve ( sc ) ; } } void solve ( Scanner sc ) { int n = sc . nextInt ( ) ; Map < Integer , Integer > aMap = new TreeMap < > ( ( x , y ) -> y - x ) ; for ( int i = 0 ; i < n ; i ++ ) { int a = sc . nextInt ( ) ; Integer count = aMap . getOrDefault ( a , 0 ) + 1 ; aMap . put ( a , count ) ; } long x = 0 ; for ( Entry < Integer , Integer > e : aMap . entrySet ( ) ) { if ( e . getValue ( ) >= 4 && x == 0 ) { System . out . println ( ( long ) e . getKey ( ) * e . getKey ( ) ) ; return ; } if ( e . getValue ( ) >= 2 && x == 0 ) { x = e . getKey ( ) ; continue ; } if ( e . getValue ( ) >= 2 ) { System . out . println ( x * e . getKey ( ) ) ; return ; } } System . out . println ( 0 ) ; } }
| from collections import Counter NEW_LINE import sys NEW_LINE h = w = index = 0 NEW_LINE n = int ( input ( ) ) NEW_LINE a = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE l = Counter ( a ) NEW_LINE l2 = sorted ( l . items ( ) , reverse = True ) NEW_LINE for i in range ( len ( l2 ) ) : NEW_LINE INDENT if l2 [ i ] [ 1 ] >= 2 : NEW_LINE INDENT if l2 [ i ] [ 1 ] >= 4 : NEW_LINE INDENT print ( l2 [ i ] [ 0 ] ** 2 ) NEW_LINE sys . exit ( ) NEW_LINE DEDENT w = l2 [ i ] [ 0 ] NEW_LINE index = i NEW_LINE break NEW_LINE DEDENT DEDENT for i in range ( index + 1 , len ( l2 ) ) : NEW_LINE INDENT if l2 [ i ] [ 1 ] >= 2 : NEW_LINE INDENT h = l2 [ i ] [ 0 ] NEW_LINE break NEW_LINE DEDENT DEDENT print ( h * w ) NEW_LINE
|
T746 | import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . * ; public class Main { int n ; public static void main ( String args [ ] ) { new Main ( ) . run ( ) ; } void run ( ) { FastReader sc = new FastReader ( ) ; n = sc . nextInt ( ) ; SortedMap < Integer , Integer > counts = new TreeMap < > ( Collections . reverseOrder ( ) ) ; for ( int i = 0 ; i < n ; i ++ ) { int a = sc . nextInt ( ) ; if ( ! counts . containsKey ( a ) ) { counts . put ( a , 1 ) ; } else { counts . put ( a , counts . get ( a ) + 1 ) ; } } int first = 0 ; int second = 0 ; for ( Map . Entry < Integer , Integer > entry : counts . entrySet ( ) ) { int value = entry . getValue ( ) ; if ( value >= 4 ) { if ( first == 0 ) { first = entry . getKey ( ) ; } second = entry . getKey ( ) ; break ; } else if ( value >= 2 ) { if ( first == 0 ) { first = entry . getKey ( ) ; } else { second = entry . getKey ( ) ; break ; } } } System . out . println ( ( long ) first * second ) ; } 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 sys NEW_LINE import collections NEW_LINE ns = lambda : sys . stdin . readline ( ) . rstrip ( ) NEW_LINE ni = lambda : int ( ns ( ) ) NEW_LINE nm = lambda : map ( int , sys . stdin . readline ( ) . split ( ) ) NEW_LINE nl = lambda : list ( nm ( ) ) NEW_LINE nsl = lambda : map ( str , sys . stdin . readline ( ) . split ( ) ) NEW_LINE n = ni ( ) NEW_LINE a = nl ( ) NEW_LINE c = collections . Counter ( a ) NEW_LINE key = list ( c . keys ( ) ) NEW_LINE key . sort ( reverse = True ) NEW_LINE count = 0 NEW_LINE for i in range ( len ( key ) ) : NEW_LINE INDENT if c [ key [ i ] ] >= 4 and count != 1 : NEW_LINE INDENT print ( key [ i ] ** 2 ) NEW_LINE exit ( ) NEW_LINE DEDENT if c [ key [ i ] ] >= 2 : NEW_LINE INDENT if count == 0 : NEW_LINE INDENT a = key [ i ] NEW_LINE count += 1 NEW_LINE DEDENT elif count == 1 : NEW_LINE INDENT b = key [ i ] NEW_LINE count += 1 NEW_LINE DEDENT DEDENT if count >= 2 : NEW_LINE INDENT print ( a * b ) NEW_LINE exit ( ) NEW_LINE DEDENT DEDENT print ( 0 ) NEW_LINE
|
T747 | import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . * ; public class Main { int n ; public static void main ( String args [ ] ) { new Main ( ) . run ( ) ; } void run ( ) { FastReader sc = new FastReader ( ) ; n = sc . nextInt ( ) ; SortedMap < Integer , Integer > counts = new TreeMap < > ( Collections . reverseOrder ( ) ) ; for ( int i = 0 ; i < n ; i ++ ) { int a = sc . nextInt ( ) ; if ( ! counts . containsKey ( a ) ) { counts . put ( a , 1 ) ; } else { counts . put ( a , counts . get ( a ) + 1 ) ; } } int first = 0 ; int second = 0 ; for ( Map . Entry < Integer , Integer > entry : counts . entrySet ( ) ) { int value = entry . getValue ( ) ; if ( value >= 4 ) { if ( first == 0 ) { first = entry . getKey ( ) ; } second = entry . getKey ( ) ; break ; } else if ( value >= 2 ) { if ( first == 0 ) { first = entry . getKey ( ) ; } else { second = entry . getKey ( ) ; break ; } } } System . out . println ( ( long ) first * second ) ; } 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 ; } } }
| N = int ( input ( ) ) NEW_LINE A = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE dic = { } NEW_LINE max1 , max2 = 0 , 0 NEW_LINE count = 0 NEW_LINE for i in range ( N ) : NEW_LINE INDENT if ( A [ i ] in dic ) : NEW_LINE INDENT dic [ A [ i ] ] += 1 NEW_LINE if ( dic [ A [ i ] ] % 2 == 0 ) : NEW_LINE INDENT count += 1 NEW_LINE if ( max1 < A [ i ] ) : NEW_LINE INDENT max2 = max1 NEW_LINE max1 = A [ i ] NEW_LINE DEDENT if ( A [ i ] < max1 ) : NEW_LINE INDENT max2 = max ( max2 , A [ i ] ) NEW_LINE DEDENT DEDENT DEDENT else : NEW_LINE INDENT dic [ A [ i ] ] = 1 NEW_LINE DEDENT DEDENT ans = 0 NEW_LINE if ( count >= 2 ) : NEW_LINE INDENT if ( dic [ max1 ] >= 4 ) : NEW_LINE INDENT ans = max1 * max1 NEW_LINE DEDENT else : NEW_LINE INDENT ans = max1 * max2 NEW_LINE DEDENT DEDENT print ( ans ) NEW_LINE
|
T748 | import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . * ; public class Main { int n ; public static void main ( String args [ ] ) { new Main ( ) . run ( ) ; } void run ( ) { FastReader sc = new FastReader ( ) ; n = sc . nextInt ( ) ; SortedMap < Integer , Integer > counts = new TreeMap < > ( Collections . reverseOrder ( ) ) ; for ( int i = 0 ; i < n ; i ++ ) { int a = sc . nextInt ( ) ; if ( ! counts . containsKey ( a ) ) { counts . put ( a , 1 ) ; } else { counts . put ( a , counts . get ( a ) + 1 ) ; } } int first = 0 ; int second = 0 ; for ( Map . Entry < Integer , Integer > entry : counts . entrySet ( ) ) { int value = entry . getValue ( ) ; if ( value >= 4 ) { if ( first == 0 ) { first = entry . getKey ( ) ; } second = entry . getKey ( ) ; break ; } else if ( value >= 2 ) { if ( first == 0 ) { first = entry . getKey ( ) ; } else { second = entry . getKey ( ) ; break ; } } } System . out . println ( ( long ) first * second ) ; } 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 ; } } }
| N = int ( input ( ) ) NEW_LINE A = [ int ( a ) for a in input ( ) . split ( ) ] NEW_LINE d = { } NEW_LINE for a in A : NEW_LINE INDENT d [ a ] = d . get ( a , 0 ) + 1 NEW_LINE DEDENT B = [ 0 , 0 ] NEW_LINE for k in d : NEW_LINE INDENT if d [ k ] >= 4 : NEW_LINE INDENT B . append ( k ) NEW_LINE B . append ( k ) NEW_LINE DEDENT elif d [ k ] >= 2 : NEW_LINE INDENT B . append ( k ) NEW_LINE DEDENT DEDENT B . sort ( ) NEW_LINE print ( B [ - 1 ] * B [ - 2 ] ) NEW_LINE
|
T749 | import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . * ; public class Main { int n ; public static void main ( String args [ ] ) { new Main ( ) . run ( ) ; } void run ( ) { FastReader sc = new FastReader ( ) ; n = sc . nextInt ( ) ; SortedMap < Integer , Integer > counts = new TreeMap < > ( Collections . reverseOrder ( ) ) ; for ( int i = 0 ; i < n ; i ++ ) { int a = sc . nextInt ( ) ; if ( ! counts . containsKey ( a ) ) { counts . put ( a , 1 ) ; } else { counts . put ( a , counts . get ( a ) + 1 ) ; } } int first = 0 ; int second = 0 ; for ( Map . Entry < Integer , Integer > entry : counts . entrySet ( ) ) { int value = entry . getValue ( ) ; if ( value >= 4 ) { if ( first == 0 ) { first = entry . getKey ( ) ; } second = entry . getKey ( ) ; break ; } else if ( value >= 2 ) { if ( first == 0 ) { first = entry . getKey ( ) ; } else { second = entry . getKey ( ) ; break ; } } } System . out . println ( ( long ) first * second ) ; } 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 array NEW_LINE from bisect import * NEW_LINE from collections import * NEW_LINE import fractions NEW_LINE import heapq NEW_LINE from itertools import * NEW_LINE import math NEW_LINE import random NEW_LINE import re NEW_LINE import string NEW_LINE import sys NEW_LINE N = int ( input ( ) ) NEW_LINE As = map ( int , input ( ) . split ( ) ) NEW_LINE c = Counter ( As ) NEW_LINE ans = [ ] NEW_LINE for k in reversed ( sorted ( c . keys ( ) ) ) : NEW_LINE INDENT v = c [ k ] NEW_LINE while v >= 2 : NEW_LINE INDENT ans . append ( k ) NEW_LINE v -= 2 NEW_LINE if len ( ans ) == 2 : NEW_LINE INDENT print ( ans [ 0 ] * ans [ 1 ] ) NEW_LINE sys . exit ( 0 ) NEW_LINE DEDENT DEDENT DEDENT print ( 0 ) NEW_LINE
|
T750 | import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . * ; public class Main { int n ; public static void main ( String args [ ] ) { new Main ( ) . run ( ) ; } void run ( ) { FastReader sc = new FastReader ( ) ; n = sc . nextInt ( ) ; SortedMap < Integer , Integer > counts = new TreeMap < > ( Collections . reverseOrder ( ) ) ; for ( int i = 0 ; i < n ; i ++ ) { int a = sc . nextInt ( ) ; if ( ! counts . containsKey ( a ) ) { counts . put ( a , 1 ) ; } else { counts . put ( a , counts . get ( a ) + 1 ) ; } } int first = 0 ; int second = 0 ; for ( Map . Entry < Integer , Integer > entry : counts . entrySet ( ) ) { int value = entry . getValue ( ) ; if ( value >= 4 ) { if ( first == 0 ) { first = entry . getKey ( ) ; } second = entry . getKey ( ) ; break ; } else if ( value >= 2 ) { if ( first == 0 ) { first = entry . getKey ( ) ; } else { second = entry . getKey ( ) ; break ; } } } System . out . println ( ( long ) first * second ) ; } 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 ; } } }
| from collections import Counter NEW_LINE import sys NEW_LINE h = w = index = 0 NEW_LINE n = int ( input ( ) ) NEW_LINE a = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE l = Counter ( a ) NEW_LINE l2 = sorted ( l . items ( ) , reverse = True ) NEW_LINE for i in range ( len ( l2 ) ) : NEW_LINE INDENT if l2 [ i ] [ 1 ] >= 2 : NEW_LINE INDENT if l2 [ i ] [ 1 ] >= 4 : NEW_LINE INDENT print ( l2 [ i ] [ 0 ] ** 2 ) NEW_LINE sys . exit ( ) NEW_LINE DEDENT w = l2 [ i ] [ 0 ] NEW_LINE index = i NEW_LINE break NEW_LINE DEDENT DEDENT for i in range ( index + 1 , len ( l2 ) ) : NEW_LINE INDENT if l2 [ i ] [ 1 ] >= 2 : NEW_LINE INDENT h = l2 [ i ] [ 0 ] NEW_LINE break NEW_LINE DEDENT DEDENT print ( h * w ) NEW_LINE
|
T751 | import java . util . * ; import java . lang . * ; class Pair implements Comparable < Pair > { long a ; int cnt ; public Pair ( long i , int j ) { this . a = i ; this . cnt = j ; } public int compareTo ( Pair p ) { if ( this . cnt >= 2 && p . cnt >= 2 && this . a < p . a ) return - 1 ; if ( this . cnt < 2 && p . cnt >= 2 ) return - 1 ; return 1 ; } } class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = Integer . parseInt ( sc . next ( ) ) ; HashMap < Long , Pair > map = new HashMap < > ( ) ; ArrayList < Pair > l = new ArrayList < > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { long c = Long . parseLong ( sc . next ( ) ) ; if ( ! map . containsKey ( c ) ) { Pair p = new Pair ( c , 1 ) ; map . put ( c , p ) ; l . add ( p ) ; } else { Pair p = map . get ( c ) ; p . cnt ++ ; } } Collections . sort ( l ) ; int size = l . size ( ) ; Pair p1 = l . get ( size - 1 ) ; Pair p2 = l . get ( size - 2 ) ; long res = 0 ; if ( p1 . cnt >= 4 ) res = p1 . a * p1 . a ; else if ( p1 . cnt >= 2 && p2 . cnt >= 2 ) res = p1 . a * p2 . a ; System . out . println ( res ) ; } }
| import sys NEW_LINE import collections NEW_LINE ns = lambda : sys . stdin . readline ( ) . rstrip ( ) NEW_LINE ni = lambda : int ( ns ( ) ) NEW_LINE nm = lambda : map ( int , sys . stdin . readline ( ) . split ( ) ) NEW_LINE nl = lambda : list ( nm ( ) ) NEW_LINE nsl = lambda : map ( str , sys . stdin . readline ( ) . split ( ) ) NEW_LINE n = ni ( ) NEW_LINE a = nl ( ) NEW_LINE c = collections . Counter ( a ) NEW_LINE key = list ( c . keys ( ) ) NEW_LINE key . sort ( reverse = True ) NEW_LINE count = 0 NEW_LINE for i in range ( len ( key ) ) : NEW_LINE INDENT if c [ key [ i ] ] >= 4 and count != 1 : NEW_LINE INDENT print ( key [ i ] ** 2 ) NEW_LINE exit ( ) NEW_LINE DEDENT if c [ key [ i ] ] >= 2 : NEW_LINE INDENT if count == 0 : NEW_LINE INDENT a = key [ i ] NEW_LINE count += 1 NEW_LINE DEDENT elif count == 1 : NEW_LINE INDENT b = key [ i ] NEW_LINE count += 1 NEW_LINE DEDENT DEDENT if count >= 2 : NEW_LINE INDENT print ( a * b ) NEW_LINE exit ( ) NEW_LINE DEDENT DEDENT print ( 0 ) NEW_LINE
|
T752 | import java . util . * ; import java . lang . * ; class Pair implements Comparable < Pair > { long a ; int cnt ; public Pair ( long i , int j ) { this . a = i ; this . cnt = j ; } public int compareTo ( Pair p ) { if ( this . cnt >= 2 && p . cnt >= 2 && this . a < p . a ) return - 1 ; if ( this . cnt < 2 && p . cnt >= 2 ) return - 1 ; return 1 ; } } class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = Integer . parseInt ( sc . next ( ) ) ; HashMap < Long , Pair > map = new HashMap < > ( ) ; ArrayList < Pair > l = new ArrayList < > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { long c = Long . parseLong ( sc . next ( ) ) ; if ( ! map . containsKey ( c ) ) { Pair p = new Pair ( c , 1 ) ; map . put ( c , p ) ; l . add ( p ) ; } else { Pair p = map . get ( c ) ; p . cnt ++ ; } } Collections . sort ( l ) ; int size = l . size ( ) ; Pair p1 = l . get ( size - 1 ) ; Pair p2 = l . get ( size - 2 ) ; long res = 0 ; if ( p1 . cnt >= 4 ) res = p1 . a * p1 . a ; else if ( p1 . cnt >= 2 && p2 . cnt >= 2 ) res = p1 . a * p2 . a ; System . out . println ( res ) ; } }
| N = int ( input ( ) ) NEW_LINE A = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE dic = { } NEW_LINE max1 , max2 = 0 , 0 NEW_LINE count = 0 NEW_LINE for i in range ( N ) : NEW_LINE INDENT if ( A [ i ] in dic ) : NEW_LINE INDENT dic [ A [ i ] ] += 1 NEW_LINE if ( dic [ A [ i ] ] % 2 == 0 ) : NEW_LINE INDENT count += 1 NEW_LINE if ( max1 < A [ i ] ) : NEW_LINE INDENT max2 = max1 NEW_LINE max1 = A [ i ] NEW_LINE DEDENT if ( A [ i ] < max1 ) : NEW_LINE INDENT max2 = max ( max2 , A [ i ] ) NEW_LINE DEDENT DEDENT DEDENT else : NEW_LINE INDENT dic [ A [ i ] ] = 1 NEW_LINE DEDENT DEDENT ans = 0 NEW_LINE if ( count >= 2 ) : NEW_LINE INDENT if ( dic [ max1 ] >= 4 ) : NEW_LINE INDENT ans = max1 * max1 NEW_LINE DEDENT else : NEW_LINE INDENT ans = max1 * max2 NEW_LINE DEDENT DEDENT print ( ans ) NEW_LINE
|
T753 | import java . util . * ; import java . lang . * ; class Pair implements Comparable < Pair > { long a ; int cnt ; public Pair ( long i , int j ) { this . a = i ; this . cnt = j ; } public int compareTo ( Pair p ) { if ( this . cnt >= 2 && p . cnt >= 2 && this . a < p . a ) return - 1 ; if ( this . cnt < 2 && p . cnt >= 2 ) return - 1 ; return 1 ; } } class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = Integer . parseInt ( sc . next ( ) ) ; HashMap < Long , Pair > map = new HashMap < > ( ) ; ArrayList < Pair > l = new ArrayList < > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { long c = Long . parseLong ( sc . next ( ) ) ; if ( ! map . containsKey ( c ) ) { Pair p = new Pair ( c , 1 ) ; map . put ( c , p ) ; l . add ( p ) ; } else { Pair p = map . get ( c ) ; p . cnt ++ ; } } Collections . sort ( l ) ; int size = l . size ( ) ; Pair p1 = l . get ( size - 1 ) ; Pair p2 = l . get ( size - 2 ) ; long res = 0 ; if ( p1 . cnt >= 4 ) res = p1 . a * p1 . a ; else if ( p1 . cnt >= 2 && p2 . cnt >= 2 ) res = p1 . a * p2 . a ; System . out . println ( res ) ; } }
| N = int ( input ( ) ) NEW_LINE A = [ int ( a ) for a in input ( ) . split ( ) ] NEW_LINE d = { } NEW_LINE for a in A : NEW_LINE INDENT d [ a ] = d . get ( a , 0 ) + 1 NEW_LINE DEDENT B = [ 0 , 0 ] NEW_LINE for k in d : NEW_LINE INDENT if d [ k ] >= 4 : NEW_LINE INDENT B . append ( k ) NEW_LINE B . append ( k ) NEW_LINE DEDENT elif d [ k ] >= 2 : NEW_LINE INDENT B . append ( k ) NEW_LINE DEDENT DEDENT B . sort ( ) NEW_LINE print ( B [ - 1 ] * B [ - 2 ] ) NEW_LINE
|
T754 | import java . util . * ; import java . lang . * ; class Pair implements Comparable < Pair > { long a ; int cnt ; public Pair ( long i , int j ) { this . a = i ; this . cnt = j ; } public int compareTo ( Pair p ) { if ( this . cnt >= 2 && p . cnt >= 2 && this . a < p . a ) return - 1 ; if ( this . cnt < 2 && p . cnt >= 2 ) return - 1 ; return 1 ; } } class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = Integer . parseInt ( sc . next ( ) ) ; HashMap < Long , Pair > map = new HashMap < > ( ) ; ArrayList < Pair > l = new ArrayList < > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { long c = Long . parseLong ( sc . next ( ) ) ; if ( ! map . containsKey ( c ) ) { Pair p = new Pair ( c , 1 ) ; map . put ( c , p ) ; l . add ( p ) ; } else { Pair p = map . get ( c ) ; p . cnt ++ ; } } Collections . sort ( l ) ; int size = l . size ( ) ; Pair p1 = l . get ( size - 1 ) ; Pair p2 = l . get ( size - 2 ) ; long res = 0 ; if ( p1 . cnt >= 4 ) res = p1 . a * p1 . a ; else if ( p1 . cnt >= 2 && p2 . cnt >= 2 ) res = p1 . a * p2 . a ; System . out . println ( res ) ; } }
| import array NEW_LINE from bisect import * NEW_LINE from collections import * NEW_LINE import fractions NEW_LINE import heapq NEW_LINE from itertools import * NEW_LINE import math NEW_LINE import random NEW_LINE import re NEW_LINE import string NEW_LINE import sys NEW_LINE N = int ( input ( ) ) NEW_LINE As = map ( int , input ( ) . split ( ) ) NEW_LINE c = Counter ( As ) NEW_LINE ans = [ ] NEW_LINE for k in reversed ( sorted ( c . keys ( ) ) ) : NEW_LINE INDENT v = c [ k ] NEW_LINE while v >= 2 : NEW_LINE INDENT ans . append ( k ) NEW_LINE v -= 2 NEW_LINE if len ( ans ) == 2 : NEW_LINE INDENT print ( ans [ 0 ] * ans [ 1 ] ) NEW_LINE sys . exit ( 0 ) NEW_LINE DEDENT DEDENT DEDENT print ( 0 ) NEW_LINE
|
T755 | import java . util . * ; import java . lang . * ; class Pair implements Comparable < Pair > { long a ; int cnt ; public Pair ( long i , int j ) { this . a = i ; this . cnt = j ; } public int compareTo ( Pair p ) { if ( this . cnt >= 2 && p . cnt >= 2 && this . a < p . a ) return - 1 ; if ( this . cnt < 2 && p . cnt >= 2 ) return - 1 ; return 1 ; } } class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = Integer . parseInt ( sc . next ( ) ) ; HashMap < Long , Pair > map = new HashMap < > ( ) ; ArrayList < Pair > l = new ArrayList < > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { long c = Long . parseLong ( sc . next ( ) ) ; if ( ! map . containsKey ( c ) ) { Pair p = new Pair ( c , 1 ) ; map . put ( c , p ) ; l . add ( p ) ; } else { Pair p = map . get ( c ) ; p . cnt ++ ; } } Collections . sort ( l ) ; int size = l . size ( ) ; Pair p1 = l . get ( size - 1 ) ; Pair p2 = l . get ( size - 2 ) ; long res = 0 ; if ( p1 . cnt >= 4 ) res = p1 . a * p1 . a ; else if ( p1 . cnt >= 2 && p2 . cnt >= 2 ) res = p1 . a * p2 . a ; System . out . println ( res ) ; } }
| from collections import Counter NEW_LINE import sys NEW_LINE h = w = index = 0 NEW_LINE n = int ( input ( ) ) NEW_LINE a = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE l = Counter ( a ) NEW_LINE l2 = sorted ( l . items ( ) , reverse = True ) NEW_LINE for i in range ( len ( l2 ) ) : NEW_LINE INDENT if l2 [ i ] [ 1 ] >= 2 : NEW_LINE INDENT if l2 [ i ] [ 1 ] >= 4 : NEW_LINE INDENT print ( l2 [ i ] [ 0 ] ** 2 ) NEW_LINE sys . exit ( ) NEW_LINE DEDENT w = l2 [ i ] [ 0 ] NEW_LINE index = i NEW_LINE break NEW_LINE DEDENT DEDENT for i in range ( index + 1 , len ( l2 ) ) : NEW_LINE INDENT if l2 [ i ] [ 1 ] >= 2 : NEW_LINE INDENT h = l2 [ i ] [ 0 ] NEW_LINE break NEW_LINE DEDENT DEDENT print ( h * w ) NEW_LINE
|
T756 | import java . util . * ; import java . awt . * ; import java . awt . geom . * ; import static java . lang . System . * ; import static java . lang . Math . * ; public class Main { public static void main ( String [ ] $ ) { Scanner sc = new Scanner ( in ) ; int n = sc . nextInt ( ) ; long [ ] a = new long [ n ] ; long edge1 = 0 , edge2 = 0 ; TreeMap < Long , Long > tm = new TreeMap < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = sc . nextLong ( ) ; tm . put ( a [ i ] , tm . getOrDefault ( a [ i ] , 0l ) + 1 ) ; } while ( tm . size ( ) > 0 && edge1 == 0 ) { Map . Entry < Long , Long > temp = tm . pollLastEntry ( ) ; if ( temp . getValue ( ) > 1 ) { edge1 = temp . getKey ( ) ; tm . put ( temp . getKey ( ) , temp . getValue ( ) - 2 ) ; } } while ( tm . size ( ) > 0 && edge2 == 0 ) { Map . Entry < Long , Long > temp = tm . pollLastEntry ( ) ; if ( temp . getValue ( ) > 1 ) { edge2 = temp . getKey ( ) ; } } out . println ( edge1 * edge2 ) ; } }
| import sys NEW_LINE import collections NEW_LINE ns = lambda : sys . stdin . readline ( ) . rstrip ( ) NEW_LINE ni = lambda : int ( ns ( ) ) NEW_LINE nm = lambda : map ( int , sys . stdin . readline ( ) . split ( ) ) NEW_LINE nl = lambda : list ( nm ( ) ) NEW_LINE nsl = lambda : map ( str , sys . stdin . readline ( ) . split ( ) ) NEW_LINE n = ni ( ) NEW_LINE a = nl ( ) NEW_LINE c = collections . Counter ( a ) NEW_LINE key = list ( c . keys ( ) ) NEW_LINE key . sort ( reverse = True ) NEW_LINE count = 0 NEW_LINE for i in range ( len ( key ) ) : NEW_LINE INDENT if c [ key [ i ] ] >= 4 and count != 1 : NEW_LINE INDENT print ( key [ i ] ** 2 ) NEW_LINE exit ( ) NEW_LINE DEDENT if c [ key [ i ] ] >= 2 : NEW_LINE INDENT if count == 0 : NEW_LINE INDENT a = key [ i ] NEW_LINE count += 1 NEW_LINE DEDENT elif count == 1 : NEW_LINE INDENT b = key [ i ] NEW_LINE count += 1 NEW_LINE DEDENT DEDENT if count >= 2 : NEW_LINE INDENT print ( a * b ) NEW_LINE exit ( ) NEW_LINE DEDENT DEDENT print ( 0 ) NEW_LINE
|
T757 | import java . util . * ; import java . awt . * ; import java . awt . geom . * ; import static java . lang . System . * ; import static java . lang . Math . * ; public class Main { public static void main ( String [ ] $ ) { Scanner sc = new Scanner ( in ) ; int n = sc . nextInt ( ) ; long [ ] a = new long [ n ] ; long edge1 = 0 , edge2 = 0 ; TreeMap < Long , Long > tm = new TreeMap < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = sc . nextLong ( ) ; tm . put ( a [ i ] , tm . getOrDefault ( a [ i ] , 0l ) + 1 ) ; } while ( tm . size ( ) > 0 && edge1 == 0 ) { Map . Entry < Long , Long > temp = tm . pollLastEntry ( ) ; if ( temp . getValue ( ) > 1 ) { edge1 = temp . getKey ( ) ; tm . put ( temp . getKey ( ) , temp . getValue ( ) - 2 ) ; } } while ( tm . size ( ) > 0 && edge2 == 0 ) { Map . Entry < Long , Long > temp = tm . pollLastEntry ( ) ; if ( temp . getValue ( ) > 1 ) { edge2 = temp . getKey ( ) ; } } out . println ( edge1 * edge2 ) ; } }
| N = int ( input ( ) ) NEW_LINE A = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE dic = { } NEW_LINE max1 , max2 = 0 , 0 NEW_LINE count = 0 NEW_LINE for i in range ( N ) : NEW_LINE INDENT if ( A [ i ] in dic ) : NEW_LINE INDENT dic [ A [ i ] ] += 1 NEW_LINE if ( dic [ A [ i ] ] % 2 == 0 ) : NEW_LINE INDENT count += 1 NEW_LINE if ( max1 < A [ i ] ) : NEW_LINE INDENT max2 = max1 NEW_LINE max1 = A [ i ] NEW_LINE DEDENT if ( A [ i ] < max1 ) : NEW_LINE INDENT max2 = max ( max2 , A [ i ] ) NEW_LINE DEDENT DEDENT DEDENT else : NEW_LINE INDENT dic [ A [ i ] ] = 1 NEW_LINE DEDENT DEDENT ans = 0 NEW_LINE if ( count >= 2 ) : NEW_LINE INDENT if ( dic [ max1 ] >= 4 ) : NEW_LINE INDENT ans = max1 * max1 NEW_LINE DEDENT else : NEW_LINE INDENT ans = max1 * max2 NEW_LINE DEDENT DEDENT print ( ans ) NEW_LINE
|
T758 | import java . util . * ; import java . awt . * ; import java . awt . geom . * ; import static java . lang . System . * ; import static java . lang . Math . * ; public class Main { public static void main ( String [ ] $ ) { Scanner sc = new Scanner ( in ) ; int n = sc . nextInt ( ) ; long [ ] a = new long [ n ] ; long edge1 = 0 , edge2 = 0 ; TreeMap < Long , Long > tm = new TreeMap < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = sc . nextLong ( ) ; tm . put ( a [ i ] , tm . getOrDefault ( a [ i ] , 0l ) + 1 ) ; } while ( tm . size ( ) > 0 && edge1 == 0 ) { Map . Entry < Long , Long > temp = tm . pollLastEntry ( ) ; if ( temp . getValue ( ) > 1 ) { edge1 = temp . getKey ( ) ; tm . put ( temp . getKey ( ) , temp . getValue ( ) - 2 ) ; } } while ( tm . size ( ) > 0 && edge2 == 0 ) { Map . Entry < Long , Long > temp = tm . pollLastEntry ( ) ; if ( temp . getValue ( ) > 1 ) { edge2 = temp . getKey ( ) ; } } out . println ( edge1 * edge2 ) ; } }
| N = int ( input ( ) ) NEW_LINE A = [ int ( a ) for a in input ( ) . split ( ) ] NEW_LINE d = { } NEW_LINE for a in A : NEW_LINE INDENT d [ a ] = d . get ( a , 0 ) + 1 NEW_LINE DEDENT B = [ 0 , 0 ] NEW_LINE for k in d : NEW_LINE INDENT if d [ k ] >= 4 : NEW_LINE INDENT B . append ( k ) NEW_LINE B . append ( k ) NEW_LINE DEDENT elif d [ k ] >= 2 : NEW_LINE INDENT B . append ( k ) NEW_LINE DEDENT DEDENT B . sort ( ) NEW_LINE print ( B [ - 1 ] * B [ - 2 ] ) NEW_LINE
|
T759 | import java . util . * ; import java . awt . * ; import java . awt . geom . * ; import static java . lang . System . * ; import static java . lang . Math . * ; public class Main { public static void main ( String [ ] $ ) { Scanner sc = new Scanner ( in ) ; int n = sc . nextInt ( ) ; long [ ] a = new long [ n ] ; long edge1 = 0 , edge2 = 0 ; TreeMap < Long , Long > tm = new TreeMap < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = sc . nextLong ( ) ; tm . put ( a [ i ] , tm . getOrDefault ( a [ i ] , 0l ) + 1 ) ; } while ( tm . size ( ) > 0 && edge1 == 0 ) { Map . Entry < Long , Long > temp = tm . pollLastEntry ( ) ; if ( temp . getValue ( ) > 1 ) { edge1 = temp . getKey ( ) ; tm . put ( temp . getKey ( ) , temp . getValue ( ) - 2 ) ; } } while ( tm . size ( ) > 0 && edge2 == 0 ) { Map . Entry < Long , Long > temp = tm . pollLastEntry ( ) ; if ( temp . getValue ( ) > 1 ) { edge2 = temp . getKey ( ) ; } } out . println ( edge1 * edge2 ) ; } }
| import array NEW_LINE from bisect import * NEW_LINE from collections import * NEW_LINE import fractions NEW_LINE import heapq NEW_LINE from itertools import * NEW_LINE import math NEW_LINE import random NEW_LINE import re NEW_LINE import string NEW_LINE import sys NEW_LINE N = int ( input ( ) ) NEW_LINE As = map ( int , input ( ) . split ( ) ) NEW_LINE c = Counter ( As ) NEW_LINE ans = [ ] NEW_LINE for k in reversed ( sorted ( c . keys ( ) ) ) : NEW_LINE INDENT v = c [ k ] NEW_LINE while v >= 2 : NEW_LINE INDENT ans . append ( k ) NEW_LINE v -= 2 NEW_LINE if len ( ans ) == 2 : NEW_LINE INDENT print ( ans [ 0 ] * ans [ 1 ] ) NEW_LINE sys . exit ( 0 ) NEW_LINE DEDENT DEDENT DEDENT print ( 0 ) NEW_LINE
|
T760 | import java . util . * ; import java . awt . * ; import java . awt . geom . * ; import static java . lang . System . * ; import static java . lang . Math . * ; public class Main { public static void main ( String [ ] $ ) { Scanner sc = new Scanner ( in ) ; int n = sc . nextInt ( ) ; long [ ] a = new long [ n ] ; long edge1 = 0 , edge2 = 0 ; TreeMap < Long , Long > tm = new TreeMap < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = sc . nextLong ( ) ; tm . put ( a [ i ] , tm . getOrDefault ( a [ i ] , 0l ) + 1 ) ; } while ( tm . size ( ) > 0 && edge1 == 0 ) { Map . Entry < Long , Long > temp = tm . pollLastEntry ( ) ; if ( temp . getValue ( ) > 1 ) { edge1 = temp . getKey ( ) ; tm . put ( temp . getKey ( ) , temp . getValue ( ) - 2 ) ; } } while ( tm . size ( ) > 0 && edge2 == 0 ) { Map . Entry < Long , Long > temp = tm . pollLastEntry ( ) ; if ( temp . getValue ( ) > 1 ) { edge2 = temp . getKey ( ) ; } } out . println ( edge1 * edge2 ) ; } }
| from collections import Counter NEW_LINE import sys NEW_LINE h = w = index = 0 NEW_LINE n = int ( input ( ) ) NEW_LINE a = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE l = Counter ( a ) NEW_LINE l2 = sorted ( l . items ( ) , reverse = True ) NEW_LINE for i in range ( len ( l2 ) ) : NEW_LINE INDENT if l2 [ i ] [ 1 ] >= 2 : NEW_LINE INDENT if l2 [ i ] [ 1 ] >= 4 : NEW_LINE INDENT print ( l2 [ i ] [ 0 ] ** 2 ) NEW_LINE sys . exit ( ) NEW_LINE DEDENT w = l2 [ i ] [ 0 ] NEW_LINE index = i NEW_LINE break NEW_LINE DEDENT DEDENT for i in range ( index + 1 , len ( l2 ) ) : NEW_LINE INDENT if l2 [ i ] [ 1 ] >= 2 : NEW_LINE INDENT h = l2 [ i ] [ 0 ] NEW_LINE break NEW_LINE DEDENT DEDENT print ( h * w ) NEW_LINE
|
T761 | import java . util . ArrayList ; 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 sc = new Scanner ( System . in ) ; while ( sc . hasNextInt ( ) ) { int N = sc . nextInt ( ) ; Map < Long , Integer > cnt = new HashMap < > ( ) ; Set < Long > set = new HashSet < > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { long x = sc . nextLong ( ) ; int nowCnt = cnt . getOrDefault ( x , 0 ) ; nowCnt ++ ; cnt . put ( x , nowCnt ) ; set . add ( x ) ; } List < Long > sortList = new ArrayList < > ( set ) ; sortList . sort ( Long :: compareTo ) ; long ans = 0 ; List < Long > hen = new ArrayList < > ( ) ; for ( int i = sortList . size ( ) - 1 ; hen . size ( ) < 2 && i >= 0 ; i -- ) { long len = sortList . get ( i ) ; if ( cnt . get ( len ) >= 2 ) { hen . add ( len ) ; } if ( cnt . get ( len ) >= 4 ) { hen . add ( len ) ; } } if ( hen . size ( ) >= 2 ) { ans = hen . get ( 0 ) * hen . get ( 1 ) ; } System . out . println ( ans ) ; } } }
| import sys NEW_LINE import collections NEW_LINE ns = lambda : sys . stdin . readline ( ) . rstrip ( ) NEW_LINE ni = lambda : int ( ns ( ) ) NEW_LINE nm = lambda : map ( int , sys . stdin . readline ( ) . split ( ) ) NEW_LINE nl = lambda : list ( nm ( ) ) NEW_LINE nsl = lambda : map ( str , sys . stdin . readline ( ) . split ( ) ) NEW_LINE n = ni ( ) NEW_LINE a = nl ( ) NEW_LINE c = collections . Counter ( a ) NEW_LINE key = list ( c . keys ( ) ) NEW_LINE key . sort ( reverse = True ) NEW_LINE count = 0 NEW_LINE for i in range ( len ( key ) ) : NEW_LINE INDENT if c [ key [ i ] ] >= 4 and count != 1 : NEW_LINE INDENT print ( key [ i ] ** 2 ) NEW_LINE exit ( ) NEW_LINE DEDENT if c [ key [ i ] ] >= 2 : NEW_LINE INDENT if count == 0 : NEW_LINE INDENT a = key [ i ] NEW_LINE count += 1 NEW_LINE DEDENT elif count == 1 : NEW_LINE INDENT b = key [ i ] NEW_LINE count += 1 NEW_LINE DEDENT DEDENT if count >= 2 : NEW_LINE INDENT print ( a * b ) NEW_LINE exit ( ) NEW_LINE DEDENT DEDENT print ( 0 ) NEW_LINE
|
T762 | import java . util . ArrayList ; 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 sc = new Scanner ( System . in ) ; while ( sc . hasNextInt ( ) ) { int N = sc . nextInt ( ) ; Map < Long , Integer > cnt = new HashMap < > ( ) ; Set < Long > set = new HashSet < > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { long x = sc . nextLong ( ) ; int nowCnt = cnt . getOrDefault ( x , 0 ) ; nowCnt ++ ; cnt . put ( x , nowCnt ) ; set . add ( x ) ; } List < Long > sortList = new ArrayList < > ( set ) ; sortList . sort ( Long :: compareTo ) ; long ans = 0 ; List < Long > hen = new ArrayList < > ( ) ; for ( int i = sortList . size ( ) - 1 ; hen . size ( ) < 2 && i >= 0 ; i -- ) { long len = sortList . get ( i ) ; if ( cnt . get ( len ) >= 2 ) { hen . add ( len ) ; } if ( cnt . get ( len ) >= 4 ) { hen . add ( len ) ; } } if ( hen . size ( ) >= 2 ) { ans = hen . get ( 0 ) * hen . get ( 1 ) ; } System . out . println ( ans ) ; } } }
| N = int ( input ( ) ) NEW_LINE A = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE dic = { } NEW_LINE max1 , max2 = 0 , 0 NEW_LINE count = 0 NEW_LINE for i in range ( N ) : NEW_LINE INDENT if ( A [ i ] in dic ) : NEW_LINE INDENT dic [ A [ i ] ] += 1 NEW_LINE if ( dic [ A [ i ] ] % 2 == 0 ) : NEW_LINE INDENT count += 1 NEW_LINE if ( max1 < A [ i ] ) : NEW_LINE INDENT max2 = max1 NEW_LINE max1 = A [ i ] NEW_LINE DEDENT if ( A [ i ] < max1 ) : NEW_LINE INDENT max2 = max ( max2 , A [ i ] ) NEW_LINE DEDENT DEDENT DEDENT else : NEW_LINE INDENT dic [ A [ i ] ] = 1 NEW_LINE DEDENT DEDENT ans = 0 NEW_LINE if ( count >= 2 ) : NEW_LINE INDENT if ( dic [ max1 ] >= 4 ) : NEW_LINE INDENT ans = max1 * max1 NEW_LINE DEDENT else : NEW_LINE INDENT ans = max1 * max2 NEW_LINE DEDENT DEDENT print ( ans ) NEW_LINE
|
T763 | import java . util . ArrayList ; 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 sc = new Scanner ( System . in ) ; while ( sc . hasNextInt ( ) ) { int N = sc . nextInt ( ) ; Map < Long , Integer > cnt = new HashMap < > ( ) ; Set < Long > set = new HashSet < > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { long x = sc . nextLong ( ) ; int nowCnt = cnt . getOrDefault ( x , 0 ) ; nowCnt ++ ; cnt . put ( x , nowCnt ) ; set . add ( x ) ; } List < Long > sortList = new ArrayList < > ( set ) ; sortList . sort ( Long :: compareTo ) ; long ans = 0 ; List < Long > hen = new ArrayList < > ( ) ; for ( int i = sortList . size ( ) - 1 ; hen . size ( ) < 2 && i >= 0 ; i -- ) { long len = sortList . get ( i ) ; if ( cnt . get ( len ) >= 2 ) { hen . add ( len ) ; } if ( cnt . get ( len ) >= 4 ) { hen . add ( len ) ; } } if ( hen . size ( ) >= 2 ) { ans = hen . get ( 0 ) * hen . get ( 1 ) ; } System . out . println ( ans ) ; } } }
| N = int ( input ( ) ) NEW_LINE A = [ int ( a ) for a in input ( ) . split ( ) ] NEW_LINE d = { } NEW_LINE for a in A : NEW_LINE INDENT d [ a ] = d . get ( a , 0 ) + 1 NEW_LINE DEDENT B = [ 0 , 0 ] NEW_LINE for k in d : NEW_LINE INDENT if d [ k ] >= 4 : NEW_LINE INDENT B . append ( k ) NEW_LINE B . append ( k ) NEW_LINE DEDENT elif d [ k ] >= 2 : NEW_LINE INDENT B . append ( k ) NEW_LINE DEDENT DEDENT B . sort ( ) NEW_LINE print ( B [ - 1 ] * B [ - 2 ] ) NEW_LINE
|
T764 | import java . util . ArrayList ; 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 sc = new Scanner ( System . in ) ; while ( sc . hasNextInt ( ) ) { int N = sc . nextInt ( ) ; Map < Long , Integer > cnt = new HashMap < > ( ) ; Set < Long > set = new HashSet < > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { long x = sc . nextLong ( ) ; int nowCnt = cnt . getOrDefault ( x , 0 ) ; nowCnt ++ ; cnt . put ( x , nowCnt ) ; set . add ( x ) ; } List < Long > sortList = new ArrayList < > ( set ) ; sortList . sort ( Long :: compareTo ) ; long ans = 0 ; List < Long > hen = new ArrayList < > ( ) ; for ( int i = sortList . size ( ) - 1 ; hen . size ( ) < 2 && i >= 0 ; i -- ) { long len = sortList . get ( i ) ; if ( cnt . get ( len ) >= 2 ) { hen . add ( len ) ; } if ( cnt . get ( len ) >= 4 ) { hen . add ( len ) ; } } if ( hen . size ( ) >= 2 ) { ans = hen . get ( 0 ) * hen . get ( 1 ) ; } System . out . println ( ans ) ; } } }
| import array NEW_LINE from bisect import * NEW_LINE from collections import * NEW_LINE import fractions NEW_LINE import heapq NEW_LINE from itertools import * NEW_LINE import math NEW_LINE import random NEW_LINE import re NEW_LINE import string NEW_LINE import sys NEW_LINE N = int ( input ( ) ) NEW_LINE As = map ( int , input ( ) . split ( ) ) NEW_LINE c = Counter ( As ) NEW_LINE ans = [ ] NEW_LINE for k in reversed ( sorted ( c . keys ( ) ) ) : NEW_LINE INDENT v = c [ k ] NEW_LINE while v >= 2 : NEW_LINE INDENT ans . append ( k ) NEW_LINE v -= 2 NEW_LINE if len ( ans ) == 2 : NEW_LINE INDENT print ( ans [ 0 ] * ans [ 1 ] ) NEW_LINE sys . exit ( 0 ) NEW_LINE DEDENT DEDENT DEDENT print ( 0 ) NEW_LINE
|
T765 | import java . util . ArrayList ; 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 sc = new Scanner ( System . in ) ; while ( sc . hasNextInt ( ) ) { int N = sc . nextInt ( ) ; Map < Long , Integer > cnt = new HashMap < > ( ) ; Set < Long > set = new HashSet < > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { long x = sc . nextLong ( ) ; int nowCnt = cnt . getOrDefault ( x , 0 ) ; nowCnt ++ ; cnt . put ( x , nowCnt ) ; set . add ( x ) ; } List < Long > sortList = new ArrayList < > ( set ) ; sortList . sort ( Long :: compareTo ) ; long ans = 0 ; List < Long > hen = new ArrayList < > ( ) ; for ( int i = sortList . size ( ) - 1 ; hen . size ( ) < 2 && i >= 0 ; i -- ) { long len = sortList . get ( i ) ; if ( cnt . get ( len ) >= 2 ) { hen . add ( len ) ; } if ( cnt . get ( len ) >= 4 ) { hen . add ( len ) ; } } if ( hen . size ( ) >= 2 ) { ans = hen . get ( 0 ) * hen . get ( 1 ) ; } System . out . println ( ans ) ; } } }
| from collections import Counter NEW_LINE import sys NEW_LINE h = w = index = 0 NEW_LINE n = int ( input ( ) ) NEW_LINE a = list ( map ( int , input ( ) . split ( ) ) ) NEW_LINE l = Counter ( a ) NEW_LINE l2 = sorted ( l . items ( ) , reverse = True ) NEW_LINE for i in range ( len ( l2 ) ) : NEW_LINE INDENT if l2 [ i ] [ 1 ] >= 2 : NEW_LINE INDENT if l2 [ i ] [ 1 ] >= 4 : NEW_LINE INDENT print ( l2 [ i ] [ 0 ] ** 2 ) NEW_LINE sys . exit ( ) NEW_LINE DEDENT w = l2 [ i ] [ 0 ] NEW_LINE index = i NEW_LINE break NEW_LINE DEDENT DEDENT for i in range ( index + 1 , len ( l2 ) ) : NEW_LINE INDENT if l2 [ i ] [ 1 ] >= 2 : NEW_LINE INDENT h = l2 [ i ] [ 0 ] NEW_LINE break NEW_LINE DEDENT DEDENT print ( h * w ) NEW_LINE
|
T766 | 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 r = 0 ; int g = 0 ; int b = 0 ; for ( char c : s . toCharArray ( ) ) { switch ( c ) { case ' R ' : r ++ ; break ; case ' G ' : g ++ ; break ; case ' B ' : b ++ ; break ; } } System . out . println ( r % 2 + g % 2 + b % 2 ) ; } }
| print ( ( lambda n , l : sum ( [ l . count ( c ) % 2 for c in [ ' R ' , ' G ' , ' B ' ] ] ) ) ( input ( ) , input ( ) ) ) NEW_LINE
|
T767 | 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 r = 0 ; int g = 0 ; int b = 0 ; for ( char c : s . toCharArray ( ) ) { switch ( c ) { case ' R ' : r ++ ; break ; case ' G ' : g ++ ; break ; case ' B ' : b ++ ; break ; } } System . out . println ( r % 2 + g % 2 + b % 2 ) ; } }
| N = int ( input ( ) ) NEW_LINE S = input ( ) NEW_LINE slot = ' ' NEW_LINE for idx in range ( 0 , len ( S ) , 1 ) : NEW_LINE INDENT if len ( slot ) == 0 : NEW_LINE INDENT slot = S [ idx ] NEW_LINE DEDENT elif len ( slot ) == 1 : NEW_LINE INDENT slot = slot + S [ idx ] NEW_LINE if slot [ 0 ] == slot [ 1 ] : NEW_LINE INDENT slot = ' ' NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT if S [ idx ] == slot [ 0 ] : NEW_LINE INDENT slot = slot [ 1 : len ( slot ) ] NEW_LINE DEDENT elif S [ idx ] == slot [ - 1 ] : NEW_LINE INDENT slot = slot [ 0 : len ( slot ) - 1 ] NEW_LINE DEDENT else : NEW_LINE INDENT if idx == len ( S ) - 1 : NEW_LINE INDENT slot = slot + S [ idx ] NEW_LINE DEDENT else : NEW_LINE INDENT if S [ idx + 1 ] == slot [ 0 ] : NEW_LINE INDENT slot = slot + S [ idx ] NEW_LINE DEDENT else : NEW_LINE INDENT slot = S [ idx ] + slot NEW_LINE DEDENT DEDENT DEDENT DEDENT DEDENT print ( len ( slot ) ) NEW_LINE
|
T768 | 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 r = 0 ; int g = 0 ; int b = 0 ; for ( char c : s . toCharArray ( ) ) { switch ( c ) { case ' R ' : r ++ ; break ; case ' G ' : g ++ ; break ; case ' B ' : b ++ ; break ; } } System . out . println ( r % 2 + g % 2 + b % 2 ) ; } }
| import sys NEW_LINE from collections import defaultdict , Counter NEW_LINE from itertools import product , groupby , count , permutations , combinations NEW_LINE from math import pi , sqrt , ceil , floor NEW_LINE from collections import deque NEW_LINE from bisect import bisect , bisect_left , bisect_right NEW_LINE from string import ascii_lowercase NEW_LINE INF = float ( " inf " ) NEW_LINE sys . setrecursionlimit ( 10 ** 7 ) NEW_LINE dy = [ 0 , - 1 , 0 , 1 ] NEW_LINE dx = [ 1 , 0 , - 1 , 0 ] NEW_LINE def inside ( y : int , x : int , H : int , W : int ) -> bool : return 0 <= y < H and 0 <= x < W NEW_LINE def main ( ) : NEW_LINE INDENT global S NEW_LINE N = input ( ) NEW_LINE S = input ( ) NEW_LINE r , g , b = S . count ( " R " ) , S . count ( " G " ) , S . count ( " B " ) NEW_LINE print ( r % 2 + g % 2 + b % 2 ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT
|
T769 | 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 r = 0 ; int g = 0 ; int b = 0 ; for ( char c : s . toCharArray ( ) ) { switch ( c ) { case ' R ' : r ++ ; break ; case ' G ' : g ++ ; break ; case ' B ' : b ++ ; break ; } } System . out . println ( r % 2 + g % 2 + b % 2 ) ; } }
| N = int ( input ( ) ) NEW_LINE S = input ( ) NEW_LINE beam_width = 3 * 10 ** 4 NEW_LINE next_set = { " " } NEW_LINE for c in S : NEW_LINE INDENT a = sorted ( next_set , key = len ) [ : beam_width ] NEW_LINE next_set = set ( ) NEW_LINE add = next_set . add NEW_LINE if a [ 0 ] == " " : NEW_LINE INDENT add ( c ) NEW_LINE a = a [ 1 : ] NEW_LINE DEDENT for s in a : NEW_LINE INDENT add ( c + s if c != s [ 0 ] else s [ 1 : ] ) NEW_LINE add ( s + c if c != s [ - 1 ] else s [ : - 1 ] ) NEW_LINE DEDENT DEDENT ss = sorted ( next_set , key = len ) NEW_LINE print ( len ( ss [ 0 ] ) ) NEW_LINE
|
T770 | 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 r = 0 ; int g = 0 ; int b = 0 ; for ( char c : s . toCharArray ( ) ) { switch ( c ) { case ' R ' : r ++ ; break ; case ' G ' : g ++ ; break ; case ' B ' : b ++ ; break ; } } System . out . println ( r % 2 + g % 2 + b % 2 ) ; } }
| from collections import Counter NEW_LINE N = int ( input ( ) ) NEW_LINE S = input ( ) NEW_LINE counter = Counter ( S ) NEW_LINE ans = 0 NEW_LINE ans += counter [ ' R ' ] % 2 NEW_LINE ans += counter [ ' G ' ] % 2 NEW_LINE ans += counter [ ' B ' ] % 2 NEW_LINE print ( ans ) NEW_LINE
|
T771 | import java . util . * ; import java . util . stream . Collectors ; public class Main { enum Color { R ( " R " ) , B ( " B " ) , G ( " G " ) ; public String name ; private Color ( String string ) { this . name = string ; } public static Color toEnum ( String string ) { if ( string . equals ( R . name ) ) { return R ; } else if ( string . equals ( B . name ) ) { return B ; } else { return G ; } } } public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; final int N = scanner . nextInt ( ) ; final String S = scanner . next ( ) ; Deque < Color > deque = new ArrayDeque < > ( ) ; String [ ] strings = S . split ( " " ) ; for ( int i = 0 ; i < N ; i ++ ) { Color ball = Color . toEnum ( strings [ i ] ) ; if ( deque . size ( ) == 0 ) { deque . addLast ( ball ) ; continue ; } if ( deque . size ( ) == 1 ) { Color ball1 = deque . getFirst ( ) ; if ( ball1 == ball ) { deque . removeFirst ( ) ; } else { deque . addLast ( ball ) ; } continue ; } Color ball1 = deque . getFirst ( ) ; Color ball2 = deque . getLast ( ) ; if ( ball == ball1 ) { deque . removeFirst ( ) ; continue ; } if ( ball == ball2 ) { deque . removeLast ( ) ; continue ; } if ( i == N - 1 ) { deque . addLast ( ball ) ; continue ; } Color nextBall = Color . toEnum ( strings [ i + 1 ] ) ; if ( ball == nextBall ) { deque . addLast ( ball ) ; continue ; } if ( ball1 == nextBall ) { deque . addLast ( ball ) ; } else if ( ball2 == nextBall ) { deque . addFirst ( ball ) ; } } System . out . println ( deque . size ( ) ) ; } }
| print ( ( lambda n , l : sum ( [ l . count ( c ) % 2 for c in [ ' R ' , ' G ' , ' B ' ] ] ) ) ( input ( ) , input ( ) ) ) NEW_LINE
|
T772 | import java . util . * ; import java . util . stream . Collectors ; public class Main { enum Color { R ( " R " ) , B ( " B " ) , G ( " G " ) ; public String name ; private Color ( String string ) { this . name = string ; } public static Color toEnum ( String string ) { if ( string . equals ( R . name ) ) { return R ; } else if ( string . equals ( B . name ) ) { return B ; } else { return G ; } } } public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; final int N = scanner . nextInt ( ) ; final String S = scanner . next ( ) ; Deque < Color > deque = new ArrayDeque < > ( ) ; String [ ] strings = S . split ( " " ) ; for ( int i = 0 ; i < N ; i ++ ) { Color ball = Color . toEnum ( strings [ i ] ) ; if ( deque . size ( ) == 0 ) { deque . addLast ( ball ) ; continue ; } if ( deque . size ( ) == 1 ) { Color ball1 = deque . getFirst ( ) ; if ( ball1 == ball ) { deque . removeFirst ( ) ; } else { deque . addLast ( ball ) ; } continue ; } Color ball1 = deque . getFirst ( ) ; Color ball2 = deque . getLast ( ) ; if ( ball == ball1 ) { deque . removeFirst ( ) ; continue ; } if ( ball == ball2 ) { deque . removeLast ( ) ; continue ; } if ( i == N - 1 ) { deque . addLast ( ball ) ; continue ; } Color nextBall = Color . toEnum ( strings [ i + 1 ] ) ; if ( ball == nextBall ) { deque . addLast ( ball ) ; continue ; } if ( ball1 == nextBall ) { deque . addLast ( ball ) ; } else if ( ball2 == nextBall ) { deque . addFirst ( ball ) ; } } System . out . println ( deque . size ( ) ) ; } }
| N = int ( input ( ) ) NEW_LINE S = input ( ) NEW_LINE slot = ' ' NEW_LINE for idx in range ( 0 , len ( S ) , 1 ) : NEW_LINE INDENT if len ( slot ) == 0 : NEW_LINE INDENT slot = S [ idx ] NEW_LINE DEDENT elif len ( slot ) == 1 : NEW_LINE INDENT slot = slot + S [ idx ] NEW_LINE if slot [ 0 ] == slot [ 1 ] : NEW_LINE INDENT slot = ' ' NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT if S [ idx ] == slot [ 0 ] : NEW_LINE INDENT slot = slot [ 1 : len ( slot ) ] NEW_LINE DEDENT elif S [ idx ] == slot [ - 1 ] : NEW_LINE INDENT slot = slot [ 0 : len ( slot ) - 1 ] NEW_LINE DEDENT else : NEW_LINE INDENT if idx == len ( S ) - 1 : NEW_LINE INDENT slot = slot + S [ idx ] NEW_LINE DEDENT else : NEW_LINE INDENT if S [ idx + 1 ] == slot [ 0 ] : NEW_LINE INDENT slot = slot + S [ idx ] NEW_LINE DEDENT else : NEW_LINE INDENT slot = S [ idx ] + slot NEW_LINE DEDENT DEDENT DEDENT DEDENT DEDENT print ( len ( slot ) ) NEW_LINE
|
T773 | import java . util . * ; import java . util . stream . Collectors ; public class Main { enum Color { R ( " R " ) , B ( " B " ) , G ( " G " ) ; public String name ; private Color ( String string ) { this . name = string ; } public static Color toEnum ( String string ) { if ( string . equals ( R . name ) ) { return R ; } else if ( string . equals ( B . name ) ) { return B ; } else { return G ; } } } public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; final int N = scanner . nextInt ( ) ; final String S = scanner . next ( ) ; Deque < Color > deque = new ArrayDeque < > ( ) ; String [ ] strings = S . split ( " " ) ; for ( int i = 0 ; i < N ; i ++ ) { Color ball = Color . toEnum ( strings [ i ] ) ; if ( deque . size ( ) == 0 ) { deque . addLast ( ball ) ; continue ; } if ( deque . size ( ) == 1 ) { Color ball1 = deque . getFirst ( ) ; if ( ball1 == ball ) { deque . removeFirst ( ) ; } else { deque . addLast ( ball ) ; } continue ; } Color ball1 = deque . getFirst ( ) ; Color ball2 = deque . getLast ( ) ; if ( ball == ball1 ) { deque . removeFirst ( ) ; continue ; } if ( ball == ball2 ) { deque . removeLast ( ) ; continue ; } if ( i == N - 1 ) { deque . addLast ( ball ) ; continue ; } Color nextBall = Color . toEnum ( strings [ i + 1 ] ) ; if ( ball == nextBall ) { deque . addLast ( ball ) ; continue ; } if ( ball1 == nextBall ) { deque . addLast ( ball ) ; } else if ( ball2 == nextBall ) { deque . addFirst ( ball ) ; } } System . out . println ( deque . size ( ) ) ; } }
| import sys NEW_LINE from collections import defaultdict , Counter NEW_LINE from itertools import product , groupby , count , permutations , combinations NEW_LINE from math import pi , sqrt , ceil , floor NEW_LINE from collections import deque NEW_LINE from bisect import bisect , bisect_left , bisect_right NEW_LINE from string import ascii_lowercase NEW_LINE INF = float ( " inf " ) NEW_LINE sys . setrecursionlimit ( 10 ** 7 ) NEW_LINE dy = [ 0 , - 1 , 0 , 1 ] NEW_LINE dx = [ 1 , 0 , - 1 , 0 ] NEW_LINE def inside ( y : int , x : int , H : int , W : int ) -> bool : return 0 <= y < H and 0 <= x < W NEW_LINE def main ( ) : NEW_LINE INDENT global S NEW_LINE N = input ( ) NEW_LINE S = input ( ) NEW_LINE r , g , b = S . count ( " R " ) , S . count ( " G " ) , S . count ( " B " ) NEW_LINE print ( r % 2 + g % 2 + b % 2 ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT
|
T774 | import java . util . * ; import java . util . stream . Collectors ; public class Main { enum Color { R ( " R " ) , B ( " B " ) , G ( " G " ) ; public String name ; private Color ( String string ) { this . name = string ; } public static Color toEnum ( String string ) { if ( string . equals ( R . name ) ) { return R ; } else if ( string . equals ( B . name ) ) { return B ; } else { return G ; } } } public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; final int N = scanner . nextInt ( ) ; final String S = scanner . next ( ) ; Deque < Color > deque = new ArrayDeque < > ( ) ; String [ ] strings = S . split ( " " ) ; for ( int i = 0 ; i < N ; i ++ ) { Color ball = Color . toEnum ( strings [ i ] ) ; if ( deque . size ( ) == 0 ) { deque . addLast ( ball ) ; continue ; } if ( deque . size ( ) == 1 ) { Color ball1 = deque . getFirst ( ) ; if ( ball1 == ball ) { deque . removeFirst ( ) ; } else { deque . addLast ( ball ) ; } continue ; } Color ball1 = deque . getFirst ( ) ; Color ball2 = deque . getLast ( ) ; if ( ball == ball1 ) { deque . removeFirst ( ) ; continue ; } if ( ball == ball2 ) { deque . removeLast ( ) ; continue ; } if ( i == N - 1 ) { deque . addLast ( ball ) ; continue ; } Color nextBall = Color . toEnum ( strings [ i + 1 ] ) ; if ( ball == nextBall ) { deque . addLast ( ball ) ; continue ; } if ( ball1 == nextBall ) { deque . addLast ( ball ) ; } else if ( ball2 == nextBall ) { deque . addFirst ( ball ) ; } } System . out . println ( deque . size ( ) ) ; } }
| N = int ( input ( ) ) NEW_LINE S = input ( ) NEW_LINE beam_width = 3 * 10 ** 4 NEW_LINE next_set = { " " } NEW_LINE for c in S : NEW_LINE INDENT a = sorted ( next_set , key = len ) [ : beam_width ] NEW_LINE next_set = set ( ) NEW_LINE add = next_set . add NEW_LINE if a [ 0 ] == " " : NEW_LINE INDENT add ( c ) NEW_LINE a = a [ 1 : ] NEW_LINE DEDENT for s in a : NEW_LINE INDENT add ( c + s if c != s [ 0 ] else s [ 1 : ] ) NEW_LINE add ( s + c if c != s [ - 1 ] else s [ : - 1 ] ) NEW_LINE DEDENT DEDENT ss = sorted ( next_set , key = len ) NEW_LINE print ( len ( ss [ 0 ] ) ) NEW_LINE
|
T775 | import java . util . * ; import java . util . stream . Collectors ; public class Main { enum Color { R ( " R " ) , B ( " B " ) , G ( " G " ) ; public String name ; private Color ( String string ) { this . name = string ; } public static Color toEnum ( String string ) { if ( string . equals ( R . name ) ) { return R ; } else if ( string . equals ( B . name ) ) { return B ; } else { return G ; } } } public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; final int N = scanner . nextInt ( ) ; final String S = scanner . next ( ) ; Deque < Color > deque = new ArrayDeque < > ( ) ; String [ ] strings = S . split ( " " ) ; for ( int i = 0 ; i < N ; i ++ ) { Color ball = Color . toEnum ( strings [ i ] ) ; if ( deque . size ( ) == 0 ) { deque . addLast ( ball ) ; continue ; } if ( deque . size ( ) == 1 ) { Color ball1 = deque . getFirst ( ) ; if ( ball1 == ball ) { deque . removeFirst ( ) ; } else { deque . addLast ( ball ) ; } continue ; } Color ball1 = deque . getFirst ( ) ; Color ball2 = deque . getLast ( ) ; if ( ball == ball1 ) { deque . removeFirst ( ) ; continue ; } if ( ball == ball2 ) { deque . removeLast ( ) ; continue ; } if ( i == N - 1 ) { deque . addLast ( ball ) ; continue ; } Color nextBall = Color . toEnum ( strings [ i + 1 ] ) ; if ( ball == nextBall ) { deque . addLast ( ball ) ; continue ; } if ( ball1 == nextBall ) { deque . addLast ( ball ) ; } else if ( ball2 == nextBall ) { deque . addFirst ( ball ) ; } } System . out . println ( deque . size ( ) ) ; } }
| from collections import Counter NEW_LINE N = int ( input ( ) ) NEW_LINE S = input ( ) NEW_LINE counter = Counter ( S ) NEW_LINE ans = 0 NEW_LINE ans += counter [ ' R ' ] % 2 NEW_LINE ans += counter [ ' G ' ] % 2 NEW_LINE ans += counter [ ' B ' ] % 2 NEW_LINE print ( ans ) NEW_LINE
|
T776 | import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; char s [ ] = sc . next ( ) . toCharArray ( ) ; int [ ] num = new int [ 3 ] ; for ( int i = 0 ; i < N ; i ++ ) { switch ( s [ i ] ) { case ' R ' : num [ 0 ] ++ ; break ; case ' G ' : num [ 1 ] ++ ; break ; case ' B ' : num [ 2 ] ++ ; break ; } } int ans = 0 ; for ( int i = 0 ; i < 3 ; i ++ ) { ans += num [ i ] % 2 ; } System . out . println ( ans ) ; } }
| print ( ( lambda n , l : sum ( [ l . count ( c ) % 2 for c in [ ' R ' , ' G ' , ' B ' ] ] ) ) ( input ( ) , input ( ) ) ) NEW_LINE
|
T777 | import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; char s [ ] = sc . next ( ) . toCharArray ( ) ; int [ ] num = new int [ 3 ] ; for ( int i = 0 ; i < N ; i ++ ) { switch ( s [ i ] ) { case ' R ' : num [ 0 ] ++ ; break ; case ' G ' : num [ 1 ] ++ ; break ; case ' B ' : num [ 2 ] ++ ; break ; } } int ans = 0 ; for ( int i = 0 ; i < 3 ; i ++ ) { ans += num [ i ] % 2 ; } System . out . println ( ans ) ; } }
| N = int ( input ( ) ) NEW_LINE S = input ( ) NEW_LINE slot = ' ' NEW_LINE for idx in range ( 0 , len ( S ) , 1 ) : NEW_LINE INDENT if len ( slot ) == 0 : NEW_LINE INDENT slot = S [ idx ] NEW_LINE DEDENT elif len ( slot ) == 1 : NEW_LINE INDENT slot = slot + S [ idx ] NEW_LINE if slot [ 0 ] == slot [ 1 ] : NEW_LINE INDENT slot = ' ' NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT if S [ idx ] == slot [ 0 ] : NEW_LINE INDENT slot = slot [ 1 : len ( slot ) ] NEW_LINE DEDENT elif S [ idx ] == slot [ - 1 ] : NEW_LINE INDENT slot = slot [ 0 : len ( slot ) - 1 ] NEW_LINE DEDENT else : NEW_LINE INDENT if idx == len ( S ) - 1 : NEW_LINE INDENT slot = slot + S [ idx ] NEW_LINE DEDENT else : NEW_LINE INDENT if S [ idx + 1 ] == slot [ 0 ] : NEW_LINE INDENT slot = slot + S [ idx ] NEW_LINE DEDENT else : NEW_LINE INDENT slot = S [ idx ] + slot NEW_LINE DEDENT DEDENT DEDENT DEDENT DEDENT print ( len ( slot ) ) NEW_LINE
|
T778 | import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; char s [ ] = sc . next ( ) . toCharArray ( ) ; int [ ] num = new int [ 3 ] ; for ( int i = 0 ; i < N ; i ++ ) { switch ( s [ i ] ) { case ' R ' : num [ 0 ] ++ ; break ; case ' G ' : num [ 1 ] ++ ; break ; case ' B ' : num [ 2 ] ++ ; break ; } } int ans = 0 ; for ( int i = 0 ; i < 3 ; i ++ ) { ans += num [ i ] % 2 ; } System . out . println ( ans ) ; } }
| import sys NEW_LINE from collections import defaultdict , Counter NEW_LINE from itertools import product , groupby , count , permutations , combinations NEW_LINE from math import pi , sqrt , ceil , floor NEW_LINE from collections import deque NEW_LINE from bisect import bisect , bisect_left , bisect_right NEW_LINE from string import ascii_lowercase NEW_LINE INF = float ( " inf " ) NEW_LINE sys . setrecursionlimit ( 10 ** 7 ) NEW_LINE dy = [ 0 , - 1 , 0 , 1 ] NEW_LINE dx = [ 1 , 0 , - 1 , 0 ] NEW_LINE def inside ( y : int , x : int , H : int , W : int ) -> bool : return 0 <= y < H and 0 <= x < W NEW_LINE def main ( ) : NEW_LINE INDENT global S NEW_LINE N = input ( ) NEW_LINE S = input ( ) NEW_LINE r , g , b = S . count ( " R " ) , S . count ( " G " ) , S . count ( " B " ) NEW_LINE print ( r % 2 + g % 2 + b % 2 ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT
|
T779 | import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; char s [ ] = sc . next ( ) . toCharArray ( ) ; int [ ] num = new int [ 3 ] ; for ( int i = 0 ; i < N ; i ++ ) { switch ( s [ i ] ) { case ' R ' : num [ 0 ] ++ ; break ; case ' G ' : num [ 1 ] ++ ; break ; case ' B ' : num [ 2 ] ++ ; break ; } } int ans = 0 ; for ( int i = 0 ; i < 3 ; i ++ ) { ans += num [ i ] % 2 ; } System . out . println ( ans ) ; } }
| N = int ( input ( ) ) NEW_LINE S = input ( ) NEW_LINE beam_width = 3 * 10 ** 4 NEW_LINE next_set = { " " } NEW_LINE for c in S : NEW_LINE INDENT a = sorted ( next_set , key = len ) [ : beam_width ] NEW_LINE next_set = set ( ) NEW_LINE add = next_set . add NEW_LINE if a [ 0 ] == " " : NEW_LINE INDENT add ( c ) NEW_LINE a = a [ 1 : ] NEW_LINE DEDENT for s in a : NEW_LINE INDENT add ( c + s if c != s [ 0 ] else s [ 1 : ] ) NEW_LINE add ( s + c if c != s [ - 1 ] else s [ : - 1 ] ) NEW_LINE DEDENT DEDENT ss = sorted ( next_set , key = len ) NEW_LINE print ( len ( ss [ 0 ] ) ) NEW_LINE
|
T780 | import java . util . * ; public class Main { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int N = sc . nextInt ( ) ; char s [ ] = sc . next ( ) . toCharArray ( ) ; int [ ] num = new int [ 3 ] ; for ( int i = 0 ; i < N ; i ++ ) { switch ( s [ i ] ) { case ' R ' : num [ 0 ] ++ ; break ; case ' G ' : num [ 1 ] ++ ; break ; case ' B ' : num [ 2 ] ++ ; break ; } } int ans = 0 ; for ( int i = 0 ; i < 3 ; i ++ ) { ans += num [ i ] % 2 ; } System . out . println ( ans ) ; } }
| from collections import Counter NEW_LINE N = int ( input ( ) ) NEW_LINE S = input ( ) NEW_LINE counter = Counter ( S ) NEW_LINE ans = 0 NEW_LINE ans += counter [ ' R ' ] % 2 NEW_LINE ans += counter [ ' G ' ] % 2 NEW_LINE ans += counter [ ' B ' ] % 2 NEW_LINE print ( ans ) NEW_LINE
|
T781 | 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 ( ) ; sc . close ( ) ; if ( a == b ) { System . out . println ( " Draw " ) ; } else if ( a == 1 ) { System . out . println ( " Alice " ) ; } else if ( b == 1 ) { System . out . println ( " Bob " ) ; } else if ( a > b ) { System . out . println ( " Alice " ) ; } else { System . out . println ( " Bob " ) ; } } }
| a , b = map ( int , input ( ) . split ( ) ) NEW_LINE if a == b : print ( " Draw " ) NEW_LINE elif a == 1 : print ( " Alice " ) NEW_LINE elif b == 1 : print ( " Bob " ) NEW_LINE elif a > b : print ( " Alice " ) NEW_LINE else : print ( " Bob " ) NEW_LINE
|
T782 | 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 ( ) ; sc . close ( ) ; if ( a == b ) { System . out . println ( " Draw " ) ; } else if ( a == 1 ) { System . out . println ( " Alice " ) ; } else if ( b == 1 ) { System . out . println ( " Bob " ) ; } else if ( a > b ) { System . out . println ( " Alice " ) ; } else { System . out . println ( " Bob " ) ; } } }
| from functools import reduce NEW_LINE import math NEW_LINE def main ( ) : NEW_LINE INDENT a , b = ( int ( _ ) for _ in input ( ) . split ( ) ) NEW_LINE if a == 1 : NEW_LINE INDENT a = 14 NEW_LINE DEDENT if b == 1 : NEW_LINE INDENT b = 14 NEW_LINE DEDENT if a > b : NEW_LINE INDENT ans = ' Alice ' NEW_LINE DEDENT elif a == b : NEW_LINE INDENT ans = ' Draw ' NEW_LINE DEDENT else : NEW_LINE INDENT ans = ' Bob ' NEW_LINE DEDENT print ( ans ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT
|
T783 | 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 ( ) ; sc . close ( ) ; if ( a == b ) { System . out . println ( " Draw " ) ; } else if ( a == 1 ) { System . out . println ( " Alice " ) ; } else if ( b == 1 ) { System . out . println ( " Bob " ) ; } else if ( a > b ) { System . out . println ( " Alice " ) ; } else { System . out . println ( " Bob " ) ; } } }
| A , B = map ( int , input ( ) . split ( ) ) NEW_LINE a = ( A - 2 ) % 13 NEW_LINE b = ( B - 2 ) % 13 NEW_LINE print ( ' Alice ' if a > b else ' Bob ' if a < b else ' Draw ' ) NEW_LINE
|
T784 | 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 ( ) ; sc . close ( ) ; if ( a == b ) { System . out . println ( " Draw " ) ; } else if ( a == 1 ) { System . out . println ( " Alice " ) ; } else if ( b == 1 ) { System . out . println ( " Bob " ) ; } else if ( a > b ) { System . out . println ( " Alice " ) ; } else { System . out . println ( " Bob " ) ; } } }
| A , B = map ( int , input ( ) . split ( ) ) NEW_LINE cards = [ num for num in range ( 2 , 14 ) ] NEW_LINE cards . append ( 1 ) NEW_LINE for i in reversed ( cards ) : NEW_LINE INDENT if i == A and i == B : NEW_LINE INDENT print ( " Draw " ) NEW_LINE DEDENT elif i == A and i != B : NEW_LINE INDENT print ( " Alice " ) NEW_LINE break NEW_LINE DEDENT elif i == B and i != A : NEW_LINE INDENT print ( " Bob " ) NEW_LINE break NEW_LINE DEDENT DEDENT
|
T785 | 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 ( ) ; sc . close ( ) ; if ( a == b ) { System . out . println ( " Draw " ) ; } else if ( a == 1 ) { System . out . println ( " Alice " ) ; } else if ( b == 1 ) { System . out . println ( " Bob " ) ; } else if ( a > b ) { System . out . println ( " Alice " ) ; } else { System . out . println ( " Bob " ) ; } } }
| a , b = ( ( int ( x ) - 2 ) % 100 for x in input ( ) . split ( ) ) NEW_LINE print ( ' Draw ' if a == b else ' Alice ' if a > b else ' Bob ' ) NEW_LINE
|
T786 | import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStream ; import java . io . InputStreamReader ; import java . io . OutputStream ; import java . io . PrintWriter ; import java . util . StringTokenizer ; public class Main { public static void main ( String [ ] args ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; InputReader in = new InputReader ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; Task solver = new Task ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class Task { public void solve ( int testNumber , InputReader in , PrintWriter out ) { int A = in . nextInt ( ) ; int B = in . nextInt ( ) ; if ( A == B ) { out . println ( " Draw " ) ; } else if ( ( A > B || A == 1 ) && B != 1 ) { out . println ( " Alice " ) ; } else { out . println ( " Bob " ) ; } } } static class InputReader { public BufferedReader reader ; public StringTokenizer tokenizer ; public InputReader ( InputStream stream ) { reader = new BufferedReader ( new InputStreamReader ( stream ) , 32768 ) ; tokenizer = null ; } public String next ( ) { while ( tokenizer == null || ! tokenizer . hasMoreTokens ( ) ) { try { tokenizer = new StringTokenizer ( reader . readLine ( ) ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } } return tokenizer . nextToken ( ) ; } public char nextChar ( ) { return next ( ) . charAt ( 0 ) ; } public int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } public double nextDouble ( ) { return Double . parseDouble ( next ( ) ) ; } } }
| a , b = map ( int , input ( ) . split ( ) ) NEW_LINE if a == b : print ( " Draw " ) NEW_LINE elif a == 1 : print ( " Alice " ) NEW_LINE elif b == 1 : print ( " Bob " ) NEW_LINE elif a > b : print ( " Alice " ) NEW_LINE else : print ( " Bob " ) NEW_LINE
|
T787 | import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStream ; import java . io . InputStreamReader ; import java . io . OutputStream ; import java . io . PrintWriter ; import java . util . StringTokenizer ; public class Main { public static void main ( String [ ] args ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; InputReader in = new InputReader ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; Task solver = new Task ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class Task { public void solve ( int testNumber , InputReader in , PrintWriter out ) { int A = in . nextInt ( ) ; int B = in . nextInt ( ) ; if ( A == B ) { out . println ( " Draw " ) ; } else if ( ( A > B || A == 1 ) && B != 1 ) { out . println ( " Alice " ) ; } else { out . println ( " Bob " ) ; } } } static class InputReader { public BufferedReader reader ; public StringTokenizer tokenizer ; public InputReader ( InputStream stream ) { reader = new BufferedReader ( new InputStreamReader ( stream ) , 32768 ) ; tokenizer = null ; } public String next ( ) { while ( tokenizer == null || ! tokenizer . hasMoreTokens ( ) ) { try { tokenizer = new StringTokenizer ( reader . readLine ( ) ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } } return tokenizer . nextToken ( ) ; } public char nextChar ( ) { return next ( ) . charAt ( 0 ) ; } public int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } public double nextDouble ( ) { return Double . parseDouble ( next ( ) ) ; } } }
| from functools import reduce NEW_LINE import math NEW_LINE def main ( ) : NEW_LINE INDENT a , b = ( int ( _ ) for _ in input ( ) . split ( ) ) NEW_LINE if a == 1 : NEW_LINE INDENT a = 14 NEW_LINE DEDENT if b == 1 : NEW_LINE INDENT b = 14 NEW_LINE DEDENT if a > b : NEW_LINE INDENT ans = ' Alice ' NEW_LINE DEDENT elif a == b : NEW_LINE INDENT ans = ' Draw ' NEW_LINE DEDENT else : NEW_LINE INDENT ans = ' Bob ' NEW_LINE DEDENT print ( ans ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT
|
T788 | import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStream ; import java . io . InputStreamReader ; import java . io . OutputStream ; import java . io . PrintWriter ; import java . util . StringTokenizer ; public class Main { public static void main ( String [ ] args ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; InputReader in = new InputReader ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; Task solver = new Task ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class Task { public void solve ( int testNumber , InputReader in , PrintWriter out ) { int A = in . nextInt ( ) ; int B = in . nextInt ( ) ; if ( A == B ) { out . println ( " Draw " ) ; } else if ( ( A > B || A == 1 ) && B != 1 ) { out . println ( " Alice " ) ; } else { out . println ( " Bob " ) ; } } } static class InputReader { public BufferedReader reader ; public StringTokenizer tokenizer ; public InputReader ( InputStream stream ) { reader = new BufferedReader ( new InputStreamReader ( stream ) , 32768 ) ; tokenizer = null ; } public String next ( ) { while ( tokenizer == null || ! tokenizer . hasMoreTokens ( ) ) { try { tokenizer = new StringTokenizer ( reader . readLine ( ) ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } } return tokenizer . nextToken ( ) ; } public char nextChar ( ) { return next ( ) . charAt ( 0 ) ; } public int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } public double nextDouble ( ) { return Double . parseDouble ( next ( ) ) ; } } }
| A , B = map ( int , input ( ) . split ( ) ) NEW_LINE a = ( A - 2 ) % 13 NEW_LINE b = ( B - 2 ) % 13 NEW_LINE print ( ' Alice ' if a > b else ' Bob ' if a < b else ' Draw ' ) NEW_LINE
|
T789 | import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStream ; import java . io . InputStreamReader ; import java . io . OutputStream ; import java . io . PrintWriter ; import java . util . StringTokenizer ; public class Main { public static void main ( String [ ] args ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; InputReader in = new InputReader ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; Task solver = new Task ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class Task { public void solve ( int testNumber , InputReader in , PrintWriter out ) { int A = in . nextInt ( ) ; int B = in . nextInt ( ) ; if ( A == B ) { out . println ( " Draw " ) ; } else if ( ( A > B || A == 1 ) && B != 1 ) { out . println ( " Alice " ) ; } else { out . println ( " Bob " ) ; } } } static class InputReader { public BufferedReader reader ; public StringTokenizer tokenizer ; public InputReader ( InputStream stream ) { reader = new BufferedReader ( new InputStreamReader ( stream ) , 32768 ) ; tokenizer = null ; } public String next ( ) { while ( tokenizer == null || ! tokenizer . hasMoreTokens ( ) ) { try { tokenizer = new StringTokenizer ( reader . readLine ( ) ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } } return tokenizer . nextToken ( ) ; } public char nextChar ( ) { return next ( ) . charAt ( 0 ) ; } public int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } public double nextDouble ( ) { return Double . parseDouble ( next ( ) ) ; } } }
| A , B = map ( int , input ( ) . split ( ) ) NEW_LINE cards = [ num for num in range ( 2 , 14 ) ] NEW_LINE cards . append ( 1 ) NEW_LINE for i in reversed ( cards ) : NEW_LINE INDENT if i == A and i == B : NEW_LINE INDENT print ( " Draw " ) NEW_LINE DEDENT elif i == A and i != B : NEW_LINE INDENT print ( " Alice " ) NEW_LINE break NEW_LINE DEDENT elif i == B and i != A : NEW_LINE INDENT print ( " Bob " ) NEW_LINE break NEW_LINE DEDENT DEDENT
|
T790 | import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStream ; import java . io . InputStreamReader ; import java . io . OutputStream ; import java . io . PrintWriter ; import java . util . StringTokenizer ; public class Main { public static void main ( String [ ] args ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; InputReader in = new InputReader ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; Task solver = new Task ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; } static class Task { public void solve ( int testNumber , InputReader in , PrintWriter out ) { int A = in . nextInt ( ) ; int B = in . nextInt ( ) ; if ( A == B ) { out . println ( " Draw " ) ; } else if ( ( A > B || A == 1 ) && B != 1 ) { out . println ( " Alice " ) ; } else { out . println ( " Bob " ) ; } } } static class InputReader { public BufferedReader reader ; public StringTokenizer tokenizer ; public InputReader ( InputStream stream ) { reader = new BufferedReader ( new InputStreamReader ( stream ) , 32768 ) ; tokenizer = null ; } public String next ( ) { while ( tokenizer == null || ! tokenizer . hasMoreTokens ( ) ) { try { tokenizer = new StringTokenizer ( reader . readLine ( ) ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } } return tokenizer . nextToken ( ) ; } public char nextChar ( ) { return next ( ) . charAt ( 0 ) ; } public int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } public double nextDouble ( ) { return Double . parseDouble ( next ( ) ) ; } } }
| a , b = ( ( int ( x ) - 2 ) % 100 for x in input ( ) . split ( ) ) NEW_LINE print ( ' Draw ' if a == b else ' Alice ' if a > b else ' Bob ' ) NEW_LINE
|
T791 | 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 ( A == 1 ) { A = 14 ; } if ( B == 1 ) { B = 14 ; } if ( A == B ) { System . out . println ( " Draw " ) ; } else if ( A > B ) { System . out . println ( " Alice " ) ; } else { System . out . println ( " Bob " ) ; } } }
| a , b = map ( int , input ( ) . split ( ) ) NEW_LINE if a == b : print ( " Draw " ) NEW_LINE elif a == 1 : print ( " Alice " ) NEW_LINE elif b == 1 : print ( " Bob " ) NEW_LINE elif a > b : print ( " Alice " ) NEW_LINE else : print ( " Bob " ) NEW_LINE
|
T792 | 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 ( A == 1 ) { A = 14 ; } if ( B == 1 ) { B = 14 ; } if ( A == B ) { System . out . println ( " Draw " ) ; } else if ( A > B ) { System . out . println ( " Alice " ) ; } else { System . out . println ( " Bob " ) ; } } }
| from functools import reduce NEW_LINE import math NEW_LINE def main ( ) : NEW_LINE INDENT a , b = ( int ( _ ) for _ in input ( ) . split ( ) ) NEW_LINE if a == 1 : NEW_LINE INDENT a = 14 NEW_LINE DEDENT if b == 1 : NEW_LINE INDENT b = 14 NEW_LINE DEDENT if a > b : NEW_LINE INDENT ans = ' Alice ' NEW_LINE DEDENT elif a == b : NEW_LINE INDENT ans = ' Draw ' NEW_LINE DEDENT else : NEW_LINE INDENT ans = ' Bob ' NEW_LINE DEDENT print ( ans ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT
|
T793 | 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 ( A == 1 ) { A = 14 ; } if ( B == 1 ) { B = 14 ; } if ( A == B ) { System . out . println ( " Draw " ) ; } else if ( A > B ) { System . out . println ( " Alice " ) ; } else { System . out . println ( " Bob " ) ; } } }
| A , B = map ( int , input ( ) . split ( ) ) NEW_LINE a = ( A - 2 ) % 13 NEW_LINE b = ( B - 2 ) % 13 NEW_LINE print ( ' Alice ' if a > b else ' Bob ' if a < b else ' Draw ' ) NEW_LINE
|
T794 | 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 ( A == 1 ) { A = 14 ; } if ( B == 1 ) { B = 14 ; } if ( A == B ) { System . out . println ( " Draw " ) ; } else if ( A > B ) { System . out . println ( " Alice " ) ; } else { System . out . println ( " Bob " ) ; } } }
| A , B = map ( int , input ( ) . split ( ) ) NEW_LINE cards = [ num for num in range ( 2 , 14 ) ] NEW_LINE cards . append ( 1 ) NEW_LINE for i in reversed ( cards ) : NEW_LINE INDENT if i == A and i == B : NEW_LINE INDENT print ( " Draw " ) NEW_LINE DEDENT elif i == A and i != B : NEW_LINE INDENT print ( " Alice " ) NEW_LINE break NEW_LINE DEDENT elif i == B and i != A : NEW_LINE INDENT print ( " Bob " ) NEW_LINE break NEW_LINE DEDENT DEDENT
|
T795 | 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 ( A == 1 ) { A = 14 ; } if ( B == 1 ) { B = 14 ; } if ( A == B ) { System . out . println ( " Draw " ) ; } else if ( A > B ) { System . out . println ( " Alice " ) ; } else { System . out . println ( " Bob " ) ; } } }
| a , b = ( ( int ( x ) - 2 ) % 100 for x in input ( ) . split ( ) ) NEW_LINE print ( ' Draw ' if a == b else ' Alice ' if a > b else ' Bob ' ) NEW_LINE
|
T796 | import java . util . Scanner ; public class Main { private static Scanner sc = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { int a = sc . nextInt ( ) , b = sc . nextInt ( ) ; if ( a == b ) { System . out . println ( " Draw " ) ; return ; } if ( a == 1 ) { a += 13 ; } if ( b == 1 ) { b += 13 ; } System . out . println ( a > b ? " Alice " : " Bob " ) ; } }
| a , b = map ( int , input ( ) . split ( ) ) NEW_LINE if a == b : print ( " Draw " ) NEW_LINE elif a == 1 : print ( " Alice " ) NEW_LINE elif b == 1 : print ( " Bob " ) NEW_LINE elif a > b : print ( " Alice " ) NEW_LINE else : print ( " Bob " ) NEW_LINE
|
T797 | import java . util . Scanner ; public class Main { private static Scanner sc = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { int a = sc . nextInt ( ) , b = sc . nextInt ( ) ; if ( a == b ) { System . out . println ( " Draw " ) ; return ; } if ( a == 1 ) { a += 13 ; } if ( b == 1 ) { b += 13 ; } System . out . println ( a > b ? " Alice " : " Bob " ) ; } }
| from functools import reduce NEW_LINE import math NEW_LINE def main ( ) : NEW_LINE INDENT a , b = ( int ( _ ) for _ in input ( ) . split ( ) ) NEW_LINE if a == 1 : NEW_LINE INDENT a = 14 NEW_LINE DEDENT if b == 1 : NEW_LINE INDENT b = 14 NEW_LINE DEDENT if a > b : NEW_LINE INDENT ans = ' Alice ' NEW_LINE DEDENT elif a == b : NEW_LINE INDENT ans = ' Draw ' NEW_LINE DEDENT else : NEW_LINE INDENT ans = ' Bob ' NEW_LINE DEDENT print ( ans ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT
|
T798 | import java . util . Scanner ; public class Main { private static Scanner sc = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { int a = sc . nextInt ( ) , b = sc . nextInt ( ) ; if ( a == b ) { System . out . println ( " Draw " ) ; return ; } if ( a == 1 ) { a += 13 ; } if ( b == 1 ) { b += 13 ; } System . out . println ( a > b ? " Alice " : " Bob " ) ; } }
| A , B = map ( int , input ( ) . split ( ) ) NEW_LINE a = ( A - 2 ) % 13 NEW_LINE b = ( B - 2 ) % 13 NEW_LINE print ( ' Alice ' if a > b else ' Bob ' if a < b else ' Draw ' ) NEW_LINE
|
T799 | import java . util . Scanner ; public class Main { private static Scanner sc = new Scanner ( System . in ) ; public static void main ( String [ ] args ) { int a = sc . nextInt ( ) , b = sc . nextInt ( ) ; if ( a == b ) { System . out . println ( " Draw " ) ; return ; } if ( a == 1 ) { a += 13 ; } if ( b == 1 ) { b += 13 ; } System . out . println ( a > b ? " Alice " : " Bob " ) ; } }
| A , B = map ( int , input ( ) . split ( ) ) NEW_LINE cards = [ num for num in range ( 2 , 14 ) ] NEW_LINE cards . append ( 1 ) NEW_LINE for i in reversed ( cards ) : NEW_LINE INDENT if i == A and i == B : NEW_LINE INDENT print ( " Draw " ) NEW_LINE DEDENT elif i == A and i != B : NEW_LINE INDENT print ( " Alice " ) NEW_LINE break NEW_LINE DEDENT elif i == B and i != A : NEW_LINE INDENT print ( " Bob " ) NEW_LINE break NEW_LINE DEDENT DEDENT
|
Subsets and Splits