// Template for reading lines from stdin and printing the line count to stdout.
// Copy this code to your IDE to get started.

fun main() = println(generateSequence(::readlnOrNull).sumOf {
    (1..it.length).first { l ->
        (0 until l).none { x -> it.filterIndexed { i, _ -> i % l == x }.toSet().count { it != '?' } > 1 }
    }
})
