#include<bits/stdc++.h>
#define ll long int
using namespace std;
int main()
{
ll t, n, i, a;
while(cin >> t && t != 0)
{
multiset<ll>st;
ll sum = 0;
while(t--)
{
cin >> n;
for(i=1;i<=n;i++)
{
cin >> a;
st.insert(a);
}
auto it = st.begin();
auto ir = st.end();
ir--;
int f = *it, l = *ir;
st.erase(it);
st.erase(ir);
sum = sum + (l-f);
}
cout << sum << "\n";
}
return 0;
}
#define ll long int
using namespace std;
int main()
{
ll t, n, i, a;
while(cin >> t && t != 0)
{
multiset<ll>st;
ll sum = 0;
while(t--)
{
cin >> n;
for(i=1;i<=n;i++)
{
cin >> a;
st.insert(a);
}
auto it = st.begin();
auto ir = st.end();
ir--;
int f = *it, l = *ir;
st.erase(it);
st.erase(ir);
sum = sum + (l-f);
}
cout << sum << "\n";
}
return 0;
}
Comments
Post a Comment