#pragma warning disable IDE1006 #pragma warning disable IDE0011 using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Numerics; using System.Text; using static System.Convert; using static System.Math; using static Extentions; class IO { int idx; string[] line; public void R(params char[] sep) { line = Console.ReadLine().Split(sep); idx = 0; } public string S => line[idx++]; public string[] Ss => line.Skip(idx++).ToArray(); public char C => char.Parse(line[idx++]); public char[] Cs => line.Skip(idx++).Select(char.Parse).ToArray(); public int I => int.Parse(line[idx++]); public int[] Is => line.Skip(idx++).Select(int.Parse).ToArray(); public long L => long.Parse(line[idx++]); public long[] Ls => line.Skip(idx++).Select(long.Parse).ToArray(); public double F => double.Parse(line[idx++]); public double[] Fs => line.Skip(idx++).Select(double.Parse).ToArray(); public decimal D => decimal.Parse(line[idx++]); public decimal[] Ds => line.Skip(idx++).Select(decimal.Parse).ToArray(); public BigInteger B => BigInteger.Parse(line[idx++]); public BigInteger[] Bs => line.Skip(idx++).Select(BigInteger.Parse).ToArray(); public void Write(params T[] xs) { Console.Write(xs.First()); foreach (var x in xs.Skip(1)) Console.Write(" " + x); Console.WriteLine(); } public void Write(params object[] xs) { Console.Write(xs.First()); foreach (var x in xs.Skip(1)) Console.Write(" " + x); Console.WriteLine(); } } static class Extentions { } static class Program { public static void Main() { #if !DEBUG Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); #endif Solve(new IO()); Console.Out.Flush(); } public static void Solve(IO io) { io.R(); var n = io.I; var a = new int[n]; var b = new int[n]; for (var i = 0; i < n; i++) { io.R(); a[i] = io.I; b[i] = io.I; } var dp = new int[n, 2]; if (a[0] > b[0]) dp[0, 1] = b[0]; else dp[0, 0] = a[0]; for (var i = 1; i < n; i++) { if (dp[i - 1, 0] > dp[i - 1, 1]) { dp[i, 1] = dp[i - 1, 1] + b[i]; dp[i, 0] = dp[i - 1, 0]; } else { dp[i, 0] = dp[i - 1, 0] + a[i]; dp[i, 1] = dp[i - 1, 1]; } } io.Write(Abs(dp[n - 1, 0] - dp[n - 1, 1])); } }