#include <iostream>
#include <vector>
using namespace std;

#define mp make_pair
#define pb push_back

const int maxn = 200000;

int main() {
    int k;
    long double a, b;
    cout.precision(20);
    cin >> k;
    for (int i = 0; i < k; ++i) {
        cin >> a >> b;
        if (b == 0) cout << 1 << endl;
        else cout << ((min(a, 4*b)/(16*b)) + 0.5)*min(a, 4*b)/a + max(a-4*b, a - a)/a << endl;
    }
}


#include <iostream>
#include <vector>
using namespace std;

#define mp make_pair
#define pb push_back

const int maxn = 200000;

int main() {
    int k;
    long double a, b;
    cout.precision(20);
    cin >> k;
    for (int i = 0; i < k; ++i) {
        cin >> a >> b;
        cout << a/(16*b)+0.5 << endl;
    }
}


#include <iostream>
#include <vector>
using namespace std;

#define mp make_pair
#define pb push_back

const int maxn = 200000;

int main() {
    int k;
    long double a, b;
    cout.precision(20);
    cin >> k;
    for (int i = 0; i < k; ++i) {
        cin >> a >> b;
        if (b == 0) cout << 1 << endl;
        else if (a >= 4*b) cout << (3*b)/a + 1-4*b/a << endl;
        else cout << a / (16 * b) + 0.5 << endl;
    }
}


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

int T,a,b;
int main(){
 //   freopen("input.txt","r",stdin);
    scanf("%d",&T);
    while(T--){
        scanf("%d%d",&a,&b);
        printf("%.6lf\n",.5+1.0*min(a,b*4)/a*min(a*1.0/4,b*1.0)/b/4.0);
    }
}


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

int T,a,b;
int main(){
 //   freopen("input.txt","r",stdin);
    scanf("%d",&T);
    while(T--){
        scanf("%d%d",&a,&b);
        double res=0.5;
        if(a>4*b){
            res+=.5-1.0*b/a;
        }else res+=.25*a*.5/(2*b);
        printf("%.6lf\n",res);
    }
}


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

int T,a,b;
int main(){
 //   freopen("input.txt","r",stdin);
    scanf("%d",&T);
    while(T--){
        scanf("%d%d",&a,&b);
        double res=0.5;
        if(b==0)return puts("0");
        if(a>4*b){
            res+=.5-1.0*b/a;
        }else res+=.25*a*.5/(2*b);
        printf("%.6lf\n",res);
    }
}


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

int T,a,b;
int main(){
 //   freopen("input.txt","r",stdin);
    scanf("%d",&T);
    while(T--){
        scanf("%d%d",&a,&b);
        double res=0.5;
        if(a==0&&b==0)return puts("1");
        if(a>4*b){
            res+=.5-1.0*b/a;
        }else res+=.25*a*.5/(2*b);
        printf("%.6lf\n",res);
    }
}


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

int T,a,b;
int main(){
 //   freopen("input.txt","r",stdin);
    scanf("%d",&T);
    while(T--){
        scanf("%d%d",&a,&b);
        double res=0.5;
        if(a==0&&b==0){
            puts("1");
            continue;
        }
        if(a>4*b){
            res+=.5-1.0*b/a;
        }else res+=.25*a*.5/(2*b);
        printf("%.6lf\n",res);
    }
}


#include <iostream>
#include <cstdio>
#include <memory.h>
#include <cstring>
#include <cmath>

#include <vector>
#include <deque>

#define ABS(a) ((a)<0?-(a):(a))
#define SIGN(a) ((a)<0?-1:((a)>0?1:0))
#define SQR(a) ((a)*(a))
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)

#define in ({int x;scanf("%d", &x);x;})

#define PI (3.1415926)
#define INF (2147483647)
#define EPS (0.000001)
#define y1 stupid_cmath

typedef long long LL;

using namespace std;

int main(){
//	freopen("input.txt","r",stdin);
//	freopen("output.txt","w",stdout);
	LL a, b, t;
	cin>>t;
	while(t){

        cin>>a>>b;
        if(4*b>=a) if(b==0) cout<<"1.0000000000"; else printf("%.10lf\n", (8*b+a)/(16.0*(double)b));
        else if(a==0) cout<<"1.0000000000"; else printf("%.10lf\n", (b*3+(a-4*b))/((double)a));

        --t;
	}

	return 0;
}


#include <iostream>
#include <cstdio>
#include <memory.h>
#include <cstring>
#include <cmath>

#include <vector>
#include <deque>

#define ABS(a) ((a)<0?-(a):(a))
#define SIGN(a) ((a)<0?-1:((a)>0?1:0))
#define SQR(a) ((a)*(a))
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)

#define in ({int x;scanf("%d", &x);x;})

#define PI (3.1415926)
#define INF (2147483647)
#define EPS (0.000001)
#define y1 stupid_cmath

typedef long long LL;

using namespace std;

int main(){
//	freopen("input.txt","r",stdin);
//	freopen("output.txt","w",stdout);
	LL a, b, t;
	cin>>t;
	while(t){

        cin>>a>>b;
        if(4*b>=a) printf("%.10lf\n", (8*b+a)/(16.0*b));
        else printf("%.10lf\n", (b*24*b+(a-4*b)*(8*b))/(8.0*b*a));

        --t;
	}

	return 0;
}


#include <iostream>
#include <cstdio>
#include <memory.h>
#include <cstring>
#include <cmath>

#include <vector>
#include <deque>

#define ABS(a) ((a)<0?-(a):(a))
#define SIGN(a) ((a)<0?-1:((a)>0?1:0))
#define SQR(a) ((a)*(a))
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)

#define in ({int x;scanf("%d", &x);x;})

#define PI (3.1415926)
#define INF (2147483647)
#define EPS (0.000001)
#define y1 stupid_cmath

typedef long long LL;

using namespace std;

int main(){
//	freopen("input.txt","r",stdin);
//	freopen("output.txt","w",stdout);
	LL a, b, t;
	cin>>t;
	while(t){

        cin>>a>>b;
        if(4*b>=a) printf("%.10lf\n", (8*b+a)/(16.0*b));
        else printf("%.10lf\n", (b*24*b+(a-4*b)*(8*b))/(8.0*b*b));

        --t;
	}

	return 0;
}


#include <iostream>
#include <cstdio>
#include <memory.h>
#include <cstring>
#include <cmath>

#include <vector>
#include <deque>

#define ABS(a) ((a)<0?-(a):(a))
#define SIGN(a) ((a)<0?-1:((a)>0?1:0))
#define SQR(a) ((a)*(a))
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)

#define in ({int x;scanf("%d", &x);x;})

#define PI (3.1415926)
#define INF (2147483647)
#define EPS (0.000001)
#define y1 stupid_cmath

typedef long long LL;

using namespace std;

int main(){
//	freopen("input.txt","r",stdin);
//	freopen("output.txt","w",stdout);
	LL a, b, t;
	cin>>t;
	while(t){

        cin>>a>>b;
        if(4*b>=a) if(b==0) cout<<"1.0000000000"; else printf("%.16llf\n", (8*b+a)/(16.0*(long double)b));
        else if(a==0) cout<<"1.0000000000"; else printf("%.16llf\n", (b*3+(a-4*b))/((long double)a));

        --t;
	}

	return 0;
}


#include <iostream>
#include <cstdio>
#include <memory.h>
#include <cstring>
#include <cmath>

#include <vector>
#include <deque>

#define ABS(a) ((a)<0?-(a):(a))
#define SIGN(a) ((a)<0?-1:((a)>0?1:0))
#define SQR(a) ((a)*(a))
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)

#define in ({int x;scanf("%d", &x);x;})

#define PI (3.1415926)
#define INF (2147483647)
#define EPS (0.000001)
#define y1 stupid_cmath

typedef long long LL;

using namespace std;

int main(){
//	freopen("input.txt","r",stdin);
//	freopen("output.txt","w",stdout);
	LL a, b, t;
	cin>>t;
	while(t){

        cin>>a>>b;
        if(4*b>=a) if(b==0) cout<<"1.0000000000\n"; else printf("%.16lf\n", (8*b+a)/(16.0*( double)b));
        else if(a==0) cout<<"1.0000000000\n"; else printf("%.16lf\n", (b*3+(a-4*b))/(( double)a));

        --t;
	}

	return 0;
}


#include <iostream>
#include <cstdio>
#include <memory.h>
#include <cstring>
#include <cmath>

#include <vector>
#include <deque>

#define ABS(a) ((a)<0?-(a):(a))
#define SIGN(a) ((a)<0?-1:((a)>0?1:0))
#define SQR(a) ((a)*(a))
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)

#define in ({int x;scanf("%d", &x);x;})

#define PI (3.1415926)
#define INF (2147483647)
#define EPS (0.000001)
#define y1 stupid_cmath

typedef long long LL;

using namespace std;

int main(){
//	freopen("input.txt","r",stdin);
//	freopen("output.txt","w",stdout);
	LL a, b, t;
	cin>>t;
	while(t){

        cin>>a>>b;
        if(4*b>=a) printf("%.10lf\n", (8*b+a)/(16.0*b));
        else printf("%.10lf\n", (b*24*b+(a-4*b)*(8*b))/(8.0*b));

        --t;
	}

	return 0;
}


#include <iostream>
#include <cstdio>
#include <memory.h>
#include <cstring>
#include <cmath>

#include <vector>
#include <deque>

#define ABS(a) ((a)<0?-(a):(a))
#define SIGN(a) ((a)<0?-1:((a)>0?1:0))
#define SQR(a) ((a)*(a))
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)

#define in ({int x;scanf("%d", &x);x;})

#define PI (3.1415926)
#define INF (2147483647)
#define EPS (0.000001)
#define y1 stupid_cmath

typedef long long LL;

using namespace std;

int main(){
//	freopen("input.txt","r",stdin);
//	freopen("output.txt","w",stdout);
	LL a, b, t;
	cin>>t;
	while(t){

        cin>>a>>b;
        if(4*b>=a) if(b==0) cout<<"1.0000000000"; else printf("%.16lf\n", (8*b+a)/(16.0*( double)b));
        else if(a==0) cout<<"1.0000000000"; else printf("%.16lf\n", (b*3+(a-4*b))/(( double)a));

        --t;
	}

	return 0;
}


#include <iostream>
#include <cstdio>
#include <memory.h>
#include <cstring>
#include <cmath>

#include <vector>
#include <deque>

#define ABS(a) ((a)<0?-(a):(a))
#define SIGN(a) ((a)<0?-1:((a)>0?1:0))
#define SQR(a) ((a)*(a))
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)

#define in ({int x;scanf("%d", &x);x;})

#define PI (3.1415926)
#define INF (2147483647)
#define EPS (0.000001)
#define y1 stupid_cmath

typedef long long LL;

using namespace std;

int main(){
//	freopen("input.txt","r",stdin);
//	freopen("output.txt","w",stdout);
	LL a, b, t;
	cin>>t;
	while(t){

        cin>>a>>b;
        if(4*b>=a) printf("%.10lf\n", (8*b+a)/(16.0*(double)b));
        else printf("%.10lf\n", (b*3+(a-4*b))/((double)a));

        --t;
	}

	return 0;
}


#include<cstdio>

int n;

int main() {
	scanf("%d", &n);
	for(int i=0;i<n;i++) {
		double a, b;
		scanf("%lf%lf", &a, &b);
		if(!b) puts("1");
		else if(b>=a/4) printf("%.12lf\n", (2*b+a/4)*a/2 / (a*b*2));
		else printf("%.12lf\n", (a*b + (2*a-b*4)*b/2) / (a*b*2));
	}

	return 0;
}


#include<cstdio>

int n;

int main() {
	scanf("%d", &n);
	for(int i=0;i<n;i++) {
		double a, b;
		scanf("%lf%lf", &a, &b);
		if(!b) puts("1");
		else if(!a) puts("0.5");
		else if(b>=a/4) printf("%.12lf\n", (2*b+a/4)*a/2 / (a*b*2));
		else printf("%.12lf\n", (a*b + (2*a-b*4)*b/2) / (a*b*2));
	}

	return 0;
}


#include<cstdio>

int n;

int main() {
	scanf("%d", &n);
	for(int i=0;i<n;i++) {
		double a, b;
		scanf("%lf%lf", &a, &b);
		if(!a) puts("0.5");
		else if(!b) puts("1");
		else if(b>=a/4) printf("%.12lf\n", (2*b+a/4)*a/2 / (a*b*2));
		else printf("%.12lf\n", (a*b + (2*a-b*4)*b/2) / (a*b*2));
	}

	return 0;
}


#include<cstdio>

int n;

int main() {
	scanf("%d", &n);
	for(int i=0;i<n;i++) {
		double a, b;
		scanf("%lf%lf", &a, &b);
		if(b>=a/4) printf("%.12lf\n", (2*b+a/4)*a/2 / (a*b*2));
		else printf("%.12lf\n", a*b + (2*a-b*4)*b/2 / (a*b*2));
	}

	return 0;
}


#include <cmath>
#include <algorithm>
#include <vector>
#include <iostream>
#include <cstdio>
#include <set>
#include <queue>
#include <map>
#include <string>
#include <cstring>
#include <ctime>
using namespace std;
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Ford(i,a,b) for(int i=a;i>=b;i--)
#define Rep(i,c) for((type of c.begin()) i;i!=c.end();i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sr(x) (int)x.size()
#define modul 100000000
#define nmax 100
#define BUG(x) {cout << #x << " = " << x << endl;}
#define PR(x,a,b) {cout << #x << " = "; For(_,a,b) cout << x[_] << ' '; cout << endl;}
#define fillchar(x,a,b,delta) For(_,a,b) x[_]=delta;
#define Bit(s,i) (s&(1<<i))
#define Two(x) (1<<x)
#define pii pair<int,int>
#define ll long long
#define e 1e-6
#define pi acos(-1)
int n,test;
double a,b,res,l,r,bb;
int main()
{
  //  freopen("codeforce.inp","r",stdin);
  //  freopen("codeforce.out","w",stdout);
    for(scanf("%d",&test);test;test--) {
        scanf("%lf%lf",&a,&b);
        int x=1;
        while (x*10*max(a,b)<=1000000&& max(a,b)!=0) x*=10;
        a*=x;b*=x;
        bb=min(a/4,b);
        l=a-bb*4+1,r=a+1;
        res=((((r-l)/4)+1)*(r+l) )/2;
        res+=b *(a+1);
        printf("%.10lf\n",1.0*res/((2*b+1)*(a+1)));
    }
    return 0;
}


#include <cmath>
#include <algorithm>
#include <vector>
#include <iostream>
#include <cstdio>
#include <set>
#include <queue>
#include <map>
#include <string>
#include <cstring>
#include <ctime>
using namespace std;
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Ford(i,a,b) for(int i=a;i>=b;i--)
#define Rep(i,c) for((type of c.begin()) i;i!=c.end();i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sr(x) (int)x.size()
#define modul 100000000
#define nmax 100
#define BUG(x) {cout << #x << " = " << x << endl;}
#define PR(x,a,b) {cout << #x << " = "; For(_,a,b) cout << x[_] << ' '; cout << endl;}
#define fillchar(x,a,b,delta) For(_,a,b) x[_]=delta;
#define Bit(s,i) (s&(1<<i))
#define Two(x) (1<<x)
#define pii pair<int,int>
#define ll long long
#define e 1e-6
#define pi acos(-1)
int n,test,a,b;
int main()
{
   // freopen("codeforce.inp","r",stdin);
    for(scanf("%d",&test);test;test--) {
        scanf("%d%d",&a,&b);
        int x=1;
        while ((ll)x*10*max(a,b)<=100000000) x*=10;
        a*=x;b*=x;
    //    BUG(a);BUG(b);
        int bb=min(a/4,b);
    //    BUG(bb);
        int l=a-bb*4+1,r=a+1;
    //    BUG(l);BUG(r);
        ll res=((((r-l)/4)+1)*(ll) (r+l) )/2;
     //   BUG(res);
        res+=b* (ll) (a+1);
        printf("%.10lf\n",1.0*res/((2*b+1)*(ll)(a+1)));
    }
    return 0;
}


#include <cmath>
#include <algorithm>
#include <vector>
#include <iostream>
#include <cstdio>
#include <set>
#include <queue>
#include <map>
#include <string>
#include <cstring>
#include <ctime>
using namespace std;
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Ford(i,a,b) for(int i=a;i>=b;i--)
#define Rep(i,c) for((type of c.begin()) i;i!=c.end();i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sr(x) (int)x.size()
#define modul 100000000
#define nmax 100
#define BUG(x) {cout << #x << " = " << x << endl;}
#define PR(x,a,b) {cout << #x << " = "; For(_,a,b) cout << x[_] << ' '; cout << endl;}
#define fillchar(x,a,b,delta) For(_,a,b) x[_]=delta;
#define Bit(s,i) (s&(1<<i))
#define Two(x) (1<<x)
#define pii pair<int,int>
#define ll long long
#define e 1e-6
#define pi acos(-1)
int n,test,a,b;
int main()
{
  //  freopen("codeforce.inp","r",stdin);
    for(scanf("%d",&test);test;test--) {
        scanf("%d%d",&a,&b);
        int x=1;
        while ((ll)x*10*max(a,b)<=10000000) x*=10;
        a*=x;b*=x;
    //    BUG(a);BUG(b);
        int bb=min(a/4,b);
    //    BUG(bb);
        int l=a-bb*4+1,r=a+1;
    //    BUG(l);BUG(r);
        ll res=((((r-l)/4)+1)*(ll) (r+l) )/2;
     //   BUG(res);
        res+=b* (ll) (a+1);
        printf("%.10lf\n",1.0*res/((2*b+1)*(ll)(a+1)));
    }
    return 0;
}


#include <cmath>
#include <algorithm>
#include <vector>
#include <iostream>
#include <cstdio>
#include <set>
#include <queue>
#include <map>
#include <string>
#include <cstring>
#include <ctime>
using namespace std;
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Ford(i,a,b) for(int i=a;i>=b;i--)
#define Rep(i,c) for((type of c.begin()) i;i!=c.end();i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sr(x) (int)x.size()
#define modul 100000000
#define nmax 100
#define BUG(x) {cout << #x << " = " << x << endl;}
#define PR(x,a,b) {cout << #x << " = "; For(_,a,b) cout << x[_] << ' '; cout << endl;}
#define fillchar(x,a,b,delta) For(_,a,b) x[_]=delta;
#define Bit(s,i) (s&(1<<i))
#define Two(x) (1<<x)
#define pii pair<int,int>
#define ll long long
#define e 1e-6
#define pi acos(-1)
int n,test,a,b;
int main()
{
  //  freopen("codeforce.inp","r",stdin);
    for(scanf("%d",&test);test;test--) {
        scanf("%d%d",&a,&b);
        int x=1;
        while ((ll)x*10*max(a,b)<=1000000000) x*=10;
        a*=x;b*=x;
    //    BUG(a);BUG(b);
        int bb=min(a/4,b);
     //   BUG(bb);
        int l=1,r=4*bb+1;
      //  BUG(l);BUG(r);
        ll res=(((r-l)/4+1)*(ll) (r+l) )/2;
      // BUG(res);
        res+=(b+1)* (ll) (a+1);
        printf("%.10lf\n",1.0*res/((2*b+1)*(ll)(a+1)));
    }
    return 0;
}


#include <cmath>
#include <algorithm>
#include <vector>
#include <iostream>
#include <cstdio>
#include <set>
#include <queue>
#include <map>
#include <string>
#include <cstring>
#include <ctime>
using namespace std;
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Ford(i,a,b) for(int i=a;i>=b;i--)
#define Rep(i,c) for((type of c.begin()) i;i!=c.end();i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sr(x) (int)x.size()
#define modul 100000000
#define nmax 100
#define BUG(x) {cout << #x << " = " << x << endl;}
#define PR(x,a,b) {cout << #x << " = "; For(_,a,b) cout << x[_] << ' '; cout << endl;}
#define fillchar(x,a,b,delta) For(_,a,b) x[_]=delta;
#define Bit(s,i) (s&(1<<i))
#define Two(x) (1<<x)
#define pii pair<int,int>
#define ll long long
#define e 1e-6
#define pi acos(-1)
int n,test;
double a,b,res,l,r,bb;
int main()
{
   // freopen("codeforce.inp","r",stdin);
  //  freopen("codeforce.out","w",stdout);
    for(scanf("%d",&test);test;test--) {
        scanf("%lf%lf",&a,&b);
        int x=1;
        while (x*10*max(a,b)<=1000000) x*=10;
        a*=x;b*=x;
        bb=min(a/4,b);
        l=a-bb*4+1,r=a+1;
        res=((((r-l)/4)+1)*(r+l) )/2;
        res+=b *(a+1);
        printf("%.10lf\n",1.0*res/((2*b+1)*(a+1)));
    }
    return 0;
}


#include <cmath>
#include <algorithm>
#include <vector>
#include <iostream>
#include <cstdio>
#include <set>
#include <queue>
#include <map>
#include <string>
#include <cstring>
#include <ctime>
using namespace std;
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Ford(i,a,b) for(int i=a;i>=b;i--)
#define Rep(i,c) for((type of c.begin()) i;i!=c.end();i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sr(x) (int)x.size()
#define modul 100000000
#define nmax 100
#define BUG(x) {cout << #x << " = " << x << endl;}
#define PR(x,a,b) {cout << #x << " = "; For(_,a,b) cout << x[_] << ' '; cout << endl;}
#define fillchar(x,a,b,delta) For(_,a,b) x[_]=delta;
#define Bit(s,i) (s&(1<<i))
#define Two(x) (1<<x)
#define pii pair<int,int>
#define ll long long
#define e 1e-6
#define pi acos(-1)
int n,test,a,b;
int main()
{
  //  freopen("codeforce.inp","r",stdin);
  //  freopen("codeforce.out","w",stdout);
    for(scanf("%d",&test);test;test--) {
        scanf("%d%d",&a,&b);
        int x=1;
        while ((ll)x*10*max(a,b)<=100000000 && max(a,b)!=0) x*=10;
        a*=x;b*=x;
        int bb=min(a/4,b);
        int l=a-bb*4+1,r=a+1;
        ll res=((((r-l)/4)+1)*(ll) (r+l) )/2;
        res+=b* (ll) (a+1);
        printf("%.10lf\n",1.0*res/((2*b+1)*(ll)(a+1)));
    }
    return 0;
}


#include <cmath>
#include <algorithm>
#include <vector>
#include <iostream>
#include <cstdio>
#include <set>
#include <queue>
#include <map>
#include <string>
#include <cstring>
#include <ctime>
using namespace std;
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Ford(i,a,b) for(int i=a;i>=b;i--)
#define Rep(i,c) for((type of c.begin()) i;i!=c.end();i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sr(x) (int)x.size()
#define modul 100000000
#define nmax 100
#define BUG(x) {cout << #x << " = " << x << endl;}
#define PR(x,a,b) {cout << #x << " = "; For(_,a,b) cout << x[_] << ' '; cout << endl;}
#define fillchar(x,a,b,delta) For(_,a,b) x[_]=delta;
#define Bit(s,i) (s&(1<<i))
#define Two(x) (1<<x)
#define pii pair<int,int>
#define ll long long
#define e 1e-6
#define pi acos(-1)
int n,test,a,b;
int main()
{
   // freopen("codeforce.inp","r",stdin);
  //  freopen("codeforce.out","w",stdout);
    for(scanf("%d",&test);test;test--) {
        scanf("%d%d",&a,&b);
        int x=1;
        while ((ll)x*10*max(a,b)<=1000000) x*=10;
        a*=x;b*=x;
        int bb=min(a/4,b);
        ll l=a-bb*4+1,r=a+1;
        ll res=((((r-l)/4)+1)*(ll) (r+l) )/2;
        res+=b* (ll) (a+1);
        printf("%.10lf\n",1.0*res/((2*b+1)*(ll)(a+1)));
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <deque>
#include <queue>
#include <stack>
#include <math.h>
#include <map>
#include <bitset>
#include <set>

using namespace std;

int cmp(double x, double y) {
    if (fabs(x - y) < 1e-7) return 0;
    if (x < y) return -1;
    return 1;
}

float call(double a, double b) {

      double s1, s2;

      if (cmp(a / 4, b) <= 0) {
         s1 = b + a / 8;
         //s2 = (b - a / 4 + b) / 2;
      }
      else {
           double l1, l2, t1, t2;
           l1 = b * 4;
           t1 = b + b / 2;
           l2 = a - l1;
           t2 = 2*b;

           s1 = (l1 * t1 + l2 * t2) / a;
          //s2 = (b / 2) * l1 / a;
      }

      return s1 / (2 * b);
}

int main() {
    int n, a, b;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d %d", &a, &b);
        if (b == 0) printf("1\n");
        else if (a == 0) printf("0.5\n");
        else  printf("%.9lf\n", call(a, b));
    }
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <deque>
#include <queue>
#include <stack>
#include <math.h>
#include <map>
#include <bitset>
#include <set>

using namespace std;

int cmp(double x, double y) {
    if (fabs(x - y) < 1e-7) return 0;
    if (x < y) return -1;
    return 1;
}

float call(double a, double b) {

      double s1, s2;

      if (cmp(a / 4, b) <= 0) {
         s1 = b + a / 8;
         s2 = (b - a / 4 + b) / 2;
      }
      else {
           double l1, l2, t1, t2;
           l1 = b * 4;
           t1 = b + b / 2;
           l2 = a - l1;
           t2 = b;

           s1 = (l1 * t1 + l2 * t2) / a;
           s2 = (b / 2) * l1 / a;
      }

      return s1 / (2 * b);
}

int main() {
    int n, a, b;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d %d", &a, &b);
        if (b == 0) printf("1\n");
        else if (a == 0) printf("0.5\n");
        else  printf("%.9lf\n", call(a, b));
    }
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <deque>
#include <queue>
#include <stack>
#include <math.h>
#include <map>
#include <bitset>
#include <set>

using namespace std;

int cmp(double x, double y) {
    if (fabs(x - y) < 1e-7) return 0;
    if (x < y) return -1;
    return 1;
}

float call(double a, double b) {

      double s1, s2;

      a = 0.5;
      if (cmp(a / 4, b) <= 0) s1 = b + a / 8;
      else {
           double l1, l2, t1, t2;
           l1 = b * 4;
           t1 = b + b / 2;
           l2 = a - l1;
           t2 = b;

           s1 = (l1 * t1 + l2 * t2) / a;
      }

      return s1 / (2 * b);
}

int main() {
    int n, a, b;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d %d", &a, &b);
        if (b == 0) printf("1\n");
        else if (a == 0) printf("0.5\n");
        else  printf("%.9lf\n", call(a, b));
    }
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <deque>
#include <queue>
#include <stack>
#include <math.h>
#include <map>
#include <bitset>
#include <set>

using namespace std;

int cmp(double x, double y) {
    if (fabs(x - y) < 1e-7) return 0;
    if (x < y) return -1;
    return 1;
}

float call(double a, double b) {

      double s1, s2;

      if (cmp(a / 4, b) <= 0) {
         s1 = b + a / 8;
         s2 = (b - a / 4 + b) / 2;
      }
      else {
           double l1, l2, t1, t2;
           l1 = b * 4;
           t1 = b + b / 2;
           l2 = a - l1;
           t2 = b;

           s1 = (l1 * t1 + l2 * t2) / (l1 + l2);
           s2 = (b / 2) * l1 / (l1 + l2);
      }

      return s1 / (s2 + s1);
}

int main() {
    int n, a, b;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d %d", &a, &b);
        if (b == 0) printf("1\n");
        else if (a == 0) printf("0.5\n");
        else  printf("%.9lf\n", call(a, b));
    }
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <deque>
#include <queue>
#include <stack>
#include <math.h>
#include <map>
#include <bitset>
#include <set>

using namespace std;

int cmp(float x, float y) {
    if (fabs(x - y) < 1e-6) return 0;
    if (x < y) return -1;
    return 1;
}

float call(float a, float b) {

      float s1, s2;

      if (cmp(a / 4, b) <= 0) {
         s1 = b + a / 8;
         s2 = (b - a / 4 + b) / 2;
      }
      else {
           float l1, l2, t1, t2;
           l1 = b * 4;
           t1 = b + b / 2;
           l2 = a - l1;
           t2 = b;

           s1 = (l1 * t1 + l2 * t2) / (l1 + l2);
           s2 = (b + b / 2) * l1 / (l1 + l2);
      }

      return s1 / (s2 + s1);
}

int main() {
    int n, a, b;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d %d", &a, &b);
        if (b == 0) printf("1\n");
        else if (a == 0) printf("0.5\n");
        else  printf("%f\n", call(a, b));
    }
}


//In the name of God
#include <iostream>
#include <iomanip>
using namespace std;

void solve()
{
  long double a,b;
  cin>>a>>b;
  cout<<fixed<<setprecision(10);
  if(a/4<=b)
    cout<<(a/8+b)/(2*b)<<endl;
  else
    cout<<(a+2*b+(a-4*b))/(a*2)<<endl;
}

int main()
{
  int t;
  cin>>t;
  while(t--)
    solve();
  return 0;
}


///In the name of God
#include <iostream>
#include <iomanip>
using namespace std;

const double EPS=1e-8;
void solve()
{
  long double a,b;
  cin>>a>>b;
  if(a<EPS and b<EPS)
    {cout<<1<<endl; return;}
  if(a<EPS)
    {cout<<1.0/2<<endl; return;}
  if(b<EPS)
    {cout<<1<<endl; return;}
  cout<<fixed<<setprecision(10);
  if(a/4<=b)
    cout<<(a/8+b)/(2*b)<<endl;
  else
    cout<<1-b/a<<endl;
}

int main()
{
  int t;
  cin>>t;
  while(t--)
    solve();
  return 0;
}


//In the name of God
#include <iostream>
#include <iomanip>
using namespace std;

void solve()
{
  long double a,b;
  cin>>a>>b;
  cout<<fixed<<setprecision(10);
  if(a/4<=b)
    cout<<(a/8+b)/(2*b)<<endl;
  else
    cout<<1-b/a<<endl;
}

int main()
{
  int t;
  cin>>t;
  while(t--)
    solve();
  return 0;
}


#include <iostream>
#include <cstdio>
#include <set>
#include <map>
#include <algorithm>
#include <string.h>
#include <vector>
#include <queue>
#include <stack>
using namespace std;
long long int dp[200100],tem[200100],pre[200100];
struct ab{
    int x,y;
    bool operator<(const ab &u)const{
        return x<u.x;
    }
}a[200100];
long long int n,m;

long long int ans,res,cnt,temp,p;
const int N=110;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i].x;
        a[i].y=i;
    }
    sort(a+1,a+1+n);
    dp[1]=0;
    dp[3]=dp[2]=1e18;
    memset(pre,-1,sizeof(pre));
    ans=1e18,p=-1;
    for(int i=3;i<=n;i++){
        if(dp[i-3]-a[i-2].x<ans){
            ans=dp[i-3]-a[i-2].x;
            p=i-3;
        }
        dp[i]=ans+a[i].x;
        pre[i]=p;
    }
    int pr=n;
    vector<int>op;
    while(pr){
        op.push_back(pr);
        pr=pre[pr];
    }
    reverse(op.begin(),op.end());
    for(int i=1;i<=op[0];i++)
        tem[a[i].y]=1;
    for(int i=1;i<op.size();i++){
        for(int j=op[i-1]+1;j<=op[i];j++){
            tem[a[j].y]=i+1;
        }
    }
    cout<<dp[n]<<' '<<op.size()<<endl;
    for(int i=1;i<=n;i++)
        cout<<tem[i]<<' ';
    cout<<endl;
}


#include <iostream>
#include <cstdio>
#include <set>
#include <map>
#include <algorithm>
#include <string.h>
#include <vector>
#include <queue>
#include <stack>
using namespace std;
long long int dp[200100],tem[200100],pre[200100];
struct ab{
    int x,y;
    bool operator<(const ab &u)const{
        return x<u.x;
    }
}a[200100];
long long int n,m;

long long int ans,res,cnt,temp,p;
const int N=110;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i].x;
        a[i].y=i;
    }
    sort(a+1,a+1+n);
    dp[0]=0;
    dp[1]=1e18;
    dp[2]=1e18;
    memset(pre,-1,sizeof(pre));
    ans=1e18,p=-1;
    for(int i=3;i<=n;i++){
        if(dp[i-3]-a[i-2].x<ans){
            ans=dp[i-3]-a[i-2].x;
            p=i-3;
        }
        dp[i]=ans+a[i].x;
        pre[i]=p;
    }
    long long pr=n;
    vector<long long>op;
    while(pr>0){
        op.push_back(pr);
        pr=pre[pr];
    }
    reverse(op.begin(),op.end());
    for(int i=1;i<=op[0];i++)
        tem[a[i].y]=1;
    for(int i=1;i<op.size();i++){
        for(int j=op[i-1]+1;j<=op[i];j++){
            tem[a[j].y]=i+1;
        }
    }
    cout<<dp[n]<<' '<<op.size()<<endl;
    for(int i=1;i<=n;i++)
        cout<<tem[i]<<' ';
    cout<<endl;
}


#include <iostream>
#include <cstdio>
#include <set>
#include <map>
#include <algorithm>
#include <string.h>
#include <vector>
#include <queue>
#include <stack>
using namespace std;
long long int dp[200100],tem[200100],pre[200100];
struct ab{
    int x,y;
    bool operator<(const ab &u)const{
        return x<u.x;
    }
}a[200100];
long long int n,m;

long long int ans,res,cnt,temp,p;
const int N=110;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i].x;
        a[i].y=i;
    }
    sort(a+1,a+1+n);
    dp[1]=0;
    dp[3]=dp[2]=1e18;
    memset(pre,-1,sizeof(pre));
    ans=1e18,p=-1;
    for(int i=3;i<=n;i++){
        if(dp[i-3]-a[i-2].x<ans){
            ans=dp[i-3]-a[i-2].x;
            p=i-3;
        }
        dp[i]=ans+a[i].x;
        pre[i]=p;
    }
    long long pr=n;
    vector<long long>op;
    while(pr){
        op.push_back(pr);
        pr=pre[pr];
    }
    reverse(op.begin(),op.end());
    for(int i=1;i<=op[0];i++)
        tem[a[i].y]=1;
    for(int i=1;i<op.size();i++){
        for(int j=op[i-1]+1;j<=op[i];j++){
            tem[a[j].y]=i+1;
        }
    }
    cout<<dp[n]<<' '<<op.size()<<endl;
    for(int i=1;i<=n;i++)
        cout<<tem[i]<<' ';
    cout<<endl;
}


#include <iostream>
#include <cstdio>
#include <set>
#include <map>
#include <algorithm>
#include <string.h>
#include <vector>
#include <queue>
#include <stack>
using namespace std;
long long int dp[200100],tem[200100],pre[200100];
struct ab{
    int x,y;
    bool operator<(const ab &u)const{
        return x<u.x;
    }
}a[200100];
long long int n,m;

long long int ans,res,cnt,temp,p;
const int N=110;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i].x;
        a[i].y=i;
    }
    sort(a+1,a+1+n);
    dp[1]=0;
    dp[3]=dp[2]=1e18;
    memset(pre,-1,sizeof(pre));
    ans=1e18,p=-1;
    for(int i=3;i<=n;i++){
        if(dp[i-3]-a[i-2].x<ans){
            ans=dp[i-3]-a[i-2].x;
            p=i-3;
        }
        dp[i]=ans+a[i].x;
        pre[i]=p;
    }
    long long pr=n;
    vector<long long>op;
    while(pr>0){
        op.push_back(pr);
        pr=pre[pr];
    }
    reverse(op.begin(),op.end());
    for(int i=1;i<=op[0];i++)
        tem[a[i].y]=1;
    for(int i=1;i<op.size();i++){
        for(int j=op[i-1]+1;j<=op[i];j++){
            tem[a[j].y]=i+1;
        }
    }
    cout<<dp[n]<<' '<<op.size()<<endl;
    for(int i=1;i<=n;i++)
        cout<<tem[i]<<' ';
    cout<<endl;
}


#include<iostream>
#include<algorithm>
#include<map>
using namespace::std;

long long int dp[200005][2];
pair<long long int,long long int> ar[200005];
//map<int,int> m;
long long int m2[200005],m[200005];
bool cnt[200005];

int main() {
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>ar[i].first,ar[i].second=i;
	sort(ar,ar+n);
	dp[2][0]=ar[2].first-ar[0].first;
	dp[2][1]=ar[0].first;
	m[ar[0].second]=m[ar[1].second]=m[ar[2].second]=1;
	for(int i=3;i<n;i++){
		dp[i][0]=dp[i-1][0]+ar[i].first-ar[i-1].first;
		dp[i][1]=dp[i-1][1];
		m[ar[i].second]=m[ar[i-1].second];
		if(i>=5 && dp[i][0]>ar[i].first-ar[i-2].first+dp[i-3][0]){
			//cout<<i<<'\n';
			cnt[i]=1;
			dp[i][0]=ar[i].first-ar[i-2].first+dp[i-3][0];

			dp[i][1]=ar[i-2].first;
			m[ar[i].second]=m[ar[i-1].second]=m[ar[i-2].second]=m[ar[i-3].second]+1;
		}
	}
	//for(int i=0;i<n;i++)
	//	cout<<cnt[i]<<' ';
	//cout<<'\n';
	int r=n,t=1;
	for(int i=n-1;i>-1;){
		while(i>-1 && cnt[i]!=1) i--;
		if(i==-1)
			m2[0]+=t, m2[r]-=t;
		else m2[i-2]+=t,m2[r]-=t;
		r=i-2;
		i-=3;
		t++;
	}
	for(int i=1;i<=n;i++)
		m2[i]+=m2[i-1];//cout<<m[i]<<' ';
	//cout<<'\n';
	for(int i=0;i<n;i++)
		m[ar[i].second]=m2[i];
	cout<<dp[n-1][0]<<' '<<t-1<<'\n';//m[ar[n-1].second]<<'\n';
	for(int i=0;i<n;i++)
		cout<<m[i]<<' ';
	cout<<'\n';
}


#include<iostream>
#include<algorithm>
#include<map>
using namespace::std;

long long int dp[200005][2];
pair<long long int,long long int> ar[200005];
//map<int,int> m;
long long int m[200005];
bool cnt[200005];

int main() {
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>ar[i].first,ar[i].second=i;
	sort(ar,ar+n);
	dp[2][0]=ar[2].first-ar[0].first;
	dp[2][1]=ar[0].first;
	m[ar[0].second]=m[ar[1].second]=m[ar[2].second]=1;
	for(int i=3;i<n;i++){
		dp[i][0]=dp[i-1][0]+ar[i].first-ar[i-1].first;
		dp[i][1]=dp[i-1][1];
		m[ar[i].second]=m[ar[i-1].second];
		if(i>=5 && dp[i][0]>ar[i].first-ar[i-2].first+dp[i-3][0]){
			//cout<<i<<'\n';
			cnt[i]=1;
			dp[i][0]=ar[i].first-ar[i-2].first+dp[i-3][0];
			for(int j=i-5;j<=i-3;j++)
				m[ar[j].second]=m[ar[i-6].second]+(cnt[i-3]);
			dp[i][1]=ar[i-2].first;
			m[ar[i].second]=m[ar[i-1].second]=m[ar[i-2].second]=m[ar[i-3].second]+1;
		}
	}
	cout<<dp[n-1][0]<<' '<<m[ar[n-1].second]<<'\n';
	for(int i=0;i<n;i++)
		cout<<m[i]<<' ';
	cout<<'\n';
}


#include<iostream>
#include<algorithm>
#include<map>
using namespace::std;

long long int dp[200005][2];
pair<long long int,long long int> ar[200005];
//map<int,int> m;
long long int m[200005];
bool cnt[200005];

int main() {
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>ar[i].first,ar[i].second=i;
	sort(ar,ar+n);
	dp[2][0]=ar[2].first-ar[0].first;
	dp[2][1]=ar[0].first;
	m[ar[0].second]=m[ar[1].second]=m[ar[2].second]=1;
	for(int i=3;i<n;i++){
		dp[i][0]=dp[i-1][0]+ar[i].first-ar[i-1].first;
		dp[i][1]=dp[i-1][1];
		m[ar[i].second]=m[ar[i-1].second];
		if(i>=5 && dp[i][0]>ar[i].first-ar[i-2].first+dp[i-3][0]){
			//cout<<i<<'\n';
			cnt[i]=1;
			dp[i][0]=ar[i].first-ar[i-2].first+dp[i-3][0];
			for(int j=i-5;j<=i-3;j++)
				m[ar[j].second]=(i==5?1:m[ar[i-6].second])+(cnt[i-3]);
			dp[i][1]=ar[i-2].first;
			m[ar[i].second]=m[ar[i-1].second]=m[ar[i-2].second]=m[ar[i-3].second]+1;
		}
	}
	cout<<dp[n-1][0]<<' '<<m[ar[n-1].second]<<'\n';
	for(int i=0;i<n;i++)
		cout<<m[i]<<' ';
	cout<<'\n';
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

ll dp[200007];
ll INF = 2 * 1e18 - 1;

int main()
{
    ios::sync_with_stdio(0);
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    ll i, n, c, j, next;
    cin >> n;
    vector<pair<ll, ll>> a(n);
    for (i = 0; i < n; i++)
    {
        cin >> c;
        a[i] = {c, i};
    }
    sort(a.begin(), a.end());
    for (i = 1; i <= n; i++)
        dp[i] = INF;
    for (i = 0; i <= n; i++)
    {
        if (i + 3 <= n)
            dp[i + 3] = min(dp[i + 3], dp[i] + a[i + 2].first - a[i].first);
        if (i + 4 <= n)
            dp[i + 4] = min(dp[i + 4], dp[i] + a[i + 3].first - a[i].first);
        if (i + 5 <= n)
            dp[i + 5] = min(dp[i + 5], dp[i] + a[i + 4].first - a[i].first);
    }
    vector<ll> team(n);
    ll cntteam = 0, num = 1;
    i = n + 1;
    /*for (j = 0; j <= n; j++)
        cout << dp[j] << " ";
    cout << endl;*/
    while (i != 1)
    {
        cout << i << endl;
        if (i - 4 >= 0 && dp[i - 4] + a[i - 2].first - a[i - 4].first == dp[i - 1])
            next = i - 3;
        if (i - 5 >= 0 && dp[i - 5] + a[i - 2].first - a[i - 5].first == dp[i - 1])
            next = i - 4;
        if (i - 6 >= 0 && dp[i - 6] + a[i - 2].first - a[i - 6].first == dp[i - 1])
            next = i - 5;
        for (j = i - 2; j >= next - 1; j--)
            team[a[j].second] = num;
        cntteam++;
        num++;
        i = next;
    }
    cout << dp[n] << " " << cntteam << endl;
    for (i = 0; i < n; i++)
        cout << team[i] << " ";
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

ll dp[200007];
ll INF = 2 * 1e18 - 1;

int main()
{
    ios::sync_with_stdio(0);
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    ll i, n, c, j, next;
    cin >> n;
    vector<pair<ll, ll>> a(n);
    for (i = 0; i < n; i++)
    {
        cin >> c;
        a[i] = {c, i};
    }
    sort(a.begin(), a.end());
    for (i = 1; i <= n; i++)
        dp[i] = INF;
    for (i = 0; i <= n; i++)
    {
        if (i + 3 <= n)
            dp[i + 3] = min(dp[i + 3], dp[i] + a[i + 2].first - a[i].first);
        if (i + 4 <= n)
            dp[i + 4] = min(dp[i + 4], dp[i] + a[i + 3].first - a[i].first);
        if (i + 5 <= n)
            dp[i + 5] = min(dp[i + 5], dp[i] + a[i + 4].first - a[i].first);
    }
    vector<ll> team(n);
    ll cntteam = 0, num = 1;
    i = n + 1;
    /*for (j = 0; j <= n; j++)
        cout << dp[j] << " ";
    cout << endl;*/
    while (i != 1)
    {
        if (i - 4 >= 0 && dp[i - 4] + a[i - 2].first - a[i - 4].first == dp[i - 1])
            next = i - 3;
        if (i - 5 >= 0 && dp[i - 5] + a[i - 2].first - a[i - 5].first == dp[i - 1])
            next = i - 4;
        if (i - 6 >= 0 && dp[i - 6] + a[i - 2].first - a[i - 6].first == dp[i - 1])
            next = i - 5;
        for (j = i - 1; j >= next; j--)
            team[a[j].second] = num;
        cntteam++;
        num++;
        i = next;
    }
    cout << dp[n] << " " << cntteam << endl;
    for (i = 0; i < n; i++)
        cout << team[i] << " ";
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

ll dp[200007];
ll INF = 2 * 1e18 - 1;

int main()
{
    ios::sync_with_stdio(0);
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    ll i, n, c, j, next;
    cin >> n;
    vector<pair<ll, ll>> a(n);
    for (i = 0; i < n; i++)
    {
        cin >> c;
        a[i] = {c, i};
    }
    sort(a.begin(), a.end());
    for (i = 1; i <= n; i++)
        dp[i] = INF;
    for (i = 0; i <= n; i++)
    {
        dp[i + 3] = min(dp[i + 3], dp[i] + a[i + 2].first - a[i].first);
        dp[i + 4] = min(dp[i + 4], dp[i] + a[i + 3].first - a[i].first);
        dp[i + 5] = min(dp[i + 5], dp[i] + a[i + 4].first - a[i].first);
    }
    vector<ll> team(n);
    ll cntteam = 0, num = 1;
    i = n + 1;
    for (j = 0; j <= n; j++)
        cout << dp[j] << " ";
    cout << endl;
    while (i != 1)
    {
        if (i - 4 >= 0 && dp[i - 4] + a[i - 2].first - a[i - 4].first == dp[i - 1])
            next = i - 3;
        if (i - 5 >= 0 && dp[i - 5] + a[i - 2].first - a[i - 5].first == dp[i - 1])
            next = i - 4;
        if (i - 6 >= 0 && dp[i - 6] + a[i - 2].first - a[i - 6].first == dp[i - 1])
            next = i - 5;
        for (j = i - 1; j >= next; j--)
            team[a[j].second] = num;
        cntteam++;
        num++;
        i = next;
    }
    cout << dp[n] << " " << cntteam << endl;
    for (i = 0; i < n; i++)
        cout << team[i] << " ";

}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

ll dp[200007];
ll INF = 2 * 1e18 - 1;

int main()
{
    ios::sync_with_stdio(0);
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    ll i, n, c, j, next;
    cin >> n;
    vector<pair<ll, ll>> a(n);
    for (i = 0; i < n; i++)
    {
        cin >> c;
        a[i] = {c, i};
    }
    sort(a.begin(), a.end());
    for (i = 1; i <= n; i++)
        dp[i] = INF;
    for (i = 0; i <= n; i++)
    {
        if (i + 3 <= n)
            dp[i + 3] = min(dp[i + 3], dp[i] + a[i + 2].first - a[i].first);
        if (i + 4 <= n)
            dp[i + 4] = min(dp[i + 4], dp[i] + a[i + 3].first - a[i].first);
        if (i + 5 <= n)
            dp[i + 5] = min(dp[i + 5], dp[i] + a[i + 4].first - a[i].first);
    }
    vector<ll> team(n);
    ll cntteam = 0, num = 1;
    i = n + 1;
    /*for (j = 0; j <= n; j++)
        cout << dp[j] << " ";
    cout << endl;*/
    while (i != 1)
    {
        //cout << i << endl;
        if (i - 4 >= 0 && dp[i - 4] + a[i - 2].first - a[i - 4].first == dp[i - 1])
            next = i - 3;
        if (i - 5 >= 0 && dp[i - 5] + a[i - 2].first - a[i - 5].first == dp[i - 1])
            next = i - 4;
        if (i - 6 >= 0 && dp[i - 6] + a[i - 2].first - a[i - 6].first == dp[i - 1])
            next = i - 5;
        for (j = i - 2; j >= next - 1; j--)
            team[a[j].second] = num;
        cntteam++;
        num++;
        i = next;
    }
    cout << dp[n] << " " << cntteam << endl;
    for (i = 0; i < n; i++)
        cout << team[i] << " ";
}


#include<algorithm>
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
typedef long long ll;
const int maxn = 200000 + 5;
struct stu{
    int id;
    int teamnum;
    int team;
    int adc;
};
stu st[maxn];
ll dp[maxn]; // dp[i] 代表前i个学生分组后最小diversity
bool cmp1(stu& s1, stu& s2){
    return s1.adc < s2.adc;
}
bool cmp2(stu &s1, stu& s2){
    return s1.id < s2.id;
}

int main()
{
    int n;
    scanf("%d", &n);
    for(int i=0; i<n; i++){
        scanf("%d", &st[i].adc);
        st[i].id = i;
    }
    for(int i=0; i<n; i++) dp[i] = 1000000000;
    sort(st, st+n, cmp1);
    dp[0] = dp[1] = 0;
    dp[2] = st[2].adc - st[0].adc; st[2].teamnum = 3;
    if(n>=3) dp[3] = st[3].adc - st[0].adc; st[3].teamnum = 4;
    if(n>=4) dp[4] = st[4].adc - st[0].adc; st[4].teamnum = 5;
    for(int i=5; i<n; i++){
        if(i-3>=2){
            if(dp[i] > dp[i-3]+st[i].adc - st[i-2].adc){
                dp[i] = dp[i-3]+st[i].adc - st[i-2].adc;
                st[i].teamnum = 3;
            }
        }
        if(i-4>=2){
            if(dp[i] > dp[i-4]+st[i].adc - st[i-3].adc){
                dp[i] = dp[i-4]+st[i].adc - st[i-3].adc;
                st[i].teamnum = 4;
            }
        }
        if(i-5>=2){
            if(dp[i] > dp[i-5]+st[i].adc - st[i-4].adc){
                dp[i] = dp[i-5]+st[i].adc - st[i-4].adc;
                st[i].teamnum = 5;
            }
        }
    }
    cout<<dp[n-1];

    int ct = 1;
    for(int i=n-1; i>=0;){
        int cnt = st[i].teamnum;
        for(int j=0; j<cnt; j++){
            st[i-j].team = ct;
        }
        i -= cnt;
        ct++;
    }
    printf(" %d\n", ct-1);
    sort(st, st+n, cmp2);
    for(int i=0; i<n-1; i++){
        printf("%d ", st[i].team);
    }
    printf("%d\n", st[n-1].team);

    return 0;
}


#include<algorithm>
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
typedef long long ll;
const int maxn = 200000 + 5;
struct stu{
    int id;
    int teamnum;
    int team;
    int adc;
};
stu st[maxn];
ll dp[maxn]; // dp[i] 代表前i个学生分组后最小diversity
bool cmp1(stu& s1, stu& s2){
    return s1.adc < s2.adc;
}
bool cmp2(stu &s1, stu& s2){
    return s1.id < s2.id;
}

int main()
{
    int n;
    scanf("%d", &n);
    for(int i=0; i<n; i++){
        scanf("%d", &st[i].adc);
        st[i].id = i;
    }
    for(int i=0; i<n; i++) dp[i] = maxn + 1;
    sort(st, st+n, cmp1);
    dp[0] = dp[1] = 0;
    dp[2] = st[2].adc - st[0].adc; st[2].teamnum = 3;
    if(n>=3) dp[3] = st[3].adc - st[0].adc; st[3].teamnum = 4;
    if(n>=4) dp[4] = st[4].adc - st[0].adc; st[4].teamnum = 5;
    for(int i=5; i<n; i++){
        if(i-3>=2){
            if(dp[i] > dp[i-3]+st[i].adc - st[i-2].adc){
                dp[i] = dp[i-3]+st[i].adc - st[i-2].adc;
                st[i].teamnum = 3;
            }
        }
        if(i-4>=2){
            if(dp[i] > dp[i-4]+st[i].adc - st[i-3].adc){
                dp[i] = dp[i-4]+st[i].adc - st[i-3].adc;
                st[i].teamnum = 4;
            }
        }
        if(i-5>=2){
            if(dp[i] > dp[i-5]+st[i].adc - st[i-4].adc){
                dp[i] = dp[i-5]+st[i].adc - st[i-4].adc;
                st[i].teamnum = 5;
            }
        }
    }
    cout<<dp[n-1];

    int ct = 1;
    for(int i=n-1; i>=0;){
        int cnt = st[i].teamnum;
        for(int j=0; j<cnt; j++){
            st[i-j].team = ct;
        }
        i -= cnt;
        ct++;
    }
    printf(" %d\n", ct-1);
    sort(st, st+n, cmp2);
    for(int i=0; i<n-1; i++){
        printf("%d ", st[i].team);
    }
    printf("%d\n", st[n-1].team);

    return 0;
}


#include<algorithm>
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 5;
struct stu{
    int id;
    int teamnum;
    int team;
    int adc;
};
stu st[maxn];
ll dp[maxn]; // dp[i] 代表前i个学生分组后最小diversity
bool cmp1(stu& s1, stu& s2){
    return s1.adc < s2.adc;
}
bool cmp2(stu &s1, stu& s2){
    return s1.id < s2.id;
}

int main()
{
    int n;
    scanf("%d", &n);
    for(int i=0; i<n; i++){
        scanf("%d", &st[i].adc);
        st[i].id = i;
    }
    for(int i=0; i<n; i++) dp[i] = maxn + 1;
    sort(st, st+n, cmp1);
    dp[0] = dp[1] = 0;
    dp[2] = st[2].adc - st[0].adc; st[2].teamnum = 3;
    if(n>=3) dp[3] = st[3].adc - st[0].adc; st[3].teamnum = 4;
    if(n>=4) dp[4] = st[4].adc - st[0].adc; st[4].teamnum = 5;
    for(int i=5; i<n; i++){
        if(i-3>=2){
            if(dp[i] > dp[i-3]+st[i].adc - st[i-2].adc){
                dp[i] = dp[i-3]+st[i].adc - st[i-2].adc;
                st[i].teamnum = 3;
            }
        }
        if(i-4>=2){
            if(dp[i] > dp[i-4]+st[i].adc - st[i-3].adc){
                dp[i] = dp[i-4]+st[i].adc - st[i-3].adc;
                st[i].teamnum = 4;
            }
        }
        if(i-5>=2){
            if(dp[i] > dp[i-5]+st[i].adc - st[i-4].adc){
                dp[i] = dp[i-5]+st[i].adc - st[i-4].adc;
                st[i].teamnum = 5;
            }
        }
    }
    cout<<dp[n-1];

    int ct = 1;
    for(int i=n-1; i>=0;){
        int cnt = st[i].teamnum;
        for(int j=0; j<cnt; j++){
            st[i-j].team = ct;
        }
        i -= cnt;
        ct++;
    }
    printf(" %d\n", ct-1);
    sort(st, st+n, cmp2);
    for(int i=0; i<n-1; i++){
        printf("%d ", st[i].team);
    }
    printf("%d\n", st[n-1].team);

    return 0;
}


#include<algorithm>
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 5;
struct stu{
    ll id;
    ll teamnum;
    ll team;
    ll adc;
};
stu st[maxn];
ll dp[maxn]; // dp[i] 代表前i个学生分组后最小diversity
bool cmp1(stu& s1, stu& s2){
    return s1.adc < s2.adc;
}
bool cmp2(stu &s1, stu& s2){
    return s1.id < s2.id;
}

int main()
{
    int n;
    scanf("%d", &n);
    for(int i=0; i<n; i++){
        scanf("%I64d", &st[i].adc);
        st[i].id = i;
    }
    for(int i=0; i<n; i++) dp[i] = maxn + 1;
    sort(st, st+n, cmp1);
    dp[0] = dp[1] = 0;
    dp[2] = st[2].adc - st[0].adc; st[2].teamnum = 3;
    if(n>=3) dp[3] = st[3].adc - st[0].adc; st[3].teamnum = 4;
    if(n>=4) dp[4] = st[4].adc - st[0].adc; st[4].teamnum = 5;
    for(int i=5; i<n; i++){
        if(i-3>=2){
            if(dp[i] > dp[i-3]+st[i].adc - st[i-2].adc){
                dp[i] = dp[i-3]+st[i].adc - st[i-2].adc;
                st[i].teamnum = 3;
            }
        }
        if(i-4>=2){
            if(dp[i] > dp[i-4]+st[i].adc - st[i-3].adc){
                dp[i] = dp[i-4]+st[i].adc - st[i-3].adc;
                st[i].teamnum = 4;
            }
        }
        if(i-5>=2){
            if(dp[i] > dp[i-5]+st[i].adc - st[i-4].adc){
                dp[i] = dp[i-5]+st[i].adc - st[i-4].adc;
                st[i].teamnum = 5;
            }
        }
    }
    cout<<dp[n-1];

    int ct = 1;
    for(int i=n-1; i>=0;){
        int cnt = st[i].teamnum;
        for(int j=0; j<cnt; j++){
            st[i-j].team = ct;
        }
        i -= cnt;
        ct++;
    }
    printf(" %d\n", ct-1);
    sort(st, st+n, cmp2);
    for(int i=0; i<n-1; i++){
        printf("%I64d ", st[i].team);
    }
    printf("%I64d\n", st[n-1].team);

    return 0;
}


#include<algorithm>
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 5;
struct stu{
    ll id;
    ll teamnum;
    ll team;
    ll adc;
};
stu st[maxn];
ll dp[maxn]; // dp[i] 代表前i个学生分组后最小diversity
bool cmp1(stu& s1, stu& s2){
    return s1.adc < s2.adc;
}
bool cmp2(stu &s1, stu& s2){
    return s1.id < s2.id;
}

int main()
{
    int n;
    cin>>n;
    for(int i=0; i<n; i++){
        cin>>st[i].adc;
        st[i].id = i;
    }
    for(int i=0; i<n; i++) dp[i] = maxn + 1;
    sort(st, st+n, cmp1);
    dp[0] = dp[1] = 0;
    dp[2] = st[2].adc - st[0].adc; st[2].teamnum = 3;
    if(n>=3) dp[3] = st[3].adc - st[0].adc; st[3].teamnum = 4;
    if(n>=4) dp[4] = st[4].adc - st[0].adc; st[4].teamnum = 5;
    for(int i=5; i<n; i++){
        if(i-3>=2){
            if(dp[i] > dp[i-3]+st[i].adc - st[i-2].adc){
                dp[i] = dp[i-3]+st[i].adc - st[i-2].adc;
                st[i].teamnum = 3;
            }
        }
        if(i-4>=2){
            if(dp[i] > dp[i-4]+st[i].adc - st[i-3].adc){
                dp[i] = dp[i-4]+st[i].adc - st[i-3].adc;
                st[i].teamnum = 4;
            }
        }
        if(i-5>=2){
            if(dp[i] > dp[i-5]+st[i].adc - st[i-4].adc){
                dp[i] = dp[i-5]+st[i].adc - st[i-4].adc;
                st[i].teamnum = 5;
            }
        }
    }
    cout<<dp[n-1];

    int ct = 1;
    for(int i=n-1; i>=0;){
        int cnt = st[i].teamnum;
        for(int j=0; j<cnt; j++){
            st[i-j].team = ct;
        }
        i -= cnt;
        ct++;
    }
    cout<<" "<<ct-1<<endl;
    sort(st, st+n, cmp2);
    for(int i=0; i<n-1; i++){
        cout<<st[i].team<<" ";
    }
    cout<<st[n-1].team<<endl;

    return 0;
}


#include <bits/stdc++.h>
#define ll long long int
#define FASTIO std::ios::sync_with_stdio(false);
#define pb push_back
#define mp make_pair
#define ld long double
#define F first
#define S second
#define input_from_file  freopen("input.txt", "r", stdin);
using namespace std;
#define inf 1000000000000
ll dp[200005];
ll ans[200005];
ll sol[200005];

int main()
{
FASTIO
// input_from_file

ll n;
cin >> n;

vector<pair<ll, ll>> v;
for(ll i = 0; i < n; i++){
  ll x;
  cin >> x;
  v.pb(mp(x, i));
}

sort(v.begin(), v.end());

for(ll i = 1; i <= n; i++){
  dp[i] = inf;
  ans[i] = -1;
}

for(ll i = 0; i < n; i++){
  for(ll j = 3; j <= 5 && i + j <= n; j++){
    ll x = v[i + j - 1].F - v[i].F;
    if(dp[i + j] > dp[i] + x){
      dp[i + j] = dp[i] + x;
      ans[i + j] = i;
    }
  }
}

ll curr = n;
ll cnt = 0;

while(curr != 0){
  for(ll i = curr - 1; i >= ans[curr]; i--){
    sol[v[i].S] = cnt;
  }
  cnt++;
  curr = ans[curr];
}

cout << dp[n] << " " << cnt << endl;
for(ll i = 0; i < n; i++){
  cout << sol[i] + 1 << " ";
}
}


#include <bits/stdc++.h>
#define ll long long int
#define FASTIO std::ios::sync_with_stdio(false);
#define pb push_back
#define mp make_pair
#define ld long double
#define F first
#define S second
#define input_from_file  freopen("input.txt", "r", stdin);
using namespace std;
#define inf 1000000000000

int main()
{
FASTIO
// input_from_file

ll n;
cin >> n;

vector<pair<ll, ll>> v;
for(ll i = 0; i < n; i++){
  ll x;
  cin >> x;
  v.pb(mp(x, i));
}

sort(v.begin(), v.end());
ll dp[n];
ll ans[n];
dp[0] = 0;
dp[1] = 0;
dp[2] = v[2].F - v[0].F;
for(ll i = 3; i <= n; i++){
  dp[i] = inf;
  ans[i] = -1;
}

for(ll i = 0; i < n; i++){
  for(ll j = 3; j <= 5 && i + j <= n; j++){
    ll x = v[i + j - 1].F - v[i].F;
    if(dp[i + j] > dp[i] + x){
      dp[i + j] = dp[i] + x;
      ans[i + j] = i;
    }
  }
}

ll curr = n;
ll cnt = 0;
ll sol[n];

// for(ll i = 0; i <= n; i++){
//   cout << dp[i] << " ";
// }
// exit(0);

while(curr != 0){
  for(ll i = curr - 1; i >= ans[curr]; i--){
    sol[v[i].S] = cnt;
  }
  cnt++;
  curr = ans[curr];
}

cout << dp[n] << " " << cnt << endl;
for(ll i = 0; i < n; i++){
  cout << sol[i] + 1 << " ";
}
}


#include <bits/stdc++.h>
#define ll long long int
#define FASTIO std::ios::sync_with_stdio(false);
#define pb push_back
#define mp make_pair
#define ld long double
#define F first
#define S second
#define input_from_file  freopen("input.txt", "r", stdin);
using namespace std;
#define inf 1000000000000

int main()
{
FASTIO
// input_from_file

ll n;
cin >> n;

vector<pair<ll, ll>> v;
for(ll i = 0; i < n; i++){
  ll x;
  cin >> x;
  v.pb(mp(x, i));
}

sort(v.begin(), v.end());
ll dp[n + 1];
ll ans[n + 1];
dp[0] = 0;
dp[1] = 0;
dp[2] = v[2].F - v[0].F;
for(ll i = 3; i <= n; i++){
  dp[i] = inf;
  ans[i] = -1;
}

for(ll i = 0; i < n; i++){
  for(ll j = 3; j <= 5 && i + j <= n; j++){
    ll x = v[i + j - 1].F - v[i].F;
    if(dp[i + j] > dp[i] + x){
      dp[i + j] = dp[i] + x;
      ans[i + j] = i;
    }
  }
}

ll curr = n;
ll cnt = 0;
ll sol[n];

// for(ll i = 0; i <= n; i++){
//   cout << dp[i] << " ";
// }
// exit(0);

while(curr != 0){
  for(ll i = curr - 1; i >= ans[curr]; i--){
    sol[v[i].S] = cnt;
  }
  cnt++;
  curr = ans[curr];
}

cout << dp[n] << " " << cnt << endl;
for(ll i = 0; i < n; i++){
  cout << sol[i] + 1 << " ";
}
}


#include <iostream>
#include <vector>
#include <algorithm>

#define all(v) (v).begin(), (v).end()
using namespace std;

struct programmer
{
    int level, index;

    programmer(){}
};

int sort_by_level(programmer &A, programmer &B)
{
    return (A.level < B.level);
}

int main()
{
    int no_of_elements;
    cin >> no_of_elements;

    vector <programmer> P(no_of_elements);
    for(int i = 0; i < no_of_elements; i++)
    {
        cin >> P[i].level;

        P[i].index = i;
    }

    sort(all(P), sort_by_level);

    vector <int> minimum_diversity(no_of_elements);
    for(int i = 0; i < no_of_elements; i++)
    {
        if(i < 5)
        {
            minimum_diversity[i] = P[i].level - P[0].level;

            continue;
        }

        minimum_diversity[i] = P[i].level - P[i - 2].level + minimum_diversity[i - 3];
        for(int j = i - 2; j >= i - 4; j--)
        {
            minimum_diversity[i] = min(minimum_diversity[i],
                                       P[i].level - P[j].level + minimum_diversity[j - 1]);
        }
    }

    int last_team = 0;
    vector <int> team_no(no_of_elements);
    for(int i = no_of_elements - 1; i >= 0; i--)
    {
        int team_ending;

        for(int j = max(i - 4, 0); j <= i - 2; j++)
        {
            if(minimum_diversity[i] == P[i].level - P[j].level + minimum_diversity[j - 1])
            {
                team_ending = j;
                break;
            }
        }

        last_team++;
        for(int j = team_ending; j <= i; j++)
        {
            team_no[P[j].index] = last_team;
        }

        i = team_ending;
    }

    cout << minimum_diversity[no_of_elements - 1] << " " << last_team << "\n";
    for(int i = 0; i < no_of_elements; i++)
    {
        cout << team_no[i] << " ";
    }
    cout << "\n";
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>

#define all(v) (v).begin(), (v).end()
using namespace std;

struct element
{
    int value, original_position, part_number;

    element()
    {
        value = 0;
    };

    int operator <(const element &E)
    {
        return (value < E.value);
    }
};

int main()
{
    int number_of_elements;
    cin >> number_of_elements;

    vector <element> A(number_of_elements + 1);
    for(int i = 1; i <= number_of_elements; i++)
    {
        int x;
        cin >> x;

        A[i].value = x;
        A[i].original_position = i;
    }

    sort(all(A));

    if(number_of_elements <= 5)
    {
        cout << A[number_of_elements].value - A[1].value << " 1\n";

        for(int i = 1; i <= number_of_elements; i++)
        {
            cout << "1 ";
        }

        return 0;
    }

    vector <long long> answer(number_of_elements + 1);

    const int oo = 1e18;
    vector <long long> best_suffix(number_of_elements + 1, oo);
    for(int i = 1; i <= number_of_elements; i++)
    {
        if(i - 2 >= 3)
        {
            answer[i] = A[i].value + best_suffix[i - 2];
        }
        else
        {
            if(i == 1)
            {
                answer[i] = 0;
            }
            else
            {
                answer[i] = A[i].value - A[1].value;
            }

            best_suffix[i] = -A[1].value;
        }

        best_suffix[i] = min(best_suffix[i - 1], -A[i].value + answer[i - 1]);
        //cout << A[i].value << " Answer " << i << " = " << answer[i] << " and best suffix = " << best_suffix[i] << "\n";
    }

    int last = number_of_elements, sum = answer[number_of_elements];
    A[number_of_elements].part_number = 1;
    for(int i = number_of_elements - 1; i >= 1; i--)
    {
        if(A[last].value - A[i + 1].value + answer[i] == sum && (last - i >= 3 && i >= 3))
        {
            A[i].part_number = A[last].part_number + 1;

            sum -= (A[last].value - A[i + 1].value);

            last = i;
        }
        else
        {
            A[i].part_number = A[last].part_number;
        }
    }

    vector <int> part_alloted(number_of_elements + 1);
    for(int i = 1; i <= number_of_elements; i++)
    {
        part_alloted[A[i].original_position] = A[i].part_number;
    }

    cout << answer[number_of_elements] << " " << A[1].part_number << "\n";
    for(int i = 1; i <= number_of_elements; i++)
    {
        cout << part_alloted[i] << " ";
    }

    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>

#define all(v) (v).begin(), (v).end()
using namespace std;

struct element
{
    int value, original_position, part_number;

    element()
    {
        value = 0;
    };

    int operator <(const element &E)
    {
        return (value < E.value);
    }
};

int main()
{
    int number_of_elements;
    cin >> number_of_elements;

    vector <element> A(number_of_elements + 1);
    for(int i = 1; i <= number_of_elements; i++)
    {
        int x;
        cin >> x;

        A[i].value = x;
        A[i].original_position = i;
    }

    sort(all(A));

    if(number_of_elements <= 5)
    {
        cout << A[number_of_elements].value - A[1].value << " 1\n";

        for(int i = 1; i <= number_of_elements; i++)
        {
            cout << "1 ";
        }

        return 0;
    }

    vector <int> answer(number_of_elements + 1);

    const int oo = 1e9;
    vector <int> best_suffix(number_of_elements + 1, oo);
    for(int i = 1; i <= number_of_elements; i++)
    {
        if(i - 2 >= 3)
        {
            answer[i] = A[i].value + best_suffix[i - 2];
        }
        else
        {
            if(i == 1)
            {
                answer[i] = 0;
            }
            else
            {
                answer[i] = A[i].value - A[1].value;
            }

            best_suffix[i] = -A[1].value;
        }

        best_suffix[i] = min(best_suffix[i - 1], -A[i].value + answer[i - 1]);
        //cout << A[i].value << " Answer " << i << " = " << answer[i] << " and best suffix = " << best_suffix[i] << "\n";
    }

    int last = number_of_elements, sum = answer[number_of_elements];
    A[number_of_elements].part_number = 1;
    for(int i = number_of_elements - 1; i >= 1; i--)
    {
        if(A[last].value - A[i + 1].value + answer[i] == sum && A[i + 1].value != A[i].value)
        {
            A[i].part_number = A[last].part_number + 1;

            sum -= (A[last].value - A[i + 1].value);

            last = i;
        }
        else
        {
            A[i].part_number = A[last].part_number;
        }
    }

    vector <int> part_alloted(number_of_elements + 1);
    for(int i = 1; i <= number_of_elements; i++)
    {
        part_alloted[A[i].original_position] = A[i].part_number;
    }

    cout << answer[number_of_elements] << " " << A[1].part_number << "\n";
    for(int i = 1; i <= number_of_elements; i++)
    {
        cout << part_alloted[i] << " ";
    }

    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>

#define all(v) (v).begin(), (v).end()
using namespace std;

struct element
{
    int value, original_position, part_number;

    element()
    {
        value = 0;
    };

    int operator <(const element &E)
    {
        return (value < E.value);
    }
};

int main()
{
    int number_of_elements;
    cin >> number_of_elements;

    vector <element> A(number_of_elements + 1);
    for(int i = 1; i <= number_of_elements; i++)
    {
        int x;
        cin >> x;

        A[i].value = x;
        A[i].original_position = i;
    }

    sort(all(A));

    if(number_of_elements <= 5)
    {
        cout << A[number_of_elements].value - A[1].value << " 1\n";

        for(int i = 1; i <= number_of_elements; i++)
        {
            cout << "1 ";
        }

        return 0;
    }

    vector <int> answer(number_of_elements + 1);

    const int oo = 1e9;
    vector <int> best_suffix(number_of_elements + 1, oo);
    for(int i = 1; i <= number_of_elements; i++)
    {
        if(i - 2 >= 3)
        {
            answer[i] = A[i].value + best_suffix[i - 2];
        }
        else
        {
            if(i == 1)
            {
                answer[i] = 0;
            }
            else
            {
                answer[i] = A[i].value - A[1].value;
            }

            best_suffix[i] = -A[1].value;
        }

        best_suffix[i] = min(best_suffix[i - 1], -A[i].value + answer[i - 1]);
        //cout << A[i].value << " Answer " << i << " = " << answer[i] << " and best suffix = " << best_suffix[i] << "\n";
    }

    int last = number_of_elements, sum = answer[number_of_elements];
    A[number_of_elements].part_number = 1;
    for(int i = number_of_elements - 1; i >= 1; i--)
    {
        if(A[last].value - A[i + 1].value + answer[i] == sum && (last - i >= 3))
        {
            A[i].part_number = A[last].part_number + 1;

            sum -= (A[last].value - A[i + 1].value);

            last = i;
        }
        else
        {
            A[i].part_number = A[last].part_number;
        }
    }

    vector <int> part_alloted(number_of_elements + 1);
    for(int i = 1; i <= number_of_elements; i++)
    {
        part_alloted[A[i].original_position] = A[i].part_number;
    }

    cout << answer[number_of_elements] << " " << A[1].part_number << "\n";
    for(int i = 1; i <= number_of_elements; i++)
    {
        cout << part_alloted[i] << " ";
    }

    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>

#define all(v) (v).begin(), (v).end()
using namespace std;

struct programmer
{
    int level, index;

    programmer(){}
};

int sort_by_level(programmer &A, programmer &B)
{
    return (A.level < B.level);
}

int main()
{
    int no_of_elements;
    cin >> no_of_elements;

    vector <programmer> P(no_of_elements);
    for(int i = 0; i < no_of_elements; i++)
    {
        cin >> P[i].level;

        P[i].index = i;
    }

    sort(all(P), sort_by_level);

    vector <long long> minimum_diversity(no_of_elements);
    for(int i = 0; i < no_of_elements; i++)
    {
        if(i < 5)
        {
            minimum_diversity[i] = P[i].level - P[0].level;

            continue;
        }

        minimum_diversity[i] = P[i].level - P[i - 2].level + minimum_diversity[i - 3];
        for(int j = i - 2; j >= i - 4; j--)
        {
            minimum_diversity[i] = min(minimum_diversity[i],
                                       P[i].level - P[j].level + minimum_diversity[j - 1]);
        }
    }

    int last_team = 0;
    vector <int> team_no(no_of_elements);
    for(int i = no_of_elements - 1; i > 0; i--)
    {
        int team_ending = (i >= 5 ? i - 2 : 0);

        for(int j = max(i - 4, 0); j <= i - 2 && i > 5; j++)
        {
            if(minimum_diversity[i] == P[i].level - P[j].level + minimum_diversity[j - 1])
            {
                team_ending = j;
                break;
            }
        }

        last_team++;
        for(int j = team_ending; j <= i; j++)
        {
            team_no[P[j].index] = last_team;
        }

        i = team_ending;
    }

    cout << minimum_diversity[no_of_elements - 1] << " " << last_team << "\n";
    for(int i = 0; i < no_of_elements; i++)
    {
        cout << team_no[i] << " ";
    }
    cout << "\n";
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>

#define all(v) (v).begin(), (v).end()
using namespace std;

struct element
{
    int value, original_position, part_number;

    element()
    {
        value = 0;
    };

    int operator <(const element &E)
    {
        return (value < E.value);
    }
};

int main()
{
    int number_of_elements;
    cin >> number_of_elements;

    vector <element> A(number_of_elements + 1);
    for(int i = 1; i <= number_of_elements; i++)
    {
        int x;
        cin >> x;

        A[i].value = x;
        A[i].original_position = i;
    }

    sort(all(A));

    if(number_of_elements <= 5)
    {
        cout << A[number_of_elements].value - A[1].value << " 1\n";

        for(int i = 1; i <= number_of_elements; i++)
        {
            cout << "1 ";
        }

        return 0;
    }

    vector <int> answer(number_of_elements + 1);

    const int oo = 1e9;
    vector <int> best_suffix(number_of_elements + 1, oo);
    for(int i = 1; i <= number_of_elements; i++)
    {
        if(i - 2 >= 3)
        {
            answer[i] = A[i].value + best_suffix[i - 2];
        }
        else
        {
            if(i == 1)
            {
                answer[i] = 0;
            }
            else
            {
                answer[i] = A[i].value - A[1].value;
            }

            best_suffix[i] = -A[1].value;
        }

        best_suffix[i] = min(best_suffix[i - 1], -A[i].value + answer[i - 1]);
        //cout << A[i].value << " Answer " << i << " = " << answer[i] << " and best suffix = " << best_suffix[i] << "\n";
    }

    int last = number_of_elements, sum = answer[number_of_elements];
    A[number_of_elements].part_number = 1;
    for(int i = number_of_elements - 1; i >= 1; i--)
    {
        if(A[last].value - A[i + 1].value + answer[i] == sum && (last - i >= 3 && i >= 3))
        {
            A[i].part_number = A[last].part_number + 1;

            sum -= (A[last].value - A[i + 1].value);

            last = i;
        }
        else
        {
            A[i].part_number = A[last].part_number;
        }
    }

    vector <int> part_alloted(number_of_elements + 1);
    for(int i = 1; i <= number_of_elements; i++)
    {
        part_alloted[A[i].original_position] = A[i].part_number;
    }

    cout << answer[number_of_elements] << " " << A[1].part_number << "\n";
    for(int i = 1; i <= number_of_elements; i++)
    {
        cout << part_alloted[i] << " ";
    }

    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>

#define all(v) (v).begin(), (v).end()
using namespace std;

struct programmer
{
    int level, index;

    programmer()
    {
        level = 0; index = 0;
    }
};

int sort_by_level(programmer &A, programmer &B)
{
    return (A.level < B.level);
}

int main()
{
    int no_of_elements;
    cin >> no_of_elements;

    vector <programmer> P(no_of_elements + 1);
    for(int i = 1; i <= no_of_elements; i++)
    {
        cin >> P[i].level;

        P[i].index = i;
    }

    sort(all(P), sort_by_level);

    vector <long long> minimum_diversity(no_of_elements + 1);
    for(int i = 1; i <= no_of_elements; i++)
    {
        if(i <= 5)
        {
            minimum_diversity[i] = P[i].level - P[1].level;

            continue;
        }

        minimum_diversity[i] = P[i].level - P[i - 2].level + minimum_diversity[i - 3];
        for(int j = i - 2; j >= i - 4 && j - 1 >= 3; j--)
        {
            minimum_diversity[i] = min(minimum_diversity[i],
                                       P[i].level - P[j].level + minimum_diversity[j - 1]);
        }

        //cout << "F(" << i << ") = " << minimum_diversity[i] << "\n";
    }

    int last_team = 0;
    vector <int> team_no(no_of_elements + 1);
    for(int i = no_of_elements; i > 0; i--)
    {
        int team_ending = (i >= 6 ? i - 2 : 0);

        for(int j = i - 2; j >= i - 4 && j - 1 >= 3; j--)
        {
            if(minimum_diversity[i] == P[i].level - P[j].level + minimum_diversity[j - 1])
            {
                team_ending = j;
                break;
            }
        }

        last_team++;
        for(int j = team_ending; j <= i; j++)
        {
            team_no[P[j].index] = last_team;
        }

        i = team_ending;
    }

    cout << minimum_diversity[no_of_elements] << " " << last_team << "\n";
    for(int i = 1; i <= no_of_elements; i++)
    {
        cout << team_no[i] << " ";
    }
    cout << "\n";
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>

#define all(v) (v).begin(), (v).end()
using namespace std;

struct programmer
{
    int level, index;

    programmer()
    {
        level = 0; index = 0;
    }
};

int sort_by_level(programmer &A, programmer &B)
{
    return (A.level < B.level);
}

int main()
{
    int no_of_elements;
    cin >> no_of_elements;

    vector <programmer> P(no_of_elements + 1);
    for(int i = 1; i <= no_of_elements; i++)
    {
        cin >> P[i].level;

        P[i].index = i;
    }

    sort(all(P), sort_by_level);

    vector <long long> minimum_diversity(no_of_elements);
    for(int i = 1; i <= no_of_elements; i++)
    {
        if(i <= 5)
        {
            minimum_diversity[i] = P[i].level - P[1].level;

            continue;
        }

        minimum_diversity[i] = P[i].level - P[i - 2].level + minimum_diversity[i - 3];
        for(int j = i - 2; j >= i - 4; j--)
        {
            minimum_diversity[i] = min(minimum_diversity[i],
                                       P[i].level - P[j].level + minimum_diversity[j - 1]);
        }
    }

    int last_team = 0;
    vector <int> team_no(no_of_elements + 1);
    for(int i = no_of_elements; i > 0; i--)
    {
        int team_ending = (i >= 6 ? i - 2 : 0);

        for(int j = max(i - 4, 1); j <= i - 2 && i > 5; j++)
        {
            if(minimum_diversity[i] == P[i].level - P[j].level + minimum_diversity[j - 1])
            {
                team_ending = j;
                break;
            }
        }

        last_team++;
        for(int j = team_ending; j <= i; j++)
        {
            team_no[P[j].index] = last_team;
        }

        i = team_ending;
    }

    cout << minimum_diversity[no_of_elements] << " " << last_team << "\n";
    for(int i = 1; i <= no_of_elements; i++)
    {
        cout << team_no[i] << " ";
    }
    cout << "\n";
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>

#define all(v) (v).begin(), (v).end()
using namespace std;

struct element
{
    int value, original_position, part_number;

    element()
    {
        value = 0;
    };

    int operator <(const element &E)
    {
        return (value < E.value);
    }
};

int main()
{
    int number_of_elements;
    cin >> number_of_elements;

    vector <element> A(number_of_elements + 1);
    for(int i = 1; i <= number_of_elements; i++)
    {
        int x;
        cin >> x;

        A[i].value = x;
        A[i].original_position = i;
    }

    sort(all(A));

    if(number_of_elements <= 5)
    {
        cout << A[number_of_elements].value - A[1].value << " 1\n";

        for(int i = 1; i <= number_of_elements; i++)
        {
            cout << "1 ";
        }

        return 0;
    }

    const long long oo = 1e18;
    vector <long long> best_suffix(number_of_elements + 1, oo);
    vector <long long> answer(number_of_elements + 1, oo);
    for(int i = 1; i <= number_of_elements; i++)
    {
        if(i >= 3)
        {
            answer[i] = A[i].value + best_suffix[i - 2];
        }
        else
        {
            answer[i] = oo;

            best_suffix[i] = -A[1].value;
        }

        best_suffix[i] = min(best_suffix[i - 1], -A[i].value + answer[i - 1]);
        //cout << A[i].value << " Answer " << i << " = " << answer[i] << " and best suffix = " << best_suffix[i] << "\n";
    }

    int last = number_of_elements, sum = answer[number_of_elements];
    A[number_of_elements].part_number = 1;
    for(int i = number_of_elements - 1; i >= 1; i--)
    {
        if(A[last].value - A[i + 1].value + answer[i] == sum && (last - i >= 3 && i >= 3))
        {
            A[i].part_number = A[last].part_number + 1;

            sum -= (A[last].value - A[i + 1].value);

            last = i;
        }
        else
        {
            A[i].part_number = A[last].part_number;
        }
    }

    vector <int> part_alloted(number_of_elements + 1);
    for(int i = 1; i <= number_of_elements; i++)
    {
        part_alloted[A[i].original_position] = A[i].part_number;
    }

    cout << answer[number_of_elements] << " " << A[1].part_number << "\n";
    for(int i = 1; i <= number_of_elements; i++)
    {
        cout << part_alloted[i] << " ";
    }

    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>

#define all(v) (v).begin(), (v).end()
using namespace std;

struct element
{
    int value, original_position, part_number;

    element()
    {
        value = 0;
    };

    int operator <(const element &E)
    {
        return (value < E.value);
    }
};

int main()
{
    int number_of_elements;
    cin >> number_of_elements;

    vector <element> A(number_of_elements + 1);
    for(int i = 1; i <= number_of_elements; i++)
    {
        int x;
        cin >> x;

        A[i].value = x;
        A[i].original_position = i;
    }

    sort(all(A));

    if(number_of_elements <= 5)
    {
        cout << A[number_of_elements].value - A[1].value << " 1\n";

        for(int i = 1; i <= number_of_elements; i++)
        {
            cout << "1 ";
        }

        return 0;
    }

    vector <long long> answer(number_of_elements + 1);

    const long long oo = 1e18;
    vector <long long> best_suffix(number_of_elements + 1, oo);
    for(int i = 1; i <= number_of_elements; i++)
    {
        if(i >= 3)
        {
            answer[i] = A[i].value + best_suffix[i - 2];
        }
        else
        {
            if(i == 1)
            {
                answer[i] = 0;
            }
            else
            {
                answer[i] = A[i].value - A[1].value;
            }

            best_suffix[i] = -A[1].value;
        }

        best_suffix[i] = min(best_suffix[i - 1], -A[i].value + answer[i - 1]);
        //cout << A[i].value << " Answer " << i << " = " << answer[i] << " and best suffix = " << best_suffix[i] << "\n";
    }

    int last = number_of_elements, sum = answer[number_of_elements];
    A[number_of_elements].part_number = 1;
    for(int i = number_of_elements - 1; i >= 1; i--)
    {
        if(A[last].value - A[i + 1].value + answer[i] == sum && (last - i >= 3 && i >= 3))
        {
            A[i].part_number = A[last].part_number + 1;

            sum -= (A[last].value - A[i + 1].value);

            last = i;
        }
        else
        {
            A[i].part_number = A[last].part_number;
        }
    }

    vector <int> part_alloted(number_of_elements + 1);
    for(int i = 1; i <= number_of_elements; i++)
    {
        part_alloted[A[i].original_position] = A[i].part_number;
    }

    cout << answer[number_of_elements] << " " << A[1].part_number << "\n";
    for(int i = 1; i <= number_of_elements; i++)
    {
        cout << part_alloted[i] << " ";
    }

    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>

#define all(v) (v).begin(), (v).end()
using namespace std;

struct element
{
    int value, original_position, part_number;

    element()
    {
        value = 0;
    };

    int operator <(const element &E)
    {
        return (value < E.value);
    }
};

int main()
{
    int number_of_elements;
    cin >> number_of_elements;

    vector <element> A(number_of_elements + 1);
    for(int i = 1; i <= number_of_elements; i++)
    {
        int x;
        cin >> x;

        A[i].value = x;
        A[i].original_position = i;
    }

    sort(all(A));

    if(number_of_elements <= 5)
    {
        cout << A[number_of_elements].value - A[1].value << " 1\n";

        for(int i = 1; i <= number_of_elements; i++)
        {
            cout << "1 ";
        }

        return 0;
    }

    vector <long long> answer(number_of_elements + 1);

    const long long oo = 1e18;
    vector <long long> best_suffix(number_of_elements + 1, oo);
    for(int i = 1; i <= number_of_elements; i++)
    {
        if(i - 2 >= 3)
        {
            answer[i] = A[i].value + best_suffix[i - 2];
        }
        else
        {
            if(i == 1)
            {
                answer[i] = 0;
            }
            else
            {
                answer[i] = A[i].value - A[1].value;
            }

            best_suffix[i] = -A[1].value;
        }

        best_suffix[i] = min(best_suffix[i - 1], -A[i].value + answer[i - 1]);
        //cout << A[i].value << " Answer " << i << " = " << answer[i] << " and best suffix = " << best_suffix[i] << "\n";
    }

    int last = number_of_elements, sum = answer[number_of_elements];
    A[number_of_elements].part_number = 1;
    for(int i = number_of_elements - 1; i >= 1; i--)
    {
        if(A[last].value - A[i + 1].value + answer[i] == sum && (last - i >= 3 && i >= 3))
        {
            A[i].part_number = A[last].part_number + 1;

            sum -= (A[last].value - A[i + 1].value);

            last = i;
        }
        else
        {
            A[i].part_number = A[last].part_number;
        }
    }

    vector <int> part_alloted(number_of_elements + 1);
    for(int i = 1; i <= number_of_elements; i++)
    {
        part_alloted[A[i].original_position] = A[i].part_number;
    }

    cout << answer[number_of_elements] << " " << A[1].part_number << "\n";
    for(int i = 1; i <= number_of_elements; i++)
    {
        cout << part_alloted[i] << " ";
    }

    return 0;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e5 + 10;
pair<int, int>a[N];
pair<ll, int>dp[N];
int ans[N];
int cnt = 0;
int main(void) {
	std::ios::sync_with_stdio(false);
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {cin >> a[i].first; a[i].second = i;}
	sort(a + 1, a + 1 + n);
	for (int i = 3; i <= n; i++) {
		dp[i] = make_pair(1e18, 0);
		for (int j = (max(0, i - 5) ? max(3, i - 5) : 0); j <= (i - 3 < 3 ? 0 : i - 3); j++)
			dp[i] = min(dp[i], make_pair(dp[j].first + a[i].first - a[j + 1].first, j));
	}
	for (int i = n; i; i = dp[i].second)
		for (int j = (++cnt, dp[i].second + 1); j <= i; j++)
			ans[a[j].second] = cnt;
	cout << dp[n].first << ' ' << cnt << endl;
	for (int i = 1; i <= n; i++) cout << ans[i] << (i == n ? '\n' : ' ');
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e5 + 10;
struct str{
	int v;
	int p;
	int asc;
}a[N];
int dp[N];
bool cmpv(struct str n, struct str m) {return n.v < m.v;}
bool cmpp(struct str n, struct str m) {return n.p < m.p;}
int main(void) {
	std::ios::sync_with_stdio(false);
	int n;
	int res = 1;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i].v;
		a[i].p = i;
	}
	sort(a, a + n, cmpv);
	memset(dp, 0, sizeof(dp)), dp[0] = 0;
	for (int i = 1; i < n; i++) {
		dp[i] = dp[i - 1] + a[i].v - a[i - 1].v;
		for (int d = 3; d <= 5 && i - d >= 2; d++) {
			dp[i] = min(dp[i], dp[i - d] + a[i].v - a[i - d + 1].v);
		}
	}
	for (int i = n - 1; i >= 0;) {
		int d = 0;
		for (int j = 3; j <= 5 && i >= 5; j++)
			if (dp[i] == dp[i - j] + a[i].v - a[i - j + 1].v) d = j;
		if (d == 0) d = i + 1;
		int j = d; while (j--) a[i - j].asc =  res;
		res++, i -= d;
	}
	sort(a, a + n, cmpp);
	cout << dp[n - 1] << ' ' << res - 1 << endl;
	for (int i = 0; i < n; i++)
		cout << a[i].asc << ' ';
	cout << endl;
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e5 + 10;
pair<int, int>a[N];
pair<ll, int>dp[N];
int ans[N];
int cnt = 0;
int main(void) {
	std::ios::sync_with_stdio(false);
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {cin >> a[i].first; a[i].second = i;}
	sort(a + 1, a + 1 + n);
	for (int i = 3; i <= n; i++) {
		dp[i] = make_pair(1e18, 0);
		for (int j = max(0, i - 5); j <= i - 3; j++)
			dp[i] = min(dp[i], make_pair(dp[j].first + a[i].first - a[j + 1].first, j));
	}
	for (int i = n; i; i = dp[i].second)
		for (int j = (++cnt, dp[i].second + 1); j <= i; j++)
			ans[a[j].second] = cnt;
	cout << dp[n].first << ' ' << cnt << endl;
	for (int i = 1; i <= n; i++) cout << ans[i] << (i == n ? '\n' : ' ');
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e5 + 10;
struct str{
	int v;
	int p;
	int asc;
}a[N];
int dp[N];
bool cmpv(struct str n, struct str m) {return n.v < m.v;}
bool cmpp(struct str n, struct str m) {return n.p < m.p;}
int main(void) {
	std::ios::sync_with_stdio(false);
	int n;
	int res = 1;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i].v;
		a[i].p = i;
	}
	sort(a, a + n, cmpv);
	memset(dp, 0, sizeof(dp)), dp[0] = 0;
	for (int i = 1; i < n; i++) {
		dp[i] = dp[i - 1] + a[i].v - a[i - 1].v;
		for (int d = 3; d <= 5 && i - d >= 2; d++) {
			dp[i] = min(dp[i], dp[i - d] + a[i].v - a[i - d + 1].v);
		}
	}
	for (int i = n - 1; i >= 0;) {
		int d;
		for (int j = 3; j <= 5; j++)
			if (i - j >= 0 && dp[i] == dp[i - j] + a[i].v - a[i - j + 1].v) d = j;
		int j = d; while (j--) a[i - j].asc =  res;
		res++, i -= d;
	}
	sort(a, a + n, cmpp);
	cout << dp[n - 1] << ' ' << res - 1 << endl;
	for (int i = 0; i < n; i++)
		cout << a[i].asc << ' ';
	cout << endl;
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e5 + 10;
pair<int, int>a[N];
pair<ll, int>dp[N];
int ans[N];
int cnt = 0;
int main(void) {
	std::ios::sync_with_stdio(false);
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {cin >> a[i].first; a[i].second = i;}
	sort(a + 1, a + 1 + n);
	for (int i = 1; i <= n; i++) {
		dp[i] = make_pair(1e18, 0);
		for (int j = max(0, i - 5); j <= i - 3; j++)
			dp[i] = min(dp[i], make_pair(dp[j].first + a[i].first - a[j + 1].first, j));
	}
	for (int i = n; i; i = dp[i].second)
		for (int j = (++cnt, dp[i].second + 1); j <= i; j++)
			ans[a[j].second] = cnt;
	cout << dp[n].first << ' ' << cnt << endl;
	for (int i = 1; i <= n; i++) cout << ans[i] << (i == n ? '\n' : ' ');
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e5 + 10;
struct str{
	int v;
	int p;
	int asc;
}a[N];
int dp[N];
bool cmpv(struct str n, struct str m) {return n.v < m.v;}
bool cmpp(struct str n, struct str m) {return n.p < m.p;}
int main(void) {
	std::ios::sync_with_stdio(false);
	int n;
	int res = 1;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i].v;
		a[i].p = i;
	}
	sort(a, a + n, cmpv);
	memset(dp, 0, sizeof(dp)), dp[0] = 0;
	for (int i = 1; i < n; i++) {
		dp[i] = dp[i - 1] + a[i].v - a[i - 1].v;
		for (int d = 3; d <= 5 && i - d >= 2; d++) {
			dp[i] = min(dp[i], dp[i - d] + a[i].v - a[i - d + 1].v);
		}
	}
	for (int i = n - 1; i >= 0;) {
		int d;
		for (int j = 3; j <= 5; j++)
			if (dp[i] == dp[i - j] + a[i].v - a[i - j + 1].v) d = j;
		int j = d; while (j--) a[i - j].asc =  res;
		res++, i -= d;
	}
	sort(a, a + n, cmpp);
	cout << dp[n - 1] << ' ' << res - 1 << endl;
	for (int i = 0; i < n; i++)
		cout << a[i].asc << ' ';
	cout << endl;
	return 0;
}


#include <bits/stdc++.h>
#define rep(i,n) for(int i=1;i<=(n);i++)
#define ll long long
using namespace std;
const int N = 2e5 + 10;
pair<int, int>a[N];
pair<ll, int>dp[N];
int ans[N];
int cnt = 0;
int main(void) {
	std::ios::sync_with_stdio(false);
	int n; cin >> n;
	for (int i = 1; i <= n; i++) cin >> a[i].first, a[i].second = i;
	sort(a + 1, a + 1 + n);
	for (int i = 3; i <= n; i++) {
		dp[i] = make_pair(1e18, 0);
		for (int j = (max(0, j - 5) == j - 5 ? max(j - 5, 3) : 0); j <= (i - 3 < 3 ? 0 : i - 3); j++)
			dp[i] = min(dp[i], make_pair(dp[j].first + a[i].first - a[j + 1].first, j));
	}
	for (int i = n; i; i = dp[i].second)
		for (int j = (++cnt, dp[i].second + 1); j <= i; j++)
			ans[a[j].second] = cnt;
	cout << dp[n].first << ' ' << cnt << endl;
	for (int i = 1; i <= n; i++) cout << ans[i] << (i == n ? '\n' : ' ');
	return 0;
}


#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define ll long long
using namespace std;
const int N = 2e5 + 10;
int a[N], b[N], c[N], dp[N];
bool cmp(int n, int m) {return a[n] < a[m];}
int main(void) {
	std::ios::sync_with_stdio(false);
	int n;
	cin >> n;
	rep(i, n) {cin >> a[i]; c[i] = i; dp[i] = 0;}
	sort(c, c + n, cmp);
	for (int i = 1; i < n; i++) {
		dp[i] = dp[i - 1] + a[c[i]] - a[c[i - 1]];
		for (int j = 3; j <= 5 && i - j >= 2; j++) {
			dp[i] = min(dp[i], dp[i - j] + a[c[i]] - a[c[i - j + 1]]);
		}
	}
	int res = 1;
	for (int i = n - 1; i >= 2;) {
		int d = i + 1;
		for (int j = 3; j <= 5 && i - j >= 2; j++) {
			if (dp[i] == dp[i - j] + a[c[i]] - a[c[i - j + 1]]) d = j;
		}
		while (d--) b[c[i--]] = res;
		res++;
	}
	cout << dp[n - 1] << ' ' << res - 1 << endl;
	rep(i, n) cout << b[i] << (i == n - 1 ? '\n' : ' ');
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>

#define INF 1000000000000

using std::cin;
using std::cout;
using std::sort;
using std::min;
using std::pair;
using std::vector;
using std::reverse;

int n;
pair<int, long long> a[200000];
long long dp[200000];
int p[200000];
vector<int> r(200000, 0);

bool comp(const pair<int, long long>& p1, const pair<int, long long>& p2)
{
	return p1.second < p2.second;
}

int main()
{
	cin >> n;
	for (int i = 0; i < n; ++i) a[i].first = i, cin >> a[i].second;
	sort(a, a + n, comp);
	dp[0] = INF; dp[1] = INF; dp[2] = a[2].second - a[0].second;
	p[0] = 0, p[1] = 0, p[2] = 0;
	for (int i = 3; i < n; ++i)
	{
		if (i == 3) dp[i] = a[i].second - a[0].second, p[i] = 0;
		else if (i == 4) dp[i] = a[i].second - a[0].second, p[i] = 0;
		else
		{
			long long c1 = dp[i - 3] + a[i].second - a[i - 2].second;
			long long c2 = dp[i - 4] + a[i].second - a[i - 3].second;
			long long c3 = dp[i - 5] + a[i].second - a[i - 4].second;

			if (c1 < c2 && c1 < c3)
				dp[i] = c1, p[i] = i - 3;
			else if (c2 < c1 && c2 < c3)
				dp[i] = c2, p[i] = i - 4;
			else if (c3 < c1 && c3 < c2)
				dp[i] = c3, p[i] = i - 5;
		}
	}

	int i = n - 1;
	int cnt = 0;
	while (i != 0)
	{
		++cnt;
		int iOld = i;
		i = p[i];
		for (int j = iOld; j > i; --j)
			r[a[j].first] = cnt;
	}
	r[a[i].first] = cnt;

	cout << dp[n - 1] << ' ' << cnt << '\n';
	for (int i = 0; i < n; ++i)
		cout << r[i] << ' ';
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>

#define INF 1000000000000

using std::cin;
using std::cout;
using std::sort;
using std::min;
using std::pair;
using std::vector;
using std::reverse;

int n;
pair<int, long long> a[200000];
unsigned long long dp[200000];
int p[200000];
vector<int> r(200000, 0);

bool comp(const pair<int, long long>& p1, const pair<int, long long>& p2)
{
	return p1.second < p2.second;
}

int main()
{
	cin >> n;
	for (int i = 0; i < n; ++i) a[i].first = i, cin >> a[i].second;
	sort(a, a + n, comp);
	dp[0] = INF; dp[1] = INF; dp[2] = a[2].second - a[0].second;
	p[0] = 0, p[1] = 0, p[2] = 0;
	for (int i = 3; i < n; ++i)
	{
		if (i == 3) dp[i] = a[i].second - a[0].second, p[i] = 0;
		else if (i == 4) dp[i] = a[i].second - a[0].second, p[i] = 0;
		else
		{
			long long c1 = dp[i - 3] + a[i].second - a[i - 2].second;
			long long c2 = dp[i - 4] + a[i].second - a[i - 3].second;
			long long c3 = dp[i - 5] + a[i].second - a[i - 4].second;

			if (c1 < c2 && c1 < c3)
				dp[i] = c1, p[i] = i - 3;
			else if (c2 < c1 && c2 < c3)
				dp[i] = c2, p[i] = i - 4;
			else if (c3 < c1 && c3 < c2)
				dp[i] = c3, p[i] = i - 5;
		}
	}

	int i = n - 1;
	int cnt = 0;
	while (i != 0)
	{
		++cnt;
		int iOld = i;
		i = p[i];
		for (int j = iOld; j > i; --j)
			r[a[j].first] = cnt;
	}
	r[a[i].first] = cnt;

	cout << dp[n - 1] << ' ' << cnt << '\n';
	for (int i = 0; i < n; ++i)
		cout << r[i] << ' ';
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>

#define INF 1000000000000

using std::cin;
using std::cout;
using std::sort;
using std::min;
using std::pair;
using std::vector;
using std::reverse;

int n;
pair<int, long long> a[200000];
unsigned long long dp[200000];
int p[200000];
vector<int> r(200000, 0);

bool comp(const pair<int, long long>& p1, const pair<int, long long>& p2)
{
	return p1.second < p2.second;
}

int main()
{
	cin >> n;
	for (int i = 0; i < n; ++i) a[i].first = i, cin >> a[i].second;
	sort(a, a + n, comp);
	dp[0] = INF; dp[1] = INF; dp[2] = a[2].second - a[0].second;
	p[0] = 0, p[1] = 0, p[2] = 0;
	for (int i = 3; i < n; ++i)
	{
		if (i == 3) dp[i] = a[i].second - a[0].second, p[i] = 0;
		else if (i == 4) dp[i] = a[i].second - a[0].second, p[i] = 0;
		else
		{
			unsigned long long c1 = dp[i - 3] + a[i].second - a[i - 2].second;
			unsigned long long c2 = dp[i - 4] + a[i].second - a[i - 3].second;
			unsigned long long c3 = dp[i - 5] + a[i].second - a[i - 4].second;

			if (c1 <= c2 && c1 <= c3)
				dp[i] = c1, p[i] = i - 3;
			else if (c2 <= c1 && c2 <= c3)
				dp[i] = c2, p[i] = i - 4;
			else if (c3 <= c1 && c3 <= c2)
				dp[i] = c3, p[i] = i - 5;
		}
	}

	int i = n - 1;
	int cnt = 0;
	while (i != 0)
	{
		++cnt;
		int iOld = i;
		i = p[i];
		for (int j = iOld; j > i; --j)
			r[a[j].first] = cnt;
	}
	r[a[i].first] = cnt;

	cout << dp[n - 1] << ' ' << cnt << '\n';
	for (int i = 0; i < n; ++i)
		cout << r[i] << ' ';
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <iomanip>
#include <set>
#include <map>
#define MOD 1000000007
#define pb push_back
#define ll long long
using namespace std;

struct Data {
	ll skill;
	int id;

	friend bool operator<(Data& a, Data& b) {
		return a.skill < b.skill;
	}
};

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);

#ifdef _HOME_TEST_
	freopen("input.txt", "r", stdin);
#endif

	int n, k;
	cin >> n;

	vector<Data> a(n + 1);
	a[0] = { -1, 0 };
	for (int i = 1; i <= n; i++) {
		int x;
		cin >> x;
		a[i] = { x, i };
	}
	sort(a.begin(), a.end());

	vector<ll> dp(n + 1, 1e9);
	vector<int> par(n + 1, -1);
	vector<int> clr(n + 1, -1);

	dp[0] = 0;
	clr[0] = 0;
	par[1] = par[2] = par[3] = 1;
	for (int i = 4; i <= n; i++) par[i] = i;

	for (int i = 3; i <= n; i++) {
		for (int j = 3; j <= 5; j++) {
			if (i - j >= 0) {
				if (dp[i - j] + a[i].skill - a[i - j + 1].skill < dp[i]) {
					dp[i] = min(dp[i], dp[i - j] + a[i].skill - a[i - j + 1].skill);
					par[i] = i - j + 1;
				}
			}
		}
	}

	int i = n;
	int col = 1;
	while (par[i] != -1) {
		for (int j = i; j >= par[i]; j--) clr[a[j].id] = col;
		i = par[i] - 1;
		col++;
	}

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

	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <iomanip>
#include <set>
#include <map>
#define MOD 1000000007
#define pb push_back
#define ll long long
using namespace std;

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);

#ifdef _HOME_TEST_
	freopen("input.txt", "r", stdin);
#endif

	int n, k;
	cin >> n;

	vector<int> skill(n + 1);
	skill[0] = -1;
	for (int i = 1; i <= n; i++) cin >> skill[i];
	sort(skill.begin(), skill.end());

	vector<int> dp(n + 1, 1e9);
	vector<int> par(n + 1, -1);
	vector<int> clr(n + 1, -1);

	dp[0] = 0;
	clr[0] = 0;
	par[1] = par[2] = par[3] = 1;
	for (int i = 4; i <= n; i++) par[i] = i;

	for (int i = 3; i <= n; i++) {
		for (int j = 3; j <= 5; j++) {
			if (i - j >= 0) {
				if (dp[i - j] + skill[i] - skill[i - j + 1] < dp[i]) {
					dp[i] = min(dp[i], dp[i - j] + skill[i] - skill[i - j + 1]);
					par[i] = i - j + 1;
				}
			}
		}
	}

	int i = n;
	int col = 1;
	while (par[i] != -1) {
		for (int j = i; j >= par[i]; j--) clr[j] = col;
		i = par[i] - 1;
		col++;
	}

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

	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <iomanip>
#include <set>
#include <map>
#define MOD 1000000007
#define pb push_back
#define ll long long
using namespace std;

struct Data {
	int skill;
	int id;

	friend bool operator<(Data& a, Data& b) {
		return a.skill < b.skill;
	}
};

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);

#ifdef _HOME_TEST_
	freopen("input.txt", "r", stdin);
#endif

	int n, k;
	cin >> n;

	vector<Data> a(n + 1);
	a[0] = { -1, 0 };
	for (int i = 1; i <= n; i++) {
		int x;
		cin >> x;
		a[i] = { x, i };
	}
	sort(a.begin(), a.end());

	vector<int> dp(n + 1, 1e9);
	vector<int> par(n + 1, -1);
	vector<int> clr(n + 1, -1);

	dp[0] = 0;
	clr[0] = 0;
	par[1] = par[2] = par[3] = 1;
	for (int i = 4; i <= n; i++) par[i] = i;

	for (int i = 3; i <= n; i++) {
		for (int j = 3; j <= 5; j++) {
			if (i - j >= 0) {
				if (dp[i - j] + a[i].skill - a[i - j + 1].skill < dp[i]) {
					dp[i] = min(dp[i], dp[i - j] + a[i].skill - a[i - j + 1].skill);
					par[i] = i - j + 1;
				}
			}
		}
	}

	int i = n;
	int col = 1;
	while (par[i] != -1) {
		for (int j = i; j >= par[i]; j--) clr[a[j].id] = col;
		i = par[i] - 1;
		col++;
	}

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

	return 0;
}


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

typedef long long ll;
vector<vector<ll>> dp;
vector<pair<ll, int>> stus;
vector<vector<int>> p;
vector<int> team;
int n , k;
int main()
{
	cin >> n;
	k = n / 3;

	dp = vector<vector<ll>>(k + 1, vector<ll>(3, LLONG_MAX));
	p = vector<vector<int>>(k + 1, vector<int>(3, -1));
	team = vector<int>(n + 1);
	for (int i = 1; i <= n; i++)
	{
		ll num;
		cin >> num;
		stus.push_back({ num , i });
	}
	sort(stus.begin(), stus.end());

	dp[1][0] = stus[2].first - stus[0].first;
	dp[1][1] = stus[3].first - stus[0].first;
	dp[1][2] = stus[4].first - stus[0].first;
	//cout << "dp[1][0]:" << dp[1][0] << endl;
	//cout << "dp[1][1]:" << dp[1][1] << endl;
	//cout << "dp[1][2]:" << dp[1][2] << endl;

	for (int i = 2; i <= k; i++)
	{
		for (int j = 0; j < 3 && 3 * i + j <= n; j++)
		{
			for (int m = 0; m <= j; m++)
			{
				if (dp[i - 1][m] + stus[3 * i + j - 1].first - stus[3 * (i - 1) + m].first < dp[i][j])
				{
					dp[i][j] = dp[i - 1][m] + stus[3 * i + j - 1].first - stus[3 * (i - 1) + m].first;
					p[i][j] = m;
				}
			}
		}
	}

	ll res = dp[k][n % 3];
	int curt = n % 3;
	for (int i = k; i >= 1; i--)
	{
		int left;
		if (p[i][curt] == -1) left = 0;
		else left = 3 * (i - 1) + p[i][curt];

		for (int j = left; j < 3 * i + curt; j++) team[stus[j].second] = i;

		curt = p[i][curt];
	}

	cout << res << " " << k << endl;
	for (int i = 1; i <= n; i++) cout << team[i] << " ";

	return 0;
}


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

typedef pair<int, int> pii;
int main()
{
	int n;
	cin >> n;

	vector<pii> nums(n), dp(n + 1, { INT_MAX , -1 });
	dp[0] = { 0 , -1 };
	for (int i = 0; i < n; i++)
	{
		cin >> nums[i].first;
		nums[i].second = i;
	}

	sort(nums.begin(), nums.end());
	for (int i = 3; i <= n; i++)
	{
		for (int j = 3; j <= 5; j++)
		{
			if (i < j) continue;
			if (dp[i - j].first != INT_MAX && dp[i - j].first + nums[i - 1].first - nums[i - j].first < dp[i].first)
			{
				dp[i] = { dp[i - j].first + nums[i - 1].first - nums[i - j].first , i - j };
			}
		}
	}

	int pos = n , cnt = 0;
	vector<int> p(n);
	while (pos)
	{
		++cnt;
		int npos = dp[pos].second;
		for (int i = pos; i > npos; i--)
		{
			p[nums[i-1].second] = cnt;
		}
		pos = npos;
	}

	//for (int i = 0; i < n; i++)
	//{
	//	p[i] = cnt + 1 - p[i];
	//}

	cout << dp[n].first <<" "<<cnt<< endl;
	for (int i = 0; i < n; i++)
	{
		cout << p[i] << " ";
	}

	return 0;
}


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

typedef long long ll;
vector<ll> dp;
vector<pair<ll, int>> stus;
vector<int> p;
vector<int> team;
int n , k = 0;
int main()
{
	cin >> n;

	dp = vector<ll>(n + 1, LONG_MAX);
	p = vector<int>(n + 1 , -1);
	team = vector<int>(n + 1);
	for (int i = 1; i <= n; i++)
	{
		ll num;
		cin >> num;
		stus.push_back({ num , i });
	}
	sort(stus.begin(), stus.end());

	dp[0] = 0;
	for(int i = 0 ; i < n ; i++)
		for (int j = 3; j <= 5 && i + j <= n; j++)
		{
			if (dp[i] + stus[i + j - 1].first - stus[i].first < dp[i + j])
			{
				dp[i + j] = dp[i] + stus[i + j - 1].first - stus[i].first;
				p[i + j] = i;
			}
		}

	int fa = n;
	while (fa > 0)
	{
		k++;
		fa = p[fa];
	}

	int right = n;
	for (int i = k; i >= 1; i--)
	{
		int left = p[right];
		for (int j = left; j < right; j++) team[stus[j].second] = i;

		right = left;
	}

	cout << dp[n] << " " << k << endl;
	for (int i = 1; i <= n; i++) cout << team[i] << " ";
	return 0;
}


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

typedef long long ll;
vector<vector<ll>> dp;
vector<pair<ll, int>> stus;
vector<vector<int>> p;
vector<int> team;
int n , k;
int main()
{
	cin >> n;
	k = n / 3;

	dp = vector<vector<ll>>(k + 1, vector<ll>(3, INT_MAX));
	p = vector<vector<int>>(k + 1, vector<int>(3, -1));
	team = vector<int>(n + 1);
	for (int i = 1; i <= n; i++)
	{
		ll num;
		cin >> num;
		stus.push_back({ num , i });
	}
	sort(stus.begin(), stus.end());

	dp[1][0] = stus[2].first - stus[0].first;
	dp[1][1] = stus[3].first - stus[0].first;
	dp[1][2] = stus[4].first - stus[0].first;
	//cout << "dp[1][0]:" << dp[1][0] << endl;
	//cout << "dp[1][1]:" << dp[1][1] << endl;
	//cout << "dp[1][2]:" << dp[1][2] << endl;

	for (int i = 2; i <= k; i++)
	{
		for (int j = 0; j < 3 && 3 * i + j <= n; j++)
		{
			for (int m = 0; m <= j; m++)
			{
				if (dp[i - 1][m] + stus[3 * i + j - 1].first - stus[3 * (i - 1) + m].first < dp[i][j])
				{
					dp[i][j] = dp[i - 1][m] + stus[3 * i + j - 1].first - stus[3 * (i - 1) + m].first;
					p[i][j] = m;
				}
			}
		}
	}

	ll res = dp[k][n % 3];
	int curt = n % 3;
	for (int i = k; i >= 1; i--)
	{
		int left;
		if (p[i][curt] == -1) left = 0;
		else left = 3 * (i - 1) + p[i][curt];

		for (int j = left; j < 3 * i + curt; j++) team[stus[j].second] = i;

		curt = p[i][curt];
	}

	cout << res << " " << k << endl;
	for (int i = 1; i <= n; i++) cout << team[i] << " ";

	return 0;
}