/* Author : Nguyen Thanh Tung - Tran Hung Dao High School for Gifted Student */
#include <bits/stdc++.h>
#define endl '\n'
#define int long long
using namespace std;
typedef pair<int, int> ii;
const int N = 1e5 + 7;
const long long oo = 1e18 + 7;
const long long MOD = 1e9 + 7;
int n, a[N], b[N], dp[N];
void solve() {
cin >> n;
for(int i = 1; i <= n; ++i) {
cin >> a[i] >> b[i];
}
dp[n] = a[n];
for(int i = n - 1; i >= 1; --i) {
dp[i] = min(dp[i + 1] + a[i], dp[i + 2] + b[i]);
}
cout << dp[1] << endl;
for(int i = 1; i <= n; ++i) {
if(dp[i] == dp[i + 1] + a[i]) {
cout << "1 ";
}
else {
cout << "2 0 ";
++i;
}
}
}
signed main () {
ios_base::sync_with_stdio (false);
cin.tie(nullptr), cout.tie(nullptr);
#define TASK "riceatm"
if (fopen(TASK".INP", "r")) {
freopen(TASK".INP", "r", stdin);
freopen(TASK".OUT", "w", stdout);
}
solve();
return 0;
}
LyogQXV0aG9yIDogTmd1eWVuIFRoYW5oIFR1bmcgLSBUcmFuIEh1bmcgRGFvIEhpZ2ggU2Nob29sIGZvciBHaWZ0ZWQgU3R1ZGVudCAqLwoKI2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CgojZGVmaW5lIGVuZGwgCQkgICAgICdcbicKI2RlZmluZSBpbnQgCQkgICAgIGxvbmcgbG9uZwoKdXNpbmcgbmFtZXNwYWNlIAkgICAgIHN0ZDsKCnR5cGVkZWYgcGFpcjxpbnQsIGludD4gaWk7Cgpjb25zdCBpbnQgICAgICAgTiAgICAgID0gMWU1ICsgNzsKY29uc3QgbG9uZyBsb25nIG9vICAgICA9IDFlMTggKyA3Owpjb25zdCBsb25nIGxvbmcgTU9EICAgID0gMWU5ICsgNzsKCmludCBuLCBhW05dLCBiW05dLCBkcFtOXTsKCnZvaWQgc29sdmUoKSB7CiAgIGNpbiA+PiBuOwogICBmb3IoaW50IGkgPSAxOyBpIDw9IG47ICsraSkgewogICAgICBjaW4gPj4gYVtpXSA+PiBiW2ldOwogICB9CiAgIGRwW25dID0gYVtuXTsKICAgZm9yKGludCBpID0gbiAtIDE7IGkgPj0gMTsgLS1pKSB7CiAgICAgIGRwW2ldID0gbWluKGRwW2kgKyAxXSArIGFbaV0sIGRwW2kgKyAyXSArIGJbaV0pOwogICB9CiAgIGNvdXQgPDwgZHBbMV0gPDwgZW5kbDsKICAgZm9yKGludCBpID0gMTsgaSA8PSBuOyArK2kpIHsKICAgICAgaWYoZHBbaV0gPT0gZHBbaSArIDFdICsgYVtpXSkgewogICAgICAgICBjb3V0IDw8ICIxICI7CiAgICAgIH0KICAgICAgZWxzZSB7CiAgICAgICAgIGNvdXQgPDwgIjIgMCAiOwogICAgICAgICArK2k7CiAgICAgIH0KICAgfQp9CiAgICAgICAgICAgCnNpZ25lZCBtYWluICgpIHsKICAgaW9zX2Jhc2U6OnN5bmNfd2l0aF9zdGRpbyAoZmFsc2UpOwogICBjaW4udGllKG51bGxwdHIpLCBjb3V0LnRpZShudWxscHRyKTsKCiAgICNkZWZpbmUgVEFTSyAicmljZWF0bSIKICAgaWYgKGZvcGVuKFRBU0siLklOUCIsICJyIikpIHsKICAgICAgZnJlb3BlbihUQVNLIi5JTlAiLCAiciIsIHN0ZGluKTsKICAgICAgZnJlb3BlbihUQVNLIi5PVVQiLCAidyIsIHN0ZG91dCk7CiAgIH0KICAgCiAgIHNvbHZlKCk7CiAgIHJldHVybiAwOwp9Cg==