Formula for the quality of any given How I Met Your Mother episode:
Q = 8B - T^2 - 2S
where Q=quality, B=screen time of Barney in minutes, T=screen time of Ted in minutes, and S=season number
As we can see here, quality increases linearly with screen time of Barney. Furthermore, Barney's screen presence makes up for the undesirable nature of Ted at lower amounts, still allowing for a quality episode as long as the season number is not too high. However, Ted's screen presence quickly outpaces Barney's screen presence as you get to higher numbers, so that an episode with high amounts of both Ted and Barney ultimately results in a low quality episode. As we can see, an ideal episode is one in which Barney's screen time is maximized, Ted's screen time is minimized, and the season is early.
Recently, other researchers have proposed an amendment to the current formula as a means to incorporate Marshall and Lily into consideration. There is general consensus to label it simply as the variable, M, as Lily's value is only in relation to making Marshall funny. This is the most complicated aspect of the formula, as M greatly adds value to an episode in very small amounts, but as screen time increases, the increase in Quality (Q) drops off severely. Furthermore, at levels higher than approximately 3 minutes, the presence of Marshall and Lily actually causes a decrease in Quality, as can be seen in the following graph.
While there is considerable disagreement about the coefficient to the logarithmic representation of variable, M, we believe the following to be the most accurate representation of the effect of M on Quality. The proposed amendment to the formula, thus, is as follows:
Q = 8B - T^2 - 2S + 4log[1/(M/3)]