1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

/*
#pragma GCC target("avx2")
#pragma GCC optimization("Ofast")
#pragma GCC optimization("unroll-loops")
*/

using namespace __gnu_pbds;
using namespace std;

#define mp make_pair
#define eb emplace_back
#define pb push_back
#define e1 first
#define e2 second
#define vt vector
#define maxi(x,y) x=max(x,y)
#define mini(x,y) x=min(x,y)
#define size(x) (int)x.size()
#define all(r) begin(r),end(r)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define cx real()
#define cy imag()
#define precision(x) setprecision(x)<<fixed
#define time chrono::high_resolution_clock().now().time_since_epoch().count()
#ifndef DEBUG
#define DEBUG false
#endif
#define dbg if(DEBUG)

typedef long long ll;
typedef long double ld;
typedef complex<long double> cplx;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef vt<int> vi;
typedef vt<vi> vvi;
typedef vt<bool> vb;
typedef vt<vb> vvb;
typedef vt<char> vc;
typedef vt<vc> vvc;
typedef vt<string> vs;
typedef vt<vs> vvs;
typedef vt<ll> vll;
typedef vt<vll> vvll;
typedef vt<ld> vld;
typedef vt<vld> vvld;
typedef vt<cplx> vcplx;
typedef vt<vcplx> vvcplx;

template<typename T>
using ordset=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

template<typename T1,typename T2>
ostream& operator<<(ostream &os,pair<T1,T2>& VAR){
	os<<"("<<VAR.e1<<","<<VAR.e2<<")";
	return os;
}

template<typename T>
ostream& operator<<(ostream& os,vt<T>& VAR){
	os<<"[";
	for(int i=0;i<size(VAR)-1;i++)
		os<<VAR[i]<<",";
	if(size(VAR))
		os<<VAR.back();
	os<<"]";
	return os;
}

template<typename T>
istream& operator>>(istream& is,complex<T>& VAR){
	T value;
	is>>value;
	VAR.real(value);
	is>>value;
	VAR.imag(value);
	return is;
}

const bool TESTS=false;

/*
dp[i] -> minimal time required so that the car occupies the i'th place in the middle row

1. check if there is a car over koporski
	1.1 if there is no car, its optimal to just drive forward at max speed
	2.1 if there is a car, we know we shall pass through the middle row

2. we need to find the earliest opening in the middle that we can go to
	2.1 to find this opening, we must iterate over all of the middle elements, and check when is the earliest time we can go to it, if ever
	2.3 in case no such element exists, the first element before all the cars is the answer.

3. now that we found the earliest element, we know that we will never go lower in the second row. This is because we would make a cycle coming back up
	3.1 we just iterate over the positions in the dp from 0 to N, and for each position we check when is the earliest time we can go one above
		3.1.1 we can either go one above by going to the left on a faster lane, or to the right on a slower lane

4. we will implement going to the left using a simple prefix sum array, and going to the right using a segment tree (? maybe we can do this faster)

5. after computing all of the dp values, it's safe to assume that the answer is either dp[N] or dp[N] + time to overtake the farthest cars

overall the solution works in O(nlogn) with minor precision errors (i hope so), it might require some constant factor optimization

remember to stress test using the error function provided in the statement
*/

const int MAXN=2e5+10;

int max_velocity;
int velocity[3];
int last_in_lane[3];
bitset<MAXN> car[3];
int gap_length[3][MAXN];
int next_opening[3][MAXN];
int car_length[3][MAXN];
int car_length_down[3][MAXN];

ld dp[MAXN];

vi left_car_positions;
vi right_car_positions;

const int INT_INF=1e9+2137;
const ld LD_INF=1e18+2137;
const ld LD_INF_SMALL=1e9+2137;

const ld eps=1e-9;

const int base=(1<<18);

int segment_tree[base*2];

int find_geq(int p,ld val){
	//cout<<p<<' '<<val<<'\n';
	//int p2=p;
	p+=base;
	if(1.0*segment_tree[p]>=val-eps){
	
	}
	else{
		bool went_from_right;
		if(p&1)
			went_from_right=true;
		else
			went_from_right=false;
		p/=2;
		while(1.0*segment_tree[p*2+1]<val||went_from_right){
			if(p&1)
				went_from_right=true;
			else
				went_from_right=false;
			p/=2;
		}
		p=p*2+1;
		while(p<base){
			if(1.0*segment_tree[p*2]>=val-eps)
				p*=2;
			else
				p=p*2+1;
		}
	}
	//return p-base;
	/*p2+=base;
	while(1.0*segment_tree[p2]<val-eps)
		p2++;
	assert(1.0*segment_tree[p2]>=val-eps);*/
	//cout<<'\n';
	//cout<<"query answers:\n";
	//cout<<p2-base<<'\n';
	//cout<<p-base<<'\n';
	//cout<<'\n';
	//assert(p2==p);
	return p-base;
}

void solve(){
	//processing the input
	int n;
	cin>>n;
	cin>>max_velocity;
	for(int i=0;i<3;i++)
		cin>>velocity[i];
	for(int i=0;i<3;i++){
		string s;
		cin>>s;
		last_in_lane[i]=-1;
		for(int j=0;j<n;j++)
			if(s[j]=='#'){
				car[i][j+1]=true;
				last_in_lane[i]=j+1;
			}
	}
	//locate koporski
	int koporski_position;
	for(int i=0;i<=n;i++)
		if(car[2][i]){
			koporski_position=i;
			break;
		}
	car[2][koporski_position]=false;
	//helper function, allows to compute the time koporski will overtake all of the farthest cars, assuming that he is already the first in his lane
	function<ld(ld,ld)> overtake_all=[&](ld _time,ld position){
		ld added_time=0.0;
		for(int i=0;i<3;i++){
			if(last_in_lane[i]==-1)
				continue;
			ld car_end_position=1.0*last_in_lane[i]+_time*velocity[i]+1.0;
			ld time_needed=(car_end_position-position)/(1.0*(max_velocity-velocity[i]));
			if(time_needed>added_time)
				added_time=time_needed;
		}
		return _time+added_time;
	};
	if(koporski_position==last_in_lane[2]){
		last_in_lane[2]=-1;
		cout<<precision(12)<<overtake_all(0.0,koporski_position)<<'\n';
		return;
	}
	for(int i=0;i<3;i++){
		gap_length[i][n+1]=INT_INF;
		next_opening[i][n+1]=-1;
		for(int j=n;j>=0;j--){
			if(!car[i][j+1])
				next_opening[i][j]=j+1;
			else
				next_opening[i][j]=next_opening[i][j+1];
			if(car[i][j])
				gap_length[i][j]=0;
			else
				gap_length[i][j]=gap_length[i][j+1]+1;
		}
	}
	//set all dp values to infinity
	for(int i=0;i<=n+1;i++)
		dp[i]=LD_INF;
	//when does koporski get blocked if he goes up with max velocity
	ld koporski_gets_blocked=(1.0*gap_length[2][koporski_position]-1.0)/(1.0*(max_velocity-velocity[2]));
	for(int i=0;i<=n+1;i++){
		if(car[1][i])
			continue;
		if(i<koporski_position){
			ld koporski_alligns=(1.0*(koporski_position-i))/(1.0*velocity[1]);
			dp[i]=koporski_alligns;
		}
		else{
			ld koporski_alligns=(1.0*(i-koporski_position))/(1.0*(max_velocity-velocity[1]));	
			if(koporski_alligns<=koporski_gets_blocked+eps)
				dp[i]=koporski_alligns;
		}
	}
	//preparing the left cars for queries
	for(int i=0;i<=n+1;i++)
		if(car[0][i])
			left_car_positions.eb(i);
	for(int i=0;i<3;i++){
		for(int j=n+1;j>=0;j--){
			if(car[i][j])
				car_length[i][j]=car_length[i][j+1]+1;
			else
				car_length[i][j]=0;
		}
		if(car[i][0])
			car_length_down[i][0]=1;
		else
			car_length_down[i][0]=0;
		for(int j=1;j<=n+1;j++)
			if(car[i][j])
				car_length_down[i][j]=car_length_down[i][j-1]+1;
			else
				car_length_down[i][j]=0;
	}
	//preparing the right cars for queries
	for(int i=0;i<=n+1;i++)
		if(car[2][i])
			right_car_positions.eb(i);
	for(int i=0;i<=n+1;i++)
		segment_tree[base+i]=gap_length[2][i];
	for(int i=base-1;i>0;i--)
		segment_tree[i]=max(segment_tree[i*2],segment_tree[i*2+1]);
	ld ans=LD_INF;
	for(int i=0;i<=n+1;i++){
		//can we even reach this position as hakier koporski
		if(dp[i]>=LD_INF-eps)
			continue;
		if(i<=n){
			if(!car[1][i+1]){
				ld goes_up_by_one=1.0/(max_velocity-velocity[1]);
				ld total_time_up=dp[i]+goes_up_by_one;
				if(total_time_up<dp[i+1])
					dp[i+1]=total_time_up;
			}
			else{
				//go up using left lane
				if(last_in_lane[0]!=-1){
					ld left_lane_farthest=1.0*last_in_lane[0]+velocity[0]*dp[i]+1.0;
					ld koporski_begin_position=1.0*i+dp[i]*velocity[1];
					if(!(koporski_begin_position>=left_lane_farthest-eps)){
						int l=0,r=size(left_car_positions)-1;
						while(l<r){
							int m=(l+r)/2;
							ld left_car_height=1.0*left_car_positions[m]+velocity[0]*dp[i]+1.0*car_length[0][left_car_positions[m]];
							if(!(koporski_begin_position>=left_car_height-eps))
								r=m;
							else
								l=m+1;
						}
						//if(i==8)
						//	cout<<"XD\n";
						ld left_car_low=1.0*left_car_positions[l]+velocity[0]*dp[i];
						ld time_till_allign=((koporski_begin_position+1.0)-left_car_low)/(velocity[0]-velocity[1]);
						if(time_till_allign<0.0)
							time_till_allign=0.0;
						//if(i==8)
						//	cout<<time_till_allign+dp[i]<<'\n';
						//if(i==8){
						//	cout<<l<<'\n';
						//	cout<<koporski_begin_position<<' '<<left_car_low<<'\n';
						//}
						/*if(i==2)
							cout<<time_till_allign<<'\n';*/
						//i can cross to the left for free now
						koporski_begin_position+=time_till_allign*velocity[1];
						left_car_low+=time_till_allign*velocity[0];
						/*if(i==2){
							cout<<left_car_low<<' '<<koporski_begin_position+1.0<<'\n';
							cout<<2.0+(1.0/(15.0-10.0))*15.0<<'\n';
							cout<<dp[i]+time_till_allign<<'\n';
						}*/
						koporski_gets_blocked=(left_car_low-(koporski_begin_position+1.0))/(max_velocity-velocity[0]);
						/*if(i==2)
							cout<<koporski_gets_blocked<<'\n';*/
						ld next_car_position=koporski_begin_position+1.0+car_length[1][i+1];
						ld time_till_allign2=(next_car_position-koporski_begin_position)/(max_velocity-velocity[1]);
						if(time_till_allign2<koporski_gets_blocked+eps){
							ld total_time=time_till_allign+time_till_allign2+dp[i];
							if(total_time<dp[i+car_length[1][i+1]+1])
								dp[i+car_length[1][i+1]+1]=total_time;
						}
						else{
							koporski_begin_position+=koporski_gets_blocked*max_velocity;
							/*if(i==2)
								cout<<"XD\n";
							if(i==2){
								cout<<koporski_begin_position<<' '<<'\n';
								cout<<1.0*i+2.0+velocity[1]*(time_till_allign+dp[i]+koporski_gets_blocked)<<'\n';
								cout<<time_till_allign+dp[i]+koporski_gets_blocked<<'\n';
							}*/
							next_car_position+=koporski_gets_blocked*velocity[1];
							ld time_till_allign3=(next_car_position-koporski_begin_position)/(velocity[0]-velocity[1]);
							ld total_time=time_till_allign+koporski_gets_blocked+time_till_allign3+dp[i];
							//if(i==8)
							//	cout<<dp[i]+time_till_allign<<'\n';
							if(total_time<dp[i+car_length[1][i+1]+1])
								dp[i+car_length[1][i+1]+1]=total_time;
						}
					}
				}
				//go up using right lane
				{
					//we must find the lowest position that needs to disappear
					ld koporski_position_begin=1.0*i+dp[i]*velocity[1];
					ld koporski_position_end=koporski_position_begin+1.0;
					int l=0,r=size(right_car_positions)-1;
					int temp_ans=-1;
					while(l<=r){
						int m=(l+r)/2;
						ld right_car_depth=1.0*right_car_positions[m]+velocity[2]*dp[i]-1.0*car_length_down[2][right_car_positions[m]]+1.0;
						if(right_car_depth<=koporski_position_end+eps){
							temp_ans=m;
							l=m+1;
						}
						else
							r=m-1;
					}
					if(temp_ans!=size(right_car_positions)-1){
						ld move_to_accomodate;
						if(temp_ans==-1)
							move_to_accomodate=0.0;
						else{
							ld right_car_height=1.0*right_car_positions[temp_ans]+velocity[2]*dp[i]+1.0;
							move_to_accomodate=(right_car_height-koporski_position_begin)/(velocity[1]-velocity[2]);
							if(move_to_accomodate<0.0)
								move_to_accomodate=0.0;
						}
						koporski_position_begin+=move_to_accomodate*velocity[1];
						koporski_position_end=koporski_position_begin+1.0;
						ld time_to_next_empty=(1.0*car_length[1][i+1]+1.0)/(1.0*(max_velocity-velocity[1]));
						ld minimal_sufficient_length=time_to_next_empty*(1.0*(max_velocity-velocity[2]))+1.0;
						ld next_right_car_begin=1.0*right_car_positions[temp_ans+1]+(dp[i]+move_to_accomodate)*velocity[2];
						ld length_between=next_right_car_begin-koporski_position_end+1.0;
						/*if(i==2){
							cout<<"minimal_sufficient_length: "<<minimal_sufficient_length<<'\n';
							cout<<"length_between: "<<length_between<<'\n';
						}*/
						if(length_between>=minimal_sufficient_length-eps){
							/*if(i==4){
								cout<<"XD\n";
								cout<<minimal_sufficient_length<<'\n';
								cout<<length_between<<'\n';
								cout<<temp_ans<<'\n';
							}*/
							ld total_time=dp[i]+move_to_accomodate+time_to_next_empty;
							if(dp[i+car_length[1][i+1]+1]>total_time)
								dp[i+car_length[1][i+1]+1]=total_time;
						}
						else{
							//if(i==5)
							//	cout<<minimal_sufficient_length+1.0<<'\n';
							int pozycja_ziomka=find_geq(right_car_positions[temp_ans+1],minimal_sufficient_length);
							ld dokladna_pozycja_ziomka=1.0*pozycja_ziomka+dp[i]*velocity[2]+move_to_accomodate*velocity[2];
							ld czas_do_ziomka=(dokladna_pozycja_ziomka-koporski_position_begin)/(1.0*(velocity[1]-velocity[2]));
							ld total_time=dp[i]+move_to_accomodate+czas_do_ziomka+time_to_next_empty;
							/*if(i==10){
								cout<<"Right car: "<<right_car_positions[temp_ans+1]<<'\n';
								cout<<minimal_sufficient_length<<'\n';
								cout<<pozycja_ziomka<<' '<<segment_tree[pozycja_ziomka+base]<<'\n';
								cout<<koporski_position_begin<<' '<<dokladna_pozycja_ziomka<<'\n';
								cout<<temp_ans<<' '<<size(right_car_positions)<<'\n';
								cout<<dp[i]<<' '<<move_to_accomodate<<' '<<czas_do_ziomka<<' '<<time_to_next_empty<<'\n';
								//cout<<total_time<<'\n';
							}*/
							if(dp[i+car_length[1][i+1]+1]>total_time)
								dp[i+car_length[1][i+1]+1]=total_time;
						}
					}
				}
				//cos tu nie dziala, z jakiegos powodu mam lepsze wyniki niz sa faktycznie
			}
		}
		//do we win if we go straight up?
		if(gap_length[1][i]>=INT_INF){
			ld winning_time=overtake_all(dp[i],1.0*i+velocity[1]*dp[i]);
			if(winning_time<ans)
				ans=winning_time;
			continue;
		}
		//do we win if we go to the left?
		{
			if(last_in_lane[0]==-1){
				ld winning_time=overtake_all(dp[i],1.0*i+velocity[1]*dp[i]);
				if(winning_time<ans)
					ans=winning_time;
				continue;
			}
			else{
				koporski_gets_blocked=(1.0*gap_length[1][i]-1.0)/(1.0*(max_velocity-velocity[1]));
				ld koporski_car_begin_position=1.0*i+velocity[1]*dp[i]+koporski_gets_blocked*max_velocity;
				ld left_car_end_position=dp[i]*velocity[0]+1.0*last_in_lane[0]+1.0+koporski_gets_blocked*velocity[0];
				if(koporski_car_begin_position>=left_car_end_position-eps){
					ld winning_time=overtake_all(dp[i],1.0*i+velocity[1]*dp[i]);
					if(winning_time<ans)
						ans=winning_time;
					continue;
				}
			}
		}
		//do we win if we go to the right
		{
			/*if(i==4)
				cout<<"XD\n";*/
			koporski_gets_blocked=(1.0*gap_length[1][i]-1.0)/(1.0*(max_velocity-velocity[1]));
			/*if(i==4)
				cout<<"koporski_gets_blocked: "<<koporski_gets_blocked<<'\n';*/
			ld koporski_car_begin_position=1.0*i+velocity[1]*dp[i]+koporski_gets_blocked*max_velocity;
			/*if(i==4)
				cout<<"koporski_car_begin_position: "<<koporski_car_begin_position<<'\n';*/
			ld right_car_end_position=dp[i]*velocity[2]+1.0*last_in_lane[2]+1.0+koporski_gets_blocked*velocity[2];
			/*if(i==4)
				cout<<"right_car_end_position: "<<right_car_end_position<<'\n';*/
			if(koporski_car_begin_position>=right_car_end_position-eps){
				ld winning_time=overtake_all(dp[i],1.0*i+velocity[1]*dp[i]);
				if(winning_time<ans)
					ans=winning_time;
				continue;
			}
			ld additional_time_needed=(right_car_end_position-koporski_car_begin_position)/(1.0*(velocity[1]-velocity[2]));
			ld winning_time=overtake_all(dp[i]+koporski_gets_blocked+additional_time_needed,koporski_car_begin_position+additional_time_needed*velocity[1]);
			if(winning_time<ans)
				ans=winning_time;
		}
	}
	cout<<precision(13)<<ans<<'\n';
	//for(int i=0;i<=n+1;i++)
	//	cout<<dp[i]<<' ';
	/*for(int i=0;i<=n+1;i++)
		cout<<segment_tree[i+base]<<' ';
	cout<<'\n';
	cout<<find_geq(7,3.1);*/
	//for(int i=0;i<=n+1;i++)
	//	cout<<segment_tree[i+base]<<' ';
}

int32_t main(){
	fastio;
	if(TESTS){
		int TEST_COUNT;
		cin>>TEST_COUNT;
		for(int i=0;i<TEST_COUNT;i++)
			solve();
	}
	else
		solve();
	return 0;
}