#include <bits/stdc++.h>
using namespace std;
string appendNext(string str){
string str1;
char ch = str[0];
int chCount = 1;
for(int i = 1; i <= str.size(); i++){
if (str[i] == ch){
chCount++;
}
else {
char chr = chCount + '0';
str1 = str1 + chr;
str1 = str1 + ch;
ch = str[i];
chCount = 1;
}
}
return str1;
}
string countAndSay(int n) {
if (n == 1) {
return "1";
}
string str1 = "1";
string strn;
for (int i = 1; i < n; i++){
strn = appendNext(str1);
str1 = strn;
}
return strn;
}
int main() {
cout << countAndSay(5);
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgpzdHJpbmcgYXBwZW5kTmV4dChzdHJpbmcgc3RyKXsKICAgIHN0cmluZyBzdHIxOwogICAgY2hhciBjaCA9IHN0clswXTsKICAgIGludCBjaENvdW50ID0gMTsKICAgIGZvcihpbnQgaSA9IDE7IGkgPD0gc3RyLnNpemUoKTsgaSsrKXsKICAgICAgICBpZiAoc3RyW2ldID09IGNoKXsKICAgICAgICAgICAgY2hDb3VudCsrOwogICAgICAgIH0KICAgICAgICBlbHNlIHsKICAgICAgICAgICAgY2hhciBjaHIgPSBjaENvdW50ICsgJzAnOwogICAgICAgICAgICBzdHIxID0gc3RyMSArIGNocjsKICAgICAgICAgICAgc3RyMSA9IHN0cjEgKyBjaDsKICAgICAgICAgICAgY2ggPSBzdHJbaV07CiAgICAgICAgICAgIGNoQ291bnQgPSAxOwogICAgICAgIH0KICAgIH0KICAgIHJldHVybiBzdHIxOwp9CgpzdHJpbmcgY291bnRBbmRTYXkoaW50IG4pIHsKICAgIGlmIChuID09IDEpIHsKICAgICAgICByZXR1cm4gIjEiOwogICAgfQogICAgc3RyaW5nIHN0cjEgPSAiMSI7CiAgICBzdHJpbmcgc3RybjsKICAgIGZvciAoaW50IGkgPSAxOyBpIDwgbjsgaSsrKXsKICAgICAgICBzdHJuID0gYXBwZW5kTmV4dChzdHIxKTsKICAgICAgICBzdHIxID0gc3RybjsKICAgIH0KICAgIHJldHVybiBzdHJuOwp9CgppbnQgbWFpbigpIHsKCWNvdXQgPDwgY291bnRBbmRTYXkoNSk7CglyZXR1cm4gMDsKfQ==