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

namespace ConsoleApplication1
{
    class Program
    {
        const long mod = 1000000007;
        static long phi(long n)
        {
            long result = n;
            for (long 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;
        }

        static void Main()
        {
            string[] token = Console.ReadLine().Split(' ');
            long n = long.Parse(token[0]);
            long k = long.Parse(token[1]);
            long t = 1;
            long ans = n;
            if (k >= n)
            {
                Console.WriteLine(1);
                return;
            }
            else
            {
                while (t <= k)
                {
                    if (t == 1)
                    {
                        ans = phi(ans);
                        t++;
                    }
                    else if (t % 2 == 1)
                    {
                        ans = phi(ans);
                        t++;
                    }
                    else
                    {
                        t++;
                        continue;
                    }
                }
            }
            Console.WriteLine(ans % mod);
            Console.Read();
        }
    }
}


namespace topCoder
{
	using System;
	using System.Collections.Generic;

	class p3
	{
		static void Main(string[] args)
		{
			//p1 o = new p1();
			//o.foo();

			//p2 o = new p2();
			//o.foo();

			p3 o = new p3();
			o.foo();
		}
		public void foo()
		{
			string[] sp = Console.ReadLine().Split(' ');
			int n = int.Parse(sp[0]);
			int m = int.Parse(sp[1]);
			bfs(n, m);
		}
		private void bfs(int n, int m)
		{
			Queue<KeyValuePair<int, int>> q = new Queue<KeyValuePair<int,int>>();
			q.Enqueue(new KeyValuePair<int,int>(n, 0));
			while (q.Count > 0)
			{
				KeyValuePair<int,int> pr = q.Dequeue();
				int cur = pr.Key;
				int d = pr.Value;
				if (cur == m)
				{
					Console.WriteLine(d); return;
				}
				q.Enqueue(new KeyValuePair<int, int>(2*cur, d+1));
				q.Enqueue(new KeyValuePair<int, int>(cur-1, d + 1));
			}
		}
	}
}


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

namespace Z1294
{
    class Program
    {
        struct Node
        {
            public int num, operations;
        }

        static void Main(string[] args)
        {
            string[] req = Console.ReadLine().Split(' ');

            int m, n;

            n = int.Parse(req[0]);
            m = int.Parse(req[1]);

            Queue<Node> nums = new Queue<Node>();

            nums.Enqueue(new Node() { operations = 1, num = n});

            while (nums.Count > 0)
            {
                Node temp = nums.Dequeue();

                if (temp.num * 2 == m || temp.num - 1 == m)
                {
                    Console.WriteLine(temp.operations);
                    return;
                }
                else
                {
                    nums.Enqueue(new Node() { operations = temp.operations + 1, num = temp.num * 2 });

                    if (temp.num > 0)
                        nums.Enqueue(new Node() { operations = temp.operations + 1, num = temp.num - 1 });
                }
            }
        }
    }
}


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

namespace CodeForces
{
    class R175_Div2_D
    {
        static void Main(string[] args)
        {
            long mod = 1000000007;
            int n = int.Parse(Console.ReadLine());

            long f = 1;
            for (int i = 1; i <= n; i++)
                f *= i;

            f *= f;

            for (int i = 1; i <= n-2; i++)
                f /= 2;

            f = f % mod;

            if (n == 2)
                Console.WriteLine(0);
            else
                Console.WriteLine(f);
        }
    }
}


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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            var dt = System.DateTime.Now;
            int t = int.Parse(str[0]);
            int l = int.Parse(str[1]);
            int r = int.Parse(str[2]);
            int mod = 1000000007;

            long[] f = new long[5000010];

            f[2] = 1;
            int prime;
            for (int i = 3; i <= r; i++)
            {
                prime = 1;
                for (int j = 2; j * j <= i; j++)
                {
                    if ( i%j == 0 )
                    {
                        int d = i / j;
                        f[i] = (long)d * f[j] + f[d];
                        prime = 0;
                        break;
                    }
                }
                if (prime == 1)
                {
                    f[i] = (long)i * (i - 1) / 2;
                }
            }

            /*for (int i = 4500000; i < 4500100; i++)
                Console.WriteLine(f[i]);
            */
            int res = 0;

            for (int i = r; i >= l; i--) res =  (int) ( ((long)res * t + f[i]) % mod );

           /* for (int i = r; i <= r; i++)
            {
                res += (int) ( ((long)st * f[i])%mod );
                res = (int)( res % mod );
                st = (int) ( ( (long)t * (long)st ) %mod );
            }*/
            Console.WriteLine(res);
            //Console.WriteLine(System.DateTime.Now - dt);
        }
    }

}


using System;
class Test{
    public static void Main(String[] args){
        string [] str =  Console.ReadLine().Split();
        int n = Int32.Parse(str[0]);
        int a = Int32.Parse(str[1]);
        int b = Int32.Parse(str[2]);
        int sum1 = n-a;
        int sum2 = n-b;
        if(a+b>=n){
            Console.WriteLine(n-a);
        }else{
            if(n-a>b){
                Console.WriteLine(b+1);
            } else if(n-a == b){
                Console.WriteLie(b);
            } else {
                Console.WriteLine(n-a);
            }
        }
    }
}


static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int i = 2;
            int f = n;
            int c = 1;
            int l = n;

            while (f > 1) {
                f = (n - n % i) / i;
                if (l != f)
                {
                    l = f;
                    c++;
                }
                i++;
            }

            Console.WriteLine(c);
        }


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

namespace _123
{
    class Program
    {
        static void Main(string[] args)
        {
            int a = Convert.ToInt32( Console.ReadLine());
            //
            int index = 0;
            int B = a;
            while (B != 1)
            {
                index++;
                B = a / index;
            }
            //
            Console.WriteLine(index);
            Console.ReadKey();
        }
    }
}


using System;
using System.Globalization;
using System.IO;
using System.Text;
using static System.Console;
using static System.Math;

namespace Olymp
{
  public class ProblemSolver
  {
    private readonly Tokenizer input;

    public void Solve()
    {
      var s1 = input.ReadToken();
      var s2 = input.ReadToken();
      var d1 = DateTime.ParseExact(s1, "hh:mm", null).TimeOfDay;
      var d2 = DateTime.ParseExact(s2, "hh:mm", null).TimeOfDay;
      var dd = (d2 - d1).TotalMinutes / 2;
      Write(d1.Add(TimeSpan.FromMinutes(dd)).ToString(@"hh\:mm"));
    }

    public ProblemSolver(TextReader input)
    {
      this.input = new Tokenizer(input);
    }
  }

  #region Service classes

  public class Tokenizer
  {
    private TextReader reader;

    public string ReadToEnd()
    {
      return this.reader.ReadToEnd();
    }

    public int ReadInt()
    {
      var c = SkipWS();
      if (c == -1)
        throw new EndOfStreamException();
      var isNegative = false;
      if (c == '-' || c == '+')
      {
        isNegative = c == '-';
        c = this.reader.Read();
        if (c == -1)
          throw new InvalidOperationException();
      }
      if (!char.IsDigit((char)c))
        throw new InvalidOperationException();
      var result = (char)c - '0';
      c = this.reader.Read();
      while (c > 0 && !char.IsWhiteSpace((char)c))
      {
        if (!char.IsDigit((char)c))
          throw new InvalidOperationException();
        result = result * 10 + (char)c - '0';
        c = this.reader.Read();
      }
      if (isNegative)
        result = -result;
      return result;
    }

    public string ReadLine()
    {
      return reader.ReadLine();
    }

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

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

    public int[] ReadIntArray(int n)
    {
      var a = new int[n];
      for (var i = 0; i < n; i++)
        a[i] = ReadInt();
      return a;
    }

    public long[] ReadLongArray(int n)
    {
      var a = new long[n];
      for (var i = 0; i < n; i++)
        a[i] = ReadLong();
      return a;
    }

    public double[] ReadDoubleArray(int n)
    {
      var a = new double[n];
      for (var i = 0; i < n; i++)
        a[i] = ReadDouble();
      return a;
    }

    public string ReadToken()
    {
      var c = SkipWS();
      if (c == -1)
        return null;
      var sb = new StringBuilder();
      while (c > 0 && !char.IsWhiteSpace((char)c))
      {
        sb.Append((char)c);
        c = this.reader.Read();
      }
      return sb.ToString();
    }

    private int SkipWS()
    {
      var c = this.reader.Read();
      if (c == -1)
        return c;
      while (c > 0 && char.IsWhiteSpace((char)c))
        c = this.reader.Read();
      return c;
    }

    public Tokenizer(TextReader reader)
    {
      this.reader = reader;
    }
  }

  internal class Program
  {
    public static void Main(string[] args)
    {
      var solver = new ProblemSolver(Console.In);
      solver.Solve();
    }
  }

  #endregion
}


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

namespace ConsoleApplication42
{
    class Program
    {
        static void Main(string[] args)
        {
            int a = Convert.ToInt32(Console.ReadLine());
            string[] s = Console.ReadLine().Split();
            int b = Convert.ToInt32(s[0]);
            for (int i = 0; i < a; ++i)
            {
                if (b <= Convert.ToInt32(s[i]))
                {
                    b = Convert.ToInt32(s[i]);
                }
            }
            int c = b - 5;
            int sh = 0;
            for (int i = 0; i < a; ++i)
            {
                if (c <= Convert.ToInt32(s[i]))
                {
                    sh++;
                }
            }
            Console.WriteLine(sh);
        }
    }
}


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

namespace lab1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.OutputEncoding = Encoding.Unicode;
            //Console.Write("Введите размер массива: ");
            int n = Convert.ToInt32(Console.ReadLine());
            int[] array = new int[n];
            /*for (int i = 0; i < n; i++)
            {
                Console.Write("\nВведите " + Convert.ToString(i + 1) + " элемент: ");
                array[i] = Convert.ToInt32(Console.ReadLine());
            }*/
            string[] line = Console.ReadLine().Split(' ');
            for (int i = 0; i < n; i++)
                array[i] = Convert.ToInt32(line[i]);
            MergeSortAlgorithm<int>.MergeSort(array, 0, n - 1);
            for (int i = 0; i < n; i++)
            {
                Console.Write(Convert.ToString(array[i]) + " ");
            }
            //Console.ReadKey();
        }
    }

    class MergeSortAlgorithm<T> where T : IComparable<T>
    {
        public static void MergeSort(T[] array, int left, int right)
        {
            if (left == right)
                return;
            int mid = (left + right) / 2;
            MergeSort(array, left, mid);
            MergeSort(array, mid + 1, right);
            Merge(array, left, mid, array, mid + 1, right);
        }

        public static void Merge(T[] array1, int left1, int right1, T[] array2, int left2, int right2)
        {
            T[] newArray = new T[right2 - left2 + 1 + right1 - left1 + 1];
            int it1 = left1, it2 = left2, itNew = 0;
            while (it1 <= right1 || it2 <= right2)
            {
                if (it1 <= right1 && (it2 > right2 || Compare(ref array1[it1], ref array2[it2])))
                {
                    newArray[itNew] = array1[it1++];
                }
                else
                {
                    newArray[itNew] = array2[it2++];
                }
                itNew++;
            }
            itNew = 0;
            for (int i = left1; i <= right1; i++)
            {
                array1[i] = newArray[itNew++];
            }
            for (int i = left2; i <= right2; i++)
            {
                array2[i] = newArray[itNew++];
            }
        }

        public static bool Compare(ref T a, ref T b)// where T : IComparable<T>
        {
            return a.CompareTo(b) <= 0;
        }
    }
}


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

namespace codeforces
{
    class Program
    {
        public static string SortStringChars(string s)
        {
            char[] c = s.ToCharArray();
            Array.Sort(c);
            return new String(c);
        }
        static void Main(string[] args)
        {
            //   StreamReader objReader = new StreamReader("input.txt");
            string sa = Console.ReadLine();
            int[] input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();

            string[] st = Console.ReadLine().Split(' ');
         //   int k = int.Parse(st);
          //  string[] Mas=new string[int.Parse(sa)];

            string s="",Gamotana="";

            //for (int i = 0; i < st.Length; i++)
            //{
            //    Mas[i]= st[i];
            //  //  i++;
            //}

            //string sort = SortStringChars(s);.
            Array.Sort(input);
            for (int j = 0; j < input.Length; j++)
            {
                Gamotana += input[j];
                Gamotana += " ";
            }
          string gamo=  Gamotana.Remove(Gamotana.Length - 1);

            Console.WriteLine(gamo);
        }
    }
}


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

namespace ConsoleApplication9
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = Console.ReadLine();

            int n = Int32.Parse(Console.ReadLine());

            Dictionary<int, string> monthNumber = new Dictionary<int, string>()
            {
                {1, "January"},
                {2, "February"},
                {3, "March"},
                {4, "April"},
                {5, "May"},
                {6, "June"},
                {7, "July"},
                {8, "August"},
                {9, "September"},
                {10, "October"},
                {11, "November"},
                {12, "December"}
            };

            int m = monthNumber.Where(el => el.Value == str).Select(el => el.Key).First();

            int result = (n + m) % 12;

            string month = monthNumber.Where(el => el.Key == result).Select(el => el.Value).First();

            Console.WriteLine(month);
        }
    }
}


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

namespace ConsoleApplication34
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            int r = 1;
            int t = 0;
            string [] a = Console.ReadLine().Split();
            List <int> s = new List<int>();
            for(int i = 0; i<n;i++)
            {
                s.Add(Convert.ToInt32(a[i]));
            }
            for (int i = s.IndexOf(1); i < n; i++)
            {
                if(s[i]==1)
                {
                    r = r * (t + 1);
                    t = 0;
                }
                else
                {
                    t++;
                }
            }
            Console.WriteLine(r);
            //Console.ReadLine();
        }
    }
}


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)
        {
            string n = Console.ReadLine();
            int[] arr = Array.ConvertAll(Console.ReadLine().Split(), Convert.ToInt32);
            int prefZero = 0;
            int lastZero = 0;
            int fCount = 0;
            int lCount = arr.Length - 1;
            int result = 1;
            if (arr[fCount] == 0)
            {
                while (true)
                {
                    if (arr[fCount] == 0)
                    {
                        prefZero++;
                    }
                    else
                    {
                        break;
                    }
                    fCount++;
                }
            }
            if (arr[lCount] == 0)
            {
                while (true)
                {
                    if (arr[lCount] == 0)
                    {
                        lastZero++;
                    }
                    else
                    {
                        break;
                    }
                    lCount--;
                }
            }
            if ((arr.Length - lastZero - prefZero) != 1)
            {
                int i = fCount;
                while (i <= lCount)
                {
                    if (arr[i] == 0)
                    {
                        int count = 0;
                        while (arr[i] == 0)
                        {
                            if (arr[i] != 0)
                            {
                                break;
                            }
                            count++;
                            i++;
                        }

                        result *= count + 1;
                    }
                    else { i++; }
                }
            }

            Console.WriteLine(result);
        }
    }
}


using System;

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

namespace Codeforces
{
    public class Input
    {
        private static string _line;

        public static bool Next()
        {
            _line = Console.ReadLine();
            return _line != null;
        }

        public static bool Next(out long a)
        {
            var ok = Next();
            a = ok ? long.Parse(_line) : 0;
            return ok;
        }

        public static bool Next(out long a, out long b)
        {
            var ok = Next();
            if (ok)
            {
                var array = _line.Split(' ').Select(long.Parse).ToArray();
                a = array[0];
                b = array[1];
            }
            else
            {
                a = b = 0;
            }

            return ok;
        }

        public static bool Next(out long a, out long b, out long c)
        {
            var ok = Next();
            if (ok)
            {
                var array = _line.Split(' ').Select(long.Parse).ToArray();
                a = array[0];
                b = array[1];
                c = array[2];
            }
            else
            {
                a = b = c = 0;
            }
            return ok;
        }

        public static bool Next(out long a, out long b, out long c, out long d)
        {
            var ok = Next();
            if (ok)
            {
                var array = _line.Split(' ').Select(long.Parse).ToArray();
                a = array[0];
                b = array[1];
                c = array[2];
                d = array[3];
            }
            else
            {
                a = b = c = d = 0;
            }
            return ok;
        }

        public static bool Next(out long a, out long b, out long c, out long d, out long e)
        {
            var ok = Next();
            if (ok)
            {
                var array = _line.Split(' ').Select(long.Parse).ToArray();
                a = array[0];
                b = array[1];
                c = array[2];
                d = array[3];
                e = array[4];
            }
            else
            {
                a = b = c = d = e = 0;
            }
            return ok;
        }

        public static List<long> Numbers()
        {
            return !Next() ? new List<long>() : _line.Split(' ').Select(long.Parse).ToList();
        }

        public static bool Next(out string value)
        {
            value = string.Empty;
            if (!Next()) return false;
            value = _line;
            return true;
        }
    }

    public class DisjointSet
    {
        private readonly int[] _parent;
        private readonly int[] _rank;
        public int Count { get; private set; }

        public DisjointSet(int count, int initialize = 0)
        {
            Count = count;
            _parent = new int[Count];
            _rank = new int[Count];
            for (var i = 0; i < initialize; i++) _parent[i] = i;
        }

        private DisjointSet(int count, int[] parent, int[] rank)
        {
            Count = count;
            _parent = parent;
            _rank = rank;
        }

        public void Add(int v)
        {
            _parent[v] = v;
            _rank[v] = 0;
        }

        public int Find_Recursive(int v)
        {
            if (_parent[v] == v) return v;
            return _parent[v] = Find(_parent[v]);
        }

        public int Find(int v)
        {
            if (_parent[v] == v) return v;
            var last = v;
            while (_parent[last] != last) last = _parent[last];
            while (_parent[v] != v)
            {
                var t = _parent[v];
                _parent[v] = last;
                v = t;
            }
            return last;
        }

        public int this[int v]
        {
            get { return Find(v); }
            set { Union(v, value); }
        }

        public void Union(int a, int b)
        {
            a = Find(a);
            b = Find(b);
            if (a == b) return;
            if (_rank[a] < _rank[b])
            {
                var t = _rank[a];
                _rank[a] = _rank[b];
                _rank[b] = t;
            }
            _parent[b] = a;
            if (_rank[a] == _rank[b]) _rank[a]++;
        }

        public int GetSetCount()
        {
            var result = 0;
            for (var i = 0; i < Count; i++)
            {
                if (_parent[i] == i) result++;
            }
            return result;
        }

        public DisjointSet Clone()
        {
            var rank = new int[Count];
            _rank.CopyTo(rank, 0);
            var parent = new int[Count];
            _parent.CopyTo(parent, 0);
            return new DisjointSet(Count, parent, rank);
        }

        public override string ToString()
        {
            return string.Join(",", _parent.Take(50));
        }
    }

    public class Matrix
    {
        public static Matrix Create(int i, int j)
        {
            var m = new Matrix(i, j);
            return m;
        }

        public static Matrix Create(int i)
        {
            var m = new Matrix(i, i);
            return m;
        }

        public long Modulo { get; set; }

        private readonly int _width;
        private readonly int _height;
        private readonly long[,] _data;
        public int Width{get { return _width; }}
        public int Height{get { return _height; }}

        private Matrix(int i, int j)
        {
            Modulo = 1000000000000000000L;
            _width = j;
            _height = i;
            _data = new long[_height, _width];
        }

        public static Matrix operator *(Matrix m1, Matrix m2)
        {
            if (m1.Width != m2.Height) throw new InvalidDataException("m1.Width != m2.Height");
            var m = Create(m2.Width, m1.Height);
            m.Modulo = m1.Modulo;
            for (var i=0;i<m2.Width;i++)
                for (var j = 0; j < m1.Height; j++)
                {
                    for (var k = 0; k < m1.Width; k++)
                        m[j, i] += (m1[j, k]*m2[k, i]) % m1.Modulo;
                    m[j, i] %= m1.Modulo;
                }
            return m;
        }

        public static Matrix operator +(Matrix m1, Matrix m2)
        {
            var m = m1.Clone();
            for (var i=0;i<m2.Width;i++)
                for (var j = 0; j < m1.Height; j++)
                    m[j, i] = (m[j, i] + m2[j, i]) % m1.Modulo;
            return m;
        }

        public static Matrix operator -(Matrix m1, Matrix m2)
        {
            var m = m1.Clone();
            for (var i=0;i<m2.Width;i++)
                for (var j = 0; j < m1.Height; j++)
                    m[j, i] = (m[j, i] - m2[j, i]) % m1.Modulo;
            return m;
        }

        public static Matrix operator *(Matrix m1, long l)
        {
            var m = m1.Clone();
            for (var i=0;i<m1.Width;i++)
                for (var j=0;j<m1.Height;j++)
                        m[j, i] = (m[j, i] * l) % m.Modulo;
            return m;
        }

        public static Matrix operator *(long l, Matrix m1)
        {
            return m1*l;
        }

        public static Matrix operator +(Matrix m1, long l)
        {
            var m = m1.Clone();
            for (var i = 0; i < m1.Width; i++)
                    m[i, i] = (m[i, i] + l) % m.Modulo;
            return m;
        }

        public static Matrix operator +(long l, Matrix m1)
        {
            return m1 + l;
        }

        public static Matrix operator -(Matrix m1, long l)
        {
            return m1 + (-l);
        }

        public static Matrix operator -(long l, Matrix m1)
        {
            var m = m1.Clone() * -1;
            return m + l;
        }

        public Matrix BinPower(long l)
        {
            var n = 1;
            var m = Clone();
            var result = new Matrix(m.Height, m.Width) + 1;
            result.Modulo = m.Modulo;
            while (l != 0)
            {
                var i = l & ~(l - 1);
                l -= i;
                while (n < i)
                {
                    m = m*m;
                    n <<= 1;
                }
                result *= m;
            }
            return result;
        }

        public void Fill(long l)
        {
            l %= Modulo;
            for (var i = 0; i < _height; i++)
                for (var j = 0; j < _width; j++)
                    _data[i, j] = l;
        }

        public Matrix Clone()
        {
            var m = new Matrix(_width, _height);
            Array.Copy(_data, m._data, _data.Length);
            m.Modulo = Modulo;
            return m;
        }

        public long this[int i, int j]
        {
            get { return _data[i, j]; }
            set { _data[i, j] = value % Modulo; }
        }
    }

    public class RedBlackTree<TKey, TValue> : IEnumerable<KeyValuePair<TKey, TValue>>
    {
        private readonly List<Node> _items = new List<Node>();
        private Node _root;
        private readonly IComparer<TKey> _comparer;

        public RedBlackTree()
        {
            _comparer = Comparer<TKey>.Default;
        }

        private Node _search(TKey key)
        {
            var node = _root;
            while (node != null)
            {
                var i = _comparer.Compare(key, node.Key);
                if (i == 0) return node;
                node = i > 0 ? node.Right : node.Left;
            }
            return null;
        }

        public void Add(TKey key, TValue value)
        {
            var node = new Node { Key = key, Value = value, Red = true };
            _items.Add(node);
            if (_root == null)
            {
                _root = node;
                _root.Red = false;
                return;
            }
            var x = _root;
            Node y = null;
            while (x != null)
            {
                y = x;
                x = _comparer.Compare(key, x.Key) > 0 ? x.Right : x.Left;
            }
            node.Parent = y;
            if (y == null) _root = node;
            else if (_comparer.Compare(key, y.Key) > 0) y.Right = node;
            else y.Left = node;
            InsertFixup(node);
        }

        private void InsertFixup(Node node)
        {
            while (true)
            {
                var parent = node.Parent;
                if (parent == null || !parent.Red || parent.Parent == null) break;
                var grand = parent.Parent;

                if (parent == grand.Left)
                {
                    var uncle = grand.Right;
                    if (uncle != null && uncle.Red) /* parent and uncle both red: we could swap colors of them with grand */
                    {
                        parent.Red = false;
                        uncle.Red = false;
                        grand.Red = true;
                        node = grand; /* and continue fixing tree for grand */
                    }
                    else if (node == parent.Right) /* we rotate around the parent */
                    {
                        node = parent;
                        RotateLeft(node);
                    }
                    else /* rotate around grand and switch colors of grand and parent */
                    {
                        parent.Red = false;
                        grand.Red = true;
                        RotateRight(grand);
                        if (grand == _root) _root = parent;
                        break; /* and finish since tree is fixed */
                    }
                }
                else
                {
                    if (_root.Parent != null) Debugger.Break();

                    var uncle = grand.Left;
                    if (uncle != null && uncle.Red) /* parent and uncle both red: we could swap colors of them with grand */
                    {
                        parent.Red = false;
                        uncle.Red = false;
                        grand.Red = true;
                        node = grand; /* and continue fixing tree for grand */
                    }
                    else if (node == parent.Left) /* we rotate around the parent */
                    {
                        node = parent;
                        RotateRight(node);
                    }
                    else /* rotate around grand and switch colors of grand and parent */
                    {
                        parent.Red = false;
                        grand.Red = true;
                        RotateLeft(grand);
                        if (grand == _root) _root = parent;
                        break; /* and finish since tree is fixed */
                    }
                }
            }
            _root.Red = false;
        }

        private void RotateLeft(Node node)
        {
            if (node.Right == null)
                throw new NotSupportedException("Cannot rotate left: right node is missing");
            var parent = node.Parent;
            var right = node.Right;
            right.Parent = parent;
            if (parent != null)
            {
                if (parent.Left == node) parent.Left = right;
                else parent.Right = right;
            }
            node.Right = right.Left;
            if (node.Right != null)
                node.Right.Parent = node;
            right.Left = node;
            node.Parent = right;
        }

        private void RotateRight(Node node)
        {
            if (node.Left == null)
                throw new NotSupportedException("Cannot rotate right: left node is missing");
            var parent = node.Parent;
            var left = node.Left;
            left.Parent = parent;
            if (parent != null)
            {
                if (parent.Left == node) parent.Left = left;
                else parent.Right = left;
            }
            node.Left = left.Right;
            if (node.Left != null)
                node.Left.Parent = node;
            left.Right = node;
            node.Parent = left;
        }

        public void Remove(TKey key)
        {
            var node = _search(key);
            if (node == null) return;

            var deleted = node.Left == null || node.Right == null ? node : Next(node);
            var child = deleted.Left ?? deleted.Right;
            if (child != null)
                child.Parent = deleted.Parent;
            if (deleted.Parent == null) /* root */
                _root = child;
            else if (deleted == deleted.Parent.Left)
                deleted.Parent.Left = child;
            else
                deleted.Parent.Right = child;
            if (node != deleted)
            {
                node.Key = deleted.Key;
                node.Value = deleted.Value;
            }

            if (!deleted.Red)
            {
                DeleteFixup(child, deleted.Parent);
            }
        }

        private void DeleteFixup(Node node, Node parent)
        {
            while (parent != null && (node == null || !node.Red))
            {
                if (node == parent.Left)
                {
                    var brother = parent.Right;
                    if (brother.Red)
                    {
                        brother.Red = false;
                        parent.Red = true;
                        RotateLeft(parent);
                        brother = parent.Right;
                    }
                    if ((brother.Left == null || !brother.Left.Red) && (brother.Right == null || !brother.Right.Red))
                    {
                        node = parent.Red ? _root : parent;
                        brother.Red = true;
                        parent.Red = false;
                    }
                    else
                    {
                        if (brother.Right == null || !brother.Right.Red)
                        {
                            if (brother.Left != null)
                                brother.Left.Red = false;
                            brother.Red = true;
                            RotateRight(brother);
                            brother = parent.Right;
                        }
                        if (!brother.Right.Red) Debugger.Break();
                        brother.Red = parent.Red;
                        parent.Red = false;
                        if (brother.Right != null)
                            brother.Right.Red = false;
                        RotateLeft(parent);
                        node = _root;
                    }
                }
                else
                {
                    var brother = parent.Left;
                    if (brother.Red)
                    {
                        brother.Red = false;
                        parent.Red = true;
                        RotateRight(parent);
                        brother = parent.Left;
                    }
                    if ((brother.Right == null || !brother.Right.Red) && (brother.Left == null || !brother.Left.Red))
                    {
                        node = parent.Red ? _root : parent;
                        brother.Red = true;
                        parent.Red = false;
                    }
                    else
                    {
                        if (brother.Left == null || !brother.Left.Red)
                        {
                            if (brother.Right != null)
                                brother.Right.Red = false;
                            brother.Red = true;
                            RotateLeft(brother);
                            brother = parent.Left;
                        }
                        brother.Red = parent.Red;
                        parent.Red = false;
                        if (brother.Left != null)
                            brother.Left.Red = false;
                        RotateRight(parent);
                        node = _root;
                    }
                }
                parent = node.Parent;
            }

            node.Red = false;
        }

        public TValue this[TKey key]
        {
            get
            {
                var node = _search(key);
                return node == null ? default(TValue) : node.Value;
            }
            set
            {
                var node = _search(key);
                if (node == null) Add(key, value);
                else node.Value = value;
            }
        }

        public bool Check()
        {
            int count;
            return _root == null || _root.Check(out count);
        }

        private Node Minimum(Node node)
        {
            var result = node;
            while (result.Left != null) result = result.Left;
            return result;
        }

        private Node Maximum(Node node)
        {
            var result = node;
            while (result.Right != null) result = result.Right;
            return result;
        }

        private Node Next(Node node)
        {
            Node result;
            if (node.Right != null)
            {
                result = Minimum(node.Right);
            }
            else
            {
                while (node.Parent != null && node.Parent.Right == node)
                    node = node.Parent;
                result = node.Parent;
            }
            return result;
        }

        private Node Previous(Node node)
        {
            Node result;
            if (node.Left != null)
            {
                result = Maximum(node.Left);
            }
            else
            {
                while (node.Parent != null && node.Parent.Left == node)
                    node = node.Parent;
                result = node.Parent;
            }
            return result;
        }

        public void Print()
        {
            var node = Minimum(_root);
            while (node != null)
            {
                Console.Write(node.Red ? '*' : ' ');
                Console.Write(node.Key);
                Console.Write('\t');
                node = Next(node);
            }
        }

        #region Nested classes

        [DebuggerDisplay("{ToString()}")]
        private sealed class Node
        {
            public TKey Key;
            public TValue Value;
            public bool Red;

            public Node Parent;
            public Node Left;
            public Node Right;

            public bool Check(out int count)
            {
                count = 0;
                if (Red)
                {
                    if (Left != null && Left.Red) return false;
                    if (Right != null && Right.Red) return false;
                }
                var left = 0;
                var right = 0;
                if (Left != null && !Left.Check(out left)) return false;
                if (Right != null && !Right.Check(out right)) return false;
                count = left + (Red ? 0 : 1);
                if (left != right)
                {
                    ;
                }
                return left == right;
            }

            public override string ToString()
            {
                return ToShortString(2);
            }

            private string ToShortString(int depth = 0)
            {
                return depth == 0
                    ? string.Format("{0}{1}", Red ? "*" : "", Key)
                    : string.Format("({1}<{0}>{2})", ToShortString(), Left == null ? "null" : Left.ToShortString(depth - 1), Right == null ? "null" : Right.ToShortString(depth - 1));
            }
        }

        #endregion

        #region IEnumerable

        public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator()
        {
            throw new NotImplementedException();
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return GetEnumerator();
        }

        #endregion
    }
}

namespace Codeforces.TaskC
{
    public class Task
    {
        public static void Main()
        {
            var task = new Task();
            try
            {
                task.Solve();
            }
            catch (Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(ex);
                throw;
            }
        }

        /*abacabadabacaba*/

        private long MaxSubstring(long best, long l, long r, long a, long b, int ch)
        {
            if (l > r || a > b) return best;
            if ((best >= b - a + 1) || (best >= r - l + 1)) return best;

            best = Math.Max(best, Math.Min(r, b) - Math.Max(l, a) + 1);
            var divide = 1 << ch;
             bool f1 = false, f2 = false;

            if (r == divide && l == r) return best;
            if (a == divide && a == b) return best;

            if (l == divide) l++;
            if (r == divide) r--;
            if (a == divide) a++;
            if (b == divide) b--;

            if (l > divide)
            {
                l -= divide;
                f1 = true;
            }
            if (r > divide)
            {
                r -= divide;
                f1 = !f1;
            }
            if (a > divide)
            {
                a -= divide;
                f2 = true;
            }
            if (b > divide)
            {
                b -= divide;
                f2 = !f2;
            }

            if (--ch > 0)
            {
                if (f1 && f2) best = Math.Max(Math.Max(best, divide - Math.Max(l, a)), Math.Min(r, b));
                if (f1 && !f2)
                {
                    best = MaxSubstring(best, l, divide - 1, a, b, ch);
                    best = MaxSubstring(best, 1, r, a, b, ch);
                }
                if (!f1 && f2)
                {
                    best = MaxSubstring(best, l, r, a, divide - 1, ch);
                    best = MaxSubstring(best, l, r, 1, b, ch);
                }
                if (!f1 && !f2) best = MaxSubstring(best, l, r, a, b, ch);
                if (f1 && f2)
                {
                    best = MaxSubstring(best, 1, r, a, divide - 1, ch);
                    best = MaxSubstring(best, l, divide - 1, 1, b, ch);
                }
            }

            return best;
        }

        void Solve()
        {
            long l1, r1, l2, r2;
            Input.Next(out l1, out r1, out l2, out r2);
            var n = MaxSubstring(0, l1, r1, l2, r2, 29);
            Console.WriteLine(n);
        }
    }
}


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

namespace ConsoleApplication1
{
    class Program
    {
         static void Main(string[] args)
         {
             string[] s = Console.ReadLine().Split(' ');
             int x = int.Parse(s[0]);
             int y = int.Parse(s[1]);
             double r = Math.Sqrt(x * x + y * y);
             if (r - Math.Truncate(r) == 0)
             {
                 Console.WriteLine("black");
                 return;
             }
             else
             {
                 if (Math.Truncate(r) % 2 == 0)
                 {
                     if(x * y > 0)
                     {
                         Console.WriteLine("black");
                     }
                     else
                     {
                         Console.WriteLine("white");
                     }
                 }
                 else
                 {
                     Console.WriteLine("black");
                 }
             }

          }
     }
 }


using System;

namespace qwetry {
  class Program {
    static void Main() {
      string[] s = Console.ReadLine().Split(' ');
      int x = int.Parse(s[0]);
      int y = int.Parse(s[1]);
      if (x == 0 || y == 0) {
        Console.Write("black");
        return;
      }
      if (x * y > 0) {
        if (Math.Sqrt(x * x + y * y) % 2 >= 0 && Math.Sqrt(x * x + y * y) % 2 <= 1) {
          Console.Write("black");
        } else {
          Console.Write("white");
        }
      } else {
        if (Math.Sqrt(x * x + y * y) % 2 >= 1 && Math.Sqrt(x * x + y * y) % 2 == 0) {
          Console.Write("black");
        } else {
          Console.Write("white");
        }
      }
      Console.ReadKey();
    }
  }
}


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

namespace nolifer
{
    class Program
    {
        static void Main(string[] args)
        {
            List<string> nums = new List<string>();
            int a = Convert.ToInt32(Console.ReadLine());
            for (int i = 0; i <= 9 * a.ToString().Length; i++)
            {
                int b = a - i;
                string c = b.ToString();
                for (int j = 0; j < c.Length;j++)
                {
                    b += Convert.ToInt32(c[j].ToString());

                }

                if (b == a)
                {
                    nums.Add(c);
                }
            }
            Console.WriteLine(nums.Count);
            foreach (string w in nums)
            {
                Console.WriteLine(w);
            }

        }
    }
}


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

namespace LuckySubstring
{
    class Program
    {
        static bool IsLucky(long n)
        {
            var num = n;
            while (num > 0)
            {
                var digit = num - (num / 10) * 10;
                if (digit != 4 && digit != 7) return false;
                num /= 10;
            }

            return true;
        }

        static void Main(string[] args)
        {
            var luckyNumbers = new List<long>();
            for (var n = 1; n <= 1000; n++)
            {
                if (IsLucky(n)) luckyNumbers.Add(n);
            }

            var answers = new Dictionary<long, long>();
            string input = Console.ReadLine();
            if (!string.IsNullOrEmpty(input))
            {
                for (var length=1; length<input.Length; length++)
                {
                    for (var pos=0; pos<=input.Length - length; pos++)
                    {
                        var strNum = input.Substring(pos, length);
                        var num = Convert.ToInt64(strNum);
                        if (IsLucky(num))
                        {
                            //Console.WriteLine("Found lucky number {0} of length {1}", num, length);
                            if (answers.ContainsKey(num))
                            {
                                answers[num]++;
                            } else
                            {
                                answers.Add(num, 1);
                            }
                        }
                    }
                }
            }

            var maxOcc = 0L;
            foreach (var num in answers)
            {
                if (num.Value > maxOcc) maxOcc = num.Value;
            }
            var maxAnswers = new List<long>();
            foreach (var num in answers)
            {
                if (num.Value == maxOcc) maxAnswers.Add(num.Key);
            }
            //Console.WriteLine("MaxOcc = {0}", maxOcc);
            var lexMin = "99999999999999999999999999999999999999999999999999";
            foreach (var num in maxAnswers)
            {
                if (string.Compare(num.ToString(), lexMin) < 0) lexMin = num.ToString();
            }

            if (lexMin != "99999999999999999999999999999999999999999999999999")
                Console.WriteLine(lexMin);
            else Console.WriteLine("-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)
      {
        string s = Console.ReadLine();
        int seven = 0;
        int four = 0;
        List<int> lucky = new List<int>();
        for(int i=0;i<s.Length;i++)
        {
           if(s[i]=='4'||s[i]=='7'){
              string sN = "";
              bool zeroExist = false;
              for(int j=i;j<s.Length;j++){
                 if(s[j]==0)zeroExist = true;
                 if(s[j]!='4'&&s[j]!='7')break;
                 sN += s[j];
                 lucky.Add(int.Parse(sN));
              }
             // if(!zeroExist&&sN.Length>0)lucky.Add(int.Parse(sN));
           }
        }
        lucky.Sort();

        if(lucky.Count>0){
          int counter = 0;
        int longestOccurance = 0;
        int mostFrequentNumber = 0;

        for (int i = 0; i < lucky.Count; i++)
        {
            counter = 0;

            for (int j = 0; j < lucky.Count; j++)
            {
                if (lucky[j] == lucky[i])
                {
                    counter++;
                }
            }

            if (counter > longestOccurance)
            {
                longestOccurance = counter;
                mostFrequentNumber = lucky[i];
            }
        }

         if(longestOccurance>-1){
            Console.WriteLine(mostFrequentNumber);
         }else{
           Console.WriteLine(lucky[0]);
         }
        }else{
         Console.WriteLine(-1);
        }
      }
  }
}


int t = int.Parse(Console.ReadLine().Trim().Split(' ')[1]);
			string s = Console.ReadLine().Trim();
			for(int i = 0; i < t; i++) s = s.Replace("BG", "GB");
			Console.WriteLine(s);


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

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

            //Console.SetIn(new StreamReader("file.in"));
            /*
            FileStream filestream = new FileStream("out.txt", FileMode.Create);
            var streamwriter = new StreamWriter(filestream);
            streamwriter.AutoFlush = true;
            Console.SetOut(streamwriter);
            */

            int n = int.Parse(Console.ReadLine());
            int[] v = Array.ConvertAll(Console.ReadLine().Split(' '), ts = int.Parse(ts));
            Array.Sort(v);
            Console.WriteLine(v[n - 1] - v[0]);
            int aux = v[0];
            v[0] = v[n - 1];
            v[n - 1] = aux;
            for (int i = 0; i < n; i++) {
                Console.Write("{0} ", v[i]);
            }

            //Console.ReadKey();
        }
    }
}


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

namespace probleme {
    class Program {
        static void Main(string[] args) {
            //Console.SetIn(new StreamReader("file.txt"));
            string[] s = Console.ReadLine().Split(':');
            int hh1 = int.Parse(s[0]), mm1 = int.Parse(s[1]);
            s = Console.ReadLine().Split(':');
            int hh2 = int.Parse(s[1]), mm2 = int.Parse(s[2]);
            int mm3 = mm1 - mm2;
            if (mm3 < 0) {
                mm3 += 60;
                hh1--;
            }
            int hh3 = hh1 - hh2;
            if (hh3 < 0) {
                hh3 += 24;
            }
            char[] ans = new char[5];
            ans[4] = (char)(mm3 % 10 + '0');
            mm3 /= 10;
            ans[3] = (char)(mm3 + '0');
            ans[2] = ':';
            ans[1] = (char)(hh3 % 10 + '0');
            hh3 /= 10;
            ans[0] = (char)(hh3 + '0');
            Console.Write(ans);
            //Console.ReadKey();
        }
    }
}


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

namespace _387A___George_and_Sleep
{
    class Program
    {
        static void Main(string[] args)
        {
            //StreamReader RE = new StreamReader(@"c:\users\amirhossin\documents\visual studio 2013\Projects\387A - George and Sleep\387A - George and Sleep\a.in");
            while (true)
            {
                string a = Console.ReadLine();
                string b = Console.ReadLine();
                string Ans="";

                DateTime Start=new DateTime (), End=new DateTime (),Base;
                Start = DateTime.Parse(b);
                End = DateTime.Parse(a);

                int H = End.Hour - Start.Hour,M=End.Minute-Start.Minute;
                if(H<=0 && M<0)
                {
                    H += 23;
                }
                if (H < 0)
                    H += 24;
                if (M < 0)
                    M += 60;
                if (H / 10 == 0)
                    Ans += "0" + H.ToString();
                else
                    Ans += H.ToString();
                Ans += ":";
                if (M / 10 == 0)
                    Ans += "0" + M.ToString();
                else
                    Ans += M.ToString();
                Console.WriteLine(Ans);

            }
        }
    }
}


<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">x86</Platform>
    <ProductVersion>8.0.30703</ProductVersion>
    <SchemaVersion>2.0</SchemaVersion>
    <ProjectGuid>{05C93F62-5FEB-405E-A6A6-8DA166CFDD88}</ProjectGuid>
    <OutputType>Exe</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>Игрушечные_армии</RootNamespace>
    <AssemblyName>Игрушечные армии</AssemblyName>
    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
    <TargetFrameworkProfile>Client</TargetFrameworkProfile>
    <FileAlignment>512</FileAlignment>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
    <PlatformTarget>x86</PlatformTarget>
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\Debug\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
    <PlatformTarget>x86</PlatformTarget>
    <DebugType>pdbonly</DebugType>
    <Optimize>true</Optimize>
    <OutputPath>bin\Release\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="System" />
    <Reference Include="System.Core" />
    <Reference Include="System.Xml.Linq" />
    <Reference Include="System.Data.DataSetExtensions" />
    <Reference Include="Microsoft.CSharp" />
    <Reference Include="System.Data" />
    <Reference Include="System.Xml" />
  </ItemGroup>
  <ItemGroup>
    <Compile Include="Program.cs" />
    <Compile Include="Properties\AssemblyInfo.cs" />
  </ItemGroup>
  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
  <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
       Other similar extension points exist, see Microsoft.Common.targets.
  <Target Name="BeforeBuild">
  </Target>
  <Target Name="AfterBuild">
  </Target>
  -->
</Project>


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

class Program
{
	int[][] c;
	int n, m;
	int mod = 1000000007;
	int add(int x, int y)
	{
		x+=y;
		return x < mod ? x : x - mod;
	}
	int mul(int x, int y)
	{
		return Convert.ToInt32(Convert.ToInt64(x) * y % mod);
	}
	void run()
	{
		String[] str = Console.ReadLine().Split(' ');
		n = Convert.ToInt32(str[0]);
		m = Convert.ToInt32(str[1]);
		int[][] dp=new int[n+1][];
		for (int i = 1; i <= n; i++)
		{
			dp[i] = new int[m-1];
			if (i == 1)
			{
				for (int j = 0; j <= m - 2; j++)
					dp[i][j] = 1;
				continue;
			}
			int now = 0;
			for (int j = 0; j <= m-2; j++)
			{
				now= add(now,dp[i-1][j]);
				dp[i][j] = add(j == 0 ? 0 : dp[i][j - 1], now);
			}
		}

		int[][] sum = new int[n+1][];
		for (int i = 0; i <= n; i++)
		{
			sum[i] = new int[m - 1];
			for (int j = 0; j <= m - 2; j++)
				sum[i][j] = i == 0 ? 0 : sum[i - 1][j] + dp[i][j];
		}

		int res = 0;
		for (int i = 1; i <= n; i++)
			for (int j = 0; j <= m - 2; j++)
			{
				res = add(res, mul(mul(sum[i][j], add(sum[n - i + 1][j], mod - sum[n - i][j])), m - 1 - j));
			}
		Console.WriteLine(res);
	}
	static void Main(String[] args)
	{
		new Program().run();
	}
}


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

namespace ConsoleApp88
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = int.Parse(Console.ReadLine()).ToString();
            int counter = 0;
            for (int i = s.Length-1; i >= 0; i--)
            {
                if (s[i] == '0')
                {
                    counter++;
                }

            }
            Console.WriteLine((counter>=6)?"yes":"no");
        }

    }
}


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

class Startup
{
    static void Main()
    {
        int intInput = int.Parse(Console.ReadLine());
        string input = intInput.ToString();
        int zeroesCount = input.Count(f => f == '0');
        Console.WriteLine(zeroesCount > 5 ? "yes":"no");
    }
}


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

namespace Codeforces
{
    internal class Program
    {
        private const string TEST = "B1";

        private static void Solve()
        {
            var input = ReadIntArray();
            var w = input[0];
            var h = input[1];
            var res = 0L;
            for (int i = 0; i < w; i++)
            {
                for (int j = 0; j < h; j++)
                {
                    var hMax = Math.Min(j, h - j);
                    res += Math.Max(0L, w - 1 - i)*Math.Max(0L, hMax);
                }
            }
            WriteLine(res);
        }

        private static void Main()
        {
            if (Debugger.IsAttached)
            {
                Console.SetIn(new StreamReader(String.Format(@"..\..\..\..\Tests\{0}.in", TEST)));
            }

            Solve();

            if (Debugger.IsAttached)
            {
                Console.In.Close();
                Console.SetIn(new StreamReader(Console.OpenStandardInput()));
                Console.ReadLine();
            }
        }

        #region Reader

        private static string Read()
        {
            return Console.ReadLine();
        }

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

        private static List<int> ReadIntArray()
        {
            var input = Console.ReadLine().Split(' ').Select(Int32.Parse).ToList();
            return input;
        }

        private static int ReadInt()
        {
            return Int32.Parse(Console.ReadLine());
        }

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

        private static int ReadNextInt(string[] input, int index)
        {
            return Int32.Parse(input[index]);
        }

        private static double ReadDouble()
        {
            return double.Parse(Console.ReadLine(), CultureInfo.InvariantCulture);
        }

        private static List<double> ReadDoubleArray()
        {
            return Console.ReadLine().Split(' ').Select(d => double.Parse(d, CultureInfo.InvariantCulture)).ToList();
        }

        private static void WriteLine(object value)
        {
            Console.WriteLine(value);
        }

        private static void Write(object value)
        {
            Console.Write(value);
        }

        #endregion
    }
}


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

namespace Codeforces._20120510
{
    public class B
    {
        public static void Main(string[] args)
        {
            var wh = GetListOfLong();
            Console.WriteLine(Solve(wh[0], wh[1]));
        }

        public static long Solve(long w, long h)
        {
            long ret = 0;

            for (long d1 = 2; d1 <= w; d1 += 2)
                for (long d2 = 2; d2 <= h; d2 += 2)
                {
                    ret += (w - d1 / 2) * (h - d2 / 2);
                }

            return ret;
        }

        public static List<long> GetListOfLong()
        {
            return Console.ReadLine().Split(' ').Select(t => long.Parse(t)).ToList();
        }
    }
}


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

namespace IQ_Test
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] matrix;
            string[,] matrix1 = new string[4, 4];
            int z = 0;
            int y = 0;

            for (int i = 0; i < 4; i++)
            {
                string x = Console.ReadLine();
                matrix = x.Split(' ');
                for (int j = 0; j < 4; j++)
                {
                    matrix1[i, j] = matrix[j];
                }

            }
            for (int i = 0; i < 3; i++)
            {

                for (int j = 0; j < 3; j++)
                {
                    for (int l = i; l < i + 1; l++)
                    {
                        for (int k = j; k < j + 1; k++)
                        {
                            if (matrix1[l,k]=="#")
                            {z++;}
                        if (matrix1[l,k]==".")
                            {y++;}

                        }
                    }
                }

            }
            if (Math.Abs(z - y) == 2)
            { Console.WriteLine("YES"); }
            else
            { Console.WriteLine("NO"); }

        }
    }
}


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

namespace probleme {
    class Program {
        static void Main(string[] args) {
            //Console.SetIn(new StreamReader("file.txt"));
            char[][] inp = new char[4][];
            for (int i = 0; i < 4; i++) {
                inp[i] = Console.ReadLine().ToCharArray();
            }
            int[,] m = new int[3, 3];
            bool sol = false;
            for (int i = 0; i < 3; i++) {
                for (int j = 0; j < 3; j++) {
                    if (inp[i][j] == '#') {
                        m[i, j]++;
                    }
                    if (inp[i + 1][j] == '#') {
                        m[i + 1, j]++;
                    }
                    if (inp[i][j + 1] == '#') {
                        m[i, j + 1]++;
                    }
                    if (inp[i + 1][j + 1] == '#') {
                        m[i + 1, j + 1]++;
                    }
                    if (m[i, j] != 2) {
                        sol = true;
                    }
                }
            }
            if (sol) {
                Console.Write("YES");
            } else {
                Console.Write("NO");
            }
            //Console.ReadKey();
        }
    }
}


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

namespace Codeforces659A
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] inp = Console.ReadLine().Split();
            int n = Convert.ToInt32(inp[0]);
            int a = Convert.ToInt32(inp[1]);
            int b = Convert.ToInt32(inp[2]);

            int outp = b == 0 ? a : a > Math.Abs(b) ? (b + a) % n : n - Math.Abs(a + b) % n;
            if (outp == 0)
                outp = n;

            Console.WriteLine(outp);
            inp = Console.ReadLine().Split();
        }
    }
}


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

class Test
{
    static long gcd(long a, long b)
    {

        if (b > a)
        {
            long temp = a;
            a = b;
            b = temp;
        }

        while (true)
        {
            a = a%b;
            long temp = a;
            a = b;
            b = temp;

            if (b == 0)
                return a;
        }

    }

    static void Main(string[] args)
    {
        long[] tokens = Console.Readline().Split(' ').Select(x => long.Parse(x)).ToArray();
        long lcm = token[0]*token[1] / gcd(token[0], token[1]);

        long diff = (lcm/tokens[0]) - (lcm / tokens[1]);

        if (diff == 1 || diff == -1)
            Console.WriteLine("Equal");
        else if (diff > 0)
            Console.WriteLine("Dasha");
        else if (diff < 0)
            Console.WriteLine("Masha");
    }

}


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

namespace probleme {
    class Program {
        static void Main(string[] args) {
            Console.SetIn(new StreamReader("file.txt"));
            char[][]table = new char[8][];
            for (int i=0;i<8;i++){
                table[i] = Console.ReadLine().ToCharArray();
            }
            int minW = 9;
            for (int j = 0; j < 8; j++) {
                int minR = 9;
                bool free = true;
                for (int i = 7; i >= 0; i--) {
                    if (table[i][j] == 'B') {
                        free = false;
                    }
                    if (table[i][j] == 'W') {
                        minR = i;
                        free = true;
                    }
                }
                if (free && minR < minW) {
                    minW = minR;
                }
            }
            int minB = 9;
            for (int j = 0; j < 8; j++) {
                int minR = 9;
                bool free = true;
                for (int i = 0; i < 8; i++) {
                    if (table[i][j] == 'W') {
                        free = false;
                    }
                    if (table[i][j] == 'B') {
                        minR = 7 - i;
                        free = true;
                    }
                }
                if (free && minR < minB) {
                    minB = minR;
                }
            }
            Console.Write("{0} {1}\n", minW, minB);
            if (minW <= minB) {
                Console.Write("A");
            } else {
                Console.Write("B");
            }
            Console.ReadKey();
        }
    }
}


using System;
using System.Globalization;
using System.IO;
using System.Linq;

namespace CF313
{
	internal class Program
	{
		private static void Main(string[] args)
		{
			//var sr = new InputReader(new StreamReader(new FileStream("input.txt", FileMode.Open)));
			var sr = new InputReader(Console.In);
			var sw = Console.Out;
			var task = new Task();
			task.Solve(1, sr, sw);
			//Console.ReadKey();
		}
	}

	internal class Task
	{
		public void Solve(int testNumber, InputReader sr, TextWriter sw)
		{
			var array = new char[8][];
			for (var i = 0; i < 8; i++) {
				var next = sr.NextString();
				array[i] = next.ToCharArray();
			}
			var minA = Int32.MaxValue;
			var minB = Int32.MaxValue;
			for (var j = 0; j < 8; j++) {
				for (var i = 0; i < 8; i++) {
					if (array[i][j] == 'W') {
						var can = true;
						for (var k = i - 1; k >= 0; k--) {
							if (array[k][j] != '.') {
								can = false;
								break;
							}
						}
						if (can) {
							minA = minA > (i - 1) ? i - 1 : minA;
						}
					}
					if (array[i][j] == 'B') {
						var can = true;
						for (var k = i + 1; k >= 7; k++) {
							if (array[k][j] != '.') {
								can = false;
								break;
							}
						}
						if (can) {
							minB = minB > (7 - i) ? 7 - i : minB;
						}
					}
				}
			}

			sw.WriteLine(minA < minB ? "A" : "B");
		}
	}

	internal class InputReader : IDisposable
	{
		private readonly TextReader sr;
		private bool isDispose = false;

		public InputReader(TextReader stream)
		{
			sr = stream;
		}

		public string NextString()
		{
			var result = sr.ReadLine();
			return result;
		}

		public int NextInt32()
		{
			return Int32.Parse(NextString());
		}

		public long NextInt64()
		{
			return Int64.Parse(NextString());
		}

		public string[] NextSplitStrings()
		{
			return NextString()
				.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
		}

		public T[] ReadArray<T>(Func<string, CultureInfo, T> func)
		{
			return NextSplitStrings()
				.Select(s => func(s, CultureInfo.InvariantCulture))
				.ToArray();
		}

		public void Dispose()
		{
			Dispose(true);
			GC.SuppressFinalize(this);
		}

		protected void Dispose(bool dispose)
		{
			if (!isDispose) {
				if (dispose)
					sr.Close();
				isDispose = true;
			}
		}

		~InputReader()
		{
			Dispose(false);
		}
	}
}


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' };

        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

            string[] sp = Console.ReadLine().Split();

            int[] a = new int[3];

            for (int i = 0; i < 3; ++i)
            {
                a[i] = int.Parse(sp[i]);
            }

            HashSet<int> hashSet = new HashSet<int>();

            a[0] %= a[1];
            int d = -1;
            int pos = 0;
            while (a[0] != 0 && (!hashSet.Contains(a[0])))
            {
                hashSet.Add(a[0]);
                a[0] *= 10;
                d = a[0] / a[1];
                if (d == a[2])
                {
                    break;
                }

                ++pos;
                a[0] %= a[1];
            }

            Console.WriteLine((d == a[2] || a[0] == a[2]) ? pos : -1);

#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;

namespace test
{
    class Program
    {
        static void Main()
        {
            string txt;
            while ((txt = Console.ReadLine()) != null)
            {
                var lst = txt.Split(' ');
                var a = int.Parse(lst[0]);
                var b = int.Parse(lst[1]);
                var c = int.Parse(lst[2]);
                var m = a % b;
                var pos = -1;

                if (m == 0)
                {
                    if (c == 0)
                    {
                        pos = 1;
                    }
                }
                else
                {
                    var p = 1;
                    m *= 10;
                    while (true)
                    {
                        var x = m / b;
                        if (x == c)
                        {
                            pos = p;
                            break;
                        }
                        var y = m % b;

                        if (y == 0)
                        {
                            if (c == 0)
                            {
                                pos = p + 1;
                            }

                            break;
                        }

                        y *= 10;
                        if (y == m)
                        {
                            break;
                        }
                        p++;
                        m = y;
                    }
                }
                Console.WriteLine(pos);
            }
        }
    }
}


using System;

namespace ddmmyy
{
	class MainClass
	{
		public static  bool chkdate(DateTime dt, int bdd, int bmm, int byy)
		{
			byy +=2000;
			if (bdd>31) return false;
			if (bmm>12) return false;
			int iLastDay = DateTime.DaysInMonth(byy, bmm);
			if (bdd>iLastDay) return false;
			DateTime test = new DateTime(byy, bmm, bdd);
			if (test <= dt) return true;
			return false;
		}

		public static void Main (string[] args)
		{
				bool ret = false;
                string wkstr = Console.ReadLine();
                string[] stArray = wkstr.Split('.');
                int dd = Int32.Parse(stArray[0]);
                int mm = Int32.Parse(stArray[1]);
                int yy = Int32.Parse(stArray[2]);
				DateTime dt = new DateTime(2000+yy-18,mm,dd);
                wkstr = Console.ReadLine();
                stArray = wkstr.Split('.');
                int bdd = Int32.Parse(stArray[0]);
                int bmm = Int32.Parse(stArray[1]);
                int byy = Int32.Parse(stArray[2]);
				if (yy>18) {
					if (chkdate(dt,bdd,bmm,byy) ) ret= true;
					if (chkdate(dt,bdd,byy,bmm) ) ret= true;
					if (chkdate(dt,bmm,bdd,byy) ) ret= true;
					if (chkdate(dt,bmm,byy,bdd) ) ret= true;
					if (chkdate(dt,byy,bdd,bmm) ) ret= true;
					if (chkdate(dt,byy,bmm,bdd) ) ret= true;
				}
			  	if (ret) Console.WriteLine("YES");
				else Console.WriteLine("NO");
		}
	}
}


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

namespace task30B
{
    class Program
    {
        static bool TryToDate(string dd, string mm, string yy, ref DateTime dt)
        {
            bool result = true;
            yy = "20" + yy;
            try
            {
                dt = new DateTime(Int32.Parse(yy), Int32.Parse(mm), Int32.Parse(dd));
            }
            catch
            {
                result = false;
            }
            return result;
        }

        static bool Answer(string dd, string mm, string yy, DateTime dProg)
        {
            bool f = false;
            DateTime result = DateTime.Now;
            if (TryToDate(dd, mm, yy, ref result))
            {
                TimeSpan t = dProg - result;
                DateTime d = new DateTime(t.Ticks);
                if (d.Year - 1 >= 18)
                {
                    f = true;
                }
            }
            return f;
        }
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split('.');
            DateTime dProg = new DateTime(Int32.Parse("20" + input[2]), Int32.Parse(input[1]), Int32.Parse(input[0]));
            input = Console.ReadLine().Split('.');
            DateTime dVasya = new DateTime(Int32.Parse("20" + input[2]), Int32.Parse(input[1]), Int32.Parse(input[0]));
            /*TimeSpan t = dProg - dVasya;
            if (t.Ticks < 0)
            {
                Console.WriteLine("NO");
                return;
            }*/
            string dd = input[0];
            string mm = input[1];
            string yy = input[2];
            //1 2 3
            bool result = Answer(dd, mm, yy, dProg);
            if (result)
            {
                Console.WriteLine("YES");
                return;
            }
            //1 3 2
            result = Answer(dd, yy, mm, dProg);
            if (result)
            {
                Console.WriteLine("YES");
                return;
            }
            //2 1 3
            result = Answer(mm, dd, yy, dProg);
            if (result)
            {
                Console.WriteLine("YES");
                return;
            }
            //2 3 1
            result = Answer(mm, yy, dd, dProg);
            if (result)
            {
                Console.WriteLine("YES");
                return;
            }
            //3 1 2
            result = Answer(yy, dd, mm, dProg);
            if (result)
            {
                Console.WriteLine("YES");
                return;
            }
            //3 2 1
            result = Answer(yy, mm, dd, dProg);
            if (result)
            {
                Console.WriteLine("YES");
                return;
            }
            Console.WriteLine("NO");
            //Console.ReadLine();
        }
    }
}


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

// (づ°ω°)づﾐe★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜
public class Solver
{
    class Edge<T>
    {
        public int To, Inv;
        public T Capacity;
        public Edge(int to, int inv, T capacity)
        {
            To = to;
            Inv = inv;
            Capacity = capacity;
        }
    }

    static void AddEdge<T>(List<Edge<T>>[] g, int from, int to, T capacity, bool directed = true)
    {
        g[from].Add(new Edge<T>(to, g[to].Count, capacity));
        g[to].Add(new Edge<T>(from, g[from].Count - 1, directed ? default(T) : capacity));
    }

    static class Flow
    {
        private static int[] level;
        private static int[] ptr;
        private static int n, source, sink;
        private static List<Edge<long>>[] g;

        public static long Find(List<Edge<long>>[] g, int source, int sink)
        {
            n = g.Length;
            level = new int[n];
            ptr = new int[n];
            Flow.g = g;
            Flow.source = source;
            Flow.sink = sink;

            long ret = 0;
            while (true)
            {
                Bfs();
                if (level[sink] < 0)
                    return ret;
                Array.Clear(ptr, 0, n);
                long f;
                while ((f = Dfs(source, int.MaxValue / 2)) > 0)
                    ret += f;
            }
        }

        static void Bfs()
        {
            for (int i = 0; i < n; i++)
                level[i] = -1;
            var q = new Queue<int>();
            level[source] = 0;
            q.Enqueue(source);
            while (q.Count > 0)
            {
                var v = q.Dequeue();
                foreach (var e in g[v])
                    if (e.Capacity > 0 && level[e.To] < 0)
                    {
                        level[e.To] = level[v] + 1;
                        q.Enqueue(e.To);
                    }
            }
        }

        static long Dfs(int v, long f)
        {
            if (v == sink)
                return f;
            for (; ptr[v] < g[v].Count; ptr[v]++)
            {
                var e = g[v][ptr[v]];
                if (e.Capacity <= 0 || level[v] >= level[e.To])
                    continue;
                long d = Dfs(e.To, Math.Min(f, e.Capacity));
                if (d <= 0)
                    continue;
                e.Capacity -= d;
                g[e.To][e.Inv].Capacity += d;
                return d;
            }
            return 0;
        }
    }

    public void Solve()
    {
        for (int tt = ReadInt(); tt > 0; tt--)
        {
            int n = ReadInt();
            var a = ReadIntArray();
            var b = ReadIntArray();

            long ans = 1L * Math.Min(a[0], b[1]) + Math.Min(a[1], b[2]) + Math.Min(a[2], b[0]);
            var g = Init<List<Edge<long>>>(8);
            for (int i = 0; i < 3; i++)
            {
                AddEdge(g, 6, i, a[i]);
                AddEdge(g, i + 3, 7, b[i]);
                for (int j = 0; j < 2; j++)
                    AddEdge(g, i, (i + 2 + j) % 3 + 3, long.MaxValue);
            }

            Write(a.Sum(aa => (long)aa) - Flow.Find(g, 6, 7), ans);
        }
    }

    #region Main

    protected static TextReader reader;
    protected 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("input.txt");
        //writer = new StreamWriter("output.txt");
#endif
        try
        {
            new Solver().Solve();
            //var thread = new Thread(new Solver().Solve, 1024 * 1024 * 128);
            //thread.Start();
            //thread.Join();
        }
        catch (Exception ex)
        {
#if DEBUG
            Console.WriteLine(ex);
#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); }
    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 double ReadDouble() { return double.Parse(ReadToken(), CultureInfo.InvariantCulture); }
    public static int[] ReadIntArray() { return ReadAndSplitLine().Select(int.Parse).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 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;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Windows_приложения1
{
    class Program
    {
        static void Main(string[] args)
        {
            ulong a, b;
            string s = Console.ReadLine();
            string[] number = s.Split();
            ulong.TryParse(number[0], out a);
            ulong.TryParse(number[1], out b);
            for (ulong i = 1; i <= a || i <= b; i++)
             {
                 a = a - (i * 2-1);
                 if (a < 0) { Console.WriteLine("Vladik"); return; }
                 b = b - (i * 2);
                 if (b < 0) { Console.WriteLine("Valera"); return; }
             }
        }
    }
}


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

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

            int h = int.Parse(Console.ReadLine());
            int m = int.Parse(Console.ReadLine());

            int count = 0;
            while (h % 10 != 7 && m % 10 != 7)
            {
                if (m < x)
                {
                    m = (m + 60 - x) % 60;
                    h = (h == 0) ? 23 : --h;
                }
                else
                {
                    m -= x;
                }
                count++;
            }

            Console.WriteLine(count);
        }
    }
}


string s = Console.ReadLine();
            string[] array = s.Split(' ');
            int[] numbers = new int[3];
            for (int i = 0; i < array.Length; i++)
                numbers[i] = int.Parse(array[i]);
            bool flag = false;

            for (int i = 0; i < (int) (numbers[2]/numbers[0]); i++)
            {
                for (int j = 0; j < (int) (numbers[2]/numbers[0]); j++)
                {
                    if (numbers[0]*i + numbers[1]*j == numbers[2])
                    {
                        flag = true;
                        break;
                    }
                }
            }
            Console.WriteLine(flag ? "Yes" : "No");


using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            int m = Convert.ToInt32(Console.ReadLine());
            int answ = ans(n, m);
            Console.WriteLine(answ);
        }
        public static int ans(int n, int m)
        {
            while (true)
            {
                for (int i = 1; i <= n; i++)
                {
                    m -= i;
                    if (m < 0) { return m + i; }
                    else if (m == 0)
                    {
                        return 0;
                    }
                }
            }
        }
    }
}


using System;

namespace ConsoleApplication1
{
    class Program
    {
        static bool She(byte a,byte b)
        {
            if(a==b)
            {
                return true;
            }
            return a-1==b;
        }
        static bool He(byte a, byte b)
        {
            if (a-1 == b)
            {
                return true;
            }
            return a<=b*2+2;
        }
        static void Main()
        {
            var s1 = Console.ReadLine().Split(' ');
            var s2 = Console.ReadLine().Split(' ');
            var b1 = new[] {Convert.ToByte(s1[0]), Convert.ToByte(s1[1])};
            var b2 = new[] { Convert.ToByte(s2[0]), Convert.ToByte(s2[1]) };
            var t = b1[0] >= b2[1] ? She(b1[0], b2[1]) : He(b2[1], b1[0]);
            if(!t)
            {
                t = b1[1]>=b2[0] ? She(b1[1], b2[0]) : He(b2[0], b1[1]);
            }
            if (!t)
            {
                t = b1[1] >= b2[1] ? She(b1[1], b2[1]) : He(b2[1], b1[1]);
            }
            if (!t)
            {
                t = b1[0] >= b2[0] ? She(b1[0], b2[0]) : He(b2[0], b1[0]);
            }
            Console.WriteLine(t?"YES":"NO");
        }
    }
}


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

namespace ConsoleApplication14
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine(), c = Console.ReadLine();
            int x = 0, y = 1;
            for (int i = 0; i < s.Length; i++)
            {
                if (s[i] != c[c.Length - y])
                    x++;
                y++;
            }
            if (x > 0)
                Console.WriteLine("NO");
            else
                Console.WriteLine("YES");

        }
    }
}


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

    public class Program
    {
        public static void Main(string[] args)
        {
            var first = Console.ReadLine();
            var second = Console.ReadLine();
            var output = Convert.ToByte(first, 2) ^ Convert.ToByte(second, 2);
            var outS = Convert.ToString(output, 2);
            var temp = "";
            StringBuilder sb=new StringBuilder(outS);
            var tempLength = outS.Length;
            while (tempLength != first.Length)
            {
                temp += "0";
                tempLength++;
            }
            Console.WriteLine(temp + outS);

        }
    }


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

namespace Hack_it
{
    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)
        {
            BigInteger sum = 0;
            BigInteger count = 1;
            int i = 1;
            for (; i <= 20; i++)
            {
                count *= 10;
            }

            for (int j = 1; j < 10; j++)
            {
                sum += count*j*i;
            }
            sum += 1;

            BigInteger a = BigInteger.Parse(reader.ReadLine());

            BigInteger d = sum%a;
            if (d != 0)
            {
                d = a - d;
            }

            writer.WriteLine("{0} {1}", d + 1, count + d);
            writer.Flush();
        }
    }
}


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

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){

		bool[] isPrime = new bool[N+1];
		for(int i=2;i<=N;i++) isPrime[i] = true;
		for(int i=2;i<=N;i++){
			if(!isPrime[i]) continue;
			for(int j=i+i;j<=N;j+=i) isPrime[j] = false;
		}

		int[] bp = new int[N+1];
		for(int i=0;i<=N;i++) bp[i] = i;
		for(int i=2;i<=N;i++){
			if(bp[i] == i){
				for(int j=i+i;j<=N;j+=i){
					bp[j] = i;
				}
			}
		}
//Console.WriteLine("ok");
		int min = N - bp[N] + 1;
		bool[] pos = new bool[N+1];
		pos[N] = true;
		for(int j=0;j<bp[N];j++){
			pos[N-j] = true;
			if(isPrime[N-j]) pos[N-j] = false;
		}

		for(int i=0;i<=N;i++){
			if(pos[i]){
				if(isPrime[i]) {
					pos[i] = false;
					continue;
				}
				for(int j=0;j<bp[i];j++){
					pos[i-j] = true;
					//if(isPrime[i-j]) pos[i-j] = false;
				}
			}
		}

		int min2 = 0;
		for(int i=0;i<=N;i++){
			if(pos[i]){
				min2 = i;
				break;;
			}
		}

		Console.WriteLine(Math.Min(min2, min));

	}

	int N;
	public Sol(){
		N = ri();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}