Problem:
Score : 300 points

Problem Statement

AtCoDeer the deer and his friend TopCoDeer is playing a game.
The game consists of N turns.
In each turn, each player plays one of the two gestures, Rock and Paper, as in Rock-paper-scissors, under the following condition:

(※) After each turn, (the number of times the player has played Paper)≦(the number of times the player has played Rock).

Each player's score is calculated by (the number of turns where the player wins) - (the number of turns where the player loses), where the outcome of each turn is determined by the rules of Rock-paper-scissors.

(For those who are not familiar with Rock-paper-scissors: If one player plays Rock and the other plays Paper, the latter player will win and the former player will lose. If both players play the same gesture, the round is a tie and neither player will win nor lose.)

With his supernatural power, AtCoDeer was able to foresee the gesture that TopCoDeer will play in each of the N turns, before the game starts.
Plan AtCoDeer's gesture in each turn to maximize AtCoDeer's score.

The gesture that TopCoDeer will play in each turn is given by a string s. If the i-th (1≦i≦N) character in s is g, TopCoDeer will play Rock in the i-th turn. Similarly, if the i-th (1≦i≦N) character of s in p, TopCoDeer will play Paper in the i-th turn.

Constraints

1≦N≦10^5

N=|s|

Each character in s is g or p.

The gestures represented by s satisfy the condition (※).

Input

The input is given from Standard Input in the following format:

s

Output

Print the AtCoDeer's maximum possible score.

Sample Input 1

gpg

Sample Output 1

0

Playing the same gesture as the opponent in each turn results in the score of 0, which is the maximum possible score.

Sample Input 2

ggppgggpgg

Sample Output 2

2

For example, consider playing gestures in the following order: Rock, Paper, Rock, Paper, Rock, Rock, Paper, Paper, Rock, Paper. This strategy earns three victories and suffers one defeat, resulting in the score of 2, which is the maximum possible score.

Solution in C# (Mono 4.6.2.0) (judge verdict: Time Limit Exceeded)

using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;


class Program
{
    public void Proc()
    {
        Reader.IsDebug = false;
        this.TE = Reader.ReadLine();
        int[] tmp = GetAns(0, 0);
        int ans = tmp[0] - tmp[1];
        Console.WriteLine(ans);
    }

    private string TE;

    private Dictionary<int, Dictionary<int, int[]>> dic = new Dictionary<int, Dictionary<int, int[]>>();
    private int[] GetAns(int gCount, int pCount) {
        if(!dic.ContainsKey(gCount)) {
            dic.Add(gCount, new Dictionary<int,int[]>());
        }
        if (dic[gCount].ContainsKey(pCount))
        {
            return dic[gCount][pCount];
        }

        if (gCount + pCount == this.TE.Length - 1)
        {
            if (gCount > pCount)
            {
                if (this.TE.Last() == 'g')
                {
                    return new int[] { 1, 0 };
                }
                else
                {
                    return new int[] { 0, 0 };
                }
            }
            else
            {
                if (this.TE.Last() == 'p')
                {
                    return new int[] { 0, 1 };
                }
                else
                {
                    return new int[] { 0, 0 };
                }
            }
        }

        int idx = gCount + pCount;
        int[] ans = new int[] { 0, 100000 };
        if (gCount > pCount)
        {
            int retWin = 0;
            if (this.TE[idx] == 'g')
            {
                retWin++;
            }
            int[] ret = new List<int>(this.GetAns(gCount, pCount + 1)).ToArray();
            ret[0] += retWin;
            ans = ret;
        }

        int ls = 0;
        if (this.TE[idx] == 'p')
        {
            ls++;
        }
        int[] ret2 = new List<int>(this.GetAns(gCount + 1, pCount)).ToArray();
        ret2[1] += ls;

        if (ans[0] - ans[1] < ret2[0] - ret2[1])
        {
            ans = ret2;
        }
        dic[gCount].Add(pCount, ans);
        return ans;
    }
 

    public class Reader
    {
        public static bool IsDebug = true;
        private static String PlainInput = @"


ggppgggpgg



";
        private static System.IO.StringReader Sr = null;
        public static string ReadLine()
        {
            if (IsDebug)
            {
                if (Sr == null)
                {
                    Sr = new System.IO.StringReader(PlainInput.Trim());
                }
                return Sr.ReadLine();
            }
            else
            {
                return Console.ReadLine();
            }
        }
    }
    static void Main()
    {
        Program prg = new Program();
        prg.Proc();
    }
}