#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <utility>
#include <map>
#include <math.h>
#include <sstream>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <unordered_set>
#include <unordered_map>

using namespace std;

#define loop(iii,l,r) for (int iii = l; iii < r; iii++)
#define tests int T; cin >> T; while(T--)
#define all(c) (c).begin(),(c).end() //handy for function like "sort()"
#define ll long long //data types used often, but you don't want to type them time by time
#define ull unsigned long long
#define ui unsigned int
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); //to desynchronize the input of cin and scanf
#define PI 3.1415926535897932384626
//for map, pair
#define mp make_pair
#define fi first
#define se second
//for vectors
#define pb push_back
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef vector<ii> vii;

// *****************************

unordered_map<int, unordered_set<int> > m;

ll skills[200005], dp[200005], used[200005];
ll INF = 2000000000000000;

int main(){

    int n;
    cin >> n;
    loop(i,0,n){
        cin >> skills[i];
        m[skills[i]].insert(i);
    }

    loop(i,0,n+1){
        dp[i] = INF;
        used[i] = 1;
    }

    sort(skills, skills+n);

    dp[0] = 0;

    loop(i,3,n+1){
        ll three = dp[i-3] + skills[i-1] - skills[i-3];
        if (three < dp[i]){
            used[i] = 3;
            dp[i] = three;
        }
        if (i >= 4){
            ll four = dp[i-4] + skills[i-1] - skills[i-4];
            if (four < dp[i]){
                used[i] = 4;
                dp[i] = four;
            }
        }
        if (i >= 5){
            ll five = dp[i-5] + skills[i-1] - skills[i-5];
            if (five < dp[i]){
                used[i] = 5;
                dp[i] = five;
            }
        }

        // dp[i] = min(dp[i], dp[i-3] + skills[i-1] - skills[i-3]);
        // if (i >= 4)  dp[i] = min(dp[i], dp[i-4] + skills[i-1] - skills[i-4]);
        // if (i >= 5)  dp[i] = min(dp[i], dp[i-5] + skills[i-1] - skills[i-5]);
        // cout << dp[i] << " ";
    }

    ll maxDiff = dp[n];

    vector<ll> s;

    for (int i = n; i > 0; i-=used[i]){
        s.push_back(used[i]);
    }

    int i = 0, group = 1;
    for (int t = s.size()-1; t >= 0; t--){
        int num = s[t];
        loop(j,0,num){
            dp[i++] = group;
        }
        group++;
    }

    loop(i,0,n){
        unordered_set<int>::iterator it = m[skills[i]].begin();
        used[*it] = dp[i];
        m[skills[i]].erase(it);
    }

    cout << maxDiff << " " << group-1 << endl;

    loop(i,0,n)
        cout << used[i] << " ";
    cout << endl;

}


#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <utility>
#include <map>
#include <math.h>
#include <sstream>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <unordered_set>
#include <unordered_map>

using namespace std;

#define loop(iii,l,r) for (int iii = l; iii < r; iii++)
#define tests int T; cin >> T; while(T--)
#define all(c) (c).begin(),(c).end() //handy for function like "sort()"
#define ll long long //data types used often, but you don't want to type them time by time
#define ull unsigned long long
#define ui unsigned int
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); //to desynchronize the input of cin and scanf
#define PI 3.1415926535897932384626
//for map, pair
#define mp make_pair
#define fi first
#define se second
//for vectors
#define pb push_back
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef vector<ii> vii;

// *****************************

// unordered_map<int, unordered_set<int> > m;

pair<ll,ll> skills[200005];

ll dp[200005], used[200005];
ll INF = 2000000000000000;

int main(){

    int n;
    cin >> n;
    loop(i,0,n){
        int cur;
        cin >> cur;
        skills[i] = mp(cur, i);
    }

    loop(i,0,n+1){
        dp[i] = INF;
        used[i] = 1;
    }

    sort(skills, skills+n);

    dp[0] = 0;

    loop(i,3,n+1){
        ll three = dp[i-3] + skills[i-1].first - skills[i-3].first;
        if (three < dp[i]){
            used[i] = 3;
            dp[i] = three;
        }
        if (i >= 4){
            ll four = dp[i-4] + skills[i-1].first - skills[i-4].first;
            if (four < dp[i]){
                used[i] = 4;
                dp[i] = four;
            }
        }
        if (i >= 5){
            ll five = dp[i-5] + skills[i-1].first - skills[i-5].first;
            if (five < dp[i]){
                used[i] = 5;
                dp[i] = five;
            }
        }

        // dp[i] = min(dp[i], dp[i-3] + skills[i-1] - skills[i-3]);
        // if (i >= 4)  dp[i] = min(dp[i], dp[i-4] + skills[i-1] - skills[i-4]);
        // if (i >= 5)  dp[i] = min(dp[i], dp[i-5] + skills[i-1] - skills[i-5]);
        // cout << dp[i] << " ";
    }

    ll maxDiff = dp[n];

    vector<ll> s;

    for (int i = n; i > 0; i-=used[i]){
        s.push_back(used[i]);
    }

    int i = 0, group = 1;
    for (int t = s.size()-1; t >= 0; t--){
        int num = s[t];
        loop(j,0,num){
            dp[i++] = group;
        }
        group++;
    }

    loop(i,0,n){
        used[skills[i].second] = dp[i];
    }

    cout << maxDiff << " " << group-1 << endl;

    loop(i,0,n)
        cout << used[i] << " ";
    cout << endl;

}


#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <utility>
#include <map>
#include <math.h>
#include <sstream>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <unordered_set>
#include <unordered_map>

using namespace std;

#define loop(iii,l,r) for (int iii = l; iii < r; iii++)
#define tests int T; cin >> T; while(T--)
#define all(c) (c).begin(),(c).end() //handy for function like "sort()"
#define ll long long //data types used often, but you don't want to type them time by time
#define ull unsigned long long
#define ui unsigned int
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); //to desynchronize the input of cin and scanf
#define PI 3.1415926535897932384626
//for map, pair
#define mp make_pair
#define fi first
#define se second
//for vectors
#define pb push_back
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef vector<ii> vii;

// *****************************

unordered_map<int, set<int> > m;

int skills[200005], dp[200005], used[200005];
int INF = 2000000000;

int main(){

    int n;
    cin >> n;
    loop(i,0,n){
        cin >> skills[i];
        m[skills[i]].insert(i);
    }

    loop(i,0,n+1){
        dp[i] = INF;
        used[i] = 1;
    }

    sort(skills, skills+n);

    dp[0] = 0;

    loop(i,3,n+1){
        int three = dp[i-3] + skills[i-1] - skills[i-3];
        if (three < dp[i]){
            used[i] = 3;
            dp[i] = three;
        }
        if (i >= 4){
            int four = dp[i-4] + skills[i-1] - skills[i-4];
            if (four < dp[i]){
                used[i] = 4;
                dp[i] = four;
            }
        }
        if (i >= 5){
            int five = dp[i-5] + skills[i-1] - skills[i-5];
            if (five < dp[i]){
                used[i] = 5;
                dp[i] = five;
            }
        }

        // dp[i] = min(dp[i], dp[i-3] + skills[i-1] - skills[i-3]);
        // if (i >= 4)  dp[i] = min(dp[i], dp[i-4] + skills[i-1] - skills[i-4]);
        // if (i >= 5)  dp[i] = min(dp[i], dp[i-5] + skills[i-1] - skills[i-5]);
        // cout << dp[i] << " ";
    }

    int maxDiff = dp[n];

    vector<int> s;

    for (int i = n; i > 0; i-=used[i]){
        s.push_back(used[i]);
    }

    int i = 0, group = 1;
    for (int t = s.size()-1; t >= 0; t--){
        int num = s[t];
        loop(j,0,num){
            dp[i++] = group;
        }
        group++;
    }

    loop(i,0,n){
        set<int>::iterator it = m[skills[i]].begin();
        used[*it] = dp[i];
        m[skills[i]].erase(it);
    }

    cout << maxDiff << " " << group-1 << endl;

    loop(i,0,n)
        cout << used[i] << " ";
    cout << endl;

}


#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <utility>
#include <map>
#include <math.h>
#include <sstream>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <unordered_set>
#include <unordered_map>

using namespace std;

#define loop(iii,l,r) for (int iii = l; iii < r; iii++)
#define tests int T; cin >> T; while(T--)
#define all(c) (c).begin(),(c).end() //handy for function like "sort()"
#define ll long long //data types used often, but you don't want to type them time by time
#define ull unsigned long long
#define ui unsigned int
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); //to desynchronize the input of cin and scanf
#define PI 3.1415926535897932384626
//for map, pair
#define mp make_pair
#define fi first
#define se second
//for vectors
#define pb push_back
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef vector<ii> vii;

// *****************************

unordered_map<int, set<int> > m;

int skills[200005], dp[200005], used[200005], ans[200005];
int INF = 2000000000;

int main(){

    int n;
    cin >> n;
    loop(i,0,n){
        cin >> skills[i];
        m[skills[i]].insert(i);
    }

    loop(i,0,n+1)
        dp[i] = INF;

    sort(skills, skills+n);

    dp[0] = 0;

    loop(i,3,n+1){
        int three = dp[i-3] + skills[i-1] - skills[i-3];
        if (three < dp[i]){
            used[i] = 3;
            dp[i] = three;
        }
        int four = dp[i-4] + skills[i-1] - skills[i-4];
        if (i >= 4 && four < dp[i]){
            used[i] = 4;
            dp[i] = four;
        }
        int five = dp[i-5] + skills[i-1] - skills[i-5];
        if (i >= 5 && five < dp[i]){
            used[i] = 5;
            dp[i] = five;
        }
        // dp[i] = min(dp[i], dp[i-3] + skills[i-1] - skills[i-3]);
        // if (i >= 4)  dp[i] = min(dp[i], dp[i-4] + skills[i-1] - skills[i-4]);
        // if (i >= 5)  dp[i] = min(dp[i], dp[i-5] + skills[i-1] - skills[i-5]);
        // cout << dp[i] << " ";
    }

    int maxDiff = dp[n];

    stack<int> s;

    for (int i = n; i > 0; i-=used[i]){
        s.push(used[i]);
    }

    int i = 0, group = 1;
    while (!s.empty()){
        int num = s.top(); s.pop();
        loop(j,0,num){
            dp[i++] = group;
        }
        group++;
    }

    loop(i,0,n){
        set<int>::iterator it = m[skills[i]].begin();
        ans[*it] = dp[i];
        m[skills[i]].erase(it);
    }

    cout << maxDiff << " " << group-1 << endl;

    loop(i,0,n)
        cout << ans[i] << " ";
    cout << endl;

}


#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <utility>
#include <map>
#include <math.h>
#include <sstream>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <unordered_set>
#include <unordered_map>

using namespace std;

#define loop(iii,l,r) for (int iii = l; iii < r; iii++)
#define tests int T; cin >> T; while(T--)
#define all(c) (c).begin(),(c).end() //handy for function like "sort()"
#define ll long long //data types used often, but you don't want to type them time by time
#define ull unsigned long long
#define ui unsigned int
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); //to desynchronize the input of cin and scanf
#define PI 3.1415926535897932384626
//for map, pair
#define mp make_pair
#define fi first
#define se second
//for vectors
#define pb push_back
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef vector<ii> vii;

// *****************************

unordered_map<int, set<int> > m;

ll skills[200005], dp[200005], used[200005];
ll INF = 2000000000000000;

int main(){

    int n;
    cin >> n;
    loop(i,0,n){
        cin >> skills[i];
        m[skills[i]].insert(i);
    }

    loop(i,0,n+1){
        dp[i] = INF;
        used[i] = 1;
    }

    sort(skills, skills+n);

    dp[0] = 0;

    loop(i,3,n+1){
        ll three = dp[i-3] + skills[i-1] - skills[i-3];
        if (three < dp[i]){
            used[i] = 3;
            dp[i] = three;
        }
        if (i >= 4){
            ll four = dp[i-4] + skills[i-1] - skills[i-4];
            if (four < dp[i]){
                used[i] = 4;
                dp[i] = four;
            }
        }
        if (i >= 5){
            ll five = dp[i-5] + skills[i-1] - skills[i-5];
            if (five < dp[i]){
                used[i] = 5;
                dp[i] = five;
            }
        }

        // dp[i] = min(dp[i], dp[i-3] + skills[i-1] - skills[i-3]);
        // if (i >= 4)  dp[i] = min(dp[i], dp[i-4] + skills[i-1] - skills[i-4]);
        // if (i >= 5)  dp[i] = min(dp[i], dp[i-5] + skills[i-1] - skills[i-5]);
        // cout << dp[i] << " ";
    }

    ll maxDiff = dp[n];

    vector<ll> s;

    for (int i = n; i > 0; i-=used[i]){
        s.push_back(used[i]);
    }

    int i = 0, group = 1;
    for (int t = s.size()-1; t >= 0; t--){
        int num = s[t];
        loop(j,0,num){
            dp[i++] = group;
        }
        group++;
    }

    loop(i,0,n){
        set<int>::iterator it = m[skills[i]].begin();
        used[*it] = dp[i];
        m[skills[i]].erase(it);
    }

    cout << maxDiff << " " << group-1 << endl;

    loop(i,0,n)
        cout << used[i] << " ";
    cout << endl;

}


#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <utility>
#include <map>
#include <math.h>
#include <sstream>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <unordered_set>
#include <unordered_map>

using namespace std;

#define loop(iii,l,r) for (int iii = l; iii < r; iii++)
#define tests int T; cin >> T; while(T--)
#define all(c) (c).begin(),(c).end() //handy for function like "sort()"
#define ll long long //data types used often, but you don't want to type them time by time
#define ull unsigned long long
#define ui unsigned int
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); //to desynchronize the input of cin and scanf
#define PI 3.1415926535897932384626
//for map, pair
#define mp make_pair
#define fi first
#define se second
//for vectors
#define pb push_back
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef vector<ii> vii;

// *****************************

unordered_map<int, set<int> > m;

int skills[200005], dp[200005], used[200005];
int INF = 2000000000;

int main(){

    int n;
    cin >> n;
    loop(i,0,n){
        cin >> skills[i];
        m[skills[i]].insert(i);
    }

    loop(i,0,n+1)
        dp[i] = INF;

    sort(skills, skills+n);

    dp[0] = 0;

    loop(i,3,n+1){
        int three = dp[i-3] + skills[i-1] - skills[i-3];
        if (three < dp[i]){
            used[i] = 3;
            dp[i] = three;
        }
        int four = dp[i-4] + skills[i-1] - skills[i-4];
        if (i >= 4 && four < dp[i]){
            used[i] = 4;
            dp[i] = four;
        }
        int five = dp[i-5] + skills[i-1] - skills[i-5];
        if (i >= 5 && five < dp[i]){
            used[i] = 5;
            dp[i] = five;
        }
        // dp[i] = min(dp[i], dp[i-3] + skills[i-1] - skills[i-3]);
        // if (i >= 4)  dp[i] = min(dp[i], dp[i-4] + skills[i-1] - skills[i-4]);
        // if (i >= 5)  dp[i] = min(dp[i], dp[i-5] + skills[i-1] - skills[i-5]);
        // cout << dp[i] << " ";
    }

    int maxDiff = dp[n];

    stack<int> s;

    for (int i = n; i > 0; i-=used[i]){
        s.push(used[i]);
    }

    int i = 0, group = 1;
    while (!s.empty()){
        int num = s.top(); s.pop();
        loop(j,0,num){
            dp[i++] = group;
        }
        group++;
    }

    loop(i,0,n){
        set<int>::iterator it = m[skills[i]].begin();
        used[*it] = dp[i];
        m[skills[i]].erase(it);
    }

    cout << maxDiff << " " << group-1 << endl;

    loop(i,0,n)
        cout << used[i] << " ";
    cout << endl;

}


#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <utility>
#include <map>
#include <math.h>
#include <sstream>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <unordered_set>
#include <unordered_map>

using namespace std;

#define loop(iii,l,r) for (int iii = l; iii < r; iii++)
#define tests int T; cin >> T; while(T--)
#define all(c) (c).begin(),(c).end() //handy for function like "sort()"
#define ll long long //data types used often, but you don't want to type them time by time
#define ull unsigned long long
#define ui unsigned int
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); //to desynchronize the input of cin and scanf
#define PI 3.1415926535897932384626
//for map, pair
#define mp make_pair
#define fi first
#define se second
//for vectors
#define pb push_back
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef vector<ii> vii;

// *****************************

unordered_map<int, set<int> > m;

int skills[200005], dp[200005], used[200005];
int INF = 2000000000;

int main(){

    int n;
    cin >> n;
    loop(i,0,n){
        cin >> skills[i];
        m[skills[i]].insert(i);
    }

    loop(i,0,n+1){
        dp[i] = INF;
        // used[i] = 1;
    }

    sort(skills, skills+n);

    dp[0] = 0;

    loop(i,3,n+1){
        int three = dp[i-3] + skills[i-1] - skills[i-3];
        if (three < dp[i]){
            used[i] = 3;
            dp[i] = three;
        }
        if (i >= 4){
            int four = dp[i-4] + skills[i-1] - skills[i-4];
            if (four < dp[i]){
                used[i] = 4;
                dp[i] = four;
            }
        }
        if (i >= 5){
            int five = dp[i-5] + skills[i-1] - skills[i-5];
            if (five < dp[i]){
                used[i] = 5;
                dp[i] = five;
            }
        }

        // dp[i] = min(dp[i], dp[i-3] + skills[i-1] - skills[i-3]);
        // if (i >= 4)  dp[i] = min(dp[i], dp[i-4] + skills[i-1] - skills[i-4]);
        // if (i >= 5)  dp[i] = min(dp[i], dp[i-5] + skills[i-1] - skills[i-5]);
        // cout << dp[i] << " ";
    }

    int maxDiff = dp[n];

    vector<int> s;

    for (int i = n; i > 0; i-=used[i]){
        s.push_back(used[i]);
    }

    int i = 0, group = 1;
    for (int t = s.size()-1; t >= 0; t--){
        int num = s[t];
        loop(j,0,num){
            dp[i++] = group;
        }
        group++;
    }

    loop(i,0,n){
        set<int>::iterator it = m[skills[i]].begin();
        used[*it] = dp[i];
        m[skills[i]].erase(it);
    }

    cout << maxDiff << " " << group-1 << endl;

    loop(i,0,n)
        cout << used[i] << " ";
    cout << endl;

}


#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <utility>
#include <map>
#include <math.h>
#include <sstream>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <unordered_set>
#include <unordered_map>

using namespace std;

#define loop(iii,l,r) for (int iii = l; iii < r; iii++)
#define tests int T; cin >> T; while(T--)
#define all(c) (c).begin(),(c).end() //handy for function like "sort()"
#define ll long long //data types used often, but you don't want to type them time by time
#define ull unsigned long long
#define ui unsigned int
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); //to desynchronize the input of cin and scanf
#define PI 3.1415926535897932384626
//for map, pair
#define mp make_pair
#define fi first
#define se second
//for vectors
#define pb push_back
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef vector<ii> vii;

// *****************************

// unordered_map<int, unordered_set<int> > m;

pair<ll,ll> skills[200005];

ll dp[200005], used[200005];
ll INF = 2000000000000000;

int main(){

    int n;
    cin >> n;
    loop(i,0,n){
        int cur;
        cin >> cur;
        skills[i] = mp(cur, i);
    }

    loop(i,0,n+1){
        dp[i] = INF;
    }

    sort(skills, skills+n);

    dp[0] = 0;

    loop(i,3,n+1){
        ll three = dp[i-3] + skills[i-1].first - skills[i-3].first;
        if (three < dp[i]){
            used[i] = 3;
            dp[i] = three;
        }
        if (i >= 4){
            ll four = dp[i-4] + skills[i-1].first - skills[i-4].first;
            if (four < dp[i]){
                used[i] = 4;
                dp[i] = four;
            }
        }
        if (i >= 5){
            ll five = dp[i-5] + skills[i-1].first - skills[i-5].first;
            if (five < dp[i]){
                used[i] = 5;
                dp[i] = five;
            }
        }
    }

    ll maxDiff = dp[n];

    vector<ll> s;

    for (int i = n; i > 0; i-=used[i]){
        s.push_back(used[i]);
    }

    int i = 0, group = 1;
    for (int t = s.size()-1; t >= 0; t--){
        int num = s[t];
        loop(j,0,num){
            dp[i++] = group;
        }
        group++;
    }

    loop(i,0,n){
        used[skills[i].second] = dp[i];
    }

    cout << maxDiff << " " << group-1 << endl;

    loop(i,0,n)
        cout << used[i] << " ";
    cout << endl;

}


#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <utility>
#include <map>
#include <math.h>
#include <sstream>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <unordered_set>
#include <unordered_map>

using namespace std;

#define loop(iii,l,r) for (int iii = l; iii < r; iii++)
#define tests int T; cin >> T; while(T--)
#define all(c) (c).begin(),(c).end() //handy for function like "sort()"
#define ll long long //data types used often, but you don't want to type them time by time
#define ull unsigned long long
#define ui unsigned int
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); //to desynchronize the input of cin and scanf
#define PI 3.1415926535897932384626
//for map, pair
#define mp make_pair
#define fi first
#define se second
//for vectors
#define pb push_back
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef vector<ii> vii;

// *****************************

unordered_map<int, set<int> > m;

int skills[200005], dp[200005], used[200005];
int INF = 2000000000;

int main(){

    int n;
    cin >> n;
    loop(i,0,n){
        cin >> skills[i];
        m[skills[i]].insert(i);
    }

    loop(i,0,n+1){
        dp[i] = INF;
        used[i] = 1;
    }

    sort(skills, skills+n);

    dp[0] = 0;

    loop(i,3,n+1){
        int three = dp[i-3] + skills[i-1] - skills[i-3];
        if (three < dp[i]){
            used[i] = 3;
            dp[i] = three;
        }
        int four = dp[i-4] + skills[i-1] - skills[i-4];
        if (i >= 4 && four < dp[i]){
            used[i] = 4;
            dp[i] = four;
        }
        int five = dp[i-5] + skills[i-1] - skills[i-5];
        if (i >= 5 && five < dp[i]){
            used[i] = 5;
            dp[i] = five;
        }
        // dp[i] = min(dp[i], dp[i-3] + skills[i-1] - skills[i-3]);
        // if (i >= 4)  dp[i] = min(dp[i], dp[i-4] + skills[i-1] - skills[i-4]);
        // if (i >= 5)  dp[i] = min(dp[i], dp[i-5] + skills[i-1] - skills[i-5]);
        // cout << dp[i] << " ";
    }

    int maxDiff = dp[n];

    vector<int> s;

    for (int i = n; i > 0; i-=used[i]){
        s.push_back(used[i]);
    }

    int i = 0, group = 1;
    for (int t = s.size()-1; t >= 0; t--){
        int num = s[t];
        loop(j,0,num){
            dp[i++] = group;
        }
        group++;
    }

    loop(i,0,n){
        set<int>::iterator it = m[skills[i]].begin();
        used[*it] = dp[i];
        m[skills[i]].erase(it);
    }

    cout << maxDiff << " " << group-1 << endl;

    loop(i,0,n)
        cout << used[i] << " ";
    cout << endl;

}


#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <utility>
#include <map>
#include <math.h>
#include <sstream>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <unordered_set>
#include <unordered_map>

using namespace std;

#define loop(iii,l,r) for (int iii = l; iii < r; iii++)
#define tests int T; cin >> T; while(T--)
#define all(c) (c).begin(),(c).end() //handy for function like "sort()"
#define ll long long //data types used often, but you don't want to type them time by time
#define ull unsigned long long
#define ui unsigned int
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); //to desynchronize the input of cin and scanf
#define PI 3.1415926535897932384626
//for map, pair
#define mp make_pair
#define fi first
#define se second
//for vectors
#define pb push_back
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef vector<ii> vii;

// *****************************

unordered_map<int, set<int> > m;

int skills[200005], dp[200005], used[200005];
int INF = 2000000000;

int main(){

    int n;
    cin >> n;
    loop(i,0,n){
        cin >> skills[i];
        m[skills[i]].insert(i);
    }

    loop(i,0,n+1)
        dp[i] = INF;

    sort(skills, skills+n);

    dp[0] = 0;

    loop(i,3,n+1){
        int three = dp[i-3] + skills[i-1] - skills[i-3];
        if (three < dp[i]){
            used[i] = 3;
            dp[i] = three;
        }
        int four = dp[i-4] + skills[i-1] - skills[i-4];
        if (i >= 4 && four < dp[i]){
            used[i] = 4;
            dp[i] = four;
        }
        int five = dp[i-5] + skills[i-1] - skills[i-5];
        if (i >= 5 && five < dp[i]){
            used[i] = 5;
            dp[i] = five;
        }
        // dp[i] = min(dp[i], dp[i-3] + skills[i-1] - skills[i-3]);
        // if (i >= 4)  dp[i] = min(dp[i], dp[i-4] + skills[i-1] - skills[i-4]);
        // if (i >= 5)  dp[i] = min(dp[i], dp[i-5] + skills[i-1] - skills[i-5]);
        // cout << dp[i] << " ";
    }

    int maxDiff = dp[n];

    vector<int> s;

    for (int i = n; i > 0; i-=used[i]){
        s.push_back(used[i]);
    }

    int i = 0, group = 1;
    for (int t = s.size()-1; t >= 0; t--){
        int num = s[t];
        loop(j,0,num){
            dp[i++] = group;
        }
        group++;
    }

    loop(i,0,n){
        set<int>::iterator it = m[skills[i]].begin();
        used[*it] = dp[i];
        m[skills[i]].erase(it);
    }

    cout << maxDiff << " " << group-1 << endl;

    loop(i,0,n)
        cout << used[i] << " ";
    cout << endl;

}


#include<bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define ld long double
#define endl "\n"
#define ld long double
#define ff first
#define ss second
#define pi pair<ll,ll>
#define PI 3.141592653589793238462643383279502884L
#define mp make_pair
#define pb push_back
#define fall(i,a,b) for(int i=a;i<b;i++)
#define sz(x)  (ll)x.size()
#define all(x) x.begin(),x.end()
#define ed cout<<"ed"
ll mod1 = 998244353 ;
ll mod = 1e9 + 7;
const ll N = 2e5+10;
ll n, dp[N],p[N];
pi a[N],ans[N];

void solve(){
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i].ff,a[i].ss=i;
	sort(a,a+n);
    for(int i=1;i<=n+2;i++)dp[i]=1e15,ans[i].ff=a[i].ss;
	dp[0]=0;
	for(int i=0;i<n;i++){
	   for(int j=3;j<=5;j++){
	       if(i+j<=n && dp[i+j]> dp[i]+a[i+j-1].ff-a[i].ff)
	       dp[i+j]=dp[i]+a[i+j-1].ff-a[i].ff,p[i+j]=j;
	   }
	}
	int i=n,c=1,k;
	while(i>0){
	   k=p[i];
	   while(k--)ans[i-1].ss=c,i--;
	   c++;
	}
	sort(ans,ans+n);
	cout<<dp[n]<<" "<<c-1<<endl;
	for(int i=0;i<n;i++)cout<<ans[i].ss<<" ";
}

int main(){
   fio;
   int t=1;
   //cin>>t;
   while(t--){
       solve();
   }
return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define ld long double
#define endl "\n"
#define ld long double
#define ff first
#define ss second
#define pi pair<ll,ll>
#define PI 3.141592653589793238462643383279502884L
#define mp make_pair
#define pb push_back
#define fall(i,a,b) for(int i=a;i<b;i++)
#define sz(x)  (ll)x.size()
#define all(x) x.begin(),x.end()
#define ed cout<<"ed"
ll mod1 = 998244353 ;
ll mod = 1e9 + 7;
const ll N = 2e5+10;
ll n, dp[N],p[N];
pi a[N],ans[N];

void solve(){
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i].ff,a[i].ss=i;
	sort(a,a+n);
    for(int i=0;i<=n+2;i++)dp[i]=1e15,ans[i].ff=a[i].ss;
	dp[0]=0;
	for(int i=0;i<n;i++){
	   for(int j=3;j<=5;j++){
	       if(i+j<=n && dp[i+j]> dp[i]+a[i+j-1].ff-a[i].ff)
	       dp[i+j]=dp[i]+a[i+j-1].ff-a[i].ff,p[i+j]=j;
	   }
	}
	int i=n,c=1,k;
	while(i>0){
	   k=p[i];
	   while(k--)ans[i-1].ss=c,i--;
	   c++;
	}
	sort(ans,ans+n);
	cout<<dp[n]<<" "<<c-1<<endl;
	for(int i=0;i<n;i++)cout<<ans[i].ss<<" ";
}

int main(){
   fio;
   int t=1;
   //cin>>t;
   while(t--){
       solve();
   }
return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define ld long double
#define endl "\n"
#define ld long double
#define ff first
#define ss second
#define pi pair<ll,ll>
#define PI 3.141592653589793238462643383279502884L
#define mp make_pair
#define pb push_back
#define fall(i,a,b) for(int i=a;i<b;i++)
#define sz(x)  (ll)x.size()
#define all(x) x.begin(),x.end()
#define ed cout<<"ed"
ll mod1 = 998244353 ;
ll mod = 1e9 + 7;
const ll N = 1e5+10;
ll n, dp[N],p[N];
pi a[N],ans[N];

void solve(){
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i].ff,a[i].ss=i;
	sort(a,a+n);
    for(int i=1;i<=n+2;i++)dp[i]=1e15,ans[i].ff=a[i].ss;
	dp[0]=0;
	for(int i=0;i<n;i++){
	   for(int j=3;j<=5;j++){
	       if(i+j<=n && dp[i+j]> dp[i]+a[i+j-1].ff-a[i].ff)
	       dp[i+j]=dp[i]+a[i+j-1].ff-a[i].ff,p[i+j]=j;
	   }
	}
	int i=n,c=1,k;
	while(i>0){
	   k=p[i];
	   while(k--)ans[i-1].ss=c,i--;
	   c++;
	}
	sort(ans,ans+n);
	cout<<dp[n]<<" "<<c-1<<endl;
	for(int i=0;i<n;i++)cout<<ans[i].ss<<" ";
}

int main(){
   fio;
   int t=1;
   //cin>>t;
   while(t--){
       solve();
   }
return 0;
}


#include <bits/stdc++.h>
using namespace std;
long long oo = 10000000000000;
long long  dp [ 200001 ] ;
long long n;
long long resp [ 200001 ] ;
vector < pair < long long , long long > > arr;
long long  busquedad ( long long x ){
    if ( x ==  n  ) return 0;
    if ( x > n ) return oo;
    if ( dp [ x ] != -1 ) return dp [ x ] ;
    dp [ x ] = busquedad ( x + 3 ) + arr [ x + 3 - 1 ].first - arr [ x ].first ;
    dp [ x ] = min ( busquedad ( x + 4 ) + arr [ x + 3 ].first - arr [ x ].first , dp [ x ] ) ;
    return dp [ x ] ;
}
long long cont = 1 ;
void record ( long long x ) {
    if ( x == n ) return ;
    if ( ( busquedad ( x + 3 ) + arr [ x + 3 - 1 ].first - arr [ x ].first )  == dp [ x ] ){
        for ( long long i = 0 ; i < 3 ; i++ ) {
            resp [ arr [ x+ i ].second ] = cont ;
        }
        cont++;
        record ( x + 3 ) ;
    }
    else{
        for ( long long i = 0 ; i < 4 ; i++ ) {
            resp [ arr [ x + i  ].second ] = cont ;
        }
        cont++;
        record ( x + 4 );
    }
}
int main ( ){
    memset ( dp , -1 , sizeof ( dp )  );
    cin>>n;
    for ( long long i = 0 ; i < n ; i++ ){
        long long x ;
        cin>>x;
        arr.push_back ( { x , i } ) ;
    }
    sort ( arr.begin ( ) , arr.end ( ) );
    if ( n < 6 ) {
        cout<<arr [ n -1 ].first - arr [ 0 ].first<<" 1"<<endl;
        for ( long long i = 0 ; i < n ; i++ ) cout<<"1"<<" ";
        cout<<endl;
        return 0;
    }
    cout<<busquedad ( 0 )<<" ";
    record ( 0 ) ;
    cout<<cont - 1 <<endl;
    for ( long long i = 0 ; i < n ; i++ ) cout<<resp [ i ]  <<" ";
    cout<<endl;
    return 0 ;
}


#include <bits/stdc++.h>
using namespace std;
long long oo = 1e15;
long long  dp [ 200001 ] ;
int n;
int resp [ 200001 ] ;
vector < pair < int , int > > arr;
long long  busquedad ( int x ){
    if ( x ==  n  ) return 0;
    if ( x > n - 1  ) return oo;
    if ( dp [ x ] != -1 ) return dp [ x ] ;
    dp [ x ] = busquedad ( x + 3 ) + arr [ x + 3 - 1 ].first - arr [ x ].first ;
    dp [ x ] = min ( busquedad ( x + 4 ) + arr [ x + 3 ].first - arr [ x ].first , dp [ x ] ) ;
    return dp [ x ] ;
}
int cont = 1 ;
void record ( int x ) {
    if ( x == n ) return ;
    if ( ( busquedad ( x + 3 ) + arr [ x + 3 - 1 ].first - arr [ x ].first )  == dp [ x ] ){
        for ( int i = 0 ; i < 3 ; i++ ) {
            resp [ arr [ x+ i ].second ] = cont ;
        }
        cont++;
        record ( x + 3 ) ;
    }
    else{
        for ( int i = 0 ; i < 4 ; i++ ) {
            resp [ arr [ x + i  ].second ] = cont ;
        }
        cont++;
        record ( x + 4 );
    }
}
int main ( ){
    memset ( dp , -1 , sizeof ( dp )  );
    cin>>n;
    for ( int i = 0 ; i < n ; i++ ){
        int x ;
        cin>>x;
        arr.push_back ( { x , i } ) ;
    }
    sort ( arr.begin ( ) , arr.end ( ) );
    if ( n < 6 ) {
        cout<<arr [ n -1 ].first - arr [ 0 ].first<<" 1"<<endl;
        for ( int i = 0 ; i < n ; i++ ) cout<<"1"<<" ";
        cout<<endl;
        return 0;
    }
    cout<<busquedad ( 0 )<<" ";
    record ( 0 ) ;
    cout<<cont - 1 <<endl;
    for ( int i = 0 ; i < n ; i++ ) cout<<resp [ i ]  <<" ";
    cout<<endl;
    return 0 ;
}


#include <bits/stdc++.h>
using namespace std;
long long oo = 10000000000000;
long long  dp [ 200001 ] ;
long long n;
long long resp [ 200001 ] ;
vector < pair < long long , long long > > arr;
long long  busquedad ( long long x ){
    if ( x ==  n  ) return 0;
    if ( dp [ x ] != -1 ) return dp [ x ] ;
    if ( x + 3 <= n ) dp [ x ] = busquedad ( x + 3 ) + arr [ x + 3 - 1 ].first - arr [ x ].first ;
    if ( x + 4 <= n ) dp [ x ] = min ( busquedad ( x + 4 ) + arr [ x + 3 ].first - arr [ x ].first , dp [ x ] ) ;
    if ( dp [ x ] == -1 ){
        dp [ x ] = oo ;
    }
    return dp [ x ] ;
}
long long cont = 1 ;
void record ( long long x ) {
    if ( x == n ) return ;
    if ( ( busquedad ( x + 3 ) + arr [ x + 3 - 1 ].first - arr [ x ].first )  == dp [ x ] ){
        for ( long long i = 0 ; i < 3 ; i++ ) {
            resp [ arr [ x+ i ].second ] = cont ;
        }
        cont++;
        record ( x + 3 ) ;
    }
    else{
        for ( long long i = 0 ; i < 4 ; i++ ) {
            resp [ arr [ x + i  ].second ] = cont ;
        }
        cont++;
        record ( x + 4 );
    }
}
int main ( ){
    memset ( dp , -1 , sizeof ( dp )  );
    cin>>n;
    for ( long long i = 0 ; i < n ; i++ ){
        long long x ;
        cin>>x;
        arr.push_back ( { x , i } ) ;
    }
    sort ( arr.begin ( ) , arr.end ( ) );
    if ( n < 6 ) {
        cout<<arr [ n -1 ].first - arr [ 0 ].first<<" 1"<<endl;
        for ( long long i = 0 ; i < n ; i++ ) cout<<"1"<<" ";
        cout<<endl;
        return 0;
    }
    cout<<busquedad ( 0 )<<" ";
    record ( 0 ) ;
    cout<<cont - 1 <<endl;
    for ( long long i = 0 ; i < n ; i++ ) cout<<resp [ i ]  <<" ";
    cout<<endl;
    return 0 ;
}


#include <bits/stdc++.h>
using namespace std;
long long oo = 1e15;
long long  dp [ 200001 ] ;
long long n;
long long resp [ 200001 ] ;
vector < pair < long long , long long > > arr;
long long  busquedad ( long long x ){
    if ( x ==  n  ) return 0;
    if ( x > n - 1  ) return oo;
    if ( dp [ x ] != -1 ) return dp [ x ] ;
    dp [ x ] = busquedad ( x + 3 ) + arr [ x + 3 - 1 ].first - arr [ x ].first ;
    dp [ x ] = min ( busquedad ( x + 4 ) + arr [ x + 3 ].first - arr [ x ].first , dp [ x ] ) ;
    return dp [ x ] ;
}
long long cont = 1 ;
void record ( long long x ) {
    if ( x == n ) return ;
    if ( ( busquedad ( x + 3 ) + arr [ x + 3 - 1 ].first - arr [ x ].first )  == dp [ x ] ){
        for ( long long i = 0 ; i < 3 ; i++ ) {
            resp [ arr [ x+ i ].second ] = cont ;
        }
        cont++;
        record ( x + 3 ) ;
    }
    else{
        for ( long long i = 0 ; i < 4 ; i++ ) {
            resp [ arr [ x + i  ].second ] = cont ;
        }
        cont++;
        record ( x + 4 );
    }
}
int main ( ){
    memset ( dp , -1 , sizeof ( dp )  );
    cin>>n;
    for ( long long i = 0 ; i < n ; i++ ){
        long long x ;
        cin>>x;
        arr.push_back ( { x , i } ) ;
    }
    sort ( arr.begin ( ) , arr.end ( ) );
    if ( n < 6 ) {
        cout<<arr [ n -1 ].first - arr [ 0 ].first<<" 1"<<endl;
        for ( long long i = 0 ; i < n ; i++ ) cout<<"1"<<" ";
        cout<<endl;
        return 0;
    }
    cout<<busquedad ( 0 )<<" ";
    record ( 0 ) ;
    cout<<cont - 1 <<endl;
    for ( long long i = 0 ; i < n ; i++ ) cout<<resp [ i ]  <<" ";
    cout<<endl;
    return 0 ;
}


#include <bits/stdc++.h>
using namespace std;
long long oo = 10000000000000;
long long  dp [ 200001 ] ;
long long n;
long long resp [ 200001 ] ;
vector < pair < long long , long long > > arr;
long long  busquedad ( long long x ){
    if ( x ==  n  ) return 0;
    if ( dp [ x ] != -1 ) return dp [ x ] ;
    if ( x + 3 <= n ) dp [ x ] = busquedad ( x + 3 ) + arr [ x + 3 - 1 ].first - arr [ x ].first ;
    if ( x + 4 <= n ) dp [ x ] = min ( busquedad ( x + 4 ) + arr [ x + 3 ].first - arr [ x ].first , dp [ x ] ) ;
    if ( x + 5 <= n ) dp [ x ] = min ( busquedad ( x + 5 ) + arr [ x + 4 ].first - arr [ x ].first , dp [ x ] ) ;
    if ( dp [ x ] == -1 ){
        dp [ x ] = oo ;
    }
    return dp [ x ] ;
}
long long cont = 1 ;
void record ( long long x ) {
    if ( x == n ) return ;
    if ( ( busquedad ( x + 3 ) + arr [ x + 3 - 1 ].first - arr [ x ].first )  == dp [ x ] ){
        for ( long long i = 0 ; i < 3 ; i++ ) {
            resp [ arr [ x+ i ].second ] = cont ;
        }
        cont++;
        record ( x + 3 ) ;
    }
    else if (  busquedad ( x + 4 ) + arr [ x + 3 ].first - arr [ x ].first == dp [ x ] ) {
        for ( long long i = 0 ; i < 4 ; i++ ) {
            resp [ arr [ x + i  ].second ] = cont ;
        }
        cont++;
        record ( x + 4 );
    }
    else{
        for ( long long i = 0 ; i < 5 ; i++ ) {
            resp [ arr [ x + i  ].second ] = cont ;
        }
        cont++;
        record ( x + 5 );
    }
}
int main ( ){
    memset ( dp , -1 , sizeof ( dp )  );
    cin>>n;
    for ( long long i = 0 ; i < n ; i++ ){
        long long x ;
        cin>>x;
        arr.push_back ( { x , i } ) ;
    }
    sort ( arr.begin ( ) , arr.end ( ) );
    cout<<busquedad ( 0 )<<" ";
    record ( 0 ) ;
    cout<<cont - 1 <<endl;
    for ( long long i = 0 ; i < n ; i++ ) cout<<resp [ i ]  <<" ";
    cout<<endl;
    return 0 ;
}


#include <bits/stdc++.h>
using namespace std;
long long oo = 10000000000000;
long long  dp [ 200001 ] ;
long long n;
long long resp [ 200001 ] ;
vector < pair < long long , long long > > arr;
long long  busquedad ( long long x ){
    if ( x ==  n  ) return 0;
    if ( dp [ x ] != -1 ) return dp [ x ] ;
    if ( x + 3 <= n ) dp [ x ] = busquedad ( x + 3 ) + arr [ x + 3 - 1 ].first - arr [ x ].first ;
    if ( x + 4 <= n ) dp [ x ] = min ( busquedad ( x + 4 ) + arr [ x + 3 ].first - arr [ x ].first , dp [ x ] ) ;
    return dp [ x ] ;
}
long long cont = 1 ;
void record ( long long x ) {
    if ( x == n ) return ;
    if ( ( busquedad ( x + 3 ) + arr [ x + 3 - 1 ].first - arr [ x ].first )  == dp [ x ] ){
        for ( long long i = 0 ; i < 3 ; i++ ) {
            resp [ arr [ x+ i ].second ] = cont ;
        }
        cont++;
        record ( x + 3 ) ;
    }
    else{
        for ( long long i = 0 ; i < 4 ; i++ ) {
            resp [ arr [ x + i  ].second ] = cont ;
        }
        cont++;
        record ( x + 4 );
    }
}
int main ( ){
    memset ( dp , -1 , sizeof ( dp )  );
    cin>>n;
    for ( long long i = 0 ; i < n ; i++ ){
        long long x ;
        cin>>x;
        arr.push_back ( { x , i } ) ;
    }
    sort ( arr.begin ( ) , arr.end ( ) );
    if ( n < 6 ) {
        cout<<arr [ n -1 ].first - arr [ 0 ].first<<" 1"<<endl;
        for ( long long i = 0 ; i < n ; i++ ) cout<<"1"<<" ";
        cout<<endl;
        return 0;
    }
    cout<<busquedad ( 0 )<<" ";
    record ( 0 ) ;
    cout<<cont - 1 <<endl;
    for ( long long i = 0 ; i < n ; i++ ) cout<<resp [ i ]  <<" ";
    cout<<endl;
    return 0 ;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define f first
#define s second

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

bool comp(pair<long long,int> a,pair<long long, int> b){
    return a.f<b.f;
}
int main() {
    cin.sync_with_stdio(0); cin.tie(0);
    cin.exceptions(cin.failbit);

    int n;
    cin>>n;
    vector<pair<ll,int>> a(n);
    rep(i,0,n){cin>>a[i].f;a[i].s=i;}
    sort(all(a),comp);
    vector<ll> c(n,99999999);
    if(n<6){
        cout<<a[n-1].f-a[0].f<<" 1"<<endl;
        rep(i,0,n)cout<<"1 ";
    }else{
        c[0]=0;c[1]=0;c[2]=a[2].f-a[0].f;c[3]=a[3].f-a[0].f;c[4]=a[4].f-a[0].f;
        vector<int> endp(n,-1);
        rep(i,5,n){
            for(int j=i-5;j<=i-3;++j){
                if(c[i]>c[j]+a[i].f-a[j+1].f){
                    c[i]=c[j]+a[i].f-a[j+1].f;
                    endp[i]=j;
                }
            }
        }
        cout<<c[n-1]<<" ";
        vi teams(n);
        int ep=endp[n-1];
        int t=1;
        for(int i=n-1;i>=0;i--){
            if(ep==i){
                ep=endp[ep];
                ++t;
            }
            teams[a[i].s]=t;
        }
        cout<<t<<endl;
        trav(e,teams)cout<<t-e+1<<" ";
    }
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define f first
#define s second

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

bool comp(pair<long long,int> a,pair<long long, int> b){
    return a.f<b.f;
}
int main() {
    cin.sync_with_stdio(0); cin.tie(0);
    cin.exceptions(cin.failbit);

    int n;
    cin>>n;
    vector<pair<ll,int>> a(n);
    rep(i,0,n){cin>>a[i].f;a[i].s=i;}
    sort(all(a),comp);
    vector<ll> c(n,99999999);
    if(n<6){
        cout<<a[n-1].f-a[0].f<<endl;
        rep(i,0,n)cout<<"1 ";
    }else{
        c[0]=0;c[1]=0;c[2]=a[2].f-a[0].f;c[3]=a[3].f-a[0].f;c[4]=a[4].f-a[0].f;
        vector<int> endp(n,-1);
        rep(i,5,n){
            for(int j=i-3;j>=i-5;--j){
                if(c[i]>c[j]+a[i].f-a[j+1].f){
                    c[i]=c[j]+a[i].f-a[j+1].f;
                    endp[i]=j;
                }
            }
        }
        cout<<c[n-1]<<" ";
        vi teams(n);
        int ep=endp[n-1];
        int t=1;
        for(int i=n-1;i>=0;i--){
            if(ep==i){
                ep=endp[ep];
                ++t;
            }
            teams[a[i].s]=t;
        }
        cout<<t<<endl;
        trav(e,teams)cout<<t-e+1<<" ";
    }
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define f first
#define s second

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

bool comp(pair<long long,int> a,pair<long long, int> b){
    return a.f<b.f;
}
ll val(int j,vector<ll>& c){
    if(j>=0)return c[j];
    return 0;
}
int main() {
    cin.sync_with_stdio(0); cin.tie(0);
    cin.exceptions(cin.failbit);

    int n;
    cin>>n;
    vector<pair<ll,int>> a(n);
    rep(i,0,n){cin>>a[i].f;a[i].s=i;}
    sort(all(a),comp);
    vector<ll> c(n,99999999);
    if(n<6){
        cout<<a[n-1].f-a[0].f<<" 1"<<endl;
        rep(i,0,n)cout<<"1 ";
    }else{
        c[0]=0;c[1]=0;c[2]=a[2].f-a[0].f;c[3]=a[3].f-a[0].f;c[4]=a[4].f-a[0].f;
        vector<int> endp(n,-1);
        rep(i,5,n){
            for(int j=i-5;j<=i-3;++j){
                if(c[i]>val(j,c)+a[i].f-a[j+1].f){
                    c[i]=val(j,c)+a[i].f-a[j+1].f;
                    endp[i]=j;
                }
            }
        }
        cout<<c[n-1]<<" ";
        vi teams(n);
        int ep=endp[n-1];
        int t=1;
        for(int i=n-1;i>=0;i--){
            if(ep==i){
                ep=endp[ep];
                ++t;
            }
            teams[a[i].s]=t;
        }
        cout<<t<<endl;
        trav(e,teams)cout<<t-e+1<<" ";
    }
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define f first
#define s second

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

bool comp(pair<long long,int> a,pair<long long, int> b){
    return a.f<b.f;
}
int main() {
    cin.sync_with_stdio(0); cin.tie(0);
    cin.exceptions(cin.failbit);

    int n;
    cin>>n;
    vector<pair<ll,int>> a(n);
    rep(i,0,n){cin>>a[i].f;a[i].s=i;}
    sort(all(a),comp);
    vector<ll> c(n,99999999);
    if(n<6){
        cout<<a[n-1].f-a[0].f<<endl;
        rep(i,0,n)cout<<"1 ";
    }else{
        c[0]=0;c[1]=0;c[2]=a[2].f-a[0].f;c[3]=a[3].f-a[0].f;c[4]=a[4].f-a[0].f;
        vector<int> endp(n,-1);
        rep(i,5,n){
            for(int j=i-3;j>=i-5;--j){
                if(c[i]>c[j]+a[i].f-a[j+1].f){
                    c[i]=c[j]+a[i].f-a[j+1].f;
                    endp[i]=j;
                }
            }
        }
        cout<<c[n-1]<<endl;
        vi teams(n);
        int ep=endp[n-1];
        int t=1;
        for(int i=n-1;i>=0;i--){
            if(ep==i){
                ep=endp[ep];
                ++t;
            }
            teams[a[i].s]=t;
        }
        trav(e,teams)cout<<t-e+1<<" ";
    }
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define f first
#define s second

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

bool comp(pair<long long,int> a,pair<long long, int> b){
    return a.f<b.f;
}
/*ll val(int j,vector<ll>& c){
    if(j>=0)return c[j];
    return 0;
}*/
int main() {
    cin.sync_with_stdio(0); cin.tie(0);
    cin.exceptions(cin.failbit);

    int n;
    cin>>n;
    vector<pair<ll,int>> a(n);
    rep(i,0,n){cin>>a[i].f;a[i].s=i;}
    sort(all(a),comp);
    vector<ll> c(n,223372036854775);
    if(n<6){
        cout<<a[n-1].f-a[0].f<<" 1"<<endl;
        rep(i,0,n)cout<<"1 ";
    }else{
        c[0]=223372036854775;c[1]=223372036854775;c[2]=a[2].f-a[0].f;c[3]=a[3].f-a[0].f;c[4]=a[4].f-a[0].f;
        vector<int> endp(n,-1);
        rep(i,5,n){
            for(int j=i-5;j<=i-3;++j){
                if(c[i]>c[j]+a[i].f-a[j+1].f){
                    c[i]=c[j]+a[i].f-a[j+1].f;
                    endp[i]=j;
                }
            }
        }
        cout<<c[n-1]<<" ";
        vi teams(n);
        int ep=endp[n-1];
        int t=1;
        for(int i=n-1;i>=0;i--){
            if(ep==i){
                ep=endp[ep];
                ++t;
            }
            teams[a[i].s]=t;
        }
        cout<<t<<endl;
        trav(e,teams)cout<<t-e+1<<" ";
    }
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define f first
#define s second

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

bool comp(pair<long long,int> a,pair<long long, int> b){
    return a.f<b.f;
}

ll val(int j,vector<ll>& c){
    if(j>=0)return c[j];
    return 0;
}
int main() {
    cin.sync_with_stdio(0); cin.tie(0);
    cin.exceptions(cin.failbit);

    int n;
    cin>>n;
    vector<pair<ll,int>> a(n);
    rep(i,0,n){cin>>a[i].f;a[i].s=i;}
    sort(all(a),comp);
    vector<ll> c(n,99999999);
    if(n<6){
        cout<<a[n-1].f-a[0].f<<endl;
        rep(i,0,n)cout<<"1 ";
    }else{
        c[0]=99999999;c[1]=99999999 ;c[2]=a[2].f-a[0].f;c[3]=a[3].f-a[0].f;c[4]=a[4].f-a[0].f;
        vector<int> endp(n,-1);
        rep(i,5,n){
            for(int j=i-3;j>=i-5;--j){
                if(c[i]>val(j,c)+a[i].f-a[j+1].f){
                    c[i]=val(j,c)+a[i].f-a[j+1].f;
                    endp[i]=j;
                }
            }
        }
        cout<<c[n-1]<<" ";
        vi teams(n);
        int ep=endp[n-1];
        int t=1;
        for(int i=n-1;i>=0;i--){
            if(ep==i){
                ep=endp[ep];
                ++t;
            }
            teams[a[i].s]=t;
        }
        cout<<t<<endl;
        trav(e,teams)cout<<t-e+1<<" ";
    }
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define f first
#define s second

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

bool comp(pair<long long,int> a,pair<long long, int> b){
    return a.f<b.f;
}
int main() {
    cin.sync_with_stdio(0); cin.tie(0);
    cin.exceptions(cin.failbit);

    int n;
    cin>>n;
    vector<pair<ll,int>> a(n);
    rep(i,0,n){cin>>a[i].f;a[i].s=i;}
    sort(all(a),comp);
    vector<ll> c(n,99999999);
    if(n<6){
        cout<<a[n-1].f-a[0].f<<" 1"<<endl;
        rep(i,0,n)cout<<"1 ";
    }else{
        c[0]=0;c[1]=0;c[2]=a[2].f-a[0].f;c[3]=a[3].f-a[0].f;c[4]=a[4].f-a[0].f;
        vector<int> endp(n,-1);
        rep(i,5,n){
            for(int j=i-3;j>=i-5;--j){
                if(c[i]>c[j]+a[i].f-a[j+1].f){
                    c[i]=c[j]+a[i].f-a[j+1].f;
                    endp[i]=j;
                }
            }
        }
        cout<<c[n-1]<<" ";
        vi teams(n);
        int ep=endp[n-1];
        int t=1;
        for(int i=n-1;i>=0;i--){
            if(ep==i){
                ep=endp[ep];
                ++t;
            }
            teams[a[i].s]=t;
        }
        cout<<t<<endl;
        trav(e,teams)cout<<t-e+1<<" ";
    }
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define f first
#define s second

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

bool comp(pair<long long,int> a,pair<long long, int> b){
    return a.f<b.f;
}
ll val(int j,vector<ll>& c){
    if(j>=0)return c[j];
    return 0;
}
int main() {
    cin.sync_with_stdio(0); cin.tie(0);
    cin.exceptions(cin.failbit);

    int n;
    cin>>n;
    vector<pair<ll,int>> a(n);
    rep(i,0,n){cin>>a[i].f;a[i].s=i;}
    sort(all(a),comp);
    vector<ll> c(n,99999999);
    if(n<6){
        cout<<a[n-1].f-a[0].f<<" 1"<<endl;
        rep(i,0,n)cout<<"1 ";
    }else{
        c[0]=9999999;c[1]=9999999;c[2]=a[2].f-a[0].f;c[3]=a[3].f-a[0].f;c[4]=a[4].f-a[0].f;
        vector<int> endp(n,-1);
        rep(i,5,n){
            for(int j=i-5;j<=i-3;++j){
                if(c[i]>c[j]+a[i].f-a[j+1].f){
                    c[i]=c[j]+a[i].f-a[j+1].f;
                    endp[i]=j;
                }
            }
        }
        cout<<c[n-1]<<" ";
        vi teams(n);
        int ep=endp[n-1];
        int t=1;
        for(int i=n-1;i>=0;i--){
            if(ep==i){
                ep=endp[ep];
                ++t;
            }
            teams[a[i].s]=t;
        }
        cout<<t<<endl;
        trav(e,teams)cout<<t-e+1<<" ";
    }
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<ll,int> P;

int n ;
P a[200050];
ll dp[5][200050];
int res[200050];
int ans[200050];

int main()
{
    cin >> n;

    for(int i =1 ;i <= n;i++){
        scanf("%lld",&a[i].first);
        a[i].second = i;
    }
    sort(a+1,a+n+1);

   dp[2][1] = dp[3][1] = -1e18;
    for(int i = 2 ; i <= n;i++){
        dp[2][i] = dp[1][i-1];
        dp[3][i] = max(dp[2][i-1] , dp[3][i-1]);

        dp[1][i] = dp[3][i-1] + (a[i].first - a[i-1].first);
    }

    int id = 1;
    int cnt = 3;
    ll now = dp[3][n];
    for(int i = n - 2; i ; i--){
        if(cnt >= 3 && now == dp[1][i]){
            res[i] = id++;
            now -= a[i].first - a[i-1].first;
            cnt = 1;
        }
        else cnt ++;
    }

    cout << a[n].first - a[1].first - dp[3][n] <<" "<< id - 1<< "\n";
    for(int i =1 ; i<=n;i++){
        if(!res[i]){
            res[i] = res[i-1];
        }
        ans[a[i].second] = res[i];
    }

    for(int i =1 ;i <= n;i++){
        printf("%d ",ans[i]);
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<ll,int> P;

int n ;
P a[200050];
ll dp[5][200050];
int res[200050];
int ans[200050];

int main()
{
    cin >> n;

    for(int i =1 ;i <= n;i++){
        scanf("%lld",&a[i].first);
        a[i].second = i;
    }
    sort(a+1,a+n+1);

   dp[2][1] = dp[3][1] = -1e18;
    for(int i = 2 ; i <= n;i++){
        dp[2][i] = dp[1][i-1];
        dp[3][i] = max(dp[2][i-1] , dp[3][i-1]);

        dp[1][i] = dp[3][i-1] + (a[i].first - a[i-1].first);
    }

    int id = 1;
    ll now = dp[3][n];
    for(int i = n - 2; i ; i--){
        if(now == dp[1][i]){
            res[i] = id++;
            now -= a[i].first - a[i-1].first;
        }
    }

    cout << a[n].first - a[1].first - dp[3][n] <<" "<< id - 1<< "\n";
    for(int i =1 ; i<=n;i++){
        if(!res[i]){
            res[i] = res[i-1];
        }
        ans[a[i].second] = res[i];
    }

    for(int i =1 ;i <= n;i++){
        printf("%d ",ans[i]);
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<ll,int> P;

int n ;
P a[200050];
ll dp[5][200050];
int res[200050];
int ans[200050];

int main()
{
    cin >> n;

    for(int i =1 ;i <= n;i++){
        scanf("%d",&a[i].first);
        a[i].second = i;
    }
    sort(a+1,a+n+1);

   dp[2][1] = dp[3][1] = -1e18;
    for(int i = 2 ; i <= n;i++){
        dp[2][i] = max(dp[1][i-1] , dp[2][i-1]);
        dp[3][i] = dp[2][i-1];

        dp[1][i] = dp[3][i-1] + (a[i].first - a[i-1].first);
    }

    int id = 1;
    int now = dp[3][n];
    for(int i = n - 1; i ; i--){
        if(now == dp[1][i]){
            res[i] = id++;
            now -= a[i].first - a[i-1].first;
        }
    }

    cout << a[n].first - a[1].first - dp[3][n] <<" "<< id - 1<< "\n";
    for(int i =1 ; i<=n;i++){
        if(!res[i]){
            res[i] = res[i-1];
        }
        ans[a[i].second] = res[i];
    }

    for(int i =1 ;i <= n;i++){
        printf("%d ",ans[i]);
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<ll,int> P;

int n ;
P a[200050];
ll dp[5][200050];
int res[200050];
int ans[200050];

int main()
{
    cin >> n;

    for(int i =1 ;i <= n;i++){
        scanf("%lld",&a[i].first);
        a[i].second = i;
    }
    sort(a+1,a+n+1);

   dp[2][1] = dp[3][1] = -1e18;
    for(int i = 2 ; i <= n;i++){
        dp[2][i] = max(dp[1][i-1] , dp[2][i-1]);
        dp[3][i] = dp[2][i-1];

        dp[1][i] = dp[3][i-1] + (a[i].first - a[i-1].first);
    }

    int id = 1;
    ll now = dp[3][n];
    for(int i = n - 1; i ; i--){
        if(now == dp[1][i]){
            res[i] = id++;
            now -= a[i].first - a[i-1].first;
        }
    }

    cout << a[n].first - a[1].first - dp[3][n] <<" "<< id - 1<< "\n";
    for(int i =1 ; i<=n;i++){
        if(!res[i]){
            res[i] = res[i-1];
        }
        ans[a[i].second] = res[i];
    }

    for(int i =1 ;i <= n;i++){
        printf("%d ",ans[i]);
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<ll,int> P;

int n ;
P a[200050];
ll dp[5][200050];
int res[200050];
int ans[200050];

int main()
{
    cin >> n;

    for(int i =1 ;i <= n;i++){
        scanf("%lld",&a[i].first);
        a[i].second = i;
    }
    sort(a+1,a+n+1);

   dp[2][1] = dp[3][1] = -1e18;
    for(int i = 2 ; i <= n;i++){
        dp[2][i] = dp[1][i-1];
        dp[3][i] = max(dp[2][i-1] , dp[3][i-1]);

        dp[1][i] = dp[3][i-1] + (a[i].first - a[i-1].first);
    }

    int id = 1;
    ll now = dp[3][n];
    for(int i = n - 1; i ; i--){
        if(now == dp[1][i]){
            res[i] = id++;
            now -= a[i].first - a[i-1].first;
        }
    }

    cout << a[n].first - a[1].first - dp[3][n] <<" "<< id - 1<< "\n";
    for(int i =1 ; i<=n;i++){
        if(!res[i]){
            res[i] = res[i-1];
        }
        ans[a[i].second] = res[i];
    }

    for(int i =1 ;i <= n;i++){
        printf("%d ",ans[i]);
    }

    return 0;
}


#include<bits/stdc++.h>

#define X first
#define Y second
#define eb push_back
#define siz(a) int(a.size())
#define endl "\n"

#define trace2(x, y)             cerr <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)          cerr <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cerr <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cerr <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;

using namespace std;

typedef long long int ll;
typedef vector < int > vi;
typedef vector < ll > vll;

const int mod=1e9+7;
const int maxn=1e6+5;

/*	finding inverse upto n
 * for i in xrange(2, N):
    ifc[i] = -(mod / i) * ifc[mod % i] % mod
 *
*/
ll power(ll base, ll exp, ll mod){ll res = 1; while(exp){if(exp%2)res*=base;base*=base;res%=mod;base%=mod;exp/=2;}return res;}

ll n, arr[maxn], dp[maxn], val[maxn];

ll go(ll idx){
	if(idx == n+1){
		return 0;
	}
	if(idx + 2 > n){
		return maxn;
	}

	ll &ret = dp[idx];

	if(ret != -1){
		return ret;
	}
	ret = 100ll*mod;
	ll save = 0;
	for(int i = idx+2; i<=n && i < idx+10; i++){
		ll curr = go(i+1) + arr[i]-arr[idx];

		if(curr < ret){
			ret = curr;
			save = i;
		}
	}
	val[idx] = save;
	return ret;
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
	cin >> n;
	memset(dp, -1, sizeof(dp));
	vector<pair<ll, ll> > v;
	for(int i = 1; i<=n; i++){
		cin >> arr[i];
		v.eb({arr[i], i});
	}
	sort(arr+1, arr+n+1);
	sort(v.begin(), v.end());
	cout << go(1) << " ";
	int cnt = 0;
	memset(dp, 0, sizeof(dp));
	for(int i = 1; i<=n; i=val[i]+1){
		cnt++;
		for(int j = i; j<=val[i]; j++){
			// trace3(j, v[j].X, v[j].Y);
			dp[v[j-1].Y] = cnt;
		}
	}

	cout << cnt << endl;
	for(int i = 1; i<=n; i++)
		cout << dp[i] << " ";

	return 0;
}


#include<bits/stdc++.h>

#define X first
#define Y second
#define eb push_back
#define siz(a) int(a.size())
#define endl "\n"

#define trace2(x, y)             cerr <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)          cerr <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cerr <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cerr <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;

using namespace std;

typedef long long int ll;
typedef vector < int > vi;
typedef vector < ll > vll;

const int mod=1e9+7;
const int maxn=1e6+5;

/*	finding inverse upto n
 * for i in xrange(2, N):
    ifc[i] = -(mod / i) * ifc[mod % i] % mod
 *
*/
ll power(ll base, ll exp, ll mod){ll res = 1; while(exp){if(exp%2)res*=base;base*=base;res%=mod;base%=mod;exp/=2;}return res;}

ll n, arr[maxn], dp[maxn], val[maxn];

ll go(ll idx){
	// trace2(idx, "shit");
	if(idx == n+1){
		return 0;
	}
	if(idx + 2 > n){
		return mod;
	}

	ll &ret = dp[idx];

	if(ret != -1){
		return ret;
	}
	ret = mod;
	ll save = 0;
	for(int i = idx+2; i<=n && i < idx+10; i++){
		ll curr = go(i+1) + arr[i]-arr[idx];

		if(curr < ret){
			ret = curr;
			save = i;
		}
	}
	val[idx] = save;
	return ret;
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
	cin >> n;
	memset(dp, -1, sizeof(dp));
	vector<pair<ll, ll> > v;
	for(int i = 1; i<=n; i++){
		cin >> arr[i];
		v.eb({arr[i], i});
	}
	sort(arr+1, arr+n+1);
	sort(v.begin(), v.end());
	cout << go(1) << " ";
	int cnt = 0;
	// for(int i = 1; i<=n; i++)
	// 	trace2(i, val[i]);
	memset(dp, 0, sizeof(dp));
	for(int i = 1; i<=n; i=val[i]+1){
		cnt++;
		// trace2(i, val[i])
		assert(val[i] >= i+2);
		for(int j = i; j<=val[i]; j++){
			// trace3(j, v[j].X, v[j].Y);
			dp[v[j-1].Y] = cnt;
		}
	}

	cout << cnt << endl;
	for(int i = 1; i<=n; i++)
		cout << dp[i] << " ";

	return 0;
}


#include<bits/stdc++.h>

#define X first
#define Y second
#define eb push_back
#define siz(a) int(a.size())
#define endl "\n"

#define trace2(x, y)             cerr <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)          cerr <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cerr <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cerr <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;

using namespace std;

typedef long long int ll;
typedef vector < int > vi;
typedef vector < ll > vll;

const int mod=1e9+7;
const int maxn=1e6+5;

/*	finding inverse upto n
 * for i in xrange(2, N):
    ifc[i] = -(mod / i) * ifc[mod % i] % mod
 *
*/
ll power(ll base, ll exp, ll mod){ll res = 1; while(exp){if(exp%2)res*=base;base*=base;res%=mod;base%=mod;exp/=2;}return res;}

ll n, arr[maxn], dp[maxn], val[maxn];

ll go(ll idx){
	// trace2(idx, "shit");
	if(idx == n+1){
		return 0;
	}
	if(idx + 2 > n){
		return 100ll*mod;
	}

	ll &ret = dp[idx];

	if(ret != -1){
		return ret;
	}
	ret = 100ll*mod;
	ll save = 0;
	for(int i = idx+2; i<=n && i < idx+9; i++){
		ll curr = go(i+1) + arr[i]-arr[idx];

		if(curr < ret){
			ret = curr;
			save = i;
		}
	}
	val[idx] = save;
	return ret;
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
	cin >> n;
	memset(dp, -1, sizeof(dp));
	vector<pair<ll, ll> > v;
	for(int i = 1; i<=n; i++){
		cin >> arr[i];
		v.eb({arr[i], i});
	}
	sort(arr+1, arr+n+1);
	sort(v.begin(), v.end());
	cout << go(1) << " ";
	int cnt = 0;
	// for(int i = 1; i<=n; i++)
	// 	trace2(i, val[i]);
	memset(dp, 0, sizeof(dp));
	for(int i = 1; i<=n; i=val[i]+1){
		cnt++;
		// trace2(i, val[i])
		assert(val[i] >= i+2);
		for(int j = i; j<=val[i]; j++){
			// trace3(j, v[j].X, v[j].Y);
			dp[v[j-1].Y] = cnt;
		}
	}

	cout << cnt << endl;
	for(int i = 1; i<=n; i++)
		cout << dp[i] << " ";

	return 0;
}


#include<bits/stdc++.h>

#define X first
#define Y second
#define eb push_back
#define siz(a) int(a.size())
#define endl "\n"

#define trace2(x, y)             cerr <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)          cerr <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cerr <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cerr <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;

using namespace std;

typedef long long int ll;
typedef vector < int > vi;
typedef vector < ll > vll;

const int mod=1e9+7;
const int maxn=1e6+5;

/*	finding inverse upto n
 * for i in xrange(2, N):
    ifc[i] = -(mod / i) * ifc[mod % i] % mod
 *
*/
ll power(ll base, ll exp, ll mod){ll res = 1; while(exp){if(exp%2)res*=base;base*=base;res%=mod;base%=mod;exp/=2;}return res;}

ll n, arr[maxn], dp[maxn], val[maxn];

ll go(ll idx){
	// trace2(idx, "shit");
	if(idx == n+1){
		return 0;
	}
	if(idx + 2 > n){
		return 100ll*mod;
	}

	ll &ret = dp[idx];

	if(ret != -1){
		return ret;
	}
	ret = 100ll*mod;
	ll save = 0;
	for(int i = idx+2; i<=n && i < idx+10; i++){
		ll curr = go(i+1) + arr[i]-arr[idx];

		if(curr < ret){
			ret = curr;
			save = i;
		}
	}
	val[idx] = save;
	return ret;
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
	cin >> n;
	memset(dp, -1, sizeof(dp));
	vector<pair<ll, ll> > v;
	for(int i = 1; i<=n; i++){
		cin >> arr[i];
		v.eb({arr[i], i});
	}
	sort(arr+1, arr+n+1);
	sort(v.begin(), v.end());
	cout << go(1) << " ";
	int cnt = 0;
	// for(int i = 1; i<=n; i++)
	// 	trace2(i, val[i]);
	memset(dp, 0, sizeof(dp));
	for(int i = 1; i<=n; i=val[i]+1){
		cnt++;
		// trace2(i, val[i])
		//assert(val[i] >= i+2);
		for(int j = i; j<=val[i]; j++){
			// trace3(j, v[j].X, v[j].Y);
			dp[v[j-1].Y] = cnt;
		}
	}

	cout << cnt << endl;
	for(int i = 1; i<=n; i++)
		cout << dp[i] << " ";

	return 0;
}


#include<bits/stdc++.h>

#define X first
#define Y second
#define eb push_back
#define siz(a) int(a.size())
#define endl "\n"

#define trace2(x, y)             cerr <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)          cerr <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cerr <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cerr <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;

using namespace std;

typedef long long int ll;
typedef vector < int > vi;
typedef vector < ll > vll;

const int mod=1e9+7;
const int maxn=1e6+5;

/*	finding inverse upto n
 * for i in xrange(2, N):
    ifc[i] = -(mod / i) * ifc[mod % i] % mod
 *
*/
ll power(ll base, ll exp, ll mod){ll res = 1; while(exp){if(exp%2)res*=base;base*=base;res%=mod;base%=mod;exp/=2;}return res;}

ll n, arr[maxn], dp[maxn], val[maxn];

ll go(ll idx){
	if(idx == n+1){
		return 0;
	}
	if(idx + 2 > n){
		return maxn;
	}

	ll &ret = dp[idx];

	if(ret != -1){
		return ret;
	}
	ret = 100ll*mod;
	ll save = 0;
	for(int i = idx+2; i<=n && i < idx+100; i++){
		ll curr = go(i+1) + arr[i]-arr[idx];

		if(curr < ret){
			ret = curr;
			save = i;
		}
	}
	val[idx] = save;
	return ret;
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
	cin >> n;
	memset(dp, -1, sizeof(dp));
	vector<pair<ll, ll> > v;
	for(int i = 1; i<=n; i++){
		cin >> arr[i];
		v.eb({arr[i], i});
	}
	sort(arr+1, arr+n+1);
	sort(v.begin(), v.end());
	cout << go(1) << " ";
	int cnt = 0;
	memset(dp, 0, sizeof(dp));
	for(int i = 1; i<=n; i=val[i]+1){
		cnt++;
		for(int j = i; j<=val[i]; j++){
			// trace3(j, v[j].X, v[j].Y);
			dp[v[j-1].Y] = cnt;
		}
	}

	cout << cnt << endl;
	for(int i = 1; i<=n; i++)
		cout << dp[i] << " ";

	return 0;
}


#include<bits/stdc++.h>

#define X first
#define Y second
#define eb push_back
#define siz(a) int(a.size())
#define endl "\n"

#define trace2(x, y)             cerr <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)          cerr <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cerr <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cerr <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;

using namespace std;

typedef long long int ll;
typedef vector < int > vi;
typedef vector < ll > vll;

const int mod=1e9+7;
const int maxn=1e6+5;

/*	finding inverse upto n
 * for i in xrange(2, N):
    ifc[i] = -(mod / i) * ifc[mod % i] % mod
 *
*/
ll power(ll base, ll exp, ll mod){ll res = 1; while(exp){if(exp%2)res*=base;base*=base;res%=mod;base%=mod;exp/=2;}return res;}

ll n, arr[maxn], dp[maxn], val[maxn];

ll go(ll idx){
	// trace2(idx, "shit");
	if(idx == n+1){
		return 0;
	}
	if(idx + 2 > n){
		return 100ll*mod;
	}

	ll &ret = dp[idx];

	if(ret != -1){
		return ret;
	}
	ret = 100ll*mod;
	ll save = 0;
	for(int i = idx+2; i<=n && i < idx+4; i++){
		ll curr = go(i+1) + arr[i]-arr[idx];

		if(curr < ret){
			ret = curr;
			save = i;
		}
	}
	val[idx] = save;
	return ret;
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
	cin >> n;
	memset(dp, -1, sizeof(dp));
	vector<pair<ll, ll> > v;
	for(int i = 1; i<=n; i++){
		cin >> arr[i];
		v.eb({arr[i], i});
	}
	sort(arr+1, arr+n+1);
	sort(v.begin(), v.end());
	cout << go(1) << " ";
	int cnt = 0;
	// for(int i = 1; i<=n; i++)
	// 	trace2(i, val[i]);
	memset(dp, 0, sizeof(dp));
	for(int i = 1; i<=n; i=val[i]+1){
		cnt++;
		// trace2(i, val[i])
		//assert(val[i] >= i+2);
		for(int j = i; j<=val[i]; j++){
			// trace3(j, v[j].X, v[j].Y);
			dp[v[j-1].Y] = cnt;
		}
	}

	cout << cnt << endl;
	for(int i = 1; i<=n; i++)
		cout << dp[i] << " ";

	return 0;
}


#include<bits/stdc++.h>

#define X first
#define Y second
#define eb push_back
#define siz(a) int(a.size())
#define endl "\n"

#define trace2(x, y)             cerr <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)          cerr <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cerr <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cerr <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;

using namespace std;

typedef long long int ll;
typedef vector < int > vi;
typedef vector < ll > vll;

const int mod=1e9+7;
const int maxn=1e6+5;

/*	finding inverse upto n
 * for i in xrange(2, N):
    ifc[i] = -(mod / i) * ifc[mod % i] % mod
 *
*/
ll power(ll base, ll exp, ll mod){ll res = 1; while(exp){if(exp%2)res*=base;base*=base;res%=mod;base%=mod;exp/=2;}return res;}

ll n, arr[maxn], dp[maxn], val[maxn];

ll go(ll idx){
	// trace2(idx, "shit");
	if(idx == n+1){
		return 0;
	}
	if(idx + 2 > n){
		return mod;
	}

	ll &ret = dp[idx];

	if(ret != -1){
		return ret;
	}
	ret = mod;
	ll save = 0;
	for(int i = idx+2; i<=n && i < idx+10; i++){
		ll curr = go(i+1) + arr[i]-arr[idx];

		if(curr < ret){
			ret = curr;
			save = i;
		}
	}
	val[idx] = save;
	return ret;
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
	cin >> n;
	memset(dp, -1, sizeof(dp));
	vector<pair<ll, ll> > v;
	for(int i = 1; i<=n; i++){
		cin >> arr[i];
		v.eb({arr[i], i});
	}
	sort(arr+1, arr+n+1);
	sort(v.begin(), v.end());
	cout << go(1) << " ";
	int cnt = 0;
	// for(int i = 1; i<=n; i++)
	// 	trace2(i, val[i]);
	memset(dp, 0, sizeof(dp));
	for(int i = 1; i<=n; i=val[i]+1){
		cnt++;
		// trace2(i, val[i])
		//assert(val[i] >= i+2);
		for(int j = i; j<=val[i]; j++){
			// trace3(j, v[j].X, v[j].Y);
			dp[v[j-1].Y] = cnt;
		}
	}

	cout << cnt << endl;
	for(int i = 1; i<=n; i++)
		cout << dp[i] << " ";

	return 0;
}


#include<bits/stdc++.h>

#define X first
#define Y second
#define eb push_back
#define siz(a) int(a.size())
#define endl "\n"

#define trace2(x, y)             cerr <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)          cerr <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cerr <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cerr <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;

using namespace std;

typedef long long int ll;
typedef vector < int > vi;
typedef vector < ll > vll;

const int mod=1e9+7;
const int maxn=1e6+5;

/*	finding inverse upto n
 * for i in xrange(2, N):
    ifc[i] = -(mod / i) * ifc[mod % i] % mod
 *
*/
ll power(ll base, ll exp, ll mod){ll res = 1; while(exp){if(exp%2)res*=base;base*=base;res%=mod;base%=mod;exp/=2;}return res;}

ll n, arr[maxn], dp[maxn], val[maxn];

ll go(ll idx){
	// trace2(idx, "shit");
	if(idx == n+1){
		return 0;
	}
	if(idx + 2 > n){
		return 100ll*mod;
	}

	ll &ret = dp[idx];

	if(ret != -1){
		return ret;
	}
	ret = 100ll*mod;
	ll save = 0;
	for(int i = idx+2; i<=n && i < idx+4; i++){
		ll curr = go(i+1) + arr[i]-arr[idx];

		if(curr < ret){
			ret = curr;
			save = i;
		}
	}
	val[idx] = save;
	return ret;
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
	cin >> n;
	memset(dp, -1, sizeof(dp));
	vector<pair<ll, ll> > v;
	for(int i = 1; i<=n; i++){
		cin >> arr[i];
		v.eb({arr[i], i});
	}
	sort(arr+1, arr+n+1);
	sort(v.begin(), v.end());
	cout << go(1) << " ";
	int cnt = 0;
	// for(int i = 1; i<=n; i++)
	// 	trace2(i, val[i]);
	memset(dp, 0, sizeof(dp));
	for(int i = 1; i<=n; i=val[i]+1){
		cnt++;
		// trace2(i, val[i])
		assert(val[i] >= i+2);
		for(int j = i; j<=val[i]; j++){
			// trace3(j, v[j].X, v[j].Y);
			dp[v[j-1].Y] = cnt;
		}
	}

	cout << cnt << endl;
	for(int i = 1; i<=n; i++)
		cout << dp[i] << " ";

	return 0;
}


#include<bits/stdc++.h>

#define X first
#define Y second
#define eb push_back
#define siz(a) int(a.size())
#define endl "\n"

#define trace2(x, y)             cerr <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)          cerr <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cerr <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cerr <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;

using namespace std;

typedef long long int ll;
typedef vector < int > vi;
typedef vector < ll > vll;

const int mod=1e9+7;
const int maxn=1e6+5;

/*	finding inverse upto n
 * for i in xrange(2, N):
    ifc[i] = -(mod / i) * ifc[mod % i] % mod
 *
*/
ll power(ll base, ll exp, ll mod){ll res = 1; while(exp){if(exp%2)res*=base;base*=base;res%=mod;base%=mod;exp/=2;}return res;}

ll n, arr[maxn], dp[maxn], val[maxn];

ll go(ll idx){
	// trace2(idx, "shit");
	if(idx == n+1){
		return 0;
	}
	if(idx + 2 > n){
		return maxn;
	}

	ll &ret = dp[idx];

	if(ret != -1){
		return ret;
	}
	ret = mod;
	ll save = 0;
	for(int i = idx+2; i<=n && i < idx+5; i++){
		ll curr = go(i+1) + arr[i]-arr[idx];

		if(curr < ret){
			ret = curr;
			save = i;
		}
	}
	val[idx] = save;
	return ret;
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
	cin >> n;
	memset(dp, -1, sizeof(dp));
	vector<pair<ll, ll> > v;
	for(int i = 1; i<=n; i++){
		cin >> arr[i];
		v.eb({arr[i], i});
	}
	sort(arr+1, arr+n+1);
	sort(v.begin(), v.end());
	cout << go(1) << " ";
	int cnt = 0;
	// for(int i = 1; i<=n; i++)
	// 	trace2(i, val[i]);
	memset(dp, 0, sizeof(dp));
	for(int i = 1; i<=n; i=val[i]+1){
		cnt++;
		// trace2(i, val[i])
		assert(val[i] >= i+2);
		for(int j = i; j<=val[i]; j++){
			// trace3(j, v[j].X, v[j].Y);
			dp[v[j-1].Y] = cnt;
		}
	}

	cout << cnt << endl;
	for(int i = 1; i<=n; i++)
		cout << dp[i] << " ";

	return 0;
}


#include<bits/stdc++.h>

#define X first
#define Y second
#define eb push_back
#define siz(a) int(a.size())
#define endl "\n"

#define trace2(x, y)             cerr <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)          cerr <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cerr <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cerr <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;

using namespace std;

typedef long long int ll;
typedef vector < int > vi;
typedef vector < ll > vll;

const int mod=1e9+7;
const int maxn=1e6+5;

/*	finding inverse upto n
 * for i in xrange(2, N):
    ifc[i] = -(mod / i) * ifc[mod % i] % mod
 *
*/
ll power(ll base, ll exp, ll mod){ll res = 1; while(exp){if(exp%2)res*=base;base*=base;res%=mod;base%=mod;exp/=2;}return res;}

ll n, arr[maxn], dp[maxn], val[maxn];

ll go(ll idx){
	// trace2(idx, "shit");
	if(idx == n+1){
		return 0;
	}
	if(idx + 2 > n){
		return 100ll*mod;
	}

	ll &ret = dp[idx];

	if(ret != -1){
		return ret;
	}
	ret = 100ll*mod;
	ll save = 0;
	for(int i = idx+2; i<=n && i < idx+5; i++){
		ll curr = go(i+1) + arr[i]-arr[idx];

		if(curr < ret){
			ret = curr;
			save = i;
		}
	}
	val[idx] = save;
	return ret;
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
	cin >> n;
	memset(dp, -1, sizeof(dp));
	vector<pair<ll, ll> > v;
	for(int i = 1; i<=n; i++){
		cin >> arr[i];
		v.eb({arr[i], i});
	}
	sort(arr+1, arr+n+1);
	sort(v.begin(), v.end());
	cout << go(1) << " ";
	int cnt = 0;
	// for(int i = 1; i<=n; i++)
	// 	trace2(i, val[i]);
	memset(dp, 0, sizeof(dp));
	for(int i = 1; i<=n; i=val[i]+1){
		cnt++;
		// trace2(i, val[i])
		assert(val[i] >= i+2);
		for(int j = i; j<=val[i]; j++){
			// trace3(j, v[j].X, v[j].Y);
			dp[v[j-1].Y] = cnt;
		}
	}

	cout << cnt << endl;
	for(int i = 1; i<=n; i++)
		cout << dp[i] << " ";

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 1e5 + 10;
const long long INF = (long long)1e17 + 10;

int n, m, s, t;
int a[N], b[N], l[N];
struct edge {
  int to, cost;
  edge(int to, int cost) : to(to), cost(cost) {}
};
vector<edge> e;
vector<int> g[N];
vector<int> g2[N];
long long diss[N], dist[N];
int cnt[N], idx[N];
long long len;
bool vis[N], fl[N], ans[N];

void dijkstra(int sc, vector<int> g[N], long long *dis) {
  fill(dis + 1, dis + n + 1, INF);
  priority_queue<pair<long long, int> > pq;
  pq.push(make_pair(0, sc));
  memset(vis, 0, sizeof(vis));
  while (!pq.empty()) {
    pair<long long, int> tmp = pq.top();
    pq.pop();
    if (vis[tmp.second]) continue;
    vis[tmp.second] = 1;
    dis[tmp.second] = -tmp.first;
    for (auto j : g[tmp.second]) {
      int u = e[j].to;
      int c = e[j].cost;
      if (vis[u]) continue;
      pair<long long, int> nxt = make_pair(-dis[tmp.second] - c, u);
      pq.push(nxt);
    }
  }
}

int cmp(int a, int b) {
  return diss[a] < diss[b];
}

int main() {
  scanf("%d%d%d%d", &n, &m, &s, &t);
  for (int i = 0; i < m; ++i) {
    scanf("%d%d%d", a + i, b + i, l + i);
    g[a[i]].push_back(e.size());
    e.push_back(edge(b[i], l[i]));
    g2[b[i]].push_back(e.size());
    e.push_back(edge(a[i], l[i]));
  }
  dijkstra(s, g, diss);
  dijkstra(t, g2, dist);
  len = diss[t];
  for (int i = 1; i <= n; ++i) {
    idx[i] = i;
  }
  sort(idx + 1, idx + n + 1, cmp);
  fill(fl + 1, fl + n + 1, 1);
  int k = 2;
  for (int i = 1; i < n; ++i) {
    int v = idx[i];
    if (diss[v] + dist[v] != len) {
      fl[v] = 0;
      continue;
    }
    if (fl[v]) {
      k = i + 1;
    }
    long long mx = diss[v];
    int tmp = 0;
    for (auto j : g[v]) {
      int u = e[j].to;
      int c = e[j].cost;
      if (diss[u] == diss[v] + c && diss[u] + dist[u] == len) {
        if (mx < diss[u]) {
          mx = diss[u];
          tmp = 1;
        }
        else if (mx == diss[u]) {
          tmp++;
        }
      }
    }
    for (; diss[idx[k]] < mx; ++k) {
      fl[idx[k]] = 0;
    }
    if (tmp >= 2) {
      for (; diss[idx[k]] <= mx; ++k) {
        fl[idx[k]] = 0;
      }
    }
  }
  for (int i = 1; i < n; ++i) {
    int v = idx[i];
    if (fl[v]) {
      vector<int> tmp;
      for (auto j : g[v]) {
        int u = e[j].to;
        int c = e[j].cost;
        if (diss[v] + c + dist[u] == len) {
          tmp.push_back(j);
        }
      }
      if (tmp.size() == 1) {
        ans[tmp[0] / 2] = 1;
      }
    }
  }
  for (int i = 0; i < m; ++i) {
    if (ans[i]) {
      puts("YES");
    }
    else {
      long long mn = diss[a[i]] + dist[b[i]];
      if (len - 1 > mn) {
        printf("CAN %d\n", l[i] - (len - 1 - mn));
      }
      else {
        puts("NO");
      }
    }
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 1e5 + 10;

int n, m, s, t;
int a[N], b[N], l[N];
struct edge {
  int to, cost;
  edge(int to, int cost) : to(to), cost(cost) {}
};
vector<edge> e;
vector<int> g[N];
long long diss[N], dist[N];
int cnt[N], idx[N];
long long len;
bool vis[N], fl[N], ans[N];

void dijkstra(int sc, long long *dis) {
  priority_queue<pair<long long, int> > pq;
  pq.push(make_pair(0, sc));
  memset(vis, 0, sizeof(vis));
  while (!pq.empty()) {
    pair<long long, int> tmp = pq.top();
    pq.pop();
    if (vis[tmp.second]) continue;
    vis[tmp.second] = 1;
    dis[tmp.second] = -tmp.first;
    for (auto j : g[tmp.second]) {
      int u = e[j].to;
      int c = e[j].cost;
      if (vis[u]) continue;
      pair<int, int> nxt = make_pair(-dis[tmp.second] - c, u);
      pq.push(nxt);
    }
  }
}

int cmp(int a, int b) {
  return diss[a] < diss[b];
}

int main() {
  scanf("%d%d%d%d", &n, &m, &s, &t);
  for (int i = 0; i < m; ++i) {
    scanf("%d%d%d", a + i, b + i, l + i);
    g[a[i]].push_back(e.size());
    e.push_back(edge(b[i], l[i]));
    g[b[i]].push_back(e.size());
    e.push_back(edge(a[i], l[i]));
  }
  dijkstra(s, diss);
  dijkstra(t, dist);
  len = diss[t];
  for (int i = 1; i <= n; ++i) {
    idx[i] = i;
  }
  sort(idx + 1, idx + n + 1, cmp);
  fill(fl + 1, fl + n + 1, 1);
  memset(vis, 0, sizeof(vis));
  int k = 1;
  for (int i = 1; i <= n; ++i) {
    int v = idx[i];
    if (diss[v] + dist[v] != len) {
      fl[v] = 0;
      continue;
    }
    vis[v] = 1;
    if (fl[v]) {
      k = v + 1;
    }
    int mx = v;
    for (auto j : g[v]) {
      int u = e[j].to;
      if (vis[u]) continue;
      int c = e[j].cost;
      if (diss[u] == diss[v] + c && diss[u] + dist[u] == len) {
        mx = max(mx, u);
      }
    }
    for (; k < mx; ++k) {
      fl[k] = 0;
    }
  }
  memset(vis, 0, sizeof(vis));
  for (int i = 1; i <= n; ++i) {
    int v = idx[i];
    vis[v] = 1;
    if (fl[v]) {
      vector<int> tmp;
      for (auto j : g[v]) {
        int u = e[j].to;
        if (vis[u]) continue;
        int c = e[j].cost;
        if (diss[v] + c + dist[u] == len) {
          tmp.push_back(j);
        }
      }
      if (tmp.size() == 1) {
        ans[tmp[0] / 2] = 1;
      }
    }
  }
  for (int i = 0; i < m; ++i) {
    if (ans[i]) {
      puts("YES");
    }
    else {
      long long mn = min(diss[a[i]] + dist[b[i]], diss[b[i]] + dist[a[i]]);
      if (len - 1 > mn) {
        printf("CAN %d\n", l[i] - (len - 1 - mn));
      }
      else {
        puts("NO");
      }
    }
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 1e5 + 10;
const long long INF = (long long)1e17 + 10;

int n, m, s, t;
int a[N], b[N], l[N];
struct edge {
  int to, cost;
  edge(int to, int cost) : to(to), cost(cost) {}
};
vector<edge> e;
vector<int> g[N];
vector<int> g2[N];
long long diss[N], dist[N];
int cnt[N], idx[N];
long long len;
bool vis[N], fl[N], ans[N];
map<long long, set<int> > mp;

void dijkstra(int sc, vector<int> g[N], long long *dis) {
  fill(dis + 1, dis + n + 1, INF);
  priority_queue<pair<long long, int> > pq;
  pq.push(make_pair(0, sc));
  memset(vis, 0, sizeof(vis));
  while (!pq.empty()) {
    pair<long long, int> tmp = pq.top();
    pq.pop();
    if (vis[tmp.second]) continue;
    vis[tmp.second] = 1;
    dis[tmp.second] = -tmp.first;
    for (auto j : g[tmp.second]) {
      int u = e[j].to;
      int c = e[j].cost;
      if (vis[u]) continue;
      pair<long long, int> nxt = make_pair(-dis[tmp.second] - c, u);
      pq.push(nxt);
    }
  }
}

int cmp(int a, int b) {
  return diss[a] < diss[b];
}

int main() {
  scanf("%d%d%d%d", &n, &m, &s, &t);
  for (int i = 0; i < m; ++i) {
    scanf("%d%d%d", a + i, b + i, l + i);
    g[a[i]].push_back(e.size());
    e.push_back(edge(b[i], l[i]));
    g2[b[i]].push_back(e.size());
    e.push_back(edge(a[i], l[i]));
  }
  dijkstra(s, g, diss);
  dijkstra(t, g2, dist);
  len = diss[t];
  for (int i = 1; i <= n; ++i) {
    idx[i] = i;
  }
  sort(idx + 1, idx + n + 1, cmp);
  fill(fl + 1, fl + n + 1, 1);
  int k = 2;
  for (int i = 1; i < n; ++i) {
    int v = idx[i];
    if (diss[v] + dist[v] != len) {
      fl[v] = 0;
      continue;
    }
    if (fl[v]) {
      k = i + 1;
    }
    long long mx = diss[v];
    set<int> tmp;
    for (auto j : g[v]) {
      int u = e[j].to;
      int c = e[j].cost;
      if (diss[u] == diss[v] + c && diss[u] + dist[u] == len) {
        if (mx < diss[u]) {
          mx = diss[u];
          tmp.clear();
          tmp.insert(u);
        }
        else if (mx == diss[u]) {
          tmp.insert(u);
        }
      }
    }
    for (; diss[idx[k]] < mx && k <= n; ++k) {
      fl[idx[k]] = 0;
    }
    if (tmp.size() >= 2) {
      for (; diss[idx[k]] <= mx && k <= n; ++k) {
        fl[idx[k]] = 0;
      }
    }
  }
  for (int i = 1; i < n; ++i) {
    int v = idx[i];
    if (fl[v]) {
      mp[diss[v]].insert(v);
    }
  }
  for (auto &kv : mp) {
    if (kv.second.size() > 1) {
      for (auto i : kv.second) {
        fl[i] = 0;
      }
    }
  }
  for (int i = 1; i < n; ++i) {
    int v = idx[i];
    if (fl[v]) {
      vector<int> tmp;
      for (auto j : g[v]) {
        int u = e[j].to;
        int c = e[j].cost;
        if (diss[v] + c + dist[u] == len) {
          tmp.push_back(j);
        }
      }
      if (tmp.size() == 1) {
        ans[tmp[0] / 2] = 1;
      }
    }
  }
  for (int i = 0; i < m; ++i) {
    if (ans[i]) {
      puts("YES");
    }
    else {
      long long mn = diss[a[i]] + dist[b[i]];
      if (len - 1 > mn) {
        printf("CAN %d\n", l[i] - (len - 1 - mn));
      }
      else {
        puts("NO");
      }
    }
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 1e5 + 10;

int n, m, s, t;
int a[N], b[N], l[N];
struct edge {
  int to, cost;
  edge(int to, int cost) : to(to), cost(cost) {}
};
vector<edge> e;
vector<int> g[N];
long long diss[N], dist[N];
int cnt[N], idx[N];
long long len;
bool vis[N], fl[N], ans[N];

void dijkstra(int sc, long long *dis) {
  priority_queue<pair<long long, int> > pq;
  pq.push(make_pair(0, sc));
  memset(vis, 0, sizeof(vis));
  while (!pq.empty()) {
    pair<long long, int> tmp = pq.top();
    pq.pop();
    if (vis[tmp.second]) continue;
    vis[tmp.second] = 1;
    dis[tmp.second] = -tmp.first;
    for (auto j : g[tmp.second]) {
      int u = e[j].to;
      int c = e[j].cost;
      if (vis[u]) continue;
      pair<int, int> nxt = make_pair(-dis[tmp.second] - c, u);
      pq.push(nxt);
    }
  }
}

int cmp(int a, int b) {
  return diss[a] < diss[b];
}

int main() {
  scanf("%d%d%d%d", &n, &m, &s, &t);
  for (int i = 0; i < m; ++i) {
    scanf("%d%d%d", a + i, b + i, l + i);
    g[a[i]].push_back(e.size());
    e.push_back(edge(b[i], l[i]));
    g[b[i]].push_back(e.size());
    e.push_back(edge(a[i], l[i]));
  }
  dijkstra(s, diss);
  dijkstra(t, dist);
  len = diss[t];
  for (int i = 1; i <= n; ++i) {
    idx[i] = i;
  }
  sort(idx + 1, idx + n + 1, cmp);
  fill(fl + 1, fl + n + 1, 1);
  memset(vis, 0, sizeof(vis));
  int k = 1;
  for (int i = 1; i < n; ++i) {
    int v = idx[i];
    if (diss[v] + dist[v] != len) {
      fl[v] = 0;
      continue;
    }
    vis[v] = 1;
    if (fl[v]) {
      k = i + 1;
    }
    long long mx = diss[v];
    for (auto j : g[v]) {
      int u = e[j].to;
      if (vis[u]) continue;
      int c = e[j].cost;
      if (diss[u] == diss[v] + c && diss[u] + dist[u] == len) {
        mx = max(mx, diss[u]);
      }
    }
    for (; diss[idx[k]] < mx; ++k) {
      fl[idx[k]] = 0;
    }
  }
  memset(vis, 0, sizeof(vis));
  for (int i = 1; i <= n; ++i) {
    int v = idx[i];
    vis[v] = 1;
    if (fl[v]) {
      vector<int> tmp;
      for (auto j : g[v]) {
        int u = e[j].to;
        if (vis[u]) continue;
        int c = e[j].cost;
        if (diss[v] + c + dist[u] == len) {
          tmp.push_back(j);
        }
      }
      if (tmp.size() == 1) {
        ans[tmp[0] / 2] = 1;
      }
    }
  }
  for (int i = 0; i < m; ++i) {
    if (ans[i]) {
      puts("YES");
    }
    else {
      long long mn = min(diss[a[i]] + dist[b[i]], diss[b[i]] + dist[a[i]]);
      if (len - 1 > mn) {
        printf("CAN %d\n", l[i] - (len - 1 - mn));
      }
      else {
        puts("NO");
      }
    }
  }
  return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <memory.h>
#include <set>
#include <algorithm>
#include <map>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <climits>
#include <cmath>
#include <iomanip>

#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define endl '\n'
#define dbgv(arr) cout << #arr << ": "; for (int i = 0; i < (int)arr.size(); i++) cout << arr[i] << " "; cout << endl;
#define dbge(el) cout << #el << ": " << el << endl;
#define dbgvv(arr) cout << #arr << ": "; for (int i = 0; i < (int)arr.size(); i++) cout << "(" << arr[i].first << " " << arr[i].second << ") "; cout << endl;
#define sz(s) ((int)(s).size())
#define re return
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> ii;
typedef vector< pair<int, int> > vii;

template<class T> T abs(T x) { return x > 0 ? x : -x; }

const int maxn = 100000 + 100;
int n, m, s, t;
vii e[maxn];
vii e2[maxn];
int from[maxn];
int to[maxn];
int w[maxn];
bool was[maxn];
ll cnt1[maxn];
ll cnt2[maxn];

vll dijkstra(int v, vii *e, ll *cnt) {
	vll d(n, LLONG_MAX);
	set< pair<ll, ll> > q;

	memset(was, 0, sizeof(was));

	d[v] = 0;
	q.insert(mp(0, v));
	cnt[v] = 1;

	while (!q.empty()) {
		pair<ll, ll> cur = *q.begin();
		ll dist = cur.fi;
		int idx = cur.se;
		was[idx] = true;

		q.erase(cur);

		rep(i, sz(e[idx])) {
			if (!was[e[idx][i].fi]) {
				if (d[e[idx][i].fi] > dist + e[idx][i].se) {
					auto it = q.lower_bound(mp(d[e[idx][i].fi], e[idx][i].fi));
					if (it != q.end()) q.erase(it);
					d[e[idx][i].fi] = dist + e[idx][i].se;
					q.insert(mp(d[e[idx][i].fi], e[idx][i].fi));
					cnt[e[idx][i].fi] = cnt[idx];
				} else if (d[e[idx][i].fi] == dist + e[idx][i].se) {
					cnt[e[idx][i].fi] += cnt[idx];
				}
			}
		}
	}

	re d;
}

int main()
{
	map<ii, int> minw;
	map<ii, int> kr;

	scanf("%d%d%d%d", &n, &m, &s, &t);
	s--;
	t--;
	rep(i, m) {
		int a, b, l;
		scanf("%d%d%d", &a, &b, &l);
		from[i] = a - 1;
		to[i] = b - 1;
		w[i] = l;
		e[a - 1].pb(mp(b - 1, l));
		e2[b - 1].pb(mp(a - 1, l));

		if (minw.count(mp(a - 1, b - 1)) == 0)
			minw[mp(a - 1, b - 1)] = w[i];
		else
			minw[mp(a - 1, b - 1)] = min(minw[mp(a - 1, b - 1)], w[i]);
	}

	rep(i, m) {
		if (minw[mp(from[i], to[i])] == w[i])
			kr[mp(from[i], to[i])]++;
	}

	vll ds = dijkstra(s, &e[0], cnt1);
	vll dt = dijkstra(t, &e2[0], cnt2);

	ll best = ds[t];
	ll cpaths = cnt1[t];

	//dbge(best);
	//dbge(cpaths);

	rep(i, m) {
		if (ds[from[i]] == LLONG_MAX || dt[to[i]] == LLONG_MAX) {
			cout << "NO" << endl;
			continue;
		}

		ll w1 = ds[from[i]] + w[i] + dt[to[i]] - best;

		//dbge(i);
		//dbge(ds[from[i]]);
		//dbge(dt[to[i]]);
		//dbge(w[i]);
		//dbge(w1);

		if (w1 == 0) {
			if (cnt1[from[i]] * cnt2[to[i]] * kr[mp(from[i], to[i])] != cpaths) {
				if (w[i] > 1) {
					cout << "CAN 1" << endl;
				} else {
					cout << "NO" << endl;
				}
			} else {
				if (kr[mp(from[i], to[i])] > 1 && w[i] > 1) {
					cout << "CAN 1" << endl;
				} else {
					cout << "YES" << endl;
				}
			}
		} else if (w1 + 1 < w[i]) {
			cout << "CAN " << w1 + 1 << endl;
		} else {
			cout << "NO" << endl;
		}
	}

	return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <memory.h>
#include <set>
#include <algorithm>
#include <map>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <climits>
#include <cmath>
#include <iomanip>

#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define endl '\n'
#define dbgv(arr) cout << #arr << ": "; for (int i = 0; i < (int)arr.size(); i++) cout << arr[i] << " "; cout << endl;
#define dbge(el) cout << #el << ": " << el << endl;
#define dbgvv(arr) cout << #arr << ": "; for (int i = 0; i < (int)arr.size(); i++) cout << "(" << arr[i].first << " " << arr[i].second << ") "; cout << endl;
#define sz(s) ((int)(s).size())
#define re return
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> ii;
typedef vector< pair<int, int> > vii;

template<class T> T abs(T x) { return x > 0 ? x : -x; }

const ll mod = 1000000000ll + 3;
const int maxn = 100000 + 100;
int n, m, s, t;
vii e[maxn];
vii e2[maxn];
int from[maxn];
int to[maxn];
int w[maxn];
bool was[maxn];
ll cnt1[maxn];
ll cnt2[maxn];

vll dijkstra(int v, vii *e, ll *cnt) {
	vll d(n, LLONG_MAX);
	set< pair<ll, ll> > q;

	memset(was, 0, sizeof(was));

	d[v] = 0;
	q.insert(mp(0, v));
	cnt[v] = 1;

	while (!q.empty()) {
		pair<ll, ll> cur = *q.begin();
		ll dist = cur.fi;
		int idx = cur.se;
		was[idx] = true;

		q.erase(cur);

		rep(i, sz(e[idx])) {
			int target = e[idx][i].fi;
			if (!was[target]) {
				if (d[target] > dist + e[idx][i].se) {
					auto it = q.lower_bound(mp(d[target], target));
					if (it != q.end()) q.erase(it);
					d[target] = dist + e[idx][i].se;
					q.insert(mp(d[target], target));
					cnt[target] = cnt[idx];
				} else if (d[target] == dist + e[idx][i].se) {
					cnt[target] = (cnt[target] + cnt[idx]) % mod;
				}
			}
		}
	}

	re d;
}

int main()
{
	map<ii, int> minw;
	map<ii, int> kr;

	scanf("%d%d%d%d", &n, &m, &s, &t);
	s--;
	t--;
	rep(i, m) {
		int a, b, l;
		scanf("%d%d%d", &a, &b, &l);
		from[i] = a - 1;
		to[i] = b - 1;
		w[i] = l;
		e[a - 1].pb(mp(b - 1, l));
		e2[b - 1].pb(mp(a - 1, l));

		if (minw.count(mp(a - 1, b - 1)) == 0)
			minw[mp(a - 1, b - 1)] = w[i];
		else
			minw[mp(a - 1, b - 1)] = min(minw[mp(a - 1, b - 1)], w[i]);
	}

	rep(i, m) {
		if (minw[mp(from[i], to[i])] == w[i])
			kr[mp(from[i], to[i])]++;
	}

	vll ds = dijkstra(s, &e[0], cnt1);
	vll dt = dijkstra(t, &e2[0], cnt2);

	ll best = ds[t];
	ll cpaths = cnt1[t];

	rep(i, m) {
		if (ds[from[i]] == LLONG_MAX || dt[to[i]] == LLONG_MAX) {
			cout << "NO" << endl;
			continue;
		}

		ll w1 = ds[from[i]] + w[i] + dt[to[i]] - best;

		if (w1 == 0) {
			if (((cnt1[from[i]] * cnt2[to[i]] % mod) * kr[mp(from[i], to[i])]) % mod != cpaths) {
				if (w[i] > 1) {
					cout << "CAN 1" << endl;
				} else {
					cout << "NO" << endl;
				}
			} else {
				if (kr[mp(from[i], to[i])] > 1 && w[i] > 1) {
					cout << "CAN 1" << endl;
				} else {
					cout << "YES" << endl;
				}
			}
		} else if (w1 + 1 < w[i]) {
			cout << "CAN " << w1 + 1 << endl;
		} else {
			cout << "NO" << endl;
		}
	}

	return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <memory.h>
#include <set>
#include <algorithm>
#include <map>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <climits>
#include <cmath>
#include <iomanip>

#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define endl '\n'
#define dbgv(arr) cout << #arr << ": "; for (int i = 0; i < (int)arr.size(); i++) cout << arr[i] << " "; cout << endl;
#define dbge(el) cout << #el << ": " << el << endl;
#define dbgvv(arr) cout << #arr << ": "; for (int i = 0; i < (int)arr.size(); i++) cout << "(" << arr[i].first << " " << arr[i].second << ") "; cout << endl;
#define sz(s) ((int)(s).size())
#define re return
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> ii;
typedef vector< pair<int, int> > vii;

template<class T> T abs(T x) { return x > 0 ? x : -x; }

const int maxn = 100000 + 100;
int n, m, s, t;
vii e[maxn];
vii e2[maxn];
int from[maxn];
int to[maxn];
int w[maxn];
bool was[maxn];
ll paths[maxn];
map<ii, int> eindex;

vll dijkstra(int v, vii *e) {
	vll d(n, LLONG_MAX);
	set< pair<ll, ll> > q;

	memset(was, 0, sizeof(was));

	d[v] = 0;
	q.insert(mp(0, v));

	while (!q.empty()) {
		pair<ll, ll> cur = *q.begin();
		ll dist = cur.fi;
		int idx = cur.se;
		was[idx] = true;

		q.erase(cur);

		rep(i, sz(e[idx])) {
			if (!was[e[idx][i].fi] && d[e[idx][i].fi] > dist + e[idx][i].se) {
				auto it = q.lower_bound(mp(d[e[idx][i].fi], e[idx][i].fi));
				if (it != q.end()) q.erase(it);
				d[e[idx][i].fi] = dist + e[idx][i].se;
				q.insert(mp(d[e[idx][i].fi], e[idx][i].fi));
			}
		}
	}

	re d;
}

ll dfs(int v, ll flow, vll& d) {
	if (v == t)
		re flow;

	ll ans = 0;
	map<int, int> compression;
	map<int, ll> compression_result;

	rep(i, sz(e[v])) {
		if (!was[e[v][i].fi] && d[e[v][i].fi] == d[v] + e[v][i].se) {
			compression[e[v][i].fi]++;
		}
	}

	for (auto it = compression.begin(); it != compression.end(); ++it) {
		int target = it->fi;
		int add_flow = it->se;

		was[target] = true;
		ll res = dfs(target, flow * add_flow, d);
		ans += res;
		compression_result[target] = res;

		was[target] = false;
	}

	rep(i, sz(e[v])) {
		int target = e[v][i].fi;
		if (!was[target] && d[target] == d[v] + e[v][i].se) {
			ll res = compression_result[target];
			if (res > 0) {
				paths[eindex[mp(v, i)]] += compression_result[target] / compression[target];
			}
		}
	}

	re ans;
}

int main()
{
	scanf("%d%d%d%d", &n, &m, &s, &t);
	s--;
	t--;
	rep(i, m) {
		int a, b, l;
		scanf("%d%d%d", &a, &b, &l);
		from[i] = a - 1;
		to[i] = b - 1;
		w[i] = l;
		e[a - 1].pb(mp(b - 1, l));
		eindex[mp(a - 1, sz(e[a - 1]) - 1)] = i;
		e2[b - 1].pb(mp(a - 1, l));
	}

	vll ds = dijkstra(s, &e[0]);
	vll dt = dijkstra(t, &e2[0]);

	memset(was, 0, sizeof(was));
	ll best = ds[t];
	ll cpaths = dfs(s, 1, ds);

	//dbge(best);
	//dbge(cpaths);

	rep(i, m) {
		if (ds[from[i]] == LLONG_MAX || dt[to[i]] == LLONG_MAX) {
			cout << "NO" << endl;
			continue;
		}

		ll w1 = ds[from[i]] + w[i] + dt[to[i]] - best;

		//dbge(i);
		//dbge(ds[from[i]]);
		//dbge(dt[to[i]]);
		//dbge(w[i]);
		//dbge(w1);

		if (w1 == 0) {
			if (paths[i] != cpaths) {
				if (w[i] > 1) {
					cout << "CAN 1" << endl;
				} else {
					cout << "NO" << endl;
				}
			}
			else
				cout << "YES" << endl;
		} else if (w1 + 1 < w[i]) {
			cout << "CAN " << w1 + 1 << endl;
		} else {
			cout << "NO" << endl;
		}
	}

	return 0;
}