#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <queue>
#include <stack>
#include <string>
#include <map>
#include <set>
#include <bitset>
#include <iomanip>
#include <unordered_map>
#include <cstdlib>
#include <random>

using namespace std;
typedef long long ll;
typedef long double ld;
#define fori(k, n) for(int i = k; i < n; i++)
#define forj(k, n) for(int j = k; j < n; j++)
#define fork(f, n) for(int k = f; k < n; k++)
#define vi vector <int>
#define vll vector <ll>
#define sc(n) scanf("%d", &n);
#define pii pair <int, int>
#define np nullptr

const ll INF = 1e12;
const ll md = 1e9 + 7;
const ld eps = 1e-6;

int used[10000000];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll a, b, flag = 0, sum = 0;
    vector <int> ans1, ans2;
    cin >> a >> b;
    for(ll x = 1; x <= 500000; x++) {
        if((x + 2) * (x + 1) / 2 > a + b) {
            for(int j = x; j >= 1; j--) {
                if(a - j >= 0) {
                    a -= j;
                    ans1.push_back(j);
                } else {
                    if(b - j >= 0) {
                        b -= j;
                        ans2.push_back(j);
                    }
                }
            }
            break;
        }
    }
    cout << ans1.size() << endl;
    fori(0, ans1.size()) {
        cout << ans1[i] << ' ';
    }
    cout << endl;
    cout << ans2.size() << endl;
    fori(0, ans2.size()) {
        cout << ans2[i] << ' ';
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <queue>
#include <stack>
#include <string>
#include <map>
#include <set>
#include <bitset>
#include <iomanip>
#include <unordered_map>
#include <cstdlib>
#include <random>

using namespace std;
typedef long long ll;
typedef long double ld;
#define fori(k, n) for(int i = k; i < n; i++)
#define forj(k, n) for(int j = k; j < n; j++)
#define fork(f, n) for(int k = f; k < n; k++)
#define vi vector <int>
#define vll vector <ll>
#define sc(n) scanf("%d", &n);
#define pii pair <int, int>
#define np nullptr

const ll INF = 1e12;
const ll md = 1e9 + 7;
const ld eps = 1e-6;

int used[10000000];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll a, b, flag = 0, sum = 0;
    vector <int> ans1, ans2;
    cin >> a >> b;
    if(a > b) {
        swap(a, b);
        flag = 1;
    }
    fori(1, 2000000) {
        sum += i;
        if(sum > a) {
            sum -= i;
            break;
        }
        used[i] = 1;
        ans1.push_back(i);
    }
    if(ans1.size() != 0) {
        int last = ans1.back();
        ans1.pop_back();
        used[last] = 0;
        ans1.push_back(a - (sum - last));
        used[a - (sum - last)] = 1;
    }
    sum = 0;
    fori(1, 2000000) {
        if(used[i]) continue;
        sum += i;
        if(sum > b)
            break;
        ans2.push_back(i);
    }
    if(!flag) {
        cout << ans1.size() << endl;
        fori(0, ans1.size()) {
            cout << ans1[i] << ' ';
        }
        cout << endl;
        cout << ans2.size() << endl;
        fori(0, ans2.size()) {
            cout << ans2[i] << ' ';
        }
    } else {
        cout << ans2.size() << endl;
        fori(0, ans2.size()) {
            cout << ans2[i] << ' ';
        }
        cout << endl;
        cout << ans1.size() << endl;
        fori(0, ans1.size()) {
            cout << ans1[i] << ' ';
        }
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <queue>
#include <stack>
#include <string>
#include <map>
#include <set>
#include <bitset>
#include <iomanip>
#include <unordered_map>
#include <cstdlib>
#include <random>

using namespace std;
typedef long long ll;
typedef long double ld;
#define fori(k, n) for(int i = k; i < n; i++)
#define forj(k, n) for(int j = k; j < n; j++)
#define fork(f, n) for(int k = f; k < n; k++)
#define vi vector <int>
#define vll vector <ll>
#define sc(n) scanf("%d", &n);
#define pii pair <int, int>
#define np nullptr

const ll INF = 1e12;
const ll md = 1e9 + 7;
const ld eps = 1e-6;

ll a, b, used[2000000];
vector <int> ans1, ans2;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    bool flag = false;
    cin >> a >> b;
    if(b > a) {
        swap(a, b);
        flag = true;
    }
    ll cur = 0;
    int last = 0;
    fori(1, 2000000) {
        cur += i;
        if(cur > a) {
            cur -= i;
            last = i - 1;
            break;
        }
        ans1.push_back(i);
        used[i] = 1;
    }
    int sz = ans1.size() - 1;
    for(int i = sz; i >= 0; i--) {
        ll ch = cur - ans1[i];
        if(used[ch] == 0 && cur - ans1[i] + ch <= a) {
            used[ans1[i]] = 0;
            used[ch] = 1;
            //cout << ans1[i] << endl;
            cur -= ans1[i];
            cur += ch;
            ans1.push_back(ch);
            ans1[i] = -1;
        }
    }
    cur = 0;
    fori(1, 2000000) {
        if(used[i] == 1) continue;
        cur += i;
        if(cur > b)
            break;
        ans2.push_back(i);
    }
    vector <int> a;
    fori(0, ans1.size()) {
        if(ans1[i] != -1)
            a.push_back(ans1[i]);
    }
    if(flag) {
    cout << ans2.size() << "\n";
    fori(0, ans2.size())
        cout << ans2[i] << ' ';
    cout << endl;
    cout << a.size() << "\n";
    fori(0, a.size())
        cout << a[i] << ' ';
       return 0;
    }
    cout << a.size() << "\n";
    fori(0, a.size())
        cout << a[i] << ' ';
    cout << endl;
    cout << ans2.size() << "\n";
    fori(0, ans2.size())
        cout << ans2[i] << ' ';
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <queue>
#include <stack>
#include <string>
#include <map>
#include <set>
#include <bitset>
#include <iomanip>
#include <unordered_map>
#include <cstdlib>
#include <random>

using namespace std;
typedef long long ll;
typedef long double ld;
#define fori(k, n) for(int i = k; i < n; i++)
#define forj(k, n) for(int j = k; j < n; j++)
#define fork(f, n) for(int k = f; k < n; k++)
#define vi vector <int>
#define vll vector <ll>
#define sc(n) scanf("%d", &n);
#define pii pair <int, int>
#define np nullptr

const ll INF = 1e12;
const ll md = 1e9 + 7;
const ld eps = 1e-6;

int used[10000000];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll a, b, flag = 0, sum = 0;
    vector <int> ans1, ans2;
    cin >> a >> b;
    if(a > b) {
        swap(a, b);
        flag = 1;
    }
    fori(1, 2000000) {
        sum += i;
        if(sum > a) {
            sum -= i;
            break;
        }
        used[i] = 1;
        ans1.push_back(i);
    }
    int last = ans1.back();
    ans1.pop_back();
    used[last] = 0;
    ans1.push_back(a - (sum - last));
    used[a - (sum - last)] = 1;
    sum = 0;
    fori(1, 2000000) {
        if(used[i]) continue;
        sum += i;
        if(sum > b)
            break;
        ans2.push_back(i);
    }
    if(!flag) {
        cout << ans1.size() << endl;
        fori(0, ans1.size()) {
            cout << ans1[i] << ' ';
        }
        cout << endl;
        cout << ans2.size() << endl;
        fori(0, ans2.size()) {
            cout << ans2[i] << ' ';
        }
    } else {
        cout << ans2.size() << endl;
        fori(0, ans2.size()) {
            cout << ans2[i] << ' ';
        }
        cout << endl;
        cout << ans1.size() << endl;
        fori(0, ans1.size()) {
            cout << ans1[i] << ' ';
        }
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <queue>
#include <stack>
#include <string>
#include <map>
#include <set>
#include <bitset>
#include <iomanip>
#include <unordered_map>
#include <cstdlib>
#include <random>

using namespace std;
typedef long long ll;
typedef long double ld;
#define fori(k, n) for(int i = k; i < n; i++)
#define forj(k, n) for(int j = k; j < n; j++)
#define fork(f, n) for(int k = f; k < n; k++)
#define vi vector <int>
#define vll vector <ll>
#define sc(n) scanf("%d", &n);
#define pii pair <int, int>
#define np nullptr

const ll INF = 1e12;
const ll md = 1e9 + 7;
const ld eps = 1e-6;

ll a, b, used[10000000];
vector <int> ans1, ans2;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    bool flag = false;
    cin >> a >> b;
    if(b > a) {
        swap(a, b);
        flag = true;
    }
    ll cur = 0;
    fori(1, 10000000) {
        cur += i;
        if(cur > a) {
            cur -= i;
            break;
        }
        ans1.push_back(i);
        used[i] = 1;
    }
    int sz = ans1.size() - 1;
    for(int i = 0; i < sz; i++) {
        ll ch = a - (cur - ans1[i]);
        if(used[ch] == 0 && cur - ans1[i] + ch <= a && ch != 0) {
            used[ans1[i]] = 0;
            used[ch] = 1;
            cur -= ans1[i];
            cur += ch;
            ans1.push_back(ch);
            ans1[i] = -1;
        }
    }
    cur = 0;
    fori(1, 10000000) {
        if(used[i] == 1) continue;
        cur += i;
        if(cur > b)
            break;
        ans2.push_back(i);
    }
    vector <int> aa;
    fori(0, ans1.size()) {
        if(ans1[i] != -1)
            aa.push_back(ans1[i]);
    }
    if(flag) {
        cout << ans2.size() << "\n";
        fori(0, ans2.size())
            cout << ans2[i] << ' ';
        if(ans2.size() != 0)
            cout << endl;
        cout << aa.size() << "\n";
        fori(0, aa.size())
            cout << aa[i] << ' ';
        return 0;
    }
    cout << aa.size() << "\n";
    fori(0, aa.size())
        cout << aa[i] << ' ';
    if(aa.size() != 0)
        cout << endl;
    cout << ans2.size() << "\n";
    fori(0, ans2.size())
        cout << ans2[i] << ' ';
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <queue>
#include <stack>
#include <string>
#include <map>
#include <set>
#include <bitset>
#include <iomanip>
#include <unordered_map>
#include <cstdlib>
#include <random>

using namespace std;
typedef long long ll;
typedef long double ld;
#define fori(k, n) for(int i = k; i < n; i++)
#define forj(k, n) for(int j = k; j < n; j++)
#define fork(f, n) for(int k = f; k < n; k++)
#define vi vector <int>
#define vll vector <ll>
#define sc(n) scanf("%d", &n);
#define pii pair <int, int>
#define np nullptr

const ll INF = 1e12;
const ll md = 1e9 + 7;
const ld eps = 1e-6;

ll a, b, used[10000000];
vector <int> ans1, ans2;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    bool flag = false;
    cin >> a >> b;
    if(b > a) {
        swap(a, b);
        flag = true;
    }
    ll cur = 0;
    fori(1, 10000000) {
        cur += i;
        if(cur > a) {
            cur -= i;
            break;
        }
        ans1.push_back(i);
        used[i] = 1;
    }
    int sz = ans1.size() - 1;
    for(int i = sz; i >= 0; i--) {
        ll ch = a - (cur - ans1[i]);
        if(used[ch] == 0 && cur - ans1[i] + ch <= a && ch != 0) {
            used[ans1[i]] = 0;
            used[ch] = 1;
            cur -= ans1[i];
            cur += ch;
            ans1.push_back(ch);
            ans1[i] = -1;
        }
    }
    cur = 0;
    fori(1, 10000000) {
        if(used[i] == 1) continue;
        cur += i;
        if(cur > b)
            break;
        ans2.push_back(i);
    }
    vector <int> a;
    fori(0, ans1.size()) {
        if(ans1[i] != -1)
            a.push_back(ans1[i]);
    }
    if(flag) {
        cout << ans2.size() << "\n";
        fori(0, ans2.size())
            cout << ans2[i] << ' ';
        if(ans2.size() != 0)
            cout << endl;
        cout << a.size() << "\n";
        fori(0, a.size())
            cout << a[i] << ' ';
        return 0;
    }
    cout << a.size() << "\n";
    fori(0, a.size())
        cout << a[i] << ' ';
    if(a.size() != 0)
        cout << endl;
    cout << ans2.size() << "\n";
    fori(0, ans2.size())
        cout << ans2[i] << ' ';
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <queue>
#include <stack>
#include <string>
#include <map>
#include <set>
#include <bitset>
#include <iomanip>
#include <unordered_map>
#include <cstdlib>
#include <random>

using namespace std;
typedef long long ll;
typedef long double ld;
#define fori(k, n) for(int i = k; i < n; i++)
#define forj(k, n) for(int j = k; j < n; j++)
#define fork(f, n) for(int k = f; k < n; k++)
#define vi vector <int>
#define vll vector <ll>
#define sc(n) scanf("%d", &n);
#define pii pair <int, int>
#define np nullptr

const ll INF = 1e12;
const ll md = 1e9 + 7;
const ld eps = 1e-6;

int used[10000000];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll a, b, flag = 0, sum = 0;
    vector <int> ans1, ans2;
    cin >> a >> b;
    for(int x = 1; x <= 50000; x++) {
        if((x + 2) * (x + 1) / 2 > a + b) {
            for(int j = x; j >= 1; j--) {
                if(a - j >= 0) {
                    a -= j;
                    ans1.push_back(j);
                } else {
                    if(b - j >= 0) {
                        b -= j;
                        ans2.push_back(j);
                    }
                }
            }
            break;
        }
    }
    cout << ans1.size() << endl;
    fori(0, ans1.size()) {
        cout << ans1[i] << ' ';
    }
    cout << endl;
    cout << ans2.size() << endl;
    fori(0, ans2.size()) {
        cout << ans2[i] << ' ';
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <queue>
#include <stack>
#include <string>
#include <map>
#include <set>
#include <bitset>
#include <iomanip>
#include <unordered_map>
#include <cstdlib>
#include <random>

using namespace std;
typedef long long ll;
typedef long double ld;
#define fori(k, n) for(int i = k; i < n; i++)
#define forj(k, n) for(int j = k; j < n; j++)
#define fork(f, n) for(int k = f; k < n; k++)
#define vi vector <int>
#define vll vector <ll>
#define sc(n) scanf("%d", &n);
#define pii pair <int, int>
#define np nullptr

const ll INF = 1e12;
const ll md = 1e9 + 7;
const ld eps = 1e-6;

ll a, b, used[2000000];
vector <int> ans1, ans2;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    bool flag = false;
    cin >> a >> b;
    if(b > a) {
        swap(a, b);
        flag = true;
    }
    ll cur = 0;
    int last = 0;
    fori(1, 2000000) {
        cur += i;
        if(cur > a) {
            cur -= i;
            last = i - 1;
            break;
        }
        ans1.push_back(i);
        used[i] = 1;
    }
    int sz = ans1.size() - 1;
    for(int i = sz; i >= 0; i--) {
        ll ch = cur - ans1[i];
        if(used[ch] == 0 && cur - ans1[i] + ch <= a && ch != 0) {
            used[ans1[i]] = 0;
            used[ch] = 1;
            cur -= ans1[i];
            cur += ch;
            ans1.push_back(ch);
            ans1[i] = -1;
        }
    }
    cur = 0;
    fori(1, 2000000) {
        if(used[i] == 1) continue;
        cur += i;
        if(cur > b)
            break;
        ans2.push_back(i);
    }
    vector <int> a;
    fori(0, ans1.size()) {
        if(ans1[i] != -1)
            a.push_back(ans1[i]);
    }
    if(flag) {
        cout << ans2.size() << "\n";
        fori(0, ans2.size())
            cout << ans2[i] << ' ';
        if(ans2.size() != 0)
            cout << endl;
        cout << a.size() << "\n";
        fori(0, a.size())
            cout << a[i] << ' ';
            return 0;
        }
    cout << a.size() << "\n";
    fori(0, a.size())
        cout << a[i] << ' ';
    if(a.size() != 0)
        cout << endl;
    cout << ans2.size() << "\n";
    fori(0, ans2.size())
        cout << ans2[i] << ' ';
    return 0;
}


#include <iostream>
#include <algorithm>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <cmath>
#include <unordered_map>
#include <queue>
#include <map>
#include <functional>
#include <stack>
#include <cmath>
#include <cstring>
#include <random>
#include <chrono>
#include <memory>
#include <cassert>
#include <numeric>
#include <iomanip>
#include <array>
#define int long long
#define pic pair<int, char>
#define x first
#define y second
#define ll long long
#define pii pair<long long, long long>
#define endl "\n"
#define all(a) (a).begin(), (a).end()
#pragma GCC optimize ("O3")
#define PI 3.14159265
#define pdd pair<double, double>
#define rect pair<pii, pii>

using namespace std;

const int N = 1e6 + 14;
const int inf = (int)1e18 + 10;
const int mod = 1e9 + 7;
const double eps = 1e-6;

mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

using namespace std;

int a, b;
bool used[N];

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cout.precision(20);

	cin >> a >> b;

	bool sw = false;

	if (a > b)
	{
		swap(a, b);
		sw = true;
	}

		set<int> sta;

		for (int i = 1; true; ++i)
			if (i * (i + 1) / 2 >= a)
			{
				int sum = (i - 1) * i / 2;
				a -= sum;

				if (a)
				{
					int x = i - a;
					sta.erase(x);
					used[x] = false;
					sta.insert(i);
					used[i] = true;
					break;
				}
			}
			else
			{
				sta.insert(i);
				used[i] = true;
			}

		set<int> stb;

		for (int i = 1; true; ++i)
			if (!used[i])
			{
				if (i <= b)
				{
					b -= i;
					used[i] = true;
					stb.insert(i);
				}
				else
					break;
			}

		if (sw)
			swap(sta, stb);

	cout << sta.size() << endl;

	for (auto it : sta)
		cout << it << " ";

	cout << endl;

	cout << stb.size() << endl;

	for (auto it : stb)
		cout << it << " ";

	cout << endl;
}


#include <iostream>
#include <algorithm>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <cmath>
#include <unordered_map>
#include <queue>
#include <map>
#include <functional>
#include <stack>
#include <cmath>
#include <cstring>
#include <random>
#include <chrono>
#include <memory>
#include <cassert>
#include <numeric>
#include <iomanip>
#include <array>
#define int long long
#define pic pair<int, char>
#define x first
#define y second
#define ll long long
#define pii pair<long long, long long>
#define endl "\n"
#define all(a) (a).begin(), (a).end()
#pragma GCC optimize ("O3")
#define PI 3.14159265
#define pdd pair<double, double>
#define rect pair<pii, pii>

using namespace std;

const int N = 2e6 + 14;
const int inf = (int)1e18 + 10;
const int mod = 1e9 + 7;
const double eps = 1e-6;

mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

using namespace std;

int a, b;
set<int> sta;
set<int> stb;

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cout.precision(20);

	cin >> a >> b;

	bool sw = false;

	if (a > b)
	{
		swap(a, b);
		sw = true;
	}

	for(int i = 1; true; ++i)
		if (i * (i + 1) / 2 > a + b)
		{
			int mxi = i - 1;

			for(int j = mxi; j >= 0; --j)
				if (a >= j)
				{
					a -= j;
					sta.insert(j);
				}

			break;
		}

	for (int i = 1; true; ++i)
		if (sta.find(i) == sta.end())
			if (b < i)
				break;
			else
			{
				b -= i;
				stb.insert(i);
			}

	if (sta.find(0) != sta.end())
		sta.erase(0);

	if (stb.find(0) != stb.end())
		stb.erase(0);

	if (sw)
		swap(sta, stb);

	cout << sta.size() << endl;

	for (auto it : sta)
		cout << it << " ";

	cout << endl;

	cout << stb.size() << endl;

	for (auto it : stb)
		cout << it << " ";

	cout << endl;
}


#include <iostream>
#include <algorithm>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <cmath>
#include <unordered_map>
#include <queue>
#include <map>
#include <functional>
#include <stack>
#include <cmath>
#include <cstring>
#include <random>
#include <chrono>
#include <memory>
#include <cassert>
#include <numeric>
#include <iomanip>
#include <array>
#define int long long
#define pic pair<int, char>
#define x first
#define y second
#define ll long long
#define pii pair<long long, long long>
#define endl "\n"
#define all(a) (a).begin(), (a).end()
#pragma GCC optimize ("O3")
#define PI 3.14159265
#define pdd pair<double, double>
#define rect pair<pii, pii>

using namespace std;

const int N = 1e6 + 14;
const int inf = (int)1e18 + 10;
const int mod = 1e9 + 7;
const double eps = 1e-6;

mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

using namespace std;

int a, b;
bool used[N];

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cout.precision(20);

	cin >> a >> b;

	set<int> sta;

	for(int i = 1; true; ++i)
		if (i * (i + 1) / 2 >= a)
		{
			int sum = (i - 1) * i / 2;
			a -= sum;

			if (a)
			{
				int x = i - a;
				sta.erase(x);
				used[x] = false;
				sta.insert(i);
				used[i] = true;
				break;
			}
		}
		else
		{
			sta.insert(i);
			used[i] = true;
		}

	set<int> stb;

	for (int i = 1; true; ++i)
		if (!used[i])
		{
			if (i <= b)
			{
				b -= i;
				used[i] = true;
				stb.insert(i);
			}
			else
				break;
		}

	cout << sta.size() << endl;

	for (auto it : sta)
		cout << it << " ";

	cout << endl;

	cout << stb.size() << endl;

	for (auto it : stb)
		cout << it << " ";

	cout << endl;
}


#include <iostream>
#include <algorithm>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <cmath>
#include <unordered_map>
#include <queue>
#include <map>
#include <functional>
#include <stack>
#include <cmath>
#include <cstring>
#include <random>
#include <chrono>
#include <memory>
#include <cassert>
#include <numeric>
#include <iomanip>
#include <array>
#define int long long
#define pic pair<int, char>
#define x first
#define y second
#define ll long long
#define pii pair<long long, long long>
#define endl "\n"
#define all(a) (a).begin(), (a).end()
#pragma GCC optimize ("O3")
#define PI 3.14159265
#define pdd pair<double, double>
#define rect pair<pii, pii>

using namespace std;

const int N = 2e6 + 14;
const int inf = (int)1e18 + 10;
const int mod = 1e9 + 7;
const double eps = 1e-6;

mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

using namespace std;

int a, b;
bool used[N];
set<int> sta;
set<int> stb;

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cout.precision(20);

	cin >> a >> b;

	for(int i = 1; true; ++i)
		if (i * (i + 1) / 2 > a + b)
		{
			int mxi = i - 1;

			if (min(a, b) <= mxi)
			{
				if (a < b)
				{
					sta.insert(a);
					used[a] = true;
				}
				else
				{
					stb.insert(b);
					used[b] = true;
				}
			}
			else
			{
				if (a < b)
				{
					if (2 * a != mxi)
					{
						sta.insert(mxi);
						sta.insert(a - mxi);
					}
					else
					{
						sta.insert(mxi - 1);
						sta.insert(a - (mxi - 1));
					}
				}
				else
				{
					if (2 * b != mxi)
					{
						stb.insert(mxi);
						stb.insert(b - mxi);
					}
					else
					{
						stb.insert(mxi - 1);
						stb.insert(b - (mxi - 1));
					}
				}
			}

			break;
		}

	if (a < b)
	{
		for(int i = 1; true; ++i)
			if (!used[i] && !sta.count(i) && ! stb.count(i))
			{
				if (i > b)
					break;
				else
				{
					b -= i;
					stb.insert(i);
				}
			}
	}
	else
	{
		for (int i = 1; true; ++i)
			if (!used[i] && !sta.count(i) && !stb.count(i))
			{
				if (i > a)
					break;
				else
				{
					a -= i;
					sta.insert(i);
				}
			}
	}

	if (sta.find(0) != sta.end())
		sta.erase(0);

	if (stb.find(0) != stb.end())
		stb.erase(0);

	cout << sta.size() << endl;

	for (auto it : sta)
		cout << it << " ";

	cout << endl;

	cout << stb.size() << endl;

	for (auto it : stb)
		cout << it << " ";

	cout << endl;
}


#include <iostream>
#include <algorithm>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <cmath>
#include <unordered_map>
#include <queue>
#include <map>
#include <functional>
#include <stack>
#include <cmath>
#include <cstring>
#include <random>
#include <chrono>
#include <memory>
#include <cassert>
#include <numeric>
#include <iomanip>
#include <array>
#define int long long
#define pic pair<int, char>
#define x first
#define y second
#define ll long long
#define pii pair<long long, long long>
#define endl "\n"
#define all(a) (a).begin(), (a).end()
#pragma GCC optimize ("O3")
#define PI 3.14159265
#define pdd pair<double, double>
#define rect pair<pii, pii>

using namespace std;

const int N = 1e6 + 14;
const int inf = (int)1e18 + 10;
const int mod = 1e9 + 7;
const double eps = 1e-6;

mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

using namespace std;

int a, b;

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cout.precision(20);

	cin >> a >> b;

	set<int> sta;
	set<int> stb;

	bool sw = false;

	for (int i = 1; i <= 1e6; ++i)
	{
		if (!sw)
		{
			if (a >= i)
			{
				a -= i;
				sta.insert(i);
			}
			else if (b >= i)
			{
				b -= i;
				stb.insert(i);
			}
			else
			{
				if (a)
				{
					auto it = sta.find(i - a);

					if (it != sta.end())
					{
						int x = *it;
						sta.erase(it);
						sta.insert(i);
						a = 0;

						if (x <= b)
						{
							stb.insert(x);
							b -= x;
						}
					}
					else
					{
						it = stb.find(i - b);

						if (it == stb.end())
							break;

						int x = *it;
						stb.erase(it);
						stb.insert(i);
						b = 0;

						if (x <= a)
						{
							sta.insert(x);
							a -= x;
						}
					}
				}
			}
		}
		else
		{
			if (b >= i)
			{
				b -= i;
				stb.insert(i);
			}
			else if (a >= i)
			{
				a -= i;
				sta.insert(i);
			}
			else
			{
				if (a)
				{
					auto it = sta.find(i - a);

					if (it != sta.end())
					{
						int x = *it;
						sta.erase(it);
						sta.insert(i);
						a = 0;

						if (x <= b)
						{
							stb.insert(x);
							b -= x;
						}
					}
					else
					{
						it = stb.find(i - b);

						if (it == stb.end())
							break;

						int x = *it;
						stb.erase(it);
						stb.insert(i);
						b = 0;

						if (x <= a)
						{
							sta.insert(x);
							a -= x;
						}
					}
				}
			}
		}

		sw = !sw;
	}

	cout << sta.size() << endl;

	for (auto it : sta)
		cout << it << " ";

	cout << endl;

	cout << stb.size() << endl;

	for (auto it : stb)
		cout << it << " ";

	cout << endl;
}


#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
vector<int> make(int s, int x, vector<int>& used) {
  vector<int> res;
  for (int i = x; i >= 1; i--) {
    if (!used[i] && s - i >= 0) {
      s -= i;
      res.push_back(i);
      used[i] = true;
    }
  }
  return res;
}
void out(vector<int> v) {
  cout << v.size() << endl;
  for (int i = 0; i < (int) v.size(); i++) {
    if (i > 0) cout << " ";
    cout << v[i];
  }
  cout << endl;
}
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  int a, b;
  cin >> a >> b;
  int x = 1;
  while (x * (x + 1) / 2 <= a + b) x++;
  x--;
  vector<int> used(x + 1);
  out(make(a, x, used));
  out(make(b, x, used));
  return 0;
}


#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
vector<int> make(int s, int x, vector<int>& used) {
  vector<int> res;
  for (int i = x; i >= 1; i--) {
    if (s - i >= 0 && !used[i]) {
      res.push_back(i);
      s -= i;
      used[i] = true;
    }
  }
  return res;
}
void out(vector<int> v) {
  cout << v.size() << endl;
  for (int i = 0; i < (int) v.size(); i++) {
    if (i > 0) cout << " ";
    cout << v[i];
  }
  cout << endl;
}
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  int a, b;
  cin >> a >> b;
  int x = 1;
  while (x * (x + 1) / 2 < a + b) x++;
  vector<int> used(x + 1);
  out(make(a, x, used));
  out(make(b, x, used));
  return 0;
}


#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
vector<int> make(int s, int x, vector<int>& used) {
  vector<int> res;
  for (int i = x; i >= 1; i--) {
    if (!used[i] && s - i >= 0) {
      s -= i;
      res.push_back(i);
      used[i] = true;
    }
  }
  return res;
}
void out(vector<int> v) {
  cout << v.size() << endl;
  for (int i = 0; i < (int) v.size(); i++) {
    if (i > 0) cout << " ";
    cout << v[i];
  }
  cout << endl;
}
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  int a, b;
  cin >> a >> b;
  int x = 1;
  while (1LL * x * (x + 1) / 2 <= a + b) x++;
  vector<int> used(x + 1);
  out(make(a, x, used));
  out(make(b, x, used));
  return 0;
}


#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
vector<int> make(int s, int x, vector<int>& used) {
  vector<int> res;
  for (int i = x; i >= 1; i--) {
    if (!used[i] && s - i >= 0) {
      s -= i;
      res.push_back(i);
      used[i] = true;
    }
  }
  return res;
}
void out(vector<int> v) {
  cout << v.size() << endl;
  for (int i = 0; i < (int) v.size(); i++) {
    if (i > 0) cout << " ";
    cout << v[i];
  }
  cout << endl;
}
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  int a, b;
  cin >> a >> b;
  int x = 1;
  while (1LL * x * (x + 1) / 2 <= a + b) x++;
  x--;
  vector<int> used(x + 1);
  out(make(a, x, used));
  out(make(b, x, used));
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
static const int _ = [](){
	ios::sync_with_stdio(false);
	cin.sync_with_stdio(false);
	cout.sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	return 0;
}();

#define ll long long
#define ull unsigned long long
#define rep(i,a) for(ll i=0;i<(a);i++)
#define rng(i,a,b) for(ll i=(a);i<=(b);i++)
#define rev(i,a) for(ll i=(a)-1;i>=0;i--)
#define S size()
#define all(a) (a).begin(),(a).end()
#define any(i,a) for(auto& i:a)
#define pll pair<ll,ll>
#define pii pair<int,int>
#define X first
#define Y second
#define V vector
#define VL V<ll>
#define VVL V<VL>
#define VS V<string>

template<class T> inline vector<T> rv(ll n) { vector<T> v(n); rep(i, n) cin >> v[i]; return v; }
template<class T> inline void pv(const vector<T>& v) { rep(i, v.size()) cout << v[i] << " "; cout << endl; }
template<class T, class U> inline void amax(T& a, const U& b){ if (a < b) a = b; }
template<class T, class U> inline void amin(T& a, const U& b){ if (a > b) a = b; }

const ll MOD = 1e9 + 7;
const ll MOD1 = 998244353;
struct custom_hash {
	static uint64_t splitmix64(uint64_t x) {
		// http://xorshift.di.unimi.it/splitmix64.c
		x += 0x9e3779b97f4a7c15;
		x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
		x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
		return x ^ (x >> 31);
	}

	size_t operator()(uint64_t x) const {
		static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
		return splitmix64(x + FIXED_RANDOM);
	}
};

struct Rd {
	template<typename T>
	Rd& operator>>(T& n){
		cin >> n;
		return *this;
	}
	template<typename T>
	Rd& operator>>(vector<T>& v){
		for (ll i = 0; i < v.size(); i++){
			cin >> v[i];
		}
		return *this;
	}
	template<typename T, typename U>
	Rd& operator>>(vector<pair<T,U>>& v){
		for (ll i = 0; i < v.size(); i++){
			cin >> v[i].first >> v[i].second;
		}
		return *this;
	}
	template<typename T>
	Rd& operator>>(vector<vector<T>>& v){
		for (ll i = 0; i < v.size(); i++){
			for (ll j = 0; j < v[i].size(); j++){
				cin >> v[i][j];
			}
		}
		return *this;
	}
} rd;

ll GCD(ll a, ll b) {
	while (b) {
		ll r = a % b;
		a = b;
		b = r;
	}
	return a;
}

int main(int argc, char** argv){
	ll a, b, n = 0, cnt = 0; cin >> a >> b;
	while ((n + 2)*(n + 1) / 2 <= a + b) n++;
	vector<bool> f(n + 7, false);
	for (ll i = n; i >= 1; i--) if (a >= i) f[i] = true, ++cnt, a -= i;
	cout << cnt << '\n';
	for (ll i = 1; i <= n; i++) if (f[i]) cout << i << ' ';
	cout << '\n' << n - cnt << '\n';
	for (ll i = 1; i <= n; i++) if (!f[i]) cout << i << ' ';
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
static const int _ = [](){
	ios::sync_with_stdio(false);
	cin.sync_with_stdio(false);
	cout.sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	return 0;
}();

#define ll long long
#define ull unsigned long long
#define rep(i,a) for(ll i=0;i<(a);i++)
#define rng(i,a,b) for(ll i=(a);i<=(b);i++)
#define rev(i,a) for(ll i=(a)-1;i>=0;i--)
#define S size()
#define all(a) (a).begin(),(a).end()
#define any(i,a) for(auto& i:a)
#define pll pair<ll,ll>
#define pii pair<int,int>
#define X first
#define Y second
#define V vector
#define VL V<ll>
#define VVL V<VL>
#define VS V<string>

template<class T> inline vector<T> rv(ll n) { vector<T> v(n); rep(i, n) cin >> v[i]; return v; }
template<class T> inline void pv(const vector<T>& v) { rep(i, v.size()) cout << v[i] << " "; cout << endl; }
template<class T, class U> inline void amax(T& a, const U& b){ if (a < b) a = b; }
template<class T, class U> inline void amin(T& a, const U& b){ if (a > b) a = b; }

const ll MOD = 1e9 + 7;
const ll MOD1 = 998244353;
struct custom_hash {
	static uint64_t splitmix64(uint64_t x) {
		// http://xorshift.di.unimi.it/splitmix64.c
		x += 0x9e3779b97f4a7c15;
		x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
		x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
		return x ^ (x >> 31);
	}

	size_t operator()(uint64_t x) const {
		static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
		return splitmix64(x + FIXED_RANDOM);
	}
};

struct Rd {
	template<typename T>
	Rd& operator>>(T& n){
		cin >> n;
		return *this;
	}
	template<typename T>
	Rd& operator>>(vector<T>& v){
		for (ll i = 0; i < v.size(); i++){
			cin >> v[i];
		}
		return *this;
	}
	template<typename T, typename U>
	Rd& operator>>(vector<pair<T,U>>& v){
		for (ll i = 0; i < v.size(); i++){
			cin >> v[i].first >> v[i].second;
		}
		return *this;
	}
	template<typename T>
	Rd& operator>>(vector<vector<T>>& v){
		for (ll i = 0; i < v.size(); i++){
			for (ll j = 0; j < v[i].size(); j++){
				cin >> v[i][j];
			}
		}
		return *this;
	}
} rd;

ll GCD(ll a, ll b) {
	while (b) {
		ll r = a % b;
		a = b;
		b = r;
	}
	return a;
}

unordered_map<ll, vector<ll>, custom_hash> memo;
vector<ll> fac(ll n){
	//if (memo.count(n)) return memo[n];
	set<ll> s{ 1, n };
	ll sq = sqrt(n);
	for (ll i = 2; i <= sq; i++){
		if ((n%i) == 0){
			s.insert(i);
			s.insert(n / i);
		}
	}
	vector<ll> v(all(s));
	//memo[n] = v;
	return v;
}

const int N = 3e5 + 5, M = 1.5e7 + 5;
int n, g, ans, a[N], cc[M], np[M];

int main(int argc, char** argv){
	ll a, b; cin >> a >> b;
	ll l = 1, r = 1e10, m = (l + r) / 2;
	while (l+1 < r){
		ll c = (m*m + m) / 2;
		if (c == (a + b)) break;
		if (c > (a + b)){
			r = m;
		}
		else {
			l = m;
		}
		m = (l + r) / 2;
	}
	while ((m*m + m) / 2 < (a + b) && ((m + 1)*(m + 1) + m + 1) / 2 <= (a + b)){
		m++;
	}

	ll sa = 0, sb = 0;
	vector<ll> va, vb;

	unordered_map<ll, ll, custom_hash> mm;
	ll sum = 0;
	ll as = -1, ae = -1, bs = -1, be = -1;
	rng(i, 1, m){
		sum += i;
		mm[sum] = i;
		if (mm.count(sum - a)){
			as = mm[sum - a];
			ae = i;
			break;
		}
		if (mm.count(sum - b)){
			bs = mm[sum - b];
			be = i;
			break;
		}
	}

	if (as >= 0){
		rng(i, 1, m){
			if (i > as && i <= ae) va.push_back(i), sa += i;
			else if (b - sb >= i) vb.push_back(i), sb += i;
			else break;
		}
	}
	else if (bs >= 0){
		rng(i, 1, m){
			if (i > bs && i <= be) vb.push_back(i), sb += i;
			else if (a - sa >= i) va.push_back(i), sa += i;
			else break;
		}
	}
	else {
		rng(i, 1, 1e9){
			if (a - sa > i && a - sa <= m && b - sb >= i){
				sb += i;
				vb.push_back(i);
			}
			else if (b - sb > i && b - sb <= m && a - sa >= i){
				sa += i;
				va.push_back(i);
			}
			else if (a - sa >= i){
				sa += i;
				va.push_back(i);
			}
			else if (b - sb >= i){
				sb += i;
				vb.push_back(i);
			}
			else {
				break;
			}
		}
	}

	cout << va.size() << endl;
	rep(i, va.size()){
		cout << va[i] << ' ';
	}
	cout << endl << vb.size() << endl;
	rep(i, vb.size()){
		cout << vb[i] << ' ';
	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
static const int _ = [](){
	ios::sync_with_stdio(false);
	cin.sync_with_stdio(false);
	cout.sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	return 0;
}();

#define ll long long
#define ull unsigned long long
#define rep(i,a) for(ll i=0;i<(a);i++)
#define rng(i,a,b) for(ll i=(a);i<=(b);i++)
#define rev(i,a) for(ll i=(a)-1;i>=0;i--)
#define S size()
#define all(a) (a).begin(),(a).end()
#define any(i,a) for(auto& i:a)
#define pll pair<ll,ll>
#define pii pair<int,int>
#define X first
#define Y second
#define V vector
#define VL V<ll>
#define VVL V<VL>
#define VS V<string>

template<class T> inline vector<T> rv(ll n) { vector<T> v(n); rep(i, n) cin >> v[i]; return v; }
template<class T> inline void pv(const vector<T>& v) { rep(i, v.size()) cout << v[i] << " "; cout << endl; }
template<class T, class U> inline void amax(T& a, const U& b){ if (a < b) a = b; }
template<class T, class U> inline void amin(T& a, const U& b){ if (a > b) a = b; }

const ll MOD = 1e9 + 7;
const ll MOD1 = 998244353;
struct custom_hash {
	static uint64_t splitmix64(uint64_t x) {
		// http://xorshift.di.unimi.it/splitmix64.c
		x += 0x9e3779b97f4a7c15;
		x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
		x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
		return x ^ (x >> 31);
	}

	size_t operator()(uint64_t x) const {
		static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
		return splitmix64(x + FIXED_RANDOM);
	}
};

struct Rd {
	template<typename T>
	Rd& operator>>(T& n){
		cin >> n;
		return *this;
	}
	template<typename T>
	Rd& operator>>(vector<T>& v){
		for (ll i = 0; i < v.size(); i++){
			cin >> v[i];
		}
		return *this;
	}
	template<typename T, typename U>
	Rd& operator>>(vector<pair<T,U>>& v){
		for (ll i = 0; i < v.size(); i++){
			cin >> v[i].first >> v[i].second;
		}
		return *this;
	}
	template<typename T>
	Rd& operator>>(vector<vector<T>>& v){
		for (ll i = 0; i < v.size(); i++){
			for (ll j = 0; j < v[i].size(); j++){
				cin >> v[i][j];
			}
		}
		return *this;
	}
} rd;

ll GCD(ll a, ll b) {
	while (b) {
		ll r = a % b;
		a = b;
		b = r;
	}
	return a;
}

unordered_map<ll, vector<ll>, custom_hash> memo;
vector<ll> fac(ll n){
	//if (memo.count(n)) return memo[n];
	set<ll> s{ 1, n };
	ll sq = sqrt(n);
	for (ll i = 2; i <= sq; i++){
		if ((n%i) == 0){
			s.insert(i);
			s.insert(n / i);
		}
	}
	vector<ll> v(all(s));
	//memo[n] = v;
	return v;
}

const int N = 3e5 + 5, M = 1.5e7 + 5;
int n, g, ans, a[N], cc[M], np[M];

int main(int argc, char** argv){
	ll a, b; cin >> a >> b;
	ll l = 1, r = 1e10, m = (l + r) / 2;
	while (l+1 < r){
		ll c = (m*m + m) / 2;
		if (c == (a + b)) break;
		if (c > (a + b)){
			r = m;
		}
		else {
			l = m;
		}
		m = (l + r) / 2;
	}
	while ((m*m + m) / 2 < (a + b) && ((m + 1)*(m + 1) + m + 1) / 2 <= (a + b)){
		m++;
	}

	ll sa = 0, sb = 0;
	vector<ll> va, vb;

	unordered_map<ll, ll, custom_hash> mm;
	ll sum = 0;
	ll as = -1, ae = -1, bs = -1, be = -1;
	rng(i, 1, m){
		sum += i;
		mm[sum] = i;
		if (mm.count(sum - a)){
			as = mm[sum - a];
			ae = i;
			break;
		}
		if (mm.count(sum - b)){
			bs = mm[sum - b];
			be = i;
			break;
		}
	}

	if (as >= 0){
		rng(i, 1, m){
			if (i > as && i <= ae) va.push_back(i), sa += i;
			else if (b - sb >= i) vb.push_back(i), sb += i;
			else break;
		}
	}
	else if (bs >= 0){
		rng(i, 1, m){
			if (i > bs && i <= be) vb.push_back(i), sb += i;
			else if (a - sa >= i) va.push_back(i), sa += i;
			else break;
		}
	}
	else {
		ll k = 2, sw = 0;
		if (a<b) swap(a, b), sw = 1;
		while (a / k > m) k++;
		ae = as = (a / k) - (a / k / 2);
		unordered_set<ll, custom_hash> s;
		while (a - sa >= ae && a - sa > m)  sa += ae, ae++, s.insert(ae);
		if (a - sa < m && (a-sa>ae||a-sa<as)){
			s.insert(a - sa);
		}
		va.insert(va.end(),all(s));
		rng(i, 1, m){
			if (b - sb >= i && !s.count(i)) vb.push_back(i), sb += i;
		}
		if (sw){
			swap(va, vb);
		}
	}

	cout << va.size() << endl;
	rep(i, va.size()){
		cout << va[i] << ' ';
	}
	cout << endl << vb.size() << endl;
	rep(i, vb.size()){
		cout << vb[i] << ' ';
	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
static const int _ = [](){
	ios::sync_with_stdio(false);
	cin.sync_with_stdio(false);
	cout.sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	return 0;
}();

#define ll long long
#define ull unsigned long long
#define rep(i,a) for(ll i=0;i<(a);i++)
#define rng(i,a,b) for(ll i=(a);i<=(b);i++)
#define rev(i,a) for(ll i=(a)-1;i>=0;i--)
#define S size()
#define all(a) (a).begin(),(a).end()
#define any(i,a) for(auto& i:a)
#define pll pair<ll,ll>
#define pii pair<int,int>
#define X first
#define Y second
#define V vector
#define VL V<ll>
#define VVL V<VL>
#define VS V<string>

template<class T> inline vector<T> rv(ll n) { vector<T> v(n); rep(i, n) cin >> v[i]; return v; }
template<class T> inline void pv(const vector<T>& v) { rep(i, v.size()) cout << v[i] << " "; cout << endl; }
template<class T, class U> inline void amax(T& a, const U& b){ if (a < b) a = b; }
template<class T, class U> inline void amin(T& a, const U& b){ if (a > b) a = b; }

const ll MOD = 1e9 + 7;
const ll MOD1 = 998244353;
struct custom_hash {
	static uint64_t splitmix64(uint64_t x) {
		// http://xorshift.di.unimi.it/splitmix64.c
		x += 0x9e3779b97f4a7c15;
		x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
		x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
		return x ^ (x >> 31);
	}

	size_t operator()(uint64_t x) const {
		static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
		return splitmix64(x + FIXED_RANDOM);
	}
};

struct Rd {
	template<typename T>
	Rd& operator>>(T& n){
		cin >> n;
		return *this;
	}
	template<typename T>
	Rd& operator>>(vector<T>& v){
		for (ll i = 0; i < v.size(); i++){
			cin >> v[i];
		}
		return *this;
	}
	template<typename T, typename U>
	Rd& operator>>(vector<pair<T,U>>& v){
		for (ll i = 0; i < v.size(); i++){
			cin >> v[i].first >> v[i].second;
		}
		return *this;
	}
	template<typename T>
	Rd& operator>>(vector<vector<T>>& v){
		for (ll i = 0; i < v.size(); i++){
			for (ll j = 0; j < v[i].size(); j++){
				cin >> v[i][j];
			}
		}
		return *this;
	}
} rd;

ll GCD(ll a, ll b) {
	while (b) {
		ll r = a % b;
		a = b;
		b = r;
	}
	return a;
}

unordered_map<ll, vector<ll>, custom_hash> memo;
vector<ll> fac(ll n){
	//if (memo.count(n)) return memo[n];
	set<ll> s{ 1, n };
	ll sq = sqrt(n);
	for (ll i = 2; i <= sq; i++){
		if ((n%i) == 0){
			s.insert(i);
			s.insert(n / i);
		}
	}
	vector<ll> v(all(s));
	//memo[n] = v;
	return v;
}

const int N = 3e5 + 5, M = 1.5e7 + 5;
int n, g, ans, a[N], cc[M], np[M];

int main(int argc, char** argv){
	ll a, b; cin >> a >> b;
	ll l = 1, r = 1e10, m = (l + r) / 2;
	while (l+1 < r){
		ll c = (m*m + m) / 2;
		if (c == (a + b)) break;
		if (c > (a + b)){
			r = m;
		}
		else {
			l = m;
		}
		m = (l + r) / 2;
	}
	while ((m*m + m) / 2 < (a + b) && ((m + 1)*(m + 1) + m + 1) / 2 <= (a + b)){
		m++;
	}

	ll sa = 0, sb = 0;
	vector<ll> va, vb;

	unordered_map<ll, ll, custom_hash> mm;
	ll sum = 0;
	ll as = -1, ae = -1, bs = -1, be = -1;
	rng(i, 1, m){
		sum += i;
		mm[sum] = i;
		if (mm.count(sum - a)){
			as = mm[sum - a];
			ae = i;
			break;
		}
		if (mm.count(sum - b)){
			bs = mm[sum - b];
			be = i;
			break;
		}
	}

	if (as >= 0){
		rng(i, 1, m){
			if (i > as && i <= ae) va.push_back(i), sa += i;
			else if (b - sb >= i) vb.push_back(i), sb += i;
			else break;
		}
	}
	else if (bs >= 0){
		rng(i, 1, m){
			if (i > bs && i <= be) vb.push_back(i), sb += i;
			else if (a - sa >= i) va.push_back(i), sa += i;
			else break;
		}
	}
	else {
		ll k = 2, sw = 0;
		if (a<b) swap(a, b), sw = 1;
		while (a / k > m) k++;
		ae = as = a / k;
		unordered_set<ll, custom_hash> s;
		while (a - sa > 0 && a - sa > m)  sa += ae, ae++, s.insert(ae);
		if (a - sa < m && (a-sa>ae||a-sa<as)){
			s.insert(a - sa);
		}
		va.insert(va.end(),all(s));
		rng(i, 1, m){
			if (b - sb >= i && !s.count(i)) vb.push_back(i), sb += i;
		}
		if (sw){
			swap(va, vb);
		}
	}

	cout << va.size() << endl;
	rep(i, va.size()){
		cout << va[i] << ' ';
	}
	cout << endl << vb.size() << endl;
	rep(i, vb.size()){
		cout << vb[i] << ' ';
	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
static const int _ = [](){
	ios::sync_with_stdio(false);
	cin.sync_with_stdio(false);
	cout.sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	return 0;
}();

#define ll long long
#define ull unsigned long long
#define rep(i,a) for(ll i=0;i<(a);i++)
#define rng(i,a,b) for(ll i=(a);i<=(b);i++)
#define rev(i,a) for(ll i=(a)-1;i>=0;i--)
#define S size()
#define all(a) (a).begin(),(a).end()
#define any(i,a) for(auto& i:a)
#define pll pair<ll,ll>
#define pii pair<int,int>
#define X first
#define Y second
#define V vector
#define VL V<ll>
#define VVL V<VL>
#define VS V<string>

template<class T> inline vector<T> rv(ll n) { vector<T> v(n); rep(i, n) cin >> v[i]; return v; }
template<class T> inline void pv(const vector<T>& v) { rep(i, v.size()) cout << v[i] << " "; cout << endl; }
template<class T, class U> inline void amax(T& a, const U& b){ if (a < b) a = b; }
template<class T, class U> inline void amin(T& a, const U& b){ if (a > b) a = b; }

const ll MOD = 1e9 + 7;
const ll MOD1 = 998244353;
struct custom_hash {
	static uint64_t splitmix64(uint64_t x) {
		// http://xorshift.di.unimi.it/splitmix64.c
		x += 0x9e3779b97f4a7c15;
		x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
		x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
		return x ^ (x >> 31);
	}

	size_t operator()(uint64_t x) const {
		static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
		return splitmix64(x + FIXED_RANDOM);
	}
};

struct Rd {
	template<typename T>
	Rd& operator>>(T& n){
		cin >> n;
		return *this;
	}
	template<typename T>
	Rd& operator>>(vector<T>& v){
		for (ll i = 0; i < v.size(); i++){
			cin >> v[i];
		}
		return *this;
	}
	template<typename T, typename U>
	Rd& operator>>(vector<pair<T,U>>& v){
		for (ll i = 0; i < v.size(); i++){
			cin >> v[i].first >> v[i].second;
		}
		return *this;
	}
	template<typename T>
	Rd& operator>>(vector<vector<T>>& v){
		for (ll i = 0; i < v.size(); i++){
			for (ll j = 0; j < v[i].size(); j++){
				cin >> v[i][j];
			}
		}
		return *this;
	}
} rd;

ll GCD(ll a, ll b) {
	while (b) {
		ll r = a % b;
		a = b;
		b = r;
	}
	return a;
}

unordered_map<ll, vector<ll>, custom_hash> memo;
vector<ll> fac(ll n){
	//if (memo.count(n)) return memo[n];
	set<ll> s{ 1, n };
	ll sq = sqrt(n);
	for (ll i = 2; i <= sq; i++){
		if ((n%i) == 0){
			s.insert(i);
			s.insert(n / i);
		}
	}
	vector<ll> v(all(s));
	//memo[n] = v;
	return v;
}

const int N = 3e5 + 5, M = 1.5e7 + 5;
int n, g, ans, a[N], cc[M], np[M];

int main(int argc, char** argv){
	ll a, b; cin >> a >> b;
	ll l = 1, r = 1e10, m = (l + r) / 2;
	while (l+1 < r){
		ll c = (m*m + m) / 2;
		if (c == (a + b)) break;
		if (c > (a + b)){
			r = m;
		}
		else {
			l = m;
		}
		m = (l + r) / 2;
	}
	while ((m*m + m) / 2 < (a + b) && ((m + 1)*(m + 1) + m + 1) / 2 <= (a + b)){
		m++;
	}

	ll sa = 0, sb = 0;
	vector<ll> va, vb;

	unordered_map<ll, ll, custom_hash> mm;
	ll sum = 0;
	ll as = -1, ae = -1, bs = -1, be = -1;
	rng(i, 1, m){
		sum += i;
		mm[sum] = i;
		if (mm.count(sum - a)){
			as = mm[sum - a];
			ae = i;
			break;
		}
		if (mm.count(sum - b)){
			bs = mm[sum - b];
			be = i;
			break;
		}
	}

	if (as >= 0){
		rng(i, 1, m){
			if (i > as && i <= ae) va.push_back(i), sa += i;
			else if (b - sb >= i) vb.push_back(i), sb += i;
			else break;
		}
	}
	else if (bs >= 0){
		rng(i, 1, m){
			if (i > bs && i <= be) vb.push_back(i), sb += i;
			else if (a - sa >= i) va.push_back(i), sa += i;
			else break;
		}
	}
	else {
		ll k = 2, sw = 0;
		if (a<b) swap(a, b), sw = 1;
		while (a / k > m) k++;
		ae = as = (a / k);
		unordered_set<ll, custom_hash> s;
		while (a - sa >= ae && a - sa > m)  sa += ae, ae++, s.insert(ae);
		if (a - sa < m && (a-sa>ae||a-sa<as)){
			s.insert(a - sa);
		}
		va.insert(va.end(),all(s));
		rng(i, 1, m){
			if (b - sb >= i && !s.count(i)) vb.push_back(i), sb += i;
		}
		if (sw){
			swap(va, vb);
		}
	}

	cout << va.size() << endl;
	rep(i, va.size()){
		cout << va[i] << ' ';
	}
	cout << endl << vb.size() << endl;
	rep(i, vb.size()){
		cout << vb[i] << ' ';
	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
static const int _ = [](){
	ios::sync_with_stdio(false);
	cin.sync_with_stdio(false);
	cout.sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	return 0;
}();

#define ll long long
#define ull unsigned long long
#define rep(i,a) for(ll i=0;i<(a);i++)
#define rng(i,a,b) for(ll i=(a);i<=(b);i++)
#define rev(i,a) for(ll i=(a)-1;i>=0;i--)
#define S size()
#define all(a) (a).begin(),(a).end()
#define any(i,a) for(auto& i:a)
#define pll pair<ll,ll>
#define pii pair<int,int>
#define X first
#define Y second
#define V vector
#define VL V<ll>
#define VVL V<VL>
#define VS V<string>

template<class T> inline vector<T> rv(ll n) { vector<T> v(n); rep(i, n) cin >> v[i]; return v; }
template<class T> inline void pv(const vector<T>& v) { rep(i, v.size()) cout << v[i] << " "; cout << endl; }
template<class T, class U> inline void amax(T& a, const U& b){ if (a < b) a = b; }
template<class T, class U> inline void amin(T& a, const U& b){ if (a > b) a = b; }

const ll MOD = 1e9 + 7;
const ll MOD1 = 998244353;
struct custom_hash {
	static uint64_t splitmix64(uint64_t x) {
		// http://xorshift.di.unimi.it/splitmix64.c
		x += 0x9e3779b97f4a7c15;
		x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
		x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
		return x ^ (x >> 31);
	}

	size_t operator()(uint64_t x) const {
		static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
		return splitmix64(x + FIXED_RANDOM);
	}
};

struct Rd {
	template<typename T>
	Rd& operator>>(T& n){
		cin >> n;
		return *this;
	}
	template<typename T>
	Rd& operator>>(vector<T>& v){
		for (ll i = 0; i < v.size(); i++){
			cin >> v[i];
		}
		return *this;
	}
	template<typename T, typename U>
	Rd& operator>>(vector<pair<T,U>>& v){
		for (ll i = 0; i < v.size(); i++){
			cin >> v[i].first >> v[i].second;
		}
		return *this;
	}
	template<typename T>
	Rd& operator>>(vector<vector<T>>& v){
		for (ll i = 0; i < v.size(); i++){
			for (ll j = 0; j < v[i].size(); j++){
				cin >> v[i][j];
			}
		}
		return *this;
	}
} rd;

ll GCD(ll a, ll b) {
	while (b) {
		ll r = a % b;
		a = b;
		b = r;
	}
	return a;
}

unordered_map<ll, vector<ll>, custom_hash> memo;
vector<ll> fac(ll n){
	//if (memo.count(n)) return memo[n];
	set<ll> s{ 1, n };
	ll sq = sqrt(n);
	for (ll i = 2; i <= sq; i++){
		if ((n%i) == 0){
			s.insert(i);
			s.insert(n / i);
		}
	}
	vector<ll> v(all(s));
	//memo[n] = v;
	return v;
}

const int N = 3e5 + 5, M = 1.5e7 + 5;
int n, g, ans, a[N], cc[M], np[M];

int main(int argc, char** argv){
	ll a, b; cin >> a >> b;
	ll l = 1, r = 1e10, m = (l + r) / 2;
	while (l+1 < r){
		ll c = (m*m + m) / 2;
		if (c == (a + b)) break;
		if (c > (a + b)){
			r = m;
		}
		else {
			l = m;
		}
		m = (l + r) / 2;
	}
	while ((m*m + m) / 2 < (a + b) && ((m + 1)*(m + 1) + m + 1) / 2 <= (a + b)){
		m++;
	}

	ll sa = 0, sb = 0;
	vector<ll> va, vb;
	rng(i, 1, 1e9){
		if (a - sa > i && a - sa <= m && b - sb >= i){
			sb += i;
			vb.push_back(i);
		}
		else if (b - sb > i && b - sb <= m && a - sa >= i){
			sa += i;
			va.push_back(i);
		}
		else if (a - sa >= i){
			sa += i;
			va.push_back(i);
		}
		else if (b - sb >= i){
			sb += i;
			vb.push_back(i);
		}
		else {
			break;
		}
	}

	cout << va.size() << endl;
	rep(i, va.size()){
		cout << va[i] << ' ';
	}
	cout << endl << vb.size() << endl;
	rep(i, vb.size()){
		cout << vb[i] << ' ';
	}

	return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <cmath>
#include <list>
#include <ctime>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#define speed ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define inf 0x3f3f3f3f
using namespace std;
inline int FastI() {
	char c = ' '; int ans = 0;
	bool minus = 0;
	while (!isdigit(c)) {
		if (c == '-')
			minus = 1;
		c = _getc_nolock(stdin);
		if (!isdigit(c))
			minus = 0;
	}
	while (isdigit(c)) {
		ans *= 10ll;
		ans += c - '0';
		c = _getc_nolock(stdin);
	}
	if (minus) return -ans;
	else return ans;
}
inline void FastO(int val) {
	bool c = 0;
	if (val < 0)
		_putc_nolock('-', stdout), val = -val;
	for (int i = 1000000000; i >= 1; i /= 10) {
		if (val / i) {
			c = 1;
			_putc_nolock(val / i + '0', stdout);
			val %= i;
		}
		else if (c) _putc_nolock('0', stdout);
	}
	if (!c) _putc_nolock('0', stdout);
	_putc_nolock(' ', stdout);
}

int main() {
	speed;
	int a = FastI(), b = FastI(), ab = a + b, to, l = 0, r = 1000000000;
	if (a + b == 0)
		return cout << "0\n0", 0;
	while (1) {
		long long mid = l + ((r - l) / 2), v = (mid * (mid + 1)) / 2, vp = (mid * (mid - 1)) / 2;
		if (v > ab && vp <= ab) {
			to = mid;
			break;
		}
		if (v > ab)
			r = mid;
		else
			l = mid;
	}
	vector<int>v(to);
	int cnt = 0;
	for (int i = to - 1; i > 0; i--)
		if (i <= a) {
			a -= i;
			v[i] = 1;
			cnt++;
		}
	cout << cnt << '\n';
	for (int i = 1; i < to; ++i)
		if (v[i])
			cout << i << ' ';
	cout << '\n' << to - cnt - 1 << '\n';
	for (int i = 1; i < to; ++i)
		if (!v[i])
			cout << i << ' ';
}


using System;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace Golden_System
{
    internal class Program
    {
        //public static int k = 1;
        //public static int height = 1;
        //private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024 * 10), Encoding.ASCII, false, 1024 * 10);
        //public interface INode
        //{
        //}
        //public class Node : INode
        //{
        //    public string data;
        //    public List<Node> list_nodes = new List<Node>();
        //    public Node(string data)
        //    {
        //        this.data = data;
        //    }
        //    public void add(Node node1)
        //    {
        //        list_nodes.Add(node1);
        //    }
        //}
        //public static int RunTreeSTMT(Node node, string searchStr, string insert)
        //{
        //    Node root = node;
        //    if (String.Compare(root.data, searchStr, true) == 0)
        //    {
        //        root.add(new Node(insert));
        //        return 0;
        //    }
        //    else
        //    {
        //        for (int i = 0; i < root.list_nodes.Count; i++)
        //            RunTreeSTMT(root.list_nodes[i], searchStr, insert);
        //    }
        //    return 1;

        //}
        //public static int HightOfTree(Node node)
        //{
        //    Node root = node;
        //    if (root.list_nodes.Count == 0)
        //    {
        //        if (height < k)
        //            height = k;
        //        k = 1;
        //    }
        //    else
        //    {
        //        for (int i = 0; i < root.list_nodes.Count; i++)
        //        {
        //            k++;
        //            HightOfTree(root.list_nodes[i]);

        //        }
        //    }
        //    return height;
        //}
        public static int Main(string[] args)
        {
            int[,] arr=new int[200000,2];
            int max1, max2,summary_width;
            max1 = 1;
            max2 = 1;
            summary_width = 0;
            string[] split = new string[2];
            int n = int.Parse(Console.ReadLine());
            for (int i = 0; i < n; i++)
            {
                string str = Console.ReadLine();
                split = str.Split(new Char[] { ' ' });
                arr[i,0] = int.Parse(split[0]);
                summary_width += arr[i, 0];
                arr[i,1] = int.Parse(split[1]);
                if (arr[i, 1] >= max1 && arr[i, 1] >= max2)
                {
                    max2 = max1;
                    max1 = arr[i, 1];
                }
                else if (arr[i, 1] >= max2 && arr[i, 1] < max1)
                    max2 = arr[i, 1];
                else if (arr[i, 1] == max1)
                    max2 = max1;
                if(max1<max2)
                {
                    int temp =max1;
                    max1=max2;
                    max2=temp;
                }
            }
            for (int i = 0; i < n; i++)
            {
                if (arr[i, 1] == max1)
                    Console.Write(max2*(summary_width-arr[i,0])+" ");
                else
                    Console.Write(max1 * (summary_width - arr[i, 0]) + " ");
            }
                return 0;
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace B {
    class Program {
        static void Main(string[] args) {
            int n = int.Parse(Console.ReadLine());
            int[,] friends = new int[n, 2];

            for(int i = 0; i < n; i++) {
                var s = Console.ReadLine().Split(' ');
                friends[i, 0] = int.Parse(s[0]);
                friends[i, 1] = int.Parse(s[1]);
            }

            for (int i = 0; i < n; i++) {

                int width, height;
                width = height = 0;

                for (int j = 0; j < n; j++) {
                    if (i == j) {
                        continue;
                    }

                    height = friends[j, 1] > height ? friends[j, 1] : height;
                    width += friends[j, 0];
                }
                Console.Write("{0} ", width * height);
            }
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[,] friends = new int[n, 2];
            int allWidth = 0;
            int height1 = 0;
            int height2 = 0;

            for (int i = 0; i < n; i++)
            {
                int[] size = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
                int width = size[0];
                int height = size[1];

                allWidth += width;

                if (height > height2)
                {
                    height1 = height2;
                    height2 = height;
                }
                else if (height > height1)
                {
                    height1 = height;
                }
                friends[i, 0] = width;
                friends[i, 1] = height;
            }

            for (int i = 0; i < n; i++)
            {
                int width = allWidth - friends[i, 0];
                int height = friends[i, 1] == height2 ? height1 : height2;

                Console.Write(string.Format("{0} ", width * height));
            }
        }
    }
}


using System;
using System.Collections.Generic;
using System.Text;

namespace Reposts
{

    class Program
    {
        static void Main(string[] args)
        {
            long count = long.Parse(Console.ReadLine());
            long[,] arr = new long[count, 2];
            long maxInd = 0;
            long maxL = -1;
            long preMax = -1;
            long totalW = 0;
            var strs = Console.ReadLine().Split(' ');
            arr[0, 0] = long.Parse(strs[0]);
            arr[0, 1] = long.Parse(strs[1]);
            totalW += arr[0, 0];
            strs = Console.ReadLine().Split(' ');
            arr[1, 0] = long.Parse(strs[0]);
            arr[1, 1] = long.Parse(strs[1]);
            totalW += arr[1, 0];
            if (arr[0, 1] > arr[1, 1])
            {
                maxL = arr[0, 1];
                preMax = arr[1, 1];
            }
            else
            {
                 maxL = arr[1, 1];
                preMax = arr[0, 1];
            }
            for (long i = 2; i < count; i++)
            {
                strs = Console.ReadLine().Split(' ');
                arr[i, 0] = long.Parse(strs[0]);
                arr[i, 1] = long.Parse(strs[1]);
                totalW += arr[i, 0];
                if (maxL <= arr[i, 1])
                {
                    preMax = maxL;
                    maxL = arr[i, 1];
                }
            }
            long f = totalW*maxL;
            StringBuilder sb=new StringBuilder();
            for (int i = 0; i < count; i++)
            {
                if (arr[i, 1] == maxL)
                {
                    sb.Append( ((totalW - arr[i, 0])*preMax));
                }
                else
                {
                    sb.Append((totalW - arr[i, 0]) * maxL);
                }
                sb.Append(' ');
            }
            sb.Remove(sb.Length - 1, 1);
            Console.WriteLine(sb.ToString());

        }
    }
}


using System;
using System.Collections.Generic;
using System.Text;

namespace Reposts
{

    class Program
    {
        static void Main(string[] args)
        {
            long count = long.Parse(Console.ReadLine());
            long[,] arr = new long[count, 2];
            long maxInd = 0;
            long maxL = 0;
            long preMax = 0;
            long totalW = 0;

            if (arr[0, 1] > arr[1, 1])
            {
                maxL = arr[0, 1];
                preMax = arr[1, 1];
            }
            else
            {
                 maxL = arr[1, 1];
                preMax = arr[0, 1];
            }
            for (long i = 0; i < count; i++)
            {
                var strs = Console.ReadLine().Split(' ');
                arr[i, 0] = long.Parse(strs[0]);
                arr[i, 1] = long.Parse(strs[1]);
                totalW += arr[i, 0];
                if (arr[i, 1] > maxL)
                {
                    preMax = maxL;
                    maxL = arr[i, 1];
                }
                else
                {
                    if (arr[i, 1] > preMax)
                        preMax = arr[i, 1];
                }
            }
            long f = totalW*maxL;
            StringBuilder sb=new StringBuilder();
            for (int i = 0; i < count; i++)
            {
                if (arr[i, 1] != maxL)
                {
                    sb.Append( ((totalW - arr[i, 0])*maxL));
                }
                else
                {
                    sb.Append((totalW - arr[i, 0]) * preMax);
                }
                sb.Append(' ');
            }
            sb.Remove(sb.Length - 1, 1);
            Console.WriteLine(sb.ToString());

        }
    }
}


using System;
using System.Collections.Generic;
using System.Text;

namespace Reposts
{

    class Program
    {
        static void Main(string[] args)
        {
            int count = int.Parse(Console.ReadLine());
            int[,]arr=new int[count,2];
            int maxInd = 0;
            int maxL = -1;
            int preMax = -1;
            int totalW = 0;
            var strs = Console.ReadLine().Split(' ');
                arr[0, 0] = int.Parse(strs[0]);
                arr[0, 1] = int.Parse(strs[1]);
            totalW += arr[0, 0];
            strs = Console.ReadLine().Split(' ');
                arr[1, 0] = int.Parse(strs[0]);
                arr[1, 1] = int.Parse(strs[1]);
            totalW += arr[1, 0];
            if (arr[0, 1] > arr[1, 1])
            {
                maxL = arr[0, 1];
                preMax = arr[1, 1];
            }
            else
            {
                 maxL = arr[1, 1];
                preMax = arr[0, 1];
            }
            for (int i = 2; i < count; i++)
            {
                strs = Console.ReadLine().Split(' ');
                arr[i, 0] = int.Parse(strs[0]);
                arr[i, 1] = int.Parse(strs[1]);
                totalW += arr[i, 0];
                if (maxL <= arr[i, 1])
                {
                    preMax = maxL;
                    maxL = arr[i, 1];
                }
            }
            long f = totalW*maxL;
            StringBuilder sb=new StringBuilder();
            for (int i = 0; i < count; i++)
            {
                if (arr[i, 1] == maxL)
                {
                    sb.Append((long) ((totalW - arr[i, 0])*preMax));
                }
                else
                {
                    sb.Append((long)((totalW - arr[i, 0]) * maxL));
                }
                sb.Append(' ');
            }
            sb.Remove(sb.Length - 1, 1);
            Console.WriteLine(sb.ToString());

        }
    }
}


using System;
using System.Collections.Generic;
using System.Diagnostics;

namespace SolutionA
{
    class Program
    {
        static void Main(string[] args)
        {
            int num = int.Parse(Console.ReadLine());

            int[] width = new int[num];
            int[] height = new int[num];

            int totalWidth = 0;

            for (int i = 0; i < num; i++)
            {
                int[] f = toIntArray(Console.ReadLine().Split(' '));

                totalWidth += f[0];

                width[i] = f[0];
                height[i] = f[1];
            }

            initMax(height, num);
            for (int i = 0; i < num; i++)
            {
                Console.Write(((totalWidth - width[i]) * (getMaxHeight(i))) + " ");
            }

            Console.WriteLine();
        }

        static int getMaxHeight(int index)
        {
            if (index != maxIndex)
                return maxHeight;
            else
                return lastMaxHeight;
        }

        static int maxHeight = -1, lastMaxHeight = -1, maxIndex = -1;
        static void initMax(int[] array, int l)
        {
            int max = -1;
            for (int i = 0; i < l; i++)
            {
                if (max == -1 || array[i] > max)
                {
                    max = array[i];
                    maxIndex = i;
                }
            }

            maxHeight = max;

            int[] copy = (int[])array.Clone();
            Array.Sort(copy);
            lastMaxHeight = copy[l - 2];
        }

        static int[] toIntArray(string[] data)
        {
            int[] digits = new int[data.Length];
            for (int i = 0; i < data.Length; i++) digits[i] = int.Parse(data[i]);
            return digits;
        }
    }
}


using System;
using System.Collections.Generic;
using System.Diagnostics;

namespace SolutionA
{
    class Program
    {
        static void Main(string[] args)
        {
            int num = int.Parse(Console.ReadLine());

            int[] width = new int[num];
            int[] height = new int[num];

            int totalWidth = 0;

            for (int i = 0; i < num; i++)
            {
                int[] f = toIntArray(Console.ReadLine().Split(' '));

                totalWidth += f[0];

                width[i] = f[0];
                height[i] = f[1];
            }

            for (int i = 0; i < num; i++)
            {
                Console.Write(((totalWidth - width[i]) * (getMaxHeight(height, num, i))) + " ");
            }

            Console.WriteLine();
        }

        static int getMaxHeight(int[] array, int l, int not)
        {
            int max = -1;

            for (int i = 0; i < l; i++)
            {
                if (i != not && (max == -1 || array[i] > max))
                {
                    max = array[i];
                }
            }

            return max;
        }

        static int[] toIntArray(string[] data)
        {
            int[] digits = new int[data.Length];
            for (int i = 0; i < data.Length; i++) digits[i] = int.Parse(data[i]);
            return digits;
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication3
{
    class Wah
    {
        int w;
        int h;
        static public long cw = 0;
        static public int max1 = 0;
        static public int max2 = 0;
        public void MinSqauer()
        {
            int r;
            long k = cw - (long)w;
            if (h == max1)
                r = max2;
            else
                r = max1;
            Console.Write("{0} ", r*k);
        }

        public Wah(int w, int h)
        {
            this.w = w;
            this.h = h;
            cw += w;
            if (h >= max1)
                max1 = h;
            else
                if (h > max2)
                    max2 = h;

        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            Wah[] a = new Wah[n];
            for (int i = 0; i < n; ++i)
            {
                string str = Console.ReadLine();
                int index = str.IndexOf(' ');
                int w = Convert.ToInt32(str.Remove(index));
                int h = Convert.ToInt32(str.Substring(index));
                a[i] = new Wah(w, h);
            }
            for (int i = 0; i < n; ++i)
            {
                a[i].MinSqauer();
            }

        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication3
{
    class Wah
    {
        int w;
        int h;
        static public int cw = 0;
        static public int max1 = 0;
        static public int max2 = 0;
        public void MinSqauer()
        {
            int r, k = cw - w;
            if (h == max1)
                r = max2;
            else
                r = max1;
            Console.Write("{0} ", r*k);
        }

        public Wah(int w, int h)
        {
            this.w = w;
            this.h = h;
            cw += w;
            if (h > max1)
                max1 = h;
            else
                if (h > max2)
                    max2 = h;

        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            Wah[] a = new Wah[n];
            for (int i = 0; i < n; ++i)
            {
                string str = Console.ReadLine();
                int index = str.IndexOf(' ');
                int w = Convert.ToInt32(str.Remove(index));
                int h = Convert.ToInt32(str.Substring(index));
                a[i] = new Wah(w, h);
            }
            for (int i = 0; i < n; ++i)
            {
                a[i].MinSqauer();
            }

        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication3
{
    class Wah
    {
        int w;
        int h;
        static public long cw = 0;
        static public int max1 = 0;
        static public int max2 = 0;
        public void MinSqauer()
        {
            int r;
            long k = cw - (long)w;
            if (h == max1)
                r = max2;
            else
                r = max1;
            long sqauer = (long)r * (long)k;
            Console.Write("{0} ", sqauer);
        }

        public Wah(int w, int h)
        {
            this.w = w;
            this.h = h;
            cw += w;
            if (h > max1)
            {
                max2 = max1;
                max1 = h;
            }
            else
                if (h > max2)
                    max2 = h;

        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            Wah[] a = new Wah[n];
            for (int i = 0; i < n; ++i)
            {
                string str = Console.ReadLine();
                int index = str.IndexOf(' ');
                int w = Convert.ToInt32(str.Remove(index));
                int h = Convert.ToInt32(str.Substring(index));
                a[i] = new Wah(w, h);
            }
            for (int i = 0; i < n; ++i)
            {
                a[i].MinSqauer();
            }

        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication3
{
    class Wah
    {
        int w;
        int h;
        static public int cw = 0;
        static public int max1 = 0;
        static public int max2 = 0;
        public void MinSqauer()
        {
            int r;
            int k = cw - w;
            if (h == max1)
                r = max2;
            else
                r = max1;
            Console.Write("{0} ", r*k);
        }

        public Wah(int w, int h)
        {
            this.w = w;
            this.h = h;
            cw += w;
            if (h > max1)
            {
                max2 = max1;
                max1 = h;
            }
            else
                if (h > max2)
                    max2 = h;

        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            Wah[] a = new Wah[n];
            for (int i = 0; i < n; ++i)
            {
                string str = Console.ReadLine();
                int index = str.IndexOf(' ');
                int w = Convert.ToInt32(str.Remove(index));
                int h = Convert.ToInt32(str.Substring(index));
                a[i] = new Wah(w, h);
            }
            for (int i = 0; i < n; ++i)
            {
                a[i].MinSqauer();
            }

        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication3
{
    class Wah
    {
        int w;
        int h;
        static public long cw = 0;
        static public int max1 = 0;
        static public int max2 = 0;
        public void MinSqauer()
        {
            int r;
            long k = cw - (long)w;
            if (h == max1)
                r = max2;
            else
                r = max1;
            Console.Write("{0} ", r*k);
        }

        public Wah(int w, int h)
        {
            this.w = w;
            this.h = h;
            cw += w;
            if (h > max1)
                max1 = h;
            else
                if (h > max2)
                    max2 = h;

        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            Wah[] a = new Wah[n];
            for (int i = 0; i < n; ++i)
            {
                string str = Console.ReadLine();
                int index = str.IndexOf(' ');
                int w = Convert.ToInt32(str.Remove(index));
                int h = Convert.ToInt32(str.Substring(index));
                a[i] = new Wah(w, h);
            }
            for (int i = 0; i < n; ++i)
            {
                a[i].MinSqauer();
            }

        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication3
{
    class Wah
    {
        int w;
        int h;
        static public long cw = 0;
        static public int max1 = 0;
        static public int max2 = 0;
        public void MinSqauer()
        {
            int r;
            long k = cw - (long)w;
            if (h == max1)
                r = max2;
            else
                r = max1;
            long sqauer = (long)r * (long)k;
            Console.Write("{0} ", sqauer);
        }

        public Wah(int w, int h)
        {
            this.w = w;
            this.h = h;
            cw += w;
            if (h > max1)
                max1 = h;
            else
                if (h > max2)
                    max2 = h;

        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            Wah[] a = new Wah[n];
            for (int i = 0; i < n; ++i)
            {
                string str = Console.ReadLine();
                int index = str.IndexOf(' ');
                int w = Convert.ToInt32(str.Remove(index));
                int h = Convert.ToInt32(str.Substring(index));
                a[i] = new Wah(w, h);
            }
            for (int i = 0; i < n; ++i)
            {
                a[i].MinSqauer();
            }

        }
    }
}


using System;
using System.IO;
using System.Linq;
using System.Text;

namespace Photo_to_Remember
{
    internal class Program
    {
        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);

        private static void Main(string[] args)
        {
            int n = Next();

            var w = new int[n];
            var h = new int[n];
            for (int i = 0; i < n; i++)
            {
                w[i] = Next();
                h[i] = Next();
            }

            int sum = w.Sum();
            int maxi = 0;
            for (int i = 1; i < n; i++)
            {
                if (h[i] > h[maxi])
                    maxi = i;
            }
            int max2 = int.MinValue;
            for (int i = 0; i < n; i++)
            {
                if (i == maxi)
                    continue;
                if (h[i] > max2)
                    max2 = h[i];
            }

            for (int i = 0; i < n; i++)
            {
                if (i == maxi)
                {
                    writer.WriteLine((sum - w[i])*max2);
                }
                else
                {
                    writer.WriteLine((sum - w[i])*h[maxi]);
                }
            }

            writer.Flush();
        }

        private static int Next()
        {
            int c;
            int res = 0;
            do
            {
                c = reader.Read();
                if (c == -1)
                    return res;
            } while (c < '0' || c > '9');
            res = c - '0';
            while (true)
            {
                c = reader.Read();
                if (c < '0' || c > '9')
                    return res;
                res *= 10;
                res += c - '0';
            }
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace second
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            string[] temp = Console.ReadLine().Split(' ');

            Person[] arr = new Person[n];
            arr[0] = new Person(Convert.ToInt32(temp[0]), Convert.ToInt32(temp[1]));

            int sumW = arr[0].w;
            Max hMax = new Max(arr[0].h, 0);

            for(int i = 1; i < n; i++)
            {
                temp = Console.ReadLine().Split(' ');

                arr[i] = new Person(Convert.ToInt32(temp[0]), Convert.ToInt32(temp[1]));

                sumW += arr[i].w;

                if(hMax.value < arr[i].h)
                {
                    hMax.value = arr[i].h;
                    hMax.num = i;
                }

            }

            for(int i = 0; i < n; i++)
            {
                int h = 0, w = sumW - arr[i].w;

                if (hMax.num != i)
                {
                    h = hMax.value;
                }
                else
                {
                    for (int j = 0; j < n; j++)
                    {
                        if (i == j)
                            continue;

                        if (arr[j].h > h)
                            h = arr[j].h;

                    }
                }

                Console.Write("{0} ", w * h);
            }

        }
    }

    class Person
    {
        public int w;
        public int h;

        public Person(int w, int h)
        {
            this.w = w;
            this.h = h;
        }
    }

    class Max
    {
        public int value;
        public int num;

        public Max(int value, int num)
        {
            this.value = value;
            this.num = num;
        }
    }
}


using System;
using System.Collections.Generic;

namespace _522B
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            var w = new int[n];
            var h = new int[n];
            int wSum = 0;
            int hMax1 = 0, hMax2 = 0;
            HashSet<int> hMax1I = new HashSet<int>(), hMax2I = new HashSet<int>();
            hMax1 = h[0]; hMax1I.Add(0);
            for (int i = 0; i < n; i++)
            {
                string[] line = Console.ReadLine().Split(' ');
                int x = int.Parse(line[0]), y = int.Parse(line[1]);
                w[i] = x; wSum += x;
                if (y > hMax1)
                {
                    if (hMax1 > hMax2)
                    {
                        hMax2 = hMax1;
                        hMax2I.Clear();
                        foreach (var a in hMax1I) hMax2I.Add(a);
                    }
                    hMax1 = y;
                    hMax1I.Clear();
                    hMax1I.Add(i);
                }
                else if (y == hMax1)
                {
                    hMax1I.Add(i);
                }
                else if (y > hMax2)
                {
                    hMax2 = y;
                    hMax2I.Clear();
                    hMax2I.Add(i);
                }
                else if (y == hMax2)
                {
                    hMax2I.Add(i);
                }
            }
            int[] b = new int[n];
            for (int i = 0; i < n; i++)
            {
                wSum -= w[i];
                if (i > 0) wSum += w[i - 1];
                int hValue = hMax1;
                if (hMax1I.Contains(i)) hValue = hMax2;
                b[i] = wSum * hValue;
            }
            Console.WriteLine(string.Join(" ", b));
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;

namespace _522B
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            var w = new int[n];
            var h = new int[n];
            int wSum = 0;
            int hMax1 = 0, hMax2 = 0;
            HashSet<int> hMax1I = new HashSet<int>(), hMax2I = new HashSet<int>();
            for (int i = 0; i < n; i++)
            {
                string[] line = Console.ReadLine().Split(' ');
                int x = int.Parse(line[0]), y = int.Parse(line[1]);
                w[i] = x; wSum += x;
                if (hMax1 == 0)
                {
                    hMax1 = y;
                    hMax1I.Add(i);
                }
                else if (hMax2 == 0)
                {
                    if (y > hMax1)
                    {
                        hMax2 = hMax1;
                        hMax2I.Add(hMax1I.First());
                        hMax1 = y;
                        hMax1I.Add(i);
                    }
                    else
                    {
                        hMax2 = y;
                        hMax2I.Add(i);
                    }
                }
                else if (y > hMax1)
                {
                    if (hMax1 > hMax2)
                    {
                        hMax2 = hMax1;
                        hMax2I.Clear();
                        foreach (var a in hMax1I) hMax2I.Add(a);
                    }
                    hMax1 = y;
                    hMax1I.Clear();
                    hMax1I.Add(i);
                }
                else if (y == hMax1)
                {
                    hMax1I.Add(i);
                }
                else if (y > hMax2)
                {
                    hMax2 = y;
                    hMax2I.Clear();
                    hMax2I.Add(i);
                }
                else if (y == hMax2)
                {
                    hMax2I.Add(i);
                }
            }
            int[] b = new int[n];
            for (int i = 0; i < n; i++)
            {
                wSum -= w[i];
                if (i > 0) wSum += w[i - 1];
                int hValue = hMax1;
                if (hMax1I.Contains(i)) hValue = hMax2;
                b[i] = wSum * hValue;
            }
            Console.WriteLine(string.Join(" ", b));
        }
    }
}


using System;
using System.Linq;

namespace _522B
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] w = new int[n], h = new int[n];
            for (int i = 0; i < n; i++)
            {
                string[] line = Console.ReadLine().Split(' ');
                w[i] = int.Parse(line[0]); h[i] = int.Parse(line[1]);
            }
            int wSum = w.Sum();
            int max1 = 0, max1I = 0, max2 = 0;
            for (int i = 0; i < n; i++)
            {
                if (h[i] > max1)
                {
                    max1 = h[i];
                    max1I = i;
                }
                else if (h[i] <= max1 && h[i] >= max2)
                    max2 = h[i];
            }
            int[] b = new int[n];
            for (int i = 0; i < n; i++)
                b[i] = (wSum - w[i]) * (max1I == i ? max2 : max1);
            Console.WriteLine(string.Join(" ", b));
        }
    }
}


using System;
using System.Linq;

namespace _522B
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] w = new int[n], h = new int[n];
            for (int i = 0; i < n; i++)
            {
                string[] line = Console.ReadLine().Split(' ');
                w[i] = int.Parse(line[0]); h[i] = int.Parse(line[1]);
            }
            int wSum = w.Sum();
            int max1 = 0, max1I = 0, max2 = 0;
            for (int i = 0; i < n; i++)
            {
                if (h[i] > max1)
                {
                    if (max1 > max2) max2 = max1;
                    max1 = h[i];
                    max1I = i;
                }
                else if (h[i] <= max1 && h[i] >= max2)
                    max2 = h[i];
            }
            int[] b = new int[n];
            for (int i = 0; i < n; i++)
                b[i] = (wSum - w[i]) * (max1I == i ? max2 : max1);
            Console.WriteLine(string.Join(" ", b));
        }
    }
}


using System;
using System.Collections.Generic;

namespace _522B
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            var w = new int[n];
            var h = new int[n];
            int wSum = 0;
            int hMax1 = 0, hMax2 = 0;
            HashSet<int> hMax1I = new HashSet<int>(), hMax2I = new HashSet<int>();
            for (int i = 0; i < n; i++)
            {
                string[] line = Console.ReadLine().Split(' ');
                int x = int.Parse(line[0]), y = int.Parse(line[1]);
                w[i] = x; wSum += x;
                if (y > hMax1)
                {
                    if (hMax1 > hMax2)
                    {
                        hMax2 = hMax1;
                        hMax2I.Clear();
                        foreach (var a in hMax1I) hMax2I.Add(a);
                    }
                    hMax1 = y;
                    hMax1I.Clear();
                    hMax1I.Add(i);
                }
                else if (y == hMax1)
                {
                    hMax1I.Add(i);
                }
                else if (y > hMax2)
                {
                    hMax2 = y;
                    hMax2I.Clear();
                    hMax2I.Add(i);
                }
                else if (y == hMax2)
                {
                    hMax2I.Add(i);
                }
            }
            int[] b = new int[n];
            for (int i = 0; i < n; i++)
            {
                wSum -= w[i];
                if (i > 0) wSum += w[i - 1];
                int hValue = hMax1;
                if (hMax1I.Contains(i)) hValue = hMax2;
                b[i] = wSum * hValue;
            }
            Console.WriteLine(string.Join(" ", b));
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;

namespace _522B
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            var w = new int[n];
            var h = new int[n];
            int wSum = 0;
            int hMax1 = 0, hMax2 = 0;
            HashSet<int> hMax1I = new HashSet<int>(), hMax2I = new HashSet<int>();
            for (int i = 0; i < n; i++)
            {
                string[] line = Console.ReadLine().Split(' ');
                int x = int.Parse(line[0]), y = int.Parse(line[1]);
                w[i] = x; wSum += x;
                if (hMax1 == 0)
                {
                    hMax1 = y;
                    hMax1I.Add(i);
                }
                else if (hMax2 == 0)
                {
                    if (y > hMax1)
                    {
                        hMax2 = hMax1;
                        hMax2I.Add(hMax1I.First());
                        hMax1I.Clear();
                        hMax1 = y;
                        hMax1I.Add(i);
                    }
                    else
                    {
                        hMax2 = y;
                        hMax2I.Add(i);
                    }
                }
                if (y > hMax1)
                {
                    if (hMax1 > hMax2)
                    {
                        hMax2 = hMax1;
                        hMax2I.Clear();
                        foreach (var a in hMax1I) hMax2I.Add(a);
                    }
                    hMax1 = y;
                    hMax1I.Clear();
                    hMax1I.Add(i);
                }
                else if (y == hMax1)
                {
                    hMax1I.Add(i);
                }
                else if (y > hMax2)
                {
                    hMax2 = y;
                    hMax2I.Clear();
                    hMax2I.Add(i);
                }
                else if (y == hMax2)
                {
                    hMax2I.Add(i);
                }
            }
            int[] b = new int[n];
            for (int i = 0; i < n; i++)
            {
                wSum -= w[i];
                if (i > 0) wSum += w[i - 1];
                int hValue = hMax1;
                if (hMax1I.Contains(i)) hValue = hMax2;
                b[i] = wSum * hValue;
            }
            Console.WriteLine(string.Join(" ", b));
        }
    }
}


using System;

namespace PhotoNaPamyat
{
    class Program
    {
        static void Main()
        {
            int n = int.Parse(Console.ReadLine());
            int[] h=new int[n];
            int[] w = new int[n];
            int hmax=0, hmax2 = 0, sum=0;

            for (int i = 0; i < n; i++)
            {
                string[] nums = Console.ReadLine().Split(' ');
                w[i] = int.Parse(nums[0]);
                sum += w[i];
                h[i] = int.Parse(nums[1]);
                if (h[i] > hmax)
                {
                    hmax2 = hmax;
                    hmax = h[i];
                }
                else if (h[i] > hmax2)
                {
                    hmax2 = h[i];
                }
            }
            int size = 0;
            for (int i = 0; i < n; i++)
            {
                if (h[i] == hmax)
                    size = hmax2;
                else size = hmax;
                size = (sum - w[i]) * size;
                Console.Write("{0} ", size);
            }

        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication2
{
    class Program
    {
        public static int Max(int[] a, int j)
        {
            int[] max1 = new int[a.Length];
            Array.Copy(a, max1,a.Length);
            int[] max2 = new int[a.Length];
            Array.Copy(a, max2, a.Length);

                for (int i = 0; i < j; i++)
                {
                    if (i != 0)
                        max1[i] = Math.Max(max1[i], max1[i - 1]);
                }
            for (int i = a.Length-1; i > j; i--)
            {
                if (i != a.Length-1)
                    max2[i] = Math.Max(max2[i], max2[i + 1]);
            }
            int max = 0;
            if (j == 0)
                max = max2[j + 1];
            else if (j == a.Length-1)
                max = max1[j - 1];
            else
                max = Math.Max(max2[j + 1], max1[j - 1]);
            return max;
        }

        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());

            int[] w = new int[n];
            int[] h = new int[n];

            int width = 0;
            int height = 0;

            for (int i = 0; i < n; i++)
            {
                string[] wh = Console.ReadLine().Split(' ');
                w[i] = Convert.ToInt32(wh[0]);
                h[i] = Convert.ToInt32(wh[1]);
            }

            int[] result = new int[n];

            for (int j = 0; j < n; j++)
            {
                    width = w.Sum() - w[j];
                    height = Max(h, j);
                    Console.WriteLine(width + " " + height);
                    result[j] = width * height;
            }

            for (int i = 0; i < n; i++)
                Console.Write(result[i] + " ");
            //Console.ReadKey();
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication2
{
    class Program
    {

        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());

            int[] w = new int[n];
            int[] h = new int[n];

            int[] max1 = new int[n];
            int[] max2 = new int[n];

            int width = 0;
            int height = 0;

            for (int i = 0; i < n; i++)
            {
                string[] wh = Console.ReadLine().Split(' ');
                w[i] = int.Parse(wh[0]);
                h[i] = int.Parse(wh[1]);
                if (i != 0)
                    max1[i] = Math.Max(h[i], h[i - 1]);
            }
            max1[0] = h[0];
            max2[n - 1] = h[n - 1];

            for (int i = h.Length - 1; i > 0; i--)
            {
                if (i != h.Length - 1)
                    max2[i] = Math.Max(h[i], h[i + 1]);
            }
            int[] result = new int[n];

            for (int i = 0; i < n; i++)
            {
                    width = w.Sum() - w[i];
                    if (i == 0)
                        height = max2[i + 1];
                    else if (i == h.Length - 1)
                        height = max1[i - 1];
                    else
                    height = Math.Max(max1[i - 1], max2[i + 1]);
                    //Console.WriteLine(width + " " + height);
                    result[i] = width * height;
            }

            for (int i = 0; i < n; i++)
                Console.Write(result[i] + " ");
            //Console.ReadKey();
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication2
{
    class Program
    {

        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());

            int[] w = new int[n];
            int[] h = new int[n];

            int[] max1 = new int[n];
            int[] max2 = new int[n];

            int width = 0;
            int height = 0;

            for (int i = 0; i < n; i++)
            {
                string[] wh = Console.ReadLine().Split(' ');
                w[i] = int.Parse(wh[0]);
                h[i] = int.Parse(wh[1]);
                if (i != 0)
                    max1[i] = Math.Max(h[i], h[i - 1]);
            }
            max1[0] = h[0];
            max2[n - 1] = h[n - 1];

            for (int i = h.Length - 1; i > 0; i--)
            {
                if (i != h.Length - 1)
                    max2[i] = Math.Max(h[i], h[i + 1]);
            }
            int[] result = new int[n];

            for (int i = 0; i < n; i++)
            {
                    width = w.Sum() - w[i];
                    if (i == 0)
                        height = max2[i + 1];
                    else if (i == h.Length - 1)
                        height = max1[i - 1];
                    else
                    height = Math.Max(max1[i - 1], max2[i + 1]);
                    //Console.WriteLine(width + " " + height);
                    result[i] = width * height;
                Console.Write(result[i] + " ");
            }
            //Console.ReadKey();
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication2
{
    class Program
    {

        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());

            int[] w = new int[n];
            int[] h = new int[n];

            int width = 0;
            int height = 0;

            for (int i = 0; i < n; i++)
            {
                string[] wh = Console.ReadLine().Split(' ');
                w[i] = Convert.ToInt32(wh[0]);
                h[i] = Convert.ToInt32(wh[1]);
            }

            int[] result = new int[n];

            int[] max1 = new int[h.Length];
            Array.Copy(h, max1, h.Length);
            int[] max2 = new int[h.Length];
            Array.Copy(h, max2, h.Length);

            for (int i = 0; i < h.Length; i++)
            {
                if (i != 0)
                    max1[i] = Math.Max(max1[i], max1[i - 1]);
            }

            for (int i = h.Length - 1; i > 0; i--)
            {
                if (i != h.Length - 1)
                    max2[i] = Math.Max(max2[i], max2[i + 1]);
            }

            for (int i = 0; i < n; i++)
            {
                    width = w.Sum() - w[i];
                    if (i == 0)
                        height = max2[i + 1];
                    else if (i == h.Length - 1)
                        height = max1[i - 1];
                    else
                    height = Math.Max(max1[i - 1], max2[i + 1]);
                    //Console.WriteLine(width + " " + height);
                    result[i] = width * height;
            }

            for (int i = 0; i < n; i++)
                Console.Write(result[i] + " ");
            //Console.ReadKey();
        }
    }
}