I can't sleep, so here's 1-1 and 1-2, unfortunately I couldn't think of any silly solutions this time, so it's straightforward instead:
spoiler
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <set>
#include <iterator>
int main() {
std::multiset<int> l, r;
int a, b;
while (std::cin >> a >> b) {
l.insert(a); r.insert(b);
}
std::vector<int> delta;
std::transform(l.begin(), l.end(), r.begin(), std::back_inserter(delta),
[](int x, int y) { return std::abs(x-y); }
);
std::cout << std::accumulate(delta.begin(), delta.end(), 0) << std::endl;
}
spoiler
#include <iostream>
#include <numeric>
#include <set>
int main() {
std::multiset<int> l, r;
int a, b;
while (std::cin >> a >> b) {
l.insert(a); r.insert(b);
}
std::cout << std::accumulate(l.begin(), l.end(), 0, [&r](int acc, int x) {
return acc + x * r.count(x);
}) << std::endl;
}