#include #define DEBUG(C) cerr << #C << " = " << C << endl using namespace std; const int MAX = 44; int n; long long a[MAX], b[MAX]; long long dp[MAX][2]; const long long inf = 1e18; int main() { scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%lld%lld", a + i, b + i); } for (int i = 0; i < n; i++) { for (int j = 0; j < 2; j++) { dp[i][j] = inf; } } dp[0][0] = dp[0][1] = 0; for (int i = 0; i < n; i++) { dp[i + 1][0] = min(llabs(dp[i][0] + a[i]), llabs(dp[i][1] - a[i])); dp[i + 1][1] = min(llabs(dp[i][0] - b[i]), llabs(dp[i][1] + b[i])); } cout << min(llabs(dp[n][0]), llabs(dp[n][1])) << endl; return 0; }