Problem:
A Die Maker
The work of die makers starts early in the morning.
You are a die maker.
You receive orders from customers, and make various kinds of dice every day.
Today, you received an order of a cubic die with six numbers
t
1
,
t
2
, ...,
t
6
on whichever faces.
For making the ordered die, you use a tool of flat-board shape.
You initially have a die with a zero on each face.
If you rotate the die by 90 degrees on the tool towards one of northward, southward, eastward, and southward,
the number on the face that newly touches the tool is increased by one.
By rotating the die towards appropriate directions repeatedly,
you may obtain the ordered die.
The final numbers on the faces of the die
is determined by the sequence of directions towards which you rotate the die.
We call the string that represents the sequence of directions an
operation sequence.
Formally, we define operation sequences as follows.
An operation sequence consists of
n
characters, where
n
is the number of rotations made.
If you rotate the die eastward in the
i
-th rotation,
the
i
-th character of the operation sequence is
E
.
Similarly, if you rotate it westward, it is
W
,
if southward, it is
S
, otherwise,
if northward, it is
N
.
For example, the operation sequence
NWS
represents
the sequence of three rotations, northward first, westward next,
and finally southward.
Given six integers of the customer's order,
compute an operation sequence that makes a die to order.
If there are two or more possibilities, you should compute the earliest operation sequence in dictionary order.
Input
The input consists of multiple datasets.
The number of datasets does not exceed 40.
Each dataset has the following form.
t
1
t
2
t
3
t
4
t
5
t
6
p
q
t
1
,
t
2
, ...,
t
6
are integers that represent the order from the customer.
Further,
p
and
q
are positive integers that specify the output range of the operation sequence (see the details below).
Each dataset satisfies
0 ≤
t
1
≤
t
2
≤ ... ≤
t
6
≤ 5,000
and
1 ≤
p
≤
q
≤
t
1
+
t
2
+...+
t
6
.
A line containing six zeros denotes the end of the input.
Output
For each dataset,
print the subsequence,
from the
p
-th position to the
q
-th position, inclusively,
of the operation sequence that is the earliest in dictionary order.
If it is impossible to make the ordered die, print
impossible
.
Here, dictionary order is recursively defined as follows.
The empty string comes the first in dictionary order.
For two nonempty strings
x
=
x
1
...
x
k
and
y
=
y
1
...
y
l
, the string
x
precedes the string
y
in dictionary order if
x
1
precedes
y
1
in alphabetical order ('A' to 'Z'), or
x
1
and
y
1
are the same character and
x
2
...
x
k
precedes
y
2
...
y
l
in dictionary order.
Sample Input
1 1 1 1 1 1
1 6
1 1 1 1 1 1
4 5
0 0 0 0 0 2
1 2
0 0 2 2 2 4
5 9
1 2 3 4 5 6
15 16
0 1 2 3 5 9
13 16
2 13 22 27 31 91
100 170
0 0 0 0 0 0
Output for the Sample Input
EEENEE
NE
impossible
NSSNW
EN
EWNS
SNSNSNSNSNSNSNSNSNSNSNSSNSNSNSNSNSNSNSNSNSNSNSNSNSNSNSNSNSNSNSNSNSNWEWE

Submitted solutions:

code_snippet: #include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) sort(ALL(v)), (v).erase(unique(ALL(v)), (v).end())
#define SZ(v) (int)v.size()
#define MIN(v) *min_element(ALL(v))
#define MAX(v) *max_element(ALL(v))
#define LB(v, x) int(lower_bound(ALL(v), (x)) - (v).begin())
#define UB(v, x) int(upper_bound(ALL(v), (x)) - (v).begin())

using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long;
using i128 = __int128_t;
using u128 = __uint128_t;
const int inf = 0x3fffffff;
const ll INF = 0x1fffffffffffffff;

template <typename T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T, typename U> T ceil(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? (x + y - 1) / y : x / y);
}
template <typename T, typename U> T floor(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? x / y : (x - y + 1) / y);
}
template <typename T> int popcnt(T x) {
    return __builtin_popcountll(x);
}
template <typename T> int topbit(T x) {
    return (x == 0 ? -1 : 63 - __builtin_clzll(x));
}
template <typename T> int lowbit(T x) {
    return (x == 0 ? -1 : __builtin_ctzll(x));
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "P(" << p.first << ", " << p.second << ")";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &map_var) {
    os << "{";
    for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
        os << "(" << itr->first << ", " << itr->second << ")";
        itr++;
        if (itr != map_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &set_var) {
    os << "{";
    for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
        os << *itr;
        ++itr;
        if (itr != set_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
#ifdef LOCAL
#define show(...) _show(0, #__VA_ARGS__, __VA_ARGS__)
#else
#define show(...) true
#endif
template <typename T> void _show(int i, T name) {
    cerr << '\n';
}
template <typename T1, typename T2, typename... T3>
void _show(int i, const T1 &a, const T2 &b, const T3 &...c) {
    for (; a[i] != ',' && a[i] != '\0'; i++)
        cerr << a[i];
    cerr << ":" << b << " ";
    _show(i + 1, a, c...);
}

/**
 * @brief template
 */

char CINF = (char)('Z'+1);
string SINF(1,CINF);

string MOVE = "ENSW";

struct Dice {
    int A[6];
    int &operator[] (int i) {
        return A[i];
    }
};

Dice rotE(Dice D) {
    Dice E;
    E[0] = D[1];
    E[1] = D[5];
    E[2] = D[2];
    E[3] = D[3];
    E[4] = D[0];
    E[5] = D[4];
    return E;
}

Dice rotN(Dice D) {
    Dice E;
    E[0] = D[2];
    E[1] = D[1];
    E[2] = D[5];
    E[3] = D[0];
    E[4] = D[4];
    E[5] = D[3];
    return E;
}

Dice rotS(Dice D) {
    Dice E;
    E[0] = D[3];
    E[1] = D[1];
    E[2] = D[0];
    E[3] = D[5];
    E[4] = D[4];
    E[5] = D[2];
    return E;
}

Dice rotW(Dice D) {
    Dice E;
    E[0] = D[4];
    E[1] = D[0];
    E[2] = D[2];
    E[3] = D[3];
    E[4] = D[5];
    E[5] = D[1];
    return E;
}

Dice rot(Dice D, int i) {
    if (i == 0) return rotE(D);
    if (i == 1) return rotN(D);
    if (i == 2) return rotS(D);
    if (i == 3) return rotW(D);
    return D;
}

string Solve(vector<int> A) {
    auto Judge = [&](Dice D) -> bool {
        if (D[0] < 0) return false;
        int SUM = 0;
        rep(i,0,6) SUM += D[i];
        vector<int> Y(3);
        rep(i,0,3) Y[i] = D[i] + D[5-i];
        if (Y[0] > SUM / 2) return false;
        if (Y[1] > (SUM+1) / 2) return false;
        if (Y[2] > (SUM+1) / 2) return false;
        return true;
    };
    auto canMove = [&](Dice D, int i) -> bool {
        auto E = rot(D,i);
        E[0]--;
        return Judge(E);
    };
    bool check = false;
    Dice D;
    rep(i,0,6) D[i] = A[i];
    rep(i,0,4) {
        if (canMove(D,i)) check = true;
    }
    if (!check) return SINF;
    string Ret = "";
    int COUNT = 0;
    rep(i,0,6) COUNT += A[i];
    while(COUNT--) {
        int next = -1;
        rep(i,0,4) {
            if (canMove(D,i)) {
                next = i;
                break;
            }
        }
        Ret += MOVE[next];
        D = rot(D,next);
        D[0]--;
    }
    return Ret;
}

int main() {
while(1) {
    vector<int> A(6);
    int COUNT = 0;
    rep(i,0,6) cin >> A[i], COUNT += A[i];
    if (COUNT == 0) return 0;
    int X, Y;
    cin >> X >> Y;
    X--;
    vector<int> ord(6);
    iota(ALL(ord),0);
    string ANS = SINF;
    do {
        vector<int> B(6);
        rep(i,0,6) B[i] = A[ord[i]];
        string Ret = Solve(B);
        chmin(ANS, Ret);
    } while(next_permutation(ALL(ord)));
    if (ANS == SINF) {
        cout << "impossible" << endl;
    }
    else {
        cout << ANS.substr(X,Y-X) << endl;
    }
}
}
accuracy: 1
time_ms: 6490
memory_kb: 3260
final_rank: 17

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = int;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vd = vector<double>;
using vvd = vector<vd>;
using vvvd = vector<vvd>;
#define all(A) A.begin(),A.end()
#define ALL(A) A.begin(),A.end()
#define rep(i, n) for (int i = 0; i < (int) (n); i++)
template<class T>
bool chmax(T& p, T q) {
    if (p < q) {
        p = q; return 1;
    }
    return 0;
};
template<class T>
bool chmin(T& p, T q) {
    if (p > q) {
        p = q; return 1;
    }
    return 0;
};


void roll(vll &D, char C) {
    ll SV=D[0];
    if (C == 'E') {
        D[0] = D[1];
        D[1] = D[5];
        D[5] = D[3];
        D[3] = SV;
    }
    else if (C == 'W'){
        D[0] = D[3];
        D[3] = D[5];
        D[5] = D[1];
        D[1] = SV;
    }
    else if (C == 'N') {
        D[0] = D[4];
        D[4] = D[5];
        D[5] = D[2];
        D[2] = SV;
    }
    else if (C == 'S'){
        D[0] = D[2];
        D[2] = D[5];
        D[5] = D[4];
        D[4] = SV;
    }
}

bool is_valid(vll &D,char C){
    if(C=='E'||C=='W'){
        if(C=='E'&&D[1]==0)return 0;
        if(C=='W'&&D[3]==0)return 0;
        if (D[0] + D[5] > D[1] + D[2] + D[3] + D[4])return 0;
        if (D[1]-1 + D[3] > D[0] + D[2] + D[5] + D[4])return 0;
        if (D[2] + D[4] > D[1] + D[0] + D[3] + D[5])return 0;
        return 1;
    }
    if(C=='N'||C=='S'){
        if(C=='N'&&D[4]==0)return 0;
        if(C=='S'&&D[2]==0)return 0;
        if (D[0] + D[5] > D[1] + D[2] + D[3] + D[4])return 0;
        if (D[1] + D[3] > D[0] + D[2] + D[5] + D[4])return 0;
        if (D[2] + D[4]-1 > D[1] + D[0] + D[3] + D[5])return 0;
        return 1;
    }
    return 1;
}

void solve(vll D, ll S) {
    ll P, Q;
    cin >> P >> Q;
    P--; Q -= P;
    string AN ;
    rep(i,S)AN.push_back('Z');
    sort(all(D));
    ll MX=D[5];
    do {
        vll P = D;
        string R = "";
        string G = "ENSW";
        bool is_same=1;
        rep(i, S) {
            bool is_OK = 0;
            rep(k, 4) {
                if(i==0&&k!=0)break;
                if(is_valid(P,G[k])){
                    roll(P, G[k]);
                    P[0]--;
                    R.push_back(G[k]);
                    if(is_same&&G[k]>AN[i]){
                        is_OK = 0;
                    }
                    if(G[k]<AN[i])is_same=0;
                    is_OK = 1;
                    break;
                }
            }
            if (!is_OK){
                R = "Z";
                break;
            }
        }
        chmin(AN, R);
    } while (next_permutation(all(D)));
    if (AN == "Z") {
        cout << "impossible" << endl;
    }
    else {
        cout << AN.substr(P, Q) << endl;
    }
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    vll D(6);
    while (1) {
        ll S = 0;
        rep(i, 6) {
            cin >> D[i];
            S += D[i];
        }
        if (S == 0)return 0;
        solve(D, S);
    }

}
accuracy: 1
time_ms: 930
memory_kb: 3512
final_rank: 5

code_snippet: #include <bits/stdc++.h>
#include <time.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vd = vector<double>;
using vvd = vector<vd>;
using vvvd = vector<vvd>;
#define all(A) A.begin(),A.end()
#define ALL(A) A.begin(),A.end()
#define rep(i, n) for (int i = 0; i < (int) (n); i++)
template<class T>
bool chmax(T& p, T q) {
    if (p < q) {
        p = q; return 1;
    }
    return 0;
};
template<class T>
bool chmin(T& p, T q) {
    if (p > q) {
        p = q; return 1;
    }
    return 0;
};


void roll(vll &D, char C) {
    ll SV=D[0];
    if (C == 'E') {
        D[0] = D[1];
        D[1] = D[5];
        D[5] = D[3];
        D[3] = SV;
    }
    else if (C == 'W'){
        D[0] = D[3];
        D[3] = D[5];
        D[5] = D[1];
        D[1] = SV;
    }
    else if (C == 'N') {
        D[0] = D[4];
        D[4] = D[5];
        D[5] = D[2];
        D[2] = SV;
    }
    else if (C == 'S'){
        D[0] = D[2];
        D[2] = D[5];
        D[5] = D[4];
        D[4] = SV;
    }
}

bool is_valid(vll &D,char C){
    if(C=='E'||C=='W'){
        if(C=='E'&&D[1]==0)return 0;
        if(C=='W'&&D[3]==0)return 0;
        if (D[0] + D[5] > D[1] + D[2] + D[3] + D[4])return 0;
        if (D[1]-1 + D[3] > D[0] + D[2] + D[5] + D[4])return 0;
        if (D[2] + D[4] > D[1] + D[0] + D[3] + D[5])return 0;
        return 1;
    }
    if(C=='N'||C=='S'){
        if(C=='N'&&D[4]==0)return 0;
        if(C=='S'&&D[2]==0)return 0;
        if (D[0] + D[5] > D[1] + D[2] + D[3] + D[4])return 0;
        if (D[1] + D[3] > D[0] + D[2] + D[5] + D[4])return 0;
        if (D[2] + D[4]-1 > D[1] + D[0] + D[3] + D[5])return 0;
        return 1;
    }
    return 1;
}

bool is_valid(vll &D) {
    if (D[0]-1 + D[5] > D[1] + D[2] + D[3] + D[4])return 0;
    if (D[1] + D[3] > D[0] + D[2] + D[5] + D[4])return 0;
    if (D[2] + D[4] > D[1] + D[0] + D[3] + D[5])return 0;
    return 1;
}

void solve(vll D, ll S) {
    clock_t start = clock();
    ll P, Q;
    cin >> P >> Q;
    P--; Q -= P;
    string AN ;
    rep(i,S)AN.push_back('Z');
    sort(all(D));
    ll MX=D[5];
    do {
        vll P = D;
        string R = "";
        string G = "ENSW";
        bool is_same=1;
        rep(i, S) {
            bool is_OK = 0;
            rep(k, 4) {
                if(i==0&&k!=0)break;
                if(is_valid(P,G[k])){
                    roll(P, G[k]);
                    P[0]--;
                    R.push_back(G[k]);
                    if(is_same&&G[k]>AN[i]){
                        is_OK = 0;
                    }
                    if(G[k]<AN[i])is_same=0;
                    is_OK = 1;
                    break;
                }
            }
            if (!is_OK){
                R = "Z";
                break;
            }
        }
        chmin(AN, R);
    } while (next_permutation(all(D)));
    if (AN == "Z") {
        cout << "impossible" << endl;
    }
    else {
        // cout<<"OK"<<endl;
        cout << AN.substr(P, Q) << endl;
    }
    clock_t end = clock();

    // const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC * 1000.0;
    // cout<<time<<endl;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    vll D(6);
    while (1) {
        ll S = 0;
        rep(i, 6) {
            cin >> D[i];
            S += D[i];
        }
        if (S == 0)return 0;
        solve(D, S);
    }

}
accuracy: 1
time_ms: 940
memory_kb: 3588
final_rank: 7

code_snippet: #include <bits/stdc++.h>
#include <time.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vd = vector<double>;
using vvd = vector<vd>;
using vvvd = vector<vvd>;
#define all(A) A.begin(),A.end()
#define ALL(A) A.begin(),A.end()
#define rep(i, n) for (int i = 0; i < (int) (n); i++)
template<class T>
bool chmax(T& p, T q) {
    if (p < q) {
        p = q; return 1;
    }
    return 0;
};
template<class T>
bool chmin(T& p, T q) {
    if (p > q) {
        p = q; return 1;
    }
    return 0;
};


void roll(vll &D, char C) {
    ll SV=D[0];
    if (C == 'E') {
        D[0] = D[1];
        D[1] = D[5];
        D[5] = D[3];
        D[3] = SV;
    }
    else if (C == 'W'){
        D[0] = D[3];
        D[3] = D[5];
        D[5] = D[1];
        D[1] = SV;
    }
    else if (C == 'N') {
        D[0] = D[4];
        D[4] = D[5];
        D[5] = D[2];
        D[2] = SV;
    }
    else if (C == 'S'){
        D[0] = D[2];
        D[2] = D[5];
        D[5] = D[4];
        D[4] = SV;
    }
}

bool is_valid(vll &D) {
    if (D[0]-1 + D[5] > D[1] + D[2] + D[3] + D[4])return 0;
    if (D[1] + D[3] > D[0] + D[2] + D[5] + D[4])return 0;
    if (D[2] + D[4] > D[1] + D[0] + D[3] + D[5])return 0;
    return 1;
}

void solve(vll D, ll S) {
    clock_t start = clock();
    ll P, Q;
    cin >> P >> Q;
    P--; Q -= P;
    string AN ;
    rep(i,S)AN.push_back('Z');
    sort(all(D));
    ll MX=D[5];
    do {
        vll P = D;
        string R = "";
        string G = "ENSW";
        bool is_same=1;
        rep(i, S) {
            bool is_OK = 0;
            rep(k, 4) {
                if(i==0&&k!=0)break;
                roll(P, G[k]);
                if (is_valid(P)&&P[0]>0) {
                    P[0]--;
                    R.push_back(G[k]);
                    if(is_same&&G[k]>AN[i]){
                        is_OK = 0;
                    }
                    if(G[k]<AN[i])is_same=0;
                    is_OK = 1;
                    break;
                }
                roll(P,G[3-k]);
            }
            if (!is_OK){
                R = "Z";
                break;
            }
        }
        chmin(AN, R);
    } while (next_permutation(all(D)));
    if (AN == "Z") {
        cout << "impossible" << endl;
    }
    else {
        // cout<<"OK"<<endl;
        cout << AN.substr(P, Q) << endl;
    }
    clock_t end = clock();

    // const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC * 1000.0;
    // cout<<time<<endl;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    vll D(6);
    while (1) {
        ll S = 0;
        rep(i, 6) {
            cin >> D[i];
            S += D[i];
        }
        if (S == 0)return 0;
        solve(D, S);
    }

}
accuracy: 1
time_ms: 1150
memory_kb: 3496
final_rank: 8

code_snippet: #include <bits/stdc++.h>
#include <time.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vd = vector<double>;
using vvd = vector<vd>;
using vvvd = vector<vvd>;
#define all(A) A.begin(),A.end()
#define ALL(A) A.begin(),A.end()
#define rep(i, n) for (int i = 0; i < (int) (n); i++)
template<class T>
bool chmax(T& p, T q) {
    if (p < q) {
        p = q; return 1;
    }
    return 0;
};
template<class T>
bool chmin(T& p, T q) {
    if (p > q) {
        p = q; return 1;
    }
    return 0;
};


vll roll(vll &D, char C) {
    vll res = D;
    if (C == 'E') {
        res[0] = D[1];
        res[1] = D[5];
        res[5] = D[3];
        res[3] = D[0];
    }
    else if (C == 'W'){
        res[0] = D[3];
        res[3] = D[5];
        res[5] = D[1];
        res[1] = D[0];
    }
    else if (C == 'N') {
        res[0] = D[4];
        res[4] = D[5];
        res[5] = D[2];
        res[2] = D[0];
    }
    else if (C == 'S'){
        res[0] = D[2];
        res[2] = D[5];
        res[5] = D[4];
        res[4] = D[0];
    }
    return res;
}

bool is_valid(vll &D) {
    if (D[0]-1 + D[5] > D[1] + D[2] + D[3] + D[4])return 0;
    if (D[1] + D[3] > D[0] + D[2] + D[5] + D[4])return 0;
    if (D[2] + D[4] > D[1] + D[0] + D[3] + D[5])return 0;

    return 1;
}

void solve(vll D, ll S) {
    clock_t start = clock();
    ll P, Q;
    cin >> P >> Q;
    P--; Q -= P;
    string AN ;
    rep(i,S)AN.push_back('Z');
    sort(all(D));
    ll MX=D[5];
    do {
        vll P = D;
        string R = "";
        string G = "ENSW";
        bool is_same=1;
        rep(i, S) {
            bool is_OK = 0;
            rep(k, 4) {
                if(i==0&&k!=0)break;
                vll NP = roll(P, G[k]);
                if (is_valid(NP)&&NP[0]>0) {
                    P = NP;
                    P[0]--;
                    R.push_back(G[k]);
                    if(is_same&&G[k]>AN[i]){
                        is_OK = 0;
                    }
                    if(G[k]<AN[i])is_same=0;
                    is_OK = 1;
                    break;
                }
            }
            if (!is_OK){
                R = "Z";
                break;
            }
        }
        chmin(AN, R);
    } while (next_permutation(all(D)));
    if (AN == "Z") {
        cout << "impossible" << endl;
    }
    else {
        // cout<<"OK"<<endl;
        cout << AN.substr(P, Q) << endl;
    }
    clock_t end = clock();

    // const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC * 1000.0;
    // cout<<time<<endl;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    vll D(6);
    while (1) {
        ll S = 0;
        rep(i, 6) {
            cin >> D[i];
            S += D[i];
        }
        if (S == 0)return 0;
        solve(D, S);
    }

}
accuracy: 1
time_ms: 4490
memory_kb: 3528
final_rank: 16

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, t) for (int i = (int)(s); i < (int)(t); ++i)
#define revrep(i, t, s) for (int i = (int)(t) - 1; i >= (int)(s); --i)
#define all(x) begin(x), end(x)
template <typename T>
bool chmax(T& a, const T& b) {
    return a < b ? (a = b, 1) : 0;
}
template <typename T>
bool chmin(T& a, const T& b) {
    return a > b ? (a = b, 1) : 0;
}

struct Die {
    int top = 1, south = 2, east = 3, west = 4, north = 5, bottom = 6;

    void roll(char dir) {
        if (dir == 'N') {
            int tmp = top;
            top = south;
            south = bottom;
            bottom = north;
            north = tmp;
        } else if (dir == 'E') {
            int tmp = top;
            top = west;
            west = bottom;
            bottom = east;
            east = tmp;
        } else if (dir == 'W') {
            int tmp = top;
            top = east;
            east = bottom;
            bottom = west;
            west = tmp;
        } else if (dir == 'S') {
            int tmp = top;
            top = north;
            north = bottom;
            bottom = south;
            south = tmp;
        } else {
            assert(false);
        }
    }
};

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);

    const string dir = "ENSW";

    auto check = [&](vector<int>& val, int cur) {
        int sum = 0;
        rep(i, 0, 6) {
            if (val[i] < 0) return false;
            sum += val[i];
        }
        rep(i, 0, 3) {
            int x = val[i] + val[5 - i];
            if (i == min(cur, 5 - i)) {
                if (sum - x < x) return false;
            } else {
                if (sum - x < x - 1) return false;
            }
        }
        return true;
    };

    while (true) {
        vector<int> t(6);
        int sum = 0;
        for (auto& x : t) cin >> x, sum += x;
        if (t[5] == 0) break;
        int p, q;
        cin >> p >> q;
        --p;

        string ans = "Z";

        vector<int> idx(6);
        iota(all(idx), 0);
        do {
            vector<int> val(6);
            rep(v, 0, 6) val[v] = t[idx[v]];
            if (val[0] == 0) continue;
            --val[0];
            string res = "E";
            Die die;
            die.roll('N');
            die.roll('N');
            // 1 is facing down

            int edges = sum - 1;
            rep(t, 0, sum - 1) {
                char move = '?';
                --edges;
                for (char c : dir) {
                    die.roll(c);
                    --val[die.bottom - 1];
                    if (check(val, die.bottom - 1)) {
                        move = c;
                        break;
                    } else {
                        ++val[die.bottom - 1];
                        die.roll(c);
                        die.roll(c);
                        die.roll(c);
                    }
                }
                if (move == '?') {
                    res = "Z";
                    break;
                }
                res.push_back(move);
            }
            chmin(ans, res);
        } while (next_permutation(all(idx)));

        cout << (ans == "Z" ? "impossible" : ans.substr(p, q - p)) << "\n";
    }
}
accuracy: 1
time_ms: 2210
memory_kb: 3456
final_rank: 13

code_snippet: #include <bits/stdc++.h>
using namespace std;

#pragma GCC target("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

using ll = long long;

template<class T>
bool chmin(T &a, const T &b) {if (a > b) {a = b; return 1;} return 0;}

bool is_end = false;

string ENSW = "ENSW";

// origin = {0, 1, 2, 3, 4, 5}
int rotate_dice[4][6] = 
{
    {2, 1, 5, 0, 4, 3}, // to E
    {4, 0, 2, 3, 5, 1}, // to N
    {1, 5, 2, 3, 0, 4}, // to S
    {3, 1, 0, 5, 4, 2}  // to W
};

bool isvalid(const array<int, 6> &vec)
{
    if (vec[0] < 0) return false;
    int sum = accumulate(vec.begin(), vec.end(), 0);
    
    if (2 * vec[0] + 2 * vec[5] > sum) return false;
    if (2 * vec[1] + 2 * vec[4] - 1 > sum) return false;
    if (2 * vec[2] + 2 * vec[3] - 1 > sum) return false;
    
    return true;
}

bool is_zero(const array<int, 6> &dice)
{
    for (uint i = 0; i < 6; ++i)
    {
        if (dice[i] != 0) return false;
    }
    return true;
}


vector<int> global_vec(30000 + 100);

bool dfs(int depth, array<int, 6> dice)
{
    if (depth == 0) return true;
    
    for (uint dir = 0; dir < 4; ++dir)
    {
        array<int, 6> ndice = dice;
        for (int j = 0; j < 6; ++j) ndice[j] = dice[rotate_dice[dir][j]];
        ndice[0] -= 1;
        
        if (!isvalid(ndice)) continue;
        
        global_vec[depth] = dir;
        if (dfs(depth - 1, ndice)) return true;
        // global_vec.pop_back();
    }
    
    return false;
}


void solve()
{
    array<int, 6> T;
    for (uint i = 0; i < 6; ++i) cin >> T[i];
    if (T[5] == 0)
    {
        is_end = true;
        return;
    }
    int P, Q; cin >> P >> Q;
    P--, Q--;
    
    int sum = accumulate(T.begin(), T.end(), 0);
    
    string res = "Z";
    do
    {
        
        if (dfs(sum, T))
        {
            string tmp = "";
            for (uint i = sum; i > 0; --i)
            {
                tmp += ENSW[global_vec[i]];
            }
            chmin(res, tmp);
        }
        
    } while (next_permutation(T.begin(), T.end()));
    
    if (res == "Z") cout << "impossible" << endl;
    else
    {
        string ans = res.substr(P, Q + 1 - P);
        cout << ans << endl;
        // cerr << -1 << endl;
        // cout << res << endl;
    }
    
    return;
}

int main()
{
    while (!is_end)
    {
        solve();
    }
    
    return 0;
}
accuracy: 1
time_ms: 1540
memory_kb: 6696
final_rank: 20

code_snippet: #line 2 "cp-library/src/cp-template.hpp"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull  = unsigned long long;
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
using i128 = __int128_t;
template < class T > bool chmin(T& a, T b) { if(a > b) { a = b; return true; } return false; }
template < class T > bool chmax(T& a, T b) { if(a < b) { a = b; return true; } return false; }
template < class T, class U > T ceil (T x, U y) { return (x > 0 ? (x + y - 1) / y :           x / y); }
template < class T, class U > T floor(T x, U y) { return (x > 0 ?           x / y : (x - y + 1) / y); }
int popcnt(i32 x) { return __builtin_popcount(x); }
int popcnt(u32 x) { return __builtin_popcount(x); }
int popcnt(i64 x) { return __builtin_popcountll(x); }
int popcnt(u64 x) { return __builtin_popcountll(x); }

#line 2 "cp-library/src/utility/rep_itr.hpp"
template < class T > struct itr_rep {
    T i, d;
    constexpr itr_rep(const T i) noexcept : i(i), d(1) {}
    constexpr itr_rep(const T i, const T d) noexcept : i(i), d(d) {}
    void operator++() noexcept { i += d; }
    constexpr int operator*() const noexcept { return i; }
    constexpr bool operator!=(const itr_rep x) const noexcept { return d > 0 ? i < x.i : i > x.i; }
};

template < class T > struct rep {
    const itr_rep< T > s, t;
    constexpr rep(const T t) noexcept : s(0), t(t) {}
    constexpr rep(const T s, const T t) noexcept : s(s), t(t) {}
    constexpr rep(const T s, const T t, const T d) noexcept : s(s, d), t(t, d) {}
    constexpr auto begin() const noexcept { return s; }
    constexpr auto end  () const noexcept { return t; }
};

template < class T > struct revrep {
    const itr_rep < T > s, t;
    constexpr revrep(const T t) noexcept : s(t - 1, -1), t(-1, -1) {}
    constexpr revrep(const T s, const T t) noexcept : s(t - 1, -1), t(s - 1, -1) {}
    constexpr revrep(const T s, const T t, const T d) noexcept : s(t - 1, -d), t(s - 1, -d) {}
    constexpr auto begin() const noexcept { return s; }
    constexpr auto end  () const noexcept { return t; }
};
#line 3 "cp-library/src/utility/io.hpp"

/* 128bit integer */
istream& operator>>(istream& is, i128& x) {
    std::string s; is >> s;
    int pm = (s[0] == '-');
    x = 0;
    for(int i : rep(pm, int(s.size()))) x = x * 10 + (s[i] - '0');
    if(pm) x *= -1;
    return is;
}
ostream& operator<<(ostream& os, const i128& x) {
    if(x == 0) return os << '0';
    i128 y = x;
    if(y < 0) { os << '-'; y *= -1; }
    std::vector<int> ny;
    while(y > 0) { ny.push_back(y % 10); y /= 10; }
    for(int i : revrep(ny.size())) os << ny[i];
    return os;
}

template < class S, class T > istream& operator>>(istream& is,       std::pair< S, T >& x) { is >> x.first        >> x.second; return is; }
template < class S, class T > ostream& operator<<(ostream& os, const std::pair< S, T >& x) { os << x.first << " " << x.second; return os; }

namespace scanner {
    struct sca {
        template < class T > operator T() {
            T s; std::cin >> s; return s;
        }
    };
    struct vec {
        int n;
        vec(int n) : n(n) {}
        template < class T > operator std::vector< T >() {
            std::vector< T > v(n);
            for(T& x : v) std::cin >> x;
            return v;
        }
    };
    struct mat {
        int h, w;
        mat(int h, int w) : h(h), w(w) {}
        template < class T > operator std::vector< std::vector< T > >() {
            std::vector m(h, std::vector< T >(w));
            for(std::vector< T >& v : m) for(T& x : v) std::cin >> x;
            return m;
        }
    };
    struct speedup {
        speedup() {
            std::cin.tie(0);
            std::ios::sync_with_stdio(0);
        }
    } speedup_instance;
}
scanner::sca in() { return scanner::sca(); }
scanner::vec in(int n) { return scanner::vec(n); }
scanner::mat in(int h, int w) { return scanner::mat(h, w); }

namespace printer {
    void precision(int d) { std::cout << std::fixed << std::setprecision(d); }
    void flush() { std::cout.flush(); }
}

template < class T >
ostream& operator<<(ostream& os, const std::vector< T > a) {
    int n = a.size();
    for(int i : rep(n)) { os << a[i]; if(i != n - 1) os << ' '; }
    return os;
}

int print() { std::cout << '\n'; return 0; }
template < class head, class... tail > int print(head&& h, tail&&... t) {
    std::cout << h; if(sizeof...(tail)) std::cout << ' ';
    return print(std::forward<tail>(t)...);
}
template < class T > int print_n(const std::vector< T > a) {
    int n = a.size();
    for(int i : rep(n)) std::cout << a[i] << "\n";
    return 0;
}


#line 2 "cp-library/src/utility/key_val.hpp"

template < class K, class V >
struct key_val {
    K key; V val;
    key_val() {}
    key_val(K key, V val) : key(key), val(val) {}
    template < std::size_t Index >
    std::tuple_element_t< Index, key_val >& get() {
        if constexpr (Index == 0) return key;
        if constexpr (Index == 1) return val;
    }
};

namespace std {

template < class K, class V > struct tuple_size < key_val< K, V > > : integral_constant< size_t, 2 > {};
template < class K, class V > struct tuple_element < 0, key_val< K, V > > { using type = K; };
template < class K, class V > struct tuple_element < 1, key_val< K, V > > { using type = V; };

}
#line 2 "cp-library/src/utility/vec_op.hpp"
template < class T > key_val< int, T > max_of(const vector< T >& a) {
    int i = std::max_element(a.begin(), a.end()) - a.begin();
    return {i, a[i]};
}
template < class T > key_val< int, T > min_of(const vector< T >& a) {
    int i = std::min_element(a.begin(), a.end()) - a.begin();
    return {i, a[i]};
}
template < class S, class T > S sum_of(const vector< T >& a) {
    S sum = 0;
    for(const T x : a) sum += x;
    return sum;
}
template < class S, class T > vector< S > freq_of(const vector< T >& a, T L, T R) {
    vector< S > res(R - L, S(0));
    for(const T x : a) res[x - L] += 1;
    return res;
}
template < class S, class T > struct prefix_sum {
    vector< S > s;
    prefix_sum(const vector< T >& a) : s(a) {
        s.insert(s.begin(), S(0));
        for(int i : rep(a.size())) s[i + 1] += s[i];
    }
    // [L, R)
    S sum(int L, int R) { return s[R] - s[L]; }
};
#line 3 "cp-library/src/utility/heap.hpp"

template < class T > using heap_min = std::priority_queue< T, std::vector< T >, std::greater< T > >;
template < class T > using heap_max = std::priority_queue< T, std::vector< T >, std::less< T > >;

#line 27 "cp-library/src/cp-template.hpp"

#line 1 "cp-library/src/algorithm/bin_search.hpp"
template < class T, class F >
T bin_search(T ok, T ng, F f) {
    while(abs(ng - ok) > 1) {
        T mid = (ok + ng) / 2;
        (f(mid) ? ok : ng) = mid;
    }
    return ok;
}

template < class T, class F >
T bin_search_real(T ok, T ng, F f, int step = 80) {
    while(step--) {
        T mid = (ok + ng) / 2;
        (f(mid) ? ok : ng) = mid;
    }
    return ok;
}
#line 2 "cp-library/src/algorithm/argsort.hpp"

template < class T > std::vector< int > argsort(const std::vector< T > &a) {
    std::vector< int > ids((int)a.size());
    std::iota(ids.begin(), ids.end(), 0);
    std::sort(ids.begin(), ids.end(), [&](int i, int j) {
        return a[i] < a[j] || (a[i] == a[j] && i < j);
    });
    return ids;
}
#line 1 "macro.hpp"
namespace macro {

using size_type = int;
template < class container > void  sort(container& a) { std::sort(std:: begin(a), std:: end(a)); }
template < class container > void rsort(container& a) { std::sort(std::rbegin(a), std::rend(a)); }
template < class container > void reverse(container& a) { std::reverse(std::begin(a), std::end(a)); }
template < class container > void unique(container& a) {
    std::sort(std::begin(a), std::end(a));
    a.erase(std::unique(std::begin(a), std::end(a)), std::end(a));
}
template < class container > container  sorted(const container& a) { container b = a;  sort(b); return std::move(b); }
template < class container > container rsorted(const container& a) { container b = a; rsort(b); return std::move(b); }
template < class container, class compare > void sort(container& a, const compare& cmp) { std::sort(std::begin(a), std::end(a), cmp); }
template < class container, class compare > container sorted(const container& a, const compare& cmp) { container b = a; sort(b, cmp); return std::move(b); }
template < class container, class value > size_type lower_bound(const container& a, const value& x) { return std::lower_bound(std::begin(a), std::end(a), x) - std::begin(a); }
template < class container, class value > size_type upper_bound(const container& a, const value& x) { return std::upper_bound(std::begin(a), std::end(a), x) - std::begin(a); }

const std::vector<std::pair<size_type, size_type>> dir4 = { {+1,  0}, {-1,  0}, { 0, +1}, { 0, -1} };
const std::vector<std::pair<size_type, size_type>> dir8 = { {-1, -1}, {-1,  0}, {-1, +1}, { 0, -1}, { 0, +1}, {+1, -1}, {+1,  0}, {+1, +1} };

#ifdef _DEBUG
#define debug(x) std::cout << "[" << __LINE__ << "] " << #x << ": " << x << std::endl
#else
#define debug(x)
#endif

template < class container > void concat(container& a, const container& b) {
    a.insert(std::end(a), std::begin(b), std::end(b));
}
std::vector<size_type> iota(const size_type n) {
    std::vector<size_type> I(n);
    std::iota(std::begin(I), std::end(I), 0);
    return I;
}
template < class container > std::vector<size_type> sort_idx(const container& a) {
    const size_type n = a.size();
    std::vector<size_type> I = iota(n);
    std::sort(std::begin(I), std::end(I), [&](size_type i, size_type j) { return a[i] < a[j] or (a[i] == a[j] and i < j); });
    return I;
}
template < class container, class compare > std::vector<size_type> sort_idx(const container& a, const compare& cmp) {
    const size_type n = a.size();
    std::vector<size_type> I = iota(n);
    std::sort(std::begin(I), std::end(I), [&](size_type i, size_type j) { return cmp(a[i], a[j]) or (a[i] == a[j] and i < j); });
    return std::move(I);
}

struct grid {
    using size_type = int;
    size_type H, W;
    grid(const size_type H, const size_type W) : H(H), W(W) {}
    bool contains(const size_type i, const size_type j) {
        return 0 <= i and i < H and 0 <= j and j < W;
    }
};

using f64 = long double;

} // namespace macro

using namespace macro;
#line 3 "A.cpp"

const string op = "ENSW";
using dice = array<int, 6>;
enum { l, r, f, b, d, u };
const vector<dice> g = {
    {d, u, f, b, r, l},
    {l, r, d, u, b, f},
    {l, r, u, d, f, b},
    {u, d, f, b, l, r}
};

string solve(dice t) {
    sort(t);
    const int len = accumulate(t.begin(), t.end(), 0);
    string ans(len, 'Z');

    auto check = [&](dice& x) -> bool {
        for(int i : rep(6)) if(x[i] < 0) return false;
        int sum = accumulate(x.begin(), x.end(), 0);
        return x[0] + x[1] <= sum - (x[0] + x[1]) + 1
           and x[2] + x[3] <= sum - (x[2] + x[3]) + 1
           and x[4] + x[5] <= sum - (x[4] + x[5]) + 0;
    };

    do {
        if(check(t)) {
            string s = "";
            dice x = t;
            while(x != dice{}) {
                for(int k : rep(4)) {
                    dice nx;
                    for(int i : rep(6)) nx[i] = x[g[k][i]];
                    nx[4] -= 1;
                    if(check(nx)) {
                        s += op[k];
                        x = move(nx);
                        break;
                    }
                }
            }
            chmin(ans, s);
        }
    } while(next_permutation(t.begin(), t.end()));

    int p = in(), q = in(); p--;
    if(ans[0] == 'Z') return "impossible";
    return move(ans.substr(p, q - p));
}

int main() {
    while(true) {
        dice t;
        for(int i : rep(6)) t[i] = in();
        if(t == dice{}) return 0;
        print(solve(t));
    }
}
accuracy: 1
time_ms: 1570
memory_kb: 3504
final_rank: 12

code_snippet: #line 2 "cp-library/src/cp-template.hpp"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull  = unsigned long long;
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
using i128 = __int128_t;
template < class T > bool chmin(T& a, T b) { if(a > b) { a = b; return true; } return false; }
template < class T > bool chmax(T& a, T b) { if(a < b) { a = b; return true; } return false; }
template < class T, class U > T ceil (T x, U y) { return (x > 0 ? (x + y - 1) / y :           x / y); }
template < class T, class U > T floor(T x, U y) { return (x > 0 ?           x / y : (x - y + 1) / y); }
int popcnt(i32 x) { return __builtin_popcount(x); }
int popcnt(u32 x) { return __builtin_popcount(x); }
int popcnt(i64 x) { return __builtin_popcountll(x); }
int popcnt(u64 x) { return __builtin_popcountll(x); }

#line 2 "cp-library/src/utility/rep_itr.hpp"
template < class T > struct itr_rep {
    T i, d;
    constexpr itr_rep(const T i) noexcept : i(i), d(1) {}
    constexpr itr_rep(const T i, const T d) noexcept : i(i), d(d) {}
    void operator++() noexcept { i += d; }
    constexpr int operator*() const noexcept { return i; }
    constexpr bool operator!=(const itr_rep x) const noexcept { return d > 0 ? i < x.i : i > x.i; }
};

template < class T > struct rep {
    const itr_rep< T > s, t;
    constexpr rep(const T t) noexcept : s(0), t(t) {}
    constexpr rep(const T s, const T t) noexcept : s(s), t(t) {}
    constexpr rep(const T s, const T t, const T d) noexcept : s(s, d), t(t, d) {}
    constexpr auto begin() const noexcept { return s; }
    constexpr auto end  () const noexcept { return t; }
};

template < class T > struct revrep {
    const itr_rep < T > s, t;
    constexpr revrep(const T t) noexcept : s(t - 1, -1), t(-1, -1) {}
    constexpr revrep(const T s, const T t) noexcept : s(t - 1, -1), t(s - 1, -1) {}
    constexpr revrep(const T s, const T t, const T d) noexcept : s(t - 1, -d), t(s - 1, -d) {}
    constexpr auto begin() const noexcept { return s; }
    constexpr auto end  () const noexcept { return t; }
};
#line 3 "cp-library/src/utility/io.hpp"

/* 128bit integer */
istream& operator>>(istream& is, i128& x) {
    std::string s; is >> s;
    int pm = (s[0] == '-');
    x = 0;
    for(int i : rep(pm, int(s.size()))) x = x * 10 + (s[i] - '0');
    if(pm) x *= -1;
    return is;
}
ostream& operator<<(ostream& os, const i128& x) {
    if(x == 0) return os << '0';
    i128 y = x;
    if(y < 0) { os << '-'; y *= -1; }
    std::vector<int> ny;
    while(y > 0) { ny.push_back(y % 10); y /= 10; }
    for(int i : revrep(ny.size())) os << ny[i];
    return os;
}

template < class S, class T > istream& operator>>(istream& is,       std::pair< S, T >& x) { is >> x.first        >> x.second; return is; }
template < class S, class T > ostream& operator<<(ostream& os, const std::pair< S, T >& x) { os << x.first << " " << x.second; return os; }

namespace scanner {
    struct sca {
        template < class T > operator T() {
            T s; std::cin >> s; return s;
        }
    };
    struct vec {
        int n;
        vec(int n) : n(n) {}
        template < class T > operator std::vector< T >() {
            std::vector< T > v(n);
            for(T& x : v) std::cin >> x;
            return v;
        }
    };
    struct mat {
        int h, w;
        mat(int h, int w) : h(h), w(w) {}
        template < class T > operator std::vector< std::vector< T > >() {
            std::vector m(h, std::vector< T >(w));
            for(std::vector< T >& v : m) for(T& x : v) std::cin >> x;
            return m;
        }
    };
    struct speedup {
        speedup() {
            std::cin.tie(0);
            std::ios::sync_with_stdio(0);
        }
    } speedup_instance;
}
scanner::sca in() { return scanner::sca(); }
scanner::vec in(int n) { return scanner::vec(n); }
scanner::mat in(int h, int w) { return scanner::mat(h, w); }

namespace printer {
    void precision(int d) { std::cout << std::fixed << std::setprecision(d); }
    void flush() { std::cout.flush(); }
}

template < class T >
ostream& operator<<(ostream& os, const std::vector< T > a) {
    int n = a.size();
    for(int i : rep(n)) { os << a[i]; if(i != n - 1) os << ' '; }
    return os;
}

int print() { std::cout << '\n'; return 0; }
template < class head, class... tail > int print(head&& h, tail&&... t) {
    std::cout << h; if(sizeof...(tail)) std::cout << ' ';
    return print(std::forward<tail>(t)...);
}
template < class T > int print_n(const std::vector< T > a) {
    int n = a.size();
    for(int i : rep(n)) std::cout << a[i] << "\n";
    return 0;
}


#line 2 "cp-library/src/utility/key_val.hpp"

template < class K, class V >
struct key_val {
    K key; V val;
    key_val() {}
    key_val(K key, V val) : key(key), val(val) {}
    template < std::size_t Index >
    std::tuple_element_t< Index, key_val >& get() {
        if constexpr (Index == 0) return key;
        if constexpr (Index == 1) return val;
    }
};

namespace std {

template < class K, class V > struct tuple_size < key_val< K, V > > : integral_constant< size_t, 2 > {};
template < class K, class V > struct tuple_element < 0, key_val< K, V > > { using type = K; };
template < class K, class V > struct tuple_element < 1, key_val< K, V > > { using type = V; };

}
#line 2 "cp-library/src/utility/vec_op.hpp"
template < class T > key_val< int, T > max_of(const vector< T >& a) {
    int i = std::max_element(a.begin(), a.end()) - a.begin();
    return {i, a[i]};
}
template < class T > key_val< int, T > min_of(const vector< T >& a) {
    int i = std::min_element(a.begin(), a.end()) - a.begin();
    return {i, a[i]};
}
template < class S, class T > S sum_of(const vector< T >& a) {
    S sum = 0;
    for(const T x : a) sum += x;
    return sum;
}
template < class S, class T > vector< S > freq_of(const vector< T >& a, T L, T R) {
    vector< S > res(R - L, S(0));
    for(const T x : a) res[x - L] += 1;
    return res;
}
template < class S, class T > struct prefix_sum {
    vector< S > s;
    prefix_sum(const vector< T >& a) : s(a) {
        s.insert(s.begin(), S(0));
        for(int i : rep(a.size())) s[i + 1] += s[i];
    }
    // [L, R)
    S sum(int L, int R) { return s[R] - s[L]; }
};
#line 3 "cp-library/src/utility/heap.hpp"

template < class T > using heap_min = std::priority_queue< T, std::vector< T >, std::greater< T > >;
template < class T > using heap_max = std::priority_queue< T, std::vector< T >, std::less< T > >;

#line 27 "cp-library/src/cp-template.hpp"

#line 1 "cp-library/src/algorithm/bin_search.hpp"
template < class T, class F >
T bin_search(T ok, T ng, F f) {
    while(abs(ng - ok) > 1) {
        T mid = (ok + ng) / 2;
        (f(mid) ? ok : ng) = mid;
    }
    return ok;
}

template < class T, class F >
T bin_search_real(T ok, T ng, F f, int step = 80) {
    while(step--) {
        T mid = (ok + ng) / 2;
        (f(mid) ? ok : ng) = mid;
    }
    return ok;
}
#line 2 "cp-library/src/algorithm/argsort.hpp"

template < class T > std::vector< int > argsort(const std::vector< T > &a) {
    std::vector< int > ids((int)a.size());
    std::iota(ids.begin(), ids.end(), 0);
    std::sort(ids.begin(), ids.end(), [&](int i, int j) {
        return a[i] < a[j] || (a[i] == a[j] && i < j);
    });
    return ids;
}
#line 1 "macro.hpp"
namespace macro {

using size_type = int;
template < class container > void  sort(container& a) { std::sort(std:: begin(a), std:: end(a)); }
template < class container > void rsort(container& a) { std::sort(std::rbegin(a), std::rend(a)); }
template < class container > void reverse(container& a) { std::reverse(std::begin(a), std::end(a)); }
template < class container > void unique(container& a) {
    std::sort(std::begin(a), std::end(a));
    a.erase(std::unique(std::begin(a), std::end(a)), std::end(a));
}
template < class container > container  sorted(const container& a) { container b = a;  sort(b); return std::move(b); }
template < class container > container rsorted(const container& a) { container b = a; rsort(b); return std::move(b); }
template < class container, class compare > void sort(container& a, const compare& cmp) { std::sort(std::begin(a), std::end(a), cmp); }
template < class container, class compare > container sorted(const container& a, const compare& cmp) { container b = a; sort(b, cmp); return std::move(b); }
template < class container, class value > size_type lower_bound(const container& a, const value& x) { return std::lower_bound(std::begin(a), std::end(a), x) - std::begin(a); }
template < class container, class value > size_type upper_bound(const container& a, const value& x) { return std::upper_bound(std::begin(a), std::end(a), x) - std::begin(a); }

const std::vector<std::pair<size_type, size_type>> dir4 = { {+1,  0}, {-1,  0}, { 0, +1}, { 0, -1} };
const std::vector<std::pair<size_type, size_type>> dir8 = { {-1, -1}, {-1,  0}, {-1, +1}, { 0, -1}, { 0, +1}, {+1, -1}, {+1,  0}, {+1, +1} };

#ifdef _DEBUG
#define debug(x) std::cout << "[" << __LINE__ << "] " << #x << ": " << x << std::endl
#else
#define debug(x)
#endif

template < class container > void concat(container& a, const container& b) {
    a.insert(std::end(a), std::begin(b), std::end(b));
}
std::vector<size_type> iota(const size_type n) {
    std::vector<size_type> I(n);
    std::iota(std::begin(I), std::end(I), 0);
    return I;
}
template < class container > std::vector<size_type> sort_idx(const container& a) {
    const size_type n = a.size();
    std::vector<size_type> I = iota(n);
    std::sort(std::begin(I), std::end(I), [&](size_type i, size_type j) { return a[i] < a[j] or (a[i] == a[j] and i < j); });
    return I;
}
template < class container, class compare > std::vector<size_type> sort_idx(const container& a, const compare& cmp) {
    const size_type n = a.size();
    std::vector<size_type> I = iota(n);
    std::sort(std::begin(I), std::end(I), [&](size_type i, size_type j) { return cmp(a[i], a[j]) or (a[i] == a[j] and i < j); });
    return std::move(I);
}

struct grid {
    using size_type = int;
    size_type H, W;
    grid(const size_type H, const size_type W) : H(H), W(W) {}
    bool contains(const size_type i, const size_type j) {
        return 0 <= i and i < H and 0 <= j and j < W;
    }
};

using f64 = long double;

} // namespace macro

using namespace macro;
#line 3 "A.cpp"

const string op = "ENSW";
enum { l, r, f, b, d, u };
const vector<vector<int>> g = {
    {d, u, f, b, r, l},
    {l, r, d, u, b, f},
    {l, r, u, d, f, b},
    {u, d, f, b, l, r}
};

string solve(vector<int> t) {
    sort(t);
    const int len = accumulate(t.begin(), t.end(), 0);
    string ans(len, 'Z');

    auto check = [&](vector<int>& x) -> bool {
        for(int i : rep(6)) if(x[i] < 0) return false;
        int sum = accumulate(x.begin(), x.end(), 0);
        return x[0] + x[1] <= sum - (x[0] + x[1]) + 1
           and x[2] + x[3] <= sum - (x[2] + x[3]) + 1
           and x[4] + x[5] <= sum - (x[4] + x[5]) + 0;
    };

    do {
        if(check(t)) {
            string s = "";
            vector<int> x = t;
            while(x != vector(6, 0)) {
                for(int k : rep(4)) {
                    vector<int> nx(6);
                    for(int i : rep(6)) nx[i] = x[g[k][i]];
                    nx[4] -= 1;
                    if(check(nx)) {
                        s += op[k];
                        x = move(nx);
                        break;
                    }
                }
            }
            chmin(ans, s);
        }
    } while(next_permutation(t.begin(), t.end()));

    int p = in(), q = in(); p--;
    if(ans[0] == 'Z') return "impossible";
    return move(ans.substr(p, q - p));
}

int main() {
    while(true) {
        vector<int> t = in(6);
        if(t == vector<int>(6, 0)) return 0;
        print(solve(t));
    }
}
accuracy: 1
time_ms: 6360
memory_kb: 3492
final_rank: 18

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, a, b) for(ll i = a; i < b; ++i)
#define rrep(i, a, b) for(ll i = a; i >= b; --i)
constexpr ll inf = 4e18;

bool check(vector<int> mass) {
    bool ok = true;
    if(mass[0]+mass[1] > mass[2]+mass[3]+mass[4]+mass[5]) ok = false;
    if(mass[2]+mass[3]-1 > mass[0]+mass[1]+mass[4]+mass[5]) ok = false;
    if(mass[4]+mass[5]-1 > mass[0]+mass[1]+mass[2]+mass[3]) ok = false;
    return ok;
}
int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(0);
    vector<char> dir = {'E', 'N', 'S', 'W'};

    while(1) {
        string min_ans = "";
        vector<int> mass(6);
        rep(i, 0, 6) cin >> mass[i];
        bool end = true;
        rep(i, 0, 6) if(mass[i] != 0) end = false;
        if(end) break;
        int ans_l = 0;
        rep(i, 0, 6) ans_l += mass[i];
        do {
            string ans = "";
            vector<int> n_mass(6);
            rep(i, 0, 6) n_mass[i] = mass[i];

            if(!check(n_mass)) continue;
            while(1) {
                bool end = true;
                rep(i, 0, 6) if(n_mass[i] != 0) end = false;
                if(end) {
                    if(min_ans == "") min_ans = ans;
                    else if(min_ans > ans) min_ans = ans;
                    break;
                }
                if(!check(n_mass)) break;
                rep(i, 0, 4) {
                    vector<int> nv;
                    if(i==0 and n_mass[2] != 0) {
                        nv = {n_mass[2]-1, n_mass[3], n_mass[1], n_mass[0], n_mass[4], n_mass[5]};
                        if(check(nv)) {
                            swap(n_mass, nv);
                            ans.push_back(dir[i]);
                            break;
                        }
                    }
                    else if(i==1 and n_mass[4] != 0) {
                        nv = {n_mass[4]-1, n_mass[5], n_mass[2], n_mass[3], n_mass[1], n_mass[0]};
                            if(check(nv)) {
                            swap(n_mass, nv);
                            ans.push_back(dir[i]);
                            break;
                        }
                    }
                    else if(i==2 and n_mass[5] != 0) {
                        nv = {n_mass[5]-1, n_mass[4], n_mass[2], n_mass[3], n_mass[0], n_mass[1]};
                            if(check(nv)) {
                            swap(n_mass, nv);
                            ans.push_back(dir[i]);
                            break;
                        }
                    }
                    else if(i==3 and n_mass[3] != 0) {
                        nv = {n_mass[3]-1, n_mass[2], n_mass[0], n_mass[1], n_mass[4], n_mass[5]};
                        if(check(nv)) {
                            swap(n_mass, nv);
                            ans.push_back(dir[i]);
                            break;
                        }
                    }
                    
                }
            }
        } while(next_permutation(mass.begin(), mass.end()));
        // cout << endl << endl << min_ans << endl;
        int p, q;
        cin >> p >> q;
        if(min_ans == "") {
            cout << "impossible" << endl;
            continue;
        }
        for(int i=p-1; i<q; i++) cout << min_ans[i];
        cout << endl;
    }
}
accuracy: 1
time_ms: 6830
memory_kb: 3548
final_rank: 19

code_snippet: #include <bits/stdc++.h>

#define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--)
#define all(v) v.begin(), v.end()

using ll = long long;
using ld = long double;
using ull = unsigned long long;

template <typename T> bool chmin(T &a, const T &b) {
    if (a <= b) return false;
    a = b;
    return true;
}
template <typename T> bool chmax(T &a, const T &b) {
    if (a >= b) return false;
    a = b;
    return true;
}

#define debug(...)                                                     \
    std::cerr << "LINE: " << __LINE__ << " [" << #__VA_ARGS__ << "]:", \
        debug_out(__VA_ARGS__)

void debug_out() {
    std::cerr << std::endl;
}

template <typename Head, typename... Tail> void debug_out(Head h, Tail... t) {
    std::cerr << " " << h;
    if (sizeof...(t) > 0) std::cerr << " :";
    debug_out(t...);
}

template <typename T1, typename T2>
std::ostream &operator<<(std::ostream &os, const std::pair<T1, T2> &pa) {
    return os << pa.first << " " << pa.second;
}

template <typename T>
std::ostream &operator<<(std::ostream &os, const std::vector<T> &vec) {
    for (std::size_t i = 0; i < vec.size(); i++)
        os << vec[i] << (i + 1 == vec.size() ? "" : " ");
    return os;
}

typedef std::string::const_iterator State;

bool expect(State &begin, char expected) {
    return *begin == expected;
}

void consume(State &begin, char expected) {
    assert(*begin == expected);
    begin++;
}

bool isdigit(char c) {
    return '0' <= c && c <= '9';
}

bool isAlpha(char c) {
    return 'A' <= c && c <= 'Z';
}

bool isalpha(char c) {
    return 'a' <= c && c <= 'z';
}

struct Dice {
    int up = 0, front = 1, right = 2, left = 3, back = 4, down = 5;

    Dice() = default;

    void setval(const std::vector<int> &_val) {
        assert(int(_val.size()) == 6);
        val = _val;
    }

    // y++
    void rollN() {
        int buff = down;
        down = back;
        back = up;
        up = front;
        front = buff;
    }

    // y--
    void rollS() {
        int buff = down;
        down = front;
        front = up;
        up = back;
        back = buff;
    }

    // x++
    void rollE() {
        int buff = down;
        down = right;
        right = up;
        up = left;
        left = buff;
    }

    // x--
    void rollW() {
        int buff = down;
        down = left;
        left = up;
        up = right;
        right = buff;
    }

    // 右回転(時計回り)
    void rollR() {
        int buff = right;
        right = back;
        back = left;
        left = front;
        front = buff;
    }

    // 左回転(反時計回り)
    void rollL() {
        int buff = left;
        left = back;
        back = right;
        right = front;
        front = buff;
    }

    void roll(char c) {
        if (c == 'N')
            rollN();
        else if (c == 'S')
            rollS();
        else if (c == 'E')
            rollE();
        else if (c == 'W')
            rollW();
        else if (c == 'R')
            rollR();
        else if (c == 'L')
            rollL();
        else
            assert(0);
    }

    int get_index(int x) const {
        for (int i = 0; i < 6; i++) {
            if (val[i] == x) return i;
        }
        assert(0);
    }

    std::vector<Dice> makeDice() const {
        std::vector<Dice> ret;
        for (int i = 0; i < 6; i++) {
            Dice d(*this);
            if (i == 1) d.rollN();
            if (i == 2) d.rollS();
            if (i == 3) {
                d.rollS();
                d.rollS();
            }
            if (i == 4) d.rollL();
            if (i == 5) d.rollR();
            for (int j = 0; j < 4; j++) {
                ret.emplace_back(d);
                d.rollE();
            }
        }
        return ret;
    }

    int top_val() const {
        return val[up];
    }

    int right_val() const {
        return val[right];
    }

    int left_val() const {
        return val[left];
    }

    int front_val() const {
        return val[front];
    }

    int back_val() const {
        return val[back];
    }

    int down_val() const {
        return val[down];
    }

    std::vector<int> now() const {
        std::vector<int> ret(6);
        ret[0] = top_val();
        ret[1] = front_val();
        ret[2] = right_val();
        ret[3] = left_val();
        ret[4] = back_val();
        ret[5] = down_val();
        return ret;
    }

    std::vector<int> val = {0, 1, 2, 3, 4, 5};
};

bool input(std::vector<int> &t) {
    int zero = 0;
    rep(i,0,6) {
        std::cin >> t[i];
        if(t[i] == 0) zero++;
    }
    if(zero == 6) return false;
    return true;
}

int main() {
    std::vector<int> t(6);
    while(input(t)) {
        int sum = 0;
        rep(i,0,6) sum += t[i];
        int p,q;
        std::cin >> p >> q;
        p--;
        std::vector<int> idxs(6);
        std::iota(all(idxs), 0);
        std::string ans = "";
        do {
            std::vector<int> val(6);
            rep(i,0,6) val[i] = t[idxs[i]];
            Dice dice;
            dice.setval(val);
            auto check = [&]() -> bool {
                int na = dice.top_val() + dice.down_val();
                int nb = dice.left_val() + dice.right_val();
                int nc = dice.front_val() + dice.back_val();
                return dice.top_val() >= 0 && na <= nb + nc && nb <= 1 + nc + na && nc <= 1 + na + nb;
            };
            if(!check()) {
                continue;
            }
            std::string s = "";
            rep(_,0,sum) {
                {
                    dice.rollE();
                    dice.val[dice.up]--;
                    if(check()) {
                        s += 'E';
                        continue;
                    }
                    dice.val[dice.up]++;
                    dice.rollW();
                }
                {
                    dice.rollN();
                    dice.val[dice.up]--;
                    if(check()) {
                        s += 'N';
                        continue;
                    }
                    dice.val[dice.up]++;
                    dice.rollS();
                }
                {
                    dice.rollS();
                    dice.val[dice.up]--;
                    if(check()) {
                        s += 'S';
                        continue;
                    }
                    dice.val[dice.up]++;
                    dice.rollN();
                }                {
                    dice.rollW();
                    dice.val[dice.up]--;
                    if(check()) {
                        s += 'W';
                        continue;
                    }
                    dice.val[dice.up]++;
                    dice.rollE();
                }
                assert(0);
            }
            if(ans.empty()) ans = s;
            else chmin(ans, s);
        } while(std::next_permutation(all(idxs)));
        if(ans.empty()) {
            std::cout << "impossible\n";
            continue;
        }
        std::cout << ans.substr(p, q-p) << '\n';
    }
}
accuracy: 1
time_ms: 640
memory_kb: 3468
final_rank: 3

code_snippet: #include<bits/stdc++.h>
using ll = long long;
#define var auto
const char newl = '\n';

using namespace std;

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }

template<typename T = int>
struct Die {
  array<T, 6> fs;
  int& top() { return fs[0]; }
  int& south() { return fs[1]; }
  int& east() { return fs[2]; }
  int& west() { return fs[3]; }
  int& north() { return fs[4]; }
  int& bottom() { return fs[5]; }

  int sum() { return fs[0] + fs[1] + fs[2] + fs[3] + fs[4] + fs[5]; }

  void roll(char c) {
    //the view from above
    // N
    //W E
    // S
    string b("EWNSRL");
    int v[6][4] = { {0,3,5,2},
                 {0,2,5,3},
                 {0,1,5,4},
                 {0,4,5,1},
                 {1,2,4,3},
                 {1,3,4,2} };
    for (int k = 0; k < 6; k++) {
      if (b[k] != c) continue;
      int t = fs[v[k][0]];
      fs[v[k][0]] = fs[v[k][1]];
      fs[v[k][1]] = fs[v[k][2]];
      fs[v[k][2]] = fs[v[k][3]];
      fs[v[k][3]] = t;
      break;
    }
  }
  using ll = long long;
  ll hash() {
    ll res = 0;
    for (int i = 0; i < 6; i++) res = res * 256 + fs[i];
    return res;
  }
  bool operator==(const Die& d) const {
    for (int i = 0; i < 6; i++) if (fs[i] != d.fs[i]) return 0;
    return 1;
  }
};

template<typename T>
vector<Die<T>> makeDice(Die<T> d) {
  vector<Die<T>> res;
  for (int i = 0; i < 6; i++) {
    Die t(d);
    if (i == 1) t.roll('N');
    if (i == 2) t.roll('S');
    if (i == 3) t.roll('S'), t.roll('S');
    if (i == 4) t.roll('L');
    if (i == 5) t.roll('R');
    for (int k = 0; k < 4; k++) {
      res.emplace_back(t);
      t.roll('E');
    }
  }
  return res;
}

string rotates("ENSW");
bool is_valid(Die<int>& die) {
  int sum = die.sum();
  if (sum == 0) return true;
  if (sum % 2 == 1) {
    for (var&& c : rotates) {
      var nxt = die;
      nxt.roll(c);
      if (nxt.bottom() == 0) continue;
      nxt.bottom()--;
      if (is_valid(nxt)) return true;
    }
    return false;
  }

  int X = die.fs[2] + die.fs[3];
  int Y = die.fs[1] + die.fs[4];
  int Z = die.fs[0] + die.fs[5];

  if (X > Y) swap(Y, X);
  if (X + Y < Z) return true;
  if (Z < Y - X) return false;
  Z -= Y - X;

  return Z % 2 == 0;
}

bool solve() {
  vector<int> t(6);
  for (var&& elem : t) cin >> elem;
  var sum = accumulate(t.begin(), t.end(), 0);
  if (sum == 0) return false;
  int p, q;
  cin >> p >> q;

  string res;

  sort(t.begin(), t.end());
  do
  {
    Die die;
    for (int i = 0; i < t.size(); i++) die.fs[i] = t[i];
    
    // if (die.bottom() == 0) continue;
    // die.bottom()--;

    bool same = res.size() == sum;

    string cur_res = "";
    for (int cnt = 0; cnt < sum; cnt++) {
      for (var c : rotates) {
        // 枝刈り
        if (same && res[cnt] < c) break;

        var nxt = die;
        nxt.roll(c);
        if (nxt.bottom() == 0) continue;
        nxt.bottom()--;

        if (is_valid(nxt)) {
          die = nxt;
          cur_res += c;
          if (same && cur_res[cnt] < res[cnt]) same = false;
          goto end;
        }
      }
      break;
    end:;
    }

    if (cur_res.size() != sum) continue;
    res = cur_res;

  } while (next_permutation(t.begin(), t.end()));

  if (res == "") {
    cout << "impossible" << endl;
  }
  else {
    cout << res.substr(p - 1, q - p + 1) << endl;
  }

  
  return true;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  while (solve()){}
}
accuracy: 1
time_ms: 1340
memory_kb: 3428
final_rank: 10

code_snippet: #include<bits/stdc++.h>
using ll = long long;
#define var auto
const char newl = '\n';

using namespace std;

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }

bool is_opposite[6][6];

template<typename T = int>
struct Die {
  array<T, 6> fs;
  int& top() { return fs[0]; }
  int& south() { return fs[1]; }
  int& east() { return fs[2]; }
  int& west() { return fs[3]; }
  int& north() { return fs[4]; }
  int& bottom() { return fs[5]; }

  int sum() { return fs[0] + fs[1] + fs[2] + fs[3] + fs[4] + fs[5]; }

  void roll(char c) {
    //the view from above
    // N
    //W E
    // S
    string b("EWNSRL");
    int v[6][4] = { {0,3,5,2},
                 {0,2,5,3},
                 {0,1,5,4},
                 {0,4,5,1},
                 {1,2,4,3},
                 {1,3,4,2} };
    for (int k = 0; k < 6; k++) {
      if (b[k] != c) continue;
      int t = fs[v[k][0]];
      fs[v[k][0]] = fs[v[k][1]];
      fs[v[k][1]] = fs[v[k][2]];
      fs[v[k][2]] = fs[v[k][3]];
      fs[v[k][3]] = t;
      break;
    }
  }
  using ll = long long;
  ll hash() {
    ll res = 0;
    for (int i = 0; i < 6; i++) res = res * 256 + fs[i];
    return res;
  }
  bool operator==(const Die& d) const {
    for (int i = 0; i < 6; i++) if (fs[i] != d.fs[i]) return 0;
    return 1;
  }
};

template<typename T>
vector<Die<T>> makeDice(Die<T> d) {
  vector<Die<T>> res;
  for (int i = 0; i < 6; i++) {
    Die t(d);
    if (i == 1) t.roll('N');
    if (i == 2) t.roll('S');
    if (i == 3) t.roll('S'), t.roll('S');
    if (i == 4) t.roll('L');
    if (i == 5) t.roll('R');
    for (int k = 0; k < 4; k++) {
      res.emplace_back(t);
      t.roll('E');
    }
  }
  return res;
}

bool check(array<int, 6>& x) {
  int Z = x[0] + x[5];
  int Y = x[1] + x[4];
  int X = x[2] + x[3];

  if (X > Y) swap(Y, X);

  if (X + Y < Z) return true;

  if (Z < Y - X) return false;

  Z -= Y - X;

  return Z % 2 == 0;
}

string rotates("ENSW");
bool is_valid(Die<int>& die) {
  int sum = die.sum();
  if (sum == 0) return true;
  if (sum % 2 == 1) {
    for (var&& c : rotates) {
      var nxt = die;
      nxt.roll(c);
      if (nxt.bottom() == 0) continue;
      nxt.bottom()--;
      if (is_valid(nxt)) return true;
    }
    return false;
  }

  return check(die.fs);

  int fst = 0;
  int fstInd = -1;
  int snd = 0;
  int sndInd = -1;
  for (int i = 0; i < 6; i++) {
    if (fst <= die.fs[i]) {
      snd = fst;
      sndInd = fstInd;
      fst = die.fs[i];
      fstInd = i;
    }
    else if (snd <= die.fs[i]) {
      snd = die.fs[i];
      sndInd = i;
    }
  }

  assert(sndInd != -1);
  
  if (not is_opposite[fstInd][sndInd]) return true;
  if (fst + snd <= sum / 2) return true;
  return false;
}

bool solve() {
  vector<int> t(6);
  for (var&& elem : t) cin >> elem;
  var sum = accumulate(t.begin(), t.end(), 0);
  if (sum == 0) return false;
  int p, q;
  cin >> p >> q;

  string res;

  sort(t.begin(), t.end());
  do
  {
    Die die;
    for (int i = 0; i < t.size(); i++) die.fs[i] = t[i];
    
    // if (die.bottom() == 0) continue;
    // die.bottom()--;

    bool same = res.size() == sum;

    string cur_res = "";
    for (int cnt = 0; cnt < sum; cnt++) {
      for (var c : rotates) {
        // 枝刈り
        if (same && res[cnt] < c) break;

        var nxt = die;
        nxt.roll(c);
        if (nxt.bottom() == 0) continue;
        nxt.bottom()--;

        if (is_valid(nxt)) {
          die = nxt;
          cur_res += c;
          if (same && cur_res[cnt] < res[cnt]) same = false;
          goto end;
        }
      }
      break;
    end:;
    }

    if (cur_res.size() != sum) continue;
    res = cur_res;

  } while (next_permutation(t.begin(), t.end()));

  if (res == "") {
    cout << "impossible" << endl;
  }
  else {
    cout << res.substr(p - 1, q - p + 1) << endl;
  }

  
  return true;
}

int main() {
  is_opposite[0][5] = true;
  is_opposite[5][0] = true;

  is_opposite[1][4] = true;
  is_opposite[4][1] = true;

  is_opposite[2][3] = true;
  is_opposite[3][2] = true;


  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  while (solve()){}
}
accuracy: 1
time_ms: 1320
memory_kb: 3476
final_rank: 11

code_snippet: #include <bits/stdc++.h>
using namespace std;

struct Dice {
    std::array<int, 6> surface;

    Dice(int TOP = 1, int FRONT = 2) {
        assert(1 <= TOP and TOP <= 6);
        assert(1 <= FRONT and FRONT <= 6);
        assert(TOP + FRONT != 7);
        surface[0] = TOP;
        surface[1] = FRONT;
        surface[2] = dice[TOP - 1][FRONT - 1];
        surface[3] = 7 - surface[2];
        surface[4] = 7 - surface[1];
        surface[5] = 7 - surface[0];
    }

    Dice(const std::vector<int>& v) {
        assert(v.size() == 6);
        for (size_t i = 0; i < 6; i++) surface[i] = v[i];
    }

    const int& top() const { return surface[0]; }
    const int& front() const { return surface[1]; }
    const int& right() const { return surface[2]; }
    const int& left() const { return surface[3]; }
    const int& back() const { return surface[4]; }
    const int& bottom() const { return surface[5]; }
    const int& operator[](int k) const { return surface[k]; }

    int& top() { return surface[0]; }
    int& front() { return surface[1]; }
    int& right() { return surface[2]; }
    int& left() { return surface[3]; }
    int& back() { return surface[4]; }
    int& bottom() { return surface[5]; }
    int& operator[](int k) { return surface[k]; }

    bool operator==(const Dice& d) const { return surface == d.surface; }
    bool operator!=(const Dice& d) const { return surface != d.surface; }
    bool operator<(const Dice& d) const { return surface < d.surface; }

    int roll(int k) {  // x++, x--, y++, y--, turn right, turn left
        assert(0 <= k and k < 6);
        int tmp = surface[code[k][0]];
        for (int i = 0; i < 3; i++) surface[code[k][i]] = surface[code[k][i + 1]];
        surface[code[k][3]] = tmp;
        return surface[0];
    }

    int rollc(char c) {
        for (int k = 0; k < 6; k++) {
            if (direction[k] != c) continue;
            return roll(k);
        }
        assert(false);
    }

    int hash() const {
        int res = 0;
        for (size_t i = 0; i < 6; i++) {
            assert(1 <= surface[i] and surface[i] <= 6);
            (res *= 6) += surface[i] - 1;
        }
        return res;
    }

    std::vector<Dice> make_all() {
        std::vector<Dice> res;
        for (int i = 0; i < 6; i++) {
            Dice d(*this);
            if (i == 1) d.roll(2);
            if (i == 2) d.roll(3);
            if (i == 3) d.roll(3), d.roll(3);
            if (i == 4) d.roll(5);
            if (i == 5) d.roll(4);
            for (int j = 0; j < 4; j++) {
                res.emplace_back(d);
                d.roll(0);
            }
        }
        return res;
    }

    Dice identifier() {
        auto dices = make_all();
        return *min_element(dices.begin(), dices.end());
    }

private:
    const int dice[6][6] = {{0, 3, 5, 2, 4, 0}, {4, 0, 1, 6, 0, 3}, {2, 6, 0, 0, 1, 5},
                            {5, 1, 0, 0, 6, 2}, {3, 0, 6, 1, 0, 4}, {0, 4, 2, 5, 3, 0}};
    const int code[6][4] = {{0, 3, 5, 2}, {0, 2, 5, 3}, {0, 1, 5, 4}, {0, 4, 5, 1}, {1, 2, 4, 3}, {1, 3, 4, 2}};
    const char direction[6] = {'E', 'W', 'N', 'S', 'R', 'L'};
};

/**
 * @brief Dice
 * @docs docs/util/Dice.md
 */

const string directions = "EWNS";

void solve(vector<int> t) {
    string ans = "";
    sort(t.begin(), t.end());
    int sum = accumulate(t.begin(), t.end(), 0);

    do {
        Dice dice(t);
        string cur = "";
        bool update = true;
        for (int rest = sum - 1; rest >= 0 and exchange(update, false); rest--) {
            for (int dir : {0, 2, 3, 1}) {
                dice.roll(dir);
                dice.bottom()--;
                bool ok = true;
                if (dice.bottom() < 0) ok = false;
                for (int i = 0; i < 3; i++) {
                    int opposite = dice[i] + dice[5 - i];
                    if (opposite > rest - opposite + (i > 0)) ok = false;
                }
                if (ok) {
                    update = true;
                    cur += directions[dir];
                    break;
                }
                dice.bottom()++;
                dice.roll(dir ^ 1);
            }
        }
        if (!update) continue;
        if (ans == "")
            ans = cur;
        else
            ans = min(ans, cur);
    } while (next_permutation(t.begin(), t.end()));

    int p, q;
    cin >> p >> q;
    if (ans == "") {
        cout << "impossible" << '\n';
        return;
    }
    for (int i = --p; i < q; i++) cout << ans[i];
    cout << '\n';
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    vector<int> t(6);
    while (1) {
        for (int i = 0; i < 6; i++) cin >> t[i];
        if (t.back() == 0) break;
        solve(t);
    }
    return 0;
}
accuracy: 1
time_ms: 960
memory_kb: 3484
final_rank: 4

code_snippet: #define LOCAL
#include <bits/stdc++.h>
using namespace std;
#pragma region Macros
typedef long long ll;
typedef __int128_t i128;
typedef unsigned int uint;
typedef unsigned long long ull;
#define ALL(x) (x).begin(), (x).end()

template <typename T> istream& operator>>(istream& is, vector<T>& v) {
    for (T& x : v) is >> x;
    return is;
}
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    for (int i = 0; i < (int)v.size(); i++) {
        os << v[i] << (i + 1 == (int)v.size() ? "" : " ");
    }
    return os;
}
template <typename T, typename U> ostream& operator<<(ostream& os, const pair<T, U>& p) {
    os << '(' << p.first << ',' << p.second << ')';
    return os;
}
template <typename T, typename U> ostream& operator<<(ostream& os, const map<T, U>& m) {
    os << '{';
    for (auto itr = m.begin(); itr != m.end();) {
        os << '(' << itr->first << ',' << itr->second << ')';
        if (++itr != m.end()) os << ',';
    }
    os << '}';
    return os;
}
template <typename T, typename U> ostream& operator<<(ostream& os, const unordered_map<T, U>& m) {
    os << '{';
    for (auto itr = m.begin(); itr != m.end();) {
        os << '(' << itr->first << ',' << itr->second << ')';
        if (++itr != m.end()) os << ',';
    }
    os << '}';
    return os;
}
template <typename T> ostream& operator<<(ostream& os, const set<T>& s) {
    os << '{';
    for (auto itr = s.begin(); itr != s.end();) {
        os << *itr;
        if (++itr != s.end()) os << ',';
    }
    os << '}';
    return os;
}
template <typename T> ostream& operator<<(ostream& os, const multiset<T>& s) {
    os << '{';
    for (auto itr = s.begin(); itr != s.end();) {
        os << *itr;
        if (++itr != s.end()) os << ',';
    }
    os << '}';
    return os;
}
template <typename T> ostream& operator<<(ostream& os, const unordered_set<T>& s) {
    os << '{';
    for (auto itr = s.begin(); itr != s.end();) {
        os << *itr;
        if (++itr != s.end()) os << ',';
    }
    os << '}';
    return os;
}
template <typename T> ostream& operator<<(ostream& os, const deque<T>& v) {
    for (int i = 0; i < (int)v.size(); i++) {
        os << v[i] << (i + 1 == (int)v.size() ? "" : " ");
    }
    return os;
}

template <int i, typename T> void print_tuple(ostream&, const T&) {}
template <int i, typename T, typename H, class... Args> void print_tuple(ostream& os, const T& t) {
    if (i) os << ',';
    os << get<i>(t);
    print_tuple<i + 1, T, Args...>(os, t);
}
template <typename... Args> ostream& operator<<(ostream& os, const tuple<Args...>& t) {
    os << '{';
    print_tuple<0, tuple<Args...>, Args...>(os, t);
    return os << '}';
}

void debug_out() { cerr << '\n'; }
template <class Head, class... Tail> void debug_out(Head&& head, Tail&&... tail) {
    cerr << head;
    if (sizeof...(Tail) > 0) cerr << ", ";
    debug_out(move(tail)...);
}
#ifdef LOCAL
#define debug(...)                                                                   \
    cerr << " ";                                                                     \
    cerr << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << '\n'; \
    cerr << " ";                                                                     \
    debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

template <typename T> T gcd(T x, T y) { return y != 0 ? gcd(y, x % y) : x; }
template <typename T> T lcm(T x, T y) { return x / gcd(x, y) * y; }

int topbit(signed t) { return t == 0 ? -1 : 31 - __builtin_clz(t); }
int topbit(long long t) { return t == 0 ? -1 : 63 - __builtin_clzll(t); }
int botbit(signed a) { return a == 0 ? 32 : __builtin_ctz(a); }
int botbit(long long a) { return a == 0 ? 64 : __builtin_ctzll(a); }
int popcount(signed t) { return __builtin_popcount(t); }
int popcount(long long t) { return __builtin_popcountll(t); }
bool ispow2(int i) { return i && (i & -i) == i; }

template <class T> T ceil(T x, T y) {
    assert(y >= 1);
    return (x > 0 ? (x + y - 1) / y : x / y);
}
template <class T> T floor(T x, T y) {
    assert(y >= 1);
    return (x > 0 ? x / y : (x - y + 1) / y);
}

template <class T1, class T2> inline bool chmin(T1& a, T2 b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T1, class T2> inline bool chmax(T1& a, T2 b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
#pragma endregion

#include <array>
#include <cassert>
#include <string>
#include <vector>

struct Dice {
    std::array<int, 6> surface;

    Dice(int TOP = 1, int FRONT = 2) {
        assert(1 <= TOP and TOP <= 6);
        assert(1 <= FRONT and FRONT <= 6);
        assert(TOP + FRONT != 7);
        surface[0] = TOP;
        surface[1] = FRONT;
        surface[2] = dice[TOP - 1][FRONT - 1];
        surface[3] = 7 - surface[2];
        surface[4] = 7 - surface[1];
        surface[5] = 7 - surface[0];
    }

    Dice(const std::vector<int>& v) {
        assert(v.size() == 6);
        for (size_t i = 0; i < 6; i++) surface[i] = v[i];
    }

    const int& top() const { return surface[0]; }
    const int& front() const { return surface[1]; }
    const int& right() const { return surface[2]; }
    const int& left() const { return surface[3]; }
    const int& back() const { return surface[4]; }
    const int& bottom() const { return surface[5]; }
    const int& operator[](int k) const { return surface[k]; }

    int& top() { return surface[0]; }
    int& front() { return surface[1]; }
    int& right() { return surface[2]; }
    int& left() { return surface[3]; }
    int& back() { return surface[4]; }
    int& bottom() { return surface[5]; }
    int& operator[](int k) { return surface[k]; }

    bool operator==(const Dice& d) const { return surface == d.surface; }
    bool operator!=(const Dice& d) const { return surface != d.surface; }
    bool operator<(const Dice& d) const { return surface < d.surface; }

    int roll(int k) {  // x++, x--, y++, y--, turn right, turn left
        assert(0 <= k and k < 6);
        int tmp = surface[code[k][0]];
        for (int i = 0; i < 3; i++) surface[code[k][i]] = surface[code[k][i + 1]];
        surface[code[k][3]] = tmp;
        return surface[0];
    }

    int rollc(char c) {
        for (int k = 0; k < 6; k++) {
            if (direction[k] != c) continue;
            return roll(k);
        }
        assert(false);
    }

    int hash() const {
        int res = 0;
        for (size_t i = 0; i < 6; i++) {
            assert(1 <= surface[i] and surface[i] <= 6);
            (res *= 6) += surface[i] - 1;
        }
        return res;
    }

    std::vector<Dice> make_all() {
        std::vector<Dice> res;
        for (int i = 0; i < 6; i++) {
            Dice d(*this);
            if (i == 1) d.roll(2);
            if (i == 2) d.roll(3);
            if (i == 3) d.roll(3), d.roll(3);
            if (i == 4) d.roll(5);
            if (i == 5) d.roll(4);
            for (int j = 0; j < 4; j++) {
                res.emplace_back(d);
                d.roll(0);
            }
        }
        return res;
    }

    Dice identifier() {
        auto dices = make_all();
        return *min_element(dices.begin(), dices.end());
    }

private:
    const int dice[6][6] = {{0, 3, 5, 2, 4, 0}, {4, 0, 1, 6, 0, 3}, {2, 6, 0, 0, 1, 5},
                            {5, 1, 0, 0, 6, 2}, {3, 0, 6, 1, 0, 4}, {0, 4, 2, 5, 3, 0}};
    const int code[6][4] = {{0, 3, 5, 2}, {0, 2, 5, 3}, {0, 1, 5, 4}, {0, 4, 5, 1}, {1, 2, 4, 3}, {1, 3, 4, 2}};
    const char direction[6] = {'E', 'W', 'N', 'S', 'R', 'L'};
};

/**
 * @brief Dice
 * @docs docs/util/Dice.md
 */

const int INF = 1e9;
const long long IINF = 1e18;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const long long MOD = 1000000007;
// const long long MOD = 998244353;

const string directions = "EWNS";

void solve(vector<int> t) {
    string ans = "";
    sort(t.begin(), t.end());
    int sum = accumulate(t.begin(), t.end(), 0);

    do {
        Dice dice(t);
        string cur = "";
        bool update = true;
        for (int rest = sum - 1; rest >= 0 and exchange(update, false); rest--) {
            for (int dir : {0, 2, 3, 1}) {
                dice.roll(dir);
                dice.bottom()--;
                bool ok = true;
                if (dice.bottom() < 0) ok = false;
                for (int i = 0; i < 3; i++) {
                    int opposite = dice[i] + dice[5 - i];
                    if (opposite > rest - opposite + (i > 0)) ok = false;
                }
                if (ok) {
                    update = true;
                    cur += directions[dir];
                    break;
                }
                dice.bottom()++;
                dice.roll(dir ^ 1);
            }
        }
        if (!update) continue;
        if (ans == "")
            ans = cur;
        else
            ans = min(ans, cur);
    } while (next_permutation(t.begin(), t.end()));

    int p, q;
    cin >> p >> q;
    if (ans == "") {
        cout << "impossible" << '\n';
        return;
    }
    for (int i = --p; i < q; i++) cout << ans[i];
    cout << '\n';
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    vector<int> t(6);
    while (1) {
        for (int i = 0; i < 6; i++) cin >> t[i];
        if (t.back() == 0) break;
        solve(t);
    }
    return 0;
}
accuracy: 1
time_ms: 970
memory_kb: 3560
final_rank: 6

code_snippet: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=200005,INF=1<<30;

struct dice{
    int u,f,r,b,l,d;
    
    void init(int uu,int ff,int rr,int bb,int ll,int dd){
        u=uu;
        f=ff;
        r=rr;
        b=bb;
        l=ll;
        d=dd;
    }
    
    void init(vector<int> S){
        init(S[0],S[1],S[2],S[3],S[4],S[5]);
    }
    
    void turnE(){
        int save=r;
        r=u;
        u=l;
        l=d;
        d=save;
    }
    
    void turnN(){
        int save=b;
        b=u;
        u=f;
        f=d;
        d=save;
    }
    
    void turnS(){
        int save=f;
        f=u;
        u=b;
        b=d;
        d=save;
    }
    
    void turnW(){
        int save=l;
        l=u;
        u=r;
        r=d;
        d=save;
    }
    
    bool check(){
        int x=l+r,y=f+b,z=u+d;
        if(d<0) return false;
        if(x==0&&y==0&z==0) return true;
        if(x>=y&&x>=z){
            if(x<=y+z+1) return true;
            else return false;
        }
        if(y>=x&&y>=z){
            if(y<=x+z+1) return true;
            else return false;
        }
        if(z>=x&&z>=y){
            if(z<=x+y) return true;
            else return false;
        }
        return false;
    }
};

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    while(1){
        int sum=0;
        vector<int> S(6);
        for(int i=0;i<6;i++){
            cin>>S[i];
            sum+=S[i];
        }
        if(S.back()==0) break;
        int s,t;cin>>s>>t;s--;
        bool f=false;
        do{
            dice X;X.init(S);
            if(X.check()) f=true;
        }while(next_permutation(all(S)));
        
        if(!f){
            cout<<"impossible\n";
            continue;
        }
        string ans="Z";
        sort(all(S));
        
        do{
            dice X;X.init(S);
            if(!X.check()) continue;
            
            string T;
            for(int q=0;q<sum;q++){
                X.turnE();
                X.d--;
                if(X.check()){
                    T+='E';
                    continue;
                }else{
                    X.d++;
                    X.turnW();
                }
                
                X.turnN();
                X.d--;
                if(X.check()){
                    T+='N';
                    continue;
                }else{
                    X.d++;
                    X.turnS();
                }
                
                X.turnS();
                X.d--;
                if(X.check()){
                    T+='S';
                    continue;
                }else{
                    X.d++;
                    X.turnN();
                }
                
                X.turnW();
                X.d--;
                if(X.check()){
                    T+='W';
                    continue;
                }else{
                    X.d++;
                    X.turnE();
                }
            }
            
            chmin(ans,T);
            
        }while(next_permutation(all(S)));
        
        cout<<ans.substr(s,t-s)<<"\n";
    }
}
accuracy: 1
time_ms: 510
memory_kb: 3308
final_rank: 1

code_snippet: #include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
#include<cassert>
#include<set>
#include<complex>
#include<numeric>
#include<functional>
#include<unordered_map>
#include<unordered_set>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,LL> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
    for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
    for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){
    if(vec_n==-1)vec_n=vec_s.size();
    for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){
    if(vec_n==-1)vec_n=vec_s.size();
    for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
template<typename T> ostream& operator<<(ostream& os,const vector<T>& v1){
    int n=v1.size();
    for(int i=0;i<n;i++){
        if(i)os<<" ";
        os<<v1[i];
    }
    return os;
}
template<typename T1,typename T2> ostream& operator<<(ostream& os,const pair<T1,T2>& p){
    os<<p.first<<" "<<p.second;
    return os;
}
template<typename T> istream& operator>>(istream& is,vector<T>& v1){
    int n=v1.size();
    for(int i=0;i<n;i++)is>>v1[i];
    return is;
}
template<typename T1,typename T2> istream& operator>>(istream& is,pair<T1,T2>& p){
    is>>p.first>>p.second;
    return is;
}

class Dice{
    // 0
    //1234
    // 5
    //top:0, front:2, x:13, y:24, z:50
    static const int N=6;
    int A[N];
public:
    Dice(const vector<int> v1){
        assert(v1.size()>=N);
        for(int i=0;i<N;i++){
            A[i]=v1[i];
        }
    }

    //rotate: clockwise
    void rotateX(){//0->2->5->4->0
        swap(A[0],A[4]);
        swap(A[4],A[5]);
        swap(A[5],A[2]);
    }

    void rotateXrev(){
        swap(A[5],A[2]);
        swap(A[4],A[5]);
        swap(A[0],A[4]);
    }

    void rotateY(){//0->3->5->1
        swap(A[0],A[1]);
        swap(A[1],A[5]);
        swap(A[5],A[3]);
    }

    void rotateYrev(){
        swap(A[5],A[3]);
        swap(A[1],A[5]);
        swap(A[0],A[1]);
    }

    void rotateZ(){//1->2->3->4
        swap(A[4],A[3]);
        swap(A[3],A[2]);
        swap(A[2],A[1]);
    }

    void rotateZrev(){//1->2->3->4
        swap(A[2],A[1]);
        swap(A[3],A[2]);
        swap(A[4],A[3]);
    }

    bool check(){
        int a=0;
        for(int i=0;i<N;i++){
            if(A[i]<0)return false;
            a+=A[i];
        }
        if((A[0]+A[5])*2>a)return false;
        if((A[1]+A[3])*2-1>a)return false;
        if((A[2]+A[4])*2-1>a)return false;
        return true;
    }

    string calc(){
        string sa="ENSW",ss="";
        int i,j;
        while(1){
            for(i=0;i<4;i++){
                if(i==0)rotateX();
                if(i==1)rotateY();
                if(i==2)rotateYrev();
                if(i==3)rotateXrev();
                A[5]--;
                if(check())break;
                A[5]++;
                if(i==0)rotateXrev();
                if(i==1)rotateYrev();
                if(i==2)rotateY();
                if(i==3)rotateX();
            }
            if(A[5]<0 || i==4)return "impossible";
            ss.push_back(sa[i]);
            for(i=0;i<N;i++){
                if(A[i]>0)break;
            }
            if(i==N)return ss;
        }
    }


    template<typename T> T hash(int base){
        T s=0;
        for(int i=0;i<N;i++){
            s*=base;
            s+=A[i];
        }
        return s;
    }

    template<typename T> vector<T> all_hash(int base){
        int i,j;
        vector<T> vs;
        const int M=4;
        for(i=0;i<2*M;i++){
            if(i<M)rotateX();
            else rotateY();
            if(i>=M && i%2)continue;
            for(j=0;j<4;j++){
                rotateZ();
                vs.push_back(hash<T>(base));
            }
        }
        return vs;
    }
};


namespace sol{
    const int N=6;
    string ss;
    vector<int> v1(N);
    vector<int> vi(N,-1);

    void dfs(int d){
        int i;
        if(d<N){
            for(i=0;i<N;i++){
                if(vi[i]!=-1)continue;
                vi[i]=d;
                dfs(d+1);
                vi[i]=-1;
            }
            return;
        }
        vector<int> v2(N);
        for(i=0;i<N;i++){
            v2[vi[i]]=v1[i];
        }
        Dice dice(v2);
        string sa=dice.calc();
        if(sa<ss)ss=sa;
    }

    void solve(){
        int n,m;
        int i,j,k;
        int a,b,c;
        int p,q;
        while(cin>>v1){
            sort(v1.begin(),v1.end());
            if(v1.back()==0)return;
            cin>>p>>q;
            p--;
            vi.assign(N,-1);
            ss="z";
            dfs(0);
            if(ss=="impossible")cout<<ss<<endl;
            else cout<<ss.substr(p,q-p)<<endl;
        }
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    sol::solve();
}
accuracy: 1
time_ms: 1330
memory_kb: 3428
final_rank: 9

code_snippet: /**
 *	author: nok0
 *	created: 2021.06.29 22:18:07
**/
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>
using namespace std;
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif

#pragma region Macros
// rep macro
#define foa(v, a) for(auto &v : a)
#define REPname(a, b, c, d, e, ...) e
#define REP(...) REPname(__VA_ARGS__, REP3, REP2, REP1, REP0)(__VA_ARGS__)
#define REP0(x) for(int i = 0; i < (x); ++i)
#define REP1(i, x) for(int i = 0; i < (x); ++i)
#define REP2(i, l, r) for(int i = (l); i < (r); ++i)
#define REP3(i, l, r, c) for(int i = (l); i < (r); i += (c))
#define REPSname(a, b, c, ...) c
#define REPS(...) REPSname(__VA_ARGS__, REPS1, REPS0)(__VA_ARGS__)
#define REPS0(x) for(int i = 1; i <= (x); ++i)
#define REPS1(i, x) for(int i = 1; i <= (x); ++i)
#define RREPname(a, b, c, d, e, ...) e
#define RREP(...) RREPname(__VA_ARGS__, RREP3, RREP2, RREP1, RREP0)(__VA_ARGS__)
#define RREP0(x) for(int i = (x)-1; i >= 0; --i)
#define RREP1(i, x) for(int i = (x)-1; i >= 0; --i)
#define RREP2(i, r, l) for(int i = (r)-1; i >= (l); --i)
#define RREP3(i, r, l, c) for(int i = (r)-1; i >= (l); i -= (c))
#define RREPSname(a, b, c, ...) c
#define RREPS(...) RREPSname(__VA_ARGS__, RREPS1, RREPS0)(__VA_ARGS__)
#define RREPS0(x) for(int i = (x); i >= 1; --i)
#define RREPS1(i, x) for(int i = (x); i >= 1; --i)

// name macro
#define pb push_back
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define popcnt(x) __builtin_popcountll(x)
template <class T = int>
using V = std::vector<T>;
template <class T = int>
using VV = std::vector<std::vector<T>>;
template <class T>
using pqup = std::priority_queue<T, std::vector<T>, std::greater<T>>;
using ll = long long;
using ld = long double;
using int128 = __int128_t;
using pii = std::pair<int, int>;
using pll = std::pair<long long, long long>;

// input macro
template <class T, class U>
std::istream &operator>>(std::istream &is, std::pair<T, U> &p) {
	is >> p.first >> p.second;
	return is;
}
template <class T>
std::istream &operator>>(std::istream &is, std::vector<T> &v) {
	for(T &i : v) is >> i;
	return is;
}
std::istream &operator>>(std::istream &is, __int128_t &a) {
	std::string s;
	is >> s;
	__int128_t ret = 0;
	for(int i = 0; i < s.length(); i++)
		if('0' <= s[i] and s[i] <= '9')
			ret = 10 * ret + s[i] - '0';
	a = ret * (s[0] == '-' ? -1 : 1);
	return is;
}
#if __has_include(<atcoder/all>)
std::istream &operator>>(std::istream &is, atcoder::modint998244353 &a) {
	long long v;
	is >> v;
	a = v;
	return is;
}
std::istream &operator>>(std::istream &is, atcoder::modint1000000007 &a) {
	long long v;
	is >> v;
	a = v;
	return is;
}
template <int m>
std::istream &operator>>(std::istream &is, atcoder::static_modint<m> &a) {
	long long v;
	is >> v;
	a = v;
	return is;
}
template <int m>
std::istream &operator>>(std::istream &is, atcoder::dynamic_modint<m> &a) {
	long long v;
	is >> v;
	a = v;
	return is;
}
#endif
namespace scanner {
void scan(int &a) { std::cin >> a; }
void scan(long long &a) { std::cin >> a; }
void scan(std::string &a) { std::cin >> a; }
void scan(char &a) { std::cin >> a; }
void scan(char a[]) { std::scanf("%s", a); }
void scan(double &a) { std::cin >> a; }
void scan(long double &a) { std::cin >> a; }
template <class T, class U>
void scan(std::pair<T, U> &p) { std::cin >> p; }
template <class T>
void scan(std::vector<T> &a) { std::cin >> a; }
void INPUT() {}
template <class Head, class... Tail>
void INPUT(Head &head, Tail &... tail) {
	scan(head);
	INPUT(tail...);
}
}  // namespace scanner
#define VEC(type, name, size)     \
	std::vector<type> name(size); \
	scanner::INPUT(name)
#define VVEC(type, name, h, w)                                    \
	std::vector<std::vector<type>> name(h, std::vector<type>(w)); \
	scanner::INPUT(name)
#define INT(...)     \
	int __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define LL(...)            \
	long long __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define STR(...)             \
	std::string __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define CHAR(...)     \
	char __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define DOUBLE(...)     \
	double __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define LD(...)              \
	long double __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)

// output-macro
template <class T, class U>
std::ostream &operator<<(std::ostream &os, const std::pair<T, U> &p) {
	os << p.first << " " << p.second;
	return os;
}
template <class T>
std::ostream &operator<<(std::ostream &os, const std::vector<T> &a) {
	for(int i = 0; i < int(a.size()); ++i) {
		if(i) os << " ";
		os << a[i];
	}
	return os;
}
std::ostream &operator<<(std::ostream &dest, __int128_t &value) {
	std::ostream::sentry s(dest);
	if(s) {
		__uint128_t tmp = value < 0 ? -value : value;
		char buffer[128];
		char *d = std::end(buffer);
		do {
			--d;
			*d = "0123456789"[tmp % 10];
			tmp /= 10;
		} while(tmp != 0);
		if(value < 0) {
			--d;
			*d = '-';
		}
		int len = std::end(buffer) - d;
		if(dest.rdbuf()->sputn(d, len) != len) {
			dest.setstate(std::ios_base::badbit);
		}
	}
	return dest;
}
#if __has_include(<atcoder/all>)
std::ostream &operator<<(std::ostream &os, const atcoder::modint998244353 &a) { return os << a.val(); }
std::ostream &operator<<(std::ostream &os, const atcoder::modint1000000007 &a) { return os << a.val(); }
template <int m>
std::ostream &operator<<(std::ostream &os, const atcoder::static_modint<m> &a) { return os << a.val(); }
template <int m>
std::ostream &operator<<(std::ostream &os, const atcoder::dynamic_modint<m> &a) { return os << a.val(); }
#endif
template <class T>
void print(const T a) { std::cout << a << '\n'; }
template <class Head, class... Tail>
void print(Head H, Tail... T) {
	std::cout << H << ' ';
	print(T...);
}
template <class T>
void printel(const T a) { std::cout << a << '\n'; }
template <class T>
void printel(const std::vector<T> &a) {
	for(const auto &v : a)
		std::cout << v << '\n';
}
template <class Head, class... Tail>
void printel(Head H, Tail... T) {
	std::cout << H << '\n';
	printel(T...);
}
void Yes(const bool b = true) { std::cout << (b ? "Yes\n" : "No\n"); }
void No() { std::cout << "No\n"; }
void YES(const bool b = true) { std::cout << (b ? "YES\n" : "NO\n"); }
void NO() { std::cout << "NO\n"; }
void err(const bool b = true) {
	if(b) {
		std::cout << "-1\n", exit(0);
	}
}

//debug macro
namespace debugger {
template <class T>
void view(const std::vector<T> &a) {
	std::cerr << "{ ";
	for(const auto &v : a) {
		std::cerr << v << ", ";
	}
	std::cerr << "\b\b }";
}
template <class T>
void view(const std::vector<std::vector<T>> &a) {
	std::cerr << "{\n";
	for(const auto &v : a) {
		std::cerr << "\t";
		view(v);
		std::cerr << "\n";
	}
	std::cerr << "}";
}
template <class T, class U>
void view(const std::vector<std::pair<T, U>> &a) {
	std::cerr << "{\n";
	for(const auto &p : a) std::cerr << "\t(" << p.first << ", " << p.second << ")\n";
	std::cerr << "}";
}
template <class T, class U>
void view(const std::map<T, U> &m) {
	std::cerr << "{\n";
	for(const auto &p : m) std::cerr << "\t[" << p.first << "] : " << p.second << "\n";
	std::cerr << "}";
}
template <class T, class U>
void view(const std::pair<T, U> &p) { std::cerr << "(" << p.first << ", " << p.second << ")"; }
template <class T>
void view(const std::set<T> &s) {
	std::cerr << "{ ";
	for(auto &v : s) {
		view(v);
		std::cerr << ", ";
	}
	std::cerr << "\b\b }";
}

template <class T>
void view(const T &e) { std::cerr << e; }
}  // namespace debugger
#ifdef LOCAL
void debug_out() {}
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
	debugger::view(H);
	std::cerr << ", ";
	debug_out(T...);
}
#define debug(...)                                                \
	do {                                                          \
		std::cerr << __LINE__ << " [" << #__VA_ARGS__ << "] : ["; \
		debug_out(__VA_ARGS__);                                   \
		std::cerr << "\b\b]\n";                                   \
	} while(false)
#else
#define debug(...) (void(0))
#endif

// vector macro
template <class T>
int lb(const std::vector<T> &a, const T x) { return std::distance((a).begin(), std::lower_bound((a).begin(), (a).end(), (x))); }
template <class T>
int ub(const std::vector<T> &a, const T x) { return std::distance((a).begin(), std::upper_bound((a).begin(), (a).end(), (x))); }
template <class T>
void UNIQUE(std::vector<T> &a) {
	std::sort(a.begin(), a.end());
	a.erase(std::unique(a.begin(), a.end()), a.end());
}
template <class T>
std::vector<T> press(std::vector<T> &a) {
	auto res = a;
	UNIQUE(res);
	for(auto &v : a)
		v = lb(res, v);
	return res;
}
#define SORTname(a, b, c, ...) c
#define SORT(...) SORTname(__VA_ARGS__, SORT1, SORT0, ...)(__VA_ARGS__)
#define SORT0(a) std::sort((a).begin(), (a).end())
#define SORT1(a, c) std::sort((a).begin(), (a).end(), [](const auto x, const auto y) { return x c y; })
template <class T>
void ADD(std::vector<T> &a, const T x) {
	for(auto &v : a) v += x;
}
template <class T>
void SUB(std::vector<T> &a, const T x = 1) {
	for(auto &v : a) v -= x;
}
template <class T>
void MUL(std::vector<T> &a, const T x) {
	for(auto &v : a) v *= x;
}
template <class T>
void DIV(std::vector<T> &a, const T x) {
	for(auto &v : a) v /= x;
}

// math macro
template <class T, class U>
inline bool chmin(T &a, const U &b) { return a > b ? a = b, true : false; }
template <class T, class U>
inline bool chmax(T &a, const U &b) { return a < b ? a = b, true : false; }
template <class T>
T divup(T x, T y) { return (x + y - 1) / y; }
template <class T>
T POW(T a, long long n) {
	T ret = 1;
	while(n) {
		if(n & 1) ret *= a;
		a *= a;
		n >>= 1;
	}
	return ret;
}
// modpow
long long POW(long long a, long long n, const int mod) {
	long long ret = 1;
	while(n) {
		if(n & 1) (ret *= a) %= mod;
		(a *= a) %= mod;
		n >>= 1;
	}
	return ret;
}

// others
struct fast_io {
	fast_io() {
		ios::sync_with_stdio(false);
		cin.tie(nullptr);
		cout << fixed << setprecision(15);
	}
} fast_io_;
const int inf = 1e9;
const ll INF = 1e18;
#pragma endregion

V<> nd(6);
void main_() {
	string ans = "";
	VEC(int, t, 6);
	int sum = accumulate(all(t), 0);
	if(!sum) exit(0);
	INT(p, q);
	V<> perm(6);
	iota(all(perm), 0);
	do {
		string res = "";
		V<> d(6);
		REP(i, 6) { d[i] = t[perm[i]]; }

		auto chk = [&d]() -> bool {
			if(*min_element(all(d)) < 0) return 0;
			int a = d[0] + d[1];
			int b = d[2] + d[3];
			int c = d[4] + d[5];
			bool ok = 1;
			ok &= a <= b + c + 1;
			ok &= b <= a + c + 1;
			ok &= c <= a + b;
			return ok;
		};

		auto east_rotate = [&]() {
			nd[2] = d[2];
			nd[3] = d[3];
			nd[4] = d[1];
			nd[1] = d[5];
			nd[5] = d[0];
			nd[0] = d[4];
			d = nd;
			return;
		};

		auto west_rotate = [&]() {
			nd[2] = d[2];
			nd[3] = d[3];
			nd[1] = d[4];
			nd[5] = d[1];
			nd[0] = d[5];
			nd[4] = d[0];
			d = nd;
			return;
		};

		auto north_rotate = [&]() {
			nd[0] = d[0];
			nd[1] = d[1];
			nd[4] = d[3];
			nd[3] = d[5];
			nd[5] = d[2];
			nd[2] = d[4];
			d = nd;
			return;
		};

		auto south_rotate = [&]() {
			nd[0] = d[0];
			nd[1] = d[1];
			nd[3] = d[4];
			nd[5] = d[3];
			nd[2] = d[5];
			nd[4] = d[2];
			d = nd;
			return;
		};

		REP(_, sum) {
			{
				east_rotate();
				d[4]--;
				if(chk()) {
					res += 'E';
					continue;
				}
				d[4]++;
				west_rotate();
			}
			{
				north_rotate();
				d[4]--;
				if(chk()) {
					res += 'N';
					continue;
				}
				d[4]++;
				south_rotate();
			}
			{
				south_rotate();
				d[4]--;
				if(chk()) {
					res += 'S';
					continue;
				}
				d[4]++;
				north_rotate();
			}
			{
				west_rotate();
				d[4]--;
				if(chk()) {
					res += 'W';
					continue;
				}
				d[4]++;
				east_rotate();
			}
			break;
		}
		if(SZ(res) == sum) {
			if(SZ(ans) == 0)
				ans = res;
			else
				chmin(ans, res);
		}
	} while(next_permutation(all(perm)));
	if(SZ(ans) != sum) {
		print("impossible");
		return;
	}
	REP(i, p - 1, q) {
		cout << ans[i];
	}
	cout << endl;
	return;
}

int main() {
	int t = 1;
	//cin >> t;
	while(1) main_();
	return 0;
}
accuracy: 1
time_ms: 3050
memory_kb: 3568
final_rank: 15

code_snippet: /**
 *	author: nok0
 *	created: 2021.06.29 22:18:07
**/
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>
using namespace std;
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif

#pragma region Macros
// rep macro
#define foa(v, a) for(auto &v : a)
#define REPname(a, b, c, d, e, ...) e
#define REP(...) REPname(__VA_ARGS__, REP3, REP2, REP1, REP0)(__VA_ARGS__)
#define REP0(x) for(int i = 0; i < (x); ++i)
#define REP1(i, x) for(int i = 0; i < (x); ++i)
#define REP2(i, l, r) for(int i = (l); i < (r); ++i)
#define REP3(i, l, r, c) for(int i = (l); i < (r); i += (c))
#define REPSname(a, b, c, ...) c
#define REPS(...) REPSname(__VA_ARGS__, REPS1, REPS0)(__VA_ARGS__)
#define REPS0(x) for(int i = 1; i <= (x); ++i)
#define REPS1(i, x) for(int i = 1; i <= (x); ++i)
#define RREPname(a, b, c, d, e, ...) e
#define RREP(...) RREPname(__VA_ARGS__, RREP3, RREP2, RREP1, RREP0)(__VA_ARGS__)
#define RREP0(x) for(int i = (x)-1; i >= 0; --i)
#define RREP1(i, x) for(int i = (x)-1; i >= 0; --i)
#define RREP2(i, r, l) for(int i = (r)-1; i >= (l); --i)
#define RREP3(i, r, l, c) for(int i = (r)-1; i >= (l); i -= (c))
#define RREPSname(a, b, c, ...) c
#define RREPS(...) RREPSname(__VA_ARGS__, RREPS1, RREPS0)(__VA_ARGS__)
#define RREPS0(x) for(int i = (x); i >= 1; --i)
#define RREPS1(i, x) for(int i = (x); i >= 1; --i)

// name macro
#define pb push_back
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define popcnt(x) __builtin_popcountll(x)
template <class T = int>
using V = std::vector<T>;
template <class T = int>
using VV = std::vector<std::vector<T>>;
template <class T>
using pqup = std::priority_queue<T, std::vector<T>, std::greater<T>>;
using ll = long long;
using ld = long double;
using int128 = __int128_t;
using pii = std::pair<int, int>;
using pll = std::pair<long long, long long>;

// input macro
template <class T, class U>
std::istream &operator>>(std::istream &is, std::pair<T, U> &p) {
	is >> p.first >> p.second;
	return is;
}
template <class T>
std::istream &operator>>(std::istream &is, std::vector<T> &v) {
	for(T &i : v) is >> i;
	return is;
}
std::istream &operator>>(std::istream &is, __int128_t &a) {
	std::string s;
	is >> s;
	__int128_t ret = 0;
	for(int i = 0; i < s.length(); i++)
		if('0' <= s[i] and s[i] <= '9')
			ret = 10 * ret + s[i] - '0';
	a = ret * (s[0] == '-' ? -1 : 1);
	return is;
}
#if __has_include(<atcoder/all>)
std::istream &operator>>(std::istream &is, atcoder::modint998244353 &a) {
	long long v;
	is >> v;
	a = v;
	return is;
}
std::istream &operator>>(std::istream &is, atcoder::modint1000000007 &a) {
	long long v;
	is >> v;
	a = v;
	return is;
}
template <int m>
std::istream &operator>>(std::istream &is, atcoder::static_modint<m> &a) {
	long long v;
	is >> v;
	a = v;
	return is;
}
template <int m>
std::istream &operator>>(std::istream &is, atcoder::dynamic_modint<m> &a) {
	long long v;
	is >> v;
	a = v;
	return is;
}
#endif
namespace scanner {
void scan(int &a) { std::cin >> a; }
void scan(long long &a) { std::cin >> a; }
void scan(std::string &a) { std::cin >> a; }
void scan(char &a) { std::cin >> a; }
void scan(char a[]) { std::scanf("%s", a); }
void scan(double &a) { std::cin >> a; }
void scan(long double &a) { std::cin >> a; }
template <class T, class U>
void scan(std::pair<T, U> &p) { std::cin >> p; }
template <class T>
void scan(std::vector<T> &a) { std::cin >> a; }
void INPUT() {}
template <class Head, class... Tail>
void INPUT(Head &head, Tail &... tail) {
	scan(head);
	INPUT(tail...);
}
}  // namespace scanner
#define VEC(type, name, size)     \
	std::vector<type> name(size); \
	scanner::INPUT(name)
#define VVEC(type, name, h, w)                                    \
	std::vector<std::vector<type>> name(h, std::vector<type>(w)); \
	scanner::INPUT(name)
#define INT(...)     \
	int __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define LL(...)            \
	long long __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define STR(...)             \
	std::string __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define CHAR(...)     \
	char __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define DOUBLE(...)     \
	double __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define LD(...)              \
	long double __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)

// output-macro
template <class T, class U>
std::ostream &operator<<(std::ostream &os, const std::pair<T, U> &p) {
	os << p.first << " " << p.second;
	return os;
}
template <class T>
std::ostream &operator<<(std::ostream &os, const std::vector<T> &a) {
	for(int i = 0; i < int(a.size()); ++i) {
		if(i) os << " ";
		os << a[i];
	}
	return os;
}
std::ostream &operator<<(std::ostream &dest, __int128_t &value) {
	std::ostream::sentry s(dest);
	if(s) {
		__uint128_t tmp = value < 0 ? -value : value;
		char buffer[128];
		char *d = std::end(buffer);
		do {
			--d;
			*d = "0123456789"[tmp % 10];
			tmp /= 10;
		} while(tmp != 0);
		if(value < 0) {
			--d;
			*d = '-';
		}
		int len = std::end(buffer) - d;
		if(dest.rdbuf()->sputn(d, len) != len) {
			dest.setstate(std::ios_base::badbit);
		}
	}
	return dest;
}
#if __has_include(<atcoder/all>)
std::ostream &operator<<(std::ostream &os, const atcoder::modint998244353 &a) { return os << a.val(); }
std::ostream &operator<<(std::ostream &os, const atcoder::modint1000000007 &a) { return os << a.val(); }
template <int m>
std::ostream &operator<<(std::ostream &os, const atcoder::static_modint<m> &a) { return os << a.val(); }
template <int m>
std::ostream &operator<<(std::ostream &os, const atcoder::dynamic_modint<m> &a) { return os << a.val(); }
#endif
template <class T>
void print(const T a) { std::cout << a << '\n'; }
template <class Head, class... Tail>
void print(Head H, Tail... T) {
	std::cout << H << ' ';
	print(T...);
}
template <class T>
void printel(const T a) { std::cout << a << '\n'; }
template <class T>
void printel(const std::vector<T> &a) {
	for(const auto &v : a)
		std::cout << v << '\n';
}
template <class Head, class... Tail>
void printel(Head H, Tail... T) {
	std::cout << H << '\n';
	printel(T...);
}
void Yes(const bool b = true) { std::cout << (b ? "Yes\n" : "No\n"); }
void No() { std::cout << "No\n"; }
void YES(const bool b = true) { std::cout << (b ? "YES\n" : "NO\n"); }
void NO() { std::cout << "NO\n"; }
void err(const bool b = true) {
	if(b) {
		std::cout << "-1\n", exit(0);
	}
}

//debug macro
namespace debugger {
template <class T>
void view(const std::vector<T> &a) {
	std::cerr << "{ ";
	for(const auto &v : a) {
		std::cerr << v << ", ";
	}
	std::cerr << "\b\b }";
}
template <class T>
void view(const std::vector<std::vector<T>> &a) {
	std::cerr << "{\n";
	for(const auto &v : a) {
		std::cerr << "\t";
		view(v);
		std::cerr << "\n";
	}
	std::cerr << "}";
}
template <class T, class U>
void view(const std::vector<std::pair<T, U>> &a) {
	std::cerr << "{\n";
	for(const auto &p : a) std::cerr << "\t(" << p.first << ", " << p.second << ")\n";
	std::cerr << "}";
}
template <class T, class U>
void view(const std::map<T, U> &m) {
	std::cerr << "{\n";
	for(const auto &p : m) std::cerr << "\t[" << p.first << "] : " << p.second << "\n";
	std::cerr << "}";
}
template <class T, class U>
void view(const std::pair<T, U> &p) { std::cerr << "(" << p.first << ", " << p.second << ")"; }
template <class T>
void view(const std::set<T> &s) {
	std::cerr << "{ ";
	for(auto &v : s) {
		view(v);
		std::cerr << ", ";
	}
	std::cerr << "\b\b }";
}

template <class T>
void view(const T &e) { std::cerr << e; }
}  // namespace debugger
#ifdef LOCAL
void debug_out() {}
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
	debugger::view(H);
	std::cerr << ", ";
	debug_out(T...);
}
#define debug(...)                                                \
	do {                                                          \
		std::cerr << __LINE__ << " [" << #__VA_ARGS__ << "] : ["; \
		debug_out(__VA_ARGS__);                                   \
		std::cerr << "\b\b]\n";                                   \
	} while(false)
#else
#define debug(...) (void(0))
#endif

// vector macro
template <class T>
int lb(const std::vector<T> &a, const T x) { return std::distance((a).begin(), std::lower_bound((a).begin(), (a).end(), (x))); }
template <class T>
int ub(const std::vector<T> &a, const T x) { return std::distance((a).begin(), std::upper_bound((a).begin(), (a).end(), (x))); }
template <class T>
void UNIQUE(std::vector<T> &a) {
	std::sort(a.begin(), a.end());
	a.erase(std::unique(a.begin(), a.end()), a.end());
}
template <class T>
std::vector<T> press(std::vector<T> &a) {
	auto res = a;
	UNIQUE(res);
	for(auto &v : a)
		v = lb(res, v);
	return res;
}
#define SORTname(a, b, c, ...) c
#define SORT(...) SORTname(__VA_ARGS__, SORT1, SORT0, ...)(__VA_ARGS__)
#define SORT0(a) std::sort((a).begin(), (a).end())
#define SORT1(a, c) std::sort((a).begin(), (a).end(), [](const auto x, const auto y) { return x c y; })
template <class T>
void ADD(std::vector<T> &a, const T x) {
	for(auto &v : a) v += x;
}
template <class T>
void SUB(std::vector<T> &a, const T x = 1) {
	for(auto &v : a) v -= x;
}
template <class T>
void MUL(std::vector<T> &a, const T x) {
	for(auto &v : a) v *= x;
}
template <class T>
void DIV(std::vector<T> &a, const T x) {
	for(auto &v : a) v /= x;
}

// math macro
template <class T, class U>
inline bool chmin(T &a, const U &b) { return a > b ? a = b, true : false; }
template <class T, class U>
inline bool chmax(T &a, const U &b) { return a < b ? a = b, true : false; }
template <class T>
T divup(T x, T y) { return (x + y - 1) / y; }
template <class T>
T POW(T a, long long n) {
	T ret = 1;
	while(n) {
		if(n & 1) ret *= a;
		a *= a;
		n >>= 1;
	}
	return ret;
}
// modpow
long long POW(long long a, long long n, const int mod) {
	long long ret = 1;
	while(n) {
		if(n & 1) (ret *= a) %= mod;
		(a *= a) %= mod;
		n >>= 1;
	}
	return ret;
}

// others
struct fast_io {
	fast_io() {
		ios::sync_with_stdio(false);
		cin.tie(nullptr);
		cout << fixed << setprecision(15);
	}
} fast_io_;
const int inf = 1e9;
const ll INF = 1e18;
#pragma endregion

V<> nd(6);
void main_() {
	string ans = "";
	VEC(int, t, 6);
	int sum = accumulate(all(t), 0);
	if(!sum) exit(0);
	INT(p, q);
	V<> perm(6);
	iota(all(perm), 0);
	do {
		string res = "";
		V<> d(6);
		REP(i, 6) { d[i] = t[perm[i]]; }

		auto chk = [&d]() -> bool {
			if(*min_element(all(d)) < 0) return 0;
			int a = d[0] + d[1];
			int b = d[2] + d[3];
			int c = d[4] + d[5];
			bool ok = 1;
			ok &= a <= b + c + 1;
			ok &= b <= a + c + 1;
			ok &= c <= a + b;
			return ok;
		};

		auto east_rotate = [&]() {
			nd[2] = d[2];
			nd[3] = d[3];
			nd[4] = d[1];
			nd[1] = d[5];
			nd[5] = d[0];
			nd[0] = d[4];
			d = nd;
			return;
		};

		auto west_rotate = [&]() {
			nd[2] = d[2];
			nd[3] = d[3];
			nd[1] = d[4];
			nd[5] = d[1];
			nd[0] = d[5];
			nd[4] = d[0];
			d = nd;
			return;
		};

		auto north_rotate = [&]() {
			nd[0] = d[0];
			nd[1] = d[1];
			nd[4] = d[3];
			nd[3] = d[5];
			nd[5] = d[2];
			nd[2] = d[4];
			d = nd;
			return;
		};

		auto south_rotate = [&]() {
			nd[0] = d[0];
			nd[1] = d[1];
			nd[3] = d[4];
			nd[5] = d[3];
			nd[2] = d[5];
			nd[4] = d[2];
			d = nd;
			return;
		};

		REP(_, sum) {
			{
				east_rotate();
				d[4]--;
				if(chk()) {
					res += 'E';
					continue;
				}
				d[4]++;
				west_rotate();
			}
			{
				north_rotate();
				d[4]--;
				if(chk()) {
					res += 'N';
					continue;
				}
				d[4]++;
				south_rotate();
			}
			{
				south_rotate();
				d[4]--;
				if(chk()) {
					res += 'S';
					continue;
				}
				d[4]++;
				north_rotate();
			}
			{
				west_rotate();
				d[4]--;
				if(chk()) {
					res += 'W';
					continue;
				}
				d[4]++;
				east_rotate();
			}
			break;
		}
		if(SZ(res) == sum) {
			if(SZ(ans) == 0)
				ans = res;
			else
				chmin(ans, res);
		}
	} while(next_permutation(all(perm)));
	if(SZ(ans) != sum) {
		print("impossible");
		return;
	}
	REP(i, p - 1, q) {
		cout << ans[i];
	}
	cout << endl;
	return;
}

int main() {
	int t = 1;
	//cin >> t;
	while(1) main_();
	return 0;
}
accuracy: 1
time_ms: 3050
memory_kb: 3488
final_rank: 14

code_snippet: //#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
using namespace std;

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (ll)(m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD1 = 1e9+7;
const ll MOD9 = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T> using PQ = priority_queue<T>;
template<typename T> using QP = priority_queue<T,vector<T>,greater<T>>;
template<typename T1, typename T2>bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
template<typename T1, typename T2>bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T1,typename T2,typename T3>void anss(T1 x,T2 y,T3 z){ans(x!=y,x,z);};  
template<typename T>void debug(const T &v,ll h,ll w,string sv=" "){for(ll i=0;i<h;i++){cout<<v[i][0];for(ll j=1;j<w;j++)cout<<sv<<v[i][j];cout<<endl;}};
template<typename T>void debug(const T &v,ll n,string sv=" "){if(n!=0)cout<<v[0];for(ll i=1;i<n;i++)cout<<sv<<v[i];cout<<endl;};
template<typename T>void debug(const vector<T>&v){debug(v,v.size());}
template<typename T>void debug(const vector<vector<T>>&v){for(auto &vv:v)debug(vv,vv.size());}
template<typename T>void debug(stack<T> st){while(!st.empty()){cout<<st.top()<<" ";st.pop();}cout<<endl;}
template<typename T>void debug(queue<T> st){while(!st.empty()){cout<<st.front()<<" ";st.pop();}cout<<endl;}
template<typename T>void debug(deque<T> st){while(!st.empty()){cout<<st.front()<<" ";st.pop_front();}cout<<endl;}
template<typename T>void debug(PQ<T> st){while(!st.empty()){cout<<st.top()<<" ";st.pop();}cout<<endl;}
template<typename T>void debug(QP<T> st){while(!st.empty()){cout<<st.top()<<" ";st.pop();}cout<<endl;}
template<typename T>void debug(const set<T>&v){for(auto z:v)cout<<z<<" ";cout<<endl;}
template<typename T>void debug(const multiset<T>&v){for(auto z:v)cout<<z<<" ";cout<<endl;}
template<typename T,size_t size>void debug(const array<T, size> &a){for(auto z:a)cout<<z<<" ";cout<<endl;}
template<typename T,typename V>void debug(const map<T,V>&v){for(auto z:v)cout<<"["<<z.first<<"]="<<z.second<<",";cout<<endl;}
template<typename T>vector<vector<T>>vec(ll x, ll y, T w){vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,-1,0,0,1,1,-1,-1};vector<ll>dy={0,0,1,-1,1,-1,1,-1};
template<typename T>vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v(ts...))>(a,make_v(ts...));}
template<typename T1, typename T2>ostream &operator<<(ostream &os, const pair<T1, T2>&p){return os << p.first << " " << p.second;}
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v){for(auto &z:v)os << z << " ";cout<<"|"; return os;}
template<typename T>void rearrange(vector<int>&ord, vector<T>&v){
  auto tmp = v;
  for(int i=0;i<tmp.size();i++)v[i] = tmp[ord[i]];
}
template<typename Head, typename... Tail>void rearrange(vector<int>&ord,Head&& head, Tail&&... tail){
  rearrange(ord, head);
  rearrange(ord, tail...);
}
template<typename T> vector<int> ascend(const vector<T>&v){
  vector<int>ord(v.size());iota(ord.begin(),ord.end(),0);
  sort(ord.begin(),ord.end(),[&](int i,int j){return v[i]<v[j];});
  return ord;
}
template<typename T> vector<int> descend(const vector<T>&v){
  vector<int>ord(v.size());iota(ord.begin(),ord.end(),0);
  sort(ord.begin(),ord.end(),[&](int i,int j){return v[i]>v[j];});
  return ord;
}
ll FLOOR(ll n,ll div){return n>=0?n/div:(n-div+1)/div;}
ll CEIL(ll n,ll div){return n>=0?(n+div-1)/div:n/div;}
ll digitsum(ll n){ll ret=0;while(n){ret+=n%10;n/=10;}return ret;}
template<typename T>T min(const vector<T>&v){return *min_element(v.begin(),v.end());}
template<typename T>T max(const vector<T>&v){return *max_element(v.begin(),v.end());}
template<typename T>T acc(const vector<T>&v){return accumulate(v.begin(),v.end(),T(0));};
template<typename T>T reverse(const T &v){return T(v.rbegin(),v.rend());};
//mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());
int popcount(ll x){return __builtin_popcountll(x);};
int poplow(ll x){return __builtin_ctzll(x);};
int pophigh(ll x){return 63 - __builtin_clzll(x);};
template<typename T>T poll(queue<T> &q){auto ret=q.front();q.pop();return ret;};
template<typename T>T poll(priority_queue<T> &q){auto ret=q.top();q.pop();return ret;};
template<typename T>T poll(QP<T> &q){auto ret=q.top();q.pop();return ret;};
template<typename T>T poll(stack<T> &s){auto ret=s.top();s.pop();return ret;};
template< typename T = int >
struct edge {
  int to;
  T cost;
  int id;
  edge():id(-1){};
  edge(int to, T cost = 1, int id = -1):to(to), cost(cost), id(id){}
  operator int() const { return to; }
};

template<typename T>
using Graph = vector<vector<edge<T>>>;
template<typename T>
Graph<T>revgraph(const Graph<T> &g){
  Graph<T>ret(g.size());
  for(int i=0;i<g.size();i++){
    for(auto e:g[i]){
      int to = e.to;
      e.to = i;
      ret[to].push_back(e);
    }
  }
  return ret;
}
template<typename T>
Graph<T> readGraph(int n,int m,int indexed=1,bool directed=false,bool weighted=false){
  Graph<T> ret(n);
  for(int es = 0; es < m; es++){
    int u,v;
    T w=1;
    cin>>u>>v;u-=indexed,v-=indexed;
    if(weighted)cin>>w;
    ret[u].emplace_back(v,w,es);
    if(!directed)ret[v].emplace_back(u,w,es);
  }
  return ret;
}
template<typename T>
Graph<T> readParent(int n,int indexed=1,bool directed=true){
  Graph<T>ret(n);
  for(int i=1;i<n;i++){
    int p;cin>>p;
    p-=indexed;
    ret[p].emplace_back(i);
    if(!directed)ret[i].emplace_back(p);
  }
  return ret;
}
template<typename T>
struct Dice{
  array<T, 6>ar;
  Dice() = default;
  // 1
  //342
  // 0
  // 5
  Dice(array<T, 6>ar):ar(ar){}
  //xが上下、yが左右
  //0:x++
  //1:x--
  //2:y++
  //3:y--
  //4:clockwise
  //5:counter-clockwise
  void roll(int x){
    array<int, 6>trans;
    if(x == 0)ar = {ar[4],ar[5],ar[2],ar[3],ar[1],ar[0]};
    if(x == 1)ar = {ar[5],ar[4],ar[2],ar[3],ar[0],ar[1]};
    if(x == 2)ar = {ar[0],ar[1],ar[4],ar[5],ar[3],ar[2]};
    if(x == 3)ar = {ar[0],ar[1],ar[5],ar[4],ar[2],ar[3]};
    if(x == 4)ar = {ar[2],ar[3],ar[1],ar[0],ar[4],ar[5]};
    if(x == 5)ar = {ar[3],ar[2],ar[0],ar[1],ar[4],ar[5]};
  }
  bool operator==(const Dice &d) const{
    return ar == d.ar;
  }
  bool operator!=(const Dice &d) const{
    return ar != d.ar;
  }
  bool operator<(const Dice &d) const{
    return ar < d.ar;
  }
  T &operator[](int x){
    return ar[x];
  }
  T operator[](int x) const{
    return ar[x];
  }
  vector<Dice<T>>makeAll(){
    vector<Dice<T>>ret;
    for(int i=0;i<6;i++){
      Dice tmp = *this;
      if(i==1)tmp.roll(0);
      if(i==2)tmp.roll(1);
      if(i==3)tmp.roll(1),tmp.roll(1);
      if(i==4)tmp.roll(4);
      if(i==5)tmp.roll(5);
      for(int k=0;k<4;k++){
        ret.push_back(tmp);
        tmp.roll(2);
      }
    }
    return ret;
  }
  Dice<T> minDice(){
    auto dice = this->makeAll();
    return *min_element(dice.begin(), dice.end());
  }
};
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  while(1){
    array<int,6>t;
    rep(i,0,6)cin>>t[i];
    if(t[5]==0)break;
    int p,q;cin>>p>>q;
    sort(ALL(t));
    string ret="impossible";
    string ope="SNEW";
    int m=0;for(auto z:t)m+=z;
    auto check=[&](const Dice<int>&d,int sum){
      if((d[4]+d[5])*2>sum)return false;
      if((d[0]+d[1])*2>sum+1)return false;
      if((d[2]+d[3])*2>sum+1)return false;
      return true;
    };
    do{
      Dice<int>dice(t);
      if(!check(dice,m))continue;
      string s;
      rrep(sum,0,m){
        for(auto i:{2,1,0,3}){
          auto tmp=dice;
          tmp.roll(i);
          if(tmp[5]<=0)continue;
          tmp[5]-=1;
          if(check(tmp,sum)){
            s+=ope[i];
            dice=tmp;
            break;
          }
        }
        if(s.size()+sum!=m)break;
      }
      if(s.size()==m){
        chmin(ret,s);
      }
    }while(next_permutation(ALL(t)));
    //cout<<ret<<endl;
    if(ret[0]=='i')cout<<ret<<endl;
    else cout<<ret.substr(p-1,q-p+1)<<endl;
  }
  return 0;
}
accuracy: 1
time_ms: 620
memory_kb: 3264
final_rank: 2