1
+ body[data-md-color-scheme="slate"] .gslide-desc { color: var(--md-default-fg-color);}
589 Problems, 833 Solutions, 11 Languages Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solutions in 2 languages Solution in Python Solution in Python Solution in Python Solution in Python Solutions in 2 languages Solution in Python Solution in Python Python
n , v = io.read ( "*n" , "*n" )
+b = {}
+for i = 1 , n do
+ l , w , h = io.read ( "*n" , "*n" , "*n" )
+ b [ i ] = ( l * w * h )
+end
+print ( math.max ( table.unpack ( b )) - v )
+
n , v = [ int ( d ) for d in input () . split ()]
+b = []
+for _ in range ( n ):
+ l , w , h = [ int ( d ) for d in input () . split ()]
+ b . append ( l * w * h )
+print ( max ( b ) - v )
+
Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Python
notes = [ "A" , "A#" , "B" , "C" , "C#" , "D" , "D#" , "E" , "F" , "F#" , "G" , "G#" ]
-offset = [ 2 , 2 , 1 , 2 , 2 , 2 ]
-majors = {}
-for i in range ( len ( notes )):
- name = notes [ i ]
- progression = [ name ]
- for i in offset :
- index = ( notes . index ( progression [ - 1 ]) + i ) % len ( notes )
- progression . append ( notes [ index ])
- majors [ name ] = progression
-
-_ = input ()
-scales = set ( input () . split ())
-print ( " " . join ([ n for n in majors if scales < set ( majors [ n ])]) or "none" )
-
Solution in Python Solution in Python Solution in Python Python
notes = [ "A" , "A#" , "B" , "C" , "C#" , "D" , "D#" , "E" , "F" , "F#" , "G" , "G#" ]
+offset = [ 2 , 2 , 1 , 2 , 2 , 2 ]
+majors = {}
+for i in range ( len ( notes )):
+ name = notes [ i ]
+ progression = [ name ]
+ for i in offset :
+ index = ( notes . index ( progression [ - 1 ]) + i ) % len ( notes )
+ progression . append ( notes [ index ])
+ majors [ name ] = progression
+
+_ = input ()
+scales = set ( input () . split ())
+print ( " " . join ([ n for n in majors if scales < set ( majors [ n ])]) or "none" )
+
Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solutions in 3 languages Solution in Python Solutions in 3 languages C++ Lua Python
for _ = 1 , io.read ( "*n" ) do
- r , e , c = io.read ( "*n" , "*n" , "*n" )
- if e > r + c then
- print ( "advertise" )
- elseif e < r + c then
- print ( "do not advertise" )
- else
- print ( "does not matter" )
- end
-end
-
#include <iostream>
+
+using namespace std ;
+
+int main ()
+{
+ int n , r , e , c ;
+ cin >> n ;
+
+ for ( int i = 0 ; i < n ; i ++ )
+ {
+ cin >> r >> e >> c ;
+ if (( e - c ) > r )
+ {
+ cout << "advertise" ;
+ }
+ else if (( e - c ) < r )
+ {
+ cout << "do not advertise" ;
+ }
+ else
+ {
+ cout << "does not matter" ;
+ }
+ }
+}
+
for _ = 1 , io.read ( "*n" ) do
+ r , e , c = io.read ( "*n" , "*n" , "*n" )
+ if e > r + c then
print ( "advertise" )
- elif e < r + c :
+ elseif e < r + c then
print ( "do not advertise" )
- else :
+ else
print ( "does not matter" )
-
Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solutions in 2 languages Solution in Python Solutions in 2 languages Solutions in 2 languages Solutions in 2 languages Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solutions in 2 languages Solution in Python Solutions in 2 languages Solution in Python Solutions in 3 languages Solution in Python Solutions in 3 languages Java Lua Python
n , c , p = io.read ( "*n" , "*n" , "*n" )
-ans = 0
-for _ = 1 , n do
- h = io.read ( "*n" )
- if h > c + p then
- ans = ans + 1
- c , p = h , c
- end
-end
-print ( ans )
-
import java.util.Scanner ;
+
+class OffWorldRecords {
+ public static void main ( String [] args ) {
+ Scanner s = new Scanner ( System . in );
+ int n = s . nextInt ();
+ int c = s . nextInt ();
+ int p = s . nextInt ();
+ int ans = 0 ;
+
+ for ( int i = 0 ; i < n ; i ++ ) {
+ int h = s . nextInt ();
+ if ( h > c + p ) {
+ ans += 1 ;
+ p = c ;
+ c = h ;
+ }
+ }
+ System . out . println ( ans );
+ }
+}
+
n , c , p = io.read ( "*n" , "*n" , "*n" )
ans = 0
-for _ in range ( n ):
- h = int ( input ())
- if h > c + p :
- ans += 1
+for _ = 1 , n do
+ h = io.read ( "*n" )
+ if h > c + p then
+ ans = ans + 1
c , p = h , c
-print ( ans )
-
Solution in Python Solution in Python Python
import math
-
-mapping = {
- "000" : "0" ,
- "001" : "1" ,
- "010" : "2" ,
- "011" : "3" ,
- "100" : "4" ,
- "101" : "5" ,
- "110" : "6" ,
- "111" : "7" ,
-}
-b = input ()
-length = 3 * math . ceil ( len ( b ) / 3 )
-b = b . zfill ( length )
-
-print ( "" . join ([ mapping [ b [ i : i + 3 ]] for i in range ( 0 , length , 3 )]))
-
Solution in Python Solution in Python Solution in Python Solution in Python Python
1
+mapping = {
+ "000" : "0" ,
+ "001" : "1" ,
+ "010" : "2" ,
+ "011" : "3" ,
+ "100" : "4" ,
+ "101" : "5" ,
+ "110" : "6" ,
+ "111" : "7" ,
+}
+b = input ()
+length = 3 * math . ceil ( len ( b ) / 3 )
+b = b . zfill ( length )
+
+print ( "" . join ([ mapping [ b [ i : i + 3 ]] for i in range ( 0 , length , 3 )]))
+
Solution in Python Solution in Python Solution in Python Solution in Python Solutions in 2 languages Solution in Python Solution in Python Solution in Python Solution in Python Solutions in 2 languages Solutions in 3 languages Solution in Python Solution in Python Solutions in 3 languages Solution in Python Solutions in 3 languages Solution in Python Solutions in 3 languages Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solutions in 2 languages Solution in Python Solutions in 2 languages Solutions in 2 languages Solution in Python Solution in Python Solution in Python Solutions in 2 languages Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solutions in 2 languages Lua Python
n , h , v = io.read ( "*n" , "*n" , "*n" )
-print ( 4 * math.max ( h * v , ( n - h ) * ( n - v ), h * ( n - v ), v * ( n - h )))
-
n , h , v = [ int ( d ) for d in input () . split ()]
-print ( 4 * max ( h * v , ( n - h ) * ( n - v ), h * ( n - v ), v * ( n - h )))
-
Solution in Python Solution in Python Solution in Python Solution in Python Solutions in 2 languages Lua Python
n , h , v = io.read ( "*n" , "*n" , "*n" )
+print ( 4 * math.max ( h * v , ( n - h ) * ( n - v ), h * ( n - v ), v * ( n - h )))
+
n , h , v = [ int ( d ) for d in input () . split ()]
+print ( 4 * max ( h * v , ( n - h ) * ( n - v ), h * ( n - v ), v * ( n - h )))
+
Solution in Python Python
def f ( n , time , l ):
- total_time , penalty = 0 , 0
- for i , t in enumerate ( sorted ( l )):
- if total_time + t > time :
- return i , penalty
- total_time += t
- penalty = ( penalty + total_time ) % 1_000_000_007
- return n , penalty
-
-
-n , t = [ int ( d ) for d in input () . split ()]
-a , b , c , t0 = [ int ( d ) for d in input () . split ()]
-l = [ t0 ]
-for _ in range ( n - 1 ):
- l . append ((( a * l [ - 1 ] + b ) % c ) + 1 )
-
-
-n , penalty = f ( n , t , l )
-print ( n , penalty )
-
Solution in Python Solutions in 2 languages Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Python
def f ( n , time , l ):
+ total_time , penalty = 0 , 0
+ for i , t in enumerate ( sorted ( l )):
+ if total_time + t > time :
+ return i , penalty
+ total_time += t
+ penalty = ( penalty + total_time ) % 1_000_000_007
+ return n , penalty
+
+
+n , t = [ int ( d ) for d in input () . split ()]
+a , b , c , t0 = [ int ( d ) for d in input () . split ()]
+l = [ t0 ]
+for _ in range ( n - 1 ):
+ l . append ((( a * l [ - 1 ] + b ) % c ) + 1 )
+
+
+n , penalty = f ( n , t , l )
+print ( n , penalty )
+
Solution in Python Solutions in 2 languages Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Python
def adrian ( n ):
- if n == 0 :
- return ""
- elif n == 1 :
- return "A"
- elif n == 2 :
- return "AB"
- elif n == 3 :
- return "ABC"
- else :
- duplicate = n // 3
- return adrian ( 3 ) * duplicate + adrian ( n % 3 )
-
-
-def bruno ( n ):
- if n == 0 :
- return ""
- elif n == 1 :
- return "B"
- elif n == 2 :
- return "BA"
- elif n == 3 :
- return "BAB"
- elif n == 4 :
- return "BABC"
- else :
- duplicate = n // 4
- return bruno ( 4 ) * duplicate + bruno ( n % 4 )
-
-
-def goran ( n ):
- if n == 0 :
- return ""
- elif n in [ 1 , 2 ]:
- return "C" * n
- elif n in [ 3 , 4 ]:
- return "CC" + "A" * ( n - 2 )
- elif n in [ 5 , 6 ]:
- return "CCAA" + "B" * ( n - 4 )
- else :
- duplicate = n // 6
- return goran ( 6 ) * duplicate + goran ( n % 6 )
-
-
-def get_score ( ans , guess ):
- return sum ([ a == g for a , g in zip ( ans , guess )])
-
-
-n = int ( input ())
-ans = input ()
-
-result = {}
-result [ "Adrian" ] = get_score ( ans , adrian ( n ))
-result [ "Bruno" ] = get_score ( ans , bruno ( n ))
-result [ "Goran" ] = get_score ( ans , goran ( n ))
-
-best = max ( result . values ())
-print ( best )
-
-for name , score in result . items ():
- if score == best :
- print ( name )
-
Solution in Python Solutions in 2 languages Solution in Python Python
def adrian ( n ):
+ if n == 0 :
+ return ""
+ elif n == 1 :
+ return "A"
+ elif n == 2 :
+ return "AB"
+ elif n == 3 :
+ return "ABC"
+ else :
+ duplicate = n // 3
+ return adrian ( 3 ) * duplicate + adrian ( n % 3 )
+
+
+def bruno ( n ):
+ if n == 0 :
+ return ""
+ elif n == 1 :
+ return "B"
+ elif n == 2 :
+ return "BA"
+ elif n == 3 :
+ return "BAB"
+ elif n == 4 :
+ return "BABC"
+ else :
+ duplicate = n // 4
+ return bruno ( 4 ) * duplicate + bruno ( n % 4 )
+
+
+def goran ( n ):
+ if n == 0 :
+ return ""
+ elif n in [ 1 , 2 ]:
+ return "C" * n
+ elif n in [ 3 , 4 ]:
+ return "CC" + "A" * ( n - 2 )
+ elif n in [ 5 , 6 ]:
+ return "CCAA" + "B" * ( n - 4 )
+ else :
+ duplicate = n // 6
+ return goran ( 6 ) * duplicate + goran ( n % 6 )
+
+
+def get_score ( ans , guess ):
+ return sum ([ a == g for a , g in zip ( ans , guess )])
+
+
+n = int ( input ())
+ans = input ()
+
+result = {}
+result [ "Adrian" ] = get_score ( ans , adrian ( n ))
+result [ "Bruno" ] = get_score ( ans , bruno ( n ))
+result [ "Goran" ] = get_score ( ans , goran ( n ))
+
+best = max ( result . values ())
+print ( best )
+
+for name , score in result . items ():
+ if score == best :
+ print ( name )
+
Solution in Python Solution in Python Solution in Python Solutions in 4 languages Solutions in 2 languages Solution in Python Solution in Python Solutions in 4 languages Solution in Python Solutions in 2 languages Solution in Python Solution in Python Solutions in 5 languages Solutions in 2 languages Solution in Python Solutions in 5 languages Solution in Python Solution in Python Solution in Python Solution in Python Solutions in 4 languages Solution in Python Solution in Python Solutions in 4 languages Solution in Python Solutions in 2 languages Solution in Python Solution in Python Solution in Python Solutions in 2 languages Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solutions in 4 languages Solution in Python Solutions in 4 languages Go Java Lua Python
import java.util.Scanner ;
+14
package main
-class Rijeci {
- public static void main ( String [] args ) {
- Scanner s = new Scanner ( System . in );
- int k = s . nextInt ();
- int a = 1 ;
- int b = 0 ;
- for ( int i = 0 ; i < k ; i ++ ) {
- int t = b ;
- b = a + b ;
- a = t ;
-
- }
-
- System . out . println ( a + " " + b );
- }
-}
-
k = io.read ( "*n" )
-local a , b = 1 , 0
-for i = 1 , k do
- a , b = b , b + a
-end
-print ( a , b )
+import "fmt"
+
+func main () {
+ var n int
+ fmt . Scan ( & n )
+ a := 1
+ b := 0
+ for i := 0 ; i < n ; i ++ {
+ a , b = b , b + a
+ }
+ fmt . Println ( a , b )
+}
+
import java.util.Scanner ;
+
+class Rijeci {
+ public static void main ( String [] args ) {
+ Scanner s = new Scanner ( System . in );
+ int k = s . nextInt ();
+ int a = 1 ;
+ int b = 0 ;
+ for ( int i = 0 ; i < k ; i ++ ) {
+ int t = b ;
+ b = a + b ;
+ a = t ;
+
+ }
+
+ System . out . println ( a + " " + b );
+ }
+}
k = int ( input ())
-a , b = 1 , 0
-for _ in range ( k ):
+6
k = io.read ( "*n" )
+local a , b = 1 , 0
+for i = 1 , k do
a , b = b , b + a
-
+end
print ( a , b )
-
Solutions in 3 languages Solutions in 3 languages Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Python
a , b = [ int ( d ) for d in input () . split ()]
+10
a , b = [ int ( d ) for d in input () . split ()]
pairs = []
for x in range ( a , b + 1 ):
for y in range ( x , b + 1 ):
xy = x * y
- if x * y > b :
- break
- if sorted ( str ( xy )) == sorted ( str ( x ) + str ( y )):
- pairs . append (( x , y , xy ))
- if x * x > b :
- break
-
-print ( f " { len ( pairs ) } digit-preserving pair(s)" )
-for x , y , xy in pairs :
- print ( f "x = { x } , y = { y } , xy = { xy } " )
-
Solutions in 2 languages Solution in Python Solution in Python Solution in Python Solution in Python Solutions in 2 languages Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solutions in 2 languages Solution in Python Solution in Python Solutions in 2 languages Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solutions in 2 languages Solution in Python Solutions in 3 languages Go Lua Python
package main
-
-import "fmt"
-
-func main () {
- var a , b , c int
- fmt . Scan ( & a )
- fmt . Scan ( & b )
- fmt . Scan ( & c )
- x := b - a
- y := c - b
- ans := x
- if ans < y {
- ans = y
- }
- ans -= 1
- fmt . Println ( ans )
-}
-
a , b , c = io.read ( "*n" , "*n" , "*n" )
-print ( math.max ( b - a , c - b ) - 1 )
-
a , b , c = [ int ( d ) for d in input () . split ()]
-print ( max ( b - a , c - b ) - 1 )
-
Solution in Python Solution in Python Solution in Python Solutions in 2 languages Solution in Python Solution in Python Solutions in 2 languages Solution in Python Solution in Python Solutions in 3 languages Go Lua Python
package main
+
+import "fmt"
+
+func main () {
+ var a , b , c int
+ fmt . Scan ( & a )
+ fmt . Scan ( & b )
+ fmt . Scan ( & c )
+ x := b - a
+ y := c - b
+ ans := x
+ if ans < y {
+ ans = y
+ }
+ ans -= 1
+ fmt . Println ( ans )
+}
+
a , b , c = io.read ( "*n" , "*n" , "*n" )
+print ( math.max ( b - a , c - b ) - 1 )
+
a , b , c = [ int ( d ) for d in input () . split ()]
+print ( max ( b - a , c - b ) - 1 )
+
Solution in Python Solution in Python Solution in Python Solutions in 2 languages Solution in Python Solution in Python Solution in Python Solutions in 2 languages Solution in Python Python
1
+import "fmt"
+
+func main () {
+ var e , f , c int
+ fmt . Scan ( & e )
+ fmt . Scan ( & f )
+ fmt . Scan ( & c )
+ total := 0
+ s := e + f
+ for s >= c {
+ total += s / c
+ s = s % c + s / c
+ }
+ fmt . Println ( total )
+}
+
a , b , c = [ int ( d ) for d in input () . split ()]
-i , j , k = [ int ( d ) for d in input () . split ()]
-s = min ( a / i , b / j , c / k )
-print ( a - i * s , b - j * s , c - k * s )
-
Solution in Python Solution in Python Solution in Python Solutions in 4 languages Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Python
package main
-
-import "fmt"
-
-func main () {
- var a , b int
- fmt . Scan ( & a )
- fmt . Scan ( & b )
- if a < b {
- fmt . Printf ( "%d %d\n" , a , b )
- } else {
- fmt . Printf ( "%d %d\n" , b , a )
- }
-}
-
a , b = io.read ( "*n" , "*n" )
-if a < b then
- print ( a , b )
-else
- print ( b , a )
-end
-
line = input ()
-a , b = [ int ( d ) for d in line . split ()]
-if a < b :
- print ( a , b )
-else :
- print ( b , a )
-
Solutions in 2 languages Solutions in 4 languages C++ Go Lua Python
#include <iostream>
+
+using namespace std ;
+
+int main ()
+{
+ int a = 0 , b = 0 ;
+ cin >> a >> b ;
+ if ( a < b )
+ {
+ cout << a << " " << b ;
+ }
+ else
+ {
+ cout << b << " " << a ;
+ }
+}
+
package main
+
+import "fmt"
+
+func main () {
+ var a , b int
+ fmt . Scan ( & a )
+ fmt . Scan ( & b )
+ if a < b {
+ fmt . Printf ( "%d %d\n" , a , b )
+ } else {
+ fmt . Printf ( "%d %d\n" , b , a )
+ }
+}
+
a , b = io.read ( "*n" , "*n" )
+if a < b then
+ print ( a , b )
+else
+ print ( b , a )
+end
n , k , today = [ int ( d ) for d in input () . split ()]
-res = 0
-for _ in range ( n ):
- d = int ( input ())
- if d + 14 - today <= k :
- res += 1
-print ( res )
-
Solution in Python Solutions in 2 languages Java Python
m = {
- "B" : 1 ,
- "F" : 1 ,
- "P" : 1 ,
- "V" : 1 ,
- "C" : 2 ,
- "G" : 2 ,
- "J" : 2 ,
- "K" : 2 ,
- "Q" : 2 ,
- "S" : 2 ,
- "X" : 2 ,
- "Z" : 2 ,
- "D" : 3 ,
- "T" : 3 ,
- "L" : 4 ,
- "M" : 5 ,
- "N" : 5 ,
- "R" : 6 ,
-}
-
-while True :
- try :
- s = input ()
- s = [ str ( m . get ( c , "" )) for c in s ]
- prev = s [ 0 ]
- ans = [ prev ]
- for c in s [ 1 :]:
- if c != prev :
- ans . append ( c )
- prev = c
- print ( "" . join ( ans ))
- except :
- break
-
Solution in Python Solution in Python Solutions in 3 languages Solution in Python Python
m = {
+ "B" : 1 ,
+ "F" : 1 ,
+ "P" : 1 ,
+ "V" : 1 ,
+ "C" : 2 ,
+ "G" : 2 ,
+ "J" : 2 ,
+ "K" : 2 ,
+ "Q" : 2 ,
+ "S" : 2 ,
+ "X" : 2 ,
+ "Z" : 2 ,
+ "D" : 3 ,
+ "T" : 3 ,
+ "L" : 4 ,
+ "M" : 5 ,
+ "N" : 5 ,
+ "R" : 6 ,
+}
+
+while True :
+ try :
+ s = input ()
+ s = [ str ( m . get ( c , "" )) for c in s ]
+ prev = s [ 0 ]
+ ans = [ prev ]
+ for c in s [ 1 :]:
+ if c != prev :
+ ans . append ( c )
+ prev = c
+ print ( "" . join ( ans ))
+ except :
+ break
+
Solution in Python Solution in Python Solutions in 3 languages Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solutions in 2 languages Solution in Python Solution in Python Solution in Python Solution in Python Solutions in 2 languages Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solutions in 2 languages Lua Python
ds , dy , dm , ym = io.read ( "*n" , "*n" , "*n" , "*n" )
-
-for t = 1 , 5000 do
- if ( t + ds ) % dy == 0 and ( t + dm ) % ym == 0 then
- print ( t )
- break
- end
-end
-
for _ in range ( int ( input ())):
+ k , n = [ int ( d ) for d in input () . split ()]
+ s1 = sum ( range ( 1 , n + 1 ))
+ s2 = sum ( range ( 1 , 2 * n + 1 , 2 ))
+ s3 = sum ( range ( 2 , 2 * ( n + 1 ), 2 ))
+ print ( k , s1 , s2 , s3 )
+
Solution in Python Solution in Python Solution in Python Solutions in 2 languages Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Python
n = int ( input ())
-mapping = {
- "2" : "abc" ,
- "3" : "def" ,
- "4" : "ghi" ,
- "5" : "jkl" ,
- "6" : "mno" ,
- "7" : "pqrs" ,
- "8" : "tuv" ,
- "9" : "wxyz" ,
- "0" : " " ,
-}
+21
set_num = 0
+while True :
+ size = int ( input ())
+ if size == 0 :
+ break
+
+ names = []
+ for _ in range ( size ):
+ names . append ( input ())
+
+ set_num += 1
+ print ( f "SET { set_num } " )
-for i in range ( n ):
- ans = []
- prev = ""
- for c in input ():
- for d , r in mapping . items ():
- if c in r :
- if d == prev :
- ans . append ( " " )
- ans . append ( d * ( r . index ( c ) + 1 ))
- prev = d
- break
- print ( f "Case # { i + 1 } : { '' . join ( ans ) } " )
-
Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Python
n = int ( input ())
+mapping = {
+ "2" : "abc" ,
+ "3" : "def" ,
+ "4" : "ghi" ,
+ "5" : "jkl" ,
+ "6" : "mno" ,
+ "7" : "pqrs" ,
+ "8" : "tuv" ,
+ "9" : "wxyz" ,
+ "0" : " " ,
+}
+
+for i in range ( n ):
+ ans = []
+ prev = ""
+ for c in input ():
+ for d , r in mapping . items ():
+ if c in r :
+ if d == prev :
+ ans . append ( " " )
+ ans . append ( d * ( r . index ( c ) + 1 ))
+ prev = d
+ break
+ print ( f "Case # { i + 1 } : { '' . join ( ans ) } " )
+
Solution in Python Solutions in 2 languages Solution in Python Solution in Python Solution in Python Solutions in 2 languages Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solutions in 2 languages Solution in Python Solution in Python Solution in Python Solutions in 3 languages Solutions in 4 languages Solutions in 2 languages Solution in Python Solutions in 3 languages Solutions in 4 languages Solution in Python Solution in Python Solutions in 8 languages Solution in Python Solution in Python Solutions in 3 languages Solution in Python Solutions in 8 languages Solutions in 3 languages Solution in Python Solution in Python Python
t = input ()
-
-
-def u ( pos , preference ):
- if pos == preference == "U" :
- return 0
- elif pos == preference == "D" :
- return 1
- elif pos == "U" and preference == "D" :
- return 2
- else :
- return 1
-
-
-def l ( pos , preference ):
- if pos == preference == "U" :
- return 1
- elif pos == preference == "D" :
- return 0
- elif pos == "U" and preference == "D" :
- return 1
- else :
- return 2
-
-
-def b ( pos , preference ):
- if pos == preference :
- return 0
- else :
- return 1
-
-
-pu = [ u ( pos , preference ) for pos , preference in zip ( t [ 0 ] + "U" * ( len ( t ) - 2 ), t [ 1 :])]
-pl = [ l ( pos , preference ) for pos , preference in zip ( t [ 0 ] + "D" * ( len ( t ) - 2 ), t [ 1 :])]
-pb = [ b ( pos , preference ) for pos , preference in zip ( t [ 0 ] + t [ 1 : - 1 ], t [ 1 :])]
-
-print ( sum ( pu ))
-print ( sum ( pl ))
-print ( sum ( pb ))
-
Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solutions in 5 languages C++ Go Kotlin Lua Python
t = input ()
+
+
+def u ( pos , preference ):
+ if pos == preference == "U" :
+ return 0
+ elif pos == preference == "D" :
+ return 1
+ elif pos == "U" and preference == "D" :
+ return 2
+ else :
+ return 1
+
+
+def l ( pos , preference ):
+ if pos == preference == "U" :
+ return 1
+ elif pos == preference == "D" :
+ return 0
+ elif pos == "U" and preference == "D" :
+ return 1
+ else :
+ return 2
+
+
+def b ( pos , preference ):
+ if pos == preference :
+ return 0
+ else :
+ return 1
+
+
+pu = [ u ( pos , preference ) for pos , preference in zip ( t [ 0 ] + "U" * ( len ( t ) - 2 ), t [ 1 :])]
+pl = [ l ( pos , preference ) for pos , preference in zip ( t [ 0 ] + "D" * ( len ( t ) - 2 ), t [ 1 :])]
+pb = [ b ( pos , preference ) for pos , preference in zip ( t [ 0 ] + t [ 1 : - 1 ], t [ 1 :])]
+
+print ( sum ( pu ))
+print ( sum ( pl ))
+print ( sum ( pb ))
+
Solution in Python Solution in Python Solutions in 5 languages Solutions in 2 languages Solution in Python Solutions in 2 languages Lua Python
k = [
- "qwertyuiop" ,
- "asdfghjkl" ,
- "zxcvbnm" ,
-]
-
-
-def d ( a , b ):
- for r1 in range ( 3 ):
- if a in k [ r1 ]:
- c1 = k [ r1 ] . index ( a )
- break
- for r2 in range ( 3 ):
- if b in k [ r2 ]:
- c2 = k [ r2 ] . index ( b )
- break
-
- return abs ( c1 - c2 ) + abs ( r1 - r2 )
-
-
-for _ in range ( int ( input ())):
- x , n = input () . split ()
- n , w = int ( n ), []
-
- for _ in range ( n ):
- y = input ()
- dist = sum ([ d ( a , b ) for a , b in zip ( list ( x ), list ( y ))])
- w . append ([ y , dist ])
-
- print ( " \n " . join ([ f " { k } { v } " for k , v in sorted ( w , key = lambda k : ( k [ 1 ], k [ 0 ]))]))
-
Solution in Python Solutions in 2 languages Solutions in 2 languages Solution in Python Python
k = [
+ "qwertyuiop" ,
+ "asdfghjkl" ,
+ "zxcvbnm" ,
+]
+
+
+def d ( a , b ):
+ for r1 in range ( 3 ):
+ if a in k [ r1 ]:
+ c1 = k [ r1 ] . index ( a )
+ break
+ for r2 in range ( 3 ):
+ if b in k [ r2 ]:
+ c2 = k [ r2 ] . index ( b )
+ break
+
+ return abs ( c1 - c2 ) + abs ( r1 - r2 )
+
+
+for _ in range ( int ( input ())):
+ x , n = input () . split ()
+ n , w = int ( n ), []
+
+ for _ in range ( n ):
+ y = input ()
+ dist = sum ([ d ( a , b ) for a , b in zip ( list ( x ), list ( y ))])
+ w . append ([ y , dist ])
+
+ print ( " \n " . join ([ f " { k } { v } " for k , v in sorted ( w , key = lambda k : ( k [ 1 ], k [ 0 ]))]))
+
Solution in Python Solutions in 2 languages Solution in Python Solutions in 2 languages Solutions in 2 languages Solution in Python Solution in Python Solution in Python Solutions in 2 languages Lua Python
d , a , b , h = io.read ( "*n" , "*n" , "*n" , "*n" )
+m = math.pi * d * d / 4
+t = ( a + b ) * h / 2
+if m == t then
+ print ( 'Jafn storar!' )
+elseif m > t then
+ print ( 'Mahjong!' )
+else
+ print ( 'Trapizza!' )
+end
+
from operator import add , mul , sub , truediv
+14
from math import pi
-a , b , c = [ int ( d ) for d in input () . split ()]
-ops = {
- "+" : add ,
- "-" : sub ,
- "*" : mul ,
- "/" : truediv ,
-}
-
-for op , func in ops . items ():
- if a == func ( b , c ):
- print ( f " { a } = { b }{ op }{ c } " )
- break
- if func ( a , b ) == c :
- print ( f " { a }{ op }{ b } = { c } " )
-
Solutions in 5 languages Solution in Python Solution in Python Python
from operator import add , mul , sub , truediv
-import "fmt"
-
-func main () {
- var a , b int
- fmt . Scan ( & a )
- fmt . Scan ( & b )
- fmt . Println ( float32 ( a ) * float32 ( b ) / 2 )
-}
-
1
+a , b , c = [ int ( d ) for d in input () . split ()]
+ops = {
+ "+" : add ,
+ "-" : sub ,
+ "*" : mul ,
+ "/" : truediv ,
+}
+
+for op , func in ops . items ():
+ if a == func ( b , c ):
+ print ( f " { a } = { b }{ op }{ c } " )
+ break
+ if func ( a , b ) == c :
+ print ( f " { a }{ op }{ b } = { c } " )
+
Solutions in 5 languages Solution in Python Solution in Python Solution in Python Solution in Python Solutions in 2 languages Solutions in 7 languages Solution in Python Solution in Python Solutions in 2 languages Solutions in 7 languages Solutions in 5 languages Solutions in 5 languages Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Python
participants = int ( input ())
+10
import math
-vaccinated = 0
-control = 0
-infected_control_a = 0
-infected_vaccinated_a = 0
-infected_control_b = 0
-infected_vaccinated_b = 0
-infected_control_c = 0
-infected_vaccinated_c = 0
-
-for p in range ( participants ):
- record = input ()
- v , a , b , c = list ( record )
-
- if v == "N" :
- control += 1
- else :
- vaccinated += 1
-
- if a == "Y" :
- if v == "N" :
- infected_control_a += 1
- else :
- infected_vaccinated_a += 1
-
- if b == "Y" :
- if v == "N" :
- infected_control_b += 1
- else :
- infected_vaccinated_b += 1
-
- if c == "Y" :
- if v == "N" :
- infected_control_c += 1
- else :
- infected_vaccinated_c += 1
-
-
-def get_vaccine_efficacy ( infected_vaccinated , vaccinated , infected_control , control ):
- infection_rate_vaccinated = infected_vaccinated / vaccinated
- infection_rate_control = infected_control / control
- return 1 - infection_rate_vaccinated / infection_rate_control
-
-
-vaccine_efficacy = [
- get_vaccine_efficacy (
- infected_vaccinated_a ,
- vaccinated ,
- infected_control_a ,
- control ,
- ),
- get_vaccine_efficacy (
- infected_vaccinated_b ,
- vaccinated ,
- infected_control_b ,
- control ,
- ),
- get_vaccine_efficacy (
- infected_vaccinated_c ,
- vaccinated ,
- infected_control_c ,
- control ,
- ),
-]
-
-for value in vaccine_efficacy :
- if value <= 0 :
- print ( "Not Effective" )
- else :
- print ( f " { value * 100 : .6f } " )
-
Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Python
participants = int ( input ())
+
+vaccinated = 0
+control = 0
+infected_control_a = 0
+infected_vaccinated_a = 0
+infected_control_b = 0
+infected_vaccinated_b = 0
+infected_control_c = 0
+infected_vaccinated_c = 0
+
+for p in range ( participants ):
+ record = input ()
+ v , a , b , c = list ( record )
+
+ if v == "N" :
+ control += 1
+ else :
+ vaccinated += 1
+
+ if a == "Y" :
+ if v == "N" :
+ infected_control_a += 1
+ else :
+ infected_vaccinated_a += 1
+
+ if b == "Y" :
+ if v == "N" :
+ infected_control_b += 1
+ else :
+ infected_vaccinated_b += 1
+
+ if c == "Y" :
+ if v == "N" :
+ infected_control_c += 1
+ else :
+ infected_vaccinated_c += 1
+
+
+def get_vaccine_efficacy ( infected_vaccinated , vaccinated , infected_control , control ):
+ infection_rate_vaccinated = infected_vaccinated / vaccinated
+ infection_rate_control = infected_control / control
+ return 1 - infection_rate_vaccinated / infection_rate_control
+
+
+vaccine_efficacy = [
+ get_vaccine_efficacy (
+ infected_vaccinated_a ,
+ vaccinated ,
+ infected_control_a ,
+ control ,
+ ),
+ get_vaccine_efficacy (
+ infected_vaccinated_b ,
+ vaccinated ,
+ infected_control_b ,
+ control ,
+ ),
+ get_vaccine_efficacy (
+ infected_vaccinated_c ,
+ vaccinated ,
+ infected_control_c ,
+ control ,
+ ),
+]
+
+for value in vaccine_efficacy :
+ if value <= 0 :
+ print ( "Not Effective" )
+ else :
+ print ( f " { value * 100 : .6f } " )
+
Solution in Python Solution in C++ Solution in Python Solution in Python Solution in Python Solution in Python Solution in C++ Solution in Python Solution in Python Solutions in 9 languages Solution in Python Solution in Python Solutions in 9 languages Solution in Python Solution in Python Solutions in 3 languages Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Solutions in 3 languages Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Python
mapping = {
- # row 1
- "1" : "`" ,
- "2" : "1" ,
- "3" : "2" ,
- "4" : "3" ,
- "5" : "4" ,
- "6" : "5" ,
- "7" : "6" ,
- "8" : "7" ,
- "9" : "8" ,
- "0" : "9" ,
- "-" : "0" ,
- "=" : "-" ,
- # row 2
- "W" : "Q" ,
- "E" : "W" ,
- "R" : "E" ,
- "T" : "R" ,
- "Y" : "T" ,
- "U" : "Y" ,
- "I" : "U" ,
- "O" : "I" ,
- "P" : "O" ,
- "[" : "P" ,
- "]" : "[" ,
- " \\ " : "]" ,
- # row 3
- "S" : "A" ,
- "D" : "S" ,
- "F" : "D" ,
- "G" : "F" ,
- "H" : "G" ,
- "J" : "H" ,
- "K" : "J" ,
- "L" : "K" ,
- ";" : "L" ,
- "'" : ";" ,
- # row 4
- "X" : "Z" ,
- "C" : "X" ,
- "V" : "C" ,
- "B" : "V" ,
- "N" : "B" ,
- "M" : "N" ,
- "," : "M" ,
- "." : "," ,
- "/" : "." ,
- " " : " " ,
-}
-
-while True :
- try :
- s = input ()
- except :
- break
- print ( "" . join ([ mapping [ c ] for c in s ]))
-
Solution in Python Solution in Python Solutions in 6 languages Solution in Python Python
#include <iostream>
-
-using namespace std ;
-
-int main ()
-{
- int a , b ;
- cin >> a >> b ;
- int ans = ( a > b ) ? 1 : 0 ;
- cout << ans << endl ;
- return 0 ;
-}
-
mapping = {
+ # row 1
+ "1" : "`" ,
+ "2" : "1" ,
+ "3" : "2" ,
+ "4" : "3" ,
+ "5" : "4" ,
+ "6" : "5" ,
+ "7" : "6" ,
+ "8" : "7" ,
+ "9" : "8" ,
+ "0" : "9" ,
+ "-" : "0" ,
+ "=" : "-" ,
+ # row 2
+ "W" : "Q" ,
+ "E" : "W" ,
+ "R" : "E" ,
+ "T" : "R" ,
+ "Y" : "T" ,
+ "U" : "Y" ,
+ "I" : "U" ,
+ "O" : "I" ,
+ "P" : "O" ,
+ "[" : "P" ,
+ "]" : "[" ,
+ " \\ " : "]" ,
+ # row 3
+ "S" : "A" ,
+ "D" : "S" ,
+ "F" : "D" ,
+ "G" : "F" ,
+ "H" : "G" ,
+ "J" : "H" ,
+ "K" : "J" ,
+ "L" : "K" ,
+ ";" : "L" ,
+ "'" : ";" ,
+ # row 4
+ "X" : "Z" ,
+ "C" : "X" ,
+ "V" : "C" ,
+ "B" : "V" ,
+ "N" : "B" ,
+ "M" : "N" ,
+ "," : "M" ,
+ "." : "," ,
+ "/" : "." ,
+ " " : " " ,
+}
+
+while True :
+ try :
+ s = input ()
+ except :
+ break
+ print ( "" . join ([ mapping [ c ] for c in s ]))
+
Solution in Python Solutions in 6 languages Solutions in 2 languages Lua Python
package main
+
+import "fmt"
+
+func main () {
+ var a , b int
+ fmt . Scan ( & a )
+ fmt . Scan ( & b )
+ if a > b {
+ fmt . Println ( 1 )
+ } else {
+ fmt . Println ( 0 )
+ }
+}
+
import java.util.Scanner ;
+
+class WhichisGreater {
+ public static void main ( String [] args ) {
+ Scanner s = new Scanner ( System . in );
+ int a = s . nextInt ();
+ int b = s . nextInt ();
+ if ( a > b ){
+ System . out . println ( 1 );
+ } else {
+ System . out . println ( 0 );
+ }
+ }
+}
+
const readline = require ( "readline" );
+const rl = readline . createInterface ( process . stdin , process . stdout );
+
+rl . question ( "" , ( line ) => {
+ [ a , b ] = line
+ . trim ()
+ . split ( " " )
+ . map (( e ) => parseInt ( e ));
+ if ( a > b ) {
+ console . log ( 1 );
+ } else {
+ console . log ( 0 );
+ }
+});
+
n , k = io.read ( "*n" , "*n" )
-if math.log ( n , 2 ) <= k then
- print ( "Your wish is granted!" )
+6
a , b = io.read ( "*n" , "*n" )
+if a > b then
+ print ( 1 )
else
- print ( "You will become a flying monkey!" )
+ print ( 0 )
end
import math
-
-n , k = [ int ( d ) for d in input () . split ()]
-ans = math . log ( n , 2 ) <= k
-if ans :
- print ( "Your wish is granted!" )
-else :
- print ( "You will become a flying monkey!" )
-
Solution in Python Python
mapping = {
- 0 : "zero" ,
- 1 : "one" ,
- 2 : "two" ,
- 3 : "three" ,
- 4 : "four" ,
- 5 : "five" ,
- 6 : "six" ,
- 7 : "seven" ,
- 8 : "eight" ,
- 9 : "nine" ,
- 10 : "ten" ,
- 11 : "eleven" ,
- 12 : "twelve" ,
-}
-
-
-def f ( d ):
- if d < 13 :
- return mapping [ d ]
-
- ones = d % 10
- if d < 20 :
- return { 3 : "thir" , 5 : "fif" , 8 : "eigh" } . get ( ones , mapping [ ones ]) + "teen"
-
- tens = d // 10
- return (
- { 2 : "twen" , 3 : "thir" , 4 : "for" , 5 : "fif" , 8 : "eigh" } . get ( tens , mapping [ tens ])
- + "ty"
- + ( "-" + mapping [ ones ] if ones else "" )
- )
-
-
-def t ( w ):
- if w . isdigit ():
- return f ( int ( w ))
- else :
- return w
-
-
-while True :
- try :
- words = input ()
- except :
- break
- print ( " " . join ([ t ( w ) for w in words . split ()]))
-
Solution in Python Solution in Python Solutions in 2 languages Solution in Python Python
a , b = input (), input ()
-size = max ( len ( a ), len ( b ))
-
-a = [ int ( d ) for d in a . zfill ( size )]
-b = [ int ( d ) for d in b . zfill ( size )]
-
-ans_a = [ d1 for d1 , d2 in zip ( a , b ) if d1 >= d2 ]
-ans_b = [ d2 for d1 , d2 in zip ( a , b ) if d2 >= d1 ]
-
-
-def f ( ans ):
- if not ans :
- return "YODA"
- else :
- return int ( "" . join ([ str ( d ) for d in ans ]))
+19
+20
+21
+22
+23
+24
+25
+26
+27
+28
+29
+30
+31
+32
+33
+34
+35
+36
+37
+38
+39
+40
+41
+42
+43
+44
+45
+46
mapping = {
+ 0 : "zero" ,
+ 1 : "one" ,
+ 2 : "two" ,
+ 3 : "three" ,
+ 4 : "four" ,
+ 5 : "five" ,
+ 6 : "six" ,
+ 7 : "seven" ,
+ 8 : "eight" ,
+ 9 : "nine" ,
+ 10 : "ten" ,
+ 11 : "eleven" ,
+ 12 : "twelve" ,
+}
-print ( f ( ans_a ))
-print ( f ( ans_b ))
-
Solution in Python Python
l , d , x = input (), input (), input ()
-l , d , x = int ( l ), int ( d ), int ( x )
-
-for i in range ( l , d + 1 ):
- if sum ([ int ( d ) for d in str ( i )]) == x :
- print ( i )
- break
-
-for i in range ( d , l - 1 , - 1 ):
- if sum ([ int ( d ) for d in str ( i )]) == x :
- print ( i )
- break
-
Solutions in 2 languages Solution in Python Solution in Python Solution in Python Solution in Python Python
l , d , x = input (), input (), input ()
+l , d , x = int ( l ), int ( d ), int ( x )
+
+for i in range ( l , d + 1 ):
+ if sum ([ int ( d ) for d in str ( i )]) == x :
+ print ( i )
+ break
+
+for i in range ( d , l - 1 , - 1 ):
+ if sum ([ int ( d ) for d in str ( i )]) == x :
+ print ( i )
+ break
+
Solutions in 2 languages Solution in Python Solution in Python Solution in Python Solution in Python Solution in Python Back to top