#if DEBUG
using System.Reflection;
using System.Threading.Tasks;
#endif

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Numerics;
using System.Globalization;

namespace _200a
{
    class Program
    {
        static string _inputFilename = "input.txt";
        static string _outputFilename = "output.txt";
        static bool _useFileInput = false;

        static void Main(string[] args)
        {
            StreamWriter file = null;
#if DEBUG
			Console.SetIn(getInput());
#else
            if (_useFileInput)
            {
                Console.SetIn(File.OpenText(_inputFilename));
                file = new StreamWriter(_outputFilename);
                Console.SetOut(file);
            }
#endif

            try
            {
                solution();
            }
            finally
            {
                if (_useFileInput)
                {
                    file.Close();
                }
            }
        }

        static void solution()
        {
            #region SOLUTION
            var n = readInt();
            var prev = -1;
            {
                var s = Console.ReadLine();
                if (s[0] == '1')
                {
                    prev = 1;
                }
                else
                {
                    prev = 0;
                }
            }

            var count = 1;
            for (int i = 1; i < n; i++)
            {
                var s = Console.ReadLine();
                if (s[0] == '1')
                {
                    if (prev == 0)
                    {
                        count++;
                        prev = 1;
                    }
                }
                else
                {
                    if (prev == 1)
                    {
                        count++;
                        prev = 0;
                    }
                }
            }

            Console.WriteLine(count);
            //var n = readInt();
            //var m = readInt();

            //var a = readIntArray();
            //var b = readIntArray();
            #endregion
        }

        static int readInt()
        {
            return int.Parse(Console.ReadLine());
        }

        static long readLong()
        {
            return long.Parse(Console.ReadLine());
        }

        static int[] readIntArray()
        {
            return Console.ReadLine().Split(' ').Where(i => !string.IsNullOrEmpty(i)).Select(i => int.Parse(i)).ToArray();
        }

        static long[] readLongArray()
        {
            return Console.ReadLine().Split(' ').Where(i => !string.IsNullOrEmpty(i)).Select(i => long.Parse(i)).ToArray();
        }

#if DEBUG
		static StreamReader getInput()
		{
			var resName = Assembly.GetCallingAssembly().GetManifestResourceNames()[0];
			var resource = Assembly.GetCallingAssembly().GetManifestResourceStream(resName);

			return new StreamReader(resource);
		}
#endif
    }
}


using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string tmp = Console.ReadLine();
            var number = int.Parse(tmp);
            int result = 1;
            var last = Console.ReadLine()[1];
            for (int i = 1; i < number; i++)
            {
                var current = Console.ReadLine();
                if (last == current[0])
                {
                    result++;
                }
                last = current[1];
            }

            Console.WriteLine(result);
            //Console.ReadKey();
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using System.IO;
using System.Numerics;

namespace probleme {
    class Program {
        static void Main(string[] args) {
            int n = int.Parse(Console.ReadLine());
            int ans = 0;
            char ant = '2';
            for (int i = 0; i < n; i++) {
                string s = Console.ReadLine();
                if (s[0] == ant)
                    ans++;
                ant = s[1];
            }
            Console.WriteLine(ans);
            //   Console.ReadKey();
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using System.IO;
using System.Numerics;

namespace probleme {
    class Program {
        static void Main(string[] args) {
            int n = int.Parse(Console.ReadLine());
            int ans = 1;
            char ant = '2';
            for (int i = 0; i < n; i++) {
                string s = Console.ReadLine();
                if (s[0] == ant)
                    ans++;
                ant = s[1];
            }
            Console.WriteLine(ans);
            //   Console.ReadKey();
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Magnets
{
    class Program
    {
        static void Main(string[] args)
        {
            int n =int.Parse(Console.ReadLine());
            int[] magnets = new int[n];
            for (int i = 0; i < n; i++)
            {
                magnets[i] = int.Parse(Console.ReadLine());
            }
            int groups = 1;
            for (int i = 0; i < magnets.Length; i++)
            {
                if (i != 0)
                {
                    if (magnets[i] != magnets[i - 1]) groups++;
                }
            }
            Console.WriteLine(groups);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Text;

namespace CodeForces.PRACTICE
{
    // Magnets (implementation)
    class _344A
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int res = 1;
            string[] a = new string[n];
            for (int i = 0; i < n; i++)
            {
                a[i]=Console.ReadLine();
                if (i > 0 && a[i - 1] != a[i]) res++;
            }
            Console.WriteLine(res);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Codeforces
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            int count = 1;
            string[,] input = new string[n, 1];
            for (int i = 0; i < n; i++)
            {
                input[i, 0] = Console.ReadLine();
                if (i != 0)
                {
                    if (input[i - 1, 0] != input[i, 0])
                    {
                        count++;
                    }
                }

            }

            Console.Write(count);
            Console.ReadLine();
        }
    }
}


using System;
using System.Linq;

class Program
{
    static void Main()
    {
        int n = Int32.Parse(Console.ReadLine());
        string[] str = new string[n];
        for (int i=0;i<str.Length;i++)
        {
            str[i] = Console.ReadLine();
        }
        int count = 0;
        for (int i=0;i<str.Length;i++)
        {
            int j = i+1;
            while((j < str.Length)&&(str[i]==str[j]))
            {
                j++;
            }
            i = j-1;
            count++;
        }
        Console.WriteLine(count);
    }
}


using System;

namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = Convert.ToInt32(Console.ReadLine());
            int ans = 1;

            string s = Console.ReadLine();
            for (int i = 1; i < n; i++)
            {
                string s1 = Console.ReadLine();
                if (s1[0] == s[1]) ans++;
                s = s1;
            }
            Console.WriteLine(ans);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace vanya
{
    class Program
    {
        static void Main(string[] args)
        {

            #region xx

           int n  = Convert.ToInt32( Console.ReadLine());
            string[] strngs = new string[n];
            int frstcount = 0;
            strngs[0] = Console.ReadLine();
            for (int i = 1; i < n; i++)
            {
                strngs[i] = Console.ReadLine();

                    if (strngs[i-1][1] != strngs[i][0])
                    {
                        frstcount++;
                    }

            }
            Console.WriteLine(frstcount);

}
}
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace vanya
{
    class Program
    {
        static void Main(string[] args)
        {

            #region xx

           int n  = Convert.ToInt32( Console.ReadLine());
            string[] strngs = new string[n];
            int frstcount = 0;
            strngs[0] = Console.ReadLine();
            for (int i = 1; i < n; i++)
            {
                strngs[i] = Console.ReadLine();

                    if (strngs[i-1][1] != strngs[i][0])
                    {
                        frstcount++;
                    }

            }
            Console.WriteLine(frstcount);

            #endregion
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace vanya
{
    class Program
    {
        static void Main(string[] args)
        {

            #region xx

            int n  = Convert.ToInt32( Console.ReadLine());

            int frstcount = 1;
            string s = Console.ReadLine();
            for (int i = 0; i < n - 1; i++)
            {
                string d = Console.ReadLine();
                if (s[1] == d[0])
                {
                    frstcount++;
                }
                s = d;
            }
            Console.WriteLine(frstcount);

            #endregion
        }
    }
}


using System;

namespace Issue_344A
{
    class Program
    {
        public static void Main(string[] args) {
            var input = Console.ReadLine();
            var count = int.Parse(input);
            var islands = 0;
            var previous = string.Empty;

            for (int i = 0; i < count; ++i) {
                var polarity = Console.ReadLine();

                if (!IsSamePolarity(polarity, previous)) {
                    islands++;
                    previous = polarity;
                }
            }

            Console.WriteLine(islands);
        }

        private static bool IsSamePolarity(string a, string b) {
            return b != string.Empty && a[0] == b[0];
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CF_Magnets
{
    class Program
    {
        static void Main(string[] args)
        {
            int t = int.Parse(Console.ReadLine());
            Stack<int> st = new Stack<int>();
            int count = 0;
            while(t-- >0)
            {
                int s = int.Parse(Console.ReadLine());
                if(st.Count() == 0 || st.Peek() != s)
                {
                    st.Push(s);
                    count++;
                }
            }
            Console.WriteLine(count);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Text;

namespace TestPrograms
{
    class Program
    {
        static void Main(string[] args)
        {
            string input1 = Console.ReadLine();
            int nb = int.Parse(input1);

            int count = 0;

            string init = "";

            for (int i = 0; i < nb; i++)
            {
                string k = Console.ReadLine();
                if (k != init)
                {
                    count++;
                    init = k;
                }
            }

            Console.WriteLine(count);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Fun
{
	class Program
	{
		static void Main(string[] args)
		{
			int n = int.Parse(Console.ReadLine());

			string cGp = null;
			var c = 0;
			for (int i = 0; i < n; i++)
			{
				var m = Console.ReadLine();
				if (cGp != m)
				{
					cGp = m;
					c++;
				}
			}
			Console.WriteLine(c);
		}
	}
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ChallengeMagnets
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var previousGroup = string.Empty;
            var counter = 0;

            for (int i = 0; i < n; i++)
            {
                var currentLine = Console.ReadLine();

                if (previousGroup != currentLine)
                {
                    previousGroup = currentLine;
                    counter++;
                }
            }

            Console.WriteLine(counter);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Coding
{

    class Program
    {
        static void Main(string[] args)
        {

            int total = 1;

            int n = int.Parse(Console.ReadLine());
            string currentMagnet = Console.ReadLine();

            for (int i = 0; i < n - 1; i++)
            {
                string s = Console.ReadLine();

                if (s[1] == currentMagnet[0])
                {
                    currentMagnet = s;
                    total++;
                }

            }

            Console.WriteLine(total);
        }
    }
}


using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;

class Program
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        int count = 0;
        string last = "";
        for (int i = 0; i < n; i++)
        {
            string tmp = Console.ReadLine();
            if (tmp != last)
                count++;
            last = tmp;
        }
        Console.WriteLine(count);
       // Console.ReadKey();
    }
}


using System;

namespace _344A
{
    static class Program
    {
        static void Main()
        {
            var n = int.Parse(Console.ReadLine());
            var c = 1;
            var s = Console.ReadLine();
            var l = s[1];
            for (var i = 1; i < n; i++)
            {
                s = Console.ReadLine();
                if (l == s[0])
                {
                    ++c;
                }
                l = s[1];
            }
            Console.WriteLine(c);
        }
    }
}


namespace o
{
    using System;

    class Program
    {
        static void Main(string[] args)
        {
            int len = int.Parse(Console.ReadLine());
            string[] st = new string[len];
            for (int i = 0; i < len; i++)
            {
                st[i] = string.Intern(Console.ReadLine());
            }
            int counter = 1;
            string example = st[0];
            for (int i = 0; i < len; i++)
            {
                if (st[i].CompareTo(example) != 0)
                {
                    counter++;
                    example = st[i];
                }
            }
            Console.WriteLine(counter);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Magnets
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            string mag = Console.ReadLine();
            int count = 1;
            for (int i = 1; i < n; i++)
            {
                string followed = Console.ReadLine();
                if (!followed.Equals(mag))
                    count++;
                mag = followed;
            }
            Console.WriteLine(count);
            Console.ReadLine();

        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Magnets
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt16(Console.ReadLine());
            string mag = Console.ReadLine();
            int count = 1;
            for (int i = 1; i < n; i++)
            {
                string followed = Console.ReadLine();
                if (!followed.Equals(mag))
                    count++;
                mag = followed;
            }
            Console.WriteLine(count);
            Console.ReadLine();

        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Magnets
{
    class Program
    {
        static void Main(string[] args)
        {
            var data = Convert.ToInt32(Console.ReadLine());

            string temp = "";

            int count = 0;

            for (int i = 0; i < data; i++)
            {
                string val = Console.ReadLine();

                if (temp != val)
                {
                    count++;
                }
                temp = val;

            }

            Console.WriteLine(count);

        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EO
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] x = new int[n];
            int u = 0;
            for (int i = 0; i < n; i++)
            {
                x[i] = int.Parse(Console.ReadLine());
            }
            if (x.Length == 1)
            {
                Console.WriteLine(1);
            }
            else
            {
                for (int i = 0; i < n-1 ; i++)
                {
                    if (x[i] != x[i + 1])
                    {
                        u++;
                    }

                }
                Console.WriteLine(u+1);
            }
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace magnets
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] x=new int[n];
            int u = 0;
            for (int i = 0; i < n; i++)
            {
                x[i] = int.Parse(Console.ReadLine());
            }
            for (int i = 0; i < n-1; i++)
            {
                if (x[i]==x[i+1])
                {
                    u++;
                }
                else
                {
                    continue;
                }
            }
            Console.WriteLine(u);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EO
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] x = new int[n];
            int u = 0;
            for (int i = 0; i < n; i++)
            {
                x[i] = int.Parse(Console.ReadLine());
            }

                for (int i = 0; i < n-1 ; i++)
                {
                    if (x[i] != x[i + 1])
                    {
                        u++;
                    }

                }
                Console.WriteLine(u+1);

        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

namespace Rextester
{
    public class Program
    {
        public static void Main(string[] args)
        {
            int count, numb, numbp=44, result=0;
            count=int.Parse(Console.ReadLine());

            for(int i = 0; i < count; i++){
                numb = int.Parse(Console.ReadLine());
                if(numb != numbp){
                    numbp=numb;
                    result++;
                }
            }
            Console.WriteLine(result);
        }
    }
}


using System;

namespace _344A
{
	class Program
	{
		static void Main ( string [ ] args )
		{
			int n = int.Parse(Console.ReadLine()), d = 1;
			string s = Console.ReadLine();
			char prev = s[1];
			for (int i = 1; i < n; ++i)
			{
				s = Console.ReadLine();
				if (s[0] == prev)
					++d;
				prev = s[1];
			}
			Console.Write(d);
		}
	}
}


using System;
using System.Linq;

class m
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        int count = 1;
        string ls = Console.ReadLine();
        for (int i=0; i<n-1; i++)
        {
            string s = Console.ReadLine();
            if (s[0] == ls[1])
                count++;
            ls = s;
        }
        Console.WriteLine(count);
    }
}


using System;
using System.Linq;

class m
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        int[] nums = Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray();

        int maxp = 0;
        for (int i = maxp; i < n; i++)
            if (nums[i] > nums[maxp])
                maxp = i;

        int minp = n - 1;
        for (int i = minp; i >= 0; i--)
            if (nums[i] < nums[minp])
                minp = i;

        int time = maxp + n - 1 - minp;
        if (maxp > minp)
            time--;
        Console.WriteLine(time);
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Magnets
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string[] x = new string[n];
            int result = 1;
            for (int i = 0; i < n; i++)
            {
                x[i] = Console.ReadLine();

            }

            for (int i = 1; i < n; i++)
            {
                if (x[i]==x[i-1])
                {
                    continue;

                }
               else
                {
                    result++;

                }

            }
            Console.WriteLine(result);

        }
    }
}


using System;
using System.Collections.Generic;
using System.IO;

namespace prA {

    class Program {
#if ONLINE_JUDGE
        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024 * 10), System.Text.Encoding.ASCII, false, 1024 * 10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024 * 10), System.Text.Encoding.ASCII, 1024 * 10);
#else
        private static readonly StreamWriter writer = new StreamWriter("output");
        private static readonly StreamReader reader = new StreamReader("input");
#endif
        static void Main(string[] args) {

            int ans = 1;
            int n = int.Parse(reader.ReadLine());
            string prev = String.Empty;
            for(int i = 0; i < n; i++) {
                string s = reader.ReadLine();
                if(prev != String.Empty) {
                    if(s[1] == prev[0])
                        ans++;
                }
                prev = s;
            }

            writer.Write(ans);

            writer.Flush();
#if !ONLINE_JUDGE
            writer.Close();
#endif
        }
        private static int Next() {
            int c;
            int res = 0;
            do {
                c = reader.Read();
                if(c == -1)
                    return res;
            } while(c != '-' && (c < '0' || c > '9'));
            int sign = 1;
            if(c == '-') {
                sign = -1;
                c = reader.Read();
            }
            res = c - '0';
            while(true) {
                c = reader.Read();
                if(c < '0' || c > '9')
                    return res * sign;
                res *= 10;
                res += c - '0';
            }
        }
    }
}


using System;
using System.Linq;

namespace ConsoleApplication6
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());

            var lastNumber = 0;
            var groups = 0;
            for (int i = 0; i < n; i++)
            {
                var number = int.Parse(Console.ReadLine());

                if (lastNumber == 0)
                {
                    lastNumber = number;
                    groups = 1;
                }

                if (lastNumber != number)
                {
                    lastNumber = number;
                    groups++;
                }

            }

            Console.WriteLine(groups);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication6
{
    class Program
    {

        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            List<string> l = new List<string>();
            for (int i = 0; i < n; i++)
            {
                string s = Console.ReadLine();
                l.Add(s);
            }
            int k = 1;
            for (int i = 0; i < n - 1; i++)
            {
                string a1 = l[i];
                string a2 = l[i + 1];
                char c1 = a1[a1.Length - 1];
                char c2 = a2[0];
                if (c1 == c2)
                {
                    k++;
                }
            }
            Console.WriteLine(k);

        }
    }
}


using System;

namespace tren
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine()), count = 0;
            string bg = Console.ReadLine();
            while (n-->1)
            {
                string a = Console.ReadLine();
                if (bg[1] == a[0]) count++;
                bg = a;
            }
            Console.Write(count + 1);
        }
    }
}


using System;
using System.Linq;
using System.Text.RegularExpressions;

namespace tren
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string s = null;
            for(int i = 0; i < n; i++) s += Console.ReadLine();
            Regex r = new Regex (@"(0){2}|(1){2}");
            s = r.Replace(s, " ");
            Console.Write(s.Count(x => x == ' ')+1);
        }
    }
}


using System;

namespace tren
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine()), count = 0;
            string s = null;
            for(int i = 0; i < n; i++) s += Console.ReadLine();
            for(int i = 1; i < s.Length-2; i++)
            {
                if (s[i] == s[i + 1]) count++;
            }
            Console.Write(count + 1);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace cf344a
{
    class Program
    {
        static void Main(string[] args)
        {
            int n;
            n = Convert.ToInt32(Console.ReadLine());
            string[] x = new string[n];
            int z = 0;
            for(int i=0; i<x.Length; i++){
                x[i] = Console.ReadLine();
                if(i>0){
                    if(x[i]!=x[i-1]){
                        z++;
                    }
                }
                else if(i==0){
                    z++;
                }
            }

            Console.Write(z);
        }
    }
}


using System;

public class Magnets
{
	private static void Main()
	{
		var n = int.Parse(Console.ReadLine());
		var groups = 0;
		char lastPole = ' ';
		for (int i = 0; i < n; i++)
		{
			var m = Console.ReadLine();
			if(m[1] == lastPole || lastPole == ' ')
			{
				groups++;
			}
			else
			{
				lastPole = m[1];
			}
		}

		Console.WriteLine(groups);
	}
}


using System;

public class Magnets
{
	private static void Main()
	{
		var n = int.Parse(Console.ReadLine());
		var groups = 1;

		var m = Console.ReadLine();
		char lastPole = m[1];
		for (int i = 1; i < n; i++)
		{
			m = Console.ReadLine();
			if(m[0] == lastPole)
			{
				groups++;
			}

			lastPole = m[1];
		}

		Console.WriteLine(groups);
	}
}


using System;

public class Magnets
{
	private static void Main()
	{
		var n = int.Parse(Console.ReadLine());
		var groups = 0;
		char lastPole = ' ';
		for (int i = 0; i < n; i++)
		{
			var m = Console.ReadLine();
			if(m[1] == lastPole)
			{
				groups++;
			}
			else
			{
				lastPole = m[1];
			}
		}

		Console.WriteLine(groups);
	}
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int count = 0;
            string last = "hgfadsha";
            for (int i = 0; i < n; i++)
            {
                string s = Console.ReadLine();
                if (s != last)
                {
                    count++;
                    last = s;
                }
            }
            Console.WriteLine(count);
        }
    }
}


 using System;
 class Program
{
   static void Main(string[]args)
    {
         int numberOfMagnets = int.Parse(Console.ReadLine());
            int[] magnetsVaules = new int[numberOfMagnets];
            int numberOfGroups = 1;
            for (int i = 0; i < magnetsVaules.Length; i++)
            {
                magnetsVaules[i] = int.Parse(Console.ReadLine());
            }
            for (int i = 1; i < magnetsVaules.Length; i++)
            {

                if (magnetsVaules[i] != magnetsVaules[i - 1])
                    numberOfGroups++;
            }
            Console.WriteLine(numberOfGroups);
    }

}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            string[] magnits = new string[n];
            for(int i = 0; i < n; i ++)
                magnits[i] = Console.ReadLine();
            int islands = 1;
            for (int i = 1; i < n; i++)
                if (magnits[i] != magnits[i - 1])
                    islands++;
            Console.Write(islands);
        }
    }
}


using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Text;
//using System.Threading.Tasks;

namespace Problem344A {
    class Program {
        static void Main(string[] args) {
            int changes = 0;
            int magnets = Convert.ToInt32(Console.ReadLine());
            int previousMagnet = Convert.ToInt32(Console.ReadLine());
            for (int i = 1; i < magnets; i++) {
                int actMagnet = Convert.ToInt32(Console.ReadLine());
                if (previousMagnet != actMagnet) {
                    changes++;
                }

                previousMagnet = actMagnet;
            }

            Console.WriteLine(changes+1);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleSandbox
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = int.Parse(Console.ReadLine());
            var prev = a[0];
            var res = 1;
            for (int i = 1; i < n; i++)
            {
                if (prev != a[i])
                {
                    res++;
                }
                prev = a[i];
            }
            Console.WriteLine(res);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleSandbox
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = int.Parse(Console.ReadLine());
            var prev = a[0];
            var res = 0;
            for (int i = 1; i < n; i++)
            {
                if (prev == a[i])
                {
                    res++;
                }
                prev = a[i];
            }
            Console.WriteLine(res);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace codeforces
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string s = "";
            int answer = 1;
            for (int i = 0; i < n; i++)
                s += Console.ReadLine();
            for (int i = 1; i < n * 2; i++)
                if (s[i - 1] == s[i])
                    answer++;
            Console.Write(answer);
           // Console.ReadKey();
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace codeforces
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string s1 = "", s2 = "";
            int answer = 1;
            for (int i = 0; i < n; i++)
            {
                if (s1 == "")
                    s1 = Console.ReadLine();
                else
                {
                    s2 = Console.ReadLine();
                    if (s1 == s2)
                        answer++;
                    s1 = s2;
                }
            }
            Console.Write(answer);
           // Console.ReadKey();
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace codeforces
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string s = "";
            int answer = 1;
            for (int i = 0; i < n; i++)
            {
                if (i != 0)
                {
                    s += Console.ReadLine();
                    if (s[s.Length - 2] == s[s.Length - 3])
                        answer++;
                }
                else
                    s += Console.ReadLine();
            }
            Console.Write(answer);
           // Console.ReadKey();
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace codeforces
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string s1 = "", s2 = "";
            int answer = 1;
            for (int i = 0; i < n; i++)
            {
                if (s1 == "")
                    s1 = Console.ReadLine();
                else
                {
                    s2 = Console.ReadLine();
                    if (s1 != s2)
                        answer++;
                    s1 = s2;
                }
            }
            Console.Write(answer);
           // Console.ReadKey();
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Codefather_is_riseing_ha_ha_ha
{
    class Program
    {
        static void Main(string[] args)
        {
            int n=int.Parse(Console.ReadLine());
            int result=1;
            string s = Console.ReadLine();
            for (int i = 1; i < n; i++)
            {
                string ss = Console.ReadLine();
                if (ss == s) { result += 0; }
                else { result++; s = ss; }
            }
             Console.Write(result);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Numerics;

namespace WarmingUpC_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            int g = 1;
            int T = int.Parse(Console.ReadLine());
            int first = int.Parse(Console.ReadLine());
            for (int i = 1; i < T; i++)
            {
                int magnet = int.Parse(Console.ReadLine());
                if (first != magnet)
                {
                    g++;
                    first = magnet;
                }
            }
            Console.WriteLine(g);
        }
    }
}


using System;
class Program
{
    static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        int p = 0, s = 0, c = 0;
        while (n-- > 0)
        {
            p = s;
            if ((s = int.Parse(Console.ReadLine())) != p)
            {
                c++;
            }
        }
        Console.WriteLine(c);
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace R200.Div2.A.Magnets
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string row1 = Console.ReadLine();
            string row2;
            int groupCount = 1;
            for (int i = 0; i < n-1; i++)
            {
                row2 = Console.ReadLine();
                if (row1[1] == row2[0])
                {
                    groupCount++;
                }
                row1 = row2;
            }
            Console.WriteLine(groupCount);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;

namespace ConsoleApplication53
{
    class Program
    {
        static void Main(string[] args)
        {
           int n = int.Parse(Console.ReadLine());

            StringBuilder s = new StringBuilder(n);
            for (int i = 0; i < n; i++)
                s.Append(Console.ReadLine());
            string t = s.ToString();
            Console.WriteLine(Regex.Matches(t, "(00)|(11)").Count + 1);

            Console.ReadLine();
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Olymp6
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string[] s = new string[n];
            if (n == 1)
            {
                Console.WriteLine(1);
                return;
            }
            if (n == 2)
            {
                if (s[0] == s[1])
                {
                    Console.WriteLine(2);
                }
                else
                {
                    Console.WriteLine(1);
                }
                return;
            }
            for (int i=0; i<n; i++)
            {
                s[i] = Console.ReadLine();
            }
            int count = 0;
            for (int i=0; i<n-1; i++)
            {
                if (s[i] == s[i + 1]) count++;
            }
            Console.WriteLine(count);
            //Console.ReadKey();
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Olymp6
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string[] s = new string[n];
            for (int i=0; i<n; i++)
            {
                s[i] = Console.ReadLine();
            }
            int count = 0;
            for (int i=0; i<n-1; i++)
            {
                if (s[i] == s[i + 1]) count++;
            }
            Console.WriteLine(count);
            //Console.ReadKey();
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Olymp6
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string[] s = new string[n];
            if (n == 1)
            {
                Console.WriteLine(1);
                return;
            }
            if (n == 2)
            {
                if (s[0] == s[1])
                {
                    Console.WriteLine(1);
                }
                else
                {
                    Console.WriteLine(2);
                }
                return;
            }
            for (int i=0; i<n; i++)
            {
                s[i] = Console.ReadLine();
            }
            int count = n;
            for (int i=0; i<n-1; i++)
            {
                if (s[i] == s[i + 1]) count--;
            }
            Console.WriteLine(count);
            //Console.ReadKey();
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Olymp6
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string[] s = new string[n];
            if (n == 1)
            {
                Console.WriteLine(1);
                return;
            }
            for (int i=0; i<n; i++)
            {
                s[i] = Console.ReadLine();
            }
            if (n == 2)
            {
                if (s[0] == s[1])
                {
                    Console.WriteLine(1);
                }
                else
                {
                    Console.WriteLine(2);
                }
                return;
            }
            int count = n;
            for (int i=0; i<n-1; i++)
            {
                if (s[i] == s[i + 1]) count--;
            }
            Console.WriteLine(count);
            //Console.ReadKey();
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Olymp6
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string[] s = new string[n];
            if (n == 1)
            {
                Console.WriteLine(1);
                return;
            }
            if (n == 2)
            {
                if (s[0] == s[1])
                {
                    Console.WriteLine(1);
                }
                else
                {
                    Console.WriteLine(2);
                }
                return;
            }
            for (int i=0; i<n; i++)
            {
                s[i] = Console.ReadLine();
            }
            int count = 0;
            for (int i=0; i<n-1; i++)
            {
                if (s[i] == s[i + 1]) count++;
            }
            Console.WriteLine(count);
            //Console.ReadKey();
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Olymp6
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string[] s = new string[n];
            if (n == 1)
            {
                Console.WriteLine(1);
                return;
            }

            for (int i=0; i<n; i++)
            {
                s[i] = Console.ReadLine();
            }
            int count = 0;
            for (int i=0; i<n-1; i++)
            {
                if (s[i] == s[i + 1]) count++;
            }
            Console.WriteLine(count);
            //Console.ReadKey();
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ca344A
{
    class Program
    {
        static void Main(string[] args)
        {
            var countRec = Convert.ToInt32(Console.ReadLine());
            var first = Console.ReadLine();
            var answer = 0;
            for (int i = 0; i < countRec - 1; i++)
            {
                var second = Console.ReadLine();
                if (first.Last() == second.First())
                {
                    answer++;
                }
                first = (string)second.Clone();
            }
            Console.WriteLine(answer + 1);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ca344A
{
    class Program
    {
        static void Main(string[] args)
        {
            var countRec = Convert.ToInt32(Console.ReadLine());
            var first = Console.ReadLine();
            var answer = 0;
            for (int i = 0; i < countRec - 1; i++)
            {
                var second = Console.ReadLine();
                if (first.Last() == second.First())
                {
                    answer++;
                }
                first = second;
            }
            Console.WriteLine(answer + 1);
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(int i=j;i<=k;++i)
typedef long long ll;
char cch;
inline int rd(){
	int x=0,fl=1;
	cch=getchar();
	while(cch>'9'||cch<'0'){
		if(cch=='-') fl=-1;
		cch=getchar();
	}
	while(cch>='0'&&cch<='9') x=(x<<3)+(x<<1)+cch-'0',cch=getchar();
	return x*fl;
}
const int N=2e5+3;
int to[N<<1],nxt[N<<1],head[N],sz[N],cnt;
inline void add(int u,int v){
	to[++cnt]=v,nxt[cnt]=head[u],head[u]=cnt;
	to[++cnt]=u,nxt[cnt]=head[v],head[v]=cnt;
}
inline void dfs(int u,int fa,int op){
	sz[u]=1;
	for(int i=head[u];i;i=nxt[i])if(to[i]^fa){
		if(!op) ++cnt;
		dfs(to[i],u,op^1);
		sz[u]+=sz[to[i]];
	}
}
int main(){
	ll ans=0;
	int n=rd(),u,v;
	rep(i,2,n) u=rd(),v=rd(),add(u,v);
	cnt=0;
	dfs(1,0,0);
	rep(i,1,n){
		ans+=1ll*sz[i]*(n-sz[i]);
	}
	ans+=1ll*cnt*(n-cnt);
	ans/=2ll;
	printf("%lld",ans);
}


#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(int i=j;i<=k;++i)
typedef long long ll;
char cch;
inline int rd(){
	int x=0,fl=1;
	cch=getchar();
	while(cch>'9'||cch<'0'){
		if(cch=='-') fl=-1;
		cch=getchar();
	}
	while(cch>='0'&&cch<='9') x=(x<<3)+(x<<1)+cch-'0',cch=getchar();
	return x*fl;
}
const int N=2e5+3;
int to[N<<1],nxt[N<<1],head[N],sz[N],cnt;
inline void add(int u,int v){
	to[++cnt]=v,nxt[cnt]=head[u],head[u]=cnt;
	to[++cnt]=u,nxt[cnt]=head[v],head[v]=cnt;
}
inline void dfs(int u,int fa,int op){
	sz[u]=1;
	for(int i=head[u];i;i=nxt[i])if(to[i]^fa){
		if(op) ++cnt;
		dfs(to[i],u,op^1);
		sz[u]+=sz[to[i]];
	}
}
int main(){
	ll ans=0;
	int n=rd(),u,v;
	rep(i,2,n) u=rd(),v=rd(),add(u,v);
	cnt=0;
	dfs(1,0,0);
	rep(i,1,n){
		ans+=1ll*sz[i]*(n-sz[i]);
	}
	ans+=1ll*cnt*(n-cnt);
	ans/=2ll;
	printf("%lld",ans);
}


#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(int i=j;i<=k;++i)
typedef long long ll;
char cch;
inline int rd(){
	int x=0,fl=1;
	cch=getchar();
	while(cch>'9'||cch<'0'){
		if(cch=='-') fl=-1;
		cch=getchar();
	}
	while(cch>='0'&&cch<='9') x=(x<<3)+(x<<1)+cch-'0',cch=getchar();
	return x*fl;
}
const int N=2e5+3;
int to[N<<1],nxt[N<<1],head[N],sz[N],cnt;
inline void add(int u,int v){
	to[++cnt]=v,nxt[cnt]=head[u],head[u]=cnt;
	to[++cnt]=u,nxt[cnt]=head[v],head[v]=cnt;
}
inline void dfs(int u,int fa,int op){
	sz[u]=1;
	for(int i=head[u];i;i=nxt[i])if(to[i]^fa){
		if(op) ++cnt;
		dfs(to[i],u,op^1);
	}
}
int main(){
	ll ans=0;
	int n=rd(),u,v;
	rep(i,2,n) u=rd(),v=rd(),add(u,v);
	cnt=0;
	dfs(1,0,0);
	rep(i,1,n){
		ans+=1ll*sz[i]*(n-sz[i]);
	}
	ans+=1ll*cnt*(n-cnt);
	ans/=2ll;
	printf("%lld",ans);
}


#include <bits/stdc++.h>
using namespace std;

const long long mod=1e9+7;
int n;
long long a[100010],inv[100010],pre[100010],ans,fac[100010];
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i)
	scanf("%lld",&a[i]);
	inv[1]=1;
	for(int i=2;i<=n;++i)
	inv[i]=(mod-mod/i)*inv[mod%i]%mod;
	for(int i=1;i<=n;++i)
	pre[i]=(pre[i-1]+inv[i])%mod;
	for(int i=1;i<=n;++i)
	ans=(ans+pre[n-i+1]*a[i]%mod+(pre[i]-1)*a[i]%mod)%mod;
	fac[0]=1;
	for(int i=1;i<=n;++i)
	fac[i]=fac[i-1]*i%mod;
	ans=(ans*fac[n])%mod;
	printf("%lld\n",ans);
	return 0;
}\


#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(int i=j;i<=k;++i)
typedef long long ll;
char cch;
inline int rd(){
	int x=0,fl=1;
	cch=getchar();
	while(cch>'9'||cch<'0'){
		if(cch=='-') fl=-1;
		cch=getchar();
	}
	while(cch>='0'&&cch<='9') x=(x<<3)+(x<<1)+cch-'0',cch=getchar();
	return x*fl;
}
const int N=2e5+3;
int to[N<<1],nxt[N<<1],head[N],sz[N],cnt;
inline void add(int u,int v){
	to[++cnt]=v,nxt[cnt]=head[u],head[u]=cnt;
	to[++cnt]=u,nxt[cnt]=head[v],head[v]=cnt;
}
inline void dfs(int u,int fa,int op){
	sz[u]=1;
	for(int i=head[u];i;i=nxt[i])if(to[i]^fa){
		if(op) ++cnt;
		dfs(to[i],u,op^1);
	}
}
int main(){
	ll ans=0;
	int n=rd(),u,v;
	rep(i,2,n) u=rd(),v=rd(),add(u,v);
	cnt=0;
	dfs(1,0,0);
	rep(i,1,n){
		ans+=sz[i]*(n-sz[i]);
	}
	ans+=cnt*(n-cnt);
	ans/=2;
	printf("%lld",ans);
}


#include<bits/stdc++.h>
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define em emplace_back
#define sqr(x) (x) * (x)
using namespace std;
typedef long long ll;
typedef long double ld;
const int DL = 2010;
const ll INF = 1E18;
vector<int> ed[200010];
ll dpc[200010], dpnc[200010], klc[200010], klnc[200010];

void dfs(int v, int p) {
    ll sm = 0, kl = 0;
    for (auto u : ed[v]) {
        if (ed[u] == p) {
            continue;
        }
        dfs(u, v);
        ll vl = ll(1) + dpc[u];
        ll tkl = ll(1) + klc[u];
        dpnc[v] += sm * vl;
        dpnc[v] += vl;
        klnc[v] += tkl * kl;
        klnc[v] += tkl;
        vl = dpnc[u];
        tkl = klnc[u];
        dpc[v] += sm * vl;
        dpc[v] += vl;
        klc[v] += tkl * kl;
        klc[v] += tkl;
    }
}

int main() {
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    for (int i = 0; i < n - 1; ++i) {
        cin >> u >> v;
        --u;
        --v;
        ed[u].pb(v);
        ed[v].pb(u);
    }

    dfs(0, -1);
    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        ans += dpc[i] / ll(2) + (dpnc[i] - klnc[i]) / ll(2) + klnc[i];
    }
    cout << ans << '\n';
}


#include<bits/stdc++.h>
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define em emplace_back
#define sqr(x) (x) * (x)
using namespace std;
typedef long long ll;
typedef long double ld;

vector<int> ed[200010];
ll dpc[200010], dpnc[200010], klc[200010], klnc[200010];
ll ansc = 0, ansnc = 0, ansklc = 0, ansklnc = 0;

void dfs(int v, int p) {
    ll smc = 0, klcV = 0, smnc = 0, klncV = 0;
    for (auto u : ed[v]) {
        if (u == p) {
            continue;
        }
        dfs(u, v);
        ll vl = ll(1) + dpc[u] + klc[u];
        ll tkl = ll(1) + klc[u];

        ansc += smc * tkl +  vl * klcV;
        ansnc += vl;
        ansklnc += tkl * klcV;
        ansklnc += tkl;

        ansc += smnc * tkl + vl * klncV;
        ansklc += tkl * klncV;

        vl = dpnc[u] + klnc[u];
        tkl = klnc[u];
        ansc += smc * tkl + vl * klcV;
        ansc += vl;
        ansklc += tkl * klcV;
        ansklc += tkl;

        ansnc += smnc * tkl + vl * klncV;
        ansklnc += tkl * klncV;

        smnc += ll(1) + dpc[u] + klc[u];
        klncV += ll(1) + klc[u];
        smc += dpnc[u] + klnc[u];
        klcV += klnc[u];
    }

    dpc[v] = smc;
    dpnc[v] = smnc;
    klc[v] = klcV;
    klnc[v] = klncV;
}

int main() {
    ios_base::sync_with_stdio(0);
    int n, u, v;
    cin >> n;
    for (int i = 0; i < n - 1; ++i) {
        cin >> u >> v;
        --u;
        --v;
        ed[u].pb(v);
        ed[v].pb(u);
    }

    dfs(0, -1);
    cout << ansc / ll(2) + (ansnc - ansklnc + ll(1)) / ll(2)  + ansklnc << '\n';
}


#include<bits/stdc++.h>
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define em emplace_back
#define sqr(x) (x) * (x)
using namespace std;
typedef long long ll;
typedef long double ld;
const int DL = 2010;
const ll INF = 1E18;
vector<int> ed[200010];
ll dpc[200010], dpnc[200010], klc[200010], klnc[200010];
ll ansc = 0, ansnc = 0, ansklc = 0, ansklnc = 0;

void dfs(int v, int p) {
    ll smc = 0, klcV = 0, smnc = 0, klncV = 0;
    for (auto u : ed[v]) {
        if (u == p) {
            continue;
        }
        dfs(u, v);
        ll vl = ll(1) + dpc[u] + klc[u];
        ll tkl = ll(1) + klc[u];

        ansc += smc * tkl +  vl * klcV;
        ansnc += vl;
        ansklnc += tkl * klcV;
        ansklnc += tkl;

        ansc += smnc * tkl + vl * klncV;
        ansklc += tkl * klncV;

        vl = dpnc[u] + klnc[u];
        tkl = klnc[u];
        ansc += smc * tkl + vl * klcV;
        ansc += vl;
        ansklc += tkl * klcV;
        ansklc += tkl;

        ansnc += smnc * tkl + vl * klncV;
        ansklnc += tkl * klncV;

        smnc += ll(1) + dpc[u] + klc[u];
        klncV += ll(1) + klc[u];
        smc += dpnc[u] + klnc[u];
        klcV += klnc[u];
    }

    dpc[v] = smc;
    dpnc[v] = smnc;
    klc[v] = klcV;
    klnc[v] = klncV;
}

int main() {
    ios_base::sync_with_stdio(0);
    int n, u, v;
    cin >> n;
    for (int i = 0; i < n - 1; ++i) {
        cin >> u >> v;
        --u;
        --v;
        ed[u].pb(v);
        ed[v].pb(u);
    }

    dfs(0, -1);
    cout << ansc / ll(2) + (ansnc + ansklnc) / ll(2) << '\n';
}


#include<bits/stdc++.h>
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define em emplace_back
#define sqr(x) (x) * (x)
using namespace std;
typedef long long ll;
typedef long double ld;
const int DL = 2010;
const ll INF = 1E18;
vector<int> ed[200010];
ll dpc[200010], dpnc[200010], klc[200010], klnc[200010];
ll ansc = 0, ansnc = 0, ansklc = 0, ansklnc = 0;

void dfs(int v, int p) {
    ll smc = 0, klcV = 0, smnc = 0, klncV = 0;
    for (auto u : ed[v]) {
        if (u == p) {
            continue;
        }
        dfs(u, v);
        ll vl = ll(1) + dpc[u] + klc[u];
        ll tkl = ll(1) + klc[u];

        ansc += smc * tkl +  vl * klcV;
        ansnc += vl;
        ansklnc += tkl * klcV;
        ansklnc += tkl;

        ansc += smnc * tkl + vl * klncV;
        ansklc += tkl * klncV;

        vl = dpnc[u] + klnc[u];
        tkl = klnc[u];
        ansc += smc * tkl + vl * klcV;
        ansc += vl;
        ansklc += tkl * klcV;
        ansklc += tkl;

        ansnc += smnc * tkl + vl * klncV;
        ansklnc += tkl * klncV;

        smnc += ll(1) + dpc[u] + klc[u];
        klncV += ll(1) + klc[u];
        smc += dpnc[u] + klnc[u];
        klcV += klnc[u];
    }

    dpc[v] = smc;
    dpnc[v] = smnc;
    klc[v] = klcV;
    klnc[v] = klncV;
}

int main() {
    ios_base::sync_with_stdio(0);
    int n, u, v;
    cin >> n;
    for (int i = 0; i < n - 1; ++i) {
        cin >> u >> v;
        --u;
        --v;
        ed[u].pb(v);
        ed[v].pb(u);
    }

    dfs(0, -1);
    cout << ansc / ll(2) + (ansnc - ansklnc) / ll(2)  + ansklnc << '\n';
}


#include<bits/stdc++.h>
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define em emplace_back
#define sqr(x) (x) * (x)
using namespace std;
typedef long long ll;
typedef long double ld;

vector<int> ed[200010];
ll dpc[200010], dpnc[200010], klc[200010], klnc[200010];
ll ansc = 0, ansnc = 0, ansklc = 0, ansklnc = 0;

void dfs(int v, int p) {
    ll smc = 0, klcV = 0, smnc = 0, klncV = 0;
    for (auto u : ed[v]) {
        if (u == p) {
            continue;
        }
        dfs(u, v);
        ll vl = ll(1) + dpc[u] + klc[u];
        ll tkl = ll(1) + klc[u];

        ansc += smc * tkl +  vl * klcV;
        ansnc += vl;
        ansklnc += tkl * klcV;
        ansklnc += tkl;

        ansc += smnc * tkl + vl * klncV;
        ansklc += tkl * klncV;

        vl = dpnc[u] + klnc[u];
        tkl = klnc[u];
        ansc += smc * tkl + vl * klcV;
        ansc += vl;
        ansklc += tkl * klcV;
        ansklc += tkl;

        ansnc += smnc * tkl + vl * klncV;
        ansklnc += tkl * klncV;

        smnc += ll(1) + dpc[u] + klc[u];
        klncV += ll(1) + klc[u];
        smc += dpnc[u] + klnc[u];
        klcV += klnc[u];
    }

    dpc[v] = smc;
    dpnc[v] = smnc;
    klc[v] = klcV;
    klnc[v] = klncV;
}

int main() {
    ios_base::sync_with_stdio(0);
    int n, u, v;
    cin >> n;
    for (int i = 0; i < n - 1; ++i) {
        cin >> u >> v;
        --u;
        --v;
        ed[u].pb(v);
        ed[v].pb(u);
    }

    dfs(0, -1);
    cout << (ansc + ll(1)) / ll(2) + (ansnc - ansklnc + ll(1)) / ll(2)  + ansklnc << '\n';
}


#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

const int N = 2e5 + 5;

vector < int > adia[N];

int sp[N], si[N], np[N], ni[N];

long long asp, asi, anp, ani;

void dfs(int nod, int t) {
    np[nod] = 1;
    for (auto i : adia[nod]) {
        if (i == t)
            continue;
        dfs(i, nod);
        asp += ni[i] * sp[nod] + np[nod] * (si[i] + ni[i]) + np[i] * si[nod] + (sp[i] + np[i]) * ni[nod];
        asi += np[i] * sp[nod] + (sp[i] + np[i]) * np[nod] + si[nod] * ni[i] + ni[nod] * (si[i] + ni[i]);
        ani += ni[nod] * ni[i] + np[nod] * np[i];
        sp[nod] += si[i] + ni[i];
        si[nod] += sp[i] + np[i];
        np[nod] += ni[i];
        ni[nod] += np[i];
    }
}

int main()
{
    int n, a, b;
    cin >> n;
    for (int i = 1; i < n; ++i) {
        cin >> a >> b;
        adia[a].push_back(b);
        adia[b].push_back(a);
    }
    dfs(1, 0);
    cout << asp / 2 + (asi + ani) / 2;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

const int N = 1e5 + 5;

vector < int > adia[N];

int sp[N], si[N], np[N], ni[N];

long long asp, asi, anp, ani;

void dfs(int nod, int t) {
    np[nod] = 1;
    for (auto i : adia[nod]) {
        if (i == t)
            continue;
        dfs(i, nod);
        asp += ni[i] * sp[nod] + np[nod] * (si[i] + ni[i]) + np[i] * si[nod] + (sp[i] + np[i]) * ni[nod];
        asi += np[i] * sp[nod] + (sp[i] + np[i]) * np[nod] + si[nod] * ni[i] + ni[nod] * (si[i] + ni[i]);
        ani += ni[nod] * ni[i] + np[nod] * np[i];
        sp[nod] += si[i] + ni[i];
        si[nod] += sp[i] + np[i];
        np[nod] += ni[i];
        ni[nod] += np[i];
    }
}

int main()
{
    int n, a, b;
    cin >> n;
    for (int i = 1; i < n; ++i) {
        cin >> a >> b;
        adia[a].push_back(b);
        adia[b].push_back(a);
    }
    dfs(1, 0);
    cout << asp / 2 + (asi + ani) / 2;
    return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;

const int N = 1e5 + 5;

vector < int > adia[N];

int sp[N], si[N], np[N], ni[N];

long long asp, asi, anp, ani;

void dfs(int nod, int t) {
    np[nod] = 1;
    for (auto i : adia[nod]) {
        if (i == t)
            continue;
        dfs(i, nod);
        asp += ni[i] * sp[nod] + np[nod] * (si[i] + ni[i]) + np[i] * si[nod] + (sp[i] + np[i]) * ni[nod];
        asi += np[i] * sp[nod] + (sp[i] + np[i]) * np[nod] + si[nod] * ni[i] + ni[nod] * (si[i] + ni[i]);
        ani += ni[nod] * ni[i] + np[nod] * np[i];
        sp[nod] += si[i] + ni[i];
        si[nod] += sp[i] + np[i];
        np[nod] += ni[i];
        ni[nod] += np[i];
    }
}

int main()
{
    int n, a, b;
    cin >> n;
    for (int i = 1; i < n; ++i) {
        cin >> a >> b;
        adia[a].push_back(b);
        adia[b].push_back(a);
    }
    dfs(1, 0);
    cout << asp / 2 + (asi + ani) / 2;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

const int N = 2e5 + 5;

vector < int > adia[N];

long long sp[N], si[N], np[N], ni[N];

long long asp, asi, anp, ani;

void dfs(int nod, int t) {
    np[nod] = 1;
    for (auto i : adia[nod]) {
        if (i == t)
            continue;
        dfs(i, nod);
        asp += ni[i] * sp[nod] + np[nod] * (si[i] + ni[i]) + np[i] * si[nod] + (sp[i] + np[i]) * ni[nod];
        asi += np[i] * sp[nod] + (sp[i] + np[i]) * np[nod] + si[nod] * ni[i] + ni[nod] * (si[i] + ni[i]);
        ani += ni[nod] * ni[i] + np[nod] * np[i];
        sp[nod] += si[i] + ni[i];
        si[nod] += sp[i] + np[i];
        np[nod] += ni[i];
        ni[nod] += np[i];
    }
}

int main()
{
    int n, a, b;
    cin >> n;
    for (int i = 1; i < n; ++i) {
        cin >> a >> b;
        adia[a].push_back(b);
        adia[b].push_back(a);
    }
    dfs(1, 0);
    cout << asp / 2 + (asi + ani) / 2;
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

const int maxn = 2e5 + 1;
vector<int> g[maxn];
int sz[maxn];
long long sumr[maxn], sumt[maxn];
int cntt[maxn][4], cntr[maxn][4];
long long ans = 0;

void dfs(int v, int p = 0) {
	sz[v] = 1;
	cntr[v][0] = 1;
	for(int x : g[v]) {
		if(x != p) {
			dfs(x, v);
			sz[v] += sz[x];
			for(int i = 1; i <= 3; i++) cntr[v][i] += cntr[x][i - 1];
			sumr[v] += sumr[x] + sz[x];
		}
	}
	for(int x : g[v]) {
		if(x != p) {
			sumt[v] += (sumr[x] + 1) * (sz[v] - sz[x] - 1);
			cntt[v][2] += cntr[v][1] - 1;
			cntt[v][3] += cntr[v][2] - cntr[x][1];
		}
	}
	cntt[v][2] /= 2;
	ans += sumr[v] + sumt[v] - cntr[v][2] - cntr[v][3] - cntt[v][2] - cntt[v][3];
}

int main() {
	int n;
	cin >> n;
	for(int i = 1; i < n; i++) {
		int a, b;
		cin >> a >> b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	dfs(1);
	cout << ans << endl;

}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

const int maxn = 2e5 + 1;
vector<int> g[maxn];
int sz[maxn];
long long sumr[maxn], sumt[maxn];
long long cntt[maxn][2], cntr[maxn][2];
long long ans = 0;

void dfs(int v, int p = 0) {
	sz[v] = 1;
	cntr[v][0] = 1;
	for(int x : g[v]) {
		if(x != p) {
			dfs(x, v);
			sz[v] += sz[x];
			cntr[v][0] += cntr[x][1];
			cntr[v][1] += cntr[x][0];
			sumr[v] += sumr[x] + sz[x];
		}
	}
	for(int x : g[v]) {
		if(x != p) {
			sumt[v] += (sumr[x] + sz[x]) * (sz[v] - sz[x] - 1);
			cntt[v][0] += cntr[x][0] * (cntr[v][1] - cntr[x][0]);
			cntt[v][0] += cntr[x][1] * (cntr[v][0] - cntr[x][1] - 1);
			cntt[v][1] += cntr[x][1] * (cntr[v][1] - cntr[x][0]);
			cntt[v][1] += cntr[x][0] * (cntr[v][0] - cntr[x][1] - 1);
		}
	}
	cntt[v][0] /= 2;
	cntt[v][1] /= 2;
	ans += sumr[v] + sumt[v];
}

int main() {
	int n;
	cin >> n;
	for(int i = 1; i < n; i++) {
		int a, b;
		cin >> a >> b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	dfs(1);
	long long cur = 0;
	for(int i = 1; i <= n; i++) cur += cntr[i][1] + cntt[i][1];
	ans += cur;
	ans /= 2;
	cout << ans << endl;

}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

const int maxn = 2e5 + 1;
vector<int> g[maxn];
int sz[maxn];
long long sumr[maxn], sumt[maxn];
int cntt[maxn][2], cntr[maxn][2];
long long ans = 0;

void dfs(int v, int p = 0) {
	sz[v] = 1;
	cntr[v][0] = 1;
	for(int x : g[v]) {
		if(x != p) {
			dfs(x, v);
			sz[v] += sz[x];
			cntr[v][0] += cntr[x][1];
			cntr[v][1] += cntr[x][0];
			sumr[v] += sumr[x] + sz[x];
		}
	}
	for(int x : g[v]) {
		if(x != p) {
			sumt[v] += (sumr[x] + sz[x]) * (sz[v] - sz[x] - 1);
			cntt[v][0] += cntr[x][0] * (cntr[v][1] - cntr[x][0]);
			cntt[v][0] += cntr[x][1] * (cntr[v][0] - cntr[x][1] - 1);
			cntt[v][1] += cntr[x][1] * (cntr[v][1] - cntr[x][0]);
			cntt[v][1] += cntr[x][0] * (cntr[v][0] - cntr[x][1] - 1);
		}
	}
	cntt[v][0] /= 2;
	ans += sumr[v] + sumt[v];
}

int main() {
	int n;
	cin >> n;
	for(int i = 1; i < n; i++) {
		int a, b;
		cin >> a >> b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	dfs(1);
	long long cur = 0;
	for(int i = 1; i <= n; i++) cur += cntr[i][0] + cntt[i][0];
	cur -= n;
	ans += 1ll * n * (n - 1) / 2;
	ans /= 2;
	ans -= cur / 2;
	cout << ans << endl;

}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

const int maxn = 2e5 + 1;
vector<int> g[maxn];
int sz[maxn];
long long sumr[maxn], sumt[maxn];
int cntt[maxn][2], cntr[maxn][2];
long long ans = 0;

void dfs(int v, int p = 0) {
	sz[v] = 1;
	cntr[v][0] = 1;
	for(int x : g[v]) {
		if(x != p) {
			dfs(x, v);
			sz[v] += sz[x];
			cntr[v][0] += cntr[x][1];
			cntr[v][1] += cntr[x][0];
			sumr[v] += sumr[x] + sz[x];
		}
	}
	for(int x : g[v]) {
		if(x != p) {
			sumt[v] += (sumr[x] + sz[x]) * (sz[v] - sz[x] - 1);
			cntt[v][0] += cntr[x][0] * (cntr[v][1] - cntr[x][0]);
			cntt[v][0] += cntr[x][1] * (cntr[v][0] - cntr[x][1] - 1);
			cntt[v][1] += cntr[x][1] * (cntr[v][1] - cntr[x][0]);
			cntt[v][1] += cntr[x][0] * (cntr[v][0] - cntr[x][1] - 1);
		}
	}
	cntt[v][0] /= 2;
	cntt[v][1] /= 2;
	ans += sumr[v] + sumt[v];
}

int main() {
	int n;
	cin >> n;
	for(int i = 1; i < n; i++) {
		int a, b;
		cin >> a >> b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	dfs(1);
	long long cur = 0;
	for(int i = 1; i <= n; i++) cur += cntr[i][1] + cntt[i][1];
	ans += cur;
	ans /= 2;
	cout << ans << endl;

}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

const int maxn = 2e5 + 1;
vector<int> g[maxn];
int sz[maxn];
long long sumr[maxn], sumt[maxn];
long long cntt[maxn][2], cntr[maxn][2];
long long ans = 0;

void dfs(int v, int p = 0) {
	sz[v] = 1;
	cntr[v][0] = 1;
	for(int x : g[v]) {
		if(x != p) {
			dfs(x, v);
			sz[v] += sz[x];
			cntr[v][0] += cntr[x][1];
			cntr[v][1] += cntr[x][0];
			sumr[v] += sumr[x] + sz[x];
		}
	}
	for(int x : g[v]) {
		if(x != p) {
			sumt[v] += (sumr[x] + sz[x]) * (sz[v] - sz[x] - 1);
			cntt[v][0] += cntr[x][0] * (cntr[v][1] - cntr[x][0]);
			cntt[v][0] += cntr[x][1] * (cntr[v][0] - cntr[x][1] - 1);
			cntt[v][1] += cntr[x][1] * (cntr[v][1] - cntr[x][0]);
			cntt[v][1] += cntr[x][0] * (cntr[v][0] - cntr[x][1] - 1);
		}
	}
	cntt[v][0] /= 2;
	ans += sumr[v] + sumt[v];
}

int main() {
	int n;
	cin >> n;
	for(int i = 1; i < n; i++) {
		int a, b;
		cin >> a >> b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	dfs(1);
	long long cur = 0;
	for(int i = 1; i <= n; i++) cur += cntr[i][0] + cntt[i][0];
	cur -= n;
	ans += 1ll * n * (n - 1) / 2;
	ans /= 2;
	ans -= cur / 2;
	cout << ans << endl;

}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

const int maxn = 2e5 + 1;
vector<int> g[maxn];
int sz[maxn];
long long sumr[maxn], sumt[maxn];
int cntt[maxn][2], cntr[maxn][2];
long long ans = 0;

void dfs(int v, int p = 0) {
	sz[v] = 1;
	cntr[v][0] = 1;
	for(int x : g[v]) {
		if(x != p) {
			dfs(x, v);
			sz[v] += sz[x];
			cntr[v][0] += cntr[x][1];
			cntr[v][1] += cntr[x][0];
			sumr[v] += sumr[x] + sz[x];
		}
	}
	for(int x : g[v]) {
		if(x != p) {
			sumt[v] += (sumr[x] + sz[x]) * (sz[v] - sz[x] - 1);
			cntt[v][0] += cntr[x][0] * (cntr[v][1] - cntr[x][0]);
			cntt[v][0] += cntr[x][1] * (cntr[v][0] - cntr[x][1] - 1);
			cntt[v][1] += cntr[x][1] * (cntr[v][1] - cntr[x][0]);
			cntt[v][1] += cntr[x][0] * (cntr[v][0] - cntr[x][1] - 1);
		}
	}
	cntt[v][0] /= 2;
	ans += sumr[v] + sumt[v];
}

int main() {
	int n;
	cin >> n;
	for(int i = 1; i < n; i++) {
		int a, b;
		cin >> a >> b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	dfs(1);
	long long cur = 0;
	for(int i = 1; i <= n; i++) cur += cntr[i][1] + cntt[i][1];
	ans += cur;
	ans /= 2;
	cout << ans << endl;

}


#include <bits/stdc++.h>
using namespace std;

// io
#define get(i) scanf("%d", &i)
#define flush fflush(stdin)

// manipulations
#define f(i, n) for (int i = 0; i < n; i++)
#define fr(i, n) for (int i = n - 1; i >= 0; i--)
#define ff(i, a, b) for (int i = a; i <= b; i++)
#define lowbit(x) (x & -x)
#define sz(x) int((x).size())

// built-in
#define bitcount __builtin_popcount
#define gcd __gcd

// short
#define pb push_back
#define fill(arr, a) memset(arr, a, sizeof(arr))

// useful bits
#define IN(i, l, r) (l <= i && i <= r)
#define relax(a, b) a = max(a, b);

typedef vector<int> VI;
typedef pair<int, int> PII;
typedef long long ll;

ll modpow(ll a, ll b, ll mod = (ll) (1e9 + 7))
{if (!b) return 1; a %= mod; return modpow(a * a % mod, b / 2, mod) * (b & 1 ? a : 1) % mod;}

const int maxn = 2e5;
int n;
VI adj[maxn];
int subsz[maxn], centroidParent[maxn];
bool marked[maxn];

ll ans = 0;

int dfsSubsz(int v, int p) {
	if (marked[v]) return 0;
	subsz[v] = 1;
	for (int w : adj[v])
		if (w != p) subsz[v] += dfsSubsz(w, v);
	return subsz[v];
}

int dfsCentroid(int v, int p, int sz) {
	for (int w : adj[v])
		if (w != p && subsz[w] > sz / 2)
			return dfsCentroid(w, v, sz);
	return v;
}

void dfs(int v, int p, int d, int prev[], int sum[]) {
	f(i, 18) {
		if (prev[i]) ans += (ll) ((d/2) + (1<<i)) * prev[i];
		if ((d/2+1)>>i&1) sum[i]++;
	}
	ans += (d+1)/2;
	for (int w : adj[v])
		if (w != p && !marked[w])
			dfs(w, v, d+1, prev, sum);
}

void decompose(int v, int p) {
	dfsSubsz(v, p);
	int centroid = dfsCentroid(v, p, subsz[v]);
	centroidParent[centroid] = p;
	marked[centroid] = true;

	int prev[18]; fill(prev, 0);
	for (int w : adj[centroid])
		if (!marked[w]) {
			int sum[18]; fill(sum, 0);
			dfs(w, centroid, 1, prev, sum);
			f(i, 18) prev[i] += sum[i];
		}

	for (int w : adj[centroid])
		if (!marked[w]) decompose(w, centroid);
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	get(n);
	f(i, n-1) {
		int x, y; get(x), get(y); x--, y--;
		adj[x].pb(y); adj[y].pb(x);
	}

	decompose(0, -1);

	cout << ans << endl;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

// io
#define get(i) scanf("%d", &i)
#define flush fflush(stdin)

// manipulations
#define f(i, n) for (int i = 0; i < n; i++)
#define fr(i, n) for (int i = n - 1; i >= 0; i--)
#define ff(i, a, b) for (int i = a; i <= b; i++)
#define lowbit(x) (x & -x)
#define sz(x) int((x).size())

// built-in
#define bitcount __builtin_popcount
#define gcd __gcd

// short
#define pb push_back
#define fill(arr, a) memset(arr, a, sizeof(arr))

// useful bits
#define IN(i, l, r) (l <= i && i <= r)
#define relax(a, b) a = max(a, b);

typedef vector<int> VI;
typedef pair<int, int> PII;
typedef long long ll;

ll modpow(ll a, ll b, ll mod = (ll) (1e9 + 7))
{if (!b) return 1; a %= mod; return modpow(a * a % mod, b / 2, mod) * (b & 1 ? a : 1) % mod;}

const int maxn = 2e5;
int n;
VI adj[maxn];
int subsz[maxn], centroidParent[maxn];
bool marked[maxn];

ll ans = 0;

int dfsSubsz(int v, int p) {
	if (marked[v]) return 0;
	subsz[v] = 1;
	for (int w : adj[v])
		if (w != p && !marked[w]) subsz[v] += dfsSubsz(w, v);
	return subsz[v];
}

int dfsCentroid(int v, int p, int sz) {
	for (int w : adj[v])
		if (w != p && subsz[w] > sz / 2)
			return dfsCentroid(w, v, sz);
	return v;
}

void dfs(int v, int p, int d, ll preo, ll pree, int sz, int &toinc, ll &incpree, ll &incpreo) {
	toinc++;
	incpreo += d/2+1;
	incpree += (d+1)/2;
	if (d & 1) ans += (ll) sz * (d/2) + preo;
	else ans += (ll) sz * (d/2) + pree;
	ans += (d+1)/2;
	for (int w : adj[v])
		if (w != p && !marked[w])
			dfs(w, v, d+1, preo, pree, sz, toinc, incpree, incpreo);
}

void decompose(int v, int p) {
	dfsSubsz(v, p);
	int centroid = dfsCentroid(v, p, subsz[v]);
	centroidParent[centroid] = p;
	marked[centroid] = true;

	int sum = 0;
	ll preo = 0, pree = 0;
	for (int w : adj[centroid])
		if (!marked[w]) {
			int toinc = 0;
			ll incpree = 0, incpreo = 0;
			dfs(w, centroid, 1, preo, pree, sum, toinc, incpree, incpreo);
			pree += incpree, preo += incpreo;
			sum += toinc;
		}

	for (int w : adj[centroid])
		if (!marked[w]) decompose(w, centroid);
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	get(n);
	f(i, n-1) {
		int x, y; get(x), get(y); x--, y--;
		adj[x].pb(y); adj[y].pb(x);
	}

	decompose(0, -1);

	cout << ans << endl;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

// io
#define get(i) scanf("%d", &i)
#define flush fflush(stdin)

// manipulations
#define f(i, n) for (int i = 0; i < n; i++)
#define fr(i, n) for (int i = n - 1; i >= 0; i--)
#define ff(i, a, b) for (int i = a; i <= b; i++)
#define lowbit(x) (x & -x)
#define sz(x) int((x).size())

// built-in
#define bitcount __builtin_popcount
#define gcd __gcd

// short
#define pb push_back
#define fill(arr, a) memset(arr, a, sizeof(arr))

// useful bits
#define IN(i, l, r) (l <= i && i <= r)
#define relax(a, b) a = max(a, b);

typedef vector<int> VI;
typedef pair<int, int> PII;
typedef long long ll;

ll modpow(ll a, ll b, ll mod = (ll) (1e9 + 7))
{if (!b) return 1; a %= mod; return modpow(a * a % mod, b / 2, mod) * (b & 1 ? a : 1) % mod;}

const int maxn = 1e5;
int n;
VI adj[maxn];
int subsz[maxn], centroidParent[maxn];
bool marked[maxn];

ll ans = 0;

int dfsSubsz(int v, int p) {
	if (marked[v]) return 0;
	subsz[v] = 1;
	for (int w : adj[v])
		if (w != p) subsz[v] += dfsSubsz(w, v);
	return subsz[v];
}

int dfsCentroid(int v, int p, int sz) {
	for (int w : adj[v])
		if (w != p && subsz[w] > sz / 2)
			return dfsCentroid(w, v, sz);
	return v;
}

void dfs(int v, int p, int d, int prev[], int sum[]) {
	f(i, 18) {
		if (prev[i]) ans += (ll) ((d/2) + (1<<i)) * prev[i];
		if ((d/2+1)>>i&1) sum[i]++;
	}
	ans += (d+1)/2;
	for (int w : adj[v])
		if (w != p && !marked[w])
			dfs(w, v, d+1, prev, sum);
}

void decompose(int v, int p) {
	dfsSubsz(v, p);
	int centroid = dfsCentroid(v, p, subsz[v]);
	centroidParent[centroid] = p;
	marked[centroid] = true;

	int prev[18]; fill(prev, 0);
	for (int w : adj[centroid])
		if (!marked[w]) {
			int sum[18]; fill(sum, 0);
			dfs(w, centroid, 1, prev, sum);
			f(i, 18) prev[i] += sum[i];
		}

	for (int w : adj[centroid])
		if (!marked[w]) decompose(w, centroid);
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	get(n);
	f(i, n-1) {
		int x, y; get(x), get(y); x--, y--;
		adj[x].pb(y); adj[y].pb(x);
	}

	decompose(0, -1);

	cout << ans << endl;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

// io
#define get(i) scanf("%d", &i)
#define flush fflush(stdin)

// manipulations
#define f(i, n) for (int i = 0; i < n; i++)
#define fr(i, n) for (int i = n - 1; i >= 0; i--)
#define ff(i, a, b) for (int i = a; i <= b; i++)
#define lowbit(x) (x & -x)
#define sz(x) int((x).size())

// built-in
#define bitcount __builtin_popcount
#define gcd __gcd

// short
#define pb push_back
#define fill(arr, a) memset(arr, a, sizeof(arr))

// useful bits
#define IN(i, l, r) (l <= i && i <= r)
#define relax(a, b) a = max(a, b);

typedef vector<int> VI;
typedef pair<int, int> PII;
typedef long long ll;

ll modpow(ll a, ll b, ll mod = (ll) (1e9 + 7))
{if (!b) return 1; a %= mod; return modpow(a * a % mod, b / 2, mod) * (b & 1 ? a : 1) % mod;}

const int maxn = 2e5;
int n;
VI adj[maxn];
int subsz[maxn], centroidParent[maxn];
bool marked[maxn];

ll ans = 0;

int dfsSubsz(int v, int p) {
	if (marked[v]) return 0;
	subsz[v] = 1;
	for (int w : adj[v])
		if (w != p) subsz[v] += dfsSubsz(w, v);
	return subsz[v];
}

int dfsCentroid(int v, int p, int sz) {
	for (int w : adj[v])
		if (w != p && subsz[w] > sz / 2)
			return dfsCentroid(w, v, sz);
	return v;
}

ll dfs(int v, int p, int d, ll pre, int sz) {
	ll record = d / 2 + 1;
	ans += sz * (d/2) + pre;
	ans += (d+1)/2;
	for (int w : adj[v])
		if (w != p && !marked[w])
			record += dfs(w, v, d+1, pre, sz);
	return record;
}

void decompose(int v, int p) {
	dfsSubsz(v, p);
	int centroid = dfsCentroid(v, p, subsz[v]);
	centroidParent[centroid] = p;
	marked[centroid] = true;

	int sz = 0;
	ll prev = 0;
	for (int w : adj[centroid])
		if (!marked[w]) {
			prev += dfs(w, centroid, 1, prev, sz);
			sz += dfsSubsz(w, centroid);
		}

	for (int w : adj[centroid])
		if (!marked[w]) decompose(w, centroid);
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	get(n);
	f(i, n-1) {
		int x, y; get(x), get(y); x--, y--;
		adj[x].pb(y); adj[y].pb(x);
	}

	decompose(0, -1);

	cout << ans << endl;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

// io
#define get(i) scanf("%d", &i)
#define flush fflush(stdin)

// manipulations
#define f(i, n) for (int i = 0; i < n; i++)
#define fr(i, n) for (int i = n - 1; i >= 0; i--)
#define ff(i, a, b) for (int i = a; i <= b; i++)
#define lowbit(x) (x & -x)
#define sz(x) int((x).size())

// built-in
#define bitcount __builtin_popcount
#define gcd __gcd

// short
#define pb push_back
#define fill(arr, a) memset(arr, a, sizeof(arr))

// useful bits
#define IN(i, l, r) (l <= i && i <= r)
#define relax(a, b) a = max(a, b);

typedef vector<int> VI;
typedef pair<int, int> PII;
typedef long long ll;

ll modpow(ll a, ll b, ll mod = (ll) (1e9 + 7))
{if (!b) return 1; a %= mod; return modpow(a * a % mod, b / 2, mod) * (b & 1 ? a : 1) % mod;}

const int maxn = 1e5;
int n;
VI adj[maxn];
int subsz[maxn], centroidParent[maxn];
bool marked[maxn];

ll ans = 0;

int dfsSubsz(int v, int p) {
	if (marked[v]) return 0;
	subsz[v] = 1;
	for (int w : adj[v])
		if (w != p) subsz[v] += dfsSubsz(w, v);
	return subsz[v];
}

int dfsCentroid(int v, int p, int sz) {
	for (int w : adj[v])
		if (w != p && subsz[w] > sz / 2)
			return dfsCentroid(w, v, sz);
	return v;
}

ll dfs(int v, int p, int d) {
	ll sum = d/2;
	ans += (d+1)/2;
	for (int w : adj[v])
		if (w != p && !marked[w])
			sum += dfs(w, v, d+1);
	return sum;
}

void decompose(int v, int p) {
	dfsSubsz(v, p);
	int centroid = dfsCentroid(v, p, subsz[v]);
	centroidParent[centroid] = p;
	marked[centroid] = true;

	ll prevsum = 0;
	for (int w : adj[centroid])
		if (!marked[w]) {
			ll sum = dfs(w, centroid, 1);
			ans += (sum + dfsSubsz(w, centroid)) * prevsum;
			prevsum += sum + dfsSubsz(w, centroid);
		}

	for (int w : adj[centroid])
		if (!marked[w]) decompose(w, centroid);
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	get(n);
	f(i, n-1) {
		int x, y; get(x), get(y); x--, y--;
		adj[x].pb(y); adj[y].pb(x);
	}

	decompose(0, -1);

	cout << ans << endl;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

// io
#define get(i) scanf("%d", &i)
#define flush fflush(stdin)

// manipulations
#define f(i, n) for (int i = 0; i < n; i++)
#define fr(i, n) for (int i = n - 1; i >= 0; i--)
#define ff(i, a, b) for (int i = a; i <= b; i++)
#define lowbit(x) (x & -x)
#define sz(x) int((x).size())

// built-in
#define bitcount __builtin_popcount
#define gcd __gcd

// short
#define pb push_back
#define fill(arr, a) memset(arr, a, sizeof(arr))

// useful bits
#define IN(i, l, r) (l <= i && i <= r)
#define relax(a, b) a = max(a, b);

typedef vector<int> VI;
typedef pair<int, int> PII;
typedef long long ll;

ll modpow(ll a, ll b, ll mod = (ll) (1e9 + 7))
{if (!b) return 1; a %= mod; return modpow(a * a % mod, b / 2, mod) * (b & 1 ? a : 1) % mod;}

const int maxn = 2e5;
int n;
VI adj[maxn];
int subsz[maxn], centroidParent[maxn];
bool marked[maxn];

ll ans = 0;

int dfsSubsz(int v, int p) {
	if (marked[v]) return 0;
	subsz[v] = 1;
	for (int w : adj[v])
		if (w != p && !marked[w]) subsz[v] += dfsSubsz(w, v);
	return subsz[v];
}

int dfsCentroid(int v, int p, int sz) {
	for (int w : adj[v])
		if (w != p && subsz[w] > sz / 2)
			return dfsCentroid(w, v, sz);
	return v;
}

void dfs(int v, int p, int d, ll preo, ll pree, int sz, int &toinc, ll &incpree, ll &incpreo) {
	toinc++; incpreo += d/2+1; incpree += (d+1)/2;
	if (d & 1) 	ans += (ll) sz * (d/2) + preo;
	else 		ans += (ll) sz * (d/2) + pree;
	ans += (d+1)/2;
	for (int w : adj[v])
		if (w != p && !marked[w])
			dfs(w, v, d+1, preo, pree, sz, toinc, incpree, incpreo);
}

void decompose(int v, int p) {
	dfsSubsz(v, p);
	int centroid = dfsCentroid(v, p, subsz[v]);
	centroidParent[centroid] = p;
	marked[centroid] = true;

	int sum = 0;
	ll preo = 0, pree = 0;
	for (int w : adj[centroid]) {
		if (!marked[w]) {
			int toinc = 0;
			ll incpree = 0, incpreo = 0;
			dfs(w, centroid, 1, preo, pree, sum, toinc, incpree, incpreo);
			pree += incpree, preo += incpreo; sum += toinc;
		}
	}

	for (int w : adj[centroid])
		if (!marked[w]) decompose(w, centroid);
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	get(n);
	f(i, n-1) {
		int x, y; get(x), get(y); x--, y--;
		adj[x].pb(y); adj[y].pb(x);
	}

	fill(marked, false);
	ans = 0;
	decompose(0, -1);

	cout << ans << endl;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

// io
#define get(i) scanf("%d", &i)
#define flush fflush(stdin)

// manipulations
#define f(i, n) for (int i = 0; i < n; i++)
#define fr(i, n) for (int i = n - 1; i >= 0; i--)
#define ff(i, a, b) for (int i = a; i <= b; i++)
#define lowbit(x) (x & -x)
#define sz(x) int((x).size())

// built-in
#define bitcount __builtin_popcount
#define gcd __gcd

// short
#define pb push_back
#define fill(arr, a) memset(arr, a, sizeof(arr))

// useful bits
#define IN(i, l, r) (l <= i && i <= r)
#define relax(a, b) a = max(a, b);

typedef vector<int> VI;
typedef pair<int, int> PII;
typedef long long ll;

ll modpow(ll a, ll b, ll mod = (ll) (1e9 + 7))
{if (!b) return 1; a %= mod; return modpow(a * a % mod, b / 2, mod) * (b & 1 ? a : 1) % mod;}

const int maxn = 2e5;
int n;
VI adj[maxn];
int subsz[maxn], centroidParent[maxn];
bool marked[maxn];

ll ans = 0;

int dfsSubsz(int v, int p) {
	if (marked[v]) return 0;
	subsz[v] = 1;
	for (int w : adj[v])
		if (w != p && !marked[w]) subsz[v] += dfsSubsz(w, v);
	return subsz[v];
}

int dfsCentroid(int v, int p, int sz) {
	for (int w : adj[v])
		if (w != p && !marked[w] && subsz[w] > sz / 2)
			return dfsCentroid(w, v, sz);
	return v;
}

void dfs(int v, int p, int d, ll preo, ll pree, int sz, int &toinc, ll &incpree, ll &incpreo) {
	toinc++; incpreo += d/2+1; incpree += (d+1)/2;
	if (d & 1) 	ans += (ll) sz * (d/2) + preo;
	else 		ans += (ll) sz * (d/2) + pree;
	ans += (d+1)/2;
	for (int w : adj[v])
		if (w != p && !marked[w])
			dfs(w, v, d+1, preo, pree, sz, toinc, incpree, incpreo);
}

void decompose(int v, int p) {
	dfsSubsz(v, p);
	int centroid = dfsCentroid(v, p, subsz[v]);
	centroidParent[centroid] = p;
	marked[centroid] = true;

	int sum = 0;
	ll preo = 0, pree = 0;
	for (int w : adj[centroid]) {
		if (!marked[w]) {
			int toinc = 0;
			ll incpree = 0, incpreo = 0;
			dfs(w, centroid, 1, preo, pree, sum, toinc, incpree, incpreo);
			pree += incpree, preo += incpreo; sum += toinc;
		}
	}

	for (int w : adj[centroid])
		if (!marked[w]) decompose(w, centroid);
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	get(n);
	f(i, n-1) {
		int x, y; get(x), get(y); x--, y--;
		adj[x].pb(y); adj[y].pb(x);
	}

	fill(subsz, 0); fill(marked, false);
	ans = 0;
	decompose(0, -1);

	cout << ans << endl;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

// io
#define get(i) scanf("%d", &i)
#define flush fflush(stdin)

// manipulations
#define f(i, n) for (int i = 0; i < n; i++)
#define fr(i, n) for (int i = n - 1; i >= 0; i--)
#define ff(i, a, b) for (int i = a; i <= b; i++)
#define lowbit(x) (x & -x)
#define sz(x) int((x).size())

// built-in
#define bitcount __builtin_popcount
#define gcd __gcd

// short
#define pb push_back
#define fill(arr, a) memset(arr, a, sizeof(arr))

// useful bits
#define IN(i, l, r) (l <= i && i <= r)
#define relax(a, b) a = max(a, b);

typedef vector<int> VI;
typedef pair<int, int> PII;
typedef long long ll;

ll modpow(ll a, ll b, ll mod = (ll) (1e9 + 7))
{if (!b) return 1; a %= mod; return modpow(a * a % mod, b / 2, mod) * (b & 1 ? a : 1) % mod;}

const int maxn = 2e5;
int n;
VI adj[maxn];
int subsz[maxn], centroidParent[maxn];
bool marked[maxn];

ll ans = 0;

int dfsSubsz(int v, int p) {
	if (marked[v]) return 0;
	subsz[v] = 1;
	for (int w : adj[v])
		if (w != p && !marked[w]) subsz[v] += dfsSubsz(w, v);
	return subsz[v];
}

int dfsCentroid(int v, int p, int sz) {
	for (int w : adj[v])
		if (w != p && subsz[w] > sz / 2)
			return dfsCentroid(w, v, sz);
	return v;
}

ll dfs(int v, int p, int d, ll pre, int sz, int &toinc) {
	toinc++;
	ll record = min((d+1)/2, d/2+1);
	ans += (ll) sz * (d/2) + pre;
	ans += (d+1)/2;
	for (int w : adj[v])
		if (w != p && !marked[w])
			record += dfs(w, v, d+1, pre, sz, toinc);
	return record;
}

void decompose(int v, int p) {
	dfsSubsz(v, p);
	int centroid = dfsCentroid(v, p, subsz[v]);
	centroidParent[centroid] = p;
	marked[centroid] = true;

	int sum = 0;
	ll prev = 0;
	for (int w : adj[centroid])
		if (!marked[w]) {
			int toinc = 0;
			prev += dfs(w, centroid, 1, prev, sum, toinc);
			sum += toinc;
		}

	for (int w : adj[centroid])
		if (!marked[w]) decompose(w, centroid);
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	get(n);
	f(i, n-1) {
		int x, y; get(x), get(y); x--, y--;
		adj[x].pb(y); adj[y].pb(x);
	}

	decompose(0, -1);

	cout << ans << endl;

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 200005;
int sum[maxn], n;
ll dp[maxn];
struct Edge
{
    int v, w;
};
vector<Edge> tree[maxn];
void dfs(int cur, int father)
{
    sum[cur] = 1;
    for(int i = 0; i < tree[cur].size(); i++)
    {
        int son = tree[cur][i].v;
        ll len = tree[cur][i].w;
        if(father == son)
            continue;
        dfs(son, cur);
        sum[cur] += sum[son];
        dp[cur] += dp[son] + (n-sum[son])*sum[son] * len;
    }
}
int main()
{
    int u, v, w, T;
    scanf("%d", &n);

    memset(sum, 0, sizeof(sum));
    memset(dp, 0, sizeof(dp));
    for(int i = 0; i < n - 1; i++)
    {
        scanf("%d%d", &u, &v);
        Edge t1, t2;
        t1.v = v;
        t1.w = 1;
        t2.v = u;
        t2.w = 1;
        tree[u].push_back(t1);
        tree[v].push_back(t2);
    }
    dfs(1, -1);
    printf("%d\n",dp[1] - n + 1);

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 200005;
ll sum[maxn], n;
ll dp[maxn];
struct Edge
{
    int v, w;
};
vector<Edge> tree[maxn];
ll cnt;
void dfs(int cur, int father, int c)
{
    cnt += c;
    sum[cur] = 1;
    for(int i = 0; i < tree[cur].size(); i++)
    {
        int son = tree[cur][i].v;

        if(father == son)
            continue;
        dfs(son, cur, c ^ 1);
        sum[cur] += sum[son];
        dp[cur] += dp[son] + (n-sum[son])*sum[son];
    }
}
int main()
{
    int u, v, w, T;
    scanf("%lld", &n);

    memset(sum, 0, sizeof(sum));
    memset(dp, 0, sizeof(dp));
    for(int i = 0; i < n - 1; i++)
    {
        scanf("%d %d", &u, &v);
        Edge t1, t2;
        t1.v = v;
        t1.w = 1;
        t2.v = u;
        t2.w = 1;
        tree[u].push_back(t1);
        tree[v].push_back(t2);
    }
    cnt = 0;
    dfs(1, -1, 0);
    //cout << cnt << endl;
    dp[1] += cnt * (n - cnt);
    printf("%lld\n",dp[1]/2);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 200005;
int sum[maxn], n;
ll dp[maxn];
struct Edge
{
    int v, w;
};
vector<Edge> tree[maxn];
ll cnt;
void dfs(int cur, int father, int c)
{
    cnt += c;
    sum[cur] = 1;
    for(int i = 0; i < tree[cur].size(); i++)
    {
        int son = tree[cur][i].v;

        if(father == son)
            continue;
        dfs(son, cur, c ^ 1);
        sum[cur] += sum[son];
        dp[cur] += dp[son] + (n-sum[son])*sum[son];
    }
}
int main()
{
    int u, v, w, T;
    scanf("%d", &n);

    memset(sum, 0, sizeof(sum));
    memset(dp, 0, sizeof(dp));
    for(int i = 0; i < n - 1; i++)
    {
        scanf("%d %d", &u, &v);
        Edge t1, t2;
        t1.v = v;
        t1.w = 1;
        t2.v = u;
        t2.w = 1;
        tree[u].push_back(t1);
        tree[v].push_back(t2);
    }
    cnt = 0;
    dfs(1, -1, 0);
    //cout << cnt << endl;
    dp[1] += cnt * (n - cnt);
    printf("%lld\n",dp[1]/2);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 200005;
int sum[maxn], n;
ll dp[maxn];
struct Edge
{
    int v, w;
};
vector<Edge> tree[maxn];
void dfs(int cur, int father)
{
    sum[cur] = 1;
    for(int i = 0; i < tree[cur].size(); i++)
    {
        int son = tree[cur][i].v;

        if(father == son)
            continue;
        dfs(son, cur);
        sum[cur] += sum[son];
        dp[cur] += dp[son] + (n-sum[son])*sum[son];
    }
}
int main()
{
    int u, v, w, T;
    scanf("%d", &n);

    memset(sum, 0, sizeof(sum));
    memset(dp, 0, sizeof(dp));
    for(int i = 0; i < n - 1; i++)
    {
        scanf("%d %d", &u, &v);
        Edge t1, t2;
        t1.v = v;
        t1.w = 1;
        t2.v = u;
        t2.w = 1;
        tree[u].push_back(t1);
        tree[v].push_back(t2);
    }
    dfs(1, -1);
    printf("%lld\n",dp[1] - n + 1);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 200005;
int sum[maxn], n;
ll dp[maxn];
struct Edge
{
    int v, w;
};
vector<Edge> tree[maxn];
ll cnt;
void dfs(int cur, int father, int c)
{
    cnt += c;
    sum[cur] = 1;
    for(int i = 0; i < tree[cur].size(); i++)
    {
        int son = tree[cur][i].v;

        if(father == son)
            continue;
        dfs(son, cur, c ^ 1);
        sum[cur] += sum[son];
        dp[cur] += dp[son] + (n-sum[son])*sum[son];
    }
}
int main()
{
    int u, v, w, T;
    scanf("%d", &n);

    memset(sum, 0, sizeof(sum));
    memset(dp, 0, sizeof(dp));
    for(int i = 0; i < n - 1; i++)
    {
        scanf("%d %d", &u, &v);
        Edge t1, t2;
        t1.v = v;
        t1.w = 1;
        t2.v = u;
        t2.w = 1;
        tree[u].push_back(t1);
        tree[v].push_back(t2);
    }
    cnt = 0;
    dfs(1, -1, 0);
    //cout << cnt << endl;
    dp[1] += 1LL * cnt * (n - cnt);
    printf("%lld\n",dp[1]/2);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 200005;
int sum[maxn], n;
ll dp[maxn];
struct Edge
{
    int v, w;
};
vector<Edge> tree[maxn];
ll cnt;
void dfs(int cur, int father, int c)
{
    cnt += c;
    sum[cur] = 1;
    for(int i = 0; i < tree[cur].size(); i++)
    {
        int son = tree[cur][i].v;

        if(father == son)
            continue;
        dfs(son, cur, c ^ 1);
        sum[cur] += sum[son];
        dp[cur] += dp[son] + (n-sum[son])*sum[son];
    }
}
int main()
{
    int u, v, w, T;
    scanf("%d", &n);

    memset(sum, 0, sizeof(sum));
    memset(dp, 0, sizeof(dp));
    for(int i = 0; i < n - 1; i++)
    {
        scanf("%d %d", &u, &v);
        Edge t1, t2;
        t1.v = v;
        t1.w = 1;
        t2.v = u;
        t2.w = 1;
        tree[u].push_back(t1);
        tree[v].push_back(t2);
    }
    cnt = 0;
    dfs(1, -1, 0);
    //cout << cnt << endl;
    dp[1] += 1ll * cnt * (n - cnt);
    printf("%lld\n",dp[1]/2);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define sc(a) scanf("%d", &a)
#define sc2(a, b) scanf("%d %d", &a, &b)
#define sc3(a, b, c) scanf("%d %d %d", &a, &b, &c)
#define pri(x) printf("%d\n", x)
#define prie(x) printf("%d ", x)
#define mp make_pair
#define pb push_back
#define BUFF ios::sync_with_stdio(false);
#define db(x) cerr << #x << " == " << x << endl;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fll;
const ld pi = acos(-1);
const int MOD = 1e9 + 7;
const int N = 2e5 + 100;
vi g[N];
vector<ll> prof[N];
ll quantos_pares[N], quantos_impares[N], sum_pares[N], sum_impares[N];
ll resp = 0;
//(l1 + l2)*(qnt1*qnt2)
// l1*qnt1*qnt2 + l2*qnt1*qnt2
void merge(int root1, int root2) {
  ll level = 1;
  for (int i = (int)prof[root1].size() - 1; i >= 0; i--) {
    if (level % 2) {
      resp = resp + prof[root1][i] * sum_impares[root2] +
             level * prof[root1][i] * quantos_impares[root2];
      resp = resp + prof[root1][i] * sum_pares[root2] +
             level * prof[root1][i] * quantos_pares[root2] +
             prof[root1][i] * quantos_pares[root2];
    } else {
      resp = resp + prof[root1][i] * sum_impares[root2] +
             level * prof[root1][i] * quantos_impares[root2] +
             prof[root1][i] * quantos_impares[root2];
      resp = resp + prof[root1][i] * sum_pares[root2] +
             level * prof[root1][i] * quantos_pares[root2];
    }
    level++;
  }
  int vai = prof[root2].size() - 1;
  for (int i = (int)prof[root1].size() - 1; i >= 0; i--) {
    prof[root2][vai] += prof[root1][i];
    vai--;
  }
  sum_pares[root2] += sum_pares[root1];
  sum_impares[root2] += sum_impares[root1];
  quantos_pares[root2] += quantos_pares[root1];
  quantos_impares[root2] += quantos_impares[root1];
}
int dfs(int u, int last) {
  int root = u;
  for (int v : g[u]) {
    if (v == last)
      continue;
    int root2 = dfs(v, u);
    prof[root2].pb(1);
    int novo = prof[root2].size();
    swap(quantos_pares[root2], quantos_impares[root2]);
    swap(sum_pares[root2], sum_impares[root2]);
    sum_pares[root2] += quantos_pares[root2];
    sum_impares[root2] += quantos_impares[root2];
    sum_impares[root2]++;
    quantos_impares[root2]++;

    if (prof[root2].size() <= prof[root].size()) {
      merge(root2, root);
    } else {
      merge(root, root2);
      root = root2;
    }
  }
  resp = resp + sum_pares[root] + sum_impares[root] + quantos_impares[root];
  return root;
}
int main() {
  int n;
  cin >> n;
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    g[u].pb(v);
    g[v].pb(u);
  }
  dfs(1, 1);
  cout << resp / 2 << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define sc(a) scanf("%d", &a)
#define sc2(a, b) scanf("%d %d", &a, &b)
#define sc3(a, b, c) scanf("%d %d %d", &a, &b, &c)
#define pri(x) printf("%d\n", x)
#define prie(x) printf("%d ", x)
#define mp make_pair
#define pb push_back
#define BUFF ios::sync_with_stdio(false);
#define db(x) cerr << #x << " == " << x << endl;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fll;
const ld pi = acos(-1);
const int MOD = 1e9 + 7;
const int N = 2e5 + 100;
vi g[N];
vector<ll> prof[N];
ll quantos_pares[N], quantos_impares[N], sum_pares[N], sum_impares[N];
ll resp = 0;
//(l1 + l2)*(qnt1*qnt2)
// l1*qnt1*qnt2 + l2*qnt1*qnt2
void merge(int root1, int root2) {
  ll level = 1;
  for (int i = (int)prof[root1].size() - 1; i >= 0; i--) {
    if (level % 2) {
      resp = resp + prof[root1][i] * sum_impares[root2] +
             level * prof[root1][i] * quantos_impares[root2];
      resp = resp + prof[root1][i] * sum_pares[root2] +
             level * prof[root1][i] * quantos_pares[root2] +
             prof[root1][i] * quantos_pares[root2];
    } else {
      resp = resp + prof[root1][i] * sum_impares[root2] +
             level * prof[root1][i] * quantos_impares[root2] +
             prof[root1][i] * quantos_impares[root2];
      resp = resp + prof[root1][i] * sum_pares[root2] +
             level * prof[root1][i] * quantos_pares[root2];
    }
    level++;
  }
  int vai = prof[root2].size() - 1;
  for (int i = (int)prof[root1].size() - 1; i >= 0; i--) {
    prof[root2][vai] += prof[root1][i];
    vai--;
  }
  sum_pares[root2] += sum_pares[root1];
  sum_impares[root2] += sum_impares[root1];
  quantos_pares[root2] += quantos_pares[root1];
  quantos_impares[root2] += quantos_impares[root1];
}
int dfs(int u, int last) {
  int root = u;
  for (int v : g[u]) {
    if (v == last)
      continue;
    int root2 = dfs(v, u);
    prof[root2].pb(1);
    int novo = prof[root2].size();
    if (novo % 2 == 0) {
      quantos_pares[root2]++, sum_pares[root2] += novo;
    } else {
      quantos_impares[root2]++, sum_impares[root2] += novo;
    }

    if (prof[root2].size() <= prof[root].size()) {
      merge(root2, root);
    } else {
      merge(root, root2);
      root = root2;
    }
  }
  int root1 = root;
  resp = resp + sum_pares[root1] + sum_impares[root1] + quantos_impares[root1];
  return root;
}
int main() {
  int n;
  cin >> n;
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    g[u].pb(v);
    g[v].pb(u);
  }
  dfs(1, 1);
  cout << resp / 2 << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define sc(a) scanf("%d", &a)
#define sc2(a, b) scanf("%d %d", &a, &b)
#define sc3(a, b, c) scanf("%d %d %d", &a, &b, &c)
#define pri(x) printf("%d\n", x)
#define prie(x) printf("%d ", x)
#define mp make_pair
#define pb push_back
#define BUFF ios::sync_with_stdio(false);
#define db(x) cerr << #x << " == " << x << endl;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fll;
const ld pi = acos(-1);
const int MOD = 1e9 + 7;
const int N = 2e5 + 100;
vi g[N];
vector<ll> prof[N];
ll quantos_pares[N], quantos_impares[N], sum_pares[N], sum_impares[N];
ll resp = 0;

void merge(int root1, int root2) {
  ll level = 1;
  for (int i = (int)prof[root1].size() - 1; i >= 0; i--) {
    if (level % 2) {
      resp = resp + quantos_impares[root2] * level + sum_impares[root2];
      resp = resp + quantos_pares[root2] * level + sum_pares[root2] +
             quantos_pares[root2];
    } else {
      resp = resp + quantos_impares[root2] * level + sum_impares[root2] +
             quantos_impares[root2];
      resp = resp + quantos_pares[root2] * level + sum_pares[root2];
    }
    level++;
  }
  int vai = prof[root2].size() - 1;
  for (int i = (int)prof[root1].size() - 1; i >= 0; i--) {
    prof[root2][vai] += prof[root1][i];
    vai--;
  }
  sum_pares[root2] += sum_pares[root1];
  sum_impares[root2] += sum_impares[root1];
  quantos_pares[root2] += quantos_pares[root1];
  quantos_impares[root2] += quantos_impares[root1];
}
int dfs(int u, int last) {
  int root = u;
  for (int v : g[u]) {
    if (v == last)
      continue;
    int root2 = dfs(v, u);
    prof[root2].pb(v);
    int novo = prof[root2].size();
    if (novo % 2 == 0) {
      quantos_pares[root2]++, sum_pares[root2] += novo;
    } else {
      quantos_impares[root2]++, sum_impares[root2] += novo;
    }

    if (prof[root2].size() <= prof[root].size()) {
      merge(root2, root);
    } else {
      merge(root, root2);
      root = root2;
    }
  }
  int root1 = root;
  resp = resp + sum_pares[root1] + sum_impares[root1] + quantos_impares[root1];
  return root;
}
int main() {
  int n;
  cin >> n;
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    g[u].pb(v);
    g[v].pb(u);
  }
  dfs(1, 1);
  cout << resp / 2 << endl;
}