Wow, beautiful! 

I still didn’t get how those values came?
I’m sad.
same feeling bro 

KIng of adhoc problems.
Whenever humanity will talk about adhoc problems this problem will be remembered.
He has created string of type
aaaabbbbbccccdddd where repetitions of each of ‘a’,‘b’,‘c’ and ‘d’ are calculated to fit the conditions.
can anyone explain the formula,
the logic, why is it so?
My solution CodeChef: Practical coding for everyone gave wa during the contest, but the same passed later CodeChef: Practical coding for everyone
what happened?
I also checked my program for all possible values of d, it seems to be correct.
They are identical
Checker has a problem.
This question is as adhoc as it gets. Some people are gonna have a hard time digesting this(me included). I was trying some stuff using triangular numbers and having strings like “abcd…z”. I had a feeling the actual solution was much simpler. Kudos to the author.
Appeal to change the contest name to AdHoc CC Contest ;-;
During Contest, All I believe was this is a dp problem and I was finding some O(nlogn) solution. After this editorial, I am like 
Umm, I just tried this, but it gave me a WA, I think there’s something wrong with the checker.
Here is the submission
EDIT: Darn it, we had to output the string length as well, I Iiterally worked on this problem for 2 hours, and didn’t notice that we had to output the length as well, sorry folks my bad. ![]()
should i laugh or cry after seeing this solution cant judge please help!!
And 7*n is provided Just to distract us! (My all thinking starts from number 7, I make different combination of a string having the length multiple of 7)

From aaaa....bbbbb You can choose 0-D occurrence of each character.
So number of distinct Substrings is (D+1)(D+1) - 1.
-1 is because of the empty string.
Number of Palindromes in aaa...a is n\choose2 +n.