fun main() {
    val s = readLine()!!
    var ans = 0
    var g = 0
    var p = 0
    for (c in s) {
        if (c == 'g') {
            if (p < g) {
                ans++
                p++
            } else {
                g++
            }
        } else {
            if (p < g) {
                p++
            } else {
                ans--
                g++
            }
        }
    }
    println(ans)
}
