#include <iostream>
#include <string>
#include <ctype.h>
using namespace std;
int word_count, letter_count;
bool get_word()
{
char c;
// skip all characters except for letters and new-line
while (cin.get(c) && !isalpha(c) && '\n' != c)
;
// did we reach the end of line?
if (!cin || '\n' == c)
return false; // we read all the words
//
string word{ c }; // add the first read character to word
while (cin.get(c) && isalpha(c)) // while the read character is a letter add it to the word
word += c;
// the last read character is not a letter, so put it back in stream
cin.putback(c);
// now we have a word: count it
++word_count;
// count letters in word
letter_count += word.length();
// we still have words to read
return true;
}
int main()
{
while (get_word())
;
cout
<< "words: " << word_count << endl
<< "letters: " << letter_count;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RyaW5nPgojaW5jbHVkZSA8Y3R5cGUuaD4KCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgd29yZF9jb3VudCwgbGV0dGVyX2NvdW50OwoKYm9vbCBnZXRfd29yZCgpCnsKICBjaGFyIGM7CgogIC8vIHNraXAgYWxsIGNoYXJhY3RlcnMgZXhjZXB0IGZvciBsZXR0ZXJzIGFuZCBuZXctbGluZQogIHdoaWxlIChjaW4uZ2V0KGMpICYmICFpc2FscGhhKGMpICYmICdcbicgIT0gYykKICAgIDsKCiAgLy8gZGlkIHdlIHJlYWNoIHRoZSBlbmQgb2YgbGluZT8KICBpZiAoIWNpbiB8fCAnXG4nID09IGMpCiAgICByZXR1cm4gZmFsc2U7IC8vIHdlIHJlYWQgYWxsIHRoZSB3b3JkcwoKICAvLwogIHN0cmluZyB3b3JkeyBjIH07IC8vIGFkZCB0aGUgZmlyc3QgcmVhZCBjaGFyYWN0ZXIgdG8gd29yZAogIHdoaWxlIChjaW4uZ2V0KGMpICYmIGlzYWxwaGEoYykpIC8vIHdoaWxlIHRoZSByZWFkIGNoYXJhY3RlciBpcyBhIGxldHRlciBhZGQgaXQgdG8gdGhlIHdvcmQKICAgIHdvcmQgKz0gYzsKCiAgLy8gdGhlIGxhc3QgcmVhZCBjaGFyYWN0ZXI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