s.major and minor, apply the modified Kadane's algorithm.global_max, major_count, and minor_count to 0, and let rest_minor be the count of minor in s.s, incrementing major_count for major and minor_count for minor, decrementing rest_minor for minor.global_max only if minor_count > 0.major_count - minor_count < 0, reset counts to 0 only if rest_minor > 0.global_max.