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: Accepted)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Numerics;


namespace practice1
{
    class Program
    {
        static void Main(string[] args)
        {
            char[] str = Console.ReadLine().ToCharArray();
            int count_pa = 0;
            int max;
            int i;
            for (i = 0; i < str.Length; i++)
            {
                
                if (str[i] == 'p')
                {
                    count_pa++;
                }
            }

            max = str.Length / 2;
            MYCP.Print_Int(max - count_pa);
        }
    }

    

    class MYCP
    {
        //int変数を標準出力する
        public static void Print_Int(long number)
        {
            Console.WriteLine("" + number);
        }

        //int変数の配列を標準出力する
        public static void Print_Ints(int[] a)
        {
            if (a.Length == 0) return;

            Console.Write(a[0]);

            for(int i = 1; i < a.Length; i++)
            {
                Console.Write(" ");
                Console.Write(a[i]);
            }

            Console.WriteLine();
        }


        //文字列を配列化して返す
        public static string[] MyReadLineSplit()
        {
            return Console.ReadLine().Split();
        }

        //指定された個数分int変数を読み取る
        public static int[] Read_Ints(long number)
        {
            int[] a = new int[number];
            string[] buff = MyReadLineSplit();
            for (long i = 0; i < number; i++)
            {
                a[i] = int.Parse(buff[i]);
            }

            return a;
        }

        //指定された個数分BigInteger変数を読み取る
        public static BigInteger[] Read_BigIntegers(long number)
        {
            BigInteger[] a = new BigInteger[number];
            string[] buff = MyReadLineSplit();
            for(long i = 0; i < number; i++)
            {
                a[i] = BigInteger.Parse(buff[i]);
            }

            return a;
        }



        //渡された自然数が素数か判定する。素数ならtrueを返す。
        public static bool PrimeCheck_Int(int number)
        {
            if (number < 2) return false;

            for(int i = 2; i < number; i++)
            {
                if (number % i == 0) return false;
            }

            return true;
        }

        //渡された自然数が累乗数か判定する。累乗数ならtrueを返す。
        public static bool Bekizyousuu_Check_Int(int number)
        {
            if (number == 1) return true;

            int i, copy;


            for (i = 2; i < number; i++)
            {
                copy = number;
                while (copy % i == 0)
                {
                    copy /= i;
                }

                if (copy == 1) return true;
            }

            return false;
        }

        //BIgIntegerで累乗計算を行う
        public static BigInteger MyPower_BigInteger(BigInteger a,BigInteger b)
        {
            BigInteger i, x = 1;

            for (i = 0; i < b; i++)
            {
                x *= a;
            }

            return x;
        }

        //渡されたBigIntegerの配列の和を求める
        public static BigInteger MySum_BigInteger(BigInteger[] a)
        {
            BigInteger sum = 0;
            int i;

            for (i = 0; i < a.Length; i++)
            {
                sum += a[i];
            }

            return sum;

        }

        //aをN進法で表した時の各桁の総和を求める
        public static int SumKeta_Int(int a,int N_shinhou)
        {
            if (a <= 0) return 0;
            int sum = 0;

            while (a > 0)
            {
                sum += a % N_shinhou;
                a -= a % N_shinhou;
                a /= N_shinhou;

            }

            return sum;

        }

        //並び替えの通り数を求める
        public static BigInteger NPR_BigInteger(int n,int r)
        {
            BigInteger a = 1;
            for(int i = 0; i < r; i++)
            {
                a *= n;
                n--;
            }

            return a;

            
        }

        //組み合わせの通り数を求める
        public static BigInteger NCR_BigInteger(int n,int r)
        {
            BigInteger a = 1;
            for(int i = 0; i < r; i++)
            {
                a *= n;
                n--;
            }

            a /= NPR_BigInteger(r, r);

            return a;
        }
    }
}