from math import pow, ceil, floor lines = open("input.txt", 'r').read().splitlines() cols = [l.split() for l in lines] races = [(int(cols[0][i]), int(cols[1][i])) for i in range(1,len(cols[0]))] #[(time, record)] realRace = (int(lines[0].split(": ")[1].replace(" ","")), int(lines[1].split(": ")[1].replace(" ",""))) #d = t * v #charge + t = time #t = time - charge #v = charge #d = (time - charge) * charge #d = -charge^2 + time*charge summa = 1 def findWays(race): a = -1 b = race[0] c = -race[1] rangeStart = floor((-b + pow((pow(b,2)-(4*a*c)),0.5)) / (2*a)) + 1 rangeEnd = ceil((-b - pow((pow(b,2)-(4*a*c)),0.5)) / (2*a)) - 1 return rangeEnd-rangeStart+1 for r in races: summa *= findWays(r) print(summa) print(findWays(realRace))