fun main(args: Array<String>) {
    val s = readInputLine().toCharArray()
    
    val N = s.size
    
    var score = 0
    
    for (i in 0 until N) {
        if (i + 1 > (N + N % 2) / 2) {
            if (s[i] == 'g') {
                score++
            }
        } else {
            if (s[i] == 'p') {
                score--
            }
        }
    }
    
    println(score)
}

fun readInputLine(): String {
    return readLine()!!
}
