main=do
    s<-getLine
    print $ solve s
solve ('g':ss) = solo 0 ss
solve ('p':ss) = solo (-1) ss
solo n [] = n
solo n ('g':ss) = sole (n,n+1) ss
solo n ('p':ss) = sole (n-1,n) ss
sole (g,p) [] = max g p
sole (g,p) ('g':ss) = solo (max g p) ss
sole (g,p) ('p':ss) = solo (max g p - 1) ss