Language: C++

// author : ayush_nishad
// Road to Expert since : 30 Aug 2020
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define pb push_back
#define in insert
#define F first
#define S second
#define mod 1000000007
#define endl '\n'
#define all(x)  x.begin(),x.end()
#define w(x) int x;cin>>x; while(x-->0)
#define memset(a,b) memset(a,b,sizeof(a))
#define debug(x) cout << "[ " << #x  << " : " << x << " ]" << endl;

void fast()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
}
/*
think fast
think simple
*/
struct node {
	int a, b;
	node(int a, int b)
	{
		this->a = a;
		this->b = b;
	}
};

struct cmp {
	bool operator()(node const& p1, node const& p2)
	{
		return p1.a + p1.b < p2.a + p2.b; //min heap
	}
};
void mysol()
{
	int n; cin >> n;
	set<node, cmp>s;
	for (int i = 0; i < n; i++) {
		int a, b; cin >> a >> b;
		s.in(node(a, b));
	}
	if (s.size() == 1)
		cout << 0;
	else
	{
		int ans = 0;
		auto now  = *s.begin();
		s.erase(s.begin());
		ans += now.a + now.b;
		now = *(--s.end());
		ans = now.a + now.b - ans;
		cout << ans;
	}
}

int32_t main()
{
	fast();
	// w(t)
	{
		mysol();
	}
	//cerr << sizeof(dp)*(1e-6) << " megabytes\n";
	return 0;
}


Compiler output:
In file included from /usr/include/c++/14/map:62,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:152,
                 from a.cc:3:
/usr/include/c++/14/bits/stl_tree.h: In instantiation of 'static const _Key& std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_S_key(_Const_Link_type) [with _Key = node; _Val = node; _KeyOfValue = std::_Identity<node>; _Compare = cmp; _Alloc = std::allocator<node>; _Const_Link_type = const std::_Rb_tree_node<node>*]':
/usr/include/c++/14/bits/stl_tree.h:2116:47:   required from 'std::pair<std::_Rb_tree_node_base*, std::_Rb_tree_node_base*> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_get_insert_unique_pos(const key_type&) [with _Key = node; _Val = node; _KeyOfValue = std::_Identity<node>; _Compare = cmp; _Alloc = std::allocator<node>; key_type = node]'
 2116 |           __comp = _M_impl._M_key_compare(__k, _S_key(__x));
      |                                                ~~~~~~^~~~~
/usr/include/c++/14/bits/stl_tree.h:2169:4:   required from 'std::pair<std::_Rb_tree_iterator<_Val>, bool> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_insert_unique(_Arg&&) [with _Arg = node; _Key = node; _Val = node; _KeyOfValue = std::_Identity<node>; _Compare = cmp; _Alloc = std::allocator<node>]'
 2169 |         = _M_get_insert_unique_pos(_KeyOfValue()(__v));
      |           ^~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_set.h:523:25:   required from 'std::pair<typename std::_Rb_tree<_Key, _Key, std::_Identity<_Tp>, _Compare, typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key>::other>::const_iterator, bool> std::set<_Key, _Compare, _Alloc>::insert(value_type&&) [with _Key = node; _Compare = cmp; _Alloc = std::allocator<node>; typename std::_Rb_tree<_Key, _Key, std::_Identity<_Tp>, _Compare, typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key>::other>::const_iterator = std::_Rb_tree<node, node, std::_Identity<node>, cmp, std::allocator<node> >::const_iterator; typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key>::other = std::allocator<node>; typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key> = __gnu_cxx::__alloc_traits<std::allocator<node>, node>::rebind<node>; typename _Alloc::value_type = node; value_type = node]'
  523 |           _M_t._M_insert_unique(std::move(__x));
      |           ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
a.cc:48:7:   required from here
   48 |                 s.in(node(a, b));
      |                 ~~~~^~~~~~~~~~~~
/usr/include/c++/14/bits/stl_tree.h:768:15: error: static assertion failed: comparison object must be invocable as const
  768 |               is_invocable_v<const _Compare&, const _Key&, const _Key&>,
      |               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_tree.h:768:15: note: 'std::is_invocable_v<const cmp&, const node&, const node&>' evaluates to false