#include using namespace std; typedef long long ll; typedef vector vi; typedef vector vl; typedef pair pii; typedef int _loop_int; #define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i) #define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i) #define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i) #define DEBUG(x) cout<<#x<<": "<>n; int a[N]; int lp=1; int rp=n*2; FOR(i,1,2*n+1) cin>>a[i]; ll ans = 0; while(lpa[rp]-a[rp-1]){ ans += a[lp]-a[lp+1]; lp += 2; }else{ ans += a[rp]-a[rp-1]; rp-=2; } } cout << ans << endl; return 0; }