Another Contest 5 Problem 2 - Great Graffiti

View as PDF

Submit solution

Points: 3 (partial)
Time limit: 1.0s
Memory limit: 256M

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

Tudor is walking around the streets of Hong Kong when he seems some graffiti. He wishes to augment the graffiti so that the string DMOJ appears somewhere in the graffiti.

The graffiti is a string of letters. With a single can of paint, Tudor can insert one letter anywhere in the string.

Compute the minimum number of cans of paint Tudor needs to buy so that he can make DMOJ appear as a substring somewhere in the graffiti.


1 \le |S| \le 4

S will only contain letters from the string DMOJ.

Input Specification

The first and only line of input contains a single string, S.

Output Specification

Output the minimum number of cans of paint Tudor must buy.

Sample Input


Sample Output



  • -3
    hjanday  commented on May 10, 2020, 11:42 a.m.

    Can I assume that the given graffiti can in order e.g DMO or DM and not like MODJ?