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
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define mp make_pair
#define all(a) begin(a),end(a)
#define FOR(x,val,to) for(int x=(val);x<int((to));++x)
#define FORE(x,val,to) for(auto x=(val);x<=(to);++x)
#define FORR(x,arr) for(auto &x: arr)
#define FORS(x,plus,arr) for(auto x = begin(arr)+(plus); x != end(arr); ++x)
#define FORREV(x,plus,arr) for(auto x = (arr).rbegin()+(plus); x !=(arr).rend(); ++x)
#define REE(s_) {cout<<s_<<'\n';exit(0);}
#define GET(arr) for(auto &i: (arr)) sc(i)
#define whatis(x) cerr << #x << " is " << (x) << endl;
#define e1 first
#define e2 second
#define INF 0x7f7f7f7f
typedef std::pair<int,int> pi;
typedef std::vector<int> vi;
typedef std::vector<std::string> vs;
typedef int64_t ll;
typedef uint64_t ull;
#define umap unordered_map
#define uset unordered_set
using namespace std;
using namespace __gnu_pbds;

#ifdef ONLINE_JUDGE
#define whatis(x) ;
#endif
#ifdef _WIN32
#define getchar_unlocked() _getchar_nolock()
#define _CRT_DISABLE_PERFCRIT_LOCKS
#endif
template<class L, class R> ostream& operator<<(ostream &os, map<L, R> P) { for(auto const &vv: P)os<<"("<<vv.first<<","<<vv.second<<")"; return os; }
template<class T> ostream& operator<<(ostream &os, set<T> V) { os<<"[";for(auto const &vv:V)os<<vv<<","; os<<"]"; return os; }
template<class T> ostream& operator<<(ostream &os, vector<T> V) { os<<"[";for(auto const &vv:V)os<<vv<<","; os<<"]"; return os; }
template<class L, class R> ostream& operator<<(ostream &os, pair<L, R> P) { os<<"("<<P.first<<","<<P.second<<")"; return os; }
inline int fstoi(const string &str){auto it=str.begin();bool neg=0;int num=0;if(*it=='-')neg=1;else num=*it-'0';++it;while(it<str.end()) num=num*10+(*it++-'0');if(neg)num*=-1;return num;}
inline void getch(char &x){while(x = getchar_unlocked(), x < 33){;}}
inline void getstr(string &str){str.clear(); char cur;while(cur=getchar_unlocked(),cur<33){;}while(cur>32){str+=cur;cur=getchar_unlocked();}}
template<typename T> inline bool sc(T &num){ bool neg=0; int c; num=0; while(c=getchar_unlocked(),c<33){if(c == EOF) return false;} if(c=='-'){ neg=1; c=getchar_unlocked(); } for(;c>47;c=getchar_unlocked()) num=num*10+c-48; if(neg) num*=-1; return true;}template<typename T, typename ...Args> inline void sc(T &num, Args &...args){ bool neg=0; int c; num=0; while(c=getchar_unlocked(),c<33){;} if(c=='-'){ neg=1; c=getchar_unlocked(); } for(;c>47;c=getchar_unlocked()) num=num*10+c-48; if(neg) num*=-1; sc(args...); }
template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; //s.find_by_order(), s.order_of_key() <- works like lower_bound
template<typename T> using ordered_map = tree<T, int, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define N 1000001

#define double long double
// stuck in inf loop or asserts without that.
// maybe lower eps?
#define whatis(x) ;
#define assert(x) ;

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    cerr << fixed << setprecision(15);
    cout << fixed << setprecision(15);
    int L, v0, v1, v2, v3;
    sc(L, v0, v1, v2, v3);
    /* vi cars[3], notcars[3]; */
    vi cars[3];
    vector<pi> notcars[3];
    FOR(i,0,3){
        string s;
        getstr(s);
        if(i == 2)
            s[0] = '.';
        int p = 0;
        FOR(x,0,L){
            if(s[x] == '#'){
                cars[i].push_back(x);
                if(s[x - 1] != '#'){
                    /* notcars[i].push_back({p, x}); */
                    notcars[i].push_back({p, x - 1});
                    /* p = x + 1; */ // nice bug, thx for -1h of my life
                }
                p = x + 1;
            }
            /* else */
            /*     notcars[i].push_back(x); */
        }
        notcars[i].push_back({p, INF / 3});
    }
    /* constexpr double eps = 1e-12; */
    /* constexpr double eps = 1e-8; */
    constexpr double eps = 1e-9;
    /* constexpr double eps = 1e-10; */
    double pos[3]{};
    double v[3]{static_cast<double>(v1), static_cast<double>(v2), static_cast<double>(v3)};
    double t{};
    int it = 0;
    int carit[3]{};
    int notcarit[3][3]{};
    /* memset(notcarit, -1, sizeof notcarit); */
/* #define whatis(x) ; */
    for(;;){
        /* if(++it == 10) */
        /*     exit(0); */
        whatis(t)
        /* whatis(vector<double>(pos, pos + 3)) */
        /* FOR(x,0,3){ */
        /*     vector<double> ts; */
        /*     FORR(i,cars[x]){ */
        /*         ts.push_back(i + v[x] * t); */
        /*     } */
        /*     whatis(ts) */
        /* } */
        // z 3 do 2 i z 2 do 1. -> first process 1 then 3 then 2.
        /* FOR(i,0,3){ */
        bool didupd = 0;
        FORR(i,(vi{0,2,1})){
            FOR(x,0,3){
                if(abs(i - x) != 1)
                    continue;
                while(notcarit[i][x] + 1 < notcars[x].size() && notcars[x][notcarit[i][x] + 1].e1 + t * v[x] - eps <= pos[i])
                    ++notcarit[i][x];
                double updpos = min(notcars[x][notcarit[i][x]].e2 + t * v[x], pos[i]);
                if(pos[x] < updpos){
                    pos[x] = updpos;
                    /* whatis(i) */
                    /* whatis(x) */
                    /* whatis(j) */
                    /* whatis(j.e1 + t * v[x]) */
                    /* whatis(j.e2 + t * v[x]) */
                    /* whatis(pos[i]) */
                    /* whatis("upd") */
                    didupd = 1;
                }
                // brrr for now.
                /* FORR(j, notcars[x]){ */
                /*     /1* if(j.e1 + t * v[x] <= pos[i] && j.e2 + t * v[x] >= pos[i]){ // TODO eps *1/ */
                /*     /1* if(j.e2 + t * v[x] + eps <= pos[i]){ // pls let that be the sole missing piece. *1/ */
                /*     /1*     if(pos[x] < j.e2 + t * v[x]){ *1/ */
                /*     /1*         pos[x] = j.e2 + t * v[x]; *1/ */
                /*     /1*         whatis(i) *1/ */
                /*     /1*         whatis(x) *1/ */
                /*     /1*         whatis(j) *1/ */
                /*     /1*         /2* whatis(j.e1 + t * v[x]) *2/ *1/ */
                /*     /1*         /2* whatis(j.e2 + t * v[x]) *2/ *1/ */
                /*     /1*         /2* whatis(pos[i]) *2/ *1/ */
                /*     /1*         whatis("backupd") *1/ */
                /*     /1*         didupd = 1; *1/ */
                /*     /1*     } *1/ */
                /*     /1* } *1/ */
                /*     /1* if(j.e1 + t * v[x] - eps <= pos[i] && j.e2 + t * v[x] + eps >= pos[i]){ // TODO eps *1/ */
                /*     /1*     /2* pos[x] = max(pos[x], pos[i]); *2/ *1/ */
                /*     /1*     if(pos[x] < pos[i]){ *1/ */
                /*     /1*         pos[x] = pos[i]; *1/ */
                /*     /1*         whatis(i) *1/ */
                /*     /1*         whatis(x) *1/ */
                /*     /1*         whatis(j) *1/ */
                /*     /1*         whatis(j.e1 + t * v[x]) *1/ */
                /*     /1*         whatis(j.e2 + t * v[x]) *1/ */
                /*     /1*         whatis(pos[i]) *1/ */
                /*     /1*         whatis("upd") *1/ */
                /*     /1*         didupd = 1; *1/ */
                /*     /1*     } *1/ */
                /*     /1* } *1/ */
                /*     if(j.e1 + t * v[x] - eps <= pos[i]){ // TODO eps */
                /*         double updpos = min(j.e2 + t * v[x], pos[i]); */
                /*         if(pos[x] < updpos){ */
                /*             pos[x] = updpos; */
                /*             whatis(i) */
                /*             whatis(x) */
                /*             whatis(j) */
                /*             whatis(j.e1 + t * v[x]) */
                /*             whatis(j.e2 + t * v[x]) */
                /*             whatis(pos[i]) */
                /*             whatis("upd") */
                /*             didupd = 1; */
                /*         } */
                /*     } */
                /* } */
            }
        }
        if(didupd){
            /* whatis(vector<double>(pos, pos + 3)) */
            FOR(i,0,3){
                FOR(x,0,3){
                    if(abs(i - x) != 1)
                        continue;
                    while(notcarit[i][x] + 1 < notcars[x].size() && notcars[x][notcarit[i][x] + 1].e1 + t * v[x] - eps <= pos[i])
                        ++notcarit[i][x];
                }
            }
        }
        double mxp = max({pos[0], pos[1], pos[2]});
        double mxoth = -1;
        FOR(x,0,3){
            if(!cars[x].empty()){
                mxoth = max(mxoth, cars[x].back() + t * v[x]);
            }
        }
        if(abs(mxp - mxoth - 1) < eps){
            cout << t << '\n';
            exit(0);
        }
        // xd, mx delta. min isn't the strat here obv.
        /* double mxdt = 0; */
        double mndt = __builtin_inf();
        int mysp[3];
        FOR(i,0,3){
            double nxtcr = -1;
            while(carit[i] < cars[i].size() && cars[i][carit[i]] + t * v[i] <= pos[i]){
                ++carit[i];
            }
            if(carit[i] != cars[i].size())
                nxtcr = cars[i][carit[i]] + t * v[i];
            /* FORR(j, cars[i]){ */
            /*     if(j + t * v[i] > pos[i]){ // no need for eps here. */
            /*         /1* nxtcr = j; *1/ */
            /*         nxtcr = j + t * v[i]; */
            /*         break; */
            /*     } */
            /* } */
            int crv = nxtcr != -1 && abs(nxtcr - pos[i] - 1) < eps ? v[i] : v0;
            mysp[i] = crv;
            whatis(i)
            if(nxtcr == -1){ // at this point, nie muszę już zjeżdzać nigdzie.
                FOR(x,0,3){
                    if(!cars[x].empty() && cars[x].back() + t * v[x] - pos[i] + 1 > eps){
                        double dt = (cars[x].back() + t * v[x] - pos[i] + 1) / (v0 - v[x]);
                        whatis(cars[x].back() + t * v[x])
                        whatis(pos[i])
                        whatis(mxp)
                        whatis(mxoth)
                        whatis(mxp - mxoth)
                        assert(dt > eps / 2);
                        whatis("delta till will possibility:")
                        whatis(dt)
                        mndt = min(mndt, dt);
                    }
                }
                continue;
            }
            if(crv == v0){
                double dt = (nxtcr - pos[i] - 1) / (v0 - v[i]);
                /* whatis(nxtcr) */
                /* whatis(dt) */
                /* whatis(pos[i]) */
                assert(abs(nxtcr - pos[i] - 1) > eps); // this doesn't trigger
                assert(dt > eps / 2); // this doues
                whatis("crv == v0 delta till nxtcr:")
                whatis(dt)
                mndt = min(mndt, dt);
            }
            // todo być może muszę się zatrzymywać.
            FOR(x,0,3){
                if(abs(i - x) != 1)
                    continue;
                if(crv <= v[x])
                    continue;
                /* auto it = lower_bound(all(notcars[x]), pos[i] + eps, [&](double val, pi j){return j.e1 + t * v[x] > val;}); */
                /* if(j.e1 + t * v[x] >= pos[i] + eps && crv > v[x]){ // TODO eps */
                /*     double dt = (j.e1 + t * v[x] - pos[i]) / (crv - v[x]); */
                /*     if(pos[i] + (t + dt) * crv - eps < pos[x] + (t + dt) * v[x]){ // pesymistycznie. (być może tam v0 jest e.g.) */
                /*         break; */
                /*     } */
                /*     whatis("delta till overtaking possibility:") */
                /*     whatis(x) */
                /*     whatis(dt) */
                /*     assert(dt > eps / 2); */
                /*     mndt = min(mndt, dt); */
                /*     break; */
                /* } */
                if(notcarit[i][x] + 1 < notcars[x].size()){
                    assert(notcars[x][notcarit[i][x] + 1].e1 + t * v[x] >= pos[i] + eps); // triggered.
                    // -> czej, bo mógł być jeszcze update pozycji przez
                    // overtaking na początku.
                    assert(!(notcars[x][notcarit[i][x]].e1 + t * v[x] >= pos[i] + eps));
                    double dt = (notcars[x][notcarit[i][x] + 1].e1 + t * v[x] - pos[i]) / (crv - v[x]);
                    // less useless overtakes:
                    if(pos[i] + (t + dt) * crv - eps < pos[x] + (t + dt) * v[x]){ // pesymistycznie. (być może tam v0 jest e.g.)
                        /* break; */
                        continue;
                    }
                    whatis("delta till overtaking possibility:")
                    whatis(x)
                    whatis(dt)
                    assert(dt > eps / 2);
                    mndt = min(mndt, dt);
                    /* break; */
                }
                /* FORR(j, notcars[x]){ */
                /*     /1* if(j.e1 + t * v[x] <= pos[i] && j.e2 + t * v[x] >= pos[i]){ *1/ */
                /*     /1*     pos[x] = max(pos[x], pos[i]); *1/ */
                /*     /1*     /2* break; // did switch right now. *2/ *1/ */
                /*     /1*     // Actually, even if did switch right now, still have *1/ */
                /*     /1*     // to consider next one. *1/ */
                /*     /1* } *1/ */
                /*     /1* if(j.e1 + t * v[x] >= pos[i] + eps){ // TODO eps *1/ */
                /*     if(j.e1 + t * v[x] >= pos[i] + eps && crv > v[x]){ // TODO eps */
                /*         // wait, lane matters xd. */
                /*         // also, crv. */
                /*         /1* double dt = (j.e1 + t * v[x] - pos[i]) / (v0 - v[x]); *1/ */
                /*         double dt = (j.e1 + t * v[x] - pos[i]) / (crv - v[x]); */
                /*         // less useless overtakes: */
                /*         if(pos[i] + (t + dt) * crv - eps < pos[x] + (t + dt) * v[x]){ // pesymistycznie. (być może tam v0 jest e.g.) */
                /*             break; */
                /*         } */
                /*         whatis("delta till overtaking possibility:") */
                /*         whatis(x) */
                /*         whatis(dt) */
                /*         assert(dt > eps / 2); */
                /*         mndt = min(mndt, dt); */
                /*         break; */
                /*     } */
                /*     /1* else if(crv < v[x] && j.e2 + t * v[x] <= pos[i] - eps){ *1/ */
                /*     /1*     double dt = (pos[i] - j.e2 + t * v[x]) / (v[x] - crv); *1/ */
                /*     /1*     whatis("backdelta till overtaking possibility:") *1/ */
                /*     /1*     whatis(x) *1/ */
                /*     /1*     whatis(dt) *1/ */
                /*     /1*     assert(dt > eps / 2); *1/ */
                /*     /1*     mndt = min(mndt, dt); *1/ */
                /*     /1*     /2* break; *2/ *1/ */
                /*     /1* } *1/ */
                /* } */
            }
        }
        assert(mndt != __builtin_inf());
        assert(mndt > eps / 2);
        FOR(i,0,3){
            pos[i] += mysp[i] * mndt;
        }
        t += mndt;
    }
    /* cout << t << '\n'; */
}