COCI '07 Contest 4 #3 Lektira

View as PDF

Submit solution

Points: 5
Time limit: 0.6s
Memory limit: 32M

Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

Mario is making up silly games again instead of reading Dostoevsky for school. The rules of his newest game follow.

First he chooses a random word from the book. Then he splits the word in two arbitrary places to get three separate words.

After that he reverses the order of the letters in each of those three words (exchanges the first and last letters, the second and second last and so on).

Finally, he puts the three words back together in the same order in which they were before splitting. The goal of the game is to obtain the lexicographically smallest word possible. In other words, of all words that can be obtained by the above procedure, find one which would be earliest in a dictionary.

Write a program that plays Mario's game perfectly.

Input Specification

The first and only line of input contains Mario's chosen word, a string of lowercase letters of the English alphabet with no spaces.

The input word will be between 3 and 50 characters long (inclusive).

Output Specification

Output the best word on a single line.

Sample Input 1


Sample Output 1


Sample Input 2


Sample Output 2


Sample Input 3


Sample Output 3



  • 0
    a_sad_javamain  commented on Jan. 12, 2021, 8:31 p.m.

    Are the three split words allowed to be empty (length 0)?

    • 3
      cabbagecabbagecabbage  commented on Jan. 13, 2021, 12:14 a.m. edited

      from my experiment just now, no

      also, if that were allowed, the answer to sample 3 would instead be "aadnokan" from reversing "a", "nakonda", and "". so this is not allowed.

      this can also be inferred from the fact that the word length is at least 3 characters, which would make sense if each of the 3 words needed to be at least 1 character long