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

namespace AlgoTasks
{
    class Program
    {
        static void Main(string[] args)
        {
            int a = int.Parse(Console.ReadLine());
            int b = int.Parse(Console.ReadLine());
            int diff = Math.Abs(a - b);
            if (diff == 1)
                Console.WriteLine(1);
            else
            {
                int k = ((diff / 2) * 2) / 2;
                int s = (k * (k + 1) / 2) * 2;

                if (diff % 2 == 1)
                    s += k + 1;
                Console.WriteLine(s);
            }
        }
    }
}

using System;
class Program
{
    static int Sum(int a)
    {
        while (a > 1)
            return a + Sum(--a);
        return a;
    }
    static void Main()
    {
        int a = int.Parse(Console.ReadLine());
        int b = int.Parse(Console.ReadLine());
        if ((a - b) % 2 == 0)
            Console.WriteLine(Sum(Math.Abs(a - b) / 2) * 2);
        else Console.WriteLine(Sum(Math.Abs(a - b) / 2) + Sum(Math.Abs(a - b) / 2 + Math.Abs(a - b) % 2));
    }
}

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

namespace _17._03._2018
{
    class Program
    {
        static void Main(string[] args)
        {
            int a = int.Parse(Console.ReadLine());
            int b = int.Parse(Console.ReadLine());
            int sum = f(Math.Abs(b-a)/2)*2;
            if (Math.Abs(b - a) % 2 == 1)
                sum += Math.Abs(b - a) / 2 + 1;
            Console.WriteLine(sum);
        }

        static int f(int j)
        {
            int sum = 0;
            for (int i = 1; i<=j; i++)
                sum += i;
            return sum;
        }
    }
}

using System;

namespace CodeForces
{
    class Program
    {
        static void Main(string[] args)
        {
            //Console.WriteLine("Hello World!");
            FriendsMeeting.FriendsWithBenefits();
        }
    }
    class FriendsMeeting
    {
        public static void FriendsWithBenefits()
        {
            int p1 = int.Parse(Console.ReadLine());
            int p2 = int.Parse(Console.ReadLine());
            int diff = Math.Abs(p2 - p1);
            int prim_sum = diff / 2;
            int aux_sum = diff % 2 == 0 ? 0 : prim_sum + 1;
            Console.WriteLine(prim_sum*(prim_sum+1)+aux_sum);
            //Console.ReadKey();
        }
    }
}

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

namespace ProblemA
{
	public class Problem
	{
		public int a;
		public int b;

		public int[] ReadLine()
		{
			return Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
		}

		public Problem()
		{
			a = ReadLine()[0];
			b = ReadLine()[0];
		}

		public void Solve()
		{
			var answer = 0;
			var dist = Math.Abs(a - b);
			answer = (dist / 2) * (dist / 2 + 1) + (dist % 2 == 1 ? dist / 2 + 1 : 0);
			Console.WriteLine(answer);
		}
	}

	class ProblemA
	{
		static void Main(string[] args)
		{
			new Problem().Solve();
		}
	}
}

using System;
public class task
{
    private static void Main()
    {
        int b = Math.Abs(int.Parse(Console.ReadLine()) - int.Parse(Console.ReadLine()));
        if (b % 2 != 0)
            Console.WriteLine((b + 1) / 2 + (1 + ((b - 1) / 2)) * ((b-1) / 2));
        else
            Console.WriteLine((1 + b/2) * b/2);
    }
}

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 a = int.Parse(Console.ReadLine());
            int b = int.Parse(Console.ReadLine());
            int c = Math.Abs(a - b);
            int d = c / 2;
            int e = c - d;
            int f = (1 + d) * d / 2;
            int g = (1 + e) * e / 2;
            int h = f + g;
            Console.WriteLine(h);
            //Console.ReadKey();
        }
    }
}

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

namespace CodeForces
{
    static class Program
    {
        static void Main()
        {
            const string filePath = @"Data\R468A.txt";
            if (System.IO.File.Exists(filePath))
            {
                Console.SetIn(new System.IO.StreamReader(filePath));
            }

            IProblem counter = new R468A();

            foreach (var result in counter.GetResults())
            {
                Console.WriteLine(result);
            }
        }
    }

    internal class R468A : ProblemBase
    {
        public override IEnumerable<string> GetResults()
        {
            var a = this.ReadInt32();
            var b = this.ReadInt32();
            var delta = Math.Abs(b - a);
            var s1 = delta / 2;
            var s2 = delta / 2;
            if (delta % 2 == 1)
            {
                s2++;
            }

            yield return ((s1+1)*s1/2+ (s2 + 1) * s2 / 2).ToString();
        }
    }

    internal class R468B : ProblemBase
    {
        public override IEnumerable<string> GetResults()
        {
            yield return "n/a";
        }
    }

    internal class R468C : ProblemBase
    {
        public override IEnumerable<string> GetResults()
        {
            yield return "n/a";
        }
    }

    internal class R468D : ProblemBase
    {
        public override IEnumerable<string> GetResults()
        {
            yield return "n/a";
        }
    }

    abstract class MultipleTestsBase : ProblemBase
    {
        public sealed override IEnumerable<string> GetResults()
        {
            var t = Convert.ToInt32(Console.ReadLine());
            for (int testCaseNumber = 0; testCaseNumber < t; testCaseNumber++)
            {
                foreach (var result in GetTestResult(testCaseNumber + 1))
                {
                    yield return result;
                }

            }

        }

        protected abstract IEnumerable<string> GetTestResult(int caseNumber);
    }

    public interface IProblem
    {
        IEnumerable<string> GetResults();
    }

    public abstract class ProblemBase : IProblem
    {
        /// <summary>
        /// Pring array of T
        /// </summary>
        /// <typeparam name="T">Generic paramter.</typeparam>
        /// <param name="items">The items.</param>
        /// <param name="prefixMessage">The message shown first.</param>
        public void PrintArray<T>(IEnumerable<T> items, string prefixMessage)
        {
            Console.WriteLine("{0}: {1}", prefixMessage, string.Join(",", items));
        }

        public void WriteDiagnostics(string message, params object[] objects)
        {
            Console.WriteLine(message, objects);
        }

        public virtual IEnumerable<string> GetResults()
        {
            yield return "No result";
        }

        protected int[] ReadIntArray()
        {
            return Array.ConvertAll(ReadTokens(), Convert.ToInt32);
        }

        protected string[] ReadTokens()
        {
            var readLine = Console.ReadLine();
            if (readLine == null)
            {
                throw new Exception("Value read from Console is null");
            }
            return readLine.Split(' ');
        }

        protected int ReadInt32()
        {
            return Convert.ToInt32(Console.ReadLine());
        }
    }
}

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

namespace a
{
    class Program
    {
        static void Main(string[] args)
        {
            int suba = Convert.ToInt32(Console.ReadLine());
            int subb = Convert.ToInt32(Console.ReadLine());

            int b = (suba>subb)?suba:subb;
            int a = (suba < subb) ? suba : subb;

            int cen = (b +a+1) / 2;
            int usb = (cen - a) * (cen - a + 1) / 2;
            int usa = (b - cen) * (b - cen + 1) / 2;

            Console.WriteLine(usa + usb);
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.ExceptionServices;
using System.Runtime.InteropServices;
using System.Text;

namespace ConsoleApp8
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(Solve());
        }
        static int Solve()
        {
            int a = int.Parse(Console.ReadLine());
            int b = int.Parse(Console.ReadLine());
            int count = 0, currentInc = 1;
            int distance = Math.Abs(a - b);

            if (distance == 1) return 1;

            for (int i = 0; i<distance/2; i++)
            {
                count += currentInc * 2;
                currentInc++;
            }

            if (distance % 2 == 1) count += currentInc;

            return count;
        }

    }
}

using System;

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

            Console.WriteLine(GetMinTiredness(a,b));
        }

        private static int GetMinTiredness(int a, int b)
        {
            int difference;

            if (a < b)
            {
                difference = b - a;
            }
            else
            {
                difference = a -b;
            }

            var half = difference / 2;
            var evenTiredness = 0;

            for (int i = half; i > 0; i--)
            {
                evenTiredness += i;
            }

            var minTiredness = 2 * evenTiredness;

            if (difference % 2 != 0)
            {
                minTiredness += half + 1;
            }

            return minTiredness;
        }
    }
}

using System;
using System.Collections.Generic;

namespace Technocup_A
{
    class Program
    {
        static void Main(string[] args)
        {
            int a = Convert.ToInt32(Console.ReadLine());
            int b = Convert.ToInt32(Console.ReadLine());
            int c = Math.Abs(a - b) / 2;
            if (Math.Abs(a - b) == 1) c = 1;
            else
                 if (Math.Abs(a - b)%2 == 1) c = c * (c + 1) + c + 1;
                    else c = c * (c + 1);
            Console.WriteLine(c);
        }
    }
}

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

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

                  if (a > b)
                  {
                        int x = a;
                        a = b;
                        b = x;
                  }

                  int m = (a + b + 1) / 2;
                  Console.WriteLine(Sum(m - a) + Sum(b - m));
            }
            static int Sum(int n)
            {
                  return (1 + n) * n / 2;
            }

      }
}

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

namespace Contest
{
    class Program
    {
        static void Main(string[] args)
        {
            int a = Convert.ToInt32(Console.ReadLine());
            int b = Convert.ToInt32(Console.ReadLine());
            int t = a;
            a = a > b ? b : a;
            b = b > a ? b : t;
            int[] kq = new int[b-a + 1];
            for(int i = 0; i < kq.Length; i++)
                kq[i] = (a + i) * (a + i) - (a + i) * (a + b) + (a * a + b * b + b - a) / 2;
            Console.WriteLine(kq.Min());
        }
    }
}

// Problem: 931A - Friends Meeting
// Author: Gusztav Szmolik

using System;

class FriendsMeeting
    {
    public static int Main ()
        {
        ushort a = 0;
        ushort b = 0;
        if (!ReadCheckPos (ref a) || !ReadCheckPos (ref b))
            return -1;
        if (a == b)
            return -1;
        ushort tmp = Convert.ToUInt16 (a+b);
        ushort meetPos = Convert.ToUInt16 (tmp/2);
        ushort minStep = Convert.ToUInt16 (meetPos-Math.Min (a,b));
        uint ans = Convert.ToUInt32 (minStep*(minStep+1));
        if (tmp%2 == 1)
            ans += Convert.ToUInt32 (minStep+1);
        Console.WriteLine (ans);
        return 0;
        }

    static bool ReadCheckPos (ref ushort pos)
        {
        string line = Console.ReadLine ();
        if (line == null)
            return false;
        string[] words = line.Split ();
        if (words.Length != 1)
            return false;
        if (!UInt16.TryParse (words[0], out pos))
            return false;
        if (pos < 1 || pos > 1000)
            return false;
        return true;
        }
    }

using System;

namespace codeforces
{

    class Program
    {
        static void Main(string[] args)
        {
            int c1 = int.Parse(Console.ReadLine());
            int c2 = int.Parse(Console.ReadLine());
            int rez = 0, a= Math.Abs(c2-c1);
            if (a<=2)
                rez = a;
            else
            {
                for (int i = 1; i <= a/2; i++)
                {
                    rez += i;
                }
                rez *= 2;
                if (a % 2 != 0)
                    rez += a / 2 + 1;

            }
            Console.WriteLine(rez);
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main()
    {
        var a = int.Parse(ReadLine());
        var b = int.Parse(ReadLine());
        var d = Math.Abs(b - a);
        WriteLine(d % 2 == 0 ? d / 2 * (d / 2 + 1) : (d / 2 ) * (d / 2 + 1) + d / 2 + 1);
    }
}

using System;

namespace CSharp
{
    public class _931A
    {
        public static void Main()
        {
            int a = int.Parse(Console.ReadLine());
            int b = int.Parse(Console.ReadLine());

            int x = (a + b) / 2;

            int da = Math.Abs(a - x);
            int db = Math.Abs(b - x);

            Console.WriteLine(da * (da + 1) / 2 + db * (db + 1) / 2);
        }
    }
}

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

namespace codeforces
{
    class Program
    {
        private static int a, b;
        static void Main(string[] args)
        {
            a = int.Parse(Console.ReadLine());
            b = int.Parse(Console.ReadLine());
            int m = (a + b) / 2;
            int c1 = Math.Abs(m - a);
            int c2 = Math.Abs(m - b);
            Console.WriteLine(c1 * (c1 + 1) / 2 + c2 * (c2 + 1) / 2);
            Console.ReadLine();
        }
    }
}

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

namespace MeetFriend
{
    class Program
    {
        static void Main(string[] args)
        {
            int a = int.Parse(Console.ReadLine());
            int b = int.Parse(Console.ReadLine());
            int at = 0;
            int bt = 0;
            for (int i = 1; a!=b; i++)
            {
                if (a < b)
                {
                    a++;
                    at += i;

                    if (a == b)
                    {
                        break;
                    }
                    b--;
                    bt += i;
                    if (a == b)
                    {
                        break;
                    }
                }
                if (a > b)
                {
                    a--;
                    at += i;

                    if (a == b)
                    {
                        break;
                    }
                    b++;
                    bt += i;
                    if (a == b)
                    {
                        break;
                    }
                }

            }
            Console.WriteLine(at+bt);

        }
    }
}

using System;
using System.Linq;
using static System.Console;
class Solution
{
    static void Main(string[] args)
    {
        int a = Convert.ToInt32(ReadLine());
        int b = Convert.ToInt32(ReadLine());
        int sum = 0;
        int dif = Math.Abs(a - b);
        sum +=  (dif / 2 * (dif / 2 + 1));
        if(dif%2==1)
        {
            sum += dif / 2 + 1;
        }
        WriteLine(sum);

    }
}

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 m=int.Parse(Console.ReadLine());
          int sred=(n+m)/2;
          int sum=0;
          int o=0;
          for(int i=Math.Min(n,m);i<sred;i++)
          {
               o++;

               sum+=o;
          }
          o=0;
          for(int i=Math.Max(m,n);i>sred;i--)
          {
               o++;
               sum+=o;
          }
          Console.WriteLine(sum);

        }
    }
}

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

namespace Olimp
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b, a1 = 0, b1 = 0;
            int x1 = int.Parse(Console.ReadLine());
            int x2 = int.Parse(Console.ReadLine());
            if (x1 >= x2)
            {
                a = (x1 - x2) / 2;
                b = (x1 - x2) - a;
                for(int i = 0; i!= a+1; i++)
                {
                    a1 += i;
                }
                for (int i = 0; i != b+1; i++)
                {
                    b1 += i;
                }
            }
            else
            {
                a = (x2 - x1) / 2;
                b = (x2 - x1) - a;
                for (int i = 0; i != a+1; i++)
                {
                    a1 += i;
                }
                for (int i = 0; i != b+1; i++)
                {
                    b1 += i;
                }
            }
            Console.WriteLine(a1+b1);
        }
    }
}

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

namespace ConsoleApplication1
{
    class Program
    {
        static long nsum (int x)
        {
            return (long)x * (x + 1) / 2;
        }
        static void Main(string[] args)
        {
            int a = int.Parse(Console.ReadLine()), b = int.Parse(Console.ReadLine());
            int dist = Math.Abs(b - a);
            Console.WriteLine(nsum((dist + 1) / 2) + nsum(dist / 2));
        }
    }
}

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

namespace Introduction
{

    class Program
    {
        static Reader reader = new Reader();
        static void Main(string[] args)
        {
            int number1 = reader.NextInt();
            int number2 = reader.NextInt();
            int count = 0;
            int i, j;
            for (i = 1; i <= Math.Truncate((double)Math.Abs((double)(number1 - number2) / 2)); i++)
                count += i;
            for (j = 1; j <= Math.Ceiling((double)Math.Abs((double)(number1 - number2) / 2)); j++)
                count += j;
            Console.Write(count);
        }
    }

    #region Reader Class
    internal class Reader
    {
        int s_index = 0;
        List<string> s_tokens;

        public string Next()
        {
            while (s_tokens == null || s_index == s_tokens.Count)
            {
                s_tokens = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList();
                s_index = 0;
            }
            return s_tokens[s_index++];
        }

        public int NextInt()
        {
            String s = Next();

            return int.Parse(s);
        }

        public long NextLong()
        {
            String s = Next();

            return long.Parse(s);
        }

        public bool HasNext()
        {
            while (s_tokens == null || s_index == s_tokens.Count)
            {
                s_tokens = null;
                s_index = 0;
                var nextLine = Console.ReadLine();
                if (nextLine != null)
                {
                    s_tokens = nextLine.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList();
                    if (s_tokens.Count == 0)
                    {
                        continue;
                    }
                }
                return false;
            }
            return false;
        }
    }
    #endregion
}

using System;
using System.IO;
using System.Text;

namespace Friends_Meeting
{
    internal class Program
    {
        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);

        private static void Main(string[] args)
        {
            writer.WriteLine(Solve(args));
            writer.Flush();
        }

        private static int Solve(string[] args)
        {
            int a = Next();
            int b = Next();

            if (a > b)
            {
                int c = a;
                a = b;
                b = c;
            }

            int ans = 0;

            for (int i = 1; a < b; i++)
            {
                if (a < b)
                {
                    a++;
                    ans += i;
                }
                if (a < b)
                {
                    b--;
                    ans += i;
                }
            }

            return ans;
        }

        private static int Next()
        {
            int c;
            int res = 0;
            do
            {
                c = reader.Read();
                if (c == -1)
                    return res;
            } while (c < '0' || c > '9');
            res = c - '0';
            while (true)
            {
                c = reader.Read();
                if (c < '0' || c > '9')
                    return res;
                res *= 10;
                res += c - '0';
            }
        }
    }
}

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

namespace Codeforces
{
   class A
   {
     static void Main(string[] args)
     {
        int a = int.Parse(Console.ReadLine());
        int b = int.Parse(Console.ReadLine());

        int diff = Math.Abs(a-b);

        int ans = 0;

        if(diff%2==0){
           int h = diff/2;
           ans = h*(1+h)/2;
           ans = ans * 2;
        }else{
          int h1 = (diff+1)/2;
          int h2 = (diff-1)/2;

          int a1 = h1*(1+h1)/2;
          int a2 = h2*(1+h2)/2;

          ans = a2 + a1;
        }

        Console.WriteLine(ans);
     }

   }
}

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 a = int.Parse(Console.ReadLine());
           int b = int.Parse(Console.ReadLine());

           int D = Math.Abs(a-b);

           int ans = 0;int cnt = 1;
           for(int i=0;i<D;i++){
             if(i>0 && i%2==0)cnt++;
             ans += cnt;
           }
           Console.WriteLine(ans);
        }

    }
}

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

class Program
{

    static void Main(string[] args)
    {
        //var s = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

        //var a = s[0];
        //var b = s[1];

        var a = int.Parse(Console.ReadLine());
        var b = int.Parse(Console.ReadLine());

        int c = Math.Min(a, b);
        b = Math.Max(a, b);
        a = c;

        int mid = (a + b) / 2;

        int bS = b - mid;
        int aS = mid - a;

        int bE = (bS * (bS + 1)) / 2;
        int aE = (aS * (aS + 1)) / 2;

        Console.WriteLine(bE + aE);
    }
}

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

namespace CodeforcesTemplateClean
{

    class Program
    {

        static void Main(string[] args)
        {

            int a = int.Parse(Console.ReadLine());

            int b = int.Parse(Console.ReadLine());

            int way = a > b ? a- b : b - a;

            int mySteps = 0;

            int friendSteps = 0;

            int res = 0;

            for (int i = 0; i < way; i++)
            {
                if (i % 2 == 0)
                {
                    mySteps++;

                    res += mySteps;
                }

                else
                {
                    friendSteps++;

                    res += friendSteps;
                }
            }

            Console.WriteLine(res);

            //Console.ReadKey();

        }

    }

}

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

namespace Contest
{
    class Scanner
    {
        private string[] line = new string[0];
        private int index = 0;
        public string Next()
        {
            if (line.Length <= index)
            {
                line = Console.ReadLine().Split(' ');
                index = 0;
            }
            var res = line[index];
            index++;
            return res;
        }
        public int NextInt()
        {
            return int.Parse(Next());
        }
        public long NextLong()
        {
            return long.Parse(Next());
        }
        public string[] Array()
        {
            line = Console.ReadLine().Split(' ');
            index = line.Length;
            return line;
        }
        public int[] IntArray()
        {
            return Array().Select(int.Parse).ToArray();
        }
        public long[] LongArray()
        {
            return Array().Select(long.Parse).ToArray();
        }
    }

    class Program
    {
        private int A, B;
        private void Scan()
        {
            var sc = new Scanner();
            A = sc.NextInt();
            B = sc.NextInt();
        }

        private int AA(int n)
        {
            return n * (n + 1) / 2;
        }

        public void Solve()
        {
            Scan();
            var dist = Math.Abs(A - B);
            Console.WriteLine(AA(dist / 2) + AA((dist + 1) / 2));
        }

        static void Main(string[] args)
        {
            new Program().Solve();
        }
    }
}

/* Date: 04.03.2018 * Time: 22:45 */
// *

/*
�	fflush(stdout) � ����� C++;
�	System.out.flush() � Java;
�	stdout.flush() � Python;
�	flush(output) � Pascal;

*/

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

class Example
{
	public static void Main (string[] args)
	{
# if ( ! ONLINE_JUDGE )
		StreamReader sr = new StreamReader ("C:\\TRR\\2018\\Task\\07 Codeforces\\029\\A.TXT");
		StreamWriter sw = new StreamWriter ("C:\\TRR\\2018\\Task\\07 Codeforces\\029\\A.OUT");
# endif

		NumberFormatInfo nfi = NumberFormatInfo.InvariantInfo;

		string ss;
		int a, b;

# if ( ONLINE_JUDGE )
		a = int.Parse (Console.ReadLine ());
		b = int.Parse (Console.ReadLine ());
# else
		a = int.Parse (sr.ReadLine ());
		b = int.Parse (sr.ReadLine ());
		sw.WriteLine ("a = " + a + "   b = " + b);
# endif

		if (a > b )
		{
			int c = a; a = b; b = c;
		}

		int n = (b - a)/2;
		int k = n*(n+1);
		if ( (b - a)%2 == 1 )
			k += n + 1;

# if ( ONLINE_JUDGE )
		Console.WriteLine (k);
# else
		sw.WriteLine (k);
		sw.Close ();
# endif

	}
}

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

class Solution
    {
        static void Main(string[] args)
        {
            new FriendsMeeting().Solve();
        }
    }

    public abstract class ISolution
    {
        public static Func<int> ReadInt = () => int.Parse(Console.ReadLine().Trim());
        public static Func<short> ReadShort = () => short.Parse(Console.ReadLine().Trim());
        public static Func<string> ReadString = () => Console.ReadLine().Trim();
        public static Func<byte> ReadByte = () => byte.Parse(Console.ReadLine().Trim());
        public static StringBuilder output = new StringBuilder();
        public static Func<string[]> ReadArrString = () => ReadString().Split(' ').ToArray();
        public abstract void Solve();
    }

public class FriendsMeeting : ISolution
    {
        public override void Solve()
        {
            var a1 = ReadInt();
            var b1 = ReadInt();
            var a = Math.Min(a1, b1);
            var b = Math.Max(a1, b1);
            var dist = Math.Abs(b - a);
            Console.WriteLine(Math.Min(distance(dist), distance((b - (int)Math.Floor((double)(a + b) / 2))) + distance(((int)Math.Floor((double)(a + b) / 2) - a))));
        }

        public int distance(int k)
        {
            return (k * (k + 1)) / 2;
        }
    }

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

namespace G4
{
    class Program
    {
        static int[] Soliders;
        static int N, K;

        static void Main(string[] args)
        {
            int[] Steps = new int[10];
            Steps[0] = 1;
            for (int i = 1; i < 10; i++)
            {
                Steps[i] = Steps[i - 1] * 10;
            }

            //string sin = Console.ReadLine();
            int a = int.Parse(Console.ReadLine());
            int b = int.Parse(Console.ReadLine());
            int max = Math.Max(a, b);
            int min = Math.Min(a, b);
            a = min;
            b = max;
            int y = 0;
            int h1 = (b-a) / 2;
            int h2 = (b-a+1) / 2;
            y += (((h1 * (h1 + 1)) / 2) + ((h2 * (h2 + 1)) / 2));
            Console.Write(y);
        }
    }
}

using System;

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

            int d = Math.Abs(a - b);

            int temp = 0;
            for (int i = 1; i <= d / 2; i++)
                temp += i;

            temp *= 2;

            if (d % 2 == 1)
                temp += d / 2 + d % 2;

            Console.WriteLine(temp);
        }
    }
}

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

namespace A.Friends_Meeting
{
    class Program
    {
        static void Main(string[] args)
        {
            int a = int.Parse(Console.ReadLine());
            int b = int.Parse(Console.ReadLine());
            int total = 0;
            int s = (Math.Abs(a - b)) / 2;
            for (int i = 1; i <= s; i++)
            {
                total += i;
            }
            if (Math.Abs(a - b) % 2 == 0){
                total*=2;
            }
            else
            {
                for (int i = 1; i <= Math.Abs(a - b)-s; i++)
                {
                    total += i;
                }
            }
            Console.WriteLine(total);
        }
    }
}

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

namespace CF
{
    public static class FromConsole
    {
        public static T To<T>(this string input) where T : IConvertible
        {
            return (T)Convert.ChangeType(input, typeof(T));
        }

        public static T[] ToArrayOf<T>(this string input, char? delimiter = null) where T : IConvertible
        {
            IEnumerable<string> sequence = delimiter == null ? input.Select(x => x.ToString()) : input.Split(delimiter.Value);

            return sequence.Select(x => x.ToString().To<T>()).ToArray();
        }

        public static T[] ToArrayOf<T>(int count) where T : IConvertible
        {
            T[] output = new T[count];

            for (int i = 0; i < count; i++)
            {
                output[i] = Console.ReadLine().To<T>();
            }

            return output;
        }

        public static T[] ToArrayOf<T>(T value, int count)
        {
            return Enumerable.Repeat(value, count).ToArray();
        }

        public static T[][] ToMatrixOf<T>(int n, char? delimiter = null) where T : IConvertible
        {
            T[][] output = new T[n][];

            for (int i = 0; i < n; i++)
            {
                output[i] = Console.ReadLine().ToArrayOf<T>(delimiter);
            }

            return output;
        }

        public static T[][] ToMatrixOf<T>(T value, int n, int m)
        {
            T[][] output = new T[n][];

            for (int i = 0; i < n; i++)
            {
                output[i] = ToArrayOf(value, m);
            }

            return output;
        }

        public static Tuple<int, int> IndexOf<T>(this T[][] input, params T[] targets)
        {
            for (int i = 0; i < input.Length; i++)
            {
                for (int j = 0; j < input[0].Length; j++)
                {
                    if (targets.Any(x => x.Equals(input[i][j])))
                    {
                        return new Tuple<int, int>(i, j);
                    }
                }
            }

            return new Tuple<int, int>(-1, -1);
        }

        public static void AddToList<T, U>(this Dictionary<T, List<U>> input, T k, U v)
        {
            if (input.ContainsKey(k))
            {
                input[k].Add(v);
            }
            else
            {
                input.Add(k, new List<U>() { v });
            }
        }

        public static void AddAndIncrement<T>(this Dictionary<T, int> input, T k)
        {
            if (input.ContainsKey(k))
            {
                input[k]++;
            }
            else
            {
                input.Add(k, 1);
            }
        }

        public static string ToBinary(this long input)
        {
            return Convert.ToString(input, 2);
        }

        public static long ToDecimal(this string input)
        {
            return Convert.ToInt32(input, 2);
        }

        public static long Binomial(long n, long k)
        {
            long r = 1;
            long d;
            if (k > n) return 0;
            for (d = 1; d <= k; d++)
            {
                r *= n--;
                r /= d;
            }
            return r;
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            int x = Console.ReadLine().To<int>();
            int y = Console.ReadLine().To<int>();
            int l = Math.Min(x, y);
            int r = Math.Max(x, y);

            int mid = (int)Math.Floor((l + r) / 2d);
            int leftSteps = mid - l;
            int rightSteps = r - mid;

            int leftScore = 0;
            for (int i = 1; i <= leftSteps; i++)
            {
                leftScore += i;
            }
            int rightScore = 0;
            for (int i = 1; i <= rightSteps; i++)
            {
                rightScore += i;
            }

            Console.WriteLine(leftScore + rightScore);
            //Console.ReadKey();
        }
    }
}

using System;

public class Program
{
	public static void Main()
	{
		int x = Convert.ToInt32(Console.ReadLine());
		int y = Convert.ToInt32(Console.ReadLine());
		int xt = 0, xi = 1;
		int yt = 0, yi = 1;
		int d;
		int f = 0;
		if(x > y) d = x - y;
		else d = y - x;
		for(; d > 0; d--){
			if(f == 0){
				f = 1;
				xt += xi;
				xi++;
			} else {
				f = 0;
				yt += yi;
				yi++;
			}
		}
		Console.Write(xt + yt);
	}
}

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

namespace CodeforcesTemplate
{
    public static class Permutation
    {
        private static bool Next(ref int[] arr)
        {
            int k, j, l;
            for (j = arr.Length - 2; (j >= 0) && (arr[j] >= arr[j + 1]); j--) { }
            if (j == -1)
            {
                arr = arr.OrderBy(c => c).ToArray();
                return false;
            }
            for (l = arr.Length - 1; (arr[j] >= arr[l]) && (l >= 0); l--) { }
            var tmp = arr[j];
            arr[j] = arr[l];
            arr[l] = tmp;
            for (k = j + 1, l = arr.Length - 1; k < l; k++, l--)
            {
                tmp = arr[k];
                arr[k] = arr[l];
                arr[l] = tmp;
            }
            return true;
        }
        public static IEnumerable<int[]> AllPermutations(int[] arr)
        {
            do yield return arr;
            while (Next(ref arr));
        }
    }

    class Program
    {
        private const string FILENAME = "distance4";

        private const string INPUT = FILENAME + ".in";

        private const string OUTPUT = FILENAME + ".out";

        private static Stopwatch _stopwatch = new Stopwatch();

        private static StreamReader _reader = null;
        private static StreamWriter _writer = null;

        private static string[] _curLine;
        private static int _curTokenIdx;

        private static char[] _whiteSpaces = new char[] { ' ', '\t', '\r', '\n' };

        public static string Check(string s)
        {
            string letters = "aeiouy";

            while (true)
            {
                bool used = false;

                for (int i = 0; i < s.Length - 1; i++)
                {
                    if (letters.Contains(s[i].ToString()) && letters.Contains(s[i + 1].ToString()))
                    {
                        s = s.Remove(i + 1, 1);

                        used = true;
                    }
                }

                if (!used)
                {
                    return s;
                }
            }
        }

        private static string ReadNextToken()
        {
            if (_curTokenIdx >= _curLine.Length)
            {
                //Read next line
                string line = _reader.ReadLine();
                if (line != null)
                    _curLine = line.Split(_whiteSpaces, StringSplitOptions.RemoveEmptyEntries);
                else
                    _curLine = new string[] { };
                _curTokenIdx = 0;
            }

            if (_curTokenIdx >= _curLine.Length)
                return null;

            return _curLine[_curTokenIdx++];
        }

        private static int ReadNextInt()
        {
            return int.Parse(ReadNextToken());
        }

        private static void RunTimer()
        {
#if (DEBUG)

            _stopwatch.Start();

#endif
        }

        private static void Main(string[] args)
        {

#if (DEBUG)
            double before = GC.GetTotalMemory(false);
#endif

            int a = int.Parse(Console.ReadLine());

            int b = int.Parse(Console.ReadLine());

            int way = a > b ? a - b : b - a;

            int mySteps = 0;

            int friendSteps = 0;

            int res = 0;

            for (int i = 0; i < way; i++)
            {
                if (i % 2 == 0)
                {
                    mySteps++;

                    res += mySteps;
                }

                else
                {
                    friendSteps++;

                    res += friendSteps;
                }
            }

            Console.WriteLine(res);

#if (DEBUG)
            _stopwatch.Stop();

            double after = GC.GetTotalMemory(false);

            double consumedInMegabytes = (after - before) / (1024 * 1024);

            Console.WriteLine($"Time elapsed: {_stopwatch.Elapsed}");

            Console.WriteLine($"Consumed memory (MB): {consumedInMegabytes}");

            Console.ReadKey();
#endif

        }

        private static int CountLeadZeros(string source)
        {
            int countZero = 0;

            for (int i = source.Length - 1; i >= 0; i--)
            {
                if (source[i] == '0')
                {
                    countZero++;
                }

                else
                {
                    break;
                }

            }

            return countZero;
        }

        private static string ReverseString(string source)
        {
            char[] reverseArray = source.ToCharArray();

            Array.Reverse(reverseArray);

            string reversedString = new string(reverseArray);

            return reversedString;
        }

        private static int[] CopyOfRange(int[] src, int start, int end)
        {
            int len = end - start;
            int[] dest = new int[len];
            Array.Copy(src, start, dest, 0, len);
            return dest;
        }

        private static string StreamReader()
        {

            if (_reader == null)
                _reader = new StreamReader(INPUT);
            string response = _reader.ReadLine();
            if (_reader.EndOfStream)
                _reader.Close();
            return response;

        }

        private static void StreamWriter(string text)
        {

            if (_writer == null)
                _writer = new StreamWriter(OUTPUT);
            _writer.WriteLine(text);

        }

        private static int BFS(int start, int end, int[,] arr)
        {
            Queue<KeyValuePair<int, int>> queue = new Queue<KeyValuePair<int, int>>();
            List<bool> visited = new List<bool>();
            for (int i = 0; i < arr.GetLength(0); i++)
            {
                visited.Add(false);
            }

            queue.Enqueue(new KeyValuePair<int, int>(start, 0));
            KeyValuePair<int, int> node;
            int level = 0;
            bool flag = false;

            while (queue.Count != 0)
            {
                node = queue.Dequeue();
                if (node.Key == end)
                {
                    return node.Value;
                }
                flag = false;
                for (int i = 0; i < arr.GetLength(0); i++)
                {

                    if (arr[node.Key, i] == 1)
                    {
                        if (visited[i] == false)
                        {
                            if (!flag)
                            {
                                level = node.Value + 1;
                                flag = true;
                            }
                            queue.Enqueue(new KeyValuePair<int, int>(i, level));
                            visited[i] = true;
                        }
                    }
                }

            }
            return 0;

        }

        private static void Write(string source)
        {
            File.WriteAllText(OUTPUT, source);
        }

        private static string ReadString()
        {
            return File.ReadAllText(INPUT);
        }

        private static void WriteStringArray(string[] source)
        {
            File.WriteAllLines(OUTPUT, source);
        }

        private static string[] ReadStringArray()
        {
            return File.ReadAllLines(INPUT);
        }

        private static int[] GetIntArray()
        {
            return ReadString().Split(' ').Select(int.Parse).ToArray();
        }

        private static double[] GetDoubleArray()
        {
            return ReadString().Split(' ').Select(double.Parse).ToArray();
        }

        private static int[,] ReadINT2XArray(List<string> lines)
        {
            int[,] arr = new int[lines.Count, lines.Count];

            for (int i = 0; i < lines.Count; i++)
            {
                int[] row = lines[i].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();

                for (int j = 0; j < lines.Count; j++)
                {
                    arr[i, j] = row[j];
                }
            }

            return arr;
        }
    }
}

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

namespace Contest
{
    class Program
    {
        static void Main(string[] args)
        {
            int a = Convert.ToInt32(Console.ReadLine());
            int b = Convert.ToInt32(Console.ReadLine());
            int t = a;
            a = a > b ? a : b;
            b = b > a ? t : b;
            int[] kq = new int[b-a + 1];
            for(int i = 0; i < kq.Length; i++)
                kq[i] = (a + i) * (a + i) - (a + i) * (a + b) + (a * a + b * b + b - a) / 2;
            Console.WriteLine(kq.Min());
        }
    }
}

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

namespace CF
{
    public static class FromConsole
    {
        public static T To<T>(this string input) where T : IConvertible
        {
            return (T)Convert.ChangeType(input, typeof(T));
        }

        public static T[] ToArrayOf<T>(this string input, char? delimiter = null) where T : IConvertible
        {
            IEnumerable<string> sequence = delimiter == null ? input.Select(x => x.ToString()) : input.Split(delimiter.Value);

            return sequence.Select(x => x.ToString().To<T>()).ToArray();
        }

        public static T[] ToArrayOf<T>(int count) where T : IConvertible
        {
            T[] output = new T[count];

            for (int i = 0; i < count; i++)
            {
                output[i] = Console.ReadLine().To<T>();
            }

            return output;
        }

        public static T[] ToArrayOf<T>(T value, int count)
        {
            return Enumerable.Repeat(value, count).ToArray();
        }

        public static T[][] ToMatrixOf<T>(int n, char? delimiter = null) where T : IConvertible
        {
            T[][] output = new T[n][];

            for (int i = 0; i < n; i++)
            {
                output[i] = Console.ReadLine().ToArrayOf<T>(delimiter);
            }

            return output;
        }

        public static T[][] ToMatrixOf<T>(T value, int n, int m)
        {
            T[][] output = new T[n][];

            for (int i = 0; i < n; i++)
            {
                output[i] = ToArrayOf(value, m);
            }

            return output;
        }

        public static Tuple<int, int> IndexOf<T>(this T[][] input, params T[] targets)
        {
            for (int i = 0; i < input.Length; i++)
            {
                for (int j = 0; j < input[0].Length; j++)
                {
                    if (targets.Any(x => x.Equals(input[i][j])))
                    {
                        return new Tuple<int, int>(i, j);
                    }
                }
            }

            return new Tuple<int, int>(-1, -1);
        }

        public static void AddToList<T, U>(this Dictionary<T, List<U>> input, T k, U v)
        {
            if (input.ContainsKey(k))
            {
                input[k].Add(v);
            }
            else
            {
                input.Add(k, new List<U>() { v });
            }
        }

        public static void AddAndIncrement<T>(this Dictionary<T, int> input, T k)
        {
            if (input.ContainsKey(k))
            {
                input[k]++;
            }
            else
            {
                input.Add(k, 1);
            }
        }

        public static string ToBinary(this long input)
        {
            return Convert.ToString(input, 2);
        }

        public static long ToDecimal(this string input)
        {
            return Convert.ToInt32(input, 2);
        }

        public static long Binomial(long n, long k)
        {
            long r = 1;
            long d;
            if (k > n) return 0;
            for (d = 1; d <= k; d++)
            {
                r *= n--;
                r /= d;
            }
            return r;
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            int l = Console.ReadLine().To<int>();
            int r = Console.ReadLine().To<int>();

            int mid = (int)Math.Floor((l + r) / 2d);
            int leftSteps = mid - l;
            int rightSteps = r - mid;

            int leftScore = 0;
            for (int i = 1; i <= leftSteps; i++)
            {
                leftScore += i;
            }
            int rightScore = 0;
            for (int i = 1; i <= rightSteps; i++)
            {
                rightScore += i;
            }

            Console.WriteLine(leftScore + rightScore);
            //Console.ReadKey();
        }
    }
}

using System;

namespace CS_5890
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
        }
    }
}

using System;
namespace codeforces
{

    class Program
    {
        static void Main(string[] args)
        {
            int c1 = int.Parse(Console.ReadLine());
            int c2 = int.Parse(Console.ReadLine());
            int rez = 0, a= Math.Abs(c2-c1);
            if (a<=2)
                rez = a;
            else
            {
                for (int i = 1; i <= a/2; i++)
                {
                    rez += i;
                }
                rez *= 2;
                if (a % 10 != 0)
                    rez += a / 2 + 1;

            }
            Console.WriteLine(rez);
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main()
    {
        var a = int.Parse(ReadLine());
        var b = int.Parse(ReadLine());
        var d = Math.Abs(b - a);
        WriteLine(d / 2 % 2 != 0 ? d / 2 * (d / 2 + 1) : (d / 2 ) * (d / 2 + 1) + d / 2 + 1);
    }
}

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

namespace Codeforces
{
   class A
   {
     static void Main(string[] args)
     {
        int a = int.Parse(Console.ReadLine());
        int b = int.Parse(Console.ReadLine());

        int diff = Math.Abs(a-b);

        int ans = 0;

        if(diff%2==0){
           int h = diff/2;
           ans = h*(1+h)/2;
           ans = ans * 2;
        }else{
          int h1 = (diff+1)/2;
          int h2 = (diff-1)/2;

          int a1 = h1*(1+h1)/2;
          int a2 = h2*(1+2)/2;

          ans = a2 + a1;
        }

        Console.WriteLine(ans);
     }

   }
}


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

namespace CodeForces174DIV2A
{
    class CowsAndPrimitiveRoots
    {
        static void Main(string[] args)
        {
            int p = int.Parse(Console.ReadLine());
            int counter = 0; bool isgood = true; int cur = 1;
            for (int x = 1; x < p; x++)
            {
                for (int i = 1; i <= p - 2; i++)
                {
                    cur = cur * x;
                    if ((cur %= p) == 1) { isgood = false; break; }
                }
                if (isgood && ((cur*x) % p == 1)) counter++;
                isgood = true; cur = 1;
            }
            Console.WriteLine(counter);
            Console.Read();
        }
    }
}

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

namespace CP_CS
{

    class Task
    {

        static void Solve()
        {
            int n = ReadInt();
            Write(phi(phi(n)));
        }

        public static int phi(int n)
        {
            int result = n;
            for (int i = 2; i * i <= n; ++i)
                if (n % i == 0)
                {
                    while (n % i == 0)
                        n /= i;
                    result -= result / i;
                }
            if (n > 1)
                result -= result / n;
            return result;
        }

        public static bool IsPrime(int number)
        {
            if (number < 2) return false;
            if (number % 2 == 0) return (number == 2);
            int root = (int)Math.Sqrt((double)number);
            for (int i = 3; i <= root; i += 2)
            {
                if (number % i == 0) return false;
            }
            return true;
        }

        public static double Rast(int[] xy1, int[] xy2)
        {
            return Math.Sqrt(Math.Pow(xy1[0] - xy2[0], 2) + Math.Pow(xy1[1] - xy2[1], 2));
        }

        static string[] Split(string str, int chunkSize)
        {
            return Enumerable.Range(0, str.Length / chunkSize)
                .Select(i => str.Substring(i * chunkSize, chunkSize)).ToArray();
        }

        #region -- Main --

        private static TextReader reader;
        private static TextWriter writer;

        static void Main()
        {
#if DEBUG
            //reader = new StreamReader("..\\..\\input.txt");
            reader = new StreamReader(Console.OpenStandardInput());
            writer = Console.Out;
            //writer = new StreamWriter("..\\..\\output.txt");
#else
        reader = new StreamReader(Console.OpenStandardInput());
        writer = new StreamWriter(Console.OpenStandardOutput());
        //reader = new StreamReader("pluses.in");
        //writer = new StreamWriter("pluses.out");
#endif
            try
            {
                //var thread = new Thread(new Solver().Solve, 1024 * 1024 * 128);
                //thread.Start();
                //thread.Join();
                Solve();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
#if DEBUG
#else
            throw;
#endif
            }
            reader.Close();
            writer.Close();
        }

        #endregion
        #region -- Read / Write --

        private static Queue<string> currentLineTokens = new Queue<string>();

        private static string[] ReadAndSplitLine()
        {
            return reader.ReadLine().Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
        }

        private static string[] ReadAndSplitLine(char divisor)
        {
            return reader.ReadLine().Split(new[] { divisor }, StringSplitOptions.RemoveEmptyEntries);
        }

        public static string ReadToken()
        {
            while (currentLineTokens.Count == 0) currentLineTokens = new Queue<string>(ReadAndSplitLine());
            return currentLineTokens.Dequeue();
        }

        public static int ReadInt()
        {
            return int.Parse(ReadToken());
        }

        public static long ReadLong()
        {
            return long.Parse(ReadToken());
        }

        //public static BigInteger ReadBigInteger()
        //{
        //    return BigInteger.Parse(ReadToken());
        //}

        public static double ReadDouble()
        {
            return double.Parse(ReadToken(), CultureInfo.InvariantCulture);
        }

        public static int[] ReadIntArray()
        {
            return ReadAndSplitLine().Select(int.Parse).ToArray();
        }

        public static bool[] ReadBoolArray()
        {
            return ReadAndSplitLine().ToString().ToCharArray().Select(chr => chr == '1').ToArray();
        }

        public static long[] ReadLongArray()
        {
            return ReadAndSplitLine().Select(long.Parse).ToArray();
        }

        public static double[] ReadDoubleArray()
        {
            return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray();
        }

        public static int[][] ReadIntMatrix(int numberOfRows)
        {
            int[][] matrix = new int[numberOfRows][];
            for (int i = 0; i < numberOfRows; i++) matrix[i] = ReadIntArray();
            return matrix;
        }

        public static bool[][] ReadBoolMatrix(int numberOfRows)
        {
            bool[][] matrix = new bool[numberOfRows][];
            for (int i = 0; i < numberOfRows; i++)
                matrix[i] = ReadBoolArray();
            return matrix;
        }

        public static bool[][] TransposeBoolMatrix(bool[][] array, int numberOfRows)
        {
            bool[][] matrix = array;
            bool[][] ret = new bool[matrix[0].Length][];
            for (int i = 0; i < ret.Length; i++)
            {
                ret[i] = new bool[numberOfRows];
                for (int j = 0; j < numberOfRows; j++) ret[i][j] = matrix[j][i];
            }
            return ret;
        }

        public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)
        {
            int[][] matrix = ReadIntMatrix(numberOfRows);
            int[][] ret = new int[matrix[0].Length][];
            for (int i = 0; i < ret.Length; i++)
            {
                ret[i] = new int[numberOfRows];
                for (int j = 0; j < numberOfRows; j++) ret[i][j] = matrix[j][i];
            }
            return ret;
        }

        public static string[] ReadLines(int quantity)
        {
            string[] lines = new string[quantity];
            for (int i = 0; i < quantity; i++) lines[i] = reader.ReadLine().Trim();
            return lines;
        }

        public static void WriteArray<T>(IEnumerable<T> array)
        {
            writer.WriteLine(string.Join(" ", array));
        }

        public static void Write(params object[] array)
        {
            WriteArray(array);
        }
        public static void WriteLines<T>(IEnumerable<T> array)
        {
            foreach (var a in array) writer.WriteLine(a);
        }
        private class SDictionary<TKey, TValue> : Dictionary<TKey, TValue>
        {
            public new TValue this[TKey key]
            {
                get { return ContainsKey(key) ? base[key] : default(TValue); }
                set { base[key] = value; }
            }
        }
        private static T[] Init<T>(int size) where T : new()
        {
            var ret = new T[size];
            for (int i = 0; i < size; i++) ret[i] = new T();
            return ret;
        }
        #endregion
    }
}

using System;

class P {
  static void Main() {
    var p = int.Parse(Console.ReadLine());
    var n = 0;
    for (var x = 1 ; x < p ; x++) {
      var al = x ;
      var an = 1;
      while (an <= p - 1 && al % p != 1) {
        an++;
        al = (al*x) % p;
      }
      if (an == p - 1) n++;
    }
    Console.WriteLine(n);
  }
}

using System;
using System.IO;
using System.Text;

namespace Cows_and_Primitive_Roots
{
    internal class Program
    {
        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);

        private static void Main(string[] args)
        {
            int p = Next();

            int count = 0;

            for (int i = 1; i < p; i++)
            {
                int k = 1;
                for (int j = 1; j < p; j++)
                {
                    k = (k*i)%p;
                    if (k == 1)
                    {
                        if (j == p - 1)
                        {
                            count++;
                        }
                        break;
                    }
                }
            }

            writer.WriteLine(count);
            writer.Flush();
        }

        private static int Next()
        {
            int c;
            int res = 0;
            do
            {
                c = reader.Read();
                if (c == -1)
                    return res;
            } while (c < '0' || c > '9');
            res = c - '0';
            while (true)
            {
                c = reader.Read();
                if (c < '0' || c > '9')
                    return res;
                res *= 10;
                res += c - '0';
            }
        }
    }
}

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 p = Next();
            int ans = 0;
            for (int i = 1; i < p; i++) {
                int q = 1;
                bool good = true;
                for (int j = 1; j < p - 1 && good; j++) {
                    q = q * i;
                    q %= p;
                    if (q == 1)
                        good = false;
                }
                if (!good)
                    continue;
                q *= i;
                q %= p;
                if (q == 1)
                    ans++;
            }
            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;
class Program
{
    static void Main()
    {
        var p = int.Parse(Console.ReadLine());
        var cur = 0;
        foreach (var x in Enumerable.Range(1, p))
        {
            var a = x;
            var b = 1;
            while (b <= p - 1 && a % p != 1)
            {
                b++;
                a = (a * x) % p;
            }
            if (b == p - 1) cur++;
        }
        Console.WriteLine(cur);
    }
}

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

class Program {
	static void Main() {
		int p = int.Parse(Console.ReadLine());
		int x = 1, c = 0;
		while(x < p){
			int powx = x;
			bool successful = true;
			for(int i = 1; i <= p - 2; i++){
				if(powx % p == 1){
					successful = false;
					break;
				}
				powx %= p;
				powx *= x;
			}
			if(successful){
				if(powx % p == 1)
					c++;
			}
			x++;
		}
		Console.WriteLine(c);
	}
}

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

namespace CodeForces
{
	internal class Template
	{
		private static readonly Scanner cin = new Scanner();

		private static void Main()
		{
			//Console.SetIn(new StreamReader(@"C:\CodeForces\input.txt"));
			new Template().Solve();
		}

		private void Solve()
		{
			var p = cin.NextInt();
			var count = 0;
			for (var i = 1; i < p; i++)
			{
				var x = 1;
				var isOk = true;
				for (var j = 0; j < p - 2; j++)
				{
					x = (x*i)%p;
					if (x % p == 1)
					{
						isOk = false;
					}
				}
				if (isOk)
				{
					x = (x*i)%p;
					if (x % p != 1)
					{
						isOk = false;
					}
				}
				if (isOk)
				{
					count++;
				}
			}
			Console.WriteLine(count);
		}
	}

	internal class Scanner
	{
		private string[] s = new string[0];
		private int i;
		private readonly char[] cs = new[] { ' ' };

		public string Next()
		{
			if (i < s.Length) return s[i++];
			var line = Console.ReadLine() ?? string.Empty;
			s = line.Split(cs, StringSplitOptions.RemoveEmptyEntries);
			i = 1;
			return s.First();
		}

		public double NextDouble()
		{
			return double.Parse(Next());
		}

		public int NextInt()
		{
			return int.Parse(Next());
		}

		public long NextLong()
		{
			return long.Parse(Next());
		}
	}
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Web;
using System.Net;

namespace ConsoleApplication1 {
    class Program {
        static void Main( string[] args ) {
            int p = ReadInt();
            int count = 0;
            if ( p == 2 )
                count = 1;
            else
                for ( int x = 2; x < p; x++ ) {
                    int xp = x;
                    int k;
                    for ( k = 1; k <= p - 2; k++ ) {
                        if ( xp == 1 )
                            break;
                        xp = ( xp * x ) % p;
                    }
                    if ( k == p - 1 && xp == 1 )
                        count++;

                }

            Console.Write( count );
        }

        static int _current = -1;
        static string[] _words = null;
        static int ReadInt() {
            if ( _current == -1 ) {
                _words = Console.ReadLine().Split( new char[] { ' ', '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries );
                _current = 0;
            }

            int value = int.Parse( _words[ _current ] );
            if ( _current == _words.Length - 1 )
                _current = -1;
            else
                _current++;

            return value;
        }
    }
}

using System;
using System.Collections.Generic;

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            long x;
            long p = int.Parse(Console.ReadLine());
            int index = 0, max = 0;
            for (int i = 1; i < p; i++)
            {
                x = i; index = 0;
                if (x % p != 1)
                    index++;
                for (int j = 2; j < p - 1; j++)
                {
                    x = (x * i) % p;
                    if (x != 1)
                    {
                        index++;
                    }
                    else
                    {
                        index = 0;
                        break;
                    }
                }
                if (index == p - 2)
                    if ((x*i % p) == 1)
                        max++;
            }
            Console.WriteLine(max);
        }
    }
}

using System;

namespace Cows_and_Primitive_Roots
{
    class Program
    {
        static void Main(string[] args)
        {
            int p = short.Parse(Console.ReadLine());
            int count = 0;
            for (int n = 1; n < p; ++n)
            {
                bool ok = true;
                int x = 1;
                for (int i = 1; i < p - 1; ++i)
                {
                    x *= n;
                    x %= p;
                    if (x == 1)
                    {
                        ok = false;
                        break;
                    }
                }
                if (ok)
                {
                    x *= n;
                    x %= p;
                    if (x == 1)
                    {
                        count += 1;
                    }
                }
            }
            Console.WriteLine(count);
        }

    }
}

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

namespace olimp
{
    class Program
    {
        private static int[] ReadLineInArray()
        {
            return (from str in Console.ReadLine().Split(' ', '\t') select int.Parse(str)).ToArray();
        }

        private static string StringUpper(string str, params int[] who)
        {
            char[] ch = str.ToCharArray();

            foreach (var i in who)
            {
                if (i < ch.Length)
                    ch[i] = char.ToUpper(ch[i]);
            }

            return new string(ch);
        }

        static int Euler(int n)
        {
            int result = n;
            for (int i = 2; i * i <= n; ++i)
            {
                if (n % i == 0)
                {
                    while (n % i == 0)
                        n /= i;
                    result -= result / i;
                }
            }
            if (n > 1)
                result -= result / n;
            return result;
        }

        private static void Main(string[] args)
        {
            int p = int.Parse(Console.ReadLine());
            int rez = 0;

            for (int i = 0; i < p; i++)
            {

            }

            Console.WriteLine(Euler(Euler(p)));
        }
    }
}

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

namespace Codeforces
{
    class Program
    {
        static void Main()
        {
            long x = long.Parse(Console.ReadLine()) -1;

            int ans = totient((int)x);
            Console.WriteLine(ans);
        }

        static int totient(int n)
        {
            int i, ans = n;

            for (i = 2; i * i <= n; i++)
            {
                if (n % i == 0)
                    ans -= ans / i;

                while (n % i == 0)
                    n /= i;
            }

            if (n != 1)
                ans -= ans / n;
            return ans;
        }
    }
}

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

namespace CodeForces
{
    class R174_Div2_A
    {
        static void Main(string[] args)
        {
            int p = int.Parse(Console.ReadLine());
            int cnt = 0;
            long num;
            for (long x = 1; x < p; x++)
            {
                num = 1;
                bool good = true;
                for (int j = 1; j <= p - 2; j++)
                {
                    num *= x;
                    num = num % p;
                    if (num == 1)
                    {
                        good = false;
                        break;
                    }
                }
                if (good)
                {
                    num *= x;
                    num = num % p;
                    if (num == 1)
                        cnt++;
                }
            }

            Console.WriteLine(cnt);
        }
    }
}

using System;

namespace codeforces
{
    class Program
    {
        static void Main(string[] args)
        {
            int p;
            int cnt = 0;

            p = Convert.ToInt32(Console.ReadLine());

            for (int j = 1; j < p; j++)
            {
                int t = j;
                if (check(p, t)) cnt++;
            }

            Console.WriteLine(cnt);
        }

        static bool check(int p, int k)
        {
            int t = 1;
            for (int i = 1; i <= p - 2; i++)
            {
                t *= k;

                if (t % p == 1)
                    return false;

                t %= p;
            }
            if ((t * k) % p == 1)
                return true;

            return false;
        }
    }
}

using System;

namespace p2
{
    class Program
    {
        public static void Main(string[] args)
        { int p,x=0,a;
            p=Convert.ToInt32(Console.ReadLine());
            for(int i=1; i<p; i++){
               a=1;
               for(int j=1; j<p; j++) {
                  a*=i;
                  a%=p;
                  if (a==1) {
                    if (j==p-1) {
                        x++;
                    }
                    break;
                  }
            }
        }
          Console.WriteLine(x);
          //Console.ReadKey(true);
            }
        }
    }

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

namespace Codeforce
{

    class Program
    {
        static int[] parseInt(string s)
        {
            string[] temp = s.Split(' ');
            int[] res = new int[temp.Length];
            for (int i = 0; i < temp.Length; i++)
            {
                res[i] = Convert.ToInt32(temp[i]);
            }
            return res;
        }

        static int PowMod(int x, int e, int mod)
        {
            int res;

            if (e == 0)
            {
                res = 1;
            }
            else if (e == 1)
            {
                res = x;
            }
            else
            {
                res = PowMod(x, e / 2, mod);
                res = res * res % mod;
                if (e % 2 > 0)
                    res = res * x % mod;
            }

            return res;
        }

        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());

            int cnt = 0;
            for (int x = 1; x < n; x++)
            {
                bool tf = true;
                if (PowMod(x, n - 1, n) != 1)
                    tf = false;
                if (tf)
                {
                    for (int p = 1; p < n - 1; p++)
                    {
                        if (PowMod(x, p, n) == 1)
                        {
                            tf = false;
                            break;
                        }
                    }
                }

                if (tf)
                    ++cnt;
            }

            Console.WriteLine(cnt);
        }
    }
}

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

namespace olimp
{
    class Program
    {
        private static int[] ReadLineInArray()
        {
            return (from str in Console.ReadLine().Split(' ', '\t') select int.Parse(str)).ToArray();
        }

        private static string StringUpper(string str, params int[] who)
        {
            char[] ch = str.ToCharArray();

            foreach (var i in who)
            {
                if (i < ch.Length)
                    ch[i] = char.ToUpper(ch[i]);
            }

            return new string(ch);
        }

        static int Euler(int n)
        {
            int result = n;
            for (int i = 2; i * i <= n; ++i)
            {
                if (n % i == 0)
                {
                    while (n % i == 0)
                        n /= i;
                    result -= result / i;
                }
            }
            if (n > 1)
                result -= result / n;
            return result;
        }

        private static void Main(string[] args)
        {
            int p = int.Parse(Console.ReadLine());
            int rez = 0;

            for (int i = 0; i < p; i++)
            {

            }

            Console.WriteLine(Euler(Euler(p)));
           // Console.ReadLine();
        }
    }
}

#define Online

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

class Program
{
    static void Main(string[] args)
    {
#if FileIO
        StreamReader sr = new StreamReader("input.txt");
        StreamWriter sw = new StreamWriter("output.txt");
        Console.SetIn(sr);
        Console.SetOut(sw);
#endif

        int p = int.Parse(Console.ReadLine());
        int ans = 0;
        if (p == 2)
        {
            Console.WriteLine(1);
            return;
        }
        for (int x = 1; x < p; x++)
        {
            int r = x % p;
            if (r - 1 == 0) continue;
            bool isOkay = true;
            int cur = r;
            for (int i = 2; i <= p - 2; i++)
            {
                cur *= r;
                cur %= p;
                if (cur - 1 == 0)
                {
                    isOkay = false;
                    break;
                }
            }
            if (isOkay)
            {
                cur *= r;
                cur %= p;
                if (cur - 1 == 0)
                    ans++;
            }
        }

        Console.WriteLine(ans);
#if Online
        Console.ReadLine();
#endif

#if FileIO
        sr.Close();
        sw.Close();
#endif
    }

    static string[] ReadArray()
    {
        return Console.ReadLine().Split(' ');
    }
}

static class ArrayUtils
{
    public static int BinarySearch(int[] a, int val)
    {
        int left = 0;
        int right = a.Length - 1;
        int mid;

        while (left < right)
        {
            mid = left + ((right - left) >> 1);
            if (val <= a[mid])
            {
                right = mid;
            }
            else
            {
                left = mid + 1;
            }
        }

        if (a[left] == val)
            return left;
        else
            return -1;
    }
}

using System;

namespace A
{
    class Program
    {
        private static int Euler(int p)
        {
            int result = p;

            for (int i = 2; i * i <= p; i++)
            {
                if (p % i == 0)
                {
                    while (p % i == 0)
                    {
                        p /= i;
                    }
                    result -= result / i;
                }
            }
            if (p > 1)
            {
                result -= result / p;
            }

            return result;
        }

        static void Main(string[] args)
        {
            int p = int.Parse(Console.ReadLine());

            Console.WriteLine(Euler(Euler(p)));
        }
    }
}

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

namespace Codeforces174_A
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            int p = int.Parse(Console.ReadLine());
            Console.WriteLine(Eiler(Eiler(p)));
        }

        private static int Eiler(int n)
        {
            if (n == 1) return 1;
            int upperBound = (int) Math.Sqrt(n) + 1;
            Dictionary<int, int> canonical_rep = new Dictionary<int, int>();
            for (int i = 2; i <= n; i++)
                while (n%i == 0 && n != 1)
                {
                    if (canonical_rep.ContainsKey(i)) canonical_rep[i]++;
                    else
                        canonical_rep.Add(i, 1);
                    n /= i;
                }
            int result = 1;
            foreach (var divisor in canonical_rep)
            {
                result *= (int) Math.Pow(divisor.Key, divisor.Value) - (int) Math.Pow(divisor.Key, divisor.Value - 1);
            }
            return result;
        }
    }
}

using System;

class P {
  static void Main() {
    var p = int.Parse(Console.ReadLine());
    var n = 0;
    for (var x = 1 ; x < p ; x++) {
      var al = x - 1;
      var an = 1;
      while (an <= p - 1 && al % p != 0) {
        an++;
        al = (al*x - x + 1 + p) % p;
      }
      if (an == p - 1) n++;
    }
    Console.WriteLine(n);
  }
}

using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
    private static readonly int[] primesArray = GeneratePrimes(2000).ToArray();
    private static readonly HashSet<int> primes = new HashSet<int>(primesArray);
    public static IEnumerable<int> GeneratePrimes(int max)
    {
        var numbers = Enumerable.Range(2, max - 1).ToDictionary(n => n, n => true);
        for (var i = 2; i <= (max / 2); i++)
        {
            if (!numbers[i])
            {
                continue;
            }

            for (var j = 2 * i; j <= max; j += i)
            {
                numbers[j] = false;
            }
        }

        return numbers.Where(kv => kv.Value).Select(kv => kv.Key);
    }
    static void Main()
    {
        var p = int.Parse(Console.ReadLine());
        Console.WriteLine(primes.Count(d => d < p));
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
    public static IEnumerable<int> GeneratePrimes(int max)
    {
        var numbers = Enumerable.Range(2, max - 1).ToDictionary(n => n, n => true);
        for (var i = 2; i <= (max / 2); i++)
        {
            if (!numbers[i])
            {
                continue;
            }
            for (var j = 2 * i; j <= max; j += i)
            {
                numbers[j] = false;
            }
        }
        return numbers.Where(kv => kv.Value).Select(kv => kv.Key);
    }
    static void Main()
    {
        var p = int.Parse(Console.ReadLine());
        var primes = GeneratePrimes(p + 1).ToArray();
        Console.WriteLine(Array.IndexOf(primes, p));
    }
}

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

class Program {
	static void Main() {
		int p = int.Parse(Console.ReadLine());
		int x = 1, c = 0;
		while(x < p){
			int powx = x;
			bool successful = true;
			for(int i = 1; i <= p - 2; i++){
				if((powx - 1) % p == 0){
					successful = false;
					break;
				}
				powx *= x;
			}
			if(successful){
				if((powx - 1) % p == 0)
					c++;
			}
			x++;
		}
		Console.WriteLine(c);
	}
}

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

namespace CodeForces
{
	internal class Template
	{
		private static readonly Scanner cin = new Scanner();

		private static void Main()
		{
			//Console.SetIn(new StreamReader(@"C:\CodeForces\input.txt"));
			new Template().Solve();
		}

		private void Solve()
		{
			var p = cin.NextInt();
			var primes = new List<int>();
			primes.Add(2);
			primes.Add(3);
			for (var i = 5; i < 4010; i += 2)
			{
				if (!primes.Any(x => i % x == 0))
				{
					primes.Add(i);
				}
			}
			for (var i = 0; i < primes.Count; i++)
			{
				if (primes[i] == p)
				{
					Console.WriteLine(i);
					return;
				}
			}
		}
	}

	internal class Scanner
	{
		private string[] s = new string[0];
		private int i;
		private readonly char[] cs = new[] { ' ' };

		public string Next()
		{
			if (i < s.Length) return s[i++];
			var line = Console.ReadLine() ?? string.Empty;
			s = line.Split(cs, StringSplitOptions.RemoveEmptyEntries);
			i = 1;
			return s.First();
		}

		public double NextDouble()
		{
			return double.Parse(Next());
		}

		public int NextInt()
		{
			return int.Parse(Next());
		}

		public long NextLong()
		{
			return long.Parse(Next());
		}
	}
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Web;
using System.Net;

namespace ConsoleApplication1 {
    class Program {
        static void Main( string[] args ) {
            int p = ReadInt();
            int count = 0;
            for ( int x = 1; x < p; x++ ) {
                long re = 0;
                long xp = 1;
                int k;
                for ( k = 0; k <= p - 3; k++ ) {
                    xp %= p;
                    re += xp;
                    xp *= x;
                    if ( re % p == 0 )
                        break;
                }

                if ( k == p - 2 ) {
                    xp %= p;
                    re += xp;
                    if ( re % p == 0 )
                        count++;
                }

            }

            Console.Write( count );
        }

        static int _current = -1;
        static string[] _words = null;
        static int ReadInt() {
            if ( _current == -1 ) {
                _words = Console.ReadLine().Split( new char[] { ' ', '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries );
                _current = 0;
            }

            int value = int.Parse( _words[ _current ] );
            if ( _current == _words.Length - 1 )
                _current = -1;
            else
                _current++;

            return value;
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Web;
using System.Net;

namespace ConsoleApplication1 {
    class Program {
        static void Main( string[] args ) {
            int p = ReadInt();
            int count = 0;
            if ( p != 2 )
                for ( int x = 1; x < p; x++ ) {
                    long xp = x;
                    for ( int k = 1; k <= p - 1; k++ ) {
                        if ( xp % p == 1 ) {
                            if ( k == p - 1 )
                                count++;
                            else
                                break;
                        }
                        xp = ( xp * x ) % p;
                    }
                }

            Console.Write( count );
        }

        static int _current = -1;
        static string[] _words = null;
        static int ReadInt() {
            if ( _current == -1 ) {
                _words = Console.ReadLine().Split( new char[] { ' ', '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries );
                _current = 0;
            }

            int value = int.Parse( _words[ _current ] );
            if ( _current == _words.Length - 1 )
                _current = -1;
            else
                _current++;

            return value;
        }
    }
}

using System;
using System.Collections.Generic;

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            double x;
            double p = int.Parse(Console.ReadLine());
            int index = 0, max = 0;
            for (int i = 1; i < p; i++)
            {
                x = i; index = 0;
                for (int j = 1; j < p - 1; j++)
                {
                    if (((Math.Pow(x, j) - 1) % p) != 0)
                        index++;
                    else
                    {
                        index = 0;
                        continue;
                    }
                }
                if (index == p - 2)
                    if (((Math.Pow(x, p - 1) - 1) % p) == 0)
                        max++;
            }
            Console.WriteLine(max);
        }
    }
}

using System;
using System.Collections.Generic;

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            double x;
            double p = int.Parse(Console.ReadLine());
            int index = 0, max = 0;
            for (int i = 1; i <= p; i++)
            {
                x = i; index = 0;
                for (int j = 1; j < p - 1; j++)
                {
                    if (((Math.Pow(x, j) - 1) % p) != 0)
                        index++;
                    else
                    {
                        index = 0;
                        continue;
                    }
                }
                if (index == p - 2)
                    if (((Math.Pow(x, p - 1) - 1) % p) == 0)
                        max++;
            }
            Console.WriteLine(max);
        }
    }
}

using System;

namespace Cows_and_Primitive_Roots
{
    class Program
    {
        static void Main(string[] args)
        {
            short n = short.Parse(Console.ReadLine());
            short ans = 0;
            for (int i = 2; i < n; i++)
            {
                if (IsPrime(i))
                    ans++;
            }
            Console.WriteLine(ans);
        }

        public static bool IsPrime(int number)
        {
            if (number <= 1) return false;
            if (number == 2) return true;
            if (number % 2 == 0) return false;

            var boundary = (int)Math.Floor(Math.Sqrt(number));

            for (int i = 3; i <= boundary; i += 2)
                if (number % i == 0)
                    return false;

            return true;
        }
    }
}

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

namespace CodeForces
{
    class R174_Div2_A
    {
        static void Main(string[] args)
        {
            int p = int.Parse(Console.ReadLine());
            int cnt = 0;
            long num;
            //Never x=1
            for (long x = 2; x < p; x++)
            {
                num = 1;
                bool good = true;
                for (int j = 1; j <= p - 2; j++)
                {
                    num *= x;
                    num = num % p;
                    if (num == 1)
                    {
                        good = false;
                        break;
                    }
                }
                if (good)
                {
                    num *= x;
                    num = num % p;
                    if (num == 1)
                        cnt++;
                }
            }

            Console.WriteLine(cnt);
        }
    }
}

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

namespace CodeForces
{
    class R174_Div2_A
    {
        static void Main(string[] args)
        {
            int p = int.Parse(Console.ReadLine());
            int cnt = 0, num;
            for (int x = 1; x < p; x++)
            {
                num = 1;
                bool good = true;
                for (int j = 1; j <= p - 2; j++)
                {
                    num *= x;
                    if ((num - 1) % p == 0)
                    {
                        good = false;
                        break;
                    }
                }
                if (good && ((num * x) - 1) % p == 0)
                    cnt++;
            }

            Console.WriteLine(cnt);
        }
    }
}

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

namespace CodeForces
{
    class R174_Div2_A
    {
        static void Main(string[] args)
        {
            int p = int.Parse(Console.ReadLine());
            int cnt = 0;
            long num;
            //Never x=1
            for (int x = 2; x < p; x++)
            {
                num = 1;
                bool good = true;
                for (int j = 1; j <= p - 2; j++)
                {
                    num *= x;
                    num = num % p;
                    if (num == 1)
                    {
                        good = false;
                        break;
                    }
                }
                if (good)
                {
                    num *= x;
                    num = num % p;
                    if (num == 1)
                        cnt++;
                }
            }

            Console.WriteLine(cnt);
        }
    }
}

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

namespace CodeForces
{
    class R174_Div2_A
    {
        static void Main(string[] args)
        {
            int p = int.Parse(Console.ReadLine());
            int cnt = 0, num;
            if (p > 2)
            {
                for (int x = 1; x < p; x++)
                {
                    num = 1;
                    bool good = true;
                    for (int j = 1; j <= p - 2; j++)
                    {
                        num *= x;
                        if ((num - 1) % p == 0)
                        {
                            good = false;
                            break;
                        }
                    }
                    if (good && ((num * x) - 1) % p == 0)
                        cnt++;
                }
            }

            Console.WriteLine(cnt);
        }
    }
}

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

namespace p2
{
    class Program
    {
        public static void Main(string[] args)
        { double ost,p,x=1;  int s=0;
            p=Convert.ToDouble(Console.ReadLine());
            for (int i = 1; i <p; i++) {
                for (int j = 1; j < p; j++) {
                    x*=i;
                    ost=(x-1)%p;
                    if ((ost==0)&&(j==p-1)) {
                        s++;
                    }
                    if ((ost==0)&&(j<=p-1)) {
                        break;
                    }
                }
                x=1;
            }
          Console.WriteLine(s);
         // Console.ReadKey(true);
            }
        }
    }

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

namespace CodeForces174DIV2A
{
    class CowsAndPrimitiveRoots
    {
        static void Main(string[] args)
        {
            int p = int.Parse(Console.ReadLine());
            int counter = 0; bool isgood = true; int cur = 1;
            for (int x = 2; x < p; x++)
            {
                for (int i = 1; i <= p - 2; i++)
                {
                    cur = cur * x;
                    if ((cur %= p) == 1) { isgood = false; break; }
                }
                if (isgood && ((cur*x) % p == 1)) counter++;
                isgood = true; cur = 1;
            }
            Console.WriteLine(counter);
            Console.Read();
        }
    }
}

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

namespace CodeForces174DIV2A
{
    class CowsAndPrimitiveRoots
    {
        static void Main(string[] args)
        {
            int p = int.Parse(Console.ReadLine());
            int counter = 0; bool isgood = true; long cur = 1;
            for (int x = 2; x < p; x++)
            {
                for (int i = 1; i <= p - 2; i++)
                {
                    cur = cur * x;
                    if (cur % p == 1) { isgood = false; break; }
                }
                if (isgood && ((cur*x) % p == 1)) counter++;
                isgood = true; cur = 1;
            }
            Console.WriteLine(counter);
            Console.Read();
        }
    }
}

#define Online

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

class Program
{
    static void Main(string[] args)
    {
#if FileIO
        StreamReader sr = new StreamReader("input.txt");
        StreamWriter sw = new StreamWriter("output.txt");
        Console.SetIn(sr);
        Console.SetOut(sw);
#endif

        int p = int.Parse(Console.ReadLine());
        int ans = 0;
        if (p == 2)
        {
            Console.WriteLine(0);
            return;
        }
        for (int x = 1; x < p; x++)
        {
            int r = x % p;
            if (r - 1 == 0) continue;
            bool isOkay = true;
            int cur = r;
            for (int i = 2; i <= p - 2; i++)
            {
                cur *= r;
                cur %= p;
                if (cur - 1 == 0)
                {
                    isOkay = false;
                    break;
                }
            }
            if (isOkay)
            {
                cur *= r;
                cur %= p;
                if (cur - 1 == 0)
                    ans++;
            }
        }

        Console.WriteLine(ans);
#if Online
        Console.ReadLine();
#endif

#if FileIO
        sr.Close();
        sw.Close();
#endif
    }

    static string[] ReadArray()
    {
        return Console.ReadLine().Split(' ');
    }
}

static class ArrayUtils
{
    public static int BinarySearch(int[] a, int val)
    {
        int left = 0;
        int right = a.Length - 1;
        int mid;

        while (left < right)
        {
            mid = left + ((right - left) >> 1);
            if (val <= a[mid])
            {
                right = mid;
            }
            else
            {
                left = mid + 1;
            }
        }

        if (a[left] == val)
            return left;
        else
            return -1;
    }
}