S002-EE.cc 535 Bytes
#include <iostream>

using namespace std;

int main()
{
	string word;
	bool begin = false, end = false;
	unsigned int count = 0;
	while(true)
	{
		cin >> word;
		if(cin.eof())
		{
			break;
		}
		if(begin && !end)
		{
			count++;
		}
		if(word == "beginning")
		{
			begin = true;
		}
		else if(word == "end")
		{
			if(!begin)
			{
				cout << "wrong sequence" << endl;
				return 0;
			}
			count--;
			end = true;
		}
	}
	if(!begin || !end)
	{
		cout << "wrong sequence" << endl;
		return 0;
	}
	cout << count << endl;
	return 0;
}