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
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <array>
#include <random>
#include <cmath>
#include <chrono>
#include <list>
#include <ctime>
#include <sstream>
#include <queue>
#include <climits>
#include <stack>
#include <valarray>
#include <random>
#include <bitset>
#include <numeric>
#include <iomanip>
#include <cassert>
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;
#define rep(x, b, e) for(int x=(b); x<(e); ++x)
#define trav(a, x) for(auto& a : x)
#define ford(x, b, e) for(int x=((int)(b))-1; x>=(e); --x)
#define all(c) c.begin(),c.end()
#define sz(x) ((int)((x).size()))
#define pb push_back
#define eb emplace_back
#define st first
#define nd second
#define mp(x,y) make_pair(x,y)
typedef short int sint;
template<typename T> bool ckmin(T& a, const T& b){return b<a?a=b,1:0;}
template<typename T> bool ckmax(T& a, const T& b){return a<b?a=b,1:0;}

ll nwd(ll a, ll b) {
  return b == 0 ? a : nwd(b, a % b);
}

struct nu {
  ll p, q;
  nu() {
    p = 0;
    q = 1;
  }
  nu(ll x) {
    p = x;
    q = 1;
  }
  nu(ll x, ll y) {
    p = x;
    q = y;
  }

  double v() {
    return (double)p / q;
  }
};


template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const nu& a) {
  return to_string(a.p) + "/" + to_string(a.q);
}

string to_string(const string& s) {
  return '"' + s + '"';
}

string to_string(char c) {
  return string(1, c);
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}

template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

nu operator/(const nu& a, int x) {
  ll nw = nwd(a.p, x);
  x /= nw;
  // debug("div", a, x, nu(a.p / nw, a.q * x));
  return nu(a.p / nw, a.q * x);
}

nu operator*(const nu& a, int x) {
  ll nw = nwd(a.q, x);
  x /= nw;
  return nu(a.p * x, a.q / nw);
}

nu operator+(const nu& a, const nu& b) {
  // debug(a, b);
  ll up = a.p * b.q + b.p * a.q;
  ll nw = nwd(up, a.q * b.q);
  return nu(up / nw, a.q*b.q / nw);
}
nu operator+(const nu& a, int x) {
  // debug("adding", a, x, a + nu(x));
  return a + nu(x);
}

nu operator+(int x, const nu& a) {
  return a + x;
}

nu inf(1e18);
bool operator<(const nu& a, const nu&b) {
  if (a.p == inf.p) return false;
  if (b.p == inf.p) return true;
  return a.p * b.q < a.q * b.p;
}

bool operator==(const nu&a, const nu& b) {
  return a.p == b.p && a.q == b.q;
}

bool operator <=(const nu&a, const nu& b) {
  return a < b || a==b;
}

nu operator-(const nu& a, const nu& b) {
  ll licz = a.p * b.q - b.p * a.q;
  ll nw = nwd(licz, a.q * b.q);
  return nu(licz / nw, a.q * b.q / nw);
}

// #include <atcoder/modint>
// using namespace atcoder;
// using mint = modint998244353; // modint1000000007;
// typedef vector<mint> vmi;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); // use rng() to get unsigned int
// mt19937_64 for random long longs


const int N = 2e5 + 10;
int l;
int mv;
int v[3];
int c[3];
pair<int, int> cars[3][N];
nu f[3][N][2];
char inp[N];

nu best = inf;

bool DBG = false;

using State = tuple<int, int, bool>;

// void deb() {
//   rep(i, 0, 3) {
//     printf("%d: ", i);
//     rep(j, 0, c[i]) {
//       printf("(%lld, %lld) ", cars[i][j].st, cars[i][j].nd);
//     }
//     printf("\n");
//   }
// }

void writeAns() {
  // printf("tt: %lld\n", best);
  debug(best);
  printf("%.19Lf\n", (long double)best.p / best.q);
}

void checkAns(nu tt) {
  debug("checking max: ", tt);
  ckmin(best, tt);
}

void solve() {
  scanf("%d %d", &l, &mv);
  rep(i, 0, 3) {
    scanf("%d", &v[i]);
  }
  rep(i, 0, 3) {
    scanf("%s", inp);
    int len = strlen(inp);
    int wsk = 1;
    while (wsk < len) {
      if (inp[wsk] == '.') {
        ++wsk;
        continue;
      }
      int nwsk = wsk;
      while (nwsk < len && inp[nwsk] == '#') {
        ++nwsk;
      }
      int dl = nwsk - wsk;
      cars[i][c[i]++] = mp(wsk, dl); // poczatek, dlugosc
      wsk = nwsk;
    }
  }
  // deb();
  auto BridgeGapWithSpeed = [&](nu dist, int fastSpeed, int slowSpeed) {
    // debug(dist, fastSpeed, slowSpeed);
    return dist / (fastSpeed - slowSpeed);
  };
  auto BridgeGap = [&](int road, nu dist) {
    return BridgeGapWithSpeed(dist, mv, v[road]);
  };
  auto whereIsStart = [&](int road, int nr, nu tt) {
    // nu res = cars[road][nr].st + tt * v[road];
    // debug("wh start", road, nr, tt, cars[road][nr].st, tt * v[road], res);
    return cars[road][nr].st + tt * v[road];
  };
  auto whereIsEnd = [&](int road, int nr, nu tt) {
    return whereIsStart(road, nr, tt) + cars[road][nr].nd;
  };
  auto overtakeAll = [&](nu tt, nu myPosStart) { // myPos = where do I start
    nu mostTime = 0;
    rep(i, 0, 3) {
      if (c[i] == 0) continue;
      nu iDistance = whereIsEnd(i, c[i] - 1, tt);
      if (myPosStart < iDistance) {
        nu timeNeeded = BridgeGap(i, iDistance - myPosStart);
        ckmax(mostTime, timeNeeded);
      }
    }
    return mostTime;
  };
  auto printState = [&](int road, nu tt, nu myPosStart) {
    if (!DBG) return;
    printf("I am, tt: %.3lf: %.3lf - %.3lf\n", tt.v(), myPosStart.v(), (myPosStart+1).v());
    rep(i, 0, 3) {
      printf("%d: ", i);
      rep(j, 0, c[i]) {
        printf("(%.3lf - %.3lf) ", whereIsStart(i, j, tt).v(), whereIsEnd(i, j, tt).v());
      }
      printf("\n");
    }
  };
  auto find = [&](int road, nu tt, nu myPosEnd) { // find first that begins >= myPosEnd
    int p = 0, q = c[road];
    while (p < q) {
      int sr = (p + q) / 2;
      nu positionStart = whereIsStart(road, sr, tt);
      if (positionStart < myPosEnd)  {
        p = sr + 1;
      } else {
        q = sr;
      }
    }
    return p;
  };
  if (c[0] == 0 || c[1] == 0 || c[2] == 0) {
    nu tt = overtakeAll(0, 0);
    checkAns(tt);
    writeAns();
    return;
  }
  rep(i, 0, 3) {
    rep(j, 0, c[i]) {
      rep(k, 0, 2) f[i][j][k] = inf;
    }
  }
  vector<pii> ost(2);
  priority_queue<pair<nu, State>, vector<pair<nu, State>>, greater<pair<nu, State>>> pq;
  auto relax = [&](int road, int nr, bool after, nu ntime) {
    debug("relax: ", road, nr, after, ntime.v(), f[road][nr][after]);
    // if (f[road][nr][after] > ntime) {
    if (ntime < f[road][nr][after]) {
      debug("actual relax");
      f[road][nr][after] = ntime;
      pq.push(mp(ntime, make_tuple(road, nr, after)));
    }
  };
  auto freePosBefore = [&](int nroad, int oroad, nu tt, nu myPosStart, int cur_id, int next_car_id, nu distToOvertake) {
    debug("freeePosBEfore", nroad, oroad, tt.v(), myPosStart.v(), cur_id, next_car_id, distToOvertake.v());
    nu myPosEnd = myPosStart + 1;
    nu distToNextCar = whereIsStart(nroad, next_car_id, tt) - myPosEnd;
    nu timeToNextCar = BridgeGap(nroad, distToNextCar);

    // ll distToOvertake = cars[road][nr].nd + V;
    nu timeToOvertake = BridgeGap(oroad, distToOvertake);
    if (timeToOvertake <= timeToNextCar) {
      relax(oroad, cur_id, 1, tt + timeToOvertake);
    } else {
      // just go to next car
      relax(nroad, next_car_id, 0, tt + timeToNextCar);
    }
  };
  auto freeRoadAhead = [&](int road, int next_nr, nu tt, nu myPosStart) {
    nu myPosEnd = myPosStart + 1;
    nu distToCover = whereIsStart(road, next_nr, tt) - myPosEnd;
    // debug(myPosEnd, whereIsStart(road, next_nr, tt), distToCover);
    nu timeToNextCar = BridgeGap(road, distToCover);
    // debug(myPosEnd, distToCover, timeToNextCar);
    relax(road, next_nr, 0, tt + timeToNextCar);

    // I have timeToNextCar
    debug("FREEE ROAD AHEAD");
    // I can maybe move up or down:
    if (road) {
      // trying to move up
      int nr = find(road - 1, tt, myPosEnd);
      debug("next guy in front of me: ", nr);
      if (nr == 0 || whereIsEnd(road - 1, nr - 1, tt) <= myPosStart) {
        debug("I can slot directly in");
        // i can slot in directly, go up and until the next car
        if (nr == c[road - 1]) {
          // I'm done
          nu timeNeededToOvertakeAll = overtakeAll(tt, myPosStart);
          checkAns(timeNeededToOvertakeAll + tt);
        } else {
          nu distToCover = whereIsStart(road - 1, nr, tt) - myPosEnd;
          nu timeToCover = BridgeGap(road - 1, distToCover);
          relax(road - 1, nr, 0, tt + timeToCover);


          // maybe I can get in front of him
          distToCover = whereIsEnd(road - 1, nr, tt) - myPosStart;
          timeToCover = BridgeGap(road - 1, distToCover);
          if (timeToCover <= timeToNextCar) {
            relax(road - 1, nr, 1, tt + timeToCover);
          }
        }
      } else {
        debug(" I have to wait or speed up in current lane");
        // I can do 1 of 2 things
        //  a) speed up in my current line, when I have only timeToNextCar time
        //  b) slow down and wait until they pass me. I should try both
        // a)
        nu distToCover = whereIsEnd(road - 1, nr - 1, tt) - myPosStart;
        nu timeToCover = BridgeGap(road - 1, distToCover);
        debug("to outpace haster guy, I need ", timeToCover.v(), "and I have: " , timeToNextCar.v());
        if (timeToCover <= timeToNextCar) {
          relax(road - 1, nr - 1, 1, tt + timeToCover);
        }

        // b) wait a bit
        distToCover = myPosEnd - whereIsStart(road - 1, nr - 1, tt);
        timeToCover = BridgeGapWithSpeed(distToCover, v[road - 1], v[road]);
        relax(road - 1, nr - 1, 0, tt + timeToCover);
      }

      if (road + 1 < 3) {
        int nr = find(road + 1, tt, myPosEnd);
        // debug("slower road")
        if (nr == 0 || whereIsEnd(road + 1, nr - 1, tt) <= myPosStart) {
          // i can slot in directly, go up and until the next car
          if (nr == c[road + 1]) {
            // I'm done
            nu timeNeededToOvertakeAll = overtakeAll(tt, myPosStart);
            checkAns(timeNeededToOvertakeAll + tt);
          } else {
            nu distToCover = whereIsStart(road + 1, nr, tt) - myPosEnd;
            nu timeToCover = BridgeGap(road + 1, distToCover);
            relax(road + 1, nr, 0, tt + timeToCover);

            // maybe I can get in front
            distToCover = whereIsEnd(road + 1, nr, tt) - myPosStart;
            timeToCover = BridgeGap(road + 1, distToCover);
            if (timeToCover <= timeToNextCar) {
              relax(road + 1, nr, 1, tt + timeToCover);
            }
          }
        } else {
          // I can do 1 of 2 things
          //  a) speed up in my current line, when I have only timeToNextCar time
          //  b) slow down and wait until they pass me. I should try both
          // a)
          nu distToCover = whereIsEnd(road + 1, nr - 1, tt) - myPosStart;
          nu timeToCover = BridgeGap(road + 1, distToCover);
          if (timeToCover <= timeToNextCar) {
            relax(road + 1, nr - 1, 1, tt + timeToCover);
          } else {

            // b) wait a bit
            distToCover = whereIsEnd(road + 1, nr - 1, tt) - myPosStart;
            timeToCover = BridgeGapWithSpeed(distToCover, v[road], v[road + 1]);
            relax(road + 1, nr - 1, 1, tt + timeToCover);
          }
        }

      }
    }
    debug("END OF FREEE ROAD AHEAD");
  };
  rep(i, 0, 3) {
    freeRoadAhead(i, 0, 0, 0);
  }
  while (true) {
    debug("special loop");
    rep(i, 0, 2) {
      // for these roads:
      nu ttt = f[i][ost[i].st][0];
      nu myStart = whereIsStart(i, ost[i].st, ttt) - 1; // where my car starts
      debug("special", i, myStart.v(), ttt.v());
      // ??????
      while (ost[i].nd < c[i+1] && whereIsEnd(i + 1, ost[i].nd, ttt) < myStart) {
        ++ost[i].nd;
      }
      if (ost[i].nd == c[i + 1]) continue;
      nu dist = whereIsEnd(i + 1, ost[i].nd, f[i][ost[i].st][0]) - myStart;
      nu timeToWait = BridgeGapWithSpeed(dist, v[i], v[i + 1]);
      debug(dist.v(), timeToWait.v(), ttt + timeToWait);
      if (pq.empty() || ttt + timeToWait < pq.top().st) {
        relax(i + 1, ost[i].nd, true, ttt + timeToWait);
        ++ost[i].nd;
      }
    }
    debug("ost", ost);
    if (pq.empty()) {
      break;
    }

    auto [tt, state] = pq.top(); pq.pop();
    auto [road, nr, after] = state;
    if (f[road][nr][after] < tt) {
      continue;
    }

    nu myPosStart, myPosEnd;
    if (after == false) {
      myPosStart = whereIsStart(road, nr, tt) - 1;
    } else {
      myPosStart = whereIsEnd(road, nr, tt);
    }
    printState(road, tt, myPosStart);
    debug(road, nr, after, tt.v(), myPosStart.v());
    if (road < 2 && after == false)ckmax(ost[road].st, nr);
    myPosEnd = myPosStart + 1;
    if (nr + 1 == c[road] && after) {
      // means I only have to accelerate
      nu mostTime = overtakeAll(tt, myPosStart);
      checkAns(tt + mostTime);
      continue;
    }

    if (after == false) {
      // debug("stuck behind");
      // I am stuck right behind someone

      // try to move to faster lane
      if (road) {
        debug("move to faster road");
        int nNr = find(road - 1, tt, myPosEnd);
        if (nNr == 0 || !(myPosStart < whereIsEnd(road - 1, nNr - 1, tt))) { //whereIsEnd(road - 1, nNr - 1, tt) <= myPosStart) {
          debug("I can directly slot in to faster road");
          if (nNr == c[road - 1]) {
            // I'm done
            nu timeNeededToOvertakeAll = overtakeAll(tt, myPosStart);
            checkAns(timeNeededToOvertakeAll + tt);
          } else {
            // I can move directly in
            // -- need to consider what happens first
            // a) I get to the back of the next car in this lane
            // b) I can slot in front of the car I was just in
            freePosBefore(road - 1, road, tt, myPosStart, nr, nNr, cars[road][nr].nd + 1);
          }
        } else {
          debug(" I need to wait to a faster road");
          //     // musze chwile poczekac
          nu distToCover = myPosEnd - whereIsStart(road - 1, nNr - 1, tt);
          nu timeToWait = BridgeGapWithSpeed(distToCover, v[road - 1], v[road]);
          nu nTT = tt + timeToWait;
          relax(road - 1, nNr - 1, 0, nTT); // I can be just behind this guy in faster lane
        }
      }

      if (road + 1 < 3) {
        debug("Move to slower road");
        int nNr = find(road + 1, tt, myPosEnd);
        if (nNr == 0 || whereIsEnd(road + 1, nNr - 1, tt) <= myPosStart ) { // whereIsEnd(road + 1, nNr -1, tt) <= myPosStart) {
          debug(" I can directly slot in");
          if (nNr == c[road + 1]) {
            // I'm done
            nu timeNeededToOvertakeAll = overtakeAll(tt, myPosStart);
            debug("time needed", timeNeededToOvertakeAll);
            checkAns(timeNeededToOvertakeAll + tt);
          } else {
            freePosBefore(road + 1, road, tt, myPosStart, nr, nNr, cars[road][nr].nd + 1);
          }
          ++nNr;
        }
        // lets try to go in front of this dude. So try to get to (road + 1, nNr, 1)
        // rep(i, nNr - 1, c[road + 1]) {
        //   double distToCover = whereIsEnd(road + 1, i, tt) - myPosStart;
        //   double timeToWait = BridgeGapWithSpeed(distToCover, v[road], v[road + 1]);
        //   relax(road + 1, i, 1, tt + timeToWait);
        // }
      }
    } 
    if (after == true) {
      // I am right in front of a car

      // 1) try to bridge to next car
      freeRoadAhead(road, nr + 1, tt, myPosStart);
      // maybe try to slot in before car in other lane
    }
  }
  // assert(best < inf);
  writeAns();
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	int t;
	// cin >> t;
	t = 1;
	while (t--) {
		solve();
	}
}