You are at home and about to drive to work. The road is a straight line of n kilometers with no speed limit. Traffic lights stand exactly every kilometer, so the i-th light is i kilometers from your home (1≤i≤n−1). There is no light at the start of the road and none at the end.
Your car has a single button. While you hold the button down, the car accelerates at a constant 1m/s2. The moment you release the button the car stops on the spot and its speed drops to 0, so pressing the button again starts the acceleration over from a standstill. You release the button only at a traffic light, and never in the middle of the road. At time 0 the car stands still at the start of the road.
You cannot go past a red light. A light changes between green and red instantly, and passing a light exactly at the instant it changes colour is allowed. Waiting in front of a light while it is red is allowed. The instant you start moving again from a light is the instant you pass it, so the light has to be green at that instant.
You know the schedule of every light. How quickly can you reach the end of the road?
The first line contains one integer n, the length of the road in kilometers (1≤n≤16).
Each of the next n−1 lines contains three integers ti, gi and ri describing the i-th light (40≤gi,ri≤50; 0≤ti<gi+ri). Time ti is the first moment after you start driving at which that light switches from red to green, gi is the length of a green phase and ri is the length of a red phase. From ti on the light is green for gi seconds, then red for ri seconds, and this cycle repeats forever. The same cycle continues backwards in time before ti. All times are in seconds.
A light with ti>ri is therefore green at the moment you start driving and switches to red ti−ri seconds later.
Print the minimum time in seconds needed to reach the end of the road, rounded to exactly six digits after the decimal point.